From 6f8fe312921187baadf1ff797d2b5093f56b1a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=BB=E4=BD=93?= Date: Sun, 19 Feb 2023 22:51:27 +0100 Subject: [PATCH] Update how packets are sent to player --- server/include/TPlayer.h | 23 +- server/include/TServer.h | 16 +- server/src/Misc/CWordFilter.cpp | 804 +++--- server/src/Scripting/v8/V8LevelImpl.cpp | 2 +- server/src/Scripting/v8/V8PlayerImpl.cpp | 6 +- server/src/TLevel/TLevel.cpp | 18 +- server/src/TLevel/TLevelBaddy.cpp | 458 ++-- server/src/TNPC.cpp | 20 +- server/src/TPlayer/TPlayer.cpp | 409 ++- server/src/TPlayer/TPlayerExternalPlayers.cpp | 12 +- server/src/TPlayer/TPlayerLogin.cpp | 131 +- server/src/TPlayer/TPlayerNC.cpp | 59 +- server/src/TPlayer/TPlayerProps.cpp | 2292 ++++++++--------- server/src/TPlayer/TPlayerRC.cpp | 392 +-- server/src/TPlayer/TPlayerRequestText.cpp | 14 +- server/src/TPlayer/TPlayerScripts.cpp | 18 +- server/src/TPlayer/TPlayerUpdatePackages.cpp | 23 +- server/src/TServer.cpp | 81 +- server/src/TServerList.cpp | 24 +- server/src/TriggerCommandHandlers.cpp | 30 +- 20 files changed, 2415 insertions(+), 2417 deletions(-) diff --git a/server/include/TPlayer.h b/server/include/TPlayer.h index a8e8be89..d1a0c09b 100644 --- a/server/include/TPlayer.h +++ b/server/include/TPlayer.h @@ -1,7 +1,7 @@ #ifndef TPLAYER_H #define TPLAYER_H -#include +#include #include #include #include @@ -15,8 +15,6 @@ #ifdef V8NPCSERVER #include "ScriptBindings.h" -#include "TPacket.h" - #endif class TLevel; @@ -106,10 +104,17 @@ class TPlayer : public TAccount, public CSocketStub // Socket-Functions bool doMain(); - template - void sendPacket(const TPacket& packet, bool sendNow = false, bool appendNL = true) { sendPacket((unsigned char)packet.Id, packet.Data, sendNow, appendNL); }; - void sendPacket(unsigned char packetId, const CString& pPacket, bool sendNow = false, bool appendNL = true); - void sendPacketOld(CString pPacket, bool appendNL = true); + void sendPacket(const PlayerOutPacket& packet, bool sendNow = false, bool appendNL = true) { + if (newProtocol) + { + sendPacketNewProtocol((unsigned char)packet.Id, packet.Data, sendNow, appendNL); + } + else + { + sendPacketOldProtocol(CString() >> (char)packet.Id << packet.Data, appendNL); + } + }; + bool sendFile(const CString& pFile); bool sendFile(const CString& pPath, const CString& pFile); @@ -309,6 +314,10 @@ class TPlayer : public TAccount, public CSocketStub bool newProtocol; private: + // SendPacket functions. + void sendPacketNewProtocol(unsigned char packetId, const CString& pPacket, bool sendNow = false, bool appendNL = true); + void sendPacketOldProtocol(CString pPacket, bool appendNL = true); + // Login functions. bool sendLoginClient(); bool sendLoginNC(); diff --git a/server/include/TServer.h b/server/include/TServer.h index d47024bf..783b95e7 100644 --- a/server/include/TServer.h +++ b/server/include/TServer.h @@ -201,12 +201,12 @@ class TServer : public CSocketStub // Packet sending. using PlayerPredicate = std::function; - void sendPacketToAll(char packetId, CString pPacket, TPlayer *pSender) const; - void sendPacketToLevel(char packetId, CString pPacket, TLevel* pLevel, TPlayer* pPlayer = 0) const; - void sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TLevel* pLevel, TPlayer* pPlayer = 0, bool onlyGmap = false) const; - void sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf = false, bool onlyGmap = false) const; - void sendPacketToLevel(PlayerPredicate predicate, char packetId, CString pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf = false, bool onlyGmap = false) const; - void sendPacketTo(char packetId, int who, CString pPacket, TPlayer* pPlayer = 0) const; + void sendPacketToAll(PlayerOutPacket pPacket, TPlayer *pSender) const; + void sendPacketToLevel(PlayerOutPacket pPacket, TLevel* pLevel, TPlayer* pPlayer = 0) const; + void sendPacketToLevel(PlayerOutPacket pPacket, TMap* pMap, TLevel* pLevel, TPlayer* pPlayer = 0, bool onlyGmap = false) const; + void sendPacketToLevel(PlayerOutPacket pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf = false, bool onlyGmap = false) const; + void sendPacketToLevel(PlayerPredicate predicate, PlayerOutPacket pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf = false, bool onlyGmap = false) const; + void sendPacketTo(int who, PlayerOutPacket pPacket, TPlayer* pPlayer = 0) const; // Player Management unsigned int getFreePlayerId(); @@ -347,7 +347,7 @@ inline void TServer::sendToRC(const CString& pMessage, TPlayer *pSender) const if (len == -1) len = pMessage.length(); - sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << pMessage.subString(0, len), pSender); + sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << pMessage.subString(0, len)}, pSender); } inline void TServer::sendToNC(const CString& pMessage, TPlayer *pSender) const @@ -356,7 +356,7 @@ inline void TServer::sendToNC(const CString& pMessage, TPlayer *pSender) const if (len == -1) len = pMessage.length(); - sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYNC, CString() << pMessage.subString(0, len), pSender); + sendPacketTo(PLTYPE_ANYNC, {PLO_RC_CHAT, CString() << pMessage.subString(0, len)}, pSender); } #endif diff --git a/server/src/Misc/CWordFilter.cpp b/server/src/Misc/CWordFilter.cpp index 8a86020e..28678e01 100644 --- a/server/src/Misc/CWordFilter.cpp +++ b/server/src/Misc/CWordFilter.cpp @@ -1,402 +1,402 @@ -#include "IDebug.h" -#include "CLog.h" -#include "IEnums.h" -#include "CWordFilter.h" -#include "TServer.h" -#include "TPlayer.h" - -char bypass[] = -{ - ' ', '\r', '\n', -}; - -static bool isUpper(char c) -{ - return (c >= 65 && c <= 90); -} - -static bool isLower(char c) -{ - return (c >= 97 && c <= 122); -} - -static char toLower(char c) -{ - if (c >= 65 && c <= 90) - return c + 32; - return c; -} - -static char toUpper(char c) -{ - if (c >= 97 && c <= 122) - return c - 32; - return c; -} - -CWordFilter::~CWordFilter() -{ - for (std::vector::iterator i = rules.begin(); i != rules.end();) - { - SWordFilterRule* rule = *i; - delete rule; - i = rules.erase(i); - } - rules.clear(); -} - -void CWordFilter::load(const CString& file) -{ - // If we have rules, delete them. - if (rules.size() != 0) - { - for (std::vector::iterator i = rules.begin(); i != rules.end();) - { - SWordFilterRule* rule = *i; - delete rule; - i = rules.erase(i); - } - rules.clear(); - } - - // Load the file. - std::vector f = CString::loadToken(file, "\n", true); - if (f.size() == 0) return; - - // Parse the file. - for (std::vector::iterator i = f.begin(); i != f.end(); ++i) - { - CString word = *i; - std::vector wordParts = word.tokenize(); - if (wordParts.size() == 0) continue; - - if (wordParts[0] == "RULE") - { - SWordFilterRule* rule = new SWordFilterRule(); - ++i; - while (i != f.end() && (*i) != "RULEEND") - { - CString word2 = *i; - std::vector wordParts2 = word2.tokenize(); - if (wordParts2.size() == 0) - { - ++i; - continue; - } - - if (wordParts2[0] == "CHECK") - { - for (std::vector::size_type j = 1; j < wordParts2.size(); ++j) - { - if (wordParts2[j] == "chat") rule->check |= FILTER_CHECK_CHAT; - else if (wordParts2[j] == "pm") rule->check |= FILTER_CHECK_PM; - else if (wordParts2[j] == "nick") rule->check |= FILTER_CHECK_NICK; - else if (wordParts2[j] == "toall") rule->check |= FILTER_CHECK_TOALL; - } - } - else if (wordParts2[0] == "MATCH") - { - if (wordParts2.size() == 2) - rule->match = wordParts2[1]; - } - else if (wordParts2[0] == "PRECISION") - { - if (wordParts2.size() == 2) - { - if (wordParts2[1].find("%") != -1) - { - rule->precisionPercentage = true; - wordParts2[1].removeAll("%"); - } - else rule->precisionPercentage = false; - rule->precision = strtoint(wordParts2[1]); - } - } - else if (wordParts2[0] == "WORDPOSITION") - { - for (std::vector::size_type j = 1; j < wordParts2.size(); ++j) - { - if (wordParts2[j] == "full") rule->wordPosition |= FILTER_POSITION_FULL; - else if (wordParts2[j] == "start") rule->wordPosition |= FILTER_POSITION_START; - else if (wordParts2[j] == "part") rule->wordPosition |= FILTER_POSITION_PART; - } - } - else if (wordParts2[0] == "ACTION") - { - for (std::vector::size_type j = 1; j < wordParts2.size(); ++j) - { - if (wordParts2[j] == "log") rule->action |= FILTER_ACTION_LOG; - else if (wordParts2[j] == "tellrc") rule->action |= FILTER_ACTION_TELLRC; - else if (wordParts2[j] == "replace") rule->action |= FILTER_ACTION_REPLACE; - else if (wordParts2[j] == "warn") rule->action |= FILTER_ACTION_WARN; - else if (wordParts2[j] == "jail") rule->action |= FILTER_ACTION_JAIL; - else if (wordParts2[j] == "ban") rule->action |= FILTER_ACTION_BAN; - } - } - else if (wordParts2[0] == "WARNMESSAGE") - { - rule->warnMessage = word2.remove(0, 12).trim(); - } - - ++i; - } - - // Make sure we have a valid rule. - if (rule->check == 0 || rule->action == 0 || rule->wordPosition == 0) - { - delete rule; - continue; - } - - // Add the rule to the list. - rules.push_back(rule); - } - else if (wordParts[0] == "WARNMESSAGE") - { - defaultWarnMessage = word.remove(0, 12).trim(); - } - else if (wordParts[0] == "SHOWWORDSTORC") - { - if (wordParts.size() == 2 && wordParts[1] == "true") - showWordsToRC = true; - } - } -} - -int CWordFilter::apply(const TPlayer* player, CString& chat, int check) -{ - if (chat.isEmpty() || rules.size() == 0 || check == 0) return 0; - - CString out = chat; - CString warnmessage; - std::vector chatWords = chat.tokenize(); - std::vector wordsFound; - int actionsFound = 0; - - for (std::vector::iterator i = rules.begin(); i != rules.end(); ++i) - { - SWordFilterRule* rule = *i; - - // Check if we should use this rule. - if ((check & rule->check) == 0) continue; - - // Start and full will check whole words. - if (rule->wordPosition != FILTER_POSITION_PART) - { - // Loop through each word of the chat. - for (std::vector::iterator j = chatWords.begin(); j != chatWords.end(); ++j) - { - CString* word = &(*j); - - // If we are checking for a full word and the words aren't the same length, go to the next word. - if (rule->wordPosition == FILTER_POSITION_FULL && word->length() != rule->match.length()) continue; - - // See if it matches the rule. - int wordsMatched = 0; - bool failed = false; - for (int chatpos = 0; chatpos < rule->match.length() && chatpos < word->length(); ++chatpos) - { - char letter = rule->match[chatpos]; - char wordletter = (*word)[chatpos]; - if (letter == '?') - { - wordsMatched++; - continue; - } - if (isLower(letter) && letter == toLower(wordletter)) - wordsMatched++; - else if (isUpper(letter)) - { - if (toLower(letter) == toLower(wordletter)) wordsMatched++; - else - { - failed = true; - break; - } - } - } - if (failed) continue; - - // Check and see if we hit the limit. - if (rule->precisionPercentage == false && wordsMatched < rule->precision) continue; - if (rule->precisionPercentage == true && rule->precision > (int)(((float)wordsMatched / (float)rule->match.length()) * 100)) continue; - - // Add the word to the list of words found. - wordsFound.push_back(*word); - //wordsFound.push_back(rule->match); - - // Add the rule's actions to the total list of actions to take. - actionsFound |= rule->action; - - // If it is a warning rule, we are altering the message. - // We can abort and return it. - if (rule->action & FILTER_ACTION_WARN) - { - warnmessage = rule->warnMessage; - goto WordFilterActions; - } - - // Censor the word. - if (rule->action & FILTER_ACTION_REPLACE) - { - // Assemble the censor string. - CString censor; - for (int p = 0; p < word->length(); ++p) censor << "*"; - - // Censor the output. - out.replaceAllI(*word, censor); - } - } - } - else if (rule->wordPosition == FILTER_POSITION_PART) - { - for (int wordpos = 0; wordpos < chat.length(); ++wordpos) - { - int wordStart = wordpos; - - // See if it matches the rule. - int wordsMatched = 0; - bool failed = false; - CString word; - for (int chatpos = 0; chatpos < rule->match.length() && wordpos + chatpos < chat.length(); ++chatpos) - { - // Don't start on an empty space. - if (wordpos + chatpos == wordStart) - { - bool found = false; - for (int b = 0; b < sizeof(bypass); ++b) - { - if (chat[wordpos + chatpos] == bypass[b]) - { - failed = true; - found = true; - break; - } - } - if (found) break; - } - - // Don't count empty spaces. - while (true) - { - bool found = false; - for (int b = 0; b < sizeof(bypass); ++b) - { - if (chat[wordpos + chatpos] == bypass[b]) - { - found = true; - word << bypass[b]; - ++wordpos; - } - } - if (!found) break; - } - - // Check letter for match. - char letter = rule->match[chatpos]; - char wordletter = chat[wordpos + chatpos]; - if (letter == '?') - { - word << wordletter; - wordsMatched++; - continue; - } - if (isLower(letter) && letter == toLower(wordletter)) - wordsMatched++; - else if (isUpper(letter)) - { - if (toLower(letter) == toLower(wordletter)) wordsMatched++; - else - { - failed = true; - break; - } - } - word << wordletter; - } - wordpos = wordStart; - if (failed) continue; - - // Check and see if we hit the limit. - if (rule->precisionPercentage == false && wordsMatched < rule->precision) continue; - if (rule->precisionPercentage == true && rule->precision > (int)(((float)wordsMatched / (float)rule->match.length()) * 100)) continue; - - // Trim the word. - word.trimI(); - - // Add the word to the list of words found. - wordsFound.push_back(word); - //wordsFound.push_back(rule->match); - - // Add the rule's actions to the total list of actions to take. - actionsFound |= rule->action; - - // If it is a warning rule, we are altering the message. - // We can abort and return it. - if (rule->action & FILTER_ACTION_WARN) - { - warnmessage = rule->warnMessage; - goto WordFilterActions; - } - - // Censor the word. - if (rule->action & FILTER_ACTION_REPLACE) - { - // Assemble the censor string. - CString censor; - for (int p = 0; p < word.length(); ++p) censor << "*"; - - // Censor the output. - out.replaceAllI(word, censor); - } - } - } - } - -WordFilterActions: - - // If no words were found, exit now. - if (wordsFound.size() == 0) return 0; - - // Assemble a list of the bad words. - CString badwords; - for (std::vector::iterator i = wordsFound.begin(); i != wordsFound.end(); ++i) - badwords << *i << ", "; - badwords.removeI(badwords.length() - 2); - - // Apply an action based on the word. - if (actionsFound & FILTER_ACTION_LOG) - { - CLog wordfilter; - wordfilter.setFilename(CString() << server->getServerPath() << "logs/serverlog.txt"); - wordfilter.setEnabled(true); - wordfilter.out("[Word Filter] Player %s was caught using these words: %s\n", player->getAccountName().text(), badwords.text()); - } - - // Graal doesn't implement. Should we? - if (actionsFound & FILTER_ACTION_JAIL) - { - } - - // Graal doesn't implement. Should we? - if (actionsFound & FILTER_ACTION_BAN) - { - } - - // Tell RC what happened. - if (showWordsToRC || actionsFound & FILTER_ACTION_TELLRC) - { - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Word Filter: Player " << player->getAccountName() << " was caught using these words: " << badwords); - } - - // If it is a warning rule, we are altering the message. - // If not, set the message to the filtered message. - if (actionsFound & FILTER_ACTION_WARN) - { - if (warnmessage.isEmpty()) chat = defaultWarnMessage; - else chat = warnmessage; - } - else chat = out; - - return actionsFound; -} +#include "IDebug.h" +#include "CLog.h" +#include "IEnums.h" +#include "CWordFilter.h" +#include "TServer.h" +#include "TPlayer.h" + +char bypass[] = +{ + ' ', '\r', '\n', +}; + +static bool isUpper(char c) +{ + return (c >= 65 && c <= 90); +} + +static bool isLower(char c) +{ + return (c >= 97 && c <= 122); +} + +static char toLower(char c) +{ + if (c >= 65 && c <= 90) + return c + 32; + return c; +} + +static char toUpper(char c) +{ + if (c >= 97 && c <= 122) + return c - 32; + return c; +} + +CWordFilter::~CWordFilter() +{ + for (std::vector::iterator i = rules.begin(); i != rules.end();) + { + SWordFilterRule* rule = *i; + delete rule; + i = rules.erase(i); + } + rules.clear(); +} + +void CWordFilter::load(const CString& file) +{ + // If we have rules, delete them. + if (rules.size() != 0) + { + for (std::vector::iterator i = rules.begin(); i != rules.end();) + { + SWordFilterRule* rule = *i; + delete rule; + i = rules.erase(i); + } + rules.clear(); + } + + // Load the file. + std::vector f = CString::loadToken(file, "\n", true); + if (f.size() == 0) return; + + // Parse the file. + for (std::vector::iterator i = f.begin(); i != f.end(); ++i) + { + CString word = *i; + std::vector wordParts = word.tokenize(); + if (wordParts.size() == 0) continue; + + if (wordParts[0] == "RULE") + { + SWordFilterRule* rule = new SWordFilterRule(); + ++i; + while (i != f.end() && (*i) != "RULEEND") + { + CString word2 = *i; + std::vector wordParts2 = word2.tokenize(); + if (wordParts2.size() == 0) + { + ++i; + continue; + } + + if (wordParts2[0] == "CHECK") + { + for (std::vector::size_type j = 1; j < wordParts2.size(); ++j) + { + if (wordParts2[j] == "chat") rule->check |= FILTER_CHECK_CHAT; + else if (wordParts2[j] == "pm") rule->check |= FILTER_CHECK_PM; + else if (wordParts2[j] == "nick") rule->check |= FILTER_CHECK_NICK; + else if (wordParts2[j] == "toall") rule->check |= FILTER_CHECK_TOALL; + } + } + else if (wordParts2[0] == "MATCH") + { + if (wordParts2.size() == 2) + rule->match = wordParts2[1]; + } + else if (wordParts2[0] == "PRECISION") + { + if (wordParts2.size() == 2) + { + if (wordParts2[1].find("%") != -1) + { + rule->precisionPercentage = true; + wordParts2[1].removeAll("%"); + } + else rule->precisionPercentage = false; + rule->precision = strtoint(wordParts2[1]); + } + } + else if (wordParts2[0] == "WORDPOSITION") + { + for (std::vector::size_type j = 1; j < wordParts2.size(); ++j) + { + if (wordParts2[j] == "full") rule->wordPosition |= FILTER_POSITION_FULL; + else if (wordParts2[j] == "start") rule->wordPosition |= FILTER_POSITION_START; + else if (wordParts2[j] == "part") rule->wordPosition |= FILTER_POSITION_PART; + } + } + else if (wordParts2[0] == "ACTION") + { + for (std::vector::size_type j = 1; j < wordParts2.size(); ++j) + { + if (wordParts2[j] == "log") rule->action |= FILTER_ACTION_LOG; + else if (wordParts2[j] == "tellrc") rule->action |= FILTER_ACTION_TELLRC; + else if (wordParts2[j] == "replace") rule->action |= FILTER_ACTION_REPLACE; + else if (wordParts2[j] == "warn") rule->action |= FILTER_ACTION_WARN; + else if (wordParts2[j] == "jail") rule->action |= FILTER_ACTION_JAIL; + else if (wordParts2[j] == "ban") rule->action |= FILTER_ACTION_BAN; + } + } + else if (wordParts2[0] == "WARNMESSAGE") + { + rule->warnMessage = word2.remove(0, 12).trim(); + } + + ++i; + } + + // Make sure we have a valid rule. + if (rule->check == 0 || rule->action == 0 || rule->wordPosition == 0) + { + delete rule; + continue; + } + + // Add the rule to the list. + rules.push_back(rule); + } + else if (wordParts[0] == "WARNMESSAGE") + { + defaultWarnMessage = word.remove(0, 12).trim(); + } + else if (wordParts[0] == "SHOWWORDSTORC") + { + if (wordParts.size() == 2 && wordParts[1] == "true") + showWordsToRC = true; + } + } +} + +int CWordFilter::apply(const TPlayer* player, CString& chat, int check) +{ + if (chat.isEmpty() || rules.size() == 0 || check == 0) return 0; + + CString out = chat; + CString warnmessage; + std::vector chatWords = chat.tokenize(); + std::vector wordsFound; + int actionsFound = 0; + + for (std::vector::iterator i = rules.begin(); i != rules.end(); ++i) + { + SWordFilterRule* rule = *i; + + // Check if we should use this rule. + if ((check & rule->check) == 0) continue; + + // Start and full will check whole words. + if (rule->wordPosition != FILTER_POSITION_PART) + { + // Loop through each word of the chat. + for (std::vector::iterator j = chatWords.begin(); j != chatWords.end(); ++j) + { + CString* word = &(*j); + + // If we are checking for a full word and the words aren't the same length, go to the next word. + if (rule->wordPosition == FILTER_POSITION_FULL && word->length() != rule->match.length()) continue; + + // See if it matches the rule. + int wordsMatched = 0; + bool failed = false; + for (int chatpos = 0; chatpos < rule->match.length() && chatpos < word->length(); ++chatpos) + { + char letter = rule->match[chatpos]; + char wordletter = (*word)[chatpos]; + if (letter == '?') + { + wordsMatched++; + continue; + } + if (isLower(letter) && letter == toLower(wordletter)) + wordsMatched++; + else if (isUpper(letter)) + { + if (toLower(letter) == toLower(wordletter)) wordsMatched++; + else + { + failed = true; + break; + } + } + } + if (failed) continue; + + // Check and see if we hit the limit. + if (rule->precisionPercentage == false && wordsMatched < rule->precision) continue; + if (rule->precisionPercentage == true && rule->precision > (int)(((float)wordsMatched / (float)rule->match.length()) * 100)) continue; + + // Add the word to the list of words found. + wordsFound.push_back(*word); + //wordsFound.push_back(rule->match); + + // Add the rule's actions to the total list of actions to take. + actionsFound |= rule->action; + + // If it is a warning rule, we are altering the message. + // We can abort and return it. + if (rule->action & FILTER_ACTION_WARN) + { + warnmessage = rule->warnMessage; + goto WordFilterActions; + } + + // Censor the word. + if (rule->action & FILTER_ACTION_REPLACE) + { + // Assemble the censor string. + CString censor; + for (int p = 0; p < word->length(); ++p) censor << "*"; + + // Censor the output. + out.replaceAllI(*word, censor); + } + } + } + else if (rule->wordPosition == FILTER_POSITION_PART) + { + for (int wordpos = 0; wordpos < chat.length(); ++wordpos) + { + int wordStart = wordpos; + + // See if it matches the rule. + int wordsMatched = 0; + bool failed = false; + CString word; + for (int chatpos = 0; chatpos < rule->match.length() && wordpos + chatpos < chat.length(); ++chatpos) + { + // Don't start on an empty space. + if (wordpos + chatpos == wordStart) + { + bool found = false; + for (int b = 0; b < sizeof(bypass); ++b) + { + if (chat[wordpos + chatpos] == bypass[b]) + { + failed = true; + found = true; + break; + } + } + if (found) break; + } + + // Don't count empty spaces. + while (true) + { + bool found = false; + for (int b = 0; b < sizeof(bypass); ++b) + { + if (chat[wordpos + chatpos] == bypass[b]) + { + found = true; + word << bypass[b]; + ++wordpos; + } + } + if (!found) break; + } + + // Check letter for match. + char letter = rule->match[chatpos]; + char wordletter = chat[wordpos + chatpos]; + if (letter == '?') + { + word << wordletter; + wordsMatched++; + continue; + } + if (isLower(letter) && letter == toLower(wordletter)) + wordsMatched++; + else if (isUpper(letter)) + { + if (toLower(letter) == toLower(wordletter)) wordsMatched++; + else + { + failed = true; + break; + } + } + word << wordletter; + } + wordpos = wordStart; + if (failed) continue; + + // Check and see if we hit the limit. + if (rule->precisionPercentage == false && wordsMatched < rule->precision) continue; + if (rule->precisionPercentage == true && rule->precision > (int)(((float)wordsMatched / (float)rule->match.length()) * 100)) continue; + + // Trim the word. + word.trimI(); + + // Add the word to the list of words found. + wordsFound.push_back(word); + //wordsFound.push_back(rule->match); + + // Add the rule's actions to the total list of actions to take. + actionsFound |= rule->action; + + // If it is a warning rule, we are altering the message. + // We can abort and return it. + if (rule->action & FILTER_ACTION_WARN) + { + warnmessage = rule->warnMessage; + goto WordFilterActions; + } + + // Censor the word. + if (rule->action & FILTER_ACTION_REPLACE) + { + // Assemble the censor string. + CString censor; + for (int p = 0; p < word.length(); ++p) censor << "*"; + + // Censor the output. + out.replaceAllI(word, censor); + } + } + } + } + +WordFilterActions: + + // If no words were found, exit now. + if (wordsFound.size() == 0) return 0; + + // Assemble a list of the bad words. + CString badwords; + for (std::vector::iterator i = wordsFound.begin(); i != wordsFound.end(); ++i) + badwords << *i << ", "; + badwords.removeI(badwords.length() - 2); + + // Apply an action based on the word. + if (actionsFound & FILTER_ACTION_LOG) + { + CLog wordfilter; + wordfilter.setFilename(CString() << server->getServerPath() << "logs/serverlog.txt"); + wordfilter.setEnabled(true); + wordfilter.out("[Word Filter] Player %s was caught using these words: %s\n", player->getAccountName().text(), badwords.text()); + } + + // Graal doesn't implement. Should we? + if (actionsFound & FILTER_ACTION_JAIL) + { + } + + // Graal doesn't implement. Should we? + if (actionsFound & FILTER_ACTION_BAN) + { + } + + // Tell RC what happened. + if (showWordsToRC || actionsFound & FILTER_ACTION_TELLRC) + { + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Word Filter: Player " << player->getAccountName() << " was caught using these words: " << badwords}); + } + + // If it is a warning rule, we are altering the message. + // If not, set the message to the filtered message. + if (actionsFound & FILTER_ACTION_WARN) + { + if (warnmessage.isEmpty()) chat = defaultWarnMessage; + else chat = warnmessage; + } + else chat = out; + + return actionsFound; +} diff --git a/server/src/Scripting/v8/V8LevelImpl.cpp b/server/src/Scripting/v8/V8LevelImpl.cpp index 870f2e69..f6a1b755 100644 --- a/server/src/Scripting/v8/V8LevelImpl.cpp +++ b/server/src/Scripting/v8/V8LevelImpl.cpp @@ -308,7 +308,7 @@ void Level_Function_PutExplosion(const v8::FunctionCallbackInfo& args // Send the packet out. CString packet = CString() >> (short)0 >> (char)eradius >> (char)(loc[0] * 2) >> (char)(loc[1] * 2) >> (char)epower; - server->sendPacketToLevel(PLO_EXPLOSION, packet, nullptr, levelObject); + server->sendPacketToLevel({PLO_EXPLOSION, packet}, nullptr, levelObject); } } diff --git a/server/src/Scripting/v8/V8PlayerImpl.cpp b/server/src/Scripting/v8/V8PlayerImpl.cpp index 637c101c..27855729 100644 --- a/server/src/Scripting/v8/V8PlayerImpl.cpp +++ b/server/src/Scripting/v8/V8PlayerImpl.cpp @@ -1010,7 +1010,7 @@ void Player_Function_SendPM(const v8::FunctionCallbackInfo& args) // PM message CString pmMessage(*newValue); - playerObject->sendPacket(PLO_PRIVATEMESSAGE, CString() >> (short)npcServer->getId() << "\"\"," << pmMessage.gtokenize()); + playerObject->sendPacket({PLO_PRIVATEMESSAGE, CString() >> (short)npcServer->getId() << "\"\"," << pmMessage.gtokenize()}); } } @@ -1261,7 +1261,7 @@ void Player_Function_TriggerAction(const v8::FunctionCallbackInfo& ar // Unwrap Object V8ENV_SAFE_UNWRAP(args, TPlayer, playerObject); - playerObject->sendPacket(PLO_TRIGGERACTION, CString() >> (short)0 >> (int)0 >> (char)trigx >> (char)trigy << trigaction); + playerObject->sendPacket({PLO_TRIGGERACTION, CString() >> (short)0 >> (int)0 >> (char)trigx >> (char)trigy << trigaction}); } } @@ -1287,7 +1287,7 @@ void Player_Function_TriggerClient(const v8::FunctionCallbackInfo& ar // Unwrap Object V8ENV_SAFE_UNWRAP(args, TPlayer, playerObject); - playerObject->sendPacket(PLO_TRIGGERACTION, CString() >> (short)0 >> (int)0 >> (char)0 >> (char)0 << trigaction); + playerObject->sendPacket({PLO_TRIGGERACTION, CString() >> (short)0 >> (int)0 >> (char)0 >> (char)0 << trigaction}); } } } diff --git a/server/src/TLevel/TLevel.cpp b/server/src/TLevel/TLevel.cpp index 1d99d656..1cb7c735 100644 --- a/server/src/TLevel/TLevel.cpp +++ b/server/src/TLevel/TLevel.cpp @@ -105,7 +105,7 @@ TLevel::~TLevel() { CString packet = CString() >> (char)(item.getX() * 2) >> (char)(item.getY() * 2); for (auto& player : levelPlayerList) - player->sendPacket(PLO_ITEMDEL, packet); + player->sendPacket({PLO_ITEMDEL, packet}); } levelItems.clear(); @@ -307,7 +307,7 @@ bool TLevel::reload() { CString packet = CString() >> (char)(item.getX() * 2) >> (char)(item.getY() * 2); for (auto& player : levelPlayerList) - player->sendPacket(PLO_ITEMDEL, packet); + player->sendPacket({PLO_ITEMDEL, packet}); } levelItems.clear(); @@ -1200,7 +1200,7 @@ bool TLevel::alterBoard(CString& pTileData, int pX, int pY, int pWidth, int pHei // Check if we found a full tile. If so, don't accept the change. if (foundCount == 4) { - player->sendPacket(PLO_BOARDMODIFY, CString() >> (char)pX >> (char)pY >> (char)pWidth >> (char)pHeight << pTileData); + player->sendPacket({PLO_BOARDMODIFY, CString() >> (char)pX >> (char)pY >> (char)pWidth >> (char)pHeight << pTileData}); return false; } } @@ -1516,7 +1516,7 @@ bool TLevel::doTimedEvents() // change, the client won't get the new data. change.swapTiles(); change.setModTime(time(0)); - server->sendPacketToLevel(PLO_BOARDMODIFY, CString() << change.getBoardStr(), 0, this); + server->sendPacketToLevel({PLO_BOARDMODIFY, CString() << change.getBoardStr()}, nullptr, this); } } @@ -1541,7 +1541,7 @@ bool TLevel::doTimedEvents() int deleteTimer = horse.timeout.doTimeout(); if (deleteTimer == 0) { - server->sendPacketToLevel(PLO_HORSEDEL, CString() >> (char)(horse.getX() * 2) >> (char)(horse.getY() * 2), 0, this); + server->sendPacketToLevel({PLO_HORSEDEL, CString() >> (char)(horse.getX() * 2) >> (char)(horse.getY() * 2)}, nullptr, this); i = levelHorses.erase(i); } else ++i; @@ -1571,7 +1571,7 @@ bool TLevel::doTimedEvents() CString props = CString() >> (char)BDPROP_MODE >> (char)BDMODE_SWAMPSHOT; baddy->setProps(props); for (unsigned int i = 1; i < levelPlayerList.size(); ++i) - levelPlayerList[i]->sendPacket(PLO_BADDYPROPS, CString() >> (char)baddy->getId() << props); + levelPlayerList[i]->sendPacket({PLO_BADDYPROPS, CString() >> (char)baddy->getId() << props}); } } else if (baddy->getMode() == BDMODE_DIE) @@ -1583,14 +1583,14 @@ bool TLevel::doTimedEvents() // Set the baddy as dead for all the other players in the level. CString props = CString() >> (char)BDPROP_MODE >> (char)BDMODE_DEAD; for (unsigned int i = 1; i < levelPlayerList.size(); ++i) - levelPlayerList[i]->sendPacket(PLO_BADDYPROPS, CString() >> (char)baddy->getId() << props); + levelPlayerList[i]->sendPacket({PLO_BADDYPROPS, CString() >> (char)baddy->getId() << props}); } else { baddy->reset(); for (auto p : levelPlayerList) { - p->sendPacket(PLO_BADDYPROPS, CString() >> (char)baddy->getId() << baddy->getProps(p->getVersion())); + p->sendPacket({PLO_BADDYPROPS, CString() >> (char)baddy->getId() << baddy->getProps(p->getVersion())}); } } } @@ -1752,7 +1752,7 @@ void TLevel::modifyBoardDirect(uint32_t index, short tile) { auto change = TLevelBoardChange(pX, pY, 1, 1, CString() >> tile, CString() >> oldTile, -1); levelBoardChanges.push_back(change); - server->sendPacketToLevel(PLO_BOARDMODIFY, CString() << change.getBoardStr(), 0, this); + server->sendPacketToLevel({PLO_BOARDMODIFY, CString() << change.getBoardStr()}, nullptr, this); } #endif diff --git a/server/src/TLevel/TLevelBaddy.cpp b/server/src/TLevel/TLevelBaddy.cpp index 1698ef61..7d9522f7 100644 --- a/server/src/TLevel/TLevelBaddy.cpp +++ b/server/src/TLevel/TLevelBaddy.cpp @@ -1,229 +1,229 @@ -#include "IDebug.h" -#include "IEnums.h" -#include "TServer.h" -#include "IUtil.h" -#include "TLevelBaddy.h" -#include "TLevel.h" - -const int baddytypes = 10; -const char* baddyImages[baddytypes] = { - "baddygray.png", "baddyblue.png", "baddyred.png", "baddyblue.png", "baddygray.png", - "baddyhare.png", "baddyoctopus.png", "baddygold.png", "baddylizardon.png", "baddydragon.png" -}; -const char baddyStartMode[baddytypes] = { - BDMODE_WALK, BDMODE_WALK, BDMODE_WALK, BDMODE_WALK, BDMODE_SWAMPSHOT, - BDMODE_HAREJUMP, BDMODE_WALK, BDMODE_WALK, BDMODE_WALK, BDMODE_WALK -}; -const int baddyPower[baddytypes] = { - 2, 3, 4, 3, 2, - 1, 1, 6, 12, 8 -}; - - -TLevelBaddy::TLevelBaddy(const float pX, const float pY, const unsigned char pType, TLevel* pLevel, TServer* pServer) -: level(pLevel), server(pServer), type(pType), id(0), -startX(pX), startY(pY), -respawn(true), setImage(false) -{ - if (pType > baddytypes) type = 0; - verses.resize(3); - reset(); -} - -void TLevelBaddy::reset() -{ - mode = baddyStartMode[(int)type]; - x = startX; - y = startY; - power = baddyPower[(int)type]; - image = baddyImages[(int)type]; - dir = (2 << 2) | 2; // Both head/body direction is encoded in dir. - ani = 0; - setImage = false; -} - -void TLevelBaddy::dropItem() -{ - // 41.66...% chance of a green gralat. - // 41.66...% chance of something else. - // 16.66...% chance of nothing. - int itemId = rand()%12; - LevelItemType itemType = LevelItemType::INVALID; - - switch (itemId) - { - case 0: //GREENRUPEE - case 1: //BLUERUPEE - case 2: //REDRUPEE - case 3: //BOMBS - case 4: //DARTS - case 5: //HEART - itemType = TLevelItem::getItemId(itemId); - break; - - default: - if (itemId > 5 && itemId < 10) - itemType = LevelItemType::GREENRUPEE; - break; - } - - if (itemType != LevelItemType::INVALID) - { - if (level->addItem(this->x, this->y, itemType)) - server->sendPacketToLevel(PLO_ITEMADD, CString() >> (char)(this->x * 2) >> (char)(this->y * 2) >> (char)TLevelItem::getItemTypeId(itemType), 0, level); - } -} - -CString TLevelBaddy::getProp(const int propId, int clientVersion) const -{ - switch (propId) - { - case BDPROP_ID: - return CString() >> (char)id; - - case BDPROP_X: - return CString() >> (char)(x * 2); - - case BDPROP_Y: - return CString() >> (char)(y * 2); - - case BDPROP_TYPE: - return CString() >> (char)type; - - case BDPROP_POWERIMAGE: - { - if (clientVersion < CLVER_2_1 && image == baddyImages[(int)type]) - return CString() >> (char)power >> (char)image.length() << image.replaceAll(".png", ".gif"); - else return CString() >> (char)power >> (char)image.length() << image; - } - - case BDPROP_MODE: - return CString() >> (char)mode; - - case BDPROP_ANI: - return CString() >> (char)ani; - - case BDPROP_DIR: - return CString() >> (char)dir; - - case BDPROP_VERSESIGHT: - case BDPROP_VERSEHURT: - case BDPROP_VERSEATTACK: - { - unsigned int verseId = propId - BDPROP_VERSESIGHT; - if (verseId < verses.size()) - return CString() >> (char)verses[verseId].length() << verses[verseId]; - else return CString() >> (char)0; - } - } - return {}; -} - -CString TLevelBaddy::getProps(int clientVersion) const -{ - CString retVal; - for (int i = 1; i < BDPROP_COUNT; i++) - retVal >> (char)i << getProp(i, clientVersion); - return retVal; -} - -void TLevelBaddy::setProps(CString &pProps) -{ - int len = 0; - while (pProps.bytesLeft()) - { - unsigned char propId = pProps.readGUChar(); - switch (propId) - { - case BDPROP_ID: - id = pProps.readGChar(); - break; - - case BDPROP_X: - x = (float)pProps.readGChar() / 2.0f; - x = clip(x, 0.0f, 63.5f); - break; - - case BDPROP_Y: - y = (float)pProps.readGChar() / 2.0f; - y = clip(y, 0.0f, 63.5f); - break; - - case BDPROP_TYPE: - type = pProps.readGChar(); - break; - - case BDPROP_POWERIMAGE: - { - power = pProps.readGChar(); - if (pProps.bytesLeft() != 0) - { - CString newImage = pProps.readChars(pProps.readGUChar()); - - if (newImage.isEmpty()) - image = baddyImages[(int)type]; - else - { - // Why we need this I have no idea. - // For some reason, the client resets the custom image when the baddy is hurt. - if (setImage == false) - { - setImage = true; - image = newImage; - } - } - } - } - break; - - case BDPROP_MODE: - mode = pProps.readGChar(); - if (type == 4 && mode == BDMODE_HURT) - { - // Workaround for buggy client. In 2 seconds, set us back to BDMODE_SWAMPSHOT from - // inside TLevel.cpp. - timeout.setTimeout(2); - } - else if (mode == BDMODE_DIE) - { - // In 2 seconds, set our mode to BDMODE_DEAD inside TLevel.cpp. - timeout.setTimeout(2); - - // Drop items when dead. - if (server->getSettings()->getBool("baddyitems", false) == true) - dropItem(); - } - else if (mode == BDMODE_DEAD) - { - if (respawn) - timeout.setTimeout(server->getSettings()->getInt("baddyrespawntime", 60)); - else - { - if (level) - level->removeBaddy(id); - else delete this; - return; - } - } - break; - - case BDPROP_ANI: - ani = pProps.readGChar(); - break; - - case BDPROP_DIR: - dir = pProps.readGChar(); - break; - - case BDPROP_VERSESIGHT: - case BDPROP_VERSEHURT: - case BDPROP_VERSEATTACK: - { - len = pProps.readGUChar(); - unsigned int verseId = propId - BDPROP_VERSESIGHT; - if (verseId < verses.size()) - verses[verseId] = pProps.readChars(len); - } - } - } -} +#include "IDebug.h" +#include "IEnums.h" +#include "TServer.h" +#include "IUtil.h" +#include "TLevelBaddy.h" +#include "TLevel.h" + +const int baddytypes = 10; +const char* baddyImages[baddytypes] = { + "baddygray.png", "baddyblue.png", "baddyred.png", "baddyblue.png", "baddygray.png", + "baddyhare.png", "baddyoctopus.png", "baddygold.png", "baddylizardon.png", "baddydragon.png" +}; +const char baddyStartMode[baddytypes] = { + BDMODE_WALK, BDMODE_WALK, BDMODE_WALK, BDMODE_WALK, BDMODE_SWAMPSHOT, + BDMODE_HAREJUMP, BDMODE_WALK, BDMODE_WALK, BDMODE_WALK, BDMODE_WALK +}; +const int baddyPower[baddytypes] = { + 2, 3, 4, 3, 2, + 1, 1, 6, 12, 8 +}; + + +TLevelBaddy::TLevelBaddy(const float pX, const float pY, const unsigned char pType, TLevel* pLevel, TServer* pServer) +: level(pLevel), server(pServer), type(pType), id(0), +startX(pX), startY(pY), +respawn(true), setImage(false) +{ + if (pType > baddytypes) type = 0; + verses.resize(3); + reset(); +} + +void TLevelBaddy::reset() +{ + mode = baddyStartMode[(int)type]; + x = startX; + y = startY; + power = baddyPower[(int)type]; + image = baddyImages[(int)type]; + dir = (2 << 2) | 2; // Both head/body direction is encoded in dir. + ani = 0; + setImage = false; +} + +void TLevelBaddy::dropItem() +{ + // 41.66...% chance of a green gralat. + // 41.66...% chance of something else. + // 16.66...% chance of nothing. + int itemId = rand()%12; + LevelItemType itemType = LevelItemType::INVALID; + + switch (itemId) + { + case 0: //GREENRUPEE + case 1: //BLUERUPEE + case 2: //REDRUPEE + case 3: //BOMBS + case 4: //DARTS + case 5: //HEART + itemType = TLevelItem::getItemId(itemId); + break; + + default: + if (itemId > 5 && itemId < 10) + itemType = LevelItemType::GREENRUPEE; + break; + } + + if (itemType != LevelItemType::INVALID) + { + if (level->addItem(this->x, this->y, itemType)) + server->sendPacketToLevel({PLO_ITEMADD, CString() >> (char)(this->x * 2) >> (char)(this->y * 2) >> (char)TLevelItem::getItemTypeId(itemType)}, 0, level); + } +} + +CString TLevelBaddy::getProp(const int propId, int clientVersion) const +{ + switch (propId) + { + case BDPROP_ID: + return CString() >> (char)id; + + case BDPROP_X: + return CString() >> (char)(x * 2); + + case BDPROP_Y: + return CString() >> (char)(y * 2); + + case BDPROP_TYPE: + return CString() >> (char)type; + + case BDPROP_POWERIMAGE: + { + if (clientVersion < CLVER_2_1 && image == baddyImages[(int)type]) + return CString() >> (char)power >> (char)image.length() << image.replaceAll(".png", ".gif"); + else return CString() >> (char)power >> (char)image.length() << image; + } + + case BDPROP_MODE: + return CString() >> (char)mode; + + case BDPROP_ANI: + return CString() >> (char)ani; + + case BDPROP_DIR: + return CString() >> (char)dir; + + case BDPROP_VERSESIGHT: + case BDPROP_VERSEHURT: + case BDPROP_VERSEATTACK: + { + unsigned int verseId = propId - BDPROP_VERSESIGHT; + if (verseId < verses.size()) + return CString() >> (char)verses[verseId].length() << verses[verseId]; + else return CString() >> (char)0; + } + } + return {}; +} + +CString TLevelBaddy::getProps(int clientVersion) const +{ + CString retVal; + for (int i = 1; i < BDPROP_COUNT; i++) + retVal >> (char)i << getProp(i, clientVersion); + return retVal; +} + +void TLevelBaddy::setProps(CString &pProps) +{ + int len = 0; + while (pProps.bytesLeft()) + { + unsigned char propId = pProps.readGUChar(); + switch (propId) + { + case BDPROP_ID: + id = pProps.readGChar(); + break; + + case BDPROP_X: + x = (float)pProps.readGChar() / 2.0f; + x = clip(x, 0.0f, 63.5f); + break; + + case BDPROP_Y: + y = (float)pProps.readGChar() / 2.0f; + y = clip(y, 0.0f, 63.5f); + break; + + case BDPROP_TYPE: + type = pProps.readGChar(); + break; + + case BDPROP_POWERIMAGE: + { + power = pProps.readGChar(); + if (pProps.bytesLeft() != 0) + { + CString newImage = pProps.readChars(pProps.readGUChar()); + + if (newImage.isEmpty()) + image = baddyImages[(int)type]; + else + { + // Why we need this I have no idea. + // For some reason, the client resets the custom image when the baddy is hurt. + if (setImage == false) + { + setImage = true; + image = newImage; + } + } + } + } + break; + + case BDPROP_MODE: + mode = pProps.readGChar(); + if (type == 4 && mode == BDMODE_HURT) + { + // Workaround for buggy client. In 2 seconds, set us back to BDMODE_SWAMPSHOT from + // inside TLevel.cpp. + timeout.setTimeout(2); + } + else if (mode == BDMODE_DIE) + { + // In 2 seconds, set our mode to BDMODE_DEAD inside TLevel.cpp. + timeout.setTimeout(2); + + // Drop items when dead. + if (server->getSettings()->getBool("baddyitems", false) == true) + dropItem(); + } + else if (mode == BDMODE_DEAD) + { + if (respawn) + timeout.setTimeout(server->getSettings()->getInt("baddyrespawntime", 60)); + else + { + if (level) + level->removeBaddy(id); + else delete this; + return; + } + } + break; + + case BDPROP_ANI: + ani = pProps.readGChar(); + break; + + case BDPROP_DIR: + dir = pProps.readGChar(); + break; + + case BDPROP_VERSESIGHT: + case BDPROP_VERSEHURT: + case BDPROP_VERSEATTACK: + { + len = pProps.readGUChar(); + unsigned int verseId = propId - BDPROP_VERSESIGHT; + if (verseId < verses.size()) + verses[verseId] = pProps.readChars(len); + } + } + } +} diff --git a/server/src/TNPC.cpp b/server/src/TNPC.cpp index 1a7c9e45..c0acf760 100644 --- a/server/src/TNPC.cpp +++ b/server/src/TNPC.cpp @@ -202,10 +202,10 @@ void TNPC::setScriptCode(std::string pScript) // TODO(joey): refactor TMap *map = level->getMap(); - server->sendPacketToLevel(PLO_NPCDEL, CString() >> (int)getId(), map, level, 0, true); + server->sendPacketToLevel({PLO_NPCDEL, CString() >> (int)getId()}, map, level, 0, true); CString packet = CString() >> (int)getId() << getProps(0); - server->sendPacketToLevel(PLO_NPCPROPS, packet, map, level, 0, true); + server->sendPacketToLevel({PLO_NPCPROPS, packet}, map, level, 0, true); } #endif } @@ -765,7 +765,7 @@ CString TNPC::setProps(CString& pProps, int clientVersion, bool pForward) if (level != 0) map = level->getMap(); // Send the props. - server->sendPacketToLevel(PLO_NPCPROPS, CString() >> (int)id << ret, map, level, 0, true); + server->sendPacketToLevel({PLO_NPCPROPS, CString() >> (int)id << ret}, map, level, 0, true); } #ifdef V8NPCSERVER @@ -1048,7 +1048,7 @@ NPCEventResponse TNPC::runScriptEvents() propModified.clear(); if (level != nullptr) - server->sendPacketToLevel(PLO_NPCPROPS, propPacket, level->getMap(), level, nullptr, true); + server->sendPacketToLevel({PLO_NPCPROPS, propPacket}, level->getMap(), level, nullptr, true); } if (npcDeleteRequested) @@ -1357,7 +1357,7 @@ void TNPC::moveNPC(int dx, int dy, double time, int options) setY(y + dy); if (level != nullptr) - server->sendPacketToLevel(PLO_MOVE2, CString() >> (int)id >> (short)start_x >> (short)start_y >> (short)delta_x >> (short)delta_y >> (short)itime >> (char)options, level->getMap(), level); + server->sendPacketToLevel({PLO_MOVE2, CString() >> (int)id >> (short)start_x >> (short)start_y >> (short)delta_x >> (short)delta_y >> (short)itime >> (char)options}, level->getMap(), level); if (isWarpable()) testTouch(); @@ -1373,7 +1373,7 @@ void TNPC::warpNPC(TLevel *pLevel, int pX, int pY) // TODO(joey): NPCMOVED needs to be sent to everyone who potentially has this level cached or else the npc // will stay visible when you come back to the level. Should this just be sent to everyone on the server? We do // such for PLO_NPCDEL - server->sendPacketToLevel(PLO_NPCMOVED, CString() >> (int) id, level->getMap(), level); + server->sendPacketToLevel({PLO_NPCMOVED, CString() >> (int) id}, level->getMap(), level); // Remove the npc from the old level level->removeNPC(this); @@ -1394,10 +1394,10 @@ void TNPC::warpNPC(TLevel *pLevel, int pX, int pY) updatePropModTime(NPCPROP_Y2); // Send the properties to the players in the new level - server->sendPacketToLevel(PLO_NPCPROPS, CString() >> (int)id << getProps(0), level->getMap(), level, 0, true); + server->sendPacketToLevel({PLO_NPCPROPS, CString() >> (int)id << getProps(0)}, level->getMap(), level, 0, true); if (!npcName.empty()) - server->sendPacketTo(PLO_NC_NPCADD, PLTYPE_ANYNC, CString() >> (int)id >> (char)NPCPROP_CURLEVEL << getProp(NPCPROP_CURLEVEL)); + server->sendPacketTo(PLTYPE_ANYNC, {PLO_NC_NPCADD, CString() >> (int)id >> (char)NPCPROP_CURLEVEL << getProp(NPCPROP_CURLEVEL)}); // Queue event this->queueNpcAction("npc.warped"); @@ -1498,8 +1498,8 @@ void TNPC::saveNPC() fileData << "ATTR" << std::to_string(i+1) << " " << gAttribs[i] << NL; } - for (auto it = flagList.begin(); it != flagList.end(); ++it) - fileData << "FLAG " << (*it).first << "=" << (*it).second << NL; + for (auto & it : flagList) + fileData << "FLAG " << it.first << "=" << it.second << NL; fileData << "NPCSCRIPT" << NL << CString(npcScript.getSource()).replaceAll("\n", NL); if (fileData[fileData.length() - 1] != '\n') diff --git a/server/src/TPlayer/TPlayer.cpp b/server/src/TPlayer/TPlayer.cpp index b6aae8ba..548786a7 100644 --- a/server/src/TPlayer/TPlayer.cpp +++ b/server/src/TPlayer/TPlayer.cpp @@ -356,16 +356,16 @@ TPlayer::~TPlayer() // Announce our departure to other clients. if (!isNC()) { - server->sendPacketTo(PLO_OTHERPLPROPS, PLTYPE_ANYCLIENT, CString() >> (short)id >> (char)PLPROP_PCONNECTED, this); - server->sendPacketTo(PLO_DELPLAYER, PLTYPE_ANYRC, CString() >> (short)id, this); + server->sendPacketTo(PLTYPE_ANYCLIENT, {PLO_OTHERPLPROPS, CString() >> (short)id >> (char)PLPROP_PCONNECTED}, this); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_DELPLAYER, CString() >> (short)id}, this); } if (!accountName.isEmpty()) { if (isRC()) - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "RC Disconnected: " << accountName, this); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "RC Disconnected: " << accountName}, this); else if (isNC()) - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYNC, CString() << "NC Disconnected: " << accountName, this); + server->sendPacketTo(PLTYPE_ANYNC, {PLO_RC_CHAT, CString() << "NC Disconnected: " << accountName}, this); } // Log. @@ -384,7 +384,8 @@ TPlayer::~TPlayer() delete cl; i = cachedLevels.erase(i); } - for (std::map::iterator i = spLevels.begin(); i != spLevels.end(); ) + + for (auto i = spLevels.begin(); i != spLevels.end(); ) { TLevel* cl = i->second; delete cl; @@ -405,7 +406,7 @@ TPlayer::~TPlayer() bool TPlayer::onRecv() { // If our socket is gone, delete ourself. - if (playerSock == 0 || playerSock->getState() == SOCKET_STATE_DISCONNECTED) + if (playerSock == nullptr || playerSock->getState() == SOCKET_STATE_DISCONNECTED) return false; // Grab the data from the socket and put it into our receive buffer. @@ -423,7 +424,7 @@ bool TPlayer::onRecv() bool TPlayer::onSend() { - if (playerSock == 0 || playerSock->getState() == SOCKET_STATE_DISCONNECTED) + if (playerSock == nullptr || playerSock->getState() == SOCKET_STATE_DISCONNECTED) return false; // Send data. @@ -478,7 +479,7 @@ bool TPlayer::doMain() for (const auto& packet : weapon.second->getWeaponPackets(CLVER_4_0211)) { sendPacket(packet, true); } - sendPacket(PLO_NPCWEAPONSCRIPT, weapon.second->getByteCode(), true); + sendPacket({PLO_NPCWEAPONSCRIPT, weapon.second->getByteCode()}, true); } rBuffer.removeI(0, 8); @@ -568,7 +569,7 @@ bool TPlayer::doTimedEvents() if (((int)difftime(currTime, lastMovement) > maxnomovement) && ((int)difftime(currTime, lastChat) > maxnomovement)) { serverlog.out("[%s] Client %s has been disconnected due to inactivity.\n", server->getName().text(), accountName.text()); - sendPacket(PLO_DISCMESSAGE, CString() << "You have been disconnected due to inactivity."); + sendPacket({PLO_DISCMESSAGE, CString() << "You have been disconnected due to inactivity."}); return false; } } @@ -736,36 +737,30 @@ void TPlayer::decryptPacket(CString& pPacket) } } -void TPlayer::sendPacket(unsigned char packetId, const CString& pPacket, bool sendNow, bool appendNL) +void TPlayer::sendPacketNewProtocol(unsigned char packetId, const CString& pPacket, bool sendNow, bool appendNL) { serverlog.out("[%s][%i] %s\n", server->getName().text(), (int)packetId, pPacket.text()); - if (newProtocol) - { - // We ignore appendNL here because new protocol doesn't end with newlines - CString buf2 = CString() << (char)0 << (char)packetCount; - packetCount++; - buf2.writeInt3(pPacket.length()+6, false); - buf2.writeChar(packetId, false); - buf2.write(pPacket.text(), pPacket.length(), true); - if (sendNow) - { - unsigned int dsize = buf2.length(); - playerSock->sendData(buf2.text(), &dsize); - } - else - { - // append buffer - fileQueue.addPacket(buf2); - } + // We ignore appendNL here because new protocol doesn't end with newlines + CString buf2 = CString() << (char)0 << (char)packetCount; + packetCount++; + buf2.writeInt3(pPacket.length()+6, false); + buf2.writeChar(packetId, false); + buf2.write(pPacket.text(), pPacket.length(), true); + + if (sendNow) + { + unsigned int dsize = buf2.length(); + playerSock->sendData(buf2.text(), &dsize); } else { - sendPacketOld(CString() >> (char)packetId << pPacket, appendNL); + // append buffer + fileQueue.addPacket(buf2); } } -void TPlayer::sendPacketOld(CString pPacket, bool appendNL) +void TPlayer::sendPacketOldProtocol(CString pPacket, bool appendNL) { // empty buffer? if (pPacket.isEmpty()) @@ -795,7 +790,7 @@ bool TPlayer::sendFile(const CString& pFile) CString path = fileSystem->find(pFile); if (path.isEmpty()) { - sendPacket(PLO_FILESENDFAILED, CString() << pFile); + sendPacket({PLO_FILESENDFAILED, CString() << pFile}); return false; } @@ -806,7 +801,7 @@ bool TPlayer::sendFile(const CString& pFile) path.removeI(0, server->getServerPath().length()); // Send the file now. - return this->sendFile(path, pFile); + return sendFile(path, pFile); } bool TPlayer::sendFile(const CString& pPath, const CString& pFile) @@ -816,14 +811,14 @@ bool TPlayer::sendFile(const CString& pPath, const CString& pFile) fileData.load(filepath); time_t modTime = 0; - struct stat fileStat; + struct stat fileStat{}; if (stat(filepath.text(), &fileStat) != -1) modTime = fileStat.st_mtime; // See if the file exists. if (fileData.length() == 0) { - sendPacket(PLO_FILESENDFAILED, CString() << pFile); + sendPacket({PLO_FILESENDFAILED, CString() << pFile}); return false; } @@ -846,7 +841,7 @@ bool TPlayer::sendFile(const CString& pPath, const CString& pFile) if (versionID < CLVER_2_1) packetLength -= 5; // modTime isn't sent. if (fileData.length() > 64000) { - sendPacket(PLO_FILESENDFAILED, CString() << pFile); + sendPacket({PLO_FILESENDFAILED, CString() << pFile}); return false; } isBigFile = false; @@ -855,8 +850,8 @@ bool TPlayer::sendFile(const CString& pPath, const CString& pFile) // If we are sending a big file, let the client know now. if (isBigFile) { - sendPacket(PLO_LARGEFILESTART, CString() << pFile); - sendPacket(PLO_LARGEFILESIZE, CString() >> (long long)fileData.length()); + sendPacket({PLO_LARGEFILESTART, CString() << pFile}); + sendPacket({PLO_LARGEFILESIZE, CString() >> (long long)fileData.length()}); } // Send the file now. @@ -870,21 +865,21 @@ bool TPlayer::sendFile(const CString& pPath, const CString& pFile) { // We don't add a \n to the end of the packet, so subtract 1 from the packet length. if (!newProtocol) - sendPacket(PLO_RAWDATA, CString() >> (int)(packetLength - 1 + sendSize)); - sendPacket(PLO_FILE, CString() >> (char)pFile.length() << pFile << fileData.subString(0, sendSize), false); + sendPacket({PLO_RAWDATA, CString() >> (int)(packetLength - 1 + sendSize)}); + sendPacket({PLO_FILE, CString() >> (char)pFile.length() << pFile << fileData.subString(0, sendSize)}, false); } else { if (!newProtocol) - sendPacket(PLO_RAWDATA, CString() >> (int)(packetLength + sendSize)); - sendPacket(PLO_FILE, CString() >> (long long)modTime >> (char)pFile.length() << pFile << fileData.subString(0, sendSize) << "\n", false); + sendPacket({PLO_RAWDATA, CString() >> (int)(packetLength + sendSize)}); + sendPacket({PLO_FILE, CString() >> (long long)modTime >> (char)pFile.length() << pFile << fileData.subString(0, sendSize) << "\n"}, false); } fileData.removeI(0, sendSize); } // If we had sent a large file, let the client know we finished sending it. - if (isBigFile) sendPacket(PLO_LARGEFILEEND, CString() << pFile); + if (isBigFile) sendPacket({PLO_LARGEFILEEND, CString() << pFile}); return true; } @@ -903,7 +898,7 @@ bool TPlayer::testSign() float signLoc[] = {(float)sign.getX(), (float)sign.getY()}; if (y == signLoc[1] && inrange(x, signLoc[0]-1.5f, signLoc[0]+0.5f)) { - sendPacket(PLO_SAY2, CString() << sign.getUText().replaceAll("\n", "#b")); + sendPacket({PLO_SAY2, CString() << sign.getUText().replaceAll("\n", "#b")}); } } } @@ -954,7 +949,7 @@ void TPlayer::dropItemsOnDeath() gralatc -= drop_gralats; arrowc -= (drop_arrows * 5); bombc -= (drop_bombs * 5); - sendPacket(PLO_PLAYERPROPS, CString() >> (char)PLPROP_RUPEESCOUNT >> (int)gralatc >> (char)PLPROP_ARROWSCOUNT >> (char)arrowc >> (char)PLPROP_BOMBSCOUNT >> (char)bombc); + sendPacket({PLO_PLAYERPROPS, CString() >> (char)PLPROP_RUPEESCOUNT >> (int)gralatc >> (char)PLPROP_ARROWSCOUNT >> (char)arrowc >> (char)PLPROP_BOMBSCOUNT >> (char)bombc}); // Add gralats to the level. while (drop_gralats != 0) @@ -988,7 +983,7 @@ void TPlayer::dropItemsOnDeath() packet.readGChar(); // So msgPLI_ITEMADD works. msgPLI_ITEMADD(packet); - sendPacket(PLO_ITEMADD, CString() << packet.subString(1)); + sendPacket({PLO_ITEMADD, CString() << packet.subString(1)}); } // Add arrows and bombs to the level. @@ -1001,7 +996,7 @@ void TPlayer::dropItemsOnDeath() packet.readGChar(); // So msgPLI_ITEMADD works. msgPLI_ITEMADD(packet); - sendPacket(PLO_ITEMADD, CString() << packet.subString(1)); + sendPacket({PLO_ITEMADD, CString() << packet.subString(1)}); } for (int i = 0; i < drop_bombs; ++i) { @@ -1012,7 +1007,7 @@ void TPlayer::dropItemsOnDeath() packet.readGChar(); // So msgPLI_ITEMADD works. msgPLI_ITEMADD(packet); - sendPacket(PLO_ITEMADD, CString() << packet.subString(1)); + sendPacket({PLO_ITEMADD, CString() << packet.subString(1)}); } } @@ -1080,13 +1075,13 @@ bool TPlayer::processChat(CString pChat) } else if (chatParse[0] == "setbody" && chatParse.size() == 2) { - if (server->getSettings()->getBool("setbodyallowed", true) == false) return false; + if ( !server->getSettings()->getBool("setbodyallowed", true)) return false; processed = true; // Check to see if it is a default body. bool isDefault = false; - for (unsigned int i = 0; i < sizeof(__defaultbodies) / sizeof(char*); ++i) - if (chatParse[1].match(CString(__defaultbodies[i])) == true) isDefault = true; + for (auto & __defaultbody : __defaultbodies) + if ( chatParse[1].match(CString(__defaultbody))) isDefault = true; // Don't search for the file if it is one of the defaults. This protects against // malicious gservers. @@ -1132,8 +1127,8 @@ bool TPlayer::processChat(CString pChat) // Check to see if it is a default sword. bool isDefault = false; - for (unsigned int i = 0; i < sizeof(__defaultswords) / sizeof(char*); ++i) - if (chatParse[1].match(CString(__defaultswords[i])) == true) isDefault = true; + for (auto & __defaultsword : __defaultswords) + if ( chatParse[1].match(CString(__defaultsword))) isDefault = true; // Don't search for the file if it is one of the defaults. This protects against // malicious gservers. @@ -1179,8 +1174,8 @@ bool TPlayer::processChat(CString pChat) // Check to see if it is a default shield. bool isDefault = false; - for (unsigned int i = 0; i < sizeof(__defaultshields) / sizeof(char*); ++i) - if (chatParse[1].match(CString(__defaultshields[i])) == true) isDefault = true; + for (auto & __defaultshield : __defaultshields) + if ( chatParse[1].match(CString(__defaultshield))) isDefault = true; // Don't search for the file if it is one of the defaults. This protects against // malicious gservers. @@ -1299,7 +1294,7 @@ bool TPlayer::processChat(CString pChat) } TPlayer* player = server->getPlayer(chatParse[1], PLTYPE_ANYCLIENT); - if (player && player->getLevel() != 0) + if (player && player->getLevel() != nullptr) warp(player->getLevel()->getLevelName(), player->getX(), player->getY()); } // To x/y location @@ -1349,8 +1344,8 @@ bool TPlayer::processChat(CString pChat) // Check if the player is in a jailed level. std::vector jailList = server->getSettings()->getStr("jaillevels").tokenize(","); - for (std::vector::iterator i = jailList.begin(); i != jailList.end(); ++i) - if (i->trim() == levelName) return false; + for (auto & i : jailList) + if (i.trim() == levelName) return false; if ((int)difftime(time(0), lastMovement) >= 30) { @@ -1378,11 +1373,9 @@ bool TPlayer::processChat(CString pChat) CString msg; { std::vector* playerList = server->getPlayerList(); - for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) + for (auto p : *playerList) { - TPlayer* p = *i; - - // If an RC was found, add it to our string. + // If an RC was found, add it to our string. if (p->getType() & PLTYPE_ANYRC) msg << (msg.length() == 0 ? "" : ", ") << p->getAccountName(); } @@ -1405,11 +1398,9 @@ bool TPlayer::processChat(CString pChat) CString msg; { std::vector* playerList = server->getPlayerList(); - for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) + for (auto p : *playerList) { - TPlayer* p = *i; - - // If our guild matches, add it to our string. + // If our guild matches, add it to our string. if (p->getGuild() == g) msg << (msg.length() == 0 ? "" : ", ") << p->getNickname().subString(0, p->getNickname().find('(')).trimI(); } @@ -1455,15 +1446,14 @@ bool TPlayer::processChat(CString pChat) int num = 0; { std::vector* playerList = server->getPlayerList(); - for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) + for (auto p : *playerList) { - TPlayer* p = *i; - if (p == this) continue; + if (p == this) continue; // If our guild matches, send the PM. if (p->getGuild() == guild) { - p->sendPacket(PLO_PRIVATEMESSAGE, CString() >> (short)id << "\"\",\"Guild message:\",\"" << pm << "\""); + p->sendPacket({PLO_PRIVATEMESSAGE, CString() >> (short)id << "\"\",\"Guild message:\",\"" << pm << "\""}); ++num; } } @@ -1479,9 +1469,9 @@ bool TPlayer::processChat(CString pChat) bool TPlayer::isAdminIp() { std::vector adminIps = adminIp.tokenize(","); - for (std::vector::iterator i = adminIps.begin(); i != adminIps.end(); ++i) + for (auto & adminIp : adminIps) { - if (accountIpStr.match(*i)) + if (accountIpStr.match(adminIp)) return true; } @@ -1564,9 +1554,9 @@ bool TPlayer::setLevel(const CString& pLevelName, time_t modTime) { // Open Level level = TLevel::findLevel(pLevelName, server); - if (level == 0) + if (level == nullptr) { - sendPacket(PLO_WARPFAILED, CString() << pLevelName); + sendPacket({PLO_WARPFAILED, CString() << pLevelName}); return false; } @@ -1575,7 +1565,7 @@ bool TPlayer::setLevel(const CString& pLevelName, time_t modTime) if (level->isSingleplayer()) { TLevel* nl = (spLevels.find(level->getLevelName()) != spLevels.end() ? spLevels[level->getLevelName()] : 0); - if (nl == 0) + if (nl == nullptr) { level = level->clone(); spLevels[level->getLevelName()] = level; @@ -1590,17 +1580,16 @@ bool TPlayer::setLevel(const CString& pLevelName, time_t modTime) { // If any players are in this level, they might have been cached on the client. Solve this by manually removing them. std::vector* plist = level->getPlayerList(); - for (std::vector::iterator i = plist->begin(); i != plist->end(); ++i) + for (auto p : *plist) { - TPlayer* p = *i; - sendPacket(PLO_OTHERPLPROPS, p->getProps(0, 0) >> (char)PLPROP_CURLEVEL >> (char)(level->getLevelName().length() + 1 + 7) << level->getLevelName() << ".unknown" >> (char)PLPROP_X << p->getProp(PLPROP_X) >> (char)PLPROP_Y << p->getProp(PLPROP_Y)); + sendPacket({PLO_OTHERPLPROPS, p->getProps(0, 0) >> (char)PLPROP_CURLEVEL >> (char)(level->getLevelName().length() + 1 + 7) << level->getLevelName() << ".unknown" >> (char)PLPROP_X << p->getProp(PLPROP_X) >> (char)PLPROP_Y << p->getProp(PLPROP_Y)}); } // Set the correct level now. std::map >* groupLevels = server->getGroupLevels(); std::map& group = (*groupLevels)[levelGroup]; TLevel* nl = group[level->getLevelName()]; - if (nl == 0) + if (nl == nullptr) { level = level->clone(); level->setLevelName(level->getLevelName()); @@ -1619,13 +1608,18 @@ bool TPlayer::setLevel(const CString& pLevelName, time_t modTime) { if (pmap && pmap->getType() == MapType::GMAP && versionID >= CLVER_2_1) { - sendPacket(PLO_PLAYERWARP2, CString() - >> (char)(x * 2) >> (char)(y * 2) >> (char)(z + 50) - >> (char)level->getMapX() >> (char)level->getMapY() - << pmap->getMapName()); + sendPacket( + { + PLO_PLAYERWARP2, + CString() + >> (char)(x * 2) >> (char)(y * 2) >> (char)(z + 50) + >> (char)level->getMapX() >> (char)level->getMapY() + << pmap->getMapName() + } + ); } else - sendPacket(PLO_PLAYERWARP, CString() >> (char)(x * 2) >> (char)(y * 2) << levelName); + sendPacket({PLO_PLAYERWARP, CString() >> (char)(x * 2) >> (char)(y * 2) << levelName}); } // Send the level now. @@ -1636,7 +1630,7 @@ bool TPlayer::setLevel(const CString& pLevelName, time_t modTime) if (!succeed) { - sendPacket(PLO_WARPFAILED, CString() << pLevelName); + sendPacket({PLO_WARPFAILED, CString() << pLevelName}); return false; } @@ -1650,18 +1644,17 @@ bool TPlayer::setLevel(const CString& pLevelName, time_t modTime) } // Inform everybody as to the client's new location. This will update the minimap. - CString minimap = this->getProps(0, 0) >> (char)PLPROP_CURLEVEL << this->getProp(PLPROP_CURLEVEL) >> (char)PLPROP_X << this->getProp(PLPROP_X) >> (char)PLPROP_Y << this->getProp(PLPROP_Y); - for (std::vector::iterator i = server->getPlayerList()->begin(); i != server->getPlayerList()->end(); ++i) + CString minimap = getProps(0, 0) >> (char)PLPROP_CURLEVEL << getProp(PLPROP_CURLEVEL) >> (char)PLPROP_X << getProp(PLPROP_X) >> (char)PLPROP_Y << getProp(PLPROP_Y); + for (auto p : *server->getPlayerList()) { - TPlayer* p = *i; - if (p == this) + if (p == this) continue; if (pmap && pmap->isGroupMap() && levelGroup != p->getGroup()) continue; - p->sendPacket(PLO_OTHERPLPROPS, minimap); + p->sendPacket({PLO_OTHERPLPROPS, minimap}); } - //server->sendPacketToAll(this->getProps(0, 0) >> (char)PLPROP_CURLEVEL << this->getProp(PLPROP_CURLEVEL) >> (char)PLPROP_X << this->getProp(PLPROP_X) >> (char)PLPROP_Y << this->getProp(PLPROP_Y), this); + //server->sendPacketToAll(getProps(0, 0) >> (char)PLPROP_CURLEVEL << getProp(PLPROP_CURLEVEL) >> (char)PLPROP_X << getProp(PLPROP_X) >> (char)PLPROP_Y << getProp(PLPROP_Y), this); return true; } @@ -1672,7 +1665,7 @@ bool TPlayer::sendLevel(TLevel* pLevel, time_t modTime, bool fromAdjacent) CSettings* settings = server->getSettings(); // Send Level - sendPacket(PLO_LEVELNAME, CString() << pLevel->getLevelName()); + sendPacket({PLO_LEVELNAME, CString() << pLevel->getLevelName()}); time_t l_time = getCachedLevelModTime(pLevel); if (modTime == -1) modTime = pLevel->getModTime(); if (l_time == 0) @@ -1680,22 +1673,22 @@ bool TPlayer::sendLevel(TLevel* pLevel, time_t modTime, bool fromAdjacent) if (modTime != pLevel->getModTime()) { if (!newProtocol) - sendPacket(PLO_RAWDATA, CString() >> (int)(1+(64*64*2)+1)); + sendPacket({PLO_RAWDATA, CString() >> (int)(1+(64*64*2)+1)}); sendPacket(pLevel->getBoardPacket()); for (auto layerNumber : pLevel->getLayers()) { if (layerNumber == 0) continue; auto layerPacket = pLevel->getLayerPacket(layerNumber); - if (this->newProtocol) - sendPacket(PLO_RAWDATA, CString() >> (int)(layerPacket.Data.length()+2)); + if (newProtocol) + sendPacket({PLO_RAWDATA, CString() >> (int)(layerPacket.Data.length()+2)}); sendPacket(layerPacket); } } // Send links, signs, and mod time. - sendPacket(PLO_LEVELMODTIME, CString() >> (long long)pLevel->getModTime()); + sendPacket({PLO_LEVELMODTIME, CString() >> (long long)pLevel->getModTime()}); for (const auto& packet : pLevel->getLinkPackets()) { sendPacket(packet); } @@ -1724,27 +1717,27 @@ bool TPlayer::sendLevel(TLevel* pLevel, time_t modTime, bool fromAdjacent) // If we are on a gmap, change our level back to the gmap. if (pmap && pmap->getType() == MapType::GMAP) - sendPacket(PLO_LEVELNAME, CString() << pmap->getMapName()); + sendPacket({PLO_LEVELNAME, CString() << pmap->getMapName()}); // Tell the client if there are any ghost players in the level. // We don't support trial accounts so pass 0 (no ghosts) instead of 1 (ghosts present). - sendPacket(PLO_GHOSTICON, CString() >> (char)0); + sendPacket({PLO_GHOSTICON, CString() >> (char)0}); if ( !fromAdjacent || pmap != 0) { // If we are the leader, send it now. if (pLevel->getPlayer(0) == this || pLevel->isSingleplayer()) - sendPacket(PLO_ISLEADER, CString() << ""); + sendPacket({PLO_ISLEADER, CString() << ""}); } // Send new world time. - sendPacket(PLO_NEWWORLDTIME, CString() << CString().writeGInt4(server->getNWTime())); + sendPacket({PLO_NEWWORLDTIME, CString() << CString().writeGInt4(server->getNWTime())}); if ( !fromAdjacent || pmap != 0) { // Send NPCs. if (pmap && pmap->getType() == MapType::GMAP) { - sendPacket(PLO_SETACTIVELEVEL, CString() << pmap->getMapName()); + sendPacket({PLO_SETACTIVELEVEL, CString() << pmap->getMapName()}); for (const auto& packet : pLevel->getNpcPackets(this, l_time, versionID)) { sendPacket(packet); @@ -1763,7 +1756,7 @@ bool TPlayer::sendLevel(TLevel* pLevel, time_t modTime, bool fromAdjacent) } else { - sendPacket(PLO_SETACTIVELEVEL, CString() << pLevel->getLevelName()); + sendPacket({PLO_SETACTIVELEVEL, CString() << pLevel->getLevelName()}); for (const auto& packet : pLevel->getNpcPackets(this, l_time, versionID)) { sendPacket(packet); } @@ -1776,12 +1769,12 @@ bool TPlayer::sendLevel(TLevel* pLevel, time_t modTime, bool fromAdjacent) { if (pmap) { - server->sendPacketToLevel(PLO_OTHERPLPROPS, this->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool)), pmap, this, false); + server->sendPacketToLevel({PLO_OTHERPLPROPS, getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))}, pmap, this, false); std::vector* playerList = server->getPlayerList(); for (auto & i : *playerList) { TPlayer* player = (TPlayer*)i; - if (player == 0) continue; + if (player == nullptr) continue; if (player == this || player->getMap() != pmap) continue; if (pmap->isGroupMap() && levelGroup != player->getGroup()) continue; @@ -1789,7 +1782,7 @@ bool TPlayer::sendLevel(TLevel* pLevel, time_t modTime, bool fromAdjacent) { int ogmap[2] = {player->getProp(PLPROP_GMAPLEVELX).readGUChar(), player->getProp(PLPROP_GMAPLEVELY).readGUChar()}; if (abs(ogmap[0] - level->getMapX()) < 2 && abs(ogmap[1] - level->getMapY()) < 2) - this->sendPacket(PLO_OTHERPLPROPS, player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))); + sendPacket({PLO_OTHERPLPROPS, player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))}); } else if (pmap->getType() == MapType::BIGMAP) { @@ -1798,19 +1791,19 @@ bool TPlayer::sendLevel(TLevel* pLevel, time_t modTime, bool fromAdjacent) int sgmap[2] = { pLevel->getMapX(), pLevel->getMapY() }; if (abs(ogmap[0] - sgmap[0]) < 2 && abs(ogmap[1] - sgmap[1]) < 2) - this->sendPacket(PLO_OTHERPLPROPS, player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))); + sendPacket({PLO_OTHERPLPROPS, player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))}); } } } else { - server->sendPacketToLevel(PLO_OTHERPLPROPS, this->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool)), 0, level, this); + server->sendPacketToLevel({PLO_OTHERPLPROPS, getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))}, nullptr, level, this); std::vector* playerList = level->getPlayerList(); for (auto & i : *playerList) { TPlayer* player = (TPlayer*)i; if (player == this) continue; - this->sendPacket(PLO_OTHERPLPROPS, player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))); + sendPacket({PLO_OTHERPLPROPS, player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))}); } } } @@ -1834,11 +1827,11 @@ bool TPlayer::sendLevel141(TLevel* pLevel, time_t modTime, bool fromAdjacent) if (modTime != pLevel->getModTime()) { if (!newProtocol) - sendPacket(PLO_RAWDATA,CString() >> (int)(1+(64*64*2)+1)); + sendPacket({PLO_RAWDATA,CString() >> (int)(1+(64*64*2)+1)}); sendPacket(pLevel->getBoardPacket()); if (firstLevel) - sendPacket(PLO_LEVELNAME, CString() << pLevel->getLevelName()); + sendPacket({PLO_LEVELNAME, CString() << pLevel->getLevelName()}); firstLevel = false; // Send links, signs, and mod time. @@ -1852,10 +1845,10 @@ bool TPlayer::sendLevel141(TLevel* pLevel, time_t modTime, bool fromAdjacent) sendPacket(packet); } } - sendPacket(PLO_LEVELMODTIME, CString() >> (long long)pLevel->getModTime()); + sendPacket({PLO_LEVELMODTIME, CString() >> (long long)pLevel->getModTime()}); } else - sendPacket(PLO_LEVELBOARD, CString() << ""); + sendPacket({PLO_LEVELBOARD, CString() << ""}); if ( !fromAdjacent ) { @@ -1880,11 +1873,11 @@ bool TPlayer::sendLevel141(TLevel* pLevel, time_t modTime, bool fromAdjacent) // If we are the leader, send it now. if (pLevel->getPlayer(0) == this || pLevel->isSingleplayer()) - sendPacket(PLO_ISLEADER, CString() << ""); + sendPacket({PLO_ISLEADER, CString() << ""}); } // Send new world time. - sendPacket(PLO_NEWWORLDTIME, CString() << CString().writeGInt4(server->getNWTime())); + sendPacket({PLO_NEWWORLDTIME, CString() << CString().writeGInt4(server->getNWTime())}); // Send NPCs. if ( !fromAdjacent ) @@ -1895,12 +1888,12 @@ bool TPlayer::sendLevel141(TLevel* pLevel, time_t modTime, bool fromAdjacent) // Maps send to players in adjacent levels too. if ( !level->isSingleplayer() && !fromAdjacent ) { - server->sendPacketToLevel(PLO_OTHERPLPROPS, this->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool)), 0, level, this); + server->sendPacketToLevel({PLO_OTHERPLPROPS, getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))}, nullptr, level, this); std::vector* playerList = level->getPlayerList(); for (TPlayer* player : *playerList) { if (player == this) continue; - this->sendPacket(PLO_OTHERPLPROPS, player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))); + sendPacket({PLO_OTHERPLPROPS, player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool))}); } } @@ -1931,13 +1924,13 @@ bool TPlayer::leaveLevel(bool resetCache) // Send PLO_ISLEADER to new level leader. TPlayer* leader = level->getPlayer(0); - if (leader != nullptr) leader->sendPacket(PLO_ISLEADER, CString() << ""); + if (leader != nullptr) leader->sendPacket({PLO_ISLEADER, CString() << ""}); // Tell everyone I left. // This prop isn't used at all??? Maybe it is required for 1.41? // if (pmap && pmap->getType() != MAPTYPE_GMAP) { - server->sendPacketToLevel(PLO_OTHERPLPROPS, this->getProps(0, 0) >> (char)PLPROP_JOINLEAVELVL >> (char)0, 0, level, this); + server->sendPacketToLevel({PLO_OTHERPLPROPS, getProps(0, 0) >> (char)PLPROP_JOINLEAVELVL >> (char)0}, nullptr, level, this); std::vector* playerList = server->getPlayerList(); for (auto & i : *playerList) @@ -1945,12 +1938,12 @@ bool TPlayer::leaveLevel(bool resetCache) auto* player = (TPlayer*)i; if (player == this) continue; if (player->getLevel() != level) continue; - this->sendPacket(PLO_OTHERPLPROPS, player->getProps(0, 0) >> (char)PLPROP_JOINLEAVELVL >> (char)0); + sendPacket({PLO_OTHERPLPROPS, player->getProps(0, 0) >> (char)PLPROP_JOINLEAVELVL >> (char)0}); } } // Set the level pointer to 0. - level = 0; + level = nullptr; return true; } @@ -2120,13 +2113,13 @@ bool TPlayer::addWeapon(LevelItemType defaultWeapon) server->NC_AddWeapon(weapon); } - return this->addWeapon(weapon); + return addWeapon(weapon); } bool TPlayer::addWeapon(const CString& name) { TWeapon* weapon = server->getWeapon(name); - return this->addWeapon(weapon); + return addWeapon(weapon); } bool TPlayer::addWeapon(TWeapon* weapon) @@ -2151,13 +2144,13 @@ bool TPlayer::addWeapon(TWeapon* weapon) bool TPlayer::deleteWeapon(LevelItemType defaultWeapon) { TWeapon* weapon = server->getWeapon(TLevelItem::getItemName(defaultWeapon)); - return this->deleteWeapon(weapon); + return deleteWeapon(weapon); } bool TPlayer::deleteWeapon(const CString& name) { TWeapon* weapon = server->getWeapon(name); - return this->deleteWeapon(weapon); + return deleteWeapon(weapon); } bool TPlayer::deleteWeapon(TWeapon* weapon) @@ -2170,7 +2163,7 @@ bool TPlayer::deleteWeapon(TWeapon* weapon) if (id == -1) return true; // Send delete notice. - sendPacket(PLO_NPCWEAPONDEL, CString() << weapon->getName()); + sendPacket({PLO_NPCWEAPONDEL, CString() << weapon->getName()}); } return true; @@ -2178,34 +2171,34 @@ bool TPlayer::deleteWeapon(TWeapon* weapon) void TPlayer::disableWeapons() { - this->status &= ~PLSTATUS_ALLOWWEAPONS; - sendPacket(PLO_PLAYERPROPS, CString() >> (char)PLPROP_STATUS << getProp(PLPROP_STATUS)); + status &= ~PLSTATUS_ALLOWWEAPONS; + sendPacket({PLO_PLAYERPROPS, CString() >> (char)PLPROP_STATUS << getProp(PLPROP_STATUS)}); } void TPlayer::enableWeapons() { - this->status |= PLSTATUS_ALLOWWEAPONS; - sendPacket(PLO_PLAYERPROPS, CString() >> (char)PLPROP_STATUS << getProp(PLPROP_STATUS)); + status |= PLSTATUS_ALLOWWEAPONS; + sendPacket({PLO_PLAYERPROPS, CString() >> (char)PLPROP_STATUS << getProp(PLPROP_STATUS)}); } void TPlayer::freezePlayer() { - sendPacket(PLO_FREEZEPLAYER2, CString() << ""); + sendPacket({PLO_FREEZEPLAYER2, CString() << ""}); } void TPlayer::unfreezePlayer() { - sendPacket(PLO_UNFREEZEPLAYER, CString() << ""); + sendPacket({PLO_UNFREEZEPLAYER, CString() << ""}); } void TPlayer::sendRPGMessage(const CString &message) { - sendPacket(PLO_RPGWINDOW, CString() << message.gtokenize(), true); + sendPacket({PLO_RPGWINDOW, CString() << message.gtokenize()}, true); } void TPlayer::sendSignMessage(const CString &message) { - sendPacket(PLO_SAY2, CString() << message.replaceAll("\n", "#b")); + sendPacket({PLO_SAY2, CString() << message.replaceAll("\n", "#b")}); } void TPlayer::setAni(CString gani) @@ -2227,7 +2220,7 @@ void TPlayer::deleteFlag(const std::string& pFlagName, bool sendToPlayer) TAccount::deleteFlag(pFlagName); if (sendToPlayer) { - sendPacket(PLO_FLAGDEL, CString() << pFlagName); + sendPacket({PLO_FLAGDEL, CString() << pFlagName}); } } @@ -2240,9 +2233,9 @@ void TPlayer::setFlag(const std::string& pFlagName, const CString& pFlagValue, b if (sendToPlayer) { if (pFlagValue.isEmpty()) - sendPacket(PLO_FLAGSET, CString() << pFlagName); + sendPacket({PLO_FLAGSET, CString() << pFlagName}); else - sendPacket(PLO_FLAGSET, CString() << pFlagName << "=" << pFlagValue); + sendPacket({PLO_FLAGSET, CString() << pFlagName << "=" << pFlagValue}); } } @@ -2260,7 +2253,7 @@ bool TPlayer::msgPLI_NULL(CString& pPacket) if (invalidPackets > 5) { serverlog.out("[%s] Player %s is sending invalid packets.\n", server->getName().text(), nickName.text()); - sendPacket(PLO_DISCMESSAGE, CString() << "Disconnected for sending invalid packets."); + sendPacket({PLO_DISCMESSAGE, CString() << "Disconnected for sending invalid packets."}); return false; } @@ -2317,7 +2310,7 @@ bool TPlayer::msgPLI_LOGIN(CString& pPacket) break; default: serverlog.append("Unknown (%d)\n", type); - sendPacket(PLO_DISCMESSAGE, CString() << "Your client type is unknown. Please inform the " << APP_VENDOR << " Team. Type: " << CString((int)type) << "."); + sendPacket({PLO_DISCMESSAGE, CString() << "Your client type is unknown. Please inform the " << APP_VENDOR << " Team. Type: " << CString((int)type) << "."}); return false; break; } @@ -2336,7 +2329,7 @@ bool TPlayer::msgPLI_LOGIN(CString& pPacket) if (versionID == CLVER_UNKNOWN) { // Get Iterator-Key // 2.19+ RC and any client should get the key. - if ( isClient() || (isRC() && in_codec.getGen() > ENCRYPT_GEN_3) || getKey == true ) { + if ( isClient() || (isRC() && in_codec.getGen() > ENCRYPT_GEN_3) || getKey ) { key = (unsigned char)pPacket.readGChar(); in_codec.reset(key); @@ -2369,14 +2362,14 @@ bool TPlayer::msgPLI_LOGIN(CString& pPacket) // Check for available slots on the server. if (server->getPlayerList()->size() >= (unsigned int)server->getSettings()->getInt("maxplayers", 128)) { - sendPacket(PLO_DISCMESSAGE, CString() << "This server has reached its player limit."); + sendPacket({PLO_DISCMESSAGE, CString() << "This server has reached its player limit."}); return false; } // Check if they are ip-banned or not. if (server->isIpBanned(playerSock->getRemoteIp()) && !hasRight(PLPERM_MODIFYSTAFFACCOUNT)) { - sendPacket(PLO_DISCMESSAGE, CString() << "You have been banned from this server."); + sendPacket({PLO_DISCMESSAGE, CString() << "You have been banned from this server."}); return false; } @@ -2410,7 +2403,7 @@ bool TPlayer::msgPLI_LOGIN(CString& pPacket) } if (!allowed) { - sendPacket(PLO_DISCMESSAGE, CString() << "Your client version is not allowed on this server.\rAllowed: " << *server->getAllowedVersionString()); + sendPacket({PLO_DISCMESSAGE, CString() << "Your client version is not allowed on this server.\rAllowed: " << *server->getAllowedVersionString()}); return false; } } @@ -2419,7 +2412,7 @@ bool TPlayer::msgPLI_LOGIN(CString& pPacket) // TODO: localhost mode. if ( !server->getServerList()->getConnected()) { - sendPacket(PLO_DISCMESSAGE, CString() << "The login server is offline. Try again later."); + sendPacket({PLO_DISCMESSAGE, CString() << "The login server is offline. Try again later."}); return false; } @@ -2457,7 +2450,7 @@ bool TPlayer::msgPLI_BOARDMODIFY(CString& pPacket) // Alter level data. if (level->alterBoard(tiles, loc[0], loc[1], dim[0], dim[1], this)) - server->sendPacketToLevel(PLO_BOARDMODIFY, CString() << (pPacket.text() + 1), 0, level); + server->sendPacketToLevel({PLO_BOARDMODIFY, CString() << (pPacket.text() + 1)}, nullptr, level); if (loc[0] < 0 || loc[0] > 63 || loc[1] < 0 || loc[1] > 63) return true; @@ -2500,7 +2493,7 @@ bool TPlayer::msgPLI_BOARDMODIFY(CString& pPacket) spawnLevelItem(packet2, false); if (getVersion() <= CLVER_5_12) - sendPacket(PLO_ITEMADD, CString() << packet); + sendPacket({PLO_ITEMADD, CString() << packet}); } return true; @@ -2554,7 +2547,7 @@ bool TPlayer::msgPLI_NPCPROPS(CString& pPacket) CString packet = CString() >> (int)npcId; packet << npc->setProps(npcProps, versionID); - server->sendPacketToLevel(PLO_NPCPROPS, packet, pmap, this, false, true); + server->sendPacketToLevel({PLO_NPCPROPS, packet}, pmap, this, false, true); return true; } @@ -2579,13 +2572,13 @@ bool TPlayer::msgPLI_BOMBADD(CString& pPacket) //for (int i = 0; i < pPacket.length(); ++i) printf( "%02x ", (unsigned char)pPacket[i] ); printf( "\n" ); */ - server->sendPacketToLevel(PLO_BOMBADD, CString() >> (short)id << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_BOMBADD, CString() >> (short)id << (pPacket.text() + 1)}, nullptr, level, this); return true; } bool TPlayer::msgPLI_BOMBDEL(CString& pPacket) { - server->sendPacketToLevel(PLO_BOMBDEL, CString() << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_BOMBDEL, CString() << (pPacket.text() + 1)}, nullptr, level, this); return true; } @@ -2593,8 +2586,8 @@ bool TPlayer::msgPLI_TOALL(CString& pPacket) { // Check if the player is in a jailed level. std::vector jailList = server->getSettings()->getStr("jaillevels").tokenize(","); - for (std::vector::iterator i = jailList.begin(); i != jailList.end(); ++i) - if (i->trim() == levelName) return true; + for (auto & i : jailList) + if (i.trim() == levelName) return true; CString message = pPacket.readString(pPacket.readGUChar()); @@ -2607,23 +2600,22 @@ bool TPlayer::msgPLI_TOALL(CString& pPacket) } std::vector* playerList = server->getPlayerList(); - for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) + for (auto player : *playerList) { - TPlayer* player = *i; if (player == this) continue; // See if the player is allowing toalls. unsigned char flags = strtoint(player->getProp(PLPROP_ADDITFLAGS)); if (flags & PLFLAG_NOTOALL) continue; - player->sendPacket(PLO_TOALL, CString() >> (short)id >> (char)message.length() << message); + player->sendPacket({PLO_TOALL, CString() >> (short)id >> (char)message.length() << message}); } return true; } bool TPlayer::msgPLI_HORSEADD(CString& pPacket) { - server->sendPacketToLevel(PLO_HORSEADD, CString() << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_HORSEADD, CString() << (pPacket.text() + 1)}, nullptr, level, this); float loc[2] = {(float)pPacket.readGUChar() / 2.0f, (float)pPacket.readGUChar() / 2.0f}; unsigned char dir_bush = pPacket.readGUChar(); @@ -2637,7 +2629,7 @@ bool TPlayer::msgPLI_HORSEADD(CString& pPacket) bool TPlayer::msgPLI_HORSEDEL(CString& pPacket) { - server->sendPacketToLevel(PLO_HORSEDEL, CString() << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_HORSEDEL, CString() << (pPacket.text() + 1)}, nullptr, level, this); float loc[2] = {(float)pPacket.readGUChar() / 2.0f, (float)pPacket.readGUChar() / 2.0f}; @@ -2647,13 +2639,13 @@ bool TPlayer::msgPLI_HORSEDEL(CString& pPacket) bool TPlayer::msgPLI_ARROWADD(CString& pPacket) { - server->sendPacketToLevel(PLO_ARROWADD, CString() >> (short)id << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_ARROWADD, CString() >> (short)id << (pPacket.text() + 1)}, nullptr, level, this); return true; } bool TPlayer::msgPLI_FIRESPY(CString& pPacket) { - server->sendPacketToLevel(PLO_FIRESPY, CString() >> (short)id << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_FIRESPY, CString() >> (short)id << (pPacket.text() + 1)}, nullptr, level, this); return true; } @@ -2673,7 +2665,7 @@ bool TPlayer::msgPLI_THROWCARRIED(CString& pPacket) level->addNPC(npc); } } - server->sendPacketToLevel(PLO_THROWCARRIED, CString() >> (short)id << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_THROWCARRIED, CString() >> (short)id << (pPacket.text() + 1)}, nullptr, level, this); return true; } @@ -2807,11 +2799,11 @@ bool TPlayer::spawnLevelItem(CString& pPacket, bool playerDrop) { #endif if (level->addItem(loc[0], loc[1], itemType)) { - server->sendPacketToLevel(PLO_ITEMADD, CString() << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_ITEMADD, CString() << (pPacket.text() + 1)}, nullptr, level, this); } else { - sendPacket(PLO_ITEMDEL, CString() << (pPacket.text() + 1)); + sendPacket({PLO_ITEMDEL, CString() << (pPacket.text() + 1)}); } #ifdef V8NPCSERVER @@ -2824,7 +2816,7 @@ bool TPlayer::spawnLevelItem(CString& pPacket, bool playerDrop) { bool TPlayer::msgPLI_ITEMDEL(CString& pPacket) { - server->sendPacketToLevel(PLO_ITEMDEL, CString() << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_ITEMDEL, CString() << (pPacket.text() + 1)}, nullptr, level, this); float loc[2] = {(float)pPacket.readGUChar() / 2.0f, (float)pPacket.readGUChar() / 2.0f}; @@ -2834,7 +2826,7 @@ bool TPlayer::msgPLI_ITEMDEL(CString& pPacket) // If this is a PLI_ITEMTAKE packet, give the item to the player. if (pPacket[0] - 32 == PLI_ITEMTAKE) - this->setProps(CString() << TLevelItem::getItemPlayerProp(item, this), PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); + setProps(CString() << TLevelItem::getItemPlayerProp(item, this), PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); return true; } @@ -2844,11 +2836,11 @@ bool TPlayer::msgPLI_CLAIMPKER(CString& pPacket) // Get the player who killed us. unsigned int pId = pPacket.readGUShort(); TPlayer* player = server->getPlayer(pId, PLTYPE_ANYCLIENT); - if (player == 0 || player == this) return true; + if (player == nullptr || player == this) return true; // Sparring zone rating code. // Uses the glicko rating system. - if (level == 0) return true; + if (level == nullptr) return true; if (level->isSparringZone()) { // Get some stats we are going to use. @@ -2884,15 +2876,15 @@ bool TPlayer::msgPLI_CLAIMPKER(CString& pPacket) if (oldStats[0] != tLoseRating || oldStats[1] != tLoseDeviation) { setRating((int)tLoseRating, (int)tLoseDeviation); - this->setProps(CString() >> (char)PLPROP_RATING >> (int)0, PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); + setProps(CString() >> (char)PLPROP_RATING >> (int)0, PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); } if (oldStats[2] != tWinRating || oldStats[3] != tWinDeviation) { player->setRating((int)tWinRating, (int)tWinDeviation); player->setProps(CString() >> (char)PLPROP_RATING >> (int)0, PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); } - this->setLastSparTime(time(0)); - player->setLastSparTime(time(0)); + setLastSparTime(time(nullptr)); + player->setLastSparTime(time(nullptr)); } else { @@ -2932,13 +2924,13 @@ bool TPlayer::msgPLI_BADDYPROPS(CString& pPacket) // Get the baddy. TLevelBaddy* baddy = level->getBaddy(id); - if (baddy == 0) return true; + if (baddy == nullptr) return true; // Get the leader. TPlayer* leader = level->getPlayer(0); // Set the props and send to everybody in the level, except the leader. - server->sendPacketToLevel(PLO_BADDYPROPS, CString() >> (char)id << props, 0, level, leader); + server->sendPacketToLevel({PLO_BADDYPROPS, CString() >> (char)id << props}, nullptr, level, leader); baddy->setProps(props); return true; } @@ -2947,7 +2939,7 @@ bool TPlayer::msgPLI_BADDYHURT(CString& pPacket) { TPlayer* leader = level->getPlayer(0); if (leader == 0) return true; - leader->sendPacket(PLO_BADDYHURT, CString() << (pPacket.text() + 1)); + leader->sendPacket({PLO_BADDYHURT, CString() << (pPacket.text() + 1)}); return true; } @@ -2976,7 +2968,7 @@ bool TPlayer::msgPLI_BADDYADD(CString& pPacket) baddy->setProps(CString() >> (char)BDPROP_POWERIMAGE >> (char)bPower >> (char)bImage.length() << bImage); // Send the props to everybody in the level. - server->sendPacketToLevel(PLO_BADDYPROPS, CString() >> (char)baddy->getId() << baddy->getProps(), 0, level); + server->sendPacketToLevel({PLO_BADDYPROPS, CString() >> (char)baddy->getId() << baddy->getProps()}, nullptr, level); return true; } @@ -3052,7 +3044,7 @@ bool TPlayer::msgPLI_FLAGSET(CString& pPacket) } // Set Flag - this->setFlag(flagName.text(), flagValue, (versionID > CLVER_2_31)); + setFlag(flagName.text(), flagValue, (versionID > CLVER_2_31)); return true; } @@ -3080,7 +3072,7 @@ bool TPlayer::msgPLI_FLAGDEL(CString& pPacket) } // Remove Flag - this->deleteFlag(flagName); + deleteFlag(flagName); return true; } @@ -3097,7 +3089,7 @@ bool TPlayer::msgPLI_OPENCHEST(CString& pPacket) if (!hasChest(chestStr)) { LevelItemType chestItem = chest->getItemIndex(); setProps(CString() << TLevelItem::getItemPlayerProp(chestItem, this), PLSETPROPS_FORWARD | PLSETPROPS_FORWARDSELF); - sendPacket(PLO_LEVELCHEST, CString() >> (char)1 >> (char)cX >> (char)cY); + sendPacket({PLO_LEVELCHEST, CString() >> (char)1 >> (char)cX >> (char)cY}); chestList.push_back(chestStr); } } @@ -3163,7 +3155,7 @@ bool TPlayer::msgPLI_WANTFILE(CString& pPacket) //printf("WANTFILE: %s\n", file.text()); // Send file. - this->sendFile(file); + sendFile(file); return true; } @@ -3193,7 +3185,7 @@ bool TPlayer::msgPLI_HURTPLAYER(CString& pPacket) if (victim->getProp(PLPROP_STATUS).readGChar() & PLSTATUS_PAUSED) return true; // Send the packet. - victim->sendPacket(PLO_HURTPLAYER, CString() >> (short)id >> (char)hurtdx >> (char)hurtdy >> (char)power >> (int)npc); + victim->sendPacket({PLO_HURTPLAYER, CString() >> (short)id >> (char)hurtdx >> (char)hurtdy >> (char)power >> (int)npc}); return true; } @@ -3209,7 +3201,7 @@ bool TPlayer::msgPLI_EXPLOSION(CString& pPacket) // Send the packet out. CString packet = CString() >> (short)id >> (char)eradius >> (char)(loc[0] * 2) >> (char)(loc[1] * 2) >> (char)epower; - server->sendPacketToLevel(PLO_EXPLOSION, packet, pmap, this, false); + server->sendPacketToLevel({PLO_EXPLOSION, packet}, pmap, this, false); return true; } @@ -3220,18 +3212,17 @@ bool TPlayer::msgPLI_PRIVATEMESSAGE(CString& pPacket) const int sendLimit = 4; if (isClient() && (int)difftime(time(0), lastMessage) <= 4) { - sendPacket(PLO_RC_ADMINMESSAGE, CString() << - "Server message:\xa7You can only send messages once every " << CString((int)sendLimit) << " seconds."); + sendPacket({PLO_RC_ADMINMESSAGE, CString() << "Server message:\xa7You can only send messages once every " << CString((int)sendLimit) << " seconds."}); return true; } - lastMessage = time(0); + lastMessage = time(nullptr); // Check if the player is in a jailed level. std::vector jailList = server->getSettings()->getStr("jaillevels").tokenize(","); bool jailed = false; - for (std::vector::iterator i = jailList.begin(); i != jailList.end(); ++i) + for (auto & jail : jailList) { - if (i->trim() == levelName) + if (jail.trim() == levelName) { jailed = true; break; @@ -3254,8 +3245,7 @@ bool TPlayer::msgPLI_PRIVATEMESSAGE(CString& pPacket) int messageLimit = 1024; if (pmMessage.length() > messageLimit) { - sendPacket(PLO_RC_ADMINMESSAGE, CString() << - "Server message:\xa7There is a message limit of " << CString((int)messageLimit) << " characters."); + sendPacket({PLO_RC_ADMINMESSAGE, CString() << "Server message:\xa7There is a message limit of " << CString((int)messageLimit) << " characters."}); return true; } @@ -3266,8 +3256,7 @@ bool TPlayer::msgPLI_PRIVATEMESSAGE(CString& pPacket) int filter = server->getWordFilter()->apply(this, pmMessage, FILTER_CHECK_PM); if (filter & FILTER_ACTION_WARN) { - sendPacket(PLO_RC_ADMINMESSAGE, CString() << - "Word Filter:\xa7Your PM could not be sent because it was caught by the word filter."); + sendPacket({PLO_RC_ADMINMESSAGE, CString() << "Word Filter:\xa7Your PM could not be sent because it was caught by the word filter."}); return true; } } @@ -3276,11 +3265,11 @@ bool TPlayer::msgPLI_PRIVATEMESSAGE(CString& pPacket) pmMessage.gtokenizeI(); // Send the message out. - for (std::vector::iterator i = pmPlayers.begin(); i != pmPlayers.end(); ++i) + for (unsigned short & i : pmPlayers) { - if (*i >= 16000) + if (i >= 16000) { - TPlayer* pmPlayer = getExternalPlayer(*i); + TPlayer* pmPlayer = getExternalPlayer(i); if (pmPlayer != nullptr) { serverlog.out("Sending PM to global player: %s.\n", pmPlayer->getNickname().text()); pmMessage.guntokenizeI(); @@ -3290,8 +3279,8 @@ bool TPlayer::msgPLI_PRIVATEMESSAGE(CString& pPacket) } else { - TPlayer* pmPlayer = server->getPlayer(*i, PLTYPE_ANYPLAYER | PLTYPE_NPCSERVER); - if (pmPlayer == 0 || pmPlayer == this) continue; + TPlayer* pmPlayer = server->getPlayer(i, PLTYPE_ANYPLAYER | PLTYPE_NPCSERVER); + if (pmPlayer == nullptr || pmPlayer == this) continue; #ifdef V8NPCSERVER if (pmPlayer->isNPCServer()) @@ -3308,12 +3297,12 @@ bool TPlayer::msgPLI_PRIVATEMESSAGE(CString& pPacket) // Jailed people cannot send PMs to normal players. if (jailed && !isStaff() && !pmPlayer->isStaff()) { - sendPacket(PLO_PRIVATEMESSAGE, CString() >> (short)pmPlayer->getId() << "\"Server Message:\"," << "\"From jail you can only send PMs to admins (RCs).\""); + sendPacket({PLO_PRIVATEMESSAGE, CString() >> (short)pmPlayer->getId() << "\"Server Message:\"," << "\"From jail you can only send PMs to admins (RCs).\""}); continue; } // Send the message. - pmPlayer->sendPacket(PLO_PRIVATEMESSAGE, CString() >> (short)id << pmMessageType << pmMessage); + pmPlayer->sendPacket({PLO_PRIVATEMESSAGE, CString() >> (short)id << pmMessageType << pmMessage}); } } @@ -3323,7 +3312,7 @@ bool TPlayer::msgPLI_PRIVATEMESSAGE(CString& pPacket) bool TPlayer::msgPLI_NPCWEAPONDEL(CString& pPacket) { CString weapon = pPacket.readString(""); - for (std::vector::iterator i = weaponList.begin(); i != weaponList.end(); ) + for (auto i = weaponList.begin(); i != weaponList.end(); ) { if (*i == weapon) { @@ -3358,7 +3347,7 @@ bool TPlayer::msgPLI_WEAPONADD(CString& pPacket) // Type 0 means it is a default weapon. if (type == 0) { - this->addWeapon(pPacket.readGChar()); + addWeapon(pPacket.readGChar()); } // NPC weapons. else @@ -3397,7 +3386,7 @@ bool TPlayer::msgPLI_WEAPONADD(CString& pPacket) // Send the weapon to the player now. if (!hasWeapon(weapon->getName())) - this->addWeapon(weapon); + addWeapon(weapon); } return true; @@ -3438,8 +3427,8 @@ bool TPlayer::msgPLI_UPDATEFILE(CString& pPacket) } if (versionID < CLVER_2_1) - sendPacket(PLO_FILESENDFAILED, CString() << file); - else sendPacket(PLO_FILEUPTODATE, CString() << file); + sendPacket({PLO_FILESENDFAILED, CString() << file}); + else sendPacket({PLO_FILEUPTODATE, CString() << file}); return true; } @@ -3474,10 +3463,10 @@ bool TPlayer::msgPLI_ADJACENTLEVEL(CString& pPacket) // Set our old level back to normal. //sendPacket(CString() >> (char)PLO_LEVELNAME << level->getLevelName()); if (pmap && pmap->getType() == MapType::GMAP) - sendPacket(PLO_LEVELNAME, CString() << pmap->getMapName()); - else sendPacket(PLO_LEVELNAME, CString() << level->getLevelName()); + sendPacket({PLO_LEVELNAME, CString() << pmap->getMapName()}); + else sendPacket({PLO_LEVELNAME, CString() << level->getLevelName()}); if (level->getPlayer(0) == this) - sendPacket(PLO_ISLEADER, CString() << ""); + sendPacket({PLO_ISLEADER, CString() << ""}); return true; } @@ -3495,7 +3484,7 @@ bool TPlayer::msgPLI_HITOBJECTS(CString& pPacket) nPacket >> (char)(power * 2) >> (char)(loc[0] * 2) >> (char)(loc[1] * 2); if (nid != -1) nPacket >> (int)nid; - server->sendPacketToLevel(PLO_HITOBJECTS, nPacket, pmap, this, true); + server->sendPacketToLevel({PLO_HITOBJECTS, nPacket}, pmap, this, true); return true; } @@ -3606,12 +3595,12 @@ bool TPlayer::msgPLI_TRIGGERACTION(CString& pPacket) // Send it to the players now. if (actionParts[1] == "ALLPLAYERS") - server->sendPacketTo(PLO_NPCWEAPONADD, PLTYPE_ANYCLIENT, weapon_packet); + server->sendPacketTo(PLTYPE_ANYCLIENT, {PLO_NPCWEAPONADD, weapon_packet}); else { TPlayer* p; p = server->getPlayer(actionParts[1], PLTYPE_ANYCLIENT); - if (p) p->sendPacket(PLO_NPCWEAPONADD, weapon_packet); + if (p) p->sendPacket({PLO_NPCWEAPONADD, weapon_packet}); } grExecParameterList.clear(); } @@ -3698,8 +3687,8 @@ bool TPlayer::msgPLI_TRIGGERACTION(CString& pPacket) error = CString(id) << "," << error; // Send it back to the player. - sendPacket(PLO_FLAGSET, CString() << "gr.fileerror=" << error); - sendPacket(PLO_FLAGSET, CString() << "gr.filedata=" << tokens[line]); + sendPacket({PLO_FLAGSET, CString() << "gr.fileerror=" << error}); + sendPacket({PLO_FLAGSET, CString() << "gr.filedata=" << tokens[line]}); } } @@ -3771,7 +3760,7 @@ bool TPlayer::msgPLI_TRIGGERACTION(CString& pPacket) #endif // Send to the level. - server->sendPacketToLevel(PLO_TRIGGERACTION, CString() >> (short)id << (pPacket.text() + 1), 0, level, this); + server->sendPacketToLevel({PLO_TRIGGERACTION, CString() >> (short)id << (pPacket.text() + 1)}, nullptr, level, this); } } @@ -3875,12 +3864,12 @@ bool TPlayer::msgPLI_SHOOT(CString& pPacket) server->sendPacketToLevel([](const TPlayer* pl) { return pl->getVersion() < CLVER_5_07; - }, PLO_SHOOT, oldPacketBuf, pmap, this, false); + }, {PLO_SHOOT, oldPacketBuf}, pmap, this, false); server->sendPacketToLevel([](const TPlayer* pl) { return pl->getVersion() >= CLVER_5_07; - }, PLO_SHOOT2, newPacketBuf, pmap, this, false); + }, {PLO_SHOOT2, newPacketBuf}, pmap, this, false); // ActionProjectile on server. // TODO(joey): This is accurate, but have not figured out power/zangle stuff yet. @@ -3925,12 +3914,12 @@ bool TPlayer::msgPLI_SHOOT2(CString& pPacket) server->sendPacketToLevel([](const TPlayer* pl) -> bool { return pl->getVersion() < CLVER_5_07; - }, PLO_SHOOT, oldPacketBuf, pmap, this, false); + }, {PLO_SHOOT, oldPacketBuf}, pmap, this, false); server->sendPacketToLevel([](const TPlayer* pl) -> bool { return pl->getVersion() >= CLVER_5_07; - }, PLO_SHOOT2, newPacketBuf, pmap, this, false); + }, {PLO_SHOOT2, newPacketBuf}, pmap, this, false); return true; } diff --git a/server/src/TPlayer/TPlayerExternalPlayers.cpp b/server/src/TPlayer/TPlayerExternalPlayers.cpp index a3c20803..3478de70 100644 --- a/server/src/TPlayer/TPlayerExternalPlayers.cpp +++ b/server/src/TPlayer/TPlayerExternalPlayers.cpp @@ -49,9 +49,9 @@ bool TPlayer::remPMServer(CString& option) ij = externalPlayerList.erase(ij); if (isRC()) - sendPacket(PLO_DELPLAYER, CString() >> pid); + sendPacket({PLO_DELPLAYER, CString() >> pid}); else - sendPacket(PLO_OTHERPLPROPS, CString() >> pid >> (char)PLPROP_PCONNECTED); + sendPacket({PLO_OTHERPLPROPS, CString() >> pid >> (char)PLPROP_PCONNECTED}); } else ++ij; @@ -107,9 +107,9 @@ bool TPlayer::updatePMPlayers(CString& servername, CString& players) ij = externalPlayerList.erase(ij); if (isRC()) - sendPacket(PLO_DELPLAYER, CString() >> pid); + sendPacket({PLO_DELPLAYER, CString() >> pid}); else - sendPacket(PLO_OTHERPLPROPS, CString() >> pid >> (char)PLPROP_PCONNECTED); + sendPacket({PLO_OTHERPLPROPS, CString() >> pid >> (char)PLPROP_PCONNECTED}); //server->sendPacketTo(PLTYPE_ANYCLIENT, CString() >> (char)PLO_OTHERPLPROPS >> (short)id >> (char)PLPROP_PCONNECTED, this); //server->sendPacketTo(PLTYPE_ANYRC, CString() >> (char)PLO_DELPLAYER >> (short)id, this); @@ -180,10 +180,10 @@ bool TPlayer::updatePMPlayers(CString& servername, CString& players) for (std::vector::iterator ij = externalPlayerList.begin(); ij != externalPlayerList.end();) { if (isRC()) { - sendPacket(PLO_ADDPLAYER, CString() >> (short)(*ij)->getId() << (*ij)->getProp(PLPROP_ACCOUNTNAME) >> (char)PLPROP_NICKNAME << (*ij)->getProp(PLPROP_NICKNAME) >> (char)PLPROP_UNKNOWN81 >> (char)1); + sendPacket({PLO_ADDPLAYER, CString() >> (short)(*ij)->getId() << (*ij)->getProp(PLPROP_ACCOUNTNAME) >> (char)PLPROP_NICKNAME << (*ij)->getProp(PLPROP_NICKNAME) >> (char)PLPROP_UNKNOWN81 >> (char)1}); } else { - sendPacket(PLO_OTHERPLPROPS, CString() >> (short)(*ij)->getId() >> (char)PLPROP_ACCOUNTNAME << (*ij)->getProp(PLPROP_ACCOUNTNAME) >> (char)PLPROP_NICKNAME << (*ij)->getProp(PLPROP_NICKNAME) >> (char)PLPROP_UNKNOWN81 >> (char)(1)); + sendPacket({PLO_OTHERPLPROPS, CString() >> (short)(*ij)->getId() >> (char)PLPROP_ACCOUNTNAME << (*ij)->getProp(PLPROP_ACCOUNTNAME) >> (char)PLPROP_NICKNAME << (*ij)->getProp(PLPROP_NICKNAME) >> (char)PLPROP_UNKNOWN81 >> (char)(1)}); } ++ij; diff --git a/server/src/TPlayer/TPlayerLogin.cpp b/server/src/TPlayer/TPlayerLogin.cpp index 23152df2..0870b3a8 100644 --- a/server/src/TPlayer/TPlayerLogin.cpp +++ b/server/src/TPlayer/TPlayerLogin.cpp @@ -49,7 +49,7 @@ bool TPlayer::sendLogin() // Check to see if the player is banned or not. if (isBanned && !hasRight(PLPERM_MODIFYSTAFFACCOUNT)) { - sendPacket(PLO_DISCMESSAGE, CString() << "You have been banned. Reason: " << banReason.guntokenize().replaceAll("\n", "\r")); + sendPacket({PLO_DISCMESSAGE, CString() << "You have been banned. Reason: " << banReason.guntokenize().replaceAll("\n", "\r")}); return false; } @@ -60,7 +60,7 @@ bool TPlayer::sendLogin() if (!isStaff() || !isAdminIp()) { rclog.out("[%s] Attempted RC login by %s.\n", server->getName().text(), accountName.text()); - sendPacket(PLO_DISCMESSAGE, CString() << "You do not have RC rights."); + sendPacket({PLO_DISCMESSAGE, CString() << "You do not have RC rights."}); return false; } } @@ -75,7 +75,7 @@ bool TPlayer::sendLogin() // Staff only. if (server->getSettings()->getBool("onlystaff", false) && !isStaff()) { - sendPacket(PLO_DISCMESSAGE, CString() << "This server is currently restricted to staff only."); + sendPacket({PLO_DISCMESSAGE, CString() << "This server is currently restricted to staff only."}); return false; } @@ -83,7 +83,7 @@ bool TPlayer::sendLogin() std::vector adminIps = adminIp.tokenize(","); if (!isAdminIp() && vecSearch(adminIps, "0.0.0.0") == -1) { - sendPacket(PLO_DISCMESSAGE, CString() << "Your IP doesn't match one of the allowed IPs for this account."); + sendPacket({PLO_DISCMESSAGE, CString() << "Your IP doesn't match one of the allowed IPs for this account."}); return false; } } @@ -91,11 +91,11 @@ bool TPlayer::sendLogin() // Server Signature // 0x49 (73) is used to tell the client that more than eight // players will be playing. - sendPacket(PLO_SIGNATURE, CString() >> (char)73); + sendPacket({PLO_SIGNATURE, CString() >> (char)73}); //if(loginserver) { - sendPacket(PLO_FULLSTOP, ""); - sendPacket(PLO_GHOSTICON, CString() >> (char)1); + sendPacket({PLO_FULLSTOP, ""}); + sendPacket({PLO_GHOSTICON, CString() >> (char)1}); //} if (isClient()) @@ -105,19 +105,18 @@ bool TPlayer::sendLogin() // npc props it modifies. // // NOTE: This may have been deprecated after v5/v6, don't see it in iLogs - sendPacket(PLO_HASNPCSERVER, CString() << ""); + sendPacket({PLO_HASNPCSERVER, CString() << ""}); #endif - sendPacket(PLO_UNKNOWN168, CString() << ""); + sendPacket({PLO_UNKNOWN168, CString() << ""}); } // Check if the account is already in use. if (!getGuest()) { std::vector* playerList = server->getPlayerList(); - for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) + for (auto player : *playerList) { - TPlayer* player = *i; CString oacc = player->getAccountName(); unsigned short oid = (unsigned short)player->getId(); int meClient = ((type & PLTYPE_ANYCLIENT) ? 0 : ((type & PLTYPE_ANYRC) ? 1 : 2)); @@ -126,12 +125,12 @@ bool TPlayer::sendLogin() { if ((int)difftime(time(0), player->getLastData()) > 30) { - player->sendPacket(PLO_DISCMESSAGE, CString() << "Someone else has logged into your account."); + player->sendPacket({PLO_DISCMESSAGE, CString() << "Someone else has logged into your account."}); player->disconnect(); } else { - sendPacket(PLO_DISCMESSAGE, CString() << "Account is already in use."); + sendPacket({PLO_DISCMESSAGE, CString() << "Account is already in use."}); return false; } } @@ -146,7 +145,7 @@ bool TPlayer::sendLogin() bool succeeded = false; if (isClient()) succeeded = sendLoginClient(); else if (isRC()) succeeded = sendLoginRC(); - if (succeeded == false) return false; + if ( !succeeded ) return false; // Set loaded to true so our account is saved when we leave. // This also lets us send data. @@ -159,7 +158,7 @@ bool TPlayer::sendLogin() CString guildPacket = CString(); for (auto & guild : guilds) guildPacket << "\"" << ((CString)guild).trim() << "\","; - sendPacket(PLO_STAFFGUILDS, guildPacket.remove(guildPacket.length() - 1, 1)); + sendPacket({PLO_STAFFGUILDS, guildPacket.remove(guildPacket.length() - 1, 1)}); // Send out the server's available status list options. if ((isClient() && versionID >= CLVER_2_1) || isRC()) @@ -169,12 +168,12 @@ bool TPlayer::sendLogin() for (const auto& status : server->getStatusList()) pliconPacket << status.trim() << ","; - sendPacket(PLO_STATUSLIST, pliconPacket.remove(pliconPacket.length() - 1, 1)); + sendPacket({PLO_STATUSLIST, pliconPacket.remove(pliconPacket.length() - 1, 1)}); } // This comes after status icons for RC if (isRC()) - sendPacket(PLO_RC_MAXUPLOADFILESIZE, CString() >> (long long)(1048576 * 20)); + sendPacket({PLO_RC_MAXUPLOADFILESIZE, CString() >> (long long)(1048576 * 20)}); // Then during iterating the playerlist to send players to the rc client, it sends addplayer followed by rc chat per person. @@ -194,9 +193,8 @@ bool TPlayer::sendLogin() CString rcsOnline; std::vector* playerList = server->getPlayerList(); - for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) + for (TPlayer* player : *playerList) { - TPlayer* player = (TPlayer*)*i; if (player == this) continue; // Don't send npc-control players to others @@ -204,24 +202,24 @@ bool TPlayer::sendLogin() // Send the other player my props. // Send my flags to the npcserver. - player->sendPacket(player->isClient() ? PLO_OTHERPLPROPS : PLO_ADDPLAYER, player->isClient() ? myClientProps : myRCProps); + player->sendPacket({player->isClient() ? PLO_OTHERPLPROPS : PLO_ADDPLAYER, player->isClient() ? myClientProps : myRCProps}); // Add Player / RC. if (isClient()) - sendPacket(PLO_OTHERPLPROPS, player->isClient() ? player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool)) : player->getProps(__getRCLogin, sizeof(__getRCLogin)/sizeof(bool))); + sendPacket({PLO_OTHERPLPROPS, player->isClient() ? player->getProps(__getLogin, sizeof(__getLogin)/sizeof(bool)) : player->getProps(__getRCLogin, sizeof(__getRCLogin)/sizeof(bool))}); else { // Level name. If no level, send an empty space. CString levelName = (player->getLevel() ? player->getLevel()->getLevelName() : " "); // Get the other player's RC props. - this->sendPacket(PLO_ADDPLAYER, CString() + this->sendPacket({PLO_ADDPLAYER, CString() >> (short)player->getId() >> (char)player->getAccountName().length() << player->getAccountName() >> (char)PLPROP_CURLEVEL >> (char)levelName.length() << levelName >> (char)PLPROP_PSTATUSMSG << player->getProp(PLPROP_PSTATUSMSG) >> (char)PLPROP_NICKNAME << player->getProp(PLPROP_NICKNAME) - >> (char)PLPROP_COMMUNITYNAME << player->getProp(PLPROP_COMMUNITYNAME)); + >> (char)PLPROP_COMMUNITYNAME << player->getProp(PLPROP_COMMUNITYNAME)}); // If the other player is an RC, add them to the list of logged in RCs. if (player->isRC()) @@ -231,12 +229,12 @@ bool TPlayer::sendLogin() // If we are an RC, announce the list of currently logged in RCs. if (isRC() && !rcsOnline.isEmpty()) - sendPacket(PLO_RC_CHAT, CString() << "Currently online: " << rcsOnline); + sendPacket({PLO_RC_CHAT, CString() << "Currently online: " << rcsOnline}); } // Ask for processes. This causes windows v6 clients to crash if (isClient() && versionID < CLVER_6_015) - sendPacket(PLO_LISTPROCESSES, CString() << ""); + sendPacket({PLO_LISTPROCESSES, CString() << ""}); return true; } @@ -279,23 +277,23 @@ bool TPlayer::sendLoginClient() } // Sent to rc and client, but rc ignores it so... - sendPacket(PLO_CLEARWEAPONS, CString() << ""); + sendPacket({PLO_CLEARWEAPONS, CString() << ""}); // If the gr.ip hack is enabled, add it to the player's flag list. - if (settings->getBool("flaghack_ip", false) == true) + if ( settings->getBool("flaghack_ip", false)) this->setFlag("gr.ip", this->accountIpStr, true); // Send the player's flags. - for (auto i = flagList.begin(); i != flagList.end(); ++i) + for (auto & i : flagList) { - if (i->second.isEmpty()) sendPacket(PLO_FLAGSET, CString() << i->first); - else sendPacket(PLO_FLAGSET, CString() << i->first << "=" << i->second); + if (i.second.isEmpty()) sendPacket({PLO_FLAGSET, CString() << i.first}); + else sendPacket({PLO_FLAGSET, CString() << i.first << "=" << i.second}); } // Send the server's flags to the player. std::unordered_map * serverFlags = server->getServerFlags(); - for (auto i = serverFlags->begin(); i != serverFlags->end(); ++i) - sendPacket(PLO_FLAGSET, CString() << i->first << "=" << i->second); + for (auto & serverFlag : *serverFlags) + sendPacket({PLO_FLAGSET, CString() << serverFlag.first << "=" << serverFlag.second}); // Delete the bomb and bow. They get automagically added by the client for // God knows which reason. Bomb and Bow must be capitalized. @@ -303,18 +301,18 @@ bool TPlayer::sendLoginClient() //sendPacket(PLO_NPCWEAPONDEL, CString() << "Bow"); // Send the player's weapons. - for (std::vector::iterator i = weaponList.begin(); i != weaponList.end(); ++i) + for (auto & i : weaponList) { - TWeapon* weapon = server->getWeapon(*i); - if (weapon == 0) + TWeapon* weapon = server->getWeapon(i); + if (weapon == nullptr) { // Let's check to see if it is a default weapon. If so, we can add it to the server now. - LevelItemType itemType = TLevelItem::getItemId(*i); + LevelItemType itemType = TLevelItem::getItemId(i); if (itemType != LevelItemType::INVALID) { - CString defWeapPacket = CString() >> (char)PLI_WEAPONADD >> (char)0 >> (char)TLevelItem::getItemTypeId(itemType); - defWeapPacket.readGChar(); - msgPLI_WEAPONADD(defWeapPacket); + CString defaultWeaponPacket = CString() >> (char)PLI_WEAPONADD >> (char)0 >> (char)TLevelItem::getItemTypeId(itemType); + defaultWeaponPacket.readGChar(); + msgPLI_WEAPONADD(defaultWeaponPacket); continue; } continue; @@ -338,21 +336,21 @@ bool TPlayer::sendLoginClient() // Send the zlib fixing NPC to client versions 2.21 - 2.31. if (versionID >= CLVER_2_21 && versionID <= CLVER_2_31) { - sendPacket(PLO_NPCWEAPONADD, CString() + sendPacket({PLO_NPCWEAPONADD, CString() >> (char)12 << "-gr_zlib_fix" >> (char)0 >> (char)1 << "-" - >> (char)1 >> (short)_zlibFix.length() << _zlibFix); + >> (char)1 >> (short)_zlibFix.length() << _zlibFix}); } // Was blank. Sent before weapon list. - sendPacket(PLO_UNKNOWN190, CString() << ""); + sendPacket({PLO_UNKNOWN190, CString() << ""}); // Send the level to the player. // warp will call sendCompress() for us. bool warpSuccess = warp(levelName, x, y); - if (!warpSuccess && level == 0) + if (!warpSuccess && level == nullptr) { - sendPacket(PLO_DISCMESSAGE, CString() << "No level available."); + sendPacket({PLO_DISCMESSAGE, CString() << "No level available."}); serverlog.out(CString() << "[" << server->getName() << "] " << "Cannot find level for " << accountName << "\n"); return false; } @@ -363,9 +361,9 @@ bool TPlayer::sendLoginClient() CString bigmap = settings->getStr("bigmap"); if (!bigmap.isEmpty()) { - std::vector vbigmap = bigmap.tokenize(","); - if (vbigmap.size() == 4) - sendPacket(PLO_BIGMAP, CString() << vbigmap[0].trim() << "," << vbigmap[1].trim() << "," << vbigmap[2].trim() << "," << vbigmap[3].trim()); + std::vector bigmapVector = bigmap.tokenize(","); + if ( bigmapVector.size() == 4) + sendPacket({PLO_BIGMAP, CString() << bigmapVector[0].trim() << "," << bigmapVector[1].trim() << "," << bigmapVector[2].trim() << "," << bigmapVector[3].trim()}); } } @@ -375,21 +373,21 @@ bool TPlayer::sendLoginClient() CString minimap = settings->getStr("minimap"); if (!minimap.isEmpty()) { - std::vector vminimap = minimap.tokenize(","); - if (vminimap.size() == 4) - sendPacket(PLO_MINIMAP, CString() << vminimap[0].trim() << "," << vminimap[1].trim() << "," << vminimap[2].trim() << "," << vminimap[3].trim()); + std::vector minimapVector = minimap.tokenize(","); + if ( minimapVector.size() == 4) + sendPacket({PLO_MINIMAP, CString() << minimapVector[0].trim() << "," << minimapVector[1].trim() << "," << minimapVector[2].trim() << "," << minimapVector[3].trim()}); } } // Send out RPG Window greeting. if (isClient() && versionID >= CLVER_2_1) - sendPacket(PLO_RPGWINDOW, CString() << "\"Welcome to " << settings->getStr("name") << ".\",\"" << CString(APP_VENDOR) << " " << CString(APP_NAME) << " programmed by " << CString(APP_CREDITS) << ".\"" ); + sendPacket({PLO_RPGWINDOW, CString() << "\"Welcome to " << settings->getStr("name") << ".\",\"" << CString(APP_VENDOR) << " " << CString(APP_NAME) << " programmed by " << CString(APP_CREDITS) << ".\""}); // Send the start message to the player. - sendPacket(PLO_STARTMESSAGE, CString() << *(server->getServerMessage())); + sendPacket({PLO_STARTMESSAGE, CString() << *(server->getServerMessage())}); // This will allow serverwarp and some other things, for some reason. - sendPacket(PLO_SERVERTEXT, CString() << ""); + sendPacket({PLO_SERVERTEXT, CString() << ""}); return true; } @@ -398,33 +396,32 @@ bool TPlayer::sendLoginNC() { // Send database npcs std::unordered_map *npcList = server->getNPCNameList(); - for (auto it = npcList->begin(); it != npcList->end(); ++it) + for (auto & it : *npcList) { - TNPC *npc = it->second; + TNPC *npc = it.second; CString npcPacket = CString() >> (int)npc->getId() >> (char)NPCPROP_NAME << npc->getProp(NPCPROP_NAME) >> (char)NPCPROP_TYPE << npc->getProp(NPCPROP_TYPE) >> (char)NPCPROP_CURLEVEL << npc->getProp(NPCPROP_CURLEVEL); - sendPacket(PLO_NC_NPCADD, npcPacket); + sendPacket({PLO_NC_NPCADD, npcPacket}); } // Send classes CString classPacket; auto& classList = server->getClassList(); - for (auto it = classList.begin(); it != classList.end(); ++it) - sendPacket(PLO_NC_CLASSADD, CString() << it->first); + for (auto & it : classList) + sendPacket({PLO_NC_CLASSADD, CString() << it.first}); // Send list of currently connected NC's std::vector* playerList = server->getPlayerList(); - for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) + for (auto player : *playerList) { - TPlayer *player = *i; - if (player != this && player->isNC()) - sendPacket(PLO_RC_CHAT, CString() << "New NC: " << player->getAccountName()); + if (player != this && player->isNC()) + sendPacket({PLO_RC_CHAT, CString() << "New NC: " << player->getAccountName()}); } // Announce to other nc's that we logged in - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYNC, CString() << "New NC: " << accountName, this); + server->sendPacketTo(PLTYPE_ANYNC, {PLO_RC_CHAT, CString() << "New NC: " << accountName}, this); loaded = true; return true; @@ -434,7 +431,7 @@ bool TPlayer::sendLoginRC() { // This packet clears the players weapons on the client, but official // also sends it to the RC's so we are maintaining the same behavior - sendPacket(PLO_CLEARWEAPONS, CString() << ""); + sendPacket({PLO_CLEARWEAPONS, CString() << ""}); // If no nickname was specified, set the nickname to the account name. if (nickName.length() == 0) @@ -447,10 +444,10 @@ bool TPlayer::sendLoginRC() // Send the RC join message to the RC. std::vector rcmessage = CString::loadToken(CString() << server->getServerPath() << "config/rcmessage.txt", "\n", true); for (const auto & i : rcmessage) - sendPacket(PLO_RC_CHAT, CString() << i); + sendPacket({PLO_RC_CHAT, CString() << i}); - sendPacket(PLO_UNKNOWN190, CString() << ""); + sendPacket({PLO_UNKNOWN190, CString() << ""}); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "New RC: " << accountName); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "New RC: " << accountName}); return true; } diff --git a/server/src/TPlayer/TPlayerNC.cpp b/server/src/TPlayer/TPlayerNC.cpp index 1d898557..3e3a9aa3 100644 --- a/server/src/TPlayer/TPlayerNC.cpp +++ b/server/src/TPlayer/TPlayerNC.cpp @@ -36,7 +36,7 @@ bool TPlayer::msgPLI_NC_NPCGET(CString& pPacket) if (npc != nullptr) { CString npcDump = npc->getVariableDump(); - sendPacket(PLO_NC_NPCATTRIBUTES, CString() << npcDump.gtokenize()); + sendPacket({PLO_NC_NPCATTRIBUTES, CString() << npcDump.gtokenize()}); } } @@ -60,7 +60,7 @@ bool TPlayer::msgPLI_NC_NPCDELETE(CString& pPacket) bool result = server->deleteNPC(npc, true); if (result) { - server->sendPacketTo(PLO_NC_NPCDELETE, PLTYPE_ANYNC, CString() >> (int)npcId); + server->sendPacketTo(PLTYPE_ANYNC, {PLO_NC_NPCDELETE, CString() >> (int)npcId}); CString logMsg; logMsg << "NPC " << npcName << " deleted by " << accountName << "\n"; @@ -110,7 +110,7 @@ bool TPlayer::msgPLI_NC_NPCSCRIPTGET(CString& pPacket) if (npc != nullptr) { CString code = npc->getSource().getSource(); - sendPacket(PLO_NC_NPCSCRIPT, CString() >> (int)npcId << code.gtokenize()); + sendPacket({PLO_NC_NPCSCRIPT, CString() >> (int)npcId << code.gtokenize()}); } // else printf("npc doesn't exist\n"); @@ -156,10 +156,10 @@ bool TPlayer::msgPLI_NC_NPCFLAGSGET(CString& pPacket) CString flagListStr; auto flagList = npc->getFlagList(); - for (auto it = flagList->begin(); it != flagList->end(); ++it) - flagListStr << (*it).first << "=" << (*it).second << "\n"; + for (auto & it : *flagList) + flagListStr << it.first << "=" << it.second << "\n"; - sendPacket(PLO_NC_NPCFLAGS, CString() >> (int)npcId << flagListStr.gtokenize()); + sendPacket({PLO_NC_NPCFLAGS, CString() >> (int)npcId << flagListStr.gtokenize()}); } return true; @@ -212,9 +212,8 @@ bool TPlayer::msgPLI_NC_NPCFLAGSSET(CString& pPacket) std::unordered_map newFlagList; // Iterate the new list of flags from the client - for (auto it = newFlags.begin(); it != newFlags.end(); ++it) + for (auto flag : newFlags) { - CString flag = *it; std::string flagName = flag.readString("=").text(); CString flagValue = flag.readString(""); @@ -234,11 +233,11 @@ bool TPlayer::msgPLI_NC_NPCFLAGSSET(CString& pPacket) } // Iterate the old flag list, and find any flags not present in the new flag list. - for (auto it = flagList->begin(); it != flagList->end(); ++it) + for (auto & it : *flagList) { - auto newFlag = newFlagList.find(it->first); + auto newFlag = newFlagList.find(it.first); if (newFlag == newFlagList.end()) - deletedFlagMsg << "flag deleted:\t" << it->first << "=" << it->second << "\n"; + deletedFlagMsg << "flag deleted:\t" << it.first << "=" << it.second << "\n"; } // Update flag list, and save the changes @@ -299,7 +298,7 @@ bool TPlayer::msgPLI_NC_NPCADD(CString& pPacket) newNpc->setProps(CString() >> (char)NPCPROP_SCRIPTER >> (char)npcScripter.length() << npcScripter << npcProps); // Send packet to npc controls about new npc - server->sendPacketTo(PLO_NC_NPCADD, PLTYPE_ANYNC, CString() >> (int)newNpc->getId() << npcProps); + server->sendPacketTo(PLTYPE_ANYNC, {PLO_NC_NPCADD, CString() >> (int)newNpc->getId() << npcProps}); // Persist NPC newNpc->saveNPC(); @@ -334,7 +333,7 @@ bool TPlayer::msgPLI_NC_CLASSEDIT(CString& pPacket) CString ret; ret >> (char)className.length() << className << classCode.gtokenize(); - sendPacket(PLO_NC_CLASSGET, ret); + sendPacket({PLO_NC_CLASSGET, ret}); } return true; @@ -362,7 +361,7 @@ bool TPlayer::msgPLI_NC_CLASSADD(CString& pPacket) { CString ret; ret << className; - server->sendPacketTo(PLO_NC_CLASSADD, PLTYPE_ANYNC, ret); + server->sendPacketTo(PLTYPE_ANYNC, {PLO_NC_CLASSADD, ret}); } // Logging @@ -388,7 +387,7 @@ bool TPlayer::msgPLI_NC_CLASSDELETE(CString& pPacket) { CString ret; ret << className; - server->sendPacketTo(PLO_NC_CLASSDELETE, PLTYPE_ANYNC, ret); + server->sendPacketTo(PLTYPE_ANYNC, {PLO_NC_CLASSDELETE, ret}); logMsg << accountName << " has deleted class " << className << "\n"; } else @@ -421,10 +420,10 @@ bool TPlayer::msgPLI_NC_LOCALNPCSGET(CString& pPacket) npcDump << "Variables dump from level " << npcLevel->getLevelName() << "\n"; auto npcList = npcLevel->getLevelNPCs(); - for (auto it = npcList->begin(); it != npcList->end(); ++it) - npcDump << "\n" << (*it)->getVariableDump() << "\n"; + for (auto & it : *npcList) + npcDump << "\n" << it->getVariableDump() << "\n"; - sendPacket(PLO_NC_LEVELDUMP, CString() << npcDump.gtokenize()); + sendPacket({PLO_NC_LEVELDUMP, CString() << npcDump.gtokenize()}); } return true; @@ -443,16 +442,16 @@ bool TPlayer::msgPLI_NC_WEAPONLISTGET(CString& pPacket) // Iterate weapon list and send names auto weaponList = server->getWeaponList(); - for (auto it = weaponList->begin(); it != weaponList->end(); ++it) + for (auto & it : *weaponList) { - if (it->second->isDefault()) + if (it.second->isDefault()) continue; - CString weaponName = it->second->getName(); + CString weaponName = it.second->getName(); ret >> (char)weaponName.length() << weaponName; } - sendPacket(PLO_NC_WEAPONLISTGET, ret); + sendPacket({PLO_NC_WEAPONLISTGET, ret}); return true; } @@ -475,20 +474,20 @@ bool TPlayer::msgPLI_NC_WEAPONGET(CString& pPacket) if (getVersion() < NCVER_2_1) { - sendPacket(PLO_NPCWEAPONADD, CString() + sendPacket({PLO_NPCWEAPONADD, CString() >> (char)weaponName.length() << weaponName >> (char)0 >> (char)weapon->getImage().length() << weapon->getImage() - >> (char)1 >> (short)script.length() << script); + >> (char)1 >> (short)script.length() << script}); } else { - sendPacket(PLO_NC_WEAPONGET, CString() >> + sendPacket({PLO_NC_WEAPONGET, CString() >> (char)weaponName.length() << weaponName >> (char)weapon->getImage().length() << weapon->getImage() << - script); + script}); } } - else server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYNC, CString() << accountName << " prob: weapon " << weaponName << " doesn't exist"); + else server->sendPacketTo(PLTYPE_ANYNC, {PLO_RC_CHAT, CString() << accountName << " prob: weapon " << weaponName << " doesn't exist"}); return true; } @@ -512,7 +511,7 @@ bool TPlayer::msgPLI_NC_WEAPONADD(CString& pPacket) // Find Weapon TWeapon *weaponObj = server->getWeapon(weaponName); - if (weaponObj != 0) + if (weaponObj != nullptr) { // default weapon, don't update! if (weaponObj->isDefault()) @@ -587,7 +586,7 @@ bool TPlayer::msgPLI_NC_LEVELLISTGET(CString& pPacket) ret << (*it)->getActualLevelName() << "\n"; } - sendPacket(PLO_NC_LEVELLIST, CString() << ret.gtokenize()); + sendPacket({PLO_NC_LEVELLIST, CString() << ret.gtokenize()}); return true; } @@ -611,7 +610,7 @@ void TPlayer::sendNCAddr() npcServerIp = accountIpStr; } - sendPacket(PLO_NPCSERVERADDR, CString() >> (short)npcServer->getId() << npcServerIp << "," << CString(server->getNCPort())); + sendPacket({PLO_NPCSERVERADDR, CString() >> (short)npcServer->getId() << npcServerIp << "," << CString(server->getNCPort())}); } } diff --git a/server/src/TPlayer/TPlayerProps.cpp b/server/src/TPlayer/TPlayerProps.cpp index 8bba9d2f..368aed1b 100644 --- a/server/src/TPlayer/TPlayerProps.cpp +++ b/server/src/TPlayer/TPlayerProps.cpp @@ -1,1146 +1,1146 @@ -#include "IDebug.h" -#include - -#include "TServer.h" -#include "TPlayer.h" -#include "IEnums.h" -#include "IUtil.h" -#include "TMap.h" -#include "TLevel.h" - -#define serverlog server->getServerLog() -#define rclog server->getRCLog() -extern bool __sendLocal[propscount]; -extern int __attrPackets[30]; - -/* - TPlayer: Prop-Manipulation -*/ -void TPlayer::getProp(CString& buffer, int pPropId) const -{ - switch (pPropId) - { - case PLPROP_NICKNAME: - buffer >> (char)nickName.length() << nickName; - return; - - case PLPROP_MAXPOWER: - buffer >> (char)maxPower; - return; - - case PLPROP_CURPOWER: - buffer >> (char)(power * 2); - return; - - case PLPROP_RUPEESCOUNT: - buffer >> (int)gralatc; - return; - - case PLPROP_ARROWSCOUNT: - buffer >> (char)arrowc; - return; - - case PLPROP_BOMBSCOUNT: - buffer >> (char)bombc; - return; - - case PLPROP_GLOVEPOWER: - buffer >> (char)glovePower; - return; - - case PLPROP_BOMBPOWER: - buffer >> (char)bombPower; - return; - - case PLPROP_SWORDPOWER: - buffer >> (char)(swordPower + 30) >> (char)swordImg.length() << swordImg; - return; - - case PLPROP_SHIELDPOWER: - buffer >> (char)(shieldPower + 10) >> (char)shieldImg.length() << shieldImg; - return; - - case PLPROP_GANI: - { - if (isClient() && versionID < CLVER_2_1) - { - if (!bowImage.isEmpty()) - buffer >> (char)(10 + bowImage.length()) << bowImage; - else - buffer >> (char)bowPower; - return; - } - - buffer >> (char)gani.length() << gani; - return; - } - - case PLPROP_HEADGIF: - buffer >> (char)(headImg.length() + 100) << headImg; - return; - - case PLPROP_CURCHAT: - buffer >> (char)chatMsg.length() << chatMsg; - return; - - case PLPROP_COLORS: - buffer >> (char)colors[0] >> (char)colors[1] >> (char)colors[2] >> (char)colors[3] >> (char)colors[4]; - return; - - case PLPROP_ID: - buffer >> (short)id; - return; - - case PLPROP_X: - buffer >> (char)(x * 2); - return; - - case PLPROP_Y: - buffer >> (char)(y * 2); - return; - - case PLPROP_Z: - buffer >> (char)((z + 0.5f) + 50); - return; - - case PLPROP_SPRITE: - buffer >> (char)sprite; - return; - - case PLPROP_STATUS: - buffer >> (char)status; - return; - - case PLPROP_CARRYSPRITE: - buffer >> (char)carrySprite; - return; - - case PLPROP_CURLEVEL: - { - if (isClient())// || type == PLTYPE_AWAIT) - { - if (pmap && pmap->getType() == MapType::GMAP) - buffer >> (char)pmap->getMapName().length() << pmap->getMapName(); - else - { - if (level != nullptr && level->isSingleplayer()) - buffer >> (char)(levelName.length() + 13) << levelName << ".singleplayer"; - else - buffer >> (char)levelName.length() << levelName; - } - return; - } - else - buffer >> (char)1 << " "; - return; - } - - case PLPROP_HORSEGIF: - buffer >> (char)horseImg.length() << horseImg; - return; - - case PLPROP_HORSEBUSHES: - buffer >> (char)horsec; - return; - - case PLPROP_EFFECTCOLORS: - buffer >> (char)0; - return; - - case PLPROP_CARRYNPC: - buffer >> (int)carryNpcId; - return; - - case PLPROP_APCOUNTER: - buffer >> (short)(apCounter + 1); - return; - - case PLPROP_MAGICPOINTS: - buffer >> (char)mp; - return; - - case PLPROP_KILLSCOUNT: - buffer >> (int)kills; - return; - - case PLPROP_DEATHSCOUNT: - buffer >> (int)deaths; - return; - - case PLPROP_ONLINESECS: - buffer >> (int)onlineTime; - return; - - case PLPROP_IPADDR: - buffer.writeGInt5(accountIp); - return; - - case PLPROP_UDPPORT: - buffer >> (int)udpport; - return; - - case PLPROP_ALIGNMENT: - buffer >> (char)ap; - return; - - case PLPROP_ADDITFLAGS: - buffer >> (char)additionalFlags; - return; - - case PLPROP_ACCOUNTNAME: - buffer >> (char)accountName.length() << accountName; - return; - - case PLPROP_BODYIMG: - buffer >> (char)bodyImg.length() << bodyImg; - return; - - case PLPROP_RATING: - { - int temp = (((int)rating & 0xFFF) << 9) | ((int)deviation & 0x1FF); - buffer >> (int)temp; - return; - } - - case PLPROP_ATTACHNPC: - { - // Only attach type 0 (NPC) supported. - buffer >> (char)0 >> (int)attachNPC; - return; - } - - // Simplifies login. - // Manually send prop if you are leaving the level. - // 1 = join level, 0 = leave level. - case PLPROP_JOINLEAVELVL: - buffer >> (char)1; - return; - - case PLPROP_PCONNECTED: - //return CString(); - return; - - case PLPROP_PLANGUAGE: - buffer >> (char)language.length() << language; - return; - - case PLPROP_PSTATUSMSG: - { - //if (id == -1) - // break; - - if (statusMsg > server->getStatusList().size() - 1) - buffer >> (char)0; - else - buffer >> (char)statusMsg; - return; - } - - // OS type. - // Windows: wind - case PLPROP_OSTYPE: - buffer >> (char)os.length() << os; - return; - - // Text codepage. - // Example: 1252 - case PLPROP_TEXTCODEPAGE: - buffer.writeGInt(codepage); - return; - - case PLPROP_X2: - { - uint16_t val = ((uint16_t)std::abs(x * 16.0f)) << 1; - if (x < 0) - val |= 0x0001; - buffer.writeGShort(val); - return; - } - - case PLPROP_Y2: - { - uint16_t val = ((uint16_t)std::abs(y * 16.0f)) << 1; - if (y < 0) - val |= 0x0001; - buffer.writeGShort(val); - return; - } - - case PLPROP_Z2: - { - uint16_t val = ((uint16_t)std::abs(z * 16.0f)) << 1; - if (z < 0) - val |= 0x0001; - buffer.writeGShort(val); - return; - } - - case PLPROP_GMAPLEVELX: - buffer >> (char)(level ? level->getMapX() : 0); - return; - - case PLPROP_GMAPLEVELY: - buffer >> (char)(level ? level->getMapY() : 0); - return; - - // TODO(joey): figure this out. Something to do with guilds? irc-related - // (char)(some bitflag for something, uses the first 3 bits im not sure) - // okay i tested some flags, 1 removes the channel. 3 adds it. not sure what third bit does. - case PLPROP_UNKNOWN81: - //return CString(); - return; - - case PLPROP_COMMUNITYNAME: - buffer >> (char)communityName.length() << communityName; - return; - - default: - break; - } - - if (inrange(pPropId, 37, 41) || inrange(pPropId, 46, 49) || inrange(pPropId, 54, 74)) - { - for (auto i = 0; i < sizeof(__attrPackets) / sizeof(int); i++) - { - if (__attrPackets[i] == pPropId) - { - char len = std::min(attrList[i].length(), 223); - buffer >> (char)len << attrList[i].subString(0, len); - return; - } - } - } -} - -void TPlayer::setProps(CString& pPacket, uint8_t options, TPlayer* rc) -{ - CString globalBuff, levelBuff, levelBuff2, selfBuff; - bool doTouchTest = false; - bool sentInvalid = false; - int len = 0; - - while (pPacket.bytesLeft() > 0) - { - unsigned char propId = pPacket.readGUChar(); - - switch (propId) - { - case PLPROP_NICKNAME: - { - CString nick = pPacket.readChars(pPacket.readGUChar()); - - // Word filter. - int filter = server->getWordFilter()->apply(this, nick, FILTER_CHECK_NICK); - if (filter & FILTER_ACTION_WARN) - { - if (nickName.isEmpty()) - setNick("unknown"); - } - else setNick(nick, !(options & PLSETPROPS_SETBYPLAYER)); - - if (options & PLSETPROPS_FORWARD) - globalBuff >> (char)propId << getProp(propId); - - // Send this if the player is located on another server - // globalBuff >> (char)81; - - if (!(options & PLSETPROPS_FORWARDSELF)) - selfBuff >> (char)propId << getProp(propId); - } - break; - - case PLPROP_MAXPOWER: - { - uint8_t newMaxPower = pPacket.readGUChar(); - -#ifdef V8NPCSERVER - if (!(options & PLSETPROPS_SETBYPLAYER)) { -#endif - setMaxPower(newMaxPower); - setPower((float)maxPower); - -#ifdef V8NPCSERVER - levelBuff >> (char)PLPROP_MAXPOWER << getProp(PLPROP_MAXPOWER); - selfBuff >> (char)PLPROP_MAXPOWER << getProp(PLPROP_MAXPOWER); -#endif - levelBuff >> (char)PLPROP_CURPOWER << getProp(PLPROP_CURPOWER); - selfBuff >> (char)PLPROP_CURPOWER << getProp(PLPROP_CURPOWER); -#ifdef V8NPCSERVER - } -#endif - - break; - } - - case PLPROP_CURPOWER: - { - float p = (float)pPacket.readGUChar() / 2.0f; - if (ap < 40 && p > power) break; - //if ((status & PLSTATUS_HIDESWORD) != 0) - // break; - setPower(p); - break; - } - - case PLPROP_RUPEESCOUNT: - { - unsigned int newGralatCount = std::min(pPacket.readGUInt(), 9999999u); - -#ifdef V8NPCSERVER - if (!(options & PLSETPROPS_SETBYPLAYER)) { -#endif - if (rc != nullptr) - { - if (server->getSettings()->getBool("normaladminscanchangegralats", true) || (rc->isStaff() && rc->hasRight(PLPERM_SETRIGHTS))) - gralatc = newGralatCount; - } - else - { - gralatc = newGralatCount; - } -#ifdef V8NPCSERVER - } -#endif - break; - } - - case PLPROP_ARROWSCOUNT: - arrowc = pPacket.readGUChar(); - arrowc = clip(arrowc, 0, 99); - break; - - case PLPROP_BOMBSCOUNT: - bombc = pPacket.readGUChar(); - bombc = clip(bombc, 0, 99); - break; - - case PLPROP_GLOVEPOWER: - { - uint8_t newGlovePower = pPacket.readGUChar(); -#ifdef V8NPCSERVER - if (!(options & PLSETPROPS_SETBYPLAYER)) { -#endif - glovePower = std::min(newGlovePower, 3); -#ifdef V8NPCSERVER - } -#endif - break; - } - - case PLPROP_BOMBPOWER: - bombPower = pPacket.readGUChar(); - bombPower = clip(bombPower, 0, 3); - break; - - case PLPROP_SWORDPOWER: - { - int sp = pPacket.readGUChar(); - CString img; - - if (sp <= 4) - { - CSettings* settings = server->getSettings(); - sp = clip(sp, 0, settings->getInt("swordlimit", 3)); - img = CString() << "sword" << CString(sp) << (versionID < CLVER_2_1 ? ".gif" : ".png"); - } - else - { - sp -= 30; - len = pPacket.readGUChar(); - if (len > 0) - { - img = pPacket.readChars(len); - if (!img.isEmpty() && versionID < CLVER_2_1 && getExtension(img).isEmpty()) - img << ".gif"; - } - else img = ""; - } - -#ifdef V8NPCSERVER - if (!(options & PLSETPROPS_SETBYPLAYER)) { -#endif - setSwordPower(sp); -#ifdef V8NPCSERVER - } -#endif - setSwordImage(img); - } - break; - - case PLPROP_SHIELDPOWER: - { - int sp = pPacket.readGUChar(); - CString img; - - if (sp <= 3) - { - CSettings* settings = server->getSettings(); - sp = clip(sp, 0, settings->getInt("shieldlimit", 3)); - img = CString() << "shield" << CString(sp) << (versionID < CLVER_2_1 ? ".gif" : ".png"); - } - else - { - // This fixes an odd bug with the 1.41 client. - if (pPacket.bytesLeft() == 0) continue; - - sp -= 10; - if (sp < 0) break; - len = pPacket.readGUChar(); - if (len > 0) - { - img = pPacket.readChars(len); - if (!img.isEmpty() && versionID < CLVER_2_1 && getExtension(img).isEmpty()) - img << ".gif"; - } - else img = ""; - } - -#ifdef V8NPCSERVER - if (!(options & PLSETPROPS_SETBYPLAYER)) { -#endif - setShieldPower(sp); -#ifdef V8NPCSERVER - } -#endif - setShieldImage(img); - } - break; - - case PLPROP_GANI: - { - if (isClient() && versionID < CLVER_2_1) - { - int sp = pPacket.readGUChar(); - if (sp < 10) - { - bowPower = sp; - bowImage.clear(); - } - else - { - bowPower = 10; - sp -= 10; - if (sp < 0) break; - bowImage = CString() << pPacket.readChars(sp); - if (!bowImage.isEmpty() && versionID < CLVER_2_1 && getExtension(bowImage).isEmpty()) - bowImage << ".gif"; - } - break; - } - - setGani(pPacket.readChars(pPacket.readGUChar())); - if (gani == "spin") - { - CString nPacket; - nPacket >> (short)id >> (char)swordPower; - char hx = (char)((x + 1.5f) * 2); - char hy = (char)((y + 2.0f) * 2); - server->sendPacketToLevel(PLO_HITOBJECTS, CString() << nPacket >> (char)(hx) >> (char)(hy - 4), 0, level, this); - server->sendPacketToLevel(PLO_HITOBJECTS, CString() << nPacket >> (char)(hx) >> (char)(hy + 4), 0, level, this); - server->sendPacketToLevel(PLO_HITOBJECTS, CString() << nPacket >> (char)(hx - 4) >> (char)(hy), 0, level, this); - server->sendPacketToLevel(PLO_HITOBJECTS, CString() << nPacket >> (char)(hx + 4) >> (char)(hy), 0, level, this); - } - } - break; - - case PLPROP_HEADGIF: - { - len = pPacket.readGUChar(); - CString img; - if (len < 100) - { - img = CString() << "head" << CString(len) << (versionID < CLVER_2_1 ? ".gif" : ".png"); - } - else if (len > 100) - { - img = pPacket.readChars(len - 100); - - // TODO(joey): We need to check properties for newline, especially if they are sending to other clients - // as it causes havoc on the client... - int check = img.find("\n", 0); - if (check > 0) - img = img.readChars(check); - - if (!img.isEmpty() && versionID < CLVER_2_1 && getExtension(img).isEmpty()) - img << ".gif"; - } - - if (len != 100) - { - setHeadImage(img); - globalBuff >> (char)propId << getProp(propId); - } - - break; - } - - case PLPROP_CURCHAT: - { - len = pPacket.readGUChar(); - chatMsg = pPacket.readChars(std::min(len, 223)); - lastChat = time(0); - - // Try to process the chat. If it wasn't processed, apply the word filter to it. - if (!processChat(chatMsg)) - { - int found = server->getWordFilter()->apply(this, chatMsg, FILTER_CHECK_CHAT); - if (!(options & PLSETPROPS_FORWARDSELF)) - { - if ((found & FILTER_ACTION_REPLACE) || (found & FILTER_ACTION_WARN)) - selfBuff >> (char)propId << getProp(propId); - } - } - -#ifdef V8NPCSERVER - // Send chat to npcs if this wasn't changed by the npcserver - if (!rc && !chatMsg.isEmpty()) - { - if (level != nullptr) - level->sendChatToLevel(this, chatMsg.text()); - } -#endif - } - break; - - case PLPROP_COLORS: - for (unsigned char & color : colors) - color = pPacket.readGUChar(); - break; - - case PLPROP_ID: - pPacket.readGUShort(); - break; - - case PLPROP_X: - x = (float)(pPacket.readGUChar() / 2.0f); - status &= (~PLSTATUS_PAUSED); - lastMovement = time(0); - grMovementUpdated = true; - - // Do collision testing. - doTouchTest = true; - - // Let 2.30+ clients see pre-2.30 movement. - levelBuff2 >> (char)PLPROP_X2 << getProp(PLPROP_X2); - break; - - case PLPROP_Y: - y = (float)(pPacket.readGUChar() / 2.0f); - status &= (~PLSTATUS_PAUSED); - lastMovement = time(0); - grMovementUpdated = true; - - // Do collision testing. - doTouchTest = true; - - // Let 2.30+ clients see pre-2.30 movement. - levelBuff2 >> (char)PLPROP_Y2 << getProp(PLPROP_Y2); - break; - - case PLPROP_Z: - z = (float)pPacket.readGUChar() - 50.0f; - status &= (~PLSTATUS_PAUSED); - lastMovement = time(0); - grMovementUpdated = true; - doTouchTest = true; - - // Let 2.30+ clients see pre-2.30 movement. - levelBuff2 >> (char)PLPROP_Z2 << getProp(PLPROP_Z2); - break; - - case PLPROP_SPRITE: - sprite = pPacket.readGUChar(); - -#ifndef V8NPCSERVER - // Do collision testing. - doTouchTest = true; -#endif - break; - - case PLPROP_STATUS: - { - int oldStatus = status; - status = pPacket.readGUChar(); - //printf("%s: status: %d, oldStatus: %d\n", accountName.text(), status, oldStatus ); - - if (id == -1) break; - - // When they come back to life, give them hearts. - if ((oldStatus & PLSTATUS_DEAD) > 0 && (status & PLSTATUS_DEAD) == 0) - { - auto newPower = clip((ap < 20 ? 3 : (ap < 40 ? 5 : maxPower)), 0.5f, maxPower); - setPower(newPower); - - selfBuff >> (char)PLPROP_CURPOWER >> (char)(power * 2.0f); - levelBuff >> (char)PLPROP_CURPOWER >> (char)(power * 2.0f); - - if (level != 0 && level->getPlayer(0) == this) - sendPacket(PLO_ISLEADER, CString() << ""); - /* - // If we are the leader of the level, call warp(). This will fix NPCs not - // working again after we respawn. - if (level != 0 && level->getPlayer(0) == this) - warp(levelName, x, y, time(0)); - */ - } - - // When they die, increase deaths and make somebody else level leader. - if ((oldStatus & PLSTATUS_DEAD) == 0 && (status & PLSTATUS_DEAD) > 0) - { - if (level->isSparringZone() == false) - { - deaths++; - dropItemsOnDeath(); - } - - // If we are the leader and there are more players on the level, we want to remove - // ourself from the leader position and tell the new leader that they are the leader. - if (level->getPlayer(0) == this && level->getPlayer(1) != 0) - { - level->removePlayer(this); - level->addPlayer(this); - level->getPlayer(0)->sendPacket(PLO_ISLEADER, CString() << ""); - } - } - } - break; - - case PLPROP_CARRYSPRITE: - carrySprite = pPacket.readGUChar(); - break; - - case PLPROP_CURLEVEL: - len = pPacket.readGUChar(); -#ifdef V8NPCSERVER - pPacket.readChars(len); -#else - levelName = pPacket.readChars(len); -#endif - break; - - case PLPROP_HORSEGIF: - len = pPacket.readGUChar(); - horseImg = pPacket.readChars(std::min(len, 219)); // limit is 219 in case it appends .gif - if (!horseImg.isEmpty() && versionID < CLVER_2_1 && getExtension(horseImg).isEmpty()) - horseImg << ".gif"; - break; - - case PLPROP_HORSEBUSHES: - horsec = pPacket.readGUChar(); - break; - - case PLPROP_EFFECTCOLORS: - len = pPacket.readGUChar(); - if (len > 0) - pPacket.readGInt4(); - break; - - case PLPROP_CARRYNPC: - { - carryNpcId = pPacket.readGUInt(); - - // TODO: Remove when an npcserver is created. - if (server->getSettings()->getBool("duplicatecanbecarried", false) == false) - { - bool isOwner = true; - { - std::vector* playerList = server->getPlayerList(); - for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) - { - TPlayer* other = *i; - if (other == this) continue; - if (other->getProp(PLPROP_CARRYNPC).readGUInt() == carryNpcId) - { - // Somebody else got this NPC first. Force the player to throw his down - // and tell the player to remove the NPC from memory. - carryNpcId = 0; - isOwner = false; - sendPacket(PLO_PLAYERPROPS, CString() >> (char)PLPROP_CARRYNPC >> (int)0); - sendPacket(PLO_NPCDEL2, CString() >> (char)level->getLevelName().length() << level->getLevelName() >> (int)carryNpcId); - server->sendPacketToLevel(PLO_OTHERPLPROPS, CString() >> (short)id >> (char)PLPROP_CARRYNPC >> (int)0, pmap, this); - break; - } - } - } - if (isOwner) - { - // We own this NPC now so remove it from the level and have everybody else delete it. - TNPC* npc = server->getNPC(carryNpcId); - level->removeNPC(npc); - server->sendPacketToAll(PLO_NPCDEL2, CString() >> (char)level->getLevelName().length() << level->getLevelName() >> (int)carryNpcId, nullptr); - } - } - } - break; - - case PLPROP_APCOUNTER: - apCounter = pPacket.readGUShort(); - break; - - case PLPROP_MAGICPOINTS: - { - uint8_t newMP = pPacket.readGUChar(); -#ifdef V8NPCSERVER - if (!(options & PLSETPROPS_SETBYPLAYER)) { -#endif - mp = std::min(newMP, 100); -#ifdef V8NPCSERVER - } -#endif - break; - } - - case PLPROP_KILLSCOUNT: - pPacket.readGInt(); - break; - - case PLPROP_DEATHSCOUNT: - pPacket.readGInt(); - break; - - case PLPROP_ONLINESECS: - pPacket.readGInt(); - break; - - case PLPROP_IPADDR: - pPacket.readGInt5(); - break; - - case PLPROP_UDPPORT: - udpport = pPacket.readGInt(); - if (id != -1 && loaded) - server->sendPacketTo(PLO_OTHERPLPROPS, PLTYPE_ANYCLIENT, CString() >> (short)id >> (char)PLPROP_UDPPORT >> (int)udpport, this); - // TODO: udp support. - break; - - case PLPROP_ALIGNMENT: - { - uint8_t newAlignment = pPacket.readGUChar(); -#ifdef V8NPCSERVER - if (!(options & PLSETPROPS_SETBYPLAYER)) { -#endif - ap = std::min(newAlignment, 100); -#ifdef V8NPCSERVER - } -#endif - break; - } - - case PLPROP_ADDITFLAGS: - additionalFlags = pPacket.readGUChar(); - break; - - case PLPROP_ACCOUNTNAME: - len = pPacket.readGUChar(); - pPacket.readChars(len); - break; - - case PLPROP_BODYIMG: - len = pPacket.readGUChar(); - setBodyImage(pPacket.readChars(len)); - break; - - case PLPROP_RATING: - len = pPacket.readGInt(); - //rating = (float)((len >> 9) & 0xFFF); - break; - - case PLPROP_ATTACHNPC: - { - // Only supports object_type 0 (NPC). - unsigned char object_type = pPacket.readGUChar(); - unsigned int npcID = pPacket.readGUInt(); - attachNPC = npcID; - levelBuff >> (char)PLPROP_ATTACHNPC << getProp(PLPROP_ATTACHNPC); - break; - } - - case PLPROP_GMAPLEVELX: - { - int mx = pPacket.readGUChar(); - - if (level && level->getMap()) - { - auto cmap = level->getMap(); - auto& newLevelName = cmap->getLevelAt(mx, level->getMapY()); - leaveLevel(); - setLevel(newLevelName, -1); - } -#ifdef DEBUG - printf("gmap level x: %d\n", level->getMapX()); -#endif - break; - } - - case PLPROP_GMAPLEVELY: - { - int my = pPacket.readGUChar(); - - if (level && level->getMap()) - { - auto cmap = level->getMap(); - auto& newLevelName = cmap->getLevelAt(level->getMapX(), my); - leaveLevel(); - setLevel(newLevelName, -1); - } -#ifdef DEBUG - printf("gmap level y: %d\n", level->getMapY()); -#endif - break; - } - -/* - case PLPROP_UNKNOWN50: - break; -*/ - case PLPROP_PCONNECTED: - break; - - case PLPROP_PLANGUAGE: - len = pPacket.readGUChar(); - language = pPacket.readChars(len); - break; - - case PLPROP_PSTATUSMSG: - statusMsg = pPacket.readGUChar(); - if (id == -1 || !loaded) - break; - - server->sendPacketToAll(PLO_OTHERPLPROPS, CString() >> (short)id >> (char)PLPROP_PSTATUSMSG >> (char)statusMsg, this); - break; - - case PLPROP_GATTRIB1: attrList[0] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB2: attrList[1] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB3: attrList[2] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB4: attrList[3] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB5: attrList[4] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB6: attrList[5] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB7: attrList[6] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB8: attrList[7] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB9: attrList[8] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB10: attrList[9] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB11: attrList[10] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB12: attrList[11] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB13: attrList[12] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB14: attrList[13] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB15: attrList[14] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB16: attrList[15] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB17: attrList[16] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB18: attrList[17] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB19: attrList[18] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB20: attrList[19] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB21: attrList[20] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB22: attrList[21] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB23: attrList[22] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB24: attrList[23] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB25: attrList[24] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB26: attrList[25] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB27: attrList[26] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB28: attrList[27] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB29: attrList[28] = pPacket.readChars(pPacket.readGUChar()); break; - case PLPROP_GATTRIB30: attrList[29] = pPacket.readChars(pPacket.readGUChar()); break; - - // OS type. - // Windows: wind - case PLPROP_OSTYPE: - os = pPacket.readChars(pPacket.readGUChar()); - break; - - // Text codepage. - // Example: 1252 - case PLPROP_TEXTCODEPAGE: - codepage = pPacket.readGInt(); - break; - - // Location, in pixels, of the player on the level in 2.30+ clients. - // Bit 0x0001 controls if it is negative or not. - // Bits 0xFFFE are the actual value. - case PLPROP_X2: - len = pPacket.readGUShort(); - x = (len >> 1) / 16.0f; - - // If the first bit is 1, our position is negative. - if ((uint16_t)len & 0x0001) - x = -x; - - // Let pre-2.30+ clients see 2.30+ movement. - levelBuff2 >> (char)PLPROP_X << getProp(PLPROP_X); - - status &= (~PLSTATUS_PAUSED); - lastMovement = time(0); - grMovementUpdated = true; - doTouchTest = true; - break; - - case PLPROP_Y2: - len = pPacket.readGUShort(); - y = (len >> 1) / 16.0f; - - // If the first bit is 1, our position is negative. - if ((uint16_t)len & 0x0001) - y = -y; - - // Let pre-2.30+ clients see 2.30+ movement. - levelBuff2 >> (char)PLPROP_Y << getProp(PLPROP_Y); - - status &= (~PLSTATUS_PAUSED); - lastMovement = time(0); - grMovementUpdated = true; - - // Do collision testing. - doTouchTest = true; - break; - - case PLPROP_Z2: - len = pPacket.readGUShort(); - z = (len >> 1) / 16.0f; - - // If the first bit is 1, our position is negative. - if ((uint16_t)len & 0x0001) - z = -z; - - // Let pre-2.30+ clients see 2.30+ movement. - levelBuff2 >> (char)PLPROP_Z << getProp(PLPROP_Z); - - status &= (~PLSTATUS_PAUSED); - lastMovement = time(0); - grMovementUpdated = true; - - // Do collision testing. - doTouchTest = true; - - //// Let pre-2.30+ clients see 2.30+ movement. - //z = (float)(int)(((float)z2 / 16.0f) + 0.5f); - break; - - case PLPROP_UNKNOWN81: - { - auto val = pPacket.readGUChar(); - break; - } - - case PLPROP_COMMUNITYNAME: - pPacket.readChars(pPacket.readGUChar()); - break; - - default: - { - printf("Unidentified PLPROP: %i, readPos: %d\n", propId, pPacket.readPos()); - for (int i = 0; i < pPacket.length(); ++i) - printf("%02x ", (unsigned char)pPacket[i]); - printf("\n"); - sentInvalid = true; - } - return; - } - - if ((options & PLSETPROPS_FORWARD) && __sendLocal[propId]) - levelBuff >> (char)propId << getProp(propId); - - if ((options & PLSETPROPS_FORWARDSELF)) - selfBuff >> (char)propId << getProp(propId); - } - - // Send Buffers Out - if (isLoggedIn() && isLoaded()) - { - if (globalBuff.length() > 0) - server->sendPacketToAll(PLO_OTHERPLPROPS, CString() >> (short)this->id << globalBuff, this); - if (levelBuff.length() > 0) - { - // We need to arrange the props packet in a certain way depending - // on if our client supports precise movement or not. Versions 2.3+ - // support precise movement. - bool MOVE_PRECISE = false; - if (versionID >= CLVER_2_3) MOVE_PRECISE = true; - - server->sendPacketToLevel(PLO_OTHERPLPROPS, CString() >> (short)this->id << (!MOVE_PRECISE ? levelBuff : levelBuff2) << (!MOVE_PRECISE ? levelBuff2 : levelBuff), pmap, this, false); - } - if (selfBuff.length() > 0) - this->sendPacket(PLO_PLAYERPROPS, CString() << selfBuff); - -#ifdef V8NPCSERVER - // Movement check. - //if (options & PLSETPROPS_SETBYPLAYER) - if (!rc) - { - if (doTouchTest) - { - if (sprite % 4 == 0) - testSign(); - testTouch(); - } - - } -#endif - } - - if (sentInvalid) - { - // If we are getting a whole bunch of invalid packets, something went wrong. Disconnect the player. - invalidPackets++; - if (invalidPackets > 5) - { - serverlog.out("[%s] Player %s is sending invalid packets.\n", server->getName().text(), nickName.text()); - sendPacket(PLO_DISCMESSAGE, CString() << "Disconnected for sending invalid packets."); - server->deletePlayer(this); - } - } -} - -void TPlayer::sendProps(const bool *pProps, int pCount) -{ - // Definition - CString propPacket; - - // Create Props - if (isClient() && versionID < CLVER_2_1) pCount = 37; - for (int i = 0; i < pCount; ++i) - { - if (pProps[i]) - propPacket >> (char)i << getProp(i); - } - - // Send Packet - sendPacket(PLO_PLAYERPROPS, CString() << propPacket); -} - -CString TPlayer::getProps(const bool *pProps, int pCount) -{ - CString propPacket; - - // Start the prop packet. - propPacket >> (short)this->id; - - if (pCount > 0) - { - // Check if PLPROP_JOINLEAVELVL is set. - if (isClient() && pProps[PLPROP_JOINLEAVELVL]) - propPacket >> (char)PLPROP_JOINLEAVELVL >> (char)1; - - // Create Props - if (isClient() && versionID < CLVER_2_1) pCount = 37; - for (int i = 0; i < pCount; ++i) - { - if (i == PLPROP_JOINLEAVELVL) continue; - - if (i == PLPROP_ATTACHNPC && attachNPC != 0) - { - propPacket >> (char)i; - getProp(propPacket, i); - } - - if (pProps[i]) - { - propPacket >> (char)i; - getProp(propPacket, i); - } - } - - } - - if (isExternal) - propPacket >> (char)81 << "!"; - - return propPacket; -} +#include "IDebug.h" +#include + +#include "TServer.h" +#include "TPlayer.h" +#include "IEnums.h" +#include "IUtil.h" +#include "TMap.h" +#include "TLevel.h" + +#define serverlog server->getServerLog() +#define rclog server->getRCLog() +extern bool __sendLocal[propscount]; +extern int __attrPackets[30]; + +/* + TPlayer: Prop-Manipulation +*/ +void TPlayer::getProp(CString& buffer, int pPropId) const +{ + switch (pPropId) + { + case PLPROP_NICKNAME: + buffer >> (char)nickName.length() << nickName; + return; + + case PLPROP_MAXPOWER: + buffer >> (char)maxPower; + return; + + case PLPROP_CURPOWER: + buffer >> (char)(power * 2); + return; + + case PLPROP_RUPEESCOUNT: + buffer >> (int)gralatc; + return; + + case PLPROP_ARROWSCOUNT: + buffer >> (char)arrowc; + return; + + case PLPROP_BOMBSCOUNT: + buffer >> (char)bombc; + return; + + case PLPROP_GLOVEPOWER: + buffer >> (char)glovePower; + return; + + case PLPROP_BOMBPOWER: + buffer >> (char)bombPower; + return; + + case PLPROP_SWORDPOWER: + buffer >> (char)(swordPower + 30) >> (char)swordImg.length() << swordImg; + return; + + case PLPROP_SHIELDPOWER: + buffer >> (char)(shieldPower + 10) >> (char)shieldImg.length() << shieldImg; + return; + + case PLPROP_GANI: + { + if (isClient() && versionID < CLVER_2_1) + { + if (!bowImage.isEmpty()) + buffer >> (char)(10 + bowImage.length()) << bowImage; + else + buffer >> (char)bowPower; + return; + } + + buffer >> (char)gani.length() << gani; + return; + } + + case PLPROP_HEADGIF: + buffer >> (char)(headImg.length() + 100) << headImg; + return; + + case PLPROP_CURCHAT: + buffer >> (char)chatMsg.length() << chatMsg; + return; + + case PLPROP_COLORS: + buffer >> (char)colors[0] >> (char)colors[1] >> (char)colors[2] >> (char)colors[3] >> (char)colors[4]; + return; + + case PLPROP_ID: + buffer >> (short)id; + return; + + case PLPROP_X: + buffer >> (char)(x * 2); + return; + + case PLPROP_Y: + buffer >> (char)(y * 2); + return; + + case PLPROP_Z: + buffer >> (char)((z + 0.5f) + 50); + return; + + case PLPROP_SPRITE: + buffer >> (char)sprite; + return; + + case PLPROP_STATUS: + buffer >> (char)status; + return; + + case PLPROP_CARRYSPRITE: + buffer >> (char)carrySprite; + return; + + case PLPROP_CURLEVEL: + { + if (isClient())// || type == PLTYPE_AWAIT) + { + if (pmap && pmap->getType() == MapType::GMAP) + buffer >> (char)pmap->getMapName().length() << pmap->getMapName(); + else + { + if (level != nullptr && level->isSingleplayer()) + buffer >> (char)(levelName.length() + 13) << levelName << ".singleplayer"; + else + buffer >> (char)levelName.length() << levelName; + } + return; + } + else + buffer >> (char)1 << " "; + return; + } + + case PLPROP_HORSEGIF: + buffer >> (char)horseImg.length() << horseImg; + return; + + case PLPROP_HORSEBUSHES: + buffer >> (char)horsec; + return; + + case PLPROP_EFFECTCOLORS: + buffer >> (char)0; + return; + + case PLPROP_CARRYNPC: + buffer >> (int)carryNpcId; + return; + + case PLPROP_APCOUNTER: + buffer >> (short)(apCounter + 1); + return; + + case PLPROP_MAGICPOINTS: + buffer >> (char)mp; + return; + + case PLPROP_KILLSCOUNT: + buffer >> (int)kills; + return; + + case PLPROP_DEATHSCOUNT: + buffer >> (int)deaths; + return; + + case PLPROP_ONLINESECS: + buffer >> (int)onlineTime; + return; + + case PLPROP_IPADDR: + buffer.writeGInt5(accountIp); + return; + + case PLPROP_UDPPORT: + buffer >> (int)udpport; + return; + + case PLPROP_ALIGNMENT: + buffer >> (char)ap; + return; + + case PLPROP_ADDITFLAGS: + buffer >> (char)additionalFlags; + return; + + case PLPROP_ACCOUNTNAME: + buffer >> (char)accountName.length() << accountName; + return; + + case PLPROP_BODYIMG: + buffer >> (char)bodyImg.length() << bodyImg; + return; + + case PLPROP_RATING: + { + int temp = (((int)rating & 0xFFF) << 9) | ((int)deviation & 0x1FF); + buffer >> (int)temp; + return; + } + + case PLPROP_ATTACHNPC: + { + // Only attach type 0 (NPC) supported. + buffer >> (char)0 >> (int)attachNPC; + return; + } + + // Simplifies login. + // Manually send prop if you are leaving the level. + // 1 = join level, 0 = leave level. + case PLPROP_JOINLEAVELVL: + buffer >> (char)1; + return; + + case PLPROP_PCONNECTED: + //return CString(); + return; + + case PLPROP_PLANGUAGE: + buffer >> (char)language.length() << language; + return; + + case PLPROP_PSTATUSMSG: + { + //if (id == -1) + // break; + + if (statusMsg > server->getStatusList().size() - 1) + buffer >> (char)0; + else + buffer >> (char)statusMsg; + return; + } + + // OS type. + // Windows: wind + case PLPROP_OSTYPE: + buffer >> (char)os.length() << os; + return; + + // Text codepage. + // Example: 1252 + case PLPROP_TEXTCODEPAGE: + buffer.writeGInt(codepage); + return; + + case PLPROP_X2: + { + uint16_t val = ((uint16_t)std::abs(x * 16.0f)) << 1; + if (x < 0) + val |= 0x0001; + buffer.writeGShort(val); + return; + } + + case PLPROP_Y2: + { + uint16_t val = ((uint16_t)std::abs(y * 16.0f)) << 1; + if (y < 0) + val |= 0x0001; + buffer.writeGShort(val); + return; + } + + case PLPROP_Z2: + { + uint16_t val = ((uint16_t)std::abs(z * 16.0f)) << 1; + if (z < 0) + val |= 0x0001; + buffer.writeGShort(val); + return; + } + + case PLPROP_GMAPLEVELX: + buffer >> (char)(level ? level->getMapX() : 0); + return; + + case PLPROP_GMAPLEVELY: + buffer >> (char)(level ? level->getMapY() : 0); + return; + + // TODO(joey): figure this out. Something to do with guilds? irc-related + // (char)(some bitflag for something, uses the first 3 bits im not sure) + // okay i tested some flags, 1 removes the channel. 3 adds it. not sure what third bit does. + case PLPROP_UNKNOWN81: + //return CString(); + return; + + case PLPROP_COMMUNITYNAME: + buffer >> (char)communityName.length() << communityName; + return; + + default: + break; + } + + if (inrange(pPropId, 37, 41) || inrange(pPropId, 46, 49) || inrange(pPropId, 54, 74)) + { + for (auto i = 0; i < sizeof(__attrPackets) / sizeof(int); i++) + { + if (__attrPackets[i] == pPropId) + { + char len = std::min(attrList[i].length(), 223); + buffer >> (char)len << attrList[i].subString(0, len); + return; + } + } + } +} + +void TPlayer::setProps(CString& pPacket, uint8_t options, TPlayer* rc) +{ + CString globalBuff, levelBuff, levelBuff2, selfBuff; + bool doTouchTest = false; + bool sentInvalid = false; + int len = 0; + + while (pPacket.bytesLeft() > 0) + { + unsigned char propId = pPacket.readGUChar(); + + switch (propId) + { + case PLPROP_NICKNAME: + { + CString nick = pPacket.readChars(pPacket.readGUChar()); + + // Word filter. + int filter = server->getWordFilter()->apply(this, nick, FILTER_CHECK_NICK); + if (filter & FILTER_ACTION_WARN) + { + if (nickName.isEmpty()) + setNick("unknown"); + } + else setNick(nick, !(options & PLSETPROPS_SETBYPLAYER)); + + if (options & PLSETPROPS_FORWARD) + globalBuff >> (char)propId << getProp(propId); + + // Send this if the player is located on another server + // globalBuff >> (char)81; + + if (!(options & PLSETPROPS_FORWARDSELF)) + selfBuff >> (char)propId << getProp(propId); + } + break; + + case PLPROP_MAXPOWER: + { + uint8_t newMaxPower = pPacket.readGUChar(); + +#ifdef V8NPCSERVER + if (!(options & PLSETPROPS_SETBYPLAYER)) { +#endif + setMaxPower(newMaxPower); + setPower((float)maxPower); + +#ifdef V8NPCSERVER + levelBuff >> (char)PLPROP_MAXPOWER << getProp(PLPROP_MAXPOWER); + selfBuff >> (char)PLPROP_MAXPOWER << getProp(PLPROP_MAXPOWER); +#endif + levelBuff >> (char)PLPROP_CURPOWER << getProp(PLPROP_CURPOWER); + selfBuff >> (char)PLPROP_CURPOWER << getProp(PLPROP_CURPOWER); +#ifdef V8NPCSERVER + } +#endif + + break; + } + + case PLPROP_CURPOWER: + { + float p = (float)pPacket.readGUChar() / 2.0f; + if (ap < 40 && p > power) break; + //if ((status & PLSTATUS_HIDESWORD) != 0) + // break; + setPower(p); + break; + } + + case PLPROP_RUPEESCOUNT: + { + unsigned int newGralatCount = std::min(pPacket.readGUInt(), 9999999u); + +#ifdef V8NPCSERVER + if (!(options & PLSETPROPS_SETBYPLAYER)) { +#endif + if (rc != nullptr) + { + if (server->getSettings()->getBool("normaladminscanchangegralats", true) || (rc->isStaff() && rc->hasRight(PLPERM_SETRIGHTS))) + gralatc = newGralatCount; + } + else + { + gralatc = newGralatCount; + } +#ifdef V8NPCSERVER + } +#endif + break; + } + + case PLPROP_ARROWSCOUNT: + arrowc = pPacket.readGUChar(); + arrowc = clip(arrowc, 0, 99); + break; + + case PLPROP_BOMBSCOUNT: + bombc = pPacket.readGUChar(); + bombc = clip(bombc, 0, 99); + break; + + case PLPROP_GLOVEPOWER: + { + uint8_t newGlovePower = pPacket.readGUChar(); +#ifdef V8NPCSERVER + if (!(options & PLSETPROPS_SETBYPLAYER)) { +#endif + glovePower = std::min(newGlovePower, 3); +#ifdef V8NPCSERVER + } +#endif + break; + } + + case PLPROP_BOMBPOWER: + bombPower = pPacket.readGUChar(); + bombPower = clip(bombPower, 0, 3); + break; + + case PLPROP_SWORDPOWER: + { + int sp = pPacket.readGUChar(); + CString img; + + if (sp <= 4) + { + CSettings* settings = server->getSettings(); + sp = clip(sp, 0, settings->getInt("swordlimit", 3)); + img = CString() << "sword" << CString(sp) << (versionID < CLVER_2_1 ? ".gif" : ".png"); + } + else + { + sp -= 30; + len = pPacket.readGUChar(); + if (len > 0) + { + img = pPacket.readChars(len); + if (!img.isEmpty() && versionID < CLVER_2_1 && getExtension(img).isEmpty()) + img << ".gif"; + } + else img = ""; + } + +#ifdef V8NPCSERVER + if (!(options & PLSETPROPS_SETBYPLAYER)) { +#endif + setSwordPower(sp); +#ifdef V8NPCSERVER + } +#endif + setSwordImage(img); + } + break; + + case PLPROP_SHIELDPOWER: + { + int sp = pPacket.readGUChar(); + CString img; + + if (sp <= 3) + { + CSettings* settings = server->getSettings(); + sp = clip(sp, 0, settings->getInt("shieldlimit", 3)); + img = CString() << "shield" << CString(sp) << (versionID < CLVER_2_1 ? ".gif" : ".png"); + } + else + { + // This fixes an odd bug with the 1.41 client. + if (pPacket.bytesLeft() == 0) continue; + + sp -= 10; + if (sp < 0) break; + len = pPacket.readGUChar(); + if (len > 0) + { + img = pPacket.readChars(len); + if (!img.isEmpty() && versionID < CLVER_2_1 && getExtension(img).isEmpty()) + img << ".gif"; + } + else img = ""; + } + +#ifdef V8NPCSERVER + if (!(options & PLSETPROPS_SETBYPLAYER)) { +#endif + setShieldPower(sp); +#ifdef V8NPCSERVER + } +#endif + setShieldImage(img); + } + break; + + case PLPROP_GANI: + { + if (isClient() && versionID < CLVER_2_1) + { + int sp = pPacket.readGUChar(); + if (sp < 10) + { + bowPower = sp; + bowImage.clear(); + } + else + { + bowPower = 10; + sp -= 10; + if (sp < 0) break; + bowImage = CString() << pPacket.readChars(sp); + if (!bowImage.isEmpty() && versionID < CLVER_2_1 && getExtension(bowImage).isEmpty()) + bowImage << ".gif"; + } + break; + } + + setGani(pPacket.readChars(pPacket.readGUChar())); + if (gani == "spin") + { + CString nPacket; + nPacket >> (short)id >> (char)swordPower; + char hx = (char)((x + 1.5f) * 2); + char hy = (char)((y + 2.0f) * 2); + server->sendPacketToLevel({PLO_HITOBJECTS, CString() << nPacket >> (char)(hx) >> (char)(hy - 4)}, nullptr, level, this); + server->sendPacketToLevel({PLO_HITOBJECTS, CString() << nPacket >> (char)(hx) >> (char)(hy + 4)}, nullptr, level, this); + server->sendPacketToLevel({PLO_HITOBJECTS, CString() << nPacket >> (char)(hx - 4) >> (char)(hy)}, nullptr, level, this); + server->sendPacketToLevel({PLO_HITOBJECTS, CString() << nPacket >> (char)(hx + 4) >> (char)(hy)}, nullptr, level, this); + } + } + break; + + case PLPROP_HEADGIF: + { + len = pPacket.readGUChar(); + CString img; + if (len < 100) + { + img = CString() << "head" << CString(len) << (versionID < CLVER_2_1 ? ".gif" : ".png"); + } + else if (len > 100) + { + img = pPacket.readChars(len - 100); + + // TODO(joey): We need to check properties for newline, especially if they are sending to other clients + // as it causes havoc on the client... + int check = img.find("\n", 0); + if (check > 0) + img = img.readChars(check); + + if (!img.isEmpty() && versionID < CLVER_2_1 && getExtension(img).isEmpty()) + img << ".gif"; + } + + if (len != 100) + { + setHeadImage(img); + globalBuff >> (char)propId << getProp(propId); + } + + break; + } + + case PLPROP_CURCHAT: + { + len = pPacket.readGUChar(); + chatMsg = pPacket.readChars(std::min(len, 223)); + lastChat = time(0); + + // Try to process the chat. If it wasn't processed, apply the word filter to it. + if (!processChat(chatMsg)) + { + int found = server->getWordFilter()->apply(this, chatMsg, FILTER_CHECK_CHAT); + if (!(options & PLSETPROPS_FORWARDSELF)) + { + if ((found & FILTER_ACTION_REPLACE) || (found & FILTER_ACTION_WARN)) + selfBuff >> (char)propId << getProp(propId); + } + } + +#ifdef V8NPCSERVER + // Send chat to npcs if this wasn't changed by the npcserver + if (!rc && !chatMsg.isEmpty()) + { + if (level != nullptr) + level->sendChatToLevel(this, chatMsg.text()); + } +#endif + } + break; + + case PLPROP_COLORS: + for (unsigned char & color : colors) + color = pPacket.readGUChar(); + break; + + case PLPROP_ID: + pPacket.readGUShort(); + break; + + case PLPROP_X: + x = (float)(pPacket.readGUChar() / 2.0f); + status &= (~PLSTATUS_PAUSED); + lastMovement = time(0); + grMovementUpdated = true; + + // Do collision testing. + doTouchTest = true; + + // Let 2.30+ clients see pre-2.30 movement. + levelBuff2 >> (char)PLPROP_X2 << getProp(PLPROP_X2); + break; + + case PLPROP_Y: + y = (float)(pPacket.readGUChar() / 2.0f); + status &= (~PLSTATUS_PAUSED); + lastMovement = time(0); + grMovementUpdated = true; + + // Do collision testing. + doTouchTest = true; + + // Let 2.30+ clients see pre-2.30 movement. + levelBuff2 >> (char)PLPROP_Y2 << getProp(PLPROP_Y2); + break; + + case PLPROP_Z: + z = (float)pPacket.readGUChar() - 50.0f; + status &= (~PLSTATUS_PAUSED); + lastMovement = time(0); + grMovementUpdated = true; + doTouchTest = true; + + // Let 2.30+ clients see pre-2.30 movement. + levelBuff2 >> (char)PLPROP_Z2 << getProp(PLPROP_Z2); + break; + + case PLPROP_SPRITE: + sprite = pPacket.readGUChar(); + +#ifndef V8NPCSERVER + // Do collision testing. + doTouchTest = true; +#endif + break; + + case PLPROP_STATUS: + { + int oldStatus = status; + status = pPacket.readGUChar(); + //printf("%s: status: %d, oldStatus: %d\n", accountName.text(), status, oldStatus ); + + if (id == -1) break; + + // When they come back to life, give them hearts. + if ((oldStatus & PLSTATUS_DEAD) > 0 && (status & PLSTATUS_DEAD) == 0) + { + auto newPower = clip((ap < 20 ? 3 : (ap < 40 ? 5 : maxPower)), 0.5f, maxPower); + setPower(newPower); + + selfBuff >> (char)PLPROP_CURPOWER >> (char)(power * 2.0f); + levelBuff >> (char)PLPROP_CURPOWER >> (char)(power * 2.0f); + + if (level != 0 && level->getPlayer(0) == this) + sendPacket({PLO_ISLEADER, CString() << ""}); + /* + // If we are the leader of the level, call warp(). This will fix NPCs not + // working again after we respawn. + if (level != 0 && level->getPlayer(0) == this) + warp(levelName, x, y, time(0)); + */ + } + + // When they die, increase deaths and make somebody else level leader. + if ((oldStatus & PLSTATUS_DEAD) == 0 && (status & PLSTATUS_DEAD) > 0) + { + if ( !level->isSparringZone()) + { + deaths++; + dropItemsOnDeath(); + } + + // If we are the leader and there are more players on the level, we want to remove + // ourself from the leader position and tell the new leader that they are the leader. + if (level->getPlayer(0) == this && level->getPlayer(1) != 0) + { + level->removePlayer(this); + level->addPlayer(this); + level->getPlayer(0)->sendPacket({PLO_ISLEADER, CString() << ""}); + } + } + } + break; + + case PLPROP_CARRYSPRITE: + carrySprite = pPacket.readGUChar(); + break; + + case PLPROP_CURLEVEL: + len = pPacket.readGUChar(); +#ifdef V8NPCSERVER + pPacket.readChars(len); +#else + levelName = pPacket.readChars(len); +#endif + break; + + case PLPROP_HORSEGIF: + len = pPacket.readGUChar(); + horseImg = pPacket.readChars(std::min(len, 219)); // limit is 219 in case it appends .gif + if (!horseImg.isEmpty() && versionID < CLVER_2_1 && getExtension(horseImg).isEmpty()) + horseImg << ".gif"; + break; + + case PLPROP_HORSEBUSHES: + horsec = pPacket.readGUChar(); + break; + + case PLPROP_EFFECTCOLORS: + len = pPacket.readGUChar(); + if (len > 0) + pPacket.readGInt4(); + break; + + case PLPROP_CARRYNPC: + { + carryNpcId = pPacket.readGUInt(); + + // TODO: Remove when an npcserver is created. + if (server->getSettings()->getBool("duplicatecanbecarried", false) == false) + { + bool isOwner = true; + { + std::vector* playerList = server->getPlayerList(); + for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) + { + TPlayer* other = *i; + if (other == this) continue; + if (other->getProp(PLPROP_CARRYNPC).readGUInt() == carryNpcId) + { + // Somebody else got this NPC first. Force the player to throw his down + // and tell the player to remove the NPC from memory. + carryNpcId = 0; + isOwner = false; + sendPacket({PLO_PLAYERPROPS, CString() >> (char)PLPROP_CARRYNPC >> (int)0}); + sendPacket({PLO_NPCDEL2, CString() >> (char)level->getLevelName().length() << level->getLevelName() >> (int)carryNpcId}); + server->sendPacketToLevel({PLO_OTHERPLPROPS, CString() >> (short)id >> (char)PLPROP_CARRYNPC >> (int)0}, pmap, this); + break; + } + } + } + if (isOwner) + { + // We own this NPC now so remove it from the level and have everybody else delete it. + TNPC* npc = server->getNPC(carryNpcId); + level->removeNPC(npc); + server->sendPacketToAll({PLO_NPCDEL2, CString() >> (char)level->getLevelName().length() << level->getLevelName() >> (int)carryNpcId}, nullptr); + } + } + } + break; + + case PLPROP_APCOUNTER: + apCounter = pPacket.readGUShort(); + break; + + case PLPROP_MAGICPOINTS: + { + uint8_t newMP = pPacket.readGUChar(); +#ifdef V8NPCSERVER + if (!(options & PLSETPROPS_SETBYPLAYER)) { +#endif + mp = std::min(newMP, 100); +#ifdef V8NPCSERVER + } +#endif + break; + } + + case PLPROP_KILLSCOUNT: + pPacket.readGInt(); + break; + + case PLPROP_DEATHSCOUNT: + pPacket.readGInt(); + break; + + case PLPROP_ONLINESECS: + pPacket.readGInt(); + break; + + case PLPROP_IPADDR: + pPacket.readGInt5(); + break; + + case PLPROP_UDPPORT: + udpport = pPacket.readGInt(); + if (id != -1 && loaded) + server->sendPacketTo(PLTYPE_ANYCLIENT, {PLO_OTHERPLPROPS, CString() >> (short)id >> (char)PLPROP_UDPPORT >> (int)udpport}, this); + // TODO: udp support. + break; + + case PLPROP_ALIGNMENT: + { + uint8_t newAlignment = pPacket.readGUChar(); +#ifdef V8NPCSERVER + if (!(options & PLSETPROPS_SETBYPLAYER)) { +#endif + ap = std::min(newAlignment, 100); +#ifdef V8NPCSERVER + } +#endif + break; + } + + case PLPROP_ADDITFLAGS: + additionalFlags = pPacket.readGUChar(); + break; + + case PLPROP_ACCOUNTNAME: + len = pPacket.readGUChar(); + pPacket.readChars(len); + break; + + case PLPROP_BODYIMG: + len = pPacket.readGUChar(); + setBodyImage(pPacket.readChars(len)); + break; + + case PLPROP_RATING: + len = pPacket.readGInt(); + //rating = (float)((len >> 9) & 0xFFF); + break; + + case PLPROP_ATTACHNPC: + { + // Only supports object_type 0 (NPC). + unsigned char object_type = pPacket.readGUChar(); + unsigned int npcID = pPacket.readGUInt(); + attachNPC = npcID; + levelBuff >> (char)PLPROP_ATTACHNPC << getProp(PLPROP_ATTACHNPC); + break; + } + + case PLPROP_GMAPLEVELX: + { + int mx = pPacket.readGUChar(); + + if (level && level->getMap()) + { + auto cmap = level->getMap(); + auto& newLevelName = cmap->getLevelAt(mx, level->getMapY()); + leaveLevel(); + setLevel(newLevelName, -1); + } +#ifdef DEBUG + printf("gmap level x: %d\n", level->getMapX()); +#endif + break; + } + + case PLPROP_GMAPLEVELY: + { + int my = pPacket.readGUChar(); + + if (level && level->getMap()) + { + auto cmap = level->getMap(); + auto& newLevelName = cmap->getLevelAt(level->getMapX(), my); + leaveLevel(); + setLevel(newLevelName, -1); + } +#ifdef DEBUG + printf("gmap level y: %d\n", level->getMapY()); +#endif + break; + } + +/* + case PLPROP_UNKNOWN50: + break; +*/ + case PLPROP_PCONNECTED: + break; + + case PLPROP_PLANGUAGE: + len = pPacket.readGUChar(); + language = pPacket.readChars(len); + break; + + case PLPROP_PSTATUSMSG: + statusMsg = pPacket.readGUChar(); + if (id == -1 || !loaded) + break; + + server->sendPacketToAll({PLO_OTHERPLPROPS, CString() >> (short)id >> (char)PLPROP_PSTATUSMSG >> (char)statusMsg}, this); + break; + + case PLPROP_GATTRIB1: attrList[0] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB2: attrList[1] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB3: attrList[2] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB4: attrList[3] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB5: attrList[4] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB6: attrList[5] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB7: attrList[6] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB8: attrList[7] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB9: attrList[8] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB10: attrList[9] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB11: attrList[10] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB12: attrList[11] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB13: attrList[12] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB14: attrList[13] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB15: attrList[14] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB16: attrList[15] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB17: attrList[16] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB18: attrList[17] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB19: attrList[18] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB20: attrList[19] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB21: attrList[20] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB22: attrList[21] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB23: attrList[22] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB24: attrList[23] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB25: attrList[24] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB26: attrList[25] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB27: attrList[26] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB28: attrList[27] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB29: attrList[28] = pPacket.readChars(pPacket.readGUChar()); break; + case PLPROP_GATTRIB30: attrList[29] = pPacket.readChars(pPacket.readGUChar()); break; + + // OS type. + // Windows: wind + case PLPROP_OSTYPE: + os = pPacket.readChars(pPacket.readGUChar()); + break; + + // Text codepage. + // Example: 1252 + case PLPROP_TEXTCODEPAGE: + codepage = pPacket.readGInt(); + break; + + // Location, in pixels, of the player on the level in 2.30+ clients. + // Bit 0x0001 controls if it is negative or not. + // Bits 0xFFFE are the actual value. + case PLPROP_X2: + len = pPacket.readGUShort(); + x = (len >> 1) / 16.0f; + + // If the first bit is 1, our position is negative. + if ((uint16_t)len & 0x0001) + x = -x; + + // Let pre-2.30+ clients see 2.30+ movement. + levelBuff2 >> (char)PLPROP_X << getProp(PLPROP_X); + + status &= (~PLSTATUS_PAUSED); + lastMovement = time(0); + grMovementUpdated = true; + doTouchTest = true; + break; + + case PLPROP_Y2: + len = pPacket.readGUShort(); + y = (len >> 1) / 16.0f; + + // If the first bit is 1, our position is negative. + if ((uint16_t)len & 0x0001) + y = -y; + + // Let pre-2.30+ clients see 2.30+ movement. + levelBuff2 >> (char)PLPROP_Y << getProp(PLPROP_Y); + + status &= (~PLSTATUS_PAUSED); + lastMovement = time(0); + grMovementUpdated = true; + + // Do collision testing. + doTouchTest = true; + break; + + case PLPROP_Z2: + len = pPacket.readGUShort(); + z = (len >> 1) / 16.0f; + + // If the first bit is 1, our position is negative. + if ((uint16_t)len & 0x0001) + z = -z; + + // Let pre-2.30+ clients see 2.30+ movement. + levelBuff2 >> (char)PLPROP_Z << getProp(PLPROP_Z); + + status &= (~PLSTATUS_PAUSED); + lastMovement = time(0); + grMovementUpdated = true; + + // Do collision testing. + doTouchTest = true; + + //// Let pre-2.30+ clients see 2.30+ movement. + //z = (float)(int)(((float)z2 / 16.0f) + 0.5f); + break; + + case PLPROP_UNKNOWN81: + { + auto val = pPacket.readGUChar(); + break; + } + + case PLPROP_COMMUNITYNAME: + pPacket.readChars(pPacket.readGUChar()); + break; + + default: + { + printf("Unidentified PLPROP: %i, readPos: %d\n", propId, pPacket.readPos()); + for (int i = 0; i < pPacket.length(); ++i) + printf("%02x ", (unsigned char)pPacket[i]); + printf("\n"); + sentInvalid = true; + } + return; + } + + if ((options & PLSETPROPS_FORWARD) && __sendLocal[propId]) + levelBuff >> (char)propId << getProp(propId); + + if ((options & PLSETPROPS_FORWARDSELF)) + selfBuff >> (char)propId << getProp(propId); + } + + // Send Buffers Out + if (isLoggedIn() && isLoaded()) + { + if (globalBuff.length() > 0) + server->sendPacketToAll({PLO_OTHERPLPROPS, CString() >> (short)this->id << globalBuff}, this); + if (levelBuff.length() > 0) + { + // We need to arrange the props packet in a certain way depending + // on if our client supports precise movement or not. Versions 2.3+ + // support precise movement. + bool MOVE_PRECISE = false; + if (versionID >= CLVER_2_3) MOVE_PRECISE = true; + + server->sendPacketToLevel({PLO_OTHERPLPROPS, CString() >> (short)this->id << (!MOVE_PRECISE ? levelBuff : levelBuff2) << (!MOVE_PRECISE ? levelBuff2 : levelBuff)}, pmap, this, false); + } + if (selfBuff.length() > 0) + sendPacket({PLO_PLAYERPROPS, CString() << selfBuff}); + +#ifdef V8NPCSERVER + // Movement check. + //if (options & PLSETPROPS_SETBYPLAYER) + if (!rc) + { + if (doTouchTest) + { + if (sprite % 4 == 0) + testSign(); + testTouch(); + } + + } +#endif + } + + if (sentInvalid) + { + // If we are getting a whole bunch of invalid packets, something went wrong. Disconnect the player. + invalidPackets++; + if (invalidPackets > 5) + { + serverlog.out("[%s] Player %s is sending invalid packets.\n", server->getName().text(), nickName.text()); + sendPacket({PLO_DISCMESSAGE, CString() << "Disconnected for sending invalid packets."}); + server->deletePlayer(this); + } + } +} + +void TPlayer::sendProps(const bool *pProps, int pCount) +{ + // Definition + CString propPacket; + + // Create Props + if (isClient() && versionID < CLVER_2_1) pCount = 37; + for (int i = 0; i < pCount; ++i) + { + if (pProps[i]) + propPacket >> (char)i << getProp(i); + } + + // Send Packet + sendPacket({PLO_PLAYERPROPS, CString() << propPacket}); +} + +CString TPlayer::getProps(const bool *pProps, int pCount) +{ + CString propPacket; + + // Start the prop packet. + propPacket >> (short)this->id; + + if (pCount > 0) + { + // Check if PLPROP_JOINLEAVELVL is set. + if (isClient() && pProps[PLPROP_JOINLEAVELVL]) + propPacket >> (char)PLPROP_JOINLEAVELVL >> (char)1; + + // Create Props + if (isClient() && versionID < CLVER_2_1) pCount = 37; + for (int i = 0; i < pCount; ++i) + { + if (i == PLPROP_JOINLEAVELVL) continue; + + if (i == PLPROP_ATTACHNPC && attachNPC != 0) + { + propPacket >> (char)i; + getProp(propPacket, i); + } + + if (pProps[i]) + { + propPacket >> (char)i; + getProp(propPacket, i); + } + } + + } + + if (isExternal) + propPacket >> (char)81 << "!"; + + return propPacket; +} diff --git a/server/src/TPlayer/TPlayerRC.cpp b/server/src/TPlayer/TPlayerRC.cpp index 28d6812a..3460b4c6 100644 --- a/server/src/TPlayer/TPlayerRC.cpp +++ b/server/src/TPlayer/TPlayerRC.cpp @@ -104,7 +104,7 @@ void TPlayer::setPropsRC(CString& pPacket, TPlayer* rc) if ((*i) == "Bow") hadBow = true; } - if (id != -1) sendPacketOld(outPacket); + if (id != -1) sendPacketOldProtocol(outPacket); // Clear the flags and re-populate the flag list. flagList.clear(); @@ -156,7 +156,7 @@ void TPlayer::setPropsRC(CString& pPacket, TPlayer* rc) if (id != -1) { if (!hadBomb) - sendPacket(PLO_NPCWEAPONDEL, CString() << "Bomb"); + sendPacket({PLO_NPCWEAPONDEL, CString() << "Bomb"}); } // Warp the player to his new location now. @@ -179,19 +179,19 @@ CString TPlayer::getPropsRC() // Add the player's flags. ret >> (short)flagList.size(); - for (auto i = flagList.begin(); i != flagList.end(); ++i) + for (auto & i : flagList) { - CString flag = i->first; - if (!i->second.isEmpty()) flag << "=" << i->second; + CString flag = i.first; + if (!i.second.isEmpty()) flag << "=" << i.second; if (flag.length() > 0xDF) flag.removeI(0xDF); ret >> (char)flag.length() << flag; } // Add the player's chests. ret >> (short)chestList.size(); - for (std::vector::iterator i = chestList.begin(); i != chestList.end(); ++i) + for (auto & i : chestList) { - std::vector chest = (*i).tokenize(":"); + std::vector chest = i.tokenize(":"); if (chest.size() == 3) { CString chestData; @@ -218,7 +218,7 @@ bool TPlayer::msgPLI_RC_SERVEROPTIONSGET(CString& pPacket) CSettings* settings = server->getSettings(); - sendPacket(PLO_RC_SERVEROPTIONSGET, CString() << settings->getSettings().gtokenize()); + sendPacket({PLO_RC_SERVEROPTIONSGET, CString() << settings->getSettings().gtokenize()}); return true; } @@ -228,7 +228,7 @@ bool TPlayer::msgPLI_RC_SERVEROPTIONSSET(CString& pPacket) { if (isClient()) rclog.out("[Hack] %s attempted to set the server options.", accountName.text()); else rclog.out("%s attempted to set the server options.", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to change the server options."); + sendPacket({PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to change the server options."}); return true; } @@ -271,14 +271,14 @@ bool TPlayer::msgPLI_RC_SERVEROPTIONSSET(CString& pPacket) // Send RC Information CString outPacket = CString() << accountName << " has updated the server options."; std::vector *playerList = server->getPlayerList(); - for (auto i = playerList->begin(); i != playerList->end(); ++i) + for (auto & i : *playerList) { - if ((*i)->getType() & PLTYPE_ANYRC) + if (i->getType() & PLTYPE_ANYRC) { - (*i)->sendPacket(PLO_RC_CHAT, outPacket); + i->sendPacket({PLO_RC_CHAT, outPacket}); #ifdef V8NPCSERVER if (hasRight(PLPERM_NPCCONTROL)) - (*i)->sendNCAddr(); + i->sendNCAddr(); #endif } } @@ -298,7 +298,7 @@ bool TPlayer::msgPLI_RC_FOLDERCONFIGGET(CString& pPacket) foldersConfig.load(CString() << server->getServerPath() << "config/foldersconfig.txt"); foldersConfig.removeAllI("\r"); - sendPacket(PLO_RC_FOLDERCONFIGGET, CString() << foldersConfig.gtokenize()); + sendPacket({PLO_RC_FOLDERCONFIGGET, CString() << foldersConfig.gtokenize()}); return true; } @@ -308,7 +308,7 @@ bool TPlayer::msgPLI_RC_FOLDERCONFIGSET(CString& pPacket) { if (isClient()) rclog.out("[Hack] %s attempted to set the folder config.", accountName.text()); else rclog.out("%s attempted to set the folder config.", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to change the folder config."); + sendPacket({PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to change the folder config."}); return true; } @@ -322,7 +322,7 @@ bool TPlayer::msgPLI_RC_FOLDERCONFIGSET(CString& pPacket) server->loadFileSystem(); rclog.out("%s updated the folder config.\n", accountName.text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " updated the folder config."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " updated the folder config."}); return true; } @@ -367,14 +367,14 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSSET(CString& pPacket) { if (isClient()) rclog.out("[Hack] %s attempted to set a player's properties.", accountName.text()); else rclog.out("%s attempted to set a player's properties.", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to set the properties of " << p->getAccountName()); + sendPacket({PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to set the properties of " << p->getAccountName()}); return true; } p->setPropsRC(pPacket, this); p->saveAccount(); rclog.out("%s set the attributes of player %s\n", accountName.text(), p->getAccountName().text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " set the attributes of player " << p->getAccountName()); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " set the attributes of player " << p->getAccountName()}); return true; } @@ -387,7 +387,7 @@ bool TPlayer::msgPLI_RC_DISCONNECTPLAYER(CString& pPacket) if (isClient() || !hasRight(PLPERM_DISCONNECT)) { if (isClient()) rclog.out("[Hack] %s attempted to disconnect %s.\n", accountName.text(), p->getAccountName().text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to disconnect players."); + sendPacket({PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to disconnect players."}); return true; } @@ -395,13 +395,13 @@ bool TPlayer::msgPLI_RC_DISCONNECTPLAYER(CString& pPacket) if (!reason.isEmpty()) rclog.out("%s disconnected %s: %s\n", accountName.text(), p->getAccountName().text(), reason.text()); else rclog.out("%s disconnected %s.\n", accountName.text(), p->getAccountName().text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " disconnected " << p->getAccountName()); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " disconnected " << p->getAccountName()}); CString disconnectMessage = CString() << "One of the server administrators, " << accountName << ", has disconnected you"; if (!reason.isEmpty()) disconnectMessage << " for the following reason: " << reason; else disconnectMessage << "."; - p->sendPacket(PLO_DISCMESSAGE, CString() << disconnectMessage); + p->sendPacket({PLO_DISCMESSAGE, CString() << disconnectMessage}); server->deletePlayer(p); return true; } @@ -411,7 +411,7 @@ bool TPlayer::msgPLI_RC_UPDATELEVELS(CString& pPacket) if (isClient() || !hasRight(PLPERM_UPDATELEVEL)) { if (isClient()) rclog.out("[Hack] %s attempted to update levels.\n", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to update levels."); + sendPacket({PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to update levels."}); return true; } @@ -429,11 +429,11 @@ bool TPlayer::msgPLI_RC_ADMINMESSAGE(CString& pPacket) if (isClient() || !hasRight(PLPERM_ADMINMSG)) { if (isClient()) rclog.out("[Hack] %s attempted to send an admin message.\n", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to send an admin message."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to send an admin message."}); return true; } - server->sendPacketToAll(PLO_RC_ADMINMESSAGE, CString() << "Admin " << accountName << ":\xa7" << pPacket.readString(""), this); + server->sendPacketToAll({PLO_RC_ADMINMESSAGE, CString() << "Admin " << accountName << ":\xa7" << pPacket.readString("")}, this); return true; } @@ -442,14 +442,14 @@ bool TPlayer::msgPLI_RC_PRIVADMINMESSAGE(CString& pPacket) if (isClient() || !hasRight(PLPERM_ADMINMSG)) { if (isClient()) rclog.out("[Hack] %s attempted to send an admin message.\n", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to send an admin message."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to send an admin message."}); return true; } TPlayer* p = server->getPlayer(pPacket.readGUShort(), PLTYPE_ANYPLAYER); - if (p == 0) return true; + if (p == nullptr) return true; - p->sendPacket(PLO_RC_ADMINMESSAGE, CString() << "Admin " << accountName << ":\xa7" << pPacket.readString("")); + p->sendPacket({PLO_RC_ADMINMESSAGE, CString() << "Admin " << accountName << ":\xa7" << pPacket.readString("")}); return true; } @@ -480,12 +480,12 @@ bool TPlayer::msgPLI_RC_SERVERFLAGSGET(CString& pPacket) } CString ret; ret >> (short)server->getServerFlags()->size(); - for (auto i = server->getServerFlags()->begin(); i != server->getServerFlags()->end(); ++i) + for (auto & i : *server->getServerFlags()) { - CString flag = CString() << i->first << "=" << i->second; + CString flag = CString() << i.first << "=" << i.second; ret >> (char)flag.length() << flag; } - sendPacket(PLO_RC_SERVERFLAGSGET, ret); + sendPacket({PLO_RC_SERVERFLAGSGET, ret}); return true; } @@ -494,7 +494,7 @@ bool TPlayer::msgPLI_RC_SERVERFLAGSSET(CString& pPacket) if (isClient() || !hasRight(PLPERM_SETSERVERFLAGS)) { if (isClient()) rclog.out("[Hack] %s attempted to set the server flags.\n", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to set the server flags."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to set the server flags."}); return true; } @@ -512,17 +512,17 @@ bool TPlayer::msgPLI_RC_SERVERFLAGSSET(CString& pPacket) server->setFlag(pPacket.readChars(pPacket.readGUChar()), false); // Send flag changes to all players. - for (auto i = serverFlags->begin(); i != serverFlags->end(); ++i) + for (auto & serverFlag : *serverFlags) { bool found = false; for (auto j = oldFlags.begin(); j != oldFlags.end();) { // Flag name - if (i->first == j->first) + if (serverFlag.first == j->first) { // Check to see if the values are the same. // If they are, set found to true so we don't send it to the player again. - if (i->second == j->second) + if (serverFlag.second == j->second) found = true; oldFlags.erase(j++); if (found) break; @@ -533,19 +533,19 @@ bool TPlayer::msgPLI_RC_SERVERFLAGSSET(CString& pPacket) // If we didn't find a match, this is either a new flag, or a changed flag. if (!found) { - if (i->second.isEmpty()) - server->sendPacketTo(PLO_FLAGSET, PLTYPE_ANYCLIENT, CString() << i->first); + if (serverFlag.second.isEmpty()) + server->sendPacketTo(PLTYPE_ANYCLIENT, {PLO_FLAGSET, CString() << serverFlag.first}); else - server->sendPacketTo(PLO_FLAGSET, PLTYPE_ANYCLIENT, CString() << i->first << "=" << i->second); + server->sendPacketTo(PLTYPE_ANYCLIENT, {PLO_FLAGSET, CString() << serverFlag.first << "=" << serverFlag.second}); } } // If any flags were deleted, tell that to the players now. - for (auto i = oldFlags.begin(); i != oldFlags.end(); ++i) - server->sendPacketTo(PLO_FLAGDEL, PLTYPE_ANYCLIENT, CString() << i->first); + for (auto & oldFlag : oldFlags) + server->sendPacketTo(PLTYPE_ANYCLIENT, {PLO_FLAGDEL, CString() << oldFlag.first}); rclog.out("%s has updated the server flags.\n", accountName.text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " has updated the server flags."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " has updated the server flags."}); return true; } @@ -554,7 +554,7 @@ bool TPlayer::msgPLI_RC_ACCOUNTADD(CString& pPacket) if (isClient() || !hasRight(PLPERM_MODIFYSTAFFACCOUNT)) { if (isClient()) rclog.out("[Hack] %s attempted to add a new account.\n", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to create new accounts."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to create new accounts."}); return true; } @@ -573,7 +573,7 @@ bool TPlayer::msgPLI_RC_ACCOUNTADD(CString& pPacket) newAccount.saveAccount(); rclog.out("%s has created a new account: %s\n", accountName.text(), acc.text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " has created a new account: " << acc); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " has created a new account: " << acc}); return true; } @@ -582,7 +582,7 @@ bool TPlayer::msgPLI_RC_ACCOUNTDEL(CString& pPacket) if (isClient() || !hasRight(PLPERM_MODIFYSTAFFACCOUNT)) { if (isClient()) rclog.out("[Hack] %s attempted to delete an account.\n", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to delete accounts."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to delete accounts."}); return true; } @@ -596,22 +596,22 @@ bool TPlayer::msgPLI_RC_ACCOUNTDEL(CString& pPacket) if (acc == "defaultaccount") { - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not allowed to delete the default account."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not allowed to delete the default account."}); return true; } // See if the account exists. - CString accfile = CString(acc) << ".txt"; - CString accpath = server->getAccountsFileSystem()->find(accfile); - if (accpath.isEmpty()) return true; + CString accountFile = CString(acc) << ".txt"; + CString accountFilePath = server->getAccountsFileSystem()->find(accountFile); + if (accountFilePath.isEmpty()) return true; // Remove the account from the file system. - server->getAccountsFileSystem()->removeFile(accfile); + server->getAccountsFileSystem()->removeFile(accountFile); // Delete the file now. - remove(accpath.text()); + remove(accountFilePath.text()); rclog.out("%s has deleted the account: %s\n", accountName.text(), acc.text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " has deleted the account: " << acc); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " has deleted the account: " << acc}); return true; } @@ -635,20 +635,20 @@ bool TPlayer::msgPLI_RC_ACCOUNTLISTGET(CString& pPacket) CString ret; // Search through all the accounts. CFileSystem* fs = server->getAccountsFileSystem(); - for (std::map::iterator i = fs->getFileList().begin(); i != fs->getFileList().end(); ++i) + for (auto & i : fs->getFileList()) { - CString acc = removeExtension(i->first); + CString acc = removeExtension(i.first); if (acc.isEmpty()) continue; if (!acc.match(name)) continue; if (conditions.length() != 0) { - if (TAccount::meetsConditions(i->second, conditions)) + if (TAccount::meetsConditions(i.second, conditions)) ret >> (char)acc.length() << acc; } else ret >> (char)acc.length() << acc; } - sendPacket(PLO_RC_ACCOUNTLISTGET, ret); + sendPacket({PLO_RC_ACCOUNTLISTGET, ret}); return true; } @@ -660,11 +660,11 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSGET2(CString& pPacket) if (isClient() || !hasRight(PLPERM_VIEWATTRIBUTES)) { if (isClient()) rclog.out("[Hack] %s attempted to view the props of player %s.\n", accountName.text(), p->getAccountName().text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to view player props."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to view player props."}); return true; } - sendPacket(PLO_RC_PLAYERPROPSGET, CString() >> (short)p->getId() << p->getPropsRC()); + sendPacket({PLO_RC_PLAYERPROPSGET, CString() >> (short)p->getId() << p->getPropsRC()}); return true; } @@ -693,12 +693,12 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSGET3(CString& pPacket) if (isClient() || !hasRight(PLPERM_VIEWATTRIBUTES)) { if (isClient()) rclog.out("[Hack] %s attempted to view the props of player %s.\n", accountName.text(), p->getAccountName().text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to view player props."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to view player props."}); if (offline) delete p; return true; } - sendPacket(PLO_RC_PLAYERPROPSGET, CString() >> (short)p->getId() << p->getPropsRC()); + sendPacket({PLO_RC_PLAYERPROPSGET, CString() >> (short)p->getId() << p->getPropsRC()}); if (offline) delete p; return true; } @@ -712,20 +712,20 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSRESET(CString& pPacket) if (isClient() || !hasRight(PLPERM_RESETATTRIBUTES)) { if (isClient()) rclog.out("[Hack] %s attempted to reset the account: %s\n", accountName.text(), acc.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to reset accounts.\n"); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to reset accounts.\n"}); return true; } // Get the player. Create a new player if they are offline. bool offline = false; TPlayer* p = server->getPlayer(acc, PLTYPE_ANYCLIENT); - if (p == 0) + if (p == nullptr) { if (server->getAccountsFileSystem()->findi(CString(acc) << ".txt").isEmpty()) return true; offline = true; - p = new TPlayer(server, 0, -1); + p = new TPlayer(server, nullptr, -1); if (!p->loadAccount(acc)) { delete p; @@ -737,8 +737,8 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSRESET(CString& pPacket) CString adminip = p->getAdminIp(); int rights = p->getAdminRights(); std::vector folders; - for (std::vector::iterator i = p->getFolderList()->begin(); i != p->getFolderList()->end(); ++i) - folders.push_back(*i); + for (auto & i : *p->getFolderList()) + folders.push_back(i); // Reset the player. p->reset(); @@ -747,8 +747,8 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSRESET(CString& pPacket) p->setAdminIp(adminip); p->setAdminRights(rights); std::vector* pFolders = p->getFolderList(); - for (std::vector::iterator i = folders.begin(); i != folders.end(); ++i) - pFolders->push_back(*i); + for (auto & folder : folders) + pFolders->push_back(folder); // Save the account. p->saveAccount(); @@ -756,14 +756,14 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSRESET(CString& pPacket) // If the player is online, boot him from the server. if (!offline) { - p->sendPacket(PLO_DISCMESSAGE, CString() << "Your account was reset by " << accountName); + p->sendPacket({PLO_DISCMESSAGE, CString() << "Your account was reset by " << accountName}); p->setLoaded(false); // Don't save the account when the player quits. server->deletePlayer(p); } // Log it. rclog.out("%s has reset the attributes of account: %s\n", accountName.text(), acc.text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " has reset the attributes of account: " << acc); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " has reset the attributes of account: " << acc}); // Clean up. if (offline) delete p; @@ -797,7 +797,7 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSSET2(CString& pPacket) { if (isClient()) rclog.out("[Hack] %s attempted to set a player's properties.", accountName.text()); else rclog.out("%s attempted to set a player's properties.", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to set the properties of " << p->getAccountName()); + sendPacket({PLO_RC_CHAT, CString() << "Server: " << accountName << " is not authorized to set the properties of " << p->getAccountName()}); if (offline) delete p; return true; } @@ -805,7 +805,7 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSSET2(CString& pPacket) // Only people with PLPERM_MODIFYSTAFFACCOUNT can alter the default account. if (!hasRight(PLPERM_MODIFYSTAFFACCOUNT) && acc == "defaultaccount") { - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to modify the default account."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to modify the default account."}); if (offline) delete p; return true; } @@ -813,7 +813,7 @@ bool TPlayer::msgPLI_RC_PLAYERPROPSSET2(CString& pPacket) p->setPropsRC(pPacket, this); p->saveAccount(); rclog.out("%s set the attributes of player %s\n", accountName.text(), p->getAccountName().text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " set the attributes of player " << p->getAccountName()); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " set the attributes of player " << p->getAccountName()}); if (offline) delete p; return true; @@ -834,13 +834,13 @@ bool TPlayer::msgPLI_RC_ACCOUNTGET(CString& pPacket) // Get the player. bool offline = false; TPlayer* p = server->getPlayer(acc, PLTYPE_ANYCLIENT); - if (p == 0) + if (p == nullptr) { if (server->getAccountsFileSystem()->findi(CString(acc) << ".txt").isEmpty()) return true; offline = true; - p = new TPlayer(server, 0, -1); + p = new TPlayer(server, nullptr, -1); if (!p->loadAccount(acc)) { delete p; @@ -848,15 +848,20 @@ bool TPlayer::msgPLI_RC_ACCOUNTGET(CString& pPacket) } } - sendPacket(PLO_RC_ACCOUNTGET, CString() >> (char)acc.length() << acc - >> (char)0 /*>> (char)password_length << password*/ - >> (char)p->getEmail().length() << p->getEmail() - >> (char)(p->getBanned() ? 1 : 0) - >> (char)(p->getLoadOnly() ? 1 : 0) - >> (char)0 /*admin level*/ - >> (char)4 << "main" - >> (char)p->getBanLength().length() << p->getBanLength() - >> (char)p->getBanReason().length() << p->getBanReason()); + sendPacket( + { + PLO_RC_ACCOUNTGET, + CString() >> (char)acc.length() << acc + >> (char)0 /*>> (char)password_length << password*/ + >> (char)p->getEmail().length() << p->getEmail() + >> (char)(p->getBanned() ? 1 : 0) + >> (char)(p->getLoadOnly() ? 1 : 0) + >> (char)0 /*admin level*/ + >> (char)4 << "main" + >> (char)p->getBanLength().length() << p->getBanLength() + >> (char)p->getBanReason().length() << p->getBanReason() + } + ); if (offline) delete p; return true; @@ -872,14 +877,14 @@ bool TPlayer::msgPLI_RC_ACCOUNTSET(CString& pPacket) if (isClient() || !hasRight(PLPERM_MODIFYSTAFFACCOUNT)) { if (isClient()) rclog.out("[Hack] %s attempted to edit the account: %s\n", accountName.text(), acc.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to edit accounts.\n"); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to edit accounts.\n"}); return true; } CString pass = pPacket.readChars(pPacket.readGUChar()); CString email = pPacket.readChars(pPacket.readGUChar()); - bool banned = (pPacket.readGUChar() != 0 ? true : false); - bool loadOnly = (pPacket.readGUChar() != 0 ? true : false); + bool banned = pPacket.readGUChar() != 0; + bool loadOnly = pPacket.readGUChar() != 0; pPacket.readGUChar(); // admin level pPacket.readChars(pPacket.readGUChar()); // world CString banreason = pPacket.readChars(pPacket.readGUChar()); @@ -887,7 +892,7 @@ bool TPlayer::msgPLI_RC_ACCOUNTSET(CString& pPacket) // Get player. bool offline = false; TPlayer* p = server->getPlayer(acc, PLTYPE_ANYCLIENT); - if (p == 0) + if (p == nullptr) { if (server->getAccountsFileSystem()->findi(CString(acc) << ".txt").isEmpty()) return true; @@ -922,12 +927,12 @@ bool TPlayer::msgPLI_RC_ACCOUNTSET(CString& pPacket) if (hasRight(PLPERM_BAN) && banned && !offline) { p->setLoaded(false); - p->sendPacket(PLO_DISCMESSAGE, CString() << accountName << " has banned you. Reason: " << banreason.guntokenize().replaceAll("\n", "\r")); + p->sendPacket({PLO_DISCMESSAGE, CString() << accountName << " has banned you. Reason: " << banreason.guntokenize().replaceAll("\n", "\r")}); server->deletePlayer(p); } rclog.out("%s has modified the account: %s\n", accountName.text(), acc.text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " has modified the account: " << acc); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " has modified the account: " << acc}); if (offline) delete p; return true; @@ -972,15 +977,15 @@ bool TPlayer::msgPLI_RC_CHAT(CString& pPacket) { std::vector commands = CString::loadToken(CString() << server->getServerPath() << "config/rchelp.txt", "\n", true); for (auto & command : commands) - sendPacket(PLO_RC_CHAT, CString() << command); + sendPacket({PLO_RC_CHAT, CString() << command}); } else if (words[0] == "/version" && words.size() == 1) { - sendPacket(PLO_RC_CHAT, CString() << APP_NAME << " version: " << APP_VERSION); + sendPacket({PLO_RC_CHAT, CString() << APP_NAME << " version: " << APP_VERSION}); } else if (words[0] == "/credits" && words.size() == 1) { - sendPacket(PLO_RC_CHAT, CString() << "Programmed by " << APP_CREDITS); + sendPacket({PLO_RC_CHAT, CString() << "Programmed by " << APP_CREDITS}); } else if (words[0] == "/open" && words.size() != 1) { @@ -1011,7 +1016,7 @@ bool TPlayer::msgPLI_RC_CHAT(CString& pPacket) CString acc = message.readString(""); TPlayer *pl = server->getPlayer(acc, PLTYPE_ANYPLAYER); if (pl) - sendPacket(PLO_SERVERTEXT, CString() << "GraalEngine,lister,ban," << pl->getAccountName() << "," << std::to_string(pl->getDeviceId())); + sendPacket({PLO_SERVERTEXT, CString() << "GraalEngine,lister,ban," << pl->getAccountName() << "," << std::to_string(pl->getDeviceId())}); else { // TODO: player not logged in, load from offline? @@ -1041,25 +1046,25 @@ bool TPlayer::msgPLI_RC_CHAT(CString& pPacket) else if (words[0] == "/refreshservermessage" && words.size() == 1) { server->loadServerMessage(); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " refreshed the server message."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " refreshed the server message."}); rclog.out("%s refreshed the server message.\n", accountName.text()); } else if (words[0] == "/refreshfilesystem" && words.size() == 1) { server->loadFileSystem(); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " refreshed the server file list."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " refreshed the server file list."}); rclog.out("%s refreshed the server file list.\n", accountName.text()); } else if (words[0] == "/updatelevel" && words.size() != 1 && hasRight(PLPERM_UPDATELEVEL)) { std::vector levels = words[1].tokenize(","); - for (std::vector::const_iterator i = levels.begin(); i != levels.end(); ++i) + for (const auto & i : levels) { - TLevel* level = server->getLevel(*i); + TLevel* level = server->getLevel(i); if (level) { - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " updated level: " << level->getLevelName()); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " updated level: " << level->getLevelName()}); rclog.out("%s updated level: %s\n", accountName.text(), level->getLevelName().text()); level->reload(); } @@ -1070,29 +1075,29 @@ bool TPlayer::msgPLI_RC_CHAT(CString& pPacket) rclog.out("%s updated all the levels", accountName.text()); int count = 0; std::vector* levels = server->getLevelList(); - for (std::vector::iterator i = levels->begin(); i != levels->end(); ++i) + for (auto & level : *levels) { - (*i)->reload(); + level->reload(); ++count; } - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " updated all the levels (" << CString((int)count) << " levels updated)."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " updated all the levels (" << CString((int)count) << " levels updated)."}); rclog.out(" (%d levels updated).\n", count); } else if (words[0] == "/restartserver" && words.size() == 1 && hasRight(PLPERM_MODIFYSTAFFACCOUNT)) { - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " restarted the server."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " restarted the server."}); rclog.out("%s restarted the server.\n", accountName.text()); server->restart(); } else if (words[0] == "/reloadserver" && words.size() == 1 && hasRight(PLPERM_MODIFYSTAFFACCOUNT)) { - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " reloaded the server configuration files."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " reloaded the server configuration files."}); rclog.out("%s reloaded the server configuration files.\n", accountName.text()); server->loadConfigFiles(); } else if (words[0] == "/updateserverhq" && words.size() == 1 && hasRight(PLPERM_MODIFYSTAFFACCOUNT)) { - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " sent ServerHQ updates."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " sent ServerHQ updates."}); rclog.out("%s sent ServerHQ updates.\n", accountName.text()); server->loadAdminSettings(); server->getServerList()->sendServerHQ(); @@ -1116,30 +1121,30 @@ bool TPlayer::msgPLI_RC_CHAT(CString& pPacket) if (time_units.days == 0) format_time_fn(msg, time_units.seconds, "second"); - sendPacket(PLO_RC_CHAT, CString() << "Server Uptime:" << msg); + sendPacket({PLO_RC_CHAT, CString() << "Server Uptime:" << msg}); } else if (words[0] == "/reloadwordfilter" && words.size() == 1) { - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " reloaded the word filter."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " reloaded the word filter."}); rclog.out("%s reloaded the word filter.\n", accountName.text()); server->loadWordFilter(); } else if (words[0] == "/reloadipbans" && words.size() == 1) { - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " reloaded the ip bans."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " reloaded the ip bans."}); rclog.out("%s reloaded the ip bans.\n", accountName.text()); server->loadIPBans(); } else if (words[0] == "/reloadweapons" && words.size() == 1) { - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " reloaded the weapons."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " reloaded the weapons."}); rclog.out("%s reloaded the weapons.\n", accountName.text()); server->loadWeapons(true); } #ifdef V8NPCSERVER else if (words[0] == "/savenpcs" && words.size() == 1) { - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: " << accountName << " saved npc to disk."); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: " << accountName << " saved npc to disk."}); nclog.out("%s saved the npcs to disk.\n", accountName.text()); server->saveNpcs(); } @@ -1147,13 +1152,13 @@ bool TPlayer::msgPLI_RC_CHAT(CString& pPacket) { auto npcStats = server->calculateNpcStats(); - sendPacket(PLO_RC_CHAT, CString() << "Top scripts using the most execution time (in the last min)"); + sendPacket({PLO_RC_CHAT, CString() << "Top scripts using the most execution time (in the last min)"}); int idx = 0; - for (auto it = npcStats.begin(); it != npcStats.end(); ++it) + for (auto & npcStat : npcStats) { idx++; - sendPacket(PLO_RC_CHAT, CString() << CString(idx) << ". " << CString((*it).first) << " " << (*it).second); + sendPacket({PLO_RC_CHAT, CString() << CString(idx) << ". " << CString(npcStat.first) << " " << npcStat.second}); if (idx == 50) break; } @@ -1181,22 +1186,22 @@ bool TPlayer::msgPLI_RC_CHAT(CString& pPacket) if (i == 5) fs = "sword"; if (i == 6) fs = "shield"; - for (std::map::const_iterator i = fileList.begin(); i != fileList.end(); ++i) + for (auto & i : fileList) { - if (i->first.match(search)) - found[i->second.removeAll(server->getServerPath())] = fs; + if (i.first.match(search)) + found[i.second.removeAll(server->getServerPath())] = fs; } } // Return a list of files found. - for (std::map::const_iterator i = found.begin(); i != found.end(); ++i) + for (auto & i : found) { - sendPacket(PLO_RC_CHAT, CString() << "Server: File found (" << search << "): " << i->first << " [" << i->second << "]"); + sendPacket({PLO_RC_CHAT, CString() << "Server: File found (" << search << "): " << i.first << " [" << i.second << "]"}); } // No files found. if (found.size() == 0) - sendPacket(PLO_RC_CHAT, CString() << "Server: No files found matching: " << search); + sendPacket({PLO_RC_CHAT, CString() << "Server: No files found matching: " << search}); } } @@ -1208,12 +1213,12 @@ bool TPlayer::msgPLI_RC_WARPPLAYER(CString& pPacket) if (isClient() || !hasRight(PLPERM_WARPTOPLAYER)) { if (isClient()) rclog.out("[Hack] %s attempted to warp a player.\n", accountName.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to warp players.\n"); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to warp players.\n"}); return true; } TPlayer* p = server->getPlayer(pPacket.readGUShort(), PLTYPE_ANYPLAYER); - if (p == 0) return true; + if (p == nullptr) return true; float loc[2] = { (float)(pPacket.readGChar())/2.0f, (float)(pPacket.readGChar())/2.0f }; CString wLevel = pPacket.readString(""); @@ -1232,7 +1237,7 @@ bool TPlayer::msgPLI_RC_PLAYERRIGHTSGET(CString& pPacket) if (isClient() || (acc != accountName && !hasRight(PLPERM_SETRIGHTS))) { if (isClient()) rclog.out("[Hack] %s attempted to get the rights of %s\n", accountName.text(), acc.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to view that player's rights."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to view that player's rights."}); return true; } @@ -1242,13 +1247,13 @@ bool TPlayer::msgPLI_RC_PLAYERRIGHTSGET(CString& pPacket) // Get player. bool offline = false; TPlayer* p = server->getPlayer(acc, PLTYPE_ANYCLIENT); - if (p == 0) + if (p == nullptr) { if (server->getAccountsFileSystem()->findi(CString(acc) << ".txt").isEmpty()) return true; offline = true; - p = new TPlayer(server, 0, -1); + p = new TPlayer(server, nullptr, -1); if (!p->loadAccount(acc)) { delete p; @@ -1257,15 +1262,20 @@ bool TPlayer::msgPLI_RC_PLAYERRIGHTSGET(CString& pPacket) } // Get the folder list. - for (std::vector::iterator i = p->getFolderList()->begin(); i != p->getFolderList()->end(); ++i) - folders << *i << "\n"; + for (auto & i : *p->getFolderList()) + folders << i << "\n"; folders.gtokenizeI(); // Send the packet. - sendPacket(PLO_RC_PLAYERRIGHTSGET, CString() >> (char)acc.length() << acc - >> (long long)p->getAdminRights() - >> (char)p->getAdminIp().length() << p->getAdminIp() - >> (short)folders.length() << folders); + sendPacket( + { + PLO_RC_PLAYERRIGHTSGET, + CString() >> (char)acc.length() << acc + >> (long long)p->getAdminRights() + >> (char)p->getAdminIp().length() << p->getAdminIp() + >> (short)folders.length() << folders + } + ); if (offline) delete p; return true; @@ -1280,14 +1290,14 @@ bool TPlayer::msgPLI_RC_PLAYERRIGHTSSET(CString& pPacket) if (isClient() || !hasRight(PLPERM_SETRIGHTS)) { if (isClient()) rclog.out("[Hack] %s attempted to set the rights of %s\n", accountName.text(), acc.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to set player rights."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to set player rights."}); return true; } // Get player. bool offline = false; TPlayer* p = server->getPlayer(acc, PLTYPE_ANYCLIENT); - if (p == 0) + if (p == nullptr) { if (server->getAccountsFileSystem()->findi(CString(acc) << ".txt").isEmpty()) return true; @@ -1334,7 +1344,7 @@ bool TPlayer::msgPLI_RC_PLAYERRIGHTSSET(CString& pPacket) *fList = folders.tokenize("\n"); // Remove any invalid directories. - for (std::vector::iterator i = fList->begin(); i != fList->end();) + for (auto i = fList->begin(); i != fList->end();) { if ((*i).find(":") != -1 || (*i).find("..") != -1 || (*i).find(" /*") != -1) i = fList->erase(i); @@ -1369,7 +1379,7 @@ bool TPlayer::msgPLI_RC_PLAYERRIGHTSSET(CString& pPacket) } rclog.out("%s has set the rights of %s\n", accountName.text(), acc.text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " has set the rights of " << acc); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " has set the rights of " << acc}); if (offline) delete p; return true; @@ -1390,13 +1400,13 @@ bool TPlayer::msgPLI_RC_PLAYERCOMMENTSGET(CString& pPacket) // Get player. bool offline = false; TPlayer* p = server->getPlayer(acc, PLTYPE_ANYCLIENT); - if (p == 0) + if (p == nullptr) { if (server->getAccountsFileSystem()->findi(CString(acc) << ".txt").isEmpty()) return true; offline = true; - p = new TPlayer(server, 0, -1); + p = new TPlayer(server, nullptr, -1); if (!p->loadAccount(acc)) { delete p; @@ -1404,7 +1414,7 @@ bool TPlayer::msgPLI_RC_PLAYERCOMMENTSGET(CString& pPacket) } } - sendPacket(PLO_RC_PLAYERCOMMENTSGET, CString() >> (char)acc.length() << acc << p->getComments()); + sendPacket({PLO_RC_PLAYERCOMMENTSGET, CString() >> (char)acc.length() << acc << p->getComments()}); if (offline) delete p; return true; @@ -1419,20 +1429,20 @@ bool TPlayer::msgPLI_RC_PLAYERCOMMENTSSET(CString& pPacket) if (isClient() || !hasRight(PLPERM_SETCOMMENTS)) { if (isClient()) rclog.out("[Hack] %s attempted to set the comments of %s\n", accountName.text(), acc.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to set player comments."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to set player comments."}); return true; } // Get player. bool offline = false; TPlayer* p = server->getPlayer(acc, PLTYPE_ANYCLIENT); - if (p == 0) + if (p == nullptr) { if (server->getAccountsFileSystem()->findi(CString(acc) << ".txt").isEmpty()) return true; offline = true; - p = new TPlayer(server, 0, -1); + p = new TPlayer(server, nullptr, -1); if (!p->loadAccount(acc)) { delete p; @@ -1452,7 +1462,7 @@ bool TPlayer::msgPLI_RC_PLAYERCOMMENTSSET(CString& pPacket) } rclog.out("%s has set the comments of %s\n", accountName.text(), acc.text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " has set the comments of " << acc); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " has set the comments of " << acc}); if (offline) delete p; return true; @@ -1473,7 +1483,7 @@ bool TPlayer::msgPLI_RC_PLAYERBANGET(CString& pPacket) // Get player. bool offline = false; TPlayer* p = server->getPlayer(acc, PLTYPE_ANYCLIENT); - if (p == 0) + if (p == nullptr) { if (server->getAccountsFileSystem()->findi(CString(acc) << ".txt").isEmpty()) return true; @@ -1487,7 +1497,7 @@ bool TPlayer::msgPLI_RC_PLAYERBANGET(CString& pPacket) } } - sendPacket(PLO_RC_PLAYERBANGET, CString() >> (char)acc.length() << acc >> (char)(p->getBanned() ? 1 : 0) << p->getBanReason()); + sendPacket({PLO_RC_PLAYERBANGET, CString() >> (char)acc.length() << acc >> (char)(p->getBanned() ? 1 : 0) << p->getBanReason()}); if (offline) delete p; return true; @@ -1502,14 +1512,14 @@ bool TPlayer::msgPLI_RC_PLAYERBANSET(CString& pPacket) if (isClient() || !hasRight(PLPERM_BAN)) { if (isClient()) rclog.out("[Hack] %s attempted to set the ban of %s\n", accountName.text(), acc.text()); - sendPacket(PLO_RC_CHAT, CString() << "Server: You are not authorized to set player bans."); + sendPacket({PLO_RC_CHAT, CString() << "Server: You are not authorized to set player bans."}); return true; } // Get player. bool offline = false; TPlayer* p = server->getPlayer(acc, PLTYPE_ANYCLIENT); - if (p == 0) + if (p == nullptr) { if (server->getAccountsFileSystem()->findi(CString(acc) << ".txt").isEmpty()) return true; @@ -1523,7 +1533,7 @@ bool TPlayer::msgPLI_RC_PLAYERBANSET(CString& pPacket) } } - bool banned = (pPacket.readGUChar() == 0 ? false : true); + bool banned = !(pPacket.readGUChar() == 0); CString reason = pPacket.readString(""); p->setBanned(banned); @@ -1540,12 +1550,12 @@ bool TPlayer::msgPLI_RC_PLAYERBANSET(CString& pPacket) // If the player was just now banned, kick him off the server. if (banned && !offline) { - p->sendPacket(PLO_DISCMESSAGE, CString() << accountName << " has banned you. Reason: " << reason.guntokenize().replaceAll("\n", "\r")); + p->sendPacket({PLO_DISCMESSAGE, CString() << accountName << " has banned you. Reason: " << reason.guntokenize().replaceAll("\n", "\r")}); server->deletePlayer(p); } rclog.out("%s has set the ban of %s\n", accountName.text(), acc.text()); - server->sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << accountName << " has set the ban of " << acc); + server->sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << accountName << " has set the ban of " << acc}); if (offline) delete p; return true; @@ -1569,17 +1579,16 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_START(CString& pPacket) folders << *i << "\n"; // Send the folder list and the welcome message. - sendPacket(PLO_RC_FILEBROWSER_DIRLIST, CString() << folders.gtokenize()); - if (!isFtp) sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Welcome to the File Browser."); + sendPacket({PLO_RC_FILEBROWSER_DIRLIST, CString() << folders.gtokenize()}); + if (!isFtp) sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Welcome to the File Browser."}); // Create a folder map. std::map folderMap; - for (std::vector::iterator i = folderList.begin(); i != folderList.end(); ++i) + for (auto folder : folderList) { CString rights("r"); CString wild("*"); - CString folder(*i); - rights = folder.readString(" ").trim().toLower(); + rights = folder.readString(" ").trim().toLower(); folder.removeI(0, folder.readPos()); folder.replaceAllI("\\", "/"); folder.trimI(); @@ -1606,12 +1615,12 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_START(CString& pPacket) // Construct the file list. CString files; std::vector wildcards = folderMap[lastFolder].tokenize("\n"); - for (std::vector::iterator i = wildcards.begin(); i != wildcards.end(); ++i) + for (auto & i : wildcards) { - CString rights = (*i).readString(":"); - CString wildcard = (*i).readString(""); - (*i).setRead(0); - for (std::map::iterator j = fs.getFileList().begin(); j != fs.getFileList().end(); ++j) + CString rights = i.readString(":"); + CString wildcard = i.readString(""); + i.setRead(0); + for (auto j = fs.getFileList().begin(); j != fs.getFileList().end(); ++j) { // See if the file matches the wildcard. if (!j->first.match(wildcard)) @@ -1629,7 +1638,7 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_START(CString& pPacket) } // Send packet. - sendPacket(PLO_RC_FILEBROWSER_DIR, CString() >> (char)lastFolder.length() << lastFolder << files); + sendPacket({PLO_RC_FILEBROWSER_DIR, CString() >> (char)lastFolder.length() << lastFolder << files}); isFtp = true; return true; @@ -1645,12 +1654,11 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_CD(CString& pPacket) // Create a folder map. std::map folderMap; - for (std::vector::iterator i = folderList.begin(); i != folderList.end(); ++i) + for (auto folder : folderList) { CString rights("r"); CString wild("*"); - CString folder(*i); - rights = folder.readString(" ").trim().toLower(); + rights = folder.readString(" ").trim().toLower(); folder.removeI(0, folder.readPos()); folder.replaceAllI("\\", "/"); folder.trimI(); @@ -1679,10 +1687,10 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_CD(CString& pPacket) // Make sure our folder exists. CString mkdir_path = CString() << server->getServerPath(); std::vector f = lastFolder.tokenize('/'); - for (std::vector::iterator i = f.begin(); i != f.end(); ++i) + for (auto & i : f) { - if (i->isEmpty()) continue; - mkdir_path << *i << '/'; + if (i.isEmpty()) continue; + mkdir_path << i << '/'; #if defined(_WIN32) || defined(_WIN64) mkdir(mkdir_path.text()); @@ -1696,12 +1704,12 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_CD(CString& pPacket) // files: {CHAR file_packet_length}{file_packet}[space]{CHAR file_packet_length}{file_packet}[space] CString files; std::vector wildcards = folderMap[lastFolder].tokenize("\n"); - for (std::vector::iterator i = wildcards.begin(); i != wildcards.end(); ++i) + for (auto & i : wildcards) { - CString rights = (*i).readString(":"); - CString wildcard = (*i).readString(""); - (*i).setRead(0); - for (std::map::iterator j = fs.getFileList().begin(); j != fs.getFileList().end(); ++j) + CString rights = i.readString(":"); + CString wildcard = i.readString(""); + i.setRead(0); + for (auto j = fs.getFileList().begin(); j != fs.getFileList().end(); ++j) { // See if the file matches the wildcard. if (!j->first.match(wildcard)) @@ -1719,8 +1727,8 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_CD(CString& pPacket) } // Send packet. - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Folder changed to " << lastFolder); - sendPacket(PLO_RC_FILEBROWSER_DIR, CString() >> (char)lastFolder.length() << lastFolder << files); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Folder changed to " << lastFolder}); + sendPacket({PLO_RC_FILEBROWSER_DIR, CString() >> (char)lastFolder.length() << lastFolder << files}); return true; } @@ -1749,11 +1757,11 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_DOWN(CString& pPacket) // Don't let us download/view important files. if (!hasRight(PLPERM_MODIFYSTAFFACCOUNT)) { - for (unsigned int j = 0; j < sizeof(__protectedFiles) / sizeof(const char*); ++j) + for (auto & __protectedFile : __protectedFiles) { - if (checkFile == CString(__protectedFiles[j])) + if (checkFile == CString(__protectedFile)) { - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Insufficient rights to download/view " << checkFile); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Insufficient rights to download/view " << checkFile}); return true; } } @@ -1762,7 +1770,7 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_DOWN(CString& pPacket) this->sendFile(lastFolder, file); rclog.out("%s downloaded file %s\n", accountName.text(), file.text()); - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Downloaded file " << file); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Downloaded file " << file}); return true; } @@ -1808,7 +1816,7 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_UP(CString& pPacket) // Don't let us upload/overwrite important files. if (isProtected && !hasPermission) { - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Insufficent rights to upload " << checkFile); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Insufficent rights to upload " << checkFile}); return true; } @@ -1819,7 +1827,7 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_UP(CString& pPacket) fileData.save(filepath << file); rclog.out("%s uploaded file %s\n", accountName.text(), file.text()); - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Uploaded file " << file); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Uploaded file " << file}); // Update file. updateFile(this, server, lastFolder, file); @@ -1858,11 +1866,11 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_MOVE(CString& pPacket) source << lastFolder << file; // Don't let us move important files. - for (unsigned int j = 0; j < sizeof(__importantFiles) / sizeof(const char*); ++j) + for (auto & __importantFile : __importantFiles) { - if (source == CString(__importantFiles[j])) + if (source == CString(__importantFile)) { - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Not allowed to move file " << source); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Not allowed to move file " << source}); return true; } } @@ -1878,7 +1886,7 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_MOVE(CString& pPacket) // Save the new file now. CString temp; temp.load(source); - if (temp.save(destination) == false) + if (!temp.save(destination)) return true; // Remove the old file. @@ -1925,11 +1933,11 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_DELETE(CString& pPacket) CFileSystem::fixPathSeparators(filePath); // Don't let us delete important files. - for (unsigned int j = 0; j < sizeof(__importantFiles) / sizeof(const char*); ++j) + for (auto & __importantFile : __importantFiles) { - if (checkFile == CString(__importantFiles[j])) + if (checkFile == CString(__importantFile)) { - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Not allowed to delete file " << checkFile); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Not allowed to delete file " << checkFile}); return true; } } @@ -1961,7 +1969,7 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_DELETE(CString& pPacket) #endif rclog.out("%s deleted file %s\n", accountName.text(), file.text()); - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Deleted file " << file); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Deleted file " << file}); return true; } @@ -1985,11 +1993,11 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_RENAME(CString& pPacket) // Don't let us rename/overwrite important files. - for (unsigned int j = 0; j < sizeof(__importantFiles) / sizeof(const char*); ++j) + for (auto & __importantFile : __importantFiles) { - if (checkFile1 == CString(__importantFiles[j])) + if (checkFile1 == CString(__importantFile)) { - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Not allowed to rename/overwrite file " << checkFile1 << " or " << checkFile2); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Not allowed to rename/overwrite file " << checkFile1 << " or " << checkFile2}); return true; } } @@ -2056,7 +2064,7 @@ bool TPlayer::msgPLI_RC_FILEBROWSER_RENAME(CString& pPacket) } rclog.out("%s renamed file %s to %s\n", accountName.text(), f1.text(), f2.text()); - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Renamed file " << f1 << " to " << f2); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Renamed file " << f1 << " to " << f2}); return true; } @@ -2090,7 +2098,7 @@ bool TPlayer::msgPLI_RC_LARGEFILEEND(CString& pPacket) rcLargeFiles[file].save(filepath); // Remove the data from memory. - for (std::map::iterator i = rcLargeFiles.begin(); i != rcLargeFiles.end(); ++i) + for (auto i = rcLargeFiles.begin(); i != rcLargeFiles.end(); ++i) { if (i->first == file) { @@ -2103,7 +2111,7 @@ bool TPlayer::msgPLI_RC_LARGEFILEEND(CString& pPacket) updateFile(this, server, lastFolder, file); rclog.out("%s uploaded large file %s\n", accountName.text(), file.text()); - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Uploaded large file " << file); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Uploaded large file " << file}); return true; } @@ -2124,12 +2132,12 @@ bool TPlayer::msgPLI_RC_FOLDERDELETE(CString& pPacket) if (rmdir(folderpath.text())) { perror("Error removing folder"); - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Error removing " << folder << ". Folder may not exist or may not be empty."); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Error removing " << folder << ". Folder may not exist or may not be empty."}); return true; } rclog.out("%s removed folder %s\n", accountName.text(), folder.text()); - sendPacket(PLO_RC_FILEBROWSER_MESSAGE, CString() << "Folder " << folder << " has been removed.\n"); + sendPacket({PLO_RC_FILEBROWSER_MESSAGE, CString() << "Folder " << folder << " has been removed.\n"}); msgPLI_RC_FILEBROWSER_START(CString() << ""); return true; @@ -2269,7 +2277,7 @@ void updateFile(TPlayer* player, TServer* server, CString& dir, CString& file) if (pl->isClient() && pl->getVersion() >= CLVER_4_0211) { if (pl->hasSeenFile(fileName)) - pl->sendPacket(PLO_UPDATEPACKAGEISUPDATED, file); + pl->sendPacket({PLO_UPDATEPACKAGEISUPDATED, file}); // Send GS2 gani scripts if (findAni) diff --git a/server/src/TPlayer/TPlayerRequestText.cpp b/server/src/TPlayer/TPlayerRequestText.cpp index 7a4fb1d0..ba9dec9f 100644 --- a/server/src/TPlayer/TPlayerRequestText.cpp +++ b/server/src/TPlayer/TPlayerRequestText.cpp @@ -22,12 +22,12 @@ bool TPlayer::msgPLI_REQUESTTEXT(CString& pPacket) list->sendPacket(CString() >> (char)SVO_REQUESTLIST >> (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()); + sendPacket({PLO_SERVERTEXT, CString() << CString(CString() << weapon << "\n" << type << "\n" << "subscriptions" << "\n" << CString(CString() << "unlimited" << "\n" << "Unlimited Subscription" << "\n" << "\"\"" << "\n").gtokenizeI()).gtokenizeI()}); } else if (option == "bantypes") - sendPacket(PLO_SERVERTEXT, CString() << packet << ",\"\"\"Event Interruption\"\",259200\",\"\"\"Message Code Abuse\"\",259200\",\"\"\"General Scamming\"\",604800\",\"Advertising,604800\",\"\"\"General Harassment\"\",604800\",\"\"\"Racism or Severe Vulgarity\"\",1209600\",\"\"\"Sexual Harassment\"\",1209600\",\"Cheating,2592000\",\"\"\"Advertising Money Trade\"\",2592000\",\"\"\"Ban Evasion\"\",2592000\",\"\"\"Speed Hacking\"\",2592000\",\"\"\"Bug Abuse\"\",2592000\",\"\"\"Multiple Jailings\"\",2592000\",\"\"\"Server Destruction\"\",3888000\",\"\"\"Leaking Information\"\",3888000\",\"\"\"Account Scam\"\",7776000\",\"\"\"Account Sharing\"\",315360000\",\"Hacking,315360000\",\"\"\"Multiple Bans\"\",315360000\",\"\"\"Other Unlimited\"\",315360001\""); + sendPacket({PLO_SERVERTEXT, CString() << packet << ",\"\"\"Event Interruption\"\",259200\",\"\"\"Message Code Abuse\"\",259200\",\"\"\"General Scamming\"\",604800\",\"Advertising,604800\",\"\"\"General Harassment\"\",604800\",\"\"\"Racism or Severe Vulgarity\"\",1209600\",\"\"\"Sexual Harassment\"\",1209600\",\"Cheating,2592000\",\"\"\"Advertising Money Trade\"\",2592000\",\"\"\"Ban Evasion\"\",2592000\",\"\"\"Speed Hacking\"\",2592000\",\"\"\"Bug Abuse\"\",2592000\",\"\"\"Multiple Jailings\"\",2592000\",\"\"\"Server Destruction\"\",3888000\",\"\"\"Leaking Information\"\",3888000\",\"\"\"Account Scam\"\",7776000\",\"\"\"Account Sharing\"\",315360000\",\"Hacking,315360000\",\"\"\"Multiple Bans\"\",315360000\",\"\"\"Other Unlimited\"\",315360001\""}); 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()); + 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); } @@ -52,7 +52,7 @@ bool TPlayer::msgPLI_REQUESTTEXT(CString& pPacket) files++; } } - sendPacket(PLO_SERVERTEXT, CString() << CString(weapon << "\n" << type << "\n" << option << "\n" << /* File count */ CString(files) << "\n" << /* Total size in bytes */ CString(totalFileSize) << "\n").gtokenizeI()); + sendPacket({PLO_SERVERTEXT, CString() << CString(weapon << "\n" << type << "\n" << option << "\n" << /* File count */ CString(files) << "\n" << /* Total size in bytes */ CString(totalFileSize) << "\n").gtokenizeI()}); } @@ -89,9 +89,9 @@ bool TPlayer::msgPLI_SENDTEXT(CString& pPacket) if (isRC()) { // Irc players start at 16k - sendPacket(PLO_ADDPLAYER, CString() >> (short)(16000 + 0) >> (char)channelAccount.length() << channelAccount >> (char)PLPROP_NICKNAME >> (char)channelNick.length() << channelNick >> (char)PLPROP_UNKNOWN81 >> (char)3); + sendPacket({PLO_ADDPLAYER, CString() >> (short)(16000 + 0) >> (char)channelAccount.length() << channelAccount >> (char)PLPROP_NICKNAME >> (char)channelNick.length() << channelNick >> (char)PLPROP_UNKNOWN81 >> (char)3}); } - else sendPacket(PLO_OTHERPLPROPS, CString() >> (short)(16000 + 0) >> (char)PLPROP_ACCOUNTNAME >> (char)channelAccount.length() << channelAccount >> (char)PLPROP_NICKNAME >> (char)channelNick.length() << channelNick >> (char)PLPROP_UNKNOWN81 >> (char)3); + else sendPacket({PLO_OTHERPLPROPS, CString() >> (short)(16000 + 0) >> (char)PLPROP_ACCOUNTNAME >> (char)channelAccount.length() << channelAccount >> (char)PLPROP_NICKNAME >> (char)channelNick.length() << channelNick >> (char)PLPROP_UNKNOWN81 >> (char)3}); } else if (params.size() > 3) { @@ -165,7 +165,7 @@ bool TPlayer::msgPLI_SENDTEXT(CString& pPacket) if (option == "getban") { // Send param is computer id. Either 0, or the id. It is required though - sendPacket(PLO_SERVERTEXT, CString() << "GraalEngine,lister,ban," << params[0] << "," << "0"); + sendPacket({PLO_SERVERTEXT, CString() << "GraalEngine,lister,ban," << params[0] << "," << "0"}); //msgPLI_RC_PLAYERBANGET(params[0]); } } diff --git a/server/src/TPlayer/TPlayerScripts.cpp b/server/src/TPlayer/TPlayerScripts.cpp index 9c3e8d15..dd818473 100644 --- a/server/src/TPlayer/TPlayerScripts.cpp +++ b/server/src/TPlayer/TPlayerScripts.cpp @@ -27,7 +27,7 @@ bool TPlayer::msgPLI_UPDATEGANI(CString& pPacket) sendPacket(packet); // v4 and up needs this for some reason. - sendPacket(PLO_UNKNOWN195, CString() >> (char)gani.length() << gani << "\"SETBACKTO " << findAni->getSetBackTo() << "\""); + sendPacket({PLO_UNKNOWN195, CString() >> (char)gani.length() << gani << "\"SETBACKTO " << findAni->getSetBackTo() << "\""}); return true; } @@ -42,10 +42,10 @@ bool TPlayer::msgPLI_UPDATESCRIPT(CString& pPacket) if (weaponObj != nullptr) { CString b = weaponObj->getByteCode(); - if (newProtocol) - sendPacket(PLO_NPCWEAPONSCRIPT, b); - else - sendPacket(PLO_RAWDATA, CString() >> (int)b.length() << "\n" >> (char)PLO_NPCWEAPONSCRIPT << b); + if (!newProtocol) + sendPacket({PLO_RAWDATA, CString() >> (int)b.length() << "\n"}); + + sendPacket({ PLO_NPCWEAPONSCRIPT, b }); } return true; @@ -64,9 +64,9 @@ bool TPlayer::msgPLI_UPDATECLASS(CString& pPacket) if (classObj != nullptr) { if (!newProtocol) - sendPacket(PLO_RAWDATA, CString() >> (int)classObj->getByteCode().length() << "\n" >> (char)PLO_NPCWEAPONSCRIPT << classObj->getByteCode()); - else - sendPacket(PLO_NPCWEAPONSCRIPT, classObj->getByteCode()); + sendPacket({PLO_RAWDATA, CString() >> (int)classObj->getByteCode().length() << "\n"}); + + sendPacket({PLO_NPCWEAPONSCRIPT, classObj->getByteCode()}); } else { @@ -82,7 +82,7 @@ bool TPlayer::msgPLI_UPDATECLASS(CString& pPacket) // Should technically be PLO_UNKNOWN197 but for some reason the client breaks player.join() scripts // if a weapon decides to request an class that doesnt exist on the server. This seems to fix it by // sending an empty bytecode - sendPacket(PLO_NPCWEAPONSCRIPT, CString() >> (short)gstr.length() << gstr); + sendPacket({PLO_NPCWEAPONSCRIPT, CString() >> (short)gstr.length() << gstr}); } return true; diff --git a/server/src/TPlayer/TPlayerUpdatePackages.cpp b/server/src/TPlayer/TPlayerUpdatePackages.cpp index e9461ad2..b4eda5bf 100644 --- a/server/src/TPlayer/TPlayerUpdatePackages.cpp +++ b/server/src/TPlayer/TPlayerUpdatePackages.cpp @@ -23,7 +23,7 @@ bool TPlayer::msgPLI_VERIFYWANTSEND(CString& pPacket) { if (calculateCrc32Checksum(fileData) == fileChecksum) { - sendPacket(PLO_FILEUPTODATE, CString() << fileName); + sendPacket({PLO_FILEUPTODATE, CString() << fileName}); return true; } } @@ -41,14 +41,14 @@ bool TPlayer::msgPLI_UPDATEPACKAGEREQUESTFILE(CString& pPacket) // 1 -> Install, 2 -> Reinstall unsigned char installType = pPacket.readGUChar(); CString fileChecksums = pPacket.readString(""); - + // If this is a reinstall, we need to download everything so clear the checksum data if (installType == 2) fileChecksums.clear(); - + auto totalDownloadSize = 0; std::vector missingFiles; - + { auto updatePackage = server->getPackageManager().findOrAddResource(packageName.toString()); if (updatePackage) @@ -63,7 +63,7 @@ bool TPlayer::msgPLI_UPDATEPACKAGEREQUESTFILE(CString& pPacket) if (entry.checksum == userFileChecksum) needsFile = false; } - + if (needsFile) { totalDownloadSize += entry.size; @@ -72,13 +72,12 @@ bool TPlayer::msgPLI_UPDATEPACKAGEREQUESTFILE(CString& pPacket) } } } - - sendPacket(PLO_UPDATEPACKAGESIZE, CString() >> (char)packageName.length() << packageName - >> (long long)totalDownloadSize); - + + sendPacket({PLO_UPDATEPACKAGESIZE, CString() >> (char)packageName.length() << packageName >> (long long)totalDownloadSize}); + for (const auto& wantFile : missingFiles) - this->sendFile(wantFile); - - sendPacket(PLO_UPDATEPACKAGEDONE, CString() << packageName); + sendFile(wantFile); + + sendPacket({PLO_UPDATEPACKAGEDONE, CString() << packageName}); return true; } diff --git a/server/src/TServer.cpp b/server/src/TServer.cpp index 94741e8d..38d0aa3a 100644 --- a/server/src/TServer.cpp +++ b/server/src/TServer.cpp @@ -294,7 +294,7 @@ void TServer::cleanup() #endif // Save translations. - this->TS_Save(); + TS_Save(); // Save server flags. saveServerFlags(); @@ -389,7 +389,7 @@ bool TServer::doTimedEvents() if (!player->isNPCServer()) { if (!player->doTimedEvents()) - this->deletePlayer(player); + deletePlayer(player); } } } @@ -432,7 +432,7 @@ bool TServer::doTimedEvents() last1mTimer = lastTimer; // Save server flags. - this->saveServerFlags(); + saveServerFlags(); } // Stuff that happens every 3 minutes. @@ -732,7 +732,7 @@ void TServer::loadServerFlags() { std::vector lines = CString::loadToken(CString() << serverpath << "serverflags.txt", "\n", true); for (auto & line : lines) - this->setFlag(line, false); + setFlag(line, false); } void TServer::loadServerMessage() @@ -798,7 +798,7 @@ void TServer::loadWeapons(bool print) if (print) { serverlog.out("[%s] %s [updated]\n", name.text(), weapon->getName().c_str()); - TServer::sendPacketTo(PLO_RC_CHAT, PLTYPE_ANYRC, CString() << "Server: Updated weapon " << weapon->getName() << " "); + sendPacketTo(PLTYPE_ANYRC, {PLO_RC_CHAT, CString() << "Server: Updated weapon " << weapon->getName() << " "}); } } else @@ -987,7 +987,7 @@ void TServer::loadNpcs(bool print) void TServer::loadTranslations() { - this->TS_Reload(); + TS_Reload(); } void TServer::loadWordFilter() @@ -1255,7 +1255,7 @@ TNPC* TServer::addServerNpc(int npcId, float pX, float pY, TLevel *pLevel, bool // Send to level. TMap* map = pLevel->getMap(); - sendPacketToLevel(PLO_NPCPROPS, packet, map, pLevel, 0, true); + sendPacketToLevel({PLO_NPCPROPS, packet}, map, pLevel, nullptr, true); } } @@ -1268,7 +1268,7 @@ void TServer::handlePM(TPlayer * player, const CString & message) { CString npcServerMsg; npcServerMsg = "I am the npcserver for\nthis game server. Almost\nall npc actions are controlled\nby me."; - player->sendPacket(PLO_PRIVATEMESSAGE, CString() >> (short)mNpcServer->getId() << "\"\"," << npcServerMsg.gtokenize()); + player->sendPacket({PLO_PRIVATEMESSAGE, CString() >> (short)mNpcServer->getId() << "\"\"," << npcServerMsg.gtokenize()}); return; } @@ -1326,7 +1326,7 @@ TNPC* TServer::addNPC(const CString& pImage, const CString& pScript, float pX, f // Send to level. TMap* map = pLevel->getMap(); - sendPacketToLevel(PLO_NPCPROPS, packet, map, pLevel, 0, true); + sendPacketToLevel({PLO_NPCPROPS, packet}, map, pLevel, nullptr, true); } return newNPC; @@ -1364,9 +1364,9 @@ bool TServer::deleteNPC(TNPC* npc, bool eraseFromLevel) if (p->isClient()) { if (isOnMap || p->getVersion() < CLVER_2_1) - p->sendPacket(PLO_NPCDEL, CString() >> (int)npc->getId()); + p->sendPacket({PLO_NPCDEL, CString() >> (int)npc->getId()}); else - p->sendPacket(PLO_NPCDEL2, CString() >> (char)tmpLvlName.length() << tmpLvlName >> (int)npc->getId()); + p->sendPacket({PLO_NPCDEL2, CString() >> (char)tmpLvlName.length() << tmpLvlName >> (int)npc->getId()}); } } } @@ -1492,10 +1492,10 @@ void TServer::playerLoggedIn(TPlayer *player) #ifdef V8NPCSERVER // Send event to server that player is logging in - for (auto it = npcNameList.begin(); it != npcNameList.end(); ++it) + for (auto & it : npcNameList) { // TODO(joey): check if they have the event before queueing for them - TNPC *npcObject = (*it).second; + TNPC *npcObject = it.second; npcObject->queueNpcAction("npc.playerlogin", player); } #endif @@ -1558,7 +1558,7 @@ bool TServer::deleteFlag(const std::string& pFlagName, bool pSendToPlayers) { mServerFlags.erase(mServerFlag); if (pSendToPlayers) - sendPacketToAll(PLO_FLAGDEL, CString() << pFlagName, nullptr); + sendPacketToAll({PLO_FLAGDEL, CString() << pFlagName}, nullptr); return true; } @@ -1569,7 +1569,7 @@ bool TServer::setFlag(CString pFlag, bool pSendToPlayers) { std::string flagName = pFlag.readString("=").text(); CString flagValue = pFlag.readString(""); - return this->setFlag(flagName, (flagValue.isEmpty() ? "1" : flagValue), pSendToPlayers); + return setFlag(flagName, (flagValue.isEmpty() ? "1" : flagValue), pSendToPlayers); } bool TServer::setFlag(const std::string& pFlagName, const CString& pFlagValue, bool pSendToPlayers) @@ -1594,26 +1594,25 @@ bool TServer::setFlag(const std::string& pFlagName, const CString& pFlagValue, b else mServerFlags[pFlagName] = pFlagValue; if (pSendToPlayers) - sendPacketToAll(PLO_FLAGSET, CString() << pFlagName << "=" << pFlagValue, nullptr); + sendPacketToAll({PLO_FLAGSET, CString() << pFlagName << "=" << pFlagValue}, nullptr); return true; } /* Packet-Sending Functions */ -void TServer::sendPacketToAll(char packetId, CString pPacket, TPlayer *sender) const +void TServer::sendPacketToAll(PlayerOutPacket pPacket, TPlayer *sender) const { for (auto player : playerList) { if (player == sender || player->isNPCServer()) continue; - player->sendPacket(packetId, pPacket); + player->sendPacket(pPacket); } } - -void TServer::sendPacketToLevel(char packetId, CString pPacket, TLevel* pLevel, TPlayer* pPlayer) const +void TServer::sendPacketToLevel(PlayerOutPacket pPacket, TLevel* pLevel, TPlayer* pPlayer) const { if (!pLevel) return; @@ -1623,7 +1622,7 @@ void TServer::sendPacketToLevel(char packetId, CString pPacket, TLevel* pLevel, for (auto p : playerList) { if (p != pPlayer && p->isClient() && p->getLevel() == pLevel) - p->sendPacket(packetId, pPacket); + p->sendPacket(pPacket); } } else @@ -1636,13 +1635,13 @@ void TServer::sendPacketToLevel(char packetId, CString pPacket, TLevel* pLevel, int ogmap[2] = { other->getLevel()->getMapX(), other->getLevel()->getMapY() }; if (abs(ogmap[0] - sgmap[0]) < 2 && abs(ogmap[1] - sgmap[1]) < 2) - other->sendPacket(packetId, pPacket); + other->sendPacket(pPacket); } } } } -void TServer::sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TLevel* pLevel, TPlayer* pPlayer, bool onlyGmap) const +void TServer::sendPacketToLevel(PlayerOutPacket pPacket, TMap* pMap, TLevel* pLevel, TPlayer* pPlayer, bool onlyGmap) const { if (pMap == nullptr || (onlyGmap && pMap->getType() == MapType::BIGMAP))// || pLevel->isGroupLevel()) { @@ -1650,7 +1649,7 @@ void TServer::sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TLev { if ( p == pPlayer || !p->isClient()) continue; if ( p->getLevel() == pLevel) - p->sendPacket(packetId, pPacket); + p->sendPacket(pPacket); } return; } @@ -1681,12 +1680,12 @@ void TServer::sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TLev //} if (abs(ogmap[0] - sgmap[0]) < 2 && abs(ogmap[1] - sgmap[1]) < 2) - other->sendPacket(packetId, pPacket); + other->sendPacket(pPacket); } } } -void TServer::sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf, bool onlyGmap) const +void TServer::sendPacketToLevel(PlayerOutPacket pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf, bool onlyGmap) const { if (!pPlayer->getLevel()) return; @@ -1699,7 +1698,7 @@ void TServer::sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TPla { if ((p == pPlayer && !sendToSelf) || !p->isClient()) continue; if ( p->getLevel() == level) - p->sendPacket(packetId, pPacket); + p->sendPacket(pPacket); } return; } @@ -1710,7 +1709,7 @@ void TServer::sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TPla if (!player->isClient()) continue; if ( player == pPlayer) { - if (sendToSelf) pPlayer->sendPacket(packetId, pPacket); + if (sendToSelf) pPlayer->sendPacket(pPacket); continue; } if ( player->getLevel() == nullptr) continue; @@ -1738,12 +1737,12 @@ void TServer::sendPacketToLevel(char packetId, CString pPacket, TMap* pMap, TPla } if (abs(ogmap[0] - sgmap[0]) < 2 && abs(ogmap[1] - sgmap[1]) < 2) - player->sendPacket(packetId, pPacket); + player->sendPacket(pPacket); } } } -void TServer::sendPacketToLevel(PlayerPredicate predicate, char packetId, CString pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf, bool onlyGmap) const +void TServer::sendPacketToLevel(PlayerPredicate predicate, PlayerOutPacket pPacket, TMap* pMap, TPlayer* pPlayer, bool sendToSelf, bool onlyGmap) const { if (!pPlayer->getLevel()) return; @@ -1755,7 +1754,7 @@ void TServer::sendPacketToLevel(PlayerPredicate predicate, char packetId, CStrin { if ((p == pPlayer && !sendToSelf) || !p->isClient()) continue; if (p->getLevel() == level && predicate(p)) - p->sendPacket(packetId, pPacket); + p->sendPacket(pPacket); } return; } @@ -1766,7 +1765,7 @@ void TServer::sendPacketToLevel(PlayerPredicate predicate, char packetId, CStrin if (!player->isClient()) continue; if (player == pPlayer) { - if (sendToSelf) pPlayer->sendPacket(packetId, pPacket); + if (sendToSelf) pPlayer->sendPacket(pPacket); continue; } if (player->getLevel() == nullptr) continue; @@ -1794,19 +1793,19 @@ void TServer::sendPacketToLevel(PlayerPredicate predicate, char packetId, CStrin } if (abs(ogmap[0] - sgmap[0]) < 2 && abs(ogmap[1] - sgmap[1]) < 2) - player->sendPacket(packetId, pPacket); + player->sendPacket(pPacket); } } } -void TServer::sendPacketTo(char packetId, int who, CString pPacket, TPlayer* pPlayer) const +void TServer::sendPacketTo(int who, PlayerOutPacket pPacket, TPlayer* pPlayer) const { for (auto player : playerList) { if (player != pPlayer) { if (player->getType() & who) - player->sendPacket(packetId, pPacket); + player->sendPacket(pPacket); } } } @@ -1846,7 +1845,7 @@ bool TServer::NC_DelWeapon(const CString& pWeaponName) delete weaponObj; // Delete from Players - sendPacketTo(PLO_NPCWEAPONDEL, PLTYPE_ANYCLIENT, CString() << pWeaponName); + sendPacketTo(PLTYPE_ANYCLIENT, {PLO_NPCWEAPONDEL, CString() << pWeaponName}); return true; } @@ -1860,7 +1859,7 @@ void TServer::updateWeaponForPlayers(TWeapon *pWeapon) if (player->hasWeapon(pWeapon->getName())) { - player->sendPacket(PLO_NPCWEAPONDEL, CString() << pWeapon->getName()); + player->sendPacket({PLO_NPCWEAPONDEL, CString() << pWeapon->getName()}); for (const auto& packet : pWeapon->getWeaponPackets(player->getVersion())) { player->sendPacket(packet, true); } @@ -1883,9 +1882,9 @@ void TServer::updateClassForPlayers(TScriptClass *pClass) CString b = pClass->getByteCode(); if (!player->newProtocol) - player->sendPacket(PLO_RAWDATA, CString() >> (int)b.length()); + player->sendPacket({PLO_RAWDATA, CString() >> (int)b.length()}); - player->sendPacket(PLO_NPCWEAPONSCRIPT, b); + player->sendPacket({PLO_NPCWEAPONSCRIPT, b}); } } } @@ -2044,7 +2043,7 @@ CString TServer::TS_Translate(const CString& pLanguage, const CString& pKey) void TServer::TS_Reload() { // Save Translations - this->TS_Save(); + TS_Save(); // Reset Translations mTranslationManager.reset(); @@ -2056,7 +2055,7 @@ void TServer::TS_Reload() // Load Each File const std::map &temp = translationFS.getFileList(); for (auto & i : temp) - this->TS_Load(removeExtension(i.first), i.second); + TS_Load(removeExtension(i.first), i.second); } void TServer::TS_Save() diff --git a/server/src/TServerList.cpp b/server/src/TServerList.cpp index 5a0750a3..94f93a32 100644 --- a/server/src/TServerList.cpp +++ b/server/src/TServerList.cpp @@ -359,7 +359,7 @@ void TServerList::handleText(const CString& data) if (pl->inChatChannel(channel)) { CString weapon = pl->isClient() ? "-Serverlist_Chat" : "GraalEngine"; - pl->sendPacket(PLO_SERVERTEXT, CString() << weapon << tmpData); + pl->sendPacket({PLO_SERVERTEXT, CString() << weapon << tmpData}); } } } @@ -498,10 +498,10 @@ void TServerList::msgSVI_VERIGUILD(CString& pPacket) // Assign the nickname to the player. p->setNick(nickname, true); - p->sendPacket(PLO_PLAYERPROPS, CString() << prop); + p->sendPacket({PLO_PLAYERPROPS, CString() << prop}); // Tell everybody else the new nickname. - _server->sendPacketToAll(PLO_OTHERPLPROPS, CString() >> (short)playerID << prop, p); + _server->sendPacketToAll({PLO_OTHERPLPROPS, CString() >> (short)playerID << prop}, p); } } @@ -670,7 +670,7 @@ void TServerList::msgSVI_PROFILE(CString& pPacket) } // Send the profiles. - p1->sendPacket(PLO_PROFILE, CString() << profile); + p1->sendPacket({PLO_PROFILE, CString() << profile}); } void TServerList::msgSVI_ERRMSG(CString& pPacket) @@ -687,7 +687,7 @@ void TServerList::msgSVI_VERIACC2(CString& pPacket) // Get the player. TPlayer* player = _server->getPlayer(id, PLTYPE_ANYPLAYER | PLTYPE_ANYNC); - if (player == 0) return; + if (player == nullptr) return; // Overwrite the player's account name with the one from the listserver. player->setAccountName(account); @@ -695,14 +695,14 @@ void TServerList::msgSVI_VERIACC2(CString& pPacket) // If we did not get the success message, inform the client of his failure. if (message != "SUCCESS") { - player->sendPacket(PLO_DISCMESSAGE, CString() << message); + player->sendPacket({PLO_DISCMESSAGE, CString() << message}); player->setId(0); // Prevent saving of the account. player->disconnect(); return; } // Send the player his account. If it fails, disconnect him. - if (player->sendLogin() == false) + if ( !player->sendLogin()) { //player->sendPacket(CString() >> (char)PLO_DISCMESSAGE << "Failed to send login information."); player->setId(0); // Prevent saving of the account. @@ -865,7 +865,7 @@ void TServerList::msgSVI_SERVERINFO(CString& pPacket) // A hack to allow v5 clients to serverwarp to servers TPlayer *player = _server->getPlayer(pid, PLTYPE_ANYCLIENT); if (player && player->getVersion() >= CLVER_2_1) - player->sendPacket(PLO_SERVERWARP, CString() << serverpacket); + player->sendPacket({PLO_SERVERWARP, CString() << serverpacket}); } void TServerList::msgSVI_REQUESTTEXT(CString& pPacket) @@ -897,13 +897,13 @@ void TServerList::msgSVI_REQUESTTEXT(CString& pPacket) { CString channel = params[3].guntokenize(); if (player->addChatChannel(channel.text())) - player->sendPacket(PLO_SERVERTEXT, CString() << weapon << ",irc,join," << params[3].gtokenize()); + player->sendPacket({PLO_SERVERTEXT, CString() << weapon << ",irc,join," << params[3].gtokenize()}); } else if (params[2] == "part") { CString channel = params[3].guntokenize(); if (player->inChatChannel(channel.text())) - player->sendPacket(PLO_SERVERTEXT, CString() << weapon << ",irc,part," << params[3].gtokenize()); + player->sendPacket({PLO_SERVERTEXT, CString() << weapon << ",irc,part," << params[3].gtokenize()}); } } } @@ -949,7 +949,7 @@ void TServerList::msgSVI_REQUESTTEXT(CString& pPacket) //_server->getServerLog().out("[OUT] [RequestText] %s\n", message.text()); if (player->getVersion() >= CLVER_4_0211 || player->getVersion() > RCVER_1_1) - player->sendPacket(PLO_SERVERTEXT, CString() << message); + player->sendPacket({PLO_SERVERTEXT, CString() << message}); } } } @@ -985,7 +985,7 @@ void TServerList::msgSVI_PMPLAYER(CString& pPacket) p->addPMServer(servername); p->updatePMPlayers(servername, player); TPlayer* tmpPlyr = p->getExternalPlayer(account); - p->sendPacket(PLO_PRIVATEMESSAGE, CString() >> (short)tmpPlyr->getId() << pmMessageType << message3,true); + p->sendPacket({PLO_PRIVATEMESSAGE, CString() >> (short)tmpPlyr->getId() << pmMessageType << message3},true); } message2 = ""; diff --git a/server/src/TriggerCommandHandlers.cpp b/server/src/TriggerCommandHandlers.cpp index c6119d87..2a41ff8f 100644 --- a/server/src/TriggerCommandHandlers.cpp +++ b/server/src/TriggerCommandHandlers.cpp @@ -44,7 +44,7 @@ void TServer::createTriggerCommands(TriggerDispatcher::Builder builder) for (auto & serverData : serverList) actionData << CString(serverData.first).gtokenize() << "," << CString(serverData.second) << ","; - player->sendPacket(PLO_TRIGGERACTION, CString() >> (short)0 >> (int)0 >> (char)0 >> (char)0 << actionData); + player->sendPacket({PLO_TRIGGERACTION, CString() >> (short)0 >> (int)0 >> (char)0 >> (char)0 << actionData}); return true; }); @@ -151,15 +151,14 @@ void TServer::createTriggerCommands(TriggerDispatcher::Builder builder) remove(path.text()); // Remove the guild from all players. - for (std::vector::iterator i = getPlayerList()->begin(); i != getPlayerList()->end(); ++i) + for (auto p : *getPlayerList()) { - TPlayer* p = *i; - if (p->getGuild() == guild) + if (p->getGuild() == guild) { CString nick = p->getNickname(); p->setNick(nick.readString("(").trimI()); - p->sendPacket(PLO_PLAYERPROPS, CString() >> (char)PLPROP_NICKNAME << p->getProp(PLPROP_NICKNAME)); - sendPacketToAll(PLO_OTHERPLPROPS, CString() >> (short)p->getId() >> (char)PLPROP_NICKNAME << p->getProp(PLPROP_NICKNAME), p); + p->sendPacket(PlayerOutPacket{PLO_PLAYERPROPS, CString() >> (char)PLPROP_NICKNAME << p->getProp(PLPROP_NICKNAME)}); + sendPacketToAll({PLO_OTHERPLPROPS, CString() >> (short)p->getId() >> (char)PLPROP_NICKNAME << p->getProp(PLPROP_NICKNAME)}, p); } } } @@ -184,8 +183,8 @@ void TServer::createTriggerCommands(TriggerDispatcher::Builder builder) { CString nick = p->getNickname(); p->setNick(CString() << nick.readString("(").trimI() << " (" << guild << ")", true); - p->sendPacket(PLO_PLAYERPROPS, CString() >> (char)PLPROP_NICKNAME >> (char)p->getNickname().length() << p->getNickname()); - sendPacketToAll(PLO_OTHERPLPROPS, CString() >> (short)p->getId() >> (char)PLPROP_NICKNAME >> (char)p->getNickname().length() << p->getNickname(), p); + p->sendPacket({PLO_PLAYERPROPS, CString() >> (char)PLPROP_NICKNAME >> (char)p->getNickname().length() << p->getNickname()}); + sendPacketToAll({PLO_OTHERPLPROPS, CString() >> (short)p->getId() >> (char)PLPROP_NICKNAME >> (char)p->getNickname().length() << p->getNickname()}, p); } } } @@ -209,10 +208,9 @@ void TServer::createTriggerCommands(TriggerDispatcher::Builder builder) if (getSettings()->getBool("triggerhack_groups", true) && triggerData.size() == 2) { auto playerList = player->getLevel()->getPlayerList(); - for (std::vector::iterator i = playerList->begin(); i != playerList->end(); ++i) + for (auto pl : *playerList) { - TPlayer* pl = *i; - pl->setGroup(triggerData[1]); + pl->setGroup(triggerData[1]); } } @@ -252,7 +250,7 @@ void TServer::createTriggerCommands(TriggerDispatcher::Builder builder) unsigned int id = strtoint(triggerData[1]); int dx = strtoint(triggerData[2]); int dy = strtoint(triggerData[3]); - float duration = (float)strtofloat(triggerData[4]); + auto duration = (float)strtofloat(triggerData[4]); int options = strtoint(triggerData[5]); TNPC* npc = getNPC(id); @@ -263,7 +261,7 @@ void TServer::createTriggerCommands(TriggerDispatcher::Builder builder) packet >> (char)((dx * 2) + 100) >> (char)((dy * 2) + 100); packet >> (short)(duration / 0.05f); packet >> (char)options; - sendPacketToLevel(PLO_MOVE, CString() >> (int)id << packet, 0, player, true); + sendPacketToLevel({PLO_MOVE, CString() >> (int)id << packet}, nullptr, player, true); npc->setX(npc->getX() + dx * 16); npc->setY(npc->getY() + dy * 16); @@ -279,8 +277,8 @@ void TServer::createTriggerCommands(TriggerDispatcher::Builder builder) if (getSettings()->getBool("triggerhack_levels", false) && triggerData.size() == 4) { unsigned int id = strtoint(triggerData[1]); - float x = (float)strtofloat(triggerData[2]); - float y = (float)strtofloat(triggerData[3]); + auto x = (float)strtofloat(triggerData[2]); + auto y = (float)strtofloat(triggerData[3]); TNPC* npc = getNPC(id); if (npc) @@ -292,7 +290,7 @@ void TServer::createTriggerCommands(TriggerDispatcher::Builder builder) CString packet; packet >> (char)NPCPROP_X >> (char)(x * 2.0f); packet >> (char)NPCPROP_Y >> (char)(y * 2.0f); - sendPacketToLevel(PLO_NPCPROPS, CString() >> (int)id << packet, 0, player, true); + sendPacketToLevel({PLO_NPCPROPS, CString() >> (int)id << packet}, nullptr, player, true); } }