diff options
author | David Athay <ko2fan@gmail.com> | 2007-06-26 19:50:02 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2007-06-26 19:50:02 +0000 |
commit | 301ffe1048fb23548f72759b6ed0ca98e9109ff4 (patch) | |
tree | c765b6df9a83227b1d40bb59949b768fbc4c1574 /src/game-server | |
parent | 99263173738dfd6ca4ba822e0a112f1c7c17661c (diff) | |
download | manaserv-301ffe1048fb23548f72759b6ed0ca98e9109ff4.tar.gz manaserv-301ffe1048fb23548f72759b6ed0ca98e9109ff4.tar.bz2 manaserv-301ffe1048fb23548f72759b6ed0ca98e9109ff4.tar.xz manaserv-301ffe1048fb23548f72759b6ed0ca98e9109ff4.zip |
Merged guilds-and-parties branch to trunk
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/accountconnection.cpp | 162 | ||||
-rw-r--r-- | src/game-server/accountconnection.hpp | 24 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 42 | ||||
-rw-r--r-- | src/game-server/gamehandler.hpp | 6 | ||||
-rw-r--r-- | src/game-server/mapmanager.cpp | 5 | ||||
-rw-r--r-- | src/game-server/mapmanager.hpp | 5 |
6 files changed, 244 insertions, 0 deletions
diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index e54605ff..e9ea2256 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -25,8 +25,11 @@ #include "defines.h" #include "game-server/accountconnection.hpp" #include "game-server/gamehandler.hpp" +#include "game-server/map.hpp" +#include "game-server/mapcomposite.hpp" #include "game-server/mapmanager.hpp" #include "game-server/character.hpp" +#include "game-server/state.hpp" #include "net/messagein.hpp" #include "net/messageout.hpp" #include "utils/logger.h" @@ -86,6 +89,119 @@ void AccountConnection::processMessage(MessageIn &msg) int port = msg.readShort(); gameHandler->completeServerChange(id, token, address, port); } break; + + case AGMSG_GUILD_CREATE_RESPONSE: + { + if(msg.readByte() == ERRMSG_OK) + { + int playerId = msg.readLong(); + + MessageOut result(GPMSG_GUILD_CREATE_RESPONSE); + result.writeByte(ERRMSG_OK); + + /* Create a message that the player has joined the guild + * Output the guild ID and guild name + * Send a 1 if the player has rights + * to invite users, otherwise 0. + */ + MessageOut out(GPMSG_GUILD_JOINED); + out.writeShort(msg.readShort()); + out.writeString(msg.readString()); + out.writeShort(msg.readShort()); + + Character *player = gameHandler->messageMap[playerId]; + if(player) + { + gameHandler->sendTo(player, result); + gameHandler->sendTo(player, out); + } + } + } break; + + case AGMSG_GUILD_INVITE_RESPONSE: + { + if(msg.readByte() == ERRMSG_OK) + { + int playerId = msg.readLong(); + + MessageOut result(GPMSG_GUILD_INVITE_RESPONSE); + result.writeByte(ERRMSG_OK); + + Character *player = gameHandler->messageMap[playerId]; + if(player) + { + gameHandler->sendTo(player, result); + } + } + } break; + + case AGMSG_GUILD_ACCEPT_RESPONSE: + { + if(msg.readByte() == ERRMSG_OK) + { + int playerId = msg.readLong(); + + MessageOut result(GPMSG_GUILD_ACCEPT_RESPONSE); + result.writeByte(ERRMSG_OK); + + /* Create a message that the player has joined the guild + * Output the guild ID and guild name + * Send a 0 for invite rights, since player has been invited + * they wont have any rights to invite other users yet. + */ + MessageOut out(GPMSG_GUILD_JOINED); + out.writeShort(msg.readShort()); + out.writeString(msg.readString()); + out.writeShort(0); + + Character *player = gameHandler->messageMap[playerId]; + if(player) + { + gameHandler->sendTo(player, result); + gameHandler->sendTo(player, out); + } + } + } break; + + case AGMSG_GUILD_GET_MEMBERS_RESPONSE: + { + if(msg.readByte() != ERRMSG_OK) + break; + int playerId = msg.readLong(); + short guildId = msg.readShort(); + + MessageOut result(GPMSG_GUILD_GET_MEMBERS_RESPONSE); + result.writeByte(ERRMSG_OK); + result.writeShort(guildId); + while(msg.getUnreadLength()) + { + result.writeString(msg.readString()); + } + + Character *player = gameHandler->messageMap[playerId]; + if(player) + { + gameHandler->sendTo(player, result); + } + } break; + + case AGMSG_GUILD_QUIT_RESPONSE: + { + if(msg.readByte() != ERRMSG_OK) + break; + int playerId = msg.readLong(); + short guildId = msg.readShort(); + + MessageOut result(GPMSG_GUILD_QUIT_RESPONSE); + result.writeByte(ERRMSG_OK); + result.writeShort(guildId); + + Character *player = gameHandler->messageMap[playerId]; + if(player) + { + gameHandler->sendTo(player, result); + } + } break; default: LOG_WARN("Invalid message type"); @@ -101,3 +217,49 @@ void AccountConnection::playerReconnectAccount(int id, const std::string magic_t msg.writeString(magic_token, MAGIC_TOKEN_LENGTH); send(msg); } + +void AccountConnection::playerCreateGuild(int id, const std::string &guildName) +{ + LOG_INFO("Send GAMSG_GUILD_CREATE"); + MessageOut msg(GAMSG_GUILD_CREATE); + msg.writeLong(id); + msg.writeString(guildName); + send(msg); +} + +void AccountConnection::playerInviteToGuild(int id, short guildId, const std::string &member) +{ + LOG_INFO("Send GAMSG_GUILD_INVITE"); + MessageOut msg(GAMSG_GUILD_INVITE); + msg.writeLong(id); + msg.writeShort(guildId); + msg.writeString(member); + send(msg); +} + +void AccountConnection::playerAcceptInvite(int id, const std::string &guildName) +{ + LOG_INFO("Send GAMSG_GUILD_ACCEPT"); + MessageOut msg(GAMSG_GUILD_ACCEPT); + msg.writeLong(id); + msg.writeString(guildName); + send(msg); +} + +void AccountConnection::getGuildMembers(int id, short guildId) +{ + LOG_INFO("Send GAMSG_GUILD_GET_MEMBERS"); + MessageOut msg(GAMSG_GUILD_GET_MEMBERS); + msg.writeLong(id); + msg.writeShort(guildId); + send(msg); +} + +void AccountConnection::quitGuild(int id, short guildId) +{ + LOG_INFO("Send GAMSG_GUILD_QUIT"); + MessageOut msg(GAMSG_GUILD_QUIT); + msg.writeLong(id); + msg.writeShort(guildId); + send(msg); +} diff --git a/src/game-server/accountconnection.hpp b/src/game-server/accountconnection.hpp index 24ee1598..700a85ca 100644 --- a/src/game-server/accountconnection.hpp +++ b/src/game-server/accountconnection.hpp @@ -50,6 +50,30 @@ class AccountConnection: public Connection */ void playerReconnectAccount(int id, const std::string magic_token); + /** + * Sends create guild message + */ + void playerCreateGuild(int id, const std::string &guildName); + + /** + * Sends invite message + */ + void playerInviteToGuild(int id, short guildId, const std::string &name); + + /** + * Sends accept message + */ + void playerAcceptInvite(int id, const std::string &name); + + /** + * Sends get guild members message. + */ + void getGuildMembers(int id, short guildId); + + /** + * Sends quit guild message. + */ + void quitGuild(int id, short guildId); protected: /** diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index 81f7a1e5..1ca4f756 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -258,6 +258,48 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) computer.character = NULL; computer.status = CLIENT_LOGIN; } break; + + case PGMSG_GUILD_CREATE: + { + std::string name = message.readString(); + int characterId = computer.character->getDatabaseID(); + messageMap[characterId] = computer.character; + accountHandler->playerCreateGuild(characterId, name); + } break; + + case PGMSG_GUILD_INVITE: + { + short guildId = message.readShort(); + std::string member = message.readString(); + int characterId = computer.character->getDatabaseID(); + messageMap[characterId] = computer.character; + accountHandler->playerInviteToGuild(characterId, guildId, member); + } break; + + case PGMSG_GUILD_ACCEPT: + { + std::string guildName = message.readString(); + int characterId = computer.character->getDatabaseID(); + messageMap[characterId] = computer.character; + accountHandler->playerAcceptInvite(characterId, guildName); + } break; + + case PGMSG_GUILD_GET_MEMBERS: + { + short guildId = message.readShort(); + int characterId = computer.character->getDatabaseID(); + messageMap[characterId] = computer.character; + accountHandler->getGuildMembers(characterId, guildId); + } break; + + case PGMSG_GUILD_QUIT: + { + short guildId = message.readShort(); + int characterId = computer.character->getDatabaseID(); + messageMap[characterId] = computer.character; + accountHandler->quitGuild(characterId, guildId); + } break; + default: LOG_WARN("Invalid message type"); result.writeShort(XXMSG_INVALID); diff --git a/src/game-server/gamehandler.hpp b/src/game-server/gamehandler.hpp index 1e39e750..85a38674 100644 --- a/src/game-server/gamehandler.hpp +++ b/src/game-server/gamehandler.hpp @@ -85,6 +85,12 @@ class GameHandler: public ConnectionHandler */ void completeServerChange(int id, std::string const &token, std::string const &address, int port); + + /** + * Map of character's and their id used for getting which character to + * forward account server messages back to. + */ + std::map<int, Character*> messageMap; /** * Combines a client with it's character. diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp index dcb91363..dac57cac 100644 --- a/src/game-server/mapmanager.cpp +++ b/src/game-server/mapmanager.cpp @@ -130,3 +130,8 @@ bool MapManager::isActive(int mapId) const assert(i != maps.end()); return i->second.isActive; } + +short MapManager::numberOfMaps() const +{ + return maps.size(); +} diff --git a/src/game-server/mapmanager.hpp b/src/game-server/mapmanager.hpp index 1ba7c8c7..8693dbfe 100644 --- a/src/game-server/mapmanager.hpp +++ b/src/game-server/mapmanager.hpp @@ -73,6 +73,11 @@ class MapManager * Gets the activity status of the map. */ bool isActive(int) const; + + /** + * Gets the number of maps + */ + short numberOfMaps() const; /** * Destructor. |