2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/Network/multi_update.cpp $
16 * Revision 1.4 2005/03/31 00:04:25 taylor
17 * fix directory separator (thanks Pierre\!)
19 * Revision 1.3 2002/06/09 04:41:24 relnev
20 * added copyright header
22 * Revision 1.2 2002/05/26 20:22:48 theoddone33
23 * Most of network/ works
25 * Revision 1.1.1.1 2002/05/03 03:28:10 root
29 * 9 10/14/99 3:35p Jefff
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
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.
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.
45 * 5 2/04/99 6:29p Dave
46 * First full working rev of FS2 PXO support. Fixed Glide lighting
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
54 * 3 10/09/98 2:57p Dave
55 * Starting splitting up OS stuff.
57 * 2 10/07/98 10:53a Dave
60 * 1 10/07/98 10:50a Dave
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.
67 * 14 9/09/98 5:53p Dave
68 * Put in new tracker packets in API. Change cfile to be able to checksum
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
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.
79 * 11 7/15/98 10:50a Allender
80 * changed web site to get version.nfo from
82 * 10 7/15/98 10:17a Dave
83 * Made the website address lookup more robust.
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"
89 * 8 7/13/98 10:30a Lawrance
90 * add index numbers for newly localized strings
92 * 7 7/13/98 10:12a Dave
93 * Remove improperly localized strings.
95 * 6 7/10/98 5:04p Dave
96 * Fix connection speed bug on standalone server.
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.
102 * 4 7/09/98 6:07p Dave
103 * Format the text in the error dialog better.
105 * 3 7/09/98 6:01p Dave
106 * Firsts full version of PXO updater. Put in stub for displaying
109 * 2 7/09/98 4:51p Dave
110 * First revision of PXO autoupdate check system.
112 * 1 7/09/98 2:09p Dave
119 #include <winsock2.h>
121 #include "multi_update.h"
123 #include "gamesequence.h"
124 #include "osregistry.h"
127 #include "inetgetfile.h"
130 // -------------------------------------------------------------------------------------------------------------------
131 // MULTI UPDATE DEFINES/VARS
135 InetGetFile *Multi_update_get = NULL;
137 // set this to be true so that game_shutdown() will fire up the launcher, then post a quit game event
138 int Multi_update_fireup_launcher_on_exit = 0;
140 // error code string for convenient reporting
141 char Multi_update_error_string[512];
143 // -------------------------------------------------------------------------------------------------------------------
144 // MULTI UPDATE FUNCTIONS
147 // initialize the http xfer of the version info file, return 1 on success
148 int multi_update_http_init()
150 char url_file[512] = "";
151 char local_file[512] = "";
154 SDL_strlcpy(url_file, VERSION_URL, SDL_arraysize(url_file));
157 SDL_snprintf(local_file, SDL_arraysize(local_file), "%s%s%s", Cfile_root_dir, DIR_SEPARATOR_STR, VERSION_LOC_FNAME);
160 Multi_update_get = new InetGetFile(url_file, local_file);
161 if(Multi_update_get == NULL){
163 SDL_strlcpy(Multi_update_error_string, XSTR("Could not get data from website", 977), SDL_arraysize(Multi_update_error_string));
171 // do frame for the popup. returns 0 if not done yet, 1 if succeeded, 2 on error
172 int multi_update_http_do()
175 if(Multi_update_get == NULL){
177 SDL_strlcpy(Multi_update_error_string, XSTR("Could not get data from website", 977), SDL_arraysize(Multi_update_error_string));
183 if(Multi_update_get->IsFileError()){
184 delete Multi_update_get;
185 Multi_update_get = NULL;
188 SDL_strlcpy(Multi_update_error_string, XSTR("Could not get data from website", 977), SDL_arraysize(Multi_update_error_string));
194 if(Multi_update_get->IsFileReceived()){
195 delete Multi_update_get;
196 Multi_update_get = NULL;
200 // connecting, receiving
201 if(Multi_update_get->IsConnecting() || Multi_update_get->IsReceiving()){
208 // close down the http xfer
209 void multi_update_http_close()
213 // error verifying, prompt the user for some action
214 int multi_update_error_verifying()
218 memset(out_str, 0, 512);
219 SDL_snprintf(out_str, SDL_arraysize(out_str), "(%s)\n\n%s", Multi_update_error_string,
220 XSTR("There was an error verifying your version of Freespace, if you continue, you will not necessarily be up to date", 978));
222 switch(popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON, 2, XSTR("&Go back", 1524), XSTR("&Continue", 1525), out_str)){
223 // continue on in freespace like nothing happened
226 return MULTI_UPDATE_CONTINUE;
228 // go back to the main menu
230 return MULTI_UPDATE_MAIN_MENU;
234 // check to see if the version of FS on this machine is not recent. run in a popup
235 // if the versions don't check out, bail to the launcher
236 // returns 0 if freespace should continue, 1 if freespace should go back to the main menu,
237 // and 2 if the "shutdown" event was posted
238 int multi_update_gobaby()
242 int my_code = MULTI_UPDATE_MAIN_MENU;
245 if ( os_config_read_uint("PXO", "SkipVerify", 0) ) {
246 return MULTI_UPDATE_CONTINUE;
249 memset(Multi_update_error_string, 0, 512);
251 // initialize the http connection
252 if(!multi_update_http_init()){
253 return multi_update_error_verifying();
257 extern char Multi_options_proxy[512];
258 extern ushort Multi_options_proxy_port;
259 if(strlen(Multi_options_proxy) > 0){
260 SDL_snprintf(msg, SDL_arraysize(msg), "%s (%s : %d)", XSTR("Verifying Freespace Version",981), Multi_options_proxy, Multi_options_proxy_port);
262 SDL_strlcpy(msg, XSTR("Verifying Freespace Version",981), SDL_arraysize(msg));
264 ret_code = popup_till_condition(multi_update_http_do, XSTR("Cancel",948), msg);
266 // determine what to do now
270 // compare the versions
271 switch(version_compare(VERSION_LOC_FNAME, NULL, NULL, NULL, NULL, NULL, NULL)){
274 my_code = multi_update_error_verifying();
277 // earlier version - need to update
279 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))){
280 // update later (go back to main hall for now
283 my_code = MULTI_UPDATE_MAIN_MENU;
287 // set things up so that the launcher is launched when Freespace is done closing
288 Multi_update_fireup_launcher_on_exit = 1;
289 gameseq_post_event(GS_EVENT_QUIT_GAME);
291 my_code = MULTI_UPDATE_SHUTTING_DOWN;
295 // same version or higher
298 my_code = MULTI_UPDATE_CONTINUE;
303 // error of some kind (should probably notify the user or something)
305 my_code = multi_update_error_verifying();
308 // this should never happen, but if it does, go back to the main menu
310 my_code = multi_update_error_verifying();
315 multi_update_http_close();