summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-04-19 09:01:46 -0600
committerJared Adams <jaxad0127@gmail.com>2009-04-19 09:01:46 -0600
commit822690170b501397b86626e13b5a542712a1719d (patch)
tree327bd24839195d677beca694b9a8fca7b18245ca
parent124865b5d67c8c7b199046d19380e1e154ee99e4 (diff)
downloadmana-822690170b501397b86626e13b5a542712a1719d.tar.gz
mana-822690170b501397b86626e13b5a542712a1719d.tar.bz2
mana-822690170b501397b86626e13b5a542712a1719d.tar.xz
mana-822690170b501397b86626e13b5a542712a1719d.zip
Flesh out eAtehan party handling
-rw-r--r--src/commandhandler.cpp48
-rw-r--r--src/commandhandler.h5
-rw-r--r--src/gui/partywindow.cpp12
-rw-r--r--src/gui/partywindow.h2
-rw-r--r--src/net/ea/gui/partytab.cpp100
-rw-r--r--src/net/ea/partyhandler.cpp117
-rw-r--r--src/net/ea/partyhandler.h15
-rw-r--r--src/net/ea/protocol.h7
-rw-r--r--src/net/partyhandler.h18
-rw-r--r--src/net/tmwserv/partyhandler.h12
10 files changed, 290 insertions, 46 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 2f9969e8..81507791 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -56,7 +56,7 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
{
// Nothing to do
}
- if (type == "announce")
+ else if (type == "announce")
{
handleAnnounce(args, tab);
}
@@ -114,6 +114,22 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
}
}
+char CommandHandler::parseBoolean(const std::string &value)
+{
+ std::string opt = value.substr(0, 1);
+
+ if (opt == "1" ||
+ opt == "y" || opt == "Y" ||
+ opt == "t" || opt == "T")
+ return 1;
+ else if (opt == "0" ||
+ opt == "n" || opt == "N" ||
+ opt == "f" || opt == "F")
+ return 0;
+ else
+ return -1;
+}
+
void CommandHandler::handleAnnounce(const std::string &args, ChatTab *tab)
{
Net::getAdminHandler()->announce(args);
@@ -374,27 +390,21 @@ void CommandHandler::handleToggle(const std::string &args, ChatTab *tab)
return;
}
- std::string opt = args.substr(0, 1);
+ char opt = parseBoolean(args);
- if (opt == "1" ||
- opt == "y" || opt == "Y" ||
- opt == "t" || opt == "T")
- {
- tab->chatLog(_("Return now toggles chat."));
- chatWindow->setReturnTogglesChat(true);
- return;
- }
- else if (opt == "0" ||
- opt == "n" || opt == "N" ||
- opt == "f" || opt == "F")
+ switch (opt)
{
- tab->chatLog(_("Message now closes chat."));
- chatWindow->setReturnTogglesChat(false);
- return;
+ case 1:
+ tab->chatLog(_("Return now toggles chat."));
+ chatWindow->setReturnTogglesChat(true);
+ return;
+ case 0:
+ tab->chatLog(_("Message now closes chat."));
+ chatWindow->setReturnTogglesChat(false);
+ return;
+ case -1:
+ tab->chatLog(strprintf(BOOLEAN_OPTIONS, "toggle"));
}
- else
- tab->chatLog(_("Options to /toggle are \"yes\", \"no\", \"true\", "
- "\"false\", \"1\", \"0\"."));
}
void CommandHandler::handlePresent(const std::string &args, ChatTab *tab)
diff --git a/src/commandhandler.h b/src/commandhandler.h
index 2969d1a1..783e400d 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -28,6 +28,9 @@ class ChatTab;
extern ChatTab *localChatTab;
+#define BOOLEAN_OPTIONS _("Options to /%s are \"yes\", \"no\", \"true\", "\
+"\"false\", \"1\", \"0\".")
+
/**
* A class to parse and handle user commands
*/
@@ -49,6 +52,8 @@ class CommandHandler
*/
void handleCommand(const std::string &command, ChatTab *tab = localChatTab);
+ static char parseBoolean(const std::string &value);
+
private:
/**
* Handle an announce command.
diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp
index c13a0810..d9ba5a63 100644
--- a/src/gui/partywindow.cpp
+++ b/src/gui/partywindow.cpp
@@ -42,6 +42,7 @@ PartyWindow::PartyWindow() : Window(_("Party"))
setDefaultSize(620, 300, 110, 200);
loadWindowState();
+ setVisible(false); // Do not start out visible
}
PartyWindow::~PartyWindow()
@@ -72,8 +73,8 @@ PartyMember *PartyWindow::findOrCreateMember(int id)
{
member = new PartyMember;
member->avatar = new Avatar("");
- add(member->avatar, 0, (mMembers.size() - 1) * 14);
mMembers[id] = member;
+ add(member->avatar, 0, (mMembers.size() - 1) * 14);
}
return member;
@@ -99,9 +100,7 @@ int PartyWindow::findMember(const std::string &name) const
void PartyWindow::updateMember(int id, const std::string &memberName,
bool leader, bool online)
{
- // create new party member
PartyMember *player = findOrCreateMember(id);
- player->id = id;
player->name = memberName;
player->leader = leader;
player->online = online;
@@ -189,3 +188,10 @@ void PartyWindow::action(const gcn::ActionEvent &event)
mPartyInviter = "";
}
}
+
+void PartyWindow::clear()
+{
+ Window::clear();
+
+ mMembers.clear();
+}
diff --git a/src/gui/partywindow.h b/src/gui/partywindow.h
index 3729cc09..d7938f96 100644
--- a/src/gui/partywindow.h
+++ b/src/gui/partywindow.h
@@ -111,6 +111,8 @@ class PartyWindow : public Window, gcn::ActionListener
*/
void action(const gcn::ActionEvent &event);
+ void clear();
+
private:
/**
* Find a party member based on ID. Creates if not found.
diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp
index b37105e9..0ba5c7f6 100644
--- a/src/net/ea/gui/partytab.cpp
+++ b/src/net/ea/gui/partytab.cpp
@@ -21,6 +21,8 @@
#include "partytab.h"
+#include "commandhandler.h"
+
#include "net/net.h"
#include "net/partyhandler.h"
@@ -53,6 +55,9 @@ void PartyTab::showHelp()
chatLog(_("/new > Alias of create"));
chatLog(_("/invite > Invite a player to your party"));
chatLog(_("/leave > Leave the party you are in"));
+ chatLog(_("/kick > Kick some one from the party you are in"));
+ chatLog(_("/item > Show/change party item sharing options"));
+ chatLog(_("/exp > Show/change party experience sharing options"));
}
bool PartyTab::handleCommand(const std::string &type, const std::string &args)
@@ -65,8 +70,6 @@ bool PartyTab::handleCommand(const std::string &type, const std::string &args)
chatLog(_("Command: /create <party-name>"));
chatLog(_("These commands create a new party called <party-name>."));
}
- //else if (msg == "settings")
- //else if (msg == "info")
else if (args == "invite")
{
chatLog(_("Command: /invite <nick>"));
@@ -79,6 +82,26 @@ bool PartyTab::handleCommand(const std::string &type, const std::string &args)
chatLog(_("Command: /leave"));
chatLog(_("This command causes the player to leave the party."));
}
+ else if (args == "item")
+ {
+ chatLog(_("Command: /item <policy>"));
+ chatLog(_("This command changes the party's item sharing policy."));
+ chatLog(_("<policy> can be one of \"1\", \"yes\", \"true\" to "
+ "enable item sharing, or \"0\", \"no\", \"false\" to "
+ "disable item sharing."));
+ chatLog(_("Command: /item"));
+ chatLog(_("This command displays the party's current item sharing policy."));
+ }
+ else if (args == "exp")
+ {
+ chatLog(_("Command: /exp <policy>"));
+ chatLog(_("This command changes the party's experience sharing policy."));
+ chatLog(_("<policy> can be one of \"1\", \"yes\", \"true\" to "
+ "enable experience sharing, or \"0\", \"no\", \"false\" to "
+ "disable experience sharing."));
+ chatLog(_("Command: /exp"));
+ chatLog(_("This command displays the party's current experience sharing policy."));
+ }
else
return false;
}
@@ -97,14 +120,73 @@ bool PartyTab::handleCommand(const std::string &type, const std::string &args)
{
Net::getPartyHandler()->leave();
}
- else if (type == "settings")
+ else if (type == "kick")
+ {
+ Net::getPartyHandler()->kick(args);
+ }
+ else if (type == "item")
{
- chatLog(_("The settings command is not yet implemented!"));
- /*
- MessageOut outMsg(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(0); // Experience
- outMsg.writeInt16(0); // Item
- */
+ if (args.empty())
+ {
+ switch (Net::getPartyHandler()->getShareItems())
+ {
+ case PARTY_SHARE:
+ chatLog(_("Item sharing enabled."), BY_SERVER);
+ return true;
+ case PARTY_SHARE_NO:
+ chatLog(_("Item sharing disabled."), BY_SERVER);
+ return true;
+ case PARTY_SHARE_NOT_POSSIBLE:
+ chatLog(_("Item sharing not possible."), BY_SERVER);
+ return true;
+ }
+ }
+
+ char opt = CommandHandler::parseBoolean(args);
+
+ switch (opt)
+ {
+ case 1:
+ Net::getPartyHandler()->setShareItems(PARTY_SHARE);
+ break;
+ case 0:
+ Net::getPartyHandler()->setShareItems(PARTY_SHARE_NO);
+ break;
+ case -1:
+ chatLog(strprintf(BOOLEAN_OPTIONS, "item"));
+ }
+ }
+ else if (type == "exp")
+ {
+ if (args.empty())
+ {
+ switch (Net::getPartyHandler()->getShareExperience())
+ {
+ case PARTY_SHARE:
+ chatLog(_("Experience sharing enabled."), BY_SERVER);
+ return true;
+ case PARTY_SHARE_NO:
+ chatLog(_("Experience sharing disabled."), BY_SERVER);
+ return true;
+ case PARTY_SHARE_NOT_POSSIBLE:
+ chatLog(_("Experience sharing not possible."), BY_SERVER);
+ return true;
+ }
+ }
+
+ char opt = CommandHandler::parseBoolean(args);
+
+ switch (opt)
+ {
+ case 1:
+ Net::getPartyHandler()->setShareExperience(PARTY_SHARE);
+ break;
+ case 0:
+ Net::getPartyHandler()->setShareExperience(PARTY_SHARE_NO);
+ break;
+ case -1:
+ chatLog(strprintf(BOOLEAN_OPTIONS, "exp"));
+ }
}
else
return false;
diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp
index 625f233a..8001488a 100644
--- a/src/net/ea/partyhandler.cpp
+++ b/src/net/ea/partyhandler.cpp
@@ -23,6 +23,7 @@
#include "beingmanager.h"
#include "localplayer.h"
+#include "log.h"
#include "gui/chat.h"
#include "gui/partywindow.h"
@@ -82,6 +83,8 @@ void PartyHandler::handleMessage(MessageIn &msg)
break;
case SMSG_PARTY_INFO:
{
+ partyWindow->clear();
+
int length = msg.readInt16();
std::string party = msg.readString(24);
int count = (length - 28) / 46;
@@ -96,6 +99,8 @@ void PartyHandler::handleMessage(MessageIn &msg)
partyWindow->updateMember(id, nick, leader, online);
}
+
+ partyWindow->setVisible(true);
}
break;
case SMSG_PARTY_INVITE_RESPONSE:
@@ -147,9 +152,58 @@ void PartyHandler::handleMessage(MessageIn &msg)
break;
}
case SMSG_PARTY_SETTINGS:
- // I don't see this in eAthena's source
- printf("Party settings!\n");
- break;
+ {
+ // These seem to indicate the sharing mode for exp and items
+ short exp = msg.readInt16();
+ short item = msg.readInt16();
+
+ switch (exp) {
+ case PARTY_SHARE:
+ if (mShareExp == PARTY_SHARE)
+ break;
+ mShareExp = PARTY_SHARE;
+ partyTab->chatLog(_("Experience sharing enabled."), BY_SERVER);
+ break;
+ case PARTY_SHARE_NO:
+ if (mShareExp == PARTY_SHARE_NO)
+ break;
+ mShareExp =PARTY_SHARE_NO;
+ partyTab->chatLog(_("Experience sharing disabled."), BY_SERVER);
+ break;
+ case PARTY_SHARE_NOT_POSSIBLE:
+ if (mShareExp == PARTY_SHARE_NOT_POSSIBLE)
+ break;
+ mShareExp = PARTY_SHARE_NOT_POSSIBLE;
+ partyTab->chatLog(_("Experience sharing not possible."), BY_SERVER);
+ break;
+ default:
+ logger->log("Unknown party exp option: %d\n", exp);
+ }
+
+ switch (item) {
+ case PARTY_SHARE:
+ if (mShareItems == PARTY_SHARE)
+ break;
+ mShareItems = PARTY_SHARE;
+ partyTab->chatLog(_("Item sharing enabled."), BY_SERVER);
+ break;
+ case PARTY_SHARE_NO:
+ if (mShareItems == PARTY_SHARE_NO)
+ break;
+ mShareItems =PARTY_SHARE_NO;
+ partyTab->chatLog(_("Item sharing disabled."), BY_SERVER);
+ break;
+ case PARTY_SHARE_NOT_POSSIBLE:
+ if (mShareItems == PARTY_SHARE_NOT_POSSIBLE)
+ break;
+ mShareItems = PARTY_SHARE_NOT_POSSIBLE;
+ partyTab->chatLog(_("Item sharing not possible."), BY_SERVER);
+ break;
+ default:
+ logger->log("Unknown party item option: %d\n", exp);
+ }
+ break;
+ }
case SMSG_PARTY_MOVE:
{
msg.readInt32(); // id
@@ -167,7 +221,15 @@ void PartyHandler::handleMessage(MessageIn &msg)
int id = msg.readInt32();
std::string nick = msg.readString(24);
msg.readInt8(); // fail
- partyTab->chatLog(strprintf(_("%s has left your party."),
+ if (id == player_node->getId())
+ {
+ player_node->setInParty(false);
+ partyWindow->clear();
+ partyWindow->setVisible(false);
+ partyTab->chatLog(_("You have left the party."), BY_SERVER);
+ }
+ else
+ partyTab->chatLog(strprintf(_("%s has left your party."),
nick.c_str()), BY_SERVER);
partyWindow->removeMember(id);
break;
@@ -219,6 +281,7 @@ void PartyHandler::create(const std::string &name)
void PartyHandler::join(int partyId)
{
+ // TODO?
}
void PartyHandler::invite(Player *player)
@@ -229,7 +292,7 @@ void PartyHandler::invite(Player *player)
void PartyHandler::invite(const std::string &name)
{
- // TODO
+ // TODO?
}
void PartyHandler::inviteResponse(const std::string &inviter, bool accept)
@@ -243,13 +306,28 @@ void PartyHandler::inviteResponse(const std::string &inviter, bool accept)
void PartyHandler::leave()
{
MessageOut outMsg(CMSG_PARTY_LEAVE);
- partyTab->chatLog(_("Left party."), BY_SERVER);
- player_node->setInParty(false);
}
-void PartyHandler::kick(int playerId)
+void PartyHandler::kick(Player *player)
{
- // TODO
+ MessageOut outMsg(CMSG_PARTY_KICK);
+ outMsg.writeInt32(player->getId());
+ outMsg.writeString("", 24); //Unused
+}
+
+void PartyHandler::kick(const std::string &name)
+{
+ int id = partyWindow->findMember(name);
+ if (id == -1)
+ {
+ partyTab->chatLog(strprintf(_("%s is not in your party!"), name.c_str()),
+ BY_SERVER);
+ return;
+ }
+
+ MessageOut outMsg(CMSG_PARTY_KICK);
+ outMsg.writeInt32(id);
+ outMsg.writeString(name, 24); //Unused
}
void PartyHandler::chat(const std::string &text)
@@ -262,6 +340,27 @@ void PartyHandler::chat(const std::string &text)
void PartyHandler::requestPartyMembers()
{
// Our eAthena doesn't have this message
+ // Not needed anyways
+}
+
+void PartyHandler::setShareExperience(PartyShare share)
+{
+ if (share == PARTY_SHARE_NOT_POSSIBLE)
+ return;
+
+ MessageOut outMsg(CMSG_PARTY_SETTINGS);
+ outMsg.writeInt16(share);
+ outMsg.writeInt16(mShareItems);
+}
+
+void PartyHandler::setShareItems(PartyShare share)
+{
+ if (share == PARTY_SHARE_NOT_POSSIBLE)
+ return;
+
+ MessageOut outMsg(CMSG_PARTY_SETTINGS);
+ outMsg.writeInt16(mShareExp);
+ outMsg.writeInt16(share);
}
} // namespace EAthena
diff --git a/src/net/ea/partyhandler.h b/src/net/ea/partyhandler.h
index aaebe353..a9fe843b 100644
--- a/src/net/ea/partyhandler.h
+++ b/src/net/ea/partyhandler.h
@@ -49,11 +49,24 @@ class PartyHandler : public MessageHandler, public Net::PartyHandler
void leave();
- void kick(int playerId);
+ void kick(Player *player);
+
+ void kick(const std::string &name);
void chat(const std::string &text);
void requestPartyMembers();
+
+ PartyShare getShareExperience() { return mShareExp; }
+
+ void setShareExperience(PartyShare share);
+
+ PartyShare getShareItems() { return mShareItems; }
+
+ void setShareItems(PartyShare share);
+
+ private:
+ PartyShare mShareExp, mShareItems;
};
} // namespace EAthena
diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h
index d34a635f..c96b1734 100644
--- a/src/net/ea/protocol.h
+++ b/src/net/ea/protocol.h
@@ -119,7 +119,7 @@ static const int STORAGE_OFFSET = 1;
#define SMSG_PARTY_INFO 0x00fb
#define SMSG_PARTY_INVITE_RESPONSE 0x00fd
#define SMSG_PARTY_INVITED 0x00fe
-#define SMSG_PARTY_SETTINGS 0x0102
+#define SMSG_PARTY_SETTINGS 0x0101
#define SMSG_PARTY_MOVE 0x0104
#define SMSG_PARTY_LEAVE 0x0105
#define SMSG_PARTY_UPDATE_HP 0x0106
@@ -192,8 +192,9 @@ static const int STORAGE_OFFSET = 1;
#define CMSG_PARTY_CREATE 0x00f9
#define CMSG_PARTY_INVITE 0x00fc
#define CMSG_PARTY_INVITED 0x00ff
-#define CMSG_PARTY_LEAVE 0x0100 /** Undocumented */
-#define CMSG_PARTY_SETTINGS 0x0101
+#define CMSG_PARTY_LEAVE 0x0100
+#define CMSG_PARTY_SETTINGS 0x0102
+#define CMSG_PARTY_KICK 0x0103
#define CMSG_PARTY_MESSAGE 0x0108
#define CMSG_MOVE_TO_STORAGE 0x00f3 /** Move item to storage */
diff --git a/src/net/partyhandler.h b/src/net/partyhandler.h
index 85b7a2ba..f4107b67 100644
--- a/src/net/partyhandler.h
+++ b/src/net/partyhandler.h
@@ -26,6 +26,12 @@
class Player;
+enum PartyShare {
+ PARTY_SHARE_NO,
+ PARTY_SHARE,
+ PARTY_SHARE_NOT_POSSIBLE = 2
+};
+
namespace Net {
class PartyHandler
@@ -43,12 +49,22 @@ class PartyHandler
virtual void leave() = 0;
- virtual void kick(int playerId) = 0;
+ virtual void kick(Player *player) = 0;
+
+ virtual void kick(const std::string &name) = 0;
virtual void chat(const std::string &text) = 0;
virtual void requestPartyMembers() = 0;
+ virtual PartyShare getShareExperience() = 0;
+
+ virtual void setShareExperience(PartyShare share) = 0;
+
+ virtual PartyShare getShareItems() = 0;
+
+ virtual void setShareItems(PartyShare share) = 0;
+
// virtual void options() = 0;
// virtual void message() = 0;
diff --git a/src/net/tmwserv/partyhandler.h b/src/net/tmwserv/partyhandler.h
index 9dad4bbc..aa899166 100644
--- a/src/net/tmwserv/partyhandler.h
+++ b/src/net/tmwserv/partyhandler.h
@@ -48,11 +48,21 @@ public:
void leave();
- void kick(int playerId);
+ void kick(Player *player);
+
+ void kick(const std::string &name);
void chat(const std::string &text);
void requestPartyMembers();
+
+ PartyShare getShareExperience() { return PARTY_SHARE_NO; }
+
+ void setShareExperience(PartyShare share) {}
+
+ PartyShare getShareItems() { return PARTY_SHARE_NO; }
+
+ void setShareItems(PartyShare share) {}
};
} // namespace TmwServ