Crossfire Client, Branches  R11627
metaserver.c File Reference
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <client.h>
#include <cconfig.h>
#include <external.h>
#include <metaserver.h>
+ Include dependency graph for metaserver.c:

Go to the source code of this file.

Functions

int check_server_version (int entry)
 
static int get_metaserver2_data (char *metaserver2)
 
void init_metaserver (void)
 
int metaserver1_get_info (void)
 
void * metaserver1_thread (void *junk)
 
int metaserver2_get_info (void)
 
void * metaserver2_thread (void *junk)
 
size_t metaserver2_writer (void *ptr, size_t size, size_t nmemb, void *data)
 
int metaserver_check_status (void)
 
int metaserver_get_info (char *metaserver, int meta_port)
 
static void metaserver_load_cache (void)
 
static void metaserver_save_cache (void)
 
int metaserver_select (char *sel)
 
void metaserver_show (int show_selection)
 

Variables

const 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"}
 
static int ms1_is_running =0
 
pthread_mutex_t ms2_info_mutex
 
static int ms2_is_running =0
 
const char *const rcsid_common_metaserver_c
 

Function Documentation

int check_server_version ( int  entry)

Definition at line 69 of file metaserver.c.

References VERSION_CS, and VERSION_SC.

Referenced by get_metaserver(), and metaserver_show().

+ Here is the caller graph for this function:

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 369 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:

void init_metaserver ( void  )

Does single use initalization of metaserver2 variables.

Definition at line 459 of file metaserver.c.

References ms2_info_mutex.

Referenced by init_client_vars().

+ Here is the caller graph for this function:

int metaserver1_get_info ( void  )

Definition at line 729 of file metaserver.c.

References LOG(), LOG_ERROR, MAX_METASERVER, metaserver1_thread(), metaserver_load_cache(), metaserver_on, ms1_is_running, and ms2_info_mutex.

Referenced by metaserver_get_info().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* metaserver1_thread ( void *  junk)
int metaserver2_get_info ( void  )

this is basically a replacement to the metaserver_get_info - idea being that when metaserver 1 support goes away, just yank that entire function and replace it with this.

Returns
best I can tell, always returns 0

Definition at line 423 of file metaserver.c.

References LOG(), LOG_ERROR, MAX_METASERVER, metaserver2_on, metaserver2_thread(), metaserver_load_cache(), ms2_info_mutex, and ms2_is_running.

Referenced by metaserver_get_info().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* metaserver2_thread ( void *  junk)

Thread function that goes off and collects metaserver data.

Returns
exits when job is done, no return value.

Definition at line 397 of file metaserver.c.

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

Referenced by metaserver2_get_info().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Curle 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 214 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:

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

References ms1_is_running, ms2_info_mutex, and ms2_is_running.

Referenced by get_metaserver(), and metaserver_show().

+ Here is the caller graph for this function:

int metaserver_get_info ( char *  metaserver,
int  meta_port 
)

Definition at line 791 of file metaserver.c.

References meta_numservers, metaserver1_get_info(), metaserver2_get_info(), and metaserver_on.

Referenced by do_metaserver(), main(), and metaserver_select().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void metaserver_load_cache ( void  )
static

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

+ Here is the caller graph for this function:

static void metaserver_save_cache ( 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_select().

+ Here is the caller graph for this function:

int metaserver_select ( char *  sel)
void metaserver_show ( int  show_selection)

Definition at line 807 of file metaserver.c.

References cached_servers_ip, cached_servers_name, cached_servers_num, check_server_version(), draw_info(), meta_numservers, meta_sort(), metaserver_check_status(), ms2_info_mutex, NDI_BLACK, and server.

Referenced by do_metaserver(), main(), and metaserver_select().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const char* cached_server_file = NULL

Definition at line 107 of file metaserver.c.

Referenced by main(), metaserver_load_cache(), and metaserver_save_cache().

int cached_servers_loaded = 0
static

Definition at line 106 of file metaserver.c.

Referenced by metaserver_load_cache().

int cached_servers_num = 0
Meta_Info* meta_servers = NULL

Definition at line 55 of file metaserver.c.

Referenced by get_metaserver().

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

Definition at line 188 of file metaserver.c.

Referenced by metaserver2_thread().

int ms1_is_running =0
static

Definition at line 478 of file metaserver.c.

Referenced by metaserver1_get_info(), metaserver1_thread(), and metaserver_check_status().

int ms2_is_running =0
static

Definition at line 178 of file metaserver.c.

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

const char* const rcsid_common_metaserver_c
Initial value:
=
"$Id: metaserver.c 11626 2009-04-04 12:41:46Z lalo $"

Definition at line 1 of file metaserver.c.