Nilorea Library
C utilities for networking, threading, graphics
NETWORK USERS: server side network oriented user handling

Data Structures

struct  N_USER
 USER management cell. More...
 
struct  N_USERLIST
 USER list. More...
 

Macros

#define USERLIST_ALL   0
 flag to target all users in the list More...
 
#define USERLIST_ALL_EXCEPT   1
 flag to target all users in the list except one More...
 
#define USERLIST_ONE   2
 flag to target one user in the list More...
 

Functions

int userlist_add_msg_to (N_USERLIST *ulist, N_STR *msg, int id)
 add a N_STR *message to user list (USERLIST_ONE) More...
 
int userlist_add_msg_to_all (N_USERLIST *ulist, N_STR *msg)
 add a N_STR *message to user list (USERLIST_ALL) More...
 
int userlist_add_msg_to_all_except (N_USERLIST *ulist, N_STR *msg, int id)
 add a N_STR *message to user list except user 'id' (USERLIST_ALL_EXCEPT) More...
 
int userlist_add_msg_to_ex (N_USERLIST *ulist, N_STR *msg, int mode, int id)
 add a N_STR *message to user list More...
 
int userlist_add_user (N_USERLIST *ulist, NETWORK *netw)
 add an user to the list More...
 
int userlist_del_user (N_USERLIST *ulist, int id)
 delete an user from the list More...
 
int userlist_destroy (N_USERLIST **ulist)
 destroy and free a N_USERLIST *userlist More...
 
N_USERLISTuserlist_new (int max)
 create a new N_USERLIST user list with 'max' users More...
 
int userlist_send_waiting_msgs (N_USERLIST *ulist)
 send all waiting messages ofr each user of the lsit More...
 
int userlist_set_position_behavior (N_USERLIST *ulist, int id, int nb_rec_pos, int only_last_pos)
 set the position parameters for trajectory processing for user 'id' More...
 
int userlist_user_add_waiting_msg (N_USERLIST *ulist, int id, N_STR *netmsg)
 add a newtork message to specified user 'id' More...
 
int userlist_user_send_waiting_msgs (N_USERLIST *ulist, int id)
 send all waiting messages in user 'id' waiting list More...
 

Detailed Description


Data Structure Documentation

◆ N_USER

struct N_USER

USER management cell.

Definition at line 36 of file n_user.h.

+ Collaboration diagram for N_USER:
Data Fields
int id Unique world ident.
VECTOR3D * last_positions Last nb_rec_pos position messages, for a better dead reckoning / lag simulation.
char name[1024] User Name.
int nb_rec_pos Number of saved positions , default: 10.
NETWORK * netw Associated NETWORK.
LIST * netw_waitlist N_STR *messages waiting to be sent.
int only_last_pos 1 => keep only_last_position in waitlist , 0 => send all the positions, default: 1
VECTOR3D position actual position
int state State of the current user.

◆ N_USERLIST

struct N_USERLIST

USER list.

Definition at line 66 of file n_user.h.

+ Collaboration diagram for N_USERLIST:
Data Fields
int highter Position of the highter user inside the list.
N_USER * list Pointer to the allocated list of user.
int max Maximum of user inside the list.
pthread_rwlock_t user_rwbolt Mutex for thread safe user management.

Macro Definition Documentation

◆ USERLIST_ALL

#define USERLIST_ALL   0

flag to target all users in the list

Definition at line 29 of file n_user.h.

◆ USERLIST_ALL_EXCEPT

#define USERLIST_ALL_EXCEPT   1

flag to target all users in the list except one

Definition at line 31 of file n_user.h.

◆ USERLIST_ONE

#define USERLIST_ONE   2

flag to target one user in the list

Definition at line 33 of file n_user.h.

Function Documentation

◆ userlist_add_msg_to()

int userlist_add_msg_to ( N_USERLIST ulist,
N_STR msg,
int  id 
)

add a N_STR *message to user list (USERLIST_ONE)

Parameters
ulisttargeted N_USERLIST *ulist
msgnetwork message to add
idtargeted user id
Returns
TRUE or FALSE

Definition at line 240 of file n_user.c.

References userlist_add_msg_to_ex(), and USERLIST_ONE.

+ Here is the call graph for this function:

◆ userlist_add_msg_to_all()

int userlist_add_msg_to_all ( N_USERLIST ulist,
N_STR msg 
)

add a N_STR *message to user list (USERLIST_ALL)

Parameters
ulisttargeted N_USERLIST *ulist
msgnetwork message to add
Returns
TRUE or FALSE

Definition at line 252 of file n_user.c.

References userlist_add_msg_to_ex(), and USERLIST_ALL.

+ Here is the call graph for this function:

◆ userlist_add_msg_to_all_except()

int userlist_add_msg_to_all_except ( N_USERLIST ulist,
N_STR msg,
int  id 
)

add a N_STR *message to user list except user 'id' (USERLIST_ALL_EXCEPT)

Parameters
ulisttargeted N_USERLIST *ulist
iduser id to ignore
msgnetwork message to add
Returns
TRUE or FALSE

Definition at line 266 of file n_user.c.

References userlist_add_msg_to_ex(), and USERLIST_ALL_EXCEPT.

+ Here is the call graph for this function:

◆ userlist_add_msg_to_ex()

int userlist_add_msg_to_ex ( N_USERLIST ulist,
N_STR msg,
int  mode,
int  id 
)

add a N_STR *message to user list

Parameters
ulisttargeted N_USERLIST *ulist
msgnetwork message to add
modeone of USERLIST_ALL , USERLIST_ONE , USERLIST_ALL_EXCEPT
idtargeted user id to use (USERLIST_ONE) or to ignore (USERLIST_ALL_EXCEPT)
Returns
TRUE or FALSE

Definition at line 191 of file n_user.c.

References __n_assert, netw_add_msg(), nstrdup(), read_lock, unlock, USERLIST_ALL, USERLIST_ALL_EXCEPT, and USERLIST_ONE.

Referenced by userlist_add_msg_to(), userlist_add_msg_to_all(), and userlist_add_msg_to_all_except().

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

◆ userlist_add_user()

int userlist_add_user ( N_USERLIST ulist,
NETWORK netw 
)

add an user to the list

Parameters
ulisttargeted N_USERLIST *ulist
netwassociated NETWORK *network associated to the new use to create
Returns
the new user id or -1 on error

Definition at line 101 of file n_user.c.

References __n_assert, unlock, and write_lock.

◆ userlist_del_user()

int userlist_del_user ( N_USERLIST ulist,
int  id 
)

delete an user from the list

Parameters
ulisttargeted N_USERLIST *ulist
idid of the user to delete
Returns
TRUE or FALSE

Definition at line 134 of file n_user.c.

References __n_assert, list_empty(), LOG_ERR, n_log, Realloc, unlock, and write_lock.

+ Here is the call graph for this function:

◆ userlist_destroy()

int userlist_destroy ( N_USERLIST **  ulist)

destroy and free a N_USERLIST *userlist

Parameters
ulisttargeted N_USERLIST *list to destroy
Returns
TRUE or FALSE

Definition at line 278 of file n_user.c.

References __n_assert, Free, list_destroy(), unlock, and write_lock.

+ Here is the call graph for this function:

◆ userlist_new()

N_USERLIST * userlist_new ( int  max)

create a new N_USERLIST user list with 'max' users

Parameters
maxthe maximum number of users in the list
Returns
a new N_USERLIST *list or NULL

Definition at line 16 of file n_user.c.

References __n_assert, Free, init_lock, Malloc, and new_generic_list().

+ Here is the call graph for this function:

◆ userlist_send_waiting_msgs()

int userlist_send_waiting_msgs ( N_USERLIST ulist)

send all waiting messages ofr each user of the lsit

Parameters
ulisttargeted N_USERLIST *list
Returns
TRUE or FALSE

Definition at line 362 of file n_user.c.

References __n_assert, list_empty(), list_foreach, netw_add_msg(), read_lock, and unlock.

+ Here is the call graph for this function:

◆ userlist_set_position_behavior()

int userlist_set_position_behavior ( N_USERLIST ulist,
int  id,
int  nb_rec_pos,
int  only_last_pos 
)

set the position parameters for trajectory processing for user 'id'

Parameters
ulisttargeted N_USERLIST *ulist
idid of the user
nb_rec_posnumber of positions updates kept in list
only_last_posflag if we're only keeping the last position ( if set nb_rec_pos is ignored )
Returns
TRUE or FALSE

Definition at line 57 of file n_user.c.

References __n_assert, LOG_ERR, n_log, read_lock, Realloc, unlock, and write_lock.

◆ userlist_user_add_waiting_msg()

int userlist_user_add_waiting_msg ( N_USERLIST ulist,
int  id,
N_STR netmsg 
)

add a newtork message to specified user 'id'

Parameters
ulisttargeted N_USERLIST *list
idtargeted user id
netmsgnetwork message to add
Returns
TRUE or FALSE

Definition at line 306 of file n_user.c.

References __n_assert, list_push(), read_lock, and unlock.

+ Here is the call graph for this function:

◆ userlist_user_send_waiting_msgs()

int userlist_user_send_waiting_msgs ( N_USERLIST ulist,
int  id 
)

send all waiting messages in user 'id' waiting list

Parameters
ulisttargeted N_USERLIST *list
idtargeted user id
Returns
TRUE or FALSE

Definition at line 334 of file n_user.c.

References __n_assert, list_empty(), list_foreach, netw_add_msg(), read_lock, and unlock.

+ Here is the call graph for this function: