Cube  Check-in [53f10f3320]

Overview
Comment:Move ServerInfo to separate file
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 53f10f3320267c06cbe2ba5325fbc8fc3fc652b35a8e2ac0d0fdbcf7e96aa352
User & Date: js on 2025-03-09 22:00:28
Other Links: manifest | tags
Context
2025-03-10
20:39
Fix player not moving on demo playback check-in: 57b9a0a9db user: js tags: trunk
2025-03-09
22:00
Move ServerInfo to separate file check-in: 53f10f3320 user: js tags: trunk
21:36
Remove snprintf check-in: 8386716c19 user: js tags: trunk
Changes

Added src/ServerInfo.h version [fa8f02f977].

Added src/ServerInfo.mm version [4b142ee758].

Modified src/meson.build from [d42ec0e39c] to [ff6b55de94].

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
executable('client',
  [
    'Alias.m',
    'Command.mm',
    'Cube.mm',
    'DynamicEntity.mm',
    'Identifier.m',
    'KeyMapping.m',
    'MD2.mm',
    'MapModelInfo.m',
    'Menu.m',
    'MenuItem.m',
    'Projectile.m',

    'Variable.mm',
    'client.mm',
    'clientextras.mm',
    'clientgame.mm',
    'clients2c.mm',
    'commands.mm',
    'console.mm',













>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
executable('client',
  [
    'Alias.m',
    'Command.mm',
    'Cube.mm',
    'DynamicEntity.mm',
    'Identifier.m',
    'KeyMapping.m',
    'MD2.mm',
    'MapModelInfo.m',
    'Menu.m',
    'MenuItem.m',
    'Projectile.m',
    'ServerInfo.mm',
    'Variable.mm',
    'client.mm',
    'clientextras.mm',
    'clientgame.mm',
    'clients2c.mm',
    'commands.mm',
    'console.mm',

Modified src/serverbrowser.mm from [c76375cc88] to [fe609f090e].

1
2
3
4
5


6
7
8
9
10
11
12
// serverbrowser.cpp: eihrul's concurrent resolver, and server browser window
// management

#include "SDL_thread.h"
#include "cube.h"



@interface ResolverThread: OFThread
{
	volatile bool _stop;
}

@property (copy, nonatomic) OFString *query;





>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
// serverbrowser.cpp: eihrul's concurrent resolver, and server browser window
// management

#include "SDL_thread.h"
#include "cube.h"

#import "ServerInfo.h"

@interface ResolverThread: OFThread
{
	volatile bool _stop;
}

@property (copy, nonatomic) OFString *query;
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236
			}
		}
	}

	return false;
}

@interface ServerInfo: OFObject <OFComparing>
@property (nonatomic) OFString *name;
@property (nonatomic) OFString *full;
@property (nonatomic) OFString *map;
@property (nonatomic) OFString *sdesc;
@property (nonatomic) int mode, numplayers, ping, protocol, minremain;
@property (nonatomic) ENetAddress address;
@end

@implementation ServerInfo
- (OFComparisonResult)compare:(id)otherObject
{
	if (![otherObject isKindOfClass:ServerInfo.class])
		@throw [OFInvalidArgumentException exception];

	if (_ping > [otherObject ping])
		return OFOrderedDescending;
	if (_ping < [otherObject ping])
		return OFOrderedAscending;

	return [_name compare:[otherObject name]];
}
@end

static OFMutableArray<ServerInfo *> *servers;
static ENetSocket pingsock = ENET_SOCKET_NULL;
static int lastinfo = 0;

OFString *
getservername(int n)
{
	return servers[n].name;
}

void
addserver(OFString *servername)
{
	@autoreleasepool {
		for (ServerInfo *si in servers)
			if ([si.name isEqual:servername])
				return;

		ServerInfo *si = [[ServerInfo alloc] init];
		si.name = servername;
		si.full = @"";
		si.mode = 0;
		si.numplayers = 0;
		si.ping = 9999;
		si.protocol = 0;
		si.minremain = 0;
		si.map = @"";
		si.sdesc = @"";
		ENetAddress address = { .host = ENET_HOST_ANY,
			.port = CUBE_SERVINFO_PORT };
		si.address = address;

		if (servers == nil)
			servers = [[OFMutableArray alloc] init];

		[servers addObject:si];

	}
}

void
pingservers()
{
	ENetBuffer buf;







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


















<
<
<
<
<
<
<
<
<
<
<
<
<
<



|
>







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
			}
		}
	}

	return false;
}

























static OFMutableArray<ServerInfo *> *servers;
static ENetSocket pingsock = ENET_SOCKET_NULL;
static int lastinfo = 0;

OFString *
getservername(int n)
{
	return servers[n].name;
}

void
addserver(OFString *servername)
{
	@autoreleasepool {
		for (ServerInfo *si in servers)
			if ([si.name isEqual:servername])
				return;















		if (servers == nil)
			servers = [[OFMutableArray alloc] init];

		[servers
		    addObject:[[ServerInfo alloc] initWithName:servername]];
	}
}

void
pingservers()
{
	ENetBuffer buf;