Cube  Diff

Differences From Artifact [fbd128e000]:

To Artifact [bb466005e7]:


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
176
177
178
179
180
181
182




183
184
185
186


187
188
189


190

191
192
193
194
195
196
197







-
-
-
-
+
+
+

-
-
+
+

-
-
+
-







{
	return servers[n].name;
}

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

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

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

void
pingservers()
{
	ENetBuffer buf;
	uchar ping[MAXTRANS];
256
257
258
259
260
261
262
263
264

265
266
267
268

269
270
271
272
273
274
275
276
253
254
255
256
257
258
259


260

261


262

263
264
265
266
267
268
269







-
-
+
-

-
-
+
-







				si.protocol = getint(p);
				if (si.protocol != PROTOCOL_VERSION)
					si.ping = 9998;
				si.mode = getint(p);
				si.numplayers = getint(p);
				si.minremain = getint(p);
				sgetstr();
				@autoreleasepool {
					si.map = @(text);
				si.map = @(text);
				}
				sgetstr();
				@autoreleasepool {
					si.sdesc = @(text);
				si.sdesc = @(text);
				}
				break;
			}
		}
	}
}

void
302
303
304
305
306
307
308
309
310
311


312
313
314
315
316
317
318
319
295
296
297
298
299
300
301



302
303

304
305
306
307
308
309
310







-
-
-
+
+
-







			    initWithFormat:
			        (si.address.host != ENET_HOST_ANY
			                ? @"%@ [waiting for server response]"
			                : @"%@ [unknown host]\t"),
			    si.name];

		// cut off too long server descriptions
		@autoreleasepool {
			if (si.full.length > 50)
				si.full = [si.full substringToIndex:50];
		if (si.full.length > 50)
			si.full = [si.full substringToIndex:50];
		}

		menumanual(1, i, si.full);

		if (!--maxmenu)
			return;

		i++;
344
345
346
347
348
349
350
351
352

353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371


372
373
374
335
336
337
338
339
340
341


342

343
344
345
346
347
348
349
350
351
352
353
354
355
356
357



358
359

360
361







-
-
+
-















-
-
-
+
+
-


	uchar buf[MAXUPD];
	uchar *reply = retrieveservers(buf, MAXUPD);
	if (!*reply || strstr((char *)reply, "<html>") ||
	    strstr((char *)reply, "<HTML>"))
		conoutf(@"master server not replying");
	else {
		[servers removeAllObjects];
		@autoreleasepool {
			execute(@((char *)reply));
		execute(@((char *)reply));
		}
	}
	servermenu();
}

COMMAND(addserver, ARG_1STR)
COMMAND(servermenu, ARG_NONE)
COMMAND(updatefrommaster, ARG_NONE)

void
writeservercfg()
{
	FILE *f = fopen("servers.cfg", "w");
	if (!f)
		return;
	fprintf(f, "// servers connected to are added here automatically\n\n");
	@autoreleasepool {
		for (ServerInfo *si in servers.reversedArray)
			fprintf(f, "addserver %s\n", si.name.UTF8String);
	for (ServerInfo *si in servers.reversedArray)
		fprintf(f, "addserver %s\n", si.name.UTF8String);
	}
	fclose(f);
}