]> icculus.org git repositories - taylor/freespace2.git/blob - src/network/multi_update.cpp
take the inetfile stuff out of non-Windows builds since it doesn't compile properly
[taylor/freespace2.git] / src / network / multi_update.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Network/multi_update.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * $Log$
16  * Revision 1.4  2005/03/31 00:04:25  taylor
17  * fix directory separator (thanks Pierre\!)
18  *
19  * Revision 1.3  2002/06/09 04:41:24  relnev
20  * added copyright header
21  *
22  * Revision 1.2  2002/05/26 20:22:48  theoddone33
23  * Most of network/ works
24  *
25  * Revision 1.1.1.1  2002/05/03 03:28:10  root
26  * Initial import.
27  * 
28  * 
29  * 9     10/14/99 3:35p Jefff
30  * new xstrs
31  * 
32  * 8     8/24/99 1:50a Dave
33  * Fixed client-side afterburner stuttering. Added checkbox for no version
34  * checking on PXO join. Made button info passing more friendly between
35  * client and server.
36  * 
37  * 7     8/22/99 1:19p Dave
38  * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
39  * which d3d cards are detected.
40  * 
41  * 6     5/19/99 4:07p Dave
42  * Moved versioning code into a nice isolated common place. Fixed up
43  * updating code on the pxo screen. Fixed several stub problems.
44  * 
45  * 5     2/04/99 6:29p Dave
46  * First full working rev of FS2 PXO support.  Fixed Glide lighting
47  * problems.
48  * 
49  * 4     11/05/98 4:18p Dave
50  * First run nebula support. Beefed up localization a bit. Removed all
51  * conditional compiles for foreign versions. Modified mission file
52  * format.
53  * 
54  * 3     10/09/98 2:57p Dave
55  * Starting splitting up OS stuff.
56  * 
57  * 2     10/07/98 10:53a Dave
58  * Initial checkin.
59  * 
60  * 1     10/07/98 10:50a Dave
61  * 
62  * 15    9/10/98 1:17p Dave
63  * Put in code to flag missions and campaigns as being MD or not in Fred
64  * and Freespace. Put in multiplayer support for filtering out MD
65  * missions. Put in multiplayer popups for warning of non-valid missions.
66  * 
67  * 14    9/09/98 5:53p Dave
68  * Put in new tracker packets in API. Change cfile to be able to checksum
69  * portions of a file.
70  * 
71  * 13    7/24/98 11:13a Allender
72  * change way that the version.nfo file is parsed so that bogus returns
73  * from the HTTP server are accurately caught
74  * 
75  * 12    7/20/98 12:51p Allender
76  * don't remove the version.nfo file if we are exiting to launcher for
77  * update.  The launcher asssumes that the file is already present.
78  * 
79  * 11    7/15/98 10:50a Allender
80  * changed web site to get version.nfo from
81  * 
82  * 10    7/15/98 10:17a Dave
83  * Made the website address lookup more robust.
84  * 
85  * 9     7/15/98 10:04a Dave
86  * Change connect() procedure so that it uses non blocking sockets and
87  * freespace doesn't "hang"
88  * 
89  * 8     7/13/98 10:30a Lawrance
90  * add index numbers for newly localized strings
91  * 
92  * 7     7/13/98 10:12a Dave
93  * Remove improperly localized strings.
94  * 
95  * 6     7/10/98 5:04p Dave
96  * Fix connection speed bug on standalone server.
97  * 
98  * 5     7/10/98 11:33a Dave
99  * Give the user extra options when the need for updating is detected on
100  * PXO screen. Send special command line arg to fslauncher.
101  * 
102  * 4     7/09/98 6:07p Dave
103  * Format the text in the error dialog better.
104  * 
105  * 3     7/09/98 6:01p Dave
106  * Firsts full version of PXO updater. Put in stub for displaying
107  * connection status.
108  * 
109  * 2     7/09/98 4:51p Dave
110  * First revision of PXO autoupdate check system.
111  * 
112  * 1     7/09/98 2:09p Dave
113  * 
114  *
115  * $NoKeywords: $
116  */
117
118 #ifndef PLAT_UNIX
119 #include <winsock.h>
120 #endif
121 #include "multi_update.h"
122 #include "popup.h"
123 #include "gamesequence.h"
124 #include "osregistry.h"
125 #include "timer.h"
126 #include "version.h"
127 #include "inetgetfile.h"
128 #include "cfile.h"
129
130 // -------------------------------------------------------------------------------------------------------------------
131 // MULTI UPDATE DEFINES/VARS
132 //
133
134 #ifndef PLAT_UNIX
135 // file get object
136 InetGetFile *Multi_update_get = NULL;
137 #endif
138
139 // set this to be true so that game_shutdown() will fire up the launcher, then post a quit game event
140 int Multi_update_fireup_launcher_on_exit = 0;
141
142 // error code string for convenient reporting
143 char Multi_update_error_string[512];
144
145 // -------------------------------------------------------------------------------------------------------------------
146 // MULTI UPDATE FUNCTIONS
147 //
148
149 // initialize the http xfer of the version info file, return 1 on success
150 int multi_update_http_init()
151 {
152 #ifndef PLAT_UNIX
153         char url_file[512] = "";
154         char local_file[512] = "";
155
156         // url
157         strcpy(url_file, VERSION_URL);
158
159         // local file
160         strcpy(local_file, Cfile_root_dir);
161         strcat(local_file, DIR_SEPARATOR_STR);
162         strcat(local_file, VERSION_LOC_FNAME);
163
164         // new file     
165         Multi_update_get = new InetGetFile(url_file, local_file);
166         if(Multi_update_get == NULL){
167                 // error string
168                 strcpy(Multi_update_error_string, XSTR("Could not get data from website", 977));
169
170                 return 0;
171         }
172
173         return 1;
174 #else
175         return 0;
176 #endif
177 }
178
179 // do frame for the popup. returns 0 if not done yet, 1 if succeeded, 2 on error
180 int multi_update_http_do()
181 {
182 #ifndef PLAT_UNIX
183         // sanity
184         if(Multi_update_get == NULL){
185                 // error string
186                 strcpy(Multi_update_error_string, XSTR("Could not get data from website", 977));
187
188                 return 2;
189         }
190
191         // error
192         if(Multi_update_get->IsFileError()){                    
193                 delete Multi_update_get;
194                 Multi_update_get = NULL;
195
196                 // error string
197                 strcpy(Multi_update_error_string, XSTR("Could not get data from website", 977));
198                 
199                 return 2;
200         }       
201
202         // done!
203         if(Multi_update_get->IsFileReceived()){
204                 delete Multi_update_get;
205                 Multi_update_get = NULL;
206                 return 1;
207         }
208         
209         // connecting, receiving
210         if(Multi_update_get->IsConnecting() || Multi_update_get->IsReceiving()){
211                 return 0;
212         }
213
214         return 0;
215 #else
216         return 2;
217 #endif
218 }
219
220 // close down the http xfer
221 void multi_update_http_close()
222 {       
223 }
224
225 // error verifying, prompt the user for some action
226 int multi_update_error_verifying()
227 {
228         char out_str[512];
229
230         memset(out_str, 0, 512);
231         strcpy(out_str, "(");
232         strcat(out_str, Multi_update_error_string);
233         strcat(out_str, ")\n\n");
234         strcat(out_str, XSTR("There was an error verifying your version of Freespace, if you continue, you will not necessarily be up to date", 978));  
235
236         switch(popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON, 2, XSTR("&Go back", 1524), XSTR("&Continue", 1525), out_str)){
237         // continue on in freespace like nothing happened
238         case 1:
239         case -1:
240                 return MULTI_UPDATE_CONTINUE;
241
242         // go back to the main menu
243         default:
244                 return MULTI_UPDATE_MAIN_MENU;
245         }
246
247         // should never happen, but if so, move back to the main menu
248         return MULTI_UPDATE_MAIN_MENU;
249 }
250
251 // check to see if the version of FS on this machine is not recent. run in a popup
252 // if the versions don't check out, bail to the launcher
253 // returns 0 if freespace should continue, 1 if freespace should go back to the main menu,
254 // and 2 if the "shutdown" event was posted
255 int multi_update_gobaby()
256 {                       
257         char msg[512] = "";
258         int ret_code;
259         int my_code = MULTI_UPDATE_MAIN_MENU;
260
261         // maybe skip
262         if(os_config_read_uint(NULL, "SkipVerify", 0)){
263                 return MULTI_UPDATE_CONTINUE;
264         }
265
266         memset(Multi_update_error_string, 0, 512);      
267
268         // initialize the http connection
269         if(!multi_update_http_init()){          
270                 return multi_update_error_verifying();
271         }
272
273         // run the popup
274         extern char Multi_options_proxy[512];
275         extern ushort Multi_options_proxy_port;
276         if(strlen(Multi_options_proxy) > 0){
277                 sprintf(msg, "%s (%s : %d)", XSTR("Verifying Freespace Version",981), Multi_options_proxy, Multi_options_proxy_port);
278         } else {
279                 strcpy(msg, XSTR("Verifying Freespace Version",981));
280         }
281         ret_code = popup_till_condition(multi_update_http_do, XSTR("Cancel",948), msg);         
282
283         // determine what to do now
284         switch(ret_code){
285         // success
286         case 1 : 
287                 // compare the versions
288                 switch(version_compare(VERSION_LOC_FNAME, NULL, NULL, NULL, NULL, NULL, NULL)){
289                 // error
290                 case -1:
291                         my_code = multi_update_error_verifying();
292                         break;
293
294                 // earlier version - need to update
295                 case 0:                 
296                         switch(popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON, 2, "&Update Later", "&Yes", XSTR("A new version of Freespace is available. You must update to the new version to play on PXO\n\nAuto update now?", 980))){
297                         // update later (go back to main hall for now
298                         case 0 :
299                         case -1:
300                                 my_code = MULTI_UPDATE_MAIN_MENU;                       
301                                 break;
302
303                         default:
304                                 // set things up so that the launcher is launched when Freespace is done closing
305                                 Multi_update_fireup_launcher_on_exit = 1;
306                                 gameseq_post_event(GS_EVENT_QUIT_GAME);
307
308                                 my_code = MULTI_UPDATE_SHUTTING_DOWN;                   
309                         }                               
310                         break;
311
312                 // same version or higher
313                 case 1:
314                 case 2:
315                         my_code = MULTI_UPDATE_CONTINUE;
316                         break;
317                 }
318                 break;
319
320         // error of some kind (should probably notify the user or something)
321         case 2: 
322                 my_code = multi_update_error_verifying();               
323                 break;
324
325         // this should never happen, but if it does, go back to the main menu
326         default :
327                 my_code = multi_update_error_verifying();               
328                 break;
329         }       
330
331         // close down
332         multi_update_http_close();
333         
334         return my_code;         
335 }
336