35 #include "gui/viewport.h"
69 #include <curl/curl.h>
101 Window(
_(
"Who Is Online - Updating"),
108 mCurlError(
new char[CURL_ERROR_SIZE]),
110 "onlinebrowserbox.xml")),
123 mDownloadComplete(true),
126 mUpdateOnlineList(
config.getBoolValue(
"updateOnlineList")),
211 std::string(
"/w \"").append(text).append(
"\" "),
252 bool addedFromSection(
false);
256 addedFromSection =
true;
258 if (addedFromSection ==
true)
261 addedFromSection =
false;
266 addedFromSection =
true;
268 if (addedFromSection ==
true)
271 addedFromSection =
false;
276 addedFromSection =
true;
278 if (addedFromSection ==
true && !
mDisregard.empty())
296 if (player ==
nullptr)
335 const size_t numOnline = list.size();
344 FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, list)
347 const std::string nick = player->
getNick();
389 bool listStarted(
false);
391 size_t numOnline(0U);
395 const std::string gmText(
"(GM)");
396 const std::string gmText2(
"(gm)");
406 while (line !=
nullptr)
411 if (listStarted ==
true)
413 if (lineStr.find(
" users are online.") == std::string::npos)
415 if (lineStr.length() > 24)
417 nick = lineStr.substr(0, 24);
418 lineStr = lineStr.substr(25);
428 size_t pos = lineStr.find(gmText, 0);
429 if (pos != std::string::npos)
431 lineStr = lineStr.substr(pos + gmText.length());
436 pos = lineStr.find(gmText2, 0);
437 if (pos != std::string::npos)
439 lineStr = lineStr.substr(pos + gmText.length());
445 pos = lineStr.find(
'/', 0);
447 if (pos != std::string::npos)
448 lineStr = lineStr.substr(0, pos);
451 if (!lineStr.empty())
452 level = atoi(lineStr.c_str());
458 if (being !=
nullptr)
489 else if (lineStr.find(
"------------------------------")
490 != std::string::npos)
494 line = strtok(
nullptr,
"\n");
514 if (stream ==
nullptr)
519 const size_t totalMem =
size * nmemb;
520 wio->mMemoryBuffer =
static_cast<char*
>(realloc(wio->mMemoryBuffer,
521 CAST_SIZE(wio->mDownloadedBytes) + totalMem));
522 if (wio->mMemoryBuffer !=
nullptr)
524 memcpy(&(wio->mMemoryBuffer[wio->mDownloadedBytes]), ptr, totalMem);
525 wio->mDownloadedBytes +=
CAST_S32(totalMem);
542 CURL *curl = curl_easy_init();
547 curl_easy_cleanup(curl);
552 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
553 curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
554 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
556 curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr);
558 curl_easy_setopt(curl,
562 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, wio->
mCurlError);
563 curl_easy_setopt(curl, CURLOPT_URL,
url.c_str());
564 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
565 curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, ptr);
567 #if LIBCURL_VERSION_NUM >= 0x070a00
568 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
570 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 7);
571 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
579 curl_slist *pHeaders =
nullptr;
580 pHeaders = curl_slist_append(
581 pHeaders,
"pragma: no-cache");
582 pHeaders = curl_slist_append(pHeaders,
583 "Cache-Control: no-cache");
584 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaders);
586 if ((res = curl_easy_perform(curl)) != 0)
590 PRAGMA45(GCC diagnostic ignored
"-Wswitch-enum")
593 case CURLE_COULDNT_CONNECT:
595 std::cerr <<
"curl error "
598 <<
url.c_str() << std::endl;
603 curl_easy_cleanup(curl);
604 curl_slist_free_all(pHeaders);
609 curl_easy_cleanup(curl);
610 curl_slist_free_all(pHeaders);
641 "whoisonline",
this);
725 if (event.
getId() ==
"update")
778 return strprintf(
"@@%s|##%s%s (%d)@@", text.c_str(),
779 color.c_str(), text.c_str(), level);
781 return strprintf(
"@@%s|##%s%s@@", text.c_str(),
782 color.c_str(), text.c_str());
787 if (name ==
"updateOnlineList")
789 else if (name ==
"groupFriends")
795 if (player ==
nullptr)
800 const std::string &nick = player->
getNick();
809 if (
party !=
nullptr)
811 if (
party->getMember(nick) !=
nullptr)
821 if (being !=
nullptr)
824 if (guild2 !=
nullptr)
827 if (guild1 !=
nullptr)
844 if ((guild3 !=
nullptr) && guild3->
isMember(nick))
857 names.push_back(*it);
868 if (being !=
nullptr)
887 mText.append(
"(GM) ");
894 mText.append(
"\u2640");
896 mText.append(
"\u2642");
921 else if (
mIsGM && color ==
"0")
930 mText =
strprintf(
"@@%s|##%s%s %s@@", text.c_str(), color.c_str(),
931 text.c_str(),
mText.c_str());
ActorManager * actorManager
const std::string & getId() const
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
void updateSeenPlayers(const std::set< std::string > &onlinePlayers)
virtual void add(Widget *const widget)
const Guild * getGuild(const std::string &guildName) const
virtual int getLevel() const
void setLevel(const int n)
const std::string & getName() const
void setState(const uint8_t state)
void setAdvanced(const bool n)
void updateOnline(const std::set< std::string > &onlinePlayers) const
void localChatInput(const std::string &msg) const
void addInputText(const std::string &text, const bool space)
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
void removeListeners(ConfigListener *const listener)
bool isMember(const GuildMember *const member) const
static Guild * getGuild(const int16_t id)
GuildMember * getMember(const BeingId id) const
void assertLog(const char *const log_text,...)
MouseButtonT getButton() const
static void addCommonFlags(CURL *const curl)
static void secureCurl(CURL *const curl)
static void addProxy(CURL *const curl)
static void addHeaders(CURL *const curl)
virtual void requestOnlineList() const =0
const std::string getNick() const
void setIsGM(const bool b)
void setText(std::string str)
void setLevel(const char level)
RelationT getRelation(const std::string &name) const
std::string onlineListUrl
void registerWindowForReset(Window *const window)
void addRow(const std::string &row, const bool atTop)
void setOpaque(Opaque opaque)
void setLinkHandler(LinkHandler *linkHandler)
void getPlayerNames(StringVect &names)
std::set< std::string > mOnlineNicks
static size_t memoryWrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
const std::string prepareNick(const std::string &nick, const int level, const std::string &color) const
void loadList(const std::vector< OnlinePlayer * > &list)
std::set< OnlinePlayer * > mOnlinePlayers
std::vector< OnlinePlayer * > mNeutral
void handlerPlayerRelation(const std::string &nick, OnlinePlayer *const player)
static int downloadThread(void *ptr)
StaticBrowserBox * mBrowserBox
static void setNeutralColor(OnlinePlayer *const player)
std::vector< OnlinePlayer * > mFriends
void widgetResized(const Event &event)
std::vector< OnlinePlayer * > mEnemy
void optionChanged(const std::string &name)
void action(const ActionEvent &event)
WhoIsOnline::DownloadStatus mDownloadStatus
void handleLink(const std::string &link, MouseEvent *event)
void updateWindow(size_t numOnline)
std::vector< OnlinePlayer * > mDisregard
void setSaveVisible(const bool save)
void setResizable(const bool resize)
virtual void setVisible(Visible visible)
bool isWindowVisible() const
void setWindowName(const std::string &name)
void setCaption(const std::string &caption)
void enableVisibleSound(bool b)
void widgetResized(const Event &event)
void setCloseButton(const bool flag)
void setStickyButtonLock(const bool sticky)
void setLocationRelativeTo(const Widget *const widget)
#define FOR_EACH(type, iter, array)
const Image *restrict const left
const Image *restrict const right
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wredundant-decls") PRAGMA45(GCC diagnostic pop) class TestMain
#define A_DEFAULT_COPY(func)
LocalPlayer * localPlayer
bool url(InputEvent &event)
std::string trim(std::string const &str)
std::string toString(T const &value)
converts any type to a string
bool getShowBadge(const int id)
bool getHighlightName(const int id)
const std::string & getName(const int id)
ServerTypeT getNetworkType()
bool limitPackets(const PacketTypeT type)
SDL_Thread * createThread(int(*fn)(void *), const char *const name, void *const data)
void WaitThread(SDL_Thread *const thread)
class anonymous_namespace{whoisonline.cpp}::NameFunctuator nameCompare
Net::ServerFeatures * serverFeatures
Net::PlayerHandler * playerHandler
#define BLOCK_START(name)
PlayerRelationsManager playerRelations
SetupWindow * setupWindow
SocialWindow * socialWindow
std::string strprintf(const char *const format,...)
int compareStrI(const std::string &a, const std::string &b)
std::string decodeLinkText(std::string data)
std::string encodeLinkText(std::string data)
std::vector< std::string > StringVect
WhoIsOnline * whoIsOnline