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="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
 
virtual ~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=0, int offsetY=0)
 
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=0, const int offsetY=0)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w=0, int h=0)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w=1, const int h=1)
 
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)
 
virtual ~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)
 
virtual ~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)
 
virtual ~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=255U) 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=0) const
 
bool getOptionBool (const std::string &name, const bool def=false) 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")),
108  // TRANSLATORS: who is online. button.
109  mUpdateButton(new Button(this, _("Update"), "update", this)),
110  mOnlinePlayers(),
111  mOnlineNicks(),
112  mFriends(),
113  mNeutral(),
114  mDisregard(),
115  mEnemy(),
116  mDownloadedBytes(0),
118  mDownloadComplete(true),
119  mAllowUpdate(true),
120  mShowLevel(false),
121  mUpdateOnlineList(config.getBoolValue("updateOnlineList")),
122  mGroupFriends(true),
123 #ifdef TMWA_SUPPORT
125 #endif
127 {
128  mCurlError[0] = 0;
129  setWindowName("WhoIsOnline");
130 }
#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:94
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:94
bool getBoolValue(const std::string &key) const
WhoIsOnline::DownloadStatus mDownloadStatus
Definition: whoisonline.h:166
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:178
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
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
std::set< OnlinePlayer * > mOnlinePlayers
Definition: whoisonline.h:154
void setWindowName(const std::string &name)
Definition: window.h:353

◆ ~WhoIsOnline()

WhoIsOnline::~WhoIsOnline ( )

Destructor

Definition at line 173 of file whoisonline.cpp.

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

174 {
175  config.removeListeners(this);
177 
179  mThread = nullptr;
180  free(mMemoryBuffer);
181  mMemoryBuffer = nullptr;
182 
183  // Remove possibly leftover temporary download
184  delete []mCurlError;
185 
186  FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
187  delete *itd;
188  mOnlinePlayers.clear();
189  mOnlineNicks.clear();
190 }
#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:305
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 716 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().

717 {
718  if (event.getId() == "update")
719  {
720 #ifdef TMWA_SUPPORT
721  if (!mServerSideList)
722  {
724  {
725  mUpdateTimer = cur_time - 20;
726  if (mUpdateButton != nullptr)
727  mUpdateButton->setEnabled(false);
728  // TRANSLATORS: who is online window name
729  setCaption(_("Who Is Online - Update"));
731  mThread = nullptr;
732  mDownloadComplete = true;
733  }
734  }
735  else
736 #endif // TMWA_SUPPORT
737  {
739  {
742  }
743  }
744  }
745 }
Net::PlayerHandler * playerHandler
Definition: net.cpp:89
#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:523

◆ download()

void WhoIsOnline::download ( )
private

Definition at line 619 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().

620 {
621  if (mServerSideList)
622  {
625  }
626 #ifdef TMWA_SUPPORT
627  else if (mWebList)
628  {
629  mDownloadComplete = true;
631  mThread = nullptr;
632  mDownloadComplete = false;
634  "whoisonline", this);
635  if (mThread == nullptr)
637  }
638 #endif // TMWA_SUPPORT
639 }
Net::PlayerHandler * playerHandler
Definition: net.cpp:89
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 525 of file whoisonline.cpp.

References 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().

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

References FOR_EACH, and mOnlineNicks.

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

846 {
847  names.clear();
848  FOR_EACH (std::set<std::string>::const_iterator, it, mOnlineNicks)
849  names.push_back(*it);
850 }
#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 192 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.

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

◆ handlerPlayerRelation()

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

Definition at line 287 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().

289 {
290  if (player == nullptr)
291  return;
292  switch (playerRelations.getRelation(nick))
293  {
294  case Relation::NEUTRAL:
295  default:
296  setNeutralColor(player);
297  mNeutral.push_back(player);
298  break;
299 
300  case Relation::FRIEND:
301  player->setText("2");
302  if (mGroupFriends)
303  mFriends.push_back(player);
304  else
305  mNeutral.push_back(player);
306  break;
307 
310  player->setText("8");
311  mDisregard.push_back(player);
312  break;
313 
314  case Relation::ENEMY2:
315  player->setText("1");
316  mEnemy.push_back(player);
317  break;
318 
319  case Relation::IGNORED:
320  case Relation::ERASED:
321  // Ignore the ignored.
322  break;
323  }
324 }
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 326 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().

327 {
329  const size_t numOnline = list.size();
330 
331  FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
332  delete *itd;
333  mOnlinePlayers.clear();
334  mOnlineNicks.clear();
335 
336  mShowLevel = config.getBoolValue("showlevel");
337 
338  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, list)
339  {
340  OnlinePlayer *player = *it;
341  const std::string nick = player->getNick();
342  mOnlinePlayers.insert(player);
343  mOnlineNicks.insert(nick);
344 
345  if (!mShowLevel)
346  player->setLevel(0);
347 
348  handlerPlayerRelation(nick, player);
349  }
350 
351  updateWindow(numOnline);
352  if (!mOnlineNicks.empty())
353  {
354  if (chatWindow != nullptr)
356  if (socialWindow != nullptr)
358  if (actorManager != nullptr)
360  }
361  updateSize();
362  mFriends.clear();
363  mNeutral.clear();
364  mDisregard.clear();
365  mEnemy.clear();
366 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
#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 369 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().

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

◆ 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 641 of file whoisonline.cpp.

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

642 {
643  BLOCK_START("WhoIsOnline::logic")
644  mScrollArea->logic();
645  BLOCK_END("WhoIsOnline::logic")
646 }
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 503 of file whoisonline.cpp.

References CAST_S32, CAST_SIZE, and restrict.

Referenced by downloadThread(), and setAllowUpdate().

507 {
508  if (stream == nullptr)
509  return 0;
510 
511  WhoIsOnline *restrict const wio =
512  reinterpret_cast<WhoIsOnline *restrict>(stream);
513  const size_t totalMem = size * nmemb;
514  wio->mMemoryBuffer = static_cast<char*>(realloc(wio->mMemoryBuffer,
515  CAST_SIZE(wio->mDownloadedBytes) + totalMem));
516  if (wio->mMemoryBuffer != nullptr)
517  {
518  memcpy(&(wio->mMemoryBuffer[wio->mDownloadedBytes]), ptr, totalMem);
519  wio->mDownloadedBytes += CAST_S32(totalMem);
520  }
521 
522  return totalMem;
523 }
#define CAST_S32
Definition: cast.h:29
#define restrict
Definition: localconsts.h:176
#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 778 of file whoisonline.cpp.

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

Referenced by setAllowUpdate().

779 {
780  if (name == "updateOnlineList")
781  mUpdateOnlineList = config.getBoolValue("updateOnlineList");
782  else if (name == "groupFriends")
783  mGroupFriends = config.getBoolValue("groupFriends");
784 }
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 132 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().

133 {
135  const int h = 350;
136  const int w = 200;
138 
140  setCloseButton(true);
141  setResizable(true);
142  setStickyButtonLock(true);
143  setSaveVisible(true);
144 
145  if (setupWindow != nullptr)
147 
148  mUpdateButton->setEnabled(false);
149  mUpdateButton->setDimension(Rect(5, 5, w - 10, 20 + 5));
150 
152  mScrollArea->setDimension(Rect(5, 20 + 10, w - 10, h - 10 - 30));
153  mScrollArea->setSize(w - 10, h - 10 - 30);
154  mScrollArea->setSelectable(false);
156 
158  add(mScrollArea);
159 
161 
162  loadWindowState();
163  enableVisibleSound(true);
164 
165  download();
166 
167  widgetResized(Event(nullptr));
168  config.addListener("updateOnlineList", this);
169  config.addListener("groupFriends", this);
170  mGroupFriends = config.getBoolValue("groupFriends");
171 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
void setDefaultSize()
Definition: window.cpp:1186
ScrollArea * mScrollArea
Definition: whoisonline.h:151
void loadWindowState()
Definition: window.cpp:1075
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:737
void enableVisibleSound(bool b)
Definition: window.h:473
void setEnabled(const bool enabled)
Definition: widget.h:351
void setOpaque(Opaque opaque)
void setSaveVisible(const bool save)
Definition: window.h:298
Widget * getParent() const
Definition: widget.h:201
virtual void setVisible(Visible visible)
Definition: window.cpp:766
Definition: event.h:77
void widgetResized(const Event &event)
void setResizable(const bool resize)
Definition: window.cpp:615
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:760
SetupWindow * setupWindow
Definition: setupwindow.cpp:63
void setLocationRelativeTo(const Widget *const widget)
Definition: window.cpp:501
void download()
void postInit()
Definition: window.cpp:241

◆ prepareNick()

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

Definition at line 763 of file whoisonline.cpp.

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

Referenced by setAllowUpdate().

767 {
768  const std::string text = encodeLinkText(nick);
769  if (mShowLevel && level > 1)
770  {
771  return strprintf("@@%s|##%s%s (%d)@@", text.c_str(),
772  color.c_str(), text.c_str(), level);
773  }
774  return strprintf("@@%s|##%s%[email protected]@", text.c_str(),
775  color.c_str(), text.c_str());
776 }
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 786 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, and OnlinePlayer::setText().

Referenced by handlerPlayerRelation(), and setAllowUpdate().

787 {
788  if (player == nullptr)
789  return;
790 
791  if ((actorManager != nullptr) && (localPlayer != nullptr))
792  {
793  const std::string &nick = player->getNick();
794  if (nick == localPlayer->getName())
795  {
796  player->setText("s");
797  return;
798  }
799  if (localPlayer->isInParty())
800  {
801  const Party *const party = localPlayer->getParty();
802  if (party != nullptr)
803  {
804  if (party->getMember(nick) != nullptr)
805  {
806  player->setText("P");
807  return;
808  }
809  }
810  }
811 
812  const Being *const being = actorManager->findBeingByName(nick);
813  if (being != nullptr)
814  {
815  const Guild *const guild2 = localPlayer->getGuild();
816  if (guild2 != nullptr)
817  {
818  const Guild *const guild1 = being->getGuild();
819  if (guild1 != nullptr)
820  {
821  if (guild1->getId() == guild2->getId()
822  || (guild2->getMember(nick) != nullptr))
823  {
824  player->setText("U");
825  return;
826  }
827  }
828  else if (guild2->isMember(nick))
829  {
830  player->setText("U");
831  return;
832  }
833  }
834  }
835  const Guild *const guild3 = Guild::getGuild(1);
836  if ((guild3 != nullptr) && guild3->isMember(nick))
837  {
838  player->setText("U");
839  return;
840  }
841  }
842  player->setText("0");
843 }
int16_t getId() const
Definition: guild.h:127
Definition: party.h:61
Being * findBeingByName(const std::string &name, const ActorTypeT type=ActorType::Unknown) const
const Guild * getGuild(const std::string &guildName) const
Definition: being.cpp:1219
Party * getParty() const
Definition: being.h:325
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:99
bool isMember(const GuildMember *const member) const
Definition: guild.cpp:286
bool isInParty() const
Definition: being.h:316
void setText(std::string str)
const std::string & getName() const
Definition: being.h:233
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 648 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().

649 {
650  if (!mAllowUpdate)
651  return;
652 
653  BLOCK_START("WhoIsOnline::slowLogic")
654  if (mUpdateTimer == 0)
656 
657  const double timeDiff = difftime(cur_time, mUpdateTimer);
658  const int timeLimit = isWindowVisible() ? 20 : 120;
659 
660  if (mUpdateOnlineList && timeDiff >= timeLimit
662  {
663  if (mDownloadComplete == true)
664  {
665  // TRANSLATORS: who is online window name
666  setCaption(_("Who Is Online - Updating"));
667  mUpdateTimer = 0;
669  download();
670  }
671  }
672 
673 #ifdef TMWA_SUPPORT
674  switch (mDownloadStatus)
675  {
676  case UPDATE_ERROR:
677  logger->assertLog("Failed to fetch the online list:");
678  if (mCurlError != nullptr)
679  logger->assertLog("%s", mCurlError);
681  // TRANSLATORS: who is online window name
682  setCaption(_("Who Is Online - error"));
683  mUpdateButton->setEnabled(true);
684  mUpdateTimer = cur_time + 240;
685  mDownloadComplete = true;
686  updateSize();
687  break;
688  case UPDATE_LIST:
689  if (mDownloadComplete == true)
690  {
691  loadWebList();
693  mUpdateButton->setEnabled(true);
694  mUpdateTimer = 0;
695  updateSize();
696  if (!mOnlineNicks.empty())
697  {
698  if (chatWindow != nullptr)
700  if (socialWindow != nullptr)
702  if (actorManager != nullptr)
704  }
705  }
706  break;
707  case UPDATE_COMPLETE:
708  default:
709  break;
710  }
711 #endif // TMWA_SUPPORT
712 
713  BLOCK_END("WhoIsOnline::slowLogic")
714 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
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:95
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:476
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:523
void assertLog(const char *const log_text,...)
Definition: logger.cpp:280
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 753 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().

754 {
755  const Rect area = getChildrenArea();
756  if (mUpdateButton != nullptr)
757  mUpdateButton->setWidth(area.width - 10);
758 
759  if (mScrollArea != nullptr)
760  mScrollArea->setSize(area.width - 10, area.height - 10 - 30);
761 }
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:1461
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 236 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().

237 {
238  // Set window caption
239  // TRANSLATORS: who is online window name
240  setCaption(_("Who Is Online - ") + toString(CAST_U32(numOnline)));
241 
242  // List the online people
243  std::sort(mFriends.begin(), mFriends.end(), nameCompare);
244  std::sort(mNeutral.begin(), mNeutral.end(), nameCompare);
245  std::sort(mDisregard.begin(), mDisregard.end(), nameCompare);
246  bool addedFromSection(false);
247  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mFriends)
248  {
249  mBrowserBox->addRow((*it)->getText());
250  addedFromSection = true;
251  }
252  if (addedFromSection == true)
253  {
254  mBrowserBox->addRow("---");
255  addedFromSection = false;
256  }
257  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mEnemy)
258  {
259  mBrowserBox->addRow((*it)->getText());
260  addedFromSection = true;
261  }
262  if (addedFromSection == true)
263  {
264  mBrowserBox->addRow("---");
265  addedFromSection = false;
266  }
267  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mNeutral)
268  {
269  mBrowserBox->addRow((*it)->getText());
270  addedFromSection = true;
271  }
272  if (addedFromSection == true && !mDisregard.empty())
273  mBrowserBox->addRow("---");
274 
275  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mDisregard)
276  mBrowserBox->addRow((*it)->getText());
277 
280  {
283  }
285 }
#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:523
void addRow(const std::string &row, const bool atTop=false)

◆ widgetResized()

void WhoIsOnline::widgetResized ( const Event event)
virtual

Called whenever the widget changes size.

Reimplemented from Window.

Definition at line 747 of file whoisonline.cpp.

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

Referenced by postInit().

748 {
749  Window::widgetResized(event);
750  updateSize();
751 }
void widgetResized(const Event &event)
Definition: window.cpp:643
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: