aboutsummaryrefslogtreecommitdiff
path: root/src/parsec_server/MasterServerItem.cpp
blob: 445e5900b87f9a23275c3e45c83d5759dba54270 (plain)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * MasterServerList.cpp
 *
 *  Created on: Jan 2, 2013
 *      Author: jasonw
 */
// C library
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/types.h> 
#include <sys/timeb.h>

// compilation flags/debug support
#include "config.h"
#include "debug.h"

// general definitions
#include "general.h"
#include "objstruc.h"

// global externals
#include "globals.h"

// subsystem headers
#include "net_defs.h"
//FIXME: ????
#include "sys_refframe_sv.h"

// UNP header
#include "net_wrap.h"

// server defs
#include "e_defs.h"

// net game header
#include "net_game_sv.h"

// mathematics header
#include "utl_math.h"

// local module header
#include "e_gameserver.h"

// proprietary module headers
#include "con_arg.h"
#include "con_aux_sv.h"
#include "con_com_sv.h"
#include "con_main_sv.h"
#include "e_colldet.h"
#include "g_extra.h"
#include "inp_main_sv.h"
#include "net_csdf.h"
#include "net_limits.h"
#include "net_udpdriver.h"
#include "net_util.h"
#include "net_packetdriver.h"
#include "obj_clas.h"
//#include "e_stats.h"
#include "g_main_sv.h"
#include "e_connmanager.h"
#include "e_packethandler.h"
#include "e_simulator.h"
#include "e_simnetinput.h"
#include "e_simnetoutput.h"
#include "sys_refframe_sv.h"
#include "sys_util_sv.h"

#include "gd_help.h"


#include "MasterServerItem.h"

MasterServerItem::MasterServerItem() {
	// TODO Auto-generated constructor stub

}
MasterServerItem::MasterServerItem(int SrvID, int CurrPlayers, int MaxPlayers,
		int PMajor, int PMinor, char ServerName[MAX_SERVER_NAME + 1],
		char OS[MAX_OSNAME_LEN + 1], node_t *node) {

		_SrvID = SrvID;
		_CurrPlayers = CurrPlayers;
		_MaxPlayers = MaxPlayers;
		_PMajor = PMajor;
		_PMinor = PMinor;
		strncpy(_ServerName, ServerName, MAX_SERVER_NAME);
		_ServerName[MAX_SERVER_NAME] = '\0';
		strncpy(_OS, OS, MAX_OSNAME_LEN);
		_OS[MAX_OSNAME_LEN]  = '\0';
		NODE_Copy(&_Node, node);

}
MasterServerItem::~MasterServerItem() {
	// TODO Auto-generated destructor stub
}

bool MasterServerItem::update(int SrvID, int CurrPlayers, int MaxPlayers,
		int PMajor, int PMinor, char ServerName[MAX_SERVER_NAME + 1],
		char OS[MAX_OSNAME_LEN + 1], node_t *node) {

	_SrvID = SrvID;
	_CurrPlayers = CurrPlayers;
	_MaxPlayers = MaxPlayers;
	_PMajor = PMajor;
	_PMinor = PMinor;
	SAFE_STR_DUPLICATE(_ServerName, ServerName, MAX_SERVER_NAME-1);
	_ServerName[MAX_SERVER_NAME] = '\0';
	SAFE_STR_DUPLICATE(_OS, OS, MAX_OSNAME_LEN-1);
	_OS[MAX_OSNAME_LEN]  = '\0';
	NODE_Copy(&_Node, node);


	return true;
}

bool MasterServerItem::remove() {

	// set the SrvID to -1 to indicate it should be removed.
	_SrvID = -1;

	return false;
}

bool MasterServerItem::operator <(const MasterServerItem& msl) const {

	return false;
}

bool MasterServerItem::operator ==(const MasterServerItem& msl) const {

	return false;
}

bool MasterServerItem::operator !=(const MasterServerItem& msl) const {

	return false;
}



bool MasterServerItem::isValid() const {
	if(_SrvID > -1) {
		return true;
	}
	return false;
}

int MasterServerItem::GetSrvID() {
	return _SrvID;
}

int MasterServerItem::GetCurrPlayers() {
	return _CurrPlayers;
}

int MasterServerItem::GetMaxPlayers() {
	return _MaxPlayers;
}

int MasterServerItem::GetPMajor() {
	return _PMajor;
}

int MasterServerItem::GetPMinor() {
	return _PMinor;
}

int MasterServerItem::GetServerName(char *buffer, int buffer_sz) {

	int str_sz = strlen(_ServerName);
	if(buffer_sz < str_sz + 1){
		return -1;
	}

	strncpy(buffer, _ServerName, str_sz);
	buffer[str_sz + 1] = '\0';

	return 0;
}

int  MasterServerItem::GetOS(char *buffer, int buffer_sz) {
	int str_sz = strlen(_OS);
	if(buffer_sz < str_sz + 1){
		return -1;
	}

	strncpy(buffer, _OS, str_sz);
	buffer[str_sz + 1] = '\0';

	return 0;
}

MasterServerItem::MasterServerItem(const MasterServerItem& msi_copy) :
			 _SrvID (msi_copy._SrvID),
			 _CurrPlayers (msi_copy._CurrPlayers),
			 _MaxPlayers (msi_copy._MaxPlayers),
			 _PMajor (msi_copy._PMajor),
			 _PMinor (msi_copy._PMinor)
{
	strncpy(_ServerName, msi_copy._OS, MAX_SERVER_NAME);
	_ServerName[MAX_SERVER_NAME]='\0';
	strncpy( _OS, msi_copy._OS, MAX_OSNAME_LEN);
	_OS[MAX_OSNAME_LEN]='\0';
	memcpy(&_Node, &msi_copy._Node, sizeof( node_t ));

}

int MasterServerItem::GetNode(node_t* node) {
	NODE_Copy(node, &_Node);

	return true;
}