netinterface.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. // Filename: netinterface.cpp
  20. // Project: Network.lib, for Commando
  21. // Author: Tom Spencer-Smith
  22. // Date: Dec 1998
  23. // Description:
  24. //
  25. #include "netinterface.h"
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include "miscutil.h"
  30. #include "wwdebug.h"
  31. #include "win.h"
  32. #include "mmsys.h"
  33. #include "gamespyadmin.h"
  34. #include "useroptions.h"
  35. //
  36. // class statics
  37. //
  38. WideStringClass cNetInterface::Nickname;
  39. int cNetInterface::mSidePreference = -1;
  40. //-----------------------------------------------------------------------------
  41. cNetInterface::cNetInterface(void)
  42. {
  43. }
  44. //-----------------------------------------------------------------------------
  45. cNetInterface::~cNetInterface(void)
  46. {
  47. }
  48. //-----------------------------------------------------------------------------
  49. WideStringClass cNetInterface::Get_Nickname(void)
  50. {
  51. if (cGameSpyAdmin::Is_Gamespy_Game()) {
  52. //
  53. // If the gamespy nickname is blank, set it to "Unnamed"
  54. //
  55. if (!::strcmp(cUserOptions::GameSpyNickname.Get(), "")) {
  56. cUserOptions::GameSpyNickname.Set("Unnamed");
  57. }
  58. WideStringClass wide_name;
  59. wide_name.Convert_From(cUserOptions::GameSpyNickname.Get());
  60. return wide_name;
  61. } else {
  62. return Nickname;
  63. }
  64. }
  65. //-----------------------------------------------------------------------------
  66. void cNetInterface::Set_Nickname(WideStringClass & name)
  67. {
  68. if (cGameSpyAdmin::Is_Gamespy_Game()) {
  69. WideStringClass wide_name = name;
  70. if (wide_name.Get_Length() > 30) {
  71. wide_name[30] = 0;
  72. }
  73. StringClass name;
  74. wide_name.Convert_To(name);
  75. cUserOptions::GameSpyNickname.Set(name.Peek_Buffer());
  76. } else {
  77. Nickname = name;
  78. //
  79. // Abbreviate to 9 chars
  80. //
  81. if (Nickname.Get_Length() > 9) {
  82. Nickname[9] = 0;
  83. }
  84. }
  85. }
  86. //-----------------------------------------------------------------------------
  87. void cNetInterface::Set_Random_Nickname(void)
  88. {
  89. char name[MAX_COMPUTERNAME_LENGTH + 1];
  90. DWORD size = sizeof(name);
  91. ::GetComputerName(name, &size);
  92. int length_test = MAX_COMPUTERNAME_LENGTH + 1 - MAX_NICKNAME_LENGTH;
  93. if (length_test > 0) {
  94. name[MAX_NICKNAME_LENGTH - 1] = 0;
  95. }
  96. WideStringClass widename;
  97. widename.Convert_From(name);
  98. Set_Nickname(widename);
  99. }
  100. void cNetInterface::Set_Side_Preference(int side)
  101. {
  102. mSidePreference = side;
  103. }
  104. int cNetInterface::Get_Side_Preference(void)
  105. {
  106. return mSidePreference;
  107. }
  108. //WideStringClass & cNetInterface::Get_Nickname(void)
  109. /*
  110. Nickname = name;
  111. //
  112. // Abbreviate to 9 chars
  113. //
  114. if (Nickname.Get_Length() > 9) {
  115. Nickname[9] = 0;
  116. }
  117. */
  118. /*
  119. Nickname = name;
  120. int max_len = 0;
  121. if (cGameSpyAdmin::Is_Gamespy_Game()) {
  122. max_len = 34;
  123. } else {
  124. max_len = 9;
  125. }
  126. if (Nickname.Get_Length() > max_len) {
  127. Nickname[max_len] = 0;
  128. }
  129. */
  130. //return Nickname;