Crossfire Client, Trunk  R19673
Functions | Variables
metaserver.c File Reference

Deals with contacting the metaserver, getting a list of hosts, displaying and returning them to calling function, and then connecting to the server when requested. More...

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include "client.h"
#include "external.h"
#include "metaserver.h"
Include dependency graph for metaserver.c:

Go to the source code of this file.

Functions

static int get_metaserver2_data (char *metaserver2)
 Connects to the URL and gets metaserver data. More...
 
int meta_sort (Meta_Info *m1, Meta_Info *m2)
 
static void * metaserver2_thread ()
 Thread function that goes off and collects metaserver data. More...
 
static size_t metaserver2_writer (void *ptr, size_t size, size_t nmemb, void *data)
 Curl doesn't really have any built in way to get data from the URL into string data - instead, we get a blob of data which we need to find the newlines, etc from. More...
 
void metaserver_cache_add (const char *server_name, const char *server_ip)
 Add a server to the players server cache file. More...
 
static void metaserver_cache_load (void)
 Load server names and addresses or DNS names from a cache file found in the player's client data folder. More...
 
static void metaserver_cache_save (void)
 
int metaserver_check_status ()
 Sees if we are gathering data or not. More...
 
int metaserver_check_version (int entry)
 This checks the servers sc_version and cs_version to see if they are compatible. More...
 
int metaserver_get ()
 Fetch a list of public servers from the official metaserver. More...
 
void metaserver_init ()
 Initialize metaserver functions. More...
 

Variables

static char * cached_server_file = NULL
 
char * cached_servers_ip [CACHED_SERVERS_MAX]
 
static int cached_servers_loaded = 0
 
char * cached_servers_name [CACHED_SERVERS_MAX]
 
int cached_servers_num = 0
 
int meta_numservers = 0
 
Meta_Infometa_servers = NULL
 
static char * metaservers [] = {"http://crossfire.real-time.com/metaserver2/meta_client.php"}
 
GMutex ms2_info_mutex
 
static int ms2_is_running = 0
 

Detailed Description

Deals with contacting the metaserver, getting a list of hosts, displaying and returning them to calling function, and then connecting to the server when requested.

Definition in file metaserver.c.

Function Documentation

static int get_metaserver2_data ( char *  metaserver2)
static

Connects to the URL and gets metaserver data.

Parameters
metaserver2metaserver to connect to.
Returns
TRUE if successfull, false is failed for some reason.

Definition at line 425 of file metaserver.c.

References metaserver2_writer().

Referenced by metaserver2_thread().

Here is the call graph for this function:

Here is the caller graph for this function:

int meta_sort ( Meta_Info m1,
Meta_Info m2 
)

Definition at line 38 of file metaserver.c.

References Meta_Info::hostname.

Referenced by metaserver2_thread(), and prompt_metaserver().

Here is the caller graph for this function:

static void* metaserver2_thread ( )
static

Thread function that goes off and collects metaserver data.

Returns
exits when job is done, no return value.

Definition at line 458 of file metaserver.c.

References get_metaserver2_data(), meta_numservers, meta_sort(), metaservers, ms2_info_mutex, and ms2_is_running.

Referenced by metaserver_get().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Curl doesn't really have any built in way to get data from the URL into string data - instead, we get a blob of data which we need to find the newlines, etc from.

Curl also provides the data in multiple calls if there is lots of data, and does not break the data on newline, so we need to store the extra (unprocessed) data from one call to the next.

Parameters
ptrpointer to data to process.
size
nmembthe size of each piece of data, and the number of these elements. We always presume the data is byte sized, and just multiple these together to get total amount of data.
datauser supplied data pointer - in this case, it points to a buffer which is used to store unprocessed information from one call to the next.
Returns
Number of bytes processed. We always return the total number of bytes supplied - returning anything else is an error to CURL

Definition at line 286 of file metaserver.c.

References Meta_Info::cs_version, Meta_Info::idle_time, Meta_Info::in_bytes, LOG(), LOG_CRITICAL, LOG_ERROR, meta_numservers, ms2_info_mutex, Meta_Info::num_players, Meta_Info::out_bytes, Meta_Info::port, Meta_Info::sc_version, and Meta_Info::uptime.

Referenced by get_metaserver2_data().

Here is the call graph for this function:

Here is the caller graph for this function:

void metaserver_cache_add ( const char *  server_name,
const char *  server_ip 
)

Add a server to the players server cache file.

Parameters
server_name
server_ip

Definition at line 169 of file metaserver.c.

References cached_servers_ip, CACHED_SERVERS_MAX, cached_servers_name, cached_servers_num, metaserver_cache_save(), MIN, and name.

Referenced by metaserver_connect_to().

Here is the call graph for this function:

Here is the caller graph for this function:

static void metaserver_cache_load ( void  )
static

Load server names and addresses or DNS names from a cache file found in the player's client data folder.

The cache file has traditionally been named "servers.cache". The server cache file is a plain text file that is line-feed delimited. Cache entries consist of two lines each and if the file has an odd number of lines, the last entry is ignored. The first line of a cache entry is the name of the server, and the second line is an IP address or DNS hostname. Metaserver uses both entries. Metaserver 2 uses only the name since most servers set the name to a hostname anyway. The load function does no parsing, so the entries must be in the correct order. There is no mechanism to support comments. If a file has an odd number of lines, the loader assumes the last line is an incomplete entry and silently discards it.

Definition at line 110 of file metaserver.c.

References cached_server_file, cached_servers_ip, cached_servers_loaded, CACHED_SERVERS_MAX, cached_servers_name, cached_servers_num, MS_LARGE_BUF, and name.

Referenced by metaserver_get().

Here is the caller graph for this function:

static void metaserver_cache_save ( void  )
static

Definition at line 144 of file metaserver.c.

References cached_server_file, cached_servers_ip, cached_servers_name, cached_servers_num, and server.

Referenced by metaserver_cache_add().

Here is the caller graph for this function:

int metaserver_check_status ( void  )

Sees if we are gathering data or not.

Note that we don't have to check to see what update methods are being used - the is_running flag is initialized to zero no matter if we are using that method to get the data, and unless we are using ms1 or ms2, the is_running flag will never get changed to be non-zero.

Returns
Returns 1 if if we are getting data, 0 if nothing is going on right now.

Definition at line 549 of file metaserver.c.

References ms2_info_mutex, and ms2_is_running.

Referenced by prompt_metaserver().

Here is the caller graph for this function:

int metaserver_check_version ( int  entry)

This checks the servers sc_version and cs_version to see if they are compatible.

Parameters
entryentry number in the metaservers array to check.
Returns
1 if this entry is compatible, 0 if it is not. Note that this can only meaningfully check metaserver2 data - metaserver1 doesn't include protocol version number, so treats all of those as OK.

Definition at line 53 of file metaserver.c.

References VERSION_CS, and VERSION_SC.

Referenced by prompt_metaserver().

Here is the caller graph for this function:

int metaserver_get ( void  )

Fetch a list of public servers from the official metaserver.

Definition at line 480 of file metaserver.c.

References LOG(), LOG_ERROR, MAX_METASERVER, meta_numservers, metaserver2_thread(), metaserver_cache_load(), ms2_info_mutex, and ms2_is_running.

Referenced by prompt_metaserver().

Here is the call graph for this function:

Here is the caller graph for this function:

void metaserver_init ( void  )

Initialize metaserver functions.

Always call this function before using any of the metaserver-related functions or variables.

Definition at line 517 of file metaserver.c.

References cache_dir, cached_server_file, and MAX_BUF.

Referenced by client_init().

Here is the caller graph for this function:

Variable Documentation

char* cached_server_file = NULL
static

Definition at line 94 of file metaserver.c.

Referenced by metaserver_cache_load(), metaserver_cache_save(), and metaserver_init().

char* cached_servers_ip[CACHED_SERVERS_MAX]
int cached_servers_loaded = 0
static

Definition at line 93 of file metaserver.c.

Referenced by metaserver_cache_load().

char* cached_servers_name[CACHED_SERVERS_MAX]
int cached_servers_num = 0
int meta_numservers = 0
Meta_Info* meta_servers = NULL

Definition at line 34 of file metaserver.c.

Referenced by prompt_metaserver().

char* metaservers[] = {"http://crossfire.real-time.com/metaserver2/meta_client.php"}
static

Definition at line 260 of file metaserver.c.

Referenced by metaserver2_thread().

GMutex ms2_info_mutex
int ms2_is_running = 0
static

Definition at line 250 of file metaserver.c.

Referenced by metaserver2_thread(), metaserver_check_status(), and metaserver_get().