ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/loop.c
(Generate patch)

Comparing deliantra/server/socket/loop.c (file contents):
Revision 1.1.1.2 by elmex, Wed Feb 22 18:03:28 2006 UTC vs.
Revision 1.7 by root, Fri Apr 28 16:24:03 2006 UTC

1 1
2/* 2/*
3 * static char *rcsid_loop_c = 3 * static char *rcsid_loop_c =
4 * "$Id: loop.c,v 1.1.1.2 2006/02/22 18:03:28 elmex Exp $"; 4 * "$Id: loop.c,v 1.7 2006/04/28 16:24:03 root Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
113 { "ncom", (func_uint8_int_pl)NewPlayerCmd, 1}, 113 { "ncom", (func_uint8_int_pl)NewPlayerCmd, 1},
114 { "lookat", LookAt, 1}, 114 { "lookat", LookAt, 1},
115 { "lock", (func_uint8_int_pl)LockItem, 1}, 115 { "lock", (func_uint8_int_pl)LockItem, 1},
116 { "mark", (func_uint8_int_pl)MarkItem, 1}, 116 { "mark", (func_uint8_int_pl)MarkItem, 1},
117 { "mapredraw", MapRedrawCmd, 0}, /* Added: phil */ 117 { "mapredraw", MapRedrawCmd, 0}, /* Added: phil */
118 { "mapinfo", MapInfoCmd, 2}, /* CF+ */
118 { NULL, NULL, 0} /* terminator */ 119 { NULL, NULL, 0} /* terminator */
119}; 120};
120 121
121/** Face-related commands */ 122/** Face-related commands */
122static struct NsCmdMapping nscommands[] = { 123static struct NsCmdMapping nscommands[] = {
182 /* This is not the most efficient block, but keeps the code simpler - 183 /* This is not the most efficient block, but keeps the code simpler -
183 * we basically read a byte at a time until we get a newline, error, 184 * we basically read a byte at a time until we get a newline, error,
184 * or no more characters to read. 185 * or no more characters to read.
185 */ 186 */
186 do { 187 do {
188 /* hack to disable old socket mode without creating too many conflicts */
187 if (ns->inbuf.len >= MAXSOCKBUF-1) { 189 if (1 || ns->inbuf.len >= MAXSOCKBUF-1) {
188 ns->status = Ns_Dead; 190 ns->status = Ns_Dead;
189 LOG(llevDebug, "Old input socket sent too much data without newline\n"); 191 LOG(llevDebug, "Old input socket sent too much data without newline\n");
190 return; 192 return;
191 } 193 }
192#ifdef WIN32 /* ***win32: change oldsocket read() to recv() */ 194#ifdef WIN32 /* ***win32: change oldsocket read() to recv() */
322 * starting a connection) 324 * starting a connection)
323 */ 325 */
324 326
325void HandleClient(NewSocket *ns, player *pl) 327void HandleClient(NewSocket *ns, player *pl)
326{ 328{
327 int len=0,i; 329 int len=0,i,cnt;
328 unsigned char *data; 330 unsigned char *data;
329 331
330 /* Loop through this - maybe we have several complete packets here. */ 332 /* Loop through this - maybe we have several complete packets here. */
331 while (1) { 333 // limit to a few commands only, though, as to not monopolise the server
334 for (cnt = 16; cnt--; ) {
332 /* If it is a player, and they don't have any speed left, we 335 /* If it is a player, and they don't have any speed left, we
333 * return, and will read in the data when they do have time. 336 * return, and will read in the data when they do have time.
334 */ 337 */
335 if (pl && pl->state==ST_PLAYING && pl->ob != NULL && pl->ob->speed_left < 0) { 338 if (pl && pl->state==ST_PLAYING && pl->ob != NULL && pl->ob->speed_left < 0) {
336 return; 339 return;
381 ns->inbuf.buf[ns->inbuf.len]='\0'; /* Terminate buffer - useful for string data */ 384 ns->inbuf.buf[ns->inbuf.len]='\0'; /* Terminate buffer - useful for string data */
382 for (i=0; nscommands[i].cmdname !=NULL; i++) { 385 for (i=0; nscommands[i].cmdname !=NULL; i++) {
383 if (strcmp((char*)ns->inbuf.buf+2,nscommands[i].cmdname)==0) { 386 if (strcmp((char*)ns->inbuf.buf+2,nscommands[i].cmdname)==0) {
384 nscommands[i].cmdproc((char*)data,len,ns); 387 nscommands[i].cmdproc((char*)data,len,ns);
385 ns->inbuf.len=0; 388 ns->inbuf.len=0;
386 return; 389 return;//D// not doing this causes random memory corruption
390 goto next_packet;
387 } 391 }
388 } 392 }
389 /* Player must be in the playing state or the flag on the 393 /* Player must be in the playing state or the flag on the
390 * the command must be zero for the user to use the command - 394 * the command must be zero for the user to use the command -
391 * otherwise, a player cam save, be in the play_again state, and 395 * otherwise, a player cam save, be in the play_again state, and
392 * the map they were on getsswapped out, yet things that try to look 396 * the map they were on gets swapped out, yet things that try to look
393 * at the map causes a crash. If the command is valid, but 397 * at the map causes a crash. If the command is valid, but
394 * one they can't use, we still swallow it up. 398 * one they can't use, we still swallow it up.
395 */ 399 */
396 if (pl) for (i=0; plcommands[i].cmdname !=NULL; i++) { 400 if (pl) for (i=0; plcommands[i].cmdname !=NULL; i++) {
397 if (strcmp((char*)ns->inbuf.buf+2,plcommands[i].cmdname)==0) { 401 if (strcmp((char*)ns->inbuf.buf+2,plcommands[i].cmdname)==0) {
398 if (pl->state == ST_PLAYING || plcommands[i].flag == 0) 402 if (pl->state == ST_PLAYING || !(plcommands[i].flag & 1))
399 plcommands[i].cmdproc((char*)data,len,pl); 403 plcommands[i].cmdproc((char*)data,len,pl);
400 ns->inbuf.len=0; 404 ns->inbuf.len=0;
401 return; 405 //D// not doing this causes random memory corruption
406 if (plcommands[i].flag & 2)
407 goto next_packet;
408 return;
402 } 409 }
403 } 410 }
404 /* If we get here, we didn't find a valid command. Logging 411 /* If we get here, we didn't find a valid command. Logging
405 * this might be questionable, because a broken client/malicious 412 * this might be questionable, because a broken client/malicious
406 * user could certainly send a whole bunch of invalid commands. 413 * user could certainly send a whole bunch of invalid commands.
407 */ 414 */
408 LOG(llevDebug,"Bad command from client (%s)\n",ns->inbuf.buf+2); 415 LOG(llevDebug,"Bad command from client (%s)\n",ns->inbuf.buf+2);
416 next_packet:
417 ;
409 } 418 }
410} 419}
411 420
412 421
413/***************************************************************************** 422/*****************************************************************************

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines