src/network/network_client.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9911 0b8b245a2391
child 7556 de5c6eb5465d
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
    19 #include "../window.h"
    19 #include "../window.h"
    20 #include "../console.h"
    20 #include "../console.h"
    21 #include "../variables.h"
    21 #include "../variables.h"
    22 #include "../ai/ai.h"
    22 #include "../ai/ai.h"
    23 #include "../helpers.hpp"
    23 #include "../helpers.hpp"
       
    24 #include "../fileio.h"
    24 
    25 
    25 // This file handles all the client-commands
    26 // This file handles all the client-commands
    26 
    27 
    27 
    28 
    28 // So we don't make too much typos ;)
    29 // So we don't make too much typos ;)
   267 // **********
   268 // **********
   268 // Receiving functions
   269 // Receiving functions
   269 //   DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
   270 //   DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
   270 // **********
   271 // **********
   271 
   272 
   272 extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm);
   273 extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm, Subdirectory subdir);
   273 
   274 
   274 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FULL)
   275 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FULL)
   275 {
   276 {
   276 	// We try to join a server which is full
   277 	// We try to join a server which is full
   277 	_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_FULL;
   278 	_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_FULL;
   487 	return NETWORK_RECV_STATUS_OKAY;
   488 	return NETWORK_RECV_STATUS_OKAY;
   488 }
   489 }
   489 
   490 
   490 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
   491 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
   491 {
   492 {
   492 	static char filename[256];
       
   493 	static FILE *file_pointer;
   493 	static FILE *file_pointer;
   494 
   494 
   495 	byte maptype;
   495 	byte maptype;
   496 
   496 
   497 	maptype = p->Recv_uint8();
   497 	maptype = p->Recv_uint8();
   498 
   498 
   499 	if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
   499 	if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
   500 
   500 
   501 	// First packet, init some stuff
   501 	// First packet, init some stuff
   502 	if (maptype == MAP_PACKET_START) {
   502 	if (maptype == MAP_PACKET_START) {
   503 		// The name for the temp-map
   503 		file_pointer = FioFOpenFile("network_client.tmp", "wb", AUTOSAVE_DIR);;
   504 		snprintf(filename, lengthof(filename), "%s%snetwork_client.tmp",  _paths.autosave_dir, PATHSEP);
       
   505 
       
   506 		file_pointer = fopen(filename, "wb");
       
   507 		if (file_pointer == NULL) {
   504 		if (file_pointer == NULL) {
   508 			_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
   505 			_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
   509 			return NETWORK_RECV_STATUS_SAVEGAME;
   506 			return NETWORK_RECV_STATUS_SAVEGAME;
   510 		}
   507 		}
   511 
   508 
   543 
   540 
   544 		_network_join_status = NETWORK_JOIN_STATUS_PROCESSING;
   541 		_network_join_status = NETWORK_JOIN_STATUS_PROCESSING;
   545 		InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
   542 		InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
   546 
   543 
   547 		/* The map is done downloading, load it */
   544 		/* The map is done downloading, load it */
   548 		if (!SafeSaveOrLoad(filename, SL_LOAD, GM_NORMAL)) {
   545 		if (!SafeSaveOrLoad("network_client.tmp", SL_LOAD, GM_NORMAL, AUTOSAVE_DIR)) {
   549 			DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
   546 			DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
   550 			_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
   547 			_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
   551 			return NETWORK_RECV_STATUS_SAVEGAME;
   548 			return NETWORK_RECV_STATUS_SAVEGAME;
   552 		}
   549 		}
   553 		/* If the savegame has successfully loaded, ALL windows have been removed,
   550 		/* If the savegame has successfully loaded, ALL windows have been removed,