bandwidthcheck.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/bandwidthcheck.h $*
  25. * *
  26. * $Author:: Bhayes $*
  27. * *
  28. * $Modtime:: 2/18/02 9:33p $*
  29. * *
  30. * $Revision:: 9 $*
  31. * *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * *
  35. * *
  36. *---------------------------------------------------------------------------------------------*
  37. * *
  38. * Functions: *
  39. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  40. #ifndef _BANDWIDTHCHECK_H
  41. #define _BANDWIDTHCHECK_H
  42. #include <WWOnline\WaitCondition.h>
  43. #include <wwlib\except.h>
  44. #include <windows.h>
  45. #include <BandTest\BandTest.h>
  46. namespace WWOnline {
  47. class Session;
  48. }
  49. class BandwidthCheckerClass
  50. {
  51. public:
  52. /*
  53. ** Struct for packing bandwidth levels into a single byte.
  54. */
  55. #pragma pack(push)
  56. #pragma pack(1)
  57. typedef struct tInternalPackedBandwidthType {
  58. unsigned char Up : 4;
  59. unsigned char Down : 4;
  60. } InternalPackedBandwidthType;
  61. typedef union tPackedBandwidthType {
  62. InternalPackedBandwidthType Bandwidth;
  63. unsigned char RawBandwidth;
  64. } PackedBandwidthType;
  65. #pragma pack(pop)
  66. static RefPtr<WaitCondition> Detect(void);
  67. static void Check_Now(HANDLE event);
  68. static bool Got_Bandwidth(void) {return(GotBandwidth);};
  69. static void Force_Upstream_Bandwidth(unsigned int up);
  70. static unsigned long Get_Upstream_Bandwidth(void);
  71. static unsigned long Get_Reported_Upstream_Bandwidth(void);
  72. static unsigned short *Get_Upstream_Bandwidth_As_String(void);
  73. static unsigned long Get_Downstream_Bandwidth(void);
  74. static unsigned long Get_Reported_Downstream_Bandwidth(void);
  75. static unsigned short *Get_Downstream_Bandwidth_As_String(void);
  76. static unsigned short *Get_Bandwidth_As_String(void);
  77. static unsigned short *Get_Bandwidth_As_String(PackedBandwidthType bandwidth);
  78. static PackedBandwidthType Get_Packed_Bandwidth(void);
  79. static bool Failed_Due_To_No_Connection(void) {return(FailureCode == BANDTEST_NO_IP_DETECT);}
  80. static void Get_Compact_Log(StringClass &log_string);
  81. static bool Is_Thread_Running(void) { return Thread.Is_Running(); }
  82. private:
  83. static void Check(void);
  84. static const char *Get_Ping_Server_Name(void);
  85. static class BandwidthCheckerThreadClass : public ThreadClass {
  86. public:
  87. BandwidthCheckerThreadClass(const char *thread_name = "Bandwidth checker thread") : ThreadClass(thread_name, &Exception_Handler) {}
  88. void Thread_Function(void) {BandwidthCheckerClass::Check();};
  89. } Thread;
  90. friend BandwidthCheckerThreadClass;
  91. static HANDLE EventNotify;
  92. static unsigned long UpstreamBandwidth;
  93. static unsigned long ReportedUpstreamBandwidth;
  94. static unsigned long DownstreamBandwidth;
  95. static unsigned long ReportedDownstreamBandwidth;
  96. static unsigned short *UpstreamBandwidthString;
  97. static unsigned short *DownstreamBandwidthString;
  98. #define NUM_BANDS 12
  99. static char *ErrorList[13];
  100. static unsigned long Bandwidths[NUM_BANDS * 2];
  101. static unsigned short *BandwidthNames[NUM_BANDS + 1];
  102. static int FailureCode;
  103. static bool GotBandwidth;
  104. static const char *DefaultServerName;
  105. };
  106. /*
  107. ** Wait code for bandwidth detection.
  108. **
  109. **
  110. **
  111. */
  112. class BandwidthDetectWait : public SingleWait
  113. {
  114. public:
  115. static RefPtr<BandwidthDetectWait> Create(void);
  116. void WaitBeginning(void);
  117. WaitResult GetResult(void);
  118. protected:
  119. BandwidthDetectWait();
  120. virtual ~BandwidthDetectWait();
  121. BandwidthDetectWait(const BandwidthDetectWait&);
  122. const BandwidthDetectWait& operator = (const BandwidthDetectWait&);
  123. RefPtr<WWOnline::Session> WOLSession;
  124. unsigned int mPingsRemaining;
  125. HANDLE mEvent;
  126. };
  127. #endif //_BANDWIDTHCHECK_H