summaryrefslogtreecommitdiff
path: root/src/net/ea
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/ea')
-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
5 files changed, 164 insertions, 154 deletions
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