summaryrefslogtreecommitdiff
path: root/src/gui/whoisonline.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-11-30 18:13:03 +0300
committerAndrei Karas <akaras@inbox.ru>2011-11-30 20:09:16 +0300
commit7c6621108b54fd66fbb7aa87be067a34abcc3ced (patch)
tree5859964db8917a35ebb244a0114d5d3cf6578ae0 /src/gui/whoisonline.cpp
parent8871ef8ba38a11213de3cc7f35f5f9f0f3000dc0 (diff)
downloadManaVerse-7c6621108b54fd66fbb7aa87be067a34abcc3ced.tar.gz
ManaVerse-7c6621108b54fd66fbb7aa87be067a34abcc3ced.tar.bz2
ManaVerse-7c6621108b54fd66fbb7aa87be067a34abcc3ced.tar.xz
ManaVerse-7c6621108b54fd66fbb7aa87be067a34abcc3ced.zip
Add server side online players list support.
Diffstat (limited to 'src/gui/whoisonline.cpp')
-rw-r--r--src/gui/whoisonline.cpp211
1 files changed, 144 insertions, 67 deletions
diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp
index e0fa4ebcf..fde0f08da 100644
--- a/src/gui/whoisonline.cpp
+++ b/src/gui/whoisonline.cpp
@@ -41,6 +41,9 @@
#include "playerrelations.h"
#include "main.h"
+#include "net/net.h"
+#include "net/playerhandler.h"
+
#include "gui/chatwindow.h"
#include "utils/gettext.h"
@@ -181,7 +184,113 @@ void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event)
}
}
-void WhoIsOnline::loadList()
+void WhoIsOnline::updateWindow(std::vector<std::string> &friends,
+ std::vector<std::string> &neutral,
+ std::vector<std::string> &disregard,
+ std::vector<std::string> enemy,
+ int numOnline)
+{
+ //Set window caption
+ setCaption(_("Who Is Online - ") + toString(numOnline));
+
+ //List the online people
+ sort(friends.begin(), friends.end(), nameCompare);
+ sort(neutral.begin(), neutral.end(), nameCompare);
+ sort(disregard.begin(), disregard.end(), nameCompare);
+ bool addedFromSection(false);
+ for (int i = 0; i < static_cast<int>(friends.size()); i++)
+ {
+ mBrowserBox->addRow(friends.at(i));
+ addedFromSection = true;
+ }
+ if (addedFromSection == true)
+ {
+ mBrowserBox->addRow("---");
+ addedFromSection = false;
+ }
+ for (int i = 0; i < static_cast<int>(enemy.size()); i++)
+ {
+ mBrowserBox->addRow(enemy.at(i));
+ addedFromSection = true;
+ }
+ if (addedFromSection == true)
+ {
+ mBrowserBox->addRow("---");
+ addedFromSection = false;
+ }
+ for (int i = 0; i < static_cast<int>(neutral.size()); i++)
+ {
+ mBrowserBox->addRow(neutral.at(i));
+ addedFromSection = true;
+ }
+ if (addedFromSection == true && !disregard.empty())
+ {
+ mBrowserBox->addRow("---");
+ addedFromSection = false;
+ }
+ for (int i = 0; i < static_cast<int>(disregard.size()); i++)
+ {
+ mBrowserBox->addRow(disregard.at(i));
+ }
+
+ if (mScrollArea->getVerticalMaxScroll() <
+ mScrollArea->getVerticalScrollAmount())
+ {
+ mScrollArea->setVerticalScrollAmount(
+ mScrollArea->getVerticalMaxScroll());
+ }
+}
+
+void WhoIsOnline::loadList(std::vector<std::string> &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;
+
+ mOnlinePlayers.clear();
+ mShowLevel = config.getBoolValue("showlevel");
+
+ std::vector<std::string>::const_iterator it = list.begin();
+ std::vector<std::string>::const_iterator it_end = list.end();
+ for (; it != it_end; ++ it)
+ {
+ std::string nick = *it;
+ mOnlinePlayers.insert(nick);
+
+ switch (player_relations.getRelation(nick))
+ {
+ case PlayerRelation::NEUTRAL:
+ default:
+ neutral.push_back(prepareNick(nick, 0, "0"));
+ break;
+
+ case PlayerRelation::FRIEND:
+ friends.push_back(prepareNick(nick, 0, "2"));
+ break;
+
+ case PlayerRelation::DISREGARDED:
+ case PlayerRelation::BLACKLISTED:
+ disregard.push_back(prepareNick(nick, 0, "8"));
+ break;
+
+ case PlayerRelation::ENEMY2:
+ enemy.push_back(prepareNick(nick, 0, "1"));
+ break;
+
+ case PlayerRelation::IGNORED:
+ case PlayerRelation::ERASED:
+ //Ignore the ignored.
+ break;
+ }
+ }
+
+ updateWindow(friends, neutral, disregard, enemy, numOnline);
+}
+
+void WhoIsOnline::loadWebList()
{
if (!mMemoryBuffer)
return;
@@ -303,59 +412,11 @@ void WhoIsOnline::loadList()
line = strtok(nullptr, "\n");
}
- //Set window caption
- setCaption(_("Who Is Online - ") + toString(numOnline));
-
- //List the online people
- sort(friends.begin(), friends.end(), nameCompare);
- sort(neutral.begin(), neutral.end(), nameCompare);
- sort(disregard.begin(), disregard.end(), nameCompare);
- bool addedFromSection(false);
- for (int i = 0; i < static_cast<int>(friends.size()); i++)
- {
- mBrowserBox->addRow(friends.at(i));
- addedFromSection = true;
- }
- if (addedFromSection == true)
- {
- mBrowserBox->addRow("---");
- addedFromSection = false;
- }
- for (int i = 0; i < static_cast<int>(enemy.size()); i++)
- {
- mBrowserBox->addRow(enemy.at(i));
- addedFromSection = true;
- }
- if (addedFromSection == true)
- {
- mBrowserBox->addRow("---");
- addedFromSection = false;
- }
- for (int i = 0; i < static_cast<int>(neutral.size()); i++)
- {
- mBrowserBox->addRow(neutral.at(i));
- addedFromSection = true;
- }
- if (addedFromSection == true && !disregard.empty())
- {
- mBrowserBox->addRow("---");
- addedFromSection = false;
- }
- for (int i = 0; i < static_cast<int>(disregard.size()); i++)
- {
- mBrowserBox->addRow(disregard.at(i));
- }
+ updateWindow(friends, neutral, disregard, enemy, numOnline);
// Free the memory buffer now that we don't need it anymore
free(mMemoryBuffer);
mMemoryBuffer = nullptr;
-
- if (mScrollArea->getVerticalMaxScroll() <
- mScrollArea->getVerticalScrollAmount())
- {
- mScrollArea->setVerticalScrollAmount(
- mScrollArea->getVerticalMaxScroll());
- }
}
size_t WhoIsOnline::memoryWrite(void *ptr, size_t size,
@@ -461,15 +522,22 @@ int WhoIsOnline::downloadThread(void *ptr)
void WhoIsOnline::download()
{
- mDownloadComplete = true;
- if (mThread && SDL_GetThreadID(mThread))
- SDL_WaitThread(mThread, nullptr);
+ if (serverVersion < 3)
+ {
+ mDownloadComplete = true;
+ if (mThread && SDL_GetThreadID(mThread))
+ SDL_WaitThread(mThread, nullptr);
- mDownloadComplete = false;
- mThread = SDL_CreateThread(WhoIsOnline::downloadThread, this);
+ mDownloadComplete = false;
+ mThread = SDL_CreateThread(WhoIsOnline::downloadThread, this);
- if (mThread == nullptr)
- mDownloadStatus = UPDATE_ERROR;
+ if (mThread == nullptr)
+ mDownloadStatus = UPDATE_ERROR;
+ }
+ else
+ {
+ Net::getPlayerHandler()->requestOnlineList();
+ }
}
void WhoIsOnline::logic()
@@ -513,7 +581,7 @@ void WhoIsOnline::logic()
case UPDATE_LIST:
if (mDownloadComplete == true)
{
- loadList();
+ loadWebList();
mDownloadStatus = UPDATE_COMPLETE;
mUpdateButton->setEnabled(true);
mUpdateTimer = 0;
@@ -532,18 +600,27 @@ void WhoIsOnline::action(const gcn::ActionEvent &event)
{
if (event.getId() == "update")
{
- if (mDownloadStatus == UPDATE_COMPLETE)
+ if (serverVersion < 3)
{
- mUpdateTimer = cur_time - 20;
- if (mUpdateButton)
- mUpdateButton->setEnabled(false);
- setCaption(_("Who Is Online - Update"));
- if (mThread && SDL_GetThreadID(mThread))
+ if (mDownloadStatus == UPDATE_COMPLETE)
{
- SDL_WaitThread(mThread, nullptr);
- mThread = nullptr;
+ mUpdateTimer = cur_time - 20;
+ if (mUpdateButton)
+ mUpdateButton->setEnabled(false);
+ setCaption(_("Who Is Online - Update"));
+ if (mThread && SDL_GetThreadID(mThread))
+ {
+ SDL_WaitThread(mThread, nullptr);
+ mThread = nullptr;
+ }
+ mDownloadComplete = true;
}
- mDownloadComplete = true;
+ }
+ else
+ {
+ mUpdateTimer = cur_time - 20;
+ Net::getPlayerHandler()->requestOnlineList();
+ setCaption(_("Who Is Online - Update"));
}
}
}