Overview
Comment: | Convert server_entity to a class |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
21584a40b686945f20e078af058c7f2a |
User & Date: | js on 2025-03-20 16:36:34 |
Other Links: | manifest | tags |
Context
2025-03-20
| ||
16:39 | Remove non-functional FMOD support check-in: 7e4ba7f32a user: js tags: trunk | |
16:36 | Convert server_entity to a class check-in: 21584a40b6 user: js tags: trunk | |
16:04 | Convert entity to a class check-in: 4b002822f9 user: js tags: trunk | |
Changes
Added src/ServerEntity.h version [05bfd0886b].
Added src/ServerEntity.m version [000863e318].
Modified src/meson.build from [ded2471dd3] to [8f9d724584].
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 'Menu.m', 'MenuItem.m', 'OFString+Cube.mm', 'PersistentEntity.m', 'Projectile.m', 'ResolverResult.mm', 'ResolverThread.mm', 'ServerInfo.mm', 'Variable.mm', 'clients.mm', 'clientextras.mm', 'clientgame.mm', 'clients2c.mm', 'commands.mm', | > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 'Menu.m', 'MenuItem.m', 'OFString+Cube.mm', 'PersistentEntity.m', 'Projectile.m', 'ResolverResult.mm', 'ResolverThread.mm', 'ServerEntity.m', 'ServerInfo.mm', 'Variable.mm', 'clients.mm', 'clientextras.mm', 'clientgame.mm', 'clients2c.mm', 'commands.mm', |
︙ | ︙ | |||
65 66 67 68 69 70 71 72 73 74 75 76 77 78 | link_args: client_link_args, link_with: [enet], win_subsystem: 'windows') executable('server', [ 'Client.mm', 'server.mm', 'serverms.mm', 'serverutil.mm', 'tools.mm', ], objcpp_args: ['-DSTANDALONE'], dependencies: [ | > | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | link_args: client_link_args, link_with: [enet], win_subsystem: 'windows') executable('server', [ 'Client.mm', 'ServerEntity.m', 'server.mm', 'serverms.mm', 'serverutil.mm', 'tools.mm', ], objcpp_args: ['-DSTANDALONE'], dependencies: [ |
︙ | ︙ |
Modified src/server.mm from [69c5d759fc] to [9e76792f10].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // server.cpp: little more than enhanced multicaster // runs dedicated or as client coroutine #include "cube.h" #import "Client.h" #import "Entity.h" enum { ST_EMPTY, ST_LOCAL, ST_TCPIP }; static OFMutableArray<Client *> *clients; int maxclients = 8; static OFString *smapname; | > < < < < < | < | < > | | | | 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 | // server.cpp: little more than enhanced multicaster // runs dedicated or as client coroutine #include "cube.h" #import "Client.h" #import "Entity.h" #import "ServerEntity.h" enum { ST_EMPTY, ST_LOCAL, ST_TCPIP }; static OFMutableArray<Client *> *clients; int maxclients = 8; static OFString *smapname; static OFMutableArray<ServerEntity *> *sents; // true when map has changed and waiting for clients to send item bool notgotitems = true; int mode = 0; // hack: called from savegame code, only works in SP void restoreserverstate(OFArray<Entity *> *ents) { [sents enumerateObjectsUsingBlock:^( ServerEntity *e, size_t i, bool *stop) { e.spawned = ents[i].spawned; e.spawnsecs = 0; }]; } int interm = 0, minremain = 0, mapend = 0; bool mapreload = false; static OFString *serverpassword = @""; |
︙ | ︙ | |||
112 113 114 115 116 117 118 | clients[n].type = ST_EMPTY; send2(true, -1, SV_CDIS, n); } void resetitems() { | | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | clients[n].type = ST_EMPTY; send2(true, -1, SV_CDIS, n); } void resetitems() { [sents removeAllObjects]; notgotitems = true; } void pickup(uint i, int sec, int sender) // server side item pickup, acknowledge // first client that gets it { if (i >= (uint)sents.count) return; if (sents[i].spawned) { sents[i].spawned = false; sents[i].spawnsecs = sec; send2(true, sender, SV_ITEMACC, i); } } |
︙ | ︙ | |||
226 227 228 229 230 231 232 | break; } case SV_ITEMLIST: { int n; while ((n = getint(p)) != -1) if (notgotitems) { | < | > | | 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | break; } case SV_ITEMLIST: { int n; while ((n = getint(p)) != -1) if (notgotitems) { while (sents.count <= n) [sents addObject:[ServerEntity entity]]; sents[n].spawned = true; } notgotitems = false; break; } case SV_ITEMPICKUP: { |
︙ | ︙ | |||
300 301 302 303 304 305 306 | void send_welcome(int n) { ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE); uchar *start = packet->data; | | > > > | > | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | void send_welcome(int n) { ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE); uchar *start = packet->data; __block uchar *p = start + 2; putint(p, SV_INITS2C); putint(p, n); putint(p, PROTOCOL_VERSION); putint(p, *smapname.UTF8String); sendstring(serverpassword, p); putint(p, clients.count > maxclients); if (smapname.length > 0) { putint(p, SV_MAPCHANGE); sendstring(smapname, p); putint(p, mode); putint(p, SV_ITEMLIST); [sents enumerateObjectsUsingBlock:^( ServerEntity *e, size_t i, bool *stop) { if (e.spawned) putint(p, i); }]; putint(p, -1); } *(ushort *)start = ENET_HOST_TO_NET_16(p - start); enet_packet_resize(packet, p - start); send(n, packet); } |
︙ | ︙ | |||
398 399 400 401 402 403 404 | int lastconnect = 0; void serverslice(int seconds, unsigned int timeout) // main server update, called from cube main loop in // sp, or dedicated server loop { | | < | > | | | | | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | int lastconnect = 0; void serverslice(int seconds, unsigned int timeout) // main server update, called from cube main loop in // sp, or dedicated server loop { // spawn entities when timer reached [sents enumerateObjectsUsingBlock:^( ServerEntity *e, size_t i, bool *stop) { if (e.spawnsecs && (e.spawnsecs -= seconds - lastsec) <= 0) { e.spawnsecs = 0; e.spawned = true; send2(true, -1, SV_ITEMSPAWN, i); } }]; lastsec = seconds; if ((mode > 1 || (mode == 0 && nonlocalclients)) && seconds > mapend - minremain * 60) checkintermission(); if (interm && seconds > interm) { |
︙ | ︙ | |||
530 531 532 533 534 535 536 537 538 539 540 541 542 543 | void initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip, OFString *master, OFString *passwd, int maxcl) { serverpassword = passwd; maxclients = maxcl; servermsinit(master ? master : @"wouter.fov120.com/cube/masterserver/", sdesc, dedicated); if ((isdedicated = dedicated)) { ENetAddress address = { ENET_HOST_ANY, CUBE_SERVER_PORT }; if (ip.length > 0 && enet_address_set_host(&address, ip.UTF8String) < 0) | > | 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | void initserver(bool dedicated, int uprate, OFString *sdesc, OFString *ip, OFString *master, OFString *passwd, int maxcl) { serverpassword = passwd; maxclients = maxcl; sents = [[OFMutableArray alloc] init]; servermsinit(master ? master : @"wouter.fov120.com/cube/masterserver/", sdesc, dedicated); if ((isdedicated = dedicated)) { ENetAddress address = { ENET_HOST_ANY, CUBE_SERVER_PORT }; if (ip.length > 0 && enet_address_set_host(&address, ip.UTF8String) < 0) |
︙ | ︙ |