Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
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
 
#define USERLIST_ALL_EXCEPT   1
 flag to target all users in the list except one
 
#define USERLIST_ONE   2
 flag to target one user in the list
 

Functions

int userlist_add_msg_to (N_USERLIST *ulist, N_STR *msg, int id)
 add a message to a specific user by id
 
int userlist_add_msg_to_all (N_USERLIST *ulist, N_STR *msg)
 add a message to all users in the list
 
int userlist_add_msg_to_all_except (N_USERLIST *ulist, N_STR *msg, int id)
 add a message to all users except the one with the given id
 
int userlist_add_msg_to_ex (N_USERLIST *ulist, N_STR *msg, int mode, int id)
 add a message to users selected by mode and id
 
int userlist_add_user (N_USERLIST *ulist, NETWORK *netw)
 add a user associated with a NETWORK connection to the list
 
int userlist_del_user (N_USERLIST *ulist, int id)
 remove a user from the list by id
 
int userlist_destroy (N_USERLIST **ulist)
 destroy a N_USERLIST and free all resources
 
N_USERLISTuserlist_new (int max)
 allocate a new N_USERLIST with the given maximum number of users
 
int userlist_send_waiting_msgs (N_USERLIST *ulist)
 send all waiting messages for all users in the list
 
int userlist_set_position_behavior (N_USERLIST *ulist, int id, int nb_rec_pos, int only_last_pos)
 set position recording behavior for a user
 
int userlist_user_add_waiting_msg (N_USERLIST *ulist, int id, N_STR *netmsg)
 add a waiting message to a specific user's queue
 
int userlist_user_send_waiting_msgs (N_USERLIST *ulist, int id)
 send all waiting messages for a specific user
 

Detailed Description


Data Structure Documentation

◆ N_USER

struct N_USER

USER management cell.

Definition at line 53 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 80 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 46 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 48 of file n_user.h.

◆ USERLIST_ONE

#define USERLIST_ONE   2

flag to target one user in the list

Definition at line 50 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 message to a specific user by id

add a message to a specific user by id

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

Definition at line 235 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 message to all users in the list

add a message to all users in the list

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

Definition at line 245 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 message to all users except the one with the given id

add a message to all users except the one with the given id

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

Definition at line 256 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 message to users selected by mode and id

add a message to users selected by mode and id

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 192 of file n_user.c.

References __n_assert, N_USERLIST::highter, N_USERLIST::list, mode, netw, netw_add_msg(), nstrdup(), read_lock, state, unlock, N_USERLIST::user_rwbolt, 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 a user associated with a NETWORK connection to the list

add a user associated with a NETWORK connection 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 117 of file n_user.c.

References __n_assert, N_USERLIST::highter, N_USERLIST::list, netw, netw, state, unlock, N_USERLIST::user_rwbolt, and write_lock.

◆ userlist_del_user()

int userlist_del_user ( N_USERLIST ulist,
int  id 
)

remove a user from the list by id

remove a user from the list by id

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

Definition at line 144 of file n_user.c.

References __n_assert, N_USERLIST::highter, id, last_positions, N_USERLIST::list, list_empty(), LOG_ERR, N_USERLIST::max, n_log, name, nb_rec_pos, netw, netw_waitlist, only_last_pos, position, Realloc, state, unlock, N_USERLIST::user_rwbolt, and write_lock.

+ Here is the call graph for this function:

◆ userlist_destroy()

int userlist_destroy ( N_USERLIST **  ulist)

destroy a N_USERLIST and free all resources

destroy a N_USERLIST and free all resources

Parameters
ulisttargeted N_USERLIST *list to destroy
Returns
TRUE or FALSE

Definition at line 265 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)

allocate a new N_USERLIST with the given maximum number of users

allocate a new N_USERLIST with the given maximum number of users

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

Definition at line 33 of file n_user.c.

References __n_assert, Free, N_USERLIST::highter, id, init_lock, last_positions, N_USERLIST::list, Malloc, N_USERLIST::max, MAX_LIST_ITEMS, name, nb_rec_pos, netw, netw_waitlist, new_generic_list(), only_last_pos, position, state, and N_USERLIST::user_rwbolt.

+ Here is the call graph for this function:

◆ userlist_send_waiting_msgs()

int userlist_send_waiting_msgs ( N_USERLIST ulist)

send all waiting messages for all users in the list

send all waiting messages for all users in the list

Parameters
ulisttargeted N_USERLIST *list
Returns
TRUE or FALSE

Definition at line 335 of file n_user.c.

References __n_assert, N_USERLIST::highter, N_USERLIST::list, list_empty(), list_foreach, netw, netw_add_msg(), netw_waitlist, state, unlock, N_USERLIST::user_rwbolt, and write_lock.

+ 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 position recording behavior for a user

set position recording behavior for a user

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 70 of file n_user.c.

References __n_assert, last_positions, N_USERLIST::list, LOG_ERR, N_USERLIST::max, n_log, nb_rec_pos, only_last_pos, read_lock, Realloc, state, unlock, N_USERLIST::user_rwbolt, and write_lock.

◆ userlist_user_add_waiting_msg()

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

add a waiting message to a specific user's queue

add a waiting message to a specific user's queue

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

Definition at line 289 of file n_user.c.

References __n_assert, N_USERLIST::list, list_push(), netw_waitlist, state, unlock, N_USERLIST::user_rwbolt, and write_lock.

+ 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 for a specific user

send all waiting messages for a specific user

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

Definition at line 312 of file n_user.c.

References __n_assert, N_USERLIST::list, list_empty(), list_foreach, netw, netw_add_msg(), netw_waitlist, state, unlock, N_USERLIST::user_rwbolt, and write_lock.

+ Here is the call graph for this function: