1 // net_dlg.cxx -- data structures for initializing & managing network.
3 // Written by Oliver Delise, started May 1999.
5 // Copyleft (C) 1999 Oliver Delise - delise@rp-plus.de
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <simgear/compiler.h>
34 #include <simgear/constants.h>
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/misc/sg_path.hxx>
38 #include <Include/general.hxx>
41 #include <Main/globals.hxx>
42 #include <Main/fg_props.hxx>
43 #include <NetworkOLK/network.h>
46 #include "net_dlg.hxx"
48 /// The beginnings of networking :-)
49 // Needs cleaning up but works
50 // These statics should disapear when this is a class
51 static puDialogBox *NetIdDialog = 0;
52 static puFrame *NetIdDialogFrame = 0;
53 static puText *NetIdDialogMessage = 0;
54 static puInput *NetIdDialogInput = 0;
56 static char NewNetId[16];
57 static char NewNetIdLabel[] = "Enter New Callsign";
58 extern char *fgd_callsign;
60 static puOneShot *NetIdDialogOkButton = 0;
61 static puOneShot *NetIdDialogCancelButton = 0;
63 void NetIdDialog_Cancel(puObject *)
65 FG_POP_PUI_DIALOG( NetIdDialog );
68 void NetIdDialog_OK (puObject *)
72 static const SGPropertyNode *master_freeze
73 = fgGetNode("/sim/freeze/master");
75 bool freeze = master_freeze->getBoolValue();
77 fgSetBool("/sim/freeze/master", true);
81 The following needs some cleanup because
82 "string options.NetId" and "char *net_callsign"
84 NetIdDialogInput->getValue(&net_callsign);
87 NetIdDialog_Cancel( NULL );
88 fgSetString("/networking/call-sign", NetId.c_str() );
89 strcpy( fgd_callsign, net_callsign);
90 // strcpy( fgd_callsign, fgGetString("/sim/networking/call-sign").c_str());
91 /* Entering a callsign indicates : user wants Net HUD Info */
95 fgSetBool("/sim/freeze/master", false);
99 void NewCallSign(puObject *cb)
101 sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign") );
102 // sprintf( NewNetId, "%s", fgd_callsign );
103 NetIdDialogInput->setValue( NewNetId );
105 FG_PUSH_PUI_DIALOG( NetIdDialog );
108 void NewNetIdInit(void)
110 sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign") );
111 // sprintf( NewNetId, "%s", fgd_callsign );
112 int len = 150 - puGetDefaultLabelFont().getStringWidth( NewNetIdLabel ) / 2;
114 NetIdDialog = new puDialogBox (150, 50);
116 NetIdDialogFrame = new puFrame (0,0,350, 150);
117 NetIdDialogMessage = new puText (len, 110);
118 NetIdDialogMessage -> setLabel (NewNetIdLabel);
120 NetIdDialogInput = new puInput (50, 70, 300, 100);
121 NetIdDialogInput -> setValue (NewNetId);
122 NetIdDialogInput -> acceptInput();
124 NetIdDialogOkButton = new puOneShot (50, 10, 110, 50);
125 NetIdDialogOkButton -> setLegend (gui_msg_OK);
126 NetIdDialogOkButton -> setCallback (NetIdDialog_OK);
127 NetIdDialogOkButton -> makeReturnDefault(TRUE);
129 NetIdDialogCancelButton = new puOneShot (240, 10, 300, 50);
130 NetIdDialogCancelButton -> setLegend (gui_msg_CANCEL);
131 NetIdDialogCancelButton -> setCallback (NetIdDialog_Cancel);
134 FG_FINALIZE_PUI_DIALOG( NetIdDialog );
138 /*************** Deamon communication **********/
140 // These statics should disapear when this is a class
141 static puDialogBox *NetFGDDialog = 0;
142 static puFrame *NetFGDDialogFrame = 0;
143 static puText *NetFGDDialogMessage = 0;
144 //static puInput *NetFGDDialogInput = 0;
146 //static char NewNetId[16];
147 static char NewNetFGDLabel[] = "Scan for deamon ";
148 static char NewFGDHost[64] = "olk.mcp.de";
149 static int NewFGDPortLo = 10000;
150 static int NewFGDPortHi = 10001;
152 //extern char *fgd_callsign;
153 extern u_short base_port, end_port;
154 extern int fgd_ip, verbose, current_port;
155 extern char *fgd_host;
158 static puOneShot *NetFGDDialogOkButton = 0;
159 static puOneShot *NetFGDDialogCancelButton = 0;
160 static puOneShot *NetFGDDialogScanButton = 0;
162 static puInput *NetFGDHostDialogInput = 0;
163 static puInput *NetFGDPortLoDialogInput = 0;
164 static puInput *NetFGDPortHiDialogInput = 0;
166 void NetFGDDialog_Cancel(puObject *)
168 FG_POP_PUI_DIALOG( NetFGDDialog );
171 void NetFGDDialog_OK (puObject *)
175 static const SGPropertyNode *master_freeze
176 = fgGetNode("/sim/freeze/master");
178 bool freeze = master_freeze->getBoolValue();
180 fgSetBool("/sim/freeze/master", true);
183 NetFGDHostDialogInput->getValue( &NetFGD );
184 strcpy( fgd_host, NetFGD);
185 NetFGDPortLoDialogInput->getValue( (int *) &base_port );
186 NetFGDPortHiDialogInput->getValue( (int *) &end_port );
187 NetFGDDialog_Cancel( NULL );
190 fgSetBool("/sim/freeze/master", false);
194 void NetFGDDialog_SCAN (puObject *)
199 static const SGPropertyNode *master_freeze
200 = fgGetNode("/sim/freeze/master");
202 bool freeze = master_freeze->getBoolValue();
204 fgSetBool("/sim/freeze/master", true);
207 // printf("Vor getvalue %s\n");
208 NetFGDHostDialogInput->getValue( &NetFGD );
209 // printf("Vor strcpy %s\n", (char *) NetFGD);
210 strcpy( fgd_host, NetFGD);
211 NetFGDPortLoDialogInput->getValue( (int *) &base_port );
212 NetFGDPortHiDialogInput->getValue( (int *) &end_port );
213 printf("FGD: %s Port-Start: %d Port-End: %d\n", fgd_host,
214 base_port, end_port);
215 net_resolv_fgd(fgd_host);
216 printf("Resolve : %d\n", net_r);
219 fgSetBool("/sim/freeze/master", false);
224 strcpy( fgd_name, "");
225 for( current_port = base_port; ( current_port <= end_port); current_port++) {
226 fgd_send_com("0" , FGFS_host);
227 sprintf( NewNetFGDLabel , "Scanning for deamon Port: %d", current_port);
228 printf("FGD: searching %s\n", fgd_name);
229 if ( strcmp( fgd_name, "") != 0 ) {
230 sprintf( NewNetFGDLabel , "Found %s at Port: %d",
231 fgd_name, current_port);
232 fgd_port = current_port;
233 current_port = end_port+1;
236 current_port = end_port = base_port = fgd_port;
238 NetFGDDialog_Cancel( NULL );
242 void net_fgd_scan(puObject *cb)
244 NewFGDPortLo = base_port;
245 NewFGDPortHi = end_port;
246 strcpy( NewFGDHost, fgd_host);
247 NetFGDPortLoDialogInput->setValue( NewFGDPortLo );
248 NetFGDPortHiDialogInput->setValue( NewFGDPortHi );
249 NetFGDHostDialogInput->setValue( NewFGDHost );
251 FG_PUSH_PUI_DIALOG( NetFGDDialog );
255 void NewNetFGDInit(void)
257 // sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign").c_str() );
258 // sprintf( NewNetId, "%s", fgd_callsign );
260 - puGetDefaultLabelFont().getStringWidth( NewNetFGDLabel ) / 2;
262 NetFGDDialog = new puDialogBox (310, 30);
264 NetFGDDialogFrame = new puFrame (0,0,320, 170);
265 NetFGDDialogMessage = new puText (len, 140);
266 NetFGDDialogMessage -> setLabel (NewNetFGDLabel);
268 NetFGDPortLoDialogInput = new puInput (50, 70, 127, 100);
269 NetFGDPortLoDialogInput -> setValue (NewFGDPortLo);
270 NetFGDPortLoDialogInput -> acceptInput();
272 NetFGDPortHiDialogInput = new puInput (199, 70, 275, 100);
273 NetFGDPortHiDialogInput -> setValue (NewFGDPortHi);
274 NetFGDPortHiDialogInput -> acceptInput();
276 NetFGDHostDialogInput = new puInput (50, 100, 275, 130);
277 NetFGDHostDialogInput -> setValue (NewFGDHost);
278 NetFGDHostDialogInput -> acceptInput();
280 NetFGDDialogScanButton = new puOneShot (130, 10, 200, 50);
281 NetFGDDialogScanButton -> setLegend ("Scan");
282 NetFGDDialogScanButton -> setCallback (NetFGDDialog_SCAN);
283 NetFGDDialogScanButton -> makeReturnDefault(FALSE);
285 NetFGDDialogOkButton = new puOneShot (50, 10, 120, 50);
286 NetFGDDialogOkButton -> setLegend (gui_msg_OK);
287 NetFGDDialogOkButton -> setCallback (NetFGDDialog_OK);
288 NetFGDDialogOkButton -> makeReturnDefault(TRUE);
290 NetFGDDialogCancelButton = new puOneShot (210, 10, 280, 50);
291 NetFGDDialogCancelButton -> setLegend (gui_msg_CANCEL);
292 NetFGDDialogCancelButton -> setCallback (NetFGDDialog_Cancel);
295 FG_FINALIZE_PUI_DIALOG( NetFGDDialog );
299 static void net_display_toggle( puObject *cb)
301 net_hud_display = (net_hud_display) ? 0 : 1;
302 printf("Toggle net_hud_display : %d\n", net_hud_display);
307 /*************** End Networking **************/