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_USERLIST * userlist_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 54 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 81 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 47 of file n_user.h.

Referenced by userlist_add_msg_to_all(), and userlist_add_msg_to_ex().

◆ USERLIST_ALL_EXCEPT

#define USERLIST_ALL_EXCEPT   1

flag to target all users in the list except one

Definition at line 49 of file n_user.h.

Referenced by userlist_add_msg_to_all_except(), and userlist_add_msg_to_ex().

◆ USERLIST_ONE

#define USERLIST_ONE   2

flag to target one user in the list

Definition at line 51 of file n_user.h.

Referenced by userlist_add_msg_to(), and userlist_add_msg_to_ex().

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 236 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 246 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 257 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 193 of file n_user.c.

References __n_assert, N_USERLIST::highter, N_USERLIST::list, mode, N_USER::netw, netw_add_msg(), nstrdup(), read_lock, N_USER::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 118 of file n_user.c.

References __n_assert, N_USERLIST::highter, N_USERLIST::list, N_USER::netw, netw, N_USER::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 145 of file n_user.c.

References __n_assert, N_USERLIST::highter, N_USER::id, N_USER::last_positions, N_USERLIST::list, list_empty(), LOG_ERR, N_USERLIST::max, n_log, N_USER::name, N_USER::nb_rec_pos, N_USER::netw, N_USER::netw_waitlist, N_USER::only_last_pos, N_USER::position, Realloc, N_USER::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 266 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 34 of file n_user.c.

References __n_assert, Free, N_USERLIST::highter, N_USER::id, init_lock, N_USER::last_positions, N_USERLIST::list, Malloc, N_USERLIST::max, MAX_LIST_ITEMS, N_USER::name, N_USER::nb_rec_pos, N_USER::netw, N_USER::netw_waitlist, new_generic_list(), N_USER::only_last_pos, N_USER::position, N_USER::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 336 of file n_user.c.

References __n_assert, N_USERLIST::highter, N_USERLIST::list, list_empty(), list_foreach, N_USER::netw, netw_add_msg(), N_USER::netw_waitlist, N_USER::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 71 of file n_user.c.

References __n_assert, N_USER::last_positions, N_USERLIST::list, LOG_ERR, N_USERLIST::max, n_log, N_USER::nb_rec_pos, N_USER::only_last_pos, read_lock, Realloc, N_USER::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 290 of file n_user.c.

References __n_assert, N_USERLIST::list, list_push(), N_USER::netw_waitlist, N_USER::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 313 of file n_user.c.

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

Here is the call graph for this function: