diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-01-28 00:31:48 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-01-28 03:08:31 +0300 |
commit | 40f34b7ba7317f5f5c3dfbed0b291be9555d3137 (patch) | |
tree | 512bd693c37b8ad710a0f752abe3ac04e3c8ea77 | |
parent | 8333597dfaecfca2cac6b98390a8fb7131cb2a09 (diff) | |
download | ManaVerse-40f34b7ba7317f5f5c3dfbed0b291be9555d3137.tar.gz ManaVerse-40f34b7ba7317f5f5c3dfbed0b291be9555d3137.tar.bz2 ManaVerse-40f34b7ba7317f5f5c3dfbed0b291be9555d3137.tar.xz ManaVerse-40f34b7ba7317f5f5c3dfbed0b291be9555d3137.zip |
Add basic support for extended online list on evol server.
-rw-r--r-- | src/gui/socialwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/whoisonline.cpp | 135 | ||||
-rw-r--r-- | src/gui/whoisonline.h | 76 | ||||
-rw-r--r-- | src/net/tmwa/playerhandler.cpp | 22 |
4 files changed, 174 insertions, 61 deletions
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index a1a6c1cee..59ace1685 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1143,7 +1143,7 @@ public: std::vector<std::string> *players = player_relations.getPlayersByRelation(PlayerRelation::FRIEND); - std::set<std::string> players2 = whoIsOnline->getOnlinePlayers(); + const std::set<std::string> &players2 = whoIsOnline->getOnlineNicks(); if (!players) return; diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index a80fb4c89..34cfc1a57 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -48,6 +48,7 @@ #include "gui/chatwindow.h" +#include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -68,21 +69,10 @@ class NameFunctuator { public: - bool operator()(const std::string &left, - const std::string &right) const + bool operator()(const OnlinePlayer *left, + const OnlinePlayer *right) const { - for (std::string::const_iterator lit = left.begin(), - rit = right.begin(); - lit != left.end() && rit != right.end(); ++lit, ++rit) - { - if (tolower(*lit) < tolower(*rit)) - return true; - else if (tolower(*lit) > tolower(*rit)) - return false; - } - if (left.size() < right.size()) - return true; - return false; + return (compareStrI(left->getNick(), right->getNick()) < 0); } } nameCompare; @@ -149,6 +139,14 @@ WhoIsOnline::~WhoIsOnline() // Remove possibly leftover temporary download delete[] mCurlError; + + std::set<OnlinePlayer*>::iterator itd = mOnlinePlayers.begin(); + std::set<OnlinePlayer*>::iterator itd_end = mOnlinePlayers.end(); + + for (; itd != itd_end; ++ itd) + delete *itd; + mOnlinePlayers.clear(); + mOnlineNicks.clear(); } void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event) @@ -186,10 +184,10 @@ void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event) } } -void WhoIsOnline::updateWindow(std::vector<std::string> &friends, - std::vector<std::string> &neutral, - std::vector<std::string> &disregard, - std::vector<std::string> enemy, +void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends, + std::vector<OnlinePlayer*> &neutral, + std::vector<OnlinePlayer*> &disregard, + std::vector<OnlinePlayer*> enemy, int numOnline) { //Set window caption @@ -202,7 +200,7 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, bool addedFromSection(false); for (int i = 0; i < static_cast<int>(friends.size()); i++) { - mBrowserBox->addRow(friends.at(i)); + mBrowserBox->addRow(friends.at(i)->getText()); addedFromSection = true; } if (addedFromSection == true) @@ -212,7 +210,7 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, } for (int i = 0; i < static_cast<int>(enemy.size()); i++) { - mBrowserBox->addRow(enemy.at(i)); + mBrowserBox->addRow(enemy.at(i)->getText()); addedFromSection = true; } if (addedFromSection == true) @@ -222,7 +220,7 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, } for (int i = 0; i < static_cast<int>(neutral.size()); i++) { - mBrowserBox->addRow(neutral.at(i)); + mBrowserBox->addRow(neutral.at(i)->getText()); addedFromSection = true; } if (addedFromSection == true && !disregard.empty()) @@ -232,7 +230,7 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, } for (int i = 0; i < static_cast<int>(disregard.size()); i++) { - mBrowserBox->addRow(disregard.at(i)); + mBrowserBox->addRow(disregard.at(i)->getText()); } if (mScrollArea->getVerticalMaxScroll() < @@ -243,43 +241,59 @@ void WhoIsOnline::updateWindow(std::vector<std::string> &friends, } } -void WhoIsOnline::loadList(std::vector<std::string> &list) +void WhoIsOnline::loadList(std::vector<OnlinePlayer*> &list) { mBrowserBox->clearRows(); int numOnline = list.size(); - std::vector<std::string> friends; - std::vector<std::string> neutral; - std::vector<std::string> disregard; - std::vector<std::string> enemy; + std::vector<OnlinePlayer*> friends; + std::vector<OnlinePlayer*> neutral; + std::vector<OnlinePlayer*> disregard; + std::vector<OnlinePlayer*> enemy; + + std::set<OnlinePlayer*>::iterator itd = mOnlinePlayers.begin(); + std::set<OnlinePlayer*>::iterator itd_end = mOnlinePlayers.end(); + for (; itd != itd_end; ++ itd) + delete *itd; mOnlinePlayers.clear(); + mOnlineNicks.clear(); + mShowLevel = config.getBoolValue("showlevel"); - std::vector<std::string>::const_iterator it = list.begin(); - std::vector<std::string>::const_iterator it_end = list.end(); + std::vector<OnlinePlayer*>::iterator it = list.begin(); + std::vector<OnlinePlayer*>::iterator it_end = list.end(); for (; it != it_end; ++ it) { - std::string nick = *it; - mOnlinePlayers.insert(nick); + OnlinePlayer *player = *it; + std::string nick = player->getNick(); + mOnlinePlayers.insert(player); + mOnlineNicks.insert(nick); + + if (!mShowLevel) + player->setLevel(0); switch (player_relations.getRelation(nick)) { case PlayerRelation::NEUTRAL: default: - neutral.push_back(prepareNick(nick, 0, "0")); + player->setText("0"); + neutral.push_back(player); break; case PlayerRelation::FRIEND: - friends.push_back(prepareNick(nick, 0, "2")); + player->setText("2"); + neutral.push_back(player); break; case PlayerRelation::DISREGARDED: case PlayerRelation::BLACKLISTED: - disregard.push_back(prepareNick(nick, 0, "8")); + player->setText("8"); + disregard.push_back(player); break; case PlayerRelation::ENEMY2: - enemy.push_back(prepareNick(nick, 0, "1")); + player->setText("1"); + enemy.push_back(player); break; case PlayerRelation::IGNORED: @@ -290,10 +304,10 @@ void WhoIsOnline::loadList(std::vector<std::string> &list) } updateWindow(friends, neutral, disregard, enemy, numOnline); - if (!mOnlinePlayers.empty()) + if (!mOnlineNicks.empty()) { if (chatWindow) - chatWindow->updateOnline(mOnlinePlayers); + chatWindow->updateOnline(mOnlineNicks); if (socialWindow) socialWindow->updateActiveList(); } @@ -313,15 +327,16 @@ void WhoIsOnline::loadWebList() bool listStarted(false); std::string lineStr; int numOnline(0); - std::vector<std::string> friends; - std::vector<std::string> neutral; - std::vector<std::string> disregard; - std::vector<std::string> enemy; + std::vector<OnlinePlayer*> friends; + std::vector<OnlinePlayer*> neutral; + std::vector<OnlinePlayer*> disregard; + std::vector<OnlinePlayer*> enemy; // Tokenize and add each line separately char *line = strtok(mMemoryBuffer, "\n"); const std::string gmText = "(GM)"; mOnlinePlayers.clear(); + mOnlineNicks.clear(); mShowLevel = config.getBoolValue("showlevel"); @@ -383,27 +398,37 @@ void WhoIsOnline::loadWebList() } } - mOnlinePlayers.insert(nick); + + if (!mShowLevel) + level = 0; + + OnlinePlayer *player = new OnlinePlayer(nick, -1, level, -1); + mOnlinePlayers.insert(player); + mOnlineNicks.insert(nick); numOnline++; switch (player_relations.getRelation(nick)) { case PlayerRelation::NEUTRAL: default: - neutral.push_back(prepareNick(nick, level, "0")); + player->setText("0"); + neutral.push_back(player); break; case PlayerRelation::FRIEND: - friends.push_back(prepareNick(nick, level, "2")); + player->setText("2"); + friends.push_back(player); break; case PlayerRelation::DISREGARDED: case PlayerRelation::BLACKLISTED: - disregard.push_back(prepareNick(nick, level, "8")); + player->setText("8"); + disregard.push_back(player); break; case PlayerRelation::ENEMY2: - enemy.push_back(prepareNick(nick, level, "1")); + player->setText("1"); + enemy.push_back(player); break; case PlayerRelation::IGNORED: @@ -596,10 +621,10 @@ void WhoIsOnline::logic() mUpdateButton->setEnabled(true); mUpdateTimer = 0; updateSize(); - if (!mOnlinePlayers.empty()) + if (!mOnlineNicks.empty()) { if (chatWindow) - chatWindow->updateOnline(mOnlinePlayers); + chatWindow->updateOnline(mOnlineNicks); if (socialWindow) socialWindow->updateActiveList(); } @@ -681,3 +706,17 @@ void WhoIsOnline::optionChanged(const std::string &name) if (name == "updateOnlineList") mUpdateOnlineList = config.getBoolValue("updateOnlineList"); } + +void OnlinePlayer::setText(std::string color) +{ + mText = strprintf("@@%s|##%s%s", mNick.c_str(), + color.c_str(), mNick.c_str()); + + if (mLevel > 0) + mText += strprintf(" (%d)", mLevel); + + if (mVersion > 0) + mText += strprintf(" - %d", mVersion); + + mText += strprintf("@@"); +} diff --git a/src/gui/whoisonline.h b/src/gui/whoisonline.h index ade391d5a..ef25257da 100644 --- a/src/gui/whoisonline.h +++ b/src/gui/whoisonline.h @@ -42,6 +42,62 @@ class ScrollArea; struct SDL_Thread; +class OnlinePlayer +{ + public: + OnlinePlayer(std::string nick, int status, int level, int version) : + mNick(nick), + mText(""), + mStatus(status), + mLevel(level), + mVersion(version) + { + } + + const std::string getNick() const + { + return mNick; + } + + int getStaus() const + { + return mStatus; + } + + int getVersion() const + { + return mVersion; + } + + int getLevel() const + { + return mLevel; + } + + const std::string getText() + { + return mText; + } + + void setText(std::string str); + + void setLevel(int level) + { + mLevel = level; + } + + private: + std::string mNick; + + std::string mText; + + int mStatus; + + int mLevel; + + int mVersion; +}; + /** * Update progress window GUI * @@ -52,7 +108,7 @@ class WhoIsOnline : public Window, public gcn::ActionListener, public ConfigListener { - public: +public: /** * Constructor. */ @@ -68,7 +124,7 @@ class WhoIsOnline : public Window, */ void loadWebList(); - void loadList(std::vector<std::string> &list); + void loadList(std::vector<OnlinePlayer*> &list); void handleLink(const std::string& link, gcn::MouseEvent *event); @@ -78,9 +134,12 @@ class WhoIsOnline : public Window, void widgetResized(const gcn::Event &event); - std::set<std::string> &getOnlinePlayers() + const std::set<OnlinePlayer*> &getOnlinePlayers() { return mOnlinePlayers; } + const std::set<std::string> &getOnlineNicks() + { return mOnlineNicks; } + void setAllowUpdate(bool n) { mAllowUpdate = n; } @@ -109,10 +168,10 @@ private: const std::string prepareNick(std::string nick, int level, std::string color) const; - void updateWindow(std::vector<std::string> &friends, - std::vector<std::string> &neutral, - std::vector<std::string> &disregard, - std::vector<std::string> enemy, + void updateWindow(std::vector<OnlinePlayer*> &friends, + std::vector<OnlinePlayer*> &neutral, + std::vector<OnlinePlayer*> &disregard, + std::vector<OnlinePlayer*> enemy, int numOnline); enum DownloadStatus @@ -143,7 +202,8 @@ private: BrowserBox *mBrowserBox; ScrollArea *mScrollArea; time_t mUpdateTimer; - std::set<std::string> mOnlinePlayers; + std::set<OnlinePlayer*> mOnlinePlayers; + std::set<std::string> mOnlineNicks; gcn::Button *mUpdateButton; bool mAllowUpdate; diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index d5f0641eb..3d48fb341 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -218,7 +218,7 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) return; int size = msg.readInt16() - 4; - std::vector<std::string> arr; + std::vector<OnlinePlayer*> arr; if (!size) { @@ -230,11 +230,25 @@ void PlayerHandler::processOnlineList(Net::MessageIn &msg) const char *start = msg.readBytes(size); const char *buf = start; - while (buf - start + 1 < size && *(buf + 1)) + int addVal = 1; + if (serverVersion >= 4) + addVal = 3; + + while (buf - start + 1 < size && *(buf + addVal)) { -// char status = *buf; // now unused + char status = 0; + char ver = 0; + char level = 0; + if (serverVersion >= 4) + { + status = *buf; + buf ++; + level = *buf; + buf ++; + ver = *buf; + } buf ++; - arr.push_back(buf); + arr.push_back(new OnlinePlayer(buf, status, level, ver)); buf += strlen(buf) + 1; } |