forked from Daggolin/rplmaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.h
121 lines (108 loc) · 3.15 KB
/
master.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// -------------------------------------------------------------------------------
// RPLMaster
// Version: 1.2
// Author: ouned
// License: GPLv3
// Website: https://jk2.ouned.de/master/
// -------------------------------------------------------------------------------
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <math.h>
#include "ini.h"
#ifdef WIN32
# include <winsock2.h>
# pragma comment(lib, "ws2_32.lib")
#else
# include <strings.h>
# include <sys/types.h>
# include <sys/time.h>
# include <netdb.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <unistd.h>
# include <netinet/in.h>
# include <arpa/inet.h>
#endif
// ---------------------------------------------------- SETTINGS ----------------------------------------------------
#define STR_VERSION "1.2"
#define RECV_TIMEOUT 500 // should not be changed
#define TIMER_LOOP 1 // should not be changed
#define MAX_RECVLEN 2048 // max. length in bytes of an incoming udp datagram
#define MAX_SOURCE_MASTERS 16 // max. supported SourceMasters
#define MAX_PROTOCOLS 16 // max. supported protocols per SourceMaster
#define MAX_SERVERS 8192 // max. free server slots (for all protocols together)
#define MAX_REQUEST_IPS_SECOND 8192 // max. number of different IP's per second
#define MAX_SERVERS_PER_PACKET 256 // max. servers per packet in a server response packet
// ------------------------------------------------------------------------------------------------------------------
typedef uint8_t byte;
#define STR_MASTER_INFO "RPLMaster " STR_VERSION "\n"
#ifdef WIN32
# define DEFAULT_EXE_NAME "rplmaster.exe"
typedef int socklen_t;
#else
# define DEFAULT_EXE_NAME "rplmaster"
# define INVALID_SOCKET -1
# define _stricmp strcasecmp
typedef int SOCKET;
# define closesocket close
#endif
typedef enum {
MSG_DEBUG,
MSG_INFO,
MSG_WARNING,
MSG_ERROR
} msg_t;
typedef enum {
STATE_UNUSED,
STATE_DISABLED,
STATE_ACTIVE,
} srvstate_t;
typedef struct {
int active;
char host[128];
struct sockaddr_in addr;
int port;
int protocols[MAX_PROTOCOLS];
int interval;
time_t nextReq;
} srcmaster_t;
typedef struct {
srvstate_t state;
struct sockaddr_in addr;
int protocol;
time_t nextReq;
time_t disable;
time_t timeout;
time_t lastheartbeat;
} srv_t;
typedef struct {
int port;
int request;
int timeout;
int debug;
int disable;
int maxserversip;
int maxpacketsip;
int backupfile;
int stef;
srcmaster_t srcmasters[MAX_SOURCE_MASTERS];
} conf_t;
typedef struct {
struct in_addr ip;
int numreq;
} reqip_t;
void PacketReceived(byte *data, int len, struct sockaddr_in *from);
int ParseConfig(void *user, const char *section, const char *name, const char *value);
void TimerEvent();
char *Info_ValueForKey(const char *s, const char *key);
void TokenizeCommandline(const char *line, char *cmd, size_t cmdsize, ...);
int addrcmp(struct sockaddr_in *adr1, struct sockaddr_in *adr2);
int println(msg_t type, const char *fmt, ...);
const char *addrstr(const struct sockaddr_in *addr);
int NumServersIPAddr(struct sockaddr_in *addr);
void SaveServerState();
void RestoreServerState();