Atrinik Server 2.5
Defines | Functions | Variables
socket/request.c File Reference
#include <global.h>

Go to the source code of this file.

Defines

#define GET_CLIENT_FLAGS(_O_)   ((_O_)->flags[0] & 0x7f)
#define NO_FACE_SEND   (-1)
#define AddIfInt(Old, New, Type)
#define AddIfInt64(Old, New, Type)
#define AddIfShort(Old, New, Type)
#define AddIfChar(Old, New, Type)
#define AddIfFloat(Old, New, Type)
#define AddIfString(Old, New, Type)
#define map_clearcell(_cell_)

Functions

static void parse_srv_setup (char *param, char *cmdback, int type)
void SetUp (char *buf, int len, socket_struct *ns)
void AddMeCmd (char *buf, int len, socket_struct *ns)
void PlayerCmd (char *buf, int len, player *pl)
void ReplyCmd (char *buf, int len, player *pl)
static void version_mismatch_msg (socket_struct *ns)
void RequestFileCmd (char *buf, int len, socket_struct *ns)
void VersionCmd (char *buf, int len, socket_struct *ns)
void MoveCmd (char *buf, int len, player *pl)
void send_query (socket_struct *ns, uint8 flags, char *text)
void add_skill_to_skilllist (object *skill, StringBuffer *sb)
void esrv_update_skills (player *pl)
void esrv_update_stats (player *pl)
void esrv_new_player (player *pl, uint32 weight)
static int get_tiled_map_id (player *pl, struct mapdef *map)
static void copy_lastmap (socket_struct *ns, int dx, int dy)
void draw_client_map (object *pl)
static const char * get_playername_color (object *pl, object *op)
void draw_client_map2 (object *pl)
void ShopCmd (char *buf, int len, player *pl)
void QuestListCmd (char *data, int len, player *pl)
void command_clear_cmds (char *buf, int len, socket_struct *ns)
void SetSound (char *buf, int len, socket_struct *ns)
void command_move_path (uint8 *buf, int len, player *pl)
void cmd_ready (uint8 *buf, int len, player *pl)
void command_fire (uint8 *buf, int len, player *pl)
void cmd_keepalive (char *buf, int len, socket_struct *ns)
void cmd_password_change (uint8 *buf, int len, player *pl)

Variables

static int darkness_table [] = {0, 10, 30, 60, 120, 260, 480, 960}

Detailed Description

This file implements all of the goo on the server side for handling clients. It's got a bunch of global variables for keeping track of each of the clients.

Note:
All functions that are used to process data from the client have the prototype of (char *data, int datalen, int client_num). This way, we can use one dispatch table.

Definition in file request.c.


Define Documentation

#define AddIfChar (   Old,
  New,
  Type 
)
Value:
if (Old != New)                                         \
    {                                                       \
        Old = New;                                          \
        SockList_AddChar(&sl, (char) (Type));               \
        SockList_AddChar(&sl, (char) (New));                \
    }

Definition at line 595 of file request.c.

#define AddIfFloat (   Old,
  New,
  Type 
)
Value:
if (Old != New)                                         \
    {                                                       \
        Old = New;                                          \
        SockList_AddChar(&sl, (char) Type);                 \
        SockList_AddInt(&sl, (long) (New * FLOAT_MULTI));   \
    }

Definition at line 603 of file request.c.

#define AddIfInt (   Old,
  New,
  Type 
)
Value:
if (Old != New)                                         \
    {                                                       \
        Old = New;                                          \
        SockList_AddChar(&sl, (char) (Type));               \
        SockList_AddInt(&sl, (uint32) (New));               \
    }

Definition at line 571 of file request.c.

#define AddIfInt64 (   Old,
  New,
  Type 
)
Value:
if (Old != New)                                         \
    {                                                       \
        Old = New;                                          \
        SockList_AddChar(&sl, Type);                        \
        SockList_AddInt64(&sl, New);                        \
    }

Definition at line 579 of file request.c.

#define AddIfShort (   Old,
  New,
  Type 
)
Value:
if (Old != New)                                         \
    {                                                       \
        Old = New;                                          \
        SockList_AddChar(&sl, (char) (Type));               \
        SockList_AddShort(&sl, (uint16) (New));             \
    }

Definition at line 587 of file request.c.

#define AddIfString (   Old,
  New,
  Type 
)
Value:
if (Old == NULL || strcmp(Old, New))                    \
    {                                                       \
        if (Old)                                            \
        {                                                   \
            free(Old);                                      \
        }                                                   \
                                                            \
        Old = strdup_local(New);                            \
        SockList_AddChar(&sl, (char) Type);                 \
        SockList_AddChar(&sl, (char) strlen(New));          \
        strcpy((char *) sl.buf + sl.len, New);              \
        sl.len += strlen(New);                              \
    }

Definition at line 611 of file request.c.

#define map_clearcell (   _cell_)
Value:
memset((_cell_), 0, sizeof(MapCell));      \
    (_cell_)->count = -1

Clears a map cell

Definition at line 869 of file request.c.


Function Documentation

void add_skill_to_skilllist ( object skill,
StringBuffer sb 
)

Helper function for send_skilllist_cmd() and esrv_update_skills(), adds one skill to buffer which is then sent to the client as the skill list command.

Parameters:
skillSkill object to add.
sbStringBuffer instance to add to.

Definition at line 632 of file request.c.

void AddMeCmd ( char *  buf,
int  len,
socket_struct ns 
)

The client has requested to be added to the game. This is what takes care of it.

We tell the client how things worked out.

Definition at line 269 of file request.c.

void cmd_keepalive ( char *  buf,
int  len,
socket_struct ns 
)

Client notifies the server that it is still alive.

Parameters:
bufData.
lenLength of data.
nsThe client's socket.

Definition at line 2190 of file request.c.

void cmd_password_change ( uint8 buf,
int  len,
player pl 
)

Client requests a password change for a player.

Parameters:
bufData.
lenLength of data.
plThe player.

Definition at line 2202 of file request.c.

void cmd_ready ( uint8 buf,
int  len,
player pl 
)

The ready command; client informs the server about new object to mark as ready.

Parameters:
bufData.
lenLength of the data.
plPlayer.

Definition at line 2075 of file request.c.

void command_clear_cmds ( char *  buf,
int  len,
socket_struct ns 
)

Clears the commands cache.

Parameters:
bufData.
lenLength.
nsSocket.

Definition at line 1974 of file request.c.

void command_fire ( uint8 buf,
int  len,
player pl 
)

The fire command used by client's range widget, and triggered by the player using ctrl + numpad.

Parameters:
bufData.
lenLength of the data.
plPlayer.

Definition at line 2144 of file request.c.

void command_move_path ( uint8 buf,
int  len,
player pl 
)

Player wants to move to a specified x,y (of the map view).

Parameters:
bufData.
lenLength of 'buf'.
plPlayer.

Definition at line 2000 of file request.c.

static void copy_lastmap ( socket_struct ns,
int  dx,
int  dy 
) [inline, static]

Copy socket's last map according to new coordinates.

Parameters:
nsSocket.
dxX.
dyY.

Definition at line 903 of file request.c.

void draw_client_map ( object pl)

Do some checks, map name and LOS and then draw the map.

Parameters:
plWhom to draw map for.

Definition at line 928 of file request.c.

void draw_client_map2 ( object pl)

Draw the client map.

Definition at line 1210 of file request.c.

void esrv_new_player ( player pl,
uint32  weight 
)

Tells the client that here is a player it should start using.

Definition at line 849 of file request.c.

void esrv_update_skills ( player pl)

Send the player skills to the client.

Parameters:
plPlayer to send the skills to.

Definition at line 654 of file request.c.

void esrv_update_stats ( player pl)

Sends player statistics update.

We look at the old values, and only send what has changed.

Stat mapping values are in newclient.h

Since this gets sent a lot, this is actually one of the few binary commands for now.

Definition at line 694 of file request.c.

static const char* get_playername_color ( object pl,
object op 
) [static]

Figure out player name color for the client to show, in HTML notation.

As you can see in this function, it is easy to add new player name colors, just check for the match and make it return the correct color.

Parameters:
plPlayer object that will get the map data sent to.
opPlayer object on the map, to get the name from.
Returns:
The color.

Definition at line 1192 of file request.c.

static int get_tiled_map_id ( player pl,
struct mapdef map 
) [inline, static]

Get ID of a tiled map by checking player::last_update.

Parameters:
plPlayer.
mapTiled map.
Returns:
ID of the tiled map, 0 if there is no match.

Definition at line 878 of file request.c.

void MoveCmd ( char *  buf,
int  len,
player pl 
)

Moves an object (typically, container to inventory).

Syntax:

move <to> <tag> <nrof>
Parameters:
bufData.
lenLength of data.
plPlayer.

Definition at line 540 of file request.c.

static void parse_srv_setup ( char *  param,
char *  cmdback,
int  type 
) [static]

Parse server file command from client (amf, hpf, etc).

Parameters:
paramParameter for the command.
cmdbackBuffer that will be sent back to the client.
typeID of the server file.

Definition at line 46 of file request.c.

void PlayerCmd ( char *  buf,
int  len,
player pl 
)

This handles the general commands from client (ie, north, fire, cast, etc).

Parameters:
buf
len
pl

Definition at line 305 of file request.c.

void QuestListCmd ( char *  data,
int  len,
player pl 
)

Client has requested quest list of a player.

Parameters:
dataData.
lenLength of the data.
plThe player.

Definition at line 1874 of file request.c.

void ReplyCmd ( char *  buf,
int  len,
player pl 
)

This is a reply to a previous query.

Definition at line 337 of file request.c.

void RequestFileCmd ( char *  buf,
int  len,
socket_struct ns 
)

Request a srv file.

Definition at line 384 of file request.c.

void send_query ( socket_struct ns,
uint8  flags,
char *  text 
)

Asks the client to query the user.

This way, the client knows it needs to send something back (vs just printing out a message).

Definition at line 562 of file request.c.

void SetSound ( char *  buf,
int  len,
socket_struct ns 
)

Sound related functions.

Definition at line 1985 of file request.c.

void SetUp ( char *  buf,
int  len,
socket_struct ns 
)

The Setup command.

The setup syntax is:

setup <cmdname1> <parameter> <cmdname2> <parameter>...

We send the status of the command back, or zero if the command is unknown. The client must then sort it out.

Definition at line 85 of file request.c.

void ShopCmd ( char *  buf,
int  len,
player pl 
)

Handles shop commands received from the player's client.

Parameters:
bufThe buffer
lenLength of the buffer
plThe player

Definition at line 1862 of file request.c.

static void version_mismatch_msg ( socket_struct ns) [static]

Send a version mismatch message.

Parameters:
nsThe socket to send the message to

Definition at line 377 of file request.c.

void VersionCmd ( char *  buf,
int  len,
socket_struct ns 
)

Client tells its its version.

Definition at line 494 of file request.c.


Variable Documentation

int darkness_table[] = {0, 10, 30, 60, 120, 260, 480, 960} [static]

Darkness table

Definition at line 1207 of file request.c.