Differences From Artifact [0204d78717]:
- File src/clients.m — part of check-in [cc7ebd7f79] at 2025-03-26 21:47:31 on branch trunk — Run newer version of clang-format (user: js, size: 9281) [annotate] [blame] [check-ins using]
To Artifact [0b6e5b2153]:
- File
src/clients.m
— part of check-in
[75e920ae30]
at
2025-03-29 14:25:43
on branch trunk
— Switch from clang-format to manual formatting
clang-format does too many weird things. (user: js, size: 9290) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
64 65 66 67 68 69 70 | static void newname(OFString *name) { c2sinit = false; if (name.length > 16) | | | | | | | | 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 | static void newname(OFString *name) { c2sinit = false; if (name.length > 16) name = [name substringToIndex: 16]; Player.player1.name = name; } COMMAND(name, ARG_1STR, ^ (OFString *name) { newname(name); }) static void newteam(OFString *name) { c2sinit = false; if (name.length > 5) name = [name substringToIndex: 5]; Player.player1.team = name; } COMMAND(team, ARG_1STR, ^ (OFString *name) { newteam(name); }) void writeclientinfo(OFStream *stream) { [stream writeFormat: @"name \"%@\"\nteam \"%@\"\n", Player.player1.name, Player.player1.team]; } void connects(OFString *servername) { disconnect(true, false); // reset state addserver(servername); |
︙ | ︙ | |||
181 182 183 184 185 186 187 | void toserver(OFString *text) { conoutf(@"%@:\f %@", Player.player1.name, text); ctext = text; } | | | | | | | | | | | | | | 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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | void toserver(OFString *text) { conoutf(@"%@:\f %@", Player.player1.name, text); ctext = text; } COMMAND(echo, ARG_VARI, ^ (OFString *text) { conoutf(@"%@", text); }) COMMAND(say, ARG_VARI, ^ (OFString *text) { toserver(text); }) COMMAND(connect, ARG_1STR, ^ (OFString *servername) { connects(servername); }) COMMAND(disconnect, ARG_NONE, ^ { trydisconnect(); }) // collect c2s messages conveniently static OFMutableArray<OFData *> *messages; void addmsg(int rel, int num, int type, ...) { if (demoplayback) return; if (num != msgsizelookup(type)) fatal(@"inconsistant msg size for %d (%d != %d)", type, num, msgsizelookup(type)); if (messages.count == 100) { conoutf(@"command flood protection (type %d)", type); return; } OFMutableData *msg = [OFMutableData dataWithItemSize: sizeof(int) capacity: num + 2]; [msg addItem: &num]; [msg addItem: &rel]; [msg addItem: &type]; va_list marker; va_start(marker, type); for (int i = 0; i < num - 1; i++) { int tmp = va_arg(marker, int); [msg addItem: &tmp]; } va_end(marker); [msg makeImmutable]; if (messages == nil) messages = [[OFMutableArray alloc] init]; [messages addObject: msg]; } void server_err() { conoutf(@"server network error, disconnecting..."); disconnect(false, false); } int lastupdate = 0, lastping = 0; OFString *toservermap; bool senditemstoserver = false; // after a map change, since server doesn't have map data OFString *clientpassword; COMMAND(password, ARG_1STR, ^ (OFString *p) { clientpassword = p; }) bool netmapstart() { senditemstoserver = true; |
︙ | ︙ | |||
313 314 315 316 317 318 319 | putint(&p, (int)(d.pitch * DAF)); putint(&p, (int)(d.roll * DAF)); // quantize to 1/100, almost always 1 byte putint(&p, (int)(d.velocity.x * DVF)); putint(&p, (int)(d.velocity.y * DVF)); putint(&p, (int)(d.velocity.z * DVF)); // pack rest in 1 byte: strafe:2, move:2, onFloor:1, state:3 | < | | | | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | putint(&p, (int)(d.pitch * DAF)); putint(&p, (int)(d.roll * DAF)); // quantize to 1/100, almost always 1 byte putint(&p, (int)(d.velocity.x * DVF)); putint(&p, (int)(d.velocity.y * DVF)); putint(&p, (int)(d.velocity.z * DVF)); // pack rest in 1 byte: strafe:2, move:2, onFloor:1, state:3 putint(&p, (d.strafe & 3) | ((d.move & 3) << 2) | (((int)d.onFloor) << 4) | ((editmode ? CS_EDITING : d.state) << 5)); if (senditemstoserver) { packet->flags = ENET_PACKET_FLAG_RELIABLE; putint(&p, SV_ITEMLIST); if (!m_noitems) putitems(&p); putint(&p, -1); |
︙ | ︙ | |||
345 346 347 348 349 350 351 | putint(&p, SV_INITC2S); sendstring(Player.player1.name, &p); sendstring(Player.player1.team, &p); putint(&p, Player.player1.lifeSequence); } for (OFData *msg in messages) { // send messages collected during the previous frames | | | | | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | putint(&p, SV_INITC2S); sendstring(Player.player1.name, &p); sendstring(Player.player1.team, &p); putint(&p, Player.player1.lifeSequence); } for (OFData *msg in messages) { // send messages collected during the previous frames if (*(int *)[msg itemAtIndex: 1]) packet->flags = ENET_PACKET_FLAG_RELIABLE; for (int i = 0; i < *(int *)[msg itemAtIndex: 0]; i++) putint(&p, *(int *)[msg itemAtIndex: i + 2]); } [messages removeAllObjects]; if (lastmillis - lastping > 250) { putint(&p, SV_PING); putint(&p, lastmillis); lastping = lastmillis; } |
︙ | ︙ |