Table of Contents
- NETWORK MESSAGES: tools to serialize integers, double, N_STR from and back to a single N_STR *message
- Structures
- Functions
- Defines
- Functions Documentation
- function ntohd
- function netw_msg_stats_get
- function netw_msg_get_type
- function netw_get_string
- function netw_get_quit
- function netw_get_position
- function netw_get_ping
- function netw_get_ident
- function netw_bytes_stats_get
- function netmsg_make_string_msg
- function netmsg_make_quit_msg
- function netmsg_make_position_msg
- function netmsg_make_ping
- function netmsg_make_ident
- function make_str_from_msg
- function make_msg_from_str
- function htond
- function get_str_from_msg
- function get_nstr_from_msg
- function get_nb_from_msg
- function get_int_from_msg
- function get_bytes_from_msg
- function empty_msg
- function double_swap
- function delete_msg
- function create_msg
- function add_strdup_to_msg
- function add_nstrptr_to_msg
- function add_nstrdup_to_msg
- function add_nb_to_msg
- function add_int_to_msg
- function add_bytes_to_msg
- Macros Documentation
NETWORK MESSAGES: tools to serialize integers, double, N_STR from and back to a single N_STR *message
Structures
| Name | |
|---|---|
| struct | NETW_MSG network message, array of char and int |
Functions
| Name | |
|---|---|
| double | ntohd(double value) convert network double to host byte order |
| void | netw_msg_stats_get(long long * created, long long * deleted) Read lifecycle counters. |
| int | netw_msg_get_type(N_STR * msg) get the type of 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_get_quit(N_STR * msg) get quit 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_ping(N_STR * msg, int * type, int * from, int * to, int * time) get ping data from a network message |
| int | netw_get_ident(N_STR * msg, int * type, int * ident, N_STR ** name, N_STR ** passwd) get identification data from a network message |
| void | netw_bytes_stats_get(long long * sent, long long * recv) Read process-wide network byte counters, sum of [N_STR.written](Struct-N_STR#user-content-variable-written) across every netw_add_msg / netw_get_msg call. |
| 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 |
| N_STR * | netmsg_make_quit_msg(void ) create a quit 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_ping(int type, int id_from, int id_to, int time) create a ping network message |
| N_STR * | netmsg_make_ident(int type, int id, N_STR * name, N_STR * passwd) create an identification network message |
| N_STR * | make_str_from_msg(NETW_MSG * msg) serialize a NETW_MSG into a single N_STR |
| NETW_MSG * | make_msg_from_str(N_STR * str) deserialize a N_STR into a NETW_MSG |
| double | htond(double value) convert host double to network byte order |
| int | get_str_from_msg(NETW_MSG * msg, char ** str) get a char string from the message |
| int | get_nstr_from_msg(NETW_MSG * msg, N_STR ** str) get a N_STR string from the message |
| int | get_nb_from_msg(NETW_MSG * msg, double * value) get a float/double value from the message |
| int | get_int_from_msg(NETW_MSG * msg, int * value) get an int from the message |
| 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 | empty_msg(NETW_MSG ** msg) empty a NETW_MSG object |
| double | double_swap(double value) swap bytes of a double value |
| int | delete_msg(NETW_MSG ** msg) delete a NETW_MSG object |
| int | create_msg(NETW_MSG ** msg) create a NETW_MSG object |
| int | add_strdup_to_msg(NETW_MSG * msg, const char * str) add a duplicate of a char string 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_nstrdup_to_msg(NETW_MSG * msg, N_STR * str) add a duplicate of a N_STR to the message |
| int | add_nb_to_msg(NETW_MSG * msg, double value) add a float/double to the message |
| int | add_int_to_msg(NETW_MSG * msg, int value) add an int to the message |
| 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. |
Defines
| Name | |
|---|---|
| NETW_MSG_MAX_STRING_LENGTH Maximum allowed length for a single string inside a network message (default: 1 GB). |
|
| NETMSG_STRING Network Message is string: (int)type , (int)id , (N_STR *)name , (N_STR *)chan , (N_STR *)text , (int)color. |
|
| NETMSG_QUIT Network asking for exit. |
|
| NETMSG_POSITION 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. |
|
| NETMSG_PING_REQUEST Network Message is ping request: (int)type , (int)id_from , (int)id_to. |
|
| NETMSG_PING_REPLY Network Message is ping reply: (int)type , (int)id_from , (int)id_to. |
|
| NETMSG_IDENT_REQUEST Network Message is identification request: (int)type , (int)id , (N_STR *)name , (N_STR *)password. |
|
| NETMSG_IDENT_REPLY_OK Network Message is identification reply OK : (int)type , (int)id , (N_STR *)name , (N_STR *)password. |
|
| NETMSG_IDENT_REPLY_NOK Network Message is identification reply NON OK: (int)type , (int)id , (N_STR *)name , (N_STR *)password. |
|
| NETMSG_GET_BOX Network Message is box retrieve: int x , int y , int z. |
|
| NETMSG_BOX Network Message is box retrieving reply: (int x , int y , int z , N_STR *data ). |
Functions Documentation
function ntohd
double ntohd(
double value
)
convert network double to host byte order
Parameters:
- value The value to eventually swap
Return: The modified value
If needed swap bytes for a double.
convert network double to host byte order
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).
function netw_msg_get_type
int netw_msg_get_type(
N_STR * msg
)
get the type of a network message.
Parameters:
- msg A char *msg_object you want to have type
Return: The value corresponding to the type or -1 on error
Get the type of message without killing the first number. Use with netw_get_XXX.
Returns the type value (>=0) on success, -1 on error
get the type of a network message.
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
Parameters:
- msg The source string from which we are going to extract the data
- id The ID of the sending client
- name Name of user
- chan Target Channel, if any. Pass "ALL" to target the default channel
- txt The text to send
- color The color of the text
Return: TRUE or FALSE
Retrieves string from netwmsg.
get string data from a network message
function netw_get_quit
int netw_get_quit(
N_STR * msg
)
get quit data from a network message
Parameters:
- msg The source string from which we are going to extract the data
Return: TRUE or FALSE
get a formatted NETWMSG_QUIT message from the specified network
get quit data from a network message
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
Parameters:
- msg The source string from which we are going to extract the data
- id
- X X position inside a big grid
- Y Y position inside a big grid
- vx X speed
- vy Y speed
- acc_x X acceleration
- acc_y Y acceleration
- time_stamp Current Time when it was sended (for some delta we would want to compute )
Return: TRUE or FALSE
Retrieves position from netwmsg.
get position data from a network message
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
Parameters:
- msg The source string from which we are going to extract the data
- type NETW_PING_REQUEST or NETW_PING_REPLY
- from Identifiant of the sender
- to Targetted Identifiant, -1 for server ping
- time The time it was when the ping was sended
Return: TRUE or FALSE
Retrieves a ping travel elapsed time.
get ping data from a network message
function 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
Parameters:
- msg The source string from which we are going to extract the data
- type NETMSG_IDENT_NEW , NETMSG_IDENT_REPLY_OK , NETMSG_IDENT_REPLY_NOK , NETMSG_IDENT_REQUEST
- ident ID for the user
- name Name of the user
- passwd Password of the user
Return: TRUE or FALSE
Retrieves identification from netwmsg.
get identification data from a network message
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](Struct-N_STR#user-content-variable-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).
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
Parameters:
- id_from The ID of the sending client
- id_to id of the destination
- name name of the user
- chan targeted channel
- txt text to send
- color color of the text
Return: N_STR *netmsg or NULL
make a network NETMSG_STRING message with given parameters
create a string network message
function netmsg_make_quit_msg
N_STR * netmsg_make_quit_msg(
void
)
create a quit network message
Return: N_STR *netmsg or NULL
make a generic network NETMSG_QUIT message
create a quit network message
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
Parameters:
- id The ID of the sending client
- X x position
- Y y position
- vx x speed
- vy y speed
- acc_x x acceleration
- acc_y y acceleration
- time_stamp time when the position were copier
Return: N_STR *netmsg or NULL
make a network NETMSG_POSITION message with given parameters
create a position network message
function netmsg_make_ping
N_STR * netmsg_make_ping(
int type,
int id_from,
int id_to,
int time
)
create a ping network message
Parameters:
- type NETW_PING_REQUEST or NETW_PING_REPLY
- id_from Identifiant of the sender
- id_to Identifiant of the destination, -1 if the serveur itslef is targetted
- time The time it was when the ping was sended
Return: A N_STR *message or NULL
Make a ping message to send to a network.
create a ping network message
function netmsg_make_ident
N_STR * netmsg_make_ident(
int type,
int id,
N_STR * name,
N_STR * passwd
)
create an identification network message
Parameters:
- type type of identification ( NETW_IDENT_REQUEST , NETW_IDENT_NEW )
- id The ID of the sending client
- name Username
- passwd Password
Return: N_STR *netmsg or NULL
Add a formatted NETWMSG_IDENT message to the specified network.
create an identification network message
function make_str_from_msg
N_STR * make_str_from_msg(
NETW_MSG * msg
)
serialize a NETW_MSG into a single N_STR
Parameters:
Return: A pointer to the generated N_STR, do not forget to free it after use !
Make a single string of the message.
serialize a NETW_MSG into a single N_STR
function make_msg_from_str
NETW_MSG * make_msg_from_str(
N_STR * str
)
deserialize a N_STR into a NETW_MSG
Parameters:
Return: A pointer to the generated NETW_MSG, do not forget to free it after use !
Make a single message of the string.
deserialize a N_STR into a NETW_MSG
function htond
double htond(
double value
)
convert host double to network byte order
Parameters:
- value The value to eventually swap
Return: The modified value
If needed swap bytes for a double.
convert host double to network byte order
function get_str_from_msg
int get_str_from_msg(
NETW_MSG * msg,
char ** str
)
get a char string from the message
Parameters:
Return: TRUE or FALSE
Get a string from a message string list.
get a char string from the message
function get_nstr_from_msg
int get_nstr_from_msg(
NETW_MSG * msg,
N_STR ** str
)
get a N_STR string from the message
Parameters:
Return: TRUE or FALSE
Get a string from a message string list.
get a N_STR string from the message
function get_nb_from_msg
int get_nb_from_msg(
NETW_MSG * msg,
double * value
)
get a float/double value from the message
Parameters:
- msg A NETW_MSG *object for extracting number
- value A double pointer where the result will be stored
Return: TRUE or FALSE
Get a number from a message number list.
get a float/double value from the message
function get_int_from_msg
int get_int_from_msg(
NETW_MSG * msg,
int * value
)
get an int from the message
Parameters:
- msg A NETW_MSG *object for extracting int
- value An int pointer where the result will be stored
Return: TRUE or FALSE
Get an int from a message int list.
get an int from the message
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).
Parameters:
- msg source NETW_MSG
- out_bytes receives the allocated payload pointer
- out_len receives the payload size in bytes
Return: TRUE on success, FALSE on missing entry / empty payload
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.
function empty_msg
int empty_msg(
NETW_MSG ** msg
)
empty a NETW_MSG object
Parameters:
- msg A NETW_MSG **object
Return: TRUE or FALSE
Empty a NETW_MSG *object.
empty a NETW_MSG object
function double_swap
double double_swap(
double value
)
swap bytes of a double value
Parameters:
- value The double to swap
Return: A swapped double
Swap bytes endiannes for a double.
swap bytes of a double value
function delete_msg
int delete_msg(
NETW_MSG ** msg
)
delete a NETW_MSG object
Parameters:
- msg A NETW_MSG *object to delete
Return: TRUE or FALSE
Delete a NETW_MSG *object.
delete a NETW_MSG object
function create_msg
int create_msg(
NETW_MSG ** msg
)
create a NETW_MSG object
Parameters:
- msg A NETW_MSG *object
Return: TRUE or FALSE
Create a NETW_MSG *object.
create a NETW_MSG object
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
Parameters:
- msg A NETW_MSG *object to complete with the string
- str The string to add to the message
Return: TRUE or FALSE
Add a copy of char *str to the string list in the message.
add a duplicate of a char string to the message
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
Parameters:
- msg A NETW_MSG *object to complete with the string
- str The string to add to the message
Return: TRUE or FALSE
Add a string to the string list in the message.
add a N_STR pointer to the message without copying
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
Parameters:
- msg A NETW_MSG *object to complete with the string
- str The string to add to the message
Return: TRUE or FALSE
Add a copy of str to the string list in the message.
add a duplicate of a N_STR to the message
function add_nb_to_msg
int add_nb_to_msg(
NETW_MSG * msg,
double value
)
add a float/double to the message
Parameters:
- msg A NETW_MSG *object to complete with the value
- value The value to add to the message
Return: TRUE or FALSE
Warning: The floating value will be rounded by the network serialization !
Add an float to the message.
add a float/double to the message
function add_int_to_msg
int add_int_to_msg(
NETW_MSG * msg,
int value
)
add an int to the message
Parameters:
- msg A NETW_MSG *object to complete with the value
- value The value to add to the message
Return: TRUE or FALSE
Add an int to the int list int the message.
add an int to the message
function 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.
Parameters:
- msg destination NETW_MSG
- bytes pointer to the payload (copied into an internal N_STR)
- len number of bytes to copy
Return: TRUE on success, FALSE on any allocation / argument failure
Add a binary blob to the message (clean alias for a raw N_STR payload, distinguishes binary data from character strings at call sites).
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_STRlength field could be removed without touching call sites).
add a binary blob to the message, clean API for raw payloads (e.g.
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](Struct-NETW_MSG) framing revision that removes the redundant N_STRlength 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.
Macros Documentation
define 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.
define 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.
define NETMSG_QUIT
#define NETMSG_QUIT 9
Network asking for exit.
define 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.
define NETMSG_PING_REQUEST
#define NETMSG_PING_REQUEST 5
Network Message is ping request: (int)type , (int)id_from , (int)id_to.
define NETMSG_PING_REPLY
#define NETMSG_PING_REPLY 6
Network Message is ping reply: (int)type , (int)id_from , (int)id_to.
define NETMSG_IDENT_REQUEST
#define NETMSG_IDENT_REQUEST 0
Network Message is identification request: (int)type , (int)id , (N_STR *)name , (N_STR *)password.
define 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.
define 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.
define NETMSG_GET_BOX
#define NETMSG_GET_BOX 7
Network Message is box retrieve: int x , int y , int z.
define NETMSG_BOX
#define NETMSG_BOX 8
Network Message is box retrieving reply: (int x , int y , int z , N_STR *data ).
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB