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