updated docs
[rlserver.git] / sessions.h
blobab8dc888a9da80cc2c0d4dce3e987dd7019a0c4d
1 #ifndef __RLS_SESSIONS__
2 #define __RLS_SESSIONS__
4 #include <time.h>
5 #include <pthread.h>
6 #include "users.h"
7 #include "games.h"
9 struct vt100;
11 typedef struct session_info
13 int child_pid; // or 0
14 int socket;
15 int user_id; // or -1
16 char user_name[USER_NAME_LEN];
17 char game[GAME_NAME_LEN];
18 time_t last_activity; // to display idle time
20 int term_wid, term_hgt; // terminal size
21 struct vt100 *term;
22 int pty_master; // forked processes should close this
24 int observer_count; // prohibit observing if -1
25 int *observers; // array of sockets
27 pthread_mutex_t mutex; // used to lock one session only
29 // for the current game, not for the whole session
30 struct
32 time_t start_time; // when the game was started
33 int bytes_in, bytes_out; // not including observers
34 } game_stat;
36 struct session_info *prev, *next;
37 } session_info;
40 session_info* add_session (int sock);
41 // remove session from the list, socket and master_pty are not closed
42 // socket is removed from observers of all other sessions
43 void remove_session (session_info *sess);
45 // check if user is already logged in
46 int user_is_connected (int id);
48 int add_observer (int n, int sock);
49 void stop_observing (session_info *sess);
51 // send SIGTERM to all running games
52 void terminate_games (void);
54 // NB! not protected by mutex
55 void close_sessions (void);
56 // NB! not protected by mutex
57 void release_sessions (void);
59 #endif