UDPADDR.CPP 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. ** Command & Conquer Red Alert(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. #include "function.h"
  19. //#include "_WSProto.h"
  20. #include "WSPUDP.h"
  21. bool Get_Broadcast_Addresses (void)
  22. {
  23. int d_dialog_w = 320 *RESFACTOR; // dialog width
  24. int d_dialog_h = 160 *RESFACTOR; // dialog height
  25. int d_dialog_x = ((320*RESFACTOR - d_dialog_w) / 2); // dialog x-coord
  26. int d_dialog_y = ((200*RESFACTOR - d_dialog_h) / 2); // centered y-coord
  27. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  28. int d_txt6_h = 6 *RESFACTOR+1; // ht of 6-pt text
  29. int d_margin1 = 5 *RESFACTOR; // large margin
  30. int d_margin2 = 7 *RESFACTOR; // small margin
  31. int d_ip_address_list_w = 300 *RESFACTOR;
  32. int d_ip_address_list_h = ((20 * 6) + 3) *RESFACTOR; // 6 rows high
  33. int d_ip_address_list_x = d_dialog_cx - d_ip_address_list_w / 2;
  34. int d_ip_address_list_y = d_margin2 + d_dialog_y;
  35. int d_ok_w = 40*RESFACTOR;
  36. int d_ok_h = 9*RESFACTOR;
  37. int d_ok_x = d_dialog_cx + d_dialog_w / 4;
  38. int d_ok_y = d_dialog_y + d_dialog_h - 20*RESFACTOR;
  39. #if (GERMAN | FRENCH)
  40. int d_cancel_w = 50*RESFACTOR;
  41. #else
  42. int d_cancel_w = 40*RESFACTOR;
  43. #endif
  44. int d_cancel_h = 9*RESFACTOR;
  45. int d_cancel_x = d_dialog_cx - d_dialog_w / 4;
  46. int d_cancel_y = d_dialog_y + d_dialog_h - 20*RESFACTOR;
  47. //------------------------------------------------------------------------
  48. // Button Enumerations
  49. //------------------------------------------------------------------------
  50. enum {
  51. BUTTON_IPLIST=100,
  52. BUTTON_OK,
  53. BUTTON_CANCEL,
  54. };
  55. //------------------------------------------------------------------------
  56. // Redraw values: in order from "top" to "bottom" layer of the dialog
  57. //------------------------------------------------------------------------
  58. typedef enum {
  59. REDRAW_NONE = 0,
  60. REDRAW_PARMS,
  61. REDRAW_BUTTONS,
  62. REDRAW_BACKGROUND,
  63. REDRAW_ALL = REDRAW_BACKGROUND
  64. } RedrawType;
  65. //------------------------------------------------------------------------
  66. // Dialog variables
  67. //------------------------------------------------------------------------
  68. RedrawType display = REDRAW_ALL; // redraw level
  69. bool process = true; // process while true
  70. KeyNumType input;
  71. int width;
  72. int height;
  73. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  74. Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
  75. Format_Window_String("IP Addresses", SeenBuff.Get_Height(), width, height);
  76. GadgetClass *commands; // button list
  77. ColorListClass ip_address_list(BUTTON_IPLIST, d_ip_address_list_x, d_ip_address_list_y, d_ip_address_list_w, d_ip_address_list_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  78. TextButtonClass okbtn(BUTTON_OK, TXT_OK, TPF_BUTTON, d_ok_x, d_ok_y, d_ok_w, d_ok_h);
  79. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  80. ip_address_list.Set_Selected_Style(ColorListClass::SELECT_NORMAL);
  81. Fancy_Text_Print("", 0, 0, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  82. Load_Title_Page(true);
  83. CCPalette.Set(); //GamePalette.Set();
  84. /*
  85. ** Add all the ip addresses from the ini file to the list box.
  86. */
  87. CCINIClass ip_ini;
  88. int res=0;
  89. if (ip_ini.Load(CCFileClass("IP.INI"), false)) {
  90. int entry=0;
  91. char entry_name[16];
  92. do {
  93. entry++;
  94. char *temp = new char [128];
  95. sprintf (entry_name, "%d", entry);
  96. res = ip_ini.Get_String("IP_ADDRESSES", entry_name, "", temp, 128);
  97. if ( res ) {
  98. ip_address_list.Add_Item (temp);
  99. char debug[128];
  100. sprintf (debug, "RA95 - Adding address %s\n", temp);
  101. WWDebugString (debug);
  102. }
  103. }while (res);
  104. }
  105. ip_address_list.Flag_To_Redraw();
  106. //------------------------------------------------------------------------
  107. // Processing loop
  108. //------------------------------------------------------------------------
  109. while (process) {
  110. /*
  111. ** If we have just received input focus again after running in the background then
  112. ** we need to redraw.
  113. */
  114. if (AllSurfaces.SurfacesRestored) {
  115. AllSurfaces.SurfacesRestored=FALSE;
  116. display = REDRAW_ALL;
  117. }
  118. //.....................................................................
  119. // Refresh display if needed
  120. //.....................................................................
  121. if (display) {
  122. Hide_Mouse();
  123. //..................................................................
  124. // Redraw backgound & dialog box
  125. //..................................................................
  126. if (display >= REDRAW_BACKGROUND) {
  127. Load_Title_Page(true);
  128. CCPalette.Set(); //GamePalette.Set();
  129. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  130. //...............................................................
  131. // Dialog & Field labels
  132. //...............................................................
  133. Fancy_Text_Print("IP Addresses", d_dialog_cx-width/2, d_dialog_y + 25*RESFACTOR, scheme, TBLACK, TPF_TEXT);
  134. //...............................................................
  135. // Rebuild the button list
  136. //...............................................................
  137. okbtn.Zap();
  138. cancelbtn.Zap();
  139. ip_address_list.Zap();
  140. commands = &okbtn;
  141. cancelbtn.Add_Tail(*commands);
  142. ip_address_list.Add_Tail(*commands);
  143. }
  144. //..................................................................
  145. // Redraw buttons
  146. //..................................................................
  147. if (display >= REDRAW_BUTTONS) {
  148. commands->Draw_All();
  149. }
  150. Show_Mouse();
  151. display = REDRAW_NONE;
  152. }
  153. //.....................................................................
  154. // Get user input
  155. //.....................................................................
  156. input = commands->Input();
  157. //.....................................................................
  158. // Process input
  159. //.....................................................................
  160. switch (input) {
  161. //..................................................................
  162. // ESC / CANCEL: send a SIGN_OFF
  163. // - If we're part of a game, stay in this dialog; otherwise, exit
  164. //..................................................................
  165. case (KN_ESC):
  166. case (BUTTON_CANCEL | KN_BUTTON):
  167. process = false;
  168. return (false);
  169. case (BUTTON_OK | KN_BUTTON):
  170. process = false;
  171. break;
  172. }
  173. }
  174. //------------------------------------------------------------------------
  175. // Restore screen
  176. //------------------------------------------------------------------------
  177. Hide_Mouse();
  178. Load_Title_Page(true);
  179. CCPalette.Set(); //GamePalette.Set();
  180. Show_Mouse();
  181. for ( int i=0 ; i<ip_address_list.Count() ; i++ ) {
  182. char const *temp = ip_address_list.Get_Item(i);
  183. char *cut = strchr (temp, '#');
  184. if ( cut ) *cut = 0;
  185. PacketTransport->Set_Broadcast_Address ((char*)temp);
  186. }
  187. return (true);
  188. }