Crossfire Server, Branches 1.12
R18729
|
#include <global.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <metaserver2.h>
#include <version.h>
Go to the source code of this file.
Data Structures | |
struct | _LocalMeta2Info |
struct | _MetaServer2 |
Typedefs | |
typedef struct _LocalMeta2Info | LocalMeta2Info |
typedef struct _MetaServer2 | MetaServer2 |
Functions | |
static void | free_metaserver2 (MetaServer2 *ms) |
int | metaserver2_init (void) |
void * | metaserver2_thread (void *junk) |
static void | metaserver2_updates (void) |
static size_t | metaserver2_writer (void *ptr, size_t size, size_t nmemb, void *data) |
void | metaserver_init (void) |
void | metaserver_update (void) |
Variables | |
static LocalMeta2Info | local_info |
static int | metafd = -1 |
static MetaServer2 * | metaserver2 |
MetaServer2_UpdateInfo | metaserver2_updateinfo |
pthread_mutex_t | ms2_info_mutex |
static struct sockaddr_in | sock |
Definition in file metaserver.c.
typedef struct _LocalMeta2Info LocalMeta2Info |
LocalMeta2Info basically holds all the non 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 |
Start of metaserver2 logic Note: All static structures in this file should be treated as strictly private. The metaserver2 update logic runs in its own thread, so if something needs to modify these structures, proper locking is needed. This is a linked list of all the metaservers - never really know how many we have.
|
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.
Definition at line 236 of file metaserver.c.
References _MetaServer2::hostname.
Referenced by 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.
Definition at line 255 of file metaserver.c.
References _LocalMeta2Info::archbase, close_and_delete(), _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(), _MetaServer2::next, _LocalMeta2Info::notification, open_and_uncompress(), _LocalMeta2Info::portnumber, settings, snprintf(), strcasecmp(), strdup_local(), _LocalMeta2Info::text_comment, and TRUE.
Referenced by init().
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.
Definition at line 586 of file metaserver.c.
References metaserver2_updates(), and sleep.
Referenced by metaserver2_init().
|
static |
This sends an update to the various metaservers. It generates the form, and then sends it to the server
Definition at line 442 of file metaserver.c.
References _LocalMeta2Info::archbase, _LocalMeta2Info::codebase, _LocalMeta2Info::flags, FULL_VERSION, _MetaServer2::hostname, _LocalMeta2Info::hostname, _LocalMeta2Info::html_comment, _MetaServer2_UpdateInfo::in_bytes, _LocalMeta2Info::mapbase, MAX_BUF, metaserver2_writer(), _MetaServer2::next, _MetaServer2_UpdateInfo::num_players, _MetaServer2_UpdateInfo::out_bytes, _LocalMeta2Info::portnumber, snprintf(), _LocalMeta2Info::text_comment, _MetaServer2_UpdateInfo::uptime, VERSION_CS, and VERSION_SC.
Referenced by metaserver2_thread().
|
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.
Definition at line 427 of file metaserver.c.
References llevDebug, and LOG().
Referenced by metaserver2_updates().
void metaserver_init | ( | void | ) |
Connects to metaserver.
Its only called once. If we are not trying to contact the metaserver of the connection attempt fails, metafd will be set to -1. We use this instead of messing with the settings.meta_on so that that can be examined to at least see what the user was trying to do.
Definition at line 68 of file metaserver.c.
References llevDebug, LOG(), MAX_BUF, Settings::meta_host, Settings::meta_on, Settings::meta_port, Settings::meta_server, metafd, settings, and sock.
Referenced by init().
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 134 of file metaserver.c.
References cst_tot, first_player, FLAG_AFK, FLAG_WIZ, FULL_VERSION, pl::hidden, CS_Stats::ibytes, _MetaServer2_UpdateInfo::in_bytes, socket_struct::is_bot, llevDebug, LOG(), obj::map, MAX_BUF, Settings::meta_comment, Settings::meta_host, metafd, metaserver2_updateinfo, ms2_info_mutex, pl::next, _MetaServer2_UpdateInfo::num_players, pl::ob, CS_Stats::obytes, _MetaServer2_UpdateInfo::out_bytes, QUERY_FLAG, settings, snprintf(), sock, 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().
|
static |
Definition at line 223 of file metaserver.c.
|
static |
Definition at line 56 of file metaserver.c.
Referenced by metaserver_init(), and metaserver_update().
|
static |
Definition at line 201 of file metaserver.c.
Referenced by metaserver2_init().
MetaServer2_UpdateInfo metaserver2_updateinfo |
Definition at line 228 of file metaserver.c.
Referenced by metaserver_update().
pthread_mutex_t ms2_info_mutex |
The current implementation of crossfire is not very thread friendly/safe - in fact, metaserver2 is the first part to use an extra thread. As such, it would be a lot of work to add the necessary locks in the rest of the code for the metaserver2 to be able to get the data it needs. So instead, we use this MS2UpdateInfo structure to get the data from the main thread to the metaserver thread - basically, the main thread gets a lock on the mutex, updates the fields in this structure and releases the lock. The metaserver2 thread will get a lock when it needs to get this information, copy it to the post form, then unlock the structure. In that way, neither side holds the lock very long, which is especially important because the metaserver2 thread could take quite a while to do its updates.
Definition at line 226 of file metaserver.c.
Referenced by metaserver_update().
|
static |
Definition at line 58 of file metaserver.c.
Referenced by metaserver_init(), and metaserver_update().