UDPADDR.CPP 7.5 KB

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