diff options
author | David Athay <ko2fan@gmail.com> | 2008-07-07 14:07:11 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2008-07-07 14:07:11 +0000 |
commit | 833586f7e321443f86d4b857e762786a3ece440a (patch) | |
tree | 88fe682c734063fefdafc3852501f94813700165 | |
parent | 6d073b16ac9cfaf431baa6ddef7554fa65a99d4e (diff) | |
download | manaserv-833586f7e321443f86d4b857e762786a3ece440a.tar.gz manaserv-833586f7e321443f86d4b857e762786a3ece440a.tar.bz2 manaserv-833586f7e321443f86d4b857e762786a3ece440a.tar.xz manaserv-833586f7e321443f86d4b857e762786a3ece440a.zip |
Added party support between account and game servers.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/account-server/serverhandler.cpp | 222 | ||||
-rw-r--r-- | src/account-server/serverhandler.hpp | 5 | ||||
-rw-r--r-- | src/chat-server/chathandler.cpp | 26 | ||||
-rw-r--r-- | src/chat-server/party.cpp | 3 | ||||
-rw-r--r-- | src/chat-server/party.hpp | 6 |
6 files changed, 50 insertions, 219 deletions
@@ -1,3 +1,10 @@ +2008-07-07 David Athay <ko2fan@gmail.com> + + * src/account-server/serverhandler.cpp, + src/account-server/serverhandler.hpp, src/chat-server/party.cpp, + src/chat-server/party.hpp, src/chat-server/chathandler.cpp: Added party + support between account and game servers. + 2008-07-03 Roderic Morris <roderic@ccs.neu.edu> * src/game-server/character.cpp, src/game-server/gamehandler.cpp: diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 14a9efc1..7fc81100 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -324,170 +324,6 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) } } break; -#if 0 - case GAMSG_GUILD_CREATE: - { - LOG_DEBUG("GAMSG_GUILD_CREATE"); - - result.writeShort(AGMSG_GUILD_CREATE_RESPONSE); - // Check if the guild name is taken already - int playerId = msg.readLong(); - std::string guildName = msg.readString(); - if (guildManager->findByName(guildName) != NULL) - { - result.writeByte(ERRMSG_ALREADY_TAKEN); - break; - } - result.writeByte(ERRMSG_OK); - - Storage &store = Storage::instance("tmw"); - CharacterPtr ptr = store.getCharacter(playerId); - - // Add guild to character data. - ptr->addGuild(guildName); - - // Who to send data to at the other end - result.writeLong(playerId); - - short guildId = guildManager->createGuild(guildName, ptr.get()); - result.writeShort(guildId); - result.writeString(guildName); - result.writeShort(1); - enterChannel(guildName, ptr.get()); - } break; - - case GAMSG_GUILD_INVITE: - { - // Add Inviting member to guild here - LOG_DEBUG("Received msg ... GAMSG_GUILD_INVITE"); - result.writeShort(AGMSG_GUILD_INVITE_RESPONSE); - // Check if user can invite users - int playerId = msg.readLong(); - short id = msg.readShort(); - std::string member = msg.readString(); - Guild *guild = guildManager->findById(id); - - Storage &store = Storage::instance("tmw"); - CharacterPtr ptr = store.getCharacter(playerId); - - if (!guild->checkLeader(ptr.get())) - { - // Return that the user doesnt have the rights to invite. - result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS); - break; - } - - if (guild->checkInGuild(member)) - { - // Return that invited member already in guild. - result.writeByte(ERRMSG_ALREADY_TAKEN); - break; - } - - // Send invite to player using chat server - if (store.doesCharacterNameExist(member)) - { - sendInvite(member, ptr->getName(), guild->getName()); - } - - guild->addInvited(member); - result.writeByte(ERRMSG_OK); - } break; - - case GAMSG_GUILD_ACCEPT: - { - // Add accepting into guild - LOG_DEBUG("Received msg ... GAMSG_GUILD_ACCEPT"); - result.writeShort(AGMSG_GUILD_ACCEPT_RESPONSE); - int playerId = msg.readLong(); - std::string guildName = msg.readString(); - Guild *guild = guildManager->findByName(guildName); - if (!guild) - { - // Return the guild does not exist. - result.writeByte(ERRMSG_INVALID_ARGUMENT); - break; - } - - Storage &store = Storage::instance("tmw"); - CharacterPtr ptr = store.getCharacter(playerId); - - if (!guild->checkInvited(ptr->getName())) - { - // Return the user was not invited. - result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS); - break; - } - - if (guild->checkInGuild(ptr->getName())) - { - // Return that the player is already in the guild. - result.writeByte(ERRMSG_ALREADY_TAKEN); - break; - } - - result.writeByte(ERRMSG_OK); - - // Who to send data to at the other end - result.writeLong(playerId); - - // The guild id and guild name they have joined - result.writeShort(guild->getId()); - result.writeString(guildName); - - // Add member to guild - guildManager->addGuildMember(guild->getId(), ptr.get()); - - // Add guild to character - ptr->addGuild(guildName); - - // Enter Guild Channel - enterChannel(guildName, ptr.get()); - } break; - - case GAMSG_GUILD_GET_MEMBERS: - { - LOG_DEBUG("Received msg ... GAMSG_GUILD_GET_MEMBERS"); - result.writeShort(AGMSG_GUILD_GET_MEMBERS_RESPONSE); - int playerId = msg.readLong(); - short guildId = msg.readShort(); - Guild *guild = guildManager->findById(guildId); - if (!guild) - { - result.writeByte(ERRMSG_INVALID_ARGUMENT); - break; - } - result.writeByte(ERRMSG_OK); - result.writeLong(playerId); - result.writeShort(guildId); - for (std::list<std::string>::const_iterater itr = guild->getMembers()->begin(); - itr != guild->getMembers()->end(); ++itr) - { - result.writeString((*itr)); - } - } break; - - case GAMSG_GUILD_QUIT: - { - LOG_DEBUG("Received msg ... GAMSG_GUILD_QUIT"); - result.writeShort(AGMSG_GUILD_QUIT_RESPONSE); - int playerId = msg.readLong(); - short guildId = msg.readShort(); - Guild *guild = guildManager->findById(guildId); - if (!guild) - { - result.writeByte(ERRMSG_INVALID_ARGUMENT); - break; - } - Storage &store = Storage::instance("tmw"); - CharacterPtr ptr = store.getCharacter(playerId); - guildManager->removeGuildMember(guildId, ptr.get()); - result.writeByte(ERRMSG_OK); - result.writeLong(playerId); - result.writeShort(guildId); - } break; -#endif - default: LOG_WARN("ServerHandler::processMessage, Invalid message type: " << msg.getId()); @@ -528,58 +364,14 @@ void GameServerHandler::dumpStatistics(std::ostream &os) } } -#if 0 -void ServerHandler::enterChannel(const std::string &name, - CharacterData *player) +void GameServerHandler::sendPartyChange(Character *ptr, int partyId) { - MessageOut result(CPMSG_ENTER_CHANNEL_RESPONSE); - - short channelId = chatChannelManager->getChannelId(name); - ChatChannel *channel = chatChannelManager->getChannel(channelId); - - if (!channel) - { - // Channel doesn't exist yet so create one - channelId = chatChannelManager->registerPrivateChannel(name, - "Guild Channel", - ""); - channel = chatChannelManager->getChannel(channelId); - } - - if (channel && channel->addUser(player->getName())) + GameServer *s = ::getGameServerFromMap(ptr->getMapId()); + if (s) { - result.writeByte(ERRMSG_OK); - - // The user entered the channel, now give him the channel id, the - // announcement string and the user list. - result.writeShort(channelId); - result.writeString(name); - result.writeString(channel->getAnnouncement()); - const ChatChannel::ChannelUsers &userList = channel->getUserList(); - - for (ChatChannel::ChannelUsers::const_iterator i = userList.begin(), - i_end = userList.end(); - i != i_end; ++i) - { - result.writeString(*i); - } - - // Send an CPMSG_UPDATE_CHANNEL to warn other clients a user went - // in the channel. - chatHandler->warnUsersAboutPlayerEventInChat(channel, - player->getName(), - CHAT_EVENT_NEW_PLAYER); - + MessageOut msg(CGMSG_CHANGED_PARTY); + msg.writeLong(ptr->getDatabaseID()); + msg.writeLong(partyId); + s->send(msg); } - - chatHandler->sendGuildEnterChannel(result, player->getName()); -} - -void ServerHandler::sendInvite(const std::string &invitedName, - const std::string &inviterName, - const std::string &guildName) -{ - // TODO: Separate account and chat server - chatHandler->sendGuildInvite(invitedName, inviterName, guildName); } -#endif diff --git a/src/account-server/serverhandler.hpp b/src/account-server/serverhandler.hpp index e5309cff..856387d8 100644 --- a/src/account-server/serverhandler.hpp +++ b/src/account-server/serverhandler.hpp @@ -61,6 +61,11 @@ namespace GameServerHandler * Processes messages received by the connection handler. */ void process(); + + /** + * Sends chat party information + */ + void sendPartyChange(Character *ptr, int partyId); } #endif diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp index 2523445c..189fbe57 100644 --- a/src/chat-server/chathandler.cpp +++ b/src/chat-server/chathandler.cpp @@ -25,6 +25,8 @@ #include <algorithm> #include "defines.h" +#include "account-server/dalstorage.hpp" +#include "account-server/serverhandler.hpp" #include "chat-server/guild.hpp" #include "chat-server/guildmanager.hpp" #include "chat-server/chatchannelmanager.hpp" @@ -49,6 +51,12 @@ void registerChatClient(const std::string &token, chatHandler->mTokenCollector.addPendingConnect(token, p); } +void updateInfo(ChatClient *client, int partyId) +{ + Character *character = storage->getCharacter(client->characterName); + GameServerHandler::sendPartyChange(character, partyId); +} + ChatHandler::ChatHandler(): mTokenCollector(this) { @@ -340,7 +348,7 @@ ChatHandler::handleRegisterChannelMessage(ChatClient &client, MessageIn &msg) { reply.writeByte(ERRMSG_INVALID_ARGUMENT); } - else if (guildManager->doesExist(channelName) || + else if (guildManager->doesExist(channelName) || chatChannelManager->channelExists(channelName)) { // Channel already exists @@ -516,7 +524,7 @@ ChatHandler::handleTopicChange(ChatClient &client, MessageIn &msg) short channelId = msg.readShort(); std::string topic = msg.readString(); ChatChannel *channel = chatChannelManager->getChannel(channelId); - + if(!guildManager->doesExist(channel->getName())) { chatChannelManager->setChannelTopic(channelId, topic); @@ -670,7 +678,7 @@ ChatHandler::handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg) { reply.writeByte(ERRMSG_OK); reply.writeShort(guildId); - for(std::list<std::string>::const_iterator itr = guild->getMembers()->begin(); + for(std::list<std::string>::const_iterator itr = guild->getMembers()->begin(); itr != guild->getMembers()->end(); ++itr) { reply.writeString((*itr)); @@ -863,7 +871,7 @@ void ChatHandler::sendGuildListUpdate(const std::string &guildName, std::map<std::string, ChatClient*>::const_iterator chr; std::list<std::string> *members = guild->getMembers(); - for (std::list<std::string>::const_iterator itr = members->begin(); + for (std::list<std::string>::const_iterator itr = members->begin(); itr != members->end(); ++itr) { chr = mPlayerMap.find((*itr)); @@ -887,6 +895,8 @@ bool ChatHandler::handlePartyJoin(const std::string &invited, const std::string if (!c1->party) { c1->party = new Party(); + // tell game server to update info + updateInfo(c1, c1->party->getId()); } // add inviter to the party @@ -903,6 +913,9 @@ bool ChatHandler::handlePartyJoin(const std::string &invited, const std::string out.writeString(invited); out.writeByte(ERRMSG_OK); c1->send(out); + + // tell game server to update info + updateInfo(c2, c2->party->getId()); return true; } } @@ -958,6 +971,7 @@ void ChatHandler::handlePartyAcceptInvite(ChatClient &client, MessageIn &msg) { out.writeByte(ERRMSG_FAILURE); } + client.send(out); } @@ -967,6 +981,9 @@ void ChatHandler::handlePartyQuit(ChatClient &client) MessageOut out(CPMSG_PARTY_QUIT_RESPONSE); out.writeByte(ERRMSG_OK); client.send(out); + + // tell game server to update info + updateInfo(&client, 0); } void ChatHandler::removeUserFromParty(ChatClient &client) @@ -974,6 +991,7 @@ void ChatHandler::removeUserFromParty(ChatClient &client) if (client.party) { client.party->removeUser(client.characterName); + // if theres less than 1 member left, remove the party if (client.party->numUsers() < 1) { delete client.party; diff --git a/src/chat-server/party.cpp b/src/chat-server/party.cpp index f9c9b174..ff756881 100644 --- a/src/chat-server/party.cpp +++ b/src/chat-server/party.cpp @@ -27,6 +27,9 @@ Party::Party() { + static int id = 0; + id++; + mId = id; } void Party::addUser(const std::string &name) diff --git a/src/chat-server/party.hpp b/src/chat-server/party.hpp index e865f1ce..7d912abf 100644 --- a/src/chat-server/party.hpp +++ b/src/chat-server/party.hpp @@ -53,8 +53,14 @@ public: */ unsigned int numUsers() { return mUsers.size(); } + /** + * Return the party id + */ + unsigned int getId() { return mId; } + private: PartyUsers mUsers; + unsigned int mId; }; #endif |