1 // Emacs style mode select   -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // Copyright (C) 2000 by DooM Legacy Team.
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 //-----------------------------------------------------------------------------
17 
18 #ifndef SRVLIST_H
19 #define SRVLIST_H
20 
21 #include <time.h>
22 
23 enum ServerType
24 {
25 	ST_PERMANENT = 0,
26 	ST_TEMPORARY,
27 };
28 
29 //=============================================================================
30 
31 class CItem
32 {
33 	friend class CList;
34 protected:
35 	CItem *next;
36 public:
37 	CItem();
~CItem()38 	virtual ~CItem() {}; // destructor must exist and be virtual
39 	virtual void print() = 0;
40 };
41 
42 //=============================================================================
43 
44 class CList
45 {
46 protected:
47 	CItem *list;
48 	CItem *current; // the current item we are pointing on (for getfirst/getnext)
49 public:
50 	CList();
51 	virtual ~CList();
52 	int insert(CItem *);
53 	int remove(CItem *);
54 	CItem *getFirst();
55 	CItem *getNext();
56 	void show();
57 };
58 
59 //=============================================================================
60 
61 class CInetAddr
62 {
63 protected:
64 	char ip[16];
65 	char port[8];
66 	bool PortNotChanged;
67 public:
68 	CInetAddr(const char *ip, const char *port);
69 	const char *getIP();
70 	bool setPort(const char *port);
71 	const char *getPort();
72 };
73 
74 //=============================================================================
75 
76 class CPlayerItem : public CItem, public CInetAddr
77 {
78 friend class CPlayerList;
79 private:
80 	char nickname[32];
81 public:
82 	CPlayerItem(const char *ip, const char *port, const char *nickname);
83 	void print();
84 	char *getString();
85 };
86 
87 //=============================================================================
88 
89 class CPlayerList : public CList
90 {
91 };
92 
93 //=============================================================================
94 
95 #define REG_TIME_SIZE 24   //1970-00-00T00:00:00.0+00:00
96 #define GUID_SIZE 24-1 // format is 12700000000105000
97 
98 class CServerItem : public CItem, public CInetAddr
99 {
100 	friend class CServerList;
101 
102 private:
103 	char hostname[32];
104 	char version[8]; // format is: x.yy.z (like 1.30.2 or 1.31)
105 	CPlayerList players_list;
106 	char reg_time[REG_TIME_SIZE];
107 	char guid[GUID_SIZE+1];
108 
109 public:
110 	ServerType type;
111 	time_t HeartBeat;
112 
113 	CServerItem(const char *ip, const char *port, const char *hostname, const char *version, ServerType type);
114 	void print();
115 	const char *getString();
116 	const char *getName();
117 	const char *getVersion();
118 	const char *getRegtime();
119 	const char *getGuid();
120 };
121 
122 //=============================================================================
123 
124 class CServerList : public CList
125 {
126 public:
127 	void insertPlayer(CServerItem *server, CPlayerItem *player);
128 	void removePlayer(CServerItem *server, CPlayerItem *player);
129 	int insert(const char *ip, const char *port, const char *hostname, const char *version, ServerType type);
130 	int insert(CServerItem *server);
131 	int remove(const char *ip, const char *port, const char *hostname, const char *version, ServerType type);
132 	int remove(CServerItem *server);
133 	void show();
134 };
135 
136 #endif
137