Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_gui_netclient.c

Nilorea Library gui networking api test.

Nilorea Library gui networking api test

Author
Castagnier Mickael
Version
1.0
Date
02/05/2020
#define WIDTH 640
#define HEIGHT 480
#define HAVE_ALLEGRO 1
#include "nilorea/n_str.h"
#include "nilorea/n_list.h"
#include "nilorea/n_hash.h"
typedef struct PEER_OBJECT
{
double position[ 3 ];
int id ;
long int life_time ;
int update_peer( HASH_TABLE *peer_table, int id, double position[ 3 ] )
{
__n_assert( peer_table, return FALSE );
PEER_OBJECT *peer = NULL ;
if( ht_get_ptr_ex( peer_table, id, (void *)&peer ) == TRUE )
{
memcpy( peer -> position, position, 3 * sizeof( double ) );
peer -> life_time = 10000000 ; /* 10s in usec */
}
else
{
Malloc( peer, PEER_OBJECT, 1 );
__n_assert( peer, return FALSE );
memcpy( peer -> position, position, 3 * sizeof( double ) );
peer -> id = id ;
peer -> life_time = 10000000 ; /* 10s in usec */
ht_put_ptr_ex( peer_table, id, peer, &free );
}
return TRUE ;
}
int manage_peers( HASH_TABLE *peer_table, int delta_t )
{
LIST *to_kill = new_generic_list( -1 );
ht_foreach( node, peer_table )
{
PEER_OBJECT *peer = hash_val( node, PEER_OBJECT );
peer -> life_time -= delta_t ;
if( peer -> life_time < 0 )
list_push( to_kill, peer, NULL );
}
list_foreach( node, to_kill )
{
if( node && node -> ptr )
{
PEER_OBJECT *peer = (PEER_OBJECT *)node -> ptr ;
ht_remove_ex( peer_table, peer -> id );
}
}
return TRUE ;
}
int draw_peers( HASH_TABLE *peer_table, ALLEGRO_FONT *font, ALLEGRO_COLOR color )
{
ht_foreach( node, peer_table )
{
PEER_OBJECT *peer = hash_val( node, PEER_OBJECT );
/* mouse pointers */
al_draw_line( peer -> position[ 0 ] - 5, peer -> position[ 1 ], peer -> position[ 0 ] + 5, peer -> position[ 1 ], al_map_rgb( 255, 0, 0 ), 1 );
al_draw_line( peer -> position[ 0 ], peer -> position[ 1 ] + 5, peer -> position[ 0 ], peer -> position[ 1 ] - 5, al_map_rgb( 255, 0, 0 ), 1 );
N_STR *textout = NULL ;
nstrprintf( textout, "id: %d", peer -> id );
al_draw_text( font, color, peer -> position[ 0 ] + 10, peer -> position[ 1 ], ALLEGRO_ALIGN_LEFT, _nstr( textout) );
free_nstr( &textout );
}
return TRUE ;
}
void usage(void)
{
fprintf( stderr, " -v version\n"
" -V log level: LOG_INFO, LOG_NOTICE, LOG_ERR, LOG_DEBUG\n"
" -h help\n"
" -a serveur address name/ip to bind (server mode) (optionnal)\n"
" -s serveur address name/ip to connect (client mode)\n"
" -p port\n"
" -i [v4,v6] ip version (default support both ipv4 and ipv6 )\n" );
}
void process_args( int argc, char **argv, char **server, char **port, int *ip_version )
{
int getoptret = 0,
log_level = LOG_ERR; /* default log level */
/* Arguments optionnels */
/* -v version
* -V log level
* -h help
* -s serveur address name/ip to connect (client mode)
* -p port
* -i v4 ip version (default support both ipv4 and ipv6 )
* -i v6 ip version ( " " " " " " )
*/
if( argc == 1 )
{
fprintf( stderr, "No arguments given, help:\n" );
usage();
exit( 1 );
}
while( ( getoptret = getopt( argc, argv, "hvs:p:i:V:" ) ) != EOF)
{
switch( getoptret )
{
case 'i' :
if( !strcmp( "v4", optarg ) )
{
(*ip_version) = NETWORK_IPV4 ;
n_log( LOG_NOTICE, "IPV4 selected" );
}
else if( !strcmp( "v6", optarg ) )
{
(*ip_version) = NETWORK_IPV6 ;
n_log( LOG_NOTICE, "IPV6 selected" );
}
else
{
n_log( LOG_NOTICE, "IPV4/6 selected" );
}
break;
case 'v' :
fprintf( stderr, "Date de compilation : %s a %s.\n", __DATE__, __TIME__ );
exit( 1 );
case 'V' :
if( !strncmp( "LOG_NULL", optarg, 8 ) )
{
}
else
{
if( !strncmp( "LOG_NOTICE", optarg, 10 ) )
{
}
else
{
if( !strncmp( "LOG_INFO", optarg, 8 ) )
{
}
else
{
if( !strncmp( "LOG_ERR", optarg, 7 ) )
{
}
else
{
if( !strncmp( "LOG_DEBUG", optarg, 9 ) )
{
}
else
{
fprintf( stderr, "%s n'est pas un niveau de log valide.\n", optarg );
exit( -1 );
}
}
}
}
}
break;
case 's' :
(*server) = strdup( optarg );
break ;
case 'p' :
(*port) = strdup( optarg );
break ;
default :
case '?' :
{
if( optopt == 'V' )
{
fprintf( stderr, "\n Missing log level\n" );
}
else if( optopt == 'p' )
{
fprintf( stderr, "\n Missing port\n" );
}
else if( optopt != 's' )
{
fprintf( stderr, "\n Unknow missing option %c\n", optopt );
}
usage();
exit( 1 );
}
break ;
case 'h' :
{
usage();
exit( 1 );
}
break ;
}
}
} /* void process_args( ... ) */
{
};
int key[ 7 ] = {false,false,false,false,false,false,false};
/* start */
int main( int argc, char *argv[] )
{
int DONE = 0, QUIT_ASKED = 0, /* Flag to check if we are always running */
getoptret = 0, /* launch parameter check */
log_level = LOG_ERR ; /* default LOG_LEVEL */
ALLEGRO_DISPLAY *display = NULL ;
ALLEGRO_BITMAP *scr_buf = NULL ;
ALLEGRO_TIMER *fps_timer = NULL ;
ALLEGRO_TIMER *logic_timer = NULL ;
ALLEGRO_TIMER *network_heartbeat_timer = NULL ;
char *server = NULL ;
char *port = NULL ;
LIST *chatbuf = NULL;
HASH_TABLE *peer_table = NULL ;
ALLEGRO_USTR *chat_line = NULL;
N_STR *name = NULL,
*password = NULL ;
NETWORK *netw = NULL ;
unsigned long ping_time = 0 ;
int mx = 0, my = 0, mouse_b1 = 0, mouse_b2 = 0 ;
int do_draw = 0, do_logic = 0, do_network_update = 0;
N_STR *netw_exchange = NULL ;
int it = -1, ident = -1 ;
static pthread_t netw_thr ;
ALLEGRO_COLOR white_color = al_map_rgba_f(1, 1, 1, 1);
ALLEGRO_FONT *font = NULL ;
/* processing args and set log_level */
process_args( argc, argv, &server, &port, &ip_version );
if( !server )
{
n_log( LOG_ERR, "No server given. Exiting." );
exit( -1 );
}
if( !port )
{
n_log( LOG_ERR, "No port given. Exiting." );
exit( -1 );
}
#ifdef __linux__
struct sigaction sa;
sa.sa_handler = netw_sigchld_handler; // reap all dead processes
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if (sigaction(SIGCHLD, &sa, NULL) == -1)
{
perror("sigaction");
exit(1);
}
#endif
n_log( LOG_NOTICE, "%s is starting ...", argv[ 0 ] );
/* allegro 5 + addons loading */
if (!al_init())
{
n_abort("Could not init Allegro.\n");
}
if (!al_install_audio())
{
n_abort("Unable to initialize audio addon\n");
}
if (!al_init_acodec_addon())
{
n_abort("Unable to initialize acoded addon\n");
}
if (!al_init_image_addon())
{
n_abort("Unable to initialize image addon\n");
}
if (!al_init_primitives_addon() )
{
n_abort("Unable to initialize primitives addon\n");
}
if( !al_init_font_addon() )
{
n_abort("Unable to initialize font addon\n");
}
if( !al_init_ttf_addon() )
{
n_abort("Unable to initialize ttf_font addon\n");
}
if( !al_install_keyboard() )
{
n_abort("Unable to initialize keyboard handler\n");
}
if( !al_install_mouse())
{
n_abort("Unable to initialize mouse handler\n");
}
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
event_queue = al_create_event_queue();
if(!event_queue)
{
fprintf(stderr, "failed to create event_queue!\n");
al_destroy_display(display);
return -1;
}
fps_timer = al_create_timer( 1.0/60.0 );
logic_timer = al_create_timer( 1.0/60.0 );
network_heartbeat_timer = al_create_timer( 1.0/10.0 );
al_set_new_display_flags( ALLEGRO_OPENGL|ALLEGRO_WINDOWED );
display = al_create_display( WIDTH, HEIGHT );
if( !display )
{
n_abort("Unable to create display\n");
}
al_set_window_title( display, argv[ 0 ] );
al_set_new_bitmap_flags( ALLEGRO_VIDEO_BITMAP );
peer_table = new_ht( 1024 );
chatbuf = new_generic_list( 1000 );
chat_line = al_ustr_new( "" );
font = al_load_font( "2Dumb.ttf", 18, 0 );
if (! font )
{
n_log( LOG_ERR, "Unable to load 2Dumb.ttf" );
exit( 1 );
}
al_register_event_source(event_queue, al_get_display_event_source(display));
al_start_timer( fps_timer );
al_start_timer( logic_timer );
al_start_timer( network_heartbeat_timer );
al_register_event_source(event_queue, al_get_timer_event_source(fps_timer));
al_register_event_source(event_queue, al_get_timer_event_source(logic_timer));
al_register_event_source(event_queue, al_get_timer_event_source(network_heartbeat_timer));
al_register_event_source(event_queue, al_get_keyboard_event_source());
al_register_event_source(event_queue, al_get_mouse_event_source());
ALLEGRO_BITMAP *scrbuf = al_create_bitmap( WIDTH, HEIGHT );
al_hide_mouse_cursor(display);
if( netw_connect( &netw, server, port, ip_version ) != TRUE )
{
n_log( LOG_ERR, "Could not connect to %s:%s", _str( server ), _str( port ) );
}
name = char_to_nstr( "ClientName" );
password = char_to_nstr( "ClientPassword" );
if( netw_send_ident( netw, NETMSG_IDENT_REQUEST, 0, name, password ) == FALSE )
{
n_log( LOG_ERR, "Sending ident request failed" );
goto exit_client;
}
n_log( LOG_INFO,"Ident request sended");
unsigned long int ident_timeout = 10000000 ;
do
{
netw_exchange = netw_get_msg( netw );
if( netw_exchange )
{
int type = netw_msg_get_type( netw_exchange );
if( type == NETMSG_IDENT_REPLY_OK )
{
break ;
}
if( type == NETMSG_IDENT_REPLY_NOK )
{
n_log( LOG_ERR, "Login refused !!!" );
goto exit_client ;
}
}
ident_timeout -= 1000 ;
usleep( 1000 );
}
while( ident_timeout > 0 );
free_nstr( &name );
free_nstr( &password );
netw_get_ident( netw_exchange, &it, &ident, &name, &password );
n_log( LOG_INFO,"Id Message received, pointer:%p size %d id %d", netw_exchange -> data, netw_exchange -> length, ident );
if( ident == -1 )
{
n_log( LOG_ERR,"No ident received");
goto exit_client;
}
/* We got our id ! */
n_log( LOG_NOTICE, "Id is:%d", ident );
DONE = 0 ;
QUIT_ASKED = 0 ;
al_clear_keyboard_state( NULL );
al_flush_event_queue( event_queue );
do
{
do
{
ALLEGRO_EVENT ev ;
al_wait_for_event(event_queue, &ev);
if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
{
switch(ev.keyboard.keycode)
{
case ALLEGRO_KEY_UP:
key[KEY_UP] = 1;
break;
case ALLEGRO_KEY_DOWN:
key[KEY_DOWN] = 1;
break;
case ALLEGRO_KEY_LEFT:
key[KEY_LEFT] = 1;
break;
case ALLEGRO_KEY_RIGHT:
key[KEY_RIGHT] = 1;
break;
case ALLEGRO_KEY_ESCAPE:
key[KEY_ESC] = 1 ;
break;
case ALLEGRO_KEY_SPACE:
key[KEY_SPACE] = 1 ;
break;
case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL:
key[KEY_CTRL] = 1 ;
default:
break;
}
}
else if(ev.type == ALLEGRO_EVENT_KEY_UP)
{
switch(ev.keyboard.keycode)
{
case ALLEGRO_KEY_UP:
key[KEY_UP] = 0;
break;
case ALLEGRO_KEY_DOWN:
key[KEY_DOWN] = 0;
break;
case ALLEGRO_KEY_LEFT:
key[KEY_LEFT] = 0;
break;
case ALLEGRO_KEY_RIGHT:
break;
case ALLEGRO_KEY_ESCAPE:
key[KEY_ESC] = 0 ;
break;
case ALLEGRO_KEY_SPACE:
key[KEY_SPACE] = 0 ;
break;
case ALLEGRO_KEY_LCTRL:
case ALLEGRO_KEY_RCTRL:
key[KEY_CTRL] = 0 ;
default:
break;
}
}
else if( ev.keyboard.keycode == ALLEGRO_KEY_ENTER )
{
N_STR *txtmsg = new_nstr( 1024 );
al_ustr_trim_ws( chat_line ) ;
al_ustr_to_buffer( chat_line, txtmsg -> data, txtmsg -> length );
N_STR *netmsg = netmsg_make_string_msg( netw -> link . sock, -1, name, txtmsg, txtmsg, 1 );
netw_add_msg( netw, netmsg );
free_nstr( &txtmsg );
}
else if( ev.type == ALLEGRO_EVENT_TIMER )
{
if( al_get_timer_event_source( fps_timer ) == ev.any.source )
{
do_draw = 1 ;
}
else if( al_get_timer_event_source( logic_timer ) == ev.any.source )
{
do_logic = 1;
}
else if( al_get_timer_event_source( network_heartbeat_timer ) == ev.any.source )
{
do_network_update = 1;
}
}
else if( ev.type == ALLEGRO_EVENT_MOUSE_AXES )
{
mx = ev.mouse.x;
my = ev.mouse.y;
}
else if( ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN )
{
if( ev.mouse.button == 1 )
mouse_b1 = 1 ;
if( ev.mouse.button == 2 )
mouse_b2 = 1 ;
}
else if( ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP )
{
if( ev.mouse.button == 1 )
mouse_b1 = 0 ;
if( ev.mouse.button == 2 )
mouse_b2 = 0 ;
}
else if( ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE )
{
DONE = 1 ;
}
else if( ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN || ev.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT )
{
al_clear_keyboard_state( display );
al_flush_event_queue( event_queue );
}
else
{
/* Processing inputs */
get_keyboard( chat_line, ev );
}
}
while( !al_is_event_queue_empty( event_queue) );
if( do_logic == 1 )
{
N_STR *netmsg = NULL ;
netmsg = netw_get_msg( netw );
if( netmsg )
{
int type = -1 ;
type = netw_msg_get_type( netmsg );
switch( type )
{
case( NETMSG_GET_BOX ):
/* ask for world box */
break ;
case( NETMSG_BOX ):
/* a world object at position X,Y,Z with associated datas, add/update local world cache */
break ;
case( NETMSG_POSITION ):
{
/* add/update object with id at position */
double pos[ 3 ];
double spe[ 3 ];
int id = -1, timestamp = -1 ;
netw_get_position( netmsg, &id, &pos[ 0 ],&pos[ 1 ],&pos[ 2 ], &spe[ 0 ], &spe[ 1 ], &spe[ 2 ], &timestamp );
// too much log n_log( LOG_INFO, "Received position from %d: %g %g", id, pos[ 0 ], pos[ 1 ] );
update_peer( peer_table, id, pos );
}
break;
case( NETMSG_STRING ):
{
/* add text to chat */
int id = -1, color = -1 ;
N_STR *name = NULL, *txt = NULL, *chan = NULL ;
netw_get_string( netmsg, &id, &name, &chan, &txt, &color );
n_log( LOG_INFO, "Received chat from %s:%s:%s (id: %d , color:%d)", name, chan, txt, id, color );
}
break;
/* compare to sent pings and add string to chat with times */
break;
/* compare to sent pings and add string to chat with times */
break;
case( NETMSG_QUIT ):
n_log( LOG_INFO, "Quit received !" );
DONE = 1 ;
break ;
default:
n_log( LOG_ERR, "Unknow message type %d", type );
DONE = 1 ;
break ;
}
}
ping_time += 1.0 / 60.0 ;
if( key[KEY_ESC] )
{
if( QUIT_ASKED != 1 )
{
QUIT_ASKED = 1 ;
n_log( LOG_INFO, "Asking server to quit..." );
}
}
manage_peers( peer_table, 1000000 / 60.0 );
do_logic = 0 ;
}
if( do_draw == 1 )
{
al_acknowledge_resize( display );
int w = al_get_display_width( display );
int h = al_get_display_height( display );
al_set_target_bitmap( scrbuf );
al_clear_to_color( al_map_rgba( 0, 0, 0, 255 ) );
al_set_target_bitmap( al_get_backbuffer( display ) );
al_clear_to_color( al_map_rgba( 0, 0, 0, 255 ) );
al_draw_bitmap( scrbuf, 0, 0, 0 );
/* mouse pointer */
/*al_draw_line( mx - 5, my, mx + 5, my, al_map_rgb( 255, 0, 0 ), 1 );
al_draw_line( mx, my + 5, mx, my - 5, al_map_rgb( 255, 0, 0 ), 1 );*/
draw_peers( peer_table, font, white_color );
al_draw_ustr( font, white_color, 0, HEIGHT - 20, ALLEGRO_ALIGN_LEFT, chat_line );
al_flip_display();
do_draw = 0 ;
}
if( do_network_update == 1 )
{
/* send position here */
netw_send_position( netw, ident, mx, my, 0, 0, 0, 0, 0 );
do_network_update = 0 ;
}
}
while( !DONE );
exit_client:
return 0;
}
void usage(void)
Definition: ex_common.c:20
void process_args(int argc, char **argv)
Definition: ex_common.c:27
int main(void)
Definition: ex_exceptions.c:71
#define WIDTH
ALLEGRO_TIMER * fps_timer
int getoptret
int DONE
int log_level
ALLEGRO_BITMAP * scr_buf
#define HEIGHT
ALLEGRO_TIMER * logic_timer
ALLEGRO_DISPLAY * display
long int life_time
current life time, updated when receiving a position from a peer.
int id
remote object id
int draw_peers(HASH_TABLE *peer_table, ALLEGRO_FONT *font, ALLEGRO_COLOR color)
double position[3]
last received object position
int key[7]
APP_KEYS
@ KEY_SPACE
@ KEY_CTRL
@ KEY_UP
@ KEY_LEFT
@ KEY_RIGHT
@ KEY_DOWN
@ KEY_ESC
int update_peer(HASH_TABLE *peer_table, int id, double position[3])
int manage_peers(HASH_TABLE *peer_table, int delta_t)
a simple structure to hold objects positions / timeouts
NETWORK * server
Definition: ex_network.c:17
static pthread_t netw_thr
Definition: ex_network.c:22
int ip_version
Definition: ex_network.c:20
NETWORK * netw
Network for server mode, accepting incomming.
Definition: ex_network.c:18
int get_keyboard(ALLEGRO_USTR *str, ALLEGRO_EVENT event)
update a keyboard buffer from an event
Definition: n_allegro5.c:19
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
Definition: n_common.h:183
#define __n_assert(__ptr, __ret)
macro to assert things
Definition: n_common.h:276
#define _str(__PTR)
define true
Definition: n_common.h:172
void n_abort(char const *format,...)
abort program with a text
Definition: n_common.c:38
#define _nstr(__PTR)
N_STR or "NULL" string for logging purposes.
Definition: n_common.h:178
int ht_put_ptr_ex(HASH_TABLE *table, unsigned long int hash_value, void *val, void(*destructor)(void *ptr))
put a pointer value with given key in the targeted hash table (HASH_CLASSIC only)
Definition: n_hash.c:2526
#define ht_foreach(__ITEM_, __HASH_)
ForEach macro helper (classic / old)
Definition: n_hash.h:163
int ht_remove_ex(HASH_TABLE *table, unsigned long int hash_value)
Remove a key from a hash table (HASH_CLASSIC only)
Definition: n_hash.c:2582
HASH_TABLE * new_ht(unsigned long int size)
Create a hash table with the given size.
Definition: n_hash.c:2169
int ht_get_ptr_ex(HASH_TABLE *table, unsigned long int hash_value, void **val)
Retrieve a pointer value in the hash table, at the given key.
Definition: n_hash.c:2496
#define hash_val(node, type)
Cast a HASH_NODE element.
Definition: n_hash.h:159
structure of a hash table
Definition: n_hash.h:109
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
Definition: n_list.c:244
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper.
Definition: n_list.h:70
LIST * new_generic_list(int max_items)
Initialiaze a generic list container to max_items pointers.
Definition: n_list.c:20
Structure of a generic LIST container.
Definition: n_list.h:45
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition: n_log.h:74
#define LOG_DEBUG
debug-level messages
Definition: n_log.h:66
#define LOG_ERR
error conditions
Definition: n_log.h:58
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
Definition: n_log.c:97
#define LOG_NOTICE
normal but significant condition
Definition: n_log.h:62
#define LOG_NULL
no log output
Definition: n_log.h:27
#define LOG_INFO
informational
Definition: n_log.h:64
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
Definition: n_str.h:222
#define nstrprintf(__nstr_var,...)
Macro to quickly allocate and sprintf to N_STR *.
Definition: n_str.h:97
N_STR * char_to_nstr(const char *src)
Convert a char into a N_STR, short version.
Definition: n_str.c:274
N_STR * new_nstr(NSTRBYTE size)
create a new N_STR string
Definition: n_str.c:215
A box including a string and his lenght.
Definition: n_str.h:173
#define NETMSG_IDENT_REQUEST
Network Message is identification request: (int)type , (int)id , (N_STR *)name , (N_STR *)password.
Definition: n_network_msg.h:27
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)
Retrieves position from netwmsg.
#define NETMSG_PING_REQUEST
Network Message is ping request: (int)type , (int)id_from , (int)id_to.
Definition: n_network_msg.h:37
#define NETMSG_IDENT_REPLY_NOK
Network Message is identification reply NON OK: (int)type , (int)id , (N_STR *)name ,...
Definition: n_network_msg.h:31
#define NETMSG_STRING
Network Message is string: (int)type , (int)id , (N_STR *)name , (N_STR *)chan , (N_STR *)text ,...
Definition: n_network_msg.h:33
#define NETMSG_PING_REPLY
Network Message is ping reply: (int)type , (int)id_from , (int)id_to.
Definition: n_network_msg.h:39
#define NETMSG_QUIT
Network asking for exit.
Definition: n_network_msg.h:45
#define NETMSG_POSITION
Network Message position: (int)type , (int)id , (int)X , (int)Y , (int)x_shift , (int)y_shift ,...
Definition: n_network_msg.h:35
int netw_msg_get_type(N_STR *msg)
Get the type of message without killing the first number. Use with netw_get_XXX.
#define NETMSG_BOX
Network Message is box retrieving reply: (int x , int y , int z , N_STR *data )
Definition: n_network_msg.h:43
#define NETMSG_GET_BOX
Network Message is box retrieve: int x , int y , int z.
Definition: n_network_msg.h:41
#define NETMSG_IDENT_REPLY_OK
Network Message is identification reply OK : (int)type , (int)id , (N_STR *)name ,...
Definition: n_network_msg.h:29
int netw_get_string(N_STR *msg, int *id, N_STR **name, N_STR **chan, N_STR **txt, int *color)
Retrieves string from netwmsg.
int netw_get_ident(N_STR *msg, int *type, int *ident, N_STR **name, N_STR **passwd)
Retrieves identification from netwmsg.
N_STR * netmsg_make_string_msg(int id_from, int id_to, N_STR *name, N_STR *chan, N_STR *txt, int color)
make a network NETMSG_STRING message with given parameters
N_STR * netw_get_msg(NETWORK *netw)
Get a message from aimed NETWORK.
Definition: n_network.c:2067
int netw_add_msg(NETWORK *netw, N_STR *msg)
Add a message to send in aimed NETWORK.
Definition: n_network.c:1988
#define NETWORK_IPV6
Flag to force IPV6
Definition: n_network.h:31
int netw_start_thr_engine(NETWORK *netw)
Start the NETWORK netw Threaded Engine.
Definition: n_network.c:2151
#define NETWORK_IPV4
Flag to force IPV4
Definition: n_network.h:29
int netw_wait_close(NETWORK **netw)
Wait for peer closing a specified Network, destroy queues, free the structure.
Definition: n_network.c:1597
#define NETWORK_IPALL
Flag for auto detection by OS of ip version to use.
Definition: n_network.h:27
int netw_send_quit(NETWORK *netw)
Add a formatted NETMSG_QUIT message to the specified network.
Definition: n_network.c:3215
int netw_connect(NETWORK **netw, char *host, char *port, int ip_version)
Use this to connect a NETWORK to any listening one, unrestricted send/recv lists.
Definition: n_network.c:1384
int netw_send_ident(NETWORK *netw, int type, int id, N_STR *name, N_STR *passwd)
Add a formatted NETWMSG_IDENT message to the specified network.
Definition: n_network.c:3121
int netw_send_position(NETWORK *netw, int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp)
Add a formatted NETWMSG_IDENT message to the specified network.
Definition: n_network.c:3148
Structure of a NETWORK.
Definition: n_network.h:254
Allegro5 helpers.
Common headers and low-level hugly functions & define.
Hash functions and table.
List structures and definitions.
Network Engine.
Network messages , serialization tools.
N_STR and string function declaration.