]> icculus.org git repositories - taylor/freespace2.git/blob - src/network/multi_endgame.cpp
Initial revision
[taylor/freespace2.git] / src / network / multi_endgame.cpp
1 /*
2  * $Logfile: /Freespace2/code/Network/multi_endgame.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  * 10    8/22/99 1:55p Dave
13  * Cleaned up host/team-captain leaving code.
14  * 
15  * 9     8/22/99 1:19p Dave
16  * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
17  * which d3d cards are detected.
18  * 
19  * 8     4/08/99 1:05p Dave
20  * Fixed some leave game packet problems. Updated builtin mission list for
21  * multiplayer.
22  * 
23  * 7     3/24/99 4:05p Dave
24  * Put in support for assigning the player to a specific squadron with a
25  * specific logo. Preliminary work for doing pos/orient checksumming in
26  * multiplayer to reduce bandwidth.
27  * 
28  * 6     11/19/98 4:57p Dave
29  * Ignore PXO option if IPX is selected.
30  * 
31  * 5     11/19/98 4:19p Dave
32  * Put IPX sockets back in psnet. Consolidated all multiplayer config
33  * files into one.
34  * 
35  * 4     11/19/98 8:03a Dave
36  * Full support for D3-style reliable sockets. Revamped packet lag/loss
37  * system, made it receiver side and at the lowest possible level.
38  * 
39  * 3     11/05/98 5:55p Dave
40  * Big pass at reducing #includes
41  * 
42  * 2     10/07/98 10:53a Dave
43  * Initial checkin.
44  * 
45  * 1     10/07/98 10:50a Dave
46  * 
47  * 36    9/17/98 3:08p Dave
48  * PXO to non-pxo game warning popup. Player icon stuff in create and join
49  * game screens. Upped server count refresh time in PXO to 35 secs (from
50  * 20).
51  * 
52  * 35    9/15/98 7:24p Dave
53  * Minor UI changes. Localized bunch of new text.
54  * 
55  * 34    9/14/98 3:40p Allender
56  * better error checking for invalid number of waves for player wings in a
57  * multiplayer game.  Better popup message in FreeSpace side.
58  * 
59  * 33    9/11/98 5:53p Dave
60  * Final revisions to kick system changes.
61  * 
62  * 32    9/11/98 5:08p Dave
63  * More tweaks to kick notification system.
64  * 
65  * 31    9/11/98 4:14p Dave
66  * Fixed file checksumming of < file_size. Put in more verbose kicking and
67  * PXO stats store reporting.
68  * 
69  * 30    8/07/98 10:15a Allender
70  * changed the way the endgame sequencing timer works so that timer wrap
71  * doesn't hurt.  Also use the obj_set_flags for the COULD_BE_PLAYER flag
72  * 
73  * 29    7/24/98 9:27a Dave
74  * Tidied up endgame sequencing by removing several old flags and
75  * standardizing _all_ endgame stuff with a single function call.
76  * 
77  * 28    7/13/98 5:34p Lawrance
78  * index a localized string in multi_endgame.cpp
79  * 
80  * 27    7/13/98 5:19p Dave
81  * 
82  * 26    6/30/98 4:53p Allender
83  * fixed endgame problems where standalone wasn't properly dropping
84  * everyone out of a game.  Be sure that timestamp for endgame processing
85  * gets reset
86  * 
87  * 25    6/13/98 9:32p Mike
88  * Kill last character in file which caused "Find in Files" to report the
89  * file as "not a text file."
90  * 
91  * 24    6/13/98 6:01p Hoffoss
92  * Externalized all new (or forgot to be added) strings to all the code.
93  * 
94  * 23    6/13/98 3:18p Hoffoss
95  * NOX()ed out a bunch of strings that shouldn't be translated.
96  * 
97  * 22    5/24/98 8:15p Dave
98  * Tweaked pxo some more. 
99  * 
100  * 21    5/21/98 10:09a Dave
101  * Enable DNS checking for PXO and both trackers.
102  * Fixed problem with leaving the mission from the pause state. Fixed
103  * build errors in multimsgs.cpp
104  * 
105  * 20    5/20/98 9:01p Allender
106  * change RELEASE to NDEBUG.  Fix reentryancy problem in process_endgame
107  * for multiplayer
108  * 
109  * 19    5/17/98 11:54p Allender
110  * only clear flying controls when in mission
111  * 
112  * 18    5/17/98 11:34p Allender
113  * deal with resetting player controls better
114  * 
115  * 17    5/17/98 6:32p Dave
116  * Make sure clients/servers aren't kicked out of the debriefing when team
117  * captains leave a game. Fixed chatbox off-by-one error. Fixed image
118  * xfer/pilot info popup stuff.
119  * 
120  * 16    5/15/98 5:15p Dave
121  * Fix a standalone resetting bug.Tweaked PXO interface. Display captaincy
122  * status for team vs. team. Put in asserts to check for invalid team vs.
123  * team situations.
124  * 
125  * 15    5/15/98 12:09a Dave
126  * New tracker api code. New game tracker code. Finished up first run of
127  * the PXO screen. Fixed a few game server list exceptions.
128  * 
129  * 14    5/14/98 12:40a Dave
130  * Still more additions to the PXO screen. Updated tracker code.
131  * 
132  * 13    5/09/98 7:16p Dave
133  * Put in CD checking. Put in standalone host password. Made pilot into
134  * popup scrollable.
135  * 
136  * 12    5/08/98 5:05p Dave
137  * Go to the join game screen when quitting multiplayer. Fixed mission
138  * text chat bugs. Put mission type symbols on the create game list.
139  * Started updating standalone gui controls.
140  * 
141  * 11    5/07/98 6:26p Dave
142  * Fix strange boundary conditions which arise when players die/respawn
143  * while the game is being ended. Spiff up the chatbox doskey thing a bit.
144  * 
145  * 10    5/07/98 3:29p Jim
146  * Make sure standalone doesn't display a popup when ending a game.
147  * 
148  * 9     5/05/98 5:02p Dave
149  * Fix end-of-campaign sequencing to work right. Make all individual
150  * missions of a campaign replayable.
151  * 
152  * 8     5/04/98 10:39p Dave
153  * Put in endgame sequencing.  Need to check campaign situations.
154  * Realigned ship info on team select screen.
155  * 
156  * 7     5/04/98 1:43p Dave
157  * Fixed up a standalone resetting problem. Fixed multiplayer stats
158  * collection for clients. Make sure all multiplayer ui screens have the
159  * correct palette at all times.
160  * 
161  * 6     5/03/98 7:04p Dave
162  * Make team vs. team work mores smoothly with standalone. Change how host
163  * interacts with standalone for picking missions. Put in a time limit for
164  * ingame join ship select. Fix ingame join ship select screen for Vasudan
165  * ship icons.
166  * 
167  * 5     4/30/98 5:12p Dave
168  * Fixed game polling code for joining clients. Reworked some file xfer
169  * stuff.
170  * 
171  * 4     4/30/98 12:13a Allender
172  * reset control info and afterburner when entering the quit game code.
173  * Prevents odd things from happening while the popup is up.
174  * 
175  * 3     4/28/98 5:10p Dave
176  * Fixed multi_quit_game() client side sequencing problem. Turn off
177  * afterburners when ending multiplayer mission. Begin integration of mt
178  * API from Kevin Bentley.
179  * 
180  * 2     4/23/98 1:28a Dave
181  * Seemingly nailed the current_primary_bank and current_secondary_bank -1
182  * problem. Made sure non-critical button presses are _never_ sent to the
183  * server.
184  * 
185  * 1     4/22/98 5:50p Dave
186  *  
187  * 
188  * $NoKeywords: $
189  */
190
191 // #include <windows.h>
192 #include "multi.h"
193 #include "popup.h"
194 #include "object.h"
195 #include "freespace.h"
196 #include "gamesequence.h"
197 #include "chatbox.h"
198 #include "popupdead.h"
199 #include "multi_endgame.h"
200 #include "multimsgs.h"
201 #include "multiui.h"
202 #include "multiutil.h"
203 #include "multi_pmsg.h"
204
205
206 // ----------------------------------------------------------------------------------------------------------
207 // Put all functions/data related to leaving a netgame, handling players leaving, handling the server leaving,
208 // and notifying the user of all of these actions, here.
209 //
210
211
212 // ----------------------------------------------------------------------------------------------------------
213 // MULTI ENDGAME DEFINES/VARS
214 //
215
216
217 // set when the server/client has ended the game on some notification or error and is waiting for clients to leave
218 #define MULTI_ENDGAME_SERVER_WAIT                               5.0f
219 int Multi_endgame_server_waiting = 0;
220 float Multi_endgame_server_wait_stamp = -1.0f;
221 int Multi_endgame_client_waiting = 0;
222
223 // error/notification codes (taken from parameters to multi_quit_game(...)
224 int Multi_endgame_notify_code;
225 int Multi_endgame_error_code;
226 int Multi_endgame_wsa_error;
227
228 // for reentrancy problems on standalone
229 int Multi_endgame_processing;
230
231 // ----------------------------------------------------------------------------------------------------------
232 // MULTI ENDGAME FORWARD DECLARATIONS
233 //
234
235 // called when a given netgame is about to end completely
236 void multi_endgame_cleanup();
237
238 // throw up a popup with the given notification code and optional winsock code
239 void multi_endgame_popup(int notify_code,int error_code,int wsa_error = -1);
240
241 // called when server is waiting for clients to disconnect
242 int multi_endgame_server_ok_to_leave();
243
244 // check to see if we need to be warping out (strange transition possibilities)
245 void multi_endgame_check_for_warpout();
246
247
248 // ----------------------------------------------------------------------------------------------------------
249 // MULTI ENDGAME FUNCTIONS
250 //
251
252 // initialize the endgame processor (call when joining/starting a new netgame)
253 void multi_endgame_init()
254 {
255         // set this so that the server/client knows he hasn't tried to end the game
256         Multi_endgame_server_waiting = 0;       
257         Multi_endgame_client_waiting = 0;
258
259         // reset the timestamp used when server is waiting for all other clients to leave.
260         Multi_endgame_server_wait_stamp = -1.0f;
261
262         // initialiaze all endgame notify and error codes
263         Multi_endgame_notify_code = -1;
264         Multi_endgame_error_code = -1;
265         Multi_endgame_wsa_error = -1;
266
267         // for reentrancy problems in to endgame_process
268         Multi_endgame_processing = 0;
269 }
270
271 // process all endgame related events
272 void multi_endgame_process()
273 {
274         if ( Multi_endgame_processing )
275                 return;
276
277         Multi_endgame_processing = 1;
278
279         // check to see if we need to be warping out (strange transition possibilities)
280         multi_endgame_check_for_warpout();
281         
282         // if we're the server of the game
283         if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
284                 // if we're not waiting for clients to leave, do nothing
285                 if(!Multi_endgame_server_waiting){
286                         Multi_endgame_processing = 0;
287                         return;
288                 }
289
290                 // if a popup is already active, do nothing             
291                 if(popup_active()){
292                         Multi_endgame_processing = 0;
293                         return;
294                 }
295
296                 // otherwise popup until things are hunky-dory
297                 if(!multi_endgame_server_ok_to_leave()){
298                         if(Game_mode & GM_STANDALONE_SERVER){
299                                 while(!multi_endgame_server_ok_to_leave()){
300                                         // run networking, etc.
301                                         game_set_frametime(-1);
302                                         game_do_state_common(gameseq_get_state());
303                                 }
304                         } else {
305                                 popup_till_condition( multi_endgame_server_ok_to_leave , XSTR("&Cancel",645), XSTR("Waiting for clients to disconnect",646));           
306                         }
307                 }
308
309                 // mark myself as not waiting and get the hell out              
310                 multi_endgame_cleanup();        
311         } else {
312                 // if we're not waiting to leave the game, do nothing
313                 if(!Multi_endgame_client_waiting){
314                         Multi_endgame_processing = 0;
315                         return;
316                 }
317
318                 // otherwise, check to see if there is a popup active
319                 if(popup_active()){
320                         Multi_endgame_processing = 0;
321                         return;
322                 }
323
324                 // if not, then we are good to leave            
325                 multi_endgame_cleanup();
326         }
327
328         Multi_endgame_processing = 0;
329 }
330
331 // if the game has been flagged as ended (ie, its going to be reset)
332 int multi_endgame_ending()
333 {
334         return (Multi_endgame_client_waiting || Multi_endgame_server_waiting);
335 }
336
337 // reentrancy check
338 int Multi_quit_game = 0;
339 // general quit function, with optional notification, error, and winsock error codes
340 int multi_quit_game(int prompt, int notify_code, int err_code, int wsa_error)
341 {
342         int ret_val,quit_already;
343
344         // check for reentrancy
345         if(Multi_quit_game){
346                 return 0;
347         }
348
349         // if we're not connected or have not net-player
350         if((Net_player == NULL) || !(Net_player->flags & NETINFO_FLAG_CONNECTED)){
351                 return 1;
352         }
353
354         // reentrancy
355         Multi_quit_game = 1;
356
357         quit_already = 0;
358
359         // reset my control info so that I don't continually do whacky stuff.  This is ugly
360         //player_control_reset_ci( &Player->ci );
361         if ( Game_mode & GM_IN_MISSION ) {
362                 memset(&Player->ci, 0, sizeof(Player->ci) );
363                 Player->ci.afterburner_stop = 1;
364                 physics_read_flying_controls( &Player_obj->orient, &Player_obj->phys_info, &(Player->ci), flFrametime);
365         }
366
367         // CASE 1 - response to a user request
368         // if there is no associated notification or error code, don't override the prompt argument
369         if((err_code == -1) && (notify_code == -1)){
370                 // if we're the server and we're already waiting for clients to leave, don't do anything
371                 if((Net_player->flags & NETINFO_FLAG_AM_MASTER) && Multi_endgame_server_waiting){
372                         Multi_quit_game = 0;
373                         return 0;
374                 }
375
376                 // if we're the client and we're already waiting to leave, don't do anythin
377                 if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER) && Multi_endgame_client_waiting){
378                         Multi_quit_game = 0;
379                         return 0;
380                 }
381
382                 // see if we should be prompting the host for confirmation
383                 if((prompt==PROMPT_HOST || prompt==PROMPT_ALL) && (Net_player->flags & NETINFO_FLAG_GAME_HOST)){
384                         int p_flags;
385
386                         p_flags = PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON | PF_BODY_BIG;
387                         if ( Game_mode & GM_IN_MISSION )
388                                 p_flags |= PF_RUN_STATE;
389
390                         ret_val = popup(p_flags,2,POPUP_CANCEL,POPUP_OK,XSTR("Warning - quitting will end the game for all players!",647));
391
392                         // check for host cancel
393                         if((ret_val == 0) || (ret_val == -1)){
394                                 Multi_quit_game = 0;
395                                 return 0;
396                         }
397
398                         // set this so that under certain circumstances, we don't call the popup below us as well
399                         quit_already = 1;
400                 }
401
402                 // see if we should be prompting the client for confirmation
403                 if((prompt==PROMPT_CLIENT || prompt==PROMPT_ALL) && !quit_already){
404                         ret_val = popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON | PF_BODY_BIG,2,POPUP_NO,POPUP_YES,XSTR("Are you sure you want to quit?",648));
405
406                         // check for host cancel
407                         if((ret_val == 0) || (ret_val == -1)){
408                                 Multi_quit_game = 0;
409                                 return 0;
410                         }
411                         quit_already = 1;
412                 }
413
414                 // if i'm the server of the game, tell all clients that i'm leaving, then wait
415                 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
416                         send_netgame_end_error_packet(MULTI_END_NOTIFY_SERVER_LEFT,MULTI_END_ERROR_NONE);
417
418                         // set the waiting flag and the waiting timestamp
419                         Multi_endgame_server_waiting = 1;
420                         Multi_endgame_server_wait_stamp = MULTI_ENDGAME_SERVER_WAIT;
421                 }
422                 // if i'm the client, quit now
423                 else {
424                         multi_endgame_cleanup();
425                 }
426         }
427         // CASE 2 - response to an error code or packet from the server
428         // this is the case where we're being forced to quit the game because of some error or other notification
429         else {                          
430                 // if i'm the server, send a packet to the clients telling them that I'm leaving and why
431                 if((Net_player->flags & NETINFO_FLAG_AM_MASTER) && !Multi_endgame_server_waiting){
432                         // if we're in the debrief state, mark down that the server has left the game
433                         if(((gameseq_get_state() == GS_STATE_DEBRIEF) || (gameseq_get_state() == GS_STATE_MULTI_DOGFIGHT_DEBRIEF)) && !(Game_mode & GM_STANDALONE_SERVER)){
434                                 multi_debrief_server_left();
435
436                                 // add a message to the chatbox
437                                 multi_display_chat_msg(XSTR("<Team captains have left>",649),0,0);                              
438                                 
439                                 // set ourselves to be "not quitting"
440                                 Multi_quit_game = 0;
441
442                                 // tell the users, the game has ended
443                                 send_netgame_end_error_packet(notify_code,err_code);                            
444                                 return 0;
445                         }
446
447                         send_netgame_end_error_packet(notify_code,err_code);                    
448
449                         // store the globals 
450                         Multi_endgame_notify_code = notify_code;
451                         Multi_endgame_error_code = err_code;
452                         Multi_endgame_wsa_error = wsa_error;
453
454                         // by setting this, multi_endgame_process() will know to check and see if it is ok for us to leave
455                         Multi_endgame_server_waiting = 1;                               
456                         Multi_endgame_server_wait_stamp = MULTI_ENDGAME_SERVER_WAIT;
457                 }
458                 // if i'm the client, set the error codes and leave the game now
459                 else if(!Multi_endgame_client_waiting){
460                         // if we're in the debrief state, mark down that the server has left the game
461                         if((gameseq_get_state() == GS_STATE_DEBRIEF) || (gameseq_get_state() == GS_STATE_MULTI_DOGFIGHT_DEBRIEF)){
462                                 multi_debrief_server_left();
463
464                                 // add a message to the chatbox
465                                 multi_display_chat_msg(XSTR("<The server has ended the game>",650),0,0);
466
467                                 // shut our reliable socket to the server down
468                                 psnet_rel_close_socket(&Net_player->reliable_socket);
469                                 Net_player->reliable_socket = INVALID_SOCKET;
470
471                                 // remove our do-notworking flag
472                                 Net_player->flags &= ~(NETINFO_FLAG_DO_NETWORKING);
473                                 
474                                 Multi_quit_game = 0;
475                                 return 0;
476                         }
477
478                         Multi_endgame_notify_code = notify_code;
479                         Multi_endgame_error_code = err_code;
480                         Multi_endgame_wsa_error = wsa_error;
481
482                         // by setting this, multi_endgame_process() will know to check and see if it is ok for us to leave
483                         Multi_endgame_client_waiting = 1;                       
484                 }
485         }               
486
487         // unset the reentrancy flag
488         Multi_quit_game = 0;
489
490         return 1;
491 }
492
493
494 // ----------------------------------------------------------------------------------------------------------
495 // MULTI ENDGAME FORWARD DEFINITIONS
496 //
497
498 // called when a given netgame is about to end completely
499 void multi_endgame_cleanup()
500 {
501         int idx;
502
503         send_leave_game_packet();                       
504
505         // flush all outgoing io, force all packets through
506         multi_io_send_buffered_packets();
507                 
508         // mark myself as disconnected
509         if(!(Game_mode & GM_STANDALONE_SERVER)){
510                 Net_player->flags &= ~(NETINFO_FLAG_CONNECTED|NETINFO_FLAG_DO_NETWORKING);
511         }
512                 
513         // this is a semi-hack so that if we're the master and we're quitting, we don't get an assert
514         if((Net_player->flags & NETINFO_FLAG_AM_MASTER) && (Player_obj != NULL)){
515                 Player_obj->flags &= ~(OF_PLAYER_SHIP);
516                 obj_set_flags( Player_obj, Player_obj->flags | OF_COULD_BE_PLAYER );
517         }
518         
519         // shut my socket down (will also let the server know i've received any notifications/error from him)
520         // psnet_rel_close_socket( &(Net_player->reliable_socket) );
521
522         // 11/18/98 - DB, changed the above to kill all sockets. Its the safest thing to do
523         for(idx=0; idx<MAX_PLAYERS; idx++){
524                 psnet_rel_close_socket(&Net_players[idx].reliable_socket);
525                 Net_players[idx].reliable_socket = INVALID_SOCKET;
526         }
527
528         // set the game quitting flag in our local netgame info - this will _insure_ that even if we miss a packet or
529         // there is some sequencing error, the next time through the multi_do_frame() loop, the game will be ended
530         // Netgame.flags |= (NG_FLAG_QUITTING | NG_FLAG_ENDED);
531
532         // close all open SPX/TCP reliable sockets
533         if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
534                 int idx;
535                 // do it for all players, since we're leaving anyway.
536                 for(idx=0;idx<MAX_PLAYERS;idx++){
537                         // 6/25/98 -- MWA delete all players from the game
538
539                         if ( &Net_players[idx] != Net_player ) {
540                                 delete_player( idx );
541                         }                       
542                 }
543         }       
544
545         // if we're currently in the pause state, pop back into gameplay first
546         if(gameseq_get_state() == GS_STATE_MULTI_PAUSED){
547                 gameseq_pop_state();
548         }
549
550         if(Game_mode & GM_STANDALONE_SERVER){
551                 // multi_standalone_quit_game();                
552                 multi_standalone_reset_all();
553         } else {                
554                 Player->flags |= PLAYER_FLAGS_IS_MULTI;         
555
556                 // if we're in Parallax Online mode, log back in there  
557                 gameseq_post_event(GS_EVENT_MULTI_JOIN_GAME);           
558
559                 // if we have an error code, bring up the discon popup                                          
560                 if((Multi_endgame_notify_code != -1) || (Multi_endgame_error_code != -1) && !(Game_mode & GM_STANDALONE_SERVER)){
561                         multi_endgame_popup(Multi_endgame_notify_code,Multi_endgame_error_code,Multi_endgame_wsa_error);                        
562                 }               
563         }       
564
565         /*
566         extern CFILE *obj_stream;
567         if(obj_stream != NULL){
568                 cfclose(obj_stream);
569                 obj_stream = NULL;
570         }
571         */      
572
573         // unload the multiplayer common interface palette
574         multi_common_unload_palette();
575         
576         // reinitialize endgame stuff
577         // multi_endgame_init();
578 }
579
580 // throw up a popup with the given notification code and optional winsock code
581 void multi_endgame_popup(int notify_code,int error_code,int wsa_error)
582 {
583         char err_msg[255];
584         int flags = PF_USE_AFFIRMATIVE_ICON;    
585
586         // if there is a popup already active, just kill it
587         if(popup_active()){
588                 // if there is already a popup active, kill it
589                 popup_kill_any_active();
590
591                 Int3();
592         } else {
593                 // if there is a winsock error code, stick it on the end of the text
594                 if(wsa_error != -1){            
595                         sprintf(err_msg,NOX("WSAERROR : %d\n\n"),wsa_error);
596                         flags |= PF_TITLE_RED;
597                 } else {
598                         strcpy(err_msg,"");
599                 }
600
601                 // setup the error message string
602                 if(notify_code != MULTI_END_NOTIFY_NONE){
603                         switch(notify_code){
604                         case MULTI_END_NOTIFY_KICKED :
605                                 strcat(err_msg,XSTR("You have been kicked",651));
606                                 break;
607                         case MULTI_END_NOTIFY_SERVER_LEFT:
608                                 strcat(err_msg,XSTR("The server has left the game",652));
609                                 break;
610                         case MULTI_END_NOTIFY_FILE_REJECTED:
611                                 strcat(err_msg,XSTR("Your mission file has been rejected by the server",653));
612                                 break;
613                         case MULTI_END_NOTIFY_EARLY_END:
614                                 strcat(err_msg,XSTR("The game has ended while you were ingame joining",654));
615                                 break;
616                         case MULTI_END_NOTIFY_INGAME_TIMEOUT:
617                                 strcat(err_msg,XSTR("You have waited too long to select a ship",655));
618                                 break;
619                         case MULTI_END_NOTIFY_KICKED_BAD_XFER:
620                                 strcat(err_msg,XSTR("You were kicked because mission file xfer failed",998));
621                                 break;
622                         case MULTI_END_NOTIFY_KICKED_CANT_XFER:
623                                 strcat(err_msg,XSTR("You were kicked because you do not have the builtin mission",999));
624                                 strcat(err_msg, NOX(" "));
625                                 strcat(err_msg, Game_current_mission_filename);
626                                 break;
627                         case MULTI_END_NOTIFY_KICKED_INGAME_ENDED:
628                                 strcat(err_msg,XSTR("You were kicked because you were ingame joining a game that has ended",1000));
629                                 break;
630                         default : 
631                                 Int3();
632                         }               
633                 } else {        
634                         switch(error_code){
635                         case MULTI_END_ERROR_CONTACT_LOST :
636                                 strcat(err_msg,XSTR("Contact with server has been lost",656));
637                                 break;
638                         case MULTI_END_ERROR_CONNECT_FAIL :
639                                 strcat(err_msg,XSTR("Failed to connect to server on reliable socket",657));
640                                 break;
641                         case MULTI_END_ERROR_LOAD_FAIL :
642                                 strcat(err_msg,XSTR("Failed to load mission file properly",658));
643                                 break;                                          
644                         case MULTI_END_ERROR_INGAME_SHIP :
645                                 strcat(err_msg,XSTR("Unable to create ingame join player ship",659));
646                                 break;
647                         case MULTI_END_ERROR_INGAME_BOGUS :
648                                 strcat(err_msg,XSTR("Recevied bogus packet data while ingame joining",660));
649                                 break;
650                         case MULTI_END_ERROR_STRANS_FAIL :
651                                 strcat(err_msg,XSTR("Server transfer failed (obsolete)",661));
652                                 break;
653                         case MULTI_END_ERROR_SHIP_ASSIGN:
654                                 strcat(err_msg,XSTR("Server encountered errors trying to assign players to ships",662));
655                                 break;
656                         case MULTI_END_ERROR_HOST_LEFT:
657                                 strcat(err_msg,XSTR("Host has left the game, aborting...",663));
658                                 break;                  
659                         case MULTI_END_ERROR_XFER_FAIL:
660                                 strcat(err_msg,XSTR("There was an error receiving the mission file!",665));
661                                 break;
662                         case MULTI_END_ERROR_WAVE_COUNT:
663                                 strcat(err_msg,XSTR("The player wings Alpha, Beta, Gamma, and Zeta must have only 1 wave.  One of these wings currently has more than 1 wave.", 987));
664                                 break;
665                         case MULTI_END_ERROR_TEAM0_EMPTY:
666                                 strcat(err_msg,XSTR("All players from team 1 have left the game", 1466));
667                                 break;
668                         case MULTI_END_ERROR_TEAM1_EMPTY:
669                                 strcat(err_msg,XSTR("All players from team 2 have left the game", 1467));
670                                 break;
671                         case MULTI_END_ERROR_CAPTAIN_LEFT:
672                                 strcat(err_msg,XSTR("Team captain(s) have left the game, aborting...",664));
673                                 break;
674                         default :
675                                 Int3();
676                         }               
677                 }
678
679                 // show the popup
680                 popup(flags,1,POPUP_OK,err_msg);        
681         }
682 }
683
684 // called when server is waiting for clients to disconnect
685 int multi_endgame_server_ok_to_leave()
686 {
687         int idx,clients_gone;
688         
689         // check to see if our client disconnect timestamp has elapsed
690         if ( Multi_endgame_server_wait_stamp > 0.0f ) {
691                 Multi_endgame_server_wait_stamp -= flFrametime;
692                 if ( Multi_endgame_server_wait_stamp <= 0.0f ) {
693                         return 1;
694                 }
695         }
696                 
697         // check to see if all clients have disconnected
698         clients_gone = 1;
699         for(idx=0;idx<MAX_PLAYERS;idx++){
700                 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
701                         clients_gone = 0;
702                         return 0;
703                 }
704         }
705
706         // all conditions passed
707         return 1;
708 }
709
710 // check to see if we need to be warping out (strange transition possibilities)
711 void multi_endgame_check_for_warpout()
712 {
713         int need_to_warpout = 0;
714
715         // if we're not in the process of warping out - do nothing
716         if(!(Net_player->flags & NETINFO_FLAG_WARPING_OUT)){
717                 return;
718         }
719
720         // determine if sufficient warping-out conditions exist
721         if((Game_mode & GM_IN_MISSION) &&                                                                               // if i'm still in the mission
722                 ((Netgame.game_state == NETGAME_STATE_ENDGAME)  ||                              // if the netgame ended
723                  (Netgame.game_state == NETGAME_STATE_DEBRIEF))                                 // if the netgame is now in the debriefing state
724           ) {
725                 need_to_warpout = 1;
726         }
727
728         // if we need to be warping out but are stuck in a dead popup, cancel it
729         if(need_to_warpout && (popupdead_is_active() || (Net_player->flags & NETINFO_FLAG_RESPAWNING) || (Net_player->flags & NETINFO_FLAG_OBSERVER)) ){                
730                 // flush all active pushed state
731                 multi_handle_state_special();
732
733                 // begin the warpout process            
734                 gameseq_post_event(GS_EVENT_DEBRIEF);
735
736                 // if text input mode is active, clear it
737                 multi_msg_text_flush();
738         }       
739 }