]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/server/server.h
Add configuration files for client and server
[dragonblocks_alpha.git] / src / server / server.h
1 #ifndef _SERVER_H_
2 #define _SERVER_H_
3
4 #include <pthread.h>
5 #include <netinet/in.h>
6 #include <dragontype/number.h>
7 #include <dragontype/list.h>
8 #include "client/client_commands.h"
9 #include "server/server_commands.h"
10 #include "network.h"
11
12 typedef struct
13 {
14         int sockfd;                     // TCP socket to accept new connections
15         pthread_rwlock_t clients_rwlck; // lock to protect client list
16         List clients;                   // Client * -> NULL map with all connected clients
17         pthread_rwlock_t players_rwlck; // lock to protect player list
18         List players;                   // char * -> Client * map with clients that have finished auth
19 } Server;
20
21 typedef struct Client
22 {
23         int fd;               // TCP socket for connection
24         pthread_mutex_t mtx;  // mutex to protect socket
25         ClientState state;    // state of the client (created, auth, active, disconnected)
26         char *address;        // address string to use as identifier for log messages until auth is completed
27         char *name;           // player name (must be unique)
28         Server *server;       // pointer to server object (essentially the same for all clients)
29         pthread_t net_thread; // reciever thread ID
30         v3f64 pos;            // player position
31 } Client;
32
33 typedef enum
34 {
35         DISCO_NO_REMOVE = 0x01,     // don't remove from client and player list (to save extra work on server shutdown)
36         DISCO_NO_SEND = 0x02,       // don't notfiy client about the disconnect (if client sent disconnect themselves or the TCP connection died)
37         DISCO_NO_MESSAGE = 0x04,    // don't log a message about the disconnect (used on server shutdown)
38         DISCO_NO_JOIN = 0x08,       // don't wait for the reciever thread to finish (if TCP connection death was reported by reciever thread, the thread is already dead)
39 } DiscoFlag;
40
41 void server_disconnect_client(Client *client, int flags, const char *detail); // disconnect a client with various options an an optional detail message (flags: DiscoFlag bitmask)
42
43 #endif