]> git.mxchange.org Git - flightgear.git/blob - src/GUI/net_dlg.cxx
Removed stale include of options.hxx.
[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         bool freeze = globals->get_freeze();
73         if(!freeze)
74                 globals->set_freeze( true );
75 /*  
76    The following needs some cleanup because 
77    "string options.NetId" and "char *net_callsign" 
78 */
79         NetIdDialogInput->getValue(&net_callsign);
80         NetId = net_callsign;
81
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 */
87         net_hud_display = 1;
88
89         if(!freeze)
90                 globals->set_freeze( false );
91 }
92
93 void NewCallSign(puObject *cb)
94 {
95         sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign").c_str() );
96 //    sprintf( NewNetId, "%s", fgd_callsign );
97         NetIdDialogInput->setValue( NewNetId );
98
99         FG_PUSH_PUI_DIALOG( NetIdDialog );
100 }
101
102 void NewNetIdInit(void)
103 {
104         sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign").c_str() );
105 //    sprintf( NewNetId, "%s", fgd_callsign );
106         int len = 150 - puGetDefaultLabelFont().getStringWidth( NewNetIdLabel ) / 2;
107
108         NetIdDialog = new puDialogBox (150, 50);
109         {
110                 NetIdDialogFrame   = new puFrame           (0,0,350, 150);
111                 NetIdDialogMessage = new puText            (len, 110);
112                 NetIdDialogMessage ->    setLabel          (NewNetIdLabel);
113
114                 NetIdDialogInput   = new puInput           (50, 70, 300, 100);
115                 NetIdDialogInput   ->    setValue          (NewNetId);
116                 NetIdDialogInput   ->    acceptInput();
117
118                 NetIdDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
119                 NetIdDialogOkButton     ->     setLegend   (gui_msg_OK);
120                 NetIdDialogOkButton     ->     setCallback (NetIdDialog_OK);
121                 NetIdDialogOkButton     ->     makeReturnDefault(TRUE);
122
123                 NetIdDialogCancelButton =  new puOneShot   (240, 10, 300, 50);
124                 NetIdDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
125                 NetIdDialogCancelButton ->     setCallback (NetIdDialog_Cancel);
126
127         }
128         FG_FINALIZE_PUI_DIALOG( NetIdDialog );
129 }
130
131
132 /*************** Deamon communication **********/
133
134 //  These statics should disapear when this is a class
135 static puDialogBox     *NetFGDDialog = 0;
136 static puFrame         *NetFGDDialogFrame = 0;
137 static puText          *NetFGDDialogMessage = 0;
138 //static puInput         *NetFGDDialogInput = 0;
139
140 //static char NewNetId[16];
141 static char NewNetFGDLabel[] = "Scan for deamon                        "; 
142 static char NewFGDHost[64] = "olk.mcp.de"; 
143 static int  NewFGDPortLo = 10000;
144 static int  NewFGDPortHi = 10001;
145
146 //extern char *fgd_callsign;
147 extern u_short base_port, end_port;
148 extern int fgd_ip, verbose, current_port;
149 extern char *fgd_host;
150
151
152 static puOneShot       *NetFGDDialogOkButton = 0;
153 static puOneShot       *NetFGDDialogCancelButton = 0;
154 static puOneShot       *NetFGDDialogScanButton = 0;
155
156 static puInput         *NetFGDHostDialogInput = 0;
157 static puInput         *NetFGDPortLoDialogInput = 0;
158 static puInput         *NetFGDPortHiDialogInput = 0;
159
160 void NetFGDDialog_Cancel(puObject *)
161 {
162         FG_POP_PUI_DIALOG( NetFGDDialog );
163 }
164
165 void NetFGDDialog_OK (puObject *)
166 {
167         char *NetFGD;    
168
169         bool freeze = globals->get_freeze();
170         if(!freeze)
171                 globals->set_freeze( true );
172         NetFGDHostDialogInput->getValue( &NetFGD );
173         strcpy( fgd_host, NetFGD);
174         NetFGDPortLoDialogInput->getValue( (int *) &base_port );
175         NetFGDPortHiDialogInput->getValue( (int *) &end_port );
176         NetFGDDialog_Cancel( NULL );
177         if(!freeze)
178                 globals->set_freeze( false );
179 }
180
181 void NetFGDDialog_SCAN (puObject *)
182 {
183         char *NetFGD;
184         int fgd_port;
185
186         bool freeze = globals->get_freeze();
187         if(!freeze)
188                 globals->set_freeze( true );
189 //    printf("Vor getvalue %s\n");
190         NetFGDHostDialogInput->getValue( &NetFGD );
191 //    printf("Vor strcpy %s\n", (char *) NetFGD);
192         strcpy( fgd_host, NetFGD);
193         NetFGDPortLoDialogInput->getValue( (int *) &base_port );
194         NetFGDPortHiDialogInput->getValue( (int *) &end_port );
195         printf("FGD: %s  Port-Start: %d Port-End: %d\n", fgd_host, 
196                    base_port, end_port);
197         net_resolv_fgd(fgd_host);
198         printf("Resolve : %d\n", net_r);
199         if(!freeze)
200                 globals->set_freeze( false );
201         if ( net_r == 0 ) {
202                 fgd_port = 10000;
203                 strcpy( fgd_name, "");
204                 for( current_port = base_port; ( current_port <= end_port); current_port++) {
205                         fgd_send_com("0" , FGFS_host);
206                         sprintf( NewNetFGDLabel , "Scanning for deamon Port: %d", current_port); 
207                         printf("FGD: searching %s\n", fgd_name);
208                         if ( strcmp( fgd_name, "") != 0 ) {
209                                 sprintf( NewNetFGDLabel , "Found %s at Port: %d", 
210                                                  fgd_name, current_port);
211                                 fgd_port = current_port;
212                                 current_port = end_port+1;
213                         }
214                 }
215                 current_port = end_port = base_port = fgd_port;
216         }
217         NetFGDDialog_Cancel( NULL );
218 }
219
220
221 void net_fgd_scan(puObject *cb)
222 {
223         NewFGDPortLo = base_port;
224         NewFGDPortHi = end_port;
225         strcpy( NewFGDHost, fgd_host);
226         NetFGDPortLoDialogInput->setValue( NewFGDPortLo );
227         NetFGDPortHiDialogInput->setValue( NewFGDPortHi );
228         NetFGDHostDialogInput->setValue( NewFGDHost );
229
230         FG_PUSH_PUI_DIALOG( NetFGDDialog );
231 }
232
233
234 void NewNetFGDInit(void)
235 {
236 //    sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign").c_str() );
237 //    sprintf( NewNetId, "%s", fgd_callsign );
238     int len = 170
239         - puGetDefaultLabelFont().getStringWidth( NewNetFGDLabel ) / 2;
240
241         NetFGDDialog = new puDialogBox (310, 30);
242         {
243                 NetFGDDialogFrame   = new puFrame           (0,0,320, 170);
244                 NetFGDDialogMessage = new puText            (len, 140);
245                 NetFGDDialogMessage ->    setLabel          (NewNetFGDLabel);
246
247                 NetFGDPortLoDialogInput   = new puInput           (50, 70, 127, 100);
248                 NetFGDPortLoDialogInput   ->    setValue          (NewFGDPortLo);
249                 NetFGDPortLoDialogInput   ->    acceptInput();
250
251                 NetFGDPortHiDialogInput   = new puInput           (199, 70, 275, 100);
252                 NetFGDPortHiDialogInput   ->    setValue          (NewFGDPortHi);
253                 NetFGDPortHiDialogInput   ->    acceptInput();
254
255                 NetFGDHostDialogInput   = new puInput           (50, 100, 275, 130);
256                 NetFGDHostDialogInput   ->    setValue          (NewFGDHost);
257                 NetFGDHostDialogInput   ->    acceptInput();
258
259                 NetFGDDialogScanButton     =  new puOneShot   (130, 10, 200, 50);
260                 NetFGDDialogScanButton     ->     setLegend   ("Scan");
261                 NetFGDDialogScanButton     ->     setCallback (NetFGDDialog_SCAN);
262                 NetFGDDialogScanButton     ->     makeReturnDefault(FALSE);
263
264                 NetFGDDialogOkButton     =  new puOneShot   (50, 10, 120, 50);
265                 NetFGDDialogOkButton     ->     setLegend   (gui_msg_OK);
266                 NetFGDDialogOkButton     ->     setCallback (NetFGDDialog_OK);
267                 NetFGDDialogOkButton     ->     makeReturnDefault(TRUE);
268
269                 NetFGDDialogCancelButton =  new puOneShot   (210, 10, 280, 50);
270                 NetFGDDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
271                 NetFGDDialogCancelButton ->     setCallback (NetFGDDialog_Cancel);
272
273         }
274         FG_FINALIZE_PUI_DIALOG( NetFGDDialog );
275 }
276
277 /*
278 static void net_display_toggle( puObject *cb)
279 {
280         net_hud_display = (net_hud_display) ? 0 : 1;
281         printf("Toggle net_hud_display : %d\n", net_hud_display);
282 }
283
284 */
285
286 /***************  End Networking  **************/
287