]> git.mxchange.org Git - flightgear.git/blob - src/GUI/net_dlg.cxx
Viewer update from Jim Wilson:
[flightgear.git] / src / GUI / net_dlg.cxx
1 // net_dlg.cxx -- data structures for initializing & managing network.
2 //
3 // Written by Oliver Delise, started May 1999.
4 //
5 // Copyleft (C) 1999  Oliver Delise - delise@rp-plus.de
6 //
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.
11 //
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.
16 //
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.
20 //
21
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #include <simgear/compiler.h>
27
28 #ifdef HAVE_WINDOWS_H
29 #  include <windows.h>
30 #endif
31
32 #include <stdlib.h>
33
34 #include <simgear/constants.h>
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/misc/sg_path.hxx>
37
38 #include <Include/general.hxx>
39 #include <GL/gl.h>
40
41 #include <Main/globals.hxx>
42 #include <Main/fg_props.hxx>
43 #include <NetworkOLK/network.h>
44
45 #include "gui.h"
46 #include "net_dlg.hxx"
47
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;
55
56 static char NewNetId[16];
57 static char NewNetIdLabel[] = "Enter New Callsign"; 
58 extern char *fgd_callsign;
59
60 static puOneShot       *NetIdDialogOkButton = 0;
61 static puOneShot       *NetIdDialogCancelButton = 0;
62
63 void NetIdDialog_Cancel(puObject *)
64 {
65         FG_POP_PUI_DIALOG( NetIdDialog );
66 }
67
68 void NetIdDialog_OK (puObject *)
69 {
70     string NetId;
71
72     static const SGPropertyNode *master_freeze
73         = fgGetNode("/sim/freeze/master");
74
75     bool freeze = master_freeze->getBoolValue();
76     if ( !freeze ) {
77         fgSetBool("/sim/freeze/master", true);
78     }
79
80 /*  
81    The following needs some cleanup because 
82    "string options.NetId" and "char *net_callsign" 
83 */
84     NetIdDialogInput->getValue(&net_callsign);
85     NetId = net_callsign;
86
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 */
92     net_hud_display = 1;
93
94     if ( !freeze ) {
95         fgSetBool("/sim/freeze/master", false);
96     }
97 }
98
99 void NewCallSign(puObject *cb)
100 {
101         sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign") );
102 //    sprintf( NewNetId, "%s", fgd_callsign );
103         NetIdDialogInput->setValue( NewNetId );
104
105         FG_PUSH_PUI_DIALOG( NetIdDialog );
106 }
107
108 void NewNetIdInit(void)
109 {
110         sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign") );
111 //    sprintf( NewNetId, "%s", fgd_callsign );
112         int len = 150 - puGetDefaultLabelFont().getStringWidth( NewNetIdLabel ) / 2;
113
114         NetIdDialog = new puDialogBox (150, 50);
115         {
116                 NetIdDialogFrame   = new puFrame           (0,0,350, 150);
117                 NetIdDialogMessage = new puText            (len, 110);
118                 NetIdDialogMessage ->    setLabel          (NewNetIdLabel);
119
120                 NetIdDialogInput   = new puInput           (50, 70, 300, 100);
121                 NetIdDialogInput   ->    setValue          (NewNetId);
122                 NetIdDialogInput   ->    acceptInput();
123
124                 NetIdDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
125                 NetIdDialogOkButton     ->     setLegend   (gui_msg_OK);
126                 NetIdDialogOkButton     ->     setCallback (NetIdDialog_OK);
127                 NetIdDialogOkButton     ->     makeReturnDefault(TRUE);
128
129                 NetIdDialogCancelButton =  new puOneShot   (240, 10, 300, 50);
130                 NetIdDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
131                 NetIdDialogCancelButton ->     setCallback (NetIdDialog_Cancel);
132
133         }
134         FG_FINALIZE_PUI_DIALOG( NetIdDialog );
135 }
136
137
138 /*************** Deamon communication **********/
139
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;
145
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;
151
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;
156
157
158 static puOneShot       *NetFGDDialogOkButton = 0;
159 static puOneShot       *NetFGDDialogCancelButton = 0;
160 static puOneShot       *NetFGDDialogScanButton = 0;
161
162 static puInput         *NetFGDHostDialogInput = 0;
163 static puInput         *NetFGDPortLoDialogInput = 0;
164 static puInput         *NetFGDPortHiDialogInput = 0;
165
166 void NetFGDDialog_Cancel(puObject *)
167 {
168         FG_POP_PUI_DIALOG( NetFGDDialog );
169 }
170
171 void NetFGDDialog_OK (puObject *)
172 {
173     char *NetFGD;    
174
175     static const SGPropertyNode *master_freeze
176         = fgGetNode("/sim/freeze/master");
177
178     bool freeze = master_freeze->getBoolValue();
179     if ( !freeze ) {
180         fgSetBool("/sim/freeze/master", true);
181     }
182
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 );
188
189     if ( !freeze ) {
190         fgSetBool("/sim/freeze/master", false);
191     }
192 }
193
194 void NetFGDDialog_SCAN (puObject *)
195 {
196     char *NetFGD;
197     int fgd_port;
198
199     static const SGPropertyNode *master_freeze
200         = fgGetNode("/sim/freeze/master");
201
202     bool freeze = master_freeze->getBoolValue();
203     if ( !freeze ) {
204         fgSetBool("/sim/freeze/master", true);
205     }
206
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);
217
218     if ( !freeze ) {
219         fgSetBool("/sim/freeze/master", false);
220     }
221
222     if ( net_r == 0 ) {
223         fgd_port = 10000;
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;
234             }
235         }
236         current_port = end_port = base_port = fgd_port;
237     }
238     NetFGDDialog_Cancel( NULL );
239 }
240
241
242 void net_fgd_scan(puObject *cb)
243 {
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 );
250
251         FG_PUSH_PUI_DIALOG( NetFGDDialog );
252 }
253
254
255 void NewNetFGDInit(void)
256 {
257 //    sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign").c_str() );
258 //    sprintf( NewNetId, "%s", fgd_callsign );
259     int len = 170
260         - puGetDefaultLabelFont().getStringWidth( NewNetFGDLabel ) / 2;
261
262         NetFGDDialog = new puDialogBox (310, 30);
263         {
264                 NetFGDDialogFrame   = new puFrame           (0,0,320, 170);
265                 NetFGDDialogMessage = new puText            (len, 140);
266                 NetFGDDialogMessage ->    setLabel          (NewNetFGDLabel);
267
268                 NetFGDPortLoDialogInput   = new puInput           (50, 70, 127, 100);
269                 NetFGDPortLoDialogInput   ->    setValue          (NewFGDPortLo);
270                 NetFGDPortLoDialogInput   ->    acceptInput();
271
272                 NetFGDPortHiDialogInput   = new puInput           (199, 70, 275, 100);
273                 NetFGDPortHiDialogInput   ->    setValue          (NewFGDPortHi);
274                 NetFGDPortHiDialogInput   ->    acceptInput();
275
276                 NetFGDHostDialogInput   = new puInput           (50, 100, 275, 130);
277                 NetFGDHostDialogInput   ->    setValue          (NewFGDHost);
278                 NetFGDHostDialogInput   ->    acceptInput();
279
280                 NetFGDDialogScanButton     =  new puOneShot   (130, 10, 200, 50);
281                 NetFGDDialogScanButton     ->     setLegend   ("Scan");
282                 NetFGDDialogScanButton     ->     setCallback (NetFGDDialog_SCAN);
283                 NetFGDDialogScanButton     ->     makeReturnDefault(FALSE);
284
285                 NetFGDDialogOkButton     =  new puOneShot   (50, 10, 120, 50);
286                 NetFGDDialogOkButton     ->     setLegend   (gui_msg_OK);
287                 NetFGDDialogOkButton     ->     setCallback (NetFGDDialog_OK);
288                 NetFGDDialogOkButton     ->     makeReturnDefault(TRUE);
289
290                 NetFGDDialogCancelButton =  new puOneShot   (210, 10, 280, 50);
291                 NetFGDDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
292                 NetFGDDialogCancelButton ->     setCallback (NetFGDDialog_Cancel);
293
294         }
295         FG_FINALIZE_PUI_DIALOG( NetFGDDialog );
296 }
297
298 /*
299 static void net_display_toggle( puObject *cb)
300 {
301         net_hud_display = (net_hud_display) ? 0 : 1;
302         printf("Toggle net_hud_display : %d\n", net_hud_display);
303 }
304
305 */
306
307 /***************  End Networking  **************/
308