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.

133  {
134  UPDATE_ERROR = 0,
137  };

Constructor & Destructor Documentation

◆ WhoIsOnline()

WhoIsOnline::WhoIsOnline ( )

Constructor.

Definition at line 99 of file whoisonline.cpp.

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

References mCurlError, and Window::setWindowName().

◆ ~WhoIsOnline()

WhoIsOnline::~WhoIsOnline ( )

Destructor

Definition at line 178 of file whoisonline.cpp.

179 {
180  config.removeListeners(this);
182 
184  mThread = nullptr;
185  free(mMemoryBuffer);
186  mMemoryBuffer = nullptr;
187 
188  // Remove possibly leftover temporary download
189  delete []mCurlError;
190 
191  FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
192  delete *itd;
193  mOnlinePlayers.clear();
194  mOnlineNicks.clear();
195 }
void removeListeners(ConfigListener *const listener)
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
#define CHECKLISTENERS
Definition: localconsts.h:277
void WaitThread(SDL_Thread *const thread)
Definition: sdlhelper.cpp:195

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

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

724 {
725  if (event.getId() == "update")
726  {
727 #ifdef TMWA_SUPPORT
728  if (!mServerSideList)
729  {
731  {
732  mUpdateTimer = cur_time - 20;
733  if (mUpdateButton != nullptr)
734  mUpdateButton->setEnabled(false);
735  // TRANSLATORS: who is online window name
736  setCaption(_("Who Is Online - Update"));
738  mThread = nullptr;
739  mDownloadComplete = true;
740  }
741  }
742  else
743 #endif // TMWA_SUPPORT
744  {
746  {
749  }
750  }
751  }
752 }
volatile time_t cur_time
Definition: timer.cpp:58
virtual void requestOnlineList() const =0
void setEnabled(const bool enabled)
Definition: widget.h:352
void setCaption(const std::string &caption)
Definition: window.h:531
bool limitPackets(const PacketTypeT type)
@ PACKET_ONLINELIST
Definition: packettype.h:40
Net::PlayerHandler * playerHandler
Definition: net.cpp:96

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

◆ download()

void WhoIsOnline::download ( )
private

Definition at line 626 of file whoisonline.cpp.

627 {
628  if (mServerSideList)
629  {
632  }
633 #ifdef TMWA_SUPPORT
634  else if (mWebList)
635  {
636  mDownloadComplete = true;
638  mThread = nullptr;
639  mDownloadComplete = false;
641  "whoisonline", this);
642  if (mThread == nullptr)
644  }
645 #endif // TMWA_SUPPORT
646 }
static int downloadThread(void *ptr)
SDL_Thread * createThread(int(*fn)(void *), const char *const name, void *const data)
Definition: sdlhelper.cpp:118

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(), and slowLogic().

◆ downloadThread()

int WhoIsOnline::downloadThread ( void *  ptr)
staticprivate

The thread function that download the files.

Definition at line 531 of file whoisonline.cpp.

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

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

◆ getOnlineNicks()

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

Definition at line 85 of file whoisonline.h.

87  { return mOnlineNicks; }

References mOnlineNicks.

Referenced by SocialFriendsTab::getPlayersAvatars().

◆ getOnlinePlayers()

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

Definition at line 81 of file whoisonline.h.

83  { return mOnlinePlayers; }

References mOnlinePlayers.

◆ getPlayerNames()

void WhoIsOnline::getPlayerNames ( StringVect names)

Definition at line 853 of file whoisonline.cpp.

854 {
855  names.clear();
856  FOR_EACH (std::set<std::string>::const_iterator, it, mOnlineNicks)
857  names.push_back(*it);
858 }

References FOR_EACH, and mOnlineNicks.

Referenced by ChatWindow::autoComplete().

◆ handleLink()

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

Implements LinkHandler.

Definition at line 197 of file whoisonline.cpp.

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

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.

◆ handlerPlayerRelation()

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

Definition at line 293 of file whoisonline.cpp.

295 {
296  if (player == nullptr)
297  return;
298  switch (playerRelations.getRelation(nick))
299  {
300  case Relation::NEUTRAL:
301  default:
302  setNeutralColor(player);
303  mNeutral.push_back(player);
304  break;
305 
306  case Relation::FRIEND:
307  player->setText("2");
308  if (mGroupFriends)
309  mFriends.push_back(player);
310  else
311  mNeutral.push_back(player);
312  break;
313 
316  player->setText("8");
317  mDisregard.push_back(player);
318  break;
319 
320  case Relation::ENEMY2:
321  player->setText("1");
322  mEnemy.push_back(player);
323  break;
324 
325  case Relation::IGNORED:
326  case Relation::ERASED:
327  // Ignore the ignored.
328  break;
329  }
330 }
void setText(std::string str)
RelationT getRelation(const std::string &name) const
static void setNeutralColor(OnlinePlayer *const player)
@ DISREGARDED
Definition: relation.h:33
@ ENEMY2
Definition: relation.h:37
@ IGNORED
Definition: relation.h:34
@ FRIEND
Definition: relation.h:32
@ ERASED
Definition: relation.h:35
@ NEUTRAL
Definition: relation.h:31
@ BLACKLISTED
Definition: relation.h:36
PlayerRelationsManager playerRelations

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(), and loadWebList().

◆ loadList()

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

Definition at line 332 of file whoisonline.cpp.

333 {
335  const size_t numOnline = list.size();
336 
337  FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
338  delete *itd;
339  mOnlinePlayers.clear();
340  mOnlineNicks.clear();
341 
342  mShowLevel = config.getBoolValue("showlevel");
343 
344  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, list)
345  {
346  OnlinePlayer *player = *it;
347  const std::string nick = player->getNick();
348  mOnlinePlayers.insert(player);
349  mOnlineNicks.insert(nick);
350 
351  if (!mShowLevel)
352  player->setLevel(0);
353 
354  handlerPlayerRelation(nick, player);
355  }
356 
357  updateWindow(numOnline);
358  if (!mOnlineNicks.empty())
359  {
360  if (chatWindow != nullptr)
362  if (socialWindow != nullptr)
364  if (actorManager != nullptr)
366  }
367  updateSize();
368  mFriends.clear();
369  mNeutral.clear();
370  mDisregard.clear();
371  mEnemy.clear();
372 }
void updateSeenPlayers(const std::set< std::string > &onlinePlayers)
void updateOnline(const std::set< std::string > &onlinePlayers) const
const std::string getNick() const
Definition: onlineplayer.h:53
void setLevel(const char level)
Definition: onlineplayer.h:73
void updateActiveList()
void updateSize()
void handlerPlayerRelation(const std::string &nick, OnlinePlayer *const player)
void updateWindow(size_t numOnline)
SocialWindow * socialWindow

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(), and TmwAthena::PlayerRecv::processOnlineList().

◆ loadWebList()

void WhoIsOnline::loadWebList ( )

Loads and display online list from the memory buffer.

Definition at line 375 of file whoisonline.cpp.

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

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

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

649 {
650  BLOCK_START("WhoIsOnline::logic")
651  mScrollArea->logic();
653 }
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

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

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

513 {
514  if (stream == nullptr)
515  return 0;
516 
517  WhoIsOnline *restrict const wio =
518  reinterpret_cast<WhoIsOnline *restrict>(stream);
519  const size_t totalMem = size * nmemb;
520  wio->mMemoryBuffer = static_cast<char*>(realloc(wio->mMemoryBuffer,
521  CAST_SIZE(wio->mDownloadedBytes) + totalMem));
522  if (wio->mMemoryBuffer != nullptr)
523  {
524  memcpy(&(wio->mMemoryBuffer[wio->mDownloadedBytes]), ptr, totalMem);
525  wio->mDownloadedBytes += CAST_S32(totalMem);
526  }
527 
528  return totalMem;
529 }
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34
#define restrict
Definition: localconsts.h:165
int size()
Definition: emotedb.cpp:306

References CAST_S32, CAST_SIZE, restrict, and EmoteDB::size().

Referenced by downloadThread().

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

786 {
787  if (name == "updateOnlineList")
788  mUpdateOnlineList = config.getBoolValue("updateOnlineList");
789  else if (name == "groupFriends")
790  mGroupFriends = config.getBoolValue("groupFriends");
791 }

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

◆ postInit()

void WhoIsOnline::postInit ( )
virtual

Reimplemented from Window.

Definition at line 137 of file whoisonline.cpp.

138 {
140  const int h = 350;
141  const int w = 200;
143 
145  setCloseButton(true);
146  setResizable(true);
147  setStickyButtonLock(true);
148  setSaveVisible(true);
149 
150  if (setupWindow != nullptr)
152 
153  mUpdateButton->setEnabled(false);
154  mUpdateButton->setDimension(Rect(5, 5, w - 10, 20 + 5));
155 
157  mScrollArea->setDimension(Rect(5, 20 + 10, w - 10, h - 10 - 30));
158  mScrollArea->setSize(w - 10, h - 10 - 30);
159  mScrollArea->setSelectable(false);
161 
163  add(mScrollArea);
164 
166 
167  loadWindowState();
168  enableVisibleSound(true);
169 
170  download();
171 
172  widgetResized(Event(nullptr));
173  config.addListener("updateOnlineList", this);
174  config.addListener("groupFriends", this);
175  mGroupFriends = config.getBoolValue("groupFriends");
176 }
virtual void add(Widget *const widget)
void addListener(const std::string &key, ConfigListener *const listener)
Definition: event.h:79
Definition: rect.h:74
void setDimension(const Rect &dimension)
void registerWindowForReset(Window *const window)
void setOpaque(Opaque opaque)
void setLinkHandler(LinkHandler *linkHandler)
void widgetResized(const Event &event)
void download()
void setSize(const int width, const int height)
Definition: widget.cpp:367
void setDimension(const Rect &dimension)
Definition: widget.cpp:169
void setSelectable(const bool selectable)
Definition: widget.h:948
Widget * getParent() const
Definition: widget.h:202
void setSaveVisible(const bool save)
Definition: window.h:300
void setResizable(const bool resize)
Definition: window.cpp:627
virtual void setVisible(Visible visible)
Definition: window.cpp:778
void postInit()
Definition: window.cpp:249
void enableVisibleSound(bool b)
Definition: window.h:481
void setCloseButton(const bool flag)
Definition: window.cpp:749
void setStickyButtonLock(const bool sticky)
Definition: window.cpp:772
void setDefaultSize()
Definition: window.cpp:1198
void setLocationRelativeTo(const Widget *const widget)
Definition: window.cpp:509
void loadWindowState()
Definition: window.cpp:1087
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
const bool Visible_false
Definition: visible.h:30

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(), ScrollArea::setDimension(), Widget::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().

◆ prepareNick()

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

Definition at line 770 of file whoisonline.cpp.

774 {
775  const std::string text = encodeLinkText(nick);
776  if (mShowLevel && level > 1)
777  {
778  return strprintf("@@%s|##%s%s (%d)@@", text.c_str(),
779  color.c_str(), text.c_str(), level);
780  }
781  return strprintf("@@%s|##%s%s@@", text.c_str(),
782  color.c_str(), text.c_str());
783 }
std::string strprintf(const char *const format,...)
std::string encodeLinkText(std::string data)

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

◆ readFromWeb()

void WhoIsOnline::readFromWeb ( )

◆ setAllowUpdate()

void WhoIsOnline::setAllowUpdate ( const bool  n)
inline

Definition at line 89 of file whoisonline.h.

90  { mAllowUpdate = n; }

References mAllowUpdate.

Referenced by destroyGuiWindows().

◆ setNeutralColor()

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

Definition at line 793 of file whoisonline.cpp.

794 {
795  if (player == nullptr)
796  return;
797 
798  if ((actorManager != nullptr) && (localPlayer != nullptr))
799  {
800  const std::string &nick = player->getNick();
801  if (nick == localPlayer->getName())
802  {
803  player->setText("s");
804  return;
805  }
806  if (localPlayer->isInParty())
807  {
808  const Party *const party = localPlayer->getParty();
809  if (party != nullptr)
810  {
811  if (party->getMember(nick) != nullptr)
812  {
813  player->setText("P");
814  return;
815  }
816  }
817  }
818 
819  const Being *const being = actorManager->findBeingByName(nick,
821  if (being != nullptr)
822  {
823  const Guild *const guild2 = localPlayer->getGuild();
824  if (guild2 != nullptr)
825  {
826  const Guild *const guild1 = being->getGuild();
827  if (guild1 != nullptr)
828  {
829  if (guild1->getId() == guild2->getId()
830  || (guild2->getMember(nick) != nullptr))
831  {
832  player->setText("U");
833  return;
834  }
835  }
836  else if (guild2->isMember(nick))
837  {
838  player->setText("U");
839  return;
840  }
841  }
842  }
843  const Guild *const guild3 = Guild::getGuild(1);
844  if ((guild3 != nullptr) && guild3->isMember(nick))
845  {
846  player->setText("U");
847  return;
848  }
849  }
850  player->setText("0");
851 }
Party * getParty() const
Definition: being.h:330
const Guild * getGuild(const std::string &guildName) const
Definition: being.cpp:1258
bool isInParty() const
Definition: being.h:321
Definition: guild.h:70
bool isMember(const GuildMember *const member) const
Definition: guild.cpp:304
static Guild * getGuild(const int16_t id)
Definition: guild.cpp:374
int16_t getId() const
Definition: guild.h:135
GuildMember * getMember(const BeingId id) const
Definition: guild.cpp:140
Definition: party.h:63
uint32_t party

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

Referenced by handlerPlayerRelation().

◆ slowLogic()

void WhoIsOnline::slowLogic ( )

Definition at line 655 of file whoisonline.cpp.

656 {
657  if (!mAllowUpdate)
658  return;
659 
660  BLOCK_START("WhoIsOnline::slowLogic")
661  if (mUpdateTimer == 0)
663 
664  const double timeDiff = difftime(cur_time, mUpdateTimer);
665  const int timeLimit = isWindowVisible() ? 20 : 120;
666 
667  if (mUpdateOnlineList && timeDiff >= timeLimit
669  {
670  if (mDownloadComplete == true)
671  {
672  // TRANSLATORS: who is online window name
673  setCaption(_("Who Is Online - Updating"));
674  mUpdateTimer = 0;
676  download();
677  }
678  }
679 
680 #ifdef TMWA_SUPPORT
681  switch (mDownloadStatus)
682  {
683  case UPDATE_ERROR:
684  logger->assertLog("Failed to fetch the online list:");
685  if (mCurlError != nullptr)
686  logger->assertLog("%s", mCurlError);
688  // TRANSLATORS: who is online window name
689  setCaption(_("Who Is Online - error"));
690  mUpdateButton->setEnabled(true);
691  mUpdateTimer = cur_time + 240;
692  mDownloadComplete = true;
693  updateSize();
694  break;
695  case UPDATE_LIST:
696  if (mDownloadComplete == true)
697  {
698  loadWebList();
700  mUpdateButton->setEnabled(true);
701  mUpdateTimer = 0;
702  updateSize();
703  if (!mOnlineNicks.empty())
704  {
705  if (chatWindow != nullptr)
707  if (socialWindow != nullptr)
709  if (actorManager != nullptr)
711  }
712  }
713  break;
714  case UPDATE_COMPLETE:
715  default:
716  break;
717  }
718 #endif // TMWA_SUPPORT
719 
720  BLOCK_END("WhoIsOnline::slowLogic")
721 }
void assertLog(const char *const log_text,...)
Definition: logger.cpp:316
void loadWebList()
bool isWindowVisible() const
Definition: window.h:484
if(!vert) return
Logger * logger
Definition: logger.cpp:89

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

◆ updateList()

void WhoIsOnline::updateList ( StringVect list)

◆ updateSize()

void WhoIsOnline::updateSize ( )
private

Definition at line 760 of file whoisonline.cpp.

761 {
762  const Rect area = getChildrenArea();
763  if (mUpdateButton != nullptr)
764  mUpdateButton->setWidth(area.width - 10);
765 
766  if (mScrollArea != nullptr)
767  mScrollArea->setSize(area.width - 10, area.height - 10 - 30);
768 }
int width
Definition: rect.h:219
int height
Definition: rect.h:224
void setWidth(const int width)
Definition: widget.cpp:133
Rect getChildrenArea()
Definition: window.cpp:1473

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

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

◆ updateWindow()

void WhoIsOnline::updateWindow ( size_t  numOnline)
private

Definition at line 242 of file whoisonline.cpp.

243 {
244  // Set window caption
245  // TRANSLATORS: who is online window name
246  setCaption(_("Who Is Online - ") + toString(CAST_U32(numOnline)));
247 
248  // List the online people
249  std::sort(mFriends.begin(), mFriends.end(), nameCompare);
250  std::sort(mNeutral.begin(), mNeutral.end(), nameCompare);
251  std::sort(mDisregard.begin(), mDisregard.end(), nameCompare);
252  bool addedFromSection(false);
253  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mFriends)
254  {
255  mBrowserBox->addRow((*it)->getText(), false);
256  addedFromSection = true;
257  }
258  if (addedFromSection == true)
259  {
260  mBrowserBox->addRow("---", false);
261  addedFromSection = false;
262  }
263  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mEnemy)
264  {
265  mBrowserBox->addRow((*it)->getText(), false);
266  addedFromSection = true;
267  }
268  if (addedFromSection == true)
269  {
270  mBrowserBox->addRow("---", false);
271  addedFromSection = false;
272  }
273  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mNeutral)
274  {
275  mBrowserBox->addRow((*it)->getText(), false);
276  addedFromSection = true;
277  }
278  if (addedFromSection == true && !mDisregard.empty())
279  mBrowserBox->addRow("---", false);
280 
281  FOR_EACH (STD_VECTOR<OnlinePlayer*>::const_iterator, it, mDisregard)
282  mBrowserBox->addRow((*it)->getText(), false);
283 
286  {
289  }
291 }
void setVerticalScrollAmount(const int vScroll)
int getVerticalMaxScroll()
int getVerticalScrollAmount() const
Definition: scrollarea.h:274
void addRow(const std::string &row, const bool atTop)
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
class anonymous_namespace{whoisonline.cpp}::NameFunctuator nameCompare

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(), and loadWebList().

◆ widgetResized()

void WhoIsOnline::widgetResized ( const Event event)
virtual

Called whenever the widget changes size.

Reimplemented from Window.

Definition at line 754 of file whoisonline.cpp.

755 {
756  Window::widgetResized(event);
757  updateSize();
758 }
void widgetResized(const Event &event)
Definition: window.cpp:655

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

Referenced by postInit().

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: