dlgmpslaveservers.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/dlgmpslaveservers.cpp $*
  25. * *
  26. * Author:: Steve Tall *
  27. * *
  28. * $Modtime:: 2/11/02 11:03a $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "always.h"
  36. #include "dlgmpslaveservers.h"
  37. #include "menudialog.h"
  38. #include "_globals.h"
  39. #include "slavemaster.h"
  40. #include "dlgserversaveload.h"
  41. #include "rawfile.h"
  42. #include "ini.h"
  43. #include "assets.h"
  44. unsigned long SlaveServerDialogClass::EnableIDs[MAX_SLAVES] = {
  45. IDC_SLAVE_ENABLE1,
  46. IDC_SLAVE_ENABLE2,
  47. IDC_SLAVE_ENABLE3,
  48. IDC_SLAVE_ENABLE4,
  49. IDC_SLAVE_ENABLE5,
  50. IDC_SLAVE_ENABLE6,
  51. IDC_SLAVE_ENABLE7
  52. };
  53. unsigned long SlaveServerDialogClass::NickIDs[MAX_SLAVES] = {
  54. IDC_NICK_EDIT1,
  55. IDC_NICK_EDIT2,
  56. IDC_NICK_EDIT3,
  57. IDC_NICK_EDIT4,
  58. IDC_NICK_EDIT5,
  59. IDC_NICK_EDIT6,
  60. IDC_NICK_EDIT7
  61. };
  62. unsigned long SlaveServerDialogClass::PassIDs[MAX_SLAVES] = {
  63. IDC_PASS_EDIT1,
  64. IDC_PASS_EDIT2,
  65. IDC_PASS_EDIT3,
  66. IDC_PASS_EDIT4,
  67. IDC_PASS_EDIT5,
  68. IDC_PASS_EDIT6,
  69. IDC_PASS_EDIT7
  70. };
  71. unsigned long SlaveServerDialogClass::SerialIDs[MAX_SLAVES] = {
  72. IDC_SERIAL_EDIT1,
  73. IDC_SERIAL_EDIT2,
  74. IDC_SERIAL_EDIT3,
  75. IDC_SERIAL_EDIT4,
  76. IDC_SERIAL_EDIT5,
  77. IDC_SERIAL_EDIT6,
  78. IDC_SERIAL_EDIT7
  79. };
  80. unsigned long SlaveServerDialogClass::PortIDs[MAX_SLAVES] = {
  81. IDC_PORT_EDIT1,
  82. IDC_PORT_EDIT2,
  83. IDC_PORT_EDIT3,
  84. IDC_PORT_EDIT4,
  85. IDC_PORT_EDIT5,
  86. IDC_PORT_EDIT6,
  87. IDC_PORT_EDIT7
  88. };
  89. unsigned long SlaveServerDialogClass::SettingsButtons[MAX_SLAVES] = {
  90. IDC_SLAVE1_SETTINGS,
  91. IDC_SLAVE2_SETTINGS,
  92. IDC_SLAVE3_SETTINGS,
  93. IDC_SLAVE4_SETTINGS,
  94. IDC_SLAVE5_SETTINGS,
  95. IDC_SLAVE6_SETTINGS,
  96. IDC_SLAVE7_SETTINGS
  97. };
  98. char SlaveServerDialogClass::ServerSettingsFileNames[MAX_SLAVES][MAX_PATH];
  99. int SlaveServerDialogClass::SlaveNumber = 0;
  100. SlaveServerDialogClass *SlaveServerDialogClass::Instance = NULL;
  101. ////////////////////////////////////////////////////////////////
  102. //
  103. // CheatOptionsMenuClass
  104. //
  105. ////////////////////////////////////////////////////////////////
  106. SlaveServerDialogClass::SlaveServerDialogClass(void) :
  107. MenuDialogClass(IDD_MP_WOL_SLAVESERVER)
  108. {
  109. Instance = this;
  110. }
  111. void
  112. SlaveServerDialogClass::On_Init_Dialog (void)
  113. {
  114. /*
  115. ** Init the slave master.
  116. */
  117. SlaveMaster.Load();
  118. int num_slaves = SlaveMaster.Get_Num_Slaves();
  119. char nick[64];
  120. char serial[64];
  121. char pass[64];
  122. bool enable;
  123. unsigned short port;
  124. char settings_file_name[MAX_PATH];
  125. int bw;
  126. /*
  127. ** Set up the dialog entries for each slave.
  128. */
  129. for (int i=0 ; i<MAX_SLAVES ; i++) {
  130. nick[0] = 0;
  131. serial[0] = 0;
  132. enable = false;
  133. port = 0;
  134. settings_file_name[0] = 0;
  135. bw = 0;
  136. if (i < num_slaves) {
  137. SlaveServerClass *slave = SlaveMaster.Get_Slave(i);
  138. if (slave != NULL) {
  139. slave->Get(enable, nick, serial, port, settings_file_name, bw, pass);
  140. }
  141. }
  142. Check_Dlg_Button (EnableIDs[i], enable);
  143. WideStringClass tempnick(nick, true);
  144. Set_Dlg_Item_Text(NickIDs[i], tempnick.Peek_Buffer());
  145. WideStringClass temppass(pass, true);
  146. Set_Dlg_Item_Text(PassIDs[i], temppass.Peek_Buffer());
  147. WideStringClass tempser(serial, true);
  148. Set_Dlg_Item_Text(SerialIDs[i], tempser.Peek_Buffer());
  149. char temp[32];
  150. _itoa((unsigned long)port, temp, 10);
  151. WideStringClass tempport(temp, true);
  152. Set_Dlg_Item_Text(PortIDs[i], tempport.Peek_Buffer());
  153. strcpy(ServerSettingsFileNames[i], settings_file_name);
  154. Set_Slave_Button(i);
  155. }
  156. MenuDialogClass::On_Init_Dialog ();
  157. }
  158. void
  159. SlaveServerDialogClass::On_Command (int ctrl_id, int message_id, DWORD param)
  160. {
  161. switch (ctrl_id) {
  162. case IDC_MENU_BACK_BUTTON:
  163. {
  164. SlaveMaster.Reset();
  165. char *nick = "";
  166. char *pass = "";
  167. char *serial = "";
  168. bool enable = false;
  169. for (int i=0 ; i<MAX_SLAVES ; i++) {
  170. enable = Is_Dlg_Button_Checked(EnableIDs[i]);
  171. WideStringClass tempnick(Get_Dlg_Item_Text(NickIDs[i]));
  172. StringClass newnick;
  173. tempnick.Convert_To(newnick);
  174. nick = newnick.Peek_Buffer();
  175. WideStringClass temppass(Get_Dlg_Item_Text(PassIDs[i]));
  176. StringClass newpass;
  177. temppass.Convert_To(newpass);
  178. pass = newpass.Peek_Buffer();
  179. WideStringClass tempser(Get_Dlg_Item_Text(SerialIDs[i]));
  180. StringClass newser;
  181. tempser.Convert_To(newser);
  182. serial = newser.Peek_Buffer();
  183. WideStringClass tempport(Get_Dlg_Item_Text(PortIDs[i]));
  184. StringClass newport;
  185. tempport.Convert_To(newport);
  186. unsigned long port = atoi(newport.Peek_Buffer());
  187. if (port > 0xffff) {
  188. port = 0xffff;
  189. }
  190. SlaveMaster.Add_Slave(enable, nick, serial, (unsigned short)port, ServerSettingsFileNames[i], 0xffffffff, pass);
  191. }
  192. SlaveMaster.Save();
  193. }
  194. break;
  195. case IDC_SLAVE1_SETTINGS:
  196. Load_Settings(1);
  197. break;
  198. case IDC_SLAVE2_SETTINGS:
  199. Load_Settings(2);
  200. break;
  201. case IDC_SLAVE3_SETTINGS:
  202. Load_Settings(3);
  203. break;
  204. case IDC_SLAVE4_SETTINGS:
  205. Load_Settings(4);
  206. break;
  207. case IDC_SLAVE5_SETTINGS:
  208. Load_Settings(5);
  209. break;
  210. case IDC_SLAVE6_SETTINGS:
  211. Load_Settings(6);
  212. break;
  213. case IDC_SLAVE7_SETTINGS:
  214. Load_Settings(7);
  215. break;
  216. }
  217. MenuDialogClass::On_Command (ctrl_id, message_id, param);
  218. }
  219. void SlaveServerDialogClass::Load_Settings(int slave_number)
  220. {
  221. SlaveNumber = slave_number;
  222. ServerSaveLoadMenuClass::Set_From_Slave_Config(true);
  223. START_DIALOG(ServerSaveLoadMenuClass);
  224. }
  225. void SlaveServerDialogClass::Set_Slave_Settings(StringClass *file_name)
  226. {
  227. if (SlaveNumber) {
  228. int slave = SlaveNumber-1;
  229. strcpy(ServerSettingsFileNames[slave], file_name->Peek_Buffer());
  230. Set_Slave_Button(slave);
  231. }
  232. }
  233. void SlaveServerDialogClass::Set_Slave_Button(int slavenum)
  234. {
  235. char char_description[256];
  236. WideStringClass description;
  237. char file_name[MAX_PATH];
  238. sprintf(file_name, "data\\%s", ServerSettingsFileNames[slavenum]);
  239. RawFileClass file(file_name);
  240. if (file.Is_Available()) {
  241. INIClass *ini = Get_INI(ServerSettingsFileNames[slavenum]);
  242. if (ini) {
  243. description = ini->Get_Wide_String(description, "Settings", "wConfigName", L"");
  244. int size = description.Get_Length();
  245. if (size == 0) {
  246. size = ini->Get_String("Settings", "bConfigName", "", char_description, sizeof(char_description));
  247. if (size != 0) {
  248. description = char_description;
  249. } else {
  250. description = (unsigned short *)TRANSLATE(IDS_SERVER_SAVELOAD_DEFAULT);
  251. size = 1;
  252. }
  253. }
  254. //int size = ini->Get_String("Settings", "ConfigName", "Custom C&C Server Settings", description, sizeof(description));
  255. if (size) {
  256. Instance->Set_Dlg_Item_Text(SettingsButtons[slavenum], WideStringClass(description, true));
  257. }
  258. }
  259. }
  260. }
  261. ////////////////////////////////////////////////////////////////
  262. //
  263. // On_Destroy
  264. //
  265. ////////////////////////////////////////////////////////////////
  266. void
  267. SlaveServerDialogClass::On_Destroy (void)
  268. {
  269. MenuDialogClass::On_Destroy ();
  270. }