Crossfire Server, Trunk  R20513
Data Structures | Typedefs | Functions | Variables
metaserver.c File Reference

Meta-server related functions. More...

#include "global.h"
#include <ctype.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#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.c:

Go to the source code of this file.

Data Structures

struct  _LocalMeta2Info
 LocalMeta2Info basically holds all the non server metaserver2 information that we read from the metaserver2 file. More...
 
struct  _MetaServer2
 This is a linked list of all the metaservers - never really know how many we have. More...
 

Typedefs

typedef struct _LocalMeta2Info LocalMeta2Info
 LocalMeta2Info basically holds all the non server metaserver2 information that we read from the metaserver2 file. More...
 
typedef struct _MetaServer2 MetaServer2
 This is a linked list of all the metaservers - never really know how many we have. More...
 

Functions

static void free_metaserver2 (MetaServer2 *ms)
 This frees any data associated with the MetaServer2 info, including the pointer itself. More...
 
int metaserver2_init (void)
 This initializes the metaserver2 logic - it reads the metaserver2 file, storing the values away. More...
 
void * metaserver2_thread (void *junk)
 metserver2_thread is the function called from pthread_create. More...
 
static void metaserver2_updates (void)
 This sends an update to the various metaservers. More...
 
static size_t metaserver2_writer (void *ptr, size_t size, size_t nmemb, void *data)
 Handles writing of HTTP request data from the metaserver2. More...
 
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. More...
 

Variables

static LocalMeta2Info local_info
 Non volatile information on the server. More...
 
static MetaServer2metaserver2
 Metaservers to send information to. More...
 
MetaServer2_UpdateInfo metaserver2_updateinfo
 Statistics on players and such sent to the metaserver2. More...
 
pthread_mutex_t ms2_info_mutex
 Mutex to protect access to metaserver2_updateinfo. More...
 

Detailed Description

Meta-server related functions.

Date
2003-12-02

Definition in file metaserver.c.

Typedef Documentation

LocalMeta2Info basically holds all the non server metaserver2 information that we read from the metaserver2 file.

Could just have individual variables, but doing it as a structure is cleaner I think, and might be more flexible if in the future, we want to pass this information to other functions (like plugin or something)

typedef struct _MetaServer2 MetaServer2

This is a linked list of all the metaservers - never really know how many we have.

Function Documentation

static void free_metaserver2 ( MetaServer2 ms)
static

This frees any data associated with the MetaServer2 info, including the pointer itself.

Caller is responsible for updating pointers (ms->next) - really only used when wanting to free all data.

Parameters
msdata to free, pointer becomes invalid.

Definition at line 144 of file metaserver.c.

References _MetaServer2::hostname.

Referenced by metaserver2_init().

Here is the caller graph for this function:

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.

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

Definition at line 163 of file metaserver.c.

References _LocalMeta2Info::archbase, _LocalMeta2Info::codebase, Settings::confdir, Settings::csport, FALSE, _LocalMeta2Info::flags, FREE_AND_CLEAR, free_metaserver2(), _MetaServer2::hostname, _LocalMeta2Info::hostname, _LocalMeta2Info::html_comment, llevError, LOG(), _LocalMeta2Info::mapbase, MAX_BUF, metaserver2, metaserver2_thread(), ms2_info_mutex, _MetaServer2::next, _LocalMeta2Info::notification, _LocalMeta2Info::portnumber, settings, snprintf, strcasecmp(), strdup(), 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:

void* metaserver2_thread ( void *  junk)

metserver2_thread is the function called from pthread_create.

it is a trivial function - it just sleeps and calls the update function. The sleep time here is really quite arbitrary, but once a minute is probably often enough. A better approach might be to do a time() call and see how long the update takes, and sleep according to that.

Parameters
junkunused.
Returns
This function should never return/exit.

Definition at line 503 of file metaserver.c.

References metaserver2_updates(), and sleep.

Referenced by metaserver2_init().

Here is the call graph for this function:

Here is the caller graph for this function:

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

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.

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

Definition at line 343 of file metaserver.c.

References llevDebug, and LOG().

Referenced by metaserver2_updates().

Here is the call graph for this function:

Here is the caller graph for this function:

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 49 of file metaserver.c.

References cst_tot, first_player, FLAG_AFK, FLAG_WIZ, pl::hidden, CS_Stats::ibytes, _MetaServer2_UpdateInfo::in_bytes, socket_struct::is_bot, obj::map, metaserver2_updateinfo, ms2_info_mutex, pl::next, _MetaServer2_UpdateInfo::num_players, pl::ob, CS_Stats::obytes, _MetaServer2_UpdateInfo::out_bytes, QUERY_FLAG, pl::socket, ST_GET_PARTY_PASSWORD, ST_PLAYING, pl::state, CS_Stats::time_start, and _MetaServer2_UpdateInfo::uptime.

Referenced by block_until_new_connection(), and do_specials().

Here is the caller graph for this function:

Variable Documentation

LocalMeta2Info local_info
static

Non volatile information on the server.

Definition at line 129 of file metaserver.c.

MetaServer2* metaserver2
static

Metaservers to send information to.

Definition at line 106 of file metaserver.c.

Referenced by metaserver2_init().

MetaServer2_UpdateInfo metaserver2_updateinfo

Statistics on players and such sent to the metaserver2.

Definition at line 135 of file metaserver.c.

Referenced by metaserver_update().

pthread_mutex_t ms2_info_mutex

Mutex to protect access to metaserver2_updateinfo.

Definition at line 132 of file metaserver.c.

Referenced by metaserver2_init(), metaserver2_updates(), and metaserver_update().