CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

UDPADDR.CPP (7709B)


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