1 | |
1 | |
2 | /* |
2 | /* |
3 | * static char *rcsid_loop_c = |
3 | * static char *rcsid_loop_c = |
4 | * "$Id: loop.c,v 1.2 2006/04/17 06:11:40 root Exp $"; |
4 | * "$Id: loop.c,v 1.3 2006/04/17 06:25:35 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 | |
… | |
… | |
323 | * starting a connection) |
323 | * starting a connection) |
324 | */ |
324 | */ |
325 | |
325 | |
326 | void HandleClient(NewSocket *ns, player *pl) |
326 | void HandleClient(NewSocket *ns, player *pl) |
327 | { |
327 | { |
328 | int len=0,i; |
328 | int len=0,i,cnt; |
329 | unsigned char *data; |
329 | unsigned char *data; |
330 | |
330 | |
331 | /* Loop through this - maybe we have several complete packets here. */ |
331 | /* Loop through this - maybe we have several complete packets here. */ |
332 | while (1) { |
332 | // limit to a efw commands only, though, as to not monopolise the server |
|
|
333 | for (cnt = 16; --cnt; ) { |
333 | /* If it is a player, and they don't have any speed left, we |
334 | /* If it is a player, and they don't have any speed left, we |
334 | * return, and will read in the data when they do have time. |
335 | * return, and will read in the data when they do have time. |
335 | */ |
336 | */ |
336 | if (pl && pl->state==ST_PLAYING && pl->ob != NULL && pl->ob->speed_left < 0) { |
337 | if (pl && pl->state==ST_PLAYING && pl->ob != NULL && pl->ob->speed_left < 0) { |
337 | return; |
338 | return; |
… | |
… | |
382 | ns->inbuf.buf[ns->inbuf.len]='\0'; /* Terminate buffer - useful for string data */ |
383 | ns->inbuf.buf[ns->inbuf.len]='\0'; /* Terminate buffer - useful for string data */ |
383 | for (i=0; nscommands[i].cmdname !=NULL; i++) { |
384 | for (i=0; nscommands[i].cmdname !=NULL; i++) { |
384 | if (strcmp((char*)ns->inbuf.buf+2,nscommands[i].cmdname)==0) { |
385 | if (strcmp((char*)ns->inbuf.buf+2,nscommands[i].cmdname)==0) { |
385 | nscommands[i].cmdproc((char*)data,len,ns); |
386 | nscommands[i].cmdproc((char*)data,len,ns); |
386 | ns->inbuf.len=0; |
387 | ns->inbuf.len=0; |
387 | return; |
388 | continue; |
388 | } |
389 | } |
389 | } |
390 | } |
390 | /* Player must be in the playing state or the flag on the |
391 | /* Player must be in the playing state or the flag on the |
391 | * the command must be zero for the user to use the command - |
392 | * the command must be zero for the user to use the command - |
392 | * otherwise, a player cam save, be in the play_again state, and |
393 | * otherwise, a player cam save, be in the play_again state, and |
… | |
… | |
397 | if (pl) for (i=0; plcommands[i].cmdname !=NULL; i++) { |
398 | if (pl) for (i=0; plcommands[i].cmdname !=NULL; i++) { |
398 | if (strcmp((char*)ns->inbuf.buf+2,plcommands[i].cmdname)==0) { |
399 | if (strcmp((char*)ns->inbuf.buf+2,plcommands[i].cmdname)==0) { |
399 | if (pl->state == ST_PLAYING || plcommands[i].flag == 0) |
400 | if (pl->state == ST_PLAYING || plcommands[i].flag == 0) |
400 | plcommands[i].cmdproc((char*)data,len,pl); |
401 | plcommands[i].cmdproc((char*)data,len,pl); |
401 | ns->inbuf.len=0; |
402 | ns->inbuf.len=0; |
402 | return; |
403 | continue; |
403 | } |
404 | } |
404 | } |
405 | } |
405 | /* If we get here, we didn't find a valid command. Logging |
406 | /* If we get here, we didn't find a valid command. Logging |
406 | * this might be questionable, because a broken client/malicious |
407 | * this might be questionable, because a broken client/malicious |
407 | * user could certainly send a whole bunch of invalid commands. |
408 | * user could certainly send a whole bunch of invalid commands. |