/********************************************************************* v.1 enhanced_ping.cz ping function set for determining lag time between the talker and a player interval ping to player that will show dynamically on examine how fast thier connection is Requirments: ewtoo derivitive talker Notes: Do not install ping.cz, as its included in this 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 the define PING_INTERVAL is set for 10 seconds... if you wish to have this more or less often, change it accordingly. 10 is prolly the lowest you wanna go, 60 the highest (and still have it appear dynamic) its recommended if you install this, you put in a saved flag for ppl that dont wish to have an active ping done on there connection 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 *********************************************************************/ the file containing your examine() function : (top of the file) file ConnectionSpeeds[] = { {"Pending", -1}, {"Direct", 20}, {"Blazing", 30}, {"Fast", 60}, {"Speedy", 80}, {"Decent", 100}, {"Sluggish", 120}, {"Slow", 150}, {"Painful", 180}, {"Constipated", 220}, {"Unbearable", 300}, {"Horrid", 500}, {"Lag Attack", 999999}, {"", 0} }; : (above the examine function) char *ping_string ( player * p ) { int i; for (i = 0; ConnectionSpeeds[i].where[0]; i++) if ((p->last_ping / 10000) <= (long) ConnectionSpeeds[i].length) return ConnectionSpeeds[i].where; return "Spanked!"; } : examine() : add/modify the following line so that it appears in the examine : and fits how you want it to look sprintf (stack, " Connection o %s\n", ping_string (p2)); player.h : if you get any errors about struct timeval : add this line to the top of the file ... #include : where your MAX_* are define'd #define PING_INTERVAL 10 : add to the p_struct the following members ... struct timeval ping_timer; long last_ping; int next_ping; plists.c : restore_player_title() : (amongst the rest of the initlizers for the player) p->next_ping = PING_INTERVAL; p->last_ping = -1; parse.c : (top with externs/inters) extern void ping_timed ( player * p ); : actual_timer() for (scan = flatlist_start; scan; scan = scan->flat_next) if (!(scan->flags & PANIC)) { /** add these lines **/ if (scan->next_ping == 0) { scan->next_ping = -1; /* wait til ping_respond resets us */ ping_timed (scan); } if (scan->next_ping > 0) scan->next_ping--; /**********************/ socket.c : 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_timed ( player * p ) { p->last_ping = -1; /* set the last ping to be pending */ ping (p, ""); } 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)); if (p->last_ping == -1) /* its a pending timed ping */ { p->last_ping = pt; p->next_ping = PING_INTERVAL; return; } /* else it was the ping command used */ 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