diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/account-server/accounthandler.cpp | 166 | ||||
-rw-r--r-- | src/account-server/serverhandler.cpp | 116 | ||||
-rw-r--r-- | src/chat-server/chathandler.cpp | 65 | ||||
-rw-r--r-- | src/chat-server/guildhandler.cpp | 78 | ||||
-rw-r--r-- | src/chat-server/partyhandler.cpp | 14 | ||||
-rw-r--r-- | src/game-server/accountconnection.cpp | 94 | ||||
-rw-r--r-- | src/game-server/buysell.cpp | 8 | ||||
-rw-r--r-- | src/game-server/character.cpp | 30 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 86 | ||||
-rw-r--r-- | src/game-server/inventory.cpp | 96 | ||||
-rw-r--r-- | src/game-server/state.cpp | 112 | ||||
-rw-r--r-- | src/game-server/trade.cpp | 8 | ||||
-rw-r--r-- | src/net/messagein.cpp | 12 | ||||
-rw-r--r-- | src/net/messagein.hpp | 7 | ||||
-rw-r--r-- | src/net/messageout.cpp | 12 | ||||
-rw-r--r-- | src/net/messageout.hpp | 6 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 18 | ||||
-rw-r--r-- | src/serialize/characterdata.hpp | 120 |
18 files changed, 523 insertions, 525 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 7c17102a..8fa0576c 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -267,14 +267,14 @@ void AccountHandler::sendCharacterData(AccountClient &client, int slot, const Character &ch) { MessageOut charInfo(APMSG_CHAR_INFO); - charInfo.writeByte(slot); + charInfo.writeInt8(slot); charInfo.writeString(ch.getName()); - charInfo.writeByte(ch.getGender()); - charInfo.writeByte(ch.getHairStyle()); - charInfo.writeByte(ch.getHairColor()); - charInfo.writeShort(ch.getLevel()); - charInfo.writeShort(ch.getCharacterPoints()); - charInfo.writeShort(ch.getCorrectionPoints()); + charInfo.writeInt8(ch.getGender()); + charInfo.writeInt8(ch.getHairStyle()); + charInfo.writeInt8(ch.getHairColor()); + charInfo.writeInt16(ch.getLevel()); + charInfo.writeInt16(ch.getCharacterPoints()); + charInfo.writeInt16(ch.getCorrectionPoints()); for (AttributeMap::const_iterator it = ch.mAttributes.begin(), it_end = ch.mAttributes.end(); @@ -282,9 +282,9 @@ void AccountHandler::sendCharacterData(AccountClient &client, int slot, ++it) { // {id, base value in 256ths, modified value in 256ths }* - charInfo.writeLong(it->first); - charInfo.writeLong((int) (it->second.first * 256)); - charInfo.writeLong((int) (it->second.second * 256)); + charInfo.writeInt32(it->first); + charInfo.writeInt32((int) (it->second.first * 256)); + charInfo.writeInt32((int) (it->second.second * 256)); } client.send(charInfo); @@ -296,16 +296,16 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) if (client.status != CLIENT_LOGIN) { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); client.send(reply); return; } - const int clientVersion = msg.readLong(); + const int clientVersion = msg.readInt32(); if (clientVersion < Configuration::getValue("net_clientVersion", 0)) { - reply.writeByte(LOGIN_INVALID_VERSION); + reply.writeInt8(LOGIN_INVALID_VERSION); client.send(reply); return; } @@ -319,7 +319,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) const time_t lastAttempt = it->second; if (now < lastAttempt + 1) { - reply.writeByte(LOGIN_INVALID_TIME); + reply.writeInt8(LOGIN_INVALID_TIME); client.send(reply); return; } @@ -331,7 +331,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) if (stringFilter->findDoubleQuotes(username)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); client.send(reply); return; } @@ -341,7 +341,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) if (getClientCount() >= maxClients) { - reply.writeByte(ERRMSG_SERVER_FULL); + reply.writeInt8(ERRMSG_SERVER_FULL); client.send(reply); return; } @@ -351,7 +351,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) if (!acc || acc->getPassword() != sha256(password)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); client.send(reply); delete acc; return; @@ -359,7 +359,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) if (acc->getLevel() == AL_BANNED) { - reply.writeByte(LOGIN_BANNED); + reply.writeInt8(LOGIN_BANNED); client.send(reply); delete acc; return; @@ -377,7 +377,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) client.setAccount(acc); client.status = CLIENT_CONNECTED; - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); addUpdateHost(&reply); client.send(reply); // Acknowledge login @@ -397,20 +397,20 @@ void AccountHandler::handleLogoutMessage(AccountClient &client) if (client.status == CLIENT_LOGIN) { - reply.writeByte(ERRMSG_NO_LOGIN); + reply.writeInt8(ERRMSG_NO_LOGIN); } else if (client.status == CLIENT_CONNECTED) { client.unsetAccount(); client.status = CLIENT_LOGIN; - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); } else if (client.status == CLIENT_QUEUED) { // Delete it from the pendingClient list mTokenCollector.deletePendingClient(&client); client.status = CLIENT_LOGIN; - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); } client.send(reply); } @@ -439,7 +439,7 @@ bool checkCaptcha(AccountClient &client, std::string captcha) void AccountHandler::handleRegisterMessage(AccountClient &client, MessageIn &msg) { - int clientVersion = msg.readLong(); + int clientVersion = msg.readInt32(); std::string username = msg.readString(); std::string password = msg.readString(); std::string email = msg.readString(); @@ -452,55 +452,55 @@ void AccountHandler::handleRegisterMessage(AccountClient &client, if (client.status != CLIENT_LOGIN) { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } else if (!Configuration::getBoolValue("account_allowRegister", true)) { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } else if (clientVersion < minClientVersion) { - reply.writeByte(REGISTER_INVALID_VERSION); + reply.writeInt8(REGISTER_INVALID_VERSION); } else if (stringFilter->findDoubleQuotes(username)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (stringFilter->findDoubleQuotes(email)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (username.length() < minNameLength || username.length() > maxNameLength) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (stringFilter->findDoubleQuotes(password)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (!stringFilter->isEmailValid(email)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } // Checking if the Name is slang's free. else if (!stringFilter->filterContent(username)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } // Check whether the account already exists. else if (storage->doesUserNameExist(username)) { - reply.writeByte(REGISTER_EXISTS_USERNAME); + reply.writeInt8(REGISTER_EXISTS_USERNAME); } // Find out whether the email is already in use. else if (storage->doesEmailAddressExist(sha256(email))) { - reply.writeByte(REGISTER_EXISTS_EMAIL); + reply.writeInt8(REGISTER_EXISTS_EMAIL); } else if (!checkCaptcha(client, captcha)) { - reply.writeByte(REGISTER_CAPTCHA_WRONG); + reply.writeInt8(REGISTER_CAPTCHA_WRONG); } else { @@ -520,7 +520,7 @@ void AccountHandler::handleRegisterMessage(AccountClient &client, acc->setLastLogin(regdate); storage->addAccount(acc); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); addUpdateHost(&reply); // Associate account with connection @@ -542,14 +542,14 @@ void AccountHandler::handleUnregisterMessage(AccountClient &client, if (client.status != CLIENT_CONNECTED) { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); client.send(reply); return; } if (stringFilter->findDoubleQuotes(username)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); client.send(reply); return; } @@ -559,7 +559,7 @@ void AccountHandler::handleUnregisterMessage(AccountClient &client, if (!acc || acc->getPassword() != password) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); client.send(reply); delete acc; return; @@ -569,7 +569,7 @@ void AccountHandler::handleUnregisterMessage(AccountClient &client, LOG_INFO("Unregistered \"" << username << "\", AccountID: " << acc->getID()); storage->delAccount(acc); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); client.send(reply); } @@ -581,15 +581,15 @@ void AccountHandler::handleRequestRegisterInfoMessage(AccountClient &client, MessageOut reply(APMSG_REGISTER_INFO_RESPONSE); if (!Configuration::getBoolValue("account_allowRegister", true)) { - reply.writeByte(false); + reply.writeInt8(false); reply.writeString(Configuration::getValue( "account_denyRegisterReason", "")); } else { - reply.writeByte(true); - reply.writeByte(Configuration::getValue("account_minNameLength", 4)); - reply.writeByte(Configuration::getValue("account_maxNameLength", 16)); + reply.writeInt8(true); + reply.writeInt8(Configuration::getValue("account_minNameLength", 4)); + reply.writeInt8(Configuration::getValue("account_maxNameLength", 16)); reply.writeString("http://www.server.example/captcha.png"); reply.writeString("<instructions for solving captcha>"); } @@ -604,7 +604,7 @@ void AccountHandler::handleEmailChangeMessage(AccountClient &client, Account *acc = client.getAccount(); if (!acc) { - reply.writeByte(ERRMSG_NO_LOGIN); + reply.writeInt8(ERRMSG_NO_LOGIN); client.send(reply); return; } @@ -614,22 +614,22 @@ void AccountHandler::handleEmailChangeMessage(AccountClient &client, if (!stringFilter->isEmailValid(email)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (stringFilter->findDoubleQuotes(email)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (storage->doesEmailAddressExist(emailHash)) { - reply.writeByte(ERRMSG_EMAIL_ALREADY_EXISTS); + reply.writeInt8(ERRMSG_EMAIL_ALREADY_EXISTS); } else { acc->setEmail(emailHash); // Keep the database up to date otherwise we will go out of sync storage->flush(acc); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); } client.send(reply); } @@ -645,22 +645,22 @@ void AccountHandler::handlePasswordChangeMessage(AccountClient &client, Account *acc = client.getAccount(); if (!acc) { - reply.writeByte(ERRMSG_NO_LOGIN); + reply.writeInt8(ERRMSG_NO_LOGIN); } else if (stringFilter->findDoubleQuotes(newPassword)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (oldPassword != acc->getPassword()) { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } else { acc->setPassword(newPassword); // Keep the database up to date otherwise we will go out of sync storage->flush(acc); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); } client.send(reply); @@ -670,9 +670,9 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, MessageIn &msg) { std::string name = msg.readString(); - int hairStyle = msg.readByte(); - int hairColor = msg.readByte(); - int gender = msg.readByte(); + int hairStyle = msg.readInt8(); + int hairColor = msg.readInt8(); + int gender = msg.readInt8(); int numHairStyles = Configuration::getValue("char_numHairStyles", 17); int numHairColors = Configuration::getValue("char_numHairColors", 11); int numGenders = Configuration::getValue("char_numGenders", 2); @@ -685,38 +685,38 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, Account *acc = client.getAccount(); if (!acc) { - reply.writeByte(ERRMSG_NO_LOGIN); + reply.writeInt8(ERRMSG_NO_LOGIN); } else if (!stringFilter->filterContent(name)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (stringFilter->findDoubleQuotes(name)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (hairStyle > numHairStyles) { - reply.writeByte(CREATE_INVALID_HAIRSTYLE); + reply.writeInt8(CREATE_INVALID_HAIRSTYLE); } else if (hairColor > numHairColors) { - reply.writeByte(CREATE_INVALID_HAIRCOLOR); + reply.writeInt8(CREATE_INVALID_HAIRCOLOR); } else if (gender > numGenders) { - reply.writeByte(CREATE_INVALID_GENDER); + reply.writeInt8(CREATE_INVALID_GENDER); } else if ((name.length() < minNameLength) || (name.length() > maxNameLength)) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else { if (storage->doesCharacterNameExist(name)) { - reply.writeByte(CREATE_EXISTS_NAME); + reply.writeInt8(CREATE_EXISTS_NAME); client.send(reply); return; } @@ -725,7 +725,7 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, Characters &chars = acc->getCharacters(); if (chars.size() >= maxCharacters) { - reply.writeByte(CREATE_TOO_MUCH_CHARACTERS); + reply.writeInt8(CREATE_TOO_MUCH_CHARACTERS); client.send(reply); return; } @@ -735,7 +735,7 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, // Customization of character's attributes... std::vector<int> attributes = std::vector<int>(initAttr.size(), 0); for (unsigned int i = 0; i < initAttr.size(); ++i) - attributes[i] = msg.readShort(); + attributes[i] = msg.readInt16(); int totalAttributes = 0; for (unsigned int i = 0; i < initAttr.size(); ++i) @@ -747,7 +747,7 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, if (attributes.at(i) < attributesMinimum || attributes.at(i) > attributesMaximum) { - reply.writeByte(CREATE_ATTRIBUTES_OUT_OF_RANGE); + reply.writeInt8(CREATE_ATTRIBUTES_OUT_OF_RANGE); client.send(reply); return; } @@ -755,11 +755,11 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, if (totalAttributes > startPoints) { - reply.writeByte(CREATE_ATTRIBUTES_TOO_HIGH); + reply.writeInt8(CREATE_ATTRIBUTES_TOO_HIGH); } else if (totalAttributes < startPoints) { - reply.writeByte(CREATE_ATTRIBUTES_TOO_LOW); + reply.writeInt8(CREATE_ATTRIBUTES_TOO_LOW); } else { @@ -796,7 +796,7 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, trans.mMessage.append("called " + name); storage->addTransaction(trans); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); client.send(reply); // Send new characters infos back to client @@ -817,19 +817,19 @@ void AccountHandler::handleCharacterSelectMessage(AccountClient &client, Account *acc = client.getAccount(); if (!acc) { - reply.writeByte(ERRMSG_NO_LOGIN); + reply.writeInt8(ERRMSG_NO_LOGIN); client.send(reply); return; // not logged in } - unsigned charNum = msg.readByte(); + unsigned charNum = msg.readInt8(); Characters &chars = acc->getCharacters(); // Character ID = 0 to Number of Characters - 1. if (charNum >= chars.size()) { // invalid char selection - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); client.send(reply); return; } @@ -842,24 +842,24 @@ void AccountHandler::handleCharacterSelectMessage(AccountClient &client, (selectedChar->getMapId(), address, port)) { LOG_ERROR("Character Selection: No game server for the map."); - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); client.send(reply); return; } - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); LOG_DEBUG(selectedChar->getName() << " is trying to enter the servers."); std::string magic_token(utils::getMagicToken()); reply.writeString(magic_token, MAGIC_TOKEN_LENGTH); reply.writeString(address); - reply.writeShort(port); + reply.writeInt16(port); // TODO: get correct address and port for the chat server reply.writeString(Configuration::getValue("net_accountServerAddress", "localhost")); - reply.writeShort(Configuration::getValue("net_accountServerPort", + reply.writeInt16(Configuration::getValue("net_accountServerPort", DEFAULT_SERVER_PORT) + 2); GameServerHandler::registerClient(magic_token, selectedChar); @@ -883,19 +883,19 @@ void AccountHandler::handleCharacterDeleteMessage(AccountClient &client, Account *acc = client.getAccount(); if (!acc) { - reply.writeByte(ERRMSG_NO_LOGIN); + reply.writeInt8(ERRMSG_NO_LOGIN); client.send(reply); return; // not logged in } - unsigned charNum = msg.readByte(); + unsigned charNum = msg.readInt8(); Characters &chars = acc->getCharacters(); // Character ID = 0 to Number of Characters - 1. if (charNum >= chars.size()) { // invalid char selection - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); client.send(reply); return; // not logged in } @@ -905,7 +905,7 @@ void AccountHandler::handleCharacterDeleteMessage(AccountClient &client, acc->delCharacter(charNum); storage->flush(acc); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); client.send(reply); // log transaction @@ -926,7 +926,7 @@ void AccountHandler::tokenMatched(AccountClient *client, int accountID) client->setAccount(acc); client->status = CLIENT_CONNECTED; - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); client->send(reply); // Return information about available characters @@ -942,7 +942,7 @@ void AccountHandler::tokenMatched(AccountClient *client, int accountID) void AccountHandler::deletePendingClient(AccountClient *client) { MessageOut msg(APMSG_RECONNECT_RESPONSE); - msg.writeByte(ERRMSG_TIME_OUT); + msg.writeInt8(ERRMSG_TIME_OUT); client->disconnect(msg); // The client will be deleted when the disconnect event is processed } diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index b81be075..048e65bf 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -152,7 +152,7 @@ static void registerGameClient(GameServer *s, const std::string &token, { MessageOut msg(AGMSG_PLAYER_ENTER); msg.writeString(token, MAGIC_TOKEN_LENGTH); - msg.writeLong(ptr->getDatabaseID()); + msg.writeInt32(ptr->getDatabaseID()); msg.writeString(ptr->getName()); serializeCharacterData(*ptr, msg); s->send(msg); @@ -178,11 +178,11 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) LOG_DEBUG("GAMSG_REGISTER"); // TODO: check the credentials of the game server server->address = msg.readString(); - server->port = msg.readShort(); + server->port = msg.readInt16(); const std::string password = msg.readString(); // checks the version of the remote item database with our local copy - unsigned int dbversion = msg.readLong(); + unsigned int dbversion = msg.readInt32(); LOG_INFO("Game server uses itemsdatabase with version " << dbversion); LOG_DEBUG("AGMSG_REGISTER_RESPONSE"); @@ -191,22 +191,22 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { LOG_DEBUG("Item databases between account server and " "gameserver are in sync"); - outMsg.writeShort(DATA_VERSION_OK); + outMsg.writeInt16(DATA_VERSION_OK); } else { LOG_DEBUG("Item database of game server has a wrong version"); - outMsg.writeShort(DATA_VERSION_OUTDATED); + outMsg.writeInt16(DATA_VERSION_OUTDATED); } if (password == Configuration::getValue("net_password", "changeMe")) { - outMsg.writeShort(PASSWORD_OK); + outMsg.writeInt16(PASSWORD_OK); comp->send(outMsg); } else { LOG_INFO("The password given by " << server->address << ':' << server->port << " was bad."); - outMsg.writeShort(PASSWORD_BAD); + outMsg.writeInt16(PASSWORD_BAD); comp->disconnect(outMsg); break; } @@ -217,7 +217,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) while (msg.getUnreadLength()) { - int id = msg.readShort(); + int id = msg.readInt16(); LOG_INFO("Registering map " << id << '.'); if (GameServer *s = getGameServerFromMap(id)) { @@ -227,7 +227,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) else { MessageOut outMsg(AGMSG_ACTIVE_MAP); - outMsg.writeShort(id); + outMsg.writeInt16(id); comp->send(outMsg); MapStatistics &m = server->maps[id]; m.nbThings = 0; @@ -239,7 +239,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) case GAMSG_PLAYER_DATA: { LOG_DEBUG("GAMSG_PLAYER_DATA"); - int id = msg.readLong(); + int id = msg.readInt32(); if (Character *ptr = storage->getCharacter(id, NULL)) { deserializeCharacterData(*ptr, msg); @@ -266,7 +266,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) case GAMSG_REDIRECT: { LOG_DEBUG("GAMSG_REDIRECT"); - int id = msg.readLong(); + int id = msg.readInt32(); std::string magic_token(utils::getMagicToken()); if (Character *ptr = storage->getCharacter(id, NULL)) { @@ -274,11 +274,11 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) if (GameServer *s = getGameServerFromMap(mapId)) { registerGameClient(s, magic_token, ptr); - result.writeShort(AGMSG_REDIRECT_RESPONSE); - result.writeLong(id); + result.writeInt16(AGMSG_REDIRECT_RESPONSE); + result.writeInt32(id); result.writeString(magic_token, MAGIC_TOKEN_LENGTH); result.writeString(s->address); - result.writeShort(s->port); + result.writeInt16(s->port); } else { @@ -297,7 +297,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) case GAMSG_PLAYER_RECONNECT: { LOG_DEBUG("GAMSG_PLAYER_RECONNECT"); - int id = msg.readLong(); + int id = msg.readInt32(); std::string magic_token = msg.readString(MAGIC_TOKEN_LENGTH); if (Character *ptr = storage->getCharacter(id, NULL)) @@ -315,18 +315,18 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) case GAMSG_GET_QUEST: { - int id = msg.readLong(); + int id = msg.readInt32(); std::string name = msg.readString(); std::string value = storage->getQuestVar(id, name); - result.writeShort(AGMSG_GET_QUEST_RESPONSE); - result.writeLong(id); + result.writeInt16(AGMSG_GET_QUEST_RESPONSE); + result.writeInt32(id); result.writeString(name); result.writeString(value); } break; case GAMSG_SET_QUEST: { - int id = msg.readLong(); + int id = msg.readInt32(); std::string name = msg.readString(); std::string value = msg.readString(); storage->setQuestVar(id, name, value); @@ -334,22 +334,22 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) case GAMSG_BAN_PLAYER: { - int id = msg.readLong(); - int duration = msg.readShort(); + int id = msg.readInt32(); + int duration = msg.readInt16(); storage->banCharacter(id, duration); } break; case GAMSG_CHANGE_PLAYER_LEVEL: { - int id = msg.readLong(); - int level = msg.readShort(); + int id = msg.readInt32(); + int level = msg.readInt16(); storage->setPlayerLevel(id, level); } break; case GAMSG_CHANGE_ACCOUNT_LEVEL: { - int id = msg.readLong(); - int level = msg.readShort(); + int id = msg.readInt32(); + int level = msg.readInt16(); // get the character so we can get the account id Character *c = storage->getCharacter(id, NULL); @@ -363,7 +363,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { while (msg.getUnreadLength()) { - int mapId = msg.readShort(); + int mapId = msg.readInt16(); ServerStatistics::iterator i = server->maps.find(mapId); if (i == server->maps.end()) { @@ -374,13 +374,13 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) break; } MapStatistics &m = i->second; - m.nbThings = msg.readShort(); - m.nbMonsters = msg.readShort(); - int nb = msg.readShort(); + m.nbThings = msg.readInt16(); + m.nbMonsters = msg.readInt16(); + int nb = msg.readInt16(); m.players.resize(nb); for (int j = 0; j < nb; ++j) { - m.players[j] = msg.readLong(); + m.players[j] = msg.readInt32(); } } } break; @@ -389,13 +389,13 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { // Retrieve the post for user LOG_DEBUG("GCMSG_REQUEST_POST"); - result.writeShort(CGMSG_POST_RESPONSE); + result.writeInt16(CGMSG_POST_RESPONSE); // get the character id - int characterId = msg.readLong(); + int characterId = msg.readInt32(); // send the character id of sender - result.writeLong(characterId); + result.writeInt32(characterId); // get the character based on the id Character *ptr = storage->getCharacter(characterId, NULL); @@ -422,8 +422,8 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) std::vector<InventoryItem> items = letter->getAttachments(); for (unsigned int j = 0; j < items.size(); ++j) { - result.writeShort(items[j].itemId); - result.writeShort(items[j].amount); + result.writeInt16(items[j].itemId); + result.writeInt16(items[j].amount); } } @@ -437,14 +437,14 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { // Store the letter for the user LOG_DEBUG("GCMSG_STORE_POST"); - result.writeShort(CGMSG_STORE_POST_RESPONSE); + result.writeInt16(CGMSG_STORE_POST_RESPONSE); // get the sender and receiver - int senderId = msg.readLong(); + int senderId = msg.readInt32(); std::string receiverName = msg.readString(); // for sending it back - result.writeLong(senderId); + result.writeInt32(senderId); // get their characters Character *sender = storage->getCharacter(senderId, NULL); @@ -453,7 +453,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) { // Invalid character LOG_ERROR("Error finding character id for post"); - result.writeByte(ERRMSG_INVALID_ARGUMENT); + result.writeInt8(ERRMSG_INVALID_ARGUMENT); break; } @@ -463,7 +463,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) std::vector< std::pair<int, int> > items; while (msg.getUnreadLength()) { - items.push_back(std::pair<int, int>(msg.readShort(), msg.readShort())); + items.push_back(std::pair<int, int>(msg.readInt16(), msg.readInt16())); } // save the letter @@ -479,14 +479,14 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) } postalManager->addLetter(letter); - result.writeByte(ERRMSG_OK); + result.writeInt8(ERRMSG_OK); } break; case GAMSG_TRANSACTION: { LOG_DEBUG("TRANSACTION"); - int id = msg.readLong(); - int action = msg.readLong(); + int id = msg.readInt32(); + int action = msg.readInt32(); std::string message = msg.readString(); Transaction trans; @@ -499,7 +499,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) default: LOG_WARN("ServerHandler::processMessage, Invalid message type: " << msg.getId()); - result.writeShort(XXMSG_INVALID); + result.writeInt16(XXMSG_INVALID); break; } @@ -544,8 +544,8 @@ void GameServerHandler::sendPartyChange(Character *ptr, int partyId) if (s) { MessageOut msg(CGMSG_CHANGED_PARTY); - msg.writeLong(ptr->getDatabaseID()); - msg.writeLong(partyId); + msg.writeInt32(ptr->getDatabaseID()); + msg.writeInt32(partyId); s->send(msg); } } @@ -555,7 +555,7 @@ void GameServerHandler::syncDatabase(MessageIn &msg) // It is safe to perform the following updates in a transaction dal::PerformTransaction transaction(storage->database()); - int msgType = msg.readByte(); + int msgType = msg.readInt8(); while (msgType != SYNC_END_OF_BUFFER && msg.getUnreadLength() > 0) { switch (msgType) @@ -563,17 +563,17 @@ void GameServerHandler::syncDatabase(MessageIn &msg) case SYNC_CHARACTER_POINTS: { LOG_DEBUG("received SYNC_CHARACTER_POINTS"); - int charId = msg.readLong(); - int charPoints = msg.readLong(); - int corrPoints = msg.readLong(); + int charId = msg.readInt32(); + int charPoints = msg.readInt32(); + int corrPoints = msg.readInt32(); storage->updateCharacterPoints(charId, charPoints, corrPoints); } break; case SYNC_CHARACTER_ATTRIBUTE: { LOG_DEBUG("received SYNC_CHARACTER_ATTRIBUTE"); - int charId = msg.readLong(); - int attrId = msg.readLong(); + int charId = msg.readInt32(); + int attrId = msg.readInt32(); double base = msg.readDouble(); double mod = msg.readDouble(); storage->updateAttribute(charId, attrId, base, mod); @@ -582,24 +582,24 @@ void GameServerHandler::syncDatabase(MessageIn &msg) case SYNC_CHARACTER_SKILL: { LOG_DEBUG("received SYNC_CHARACTER_SKILL"); - int charId = msg.readLong(); - int skillId = msg.readByte(); - int skillValue = msg.readLong(); + int charId = msg.readInt32(); + int skillId = msg.readInt8(); + int skillValue = msg.readInt32(); storage->updateExperience(charId, skillId, skillValue); } break; case SYNC_ONLINE_STATUS: { LOG_DEBUG("received SYNC_ONLINE_STATUS"); - int charId = msg.readLong(); + int charId = msg.readInt32(); bool online; - msg.readByte() == 0x00 ? online = false : online = true; + msg.readInt8() == 0x00 ? online = false : online = true; storage->setOnlineStatus(charId, online); } } // read next message type from buffer - msgType = msg.readByte(); + msgType = msg.readInt8(); } transaction.commit(); diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp index 410c5b0b..5740dff9 100644 --- a/src/chat-server/chathandler.cpp +++ b/src/chat-server/chathandler.cpp @@ -63,7 +63,7 @@ bool ChatHandler::startListen(enet_uint16 port, const std::string &host) void ChatHandler::deletePendingClient(ChatClient *c) { MessageOut msg(CPMSG_CONNECT_RESPONSE); - msg.writeByte(ERRMSG_TIME_OUT); + msg.writeInt8(ERRMSG_TIME_OUT); // The computer will be deleted when the disconnect event is processed c->disconnect(msg); @@ -86,14 +86,14 @@ void ChatHandler::tokenMatched(ChatClient *client, Pending *p) if (!c) { // character wasnt found - msg.writeByte(ERRMSG_FAILURE); + msg.writeInt8(ERRMSG_FAILURE); } else { client->characterId = c->getDatabaseID(); delete p; - msg.writeByte(ERRMSG_OK); + msg.writeInt8(ERRMSG_OK); // Add chat client to player map mPlayerMap.insert(std::pair<std::string, ChatClient*>(client->characterName, client)); @@ -244,7 +244,7 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message) default: LOG_WARN("ChatHandler::processMessage, Invalid message type" << message.getId()); - result.writeShort(XXMSG_INVALID); + result.writeInt16(XXMSG_INVALID); break; } @@ -255,18 +255,16 @@ void ChatHandler::processMessage(NetComputer *comp, MessageIn &message) void ChatHandler::handleCommand(ChatClient &computer, const std::string &command) { LOG_INFO("Chat: Received unhandled command: " << command); - MessageOut result; - result.writeShort(CPMSG_ERROR); - result.writeByte(CHAT_UNHANDLED_COMMAND); + MessageOut result(CPMSG_ERROR); + result.writeInt8(CHAT_UNHANDLED_COMMAND); computer.send(result); } void ChatHandler::warnPlayerAboutBadWords(ChatClient &computer) { // We could later count if the player is really often unpolite. - MessageOut result; - result.writeShort(CPMSG_ERROR); - result.writeByte(CHAT_USING_BAD_WORDS); // The Channel + MessageOut result(CPMSG_ERROR); + result.writeInt8(CHAT_USING_BAD_WORDS); // The Channel computer.send(result); LOG_INFO(computer.characterName << " says bad words."); @@ -283,7 +281,7 @@ void ChatHandler::handleChatMessage(ChatClient &client, MessageIn &msg) return; } - short channelId = msg.readShort(); + short channelId = msg.readInt16(); ChatChannel *channel = chatChannelManager->getChannel(channelId); if (channel) @@ -292,7 +290,7 @@ void ChatHandler::handleChatMessage(ChatClient &client, MessageIn &msg) << ": " << text); MessageOut result(CPMSG_PUBMSG); - result.writeShort(channelId); + result.writeInt16(channelId); result.writeString(client.characterName); result.writeString(text); sendInChannel(channel, result); @@ -337,7 +335,7 @@ void ChatHandler::handleAnnounceMessage(ChatClient &client, MessageIn &msg) else { MessageOut result(CPMSG_ERROR); - result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS); + result.writeInt8(ERRMSG_INSUFFICIENT_RIGHTS); client.send(result); LOG_INFO(client.characterName << " couldn't make an announcement due to insufficient rights."); @@ -400,26 +398,26 @@ void ChatHandler::handleEnterChannelMessage(ChatClient &client, MessageIn &msg) if (!channel) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (!channel->getPassword().empty() && channel->getPassword() != givenPassword) { // Incorrect password (should probably have its own return value) - reply.writeByte(ERRMSG_INSUFFICIENT_RIGHTS); + reply.writeInt8(ERRMSG_INSUFFICIENT_RIGHTS); } else if (!channel->canJoin()) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else { if (channel->addUser(&client)) { - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); // The user entered the channel, now give him the channel // id, the announcement string and the user list. - reply.writeShort(channel->getId()); + reply.writeInt16(channel->getId()); reply.writeString(channelName); reply.writeString(channel->getAnnouncement()); const ChatChannel::ChannelUsers &users = channel->getUserList(); @@ -446,7 +444,7 @@ void ChatHandler::handleEnterChannelMessage(ChatClient &client, MessageIn &msg) } else { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } } @@ -455,7 +453,7 @@ void ChatHandler::handleEnterChannelMessage(ChatClient &client, MessageIn &msg) void ChatHandler::handleModeChangeMessage(ChatClient &client, MessageIn &msg) { - short channelId = msg.readShort(); + short channelId = msg.readInt16(); ChatChannel *channel = chatChannelManager->getChannel(channelId); if (channelId == 0 || !channel) @@ -474,7 +472,7 @@ void ChatHandler::handleModeChangeMessage(ChatClient &client, MessageIn &msg) std::string user = msg.readString(); // get the mode to change to - unsigned char mode = msg.readByte(); + unsigned char mode = msg.readInt8(); channel->setUserMode(getClient(user), mode); // set the info to pass to all channel clients @@ -496,7 +494,7 @@ void ChatHandler::handleModeChangeMessage(ChatClient &client, MessageIn &msg) void ChatHandler::handleKickUserMessage(ChatClient &client, MessageIn &msg) { - short channelId = msg.readShort(); + short channelId = msg.readInt16(); ChatChannel *channel = chatChannelManager->getChannel(channelId); if (channelId == 0 || !channel) @@ -535,21 +533,21 @@ void ChatHandler::handleQuitChannelMessage(ChatClient &client, MessageIn &msg) { MessageOut reply(CPMSG_QUIT_CHANNEL_RESPONSE); - short channelId = msg.readShort(); + short channelId = msg.readInt16(); ChatChannel *channel = chatChannelManager->getChannel(channelId); if (channelId == 0 || !channel) { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } else if (!channel->removeUser(&client)) { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } else { - reply.writeByte(ERRMSG_OK); - reply.writeShort(channelId); + reply.writeInt8(ERRMSG_OK); + reply.writeInt16(channelId); // Send an CPMSG_UPDATE_CHANNEL to warn other clients a user left // the channel. @@ -585,7 +583,7 @@ void ChatHandler::handleListChannelsMessage(ChatClient &client, MessageIn &msg) i != i_end; ++i) { reply.writeString((*i)->getName()); - reply.writeShort((*i)->getUserList().size()); + reply.writeInt16((*i)->getUserList().size()); } client.send(reply); @@ -632,7 +630,7 @@ void ChatHandler::handleListChannelUsersMessage(ChatClient &client, void ChatHandler::handleTopicChange(ChatClient &client, MessageIn &msg) { - short channelId = msg.readShort(); + short channelId = msg.readInt16(); std::string topic = msg.readString(); ChatChannel *channel = chatChannelManager->getChannel(channelId); @@ -657,7 +655,7 @@ void ChatHandler::handleTopicChange(ChatClient &client, MessageIn &msg) void ChatHandler::handleDisconnectMessage(ChatClient &client, MessageIn &msg) { MessageOut reply(CPMSG_DISCONNECT_RESPONSE); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); chatChannelManager->removeUserFromAllChannels(&client); guildManager->disconnectPlayer(&client); client.send(reply); @@ -667,11 +665,10 @@ void ChatHandler::sayToPlayer(ChatClient &computer, const std::string &playerName, const std::string &text) { - MessageOut result; LOG_DEBUG(computer.characterName << " says to " << playerName << ": " << text); // Send it to the being if the being exists - result.writeShort(CPMSG_PRIVMSG); + MessageOut result(CPMSG_PRIVMSG); result.writeString(computer.characterName); result.writeString(text); for (NetComputers::iterator i = clients.begin(), i_end = clients.end(); @@ -689,8 +686,8 @@ void ChatHandler::warnUsersAboutPlayerEventInChat(ChatChannel *channel, char eventId) { MessageOut msg(CPMSG_CHANNEL_EVENT); - msg.writeShort(channel->getId()); - msg.writeByte(eventId); + msg.writeInt16(channel->getId()); + msg.writeInt8(eventId); msg.writeString(info); sendInChannel(channel, msg); } diff --git a/src/chat-server/guildhandler.cpp b/src/chat-server/guildhandler.cpp index 523e68ac..63d69b6f 100644 --- a/src/chat-server/guildhandler.cpp +++ b/src/chat-server/guildhandler.cpp @@ -62,14 +62,14 @@ void ChatHandler::sendGuildRejoin(ChatClient &client) // Tell the client what guilds the character belongs to and their permissions MessageOut msg(CPMSG_GUILD_REJOIN); msg.writeString(guildName); - msg.writeShort(guild->getId()); - msg.writeShort(permissions); + msg.writeInt16(guild->getId()); + msg.writeInt16(permissions); // get channel id of guild channel ChatChannel *channel = joinGuildChannel(guildName, client); // send the channel id for the autojoined channel - msg.writeShort(channel->getId()); + msg.writeInt16(channel->getId()); msg.writeString(channel->getAnnouncement()); client.send(msg); @@ -111,9 +111,9 @@ void ChatHandler::sendGuildListUpdate(const std::string &guildName, { MessageOut msg(CPMSG_GUILD_UPDATE_LIST); - msg.writeShort(guild->getId()); + msg.writeInt16(guild->getId()); msg.writeString(characterName); - msg.writeByte(eventId); + msg.writeInt8(eventId); std::map<std::string, ChatClient*>::const_iterator chr; std::list<GuildMember*> members = guild->getMembers(); @@ -142,25 +142,25 @@ void ChatHandler::handleGuildCreation(ChatClient &client, // check the player hasnt already created a guild if (guildManager->alreadyOwner(client.characterId)) { - reply.writeByte(ERRMSG_LIMIT_REACHED); + reply.writeInt8(ERRMSG_LIMIT_REACHED); } else { // Guild doesnt already exist so create it Guild *guild = guildManager->createGuild(guildName, client.characterId); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); reply.writeString(guildName); - reply.writeShort(guild->getId()); - reply.writeShort(guild->getUserPermissions(client.characterId)); + reply.writeInt16(guild->getId()); + reply.writeInt16(guild->getUserPermissions(client.characterId)); // Send autocreated channel id ChatChannel* channel = joinGuildChannel(guildName, client); - reply.writeShort(channel->getId()); + reply.writeInt16(channel->getId()); } } else { - reply.writeByte(ERRMSG_ALREADY_TAKEN); + reply.writeInt8(ERRMSG_ALREADY_TAKEN); } client.send(reply); @@ -173,7 +173,7 @@ void ChatHandler::handleGuildInvitation(ChatClient &client, MessageOut invite(CPMSG_GUILD_INVITED); // send an invitation from sender to character to join guild - int guildId = msg.readShort(); + int guildId = msg.readInt16(); std::string character = msg.readString(); // get the chat client and the guild @@ -194,21 +194,21 @@ void ChatHandler::handleGuildInvitation(ChatClient &client, std::string guildName = guild->getName(); invite.writeString(senderName); invite.writeString(guildName); - invite.writeShort(guildId); + invite.writeInt16(guildId); invitedClient->send(invite); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); // add member to list of invited members to the guild guild->addInvited(invitedClient->characterId); } else { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } } else { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } client.send(reply); @@ -231,14 +231,14 @@ void ChatHandler::handleGuildAcceptInvite(ChatClient &client, { // add user to guild guildManager->addGuildMember(guild, client.characterId); - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); reply.writeString(guild->getName()); - reply.writeShort(guild->getId()); - reply.writeShort(guild->getUserPermissions(client.characterId)); + reply.writeInt16(guild->getId()); + reply.writeInt16(guild->getUserPermissions(client.characterId)); // have character join guild channel ChatChannel *channel = joinGuildChannel(guild->getName(), client); - reply.writeShort(channel->getId()); + reply.writeInt16(channel->getId()); sendGuildListUpdate(guildName, client.characterName, GUILD_EVENT_NEW_PLAYER); // success! set error to false @@ -248,7 +248,7 @@ void ChatHandler::handleGuildAcceptInvite(ChatClient &client, if (error) { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } client.send(reply); @@ -258,7 +258,7 @@ void ChatHandler::handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg) { MessageOut reply(CPMSG_GUILD_GET_MEMBERS_RESPONSE); - short guildId = msg.readShort(); + short guildId = msg.readInt16(); Guild *guild = guildManager->findById(guildId); // check for valid guild @@ -268,8 +268,8 @@ void ChatHandler::handleGuildRetrieveMembers(ChatClient &client, // make sure the requestor is in the guild if (guild->checkInGuild(client.characterId)) { - reply.writeByte(ERRMSG_OK); - reply.writeShort(guildId); + reply.writeInt8(ERRMSG_OK); + reply.writeInt16(guildId); std::list<GuildMember*> memberList = guild->getMembers(); std::list<GuildMember*>::const_iterator itr_end = memberList.end(); for (std::list<GuildMember*>::iterator itr = memberList.begin(); @@ -278,13 +278,13 @@ void ChatHandler::handleGuildRetrieveMembers(ChatClient &client, Character *c = storage->getCharacter((*itr)->mId, NULL); std::string memberName = c->getName(); reply.writeString(memberName); - reply.writeByte(mPlayerMap.find(memberName) != mPlayerMap.end()); + reply.writeInt8(mPlayerMap.find(memberName) != mPlayerMap.end()); } } } else { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } client.send(reply); @@ -296,9 +296,9 @@ void ChatHandler::handleGuildMemberLevelChange(ChatClient &client, // get the guild, the user to change the permissions, and the new permission // check theyre valid, and then change them MessageOut reply(CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE); - short guildId = msg.readShort(); + short guildId = msg.readInt16(); std::string user = msg.readString(); - short level = msg.readByte(); + short level = msg.readInt8(); Guild *guild = guildManager->findById(guildId); Character *c = storage->getCharacter(user); @@ -307,19 +307,19 @@ void ChatHandler::handleGuildMemberLevelChange(ChatClient &client, int rights = guild->getUserPermissions(c->getDatabaseID()) | level; if (guildManager->changeMemberLevel(&client, guild, c->getDatabaseID(), rights) == 0) { - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); client.send(reply); } } - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); client.send(reply); } void ChatHandler::handleGuildMemberKick(ChatClient &client, MessageIn &msg) { MessageOut reply(CPMSG_GUILD_KICK_MEMBER_RESPONSE); - short guildId = msg.readShort(); + short guildId = msg.readInt16(); std::string user = msg.readString(); Guild *guild = guildManager->findById(guildId); @@ -329,16 +329,16 @@ void ChatHandler::handleGuildMemberKick(ChatClient &client, MessageIn &msg) { if (guild->getUserPermissions(c->getDatabaseID()) & GAL_KICK) { - reply.writeByte(ERRMSG_OK); + reply.writeInt8(ERRMSG_OK); } else { - reply.writeByte(ERRMSG_INSUFFICIENT_RIGHTS); + reply.writeInt8(ERRMSG_INSUFFICIENT_RIGHTS); } } else { - reply.writeByte(ERRMSG_INVALID_ARGUMENT); + reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } client.send(reply); @@ -347,7 +347,7 @@ void ChatHandler::handleGuildMemberKick(ChatClient &client, MessageIn &msg) void ChatHandler::handleGuildQuit(ChatClient &client, MessageIn &msg) { MessageOut reply(CPMSG_GUILD_QUIT_RESPONSE); - short guildId = msg.readShort(); + short guildId = msg.readInt16(); Guild *guild = guildManager->findById(guildId); // check for valid guild @@ -357,8 +357,8 @@ void ChatHandler::handleGuildQuit(ChatClient &client, MessageIn &msg) { if (guild->checkInGuild(client.characterId)) { - reply.writeByte(ERRMSG_OK); - reply.writeShort(guildId); + reply.writeInt8(ERRMSG_OK); + reply.writeInt16(guildId); // Check if there are no members left, remove the guild channel if (guild->memberCount() == 0) @@ -373,12 +373,12 @@ void ChatHandler::handleGuildQuit(ChatClient &client, MessageIn &msg) } else { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } } else { - reply.writeByte(ERRMSG_FAILURE); + reply.writeInt8(ERRMSG_FAILURE); } client.send(reply); diff --git a/src/chat-server/partyhandler.cpp b/src/chat-server/partyhandler.cpp index e9e4222f..e3d8e098 100644 --- a/src/chat-server/partyhandler.cpp +++ b/src/chat-server/partyhandler.cpp @@ -66,7 +66,7 @@ bool ChatHandler::handlePartyJoin(const std::string &invited, const std::string c2->party = c1->party; // was successful so return success to inviter out.writeString(invited); - out.writeByte(ERRMSG_OK); + out.writeInt8(ERRMSG_OK); c1->send(out); // tell everyone a player joined @@ -143,7 +143,7 @@ void ChatHandler::handlePartyAcceptInvite(ChatClient &client, MessageIn &msg) // make them join the party if (handlePartyJoin(client.characterName, inviter)) { - out.writeByte(ERRMSG_OK); + out.writeInt8(ERRMSG_OK); mPartyInvitedUsers.erase(itr); found = true; break; @@ -155,7 +155,7 @@ void ChatHandler::handlePartyAcceptInvite(ChatClient &client, MessageIn &msg) if (!found) { - out.writeByte(ERRMSG_FAILURE); + out.writeInt8(ERRMSG_FAILURE); } client.send(out); @@ -165,7 +165,7 @@ void ChatHandler::handlePartyQuit(ChatClient &client) { removeUserFromParty(client); MessageOut out(CPMSG_PARTY_QUIT_RESPONSE); - out.writeByte(ERRMSG_OK); + out.writeInt8(ERRMSG_OK); client.send(out); // tell game server to update info @@ -202,7 +202,7 @@ void ChatHandler::handlePartyRejection(ChatClient &client, MessageIn &msg) if (!found) { - out.writeByte(ERRMSG_FAILURE); + out.writeInt8(ERRMSG_FAILURE); } // send rejection to inviter @@ -237,7 +237,7 @@ void ChatHandler::informPartyMemberQuit(ChatClient &client) if (itr->second->party == client.party) { MessageOut out(CPMSG_PARTY_MEMBER_LEFT); - out.writeShort(client.characterId); + out.writeInt16(client.characterId); itr->second->send(out); } } @@ -253,7 +253,7 @@ void ChatHandler::informPartyMemberJoined(ChatClient &client) if (itr->second->party == client.party) { MessageOut out(CPMSG_PARTY_NEW_MEMBER); - out.writeShort(client.characterId); + out.writeInt16(client.characterId); out.writeString(client.characterName); itr->second->send(out); } diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index 1f8be4d3..3c3cd88c 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -69,14 +69,14 @@ bool AccountConnection::start(int gameServerPort) // Register with the account server and send the list of maps we handle MessageOut msg(GAMSG_REGISTER); msg.writeString(gameServerAddress); - msg.writeShort(gameServerPort); + msg.writeInt16(gameServerPort); msg.writeString(password); - msg.writeLong(itemManager->getDatabaseVersion()); + msg.writeInt32(itemManager->getDatabaseVersion()); const MapManager::Maps &m = MapManager::getMaps(); for (MapManager::Maps::const_iterator i = m.begin(), i_end = m.end(); i != i_end; ++i) { - msg.writeShort(i->first); + msg.writeInt16(i->first); } send(msg); @@ -90,7 +90,7 @@ bool AccountConnection::start(int gameServerPort) void AccountConnection::sendCharacterData(Character *p) { MessageOut msg(GAMSG_PLAYER_DATA); - msg.writeLong(p->getDatabaseID()); + msg.writeInt32(p->getDatabaseID()); serializeCharacterData(*p, msg); send(msg); } @@ -101,7 +101,7 @@ void AccountConnection::processMessage(MessageIn &msg) { case AGMSG_REGISTER_RESPONSE: { - if (msg.readShort() != DATA_VERSION_OK) + if (msg.readInt16() != DATA_VERSION_OK) { LOG_ERROR("Item database is outdated! Please update to " "prevent inconsistencies"); @@ -114,7 +114,7 @@ void AccountConnection::processMessage(MessageIn &msg) LOG_DEBUG("Local item database is " "in sync with account server."); } - if (msg.readShort() != PASSWORD_OK) + if (msg.readInt16() != PASSWORD_OK) { LOG_ERROR("This game server sent a invalid password"); stop(); @@ -131,22 +131,22 @@ void AccountConnection::processMessage(MessageIn &msg) case AGMSG_ACTIVE_MAP: { - int id = msg.readShort(); + int id = msg.readInt16(); MapManager::raiseActive(id); } break; case AGMSG_REDIRECT_RESPONSE: { - int id = msg.readLong(); + int id = msg.readInt32(); std::string token = msg.readString(MAGIC_TOKEN_LENGTH); std::string address = msg.readString(); - int port = msg.readShort(); + int port = msg.readInt16(); gameHandler->completeServerChange(id, token, address, port); } break; case AGMSG_GET_QUEST_RESPONSE: { - int id = msg.readLong(); + int id = msg.readInt32(); std::string name = msg.readString(); std::string value = msg.readString(); recoveredQuestVar(id, name, value); @@ -155,16 +155,16 @@ void AccountConnection::processMessage(MessageIn &msg) case CGMSG_CHANGED_PARTY: { // Character DB id - int charid = msg.readLong(); + int charid = msg.readInt32(); // Party id, 0 for none - int partyid = msg.readLong(); + int partyid = msg.readInt32(); gameHandler->updateCharacter(charid, partyid); } break; case CGMSG_POST_RESPONSE: { // get the character - Character *character = postMan->getCharacter(msg.readLong()); + Character *character = postMan->getCharacter(msg.readInt32()); // check character is still valid if (!character) @@ -182,7 +182,7 @@ void AccountConnection::processMessage(MessageIn &msg) case CGMSG_STORE_POST_RESPONSE: { // get character - Character *character = postMan->getCharacter(msg.readLong()); + Character *character = postMan->getCharacter(msg.readInt32()); // check character is valid if (!character) @@ -206,7 +206,7 @@ void AccountConnection::playerReconnectAccount(int id, { LOG_DEBUG("Send GAMSG_PLAYER_RECONNECT."); MessageOut msg(GAMSG_PLAYER_RECONNECT); - msg.writeLong(id); + msg.writeInt32(id); msg.writeString(magic_token, MAGIC_TOKEN_LENGTH); send(msg); } @@ -214,7 +214,7 @@ void AccountConnection::playerReconnectAccount(int id, void AccountConnection::requestQuestVar(Character *ch, const std::string &name) { MessageOut msg(GAMSG_GET_QUEST); - msg.writeLong(ch->getDatabaseID()); + msg.writeInt32(ch->getDatabaseID()); msg.writeString(name); send(msg); } @@ -223,7 +223,7 @@ void AccountConnection::updateQuestVar(Character *ch, const std::string &name, const std::string &value) { MessageOut msg(GAMSG_SET_QUEST); - msg.writeLong(ch->getDatabaseID()); + msg.writeInt32(ch->getDatabaseID()); msg.writeString(name); msg.writeString(value); send(msg); @@ -232,8 +232,8 @@ void AccountConnection::updateQuestVar(Character *ch, const std::string &name, void AccountConnection::banCharacter(Character *ch, int duration) { MessageOut msg(GAMSG_BAN_PLAYER); - msg.writeLong(ch->getDatabaseID()); - msg.writeShort(duration); + msg.writeInt32(ch->getDatabaseID()); + msg.writeInt16(duration); send(msg); } @@ -246,7 +246,7 @@ void AccountConnection::sendStatistics() { MapComposite *m = i->second; if (!m->isActive()) continue; - msg.writeShort(i->first); + msg.writeInt16(i->first); int nbThings = 0, nbMonsters = 0; typedef std::vector< Thing * > Things; const Things &things = m->getEverything(); @@ -268,13 +268,13 @@ void AccountConnection::sendStatistics() ++nbThings; } } - msg.writeShort(nbThings); - msg.writeShort(nbMonsters); - msg.writeShort(players.size()); + msg.writeInt16(nbThings); + msg.writeInt16(nbMonsters); + msg.writeInt16(players.size()); for (std::vector< int >::const_iterator j = players.begin(), j_end = players.end(); j != j_end; ++j) { - msg.writeLong(*j); + msg.writeInt32(*j); } } send(msg); @@ -286,14 +286,14 @@ void AccountConnection::sendPost(Character *c, MessageIn &msg) // the id of receiving player, the letter receiver and contents, and attachments LOG_DEBUG("Sending GCMSG_STORE_POST."); MessageOut out(GCMSG_STORE_POST); - out.writeLong(c->getDatabaseID()); + out.writeInt32(c->getDatabaseID()); out.writeString(msg.readString()); // name of receiver out.writeString(msg.readString()); // content of letter while (msg.getUnreadLength()) // attachments { // write the item id and amount for each attachment - out.writeLong(msg.readShort()); - out.writeLong(msg.readShort()); + out.writeInt32(msg.readInt16()); + out.writeInt32(msg.readInt16()); } send(out); } @@ -306,15 +306,15 @@ void AccountConnection::getPost(Character *c) // send message to account server with id of retrieving player LOG_DEBUG("Sending GCMSG_REQUEST_POST"); MessageOut out(GCMSG_REQUEST_POST); - out.writeLong(c->getDatabaseID()); + out.writeInt32(c->getDatabaseID()); send(out); } void AccountConnection::changeAccountLevel(Character *c, int level) { MessageOut msg(GAMSG_CHANGE_ACCOUNT_LEVEL); - msg.writeLong(c->getDatabaseID()); - msg.writeShort(level); + msg.writeInt32(c->getDatabaseID()); + msg.writeInt16(level); send(msg); } @@ -336,7 +336,7 @@ void AccountConnection::syncChanges(bool force) << mSyncMessages << " messages." ); // attach end-of-buffer flag - mSyncBuffer->writeByte(SYNC_END_OF_BUFFER); + mSyncBuffer->writeInt8(SYNC_END_OF_BUFFER); send(*mSyncBuffer); delete (mSyncBuffer); @@ -353,10 +353,10 @@ void AccountConnection::updateCharacterPoints(int charId, int charPoints, int corrPoints) { mSyncMessages++; - mSyncBuffer->writeByte(SYNC_CHARACTER_POINTS); - mSyncBuffer->writeLong(charId); - mSyncBuffer->writeLong(charPoints); - mSyncBuffer->writeLong(corrPoints); + mSyncBuffer->writeInt8(SYNC_CHARACTER_POINTS); + mSyncBuffer->writeInt32(charId); + mSyncBuffer->writeInt32(charPoints); + mSyncBuffer->writeInt32(corrPoints); syncChanges(); } @@ -364,9 +364,9 @@ void AccountConnection::updateAttributes(int charId, int attrId, double base, double mod) { ++mSyncMessages; - mSyncBuffer->writeByte(SYNC_CHARACTER_ATTRIBUTE); - mSyncBuffer->writeLong(charId); - mSyncBuffer->writeLong(attrId); + mSyncBuffer->writeInt8(SYNC_CHARACTER_ATTRIBUTE); + mSyncBuffer->writeInt32(charId); + mSyncBuffer->writeInt32(attrId); mSyncBuffer->writeDouble(base); mSyncBuffer->writeDouble(mod); syncChanges(); @@ -376,27 +376,27 @@ void AccountConnection::updateExperience(int charId, int skillId, int skillValue) { mSyncMessages++; - mSyncBuffer->writeByte(SYNC_CHARACTER_SKILL); - mSyncBuffer->writeLong(charId); - mSyncBuffer->writeByte(skillId); - mSyncBuffer->writeLong(skillValue); + mSyncBuffer->writeInt8(SYNC_CHARACTER_SKILL); + mSyncBuffer->writeInt32(charId); + mSyncBuffer->writeInt8(skillId); + mSyncBuffer->writeInt32(skillValue); syncChanges(); } void AccountConnection::updateOnlineStatus(int charId, bool online) { mSyncMessages++; - mSyncBuffer->writeByte(SYNC_ONLINE_STATUS); - mSyncBuffer->writeLong(charId); - mSyncBuffer->writeByte(online ? 0x01 : 0x00); + mSyncBuffer->writeInt8(SYNC_ONLINE_STATUS); + mSyncBuffer->writeInt32(charId); + mSyncBuffer->writeInt8(online ? 0x01 : 0x00); syncChanges(); } void AccountConnection::sendTransaction(int id, int action, const std::string &message) { MessageOut msg(GAMSG_TRANSACTION); - msg.writeLong(id); - msg.writeLong(action); + msg.writeInt32(id); + msg.writeInt32(action); msg.writeString(message); send(msg); } diff --git a/src/game-server/buysell.cpp b/src/game-server/buysell.cpp index cf5b8fe5..a6f68e1a 100644 --- a/src/game-server/buysell.cpp +++ b/src/game-server/buysell.cpp @@ -109,13 +109,13 @@ bool BuySell::start(Actor *actor) } MessageOut msg(mSell ? GPMSG_NPC_SELL : GPMSG_NPC_BUY); - msg.writeShort(actor->getPublicID()); + msg.writeInt16(actor->getPublicID()); for (TradedItems::const_iterator i = mItems.begin(), i_end = mItems.end(); i != i_end; ++i) { - msg.writeShort(i->itemId); - msg.writeShort(i->amount); - msg.writeShort(i->cost); + msg.writeInt16(i->itemId); + msg.writeInt16(i->amount); + msg.writeInt16(i->cost); } mChar->getClient()->send(msg); return true; diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 1bb8ffa6..4e8fe032 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -78,7 +78,7 @@ Character::Character(MessageIn &msg): mAttributes.insert(std::make_pair(it1->first, Attribute(*it1->second))); // Get character data. - mDatabaseID = msg.readLong(); + mDatabaseID = msg.readInt32(); setName(msg.readString()); deserializeCharacterData(*this, msg); mOld = getPosition(); @@ -234,10 +234,10 @@ void Character::sendSpecialUpdate() { MessageOut msg(GPMSG_SPECIAL_STATUS ); - msg.writeByte(i->first); - msg.writeLong(i->second->currentMana); - msg.writeLong(i->second->neededMana); - msg.writeLong(mRechargePerSpecial); + msg.writeInt8(i->first); + msg.writeInt32(i->second->currentMana); + msg.writeInt32(i->second->neededMana); + msg.writeInt32(mRechargePerSpecial); /* Yes, the last one is redundant because it is the same for each special, but I would like to keep the netcode flexible enough to allow different recharge speed per special when necessary */ @@ -321,9 +321,9 @@ void Character::sendStatus() i_end = mModifiedAttributes.end(); i != i_end; ++i) { int attr = *i; - attribMsg.writeShort(attr); - attribMsg.writeLong(getAttribute(attr) * 256); - attribMsg.writeLong(getModifiedAttribute(attr) * 256); + attribMsg.writeInt16(attr); + attribMsg.writeInt32(getAttribute(attr) * 256); + attribMsg.writeInt32(getModifiedAttribute(attr) * 256); } if (attribMsg.getLength() > 2) gameHandler->sendTo(this, attribMsg); mModifiedAttributes.clear(); @@ -333,9 +333,9 @@ void Character::sendStatus() i_end = mModifiedExperience.end(); i != i_end; ++i) { int skill = *i; - expMsg.writeShort(skill); - expMsg.writeLong(getExpGot(skill)); - expMsg.writeLong(getExpNeeded(skill)); + expMsg.writeInt16(skill); + expMsg.writeInt32(getExpGot(skill)); + expMsg.writeInt32(getExpNeeded(skill)); } if (expMsg.getLength() > 2) gameHandler->sendTo(this, expMsg); mModifiedExperience.clear(); @@ -344,7 +344,7 @@ void Character::sendStatus() { mUpdateLevelProgress = false; MessageOut progressMessage(GPMSG_LEVEL_PROGRESS); - progressMessage.writeByte(mLevelProgress); + progressMessage.writeInt8(mLevelProgress); gameHandler->sendTo(this, progressMessage); } } @@ -604,9 +604,9 @@ void Character::levelup() mCorrectionPoints = CORRECTIONPOINTS_MAX; MessageOut levelupMsg(GPMSG_LEVELUP); - levelupMsg.writeShort(mLevel); - levelupMsg.writeShort(mCharacterPoints); - levelupMsg.writeShort(mCorrectionPoints); + levelupMsg.writeInt16(mLevel); + levelupMsg.writeInt16(mCharacterPoints); + levelupMsg.writeInt16(mCorrectionPoints); gameHandler->sendTo(this, levelupMsg); LOG_INFO(getName()<<" reached level "<<mLevel); } diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index 15214a78..5c7ba34e 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -107,7 +107,7 @@ void GameHandler::completeServerChange(int id, const std::string &token, MessageOut msg(GPMSG_PLAYER_SERVER_CHANGE); msg.writeString(token, MAGIC_TOKEN_LENGTH); msg.writeString(address); - msg.writeShort(port); + msg.writeInt16(port); c->send(msg); c->character->disconnected(); delete c->character; @@ -212,7 +212,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_NPC_NUMBER: case PGMSG_NPC_STRING: { - int id = message.readShort(); + int id = message.readInt16(); Actor *o = findActorNear(computer.character, id); if (!o || o->getType() != OBJECT_NPC) { @@ -223,11 +223,11 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) NPC *q = static_cast< NPC * >(o); if (message.getId() == PGMSG_NPC_SELECT) { - q->select(computer.character, message.readByte()); + q->select(computer.character, message.readInt8()); } else if (message.getId() == PGMSG_NPC_NUMBER) { - q->integerReceived(computer.character, message.readLong()); + q->integerReceived(computer.character, message.readInt32()); } else if (message.getId() == PGMSG_NPC_STRING) { @@ -241,8 +241,8 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_PICKUP: { - int x = message.readShort(); - int y = message.readShort(); + int x = message.readInt16(); + int y = message.readInt16(); Point ppos = computer.character->getPosition(); // TODO: use a less arbitrary value. @@ -275,7 +275,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_USE_ITEM: { - int slot = message.readByte(); + int slot = message.readInt8(); Inventory inv(computer.character); if (ItemClass *ic = itemManager->getItem(inv.getItem(slot))) { @@ -294,8 +294,8 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_DROP: { - int slot = message.readByte(); - int amount = message.readByte(); + int slot = message.readInt8(); + int amount = message.readInt8(); Inventory inv(computer.character); if (ItemClass *ic = itemManager->getItem(inv.getItem(slot))) { @@ -327,22 +327,22 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_EQUIP: { - int slot = message.readByte(); + int slot = message.readInt8(); Inventory(computer.character).equip(slot); } break; case PGMSG_UNEQUIP: { - int slot = message.readByte(); + int slot = message.readInt8(); if (slot >= 0 && slot < INVENTORY_SLOTS) Inventory(computer.character).unequip(slot); } break; case PGMSG_MOVE_ITEM: { - int slot1 = message.readByte(); - int slot2 = message.readByte(); - int amount = message.readByte(); + int slot1 = message.readInt8(); + int slot2 = message.readInt8(); + int amount = message.readInt8(); Inventory(computer.character).move(slot1, slot2, amount); // log transaction std::stringstream str; @@ -354,7 +354,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_ATTACK: { - int id = message.readShort(); + int id = message.readInt16(); LOG_DEBUG("Character " << computer.character->getPublicID() << " attacked being " << id); @@ -369,7 +369,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_USE_SPECIAL: { - int specialID = message.readByte(); + int specialID = message.readInt8(); LOG_DEBUG("Character " << computer.character->getPublicID() << " tries to use his special attack "<<specialID); computer.character->useSpecial(specialID); @@ -377,7 +377,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_ACTION_CHANGE: { - Being::Action action = (Being::Action)message.readByte(); + Being::Action action = (Being::Action)message.readInt8(); Being::Action current = (Being::Action)computer.character->getAction(); bool logActionChange = true; @@ -419,15 +419,15 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_DIRECTION_CHANGE: { - computer.character->setDirection(message.readByte()); + computer.character->setDirection(message.readInt8()); } break; case PGMSG_DISCONNECT: { - bool reconnectAccount = (bool) message.readByte(); + bool reconnectAccount = (bool) message.readInt8(); - result.writeShort(GPMSG_DISCONNECT_RESPONSE); - result.writeByte(ERRMSG_OK); // It is, when control reaches here + result.writeInt16(GPMSG_DISCONNECT_RESPONSE); + result.writeInt8(ERRMSG_OK); // It is, when control reaches here if (reconnectAccount) { @@ -452,7 +452,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_TRADE_REQUEST: { - int id = message.readShort(); + int id = message.readInt16(); if (Trade *t = computer.character->getTrading()) { @@ -462,7 +462,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) Character *q = findCharacterNear(computer.character, id); if (!q || q->isBusy()) { - result.writeShort(GPMSG_TRADE_CANCEL); + result.writeInt16(GPMSG_TRADE_CANCEL); break; } @@ -501,7 +501,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) break; case PGMSG_TRADE_SET_MONEY: { - int money = message.readLong(); + int money = message.readInt32(); t->setMoney(computer.character, money); // log transaction str << "User added " << money << " money to trade."; @@ -510,8 +510,8 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) } break; case PGMSG_TRADE_ADD_ITEM: { - int slot = message.readByte(); - t->addItem(computer.character, slot, message.readByte()); + int slot = message.readInt8(); + t->addItem(computer.character, slot, message.readInt8()); // log transaction str << "User add item from slot " << slot; accountHandler->sendTransaction(computer.character->getDatabaseID(), @@ -524,19 +524,19 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) { BuySell *t = computer.character->getBuySell(); if (!t) break; - int id = message.readShort(); - int amount = message.readShort(); + int id = message.readInt16(); + int amount = message.readInt16(); t->perform(id, amount); } break; case PGMSG_RAISE_ATTRIBUTE: { - int attribute = message.readLong(); + int attribute = message.readInt32(); AttribmodResponseCode retCode; retCode = computer.character->useCharacterPoint(attribute); - result.writeShort(GPMSG_RAISE_ATTRIBUTE_RESPONSE); - result.writeByte(retCode); - result.writeLong(attribute); + result.writeInt16(GPMSG_RAISE_ATTRIBUTE_RESPONSE); + result.writeInt8(retCode); + result.writeInt32(attribute); if (retCode == ATTRIBMOD_OK ) { @@ -555,12 +555,12 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) case PGMSG_LOWER_ATTRIBUTE: { - int attribute = message.readLong(); + int attribute = message.readInt32(); AttribmodResponseCode retCode; retCode = computer.character->useCorrectionPoint(attribute); - result.writeShort(GPMSG_LOWER_ATTRIBUTE_RESPONSE); - result.writeByte(retCode); - result.writeLong(attribute); + result.writeInt16(GPMSG_LOWER_ATTRIBUTE_RESPONSE); + result.writeInt8(retCode); + result.writeInt32(attribute); if (retCode == ATTRIBMOD_OK ) { @@ -589,7 +589,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) default: LOG_WARN("Invalid message type"); - result.writeShort(XXMSG_INVALID); + result.writeInt16(XXMSG_INVALID); break; } @@ -653,14 +653,14 @@ void GameHandler::tokenMatched(GameClient *computer, Character *character) if (!GameState::insert(character)) { - result.writeByte(ERRMSG_SERVER_FULL); + result.writeInt8(ERRMSG_SERVER_FULL); kill(character); delete character; computer->disconnect(result); return; } - result.writeByte(ERRMSG_OK); + result.writeInt8(ERRMSG_OK); computer->send(result); // Force sending the whole character to the client. @@ -680,7 +680,7 @@ void GameHandler::deletePendingClient(GameClient *computer) return; MessageOut msg(GPMSG_CONNECT_RESPONSE); - msg.writeByte(ERRMSG_TIME_OUT); + msg.writeInt8(ERRMSG_TIME_OUT); // The computer will be deleted when the disconnect event is processed computer->disconnect(msg); @@ -709,15 +709,15 @@ GameClient *GameHandler::getClientByNameSlow(const std::string &name) const void GameHandler::sendError(NetComputer *computer, int id, std::string errorMsg) { MessageOut msg(GPMSG_NPC_ERROR); - msg.writeShort(id); + msg.writeInt16(id); msg.writeString(errorMsg, errorMsg.size()); computer->send(msg); } void GameHandler::handleWalk(GameClient *client, MessageIn &message) { - int x = message.readShort(); - int y = message.readShort(); + int x = message.readInt16(); + int y = message.readInt16(); Point dst(x, y); client->character->setDestination(dst); diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp index 90d9889d..b29f08de 100644 --- a/src/game-server/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -48,7 +48,7 @@ Inventory::~Inventory() void Inventory::restart() { mInvMsg.clear(); - mInvMsg.writeShort(GPMSG_INVENTORY); + mInvMsg.writeInt16(GPMSG_INVENTORY); } void Inventory::cancel() @@ -180,15 +180,15 @@ void Inventory::equip_sub(unsigned int newCount, IdSlotMap::const_iterator &it) { const unsigned int invSlot = it->first; unsigned int count = 0, eqSlot = it->second; - mEqmMsg.writeShort(invSlot); - mEqmMsg.writeByte(newCount); + mEqmMsg.writeInt16(invSlot); + mEqmMsg.writeInt8(newCount); do { if (newCount) { if (it->second != eqSlot) { - mEqmMsg.writeByte(eqSlot); - mEqmMsg.writeByte(count); + mEqmMsg.writeInt8(eqSlot); + mEqmMsg.writeInt8(count); count = 1; eqSlot = it->second; } @@ -199,10 +199,10 @@ void Inventory::equip_sub(unsigned int newCount, IdSlotMap::const_iterator &it) } while ((++it)->first == invSlot); if (count) { - mEqmMsg.writeByte(eqSlot); - mEqmMsg.writeByte(count); + mEqmMsg.writeInt8(eqSlot); + mEqmMsg.writeInt8(count); } - mEqmMsg.writeShort(invSlot); + mEqmMsg.writeInt16(invSlot); changeEquipment(newCount ? 0 : mPoss->inventory.at(invSlot).itemId, newCount ? mPoss->inventory.at(invSlot).itemId : 0); } @@ -223,14 +223,14 @@ void Inventory::sendFull() const and equipment to the client */ MessageOut m(GPMSG_INVENTORY_FULL); - m.writeShort(mPoss->inventory.size()); + m.writeInt16(mPoss->inventory.size()); for (InventoryData::const_iterator l = mPoss->inventory.begin(), l_end = mPoss->inventory.end(); l != l_end; ++l) { assert(l->second.itemId); - m.writeShort(l->first); // Slot id - m.writeShort(l->second.itemId); - m.writeShort(l->second.amount); + m.writeInt16(l->first); // Slot id + m.writeInt16(l->second.itemId); + m.writeInt16(l->second.amount); } for (EquipData::const_iterator k = mPoss->equipSlots.begin(), @@ -238,8 +238,8 @@ void Inventory::sendFull() const k != k_end; ++k) { - m.writeByte(k->first); // equip slot - m.writeShort(k->second); // inventory slot + m.writeInt8(k->first); // equip slot + m.writeInt16(k->second); // inventory slot } gameHandler->sendTo(mClient, m); @@ -360,9 +360,9 @@ unsigned int Inventory::insert(unsigned int itemId, unsigned int amount) - it->second.amount; amount -= additions; it->second.amount += additions; - mInvMsg.writeShort(it->first); - mInvMsg.writeShort(itemId); - mInvMsg.writeShort(it->second.amount); + mInvMsg.writeInt16(it->first); + mInvMsg.writeInt16(itemId); + mInvMsg.writeInt16(it->second.amount); if (!amount) return 0; } @@ -380,9 +380,9 @@ unsigned int Inventory::insert(unsigned int itemId, unsigned int amount) mPoss->inventory[slot].itemId = itemId; mPoss->inventory[slot].amount = additions; amount -= additions; - mInvMsg.writeShort(slot++); // Last read, so also increment - mInvMsg.writeShort(itemId); - mInvMsg.writeShort(additions); + mInvMsg.writeInt16(slot++); // Last read, so also increment + mInvMsg.writeInt16(itemId); + mInvMsg.writeInt16(additions); } ++slot; // Skip the slot that the iterator points to if (it == it_end) break; @@ -438,11 +438,11 @@ unsigned int Inventory::remove(unsigned int itemId, unsigned int amount, bool fo unsigned int sub = std::min(amount, it->second.amount); amount -= sub; it->second.amount -= sub; - mInvMsg.writeShort(it->first); + mInvMsg.writeInt16(it->first); if (it->second.amount) { - mInvMsg.writeShort(it->second.itemId); - mInvMsg.writeShort(it->second.amount); + mInvMsg.writeInt16(it->second.itemId); + mInvMsg.writeInt16(it->second.amount); // Some still exist, and we have none left to remove, so // no need to run leave invy triggers. if (!amount) @@ -450,7 +450,7 @@ unsigned int Inventory::remove(unsigned int itemId, unsigned int amount, bool fo } else { - mInvMsg.writeShort(0); + mInvMsg.writeInt16(0); mPoss->inventory.erase(it); } } @@ -499,20 +499,20 @@ unsigned int Inventory::move(unsigned int slot1, unsigned int slot2, unsigned in it1->second.amount -= nb; amount -= nb; - mInvMsg.writeShort(slot1); // Slot + mInvMsg.writeInt16(slot1); // Slot if (it1->second.amount) { - mInvMsg.writeShort(it1->second.itemId); // Item Id - mInvMsg.writeShort(it1->second.amount); // Amount + mInvMsg.writeInt16(it1->second.itemId); // Item Id + mInvMsg.writeInt16(it1->second.amount); // Amount } else { - mInvMsg.writeShort(0); + mInvMsg.writeInt16(0); mPoss->inventory.erase(it1); } - mInvMsg.writeShort(slot2); // Slot - mInvMsg.writeShort(it1->second.itemId); // Item Id (same as slot 1) - mInvMsg.writeShort(nb); // Amount + mInvMsg.writeInt16(slot2); // Slot + mInvMsg.writeInt16(it1->second.itemId); // Item Id (same as slot 1) + mInvMsg.writeInt16(nb); // Amount } else { @@ -527,20 +527,20 @@ unsigned int Inventory::move(unsigned int slot1, unsigned int slot2, unsigned in it2->second.amount += nb; amount -= nb; - mInvMsg.writeShort(slot1); // Slot + mInvMsg.writeInt16(slot1); // Slot if (it1->second.amount) { - mInvMsg.writeShort(it1->second.itemId); // Item Id - mInvMsg.writeShort(it1->second.amount); // Amount + mInvMsg.writeInt16(it1->second.itemId); // Item Id + mInvMsg.writeInt16(it1->second.amount); // Amount } else { - mInvMsg.writeShort(0); + mInvMsg.writeInt16(0); mPoss->inventory.erase(it1); } - mInvMsg.writeShort(slot2); // Slot - mInvMsg.writeShort(it2->second.itemId); // Item Id - mInvMsg.writeShort(it2->second.amount); // Amount + mInvMsg.writeInt16(slot2); // Slot + mInvMsg.writeInt16(it2->second.itemId); // Item Id + mInvMsg.writeInt16(it2->second.amount); // Amount } return amount; } @@ -576,15 +576,15 @@ unsigned int Inventory::removeFromSlot(unsigned int slot, unsigned int amount) unsigned int sub = std::min(amount, it->second.amount); amount -= sub; it->second.amount -= sub; - mInvMsg.writeShort(it->first); + mInvMsg.writeInt16(it->first); if (it->second.amount) { - mInvMsg.writeShort(it->second.itemId); - mInvMsg.writeShort(it->second.amount); + mInvMsg.writeInt16(it->second.itemId); + mInvMsg.writeInt16(it->second.amount); } else { - mInvMsg.writeShort(0); + mInvMsg.writeInt16(0); mPoss->inventory.erase(it); } return amount; @@ -669,8 +669,8 @@ bool Inventory::equip(int slot, bool override) * Clean fit. Equip and apply immediately. */ if (!mDelayed) { - mEqmMsg.writeShort(slot); // Inventory slot - mEqmMsg.writeByte(it2->size()); // Equip slot type count + mEqmMsg.writeInt16(slot); // Inventory slot + mEqmMsg.writeInt8(it2->size()); // Equip slot type count } for (it3 = it2->begin(), it3_end = it2->end(); @@ -678,8 +678,8 @@ bool Inventory::equip(int slot, bool override) ++it3) { if (!mDelayed) { - mEqmMsg.writeByte(it3->first); // Equip slot - mEqmMsg.writeByte(it3->second); // How many are used + mEqmMsg.writeInt8(it3->first); // Equip slot + mEqmMsg.writeInt8(it3->second); // How many are used } /* * This bit can be somewhat inefficient, but is far better for @@ -764,8 +764,8 @@ bool Inventory::unequip(unsigned int slot, EquipData::iterator *itp) if (changed && !mDelayed) { changeEquipment(mPoss->inventory.at(it->second).itemId, 0); - mEqmMsg.writeShort(slot); - mEqmMsg.writeByte(0); + mEqmMsg.writeInt16(slot); + mEqmMsg.writeInt8(0); } return changed; } diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 2c7a5755..0c3121ca 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -149,10 +149,10 @@ static void serializeLooks(Character *ch, MessageOut &msg, bool full) Setting the upper bit tells the client to clear the slots beforehand. */ int mask = full ? mask_full | (1 << 7) : mask_diff; - msg.writeByte(mask); + msg.writeInt8(mask); for (unsigned int i = 0; i < nb_slots; ++i) { - if (mask & (1 << i)) msg.writeShort(items[i]); + if (mask & (1 << i)) msg.writeInt16(items[i]); } } @@ -195,9 +195,9 @@ static void informPlayer(MapComposite *map, Character *p) if ((oflags & UPDATEFLAG_ATTACK) && oid != pid) { MessageOut AttackMsg(GPMSG_BEING_ATTACK); - AttackMsg.writeShort(oid); - AttackMsg.writeByte(o->getDirection()); - AttackMsg.writeByte(static_cast< Being * >(o)->getAttackType()); + AttackMsg.writeInt16(oid); + AttackMsg.writeInt8(o->getDirection()); + AttackMsg.writeInt8(static_cast< Being * >(o)->getAttackType()); gameHandler->sendTo(p, AttackMsg); } @@ -205,8 +205,8 @@ static void informPlayer(MapComposite *map, Character *p) if ((oflags & UPDATEFLAG_ACTIONCHANGE)) { MessageOut ActionMsg(GPMSG_BEING_ACTION_CHANGE); - ActionMsg.writeShort(oid); - ActionMsg.writeByte(static_cast< Being * >(o)->getAction()); + ActionMsg.writeInt16(oid); + ActionMsg.writeInt8(static_cast< Being * >(o)->getAction()); gameHandler->sendTo(p, ActionMsg); } @@ -214,12 +214,12 @@ static void informPlayer(MapComposite *map, Character *p) if (oflags & UPDATEFLAG_LOOKSCHANGE) { MessageOut LooksMsg(GPMSG_BEING_LOOKS_CHANGE); - LooksMsg.writeShort(oid); + LooksMsg.writeInt16(oid); Character * c = static_cast<Character * >(o); serializeLooks(c, LooksMsg, false); - LooksMsg.writeShort(c->getHairStyle()); - LooksMsg.writeShort(c->getHairColor()); - LooksMsg.writeShort(c->getGender()); + LooksMsg.writeInt16(c->getHairStyle()); + LooksMsg.writeInt16(c->getHairColor()); + LooksMsg.writeInt16(c->getGender()); gameHandler->sendTo(p, LooksMsg); } @@ -227,8 +227,8 @@ static void informPlayer(MapComposite *map, Character *p) if (oflags & UPDATEFLAG_DIRCHANGE) { MessageOut DirMsg(GPMSG_BEING_DIR_CHANGE); - DirMsg.writeShort(oid); - DirMsg.writeByte(o->getDirection()); + DirMsg.writeInt16(oid); + DirMsg.writeInt8(o->getDirection()); gameHandler->sendTo(p, DirMsg); } @@ -240,8 +240,8 @@ static void informPlayer(MapComposite *map, Character *p) for (Hits::const_iterator j = hits.begin(), j_end = hits.end(); j != j_end; ++j) { - damageMsg.writeShort(oid); - damageMsg.writeShort(*j); + damageMsg.writeInt16(oid); + damageMsg.writeInt16(*j); } } @@ -256,7 +256,7 @@ static void informPlayer(MapComposite *map, Character *p) { // o is no longer visible from p. Send leave message. MessageOut leaveMsg(GPMSG_BEING_LEAVE); - leaveMsg.writeShort(oid); + leaveMsg.writeInt16(oid); gameHandler->sendTo(p, leaveMsg); continue; } @@ -265,34 +265,34 @@ static void informPlayer(MapComposite *map, Character *p) { // o is now visible by p. Send enter message. MessageOut enterMsg(GPMSG_BEING_ENTER); - enterMsg.writeByte(otype); - enterMsg.writeShort(oid); - enterMsg.writeByte(static_cast< Being *>(o)->getAction()); - enterMsg.writeShort(opos.x); - enterMsg.writeShort(opos.y); + enterMsg.writeInt8(otype); + enterMsg.writeInt16(oid); + enterMsg.writeInt8(static_cast< Being *>(o)->getAction()); + enterMsg.writeInt16(opos.x); + enterMsg.writeInt16(opos.y); switch (otype) { case OBJECT_CHARACTER: { Character *q = static_cast< Character * >(o); enterMsg.writeString(q->getName()); - enterMsg.writeByte(q->getHairStyle()); - enterMsg.writeByte(q->getHairColor()); - enterMsg.writeByte(q->getGender()); + enterMsg.writeInt8(q->getHairStyle()); + enterMsg.writeInt8(q->getHairColor()); + enterMsg.writeInt8(q->getGender()); serializeLooks(q, enterMsg, true); } break; case OBJECT_MONSTER: { Monster *q = static_cast< Monster * >(o); - enterMsg.writeShort(q->getSpecy()->getId()); + enterMsg.writeInt16(q->getSpecy()->getId()); enterMsg.writeString(q->getName()); } break; case OBJECT_NPC: { NPC *q = static_cast< NPC * >(o); - enterMsg.writeShort(q->getNPC()); + enterMsg.writeInt16(q->getNPC()); enterMsg.writeString(q->getName()); } break; @@ -308,16 +308,16 @@ static void informPlayer(MapComposite *map, Character *p) } // Send move messages. - moveMsg.writeShort(oid); - moveMsg.writeByte(flags); + moveMsg.writeInt16(oid); + moveMsg.writeInt8(flags); if (flags & MOVING_POSITION) { - moveMsg.writeShort(opos.x); - moveMsg.writeShort(opos.y); + moveMsg.writeInt16(opos.x); + moveMsg.writeInt16(opos.y); // We multiply the sent speed (in tiles per second) by ten // to get it within a byte with decimal precision. // For instance, a value of 4.5 will be sent as 45. - moveMsg.writeByte((unsigned short) + moveMsg.writeInt8((unsigned short) (o->getModifiedAttribute(ATTR_MOVE_SPEED_TPS) * 10)); } } @@ -348,9 +348,9 @@ static void informPlayer(MapComposite *map, Character *p) if (cflags & UPDATEFLAG_HEALTHCHANGE) { MessageOut healthMsg(GPMSG_BEING_HEALTH_CHANGE); - healthMsg.writeShort(c->getPublicID()); - healthMsg.writeShort(c->getModifiedAttribute(ATTR_HP)); - healthMsg.writeShort(c->getModifiedAttribute(ATTR_MAX_HP)); + healthMsg.writeInt16(c->getPublicID()); + healthMsg.writeInt16(c->getModifiedAttribute(ATTR_HP)); + healthMsg.writeInt16(c->getModifiedAttribute(ATTR_MAX_HP)); gameHandler->sendTo(p, healthMsg); } } @@ -383,16 +383,16 @@ static void informPlayer(MapComposite *map, Character *p) /* Send a specific message to the client when an item appears out of nowhere, so that a sound/animation can be performed. */ MessageOut appearMsg(GPMSG_ITEM_APPEAR); - appearMsg.writeShort(o->getItemClass()->getDatabaseID()); - appearMsg.writeShort(opos.x); - appearMsg.writeShort(opos.y); + appearMsg.writeInt16(o->getItemClass()->getDatabaseID()); + appearMsg.writeInt16(opos.x); + appearMsg.writeInt16(opos.y); gameHandler->sendTo(p, appearMsg); } else { - itemMsg.writeShort(willBeInRange ? o->getItemClass()->getDatabaseID() : 0); - itemMsg.writeShort(opos.x); - itemMsg.writeShort(opos.y); + itemMsg.writeInt16(willBeInRange ? o->getItemClass()->getDatabaseID() : 0); + itemMsg.writeInt16(opos.x); + itemMsg.writeInt16(opos.y); } } break; @@ -407,14 +407,14 @@ static void informPlayer(MapComposite *map, Character *p) if (b) { MessageOut effectMsg(GPMSG_CREATE_EFFECT_BEING); - effectMsg.writeShort(o->getEffectId()); - effectMsg.writeShort(b->getPublicID()); + effectMsg.writeInt16(o->getEffectId()); + effectMsg.writeInt16(b->getPublicID()); gameHandler->sendTo(p, effectMsg); } else { MessageOut effectMsg(GPMSG_CREATE_EFFECT_POS); - effectMsg.writeShort(o->getEffectId()); - effectMsg.writeShort(opos.x); - effectMsg.writeShort(opos.y); + effectMsg.writeInt16(o->getEffectId()); + effectMsg.writeInt16(opos.x); + effectMsg.writeInt16(opos.y); gameHandler->sendTo(p, effectMsg); } } @@ -593,8 +593,8 @@ bool GameState::insert(Thing *ptr) connects to this server. */ MessageOut mapChangeMessage(GPMSG_PLAYER_MAP_CHANGE); mapChangeMessage.writeString(map->getName()); - mapChangeMessage.writeShort(pos.x); - mapChangeMessage.writeShort(pos.y); + mapChangeMessage.writeInt16(pos.x); + mapChangeMessage.writeInt16(pos.y); gameHandler->sendTo(static_cast< Character * >(obj), mapChangeMessage); // update the online state of the character @@ -665,7 +665,7 @@ void GameState::remove(Thing *ptr) Actor *obj = static_cast< Actor * >(ptr); MessageOut msg(GPMSG_BEING_LEAVE); - msg.writeShort(obj->getPublicID()); + msg.writeInt16(obj->getPublicID()); Point objectPos = obj->getPosition(); for (CharacterIterator p(map->getAroundActorIterator(obj, visualRange)); @@ -683,9 +683,9 @@ void GameState::remove(Thing *ptr) Item *obj = static_cast< Item * >(ptr); Point pos = obj->getPosition(); MessageOut msg(GPMSG_ITEMS); - msg.writeShort(0); - msg.writeShort(pos.x); - msg.writeShort(pos.y); + msg.writeInt16(0); + msg.writeInt16(pos.x); + msg.writeInt16(pos.y); for (CharacterIterator p(map->getAroundActorIterator(obj, visualRange)); p; ++p) { @@ -722,7 +722,7 @@ void GameState::warp(Character *ptr, MapComposite *map, int x, int y) else { MessageOut msg(GAMSG_REDIRECT); - msg.writeLong(ptr->getDatabaseID()); + msg.writeInt32(ptr->getDatabaseID()); accountHandler->send(msg); gameHandler->prepareServerChange(ptr); } @@ -782,15 +782,15 @@ void GameState::sayTo(Actor *destination, Actor *source, const std::string &text MessageOut msg(GPMSG_SAY); if (source == NULL) { - msg.writeShort(0); + msg.writeInt16(0); } else if (!source->canMove()) { - msg.writeShort(65535); + msg.writeInt16(65535); } else { - msg.writeShort(static_cast< Actor * >(source)->getPublicID()); + msg.writeInt16(static_cast< Actor * >(source)->getPublicID()); } msg.writeString(text); @@ -802,7 +802,7 @@ void GameState::sayToAll(const std::string &text) MessageOut msg(GPMSG_SAY); // The message will be shown as if it was from the server - msg.writeShort(0); + msg.writeInt16(0); msg.writeString(text); // Sends it to everyone connected to the game server diff --git a/src/game-server/trade.cpp b/src/game-server/trade.cpp index e2f1cd0c..1c197c77 100644 --- a/src/game-server/trade.cpp +++ b/src/game-server/trade.cpp @@ -41,7 +41,7 @@ Trade::Trade(Character *c1, Character *c2): mChar1(c1), mChar2(c2), mMoney1(0), mMoney2(0), mState(TRADE_INIT), mCurrencyId(ATTR_GP) { MessageOut msg(GPMSG_TRADE_REQUEST); - msg.writeShort(c1->getPublicID()); + msg.writeInt16(c1->getPublicID()); c2->getClient()->send(msg); c1->setTrading(this); c2->setTrading(this); @@ -202,7 +202,7 @@ void Trade::setMoney(Character *c, int amount) the client lied. */ MessageOut msg(GPMSG_TRADE_SET_MONEY); - msg.writeLong(amount); + msg.writeInt32(amount); if (c == mChar1) { @@ -255,7 +255,7 @@ void Trade::addItem(Character *c, int slot, int amount) items->push_back(ti); MessageOut msg(GPMSG_TRADE_ADD_ITEM); - msg.writeShort(id); - msg.writeByte(amount); + msg.writeInt16(id); + msg.writeInt8(amount); other->getClient()->send(msg); } diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 63fd8778..7d6de273 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -36,10 +36,10 @@ MessageIn::MessageIn(const char *data, int length): mPos(0) { // Read the message ID - mId = readShort(); + mId = readInt16(); } -int MessageIn::readByte() +int MessageIn::readInt8() { int value = -1; if (mPos < mLength) @@ -51,7 +51,7 @@ int MessageIn::readByte() return value; } -int MessageIn::readShort() +int MessageIn::readInt16() { int value = -1; if (mPos + 2 <= mLength) @@ -65,7 +65,7 @@ int MessageIn::readShort() return value; } -int MessageIn::readLong() +int MessageIn::readInt32() { int value = -1; if (mPos + 4 <= mLength) @@ -87,7 +87,7 @@ double MessageIn::readDouble() memcpy(&value, mData + mPos, sizeof(double)); mPos += sizeof(double); #else - int length = readByte(); + int length = readInt8(); std::istringstream i (readString(length)); i >> value; #endif @@ -99,7 +99,7 @@ std::string MessageIn::readString(int length) // Get string length if (length < 0) { - length = readShort(); + length = readInt16(); } // Make sure the string isn't erroneous diff --git a/src/net/messagein.hpp b/src/net/messagein.hpp index c6e49ab5..f01c1850 100644 --- a/src/net/messagein.hpp +++ b/src/net/messagein.hpp @@ -44,9 +44,10 @@ class MessageIn */ int getLength() const { return mLength; } - int readByte(); /**< Reads a byte. */ - int readShort(); /**< Reads a short. */ - int readLong(); /**< Reads a long. */ + int readInt8(); /**< Reads a byte. */ + int readInt16(); /**< Reads a short. */ + int readInt32(); /**< Reads a long. */ + /** * Reads a double. HACKY and should *not* be used for client * communication! diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 950da5f3..c8310c55 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -49,7 +49,7 @@ MessageOut::MessageOut(int id): mData = (char*) malloc(INITIAL_DATA_CAPACITY); mDataSize = INITIAL_DATA_CAPACITY; - writeShort(id); + writeInt16(id); } MessageOut::~MessageOut() @@ -79,14 +79,14 @@ MessageOut::expand(size_t bytes) } } -void MessageOut::writeByte(int value) +void MessageOut::writeInt8(int value) { expand(mPos + 1); mData[mPos] = value; mPos += 1; } -void MessageOut::writeShort(int value) +void MessageOut::writeInt16(int value) { expand(mPos + 2); uint16_t t = ENET_HOST_TO_NET_16(value); @@ -94,7 +94,7 @@ void MessageOut::writeShort(int value) mPos += 2; } -void MessageOut::writeLong(int value) +void MessageOut::writeInt32(int value) { expand(mPos + 4); uint32_t t = ENET_HOST_TO_NET_32(value); @@ -116,7 +116,7 @@ void MessageOut::writeDouble(double value) o.precision(std::numeric_limits< double >::digits10); o << value; std::string str = o.str(); - writeByte(str.size()); + writeInt8(str.size()); writeString(str, str.size()); #endif } @@ -138,7 +138,7 @@ MessageOut::writeString(const std::string &string, int length) if (length < 0) { // Write the length at the start if not fixed - writeShort(stringLength); + writeInt16(stringLength); length = stringLength; } else if (length < stringLength) diff --git a/src/net/messageout.hpp b/src/net/messageout.hpp index 270b7963..cf3e0c73 100644 --- a/src/net/messageout.hpp +++ b/src/net/messageout.hpp @@ -49,11 +49,11 @@ class MessageOut */ void clear(); - void writeByte(int value); /**< Writes an integer on one byte. */ + void writeInt8(int value); /**< Writes an integer on one byte. */ - void writeShort(int value); /**< Writes an integer on two bytes. */ + void writeInt16(int value); /**< Writes an integer on two bytes. */ - void writeLong(int value); /**< Writes an integer on four bytes. */ + void writeInt32(int value); /**< Writes an integer on four bytes. */ /** * Writes a double. HACKY and should *not* be used for client diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index c186be8b..410b1cbf 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -77,7 +77,7 @@ static int npc_message(lua_State *s) return 0; } MessageOut msg(GPMSG_NPC_MESSAGE); - msg.writeShort(p->getPublicID()); + msg.writeInt16(p->getPublicID()); msg.writeString(std::string(m), l); gameHandler->sendTo(q, msg); return 1; @@ -97,7 +97,7 @@ static int npc_choice(lua_State *s) return 0; } MessageOut msg(GPMSG_NPC_CHOICE); - msg.writeShort(p->getPublicID()); + msg.writeInt16(p->getPublicID()); for (int i = 3, i_end = lua_gettop(s); i <= i_end; ++i) { if (lua_isstring(s, i)) @@ -144,7 +144,7 @@ static int npc_ask_integer(lua_State *s) return 0; } MessageOut msg(GPMSG_NPC_NUMBER); - msg.writeShort(p->getPublicID()); + msg.writeInt16(p->getPublicID()); int min = lua_tointeger(s, 3); int max = lua_tointeger(s, 4); @@ -152,9 +152,9 @@ static int npc_ask_integer(lua_State *s) if (lua_gettop(s) == 5) default_num = lua_tointeger(s, 5); - msg.writeLong(min); - msg.writeLong(max); - msg.writeLong(default_num); + msg.writeInt32(min); + msg.writeInt32(max); + msg.writeInt32(default_num); gameHandler->sendTo(q, msg); return 0; @@ -174,7 +174,7 @@ static int npc_ask_string(lua_State *s) return 0; } MessageOut msg(GPMSG_NPC_STRING); - msg.writeShort(p->getPublicID()); + msg.writeInt16(p->getPublicID()); gameHandler->sendTo(q, msg); return 0; @@ -222,7 +222,7 @@ static int npc_end(lua_State *s) } MessageOut msg(GPMSG_NPC_CLOSE); - msg.writeShort(p->getPublicID()); + msg.writeInt16(p->getPublicID()); gameHandler->sendTo(q, msg); return 0; } @@ -243,7 +243,7 @@ static int npc_post(lua_State *s) } MessageOut msg(GPMSG_NPC_POST); - msg.writeShort(p->getPublicID()); + msg.writeInt16(p->getPublicID()); gameHandler->sendTo(q, msg); return 0; diff --git a/src/serialize/characterdata.hpp b/src/serialize/characterdata.hpp index 6e1facc8..bf08dc14 100644 --- a/src/serialize/characterdata.hpp +++ b/src/serialize/characterdata.hpp @@ -33,85 +33,85 @@ template< class T > void serializeCharacterData(const T &data, MessageOut &msg) { // general character properties - msg.writeByte(data.getAccountLevel()); - msg.writeByte(data.getGender()); - msg.writeByte(data.getHairStyle()); - msg.writeByte(data.getHairColor()); - msg.writeShort(data.getLevel()); - msg.writeShort(data.getCharacterPoints()); - msg.writeShort(data.getCorrectionPoints()); - - msg.writeShort(data.mAttributes.size()); + msg.writeInt8(data.getAccountLevel()); + msg.writeInt8(data.getGender()); + msg.writeInt8(data.getHairStyle()); + msg.writeInt8(data.getHairColor()); + msg.writeInt16(data.getLevel()); + msg.writeInt16(data.getCharacterPoints()); + msg.writeInt16(data.getCorrectionPoints()); + + msg.writeInt16(data.mAttributes.size()); AttributeMap::const_iterator attr_it, attr_it_end; for (attr_it = data.mAttributes.begin(), attr_it_end = data.mAttributes.end(); attr_it != attr_it_end; ++attr_it) { - msg.writeShort(attr_it->first); + msg.writeInt16(attr_it->first); msg.writeDouble(data.getAttrBase(attr_it)); msg.writeDouble(data.getAttrMod(attr_it)); } // character skills - msg.writeShort(data.getSkillSize()); + msg.writeInt16(data.getSkillSize()); std::map<int, int>::const_iterator skill_it; for (skill_it = data.getSkillBegin(); skill_it != data.getSkillEnd() ; skill_it++) { - msg.writeShort(skill_it->first); - msg.writeLong(skill_it->second); + msg.writeInt16(skill_it->first); + msg.writeInt32(skill_it->second); } // status effects currently affecting the character - msg.writeShort(data.getStatusEffectSize()); + msg.writeInt16(data.getStatusEffectSize()); std::map<int, int>::const_iterator status_it; for (status_it = data.getStatusEffectBegin(); status_it != data.getStatusEffectEnd(); status_it++) { - msg.writeShort(status_it->first); - msg.writeShort(status_it->second); + msg.writeInt16(status_it->first); + msg.writeInt16(status_it->second); } // location - msg.writeShort(data.getMapId()); + msg.writeInt16(data.getMapId()); const Point &pos = data.getPosition(); - msg.writeShort(pos.x); - msg.writeShort(pos.y); + msg.writeInt16(pos.x); + msg.writeInt16(pos.y); // kill count - msg.writeShort(data.getKillCountSize()); + msg.writeInt16(data.getKillCountSize()); std::map<int, int>::const_iterator kills_it; for (kills_it = data.getKillCountBegin(); kills_it != data.getKillCountEnd(); kills_it++) { - msg.writeShort(kills_it->first); - msg.writeLong(kills_it->second); + msg.writeInt16(kills_it->first); + msg.writeInt32(kills_it->second); } // character specials std::map<int, Special*>::const_iterator special_it; - msg.writeShort(data.getSpecialSize()); + msg.writeInt16(data.getSpecialSize()); for (special_it = data.getSpecialBegin(); special_it != data.getSpecialEnd() ; special_it++) { - msg.writeLong(special_it->first); + msg.writeInt32(special_it->first); } // inventory - must be last because size isn't transmitted const Possessions &poss = data.getPossessions(); - msg.writeShort(poss.equipSlots.size()); // number of equipment + msg.writeInt16(poss.equipSlots.size()); // number of equipment for (EquipData::const_iterator k = poss.equipSlots.begin(), k_end = poss.equipSlots.end(); k != k_end; ++k) { - msg.writeByte(k->first); // Equip slot type - msg.writeShort(k->second); // Inventory slot + msg.writeInt8(k->first); // Equip slot type + msg.writeInt16(k->second); // Inventory slot } for (InventoryData::const_iterator j = poss.inventory.begin(), j_end = poss.inventory.end(); j != j_end; ++j) { - msg.writeShort(j->first); // slot id - msg.writeShort(j->second.itemId); // item type - msg.writeShort(j->second.amount); // amount + msg.writeInt16(j->first); // slot id + msg.writeInt16(j->second.itemId); // item type + msg.writeInt16(j->second.amount); // amount } } @@ -119,19 +119,19 @@ template< class T > void deserializeCharacterData(T &data, MessageIn &msg) { // general character properties - data.setAccountLevel(msg.readByte()); - data.setGender(msg.readByte()); - data.setHairStyle(msg.readByte()); - data.setHairColor(msg.readByte()); - data.setLevel(msg.readShort()); - data.setCharacterPoints(msg.readShort()); - data.setCorrectionPoints(msg.readShort()); + data.setAccountLevel(msg.readInt8()); + data.setGender(msg.readInt8()); + data.setHairStyle(msg.readInt8()); + data.setHairColor(msg.readInt8()); + data.setLevel(msg.readInt16()); + data.setCharacterPoints(msg.readInt16()); + data.setCorrectionPoints(msg.readInt16()); // character attributes - unsigned int attrSize = msg.readShort(); + unsigned int attrSize = msg.readInt16(); for (unsigned int i = 0; i < attrSize; ++i) { - unsigned int id = msg.readShort(); + unsigned int id = msg.readInt16(); double base = msg.readDouble(), mod = msg.readDouble(); data.setAttribute(id, base); @@ -139,62 +139,62 @@ void deserializeCharacterData(T &data, MessageIn &msg) } // character skills - int skillSize = msg.readShort(); + int skillSize = msg.readInt16(); for (int i = 0; i < skillSize; ++i) { - int skill = msg.readShort(); - int level = msg.readLong(); + int skill = msg.readInt16(); + int level = msg.readInt32(); data.setExperience(skill,level); } // status effects currently affecting the character - int statusSize = msg.readShort(); + int statusSize = msg.readInt16(); for (int i = 0; i < statusSize; i++) { - int status = msg.readShort(); - int time = msg.readShort(); + int status = msg.readInt16(); + int time = msg.readInt16(); data.applyStatusEffect(status, time); } // location - data.setMapId(msg.readShort()); + data.setMapId(msg.readInt16()); Point temporaryPoint; - temporaryPoint.x = msg.readShort(); - temporaryPoint.y = msg.readShort(); + temporaryPoint.x = msg.readInt16(); + temporaryPoint.y = msg.readInt16(); data.setPosition(temporaryPoint); // kill count - int killSize = msg.readShort(); + int killSize = msg.readInt16(); for (int i = 0; i < killSize; i++) { - int monsterId = msg.readShort(); - int kills = msg.readLong(); + int monsterId = msg.readInt16(); + int kills = msg.readInt32(); data.setKillCount(monsterId, kills); } // character specials - int specialSize = msg.readShort(); + int specialSize = msg.readInt16(); data.clearSpecials(); for (int i = 0; i < specialSize; i++) { - data.giveSpecial(msg.readLong()); + data.giveSpecial(msg.readInt32()); } Possessions &poss = data.getPossessions(); poss.equipSlots.clear(); - int equipSlotsSize = msg.readShort(); + int equipSlotsSize = msg.readInt16(); unsigned int eqSlot, invSlot; for (int j = 0; j < equipSlotsSize; ++j) { - int equipmentInSlotType = msg.readByte(); + int equipmentInSlotType = msg.readInt8(); for (int k = 0; k < equipmentInSlotType; ++k) { - eqSlot = msg.readByte(); - invSlot = msg.readShort(); + eqSlot = msg.readInt8(); + invSlot = msg.readInt16(); poss.equipSlots.insert(poss.equipSlots.end(), std::make_pair(eqSlot, invSlot)); } @@ -204,9 +204,9 @@ void deserializeCharacterData(T &data, MessageIn &msg) while (msg.getUnreadLength()) { InventoryItem i; - int slotId = msg.readShort(); - i.itemId = msg.readShort(); - i.amount = msg.readShort(); + int slotId = msg.readInt16(); + i.itemId = msg.readInt16(); + i.amount = msg.readInt16(); poss.inventory.insert(poss.inventory.end(), std::make_pair(slotId, i)); } |