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 bool freeze = globals->get_freeze();
74 globals->set_freeze( true );
76 The following needs some cleanup because
77 "string options.NetId" and "char *net_callsign"
79 NetIdDialogInput->getValue(&net_callsign);
82 NetIdDialog_Cancel( NULL );
83 fgSetString("/networking/call-sign", NetId.c_str() );
84 strcpy( fgd_callsign, net_callsign);
85 // strcpy( fgd_callsign, fgGetString("/sim/networking/call-sign").c_str());
86 /* Entering a callsign indicates : user wants Net HUD Info */
90 globals->set_freeze( false );
93 void NewCallSign(puObject *cb)
95 sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign").c_str() );
96 // sprintf( NewNetId, "%s", fgd_callsign );
97 NetIdDialogInput->setValue( NewNetId );
99 FG_PUSH_PUI_DIALOG( NetIdDialog );
102 void NewNetIdInit(void)
104 sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign").c_str() );
105 // sprintf( NewNetId, "%s", fgd_callsign );
106 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
109 NetIdDialog = new puDialogBox (150, 50);
111 NetIdDialogFrame = new puFrame (0,0,350, 150);
112 NetIdDialogMessage = new puText (len, 110);
113 NetIdDialogMessage -> setLabel (NewNetIdLabel);
115 NetIdDialogInput = new puInput (50, 70, 300, 100);
116 NetIdDialogInput -> setValue (NewNetId);
117 NetIdDialogInput -> acceptInput();
119 NetIdDialogOkButton = new puOneShot (50, 10, 110, 50);
120 NetIdDialogOkButton -> setLegend (gui_msg_OK);
121 NetIdDialogOkButton -> setCallback (NetIdDialog_OK);
122 NetIdDialogOkButton -> makeReturnDefault(TRUE);
124 NetIdDialogCancelButton = new puOneShot (240, 10, 300, 50);
125 NetIdDialogCancelButton -> setLegend (gui_msg_CANCEL);
126 NetIdDialogCancelButton -> setCallback (NetIdDialog_Cancel);
129 FG_FINALIZE_PUI_DIALOG( NetIdDialog );
133 /*************** Deamon communication **********/
135 // These statics should disapear when this is a class
136 static puDialogBox *NetFGDDialog = 0;
137 static puFrame *NetFGDDialogFrame = 0;
138 static puText *NetFGDDialogMessage = 0;
139 //static puInput *NetFGDDialogInput = 0;
141 //static char NewNetId[16];
142 static char NewNetFGDLabel[] = "Scan for deamon ";
143 static char NewFGDHost[64] = "olk.mcp.de";
144 static int NewFGDPortLo = 10000;
145 static int NewFGDPortHi = 10001;
147 //extern char *fgd_callsign;
148 extern u_short base_port, end_port;
149 extern int fgd_ip, verbose, current_port;
150 extern char *fgd_host;
153 static puOneShot *NetFGDDialogOkButton = 0;
154 static puOneShot *NetFGDDialogCancelButton = 0;
155 static puOneShot *NetFGDDialogScanButton = 0;
157 static puInput *NetFGDHostDialogInput = 0;
158 static puInput *NetFGDPortLoDialogInput = 0;
159 static puInput *NetFGDPortHiDialogInput = 0;
161 void NetFGDDialog_Cancel(puObject *)
163 FG_POP_PUI_DIALOG( NetFGDDialog );
166 void NetFGDDialog_OK (puObject *)
170 bool freeze = globals->get_freeze();
172 globals->set_freeze( true );
173 NetFGDHostDialogInput->getValue( &NetFGD );
174 strcpy( fgd_host, NetFGD);
175 NetFGDPortLoDialogInput->getValue( (int *) &base_port );
176 NetFGDPortHiDialogInput->getValue( (int *) &end_port );
177 NetFGDDialog_Cancel( NULL );
179 globals->set_freeze( false );
182 void NetFGDDialog_SCAN (puObject *)
187 bool freeze = globals->get_freeze();
189 globals->set_freeze( true );
190 // printf("Vor getvalue %s\n");
191 NetFGDHostDialogInput->getValue( &NetFGD );
192 // printf("Vor strcpy %s\n", (char *) NetFGD);
193 strcpy( fgd_host, NetFGD);
194 NetFGDPortLoDialogInput->getValue( (int *) &base_port );
195 NetFGDPortHiDialogInput->getValue( (int *) &end_port );
196 printf("FGD: %s Port-Start: %d Port-End: %d\n", fgd_host,
197 base_port, end_port);
198 net_resolv_fgd(fgd_host);
199 printf("Resolve : %d\n", net_r);
201 globals->set_freeze( false );
204 strcpy( fgd_name, "");
205 for( current_port = base_port; ( current_port <= end_port); current_port++) {
206 fgd_send_com("0" , FGFS_host);
207 sprintf( NewNetFGDLabel , "Scanning for deamon Port: %d", current_port);
208 printf("FGD: searching %s\n", fgd_name);
209 if ( strcmp( fgd_name, "") != 0 ) {
210 sprintf( NewNetFGDLabel , "Found %s at Port: %d",
211 fgd_name, current_port);
212 fgd_port = current_port;
213 current_port = end_port+1;
216 current_port = end_port = base_port = fgd_port;
218 NetFGDDialog_Cancel( NULL );
222 void net_fgd_scan(puObject *cb)
224 NewFGDPortLo = base_port;
225 NewFGDPortHi = end_port;
226 strcpy( NewFGDHost, fgd_host);
227 NetFGDPortLoDialogInput->setValue( NewFGDPortLo );
228 NetFGDPortHiDialogInput->setValue( NewFGDPortHi );
229 NetFGDHostDialogInput->setValue( NewFGDHost );
231 FG_PUSH_PUI_DIALOG( NetFGDDialog );
235 void NewNetFGDInit(void)
237 // sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign").c_str() );
238 // sprintf( NewNetId, "%s", fgd_callsign );
239 int len = 170 - puGetStringWidth( puGetDefaultLabelFont(),
240 NewNetFGDLabel ) / 2;
242 NetFGDDialog = new puDialogBox (310, 30);
244 NetFGDDialogFrame = new puFrame (0,0,320, 170);
245 NetFGDDialogMessage = new puText (len, 140);
246 NetFGDDialogMessage -> setLabel (NewNetFGDLabel);
248 NetFGDPortLoDialogInput = new puInput (50, 70, 127, 100);
249 NetFGDPortLoDialogInput -> setValue (NewFGDPortLo);
250 NetFGDPortLoDialogInput -> acceptInput();
252 NetFGDPortHiDialogInput = new puInput (199, 70, 275, 100);
253 NetFGDPortHiDialogInput -> setValue (NewFGDPortHi);
254 NetFGDPortHiDialogInput -> acceptInput();
256 NetFGDHostDialogInput = new puInput (50, 100, 275, 130);
257 NetFGDHostDialogInput -> setValue (NewFGDHost);
258 NetFGDHostDialogInput -> acceptInput();
260 NetFGDDialogScanButton = new puOneShot (130, 10, 200, 50);
261 NetFGDDialogScanButton -> setLegend ("Scan");
262 NetFGDDialogScanButton -> setCallback (NetFGDDialog_SCAN);
263 NetFGDDialogScanButton -> makeReturnDefault(FALSE);
265 NetFGDDialogOkButton = new puOneShot (50, 10, 120, 50);
266 NetFGDDialogOkButton -> setLegend (gui_msg_OK);
267 NetFGDDialogOkButton -> setCallback (NetFGDDialog_OK);
268 NetFGDDialogOkButton -> makeReturnDefault(TRUE);
270 NetFGDDialogCancelButton = new puOneShot (210, 10, 280, 50);
271 NetFGDDialogCancelButton -> setLegend (gui_msg_CANCEL);
272 NetFGDDialogCancelButton -> setCallback (NetFGDDialog_Cancel);
275 FG_FINALIZE_PUI_DIALOG( NetFGDDialog );
279 static void net_display_toggle( puObject *cb)
281 net_hud_display = (net_hud_display) ? 0 : 1;
282 printf("Toggle net_hud_display : %d\n", net_hud_display);
287 /*************** End Networking **************/