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.1 by root, Fri Feb 3 07:14:44 2006 UTC vs.
Revision 1.3 by root, Mon Apr 17 06:25:35 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.1 2006/02/03 07:14:44 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
78 */ 78 */
79 79
80typedef void (*func_uint8_int_ns) (char*, int, NewSocket *); 80typedef void (*func_uint8_int_ns) (char*, int, NewSocket *);
81 81
82struct NsCmdMapping { 82struct NsCmdMapping {
83 char *cmdname; 83 const char *cmdname;
84 func_uint8_int_ns cmdproc; 84 func_uint8_int_ns cmdproc;
85}; 85};
86 86
87typedef void (*func_uint8_int_pl)(char*, int, player *); 87typedef void (*func_uint8_int_pl)(char*, int, player *);
88struct PlCmdMapping { 88struct PlCmdMapping {
89 char *cmdname; 89 const char *cmdname;
90 func_uint8_int_pl cmdproc; 90 func_uint8_int_pl cmdproc;
91 uint8 flag; 91 uint8 flag;
92}; 92};
93 93
94/** 94/**
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, 0 }, /* 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[] = {
322 * starting a connection) 323 * starting a connection)
323 */ 324 */
324 325
325void HandleClient(NewSocket *ns, player *pl) 326void HandleClient(NewSocket *ns, player *pl)
326{ 327{
327 int len=0,i; 328 int len=0,i,cnt;
328 unsigned char *data; 329 unsigned char *data;
329 330
330 /* Loop through this - maybe we have several complete packets here. */ 331 /* Loop through this - maybe we have several complete packets here. */
331 while (1) { 332 // limit to a efw commands only, though, as to not monopolise the server
333 for (cnt = 16; --cnt; ) {
332 /* 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
333 * 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.
334 */ 336 */
335 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) {
336 return; 338 return;
381 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 */
382 for (i=0; nscommands[i].cmdname !=NULL; i++) { 384 for (i=0; nscommands[i].cmdname !=NULL; i++) {
383 if (strcmp((char*)ns->inbuf.buf+2,nscommands[i].cmdname)==0) { 385 if (strcmp((char*)ns->inbuf.buf+2,nscommands[i].cmdname)==0) {
384 nscommands[i].cmdproc((char*)data,len,ns); 386 nscommands[i].cmdproc((char*)data,len,ns);
385 ns->inbuf.len=0; 387 ns->inbuf.len=0;
386 return; 388 continue;
387 } 389 }
388 } 390 }
389 /* 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
390 * 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 -
391 * 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
396 if (pl) for (i=0; plcommands[i].cmdname !=NULL; i++) { 398 if (pl) for (i=0; plcommands[i].cmdname !=NULL; i++) {
397 if (strcmp((char*)ns->inbuf.buf+2,plcommands[i].cmdname)==0) { 399 if (strcmp((char*)ns->inbuf.buf+2,plcommands[i].cmdname)==0) {
398 if (pl->state == ST_PLAYING || plcommands[i].flag == 0) 400 if (pl->state == ST_PLAYING || plcommands[i].flag == 0)
399 plcommands[i].cmdproc((char*)data,len,pl); 401 plcommands[i].cmdproc((char*)data,len,pl);
400 ns->inbuf.len=0; 402 ns->inbuf.len=0;
401 return; 403 continue;
402 } 404 }
403 } 405 }
404 /* 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
405 * this might be questionable, because a broken client/malicious 407 * this might be questionable, because a broken client/malicious
406 * user could certainly send a whole bunch of invalid commands. 408 * user could certainly send a whole bunch of invalid commands.
709 if (pl->last_weight != -1 && pl->last_weight != WEIGHT(pl->ob)) { 711 if (pl->last_weight != -1 && pl->last_weight != WEIGHT(pl->ob)) {
710 esrv_update_item(UPD_WEIGHT, pl->ob, pl->ob); 712 esrv_update_item(UPD_WEIGHT, pl->ob, pl->ob);
711 if(pl->last_weight != WEIGHT(pl->ob)) 713 if(pl->last_weight != WEIGHT(pl->ob))
712 LOG(llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", (unsigned long)pl->last_weight, WEIGHT(pl->ob)); 714 LOG(llevError, "esrv_update_item(UPD_WEIGHT) did not set player weight: is %lu, should be %lu\n", (unsigned long)pl->last_weight, WEIGHT(pl->ob));
713 } 715 }
714 if (pl->ob->map && pl->ob->map->in_memory==MAP_IN_MEMORY) 716 /* draw_client_map does sanity checking that map is
717 * valid, so don't do it here.
718 */
715 draw_client_map(pl->ob); 719 draw_client_map(pl->ob);
716 if (pl->socket.update_look) esrv_draw_look(pl->ob); 720 if (pl->socket.update_look) esrv_draw_look(pl->ob);
717 } 721 }
718 } 722 }
719 } 723 }
720} 724}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines