Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_user.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_USER_MANAGEMENT
27
28#define N_USER_MANAGEMENT
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include "nilorea/n_common.h"
35#include "nilorea/n_log.h"
36#include "nilorea/n_str.h"
37#include "nilorea/n_network.h"
38#include "nilorea/n_3d.h"
39
46#define USERLIST_ALL 0
48#define USERLIST_ALL_EXCEPT 1
50#define USERLIST_ONE 2
51
78
80typedef struct N_USERLIST {
83
85 int max,
88
90 pthread_rwlock_t user_rwbolt;
91
93
95N_USERLIST* userlist_new(int max);
97int userlist_set_position_behavior(N_USERLIST* ulist, int id, int nb_rec_pos, int only_last_pos);
101int userlist_del_user(N_USERLIST* ulist, int id);
103int userlist_add_msg_to_ex(N_USERLIST* ulist, N_STR* msg, int mode, int id);
105int userlist_add_msg_to(N_USERLIST* ulist, N_STR* msg, int id);
109int userlist_add_msg_to_all_except(N_USERLIST* ulist, N_STR* msg, int id);
111int userlist_destroy(N_USERLIST** ulist);
113int userlist_user_add_waiting_msg(N_USERLIST* ulist, int id, N_STR* netmsg);
118
123#ifdef __cplusplus
124}
125#endif
126
127#endif // header guard
static int mode
NETWORK * netw
Network for server mode, accepting incomming.
Definition ex_network.c:38
Structure of a generic LIST container.
Definition n_list.h:58
A box including a string and his lenght.
Definition n_str.h:60
char name[1024]
User Name.
Definition n_user.h:55
VECTOR3D * last_positions
Last nb_rec_pos position messages, for a better dead reckoning / lag simulation.
Definition n_user.h:70
int only_last_pos
1 => keep only_last_position in waitlist , 0 => send all the positions, default: 1
Definition n_user.h:65
int max
Maximum of user inside the list.
Definition n_user.h:85
LIST * netw_waitlist
N_STR *messages waiting to be sent.
Definition n_user.h:75
pthread_rwlock_t user_rwbolt
Mutex for thread safe user management.
Definition n_user.h:90
int state
State of the current user.
Definition n_user.h:61
VECTOR3D position
actual position
Definition n_user.h:72
NETWORK * netw
Associated NETWORK.
Definition n_user.h:58
int highter
Position of the highter user inside the list.
Definition n_user.h:87
int id
Unique world ident.
Definition n_user.h:67
int nb_rec_pos
Number of saved positions , default: 10.
Definition n_user.h:63
N_USER * list
Pointer to the allocated list of user.
Definition n_user.h:82
int userlist_del_user(N_USERLIST *ulist, int id)
remove a user from the list by id
Definition n_user.c:144
int userlist_add_msg_to(N_USERLIST *ulist, N_STR *msg, int id)
add a message to a specific user by id
Definition n_user.c:235
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
Definition n_user.c:192
int userlist_user_send_waiting_msgs(N_USERLIST *ulist, int id)
send all waiting messages for a specific user
Definition n_user.c:312
N_USERLIST * userlist_new(int max)
allocate a new N_USERLIST with the given maximum number of users
Definition n_user.c:33
int userlist_add_msg_to_all(N_USERLIST *ulist, N_STR *msg)
add a message to all users in the list
Definition n_user.c:245
int userlist_send_waiting_msgs(N_USERLIST *ulist)
send all waiting messages for all users in the list
Definition n_user.c:335
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
Definition n_user.c:70
int userlist_add_user(N_USERLIST *ulist, NETWORK *netw)
add a user associated with a NETWORK connection to the list
Definition n_user.c:117
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
Definition n_user.c:256
int userlist_destroy(N_USERLIST **ulist)
destroy a N_USERLIST and free all resources
Definition n_user.c:265
int userlist_user_add_waiting_msg(N_USERLIST *ulist, int id, N_STR *netmsg)
add a waiting message to a specific user's queue
Definition n_user.c:289
USER management cell.
Definition n_user.h:53
USER list.
Definition n_user.h:80
Structure of a NETWORK.
Definition n_network.h:258
double VECTOR3D[3]
struct of a point
Definition n_3d.h:58
Simple 3D movement simulation.
Common headers and low-level functions & define.
Generic log system.
Network Engine.
N_STR and string function declaration.