Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
NETWORK MESSAGES: tools to serialize integers, double, N_STR from and back to a single N_STR *message

Data Structures

struct  NETW_MSG
 network message, array of char and int More...

Macros

#define NETMSG_BOX   8
 Network Message is box retrieving reply: (int x , int y , int z , N_STR *data ).
#define NETMSG_GET_BOX   7
 Network Message is box retrieve: int x , int y , int z.
#define NETMSG_IDENT_REPLY_NOK   2
 Network Message is identification reply NON OK: (int)type , (int)id , (N_STR *)name , (N_STR *)password.
#define NETMSG_IDENT_REPLY_OK   1
 Network Message is identification reply OK : (int)type , (int)id , (N_STR *)name , (N_STR *)password.
#define NETMSG_IDENT_REQUEST   0
 Network Message is identification request: (int)type , (int)id , (N_STR *)name , (N_STR *)password.
#define NETMSG_PING_REPLY   6
 Network Message is ping reply: (int)type , (int)id_from , (int)id_to.
#define NETMSG_PING_REQUEST   5
 Network Message is ping request: (int)type , (int)id_from , (int)id_to.
#define NETMSG_POSITION   4
 Network Message position: (int)type , (int)id , (int)X , (int)Y , (int)x_shift , (int)y_shift ,(int)vx ,(int)vy , (int)speed , (int)acceleration , (int)time_stamp.
#define NETMSG_QUIT   9
 Network asking for exit.
#define NETMSG_STRING   3
 Network Message is string: (int)type , (int)id , (N_STR *)name , (N_STR *)chan , (N_STR *)text , (int)color.
#define NETW_MSG_MAX_STRING_LENGTH   (1024UL * 1024UL * 1024UL)
 Maximum allowed length for a single string inside a network message (default: 1 GB).

Functions

int add_bytes_to_msg (NETW_MSG *msg, const void *bytes, size_t len)
 add a binary blob to the message, clean API for raw payloads (e.g.
int add_int_to_msg (NETW_MSG *msg, int value)
 add an int to the message
int add_nb_to_msg (NETW_MSG *msg, double value)
 add a float/double to the message
int add_nstrdup_to_msg (NETW_MSG *msg, N_STR *str)
 add a duplicate of a N_STR to the message
int add_nstrptr_to_msg (NETW_MSG *msg, N_STR *str)
 add a N_STR pointer to the message without copying
int add_strdup_to_msg (NETW_MSG *msg, const char *str)
 add a duplicate of a char string to the message
int create_msg (NETW_MSG **msg)
 create a NETW_MSG object
int delete_msg (NETW_MSG **msg)
 delete a NETW_MSG object
double double_swap (double value)
 swap bytes of a double value
int empty_msg (NETW_MSG **msg)
 empty a NETW_MSG object
int get_bytes_from_msg (NETW_MSG *msg, void **out_bytes, size_t *out_len)
 get a binary blob from the message (counterpart of add_bytes_to_msg).
int get_int_from_msg (NETW_MSG *msg, int *value)
 get an int from the message
int get_nb_from_msg (NETW_MSG *msg, double *value)
 get a float/double value from the message
int get_nstr_from_msg (NETW_MSG *msg, N_STR **str)
 get a N_STR string from the message
int get_str_from_msg (NETW_MSG *msg, char **str)
 get a char string from the message
double htond (double value)
 convert host double to network byte order
NETW_MSG * make_msg_from_str (N_STR *str)
 deserialize a N_STR into a NETW_MSG
N_STR * make_str_from_msg (NETW_MSG *msg)
 serialize a NETW_MSG into a single N_STR
N_STR * netmsg_make_ident (int type, int id, N_STR *name, N_STR *passwd)
 create an identification network message
N_STR * netmsg_make_ping (int type, int id_from, int id_to, int time)
 create a ping network message
N_STR * netmsg_make_position_msg (int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp)
 create a position network message
N_STR * netmsg_make_quit_msg (void)
 create a quit network message
N_STR * netmsg_make_string_msg (int id_from, int id_to, N_STR *name, N_STR *chan, N_STR *txt, int color)
 create a string network message
void netw_bytes_stats_get (long long *sent, long long *recv)
 Read process-wide network byte counters, sum of N_STR.written across every netw_add_msg / netw_get_msg call.
int netw_get_ident (N_STR *msg, int *type, int *ident, N_STR **name, N_STR **passwd)
 get identification data from a network message
int netw_get_ping (N_STR *msg, int *type, int *from, int *to, int *time)
 get ping data from a network message
int netw_get_position (N_STR *msg, int *id, double *X, double *Y, double *vx, double *vy, double *acc_x, double *acc_y, int *time_stamp)
 get position data from a network message
int netw_get_quit (N_STR *msg)
 get quit data from a network message
int netw_get_string (N_STR *msg, int *id, N_STR **name, N_STR **chan, N_STR **txt, int *color)
 get string data from a network message
int netw_msg_get_type (N_STR *msg)
 get the type of a network message.
void netw_msg_stats_get (long long *created, long long *deleted)
 Read lifecycle counters.
double ntohd (double value)
 convert network double to host byte order

Detailed Description


Data Structure Documentation

◆ NETW_MSG

struct NETW_MSG

network message, array of char and int

Examples
ex_accept_pool_client.c, ex_gui_network.c, and ex_network.h.

Definition at line 73 of file n_network_msg.h.

Collaboration diagram for NETW_MSG:
Data Fields
LIST * tabflt array of casted double value
LIST * tabint array of int
LIST * tabstr array of N_STR

Macro Definition Documentation

◆ NETMSG_BOX

#define NETMSG_BOX   8

Network Message is box retrieving reply: (int x , int y , int z , N_STR *data ).

Definition at line 62 of file n_network_msg.h.

◆ NETMSG_GET_BOX

#define NETMSG_GET_BOX   7

Network Message is box retrieve: int x , int y , int z.

Definition at line 60 of file n_network_msg.h.

◆ NETMSG_IDENT_REPLY_NOK

#define NETMSG_IDENT_REPLY_NOK   2

Network Message is identification reply NON OK: (int)type , (int)id , (N_STR *)name , (N_STR *)password.

Definition at line 50 of file n_network_msg.h.

Referenced by netw_get_ident().

◆ NETMSG_IDENT_REPLY_OK

#define NETMSG_IDENT_REPLY_OK   1

Network Message is identification reply OK : (int)type , (int)id , (N_STR *)name , (N_STR *)password.

Definition at line 48 of file n_network_msg.h.

Referenced by netw_get_ident().

◆ NETMSG_IDENT_REQUEST

#define NETMSG_IDENT_REQUEST   0

Network Message is identification request: (int)type , (int)id , (N_STR *)name , (N_STR *)password.

Definition at line 46 of file n_network_msg.h.

Referenced by netw_get_ident().

◆ NETMSG_PING_REPLY

#define NETMSG_PING_REPLY   6

Network Message is ping reply: (int)type , (int)id_from , (int)id_to.

Definition at line 58 of file n_network_msg.h.

Referenced by netw_get_ping().

◆ NETMSG_PING_REQUEST

#define NETMSG_PING_REQUEST   5

Network Message is ping request: (int)type , (int)id_from , (int)id_to.

Definition at line 56 of file n_network_msg.h.

Referenced by netw_get_ping().

◆ NETMSG_POSITION

#define NETMSG_POSITION   4

Network Message position: (int)type , (int)id , (int)X , (int)Y , (int)x_shift , (int)y_shift ,(int)vx ,(int)vy , (int)speed , (int)acceleration , (int)time_stamp.

Definition at line 54 of file n_network_msg.h.

Referenced by netmsg_make_position_msg(), and netw_get_position().

◆ NETMSG_QUIT

#define NETMSG_QUIT   9

Network asking for exit.

Definition at line 64 of file n_network_msg.h.

Referenced by netmsg_make_quit_msg(), and netw_get_quit().

◆ NETMSG_STRING

#define NETMSG_STRING   3

Network Message is string: (int)type , (int)id , (N_STR *)name , (N_STR *)chan , (N_STR *)text , (int)color.

Definition at line 52 of file n_network_msg.h.

Referenced by netmsg_make_string_msg(), and netw_get_string().

◆ NETW_MSG_MAX_STRING_LENGTH

#define NETW_MSG_MAX_STRING_LENGTH   (1024UL * 1024UL * 1024UL)

Maximum allowed length for a single string inside a network message (default: 1 GB).

Override before including this header to change the limit.

Definition at line 69 of file n_network_msg.h.

Referenced by make_msg_from_str().

Function Documentation

◆ add_bytes_to_msg()

int add_bytes_to_msg ( NETW_MSG * msg,
const void * bytes,
size_t len )

add a binary blob to the message, clean API for raw payloads (e.g.

packed entity wires, batched snapshots) that should not be confused with character strings. Internally wraps add_nstrptr_to_msg so the wire format is identical to a regular string today; the distinction exists for caller clarity and for a future framing compaction (the redundant N_STR length field could be removed without touching call sites).

add a binary blob to the message, clean API for raw payloads (e.g.

Parameters
msgdestination NETW_MSG
bytespointer to the payload (copied into an internal N_STR)
lennumber of bytes to copy
Returns
TRUE on success, FALSE on any allocation / argument failure

Internally this is the same wire format as add_nstrptr_to_msg, the split exists so consumers that ship packed binary records (entity wires, batched snapshots, path waypoints, etc.) can express their intent without faking a C string. A future NETW_MSG framing revision that removes the redundant N_STR length field would save 4 B per blob at the receive side; call sites using add_bytes_to_msg would pick that saving up for free.

Definition at line 280 of file n_network_msg.c.

References __n_assert, N_STR::data, free_nstr, free_nstr_ptr(), list_push(), new_nstr(), NETW_MSG::tabstr, and N_STR::written.

Here is the call graph for this function:

◆ add_int_to_msg()

int add_int_to_msg ( NETW_MSG * msg,
int value )

add an int to the message

add an int to the message

Parameters
msgA NETW_MSG *object to complete with the value
valueThe value to add to the message
Returns
TRUE or FALSE

Definition at line 202 of file n_network_msg.c.

References __n_assert, Free, list_push(), Malloc, and NETW_MSG::tabint.

Referenced by build_chat_msg(), client_worker_echo(), make_msg_from_str(), netmsg_make_ident(), netmsg_make_ping(), netmsg_make_position_msg(), netmsg_make_quit_msg(), netmsg_make_string_msg(), and send_net_datas().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_nb_to_msg()

int add_nb_to_msg ( NETW_MSG * msg,
double value )

add a float/double to the message

add a float/double to the message

Parameters
msgA NETW_MSG *object to complete with the value
valueThe value to add to the message
Warning
The floating value will be rounded by the network serialization !
Returns
TRUE or FALSE

Definition at line 179 of file n_network_msg.c.

References __n_assert, Free, list_push(), Malloc, and NETW_MSG::tabflt.

Referenced by make_msg_from_str(), and netmsg_make_position_msg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_nstrdup_to_msg()

int add_nstrdup_to_msg ( NETW_MSG * msg,
N_STR * str )

add a duplicate of a N_STR to the message

add a duplicate of a N_STR to the message

Parameters
msgA NETW_MSG *object to complete with the string
strThe string to add to the message
Returns
TRUE or FALSE

Definition at line 238 of file n_network_msg.c.

References __n_assert, N_STR::data, free_nstr_ptr(), list_push(), nstrdup(), and NETW_MSG::tabstr.

Referenced by netmsg_make_ident(), netmsg_make_string_msg(), and send_net_datas().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_nstrptr_to_msg()

int add_nstrptr_to_msg ( NETW_MSG * msg,
N_STR * str )

add a N_STR pointer to the message without copying

add a N_STR pointer to the message without copying

Parameters
msgA NETW_MSG *object to complete with the string
strThe string to add to the message
Returns
TRUE or FALSE

Definition at line 225 of file n_network_msg.c.

References __n_assert, N_STR::data, free_nstr_ptr(), list_push(), and NETW_MSG::tabstr.

Referenced by client_worker_echo(), make_msg_from_str(), and send_net_datas().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_strdup_to_msg()

int add_strdup_to_msg ( NETW_MSG * msg,
const char * str )

add a duplicate of a char string to the message

add a duplicate of a char string to the message

Parameters
msgA NETW_MSG *object to complete with the string
strThe string to add to the message
Returns
TRUE or FALSE

Definition at line 253 of file n_network_msg.c.

References __n_assert, char_to_nstr(), free_nstr_ptr(), list_push(), and NETW_MSG::tabstr.

Referenced by build_chat_msg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_msg()

int create_msg ( NETW_MSG ** msg)

create a NETW_MSG object

create a NETW_MSG object

Parameters
msgA NETW_MSG *object
Returns
TRUE or FALSE

Definition at line 111 of file n_network_msg.c.

References __n_assert, Free, g_netw_msg_created, list_destroy(), LOG_ERR, Malloc, MAX_LIST_ITEMS, n_log, and new_generic_list().

Referenced by build_chat_msg(), client_worker_echo(), make_msg_from_str(), netmsg_make_ident(), netmsg_make_ping(), netmsg_make_position_msg(), netmsg_make_quit_msg(), netmsg_make_string_msg(), and send_net_datas().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delete_msg()

int delete_msg ( NETW_MSG ** msg)

delete a NETW_MSG object

delete a NETW_MSG object

Parameters
msgA NETW_MSG *object to delete
Returns
TRUE or FALSE

Definition at line 136 of file n_network_msg.c.

References __n_assert, Free, g_netw_msg_deleted, list_destroy(), LOG_ERR, and n_log.

Referenced by build_chat_msg(), client_worker_echo(), decode_chat_msg(), get_net_datas(), make_msg_from_str(), netmsg_make_ident(), netmsg_make_ping(), netmsg_make_position_msg(), netmsg_make_quit_msg(), netmsg_make_string_msg(), netw_get_ident(), netw_get_ping(), netw_get_position(), netw_get_quit(), netw_get_string(), and send_net_datas().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ double_swap()

double double_swap ( double value)

swap bytes of a double value

swap bytes of a double value

Parameters
valueThe double to swap
Returns
A swapped double

Definition at line 58 of file n_network_msg.c.

Referenced by htond(), and ntohd().

Here is the caller graph for this function:

◆ empty_msg()

int empty_msg ( NETW_MSG ** msg)

empty a NETW_MSG object

empty a NETW_MSG object

Parameters
msgA NETW_MSG **object
Returns
TRUE or FALSE

Definition at line 162 of file n_network_msg.c.

References __n_assert, and list_empty().

Here is the call graph for this function:

◆ get_bytes_from_msg()

int get_bytes_from_msg ( NETW_MSG * msg,
void ** out_bytes,
size_t * out_len )

get a binary blob from the message (counterpart of add_bytes_to_msg).

Allocates *out_bytes (caller frees with free) and writes its size into *out_len. Returns TRUE on success, FALSE on missing entry or empty payload.

get a binary blob from the message (counterpart of add_bytes_to_msg).

The payload is handed to the caller as a plain-malloc'd buffer + length; the caller frees it when done.

Parameters
msgsource NETW_MSG
out_bytesreceives the allocated payload pointer
out_lenreceives the payload size in bytes
Returns
TRUE on success, FALSE on missing entry / empty payload

Definition at line 397 of file n_network_msg.c.

References __n_assert, N_STR::data, Free, FreeNoLog, list_shift, NETW_MSG::tabstr, and N_STR::written.

◆ get_int_from_msg()

int get_int_from_msg ( NETW_MSG * msg,
int * value )

get an int from the message

get an int from the message

Parameters
msgA NETW_MSG *object for extracting int
valueAn int pointer where the result will be stored
Returns
TRUE or FALSE

Definition at line 326 of file n_network_msg.c.

References __n_assert, Free, list_shift, and NETW_MSG::tabint.

Referenced by decode_chat_msg(), get_net_datas(), netw_get_ident(), netw_get_ping(), netw_get_position(), netw_get_quit(), and netw_get_string().

Here is the caller graph for this function:

◆ get_nb_from_msg()

int get_nb_from_msg ( NETW_MSG * msg,
double * value )

get a float/double value from the message

get a float/double value from the message

Parameters
msgA NETW_MSG *object for extracting number
valueA double pointer where the result will be stored
Returns
TRUE or FALSE

Definition at line 306 of file n_network_msg.c.

References __n_assert, Free, list_shift, and NETW_MSG::tabflt.

Referenced by netw_get_position().

Here is the caller graph for this function:

◆ get_nstr_from_msg()

int get_nstr_from_msg ( NETW_MSG * msg,
N_STR ** value )

get a N_STR string from the message

get a N_STR string from the message

Parameters
msgThe NETW_MSG where you have a str to get
valueA pointer to a NULL N_STR for storage
Returns
TRUE or FALSE

Definition at line 347 of file n_network_msg.c.

References __n_assert, list_shift, LOG_ERR, n_log, and NETW_MSG::tabstr.

Referenced by get_net_datas(), netw_get_ident(), and netw_get_string().

Here is the caller graph for this function:

◆ get_str_from_msg()

int get_str_from_msg ( NETW_MSG * msg,
char ** value )

get a char string from the message

get a char string from the message

Parameters
msgThe NETW_MSG where you have a str to get
valueA pointer to a NULL N_STR for storage
Returns
TRUE or FALSE

Definition at line 369 of file n_network_msg.c.

References __n_assert, N_STR::data, Free, list_shift, LOG_ERR, n_log, and NETW_MSG::tabstr.

Referenced by decode_chat_msg().

Here is the caller graph for this function:

◆ htond()

double htond ( double value)

convert host double to network byte order

convert host double to network byte order

Parameters
valueThe value to eventually swap
Returns
The modified value

Definition at line 81 of file n_network_msg.c.

References double_swap().

Referenced by make_str_from_msg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_msg_from_str()

NETW_MSG * make_msg_from_str ( N_STR * str)

deserialize a N_STR into a NETW_MSG

deserialize a N_STR into a NETW_MSG

Parameters
strA N_STR structure to convert into a NETW_MSG one
Returns
A pointer to the generated NETW_MSG, do not forget to free it after use !

Definition at line 552 of file n_network_msg.c.

References __n_assert, add_int_to_msg(), add_nb_to_msg(), add_nstrptr_to_msg(), create_msg(), N_STR::data, delete_msg(), Free, N_STR::length, LOG_ERR, Malloc, n_log, NETW_MSG_MAX_STRING_LENGTH, ntohd(), and N_STR::written.

Referenced by decode_chat_msg(), get_net_datas(), netw_get_ident(), netw_get_ping(), netw_get_position(), netw_get_quit(), and netw_get_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_str_from_msg()

N_STR * make_str_from_msg ( NETW_MSG * msg)

serialize a NETW_MSG into a single N_STR

serialize a NETW_MSG into a single N_STR

Parameters
msgA NETW_MSG structure to convert into a N_STR one
Returns
A pointer to the generated N_STR, do not forget to free it after use !

Definition at line 427 of file n_network_msg.c.

References __n_assert, N_STR::data, Free, free_nstr, htond(), N_STR::length, LOG_ERR, Malloc, n_log, LIST::nb_items, LIST_NODE::next, LIST_NODE::ptr, LIST::start, NETW_MSG::tabflt, NETW_MSG::tabint, NETW_MSG::tabstr, and N_STR::written.

Referenced by build_chat_msg(), client_worker_echo(), netmsg_make_ident(), netmsg_make_ping(), netmsg_make_position_msg(), netmsg_make_quit_msg(), netmsg_make_string_msg(), and send_net_datas().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netmsg_make_ident()

N_STR * netmsg_make_ident ( int type,
int id,
N_STR * name,
N_STR * passwd )

create an identification network message

create an identification network message

Parameters
typetype of identification ( NETW_IDENT_REQUEST , NETW_IDENT_NEW )
idThe ID of the sending client
nameUsername
passwdPassword
Returns
N_STR *netmsg or NULL

Definition at line 762 of file n_network_msg.c.

References __n_assert, add_int_to_msg(), add_nstrdup_to_msg(), create_msg(), delete_msg(), make_str_from_msg(), and type().

Referenced by netw_send_ident().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netmsg_make_ping()

N_STR * netmsg_make_ping ( int type,
int id_from,
int id_to,
int time )

create a ping network message

create a ping network message

Parameters
typeNETW_PING_REQUEST or NETW_PING_REPLY
id_fromIdentifiant of the sender
id_toIdentifiant of the destination, -1 if the serveur itslef is targetted
timeThe time it was when the ping was sended
Returns
A N_STR *message or NULL

Definition at line 722 of file n_network_msg.c.

References __n_assert, add_int_to_msg(), create_msg(), delete_msg(), make_str_from_msg(), and type().

Referenced by netw_send_ping().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netmsg_make_position_msg()

N_STR * netmsg_make_position_msg ( int id,
double X,
double Y,
double vx,
double vy,
double acc_x,
double acc_y,
int time_stamp )

create a position network message

create a position network message

Parameters
idThe ID of the sending client
Xx position
Yy position
vxx speed
vyy speed
acc_xx acceleration
acc_yy acceleration
time_stamptime when the position were copier
Returns
N_STR *netmsg or NULL

Definition at line 805 of file n_network_msg.c.

References __n_assert, add_int_to_msg(), add_nb_to_msg(), create_msg(), delete_msg(), make_str_from_msg(), and NETMSG_POSITION.

Referenced by netw_send_position().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netmsg_make_quit_msg()

N_STR * netmsg_make_quit_msg ( void )

create a quit network message

create a quit network message

Returns
N_STR *netmsg or NULL

Definition at line 916 of file n_network_msg.c.

References __n_assert, add_int_to_msg(), create_msg(), delete_msg(), make_str_from_msg(), and NETMSG_QUIT.

Referenced by netw_send_quit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netmsg_make_string_msg()

N_STR * netmsg_make_string_msg ( int id_from,
int id_to,
N_STR * name,
N_STR * chan,
N_STR * txt,
int color )

create a string network message

create a string network message

Parameters
id_fromThe ID of the sending client
id_toid of the destination
namename of the user
chantargeted channel
txttext to send
colorcolor of the text
Returns
N_STR *netmsg or NULL

Definition at line 865 of file n_network_msg.c.

References __n_assert, add_int_to_msg(), add_nstrdup_to_msg(), create_msg(), delete_msg(), make_str_from_msg(), and NETMSG_STRING.

Referenced by netw_send_string_to(), and netw_send_string_to_all().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netw_bytes_stats_get()

void netw_bytes_stats_get ( long long * sent,
long long * recv )

Read process-wide network byte counters, sum of N_STR.written across every netw_add_msg / netw_get_msg call.

Includes wire payload only; no framing overhead. Either pointer may be NULL. Advisory (not thread-atomic).

Definition at line 48 of file n_network_msg.c.

References g_netw_bytes_recv, and g_netw_bytes_sent.

◆ netw_get_ident()

int netw_get_ident ( N_STR * msg,
int * type,
int * ident,
N_STR ** name,
N_STR ** passwd )

get identification data from a network message

get identification data from a network message

Parameters
msgThe source string from which we are going to extract the data
typeNETMSG_IDENT_NEW , NETMSG_IDENT_REPLY_OK , NETMSG_IDENT_REPLY_NOK , NETMSG_IDENT_REQUEST
identID for the user
nameName of the user
passwdPassword of the user
Returns
TRUE or FALSE

Definition at line 978 of file n_network_msg.c.

References __n_assert, delete_msg(), free_nstr, get_int_from_msg(), get_nstr_from_msg(), LOG_ERR, make_msg_from_str(), n_log, NETMSG_IDENT_REPLY_NOK, NETMSG_IDENT_REPLY_OK, NETMSG_IDENT_REQUEST, and type().

Here is the call graph for this function:

◆ netw_get_ping()

int netw_get_ping ( N_STR * msg,
int * type,
int * from,
int * to,
int * time )

get ping data from a network message

get ping data from a network message

Parameters
msgThe source string from which we are going to extract the data
typeNETW_PING_REQUEST or NETW_PING_REPLY
fromIdentifiant of the sender
toTargetted Identifiant, -1 for server ping
timeThe time it was when the ping was sended
Returns
TRUE or FALSE

Definition at line 1135 of file n_network_msg.c.

References __n_assert, delete_msg(), get_int_from_msg(), LOG_ERR, make_msg_from_str(), n_log, NETMSG_PING_REPLY, NETMSG_PING_REQUEST, and type().

Here is the call graph for this function:

◆ netw_get_position()

int netw_get_position ( N_STR * msg,
int * id,
double * X,
double * Y,
double * vx,
double * vy,
double * acc_x,
double * acc_y,
int * time_stamp )

get position data from a network message

get position data from a network message

Parameters
msgThe source string from which we are going to extract the data
id
XX position inside a big grid
YY position inside a big grid
vxX speed
vyY speed
acc_xX acceleration
acc_yY acceleration
time_stampCurrent Time when it was sended (for some delta we would want to compute )
Returns
TRUE or FALSE

Definition at line 1027 of file n_network_msg.c.

References __n_assert, delete_msg(), get_int_from_msg(), get_nb_from_msg(), LOG_ERR, make_msg_from_str(), n_log, NETMSG_POSITION, and type().

Here is the call graph for this function:

◆ netw_get_quit()

int netw_get_quit ( N_STR * msg)

get quit data from a network message

get quit data from a network message

Parameters
msgThe source string from which we are going to extract the data
Returns
TRUE or FALSE

Definition at line 1173 of file n_network_msg.c.

References __n_assert, delete_msg(), get_int_from_msg(), make_msg_from_str(), NETMSG_QUIT, and type().

Here is the call graph for this function:

◆ netw_get_string()

int netw_get_string ( N_STR * msg,
int * id,
N_STR ** name,
N_STR ** chan,
N_STR ** txt,
int * color )

get string data from a network message

get string data from a network message

Parameters
msgThe source string from which we are going to extract the data
idThe ID of the sending client
nameName of user
chanTarget Channel, if any. Pass "ALL" to target the default channel
txtThe text to send
colorThe color of the text
Returns
TRUE or FALSE

Definition at line 1078 of file n_network_msg.c.

References __n_assert, delete_msg(), free_nstr, get_int_from_msg(), get_nstr_from_msg(), LOG_ERR, make_msg_from_str(), n_log, NETMSG_STRING, and type().

Here is the call graph for this function:

◆ netw_msg_get_type()

int netw_msg_get_type ( N_STR * msg)

get the type of a network message.

Returns the type value (>=0) on success, -1 on error

get the type of a network message.

Parameters
msgA char *msg_object you want to have type
Returns
The value corresponding to the type or -1 on error

Definition at line 939 of file n_network_msg.c.

References __n_assert, N_STR::data, LOG_ERR, n_log, and N_STR::written.

Referenced by manage_client().

Here is the caller graph for this function:

◆ netw_msg_stats_get()

void netw_msg_stats_get ( long long * created,
long long * deleted )

Read lifecycle counters.

Both pointers optional. Monotonic since process start; advisory (not thread-atomic).

Definition at line 38 of file n_network_msg.c.

References g_netw_msg_created, and g_netw_msg_deleted.

◆ ntohd()

double ntohd ( double value)

convert network double to host byte order

convert network double to host byte order

Parameters
valueThe value to eventually swap
Returns
The modified value

Definition at line 96 of file n_network_msg.c.

References double_swap().

Referenced by make_msg_from_str().

Here is the call graph for this function:
Here is the caller graph for this function: