bandwidth.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/bandwidth.cpp $*
  25. * *
  26. * $Author:: Bhayes $*
  27. * *
  28. * $Modtime:: 2/18/02 9:22p $*
  29. * *
  30. * $Revision:: 17 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "bandwidth.h" // I WANNA BE FIRST!
  36. #include "miscutil.h"
  37. #include "wwdebug.h"
  38. #include "translatedb.h"
  39. #include "string_ids.h"
  40. #include "useroptions.h"
  41. #include "bandwidthcheck.h"
  42. //-----------------------------------------------------------------------------
  43. ULONG cBandwidth::Get_Bandwidth_Bps_From_Type(BANDWIDTH_TYPE_ENUM bandwidth_type)
  44. {
  45. /*
  46. WWASSERT(bandwidth_type >= BANDWIDTH_FIRST &&
  47. bandwidth_type <= BANDWIDTH_LAST);
  48. */
  49. // WWASSERT(bandwidth_type != BANDWIDTH_CUSTOM);
  50. switch (bandwidth_type) {
  51. case BANDWIDTH_CUSTOM:
  52. return cUserOptions::BandwidthBps.Get();
  53. case BANDWIDTH_MODEM_288:
  54. return 28800;
  55. case BANDWIDTH_MODEM_336:
  56. return 33600;
  57. case BANDWIDTH_MODEM_56:
  58. return 56000;
  59. case BANDWIDTH_ISDN:
  60. return 64000;
  61. case BANDWIDTH_CABLE:
  62. return 128000;
  63. case BANDWIDTH_LANT1:
  64. return 2000000;
  65. case BANDWIDTH_AUTO:
  66. {
  67. ULONG bps = BandwidthCheckerClass::Get_Upstream_Bandwidth();
  68. // WWASSERT(bps > 0);
  69. return bps;
  70. }
  71. default:
  72. DIE;
  73. return 0xffffffff; // to avoid compiler warning
  74. }
  75. }
  76. //-----------------------------------------------------------------------------
  77. const unsigned short *cBandwidth::Get_Bandwidth_String_From_Type(BANDWIDTH_TYPE_ENUM bandwidth_type)
  78. {
  79. static char _bandwidth_auto_txt[128];
  80. static WideStringClass s;
  81. /*
  82. WWASSERT(bandwidth_type >= BANDWIDTH_FIRST &&
  83. bandwidth_type <= BANDWIDTH_LAST);
  84. */
  85. switch (bandwidth_type) {
  86. case BANDWIDTH_MODEM_288:
  87. return TRANSLATE(IDS_MP_CONNECTION_288); //"BANDWIDTH_MODEM_288";
  88. case BANDWIDTH_MODEM_336:
  89. return TRANSLATE(IDS_MP_CONNECTION_336); //"BANDWIDTH_MODEM_336";
  90. case BANDWIDTH_MODEM_56:
  91. return TRANSLATE(IDS_MP_CONNECTION_56); //"BANDWIDTH_MODEM_56";
  92. case BANDWIDTH_ISDN:
  93. return TRANSLATE(IDS_MP_CONNECTION_ISDN); //"BANDWIDTH_ISDN";
  94. case BANDWIDTH_CABLE:
  95. return TRANSLATE(IDS_MP_CONNECTION_CABLE); //"BANDWIDTH_CABLE";
  96. case BANDWIDTH_LANT1:
  97. return TRANSLATE(IDS_MP_CONNECTION_T1); //"BANDWIDTH_LANT1";
  98. case BANDWIDTH_CUSTOM:
  99. return L"BANDWIDTH_CUSTOM";
  100. case BANDWIDTH_AUTO:
  101. {
  102. //sprintf(_bandwidth_auto_txt, "BANDWIDTH_AUTO (%s)", BandwidthCheckerClass::Get_Bandwidth_As_String());
  103. s.Format(TRANSLATE(IDS_MP_CONNECTION_T1), Get_Bandwidth_Bps_From_Type(bandwidth_type));
  104. //wsprintf(_bandwidth_auto_txt, TRANSLATE(IDS_MP_CONNECTION_T1), Get_Bandwidth_Bps_From_Type(bandwidth_type));
  105. //return ((const)_bandwidth_auto_txt);
  106. return(s);
  107. }
  108. default:
  109. DIE;
  110. return L"ERROR"; // to avoid compiler warning
  111. }
  112. }
  113. //-----------------------------------------------------------------------------
  114. BANDWIDTH_TYPE_ENUM cBandwidth::Get_Bandwidth_Type_From_String(LPCSTR bandwidth_string)
  115. {
  116. WWASSERT(bandwidth_string != NULL);
  117. if (cMiscUtil::Is_String_Same(bandwidth_string, "BANDWIDTH_MODEM_288")) {
  118. return BANDWIDTH_MODEM_288;
  119. } else if (cMiscUtil::Is_String_Same(bandwidth_string, "BANDWIDTH_MODEM_336")) {
  120. return BANDWIDTH_MODEM_336;
  121. } else if (cMiscUtil::Is_String_Same(bandwidth_string, "BANDWIDTH_MODEM_56")) {
  122. return BANDWIDTH_MODEM_56;
  123. } else if (cMiscUtil::Is_String_Same(bandwidth_string, "BANDWIDTH_ISDN")) {
  124. return BANDWIDTH_ISDN;
  125. } else if (cMiscUtil::Is_String_Same(bandwidth_string, "BANDWIDTH_CABLE")) {
  126. return BANDWIDTH_CABLE;
  127. } else if (cMiscUtil::Is_String_Same(bandwidth_string, "BANDWIDTH_LANT1")) {
  128. return BANDWIDTH_LANT1;
  129. } else if (cMiscUtil::Is_String_Same(bandwidth_string, "BANDWIDTH_CUSTOM")) {
  130. return BANDWIDTH_CUSTOM;
  131. } else if (strnicmp(bandwidth_string, "BANDWIDTH_AUTO ", 15) == 0) {
  132. return BANDWIDTH_AUTO;
  133. } else {
  134. DIE;
  135. return BANDWIDTH_CUSTOM; // to avoid compiler warning
  136. }
  137. }