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