Atrinik Server  4.0
Macros | Functions
request.c File Reference
#include <global.h>
#include <toolkit/packet.h>
#include <toolkit/string.h>
#include <monster_data.h>
#include <plugin.h>
#include <monster_guard.h>
#include <player.h>
#include <object.h>
#include <exp.h>
#include <arrow.h>
#include <bow.h>
#include <magic_mirror.h>
#include <sound_ambient.h>
#include <object_methods.h>
#include <resources.h>
#include <toolkit/socket_crypto.h>

Go to the source code of this file.

Macros

#define GET_CLIENT_FLAGS(_O_)   ((_O_)->flags[0] & 0x7f)
 
#define NO_FACE_SEND   (-1)
 
#define _Add(_old, _new, _type, _bitsize)
 
#define AddIf(_old, _new, _type, _bitsize)
 
#define AddIfFloat(_old, _new, _type)
 
#define AddIfDouble(_old, _new, _type)
 
#define map_clearcell(_cell_)
 
#define map_if_clearcell()
 

Functions

void socket_command_setup (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_player_cmd (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_version (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_item_move (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void esrv_update_stats (player *pl)
 
void esrv_new_player (player *pl, uint32_t 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_map_text_anim (object *pl, const char *color, const char *text)
 
void draw_client_map (object *pl)
 
static const char * get_playername_color (object *pl, object *op)
 
void packet_append_map_name (struct packet_struct *packet, object *op, object *map_info)
 
void packet_append_map_music (struct packet_struct *packet, object *op, object *map_info)
 
void packet_append_map_weather (struct packet_struct *packet, object *op, object *map_info)
 
void draw_client_map2 (object *pl)
 
void socket_command_quest_list (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_clear (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_move_path (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_fire (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_keepalive (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_move (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void send_target_command (player *pl)
 
void socket_command_account (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void generate_quick_name (player *pl)
 
void socket_command_target (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_talk (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_control (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_combat (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
static void socket_crypto_hello (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
static void socket_crypto_key (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
static void socket_crypto_curves (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
static void socket_crypto_pubkey (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
static void socket_crypto_secret (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
static void socket_crypto_done (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_crypto (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 
void socket_command_ask_resource (socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
 

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.

Macro Definition Documentation

#define _Add (   _old,
  _new,
  _type,
  _bitsize 
)
Value:
if (packet == NULL) { \
packet = packet_new(CLIENT_CMD_STATS, 32, 128); \
} \
(_old) = (_new); \
packet_debug_data(packet, 0, "Stats command type"); \
packet_append_uint8(packet, (_type)); \
packet_debug_data(packet, 0, "%s", #_new); \
packet_append_ ## _bitsize(packet, (_new));
#define AddIf (   _old,
  _new,
  _type,
  _bitsize 
)
Value:
if ((_old) != (_new)) { \
_Add(_old, _new, _type, _bitsize); \
}
#define AddIfDouble (   _old,
  _new,
  _type 
)
Value:
if (!DBL_EQUAL(_old, _new)) { \
_Add(_old, _new, _type, double); \
}
#define AddIfFloat (   _old,
  _new,
  _type 
)
Value:
if (!FLT_EQUAL(_old, _new)) { \
_Add(_old, _new, _type, float); \
}
#define map_clearcell (   _cell_)
Value:
{ \
memset((void *) ((char *) (_cell_) + offsetof(MapCell, cleared)), 0, sizeof(MapCell) - offsetof(MapCell, cleared)); \
(_cell_)->cleared = 1; \
}

Clear a map cell.

Definition at line 635 of file request.c.

#define map_if_clearcell ( )
Value:
{ \
if (CONTR(pl)->cs->lastmap.cells[ax][ay].cleared != 1) \
{ \
packet_debug_data(packet, 0, "Clearing tile %d,%d, mask", ax, ay); \
packet_append_uint16(packet, mask | MAP2_MASK_CLEAR); \
map_clearcell(&CONTR(pl)->cs->lastmap.cells[ax][ay]); \
} \
}
#define map_clearcell(_cell_)
Definition: request.c:635

Clear a map cell, but only if it has not been cleared before.

Definition at line 642 of file request.c.

Function Documentation

static void copy_lastmap ( socket_struct ns,
int  dx,
int  dy 
)
inlinestatic

Copy socket's last map according to new coordinates.

Parameters
nsSocket.
dxX.
dyY.

Definition at line 388 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 426 of file request.c.

void draw_client_map2 ( object pl)

Draw the client map.

Definition at line 653 of file request.c.

void esrv_new_player ( player pl,
uint32_t  weight 
)

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

Definition at line 337 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 socket.h

Definition at line 187 of file request.c.

void generate_quick_name ( player pl)

Generate player's name, as visible on the map.

Parameters
plThe player.

Definition at line 2286 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 603 of file request.c.

static int get_tiled_map_id ( player pl,
struct mapdef map 
)
inlinestatic

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 362 of file request.c.

void send_target_command ( player pl)

Send target command, calculate the target's color level, etc.

Parameters
plPlayer requesting this.

Definition at line 2144 of file request.c.

void socket_command_ask_resource ( socket_struct ns,
player pl,
uint8_t *  data,
size_t  len,
size_t  pos 
)

Handler for the ask resource command.

Function to call when a specific command type is received.

Parameters
csClient socket.
plPlayer associated with the client. May be NULL if the client has not logged in yet.
dataNetwork data buffer that contains the command.
lenNumber of bytes in the command.
posPosition where to start parsing command-specific data.

Definition at line 3108 of file request.c.

void socket_command_crypto ( socket_struct ns,
player pl,
uint8_t *  data,
size_t  len,
size_t  pos 
)

Handler for the crypto socket command.

Function to call when a specific command type is received.

Parameters
csClient socket.
plPlayer associated with the client. May be NULL if the client has not logged in yet.
dataNetwork data buffer that contains the command.
lenNumber of bytes in the command.
posPosition where to start parsing command-specific data.

Definition at line 3046 of file request.c.

static void socket_crypto_curves ( socket_struct ns,
player pl,
uint8_t *  data,
size_t  len,
size_t  pos 
)
static

Handler for the crypto curves sub-command.

Function to call when a specific command type is received.

Parameters
csClient socket.
plPlayer associated with the client. May be NULL if the client has not logged in yet.
dataNetwork data buffer that contains the command.
lenNumber of bytes in the command.
posPosition where to start parsing command-specific data.

Definition at line 2811 of file request.c.

static void socket_crypto_done ( socket_struct ns,
player pl,
uint8_t *  data,
size_t  len,
size_t  pos 
)
static

Handler for the crypto done sub-command.

Function to call when a specific command type is received.

Parameters
csClient socket.
plPlayer associated with the client. May be NULL if the client has not logged in yet.
dataNetwork data buffer that contains the command.
lenNumber of bytes in the command.
posPosition where to start parsing command-specific data.

Definition at line 3006 of file request.c.

static void socket_crypto_hello ( socket_struct ns,
player pl,
uint8_t *  data,
size_t  len,
size_t  pos 
)
static

Handler for the crypto hello sub-command.

Function to call when a specific command type is received.

Parameters
csClient socket.
plPlayer associated with the client. May be NULL if the client has not logged in yet.
dataNetwork data buffer that contains the command.
lenNumber of bytes in the command.
posPosition where to start parsing command-specific data.

Definition at line 2681 of file request.c.

static void socket_crypto_key ( socket_struct ns,
player pl,
uint8_t *  data,
size_t  len,
size_t  pos 
)
static

Handler for the crypto key sub-command.

Function to call when a specific command type is received.

Parameters
csClient socket.
plPlayer associated with the client. May be NULL if the client has not logged in yet.
dataNetwork data buffer that contains the command.
lenNumber of bytes in the command.
posPosition where to start parsing command-specific data.

Definition at line 2744 of file request.c.

static void socket_crypto_pubkey ( socket_struct ns,
player pl,
uint8_t *  data,
size_t  len,
size_t  pos 
)
static

Handler for the crypto pubkey sub-command.

Function to call when a specific command type is received.

Parameters
csClient socket.
plPlayer associated with the client. May be NULL if the client has not logged in yet.
dataNetwork data buffer that contains the command.
lenNumber of bytes in the command.
posPosition where to start parsing command-specific data.

Definition at line 2894 of file request.c.

static void socket_crypto_secret ( socket_struct ns,
player pl,
uint8_t *  data,
size_t  len,
size_t  pos 
)
static

Handler for the crypto secret sub-command.

Function to call when a specific command type is received.

Parameters
csClient socket.
plPlayer associated with the client. May be NULL if the client has not logged in yet.
dataNetwork data buffer that contains the command.
lenNumber of bytes in the command.
posPosition where to start parsing command-specific data.

Definition at line 2944 of file request.c.