Advertisement
lucasgautheron

Untitled

Jun 1st, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #define LAGMAXTIME 15000 // a lag period of 15 seconds is needed
  2. #define NOLAGMINTIME 4000 // a client is considered as not lagging anymore after 4 seconds without lag
  3. #define MAXPING 500
  4.  
  5. void check_lag(client *cl)
  6. {
  7.     if(gamemillis < 10000 || (servmillis - cl->connectmillis) < 10000 || MAXPING < 300) return; // do not check at the beginning of a game or when the player joined too recently
  8.     if(cl->spj > 50 || cl->ping > MAXPING || cl->ldt > 80) // currently lagging
  9.     {
  10.         if(!cl->lagmillis) // lag period starting
  11.         {
  12.             cl->lagmillis = servmillis;
  13.         }
  14.         else if(servmillis - cl->lagmillis > LAGMAXTIME) // lag max time reached
  15.         {
  16.             disconnect_client(cl->clientnum, DISC_LAG);
  17.         }
  18.     }
  19.     else if(cl->lagmillis)
  20.     if(!cl->nolagmillis)
  21.     {// stopped lagging during a lag period
  22.         cl->nolagmillis = servmillis;
  23.     }
  24.     else if(servmillis - cl->nolagmillis > NOLAGMINTIME) // no-lag period long enough, lag period ended
  25.     {
  26.         cl->lagmillis = cl->nolagmillis = 0;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement