Crossfire Server, Trunk
metaserver.cpp File Reference
#include "global.h"
#include <ctype.h>
#include <string>
#include <mutex>
#include <thread>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include "metaserver2.h"
#include "version.h"
+ Include dependency graph for metaserver.cpp:

Go to the source code of this file.

Data Structures

struct  LocalMeta2Info


int count_players ()
void metaserver2_exit ()
int metaserver2_init (void)
void metaserver2_thread ()
static void metaserver2_updates (void)
static size_t metaserver2_writer (void *ptr, size_t size, size_t nmemb, void *data)
void metaserver_update (void)


static LocalMeta2Info local_info
MetaServer2_UpdateInfo metaserver2_updateinfo
static std::thread metaserver_thread
static std::vector< std::string > metaservers
static std::mutex ms2_info_mutex
static std::timed_mutex ms2_signal

Detailed Description

Meta-server related functions.


Definition in file metaserver.cpp.

Function Documentation

◆ count_players()

int count_players ( )

Definition at line 48 of file metaserver.cpp.

References first_player, FLAG_AFK, FLAG_WIZ, altar_valkyrie::pl, QUERY_FLAG, ST_GET_PARTY_PASSWORD, and ST_PLAYING.

Referenced by check_shutdown(), and metaserver_update().

+ Here is the caller graph for this function:

◆ metaserver2_exit()

void metaserver2_exit ( )

Stop metaserver updates.

Definition at line 485 of file metaserver.cpp.

References metaserver_thread, and ms2_signal.

Referenced by cleanup().

+ Here is the caller graph for this function:

◆ metaserver2_init()

int metaserver2_init ( void  )

This initializes the metaserver2 logic - it reads the metaserver2 file, storing the values away. Note that it may be possible/desirable for the server to re-read the values and restart connections (for example, a new metaserver has been added and you want to start updates to it immediately and not restart the server). Because of that, there is some extra logic (has_init) to try to take that into account.

1 if we will be updating the metaserver, 0 if no metaserver updates

Definition at line 324 of file metaserver.cpp.

References LocalMeta2Info::archbase, buf, LocalMeta2Info::codebase, Settings::confdir, Settings::csport, FALSE, LocalMeta2Info::flags, FREE_AND_CLEAR, LocalMeta2Info::hostname, LocalMeta2Info::html_comment, llevError, local_info, LOG(), LocalMeta2Info::mapbase, MAX_BUF, metaserver2_thread(), metaserver2_updateinfo, metaserver_thread, metaservers, ms2_signal, LocalMeta2Info::notification, LocalMeta2Info::portnumber, settings, strcasecmp(), strdup_local, LocalMeta2Info::text_comment, and TRUE.

Referenced by init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ metaserver2_thread()

void metaserver2_thread ( )

Repeatedly send updates to the metaserver, stopping when ms2_signal is acquired. Works in the background.

Definition at line 303 of file metaserver.cpp.

References metaserver2_updates(), ms2_signal, and seconds().

Referenced by metaserver2_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ metaserver2_updates()

static void metaserver2_updates ( void  )

This sends an update to the various metaservers. It generates the form, and then sends it to the server

Definition at line 259 of file metaserver.cpp.

References llevError, LOG(), metaserver2_writer(), metaservers, and altar_valkyrie::res.

Referenced by metaserver2_thread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ metaserver2_writer()

static size_t metaserver2_writer ( void *  ptr,
size_t  size,
size_t  nmemb,
void *  data 

Handles writing of HTTP request data from the metaserver2. We treat the data as a string. We should really pay attention to the header data, and do something clever if we get 404 codes or the like.

ptractual data.
sizesize of the data.
nmembnumber of elements.
datauser-provided data, unused.
number of bytes processed, always the full size.

Definition at line 145 of file metaserver.cpp.

References navar-midane_time::data, llevError, LOG(), and nlohmann::detail::void().

Referenced by metaserver2_updates().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ metaserver_update()

void metaserver_update ( void  )

Updates our info in the metaserver Note that this is used for both metaserver1 and metaserver2 - for metaserver2, it just copies dynamic data into private data structure, doing locking in the process.

Definition at line 80 of file metaserver.cpp.

References count_players(), cst_tot, CS_Stats::ibytes, MetaServer2_UpdateInfo::in_bytes, metaserver2_updateinfo, ms2_info_mutex, MetaServer2_UpdateInfo::num_players, CS_Stats::obytes, MetaServer2_UpdateInfo::out_bytes, CS_Stats::time_start, and MetaServer2_UpdateInfo::uptime.

Referenced by block_until_new_connection(), and do_specials().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ local_info

LocalMeta2Info local_info

Non volatile information on the server.

Definition at line 126 of file metaserver.cpp.

Referenced by metaserver2_init().

◆ metaserver2_updateinfo

MetaServer2_UpdateInfo metaserver2_updateinfo

Statistics on players and such sent to the metaserver2.

Definition at line 132 of file metaserver.cpp.

Referenced by metaserver2_init(), and metaserver_update().

◆ metaserver_thread

std::thread metaserver_thread

Metaserver thread, if notifications are enabled.

Definition at line 129 of file metaserver.cpp.

Referenced by metaserver2_exit(), and metaserver2_init().

◆ metaservers

std::vector<std::string> metaservers

Metaservers to send information to, list of hostnames.

Definition at line 103 of file metaserver.cpp.

Referenced by metaserver2_init(), and metaserver2_updates().

◆ ms2_info_mutex

std::mutex ms2_info_mutex

Mutex to protect access to metaserver2_updateinfo.

Definition at line 44 of file metaserver.cpp.

Referenced by metaserver_update().

◆ ms2_signal

std::timed_mutex ms2_signal

Mutex to signal the thread should stop.

Definition at line 46 of file metaserver.cpp.

Referenced by metaserver2_exit(), metaserver2_init(), and metaserver2_thread().