/********************************************************************* v.1 ping.cz ping function set for determining lag time between the talker and a player Requirments: ewtoo derivitive talker Notes: The proc used to get lag time is a bit odd... its all clean, but instead of arseing about with timing marks and such... it uses a more simple method of requesting the client to do something that isnt do'able, then waiting for the client to respond. im sure there is a more 'correct' method, but this works just fine Bug Reports: send to phypor@benland.muc.edu Licences: freely distributable and modifiable, as long as credit given in appropritate places for any distrubitions (be it this alone or within another package) Warranty: non, the author is in no way responsible for use, misuse, abuse, or any other actions misactions, reactions of this code, its provided as is. Author: phypor "if it breaks you get to keep both pieces" ~old linux proverb *********************************************************************/ player.h : if you get any errors about struct timeval : add this line to the top of the file ... #include : add to the p_struct the following member ... struct timeval ping_timer; socket.c : (top of the file with other interns) void ping_respond ( player * ); : telnet_options() if (read(p->fd, &c, 1) != 1) return; switch (c) { /** add the following lines **/ case WONT: if (read(p->fd, &c, 1) != 1) return; switch (c) /* switch for possible future cases */ { case TELOPT_STATUS: ping_respond (p); break; } break; /*****************************/ : (bottom of the file add the following) void ping ( player * p, char * str ) { char *oldstack = stack; memset (stack, 0, 10); *stack++ = (char) IAC; *stack++ = (char) DO; *stack++ = (char) TELOPT_STATUS; *stack++ = (char) NULL; write (p->fd, oldstack, strlen (oldstack)); stack = oldstack; gettimeofday (&(p->ping_timer), (struct timezone *) NULL); } void ping_respond ( player * p ) { struct timeval endtv; long pt; memset (&endtv, 0, sizeof (struct timeval)); gettimeofday (&endtv, (struct timezone *) NULL); /* a few extra cycles this way... but its unreliable using straight values */ pt = ((endtv.tv_sec - p->ping_timer.tv_sec) * 1000000) + ((endtv.tv_usec - p->ping_timer.tv_usec)); ez_tell_player (p, " You've got about %ld.%.2ld seconds of lagtime ...\n", pt / 1000000, (pt / 10000) % 1000000); } clist.h : add a command to call the function ping