diff --git a/dependencies/gs2lib b/dependencies/gs2lib index e77215fd..0ce4d38a 160000 --- a/dependencies/gs2lib +++ b/dependencies/gs2lib @@ -1 +1 @@ -Subproject commit e77215fdf20296e6195d8a3b66390cb348f5dabe +Subproject commit 0ce4d38a4b42b10bd622465a3c896912ad4c9825 diff --git a/server/include/TPacket.h b/server/include/TPacket.h index 238e242f..0ee392ab 100644 --- a/server/include/TPacket.h +++ b/server/include/TPacket.h @@ -3,10 +3,7 @@ #define GS2EMU_TPACKET_H #include - #include "IEnums.h" -#include "CString.h" - template struct TPacket { @@ -14,9 +11,16 @@ struct TPacket { CString Data; }; +/* Player packets */ typedef TPacket PlayerOutPacket; typedef std::vector PlayerOutPackets; typedef TPacket PlayerInPacket; typedef std::vector PlayerInPackets; +/* ListServer packets */ +typedef TPacket ListServerOutPacket; +typedef std::vector ListServerOutPackets; +typedef TPacket ListServerInPacket; +typedef std::vector ListServerInPackets; + #endif //GS2EMU_TPACKET_H diff --git a/server/include/TServerList.h b/server/include/TServerList.h index c14681fd..34580773 100644 --- a/server/include/TServerList.h +++ b/server/include/TServerList.h @@ -2,11 +2,12 @@ #define TSERVERLIST_H #include -#include +#include +#include #include "CFileQueue.h" #include "CString.h" #include "CSocket.h" -#include +#include "TPacket.h" enum { @@ -36,13 +37,13 @@ class TServerList : public CSocketStub ~TServerList(); bool doTimedEvents(); - + // Socket-Control Functions bool getConnected() const; bool main(); bool connectServer(); CSocket* getSocket() { return &sock; } - void sendPacket(CString& pPacket, bool sendNow = false); + void sendPacket(const ListServerOutPacket& pPacket, bool sendNow = false); // Send players to the listserver void addPlayer(TPlayer *player); @@ -93,7 +94,7 @@ class TServerList : public CSocketStub void msgSVI_SENDTEXT(CString& pPacket); void msgSVI_PMPLAYER(CString& pPacket); void msgSVI_ASSIGNPCID(CString& pPacket); - + protected: // Packet Functions bool parsePacket(CString& pPacket); diff --git a/server/src/TPlayer/TPlayer.cpp b/server/src/TPlayer/TPlayer.cpp index a94044ba..5b04ab65 100644 --- a/server/src/TPlayer/TPlayer.cpp +++ b/server/src/TPlayer/TPlayer.cpp @@ -1071,7 +1071,7 @@ bool TPlayer::processChat(CString pChat) if (file.length() != 0) setProps(CString() >> (char)PLPROP_HEADGIF >> (char)(chatParse[1].length() + 100) << chatParse[1], PLSETPROPS_SETBYPLAYER | PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); else - server->getServerList()->sendPacket(CString() >> (char)SVO_GETFILE3 >> (short)id >> (char)0 >> (char)chatParse[1].length() << chatParse[1]); + server->getServerList()->sendPacket({SVO_GETFILE3, CString() >> (short)id >> (char)0 >> (char)chatParse[1].length() << chatParse[1]}); } else if (chatParse[0] == "setbody" && chatParse.size() == 2) { @@ -1118,7 +1118,7 @@ bool TPlayer::processChat(CString pChat) if (file.length() != 0) setProps(CString() >> (char)PLPROP_BODYIMG >> (char)chatParse[1].length() << chatParse[1], PLSETPROPS_SETBYPLAYER | PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); else - server->getServerList()->sendPacket(CString() >> (char)SVO_GETFILE3 >> (short)id >> (char)1 >> (char)chatParse[1].length() << chatParse[1]); + server->getServerList()->sendPacket({SVO_GETFILE3, CString() >> (short)id >> (char)1 >> (char)chatParse[1].length() << chatParse[1]}); } else if (chatParse[0] == "setsword" && chatParse.size() == 2) { @@ -1165,7 +1165,7 @@ bool TPlayer::processChat(CString pChat) if (file.length() != 0) setProps(CString() >> (char)PLPROP_SWORDPOWER >> (char)(swordPower + 30) >> (char)chatParse[1].length() << chatParse[1], PLSETPROPS_SETBYPLAYER | PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); else - server->getServerList()->sendPacket(CString() >> (char)SVO_GETFILE3 >> (short)id >> (char)2 >> (char)chatParse[1].length() << chatParse[1]); + server->getServerList()->sendPacket({SVO_GETFILE3, CString() >> (short)id >> (char)2 >> (char)chatParse[1].length() << chatParse[1]}); } else if (chatParse[0] == "setshield" && chatParse.size() == 2) { @@ -1212,7 +1212,7 @@ bool TPlayer::processChat(CString pChat) if (file.length() != 0) setProps(CString() >> (char)PLPROP_SHIELDPOWER >> (char)(shieldPower + 10) >> (char)chatParse[1].length() << chatParse[1], PLSETPROPS_SETBYPLAYER | PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); else - server->getServerList()->sendPacket(CString() >> (char)SVO_GETFILE3 >> (short)id >> (char)3 >> (char)chatParse[1].length() << chatParse[1]); + server->getServerList()->sendPacket({SVO_GETFILE3, CString() >> (short)id >> (char)3 >> (char)chatParse[1].length() << chatParse[1]}); } else if (chatParse[0] == "setskin" && chatParse.size() == 2 && setcolorsallowed) { @@ -2078,11 +2078,14 @@ void TPlayer::setNick(CString pNickName, bool force) if (askGlobal) { server->getServerList()->sendPacket( - CString() >> (char)SVO_VERIGUILD >> (short)id - >> (char)accountName.length() << accountName - >> (char)newNick.length() << newNick - >> (char)guild.length() << guild - ); + { + SVO_VERIGUILD, + CString() >> (short)id + >> (char)accountName.length() << accountName + >> (char)newNick.length() << newNick + >> (char)guild.length() << guild + } + ); } } else @@ -3928,7 +3931,7 @@ bool TPlayer::msgPLI_SERVERWARP(CString& pPacket) { CString servername = pPacket.readString(""); server->getServerLog().out("%s is requesting serverwarp to %s", accountName.text(), servername.text()); - server->getServerList()->sendPacket(CString() >> (char)SVO_SERVERINFO >> (short)id << servername); + server->getServerList()->sendPacket({SVO_SERVERINFO, CString() >> (short)id << servername}); return true; } @@ -3959,7 +3962,7 @@ bool TPlayer::msgPLI_RAWDATA(CString& pPacket) bool TPlayer::msgPLI_PROFILEGET(CString& pPacket) { // Send the packet ID for backwards compatibility. - server->getServerList()->sendPacket(CString() >> (char)SVO_GETPROF >> (short)id << pPacket); + server->getServerList()->sendPacket({SVO_GETPROF, CString() >> (short)id << pPacket}); return true; } @@ -3970,7 +3973,7 @@ bool TPlayer::msgPLI_PROFILESET(CString& pPacket) // Old gserver would send the packet ID with pPacket so, for // backwards compatibility, do that here. - server->getServerList()->sendPacket(CString() >> (char)SVO_SETPROF << pPacket); + server->getServerList()->sendPacket({SVO_SETPROF, CString() << pPacket}); return true; } diff --git a/server/src/TPlayer/TPlayerExternalPlayers.cpp b/server/src/TPlayer/TPlayerExternalPlayers.cpp index 3478de70..c60de3b8 100644 --- a/server/src/TPlayer/TPlayerExternalPlayers.cpp +++ b/server/src/TPlayer/TPlayerExternalPlayers.cpp @@ -12,9 +12,9 @@ bool TPlayer::addPMServer(CString& option) TServerList* list = server->getServerList(); bool PMSrvExist = false; - for (std::vector::const_iterator ij = PMServerList.begin(); ij != PMServerList.end(); ++ij) + for (const auto & ij : PMServerList) { - if ((ij)->text() == option) + if (ij.text() == option) { PMSrvExist = true; } @@ -23,7 +23,7 @@ bool TPlayer::addPMServer(CString& option) if (!PMSrvExist) { PMServerList.push_back(option); - list->sendPacket(CString() >> (char)SVO_REQUESTLIST >> (short)id << CString(CString() << "GraalEngine" << "\n" << "pmserverplayers" << "\n" << option << "\n").gtokenizeI()); + list->sendPacket({SVO_REQUESTLIST, CString() >> (short)id << CString(CString() << "GraalEngine" << "\n" << "pmserverplayers" << "\n" << option << "\n").gtokenizeI()}); return true; } else @@ -196,7 +196,7 @@ bool TPlayer::updatePMPlayers(CString& servername, CString& players) bool TPlayer::pmExternalPlayer(CString servername, CString account, CString& pmMessage) { TServerList* list = server->getServerList(); - list->sendPacket(CString() >> (char)SVO_PMPLAYER >> (short)id << CString(CString() << servername << "\n" << accountName << "\n" << nickName << "\n" << "GraalEngine" << "\n" << "pmplayer" << "\n" << account << "\n" << pmMessage).gtokenizeI()); + list->sendPacket(ListServerOutPacket{SVO_PMPLAYER, CString() >> (short)id << CString(CString() << servername << "\n" << accountName << "\n" << nickName << "\n" << "GraalEngine" << "\n" << "pmplayer" << "\n" << account << "\n" << pmMessage).gtokenizeI()}); return true; } diff --git a/server/src/TPlayer/TPlayerRequestText.cpp b/server/src/TPlayer/TPlayerRequestText.cpp index ba9dec9f..f5d960d9 100644 --- a/server/src/TPlayer/TPlayerRequestText.cpp +++ b/server/src/TPlayer/TPlayerRequestText.cpp @@ -17,9 +17,9 @@ bool TPlayer::msgPLI_REQUESTTEXT(CString& pPacket) if (type == "lister") { if (option == "simplelist") - list->sendPacket(CString() >> (char)SVO_REQUESTLIST >> (short)id << CString(weapon << "\n" << type << "\n" << "simpleserverlist" << "\n").gtokenizeI()); + list->sendPacket({SVO_REQUESTLIST, CString() >> (short)id << CString(weapon << "\n" << type << "\n" << "simpleserverlist" << "\n").gtokenizeI()}); else if (option == "rebornlist") - list->sendPacket(CString() >> (char)SVO_REQUESTLIST >> (short)id << packet); + list->sendPacket({SVO_REQUESTLIST, CString() >> (short)id << packet}); else if (option == "subscriptions") { // some versions of the loginserver scripts expected the response of subscriptions2 rather than subscriptions sendPacket({PLO_SERVERTEXT, CString() << CString(CString() << weapon << "\n" << type << "\n" << "subscriptions" << "\n" << CString(CString() << "unlimited" << "\n" << "Unlimited Subscription" << "\n" << "\"\"" << "\n").gtokenizeI()).gtokenizeI()}); @@ -29,12 +29,12 @@ bool TPlayer::msgPLI_REQUESTTEXT(CString& pPacket) else if (option == "getglobalitems") sendPacket({PLO_SERVERTEXT, CString() << CString(weapon << "\n" << type << "\n" << "globalitems" << "\n" << accountName.text() << "\n" << CString(CString(CString() << "autobill=1" << "\n" << "autobillmine=1" << "\n" << "bundle=1" << "\n" << "creationtime=1212768763" << "\n" << "currenttime=1353248504" << "\n" << "description=Gives" << "\n" << "duration=2629800" << "\n" << "flags=subscription" << "\n" << "icon=graalicon_big.png" << "\n" << "itemid=1" << "\n" << "lifetime=1" << "\n" << "owner=global" << "\n" << "ownertype=server" << "\n" << "price=100" << "\n" << "quantity=988506" << "\n" << "status=available" << "\n" << "title=Gold" << "\n" << "tradable=1" << "\n" << "typeid=62" << "\n" << "world=global" << "\n").gtokenizeI()).gtokenizeI()).gtokenizeI()}); else if (option == "serverinfo") { - list->sendPacket(CString() >> (char)SVO_REQUESTSVRINFO >> (short)id << packet); + list->sendPacket({SVO_REQUESTSVRINFO, CString() >> (short)id << packet}); } } else if (type == "pmservers" || type == "pmguilds") { - list->sendPacket(CString() >> (char)SVO_REQUESTLIST >> (short)id << packet); + list->sendPacket({SVO_REQUESTLIST, CString() >> (short)id << packet}); } else if (type == "pmserverplayers") addPMServer(option); @@ -146,7 +146,7 @@ bool TPlayer::msgPLI_SENDTEXT(CString& pPacket) else if (type == "lister") { if (option == "serverinfo") - list->sendPacket(CString() >> (char)SVO_REQUESTSVRINFO >> (short)id << packet); + list->sendPacket({SVO_REQUESTSVRINFO, CString() >> (short)id << packet}); if (!getGuest()) { diff --git a/server/src/TServerList.cpp b/server/src/TServerList.cpp index 94f93a32..8cc5b712 100644 --- a/server/src/TServerList.cpp +++ b/server/src/TServerList.cpp @@ -227,28 +227,33 @@ bool TServerList::connectServer() // Use the new protocol for communicating with the listserver _fileQueue.setCodec(ENCRYPT_GEN_1, 0); - sendPacket(CString() >> (char)SVO_REGISTERV3 << version, true); + sendPacket({SVO_REGISTERV3, CString() << version}, true); _fileQueue.setCodec(ENCRYPT_GEN_2, 0); // Send before SVO_NEWSERVER or else we will get an incorrect name. CSettings* adminsettings = _server->getAdminSettings(); - sendPacket(CString() >> (char)SVO_SERVERHQPASS << adminsettings->getStr("hq_password")); + sendPacket({SVO_SERVERHQPASS, CString() << adminsettings->getStr("hq_password")}); // Send server info. - sendPacket(CString() >> (char)SVO_NEWSERVER - >> (char)name.length() << name - >> (char)desc.length() << desc - >> (char)language.length() << language - >> (char)version.length() << version - >> (char)url.length() << url - >> (char)ip.length() << ip - >> (char)port.length() << port - >> (char)localip.length() << localip); + sendPacket( + { + SVO_NEWSERVER, + CString() + >> (char)name.length() << name + >> (char)desc.length() << desc + >> (char)language.length() << language + >> (char)version.length() << version + >> (char)url.length() << url + >> (char)ip.length() << ip + >> (char)port.length() << port + >> (char)localip.length() << localip + } + ); // Set the level now. if(_server->getSettings()->getBool("onlystaff", false)) - sendPacket(CString() >> (char)SVO_SERVERHQLEVEL >> (char)0); - else sendPacket(CString() >> (char)SVO_SERVERHQLEVEL >> (char)adminsettings->getInt("hq_level", 1)); + sendPacket({SVO_SERVERHQLEVEL, CString() >> (char)0}); + else sendPacket({SVO_SERVERHQLEVEL, CString() >> (char)adminsettings->getInt("hq_level", 1)}); sendVersionConfig(); @@ -278,18 +283,19 @@ void TServerList::sendVersionConfig() sendText(fmt::format("Listserver,settings,allowedversions,{}", versionNames.text())); } -void TServerList::sendPacket(CString& pPacket, bool sendNow) +void TServerList::sendPacket(const ListServerOutPacket& pPacket, bool sendNow) { // empty buffer? - if (pPacket.isEmpty()) + if (pPacket.Data.isEmpty()) return; + CString packet = CString() >> (char)pPacket.Id << pPacket.Data; // append '\n' - if (pPacket[pPacket.length()-1] != '\n') - pPacket.writeChar('\n'); + if (packet[packet.length()-1] != '\n') + packet.writeChar('\n'); // append buffer - _fileQueue.addPacket(pPacket); + _fileQueue.addPacket(packet); // send buffer now? if (sendNow) @@ -304,7 +310,7 @@ void TServerList::addPlayer(TPlayer *player) assert(player != nullptr); CString dataPacket; - dataPacket >> (char)SVO_PLYRADD >> (short)player->getId() >> (char)player->getType(); + dataPacket >> (short)player->getId() >> (char)player->getType(); dataPacket >> (char)PLPROP_ACCOUNTNAME << player->getProp(PLPROP_ACCOUNTNAME); dataPacket >> (char)PLPROP_NICKNAME << player->getProp(PLPROP_NICKNAME); dataPacket >> (char)PLPROP_CURLEVEL << player->getProp(PLPROP_CURLEVEL); @@ -312,20 +318,20 @@ void TServerList::addPlayer(TPlayer *player) dataPacket >> (char)PLPROP_Y << player->getProp(PLPROP_Y); dataPacket >> (char)PLPROP_ALIGNMENT << player->getProp(PLPROP_ALIGNMENT); dataPacket >> (char)PLPROP_IPADDR << player->getProp(PLPROP_IPADDR); - sendPacket(dataPacket); + sendPacket({SVO_PLYRADD, dataPacket}); } void TServerList::deletePlayer(TPlayer *player) { assert(player != nullptr); - sendPacket(CString() >> (char)SVO_PLYRREM >> (short)player->getId()); + sendPacket({SVO_PLYRREM, CString() >> (short)player->getId()}); } void TServerList::sendPlayers() { // Clears the serverlist players - sendPacket(CString() >> (char)SVO_SETPLYR); + sendPacket({SVO_SETPLYR, CString()}); // Adds the players to the serverlist auto playerList = _server->getPlayerList(); @@ -405,48 +411,45 @@ void TServerList::handleText(const CString& data) void TServerList::sendText(const CString& data) { - CString dataPacket; - dataPacket.writeGChar(SVO_SENDTEXT); - dataPacket << data; - sendPacket(dataPacket); + sendPacket({SVO_SENDTEXT, data}); } void TServerList::sendText(const std::vector& stringList) { CString dataPacket; - dataPacket.writeGChar(SVO_SENDTEXT); for (const auto & string : stringList) dataPacket << string.gtokenize(); - sendPacket(dataPacket); + sendPacket({SVO_SENDTEXT, dataPacket}); } void TServerList::sendTextForPlayer(TPlayer *player, const CString& data) { assert(player != nullptr); - CString dataPacket; - dataPacket.writeGChar(SVO_REQUESTLIST); - dataPacket >> (short)player->getId() << data; - sendPacket(dataPacket); + sendPacket({SVO_REQUESTLIST, CString() >> (short)player->getId() << data}); } void TServerList::sendLoginPacketForPlayer(TPlayer *player, const CString& password, const CString& identity) { - sendPacket(CString() >> (char)SVO_VERIACC2 - >> (char)player->getAccountName().length() << player->getAccountName() - >> (char)password.length() << password - >> (short)player->getId() >> (char)player->getType() - >> (short)identity.length() << identity - ); + sendPacket( + { + SVO_VERIACC2, + CString() + >> (char)player->getAccountName().length() << player->getAccountName() + >> (char)password.length() << password + >> (short)player->getId() >> (char)player->getType() + >> (short)identity.length() << identity + } + ); } void TServerList::sendServerHQ() { CSettings* adminsettings = _server->getAdminSettings(); - sendPacket(CString() >> (char)SVO_SERVERHQPASS << adminsettings->getStr("hq_password")); + sendPacket({SVO_SERVERHQPASS, CString() << adminsettings->getStr("hq_password")}); if(_server->getSettings()->getBool("onlystaff", false)) - sendPacket(CString() >> (char)SVO_SERVERHQLEVEL >> (char)0); - else sendPacket(CString() >> (char)SVO_SERVERHQLEVEL >> (char)adminsettings->getInt("hq_level", 1)); + sendPacket({SVO_SERVERHQLEVEL, CString() >> (char)0}); + else sendPacket({SVO_SERVERHQLEVEL, CString() >> (char)adminsettings->getInt("hq_level", 1)}); } /* @@ -728,7 +731,7 @@ void TServerList::msgSVI_FILEEND2(CString& pPacket) void TServerList::msgSVI_PING(CString& pPacket) { // When server pings, we pong - sendPacket(CString() >> (char)SVO_PING); + sendPacket({SVO_PING, CString()}); } void TServerList::msgSVI_RAWDATA(CString& pPacket)