Crossfire Client, Trunk  R19733
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 <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "client.h"
#include "metaserver.h"
Include dependency graph for metaserver.c:

Go to the source code of this file.

Functions

static bool ms_check_version (Meta_Info *server)
 This checks the servers sc_version and cs_version to see if they are compatible. More...
 
void ms_fetch ()
 Fetch a list of servers from the built-in official metaservers. More...
 
bool ms_fetch_server (const char *metaserver2)
 Fetch a list of servers from the given URL. More...
 
void ms_init ()
 Initialize metaserver client. More...
 
void ms_set_callback (ms_callback function)
 Set a callback function to run whenever another metaserver is available. More...
 
static size_t ms_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...
 

Variables

static ms_callback callback
 Function to call when a new metaserver is available. More...
 
static const char * metaservers []
 

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 bool ms_check_version ( Meta_Info server)
static

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

References Meta_Info::cs_version, Meta_Info::sc_version, VERSION_CS, and VERSION_SC.

Referenced by ms_writer().

Here is the caller graph for this function:

void ms_fetch ( void  )

Fetch a list of servers from the built-in official metaservers.

Because this function can query multiple metaservers, the same servers may be listed multiple times in the results.

Definition at line 291 of file metaserver.c.

References metaservers, and ms_fetch_server().

Referenced by server_fetch().

Here is the call graph for this function:

Here is the caller graph for this function:

bool ms_fetch_server ( const char *  metaserver2)

Fetch a list of servers from the given URL.

Parameters
metaserver2
Returns

Definition at line 257 of file metaserver.c.

References ms_writer().

Referenced by ms_fetch().

Here is the call graph for this function:

Here is the caller graph for this function:

void ms_init ( void  )

Initialize metaserver client.

This function should be called before any other metaserver functions.

Definition at line 303 of file metaserver.c.

Referenced by client_init().

Here is the caller graph for this function:

void ms_set_callback ( ms_callback  function)

Set a callback function to run whenever another metaserver is available.

Parameters
function

Definition at line 54 of file metaserver.c.

References callback.

Referenced by prompt_metaserver().

Here is the caller graph for this function:

static size_t ms_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 127 of file metaserver.c.

References Meta_Info::archbase, callback, Meta_Info::codebase, Meta_Info::cs_version, EPORT, Meta_Info::flags, Meta_Info::hostname, Meta_Info::html_comment, Meta_Info::idle_time, Meta_Info::in_bytes, LOG(), LOG_CRITICAL, LOG_ERROR, Meta_Info::mapbase, ms_check_version(), MS_LARGE_BUF, Meta_Info::num_players, Meta_Info::out_bytes, Meta_Info::port, Meta_Info::sc_version, Meta_Info::text_comment, Meta_Info::uptime, and Meta_Info::version.

Referenced by ms_fetch_server().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

ms_callback callback
static

Function to call when a new metaserver is available.

Definition at line 48 of file metaserver.c.

Referenced by ms_set_callback(), ms_writer(), and setTextManager().

const char* metaservers[]
static
Initial value:
= {
"http://crossfire.real-time.com/metaserver2/meta_client.php",
"http://metaserver.eu.cross-fire.org/meta_client.php",
}

Definition at line 42 of file metaserver.c.

Referenced by ms_fetch().