Crossfire Client, Trunk  R19593
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 <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 <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)
 This checks the servers sc_version and cs_version to see if they are compatible. More...
 
static int get_metaserver2_data (char *metaserver2)
 Connects to the URL and gets metaserver data. More...
 
void init_metaserver (void)
 Does single use initalization of metaserver2 variables. More...
 
int meta_sort (Meta_Info *m1, Meta_Info *m2)
 
int metaserver1_get_info (void)
 
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. More...
 
void * metaserver2_thread (void *junk)
 Thread function that goes off and collects metaserver data. More...
 
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...
 
int metaserver_check_status (void)
 Sees if we are gathering data or not. More...
 
int metaserver_get_info (char *metaserver, int meta_port)
 This contacts the metaserver and gets the list of servers. More...
 
static void metaserver_load_cache (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_save_cache (void)
 
int metaserver_select (char *sel)
 String contains the selection that the player made for the metaserver. More...
 
void metaserver_show (int show_selection)
 Show the metaservers to the player. More...
 
void metaserver_update_cache (const char *server_name, const char *server_ip)
 Add a server to the players server cache file. More...
 

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
 

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

int check_server_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 63 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 437 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 537 of file metaserver.c.

References ms2_info_mutex.

Referenced by init_client_vars().

Here is the caller graph for this function:

int meta_sort ( Meta_Info m1,
Meta_Info m2 
)

Definition at line 47 of file metaserver.c.

References Meta_Info::hostname.

Referenced by get_metaserver(), metaserver1_thread(), metaserver2_thread(), and metaserver_show().

Here is the caller graph for this function:

int metaserver1_get_info ( void  )

Definition at line 821 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 501 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 471 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 
)

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 297 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 868 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 
)

This contacts the metaserver and gets the list of servers.

returns 0 on success, 1 on failure. Errors will get dumped to stderr, so most errors should be reasonably clear. metaserver and meta_port are the server name and port number to connect to.

Definition at line 886 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

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

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

Referenced by metaserver_update_cache().

Here is the caller graph for this function:

int metaserver_select ( char *  sel)

String contains the selection that the player made for the metaserver.

this may not be a a selection, but could be a host name or ip address. this returns 0 on sucessful selection, 1 if failure (invalid selection or the like.

Definition at line 970 of file metaserver.c.

References cached_servers_ip, cached_servers_name, cached_servers_num, CONFIG_PORT, csocket, draw_ext_info(), ClientSocket::fd, Meta_Info::hostname, init_connection(), Meta_Info::ip_addr, MAX_BUF, meta_numservers, meta_server, metaserver_get_info(), metaserver_show(), metaserver_update_cache(), ms2_info_mutex, MSG_TYPE_CLIENT, MSG_TYPE_CLIENT_METASERVER, NDI_BLACK, Meta_Info::port, server, and use_config.

Here is the call graph for this function:

void metaserver_show ( int  show_selection)

Show the metaservers to the player.

We use draw_ext_info() to do that, and also let the player know they can enter their own host name.

Definition at line 904 of file metaserver.c.

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

Referenced by do_metaserver(), and metaserver_select().

Here is the call graph for this function:

Here is the caller graph for this function:

void metaserver_update_cache ( 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 179 of file metaserver.c.

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

Referenced by metaserver_connect_to(), 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 105 of file metaserver.c.

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

char* cached_servers_ip[CACHED_SERVERS_MAX]
int cached_servers_loaded = 0
static

Definition at line 104 of file metaserver.c.

Referenced by metaserver_load_cache().

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

Definition at line 43 of file metaserver.c.

Referenced by get_metaserver().

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

Definition at line 271 of file metaserver.c.

Referenced by metaserver2_thread().

int ms1_is_running =0
static

Definition at line 556 of file metaserver.c.

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

pthread_mutex_t ms2_info_mutex
int ms2_is_running =0
static

Definition at line 261 of file metaserver.c.

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