Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_network_msg.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
26#ifndef N_NETWORK_MESSAGES
27#define N_NETWORK_MESSAGES
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
38#include <sys/param.h>
39
40#include "n_str.h"
41#include "n_list.h"
42#include "n_3d.h"
43
45#define NETMSG_IDENT_REQUEST 0
47#define NETMSG_IDENT_REPLY_OK 1
49#define NETMSG_IDENT_REPLY_NOK 2
51#define NETMSG_STRING 3
53#define NETMSG_POSITION 4
55#define NETMSG_PING_REQUEST 5
57#define NETMSG_PING_REPLY 6
59#define NETMSG_GET_BOX 7
61#define NETMSG_BOX 8
63#define NETMSG_QUIT 9
64
67#ifndef NETW_MSG_MAX_STRING_LENGTH
68#define NETW_MSG_MAX_STRING_LENGTH (1024UL * 1024UL * 1024UL)
69#endif
70
80
82double double_swap(double value);
84double htond(double value);
86double ntohd(double value);
87
89int create_msg(NETW_MSG** msg);
91int delete_msg(NETW_MSG** msg);
93int empty_msg(NETW_MSG** msg);
95int add_nb_to_msg(NETW_MSG* msg, double value);
97int add_int_to_msg(NETW_MSG* msg, int value);
99int add_nstrptr_to_msg(NETW_MSG* msg, N_STR* str);
101int add_nstrdup_to_msg(NETW_MSG* msg, N_STR* str);
103int add_strdup_to_msg(NETW_MSG* msg, const char* str);
105int get_int_from_msg(NETW_MSG* msg, int* value);
107int get_nb_from_msg(NETW_MSG* msg, double* value);
109int get_nstr_from_msg(NETW_MSG* msg, N_STR** str);
111int get_str_from_msg(NETW_MSG* msg, char** str);
116
118N_STR* netmsg_make_ping(int type, int id_from, int id_to, int time);
120N_STR* netmsg_make_ident(int type, int id, N_STR* name, N_STR* passwd);
122N_STR* netmsg_make_position_msg(int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp);
124N_STR* netmsg_make_string_msg(int id_from, int id_to, N_STR* name, N_STR* chan, N_STR* txt, int color);
127
129int netw_msg_get_type(N_STR* msg);
130
132int netw_get_ident(N_STR* msg, int* type, int* ident, N_STR** name, N_STR** passwd);
134int 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);
136int netw_get_string(N_STR* msg, int* id, N_STR** name, N_STR** chan, N_STR** txt, int* color);
138int netw_get_ping(N_STR* msg, int* type, int* from, int* to, int* time);
140int netw_get_quit(N_STR* msg);
141
146#ifdef __cplusplus
147}
148#endif
149
150#endif /*#ifndef N_NETWORK*/
Structure of a generic LIST container.
Definition n_list.h:58
A box including a string and his lenght.
Definition n_str.h:60
LIST * tabflt
array of casted double value
LIST * tabstr
array of N_STR
LIST * tabint
array of int
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 add_strdup_to_msg(NETW_MSG *msg, const char *str)
add a duplicate of a char string to the 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
NETW_MSG * make_msg_from_str(N_STR *str)
deserialize a N_STR into a NETW_MSG
int empty_msg(NETW_MSG **msg)
empty a NETW_MSG object
double double_swap(double value)
swap bytes of a double value
N_STR * make_str_from_msg(NETW_MSG *msg)
serialize a NETW_MSG into a single N_STR
int netw_get_ping(N_STR *msg, int *type, int *from, int *to, int *time)
get ping data from a network message
int add_nstrptr_to_msg(NETW_MSG *msg, N_STR *str)
add a N_STR pointer to the message without copying
int get_nb_from_msg(NETW_MSG *msg, double *value)
get a float/double value from the message
int netw_get_quit(N_STR *msg)
get quit data from a network message
int create_msg(NETW_MSG **msg)
create a NETW_MSG object
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
int netw_msg_get_type(N_STR *msg)
get the type of a network message.
int get_nstr_from_msg(NETW_MSG *msg, N_STR **str)
get a N_STR string from the message
N_STR * netmsg_make_ident(int type, int id, N_STR *name, N_STR *passwd)
create an identification network message
int add_nstrdup_to_msg(NETW_MSG *msg, N_STR *str)
add a duplicate of a N_STR to the message
int add_int_to_msg(NETW_MSG *msg, int value)
add an int to the message
double ntohd(double value)
convert network double to host byte order
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 delete_msg(NETW_MSG **msg)
delete a NETW_MSG object
int add_nb_to_msg(NETW_MSG *msg, double value)
add a float/double to the message
N_STR * netmsg_make_quit_msg(void)
create a quit network message
N_STR * netmsg_make_ping(int type, int id_from, int id_to, int time)
create a ping 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
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
int get_int_from_msg(NETW_MSG *msg, int *value)
get an int from the message
network message, array of char and int
Simple 3D movement simulation.
List structures and definitions.
N_STR and string function declaration.