summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commandhandler.cpp57
-rw-r--r--src/game.cpp9
-rw-r--r--src/game.h2
-rw-r--r--src/gui/chat.cpp10
-rw-r--r--src/gui/chat.h9
-rw-r--r--src/gui/partywindow.cpp86
-rw-r--r--src/gui/partywindow.h48
-rw-r--r--src/gui/popupmenu.cpp5
-rw-r--r--src/gui/widgets/avatar.cpp48
-rw-r--r--src/gui/widgets/avatar.h16
-rw-r--r--src/gui/widgets/chattab.cpp27
-rw-r--r--src/gui/widgets/chattab.h5
-rw-r--r--src/localplayer.cpp14
-rw-r--r--src/localplayer.h5
-rw-r--r--src/net/ea/gui/partytab.cpp68
-rw-r--r--src/net/ea/party.cpp128
-rw-r--r--src/net/ea/party.h16
-rw-r--r--src/net/ea/partyhandler.cpp104
-rw-r--r--src/net/ea/protocol.h2
-rw-r--r--src/net/tmwserv/partyhandler.cpp6
20 files changed, 339 insertions, 326 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index f2da21e0..7b5f1ddb 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -170,8 +170,6 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab)
tab->chatLog(_("/kick > Kick a user from the channel"));
tab->chatLog(_("/party > Invite a user to party"));
-#else
- tab->chatLog(_("/party > Party-related commands"));
#endif
tab->chatLog(_("/record > Start recording the chat to an external file"));
@@ -242,17 +240,15 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab)
tab->chatLog(_("Channel operators can kick and op other users "
"from the channel."));
}
-#ifdef TMWSERV_SUPPORT
else if (args == "party")
{
+#ifdef TMWSERV_SUPPORT
tab->chatLog(_("Command: /party <nick>"));
tab->chatLog(_("This command invites <nick> to party with you."));
tab->chatLog(_("If the <nick> has spaces in it, enclose it in "
"double quotes (\")."));
#else
- else if (args.substr(0, 5) == "party")
- {
- eAthena::Party::help(args);
+ tab->chatLog(_("Party commands are used on the party tab."));
#endif
}
else if (args == "present")
@@ -479,54 +475,7 @@ void CommandHandler::handleParty(const std::string &args, ChatTab *tab)
player_node->inviteToParty(args);
}
#else
- if (args.empty())
- {
- tab->chatLog(_("Unknown party command... Type \"/help\" party for more "
- "information."), BY_SERVER);
- return;
- }
-
- const std::string::size_type space = args.find(" ");
- std::string command;
- std::string rest;
-
- if (space == std::string::npos)
- {
- command = args;
- }
- else
- {
- command = args.substr(0, space);
- rest = args.substr(space + 1, args.length());
- }
-
- if (command == "prefix")
- {
- if (rest.empty())
- {
- char temp[2] = ".";
- *temp = chatWindow->getPartyPrefix();
- tab->chatLog(_("The current party prefix is ") + std::string(temp));
- }
- else if (rest.length() != 1)
- {
- tab->chatLog(_("Party prefix must be one character long."));
- }
- else
- {
- if (rest == "/")
- {
- tab->chatLog(_("Cannot use a '/' as the prefix."));
- }
- else
- {
- chatWindow->setPartyPrefix(rest.at(0));
- tab->chatLog(_("Changing prefix to ") + rest);
- }
- }
- }
- else
- eAthena::Party::respond(command, rest);
+ tab->chatLog(_("Please use party commands on the party tab."));
#endif
}
diff --git a/src/game.cpp b/src/game.cpp
index 20bf1af1..496bdeef 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -99,6 +99,7 @@
#include "net/tmwserv/inventoryhandler.h"
#include "net/tmwserv/partyhandler.h"
#else
+#include "net/ea/gui/partytab.h"
#include "net/ea/network.h"
#include "net/ea/chathandler.h"
#include "net/ea/beinghandler.h"
@@ -108,6 +109,7 @@
#include "net/ea/itemhandler.h"
#include "net/ea/npchandler.h"
#include "net/ea/playerhandler.h"
+#include "net/ea/partyhandler.h"
#include "net/ea/tradehandler.h"
#include "net/ea/protocol.h"
#include "net/ea/skillhandler.h"
@@ -353,7 +355,6 @@ static void destroyGuiWindows()
Game::Game():
mBeingHandler(new BeingHandler),
mGuildHandler(new GuildHandler),
- mPartyHandler(new PartyHandler),
mEffectHandler(new EffectHandler),
#else
Game::Game(Network *network):
@@ -362,6 +363,7 @@ Game::Game(Network *network):
mEquipmentHandler(new EquipmentHandler),
mSkillHandler(new SkillHandler),
#endif
+ mPartyHandler(new PartyHandler),
mBuySellHandler(new BuySellHandler),
mChatHandler(new ChatHandler),
mInventoryHandler(new InventoryHandler),
@@ -427,6 +429,9 @@ Game::Game(Network *network):
network->registerHandler(mPlayerHandler.get());
network->registerHandler(mSkillHandler.get());
network->registerHandler(mTradeHandler.get());
+ network->registerHandler(mPartyHandler.get());
+
+ partyTab = new PartyTab();
/*
* To prevent the server from sending data before the client
@@ -452,6 +457,8 @@ Game::~Game()
{
#ifdef TMWSERV_SUPPORT
Net::clearHandlers();
+#else
+ delete partyTab;
#endif
destroyGuiWindows();
diff --git a/src/game.h b/src/game.h
index c537d147..4491621a 100644
--- a/src/game.h
+++ b/src/game.h
@@ -68,12 +68,12 @@ class Game : public ConfigListener
MessageHandlerPtr mBeingHandler;
#ifdef TMWSERV_SUPPORT
MessageHandlerPtr mGuildHandler;
- MessageHandlerPtr mPartyHandler;
MessageHandlerPtr mEffectHandler;
#else
MessageHandlerPtr mEquipmentHandler;
MessageHandlerPtr mSkillHandler;
#endif
+ MessageHandlerPtr mPartyHandler;
MessageHandlerPtr mBuySellHandler;
MessageHandlerPtr mChatHandler;
MessageHandlerPtr mInventoryHandler;
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 10993027..014ac8b5 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -68,12 +68,9 @@ ChatWindow::ChatWindow():
mChatInput->addKeyListener(this);
mCurHist = mHistory.end();
-#ifdef EATHENA_SUPPORT
- // Read the party prefix
- std::string partyPrefix = config.getValue("PartyPrefix", "$");
- mPartyPrefix = (partyPrefix.empty() ? '$' : partyPrefix.at(0));
mReturnToggles = config.getValue("ReturnToggles", "0") == "1";
+#ifdef EATHENA_SUPPORT
// If the player had @assert on in the last session, ask the server to
// run the @assert command for the player again. Convenience for GMs.
if (config.getValue(player_node->getName() + "GMassert", 0)) {
@@ -86,13 +83,8 @@ ChatWindow::ChatWindow():
ChatWindow::~ChatWindow()
{
-#ifdef EATHENA_SUPPORT
- char partyPrefix[2] = ".";
- *partyPrefix = mPartyPrefix;
- config.setValue("PartyPrefix", partyPrefix);
config.setValue("ReturnToggles", mReturnToggles ? "1" : "0");
delete mRecorder;
-#endif
delete_all(mWhispers);
delete mItemLinkHandler;
}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 3a2f7fdb..3cf2a738 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -159,11 +159,6 @@ class ChatWindow : public Window,
*/
void scroll(int amount);
-#ifdef EATHENA_SUPPORT
- char getPartyPrefix() const { return mPartyPrefix; }
- void setPartyPrefix(char prefix) { mPartyPrefix = prefix; }
-#endif
-
/**
* Sets the file being recorded to
*
@@ -192,10 +187,6 @@ class ChatWindow : public Window,
void adjustTabSize();
-#ifdef EATHENA_SUPPORT
- char mPartyPrefix; /**< Messages beginning with the prefix are sent to
- the party */
-#endif
/** Used for showing item popup on clicking links **/
ItemLinkHandler *mItemLinkHandler;
Recorder *mRecorder;
diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp
index f5cebdfd..d2fd7173 100644
--- a/src/gui/partywindow.cpp
+++ b/src/gui/partywindow.cpp
@@ -21,7 +21,6 @@
#include "gui/partywindow.h"
-#include "gui/widgets/avatar.h"
#include "gui/widgets/chattab.h"
#ifdef TMWSERV_SUPPORT
@@ -49,7 +48,7 @@ PartyWindow::PartyWindow() : Window(_("Party"))
PartyWindow::~PartyWindow()
{
- mPartyMembers.clear();
+ mMembers.clear();
}
void PartyWindow::draw(gcn::Graphics *graphics)
@@ -57,61 +56,84 @@ void PartyWindow::draw(gcn::Graphics *graphics)
Window::draw(graphics);
}
-void PartyWindow::addPartyMember(const std::string &memberName)
+PartyMember *PartyWindow::findMember2(int id)
{
- // check to see if player is already in the party
- PartyList::iterator itr = mPartyMembers.begin(),
- itr_end = mPartyMembers.end();
+ PartyMember *member = findMember(id);
+
+ if (!member)
+ {
+ member = new PartyMember;
+ member->avatar = new Avatar("");
+ add(member->avatar, 0, (mMembers.size() - 1) * 14);
+ mMembers[id] = member;
+ }
+
+ return member;
+}
+
+int PartyWindow::findMember(const std::string &name)
+{
+ PartyList::iterator itr = mMembers.begin(),
+ itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr).name == memberName)
+ if ((*itr).second->name == name)
{
- // already in the party, dont add
- return;
+ return (*itr).first;
}
++itr;
}
- // create new party member
- PartyMember player;
- player.name = memberName;
- mPartyMembers.push_back(player);
+ return -1;
+}
- // add avatar of the new member to window
- Avatar *avatar = new Avatar(memberName);
- add(avatar, 0, (mPartyMembers.size() - 1)*14);
+void PartyWindow::updateMember(int id, const std::string &memberName,
+ bool leader, bool online)
+{
+ // create new party member
+ PartyMember *player = findMember2(id);
+ player->id = id;
+ player->name = memberName;
+ player->leader = leader;
+ player->online = online;
+ player->avatar->setName(memberName);
+ player->avatar->setOnline(online);
// show the window
- if (mPartyMembers.size() > 0)
+ if (mMembers.size() > 0)
{
setVisible(true);
}
}
-void PartyWindow::removePartyMember(const std::string &memberName)
+void PartyWindow::removeMember(int id)
{
- // remove the party member
- PartyList::iterator itr = mPartyMembers.begin(),
- itr_end = mPartyMembers.end();
-
- while (itr != itr_end)
- {
- if ((*itr).name == memberName)
- {
- mPartyMembers.erase(itr);
- break;
- }
- ++itr;
- }
+ mMembers.erase(id);
// if no-one left, remove the party window
- if (mPartyMembers.size() < 1)
+ if (mMembers.size() < 1)
{
setVisible(false);
}
}
+void PartyWindow::removeMember(const std::string &name)
+{
+ removeMember(findMember(name));
+}
+
+void PartyWindow::updateOnlne(int id, bool online)
+{
+ PartyMember *player = findMember(id);
+
+ if (!player)
+ return;
+
+ player->online = online;
+ player->avatar->setOnline(online);
+}
+
void PartyWindow::showPartyInvite(const std::string &inviter,
const std::string &partyName)
{
diff --git a/src/gui/partywindow.h b/src/gui/partywindow.h
index 64cfb582..049030e5 100644
--- a/src/gui/partywindow.h
+++ b/src/gui/partywindow.h
@@ -25,8 +25,10 @@
#include "window.h"
#include "confirm_dialog.h"
+#include "gui/widgets/avatar.h"
+
#include <string>
-#include <vector>
+#include <map>
#include <guichan/actionevent.hpp>
#include <guichan/actionlistener.hpp>
@@ -37,8 +39,13 @@
*/
struct PartyMember
{
+ int id;
std::string name;
- int vitality;
+ int health;
+ int healthMax;
+ bool leader;
+ bool online;
+ Avatar *avatar;
};
/**
@@ -65,14 +72,41 @@ class PartyWindow : public Window, gcn::ActionListener
void draw(gcn::Graphics *graphics);
/**
- * Add party member
+ * Find a party member based on ID
+ */
+ PartyMember *findMember(int id) { return mMembers[id]; }
+
+ /**
+ * Find a party member based on ID. Creates if it doesn't already exist.
+ */
+ PartyMember *findMember2(int id);
+
+ /**
+ * Returns the id of the first member found with the given name or -1
+ * if it isn't found.
+ */
+ int findMember(const std::string &name);
+
+ /**
+ * Update/add a party member
+ */
+ void updateMember(int id, const std::string &memberName,
+ bool leader = false, bool online = true);
+
+ /**
+ * Remove party member
+ */
+ void removeMember(int id);
+
+ /**
+ * Remove party member
*/
- void addPartyMember(const std::string &memberName);
+ void removeMember(const std::string &name);
/**
* Remove party member
*/
- void removePartyMember(const std::string &memberName);
+ void updateOnlne(int id, bool online);
/**
* Show party invite
@@ -86,8 +120,8 @@ class PartyWindow : public Window, gcn::ActionListener
void action(const gcn::ActionEvent &event);
private:
- typedef std::vector<PartyMember> PartyList;
- PartyList mPartyMembers;
+ typedef std::map<int, PartyMember*> PartyList;
+ PartyList mMembers;
std::string mPartyInviter;
ConfirmDialog *acceptDialog;
};
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 1f36ef45..d0281c1f 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -215,13 +215,12 @@ void PopupMenu::handleLink(const std::string &link)
{
player_node->inviteToGuild(being);
}
-
+#endif
// Add player to your party
else if (link == "party")
{
- player_node->inviteToParty(being->getName());
+ player_node->inviteToParty(dynamic_cast<Player*>(being));
}
-#endif
/*
// Follow Player action
else if (link == "follow")
diff --git a/src/gui/widgets/avatar.cpp b/src/gui/widgets/avatar.cpp
index a36c0302..2603e3ae 100644
--- a/src/gui/widgets/avatar.cpp
+++ b/src/gui/widgets/avatar.cpp
@@ -28,28 +28,52 @@
#include <guichan/widgets/label.hpp>
+namespace {
+ Image *avatarStatusOffline;
+ Image *avatarStatusOnline;
+ int avatarCount = 0;
+}
+
Avatar::Avatar(const std::string &name):
mName(name)
{
+ setOpaque(false);
setSize(110, 12);
+
+ if (avatarCount == 0)
+ {
+ ResourceManager *resman = ResourceManager::getInstance();
+ avatarStatusOffline = resman->getImage("graphics/gui/circle-gray.png");
+ avatarStatusOnline = resman->getImage("graphics/gui/circle-green.png");
+ }
+ avatarCount++;
+ avatarStatusOffline->incRef();
+ avatarStatusOnline->incRef();
+
+ mStatus = new Icon(avatarStatusOffline);
+ mStatus->setSize(12, 12);
+ add(mStatus, 1, 0);
+
mLabel = new gcn::Label(name);
mLabel->setSize(85, 12);
- mLabel->setPosition(25, 0);
- ResourceManager *resman = ResourceManager::getInstance();
- mStatusOffline = resman->getImage("graphics/gui/circle-gray.png");
- mStatusOnline = resman->getImage("graphics/gui/circle-green.png");
- mStatus = new Icon(mStatusOffline);
- mStatus->setSize(25, 12);
- mStatus->setPosition(0, 0);
+ add(mLabel, 14, 0);
}
-void Avatar::setOnline(bool online)
+Avatar::~Avatar()
{
- mStatus->setImage(online ? mStatusOnline : mStatusOffline);
+ avatarCount--;
+
+ avatarStatusOffline->decRef();
+ avatarStatusOnline->decRef();
}
-void Avatar::draw(gcn::Graphics *g)
+void Avatar::setName(const std::string &name)
+{
+ mName = name;
+ mLabel->setCaption(name);
+}
+
+void Avatar::setOnline(bool online)
{
- mLabel->draw(g);
- mStatus->draw(g);
+ mStatus->setImage(online ? avatarStatusOnline : avatarStatusOffline);
}
diff --git a/src/gui/widgets/avatar.h b/src/gui/widgets/avatar.h
index 16972104..026a3581 100644
--- a/src/gui/widgets/avatar.h
+++ b/src/gui/widgets/avatar.h
@@ -24,14 +24,14 @@
#include "guichanfwd.h"
-#include <guichan/widget.hpp>
+#include "gui/gccontainer.h"
#include <string>
class Image;
class Icon;
-class Avatar : public gcn::Widget
+class Avatar : public GCContainer
{
public:
/**
@@ -40,21 +40,21 @@ public:
*/
Avatar(const std::string &name);
+ ~Avatar();
+
/**
- * Set the avatar online status.
+ * Set the avatar's name.
*/
- void setOnline(bool online);
+ void setName(const std::string &name);
/**
- * Draws the avatar.
+ * Set the avatar's online status.
*/
- void draw(gcn::Graphics *g);
+ void setOnline(bool online);
private:
std::string mName;
Icon *mStatus;
- Image *mStatusOnline;
- Image *mStatusOffline;
gcn::Label *mLabel;
};
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index c4563cc9..4a63bbcd 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -150,12 +150,6 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord)
// TODO: Use a predefined color
lineColor = "##2"; // Equiv. to BrowserBox::GREEN
break;
-#ifdef EATHENA_SUPPORT
- case BY_PARTY:
- tmp.nick += CAT_NORMAL;
- lineColor = "##P";
- break;
-#endif
case ACT_WHISPER:
// Resend whisper through normal mechanism
chatWindow->whisper(tmp.nick, tmp.text);
@@ -215,7 +209,7 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord)
chatWindow->mRecorder->record(line.substr(3));
}
-void ChatTab::chatLog(std::string &nick, std::string &msg)
+void ChatTab::chatLog(const std::string &nick, const std::string &msg)
{
chatLog(nick + CAT_NORMAL + msg, nick == player_node->getName() ?
BY_PLAYER : BY_OTHER, false);
@@ -227,25 +221,6 @@ void ChatTab::chatInput(std::string &msg)
if (msg.empty()) return;
-#ifdef EATHENA_SUPPORT
- // Send party message
- if (msg.at(0) == chatWindow->mPartyPrefix)
- {
- msg.erase(0, 1);
- std::size_t length = msg.length() + 1;
-
- if (length == 0)
- {
- chatLog(_("Trying to send a blank party message."), BY_SERVER, true);
- return;
- }
- MessageOut outMsg(CMSG_PARTY_MESSAGE);
- outMsg.writeInt16(length + 4);
- outMsg.writeString(msg, length);
- return;
- }
-#endif
-
// Check for item link
std::string::size_type start = msg.find('[');
while (start != std::string::npos && msg[start+1] != '@')
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index 52449f6f..76b33011 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -34,9 +34,6 @@ class ScrollArea;
enum
{
BY_GM,
-#ifdef EATHENA_SUPPORT
- BY_PARTY,
-#endif
BY_PLAYER,
BY_OTHER,
BY_SERVER,
@@ -86,7 +83,7 @@ class ChatTab : public Tab
* @param msg The message text which is to be sent.
*
*/
- void chatLog(std::string &nick, std::string &msg);
+ void chatLog(const std::string &nick, const std::string &msg);
/**
* Determines whether the message is a command or message, then
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index eb54b4b1..039ed91e 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -50,10 +50,9 @@
#include "net/tmwserv/gameserver/player.h"
#include "net/tmwserv/chatserver/guild.h"
#include "net/tmwserv/chatserver/party.h"
-#endif
-
-#ifdef EATHENA_SUPPORT
+#else
#include "net/messageout.h"
+#include "net/ea/party.h"
#include "net/ea/protocol.h"
#endif
@@ -381,7 +380,16 @@ void LocalPlayer::inviteToParty(const std::string &name)
#ifdef TMWSERV_SUPPORT
Net::ChatServer::Party::invitePlayer(name);
#else
+ // need an id
+#endif
+}
+void LocalPlayer::inviteToParty(Player *player)
+{
+#ifdef TMWSERV_SUPPORT
+ Net::ChatServer::Party::invitePlayer(player->getName());
+#else
+ eAthena::Party::invite(player);
#endif
}
diff --git a/src/localplayer.h b/src/localplayer.h
index 4fd68d8f..f6df18a6 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -193,6 +193,11 @@ class LocalPlayer : public Player
void inviteToParty(const std::string &name);
/**
+ * Invite a player to join their party
+ */
+ void inviteToParty(Player *player);
+
+ /**
* Move the Inventory item from the old slot to the new slot.
*/
void moveInvItem(Item *item, int newIndex);
diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp
index 4e486bf0..9759962a 100644
--- a/src/net/ea/gui/partytab.cpp
+++ b/src/net/ea/gui/partytab.cpp
@@ -45,9 +45,73 @@ PartyTab::~PartyTab()
}
void PartyTab::handleInput(const std::string &msg) {
- // TODO
+ std::size_t length = msg.length() + 1;
+
+ MessageOut outMsg(CMSG_PARTY_MESSAGE);
+ outMsg.writeInt16(length + 4);
+ outMsg.writeString(msg, length);
}
void PartyTab::handleCommand(std::string msg) {
- // TODO
+ std::string::size_type pos = msg.find(' ');
+ std::string type(msg, 0, pos);
+ std::string args(msg, pos == std::string::npos ? msg.size() : pos + 1);
+
+ if (type == "help")
+ {
+ if (args == "")
+ {
+ partyTab->chatLog(_("-- Help --"));
+ partyTab->chatLog(_("/help > Display this help."));
+ partyTab->chatLog(_("/create > Create a new party"));
+ partyTab->chatLog(_("/new > alias of create"));
+ partyTab->chatLog(_("/leave > leave the party you are in"));
+ }
+ else if (args == "create" || args == "new")
+ {
+ partyTab->chatLog(_("Command: /party new <party-name>"));
+ partyTab->chatLog(_("Command: /party create <party-name>"));
+ partyTab->chatLog(_("These commands create a new party <party-name."));
+ }
+ //else if (msg == "settings")
+ //else if (msg == "info")
+ else if (args == "leave")
+ {
+ partyTab->chatLog(_("Command: /party leave"));
+ partyTab->chatLog(_("This command causes the player to leave the party."));
+ }
+ else if (args == "help")
+ {
+ partyTab->chatLog(_("Command: /help"));
+ partyTab->chatLog(_("This command displays a list of all commands available."));
+ partyTab->chatLog(_("Command: /help <command>"));
+ partyTab->chatLog(_("This command displays help on <command>."));
+ }
+ else
+ {
+ partyTab->chatLog(_("Unknown command."));
+ partyTab->chatLog(_("Type /help for a list of commands."));
+ }
+ }
+ else if (type == "create" || type == "new")
+ {
+ eAthena::Party::create(args);
+ }
+ else if (type == "leave")
+ {
+ eAthena::Party::leave(args);
+ }
+ else if (type == "settings")
+ {
+ partyTab->chatLog(_("The settings command is not yet implemented!"));
+ /*
+ MessageOut outMsg(CMSG_PARTY_SETTINGS);
+ outMsg.writeInt16(0); // Experience
+ outMsg.writeInt16(0); // Item
+ */
+ }
+ else
+ {
+ partyTab->chatLog("Unknown command");
+ }
}
diff --git a/src/net/ea/party.cpp b/src/net/ea/party.cpp
index 0fbba2f1..bb7fb4c6 100644
--- a/src/net/ea/party.cpp
+++ b/src/net/ea/party.cpp
@@ -33,38 +33,14 @@
#include "net/ea/gui/partytab.h"
#include "utils/gettext.h"
+#include "utils/stringutils.h"
#include "utils/strprintf.h"
-void eAthena::Party::respond(const std::string &command, const std::string &args)
-{
- if (command == "new" || command == "create")
- {
- create(args);
- return;
- }
- if (command == "leave")
- {
- leave(args);
- return;
- }
- if (command == "settings")
- {
- partyTab->chatLog(_("Not yet implemented!"), BY_SERVER);
- return;
- /*
- MessageOut outMsg(CMSG_PARTY_SETTINGS);
- outMsg.writeInt16(0); // Experience
- outMsg.writeInt16(0); // Item
- */
- }
- partyTab->chatLog(_("Party command not known."), BY_SERVER);
-}
-
void eAthena::Party::create(const std::string &party)
{
if (party.empty())
{
- localChatTab->chatLog(_("Party name is missing."), BY_SERVER);
+ partyTab->chatLog(_("Party name is missing."), BY_SERVER);
return;
}
MessageOut outMsg(CMSG_PARTY_CREATE);
@@ -74,7 +50,7 @@ void eAthena::Party::create(const std::string &party)
void eAthena::Party::leave(const std::string &args)
{
MessageOut outMsg(CMSG_PARTY_LEAVE);
- localChatTab->chatLog(_("Left party."), BY_SERVER);
+ partyTab->chatLog(_("Left party."), BY_SERVER);
player_node->setInParty(false);
}
@@ -82,32 +58,19 @@ void eAthena::Party::createResponse(bool ok)
{
if (ok)
{
- localChatTab->chatLog(_("Party successfully created."), BY_SERVER);
+ partyTab->chatLog(_("Party successfully created."), BY_SERVER);
player_node->setInParty(true);
}
else
{
- localChatTab->chatLog(_("Could not create party."), BY_SERVER);
+ partyTab->chatLog(_("Could not create party."), BY_SERVER);
}
}
-void eAthena::Party::inviteResponse(const std::string &nick, int status)
+void eAthena::Party::invite(Player *player)
{
- switch (status)
- {
- case 0:
- partyTab->chatLog(strprintf(_("%s is already a member of a party."),
- nick.c_str()), BY_SERVER);
- break;
- case 1:
- partyTab->chatLog(strprintf(_("%s refused your invitation."),
- nick.c_str()), BY_SERVER);
- break;
- case 2:
- partyTab->chatLog(strprintf(_("%s is now a member of your party."),
- nick.c_str()), BY_SERVER);
- break;
- }
+ MessageOut outMsg(CMSG_PARTY_INVITE);
+ outMsg.writeInt32(player->getId());
}
void eAthena::Party::respondToInvite(bool accept)
@@ -117,78 +80,3 @@ void eAthena::Party::respondToInvite(bool accept)
outMsg.writeInt32(accept ? 1 : 0);
player_node->setInParty(player_node->getInParty() || accept);
}
-
-void eAthena::Party::leftResponse(const std::string &nick)
-{
- localChatTab->chatLog(strprintf(_("%s has left your party."), nick.c_str()),
- BY_SERVER);
- partyWindow->removePartyMember(nick);
-}
-
-void eAthena::Party::receiveChat(Being *being, const std::string &msg)
-{
- if (!being)
- {
- return;
- }
- if (being->getType() != Being::PLAYER)
- {
- localChatTab->chatLog(_("Party chat received, but being is not a player"),
- BY_SERVER);
- return;
- }
- being->setSpeech(msg, SPEECH_TIME);
- localChatTab->chatLog(being->getName() + " : " + msg, BY_PARTY);
-}
-
-void eAthena::Party::help(const std::string &args)
-{
- // Strip "party " from the front
- std::string msg = args.substr(6, args.length());
-
- if (msg.empty())
- {
- localChatTab->chatLog(_("Command: /party <command> <args>"), BY_SERVER);
- localChatTab->chatLog(_("where <command> can be one of:"), BY_SERVER);
- localChatTab->chatLog(_(" /new"), BY_SERVER);
- localChatTab->chatLog(_(" /create"), BY_SERVER);
- localChatTab->chatLog(_(" /prefix"), BY_SERVER);
- localChatTab->chatLog(_(" /leave"), BY_SERVER);
- localChatTab->chatLog(_("This command implements the partying function."),
- BY_SERVER);
- localChatTab->chatLog(_("Type /help party <command> for further help."),
- BY_SERVER);
- return;
- }
- if (msg == "new" || msg == "create")
- {
- localChatTab->chatLog(_("Command: /party new <party-name>"), BY_SERVER);
- localChatTab->chatLog(_("Command: /party create <party-name>"), BY_SERVER);
- localChatTab->chatLog(_("These commands create a new party <party-name."),
- BY_SERVER);
- return;
- }
- if (msg == "prefix")
- {
- localChatTab->chatLog(_("Command: /party prefix <prefix-char>"), BY_SERVER);
- localChatTab->chatLog(_("This command sets the party prefix character."),
- BY_SERVER);
- localChatTab->chatLog(_("Any message preceded by <prefix-char> is sent to "
- "the party instead of everyone."), BY_SERVER);
- localChatTab->chatLog(_("Command: /party prefix"), BY_SERVER);
- localChatTab->chatLog(_("This command reports the current party prefix "
- "character."), BY_SERVER);
- return;
- }
- //if (msg == "settings")
- //if (msg == "info")
- if (msg == "leave")
- {
- localChatTab->chatLog(_("Command: /party leave"), BY_SERVER);
- localChatTab->chatLog(_("This command causes the player to leave the party."),
- BY_SERVER);
- return;
- }
- localChatTab->chatLog(_("Unknown /party command."), BY_SERVER);
- localChatTab->chatLog(_("Type /help party for a list of options."), BY_SERVER);
-}
diff --git a/src/net/ea/party.h b/src/net/ea/party.h
index 6907de47..f47c4956 100644
--- a/src/net/ea/party.h
+++ b/src/net/ea/party.h
@@ -23,6 +23,7 @@
#define PARTY_H
#include "being.h"
+#include "player.h"
#include <string>
@@ -30,28 +31,17 @@ namespace eAthena
{
namespace Party
{
- void respond(const std::string &command, const std::string &args);
-
void create(const std::string &party);
void leave(const std::string &args);
void createResponse(bool ok);
- void inviteResponse(const std::string &nick, int status);
- void invitedAsk(const std::string &nick, int gender,
- const std::string &partyName);
+
+ void invite(Player *player);
/**
* Send invite response to the server
*/
void respondToInvite(bool accept);
-
- /**
- * The player has left your party
- */
- void leftResponse(const std::string &nick);
- void receiveChat(Being *being, const std::string &msg);
-
- void help(const std::string &args);
}
}
diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp
index 7ecf0863..6fdf6803 100644
--- a/src/net/ea/partyhandler.cpp
+++ b/src/net/ea/partyhandler.cpp
@@ -21,17 +21,19 @@
#include "net/ea/partyhandler.h"
-#include "net/ea/gui/partytab.h"
+#include "beingmanager.h"
-#include "net/ea/protocol.h"
+#include "gui/chat.h"
+#include "gui/partywindow.h"
#include "net/messagein.h"
-#include "gui/chat.h"
-#include "gui/partywindow.h"
+#include "net/ea/party.h"
+#include "net/ea/protocol.h"
+#include "net/ea/gui/partytab.h"
-#include "beingmanager.h"
-#include "party.h"
+#include "utils/gettext.h"
+#include "utils/strprintf.h"
PartyTab *partyTab;
@@ -46,7 +48,7 @@ PartyHandler::PartyHandler()
SMSG_PARTY_INVITE_RESPONSE,
SMSG_PARTY_INVITED,
SMSG_PARTY_SETTINGS,
- SMSG_PARTY_MEMBER_INFO,
+ SMSG_PARTY_MOVE,
SMSG_PARTY_LEAVE,
SMSG_PARTY_UPDATE_HP,
SMSG_PARTY_UPDATE_COORDS,
@@ -55,12 +57,12 @@ PartyHandler::PartyHandler()
};
handledMessages = _messages;
- newPartyTab();
+ //newPartyTab();
}
PartyHandler::~PartyHandler()
{
- deletePartyTab();
+ //deletePartyTab();
}
void PartyHandler::handleMessage(MessageIn &msg)
@@ -71,12 +73,45 @@ void PartyHandler::handleMessage(MessageIn &msg)
eAthena::Party::createResponse(msg.readInt8());
break;
case SMSG_PARTY_INFO:
+ {
+ int length = msg.readInt16();
+ std::string party = msg.readString(24);
+ int count = (length - 28) / 46;
+
+ for (int i = 0; i < count; i++)
+ {
+ int id = msg.readInt32();
+ std::string nick = msg.readString(24);
+ std::string map = msg.readString(16);
+ bool leader = msg.readInt8() == 0;
+ bool online = msg.readInt8() == 0;
+
+ partyWindow->updateMember(id, nick, leader, online);
+ }
+ }
break;
case SMSG_PARTY_INVITE_RESPONSE:
{
std::string nick = msg.readString(24);
- int status = msg.readInt8();
- eAthena::Party::inviteResponse(nick, status);
+ switch (msg.readInt8())
+ {
+ case 0:
+ partyTab->chatLog(strprintf(_("%s is already a member of a party."),
+ nick.c_str()), BY_SERVER);
+ break;
+ case 1:
+ partyTab->chatLog(strprintf(_("%s refused your invitation."),
+ nick.c_str()), BY_SERVER);
+ break;
+ case 2:
+ partyTab->chatLog(strprintf(_("%s is now a member of your party."),
+ nick.c_str()), BY_SERVER);
+ break;
+ default:
+ partyTab->chatLog(strprintf(_("Unknown invite response for %s."),
+ nick.c_str()), BY_SERVER);
+ break;
+ }
break;
}
case SMSG_PARTY_INVITED:
@@ -104,32 +139,65 @@ void PartyHandler::handleMessage(MessageIn &msg)
break;
}
case SMSG_PARTY_SETTINGS:
+ // I don't see this in eAthena's source
+ printf("Party settings!\n");
break;
- case SMSG_PARTY_MEMBER_INFO:
+ case SMSG_PARTY_MOVE:
+ {
+ int id = msg.readInt32();
+ msg.skip(4);
+ int x = msg.readInt16();
+ int y = msg.readInt16();
+ bool online = msg.readInt8() == 0;
+ std::string party = msg.readString(24);
+ std::string nick = msg.readString(24);
+ std::string map = msg.readString(16);
+ }
break;
case SMSG_PARTY_LEAVE:
{
- /*int id = */msg.readInt32();
+ int id = msg.readInt32();
std::string nick = msg.readString(24);
- /*int fail = */msg.readInt8();
- eAthena::Party::leftResponse(nick);
+ int fail = msg.readInt8();
+ partyTab->chatLog(strprintf(_("%s has left your party."),
+ nick.c_str()), BY_SERVER);
+ partyWindow->removeMember(id);
break;
}
case SMSG_PARTY_UPDATE_HP:
+ {
+ int id = msg.readInt32();
+ int hp = msg.readInt16();
+ int hpMax = msg.readInt16();
+ }
break;
case SMSG_PARTY_UPDATE_COORDS:
+ {
+ int id = msg.readInt32();
+ int x = msg.readInt16();
+ int y = msg.readInt16();
+ }
break;
case SMSG_PARTY_MESSAGE:
- { // new block to enable local variables
+ {
int msgLength = msg.readInt16() - 8;
if (msgLength <= 0)
{
return;
}
int id = msg.readInt32();
- Being *being = beingManager->findBeing(id);
std::string chatMsg = msg.readString(msgLength);
- eAthena::Party::receiveChat(being, chatMsg);
+
+ Being *being = beingManager->findBeing(id);
+ if (being)
+ being->setSpeech(chatMsg, SPEECH_TIME);
+
+ PartyMember *member = partyWindow->findMember(id);
+ if (member)
+ partyTab->chatLog(member->name, chatMsg);
+ else
+ partyTab->chatLog(strprintf(_("An unknown member tried to "
+ "say: %s"), chatMsg.c_str()), BY_SERVER);
}
break;
}
diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h
index ff13cce9..8a4d6135 100644
--- a/src/net/ea/protocol.h
+++ b/src/net/ea/protocol.h
@@ -104,7 +104,7 @@ static const int STORAGE_OFFSET = 1;
#define SMSG_PARTY_INVITE_RESPONSE 0x00fd
#define SMSG_PARTY_INVITED 0x00fe
#define SMSG_PARTY_SETTINGS 0x0102
-#define SMSG_PARTY_MEMBER_INFO 0x0104
+#define SMSG_PARTY_MOVE 0x0104
#define SMSG_PARTY_LEAVE 0x0105
#define SMSG_PARTY_UPDATE_HP 0x0106
#define SMSG_PARTY_UPDATE_COORDS 0x0107
diff --git a/src/net/tmwserv/partyhandler.cpp b/src/net/tmwserv/partyhandler.cpp
index 510eb77a..08e58667 100644
--- a/src/net/tmwserv/partyhandler.cpp
+++ b/src/net/tmwserv/partyhandler.cpp
@@ -87,7 +87,7 @@ void PartyHandler::handleMessage(MessageIn &msg)
case CPMSG_PARTY_NEW_MEMBER:
{
- msg.readInt16(); // being id
+ int id = msg.readInt16(); // being id
std::string name = msg.readString();
localChatTab->chatLog(name + " joined the party");
@@ -95,12 +95,12 @@ void PartyHandler::handleMessage(MessageIn &msg)
if (!player_node->getInParty())
player_node->setInParty(true);
- partyWindow->addPartyMember(name);
+ partyWindow->updateMember(id, name);
} break;
case CPMSG_PARTY_MEMBER_LEFT:
{
- partyWindow->removePartyMember(msg.readString());
+ partyWindow->removeMember(msg.readString());
} break;
}
}