1 /* bzflag 2 * Copyright (c) 1993-2021 Tim Riker 3 * 4 * This package is free software; you can redistribute it and/or 5 * modify it under the terms of the license found in the file 6 * named COPYING that should have accompanied this file. 7 * 8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 13 #ifndef __LAGINFO_H__ 14 #define __LAGINFO_H__ 15 16 #include "PlayerInfo.h" 17 18 /** This class monitors the lag time for each client 19 */ 20 class LagInfo 21 { 22 public: 23 /** A default constructor. 24 It needs a pointer to the Player basic Info, 25 */ 26 LagInfo(PlayerInfo *_info); 27 28 /** Resetting lag value 29 */ 30 void reset(); 31 /** Getting lag value (in milliseconds) 32 */ 33 int getLag() const; 34 /** Getting jitter value (in milliseconds) 35 */ 36 int getJitter() const; 37 /** Getting packetloss value (in percent) 38 */ 39 int getLoss() const; 40 /** Get the floating point value of the lag (in seconds) 41 */ 42 float getLagAvg() const; 43 /** Get a printable version of lag statistics 44 */ 45 void getLagStats(char* msg, bool isAdmin) const; 46 /** functions to be called whenever a playerUpdate or ping message arrives 47 */ 48 void updatePingLag(const void *buf, bool &warn, bool &kick, 49 bool &jittwarn, bool &jittkick, 50 bool &plosswarn, bool &plosskick, 51 bool &alagannouncewarn, bool &lagannouncewarn); 52 void updateLag(float timestamp, bool ooo); 53 /** get the ping seqno, if need to send one now! 54 */ 55 int getNextPingSeqno(bool &warn, bool &kick); 56 /** update the latency 57 */ 58 void updateLatency(float &waitTime); 59 /** set the threshold for warning/kicking 60 */ 61 static void setAdminLagAnnounceThreshold(float _adminlagannouncetresh); 62 static void setLagAnnounceThreshold(float _lagannouncetresh); 63 static void setThreshold(float _threshold, float _max); 64 static void setJitterThreshold(float _jitterthreshold, float _jittermax); 65 static void setPacketLossThreshold(float _packetlossthreshold, float _max); 66 private: 67 PlayerInfo *info; 68 // lag measurement 69 float lagavg; 70 float jitteravg; 71 float lostavg; 72 float lagalpha; 73 float jitteralpha; 74 float lostalpha; 75 int lagcount; 76 int laglastwarn; 77 int lagwarncount; 78 int jittercount; 79 int jitterlastwarn; 80 int jitterwarncount; 81 int losscount; 82 int losslastwarn; 83 int losswarncount; 84 bool pingpending; 85 TimeKeeper nextping; 86 TimeKeeper lastping; 87 TimeKeeper lastupdate; 88 int pingseqno; 89 int pingssent; 90 // jitter measurement 91 float lasttimestamp; 92 93 // announcements 94 static float adminlagannouncetresh; 95 int alagcount; 96 int alaglastannounce; 97 int alagannouncecount; 98 static float lagannouncetresh; 99 int lagannouncecount; 100 TimeKeeper laglastannounce; 101 102 103 // kicks 104 static float threshold; 105 static float jitterthreshold; 106 static float lossthreshold; 107 static float max; 108 static float jittermax; 109 static float lossmax; 110 }; 111 112 #endif 113 114 // Local Variables: *** 115 // mode: C++ *** 116 // tab-width: 4 *** 117 // c-basic-offset: 4 *** 118 // indent-tabs-mode: nil *** 119 // End: *** 120 // ex: shiftwidth=4 tabstop=4 121