ManaPlus
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
WhoIsOnline Class Reference

#include <whoisonline.h>

Inheritance diagram for WhoIsOnline:
Window LinkHandler ActionListener ConfigListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 WhoIsOnline ()
 
 ~WhoIsOnline ()
 
void postInit ()
 
void loadWebList ()
 
void loadList (const std::vector< OnlinePlayer *> &list)
 
void handleLink (const std::string &link, MouseEvent *event)
 
void logic ()
 
void slowLogic ()
 
void action (const ActionEvent &event)
 
void widgetResized (const Event &event)
 
const std::set< OnlinePlayer * > & getOnlinePlayers () const
 
const std::set< std::string > & getOnlineNicks () const
 
void setAllowUpdate (const bool n)
 
void optionChanged (const std::string &name)
 
void updateList (StringVect &list)
 
void readFromWeb ()
 
void getPlayerNames (StringVect &names)
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~Window ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void setLocationHorisontallyRelativeTo (const Widget *const widget)
 
void setLocationRelativeTo (const ImagePosition::Type &position, int offsetX, int offsetY)
 
void setResizable (const bool resize)
 
void redraw ()
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void setCloseButton (const bool flag)
 
bool getCloseButton () const
 
void setAllowClose (const bool b)
 
bool getAlowClose () const
 
bool isResizable () const
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
void setShowTitle (bool flag)
 
void setStickyButton (const bool flag)
 
void setSticky (const bool sticky)
 
bool isSticky () const
 
void setStickyButtonLock (const bool sticky)
 
bool isStickyButtonLock () const
 
virtual void setVisible (Visible visible)
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void updateResizeHandler (MouseEvent &event)
 
void setWindowName (const std::string &name)
 
const std::string & getWindowName () const
 
void loadWindowState ()
 
void saveWindowState ()
 
void setDefaultSize (const int defaultX, const int defaultY, int defaultWidth, int defaultHeight)
 
void setDefaultSize ()
 
void setDefaultSize (const int defaultWidth, const int defaultHeight, const ImagePosition::Type &position, const int offsetx, const int offsetY)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
virtual void close ()
 
void setModal (const Modal modal)
 
Rect getWindowArea () const
 
bool isResizeAllowed (const MouseEvent &event) const
 
void setCaptionFont (Font *font)
 
void enableVisibleSound (bool b)
 
bool isWindowVisible () const
 
void setPadding (int padding)
 
int getPadding () const
 
void setTitleBarHeight (unsigned int height)
 
unsigned int getTitleBarHeight () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void setAlignment (Graphics::Alignment alignment)
 
Graphics::Alignment getAlignment () const
 
void setMovable (Move movable)
 
bool isMovable () const
 
Rect getChildrenArea ()
 
virtual void resizeToContent ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- Public Member Functions inherited from LinkHandler
 LinkHandler ()
 
virtual ~LinkHandler ()
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 

Static Public Member Functions

static void setNeutralColor (OnlinePlayer *const player)
 
- Static Public Member Functions inherited from Window
static void setWindowContainer (WindowContainer *const windowContainer)
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 

Private Types

enum  DownloadStatus { UPDATE_ERROR = 0, UPDATE_COMPLETE, UPDATE_LIST }
 

Private Member Functions

void download ()
 
void updateSize ()
 
void handlerPlayerRelation (const std::string &nick, OnlinePlayer *const player)
 
const std::string prepareNick (const std::string &nick, const int level, const std::string &color) const
 
void updateWindow (size_t numOnline)
 

Static Private Member Functions

static int downloadThread (void *ptr)
 
static size_t memoryWrite (void *ptr, size_t size, size_t nmemb, FILE *stream)
 

Private Attributes

time_t mUpdateTimer
 
SDL_Thread * mThread
 
char * mMemoryBuffer
 
char * mCurlError
 
StaticBrowserBoxmBrowserBox
 
ScrollAreamScrollArea
 
ButtonmUpdateButton
 
std::set< OnlinePlayer * > mOnlinePlayers
 
std::set< std::string > mOnlineNicks
 
std::vector< OnlinePlayer * > mFriends
 
std::vector< OnlinePlayer * > mNeutral
 
std::vector< OnlinePlayer * > mDisregard
 
std::vector< OnlinePlayer * > mEnemy
 
int mDownloadedBytes
 
WhoIsOnline::DownloadStatus mDownloadStatus
 
bool mDownloadComplete
 
bool mAllowUpdate
 
bool mShowLevel
 
bool mUpdateOnlineList
 
bool mGroupFriends
 
bool mWebList
 
bool mServerSideList
 

Additional Inherited Members

- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Window
bool canMove () const
 
int getOption (const std::string &name, const int def) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Attributes inherited from Window
std::string mCaption
 
Graphics::Alignment mAlignment
 
int mPadding
 
unsigned int mTitleBarHeight
 
Move mMovable
 
int mDragOffsetX
 
int mDragOffsetY
 
bool mMoved
 
SkinmSkin
 
int mDefaultX
 
int mDefaultY
 
int mDefaultWidth
 
int mDefaultHeight
 
int mCaptionOffsetX
 
int mCaptionOffsetY
 
bool mShowTitle
 
bool mLastRedraw
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Update progress window GUI

Definition at line 41 of file whoisonline.h.

Member Enumeration Documentation

◆ DownloadStatus

Enumerator
UPDATE_ERROR 
UPDATE_COMPLETE 
UPDATE_LIST 

Definition at line 132 of file whoisonline.h.

Constructor & Destructor Documentation

◆ WhoIsOnline()

WhoIsOnline::WhoIsOnline ( )

Constructor.

Definition at line 95 of file whoisonline.cpp.

References mCurlError, and Window::setWindowName().

95  :
96  // TRANSLATORS: who is online window name
97  Window(_("Who Is Online - Updating"),
99  nullptr,
100  "whoisonline.xml"),
101  mUpdateTimer(0),
102  mThread(nullptr),
103  mMemoryBuffer(nullptr),
104  mCurlError(new char[CURL_ERROR_SIZE]),
106  "onlinebrowserbox.xml")),
107  mScrollArea(new ScrollArea(this,
108  mBrowserBox, Opaque_false, std::string())),
109  // TRANSLATORS: who is online. button.
110  mUpdateButton(new Button(this, _("Update"), "update", BUTTON_SKIN, this)),
111  mOnlinePlayers(),
112  mOnlineNicks(),
113  mFriends(),
114  mNeutral(),
115  mDisregard(),
116  mEnemy(),
117  mDownloadedBytes(0),
119  mDownloadComplete(true),
120  mAllowUpdate(true),
121  mShowLevel(false),
122  mUpdateOnlineList(config.getBoolValue("updateOnlineList")),
123  mGroupFriends(true),
124 #ifdef TMWA_SUPPORT
126 #endif
128 {
129  mCurlError[0] = 0;
130  setWindowName("WhoIsOnline");
131 }
#define _(s)
Definition: gettext.h:34
ScrollArea * mScrollArea
Definition: whoisonline.h:151
bool mAllowUpdate
Definition: whoisonline.h:170
int mDownloadedBytes
Definition: whoisonline.h:163
bool mGroupFriends
Definition: whoisonline.h:173
Definition: button.h:96
Configuration config
bool mServerSideList
Definition: whoisonline.h:177
char * mMemoryBuffer
Definition: whoisonline.h:145
StaticBrowserBox * mBrowserBox
Definition: whoisonline.h:150
bool mShowLevel
Definition: whoisonline.h:171
Button * mUpdateButton
Definition: whoisonline.h:152
bool mDownloadComplete
Definition: whoisonline.h:169
Net::ServerFeatures * serverFeatures
Definition: net.cpp:97
bool getBoolValue(const std::string &key) const
WhoIsOnline::DownloadStatus mDownloadStatus
Definition: whoisonline.h:166
const std::string BUTTON_SKIN
Definition: button.h:88
virtual bool haveServerOnlineList() const =0
SDL_Thread * mThread
Definition: whoisonline.h:142
time_t mUpdateTimer
Definition: whoisonline.h:139
std::vector< OnlinePlayer * > mNeutral
Definition: whoisonline.h:158
std::vector< OnlinePlayer * > mDisregard
Definition: whoisonline.h:159
const bool Opaque_false
Definition: opaque.h:29
std::vector< OnlinePlayer * > mFriends
Definition: whoisonline.h:157
std::vector< OnlinePlayer * > mEnemy
Definition: whoisonline.h:160
ServerTypeT getNetworkType()
Definition: net.cpp:182
bool mUpdateOnlineList
Definition: whoisonline.h:172
const bool Opaque_true
Definition: opaque.h:29
std::set< std::string > mOnlineNicks
Definition: whoisonline.h:155
char * mCurlError
Definition: whoisonline.h:148
std::set< OnlinePlayer * > mOnlinePlayers
Definition: whoisonline.h:154
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
void setWindowName(const std::string &name)
Definition: window.h:354

◆ ~WhoIsOnline()

WhoIsOnline::~WhoIsOnline ( )

Destructor

Definition at line 174 of file whoisonline.cpp.

References CHECKLISTENERS, config, FOR_EACH, mCurlError, mMemoryBuffer, mOnlineNicks, mOnlinePlayers, mThread, Configuration::removeListeners(), and SDL::WaitThread().

175 {
176  config.removeListeners(this);
178 
180  mThread = nullptr;
181  free(mMemoryBuffer);
182  mMemoryBuffer = nullptr;
183 
184  // Remove possibly leftover temporary download
185  delete []mCurlError;
186 
187  FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
188  delete *itd;
189  mOnlinePlayers.clear();
190  mOnlineNicks.clear();
191 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Configuration config
void WaitThread(SDL_Thread *const thread)
Definition: sdlhelper.cpp:194
char * mMemoryBuffer
Definition: whoisonline.h:145
SDL_Thread * mThread
Definition: whoisonline.h:142
void removeListeners(ConfigListener *const listener)
std::set< std::string > mOnlineNicks
Definition: whoisonline.h:155
char * mCurlError
Definition: whoisonline.h:148
#define CHECKLISTENERS
Definition: localconsts.h:268
std::set< OnlinePlayer * > mOnlinePlayers
Definition: whoisonline.h:154

Member Function Documentation

◆ action()

void WhoIsOnline::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Implements ActionListener.

Definition at line 719 of file whoisonline.cpp.

References _, cur_time, ActionEvent::getId(), PacketLimiter::limitPackets(), mDownloadComplete, mDownloadStatus, mServerSideList, mThread, mUpdateButton, mUpdateTimer, PacketType::PACKET_ONLINELIST, playerHandler, Net::PlayerHandler::requestOnlineList(), Window::setCaption(), Widget::setEnabled(), UPDATE_COMPLETE, and SDL::WaitThread().

720 {
721  if (event.getId() == "update")
722  {
723 #ifdef TMWA_SUPPORT
724  if (!mServerSideList)
725  {
727  {
728  mUpdateTimer = cur_time - 20;
729  if (mUpdateButton != nullptr)
730  mUpdateButton->setEnabled(false);
731  // TRANSLATORS: who is online window name
732  setCaption(_("Who Is Online - Update"));
734  mThread = nullptr;
735  mDownloadComplete = true;
736  }
737  }
738  else
739 #endif // TMWA_SUPPORT
740  {
742  {
745  }
746  }
747  }
748 }
Net::PlayerHandler * playerHandler
Definition: net.cpp:92
#define _(s)
Definition: gettext.h:34
virtual void requestOnlineList() const =0
bool limitPackets(const PacketTypeT type)
bool mServerSideList
Definition: whoisonline.h:177
void WaitThread(SDL_Thread *const thread)
Definition: sdlhelper.cpp:194
Button * mUpdateButton
Definition: whoisonline.h:152
bool mDownloadComplete
Definition: whoisonline.h:169
WhoIsOnline::DownloadStatus mDownloadStatus
Definition: whoisonline.h:166
SDL_Thread * mThread
Definition: whoisonline.h:142
time_t mUpdateTimer
Definition: whoisonline.h:139
volatile time_t cur_time
Definition: timer.cpp:57
void setEnabled(const bool enabled)
Definition: widget.h:351
void setCaption(const std::string &caption)
Definition: window.h:530

◆ download()

void WhoIsOnline::download ( )
private

Definition at line 622 of file whoisonline.cpp.

References SDL::createThread(), downloadThread(), PacketLimiter::limitPackets(), mDownloadComplete, mDownloadStatus, mServerSideList, mThread, mWebList, PacketType::PACKET_ONLINELIST, playerHandler, Net::PlayerHandler::requestOnlineList(), UPDATE_ERROR, and SDL::WaitThread().

Referenced by postInit(), setAllowUpdate(), and slowLogic().

623 {
624  if (mServerSideList)
625  {
628  }
629 #ifdef TMWA_SUPPORT
630  else if (mWebList)
631  {
632  mDownloadComplete = true;
634  mThread = nullptr;
635  mDownloadComplete = false;
637  "whoisonline", this);
638  if (mThread == nullptr)
640  }
641 #endif // TMWA_SUPPORT
642 }
Net::PlayerHandler * playerHandler
Definition: net.cpp:92
virtual void requestOnlineList() const =0
static int downloadThread(void *ptr)
bool limitPackets(const PacketTypeT type)
SDL_Thread * createThread(int(*fn)(void *), const char *const name, void *const data)
Definition: sdlhelper.cpp:117
bool mServerSideList
Definition: whoisonline.h:177
void WaitThread(SDL_Thread *const thread)
Definition: sdlhelper.cpp:194
bool mDownloadComplete
Definition: whoisonline.h:169
WhoIsOnline::DownloadStatus mDownloadStatus
Definition: whoisonline.h:166
SDL_Thread * mThread
Definition: whoisonline.h:142

◆ downloadThread()

int WhoIsOnline::downloadThread ( void *  ptr)
staticprivate

The thread function that download the files.

Definition at line 527 of file whoisonline.cpp.

References Net::Download::addCommonFlags(), Net::Download::addHeaders(), Net::Download::addProxy(), CAST_U32, mAllowUpdate, mCurlError, mDownloadComplete, mDownloadedBytes, mDownloadStatus, memoryWrite(), Settings::onlineListUrl, PRAGMA45(), Net::Download::secureCurl(), settings, UPDATE_ERROR, Actions::url(), and Settings::userAgent.

Referenced by download(), and setAllowUpdate().

528 {
529  int attempts = 0;
530  WhoIsOnline *const wio = reinterpret_cast<WhoIsOnline *>(ptr);
531  if (wio == nullptr)
532  return 0;
533  CURLcode res;
534  const std::string url(settings.onlineListUrl + "/online.txt");
535 
536  while (attempts < 1 && !wio->mDownloadComplete)
537  {
538  CURL *curl = curl_easy_init();
539  if (curl != nullptr)
540  {
541  if (!wio->mAllowUpdate)
542  {
543  curl_easy_cleanup(curl);
544  curl = nullptr;
545  break;
546  }
547  wio->mDownloadedBytes = 0;
548  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
549  curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
550  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
552  curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr);
553 
554  curl_easy_setopt(curl,
555  CURLOPT_USERAGENT,
556  settings.userAgent.c_str());
557 
558  curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, wio->mCurlError);
559  curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
560  curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
561  curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, ptr);
562 
563 #if LIBCURL_VERSION_NUM >= 0x070a00
564  curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
565 #endif // LIBCURL_VERSION_NUM >= 0x070a00
566  curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 7);
567  curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
572 
573  // Make sure the resources2.txt and news.txt aren't cached,
574  // in order to always get the latest version.
575  struct curl_slist *pHeaders = nullptr;
576  pHeaders = curl_slist_append(
577  pHeaders, "pragma: no-cache");
578  pHeaders = curl_slist_append(pHeaders,
579  "Cache-Control: no-cache");
580  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaders);
581 
582  if ((res = curl_easy_perform(curl)) != 0)
583  {
585  PRAGMA45(GCC diagnostic push)
586  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
587  switch (res)
588  {
589  case CURLE_COULDNT_CONNECT:
590  default:
591  std::cerr << "curl error "
592  << CAST_U32(res) << ": "
593  << wio->mCurlError << " host: "
594  << url.c_str() << std::endl;
595  break;
596  }
597  PRAGMA45(GCC diagnostic pop)
598  attempts++;
599  curl_easy_cleanup(curl);
600  curl_slist_free_all(pHeaders);
601  curl = nullptr;
602  continue;
603  }
604 
605  curl_easy_cleanup(curl);
606  curl_slist_free_all(pHeaders);
607 
608  // It's stored in memory, we're done
609  wio->mDownloadComplete = true;
610  }
611  if (!wio->mAllowUpdate)
612  break;
613  attempts++;
614  }
615 
616  if (!wio->mDownloadComplete)
618  return 0;
619 }
#define CAST_U32
Definition: cast.h:30
static void addProxy(CURL *const curl)
Definition: download.cpp:508
std::string onlineListUrl
Definition: settings.h:114
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wunused-result") int TestLauncher
bool mAllowUpdate
Definition: whoisonline.h:170
int mDownloadedBytes
Definition: whoisonline.h:163
Settings settings
Definition: settings.cpp:31
bool mDownloadComplete
Definition: whoisonline.h:169
WhoIsOnline::DownloadStatus mDownloadStatus
Definition: whoisonline.h:166
static void secureCurl(CURL *const curl)
Definition: download.cpp:573
static void addCommonFlags(CURL *const curl)
Definition: download.cpp:612
static size_t memoryWrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
std::string userAgent
Definition: settings.h:126
static void addHeaders(CURL *const curl)
Definition: download.cpp:607
char * mCurlError
Definition: whoisonline.h:148
bool url(InputEvent &event)
Definition: commands.cpp:63

◆ getOnlineNicks()

const std::set<std::string>& WhoIsOnline::getOnlineNicks ( ) const
inline

Definition at line 85 of file whoisonline.h.

References mOnlineNicks.

Referenced by Actions::doSit(), and SocialFriendsTab::getPlayersAvatars().

87  { return mOnlineNicks; }
std::set< std::string > mOnlineNicks
Definition: whoisonline.h:155

◆ getOnlinePlayers()

const std::set<OnlinePlayer*>& WhoIsOnline::getOnlinePlayers ( ) const
inline

Definition at line 81 of file whoisonline.h.

References mOnlinePlayers.

83  { return mOnlinePlayers; }
std::set< OnlinePlayer * > mOnlinePlayers
Definition: whoisonline.h:154

◆ getPlayerNames()

void WhoIsOnline::getPlayerNames ( StringVect names)

Definition at line 849 of file whoisonline.cpp.

References FOR_EACH, and mOnlineNicks.

Referenced by ChatWindow::autoComplete(), and setAllowUpdate().

850 {
851  names.clear();
852  FOR_EACH (std::set<std::string>::const_iterator, it, mOnlineNicks)
853  names.push_back(*it);
854 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
std::set< std::string > mOnlineNicks
Definition: whoisonline.h:155

◆ handleLink()

void WhoIsOnline::handleLink ( const std::string &  link,
MouseEvent event 
)
virtual

Implements LinkHandler.

Definition at line 193 of file whoisonline.cpp.

References actorManager, ChatWindow::addInputText(), chatWindow, config, decodeLinkText(), ActorManager::findBeingByName(), Configuration::getBoolValue(), MouseEvent::getButton(), Being::getName(), MouseButton::LEFT, ChatWindow::localChatInput(), localPlayer, Viewport::mMouseX, Viewport::mMouseY, ActorType::Player, popupManager, popupMenu, MouseButton::RIGHT, PopupMenu::showPlayerPopup(), PopupMenu::showPopup(), and viewport.

194 {
195  if ((event == nullptr) || event->getButton() == MouseButton::LEFT)
196  {
197  if (chatWindow != nullptr)
198  {
199  const std::string text = decodeLinkText(link);
200  if (config.getBoolValue("whispertab"))
201  {
202  chatWindow->localChatInput("/q " + text);
203  }
204  else
205  {
207  std::string("/w \"").append(text).append("\" "),
208  true);
209  }
210  }
211  }
212  else if (event->getButton() == MouseButton::RIGHT)
213  {
214  if ((localPlayer != nullptr) && link == localPlayer->getName())
215  return;
216 
217  if (popupMenu != nullptr)
218  {
219  if (actorManager != nullptr)
220  {
221  const std::string text = decodeLinkText(link);
222  Being *const being = actorManager->findBeingByName(
223  text, ActorType::Player);
224 
225  if ((being != nullptr) && (popupManager != nullptr))
226  {
228  viewport->mMouseY,
229  being);
230  return;
231  }
232  }
233  popupMenu->showPlayerPopup(link);
234  }
235  }
236 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:89
std::string decodeLinkText(std::string data)
void localChatInput(const std::string &msg) const
Definition: chatwindow.cpp:686
MouseButtonT getButton() const
Definition: mouseevent.h:115
Configuration config
PopupManager * popupManager
int mMouseX
Definition: viewport.h:153
bool getBoolValue(const std::string &key) const
LocalPlayer * localPlayer
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
const std::string & getName() const
Definition: being.h:231
int mMouseY
Definition: viewport.h:154
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
void showPlayerPopup(const std::string &nick)
Definition: popupmenu.cpp:605
Definition: being.h:93
void showPopup(const int x, const int y, const Being *const being)
Definition: popupmenu.cpp:202
void addInputText(const std::string &text, const bool space)
ActorManager * actorManager
Viewport * viewport
Definition: viewport.cpp:35

◆ handlerPlayerRelation()

void WhoIsOnline::handlerPlayerRelation ( const std::string &  nick,
OnlinePlayer *const  player 
)
private

Definition at line 289 of file whoisonline.cpp.

References Relation::BLACKLISTED, Relation::DISREGARDED, Relation::ENEMY2, Relation::ERASED, Relation::FRIEND, PlayerRelationsManager::getRelation(), Relation::IGNORED, mDisregard, mEnemy, mFriends, mGroupFriends, mNeutral, Relation::NEUTRAL, playerRelations, setNeutralColor(), and OnlinePlayer::setText().

Referenced by loadList(), loadWebList(), and setAllowUpdate().

291 {
292  if (player == nullptr)
293  return;
294  switch (playerRelations.getRelation(nick))
295  {
296  case Relation::NEUTRAL:
297  default:
298  setNeutralColor(player);
299  mNeutral.push_back(player);
300  break;
301 
302  case Relation::FRIEND:
303  player->setText("2");
304  if (mGroupFriends)
305  mFriends.push_back(player);
306  else
307  mNeutral.push_back(player);
308  break;
309 
312  player->setText("8");
313  mDisregard.push_back(player);
314  break;
315 
316  case Relation::ENEMY2:
317  player->setText("1");
318  mEnemy.push_back(player);
319  break;
320 
321  case Relation::IGNORED:
322  case Relation::ERASED:
323  // Ignore the ignored.
324  break;
325  }
326 }
static void setNeutralColor(OnlinePlayer *const player)
RelationT getRelation(const std::string &name) const
bool mGroupFriends
Definition: whoisonline.h:173
std::vector< OnlinePlayer * > mNeutral
Definition: whoisonline.h:158
std::vector< OnlinePlayer * > mDisregard
Definition: whoisonline.h:159
void setText(std::string str)
std::vector< OnlinePlayer * > mFriends
Definition: whoisonline.h:157
std::vector< OnlinePlayer * > mEnemy
Definition: whoisonline.h:160
PlayerRelationsManager playerRelations

◆ loadList()

void WhoIsOnline::loadList ( const std::vector< OnlinePlayer *> &  list)

Definition at line 328 of file whoisonline.cpp.

References actorManager, chatWindow, StaticBrowserBox::clearRows(), config, FOR_EACH, Configuration::getBoolValue(), OnlinePlayer::getNick(), handlerPlayerRelation(), mBrowserBox, mDisregard, mEnemy, mFriends, mNeutral, mOnlineNicks, mOnlinePlayers, mShowLevel, OnlinePlayer::setLevel(), socialWindow, SocialWindow::updateActiveList(), ChatWindow::updateOnline(), ActorManager::updateSeenPlayers(), updateSize(), and updateWindow().

Referenced by EAthena::PlayerRecv::processOnlineList().

329 {
331  const size_t numOnline = list.size();
332 
333  FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
334  delete *itd;
335  mOnlinePlayers.clear();
336  mOnlineNicks.clear();
337 
338  mShowLevel = config.getBoolValue("showlevel");
339 
340  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, list)
341  {
342  OnlinePlayer *player = *it;
343  const std::string nick = player->getNick();
344  mOnlinePlayers.insert(player);
345  mOnlineNicks.insert(nick);
346 
347  if (!mShowLevel)
348  player->setLevel(0);
349 
350  handlerPlayerRelation(nick, player);
351  }
352 
353  updateWindow(numOnline);
354  if (!mOnlineNicks.empty())
355  {
356  if (chatWindow != nullptr)
358  if (socialWindow != nullptr)
360  if (actorManager != nullptr)
362  }
363  updateSize();
364  mFriends.clear();
365  mNeutral.clear();
366  mDisregard.clear();
367  mEnemy.clear();
368 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:89
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void updateWindow(size_t numOnline)
void updateActiveList()
Configuration config
StaticBrowserBox * mBrowserBox
Definition: whoisonline.h:150
bool mShowLevel
Definition: whoisonline.h:171
bool getBoolValue(const std::string &key) const
std::vector< OnlinePlayer * > mNeutral
Definition: whoisonline.h:158
const std::string getNick() const
Definition: onlineplayer.h:51
std::vector< OnlinePlayer * > mDisregard
Definition: whoisonline.h:159
std::vector< OnlinePlayer * > mFriends
Definition: whoisonline.h:157
SocialWindow * socialWindow
std::vector< OnlinePlayer * > mEnemy
Definition: whoisonline.h:160
void updateSize()
std::set< std::string > mOnlineNicks
Definition: whoisonline.h:155
void updateSeenPlayers(const std::set< std::string > &onlinePlayers)
std::set< OnlinePlayer * > mOnlinePlayers
Definition: whoisonline.h:154
void setLevel(const char level)
Definition: onlineplayer.h:71
ActorManager * actorManager
void handlerPlayerRelation(const std::string &nick, OnlinePlayer *const player)
void updateOnline(const std::set< std::string > &onlinePlayers) const

◆ loadWebList()

void WhoIsOnline::loadWebList ( )

Loads and display online list from the memory buffer.

Definition at line 371 of file whoisonline.cpp.

References actorManager, CAST_U8, StaticBrowserBox::clearRows(), config, ActorManager::findBeingByName(), FOR_EACH, Configuration::getBoolValue(), Being::getLevel(), handlerPlayerRelation(), mBrowserBox, mDisregard, mDownloadedBytes, mEnemy, mFriends, mMemoryBuffer, mNeutral, mOnlineNicks, mOnlinePlayers, mShowLevel, ActorType::Player, OnlinePlayer::setIsGM(), Being::setLevel(), Catch::trim(), Gender::UNSPECIFIED, StaticBrowserBox::updateHeight(), Being::updateName(), and updateWindow().

Referenced by slowLogic().

372 {
373  if (mMemoryBuffer == nullptr)
374  return;
375 
376  // Reallocate and include terminating 0 character
377  mMemoryBuffer = static_cast<char*>(
378  realloc(mMemoryBuffer, mDownloadedBytes + 1));
379  if (mMemoryBuffer == nullptr)
380  return;
381 
383 
385  bool listStarted(false);
386  std::string lineStr;
387  size_t numOnline(0U);
388 
389  // Tokenize and add each line separately
390  char *line = strtok(mMemoryBuffer, "\n");
391  const std::string gmText("(GM)");
392  const std::string gmText2("(gm)");
393 
394  FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
395  delete *itd;
396 
397  mOnlinePlayers.clear();
398  mOnlineNicks.clear();
399 
400  mShowLevel = config.getBoolValue("showlevel");
401 
402  while (line != nullptr)
403  {
404  std::string nick;
405  lineStr = line;
406  trim(lineStr);
407  if (listStarted == true)
408  {
409  if (lineStr.find(" users are online.") == std::string::npos)
410  {
411  if (lineStr.length() > 24)
412  {
413  nick = lineStr.substr(0, 24);
414  lineStr = lineStr.substr(25);
415  }
416  else
417  {
418  nick = lineStr;
419  lineStr.clear();
420  }
421  trim(nick);
422 
423  bool isGM(false);
424  size_t pos = lineStr.find(gmText, 0);
425  if (pos != std::string::npos)
426  {
427  lineStr = lineStr.substr(pos + gmText.length());
428  isGM = true;
429  }
430  else
431  {
432  pos = lineStr.find(gmText2, 0);
433  if (pos != std::string::npos)
434  {
435  lineStr = lineStr.substr(pos + gmText.length());
436  isGM = true;
437  }
438  }
439 
440  trim(lineStr);
441  pos = lineStr.find('/', 0);
442 
443  if (pos != std::string::npos)
444  lineStr = lineStr.substr(0, pos);
445 
446  int level = 0;
447  if (!lineStr.empty())
448  level = atoi(lineStr.c_str());
449 
450  if (actorManager != nullptr)
451  {
452  Being *const being = actorManager->findBeingByName(
453  nick, ActorType::Player);
454  if (being != nullptr)
455  {
456  if (level > 0)
457  {
458  being->setLevel(level);
459  being->updateName();
460  }
461  else
462  {
463  if (being->getLevel() > 1)
464  level = being->getLevel();
465  }
466  }
467  }
468 
469  if (!mShowLevel)
470  level = 0;
471 
472  OnlinePlayer *const player = new OnlinePlayer(nick,
473  CAST_U8(255), level,
474  Gender::UNSPECIFIED, -1);
475  mOnlinePlayers.insert(player);
476  mOnlineNicks.insert(nick);
477 
478  if (isGM)
479  player->setIsGM(true);
480 
481  numOnline++;
482  handlerPlayerRelation(nick, player);
483  }
484  }
485  else if (lineStr.find("------------------------------")
486  != std::string::npos)
487  {
488  listStarted = true;
489  }
490  line = strtok(nullptr, "\n");
491  }
492 
493  updateWindow(numOnline);
495 
496  // Free the memory buffer now that we don't need it anymore
497  free(mMemoryBuffer);
498  mMemoryBuffer = nullptr;
499  mFriends.clear();
500  mNeutral.clear();
501  mDisregard.clear();
502  mEnemy.clear();
503 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void updateWindow(size_t numOnline)
#define CAST_U8
Definition: cast.h:26
int mDownloadedBytes
Definition: whoisonline.h:163
Configuration config
char * mMemoryBuffer
Definition: whoisonline.h:145
StaticBrowserBox * mBrowserBox
Definition: whoisonline.h:150
bool mShowLevel
Definition: whoisonline.h:171
bool getBoolValue(const std::string &key) const
std::vector< OnlinePlayer * > mNeutral
Definition: whoisonline.h:158
std::string trim(std::string const &str)
std::vector< OnlinePlayer * > mDisregard
Definition: whoisonline.h:159
std::vector< OnlinePlayer * > mFriends
Definition: whoisonline.h:157
std::vector< OnlinePlayer * > mEnemy
Definition: whoisonline.h:160
void updateName()
Definition: being.cpp:3425
std::set< std::string > mOnlineNicks
Definition: whoisonline.h:155
void setIsGM(const bool b)
Definition: onlineplayer.h:57
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
virtual int getLevel() const
Definition: being.h:603
std::set< OnlinePlayer * > mOnlinePlayers
Definition: whoisonline.h:154
Definition: being.h:93
ActorManager * actorManager
void handlerPlayerRelation(const std::string &nick, OnlinePlayer *const player)
void setLevel(const int n)
Definition: being.h:600

◆ logic()

void WhoIsOnline::logic ( )
virtual

Called for all widgets in the gui each time Gui::logic is called. You can do logic stuff here like playing an animation.

See also
Gui::logic

Reimplemented from BasicContainer.

Definition at line 644 of file whoisonline.cpp.

References BLOCK_END, BLOCK_START, ScrollArea::logic(), and mScrollArea.

645 {
646  BLOCK_START("WhoIsOnline::logic")
647  mScrollArea->logic();
648  BLOCK_END("WhoIsOnline::logic")
649 }
ScrollArea * mScrollArea
Definition: whoisonline.h:151
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79

◆ memoryWrite()

size_t WhoIsOnline::memoryWrite ( void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)
staticprivate

A libcurl callback for writing to memory.

Definition at line 505 of file whoisonline.cpp.

References CAST_S32, CAST_SIZE, and restrict.

Referenced by downloadThread(), and setAllowUpdate().

509 {
510  if (stream == nullptr)
511  return 0;
512 
513  WhoIsOnline *restrict const wio =
514  reinterpret_cast<WhoIsOnline *restrict>(stream);
515  const size_t totalMem = size * nmemb;
516  wio->mMemoryBuffer = static_cast<char*>(realloc(wio->mMemoryBuffer,
517  CAST_SIZE(wio->mDownloadedBytes) + totalMem));
518  if (wio->mMemoryBuffer != nullptr)
519  {
520  memcpy(&(wio->mMemoryBuffer[wio->mDownloadedBytes]), ptr, totalMem);
521  wio->mDownloadedBytes += CAST_S32(totalMem);
522  }
523 
524  return totalMem;
525 }
#define CAST_S32
Definition: cast.h:29
#define restrict
Definition: localconsts.h:156
#define CAST_SIZE
Definition: cast.h:33

◆ optionChanged()

void WhoIsOnline::optionChanged ( const std::string &  name)
virtual

Called when an option changed. The config listener will have to be registered to the option name first.

Implements ConfigListener.

Definition at line 781 of file whoisonline.cpp.

References config, Configuration::getBoolValue(), mGroupFriends, and mUpdateOnlineList.

Referenced by setAllowUpdate().

782 {
783  if (name == "updateOnlineList")
784  mUpdateOnlineList = config.getBoolValue("updateOnlineList");
785  else if (name == "groupFriends")
786  mGroupFriends = config.getBoolValue("groupFriends");
787 }
bool mGroupFriends
Definition: whoisonline.h:173
Configuration config
bool getBoolValue(const std::string &key) const
bool mUpdateOnlineList
Definition: whoisonline.h:172

◆ postInit()

void WhoIsOnline::postInit ( )
virtual

Reimplemented from Window.

Definition at line 133 of file whoisonline.cpp.

References BasicContainer2::add(), Configuration::addListener(), ImagePosition::CENTER, config, download(), Window::enableVisibleSound(), Configuration::getBoolValue(), Widget::getParent(), Window::loadWindowState(), mBrowserBox, mGroupFriends, mScrollArea, mUpdateButton, Opaque_false, Window::postInit(), SetupWindow::registerWindowForReset(), Window::setCloseButton(), Window::setDefaultSize(), Widget::setDimension(), ScrollArea::setDimension(), Widget::setEnabled(), StaticBrowserBox::setLinkHandler(), Window::setLocationRelativeTo(), StaticBrowserBox::setOpaque(), Window::setResizable(), Window::setSaveVisible(), Widget::setSelectable(), Widget::setSize(), Window::setStickyButtonLock(), setupWindow, Window::setVisible(), Visible_false, and widgetResized().

134 {
136  const int h = 350;
137  const int w = 200;
139 
141  setCloseButton(true);
142  setResizable(true);
143  setStickyButtonLock(true);
144  setSaveVisible(true);
145 
146  if (setupWindow != nullptr)
148 
149  mUpdateButton->setEnabled(false);
150  mUpdateButton->setDimension(Rect(5, 5, w - 10, 20 + 5));
151 
153  mScrollArea->setDimension(Rect(5, 20 + 10, w - 10, h - 10 - 30));
154  mScrollArea->setSize(w - 10, h - 10 - 30);
155  mScrollArea->setSelectable(false);
157 
159  add(mScrollArea);
160 
162 
163  loadWindowState();
164  enableVisibleSound(true);
165 
166  download();
167 
168  widgetResized(Event(nullptr));
169  config.addListener("updateOnlineList", this);
170  config.addListener("groupFriends", this);
171  mGroupFriends = config.getBoolValue("groupFriends");
172 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
void setDefaultSize()
Definition: window.cpp:1193
ScrollArea * mScrollArea
Definition: whoisonline.h:151
void loadWindowState()
Definition: window.cpp:1082
Definition: rect.h:72
bool mGroupFriends
Definition: whoisonline.h:173
Configuration config
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
void setDimension(const Rect &dimension)
void addListener(const std::string &key, ConfigListener *const listener)
void registerWindowForReset(Window *const window)
StaticBrowserBox * mBrowserBox
Definition: whoisonline.h:150
void setSelectable(const bool selectable)
Definition: widget.h:947
Button * mUpdateButton
Definition: whoisonline.h:152
void setLinkHandler(LinkHandler *linkHandler)
bool getBoolValue(const std::string &key) const
const bool Visible_false
Definition: visible.h:29
virtual void add(Widget *const widget)
const bool Opaque_false
Definition: opaque.h:29
void setCloseButton(const bool flag)
Definition: window.cpp:744
void enableVisibleSound(bool b)
Definition: window.h:480
void setEnabled(const bool enabled)
Definition: widget.h:351
void setOpaque(Opaque opaque)
void setSaveVisible(const bool save)
Definition: window.h:299
Widget * getParent() const
Definition: widget.h:201
virtual void setVisible(Visible visible)
Definition: window.cpp:773
Definition: event.h:77
void widgetResized(const Event &event)
void setResizable(const bool resize)
Definition: window.cpp:622
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:767
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
void setLocationRelativeTo(const Widget *const widget)
Definition: window.cpp:508
void download()
void postInit()
Definition: window.cpp:248

◆ prepareNick()

const std::string WhoIsOnline::prepareNick ( const std::string &  nick,
const int  level,
const std::string &  color 
) const
private

Definition at line 766 of file whoisonline.cpp.

References encodeLinkText(), mShowLevel, and strprintf().

Referenced by setAllowUpdate().

770 {
771  const std::string text = encodeLinkText(nick);
772  if (mShowLevel && level > 1)
773  {
774  return strprintf("@@%s|##%s%s (%d)@@", text.c_str(),
775  color.c_str(), text.c_str(), level);
776  }
777  return strprintf("@@%s|##%s%[email protected]@", text.c_str(),
778  color.c_str(), text.c_str());
779 }
std::string encodeLinkText(std::string data)
bool mShowLevel
Definition: whoisonline.h:171
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99

◆ readFromWeb()

void WhoIsOnline::readFromWeb ( )

Referenced by setAllowUpdate().

◆ setAllowUpdate()

void WhoIsOnline::setAllowUpdate ( const bool  n)
inline

◆ setNeutralColor()

void WhoIsOnline::setNeutralColor ( OnlinePlayer *const  player)
static

Definition at line 789 of file whoisonline.cpp.

References actorManager, ActorManager::findBeingByName(), Guild::getGuild(), Being::getGuild(), Guild::getId(), Party::getMember(), Guild::getMember(), Being::getName(), OnlinePlayer::getNick(), Being::getParty(), Being::isInParty(), Guild::isMember(), localPlayer, party, ActorType::Player, and OnlinePlayer::setText().

Referenced by handlerPlayerRelation(), and setAllowUpdate().

790 {
791  if (player == nullptr)
792  return;
793 
794  if ((actorManager != nullptr) && (localPlayer != nullptr))
795  {
796  const std::string &nick = player->getNick();
797  if (nick == localPlayer->getName())
798  {
799  player->setText("s");
800  return;
801  }
802  if (localPlayer->isInParty())
803  {
804  const Party *const party = localPlayer->getParty();
805  if (party != nullptr)
806  {
807  if (party->getMember(nick) != nullptr)
808  {
809  player->setText("P");
810  return;
811  }
812  }
813  }
814 
815  const Being *const being = actorManager->findBeingByName(nick,
817  if (being != nullptr)
818  {
819  const Guild *const guild2 = localPlayer->getGuild();
820  if (guild2 != nullptr)
821  {
822  const Guild *const guild1 = being->getGuild();
823  if (guild1 != nullptr)
824  {
825  if (guild1->getId() == guild2->getId()
826  || (guild2->getMember(nick) != nullptr))
827  {
828  player->setText("U");
829  return;
830  }
831  }
832  else if (guild2->isMember(nick))
833  {
834  player->setText("U");
835  return;
836  }
837  }
838  }
839  const Guild *const guild3 = Guild::getGuild(1);
840  if ((guild3 != nullptr) && guild3->isMember(nick))
841  {
842  player->setText("U");
843  return;
844  }
845  }
846  player->setText("0");
847 }
int16_t getId() const
Definition: guild.h:127
Definition: party.h:61
const Guild * getGuild(const std::string &guildName) const
Definition: being.cpp:1257
Party * getParty() const
Definition: being.h:329
uint32_t party
GuildMember * getMember(const BeingId id) const
Definition: guild.cpp:139
LocalPlayer * localPlayer
const std::string getNick() const
Definition: onlineplayer.h:51
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:98
bool isMember(const GuildMember *const member) const
Definition: guild.cpp:286
bool isInParty() const
Definition: being.h:320
void setText(std::string str)
const std::string & getName() const
Definition: being.h:231
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
static Guild * getGuild(const int16_t id)
Definition: guild.cpp:356
Definition: being.h:93
Definition: guild.h:68
ActorManager * actorManager

◆ slowLogic()

void WhoIsOnline::slowLogic ( )

Definition at line 651 of file whoisonline.cpp.

References _, actorManager, Logger::assertLog(), BLOCK_END, BLOCK_START, chatWindow, cur_time, download(), Window::isWindowVisible(), loadWebList(), logger, mAllowUpdate, mCurlError, mDownloadComplete, mDownloadStatus, mOnlineNicks, mUpdateButton, mUpdateOnlineList, mUpdateTimer, Window::setCaption(), Widget::setEnabled(), socialWindow, UPDATE_COMPLETE, UPDATE_ERROR, UPDATE_LIST, SocialWindow::updateActiveList(), ChatWindow::updateOnline(), ActorManager::updateSeenPlayers(), and updateSize().

Referenced by Game::slowLogic().

652 {
653  if (!mAllowUpdate)
654  return;
655 
656  BLOCK_START("WhoIsOnline::slowLogic")
657  if (mUpdateTimer == 0)
659 
660  const double timeDiff = difftime(cur_time, mUpdateTimer);
661  const int timeLimit = isWindowVisible() ? 20 : 120;
662 
663  if (mUpdateOnlineList && timeDiff >= timeLimit
665  {
666  if (mDownloadComplete == true)
667  {
668  // TRANSLATORS: who is online window name
669  setCaption(_("Who Is Online - Updating"));
670  mUpdateTimer = 0;
672  download();
673  }
674  }
675 
676 #ifdef TMWA_SUPPORT
677  switch (mDownloadStatus)
678  {
679  case UPDATE_ERROR:
680  logger->assertLog("Failed to fetch the online list:");
681  if (mCurlError != nullptr)
682  logger->assertLog("%s", mCurlError);
684  // TRANSLATORS: who is online window name
685  setCaption(_("Who Is Online - error"));
686  mUpdateButton->setEnabled(true);
687  mUpdateTimer = cur_time + 240;
688  mDownloadComplete = true;
689  updateSize();
690  break;
691  case UPDATE_LIST:
692  if (mDownloadComplete == true)
693  {
694  loadWebList();
696  mUpdateButton->setEnabled(true);
697  mUpdateTimer = 0;
698  updateSize();
699  if (!mOnlineNicks.empty())
700  {
701  if (chatWindow != nullptr)
703  if (socialWindow != nullptr)
705  if (actorManager != nullptr)
707  }
708  }
709  break;
710  case UPDATE_COMPLETE:
711  default:
712  break;
713  }
714 #endif // TMWA_SUPPORT
715 
716  BLOCK_END("WhoIsOnline::slowLogic")
717 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:89
void updateActiveList()
#define _(s)
Definition: gettext.h:34
bool mAllowUpdate
Definition: whoisonline.h:170
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Logger * logger
Definition: logger.cpp:88
Button * mUpdateButton
Definition: whoisonline.h:152
bool mDownloadComplete
Definition: whoisonline.h:169
WhoIsOnline::DownloadStatus mDownloadStatus
Definition: whoisonline.h:166
void loadWebList()
time_t mUpdateTimer
Definition: whoisonline.h:139
bool isWindowVisible() const
Definition: window.h:483
volatile time_t cur_time
Definition: timer.cpp:57
SocialWindow * socialWindow
void setEnabled(const bool enabled)
Definition: widget.h:351
void updateSize()
bool mUpdateOnlineList
Definition: whoisonline.h:172
std::set< std::string > mOnlineNicks
Definition: whoisonline.h:155
char * mCurlError
Definition: whoisonline.h:148
void updateSeenPlayers(const std::set< std::string > &onlinePlayers)
void setCaption(const std::string &caption)
Definition: window.h:530
void assertLog(const char *const log_text,...)
Definition: logger.cpp:311
void download()
ActorManager * actorManager
void updateOnline(const std::set< std::string > &onlinePlayers) const

◆ updateList()

void WhoIsOnline::updateList ( StringVect list)

Referenced by setAllowUpdate().

◆ updateSize()

void WhoIsOnline::updateSize ( )
private

Definition at line 756 of file whoisonline.cpp.

References Window::getChildrenArea(), Rect::height, mScrollArea, mUpdateButton, Widget::setSize(), Widget::setWidth(), and Rect::width.

Referenced by loadList(), setAllowUpdate(), slowLogic(), and widgetResized().

757 {
758  const Rect area = getChildrenArea();
759  if (mUpdateButton != nullptr)
760  mUpdateButton->setWidth(area.width - 10);
761 
762  if (mScrollArea != nullptr)
763  mScrollArea->setSize(area.width - 10, area.height - 10 - 30);
764 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
ScrollArea * mScrollArea
Definition: whoisonline.h:151
int width
Definition: rect.h:218
void setWidth(const int width)
Definition: widget.cpp:132
Rect getChildrenArea()
Definition: window.cpp:1468
Definition: rect.h:72
Button * mUpdateButton
Definition: whoisonline.h:152
int height
Definition: rect.h:223

◆ updateWindow()

void WhoIsOnline::updateWindow ( size_t  numOnline)
private

Definition at line 238 of file whoisonline.cpp.

References _, StaticBrowserBox::addRow(), CAST_U32, FOR_EACH, ScrollArea::getVerticalMaxScroll(), ScrollArea::getVerticalScrollAmount(), mBrowserBox, mDisregard, mEnemy, mFriends, mNeutral, mScrollArea, anonymous_namespace{whoisonline.cpp}::nameCompare, Window::setCaption(), ScrollArea::setVerticalScrollAmount(), Catch::toString(), and StaticBrowserBox::updateHeight().

Referenced by loadList(), loadWebList(), and setAllowUpdate().

239 {
240  // Set window caption
241  // TRANSLATORS: who is online window name
242  setCaption(_("Who Is Online - ") + toString(CAST_U32(numOnline)));
243 
244  // List the online people
245  std::sort(mFriends.begin(), mFriends.end(), nameCompare);
246  std::sort(mNeutral.begin(), mNeutral.end(), nameCompare);
247  std::sort(mDisregard.begin(), mDisregard.end(), nameCompare);
248  bool addedFromSection(false);
249  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mFriends)
250  {
251  mBrowserBox->addRow((*it)->getText(), false);
252  addedFromSection = true;
253  }
254  if (addedFromSection == true)
255  {
256  mBrowserBox->addRow("---", false);
257  addedFromSection = false;
258  }
259  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mEnemy)
260  {
261  mBrowserBox->addRow((*it)->getText(), false);
262  addedFromSection = true;
263  }
264  if (addedFromSection == true)
265  {
266  mBrowserBox->addRow("---", false);
267  addedFromSection = false;
268  }
269  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mNeutral)
270  {
271  mBrowserBox->addRow((*it)->getText(), false);
272  addedFromSection = true;
273  }
274  if (addedFromSection == true && !mDisregard.empty())
275  mBrowserBox->addRow("---", false);
276 
277  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mDisregard)
278  mBrowserBox->addRow((*it)->getText(), false);
279 
282  {
285  }
287 }
#define CAST_U32
Definition: cast.h:30
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
#define _(s)
Definition: gettext.h:34
ScrollArea * mScrollArea
Definition: whoisonline.h:151
class anonymous_namespace{whoisonline.cpp}::NameFunctuator nameCompare
void setVerticalScrollAmount(const int vScroll)
int getVerticalMaxScroll()
StaticBrowserBox * mBrowserBox
Definition: whoisonline.h:150
int getVerticalScrollAmount() const
Definition: scrollarea.h:273
std::vector< OnlinePlayer * > mNeutral
Definition: whoisonline.h:158
std::vector< OnlinePlayer * > mDisregard
Definition: whoisonline.h:159
std::vector< OnlinePlayer * > mFriends
Definition: whoisonline.h:157
std::vector< OnlinePlayer * > mEnemy
Definition: whoisonline.h:160
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void setCaption(const std::string &caption)
Definition: window.h:530
void addRow(const std::string &row, const bool atTop)

◆ widgetResized()

void WhoIsOnline::widgetResized ( const Event event)
virtual

Called whenever the widget changes size.

Reimplemented from Window.

Definition at line 750 of file whoisonline.cpp.

References updateSize(), and Window::widgetResized().

Referenced by postInit().

751 {
752  Window::widgetResized(event);
753  updateSize();
754 }
void widgetResized(const Event &event)
Definition: window.cpp:650
void updateSize()

Field Documentation

◆ mAllowUpdate

bool WhoIsOnline::mAllowUpdate
private

Definition at line 170 of file whoisonline.h.

Referenced by downloadThread(), setAllowUpdate(), and slowLogic().

◆ mBrowserBox

StaticBrowserBox* WhoIsOnline::mBrowserBox
private

Definition at line 150 of file whoisonline.h.

Referenced by loadList(), loadWebList(), postInit(), and updateWindow().

◆ mCurlError

char* WhoIsOnline::mCurlError
private

Buffer to handler human readable error provided by curl.

Definition at line 148 of file whoisonline.h.

Referenced by downloadThread(), slowLogic(), WhoIsOnline(), and ~WhoIsOnline().

◆ mDisregard

std::vector<OnlinePlayer*> WhoIsOnline::mDisregard
private

Definition at line 159 of file whoisonline.h.

Referenced by handlerPlayerRelation(), loadList(), loadWebList(), and updateWindow().

◆ mDownloadComplete

bool WhoIsOnline::mDownloadComplete
private

Flag that show if current download is complete.

Definition at line 169 of file whoisonline.h.

Referenced by action(), download(), downloadThread(), and slowLogic().

◆ mDownloadedBytes

int WhoIsOnline::mDownloadedBytes
private

Byte count currently downloaded in mMemoryBuffer.

Definition at line 163 of file whoisonline.h.

Referenced by downloadThread(), and loadWebList().

◆ mDownloadStatus

WhoIsOnline::DownloadStatus WhoIsOnline::mDownloadStatus
private

Status of the current download.

Definition at line 166 of file whoisonline.h.

Referenced by action(), download(), downloadThread(), and slowLogic().

◆ mEnemy

std::vector<OnlinePlayer*> WhoIsOnline::mEnemy
private

Definition at line 160 of file whoisonline.h.

Referenced by handlerPlayerRelation(), loadList(), loadWebList(), and updateWindow().

◆ mFriends

std::vector<OnlinePlayer*> WhoIsOnline::mFriends
private

Definition at line 157 of file whoisonline.h.

Referenced by handlerPlayerRelation(), loadList(), loadWebList(), and updateWindow().

◆ mGroupFriends

bool WhoIsOnline::mGroupFriends
private

Definition at line 173 of file whoisonline.h.

Referenced by handlerPlayerRelation(), optionChanged(), and postInit().

◆ mMemoryBuffer

char* WhoIsOnline::mMemoryBuffer
private

Buffer for files downloaded to memory.

Definition at line 145 of file whoisonline.h.

Referenced by loadWebList(), and ~WhoIsOnline().

◆ mNeutral

std::vector<OnlinePlayer*> WhoIsOnline::mNeutral
private

Definition at line 158 of file whoisonline.h.

Referenced by handlerPlayerRelation(), loadList(), loadWebList(), and updateWindow().

◆ mOnlineNicks

std::set<std::string> WhoIsOnline::mOnlineNicks
private

◆ mOnlinePlayers

std::set<OnlinePlayer*> WhoIsOnline::mOnlinePlayers
private

Definition at line 154 of file whoisonline.h.

Referenced by getOnlinePlayers(), loadList(), loadWebList(), and ~WhoIsOnline().

◆ mScrollArea

ScrollArea* WhoIsOnline::mScrollArea
private

Definition at line 151 of file whoisonline.h.

Referenced by logic(), postInit(), updateSize(), and updateWindow().

◆ mServerSideList

bool WhoIsOnline::mServerSideList
private

Definition at line 177 of file whoisonline.h.

Referenced by action(), and download().

◆ mShowLevel

bool WhoIsOnline::mShowLevel
private

Definition at line 171 of file whoisonline.h.

Referenced by loadList(), loadWebList(), and prepareNick().

◆ mThread

SDL_Thread* WhoIsOnline::mThread
private

A thread that use libcurl to download updates.

Definition at line 142 of file whoisonline.h.

Referenced by action(), download(), and ~WhoIsOnline().

◆ mUpdateButton

Button* WhoIsOnline::mUpdateButton
private

Definition at line 152 of file whoisonline.h.

Referenced by action(), postInit(), slowLogic(), and updateSize().

◆ mUpdateOnlineList

bool WhoIsOnline::mUpdateOnlineList
private

Definition at line 172 of file whoisonline.h.

Referenced by optionChanged(), and slowLogic().

◆ mUpdateTimer

time_t WhoIsOnline::mUpdateTimer
private

Definition at line 139 of file whoisonline.h.

Referenced by action(), and slowLogic().

◆ mWebList

bool WhoIsOnline::mWebList
private

Definition at line 175 of file whoisonline.h.

Referenced by download().


The documentation for this class was generated from the following files: