2010-04-22 01:13:39 +02:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
2011-12-28 05:46:36 +01:00
// Copyright (C) 2001-2005 Martiño Figueroa
2010-04-22 01:13:39 +02:00
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
# include "menu_state_connected_game.h"
# include "menu_state_join_game.h"
2010-05-09 23:23:13 +02:00
# include "menu_state_masterserver.h"
2010-04-22 01:13:39 +02:00
# include "renderer.h"
# include "sound_renderer.h"
# include "core_data.h"
# include "config.h"
# include "menu_state_new_game.h"
# include "metrics.h"
# include "network_manager.h"
# include "network_message.h"
# include "client_interface.h"
# include "conversion.h"
# include "socket.h"
# include "game.h"
# include <algorithm>
# include <time.h>
2010-10-22 09:28:55 +02:00
# include "cache_manager.h"
2011-06-26 05:38:28 +02:00
# include "string_utils.h"
2011-02-08 04:50:59 +01:00
# include "map_preview.h"
2012-04-17 21:42:53 +02:00
# include <iterator>
2013-05-01 22:56:19 +02:00
# include "compression_utils.h"
2011-06-26 05:38:28 +02:00
# include "leak_dumper.h"
2010-04-22 01:13:39 +02:00
2013-05-01 22:56:19 +02:00
using namespace Shared : : Util ;
using namespace Shared : : CompressionUtil ;
2010-04-22 01:13:39 +02:00
namespace Glest { namespace Game {
2013-11-07 03:30:23 +01:00
static const int MAX_PING_LAG_COUNT = 6 ;
2013-05-31 21:05:34 +02:00
static const double REPROMPT_DOWNLOAD_SECONDS = 7 ;
2013-06-03 21:55:34 +02:00
//static const string ITEM_MISSING = "***missing***";
2013-10-29 07:13:38 +01:00
// above replaced with Lang::getInstance().getString("DataMissing","",true)
2012-07-06 00:03:15 +02:00
const int HEADLESSSERVER_BROADCAST_SETTINGS_SECONDS = 4 ;
2012-09-20 23:59:09 +02:00
static const char * HEADLESS_SAVED_GAME_FILENAME = " lastHeadlessGameSettings.mgg " ;
2011-03-19 13:04:18 +01:00
2013-12-31 08:32:06 +01:00
const int mapPreviewTexture_X = 5 ;
const int mapPreviewTexture_Y = 185 ;
const int mapPreviewTexture_W = 150 ;
const int mapPreviewTexture_H = 150 ;
2010-04-22 01:13:39 +02:00
struct FormatString {
void operator ( ) ( string & s ) {
s = formatString ( s ) ;
}
} ;
// =====================================================
// class MenuStateConnectedGame
// =====================================================
2013-06-01 08:07:14 +02:00
MenuStateConnectedGame : : MenuStateConnectedGame ( Program * program , MainMenu * mainMenu , JoinMenu joinMenuInfo , bool openNetworkSlots ) :
MenuState ( program , mainMenu , " connected-game " ) , modHttpServerThread ( NULL )
2010-04-22 01:13:39 +02:00
{
2013-06-01 19:23:51 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-05-23 09:12:29 +02:00
2010-09-09 23:07:39 +02:00
containerName = " ClientConnectedGame " ;
2010-08-23 06:33:21 +02:00
switchSetupRequestFlagType | = ssrft_NetworkPlayerName ;
2010-08-22 10:00:05 +02:00
updateDataSynchDetailText = false ;
2013-05-23 09:12:29 +02:00
launchingNewGame = false ;
2010-08-31 08:38:27 +02:00
2014-01-03 19:19:10 +01:00
this - > zoomedMap = false ;
2013-12-31 08:32:06 +01:00
this - > render_mapPreviewTexture_X = mapPreviewTexture_X ;
this - > render_mapPreviewTexture_Y = mapPreviewTexture_Y ;
this - > render_mapPreviewTexture_W = mapPreviewTexture_W ;
this - > render_mapPreviewTexture_H = mapPreviewTexture_H ;
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = false ;
broadcastServerSettingsDelayTimer = 0 ;
lastGameSettingsReceivedCount = 0 ;
2012-06-14 01:01:10 +02:00
soundConnectionCount = 0 ;
2012-05-26 01:00:36 +02:00
this - > factionVideo = NULL ;
2012-07-15 21:45:55 +02:00
factionVideoSwitchedOffVolume = false ;
2010-10-30 05:29:29 +02:00
currentTechName_factionPreview = " " ;
currentFactionName_factionPreview = " " ;
2011-01-01 01:50:10 +01:00
ftpClientThread = NULL ;
ftpMissingDataType = ftpmsg_MissingNone ;
getMissingMapFromFTPServer = " " ;
2013-05-31 21:05:34 +02:00
getMissingMapFromFTPServerLastPrompted = 0 ;
2011-01-01 01:50:10 +01:00
getMissingMapFromFTPServerInProgress = false ;
getMissingTilesetFromFTPServer = " " ;
2013-05-31 21:05:34 +02:00
getMissingTilesetFromFTPServerLastPrompted = 0 ;
2011-01-01 01:50:10 +01:00
getMissingTilesetFromFTPServerInProgress = false ;
2011-03-10 23:00:59 +01:00
getMissingTechtreeFromFTPServer = " " ;
2013-05-31 21:05:34 +02:00
getMissingTechtreeFromFTPServerLastPrompted = 0 ;
2011-03-10 23:00:59 +01:00
getMissingTechtreeFromFTPServerInProgress = false ;
2013-05-31 21:05:34 +02:00
2013-02-15 19:25:10 +01:00
getInProgressSavedGameFromFTPServer = " " ;
getInProgressSavedGameFromFTPServerInProgress = false ;
readyToJoinInProgressGame = false ;
2011-03-19 06:11:36 +01:00
lastCheckedCRCTilesetName = " " ;
lastCheckedCRCTechtreeName = " " ;
lastCheckedCRCMapName = " " ;
2013-11-16 19:36:54 +01:00
lastCheckedCRCTilesetValue = 0 ;
lastCheckedCRCTechtreeValue = 0 ;
lastCheckedCRCMapValue = 0 ;
2010-10-30 05:29:29 +02:00
2011-04-13 03:11:23 +02:00
mapPreviewTexture = NULL ;
2010-08-31 08:38:27 +02:00
currentFactionLogo = " " ;
factionTexture = NULL ;
2010-09-17 10:26:22 +02:00
lastMissingMap = " " ;
2010-09-17 10:46:34 +02:00
lastMissingTechtree = " " ;
lastMissingTileSet = " " ;
2010-08-31 08:38:27 +02:00
2010-08-21 15:04:52 +02:00
activeInputLabel = NULL ;
2010-07-09 20:02:31 +02:00
lastNetworkSendPing = 0 ;
2010-07-09 20:49:01 +02:00
pingCount = 0 ;
2010-04-22 01:13:39 +02:00
needToSetChangedGameSettings = false ;
2010-04-29 01:59:37 +02:00
lastSetChangedGameSettings = time ( NULL ) ;
2010-06-09 00:50:37 +02:00
showFullConsole = false ;
2010-04-23 01:18:04 +02:00
2010-11-09 00:15:50 +01:00
2010-04-23 01:18:04 +02:00
currentFactionName = " " ;
currentMap = " " ;
settingsReceivedFromServer = false ;
2010-08-05 02:48:46 +02:00
initialSettingsReceivedFromServer = false ;
returnMenuInfo = joinMenuInfo ;
Lang & lang = Lang : : getInstance ( ) ;
2010-09-17 08:37:08 +02:00
mainMessageBox . registerGraphicComponent ( containerName , " mainMessageBox " ) ;
2013-10-29 07:13:38 +01:00
mainMessageBox . init ( lang . getString ( " Ok " ) ) ;
2010-09-17 08:37:08 +02:00
mainMessageBox . setEnabled ( false ) ;
2010-12-29 20:31:51 +01:00
ftpMessageBox . registerGraphicComponent ( containerName , " ftpMessageBox " ) ;
2013-10-29 07:13:38 +01:00
ftpMessageBox . init ( lang . getString ( " ModCenter " ) , lang . getString ( " GameHost " ) ) ;
ftpMessageBox . addButton ( lang . getString ( " NoDownload " ) ) ;
2010-12-29 20:31:51 +01:00
ftpMessageBox . setEnabled ( false ) ;
2010-08-05 02:48:46 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
Config & config = Config : : getInstance ( ) ;
2010-08-23 06:33:21 +02:00
defaultPlayerName = config . getString ( " NetPlayerName " , Socket : : getHostName ( ) . c_str ( ) ) ;
2010-09-26 23:34:00 +02:00
enableFactionTexturePreview = config . getBool ( " FactionPreview " , " true " ) ;
enableMapPreview = config . getBool ( " MapPreview " , " true " ) ;
2010-04-23 01:18:04 +02:00
2011-12-26 07:29:14 +01:00
enableScenarioTexturePreview = Config : : getInstance ( ) . getBool ( " EnableScenarioTexturePreview " , " true " ) ;
scenarioLogoTexture = NULL ;
previewLoadDelayTimer = time ( NULL ) ;
needToLoadTextures = true ;
this - > dirList = Config : : getInstance ( ) . getPathListForType ( ptScenarios ) ;
2013-06-13 03:37:15 +02:00
vector < string > techtreesList = Config : : getInstance ( ) . getPathListForType ( ptTechs ) ;
techTree . reset ( new TechTree ( techtreesList ) ) ;
2011-03-11 12:11:46 +01:00
vector < string > teamItems , controlItems , results , rMultiplier , playerStatuses ;
2011-10-02 04:32:20 +02:00
int labelOffset = 23 ;
2010-08-28 01:08:35 +02:00
int setupPos = 590 ;
int mapHeadPos = 330 ;
2011-10-02 04:32:20 +02:00
int mapPos = mapHeadPos - labelOffset ;
2011-11-04 01:36:07 +01:00
int aHeadPos = 240 ;
2011-10-02 04:32:20 +02:00
int aPos = aHeadPos - labelOffset ;
2010-08-28 01:08:35 +02:00
int networkHeadPos = 700 ;
2010-12-29 02:10:53 +01:00
2010-04-22 01:13:39 +02:00
//state
2010-09-09 00:37:24 +02:00
labelStatus . registerGraphicComponent ( containerName , " labelStatus " ) ;
2011-12-03 11:02:33 +01:00
labelStatus . init ( 30 , networkHeadPos ) ;
2010-04-22 01:13:39 +02:00
labelStatus . setText ( " " ) ;
2010-09-09 00:37:24 +02:00
labelInfo . registerGraphicComponent ( containerName , " labelInfo " ) ;
2010-08-28 01:08:35 +02:00
labelInfo . init ( 30 , networkHeadPos + 30 ) ;
2010-04-22 01:13:39 +02:00
labelInfo . setText ( " " ) ;
2010-08-28 01:08:35 +02:00
labelInfo . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2011-06-28 02:51:13 +02:00
labelInfo . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-12-29 02:10:53 +01:00
2011-01-09 05:49:21 +01:00
timerLabelFlash = time ( NULL ) ;
labelDataSynchInfo . registerGraphicComponent ( containerName , " labelDataSynchInfo " ) ;
labelDataSynchInfo . init ( 30 , networkHeadPos - 60 ) ;
labelDataSynchInfo . setText ( " " ) ;
labelDataSynchInfo . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2011-06-28 02:51:13 +02:00
labelDataSynchInfo . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2011-01-09 05:49:21 +01:00
2010-04-22 01:13:39 +02:00
// fog - o - war
2012-10-06 09:06:40 +02:00
int xoffset = 70 ;
2010-09-09 00:37:24 +02:00
labelFogOfWar . registerGraphicComponent ( containerName , " labelFogOfWar " ) ;
2011-11-04 01:36:07 +01:00
labelFogOfWar . init ( xoffset + 100 , aHeadPos , 130 ) ;
2013-10-29 07:13:38 +01:00
labelFogOfWar . setText ( lang . getString ( " FogOfWar " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxFogOfWar . registerGraphicComponent ( containerName , " listBoxFogOfWar " ) ;
2011-11-04 01:36:07 +01:00
listBoxFogOfWar . init ( xoffset + 100 , aPos , 130 ) ;
2013-10-29 07:13:38 +01:00
listBoxFogOfWar . pushBackItem ( lang . getString ( " Enabled " ) ) ;
listBoxFogOfWar . pushBackItem ( lang . getString ( " Explored " ) ) ;
listBoxFogOfWar . pushBackItem ( lang . getString ( " Disabled " ) ) ;
2010-04-22 01:13:39 +02:00
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ;
listBoxFogOfWar . setEditable ( false ) ;
2010-09-04 03:24:17 +02:00
2010-09-09 00:37:24 +02:00
labelAllowObservers . registerGraphicComponent ( containerName , " labelAllowObservers " ) ;
2011-11-04 01:36:07 +01:00
labelAllowObservers . init ( xoffset + 310 , aHeadPos , 80 ) ;
2013-10-29 07:13:38 +01:00
labelAllowObservers . setText ( lang . getString ( " AllowObservers " ) ) ;
2010-09-09 00:37:24 +02:00
2012-10-22 19:53:48 +02:00
checkBoxAllowObservers . registerGraphicComponent ( containerName , " checkBoxAllowObservers " ) ;
checkBoxAllowObservers . init ( xoffset + 310 , aPos ) ;
checkBoxAllowObservers . setValue ( false ) ;
checkBoxAllowObservers . setEditable ( false ) ;
2010-09-04 03:24:17 +02:00
2012-09-17 01:42:56 +02:00
for ( int i = 0 ; i < 45 ; + + i ) {
rMultiplier . push_back ( floatToStr ( 0.5f + 0.1f * i , 1 ) ) ;
}
labelFallbackCpuMultiplier . registerGraphicComponent ( containerName , " labelFallbackCpuMultiplier " ) ;
labelFallbackCpuMultiplier . init ( xoffset + 460 , aHeadPos , 80 ) ;
2013-10-29 07:13:38 +01:00
labelFallbackCpuMultiplier . setText ( lang . getString ( " FallbackCpuMultiplier " ) ) ;
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . registerGraphicComponent ( containerName , " listBoxFallbackCpuMultiplier " ) ;
listBoxFallbackCpuMultiplier . init ( xoffset + 460 , aPos , 80 ) ;
listBoxFallbackCpuMultiplier . setItems ( rMultiplier ) ;
2013-11-02 23:30:16 +01:00
listBoxFallbackCpuMultiplier . setSelectedItem ( " 1.0 " ) ;
2012-09-17 01:42:56 +02:00
2011-09-21 08:51:28 +02:00
// Allow Switch Team Mode
labelEnableSwitchTeamMode . registerGraphicComponent ( containerName , " labelEnableSwitchTeamMode " ) ;
2011-11-04 01:36:07 +01:00
labelEnableSwitchTeamMode . init ( xoffset + 310 , aHeadPos + 45 , 80 ) ;
2013-10-29 07:13:38 +01:00
labelEnableSwitchTeamMode . setText ( lang . getString ( " EnableSwitchTeamMode " ) ) ;
2011-09-21 08:51:28 +02:00
2012-10-22 19:53:48 +02:00
checkBoxEnableSwitchTeamMode . registerGraphicComponent ( containerName , " checkBoxEnableSwitchTeamMode " ) ;
checkBoxEnableSwitchTeamMode . init ( xoffset + 310 , aPos + 45 ) ;
checkBoxEnableSwitchTeamMode . setValue ( false ) ;
checkBoxEnableSwitchTeamMode . setEditable ( false ) ;
2011-09-21 08:51:28 +02:00
labelAISwitchTeamAcceptPercent . registerGraphicComponent ( containerName , " labelAISwitchTeamAcceptPercent " ) ;
2011-11-04 01:36:07 +01:00
labelAISwitchTeamAcceptPercent . init ( xoffset + 460 , aHeadPos + 45 , 80 ) ;
2013-10-29 07:13:38 +01:00
labelAISwitchTeamAcceptPercent . setText ( lang . getString ( " AISwitchTeamAcceptPercent " ) ) ;
2011-09-21 08:51:28 +02:00
listBoxAISwitchTeamAcceptPercent . registerGraphicComponent ( containerName , " listBoxAISwitchTeamAcceptPercent " ) ;
2011-11-04 01:36:07 +01:00
listBoxAISwitchTeamAcceptPercent . init ( xoffset + 460 , aPos + 45 , 80 ) ;
2011-09-21 08:51:28 +02:00
for ( int i = 0 ; i < = 100 ; i = i + 10 ) {
listBoxAISwitchTeamAcceptPercent . pushBackItem ( intToStr ( i ) ) ;
}
listBoxAISwitchTeamAcceptPercent . setSelectedItem ( intToStr ( 30 ) ) ;
2011-09-24 09:46:56 +02:00
listBoxAISwitchTeamAcceptPercent . setEditable ( false ) ;
2011-09-21 08:51:28 +02:00
2013-05-23 08:11:46 +02:00
//create
buttonCancelDownloads . registerGraphicComponent ( containerName , " buttonCancelDownloads " ) ;
buttonCancelDownloads . init ( xoffset + 620 , 180 , 150 ) ;
2013-10-29 07:13:38 +01:00
buttonCancelDownloads . setText ( lang . getString ( " CancelDownloads " ) ) ;
2013-05-23 08:11:46 +02:00
2011-12-03 09:17:49 +01:00
listBoxPlayerStatus . registerGraphicComponent ( containerName , " listBoxPlayerStatus " ) ;
2013-05-31 21:32:20 +02:00
nonAdminPlayerStatusX = xoffset + 460 ;
listBoxPlayerStatus . init ( nonAdminPlayerStatusX , 180 , 150 ) ;
2011-12-03 09:17:49 +01:00
listBoxPlayerStatus . setTextColor ( Vec3f ( 1.0f , 0.f , 0.f ) ) ;
listBoxPlayerStatus . setLighted ( true ) ;
2013-10-29 07:13:38 +01:00
playerStatuses . push_back ( lang . getString ( " PlayerStatusSetup " ) ) ;
playerStatuses . push_back ( lang . getString ( " PlayerStatusBeRightBack " ) ) ;
playerStatuses . push_back ( lang . getString ( " PlayerStatusReady " ) ) ;
2011-12-03 09:17:49 +01:00
listBoxPlayerStatus . setItems ( playerStatuses ) ;
2010-08-05 01:39:12 +02:00
// Network Frame Period
2010-08-28 01:08:35 +02:00
xoffset = 70 ;
//map listBox
// put them all in a set, to weed out duplicates (gbm & mgm with same name)
// will also ensure they are alphabetically listed (rather than how the OS provides them)
2010-09-09 00:37:24 +02:00
listBoxMap . registerGraphicComponent ( containerName , " listBoxMap " ) ;
2010-08-28 01:08:35 +02:00
listBoxMap . init ( xoffset + 100 , mapPos , 200 ) ;
listBoxMap . setEditable ( false ) ;
2010-09-09 00:37:24 +02:00
2010-09-11 08:08:50 +02:00
labelMapInfo . registerGraphicComponent ( containerName , " labelMapInfo " ) ;
2011-11-02 20:02:25 +01:00
labelMapInfo . init ( xoffset + 100 , mapPos - labelOffset - 10 , 200 , 40 ) ;
2010-09-11 08:08:50 +02:00
labelMapInfo . setText ( " ? " ) ;
2010-09-09 00:37:24 +02:00
labelMap . registerGraphicComponent ( containerName , " labelMap " ) ;
2010-08-28 01:08:35 +02:00
labelMap . init ( xoffset + 100 , mapHeadPos ) ;
2013-10-29 07:13:38 +01:00
labelMap . setText ( lang . getString ( " Map " ) ) ;
2010-08-05 01:39:12 +02:00
2010-04-22 01:13:39 +02:00
//tileset listBox
2010-09-09 00:37:24 +02:00
listBoxTileset . registerGraphicComponent ( containerName , " listBoxTileset " ) ;
2011-11-04 01:36:07 +01:00
listBoxTileset . init ( xoffset + 460 , mapPos , 150 ) ;
2010-04-22 01:13:39 +02:00
listBoxTileset . setEditable ( false ) ;
2010-09-09 00:37:24 +02:00
labelTileset . registerGraphicComponent ( containerName , " labelTileset " ) ;
2011-11-04 01:36:07 +01:00
labelTileset . init ( xoffset + 460 , mapHeadPos ) ;
2013-10-29 07:13:38 +01:00
labelTileset . setText ( lang . getString ( " Tileset " ) ) ;
2010-12-29 02:10:53 +01:00
2010-04-22 01:13:39 +02:00
//tech Tree listBox
listBoxTechTree . setEditable ( false ) ;
2010-09-09 00:37:24 +02:00
listBoxTechTree . registerGraphicComponent ( containerName , " listBoxTechTree " ) ;
2013-05-23 08:11:46 +02:00
listBoxTechTree . init ( xoffset + 620 , mapPos , 150 ) ;
2010-09-09 00:37:24 +02:00
labelTechTree . registerGraphicComponent ( containerName , " labelTechTree " ) ;
2013-05-23 08:11:46 +02:00
labelTechTree . init ( xoffset + 620 , mapHeadPos ) ;
2013-10-29 07:13:38 +01:00
labelTechTree . setText ( lang . getString ( " TechTree " ) ) ;
2010-12-29 02:10:53 +01:00
2013-06-19 03:03:51 +02:00
labelAllowNativeLanguageTechtree . registerGraphicComponent ( containerName , " labelAllowNativeLanguageTechtree " ) ;
labelAllowNativeLanguageTechtree . init ( xoffset + 620 , mapHeadPos - 45 ) ;
2013-10-29 07:13:38 +01:00
labelAllowNativeLanguageTechtree . setText ( lang . getString ( " AllowNativeLanguageTechtree " ) ) ;
2013-06-19 03:03:51 +02:00
checkBoxAllowNativeLanguageTechtree . registerGraphicComponent ( containerName , " checkBoxAllowNativeLanguageTechtree " ) ;
checkBoxAllowNativeLanguageTechtree . init ( xoffset + 620 , mapHeadPos - 65 ) ;
checkBoxAllowNativeLanguageTechtree . setValue ( false ) ;
checkBoxAllowNativeLanguageTechtree . setEditable ( false ) ;
checkBoxAllowNativeLanguageTechtree . setEnabled ( false ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-06-01 19:23:51 +02:00
2013-10-27 17:13:27 +01:00
xoffset = 30 ;
2010-08-28 01:08:35 +02:00
int rowHeight = 27 ;
2010-04-22 01:13:39 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2010-09-09 00:37:24 +02:00
labelPlayers [ i ] . registerGraphicComponent ( containerName , " labelPlayers " + intToStr ( i ) ) ;
2013-10-26 00:09:19 +02:00
labelPlayers [ i ] . init ( xoffset , setupPos - 30 - i * rowHeight + 2 ) ;
labelPlayers [ i ] . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelPlayers [ i ] . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-04-22 01:13:39 +02:00
labelPlayers [ i ] . setEditable ( false ) ;
2010-09-09 00:37:24 +02:00
2013-10-26 00:09:19 +02:00
labelPlayerStatus [ i ] . registerGraphicComponent ( containerName , " labelPlayerStatus " + intToStr ( i ) ) ;
2013-11-08 03:50:59 +01:00
labelPlayerStatus [ i ] . init ( xoffset + 15 , setupPos - 30 - i * rowHeight + 2 , 60 ) ;
2010-09-09 00:37:24 +02:00
labelPlayerNames [ i ] . registerGraphicComponent ( containerName , " labelPlayerNames " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
labelPlayerNames [ i ] . init ( xoffset + 30 , setupPos - 30 - i * rowHeight ) ;
2010-08-21 15:04:52 +02:00
2010-09-09 00:37:24 +02:00
listBoxControls [ i ] . registerGraphicComponent ( containerName , " listBoxControls " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
listBoxControls [ i ] . init ( xoffset + 170 , setupPos - 30 - i * rowHeight ) ;
2010-04-22 01:13:39 +02:00
listBoxControls [ i ] . setEditable ( false ) ;
2010-09-09 00:37:24 +02:00
2010-11-09 00:15:50 +01:00
listBoxRMultiplier [ i ] . registerGraphicComponent ( containerName , " listBoxRMultiplier " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
listBoxRMultiplier [ i ] . init ( xoffset + 310 , setupPos - 30 - i * rowHeight , 70 ) ;
2013-10-26 00:09:19 +02:00
listBoxRMultiplier [ i ] . setEditable ( false ) ;
2010-11-09 00:15:50 +01:00
2010-09-09 00:37:24 +02:00
listBoxFactions [ i ] . registerGraphicComponent ( containerName , " listBoxFactions " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
listBoxFactions [ i ] . init ( xoffset + 390 , setupPos - 30 - i * rowHeight , 250 ) ;
2013-10-26 00:09:19 +02:00
listBoxFactions [ i ] . setLeftControlled ( true ) ;
2010-04-22 01:13:39 +02:00
listBoxFactions [ i ] . setEditable ( false ) ;
2010-09-09 00:37:24 +02:00
listBoxTeams [ i ] . registerGraphicComponent ( containerName , " listBoxTeams " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
listBoxTeams [ i ] . init ( xoffset + 650 , setupPos - 30 - i * rowHeight , 60 ) ;
2010-04-22 01:13:39 +02:00
listBoxTeams [ i ] . setEditable ( false ) ;
2010-09-09 00:37:24 +02:00
labelNetStatus [ i ] . registerGraphicComponent ( containerName , " labelNetStatus " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
labelNetStatus [ i ] . init ( xoffset + 715 , setupPos - 30 - i * rowHeight , 60 ) ;
2011-11-15 23:28:51 +01:00
labelNetStatus [ i ] . setFont ( CoreData : : getInstance ( ) . getDisplayFontSmall ( ) ) ;
labelNetStatus [ i ] . setFont3D ( CoreData : : getInstance ( ) . getDisplayFontSmall3D ( ) ) ;
2010-09-09 00:37:24 +02:00
grabSlotButton [ i ] . registerGraphicComponent ( containerName , " grabSlotButton " + intToStr ( i ) ) ;
2013-10-27 17:13:27 +01:00
grabSlotButton [ i ] . init ( xoffset + 720 , setupPos - 30 - i * rowHeight , 30 ) ;
2010-04-29 01:59:37 +02:00
grabSlotButton [ i ] . setText ( " > " ) ;
2010-04-22 01:13:39 +02:00
}
2010-09-09 00:37:24 +02:00
labelControl . registerGraphicComponent ( containerName , " labelControl " ) ;
2013-10-27 17:13:27 +01:00
labelControl . init ( xoffset + 170 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2013-10-29 07:13:38 +01:00
labelControl . setText ( lang . getString ( " Control " ) ) ;
2010-12-29 02:10:53 +01:00
2010-11-09 00:15:50 +01:00
labelRMultiplier . registerGraphicComponent ( containerName , " labelRMultiplier " ) ;
2013-10-27 17:13:27 +01:00
labelRMultiplier . init ( xoffset + 310 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2010-12-29 02:10:53 +01:00
2010-09-09 00:37:24 +02:00
labelFaction . registerGraphicComponent ( containerName , " labelFaction " ) ;
2013-10-27 17:13:27 +01:00
labelFaction . init ( xoffset + 390 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2013-10-29 07:13:38 +01:00
labelFaction . setText ( lang . getString ( " Faction " ) ) ;
2010-12-29 02:10:53 +01:00
2010-09-09 00:37:24 +02:00
labelTeam . registerGraphicComponent ( containerName , " labelTeam " ) ;
2013-10-27 17:13:27 +01:00
labelTeam . init ( xoffset + 650 , setupPos , 60 , GraphicListBox : : defH , true ) ;
2013-10-29 07:13:38 +01:00
labelTeam . setText ( lang . getString ( " Team " ) ) ;
2010-08-06 00:27:26 +02:00
labelControl . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2011-06-28 02:51:13 +02:00
labelControl . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-08-06 00:27:26 +02:00
labelFaction . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2011-06-28 02:51:13 +02:00
labelFaction . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-08-06 00:27:26 +02:00
labelTeam . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2011-06-28 02:51:13 +02:00
labelTeam . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2010-04-22 01:13:39 +02:00
//texts
2013-10-29 07:13:38 +01:00
buttonDisconnect . setText ( lang . getString ( " Return " ) ) ;
2010-04-22 01:13:39 +02:00
2013-10-29 07:13:38 +01:00
controlItems . push_back ( lang . getString ( " Closed " ) ) ;
controlItems . push_back ( lang . getString ( " CpuEasy " ) ) ;
controlItems . push_back ( lang . getString ( " Cpu " ) ) ;
controlItems . push_back ( lang . getString ( " CpuUltra " ) ) ;
controlItems . push_back ( lang . getString ( " CpuMega " ) ) ;
controlItems . push_back ( lang . getString ( " Network " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkUnassigned " ) ) ;
controlItems . push_back ( lang . getString ( " Human " ) ) ;
2010-09-04 02:32:56 +02:00
2010-11-09 00:15:50 +01:00
2010-09-14 21:10:37 +02:00
if ( config . getBool ( " EnableNetworkCpu " , " false " ) = = true ) {
2013-10-29 07:13:38 +01:00
controlItems . push_back ( lang . getString ( " NetworkCpuEasy " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpu " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpuUltra " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpuMega " ) ) ;
2010-09-14 21:10:37 +02:00
}
2010-09-04 02:32:56 +02:00
for ( int i = 1 ; i < = GameConstants : : maxPlayers ; + + i ) {
teamItems . push_back ( intToStr ( i ) ) ;
}
for ( int i = GameConstants : : maxPlayers + 1 ; i < = GameConstants : : maxPlayers + GameConstants : : specialFactions ; + + i ) {
teamItems . push_back ( intToStr ( i ) ) ;
}
2010-04-22 01:13:39 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-03-11 12:11:46 +01:00
labelPlayerStatus [ i ] . setText ( " " ) ;
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( NULL ) ;
labelPlayerStatus [ i ] . setH ( 16 ) ;
labelPlayerStatus [ i ] . setW ( 12 ) ;
2011-03-11 12:11:46 +01:00
2013-10-27 17:13:27 +01:00
labelPlayers [ i ] . setText ( intToStr ( i + 1 ) ) ;
2010-08-21 15:04:52 +02:00
labelPlayerNames [ i ] . setText ( " " ) ;
2012-07-26 08:27:00 +02:00
labelPlayerNames [ i ] . setMaxEditWidth ( 16 ) ;
2012-07-26 17:26:59 +02:00
labelPlayerNames [ i ] . setMaxEditRenderWidth ( 135 ) ;
2010-08-21 15:04:52 +02:00
2010-04-22 01:13:39 +02:00
listBoxTeams [ i ] . setItems ( teamItems ) ;
listBoxTeams [ i ] . setSelectedItemIndex ( i ) ;
listBoxControls [ i ] . setItems ( controlItems ) ;
2010-11-09 00:15:50 +01:00
listBoxRMultiplier [ i ] . setItems ( rMultiplier ) ;
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ i ] . setSelectedItem ( " 1.0 " ) ;
2010-12-29 02:10:53 +01:00
2010-04-23 01:18:04 +02:00
labelNetStatus [ i ] . setText ( " V " ) ;
2010-04-22 01:13:39 +02:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
//init controllers
listBoxControls [ 0 ] . setSelectedItemIndex ( ctHuman ) ;
2010-08-21 15:04:52 +02:00
2011-09-24 09:46:56 +02:00
//map listBox
// put them all in a set, to weed out duplicates (gbm & mgm with same name)
// will also ensure they are alphabetically listed (rather than how the OS provides them)
2012-03-28 08:25:57 +02:00
setupMapList ( " " ) ;
2011-12-28 05:46:36 +01:00
listBoxMap . setItems ( formattedPlayerSortedMaps [ 0 ] ) ;
2011-09-24 09:46:56 +02:00
buttonPlayNow . registerGraphicComponent ( containerName , " buttonPlayNow " ) ;
2011-12-03 11:02:33 +01:00
buttonPlayNow . init ( 220 , 180 , 125 ) ;
2013-10-29 07:13:38 +01:00
buttonPlayNow . setText ( lang . getString ( " PlayNow " ) ) ;
2011-09-24 09:46:56 +02:00
buttonPlayNow . setVisible ( false ) ;
2011-12-03 11:02:33 +01:00
buttonDisconnect . registerGraphicComponent ( containerName , " buttonDisconnect " ) ;
buttonDisconnect . init ( 350 , 180 , 125 ) ;
2011-12-03 09:17:49 +01:00
buttonRestoreLastSettings . registerGraphicComponent ( containerName , " buttonRestoreLastSettings " ) ;
2011-12-03 11:02:33 +01:00
buttonRestoreLastSettings . init ( 480 , 180 , 220 ) ;
2013-10-29 07:13:38 +01:00
buttonRestoreLastSettings . setText ( lang . getString ( " ReloadLastGameSettings " ) ) ;
2011-12-03 09:17:49 +01:00
2012-06-14 01:01:10 +02:00
// write hint to console:
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " ToSwitchOffMusicPress " ) + " - \" " + configKeys . getString ( " ToggleMusic " ) + " \" " ) ;
2010-06-09 00:50:37 +02:00
chatManager . init ( & console , - 1 , true ) ;
2010-09-09 00:37:24 +02:00
GraphicComponent : : applyAllCustomProperties ( containerName ) ;
2010-09-17 10:46:34 +02:00
//tileset listBox
2011-12-28 05:46:36 +01:00
setupTilesetList ( " " ) ;
2013-06-13 03:37:15 +02:00
int initialTechSelection = setupTechList ( " " , true ) ;
2011-12-28 05:46:36 +01:00
listBoxTechTree . setSelectedItemIndex ( initialTechSelection ) ;
2011-09-24 09:46:56 +02:00
2013-10-26 00:09:19 +02:00
int scenarioX = 810 ;
int scenarioY = 140 ;
2011-12-26 07:29:14 +01:00
labelScenario . registerGraphicComponent ( containerName , " labelScenario " ) ;
2013-10-26 00:09:19 +02:00
labelScenario . init ( scenarioX , scenarioY ) ;
2013-10-29 07:13:38 +01:00
labelScenario . setText ( lang . getString ( " Scenario " ) ) ;
2011-12-26 07:29:14 +01:00
listBoxScenario . registerGraphicComponent ( containerName , " listBoxScenario " ) ;
2013-10-26 00:09:19 +02:00
listBoxScenario . init ( scenarioX , scenarioY - 30 , 190 ) ;
2011-12-26 07:29:14 +01:00
checkBoxScenario . registerGraphicComponent ( containerName , " checkBoxScenario " ) ;
2013-10-26 00:09:19 +02:00
checkBoxScenario . init ( scenarioX + 90 , scenarioY ) ;
2011-12-26 07:29:14 +01:00
checkBoxScenario . setValue ( false ) ;
//scenario listbox
vector < string > resultsScenarios ;
findDirs ( dirList , resultsScenarios ) ;
// Filter out only scenarios with no network slots
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) resultsScenarios . size ( ) ; + + i ) {
2011-12-26 07:29:14 +01:00
string scenario = resultsScenarios [ i ] ;
string file = Scenario : : getScenarioPath ( dirList , scenario ) ;
2012-03-31 10:28:42 +02:00
try {
if ( file ! = " " ) {
2013-05-21 22:28:42 +02:00
bool isTutorial = Scenario : : isGameTutorial ( file ) ;
Scenario : : loadScenarioInfo ( file , & scenarioInfo , isTutorial ) ;
2012-03-31 10:28:42 +02:00
bool isNetworkScenario = false ;
2013-11-19 07:56:09 +01:00
for ( unsigned int j = 0 ; isNetworkScenario = = false & & j < ( unsigned int ) GameConstants : : maxPlayers ; + + j ) {
2012-03-31 10:28:42 +02:00
if ( scenarioInfo . factionControls [ j ] = = ctNetwork ) {
isNetworkScenario = true ;
}
}
if ( isNetworkScenario = = true ) {
scenarioFiles . push_back ( scenario ) ;
2012-03-03 05:33:39 +01:00
}
}
2012-03-31 10:28:42 +02:00
}
catch ( const std : : exception & ex ) {
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error loading scenario [%s]: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , scenario . c_str ( ) , ex . what ( ) ) ;
2012-03-31 10:28:42 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
showMessageBox ( szBuf , " Error " , false ) ;
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error(szBuf);
2011-12-26 07:29:14 +01:00
}
}
resultsScenarios . clear ( ) ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) scenarioFiles . size ( ) ; + + i ) {
2011-12-26 07:29:14 +01:00
resultsScenarios . push_back ( formatString ( scenarioFiles [ i ] ) ) ;
}
listBoxScenario . setItems ( resultsScenarios ) ;
checkBoxScenario . setEnabled ( false ) ;
2010-12-29 02:10:53 +01:00
2011-01-06 08:17:02 +01:00
if ( config . getBool ( " EnableFTPXfer " , " true " ) = = true ) {
2010-12-29 02:10:53 +01:00
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
2010-12-29 21:28:25 +01:00
string serverUrl = clientInterface - > getServerIpAddress ( ) ;
2011-01-15 19:56:03 +01:00
int portNumber = clientInterface - > getServerFTPPort ( ) ;
2010-12-29 02:10:53 +01:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] Using FTP port #: %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , portNumber ) ;
2011-01-15 20:16:00 +01:00
2010-12-29 02:10:53 +01:00
vector < string > mapPathList = config . getPathListForType ( ptMaps ) ;
std : : pair < string , string > mapsPath ;
2011-09-01 01:10:43 +02:00
if ( mapPathList . empty ( ) = = false ) {
2010-12-29 02:10:53 +01:00
mapsPath . first = mapPathList [ 0 ] ;
}
if ( mapPathList . size ( ) > 1 ) {
mapsPath . second = mapPathList [ 1 ] ;
}
2011-01-01 01:50:10 +01:00
std : : pair < string , string > tilesetsPath ;
vector < string > tilesetsList = Config : : getInstance ( ) . getPathListForType ( ptTilesets ) ;
2011-09-01 01:10:43 +02:00
if ( tilesetsList . empty ( ) = = false ) {
2011-01-01 01:50:10 +01:00
tilesetsPath . first = tilesetsList [ 0 ] ;
if ( tilesetsList . size ( ) > 1 ) {
tilesetsPath . second = tilesetsList [ 1 ] ;
}
}
2010-12-29 02:10:53 +01:00
2011-03-10 00:09:32 +01:00
std : : pair < string , string > techtreesPath ;
2011-09-01 01:10:43 +02:00
if ( techtreesList . empty ( ) = = false ) {
2011-03-10 00:09:32 +01:00
techtreesPath . first = techtreesList [ 0 ] ;
if ( techtreesList . size ( ) > 1 ) {
techtreesPath . second = techtreesList [ 1 ] ;
}
}
2011-03-26 19:37:38 +01:00
std : : pair < string , string > scenariosPath ;
vector < string > scenariosList = Config : : getInstance ( ) . getPathListForType ( ptScenarios ) ;
2011-09-01 01:10:43 +02:00
if ( scenariosList . empty ( ) = = false ) {
2011-03-26 19:37:38 +01:00
scenariosPath . first = scenariosList [ 0 ] ;
if ( scenariosList . size ( ) > 1 ) {
scenariosPath . second = scenariosList [ 1 ] ;
}
}
2011-03-09 19:35:19 +01:00
string fileArchiveExtension = config . getString ( " FileArchiveExtension " , " " ) ;
string fileArchiveExtractCommand = config . getString ( " FileArchiveExtractCommand " , " " ) ;
string fileArchiveExtractCommandParameters = config . getString ( " FileArchiveExtractCommandParameters " , " " ) ;
2011-04-10 00:20:10 +02:00
int32 fileArchiveExtractCommandSuccessResult = config . getInt ( " FileArchiveExtractCommandSuccessResult " , " 0 " ) ;
2011-03-09 19:35:19 +01:00
2013-02-15 19:25:10 +01:00
// Get path to temp files
string tempFilePath = " temp/ " ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
tempFilePath = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + tempFilePath ;
}
else {
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
tempFilePath = userData + tempFilePath ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Temp files path [%s] \n " , tempFilePath . c_str ( ) ) ;
2011-03-10 00:09:32 +01:00
ftpClientThread = new FTPClientThread ( portNumber , serverUrl ,
2011-03-26 19:37:38 +01:00
mapsPath , tilesetsPath , techtreesPath , scenariosPath ,
2011-03-10 00:09:32 +01:00
this , fileArchiveExtension , fileArchiveExtractCommand ,
2013-02-15 19:25:10 +01:00
fileArchiveExtractCommandParameters ,
fileArchiveExtractCommandSuccessResult ,
tempFilePath ) ;
2010-12-29 02:10:53 +01:00
ftpClientThread - > start ( ) ;
}
2012-10-16 00:19:22 +02:00
// Start http meta data thread
2013-01-23 15:51:28 +01:00
static string mutexOwnerId = string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
2012-10-16 00:19:22 +02:00
modHttpServerThread = new SimpleTaskThread ( this , 0 , 200 ) ;
2013-01-23 15:51:28 +01:00
modHttpServerThread - > setUniqueID ( mutexOwnerId ) ;
2012-10-16 00:19:22 +02:00
modHttpServerThread - > start ( ) ;
2013-02-15 19:25:10 +01:00
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( clientInterface ! = NULL & & clientInterface - > getJoinGameInProgress ( ) = = true ) {
2013-06-06 16:38:55 +02:00
listBoxPlayerStatus . setVisible ( false ) ;
Lang & lang = Lang : : getInstance ( ) ;
2013-02-15 19:25:10 +01:00
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
char szMsg [ 8096 ] = " " ;
if ( lang . hasString ( " JoinPlayerToCurrentGameWelcome " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " JoinPlayerToCurrentGameWelcome " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) ) ;
2013-02-15 19:25:10 +01:00
}
else {
snprintf ( szMsg , 8096 , " Player: %s has connected to the game and would like to join. " , getHumanPlayerName ( ) . c_str ( ) ) ;
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2013-02-15 19:25:10 +01:00
}
2012-10-16 00:19:22 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-12-29 02:10:53 +01:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
}
2011-10-25 20:39:11 +02:00
void MenuStateConnectedGame : : reloadUI ( ) {
Config & config = Config : : getInstance ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
2011-11-04 00:38:43 +01:00
console . resetFonts ( ) ;
2013-10-29 07:13:38 +01:00
mainMessageBox . init ( lang . getString ( " Ok " ) ) ;
ftpMessageBox . init ( lang . getString ( " ModCenter " ) , lang . getString ( " GameHost " ) ) ;
ftpMessageBox . addButton ( lang . getString ( " NoDownload " ) ) ;
2011-10-25 20:39:11 +02:00
labelInfo . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelInfo . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
labelDataSynchInfo . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelDataSynchInfo . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
2013-10-29 07:13:38 +01:00
buttonCancelDownloads . setText ( lang . getString ( " CancelDownloads " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelFogOfWar . setText ( lang . getString ( " FogOfWar " ) ) ;
2011-10-25 20:39:11 +02:00
vector < string > fowItems ;
2013-10-29 07:13:38 +01:00
fowItems . push_back ( lang . getString ( " Enabled " ) ) ;
fowItems . push_back ( lang . getString ( " Explored " ) ) ;
fowItems . push_back ( lang . getString ( " Disabled " ) ) ;
2011-10-25 20:39:11 +02:00
listBoxFogOfWar . setItems ( fowItems ) ;
2013-10-29 07:13:38 +01:00
labelAllowObservers . setText ( lang . getString ( " AllowObservers " ) ) ;
labelFallbackCpuMultiplier . setText ( lang . getString ( " FallbackCpuMultiplier " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelEnableSwitchTeamMode . setText ( lang . getString ( " EnableSwitchTeamMode " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelAISwitchTeamAcceptPercent . setText ( lang . getString ( " AISwitchTeamAcceptPercent " ) ) ;
2011-10-25 20:39:11 +02:00
vector < string > aiswitchteamModeItems ;
for ( int i = 0 ; i < = 100 ; i = i + 10 ) {
aiswitchteamModeItems . push_back ( intToStr ( i ) ) ;
}
listBoxAISwitchTeamAcceptPercent . setItems ( aiswitchteamModeItems ) ;
2012-09-17 01:42:56 +02:00
vector < string > rMultiplier ;
for ( int i = 0 ; i < 45 ; + + i ) {
rMultiplier . push_back ( floatToStr ( 0.5f + 0.1f * i , 1 ) ) ;
}
listBoxFallbackCpuMultiplier . setItems ( rMultiplier ) ;
2013-10-29 07:13:38 +01:00
labelMap . setText ( lang . getString ( " Map " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelTileset . setText ( lang . getString ( " Tileset " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelTechTree . setText ( lang . getString ( " TechTree " ) ) ;
2011-10-25 20:39:11 +02:00
vector < string > playerstatusItems ;
2013-10-29 07:13:38 +01:00
playerstatusItems . push_back ( lang . getString ( " PlayerStatusSetup " ) ) ;
playerstatusItems . push_back ( lang . getString ( " PlayerStatusBeRightBack " ) ) ;
playerstatusItems . push_back ( lang . getString ( " PlayerStatusReady " ) ) ;
2011-10-25 20:39:11 +02:00
listBoxPlayerStatus . setItems ( playerstatusItems ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelControl . setText ( lang . getString ( " Control " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelFaction . setText ( lang . getString ( " Faction " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelTeam . setText ( lang . getString ( " Team " ) ) ;
2011-10-25 20:39:11 +02:00
labelControl . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelControl . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
labelFaction . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelFaction . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
labelTeam . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelTeam . setFont3D ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ) ;
//texts
2013-10-29 07:13:38 +01:00
buttonDisconnect . setText ( lang . getString ( " Return " ) ) ;
2011-10-25 20:39:11 +02:00
vector < string > controlItems ;
2013-10-29 07:13:38 +01:00
controlItems . push_back ( lang . getString ( " Closed " ) ) ;
controlItems . push_back ( lang . getString ( " CpuEasy " ) ) ;
controlItems . push_back ( lang . getString ( " Cpu " ) ) ;
controlItems . push_back ( lang . getString ( " CpuUltra " ) ) ;
controlItems . push_back ( lang . getString ( " CpuMega " ) ) ;
controlItems . push_back ( lang . getString ( " Network " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkUnassigned " ) ) ;
controlItems . push_back ( lang . getString ( " Human " ) ) ;
2011-10-25 20:39:11 +02:00
if ( config . getBool ( " EnableNetworkCpu " , " false " ) = = true ) {
2013-10-29 07:13:38 +01:00
controlItems . push_back ( lang . getString ( " NetworkCpuEasy " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpu " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpuUltra " ) ) ;
controlItems . push_back ( lang . getString ( " NetworkCpuMega " ) ) ;
2011-10-25 20:39:11 +02:00
}
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2013-10-27 17:13:27 +01:00
labelPlayers [ i ] . setText ( intToStr ( i + 1 ) ) ;
2011-10-25 20:39:11 +02:00
listBoxControls [ i ] . setItems ( controlItems ) ;
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
labelScenario . setText ( lang . getString ( " Scenario " ) ) ;
2011-12-26 07:29:14 +01:00
2013-10-29 07:13:38 +01:00
labelAllowNativeLanguageTechtree . setText ( lang . getString ( " AllowNativeLanguageTechtree " ) ) ;
2013-06-19 03:03:51 +02:00
2013-10-29 07:13:38 +01:00
buttonPlayNow . setText ( lang . getString ( " PlayNow " ) ) ;
buttonRestoreLastSettings . setText ( lang . getString ( " ReloadLastGameSettings " ) ) ;
2011-10-25 20:39:11 +02:00
chatManager . init ( & console , - 1 , true ) ;
GraphicComponent : : reloadFontsForRegisterGraphicComponents ( containerName ) ;
}
2013-05-23 09:12:29 +02:00
void MenuStateConnectedGame : : disconnectFromServer ( ) {
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( false ) ;
if ( clientInterface ! = NULL ) {
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
if ( clientInterface - > getSocket ( ) ! = NULL ) {
if ( clientInterface - > isConnected ( ) = = true ) {
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2013-10-29 07:13:38 +01:00
string sQuitText = lang . getString ( " QuitGame " , languageList [ i ] ) ;
2013-05-23 09:12:29 +02:00
clientInterface - > sendTextMessage ( sQuitText , - 1 , false , languageList [ i ] ) ;
}
sleep ( 1 ) ;
}
clientInterface - > close ( ) ;
}
clientInterface - > reset ( ) ;
}
currentFactionName = " " ;
currentMap = " " ;
}
2010-08-31 08:38:27 +02:00
MenuStateConnectedGame : : ~ MenuStateConnectedGame ( ) {
2013-05-23 09:12:29 +02:00
if ( launchingNewGame = = false ) {
disconnectFromServer ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
networkManager . end ( ) ;
}
2012-10-16 01:10:41 +02:00
if ( modHttpServerThread ! = NULL ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-01-09 18:43:35 +01:00
2013-06-01 08:07:14 +02:00
modHttpServerThread - > setSimpleTaskInterfaceValid ( false ) ;
2012-10-16 01:10:41 +02:00
modHttpServerThread - > signalQuit ( ) ;
2013-06-01 08:07:14 +02:00
modHttpServerThread - > setThreadOwnerValid ( false ) ;
2012-10-16 01:10:41 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( modHttpServerThread - > canShutdown ( true ) = = true & &
modHttpServerThread - > shutdownAndWait ( ) = = true ) {
delete modHttpServerThread ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
modHttpServerThread = NULL ;
}
2010-12-29 02:10:53 +01:00
if ( ftpClientThread ! = NULL ) {
2013-01-29 01:10:27 +01:00
ftpClientThread - > setCallBackObject ( NULL ) ;
ftpClientThread - > signalQuit ( ) ;
sleep ( 0 ) ;
if ( ftpClientThread - > canShutdown ( true ) = = true & &
ftpClientThread - > shutdownAndWait ( ) = = true ) {
delete ftpClientThread ;
}
else {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] Error cannot shutdown ftpClientThread \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-06-01 19:23:51 +02:00
2013-01-29 01:10:27 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " %s " , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
}
ftpClientThread = NULL ;
2010-12-29 02:10:53 +01:00
}
2011-04-13 03:11:23 +02:00
cleanupMapPreviewTexture ( ) ;
2012-05-26 01:00:36 +02:00
if ( factionVideo ! = NULL ) {
factionVideo - > closePlayer ( ) ;
delete factionVideo ;
factionVideo = NULL ;
}
2010-08-31 08:38:27 +02:00
}
2012-10-16 00:19:22 +02:00
string MenuStateConnectedGame : : refreshTilesetModInfo ( string tilesetInfo ) {
std : : vector < std : : string > tilesetInfoList ;
Tokenize ( tilesetInfo , tilesetInfoList , " | " ) ;
if ( tilesetInfoList . size ( ) > = 5 ) {
Config & config = Config : : getInstance ( ) ;
ModInfo modinfo ;
modinfo . name = tilesetInfoList [ 0 ] ;
modinfo . crc = tilesetInfoList [ 1 ] ;
modinfo . description = tilesetInfoList [ 2 ] ;
modinfo . url = tilesetInfoList [ 3 ] ;
modinfo . imageUrl = tilesetInfoList [ 4 ] ;
modinfo . type = mt_Tileset ;
string itemPath = config . getPathListForType ( ptTilesets , " " ) [ 1 ] + " / " + modinfo . name + string ( " /* " ) ;
if ( itemPath . empty ( ) = = false ) {
bool forceRefresh = ( mapCRCUpdateList . find ( itemPath ) = = mapCRCUpdateList . end ( ) ) ;
uint32 crc = getFolderTreeContentsCheckSumRecursively ( itemPath , " .xml " , NULL , forceRefresh ) ;
if ( crc = = 0 ) {
itemPath = config . getPathListForType ( ptTilesets , " " ) [ 0 ] + " / " + modinfo . name + string ( " /* " ) ;
if ( itemPath . empty ( ) = = false ) {
forceRefresh = ( mapCRCUpdateList . find ( itemPath ) = = mapCRCUpdateList . end ( ) ) ;
crc = getFolderTreeContentsCheckSumRecursively ( itemPath , " .xml " , NULL , forceRefresh ) ;
}
}
modinfo . localCRC = uIntToStr ( crc ) ;
//printf("itemPath='%s' remote crc:'%s' local crc:'%s' crc='%d' \n",itemPath.c_str(),modinfo.crc.c_str(),modinfo.localCRC.c_str(),crc);
//printf("#1 refreshTilesetModInfo name [%s] modInfo.crc [%s] modInfo.localCRC [%s]\n",modinfo.name.c_str(),modinfo.crc.c_str(),modinfo.localCRC.c_str());
}
else {
modinfo . localCRC = " " ;
//printf("#2 refreshTilesetModInfo name [%s] modInfo.crc [%s] modInfo.localCRC [%s]\n",modinfo.name.c_str(),modinfo.crc.c_str(),modinfo.localCRC.c_str());
}
tilesetCacheList [ modinfo . name ] = modinfo ;
return modinfo . name ;
}
return " " ;
}
string MenuStateConnectedGame : : refreshTechModInfo ( string techInfo ) {
std : : vector < std : : string > techInfoList ;
Tokenize ( techInfo , techInfoList , " | " ) ;
if ( techInfoList . size ( ) > = 6 ) {
Config & config = Config : : getInstance ( ) ;
ModInfo modinfo ;
modinfo . name = techInfoList [ 0 ] ;
modinfo . count = techInfoList [ 1 ] ;
modinfo . crc = techInfoList [ 2 ] ;
modinfo . description = techInfoList [ 3 ] ;
modinfo . url = techInfoList [ 4 ] ;
modinfo . imageUrl = techInfoList [ 5 ] ;
modinfo . type = mt_Techtree ;
string itemPath = config . getPathListForType ( ptTechs , " " ) [ 1 ] + " / " + modinfo . name + string ( " /* " ) ;
if ( itemPath . empty ( ) = = false ) {
bool forceRefresh = ( mapCRCUpdateList . find ( itemPath ) = = mapCRCUpdateList . end ( ) ) ;
uint32 crc = getFolderTreeContentsCheckSumRecursively ( itemPath , " .xml " , NULL , forceRefresh ) ;
if ( crc = = 0 ) {
itemPath = config . getPathListForType ( ptTechs , " " ) [ 0 ] + " / " + modinfo . name + string ( " /* " ) ;
if ( itemPath . empty ( ) = = false ) {
forceRefresh = ( mapCRCUpdateList . find ( itemPath ) = = mapCRCUpdateList . end ( ) ) ;
crc = getFolderTreeContentsCheckSumRecursively ( itemPath , " .xml " , NULL , forceRefresh ) ;
}
}
modinfo . localCRC = uIntToStr ( crc ) ;
//printf("itemPath='%s' remote crc:'%s' local crc:'%s' crc='%d' \n",itemPath.c_str(),modinfo.crc.c_str(),modinfo.localCRC.c_str(),crc);
}
else {
modinfo . localCRC = " " ;
}
techCacheList [ modinfo . name ] = modinfo ;
return modinfo . name ;
}
return " " ;
}
string MenuStateConnectedGame : : getMapCRC ( string mapName ) {
Config & config = Config : : getInstance ( ) ;
vector < string > mappaths = config . getPathListForType ( ptMaps , " " ) ;
string result = " " ;
if ( mappaths . empty ( ) = = false ) {
Checksum checksum ;
string itemPath = mappaths [ 1 ] + " / " + mapName ;
if ( fileExists ( itemPath ) ) {
checksum . addFile ( itemPath ) ;
uint32 crc = checksum . getSum ( ) ;
result = uIntToStr ( crc ) ;
//printf("itemPath='%s' modinfo.name='%s' remote crc:'%s' local crc:'%s' crc='%d' \n",itemPath.c_str(),modinfo.name.c_str(),modinfo.crc.c_str(),modinfo.localCRC.c_str(),crc);
}
else {
itemPath = mappaths [ 0 ] + " / " + mapName ;
if ( fileExists ( itemPath ) ) {
checksum . addFile ( itemPath ) ;
uint32 crc = checksum . getSum ( ) ;
result = uIntToStr ( crc ) ;
//printf("itemPath='%s' modinfo.name='%s' remote crc:'%s' local crc:'%s' crc='%d' \n",itemPath.c_str(),modinfo.name.c_str(),modinfo.crc.c_str(),modinfo.localCRC.c_str(),crc);
}
else {
result = " " ;
}
}
}
else {
result = " " ;
}
return result ;
}
string MenuStateConnectedGame : : refreshMapModInfo ( string mapInfo ) {
std : : vector < std : : string > mapInfoList ;
Tokenize ( mapInfo , mapInfoList , " | " ) ;
if ( mapInfoList . size ( ) > = 6 ) {
//Config &config = Config::getInstance();
ModInfo modinfo ;
modinfo . name = mapInfoList [ 0 ] ;
modinfo . count = mapInfoList [ 1 ] ;
modinfo . crc = mapInfoList [ 2 ] ;
modinfo . description = mapInfoList [ 3 ] ;
modinfo . url = mapInfoList [ 4 ] ;
modinfo . imageUrl = mapInfoList [ 5 ] ;
modinfo . type = mt_Map ;
modinfo . localCRC = getMapCRC ( modinfo . name ) ;
mapCacheList [ modinfo . name ] = modinfo ;
return modinfo . name ;
}
return " " ;
}
2013-11-07 19:39:08 +01:00
void MenuStateConnectedGame : : simpleTask ( BaseThread * callingThread , void * userdata ) {
2012-10-16 00:19:22 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutexThreadOwner ( callingThread - > getMutexThreadOwnerValid ( ) , mutexOwnerId ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
callingThread - > getMutexThreadOwnerValid ( ) - > setOwnerId ( mutexOwnerId ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
Lang & lang = Lang : : getInstance ( ) ;
Config & config = Config : : getInstance ( ) ;
std : : string techsMetaData = " " ;
std : : string tilesetsMetaData = " " ;
std : : string mapsMetaData = " " ;
std : : string scenariosMetaData = " " ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( config . getString ( " Masterserver " , " " ) ! = " " ) {
string baseURL = config . getString ( " Masterserver " ) ;
string phpVersionParam = config . getString ( " phpVersionParam " , " ?version=0.1 " ) ;
2012-10-16 07:27:51 +02:00
string gameVersion = " &glestVersion= " + SystemFlags : : escapeURL ( glestVersionString ) ;
2013-06-01 04:31:12 +02:00
string playerUUID = " &uuid= " + SystemFlags : : escapeURL ( config . getString ( " PlayerId " , " " ) ) ;
2012-10-16 00:19:22 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] About to call first http url, base [%s].. \n " , __FILE__ , __FUNCTION__ , __LINE__ , baseURL . c_str ( ) ) ;
CURL * handle = SystemFlags : : initHTTP ( ) ;
CURLcode curlResult = CURLE_OK ;
2013-06-01 04:31:12 +02:00
techsMetaData = SystemFlags : : getHTTP ( baseURL + " showTechsForGlest.php " + phpVersionParam + gameVersion + playerUUID , handle , - 1 , & curlResult ) ;
2013-06-01 08:28:03 +02:00
2012-10-16 00:19:22 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " techsMetaData [%s] curlResult = %d \n " , techsMetaData . c_str ( ) , curlResult ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( curlResult ! = CURLE_OK ) {
string curlError = curl_easy_strerror ( curlResult ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-10-29 07:13:38 +01:00
snprintf ( szBuf , 8096 , lang . getString ( " ModErrorGettingServerData " ) . c_str ( ) , curlError . c_str ( ) ) ;
2012-10-16 00:19:22 +02:00
console . addLine ( string ( " #1 " ) + szBuf , true ) ;
}
if ( curlResult = = CURLE_OK | |
( curlResult ! = CURLE_COULDNT_RESOLVE_HOST & &
curlResult ! = CURLE_COULDNT_CONNECT ) ) {
2012-10-16 07:27:51 +02:00
tilesetsMetaData = SystemFlags : : getHTTP ( baseURL + " showTilesetsForGlest.php " + phpVersionParam + gameVersion , handle , - 1 , & curlResult ) ;
2012-10-16 00:19:22 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " tilesetsMetaData [%s] \n " , tilesetsMetaData . c_str ( ) ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( curlResult ! = CURLE_OK ) {
string curlError = curl_easy_strerror ( curlResult ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-10-29 07:13:38 +01:00
snprintf ( szBuf , 8096 , lang . getString ( " ModErrorGettingServerData " ) . c_str ( ) , curlError . c_str ( ) ) ;
2012-10-16 00:19:22 +02:00
console . addLine ( string ( " #2 " ) + szBuf , true ) ;
}
2012-10-16 07:27:51 +02:00
mapsMetaData = SystemFlags : : getHTTP ( baseURL + " showMapsForGlest.php " + phpVersionParam + gameVersion , handle , - 1 , & curlResult ) ;
2012-10-16 00:19:22 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " mapsMetaData [%s] \n " , mapsMetaData . c_str ( ) ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( curlResult ! = CURLE_OK ) {
string curlError = curl_easy_strerror ( curlResult ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-10-29 07:13:38 +01:00
snprintf ( szBuf , 8096 , lang . getString ( " ModErrorGettingServerData " ) . c_str ( ) , curlError . c_str ( ) ) ;
2012-10-16 00:19:22 +02:00
console . addLine ( string ( " #3 " ) + szBuf , true ) ;
}
2012-10-16 07:27:51 +02:00
scenariosMetaData = SystemFlags : : getHTTP ( baseURL + " showScenariosForGlest.php " + phpVersionParam + gameVersion , handle , - 1 , & curlResult ) ;
2012-10-16 00:19:22 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " scenariosMetaData [%s] \n " , scenariosMetaData . c_str ( ) ) ;
if ( curlResult ! = CURLE_OK ) {
string curlError = curl_easy_strerror ( curlResult ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-10-29 07:13:38 +01:00
snprintf ( szBuf , 8096 , lang . getString ( " ModErrorGettingServerData " ) . c_str ( ) , curlError . c_str ( ) ) ;
2012-10-16 00:19:22 +02:00
console . addLine ( string ( " #4 " ) + szBuf , true ) ;
}
}
SystemFlags : : cleanupHTTP ( & handle ) ;
}
else {
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " MasterServerMissing " ) , true ) ;
2012-10-16 00:19:22 +02:00
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
tilesetListRemote . clear ( ) ;
Tokenize ( tilesetsMetaData , tilesetListRemote , " \n " ) ;
for ( unsigned int i = 0 ; i < tilesetListRemote . size ( ) ; i + + ) {
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
string result = refreshTilesetModInfo ( tilesetListRemote [ i ] ) ;
}
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
techListRemote . clear ( ) ;
Tokenize ( techsMetaData , techListRemote , " \n " ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
for ( unsigned int i = 0 ; i < techListRemote . size ( ) ; i + + ) {
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
string result = refreshTechModInfo ( techListRemote [ i ] ) ;
}
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
mapListRemote . clear ( ) ;
Tokenize ( mapsMetaData , mapListRemote , " \n " ) ;
for ( unsigned int i = 0 ; i < mapListRemote . size ( ) ; i + + ) {
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
string result = refreshMapModInfo ( mapListRemote [ i ] ) ;
}
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( modHttpServerThread ! = NULL ) {
modHttpServerThread - > signalQuit ( ) ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2010-04-22 01:13:39 +02:00
void MenuStateConnectedGame : : mouseClick ( int x , int y , MouseButton mouseButton ) {
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
2011-01-14 18:57:37 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2010-04-22 01:13:39 +02:00
2012-11-17 02:04:04 +01:00
string advanceToItemStartingWith = " " ;
2013-05-26 05:35:31 +02:00
if ( mainMessageBox . getEnabled ( ) = = false ) {
2013-11-19 22:57:28 +01:00
if ( : : Shared : : Platform : : Window : : isKeyStateModPressed ( KMOD_SHIFT ) = = true ) {
wchar_t lastKey = : : Shared : : Platform : : Window : : extractLastKeyPressed ( ) ;
2012-11-17 02:04:04 +01:00
//printf("lastKey = %d [%c]\n",lastKey,lastKey);
advanceToItemStartingWith = lastKey ;
}
}
2013-12-31 08:32:06 +01:00
if ( mapPreviewTexture ! = NULL ) {
// printf("X: %d Y: %d [%d, %d, %d, %d]\n",
// x, y,
// this->render_mapPreviewTexture_X, this->render_mapPreviewTexture_X + this->render_mapPreviewTexture_W,
// this->render_mapPreviewTexture_Y, this->render_mapPreviewTexture_Y + this->render_mapPreviewTexture_H);
if ( x > = this - > render_mapPreviewTexture_X & & x < = this - > render_mapPreviewTexture_X + this - > render_mapPreviewTexture_W & &
y > = this - > render_mapPreviewTexture_Y & & y < = this - > render_mapPreviewTexture_Y + this - > render_mapPreviewTexture_H ) {
if ( this - > render_mapPreviewTexture_X = = mapPreviewTexture_X & &
this - > render_mapPreviewTexture_Y = = mapPreviewTexture_Y & &
this - > render_mapPreviewTexture_W = = mapPreviewTexture_W & &
this - > render_mapPreviewTexture_H = = mapPreviewTexture_H ) {
const Metrics & metrics = Metrics : : getInstance ( ) ;
this - > render_mapPreviewTexture_X = 0 ;
this - > render_mapPreviewTexture_Y = 0 ;
this - > render_mapPreviewTexture_W = metrics . getVirtualW ( ) ;
this - > render_mapPreviewTexture_H = metrics . getVirtualH ( ) ;
2014-01-03 19:19:10 +01:00
this - > zoomedMap = true ;
2013-12-31 08:32:06 +01:00
cleanupMapPreviewTexture ( ) ;
}
else {
this - > render_mapPreviewTexture_X = mapPreviewTexture_X ;
this - > render_mapPreviewTexture_Y = mapPreviewTexture_Y ;
this - > render_mapPreviewTexture_W = mapPreviewTexture_W ;
this - > render_mapPreviewTexture_H = mapPreviewTexture_H ;
2014-01-03 19:19:10 +01:00
this - > zoomedMap = false ;
2013-12-31 08:32:06 +01:00
cleanupMapPreviewTexture ( ) ;
}
}
2014-01-03 19:19:10 +01:00
if ( this - > zoomedMap = = true ) {
return ;
}
2013-12-31 08:32:06 +01:00
}
2011-01-10 01:05:31 +01:00
if ( mainMessageBox . getEnabled ( ) ) {
2012-02-19 18:37:53 +01:00
int button = 0 ;
2011-01-10 01:05:31 +01:00
if ( mainMessageBox . mouseClick ( x , y , button ) ) {
2010-09-17 08:37:08 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
2012-02-19 18:37:53 +01:00
if ( button = = 0 ) {
2010-09-17 08:37:08 +02:00
mainMessageBox . setEnabled ( false ) ;
}
}
}
2010-12-29 20:31:51 +01:00
else if ( ftpMessageBox . getEnabled ( ) ) {
2012-02-19 18:37:53 +01:00
int button = 0 ;
2010-12-29 20:31:51 +01:00
if ( ftpMessageBox . mouseClick ( x , y , button ) ) {
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
ftpMessageBox . setEnabled ( false ) ;
2012-10-16 00:19:22 +02:00
2012-10-16 00:51:40 +02:00
if ( button = = 0 | | ( button = = 1 & & ftpMessageBox . getButtonCount ( ) = = 3 ) ) {
2011-01-01 01:50:10 +01:00
if ( ftpMissingDataType = = ftpmsg_MissingMap ) {
getMissingMapFromFTPServerInProgress = true ;
2010-12-29 20:31:51 +01:00
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingMapNowDownloading " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingMapNowDownloading " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , getMissingMapFromFTPServer . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is attempting to download the map: %s " , getHumanPlayerName ( ) . c_str ( ) , getMissingMapFromFTPServer . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
2010-12-29 20:31:51 +01:00
2011-01-01 01:50:10 +01:00
if ( ftpClientThread ! = NULL ) {
2012-10-16 00:51:40 +02:00
if ( button = = 0 & & ftpMessageBox . getButtonCount ( ) = = 3 ) {
2012-10-16 00:19:22 +02:00
string mapName = getMissingMapFromFTPServer ;
string mapURL = mapCacheList [ mapName ] . url ;
if ( ftpClientThread ! = NULL ) ftpClientThread - > addMapToRequests ( mapName , mapURL ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
fileFTPProgressList [ getMissingMapFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
safeMutexFTPProgress . ReleaseLock ( ) ;
}
else {
ftpClientThread - > addMapToRequests ( getMissingMapFromFTPServer ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
fileFTPProgressList [ getMissingMapFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
safeMutexFTPProgress . ReleaseLock ( ) ;
}
2011-01-01 01:50:10 +01:00
}
}
else if ( ftpMissingDataType = = ftpmsg_MissingTileset ) {
getMissingTilesetFromFTPServerInProgress = true ;
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingTilesetNowDownloading " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTilesetNowDownloading " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , getMissingTilesetFromFTPServer . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is attempting to download the tileset: %s " , getHumanPlayerName ( ) . c_str ( ) , getMissingTilesetFromFTPServer . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
2011-01-01 01:50:10 +01:00
if ( ftpClientThread ! = NULL ) {
2012-10-16 00:51:40 +02:00
if ( button = = 0 & & ftpMessageBox . getButtonCount ( ) = = 3 ) {
2012-10-16 00:19:22 +02:00
string tilesetName = getMissingTilesetFromFTPServer ;
string tilesetURL = tilesetCacheList [ tilesetName ] . url ;
if ( ftpClientThread ! = NULL ) ftpClientThread - > addTilesetToRequests ( tilesetName , tilesetURL ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2012-10-16 23:12:58 +02:00
fileFTPProgressList [ getMissingTilesetFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
2012-10-16 00:19:22 +02:00
safeMutexFTPProgress . ReleaseLock ( ) ;
}
else {
ftpClientThread - > addTilesetToRequests ( getMissingTilesetFromFTPServer ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
fileFTPProgressList [ getMissingTilesetFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
safeMutexFTPProgress . ReleaseLock ( ) ;
}
2011-03-10 00:09:32 +01:00
}
}
else if ( ftpMissingDataType = = ftpmsg_MissingTechtree ) {
getMissingTechtreeFromFTPServerInProgress = true ;
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingTechtreeNowDownloading " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTechtreeNowDownloading " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , getMissingTechtreeFromFTPServer . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is attempting to download the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , getMissingTechtreeFromFTPServer . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
2011-03-10 00:09:32 +01:00
if ( ftpClientThread ! = NULL ) {
2012-10-16 00:51:40 +02:00
if ( button = = 0 & & ftpMessageBox . getButtonCount ( ) = = 3 ) {
2012-10-16 00:19:22 +02:00
string techName = getMissingTechtreeFromFTPServer ;
string techURL = techCacheList [ techName ] . url ;
if ( ftpClientThread ! = NULL ) ftpClientThread - > addTechtreeToRequests ( techName , techURL ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2012-10-16 23:12:58 +02:00
fileFTPProgressList [ getMissingTechtreeFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
2012-10-16 00:19:22 +02:00
safeMutexFTPProgress . ReleaseLock ( ) ;
}
else {
ftpClientThread - > addTechtreeToRequests ( getMissingTechtreeFromFTPServer ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
fileFTPProgressList [ getMissingTechtreeFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
safeMutexFTPProgress . ReleaseLock ( ) ;
}
2011-01-01 01:50:10 +01:00
}
}
2010-12-29 20:31:51 +01:00
}
}
}
2011-04-15 02:09:38 +02:00
else if ( buttonCancelDownloads . mouseClick ( x , y ) ) {
2013-05-26 04:44:36 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
2011-09-01 01:10:43 +02:00
if ( ftpClientThread ! = NULL & & fileFTPProgressList . empty ( ) = = false ) {
2013-01-29 01:10:27 +01:00
ftpClientThread - > setCallBackObject ( NULL ) ;
ftpClientThread - > signalQuit ( ) ;
sleep ( 0 ) ;
if ( ftpClientThread - > canShutdown ( true ) = = true & &
ftpClientThread - > shutdownAndWait ( ) = = true ) {
delete ftpClientThread ;
}
else {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] Error cannot shutdown ftpClientThread \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " %s " , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
}
ftpClientThread = NULL ;
2011-04-15 02:09:38 +02:00
fileFTPProgressList . clear ( ) ;
getMissingMapFromFTPServerInProgress = false ;
getMissingTilesetFromFTPServerInProgress = false ;
getMissingTechtreeFromFTPServerInProgress = false ;
getMissingMapFromFTPServer = " " ;
getMissingTilesetFromFTPServer = " " ;
getMissingTechtreeFromFTPServer = " " ;
2013-05-31 21:05:34 +02:00
getMissingMapFromFTPServerLastPrompted = 0 ;
getMissingTilesetFromFTPServerLastPrompted = 0 ;
getMissingTechtreeFromFTPServerLastPrompted = 0 ;
2011-04-15 02:09:38 +02:00
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
2013-12-14 08:04:12 +01:00
if ( clientInterface = = NULL ) {
throw megaglest_runtime_error ( " clientInterface == NULL " ) ;
}
2013-05-31 17:33:01 +02:00
if ( getInProgressSavedGameFromFTPServerInProgress = = true ) {
if ( clientInterface ! = NULL ) {
clientInterface - > close ( ) ;
return ;
}
}
getInProgressSavedGameFromFTPServer = " " ;
getInProgressSavedGameFromFTPServerInProgress = false ;
2011-04-15 02:09:38 +02:00
string serverUrl = clientInterface - > getServerIpAddress ( ) ;
int portNumber = clientInterface - > getServerFTPPort ( ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] Using FTP port #: %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , portNumber ) ;
2011-04-15 02:09:38 +02:00
Config & config = Config : : getInstance ( ) ;
vector < string > mapPathList = config . getPathListForType ( ptMaps ) ;
std : : pair < string , string > mapsPath ;
2011-09-01 01:10:43 +02:00
if ( mapPathList . empty ( ) = = false ) {
2011-04-15 02:09:38 +02:00
mapsPath . first = mapPathList [ 0 ] ;
}
if ( mapPathList . size ( ) > 1 ) {
mapsPath . second = mapPathList [ 1 ] ;
}
std : : pair < string , string > tilesetsPath ;
vector < string > tilesetsList = Config : : getInstance ( ) . getPathListForType ( ptTilesets ) ;
2011-09-01 01:10:43 +02:00
if ( tilesetsList . empty ( ) = = false ) {
2011-04-15 02:09:38 +02:00
tilesetsPath . first = tilesetsList [ 0 ] ;
if ( tilesetsList . size ( ) > 1 ) {
tilesetsPath . second = tilesetsList [ 1 ] ;
}
}
std : : pair < string , string > techtreesPath ;
vector < string > techtreesList = Config : : getInstance ( ) . getPathListForType ( ptTechs ) ;
2011-09-01 01:10:43 +02:00
if ( techtreesList . empty ( ) = = false ) {
2011-04-15 02:09:38 +02:00
techtreesPath . first = techtreesList [ 0 ] ;
if ( techtreesList . size ( ) > 1 ) {
techtreesPath . second = techtreesList [ 1 ] ;
}
}
std : : pair < string , string > scenariosPath ;
vector < string > scenariosList = Config : : getInstance ( ) . getPathListForType ( ptScenarios ) ;
2011-09-01 01:10:43 +02:00
if ( scenariosList . empty ( ) = = false ) {
2011-04-15 02:09:38 +02:00
scenariosPath . first = scenariosList [ 0 ] ;
if ( scenariosList . size ( ) > 1 ) {
scenariosPath . second = scenariosList [ 1 ] ;
}
}
string fileArchiveExtension = config . getString ( " FileArchiveExtension " , " " ) ;
string fileArchiveExtractCommand = config . getString ( " FileArchiveExtractCommand " , " " ) ;
string fileArchiveExtractCommandParameters = config . getString ( " FileArchiveExtractCommandParameters " , " " ) ;
int32 fileArchiveExtractCommandSuccessResult = config . getInt ( " FileArchiveExtractCommandSuccessResult " , " 0 " ) ;
2013-02-15 19:25:10 +01:00
// Get path to temp files
string tempFilePath = " temp/ " ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
tempFilePath = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + tempFilePath ;
}
else {
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
tempFilePath = userData + tempFilePath ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Temp files path [%s] \n " , tempFilePath . c_str ( ) ) ;
2011-04-15 02:09:38 +02:00
ftpClientThread = new FTPClientThread ( portNumber , serverUrl ,
mapsPath , tilesetsPath , techtreesPath , scenariosPath ,
this , fileArchiveExtension , fileArchiveExtractCommand ,
2013-02-15 19:25:10 +01:00
fileArchiveExtractCommandParameters ,
fileArchiveExtractCommandSuccessResult ,
tempFilePath ) ;
2011-04-15 02:09:38 +02:00
ftpClientThread - > start ( ) ;
2011-04-15 02:13:13 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-15 02:13:13 +02:00
if ( lang . hasString ( " CancelDownloadsMsg " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " CancelDownloadsMsg " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) ) ;
2011-04-15 02:13:13 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s cancelled all file downloads. " , getHumanPlayerName ( ) . c_str ( ) ) ;
2011-04-15 02:13:13 +02:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2011-04-15 02:09:38 +02:00
}
}
2010-09-17 08:37:08 +02:00
else if ( buttonDisconnect . mouseClick ( x , y ) ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2013-05-23 09:12:29 +02:00
disconnectFromServer ( ) ;
networkManager . end ( ) ;
returnToJoinMenu ( ) ;
2010-08-05 02:48:46 +02:00
return ;
2010-04-22 01:13:39 +02:00
}
2010-08-05 02:48:46 +02:00
2013-05-26 05:35:31 +02:00
if ( initialSettingsReceivedFromServer = = false ) {
return ;
}
2010-08-05 02:48:46 +02:00
2013-05-26 05:35:31 +02:00
if ( activeInputLabel ! = NULL & & activeInputLabel - > mouseClick ( x , y ) = = false ) {
2011-10-23 12:49:36 +02:00
setActiveInputLabel ( NULL ) ;
}
2010-06-30 16:51:30 +02:00
// Only allow changes after we get game settings from the server
2013-05-17 05:59:34 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) = = true ) {
2011-03-26 14:40:22 +01:00
int myCurrentIndex = - 1 ;
2011-09-24 09:46:56 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) { // find my current index by looking at editable listBoxes
2012-05-11 07:11:46 +02:00
if ( //listBoxFactions[i].getEditable() &&
2011-10-15 03:03:24 +02:00
clientInterface - > getGameSettings ( ) - > getStartLocationIndex ( clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) ) = = i ) {
2011-03-26 14:40:22 +01:00
myCurrentIndex = i ;
}
2010-04-30 03:08:29 +02:00
}
2011-10-15 03:03:24 +02:00
//printf("myCurrentIndex = %d thisFactionIndex = %d\n",myCurrentIndex,clientInterface->getGameSettings()->getThisFactionIndex());
2011-03-26 14:40:22 +01:00
if ( myCurrentIndex ! = - 1 )
2011-09-24 09:46:56 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-10-15 03:03:24 +02:00
if ( listBoxFactions [ i ] . getEditable ( ) & &
clientInterface - > getGameSettings ( ) - > getStartLocationIndex ( clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) ) = = i ) {
2012-11-17 02:04:04 +01:00
if ( listBoxFactions [ i ] . mouseClick ( x , y , advanceToItemStartingWith ) ) {
2010-06-30 16:51:30 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
ClientInterface * clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
2011-09-24 09:46:56 +02:00
if ( clientInterface - > isConnected ( ) ) {
2010-06-30 16:51:30 +02:00
clientInterface - > setGameSettingsReceived ( false ) ;
2011-04-05 07:32:35 +02:00
clientInterface - > sendSwitchSetupRequest (
listBoxFactions [ i ] . getSelectedItem ( ) ,
i ,
- 1 ,
listBoxTeams [ i ] . getSelectedItemIndex ( ) ,
getHumanPlayerName ( ) ,
getNetworkPlayerStatus ( ) ,
2011-04-05 20:39:47 +02:00
switchSetupRequestFlagType ,
lang . getLanguage ( ) ) ;
2011-03-26 14:40:22 +01:00
switchSetupRequestFlagType = ssrft_None ;
2010-06-30 16:51:30 +02:00
}
break ;
2010-04-29 01:59:37 +02:00
}
2010-04-30 03:08:29 +02:00
}
2011-10-15 03:03:24 +02:00
if ( listBoxTeams [ i ] . getEditable ( ) & &
clientInterface - > getGameSettings ( ) - > getStartLocationIndex ( clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) ) = = i ) {
2011-03-26 14:40:22 +01:00
if ( listBoxTeams [ i ] . mouseClick ( x , y ) ) {
2010-06-30 16:51:30 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
2011-03-26 14:40:22 +01:00
if ( clientInterface - > isConnected ( ) ) {
2010-06-30 16:51:30 +02:00
clientInterface - > setGameSettingsReceived ( false ) ;
2011-04-05 07:32:35 +02:00
clientInterface - > sendSwitchSetupRequest (
listBoxFactions [ i ] . getSelectedItem ( ) ,
i ,
- 1 ,
listBoxTeams [ i ] . getSelectedItemIndex ( ) ,
getHumanPlayerName ( ) ,
getNetworkPlayerStatus ( ) ,
2011-04-05 20:39:47 +02:00
switchSetupRequestFlagType ,
lang . getLanguage ( ) ) ;
2011-03-26 14:40:22 +01:00
switchSetupRequestFlagType = ssrft_None ;
2010-06-30 16:51:30 +02:00
}
break ;
}
}
2013-02-16 11:07:36 +01:00
bool canGrabSlot = false ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( clientInterface ! = NULL & & clientInterface - > getJoinGameInProgress ( ) = = true ) {
canGrabSlot = ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork & &
labelNetStatus [ i ] . getText ( ) = = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) | |
( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctHuman & &
listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed & &
listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetwork ) ) ;
}
else {
canGrabSlot = ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork & &
labelNetStatus [ i ] . getText ( ) = = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) ;
}
if ( canGrabSlot = = true ) {
2011-11-14 06:44:43 +01:00
if ( i < mapInfo . players & & grabSlotButton [ i ] . mouseClick ( x , y ) ) {
2011-09-01 23:54:31 +02:00
//printf("Send slot switch request for slot = %d, myCurrentIndex = %d\n",i,myCurrentIndex);
2013-05-26 04:44:36 +02:00
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
2010-06-30 16:51:30 +02:00
clientInterface - > setGameSettingsReceived ( false ) ;
2011-03-26 14:40:22 +01:00
settingsReceivedFromServer = false ;
2011-03-29 11:45:15 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] sending a switchSlot request from %d to %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) , i ) ;
2011-03-29 11:45:15 +02:00
2011-10-15 03:03:24 +02:00
//printf("Switch slot from %d to %d\n",myCurrentIndex,i);
2012-05-11 07:11:46 +02:00
string desiredFactionName = listBoxFactions [ myCurrentIndex ] . getSelectedItem ( ) ;
int desiredTeamIndex = listBoxTeams [ myCurrentIndex ] . getSelectedItemIndex ( ) ;
if ( checkBoxScenario . getValue ( ) = = true ) {
desiredFactionName = listBoxFactions [ i ] . getSelectedItem ( ) ;
desiredTeamIndex = listBoxTeams [ i ] . getSelectedItemIndex ( ) ;
}
2013-02-16 11:07:36 +01:00
//printf("Sending switch slot request to server...\n");
2011-04-05 07:32:35 +02:00
clientInterface - > sendSwitchSetupRequest (
2012-05-11 07:11:46 +02:00
desiredFactionName ,
2011-04-05 07:32:35 +02:00
myCurrentIndex ,
i ,
2012-05-11 07:11:46 +02:00
desiredTeamIndex ,
2011-04-05 07:32:35 +02:00
getHumanPlayerName ( ) ,
getNetworkPlayerStatus ( ) ,
2011-04-05 20:39:47 +02:00
switchSetupRequestFlagType ,
lang . getLanguage ( ) ) ;
2010-10-09 00:53:18 +02:00
labelPlayerNames [ myCurrentIndex ] . setText ( " " ) ;
labelPlayerNames [ i ] . setText ( " " ) ;
2011-03-26 14:40:22 +01:00
switchSetupRequestFlagType = ssrft_None ;
2010-06-30 16:51:30 +02:00
break ;
}
2010-04-29 01:59:37 +02:00
}
2010-08-21 15:04:52 +02:00
2011-03-26 14:40:22 +01:00
if ( labelPlayerNames [ i ] . mouseClick ( x , y ) & & ( activeInputLabel ! = & labelPlayerNames [ i ] ) ) {
if ( i = = clientInterface - > getPlayerIndex ( ) ) {
2010-08-21 15:04:52 +02:00
setActiveInputLabel ( & labelPlayerNames [ i ] ) ;
}
}
2010-04-29 01:59:37 +02:00
}
2011-03-11 12:11:46 +01:00
if ( listBoxPlayerStatus . mouseClick ( x , y ) ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-03-11 12:11:46 +01:00
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-03-11 12:11:46 +01:00
2011-04-13 00:20:41 +02:00
if ( getNetworkPlayerStatus ( ) = = npst_PickSettings )
{
listBoxPlayerStatus . setTextColor ( Vec3f ( 1.0f , 0.0f , 0.0f ) ) ;
listBoxPlayerStatus . setLighted ( true ) ;
}
else if ( getNetworkPlayerStatus ( ) = = npst_BeRightBack )
{
listBoxPlayerStatus . setTextColor ( Vec3f ( 1.0f , 1.0f , 0.0f ) ) ;
listBoxPlayerStatus . setLighted ( true ) ;
}
else if ( getNetworkPlayerStatus ( ) = = npst_Ready )
{
listBoxPlayerStatus . setTextColor ( Vec3f ( 0.0f , 1.0f , 0.0f ) ) ;
listBoxPlayerStatus . setLighted ( false ) ;
}
2011-03-11 12:11:46 +01:00
ClientInterface * clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
2013-05-17 05:59:34 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
2011-03-11 12:11:46 +01:00
clientInterface - > setGameSettingsReceived ( false ) ;
clientInterface - > sendSwitchSetupRequest (
listBoxFactions [ clientInterface - > getPlayerIndex ( ) ] . getSelectedItem ( ) ,
clientInterface - > getPlayerIndex ( ) , - 1 ,
listBoxTeams [ clientInterface - > getPlayerIndex ( ) ] . getSelectedItemIndex ( ) ,
getHumanPlayerName ( ) ,
getNetworkPlayerStatus ( ) ,
2011-04-05 20:39:47 +02:00
switchSetupRequestFlagType ,
lang . getLanguage ( ) ) ;
2011-03-11 12:11:46 +01:00
switchSetupRequestFlagType = ssrft_None ;
}
}
2011-09-24 09:46:56 +02:00
2012-07-06 00:03:15 +02:00
if ( isHeadlessAdmin ( ) = = true ) {
2011-09-24 09:46:56 +02:00
//printf("#1 admin key [%d] client key [%d]\n",settings->getMasterserver_admin(),clientInterface->getSessionKey());
2012-11-17 02:04:04 +01:00
mouseClickAdmin ( x , y , mouseButton , advanceToItemStartingWith ) ;
2011-09-24 09:46:56 +02:00
}
2013-02-15 19:25:10 +01:00
else if ( clientInterface ! = NULL & & clientInterface - > getJoinGameInProgress ( ) = = true ) {
if ( buttonPlayNow . mouseClick ( x , y ) & & buttonPlayNow . getEnabled ( ) ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-05-26 05:35:31 +02:00
uint32 tilesetCRC = lastCheckedCRCTilesetValue ;
uint32 techCRC = lastCheckedCRCTechtreeValue ;
uint32 mapCRC = lastCheckedCRCMapValue ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
bool dataSynchMismatch = ( ( mapCRC ! = 0 & & mapCRC ! = gameSettings - > getMapCRC ( ) ) | |
( tilesetCRC ! = 0 & & tilesetCRC ! = gameSettings - > getTilesetCRC ( ) ) | |
( techCRC ! = 0 & & techCRC ! = gameSettings - > getTechCRC ( ) ) ) ;
if ( dataSynchMismatch = = false ) {
PlayNow ( true ) ;
return ;
}
else {
showMessageBox ( " You cannot start the game because \n one or more clients do not have the same game data! " , " Data Mismatch Error " , false ) ;
}
2013-02-15 19:25:10 +01:00
}
}
2011-09-24 09:46:56 +02:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
}
2012-07-06 00:03:15 +02:00
bool MenuStateConnectedGame : : isHeadlessAdmin ( ) {
2011-09-24 09:46:56 +02:00
bool result = false ;
ClientInterface * clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
const GameSettings * settings = clientInterface - > getGameSettings ( ) ;
if ( settings ! = NULL ) {
//printf("#1 admin key [%d] client key [%d]\n",settings->getMasterserver_admin(),clientInterface->getSessionKey());
if ( settings - > getMasterserver_admin ( ) = = clientInterface - > getSessionKey ( ) ) {
result = true ;
}
}
}
return result ;
}
2012-07-06 00:03:15 +02:00
void MenuStateConnectedGame : : broadCastGameSettingsToHeadlessServer ( bool forceNow ) {
if ( isHeadlessAdmin ( ) = = false ) {
2011-10-22 02:19:38 +02:00
return ;
}
2011-09-24 09:46:56 +02:00
2011-10-22 02:19:38 +02:00
if ( forceNow = = true | |
2012-09-22 22:13:57 +02:00
( ( needToBroadcastServerSettings = = true ) & & ( difftime ( ( long int ) time ( NULL ) , broadcastServerSettingsDelayTimer ) > = HEADLESSSERVER_BROADCAST_SETTINGS_SECONDS ) ) ) {
2012-11-10 07:37:23 +01:00
//printf("In [%s:%s] Line: %d forceNow = %d broadcastServerSettingsDelayTimer = " MG_SIZE_T_SPECIFIER ", now =" MG_SIZE_T_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,forceNow,broadcastServerSettingsDelayTimer,time(NULL));
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = false ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctNetwork ) ;
}
2011-10-15 03:39:59 +02:00
}
2011-10-22 02:19:38 +02:00
for ( int i = mapInfo . players ; i < GameConstants : : maxPlayers ; + + i ) {
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctNetworkUnassigned ) ;
}
2011-10-15 03:39:59 +02:00
}
2011-10-22 02:19:38 +02:00
GameSettings gameSettings = * clientInterface - > getGameSettings ( ) ;
loadGameSettings ( & gameSettings ) ;
2011-09-24 09:46:56 +02:00
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " broadcast settings: \n %s \n " , gameSettings . toString ( ) . c_str ( ) ) ;
2011-10-01 10:04:30 +02:00
2011-10-22 02:19:38 +02:00
//printf("Client sending map [%s] admin key [%d]\n",gameSettings.getMap().c_str(),gameSettings.getMasterserver_admin());
2011-09-24 09:46:56 +02:00
2011-10-22 02:19:38 +02:00
clientInterface - > broadcastGameSetup ( & gameSettings ) ;
}
2011-09-24 09:46:56 +02:00
}
2011-09-27 03:11:11 +02:00
void MenuStateConnectedGame : : updateResourceMultiplier ( const int index ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ index ] . getSelectedItemIndex ( ) ) ;
2013-11-01 20:48:04 +01:00
if ( ct = = ctCpuEasy | | ct = = ctNetworkCpuEasy )
2011-09-27 03:11:11 +02:00
{
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : easyMultiplier , 1 ) ) ;
2011-09-27 03:11:11 +02:00
listBoxRMultiplier [ index ] . setEnabled ( true ) ;
}
else if ( ct = = ctCpu | | ct = = ctNetworkCpu ) {
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : normalMultiplier , 1 ) ) ;
2011-09-27 03:11:11 +02:00
listBoxRMultiplier [ index ] . setEnabled ( true ) ;
}
else if ( ct = = ctCpuUltra | | ct = = ctNetworkCpuUltra )
{
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : ultraMultiplier , 1 ) ) ;
2011-09-27 03:11:11 +02:00
listBoxRMultiplier [ index ] . setEnabled ( true ) ;
}
else if ( ct = = ctCpuMega | | ct = = ctNetworkCpuMega )
{
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : megaMultiplier , 1 ) ) ;
2011-09-27 03:11:11 +02:00
listBoxRMultiplier [ index ] . setEnabled ( true ) ;
}
2013-11-01 20:48:04 +01:00
else {
2013-11-02 23:30:16 +01:00
listBoxRMultiplier [ index ] . setSelectedItem ( floatToStr ( GameConstants : : normalMultiplier , 1 ) ) ;
2013-11-01 20:48:04 +01:00
listBoxRMultiplier [ index ] . setEnabled ( false ) ;
}
2011-09-27 03:11:11 +02:00
listBoxRMultiplier [ index ] . setEditable ( listBoxRMultiplier [ index ] . getEnabled ( ) ) ;
listBoxRMultiplier [ index ] . setVisible ( listBoxRMultiplier [ index ] . getEnabled ( ) ) ;
}
2012-11-17 02:04:04 +01:00
void MenuStateConnectedGame : : mouseClickAdmin ( int x , int y , MouseButton mouseButton , string advanceToItemStartingWith ) {
2011-09-24 09:46:56 +02:00
try {
if ( buttonPlayNow . mouseClick ( x , y ) & & buttonPlayNow . getEnabled ( ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
PlayNow ( true ) ;
return ;
}
2011-12-03 09:17:49 +01:00
else if ( buttonRestoreLastSettings . mouseClick ( x , y ) & & buttonRestoreLastSettings . getEnabled ( ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-05-26 04:44:36 +02:00
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
RestoreLastGameSettings ( ) ;
2011-12-03 09:17:49 +01:00
}
2013-06-23 07:37:47 +02:00
else if ( checkBoxAllowNativeLanguageTechtree . mouseClick ( x , y ) ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
}
2012-11-17 02:04:04 +01:00
else if ( listBoxMap . mouseClick ( x , y , advanceToItemStartingWith ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , getCurrentMapFile ( ) . c_str ( ) ) ;
2013-12-17 08:54:33 +01:00
if ( loadMapInfo ( Config : : getMapPath ( getCurrentMapFile ( ) , " " , false ) , & mapInfo , true ) = = true ) {
2011-12-05 06:26:48 +01:00
labelMapInfo . setText ( mapInfo . desc ) ;
}
else {
labelMapInfo . setText ( " ??? " ) ;
}
2011-10-15 03:39:59 +02:00
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
else if ( listBoxFogOfWar . mouseClick ( x , y ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
2012-10-22 19:53:48 +02:00
else if ( checkBoxAllowObservers . mouseClick ( x , y ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
2012-10-22 19:53:48 +02:00
else if ( checkBoxEnableSwitchTeamMode . mouseClick ( x , y ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
else if ( listBoxAISwitchTeamAcceptPercent . getEnabled ( ) & & listBoxAISwitchTeamAcceptPercent . mouseClick ( x , y ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
2012-09-17 01:42:56 +02:00
else if ( listBoxFallbackCpuMultiplier . getEnabled ( ) & & listBoxFallbackCpuMultiplier . mouseClick ( x , y ) ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
}
2012-11-17 02:04:04 +01:00
else if ( listBoxTileset . mouseClick ( x , y , advanceToItemStartingWith ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
2012-11-17 02:04:04 +01:00
else if ( listBoxTechTree . mouseClick ( x , y , advanceToItemStartingWith ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-28 05:46:36 +01:00
reloadFactions ( false , " " ) ;
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
else {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2012-05-11 07:11:46 +02:00
// set multiplier
if ( listBoxRMultiplier [ i ] . mouseClick ( x , y ) ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
//broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
}
2011-09-24 09:46:56 +02:00
2012-10-06 18:09:49 +02:00
//ensure that only 1 human player is present
2011-09-28 17:51:13 +02:00
if ( clientInterface ! = NULL & & clientInterface - > getGameSettings ( ) ! = NULL & &
2011-10-15 03:03:24 +02:00
clientInterface - > getGameSettings ( ) - > getStartLocationIndex ( clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) ) ! = i & &
2011-09-28 17:51:13 +02:00
listBoxControls [ i ] . mouseClick ( x , y ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
2012-10-06 18:36:03 +02:00
//!! this must be done two times!""
2011-09-28 17:51:13 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
listBoxControls [ i ] . mouseClick ( x , y ) ;
}
2012-10-06 18:13:51 +02:00
if ( ( isHeadlessAdmin ( ) = = true ) & & ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) ) {
2012-10-06 18:09:49 +02:00
listBoxControls [ i ] . mouseClick ( x , y ) ;
}
2012-10-06 18:36:03 +02:00
//!! this must be done two times!""
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
listBoxControls [ i ] . mouseClick ( x , y ) ;
}
2011-09-28 17:51:13 +02:00
2011-09-27 03:11:11 +02:00
updateResourceMultiplier ( i ) ;
2011-09-24 09:46:56 +02:00
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
2013-02-04 09:30:43 +01:00
else if ( clientInterface ! = NULL & & clientInterface - > getGameSettings ( ) - > getStartLocationIndex ( clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) ) ! = i & &
2012-11-17 02:04:04 +01:00
listBoxFactions [ i ] . mouseClick ( x , y , advanceToItemStartingWith ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
// Disallow CPU players to be observers
if ( factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) & &
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuEasy | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpu | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuUltra | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctCpuMega ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
listBoxFactions [ i ] . setSelectedItemIndex ( 0 ) ;
}
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
2013-02-04 09:30:43 +01:00
else if ( clientInterface ! = NULL & & clientInterface - > getGameSettings ( ) - > getStartLocationIndex ( clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) ) ! = i & &
2011-10-15 03:03:24 +02:00
listBoxTeams [ i ] . mouseClick ( x , y ) ) {
2012-03-03 05:33:39 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
if ( factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] ! = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) {
if ( listBoxTeams [ i ] . getSelectedItemIndex ( ) + 1 ! = ( GameConstants : : maxPlayers + fpt_Observer ) ) {
//lastSelectedTeamIndex[i] = listBoxTeams[i].getSelectedItemIndex();
}
}
2011-10-22 02:19:38 +02:00
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
2011-09-24 09:46:56 +02:00
}
}
}
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-09-24 09:46:56 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-03-31 10:28:42 +02:00
showMessageBox ( szBuf , " Error " , false ) ;
2010-04-22 01:13:39 +02:00
}
2011-09-24 09:46:56 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
}
2011-09-24 09:46:56 +02:00
void MenuStateConnectedGame : : PlayNow ( bool saveGame ) {
2011-12-03 09:17:49 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
GameSettings gameSettings = * clientInterface - > getGameSettings ( ) ;
loadGameSettings ( & gameSettings ) ;
2011-09-24 09:46:56 +02:00
if ( saveGame = = true ) {
2011-12-03 09:17:49 +01:00
CoreData : : getInstance ( ) . saveGameSettingsToFile ( HEADLESS_SAVED_GAME_FILENAME , & gameSettings , true ) ;
2011-09-24 09:46:56 +02:00
}
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
//printf("Client sending map [%s] admin key [%d]\n",gameSettings.getMap().c_str(),gameSettings.getMasterserver_admin());
2013-02-15 19:25:10 +01:00
if ( clientInterface - > getJoinGameInProgress ( ) = = true ) {
2013-06-07 02:29:29 +02:00
if ( readyToJoinInProgressGame = = false & & launchingNewGame = = false ) {
2013-03-01 16:56:00 +01:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
char szMsg [ 8096 ] = " " ;
if ( lang . hasString ( " JoinPlayerToCurrentGameLaunch " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " JoinPlayerToCurrentGameLaunch " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) ) ;
2013-03-01 16:56:00 +01:00
}
else {
snprintf ( szMsg , 8096 , " Player: %s is about to join the game, please wait... " , getHumanPlayerName ( ) . c_str ( ) ) ;
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
2013-02-15 19:25:10 +01:00
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2013-05-26 05:35:31 +02:00
launchingNewGame = true ;
2013-03-01 16:56:00 +01:00
clientInterface - > broadcastGameStart ( & gameSettings ) ;
}
2013-02-15 19:25:10 +01:00
return ;
}
else {
2013-05-26 05:35:31 +02:00
launchingNewGame = true ;
2013-02-15 19:25:10 +01:00
broadCastGameSettingsToHeadlessServer ( needToBroadcastServerSettings ) ;
clientInterface - > broadcastGameStart ( & gameSettings ) ;
}
2011-09-24 09:46:56 +02:00
}
string MenuStateConnectedGame : : getCurrentMapFile ( ) {
int mapIndex = listBoxMap . getSelectedItemIndex ( ) ;
2012-11-19 06:27:16 +01:00
if ( mapIndex < 0 ) {
return " " ;
}
2011-09-24 09:46:56 +02:00
return mapFiles [ mapIndex ] ;
}
2011-12-28 05:46:36 +01:00
void MenuStateConnectedGame : : reloadFactions ( bool keepExistingSelectedItem , string scenario ) {
2011-09-24 09:46:56 +02:00
vector < string > results ;
Config & config = Config : : getInstance ( ) ;
2013-11-06 00:35:11 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2011-09-24 09:46:56 +02:00
2011-12-28 05:46:36 +01:00
string scenarioDir = Scenario : : getScenarioDir ( dirList , scenario ) ;
vector < string > techPaths = config . getPathListForType ( ptTechs , scenarioDir ) ;
2013-11-19 07:14:06 +01:00
for ( int idx = 0 ; idx < ( int ) techPaths . size ( ) ; idx + + ) {
2011-09-24 09:46:56 +02:00
string & techPath = techPaths [ idx ] ;
endPathWithSlash ( techPath ) ;
2013-11-19 07:14:06 +01:00
if ( listBoxTechTree . getSelectedItemIndex ( ) > = 0 & & listBoxTechTree . getSelectedItemIndex ( ) < ( int ) techTreeFiles . size ( ) ) {
2011-09-25 07:38:35 +02:00
findDirs ( techPath + techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] + " /factions/ " , results , false , false ) ;
}
2011-09-24 09:46:56 +02:00
if ( results . empty ( ) = = false ) {
break ;
}
}
if ( results . empty ( ) = = true ) {
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error("(2)There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]");
2011-09-24 09:46:56 +02:00
//showGeneralError=true;
//generalErrorToShow = "[#2] There are no factions for the tech tree [" + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "]";
}
2013-10-26 00:09:19 +02:00
vector < string > translatedFactionNames ;
factionFiles = results ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) results . size ( ) ; + + i ) {
2013-10-26 00:09:19 +02:00
results [ i ] = formatString ( results [ i ] ) ;
string translatedString = techTree - > getTranslatedFactionName ( techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] , factionFiles [ i ] ) ;
2013-10-29 22:41:45 +01:00
if ( toLower ( translatedString ) = = toLower ( results [ i ] ) ) {
2013-10-26 00:09:19 +02:00
translatedFactionNames . push_back ( results [ i ] ) ;
}
else {
2013-11-03 22:55:50 +01:00
translatedFactionNames . push_back ( results [ i ] + " ( " + translatedString + " ) " ) ;
2013-10-26 00:09:19 +02:00
}
//printf("FACTIONS i = %d results [%s]\n",i,results[i].c_str());
2013-06-13 10:55:48 +02:00
2013-10-26 00:09:19 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " Tech [%s] has faction [%s] \n " , techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] . c_str ( ) , results [ i ] . c_str ( ) ) ;
}
2011-09-24 09:46:56 +02:00
2013-11-06 00:35:11 +01:00
results . push_back ( formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) ;
factionFiles . push_back ( formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) ;
translatedFactionNames . push_back ( " * " + lang . getString ( " Random " , " " , true ) + " * " ) ;
// Add special Observer Faction
if ( checkBoxAllowObservers . getValue ( ) = = 1 ) {
results . push_back ( formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ;
factionFiles . push_back ( formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ;
translatedFactionNames . push_back ( " * " + lang . getString ( " Observer " , " " , true ) + " * " ) ;
}
2011-09-24 09:46:56 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2013-10-26 00:09:19 +02:00
int originalIndex = listBoxFactions [ i ] . getSelectedItemIndex ( ) ;
string originalValue = ( listBoxFactions [ i ] . getItemCount ( ) > 0 ? listBoxFactions [ i ] . getSelectedItem ( ) : " " ) ;
2011-09-24 09:46:56 +02:00
2013-06-13 10:55:48 +02:00
listBoxFactions [ i ] . setItems ( results , translatedFactionNames ) ;
2011-09-24 09:46:56 +02:00
if ( keepExistingSelectedItem = = false | |
2012-10-22 19:53:48 +02:00
( checkBoxAllowObservers . getValue ( ) = = true & &
2011-09-24 09:46:56 +02:00
originalValue = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ) {
listBoxFactions [ i ] . setSelectedItemIndex ( i % results . size ( ) ) ;
if ( originalValue = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) & &
listBoxFactions [ i ] . getSelectedItem ( ) ! = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) {
if ( listBoxTeams [ i ] . getSelectedItem ( ) = = intToStr ( GameConstants : : maxPlayers + fpt_Observer ) ) {
listBoxTeams [ i ] . setSelectedItem ( intToStr ( 1 ) ) ;
}
}
}
2013-11-19 07:14:06 +01:00
else if ( originalIndex < ( int ) results . size ( ) ) {
2011-09-24 09:46:56 +02:00
listBoxFactions [ i ] . setSelectedItemIndex ( originalIndex ) ;
}
}
}
void MenuStateConnectedGame : : loadGameSettings ( GameSettings * gameSettings ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
int factionCount = 0 ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
// Test flags values
//gameSettings->setFlagTypes1(ft1_show_map_resources);
//
2011-12-26 07:29:14 +01:00
if ( checkBoxScenario . getValue ( ) = = true ) {
gameSettings - > setScenario ( scenarioInfo . name ) ;
gameSettings - > setScenarioDir ( Scenario : : getScenarioPath ( dirList , scenarioInfo . name ) ) ;
2011-12-26 08:11:52 +01:00
gameSettings - > setDefaultResources ( scenarioInfo . defaultResources ) ;
gameSettings - > setDefaultUnits ( scenarioInfo . defaultUnits ) ;
gameSettings - > setDefaultVictoryConditions ( scenarioInfo . defaultVictoryConditions ) ;
2011-12-26 07:29:14 +01:00
}
else {
gameSettings - > setScenario ( " " ) ;
gameSettings - > setScenarioDir ( " " ) ;
}
2013-06-23 07:37:47 +02:00
gameSettings - > setNetworkAllowNativeLanguageTechtree ( checkBoxAllowNativeLanguageTechtree . getValue ( ) ) ;
2012-11-10 07:37:23 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] listBoxMap.getSelectedItemIndex() = %d, mapFiles.size() = " MG_SIZE_T_SPECIFIER " , getCurrentMapFile() [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , listBoxMap . getSelectedItemIndex ( ) , mapFiles . size ( ) , getCurrentMapFile ( ) . c_str ( ) ) ;
2012-03-03 05:33:39 +01:00
2013-11-19 07:14:06 +01:00
if ( listBoxMap . getSelectedItemIndex ( ) > = 0 & & listBoxMap . getSelectedItemIndex ( ) < ( int ) mapFiles . size ( ) ) {
2011-11-05 02:27:34 +01:00
gameSettings - > setDescription ( formatString ( getCurrentMapFile ( ) ) ) ;
gameSettings - > setMap ( getCurrentMapFile ( ) ) ;
}
else {
Lang & lang = Lang : : getInstance ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-11-05 02:27:34 +01:00
if ( lang . hasString ( " DataMissingMap=Player " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingMap=Player " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , listBoxMap . getSelectedItem ( ) . c_str ( ) ) ;
2011-11-05 02:27:34 +01:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is missing the map: %s " , getHumanPlayerName ( ) . c_str ( ) , listBoxMap . getSelectedItem ( ) . c_str ( ) ) ;
2011-11-05 02:27:34 +01:00
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
}
2013-11-19 07:14:06 +01:00
if ( listBoxTileset . getSelectedItemIndex ( ) > = 0 & & listBoxTileset . getSelectedItemIndex ( ) < ( int ) tilesetFiles . size ( ) ) {
2011-11-05 02:17:11 +01:00
gameSettings - > setTileset ( tilesetFiles [ listBoxTileset . getSelectedItemIndex ( ) ] ) ;
}
else {
2011-12-03 09:17:49 +01:00
//printf("A loadGameSettings listBoxTileset.getSelectedItemIndex() = %d tilesetFiles.size() = %d\n",listBoxTileset.getSelectedItemIndex(),tilesetFiles.size());
2011-11-05 02:17:11 +01:00
Lang & lang = Lang : : getInstance ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-11-05 02:17:11 +01:00
if ( lang . hasString ( " DataMissingTileset=Player " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTileset=Player " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , listBoxTileset . getSelectedItem ( ) . c_str ( ) ) ;
2011-11-05 02:17:11 +01:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is missing the tileset: %s " , getHumanPlayerName ( ) . c_str ( ) , listBoxTileset . getSelectedItem ( ) . c_str ( ) ) ;
2011-11-05 02:17:11 +01:00
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
}
2013-11-19 07:14:06 +01:00
if ( listBoxTechTree . getSelectedItemIndex ( ) > = 0 & & listBoxTechTree . getSelectedItemIndex ( ) < ( int ) techTreeFiles . size ( ) ) {
2011-11-05 02:17:11 +01:00
gameSettings - > setTech ( techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] ) ;
}
else {
Lang & lang = Lang : : getInstance ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-11-05 02:17:11 +01:00
if ( lang . hasString ( " DataMissingTechtree=Player " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTechtree=Player " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , listBoxTechTree . getSelectedItem ( ) . c_str ( ) ) ;
2011-11-05 02:17:11 +01:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is missing the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , listBoxTechTree . getSelectedItem ( ) . c_str ( ) ) ;
2011-11-05 02:17:11 +01:00
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
}
2011-09-24 09:46:56 +02:00
2011-12-26 08:11:52 +01:00
if ( checkBoxScenario . getValue ( ) = = false ) {
gameSettings - > setDefaultUnits ( true ) ;
gameSettings - > setDefaultResources ( true ) ;
gameSettings - > setDefaultVictoryConditions ( true ) ;
}
2011-09-24 09:46:56 +02:00
gameSettings - > setFogOfWar ( listBoxFogOfWar . getSelectedItemIndex ( ) = = 0 | |
listBoxFogOfWar . getSelectedItemIndex ( ) = = 1 ) ;
2012-10-22 19:53:48 +02:00
gameSettings - > setAllowObservers ( checkBoxAllowObservers . getValue ( ) = = true ) ;
2011-09-24 09:46:56 +02:00
uint32 valueFlags1 = gameSettings - > getFlagTypes1 ( ) ;
if ( listBoxFogOfWar . getSelectedItemIndex ( ) = = 1 | |
listBoxFogOfWar . getSelectedItemIndex ( ) = = 2 ) {
valueFlags1 | = ft1_show_map_resources ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_show_map_resources ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
2011-11-21 03:08:51 +01:00
//gameSettings->setEnableObserverModeAtEndGame(listBoxEnableObserverMode.getSelectedItemIndex() == 0);
gameSettings - > setEnableObserverModeAtEndGame ( true ) ;
2012-09-22 23:44:30 +02:00
//gameSettings->setPathFinderType(static_cast<PathFinderType>(listBoxPathFinderType.getSelectedItemIndex()));
2011-09-24 09:46:56 +02:00
valueFlags1 = gameSettings - > getFlagTypes1 ( ) ;
2012-10-22 19:53:48 +02:00
if ( checkBoxEnableSwitchTeamMode . getValue ( ) = = true ) {
2011-09-24 09:46:56 +02:00
valueFlags1 | = ft1_allow_team_switching ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
else {
valueFlags1 & = ~ ft1_allow_team_switching ;
gameSettings - > setFlagTypes1 ( valueFlags1 ) ;
}
gameSettings - > setAiAcceptSwitchTeamPercentChance ( strToInt ( listBoxAISwitchTeamAcceptPercent . getSelectedItem ( ) ) ) ;
2012-09-17 01:42:56 +02:00
gameSettings - > setFallbackCpuMultiplier ( listBoxFallbackCpuMultiplier . getSelectedItemIndex ( ) ) ;
2011-09-24 09:46:56 +02:00
// First save Used slots
//for(int i=0; i<mapInfo.players; ++i)
int AIPlayerCount = 0 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct ! = ctClosed ) {
int slotIndex = factionCount ;
2012-10-07 00:56:19 +02:00
ControlType oldControlType = gameSettings - > getFactionControl ( slotIndex ) ;
2011-09-24 09:46:56 +02:00
gameSettings - > setFactionControl ( slotIndex , ct ) ;
if ( ct = = ctHuman ) {
2012-01-06 07:55:27 +01:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, slotIndex = %d, getHumanPlayerName(i) [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,slotIndex,getHumanPlayerName(i).c_str());
2011-09-24 09:46:56 +02:00
gameSettings - > setThisFactionIndex ( slotIndex ) ;
2011-10-01 10:04:30 +02:00
gameSettings - > setNetworkPlayerName ( slotIndex , getHumanPlayerName ( ) ) ;
2013-06-01 04:31:12 +02:00
gameSettings - > setNetworkPlayerUUID ( slotIndex , Config : : getInstance ( ) . getString ( " PlayerId " , " " ) ) ;
2013-11-02 20:05:59 +01:00
gameSettings - > setNetworkPlayerPlatform ( slotIndex , getPlatformNameString ( ) ) ;
2011-09-24 09:46:56 +02:00
gameSettings - > setNetworkPlayerStatuses ( slotIndex , getNetworkPlayerStatus ( ) ) ;
Lang & lang = Lang : : getInstance ( ) ;
gameSettings - > setNetworkPlayerLanguages ( slotIndex , lang . getLanguage ( ) ) ;
2013-11-01 20:48:04 +01:00
2013-11-02 23:30:16 +01:00
gameSettings - > setResourceMultiplierIndex ( slotIndex , 5 ) ;
2013-11-01 20:48:04 +01:00
}
else {
gameSettings - > setResourceMultiplierIndex ( slotIndex , listBoxRMultiplier [ i ] . getSelectedItemIndex ( ) ) ;
2011-09-24 09:46:56 +02:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] . c_str ( ) ) ;
2011-09-24 09:46:56 +02:00
gameSettings - > setFactionTypeName ( slotIndex , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] ) ;
if ( factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] = = formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) {
listBoxTeams [ i ] . setSelectedItem ( intToStr ( GameConstants : : maxPlayers + fpt_Observer ) ) ;
}
gameSettings - > setTeam ( slotIndex , listBoxTeams [ i ] . getSelectedItemIndex ( ) ) ;
gameSettings - > setStartLocationIndex ( slotIndex , i ) ;
2011-10-01 10:04:30 +02:00
//printf("!!! setStartLocationIndex #1 slotIndex = %d, i = %d\n",slotIndex, i);
2011-09-24 09:46:56 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | | listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
2012-10-07 00:56:19 +02:00
if ( oldControlType ! = ctNetwork & & oldControlType ! = ctNetworkUnassigned ) {
gameSettings - > setNetworkPlayerName ( slotIndex , " " ) ;
}
2011-09-24 09:46:56 +02:00
}
else if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctHuman ) {
AIPlayerCount + + ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, playername is AI (blank) \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i ) ;
2011-09-24 09:46:56 +02:00
2012-06-12 01:50:30 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2013-10-29 07:13:38 +01:00
gameSettings - > setNetworkPlayerName ( slotIndex , lang . getString ( " AI " ) + intToStr ( AIPlayerCount ) ) ;
2011-09-24 09:46:56 +02:00
labelPlayerNames [ i ] . setText ( " " ) ;
}
factionCount + + ;
}
else {
labelPlayerNames [ i ] . setText ( " " ) ;
}
}
// Next save closed slots
int closedCount = 0 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct = = ctClosed ) {
int slotIndex = factionCount + closedCount ;
gameSettings - > setFactionControl ( slotIndex , ct ) ;
gameSettings - > setTeam ( slotIndex , listBoxTeams [ i ] . getSelectedItemIndex ( ) ) ;
gameSettings - > setStartLocationIndex ( slotIndex , i ) ;
2011-10-01 10:04:30 +02:00
//printf("!!! setStartLocationIndex #2 slotIndex = %d, i = %d\n",slotIndex, i);
2013-11-02 23:30:16 +01:00
gameSettings - > setResourceMultiplierIndex ( slotIndex , 5 ) ;
2011-09-24 09:46:56 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , i , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] . c_str ( ) ) ;
2011-09-24 09:46:56 +02:00
gameSettings - > setFactionTypeName ( slotIndex , factionFiles [ listBoxFactions [ i ] . getSelectedItemIndex ( ) ] ) ;
2012-10-07 00:18:09 +02:00
gameSettings - > setNetworkPlayerStatuses ( slotIndex , npst_None ) ;
2011-09-24 09:46:56 +02:00
gameSettings - > setNetworkPlayerName ( slotIndex , " Closed " ) ;
closedCount + + ;
}
}
gameSettings - > setFactionCount ( factionCount ) ;
Config & config = Config : : getInstance ( ) ;
gameSettings - > setEnableServerControlledAI ( config . getBool ( " ServerControlledAI " , " true " ) ) ;
gameSettings - > setNetworkFramePeriod ( config . getInt ( " NetworkSendFrameCount " , " 20 " ) ) ;
if ( hasNetworkGameSettings ( ) = = true ) {
if ( gameSettings - > getTileset ( ) ! = " " ) {
if ( lastCheckedCRCTilesetName ! = gameSettings - > getTileset ( ) ) {
//console.addLine("Checking tileset CRC [" + gameSettings->getTileset() + "]");
2012-02-10 17:53:56 +01:00
lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + gameSettings - > getTileset ( ) + string ( " /* " ) , " .xml " , NULL ) ;
2013-06-25 01:36:03 +02:00
if ( lastCheckedCRCTilesetValue = = 0 | | lastCheckedCRCTilesetValue ! = gameSettings - > getTilesetCRC ( ) ) {
2012-02-10 17:53:56 +01:00
lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + gameSettings - > getTileset ( ) + string ( " /* " ) , " .xml " , NULL , true ) ;
}
2011-09-24 09:46:56 +02:00
lastCheckedCRCTilesetName = gameSettings - > getTileset ( ) ;
}
gameSettings - > setTilesetCRC ( lastCheckedCRCTilesetValue ) ;
}
if ( config . getBool ( " DisableServerLobbyTechtreeCRCCheck " , " false " ) = = false ) {
if ( gameSettings - > getTech ( ) ! = " " ) {
if ( lastCheckedCRCTechtreeName ! = gameSettings - > getTech ( ) ) {
//console.addLine("Checking techtree CRC [" + gameSettings->getTech() + "]");
lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /* " , " .xml " , NULL ) ;
2013-06-25 01:36:03 +02:00
if ( lastCheckedCRCTechtreeValue = = 0 | | lastCheckedCRCTechtreeValue ! = gameSettings - > getTechCRC ( ) ) {
2011-09-24 09:46:56 +02:00
lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /* " , " .xml " , NULL , true ) ;
}
2011-12-28 05:46:36 +01:00
reloadFactions ( true , gameSettings - > getScenario ( ) ) ;
2011-09-24 09:46:56 +02:00
factionCRCList . clear ( ) ;
for ( unsigned int factionIdx = 0 ; factionIdx < factionFiles . size ( ) ; + + factionIdx ) {
string factionName = factionFiles [ factionIdx ] ;
if ( factionName ! = GameConstants : : RANDOMFACTION_SLOTNAME & &
factionName ! = GameConstants : : OBSERVER_SLOTNAME ) {
//factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true);
2012-07-07 04:46:57 +02:00
uint32 factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL ) ;
2011-09-24 09:46:56 +02:00
if ( factionCRC = = 0 ) {
factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL , true ) ;
}
factionCRCList . push_back ( make_pair ( factionName , factionCRC ) ) ;
}
}
//console.addLine("Found factions: " + intToStr(factionCRCList.size()));
lastCheckedCRCTechtreeName = gameSettings - > getTech ( ) ;
}
gameSettings - > setFactionCRCList ( factionCRCList ) ;
gameSettings - > setTechCRC ( lastCheckedCRCTechtreeValue ) ;
}
}
if ( gameSettings - > getMap ( ) ! = " " ) {
if ( lastCheckedCRCMapName ! = gameSettings - > getMap ( ) ) {
Checksum checksum ;
2013-12-17 08:54:33 +01:00
string file = Config : : getMapPath ( gameSettings - > getMap ( ) , " " , false ) ;
2011-09-24 09:46:56 +02:00
//console.addLine("Checking map CRC [" + file + "]");
checksum . addFile ( file ) ;
lastCheckedCRCMapValue = checksum . getSum ( ) ;
lastCheckedCRCMapName = gameSettings - > getMap ( ) ;
}
gameSettings - > setMapCRC ( lastCheckedCRCMapValue ) ;
}
}
//replace server player by network
for ( int i = 0 ; i < gameSettings - > getFactionCount ( ) ; + + i ) {
//replace by network
if ( gameSettings - > getFactionControl ( i ) = = ctHuman ) {
gameSettings - > setFactionControl ( i , ctNetwork ) ;
}
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] Line: %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-09-24 09:46:56 +02:00
}
2010-07-02 18:54:28 +02:00
void MenuStateConnectedGame : : returnToJoinMenu ( ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-07-02 18:54:28 +02:00
2012-10-16 01:10:41 +02:00
if ( modHttpServerThread ! = NULL ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-06-01 08:28:03 +02:00
modHttpServerThread - > setSimpleTaskInterfaceValid ( false ) ;
2012-10-16 01:10:41 +02:00
modHttpServerThread - > signalQuit ( ) ;
//modHttpServerThread->setThreadOwnerValid(false);
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( modHttpServerThread - > canShutdown ( true ) = = true & &
modHttpServerThread - > shutdownAndWait ( ) = = true ) {
delete modHttpServerThread ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
modHttpServerThread = NULL ;
}
2011-01-10 01:05:31 +01:00
if ( ftpClientThread ! = NULL ) {
2013-01-29 01:10:27 +01:00
ftpClientThread - > setCallBackObject ( NULL ) ;
ftpClientThread - > signalQuit ( ) ;
sleep ( 0 ) ;
if ( ftpClientThread - > canShutdown ( true ) = = true & &
ftpClientThread - > shutdownAndWait ( ) = = true ) {
delete ftpClientThread ;
}
else {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] Error cannot shutdown ftpClientThread \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " %s " , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
}
ftpClientThread = NULL ;
2011-01-10 01:05:31 +01:00
}
2010-07-02 18:54:28 +02:00
if ( returnMenuInfo = = jmSimple ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-05-23 09:12:29 +02:00
launchingNewGame = true ;
disconnectFromServer ( ) ;
2010-05-09 23:23:13 +02:00
mainMenu - > setState ( new MenuStateJoinGame ( program , mainMenu ) ) ;
}
2010-07-02 18:54:28 +02:00
else {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-05-23 09:12:29 +02:00
launchingNewGame = true ;
disconnectFromServer ( ) ;
2010-05-09 23:23:13 +02:00
mainMenu - > setState ( new MenuStateMasterserver ( program , mainMenu ) ) ;
}
}
2011-01-10 01:05:31 +01:00
void MenuStateConnectedGame : : mouseMove ( int x , int y , const MouseState * ms ) {
2010-09-17 08:37:08 +02:00
if ( mainMessageBox . getEnabled ( ) ) {
mainMessageBox . mouseMove ( x , y ) ;
}
2010-12-29 20:31:51 +01:00
if ( ftpMessageBox . getEnabled ( ) ) {
ftpMessageBox . mouseMove ( x , y ) ;
}
2011-04-15 02:09:38 +02:00
buttonCancelDownloads . mouseMove ( x , y ) ;
2010-04-22 01:13:39 +02:00
buttonDisconnect . mouseMove ( x , y ) ;
2011-01-10 01:05:31 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2010-04-22 01:13:39 +02:00
listBoxControls [ i ] . mouseMove ( x , y ) ;
listBoxFactions [ i ] . mouseMove ( x , y ) ;
listBoxTeams [ i ] . mouseMove ( x , y ) ;
2010-04-30 03:08:29 +02:00
grabSlotButton [ i ] . mouseMove ( x , y ) ;
2010-04-22 01:13:39 +02:00
}
2010-08-21 15:04:52 +02:00
2010-04-22 01:13:39 +02:00
listBoxMap . mouseMove ( x , y ) ;
listBoxFogOfWar . mouseMove ( x , y ) ;
2012-10-22 19:53:48 +02:00
checkBoxAllowObservers . mouseMove ( x , y ) ;
2010-04-22 01:13:39 +02:00
listBoxTileset . mouseMove ( x , y ) ;
listBoxTechTree . mouseMove ( x , y ) ;
2011-03-26 14:40:22 +01:00
listBoxPlayerStatus . mouseMove ( x , y ) ;
2011-09-24 09:46:56 +02:00
2011-12-26 07:29:14 +01:00
checkBoxScenario . mouseMove ( x , y ) ;
listBoxScenario . mouseMove ( x , y ) ;
2013-06-19 03:03:51 +02:00
checkBoxAllowNativeLanguageTechtree . mouseMove ( x , y ) ;
2011-09-24 09:46:56 +02:00
buttonPlayNow . mouseMove ( x , y ) ;
2011-12-03 09:17:49 +01:00
buttonRestoreLastSettings . mouseMove ( x , y ) ;
2010-04-22 01:13:39 +02:00
}
2012-06-09 04:59:46 +02:00
bool MenuStateConnectedGame : : isVideoPlaying ( ) {
bool result = false ;
if ( factionVideo ! = NULL ) {
result = factionVideo - > isPlaying ( ) ;
}
return result ;
}
2010-08-31 08:38:27 +02:00
void MenuStateConnectedGame : : render ( ) {
2010-04-22 01:13:39 +02:00
try {
2010-09-17 08:37:08 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
2010-12-29 21:28:25 +01:00
2013-05-31 21:32:20 +02:00
if ( isHeadlessAdmin ( ) = = true ) {
listBoxPlayerStatus . setX ( buttonRestoreLastSettings . getX ( ) +
buttonRestoreLastSettings . getW ( ) + 20 ) ;
}
else {
listBoxPlayerStatus . setX ( nonAdminPlayerStatusX ) ;
}
2010-12-29 21:28:25 +01:00
if ( mainMessageBox . getEnabled ( ) ) {
2010-09-17 08:37:08 +02:00
renderer . renderMessageBox ( & mainMessageBox ) ;
}
2010-12-29 20:31:51 +01:00
2012-10-16 07:27:51 +02:00
renderer . renderButton ( & buttonDisconnect ) ;
2012-09-27 01:16:29 +02:00
if ( initialSettingsReceivedFromServer = = false ) {
return ;
}
2010-07-08 10:29:51 +02:00
2010-08-31 08:38:27 +02:00
if ( factionTexture ! = NULL ) {
2012-09-27 01:16:29 +02:00
if ( factionVideo = = NULL | | factionVideo - > isPlaying ( ) = = false ) {
renderer . renderTextureQuad ( 800 , 600 , 200 , 150 , factionTexture , 1 ) ;
}
2010-08-31 08:38:27 +02:00
}
2012-05-26 01:00:36 +02:00
if ( factionVideo ! = NULL ) {
if ( factionVideo - > isPlaying ( ) = = true ) {
factionVideo - > playFrame ( false ) ;
}
2012-09-26 00:52:07 +02:00
else {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false & &
2013-11-19 22:57:28 +01:00
: : Shared : : Graphics : : VideoPlayer : : hasBackEndVideoPlayer ( ) = = true ) {
2012-09-26 00:52:07 +02:00
if ( factionVideo ! = NULL ) {
factionVideo - > closePlayer ( ) ;
delete factionVideo ;
factionVideo = NULL ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( clientInterface ! = NULL ) {
initFactionPreview ( clientInterface - > getGameSettings ( ) ) ;
}
}
}
}
2012-05-26 01:00:36 +02:00
}
2011-04-13 03:11:23 +02:00
if ( mapPreviewTexture ! = NULL ) {
2013-12-31 08:32:06 +01:00
//renderer.renderTextureQuad(5,185,150,150,mapPreviewTexture,1.0f);
renderer . renderTextureQuad ( this - > render_mapPreviewTexture_X ,
this - > render_mapPreviewTexture_Y ,
this - > render_mapPreviewTexture_W ,
this - > render_mapPreviewTexture_H ,
mapPreviewTexture , 1.0f ) ;
2014-01-03 19:19:10 +01:00
if ( this - > zoomedMap = = true ) {
return ;
}
2011-04-13 03:11:23 +02:00
//printf("=================> Rendering map preview texture\n");
}
2010-08-31 08:38:27 +02:00
2011-12-26 07:29:14 +01:00
if ( scenarioLogoTexture ! = NULL ) {
renderer . renderTextureQuad ( 300 , 350 , 400 , 300 , scenarioLogoTexture , 1.0f ) ;
//renderer.renderBackground(scenarioLogoTexture);
}
2010-04-22 01:13:39 +02:00
renderer . renderButton ( & buttonDisconnect ) ;
2010-10-22 09:28:55 +02:00
// Get a reference to the player texture cache
std : : map < int , Texture2D * > & crcPlayerTextureCache = CacheManager : : getCachedItem < std : : map < int , Texture2D * > > ( GameConstants : : playerTextureCacheLookupKey ) ;
2010-11-06 00:12:46 +01:00
// START - this code ensure player title and player names don't overlap
int offsetPosition = 0 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
const Metrics & metrics = Metrics : : getInstance ( ) ;
2011-11-02 18:17:28 +01:00
FontMetrics * fontMetrics = NULL ;
if ( Renderer : : renderText3DEnabled = = false ) {
fontMetrics = CoreData : : getInstance ( ) . getMenuFontNormal ( ) - > getMetrics ( ) ;
}
else {
fontMetrics = CoreData : : getInstance ( ) . getMenuFontNormal3D ( ) - > getMetrics ( ) ;
}
2010-11-06 00:12:46 +01:00
if ( fontMetrics = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " fontMetrics == NULL " ) ;
2010-11-06 00:12:46 +01:00
}
int curWidth = ( metrics . toVirtualX ( fontMetrics - > getTextWidth ( labelPlayers [ i ] . getText ( ) ) ) ) ;
if ( labelPlayers [ i ] . getX ( ) + curWidth > = labelPlayerNames [ i ] . getX ( ) ) {
int newOffsetPosition = labelPlayers [ i ] . getX ( ) + curWidth + 2 ;
if ( offsetPosition < newOffsetPosition ) {
offsetPosition = newOffsetPosition ;
}
}
}
// END
2011-03-11 12:11:46 +01:00
renderer . renderListBox ( & listBoxPlayerStatus ) ;
2012-06-22 16:30:48 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
2010-10-22 09:28:55 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-09-01 23:54:31 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned ) {
//printf("Player #%d [%s] control = %d\n",i,labelPlayerNames[i].getText().c_str(),listBoxControls[i].getSelectedItemIndex());
labelPlayers [ i ] . setVisible ( true ) ;
labelPlayerNames [ i ] . setVisible ( true ) ;
listBoxControls [ i ] . setVisible ( true ) ;
2012-10-05 01:28:27 +02:00
listBoxRMultiplier [ i ] . setVisible ( true ) ;
2011-09-01 23:54:31 +02:00
listBoxFactions [ i ] . setVisible ( true ) ;
listBoxTeams [ i ] . setVisible ( true ) ;
labelNetStatus [ i ] . setVisible ( true ) ;
}
2011-04-04 07:06:22 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
renderer . renderLabel ( & labelPlayerStatus [ i ] ) ;
}
2011-03-11 12:11:46 +01:00
2010-10-22 09:28:55 +02:00
if ( crcPlayerTextureCache [ i ] ! = NULL ) {
// Render the player # label the player's color
2012-06-22 16:30:48 +02:00
2010-10-22 09:28:55 +02:00
Vec3f playerColor = crcPlayerTextureCache [ i ] - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ;
2012-06-22 16:30:48 +02:00
if ( clientInterface ! = NULL & &
clientInterface - > getGameSettings ( ) ! = NULL & &
clientInterface - > getGameSettings ( ) - > getMasterserver_admin ( ) > 0 & &
clientInterface - > getGameSettings ( ) - > getMasterserver_admin_faction_index ( ) = = i ) {
2012-09-22 22:13:57 +02:00
if ( difftime ( ( long int ) time ( NULL ) , timerLabelFlash ) < 1 ) {
2012-06-22 16:30:48 +02:00
renderer . renderLabel ( & labelPlayers [ i ] , & playerColor ) ;
}
else {
Vec4f flashColor = Vec4f ( playerColor . x , playerColor . y , playerColor . z , 0.45f ) ;
renderer . renderLabel ( & labelPlayers [ i ] , & flashColor ) ;
}
}
else {
renderer . renderLabel ( & labelPlayers [ i ] , & playerColor ) ;
}
2010-10-22 09:28:55 +02:00
// Blend the color with white so make it more readable
2010-11-02 21:19:56 +01:00
//Vec4f newColor(1.f, 1.f, 1.f, 0.57f);
//renderer.renderLabel(&labelPlayers[i],&newColor);
2010-10-22 09:28:55 +02:00
//int quadWidth = labelPlayerNames[i].getX() - labelPlayers[i].getX() - 5;
//renderer.renderTextureQuad(labelPlayers[i].getX(), labelPlayers[i].getY(), quadWidth, labelPlayers[i].getH(), crcPlayerTextureCache[i],1.0f,&playerColor);
}
else {
renderer . renderLabel ( & labelPlayers [ i ] ) ;
}
2010-11-06 00:12:46 +01:00
if ( offsetPosition > 0 ) {
labelPlayerNames [ i ] . setX ( offsetPosition ) ;
}
2010-04-22 01:13:39 +02:00
renderer . renderListBox ( & listBoxControls [ i ] ) ;
2012-05-11 07:11:46 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
2010-11-09 00:15:50 +01:00
renderer . renderListBox ( & listBoxRMultiplier [ i ] ) ;
2010-04-22 01:13:39 +02:00
renderer . renderListBox ( & listBoxFactions [ i ] ) ;
renderer . renderListBox ( & listBoxTeams [ i ] ) ;
2010-12-29 02:10:53 +01:00
2013-02-16 11:07:36 +01:00
bool canGrabSlot = false ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( clientInterface ! = NULL & & clientInterface - > getJoinGameInProgress ( ) = = true ) {
canGrabSlot = ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork & &
labelNetStatus [ i ] . getText ( ) = = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) | |
( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctHuman & &
listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed & &
listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctNetwork ) ) ;
}
else {
canGrabSlot = ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork & &
labelNetStatus [ i ] . getText ( ) = = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) ;
}
if ( canGrabSlot = = true ) {
2011-11-14 06:44:43 +01:00
if ( i < mapInfo . players ) {
renderer . renderButton ( & grabSlotButton [ i ] ) ;
}
2010-04-29 01:59:37 +02:00
}
2011-09-01 23:54:31 +02:00
else if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) {
2010-04-23 01:18:04 +02:00
renderer . renderLabel ( & labelNetStatus [ i ] ) ;
}
2010-08-21 15:04:52 +02:00
2011-09-01 23:54:31 +02:00
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetworkUnassigned | |
listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) {
2010-08-21 15:04:52 +02:00
if ( labelNetStatus [ i ] . getText ( ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
renderer . renderLabel ( & labelPlayerNames [ i ] ) ;
}
}
2010-04-22 01:13:39 +02:00
}
}
renderer . renderLabel ( & labelStatus ) ;
renderer . renderLabel ( & labelInfo ) ;
2011-01-09 05:49:21 +01:00
2012-09-22 22:13:57 +02:00
if ( difftime ( ( long int ) time ( NULL ) , timerLabelFlash ) < 1 ) {
2011-01-09 05:49:21 +01:00
renderer . renderLabel ( & labelDataSynchInfo , & RED ) ;
}
else {
renderer . renderLabel ( & labelDataSynchInfo , & WHITE ) ;
}
2010-04-22 01:13:39 +02:00
renderer . renderLabel ( & labelMap ) ;
renderer . renderLabel ( & labelFogOfWar ) ;
2010-09-04 03:24:17 +02:00
renderer . renderLabel ( & labelAllowObservers ) ;
2012-09-17 01:42:56 +02:00
renderer . renderLabel ( & labelFallbackCpuMultiplier ) ;
2010-04-22 01:13:39 +02:00
renderer . renderLabel ( & labelTileset ) ;
renderer . renderLabel ( & labelTechTree ) ;
renderer . renderLabel ( & labelControl ) ;
renderer . renderLabel ( & labelFaction ) ;
renderer . renderLabel ( & labelTeam ) ;
2010-09-11 08:08:50 +02:00
renderer . renderLabel ( & labelMapInfo ) ;
2010-04-22 01:13:39 +02:00
renderer . renderListBox ( & listBoxMap ) ;
renderer . renderListBox ( & listBoxFogOfWar ) ;
2012-10-22 19:53:48 +02:00
renderer . renderCheckBox ( & checkBoxAllowObservers ) ;
2010-04-22 01:13:39 +02:00
renderer . renderListBox ( & listBoxTileset ) ;
renderer . renderListBox ( & listBoxTechTree ) ;
2011-09-21 08:51:28 +02:00
renderer . renderLabel ( & labelEnableSwitchTeamMode ) ;
renderer . renderLabel ( & labelAISwitchTeamAcceptPercent ) ;
2012-10-22 19:53:48 +02:00
renderer . renderCheckBox ( & checkBoxEnableSwitchTeamMode ) ;
2011-09-21 08:51:28 +02:00
renderer . renderListBox ( & listBoxAISwitchTeamAcceptPercent ) ;
2012-09-17 01:42:56 +02:00
renderer . renderListBox ( & listBoxFallbackCpuMultiplier ) ;
2011-09-21 08:51:28 +02:00
2011-09-24 09:46:56 +02:00
renderer . renderButton ( & buttonPlayNow ) ;
2011-12-03 09:17:49 +01:00
renderer . renderButton ( & buttonRestoreLastSettings ) ;
2011-09-24 09:46:56 +02:00
2011-12-26 07:29:14 +01:00
renderer . renderCheckBox ( & checkBoxScenario ) ;
renderer . renderLabel ( & labelScenario ) ;
if ( checkBoxScenario . getValue ( ) = = true ) {
renderer . renderListBox ( & listBoxScenario ) ;
}
2013-06-19 03:03:51 +02:00
renderer . renderLabel ( & labelAllowNativeLanguageTechtree ) ;
renderer . renderCheckBox ( & checkBoxAllowNativeLanguageTechtree ) ;
2011-01-04 23:14:42 +01:00
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-05-23 08:11:46 +02:00
// !!! START TEMP MV
//renderer.renderButton(&buttonCancelDownloads);
//fileFTPProgressList.clear();
//fileFTPProgressList["test1a dsa asd asda sdasd asd ad ad"] = make_pair(1,"testa");
//fileFTPProgressList["test2 asdasdasdadas dasdasdasda"] = make_pair(1,"testb");
//fileFTPProgressList["test3 asdasdad asd ada dasdadasdada"] = make_pair(1,"testc");
// !!! END TEMP MV
2011-09-01 01:10:43 +02:00
if ( fileFTPProgressList . empty ( ) = = false ) {
2011-03-27 18:39:19 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2011-04-15 02:09:38 +02:00
renderer . renderButton ( & buttonCancelDownloads ) ;
2013-05-23 08:11:46 +02:00
int xLocation = buttonCancelDownloads . getX ( ) ;
2011-04-15 02:09:38 +02:00
int yLocation = buttonCancelDownloads . getY ( ) - 20 ;
2011-01-04 09:44:00 +01:00
for ( std : : map < string , pair < int , string > > : : iterator iterMap = fileFTPProgressList . begin ( ) ;
iterMap ! = fileFTPProgressList . end ( ) ; + + iterMap ) {
2013-10-29 07:13:38 +01:00
string progressLabelPrefix = lang . getString ( " ModDownloading " ) + " " + iterMap - > first + " " ;
2011-01-16 07:41:48 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nRendering file progress with the following prefix [%s]\n",progressLabelPrefix.c_str());
2011-01-04 23:13:49 +01:00
2011-08-30 23:48:32 +02:00
if ( Renderer : : renderText3DEnabled ) {
renderer . renderProgressBar3D (
iterMap - > second . first ,
2013-05-23 08:11:46 +02:00
xLocation ,
//10,
2011-08-30 23:48:32 +02:00
yLocation ,
CoreData : : getInstance ( ) . getDisplayFontSmall3D ( ) ,
2013-05-23 08:11:46 +02:00
//350,progressLabelPrefix);
300 , progressLabelPrefix ) ;
2011-08-30 23:48:32 +02:00
}
else {
renderer . renderProgressBar (
iterMap - > second . first ,
2013-05-23 08:11:46 +02:00
//10,
xLocation ,
2011-08-30 23:48:32 +02:00
yLocation ,
CoreData : : getInstance ( ) . getDisplayFontSmall ( ) ,
2013-05-23 08:11:46 +02:00
//350,progressLabelPrefix);
300 , progressLabelPrefix ) ;
2011-08-30 23:48:32 +02:00
}
2011-01-04 09:44:00 +01:00
2013-05-23 08:11:46 +02:00
yLocation - = 20 ;
2011-01-04 09:44:00 +01:00
}
}
safeMutexFTPProgress . ReleaseLock ( ) ;
2010-09-14 08:10:48 +02:00
2011-01-09 10:05:34 +01:00
if ( mainMessageBox . getEnabled ( ) ) {
renderer . renderMessageBox ( & mainMessageBox ) ;
}
if ( ftpMessageBox . getEnabled ( ) ) {
renderer . renderMessageBox ( & ftpMessageBox ) ;
}
if ( program ! = NULL ) program - > renderProgramMsgBox ( ) ;
2010-09-26 23:34:00 +02:00
if ( enableMapPreview & & ( mapPreview . hasFileLoaded ( ) = = true ) ) {
2010-09-14 08:10:48 +02:00
int mouseX = mainMenu - > getMouseX ( ) ;
int mouseY = mainMenu - > getMouseY ( ) ;
int mouse2dAnim = mainMenu - > getMouse2dAnim ( ) ;
2011-04-13 03:11:23 +02:00
if ( mapPreviewTexture = = NULL ) {
renderer . renderMouse2d ( mouseX , mouseY , mouse2dAnim ) ;
2013-12-31 08:32:06 +01:00
2011-04-13 03:11:23 +02:00
bool renderAll = ( listBoxFogOfWar . getSelectedItemIndex ( ) = = 2 ) ;
2013-12-31 08:32:06 +01:00
//renderer.renderMapPreview(&mapPreview, renderAll, 10, 350, &mapPreviewTexture);
renderer . renderMapPreview ( & mapPreview , renderAll ,
this - > render_mapPreviewTexture_X ,
this - > render_mapPreviewTexture_Y ,
& mapPreviewTexture ) ;
2011-04-13 03:11:23 +02:00
}
2010-09-14 08:10:48 +02:00
}
2010-09-15 01:02:50 +02:00
renderer . renderChatManager ( & chatManager ) ;
renderer . renderConsole ( & console , showFullConsole , true ) ;
2012-06-22 16:30:48 +02:00
2012-09-22 22:13:57 +02:00
if ( difftime ( ( long int ) time ( NULL ) , timerLabelFlash ) > 2 ) {
2012-06-22 16:30:48 +02:00
timerLabelFlash = time ( NULL ) ;
}
2010-04-22 01:13:39 +02:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2010-04-22 01:13:39 +02:00
}
}
2010-08-23 06:33:21 +02:00
void MenuStateConnectedGame : : update ( ) {
2010-09-02 23:40:43 +02:00
Chrono chrono ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2010-04-22 01:13:39 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2013-06-05 22:25:14 +02:00
ClientInterface * clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
2013-10-29 07:13:38 +01:00
string newLabelConnectionInfo = lang . getString ( " WaitingHost " ) ;
2013-06-05 22:25:14 +02:00
if ( clientInterface ! = NULL & & clientInterface - > getJoinGameInProgress ( ) = = true ) {
2013-10-29 07:13:38 +01:00
newLabelConnectionInfo = lang . getString ( " MGGameStatus2 " ) ;
2013-06-05 22:25:14 +02:00
}
2011-03-16 19:39:53 +01:00
// Test progress bar
//MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
//fileFTPProgressList["test"] = pair<int,string>(difftime(time(NULL),lastNetworkSendPing) * 20,"test file 123");
//safeMutexFTPProgress.ReleaseLock();
//
2010-07-09 20:02:31 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
2011-09-24 09:46:56 +02:00
//printf("#2 admin key [%d] client key [%d]\n",settings->getMasterserver_admin(),clientInterface->getSessionKey());
2012-07-06 00:03:15 +02:00
broadCastGameSettingsToHeadlessServer ( false ) ;
2013-06-23 07:37:47 +02:00
checkBoxAllowNativeLanguageTechtree . setEditable ( isHeadlessAdmin ( ) ) ;
checkBoxAllowNativeLanguageTechtree . setEnabled ( isHeadlessAdmin ( ) ) ;
2012-07-06 00:03:15 +02:00
listBoxMap . setEditable ( isHeadlessAdmin ( ) ) ;
2013-02-15 19:25:10 +01:00
buttonPlayNow . setVisible ( isHeadlessAdmin ( ) | |
clientInterface - > getJoinGameInProgress ( ) = = true ) ;
2012-07-06 00:03:15 +02:00
buttonRestoreLastSettings . setVisible ( isHeadlessAdmin ( ) ) ;
listBoxTechTree . setEditable ( isHeadlessAdmin ( ) ) ;
listBoxTileset . setEditable ( isHeadlessAdmin ( ) ) ;
2012-10-22 19:53:48 +02:00
checkBoxEnableSwitchTeamMode . setEditable ( isHeadlessAdmin ( ) ) ;
2012-07-06 00:03:15 +02:00
listBoxAISwitchTeamAcceptPercent . setEditable ( isHeadlessAdmin ( ) ) ;
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . setEditable ( isHeadlessAdmin ( ) ) ;
2012-07-06 00:03:15 +02:00
listBoxFogOfWar . setEditable ( isHeadlessAdmin ( ) ) ;
2012-10-22 19:53:48 +02:00
checkBoxAllowObservers . setEditable ( isHeadlessAdmin ( ) ) ;
2011-09-24 09:46:56 +02:00
2012-07-06 00:03:15 +02:00
if ( isHeadlessAdmin ( ) = = true ) {
2013-11-19 07:56:09 +01:00
for ( unsigned int i = 0 ; i < ( unsigned int ) GameConstants : : maxPlayers ; + + i ) {
2012-07-06 00:03:15 +02:00
listBoxControls [ i ] . setEditable ( isHeadlessAdmin ( ) ) ;
listBoxRMultiplier [ i ] . setEditable ( isHeadlessAdmin ( ) ) ;
listBoxFactions [ i ] . setEditable ( isHeadlessAdmin ( ) ) ;
listBoxTeams [ i ] . setEditable ( isHeadlessAdmin ( ) ) ;
2011-09-24 09:46:56 +02:00
}
}
2012-09-22 22:13:57 +02:00
if ( difftime ( ( long int ) time ( NULL ) , lastNetworkSendPing ) > = GameConstants : : networkPingInterval ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] about to sendPingMessage... \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-07-09 17:59:49 +02:00
2010-07-09 20:02:31 +02:00
lastNetworkSendPing = time ( NULL ) ;
2012-09-22 22:13:57 +02:00
clientInterface - > sendPingMessage ( GameConstants : : networkPingInterval , ( int64 ) time ( NULL ) ) ;
2010-07-09 19:12:57 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] pingCount = %d, clientInterface->getLastPingLag() = %f, GameConstants::networkPingInterval = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , pingCount , clientInterface - > getLastPingLag ( ) , GameConstants : : networkPingInterval ) ;
2010-07-09 20:49:01 +02:00
// Starting checking timeout after sending at least 3 pings to server
2011-08-31 22:04:50 +02:00
if ( clientInterface - > isConnected ( ) & &
2013-11-07 03:30:23 +01:00
pingCount > = MAX_PING_LAG_COUNT & & clientInterface - > getLastPingLag ( ) > = ( GameConstants : : networkPingInterval * MAX_PING_LAG_COUNT ) ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-08-26 18:03:54 +02:00
2012-10-15 08:54:29 +02:00
clientInterface - > updateLobby ( ) ;
2012-10-15 09:44:44 +02:00
2013-03-06 15:29:49 +01:00
if ( clientInterface - > isConnected ( ) & & clientInterface - > getJoinGameInProgress ( ) = = false & &
2013-11-07 03:30:23 +01:00
pingCount > = MAX_PING_LAG_COUNT & & clientInterface - > getLastPingLag ( ) > = ( GameConstants : : networkPingInterval * MAX_PING_LAG_COUNT ) ) {
2012-10-15 09:44:44 +02:00
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
if ( fileFTPProgressList . empty ( ) = = true ) {
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2013-11-07 03:30:23 +01:00
clientInterface - > sendTextMessage ( lang . getString ( " ConnectionTimedOut " , languageList [ i ] ) + " : " + doubleToStr ( clientInterface - > getLastPingLag ( ) , 2 ) , - 1 , false , languageList [ i ] ) ;
2012-10-15 09:44:44 +02:00
sleep ( 1 ) ;
clientInterface - > close ( ) ;
}
2012-10-15 08:42:52 +02:00
}
2012-10-15 09:44:44 +02:00
}
2010-07-09 20:02:31 +02:00
}
2010-07-09 20:49:01 +02:00
pingCount + + ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-07-09 19:12:57 +02:00
}
2010-07-09 17:01:49 +02:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2010-04-22 01:13:39 +02:00
//update status label
2010-07-08 10:29:51 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
2013-10-29 07:13:38 +01:00
buttonDisconnect . setText ( lang . getString ( " Disconnect " ) ) ;
2010-04-22 01:13:39 +02:00
2010-08-22 10:00:05 +02:00
if ( clientInterface - > getAllowDownloadDataSynch ( ) = = false ) {
2013-10-29 07:13:38 +01:00
string label = lang . getString ( " ConnectedToServer " ) ;
2010-04-22 01:13:39 +02:00
2011-01-09 05:49:21 +01:00
if ( clientInterface - > getServerName ( ) . empty ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " " + clientInterface - > getServerName ( ) ;
}
2010-08-05 07:58:14 +02:00
label = label + " , " + clientInterface - > getVersionString ( ) ;
2011-03-19 06:11:36 +01:00
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = false & &
gameSettings - > getTileset ( ) ! = " " & &
gameSettings - > getTech ( ) ! = " " & &
gameSettings - > getMap ( ) ! = " " ) {
2011-01-09 05:49:21 +01:00
Config & config = Config : : getInstance ( ) ;
2011-03-19 06:11:36 +01:00
2011-02-01 00:01:39 +01:00
MutexSafeWrapper safeMutexFTPProgress ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-03-19 06:11:36 +01:00
2012-07-07 04:46:57 +02:00
uint32 tilesetCRC = lastCheckedCRCTilesetValue ;
2011-03-19 13:04:18 +01:00
if ( lastCheckedCRCTilesetName ! = gameSettings - > getTileset ( ) & &
gameSettings - > getTileset ( ) ! = " " ) {
2011-03-20 01:11:00 +01:00
//console.addLine("Checking tileset CRC [" + gameSettings->getTileset() + "]");
2012-02-10 17:53:56 +01:00
tilesetCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + gameSettings - > getTileset ( ) + string ( " /* " ) , " .xml " , NULL ) ;
2013-06-25 01:36:03 +02:00
if ( tilesetCRC = = 0 | | tilesetCRC ! = gameSettings - > getTilesetCRC ( ) ) {
2012-02-10 17:53:56 +01:00
tilesetCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + gameSettings - > getTileset ( ) + string ( " /* " ) , " .xml " , NULL , true ) ;
}
2013-06-25 01:36:03 +02:00
2011-03-19 06:11:36 +01:00
// Test data synch
//tilesetCRC++;
lastCheckedCRCTilesetValue = tilesetCRC ;
lastCheckedCRCTilesetName = gameSettings - > getTileset ( ) ;
}
2012-07-07 04:46:57 +02:00
uint32 techCRC = lastCheckedCRCTechtreeValue ;
2011-03-19 13:04:18 +01:00
if ( lastCheckedCRCTechtreeName ! = gameSettings - > getTech ( ) & &
gameSettings - > getTech ( ) ! = " " ) {
2011-03-20 01:11:00 +01:00
//console.addLine("Checking techtree CRC [" + gameSettings->getTech() + "]");
2011-03-19 06:11:36 +01:00
techCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , string ( " / " ) + gameSettings - > getTech ( ) + string ( " /* " ) , " .xml " , NULL ) ;
2011-04-15 04:53:05 +02:00
//clientInterface->sendTextMessage("#1 TechCRC = " + intToStr(techCRC) + " remoteCRC = " + intToStr(gameSettings->getTechCRC()),-1, true, "");
2011-04-15 04:39:17 +02:00
2013-12-14 08:04:12 +01:00
if ( techCRC = = 0 | | techCRC ! = gameSettings - > getTechCRC ( ) ) {
2011-04-15 04:44:49 +02:00
techCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , string ( " / " ) + gameSettings - > getTech ( ) + string ( " /* " ) , " .xml " , NULL , true ) ;
2011-04-15 04:53:05 +02:00
//clientInterface->sendTextMessage("#2 TechCRC = " + intToStr(techCRC) + " remoteCRC = " + intToStr(gameSettings->getTechCRC()),-1, true, "");
2011-04-15 04:44:49 +02:00
}
2011-04-13 03:51:15 +02:00
if ( techCRC ! = 0 & & techCRC ! = gameSettings - > getTechCRC ( ) & &
listBoxTechTree . getSelectedItemIndex ( ) > = 0 & &
2013-10-29 07:13:38 +01:00
listBoxTechTree . getSelectedItem ( ) ! = Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) {
2011-04-13 03:51:15 +02:00
2013-11-19 07:14:06 +01:00
//time_t now = time(NULL);
2011-04-13 03:51:15 +02:00
time_t lastUpdateDate = getFolderTreeContentsCheckSumRecursivelyLastGenerated ( config . getPathListForType ( ptTechs , " " ) , string ( " / " ) + gameSettings - > getTech ( ) + string ( " /* " ) , " .xml " ) ;
2011-04-15 04:06:50 +02:00
const time_t REFRESH_CRC_DAY_SECONDS = 60 * 60 * 1 ;
2011-04-13 03:51:15 +02:00
if ( lastUpdateDate < = 0 | |
2012-09-22 22:13:57 +02:00
difftime ( ( long int ) time ( NULL ) , lastUpdateDate ) > = REFRESH_CRC_DAY_SECONDS ) {
2011-04-13 03:51:15 +02:00
techCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , string ( " / " ) + gameSettings - > getTech ( ) + string ( " /* " ) , " .xml " , NULL , true ) ;
2011-04-15 04:53:05 +02:00
//clientInterface->sendTextMessage("#3 TechCRC = " + intToStr(techCRC) + " remoteCRC = " + intToStr(gameSettings->getTechCRC()),-1, true, "");
2011-04-13 03:51:15 +02:00
}
}
2011-03-19 06:11:36 +01:00
// Test data synch
//techCRC++;
lastCheckedCRCTechtreeValue = techCRC ;
lastCheckedCRCTechtreeName = gameSettings - > getTech ( ) ;
2011-03-19 13:04:18 +01:00
loadFactions ( gameSettings , false ) ;
factionCRCList . clear ( ) ;
for ( unsigned int factionIdx = 0 ; factionIdx < factionFiles . size ( ) ; + + factionIdx ) {
string factionName = factionFiles [ factionIdx ] ;
2011-03-19 19:05:13 +01:00
if ( factionName ! = GameConstants : : RANDOMFACTION_SLOTNAME & &
factionName ! = GameConstants : : OBSERVER_SLOTNAME & &
2013-10-29 07:13:38 +01:00
factionName ! = Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) {
2011-04-15 03:39:31 +02:00
2012-07-07 04:46:57 +02:00
uint32 factionCRC = 0 ;
2013-11-19 07:14:06 +01:00
//time_t now = time(NULL);
2011-04-15 03:39:31 +02:00
time_t lastUpdateDate = getFolderTreeContentsCheckSumRecursivelyLastGenerated ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " ) ;
const time_t REFRESH_CRC_DAY_SECONDS = 60 * 60 * 24 ;
if ( lastUpdateDate < = 0 | |
2012-09-22 22:13:57 +02:00
difftime ( ( long int ) time ( NULL ) , lastUpdateDate ) > = REFRESH_CRC_DAY_SECONDS | |
2011-04-15 03:54:09 +02:00
( techCRC ! = 0 & & techCRC ! = gameSettings - > getTechCRC ( ) ) ) {
2011-04-15 03:39:31 +02:00
factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL , true ) ;
}
else {
factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL ) ;
}
2011-04-15 04:53:05 +02:00
if ( factionCRC = = 0 ) {
factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL , true ) ;
}
if ( factionCRC ! = 0 ) {
2012-07-07 04:46:57 +02:00
vector < pair < string , uint32 > > serverFactionCRCList = gameSettings - > getFactionCRCList ( ) ;
2011-04-15 04:53:05 +02:00
for ( unsigned int factionIdx1 = 0 ; factionIdx1 < serverFactionCRCList . size ( ) ; + + factionIdx1 ) {
2012-07-07 04:46:57 +02:00
pair < string , uint32 > & serverFaction = serverFactionCRCList [ factionIdx1 ] ;
2011-04-15 04:53:05 +02:00
if ( serverFaction . first = = factionName ) {
if ( serverFaction . second ! = factionCRC ) {
factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL , true ) ;
}
break ;
}
}
}
2011-04-24 06:31:39 +02:00
factionCRCList . push_back ( make_pair ( factionName , factionCRC ) ) ;
2011-03-19 19:05:13 +01:00
}
2011-03-19 13:04:18 +01:00
}
2011-03-20 01:11:00 +01:00
//console.addLine("Found factions: " + intToStr(factionCRCList.size()));
2011-03-19 06:11:36 +01:00
}
2012-07-07 04:46:57 +02:00
uint32 mapCRC = lastCheckedCRCMapValue ;
2011-03-19 13:04:18 +01:00
if ( lastCheckedCRCMapName ! = gameSettings - > getMap ( ) & &
gameSettings - > getMap ( ) ! = " " ) {
2011-03-19 06:11:36 +01:00
Checksum checksum ;
2013-12-17 08:54:33 +01:00
string file = Config : : getMapPath ( gameSettings - > getMap ( ) , " " , false ) ;
2011-03-20 01:11:00 +01:00
//console.addLine("Checking map CRC [" + file + "]");
2011-03-19 06:11:36 +01:00
checksum . addFile ( file ) ;
mapCRC = checksum . getSum ( ) ;
// Test data synch
//mapCRC++;
lastCheckedCRCMapValue = mapCRC ;
lastCheckedCRCMapName = gameSettings - > getMap ( ) ;
}
2011-01-10 08:32:12 +01:00
safeMutexFTPProgress . ReleaseLock ( ) ;
2011-01-09 05:49:21 +01:00
2011-01-14 18:57:37 +01:00
bool dataSynchMismatch = ( ( mapCRC ! = 0 & & mapCRC ! = gameSettings - > getMapCRC ( ) ) | |
2011-03-10 00:09:32 +01:00
( tilesetCRC ! = 0 & & tilesetCRC ! = gameSettings - > getTilesetCRC ( ) ) | |
( techCRC ! = 0 & & techCRC ! = gameSettings - > getTechCRC ( ) ) ) ;
2011-01-09 05:49:21 +01:00
2011-03-11 12:11:46 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nmapCRC [%d] gameSettings->getMapCRC() [%d]\ntilesetCRC [%d] gameSettings->getTilesetCRC() [%d]\ntechCRC [%d] gameSettings->getTechCRC() [%d]\n",mapCRC,gameSettings->getMapCRC(),tilesetCRC,gameSettings->getTilesetCRC(),techCRC,gameSettings->getTechCRC());
2011-01-09 05:49:21 +01:00
if ( dataSynchMismatch = = true ) {
2013-02-15 19:25:10 +01:00
//printf("Data not synched: lmap %u rmap: %u ltile: %d rtile: %u ltech: %u rtech: %u\n",mapCRC,gameSettings->getMapCRC(),tilesetCRC,gameSettings->getTilesetCRC(),techCRC,gameSettings->getTechCRC());
2013-10-29 07:13:38 +01:00
string labelSynch = lang . getString ( " DataNotSynchedTitle " ) ;
2011-01-09 05:49:21 +01:00
2011-03-19 19:11:15 +01:00
if ( mapCRC ! = 0 & & mapCRC ! = gameSettings - > getMapCRC ( ) & &
listBoxMap . getSelectedItemIndex ( ) > = 0 & &
2013-10-29 07:13:38 +01:00
listBoxMap . getSelectedItem ( ) ! = Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) {
labelSynch = labelSynch + " " + lang . getString ( " Map " ) ;
2011-01-09 05:49:21 +01:00
if ( updateDataSynchDetailText = = true & &
2013-10-29 07:13:38 +01:00
lastMapDataSynchError ! = lang . getString ( " DataNotSynchedMap " ) + " " + listBoxMap . getSelectedItem ( ) ) {
lastMapDataSynchError = lang . getString ( " DataNotSynchedMap " ) + " " + listBoxMap . getSelectedItem ( ) ;
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2013-10-29 07:13:38 +01:00
string msg = lang . getString ( " DataNotSynchedMap " , languageList [ i ] ) + " " + listBoxMap . getSelectedItem ( ) ;
2011-04-05 20:39:47 +02:00
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( msg , - 1 , localEcho , languageList [ i ] ) ;
}
2011-01-09 05:49:21 +01:00
}
}
2011-03-19 19:11:15 +01:00
if ( tilesetCRC ! = 0 & & tilesetCRC ! = gameSettings - > getTilesetCRC ( ) & &
listBoxTileset . getSelectedItemIndex ( ) > = 0 & &
2013-10-29 07:13:38 +01:00
listBoxTileset . getSelectedItem ( ) ! = Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) {
labelSynch = labelSynch + " " + lang . getString ( " Tileset " ) ;
2011-01-09 05:49:21 +01:00
if ( updateDataSynchDetailText = = true & &
2013-10-29 07:13:38 +01:00
lastTileDataSynchError ! = lang . getString ( " DataNotSynchedTileset " ) + " " + listBoxTileset . getSelectedItem ( ) ) {
lastTileDataSynchError = lang . getString ( " DataNotSynchedTileset " ) + " " + listBoxTileset . getSelectedItem ( ) ;
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2013-10-29 07:13:38 +01:00
string msg = lang . getString ( " DataNotSynchedTileset " , languageList [ i ] ) + " " + listBoxTileset . getSelectedItem ( ) ;
2011-04-05 20:39:47 +02:00
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( msg , - 1 , localEcho , languageList [ i ] ) ;
}
2011-01-09 05:49:21 +01:00
}
}
2011-03-19 19:11:15 +01:00
if ( techCRC ! = 0 & & techCRC ! = gameSettings - > getTechCRC ( ) & &
listBoxTechTree . getSelectedItemIndex ( ) > = 0 & &
2013-10-29 07:13:38 +01:00
listBoxTechTree . getSelectedItem ( ) ! = Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) {
labelSynch = labelSynch + " " + lang . getString ( " TechTree " ) ;
2011-03-10 00:09:32 +01:00
if ( updateDataSynchDetailText = = true & &
2013-10-29 07:13:38 +01:00
lastTechtreeDataSynchError ! = lang . getString ( " DataNotSynchedTechtree " ) + " " + listBoxTechTree . getSelectedItem ( ) ) {
lastTechtreeDataSynchError = lang . getString ( " DataNotSynchedTechtree " ) + " " + listBoxTechTree . getSelectedItem ( ) ;
2011-01-09 05:49:21 +01:00
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2013-10-29 07:13:38 +01:00
string msg = lang . getString ( " DataNotSynchedTechtree " , languageList [ i ] ) + " " + listBoxTechTree . getSelectedItem ( ) ;
2011-04-05 20:39:47 +02:00
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( msg , - 1 , localEcho , languageList [ i ] ) ;
}
2011-01-09 05:49:21 +01:00
2011-04-19 02:02:23 +02:00
const int MAX_CHAT_TEXT_LINE_LENGTH = 110 ;
2011-04-05 20:39:47 +02:00
//const vector<string> languageList = clientInterface->getGameSettings()->getUniqueNetworkPlayerLanguages();
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
string mismatchedFactionText = " " ;
2011-04-18 04:22:26 +02:00
vector < string > mismatchedFactionTextList ;
2012-07-07 04:46:57 +02:00
vector < pair < string , uint32 > > serverFactionCRCList = gameSettings - > getFactionCRCList ( ) ;
2011-04-05 20:39:47 +02:00
for ( unsigned int factionIdx = 0 ; factionIdx < serverFactionCRCList . size ( ) ; + + factionIdx ) {
2012-07-07 04:46:57 +02:00
pair < string , uint32 > & serverFaction = serverFactionCRCList [ factionIdx ] ;
2011-01-09 05:49:21 +01:00
2011-04-05 20:39:47 +02:00
bool foundFaction = false ;
for ( unsigned int clientFactionIdx = 0 ; clientFactionIdx < factionCRCList . size ( ) ; + + clientFactionIdx ) {
2012-07-07 04:46:57 +02:00
pair < string , uint32 > & clientFaction = factionCRCList [ clientFactionIdx ] ;
2011-04-05 20:39:47 +02:00
if ( serverFaction . first = = clientFaction . first ) {
foundFaction = true ;
if ( serverFaction . second ! = clientFaction . second ) {
2011-04-19 02:02:23 +02:00
if ( mismatchedFactionText . length ( ) > = 10 ) {
2011-04-18 04:22:26 +02:00
mismatchedFactionTextList . push_back ( mismatchedFactionText ) ;
mismatchedFactionText = " " ;
}
2011-04-05 20:39:47 +02:00
if ( mismatchedFactionText = = " " ) {
mismatchedFactionText = " The following factions are mismatched: " ;
if ( lang . hasString ( " MismatchedFactions " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
mismatchedFactionText = lang . getString ( " MismatchedFactions " , languageList [ i ] ) ;
2011-04-05 20:39:47 +02:00
}
mismatchedFactionText + = " [ " + intToStr ( factionCRCList . size ( ) ) + " ][ " + intToStr ( serverFactionCRCList . size ( ) ) + " ] - " ;
}
2011-04-18 05:00:15 +02:00
else {
mismatchedFactionText + = " , " ;
}
mismatchedFactionText + = serverFaction . first ;
2011-04-05 20:39:47 +02:00
}
break ;
}
}
if ( foundFaction = = false ) {
2013-11-19 07:56:09 +01:00
if ( ( int ) mismatchedFactionText . length ( ) > MAX_CHAT_TEXT_LINE_LENGTH ) {
2011-04-18 04:22:26 +02:00
mismatchedFactionTextList . push_back ( mismatchedFactionText ) ;
mismatchedFactionText = " " ;
}
2011-04-05 20:39:47 +02:00
if ( mismatchedFactionText = = " " ) {
mismatchedFactionText = " The following factions are mismatched: " ;
if ( lang . hasString ( " MismatchedFactions " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
mismatchedFactionText = lang . getString ( " MismatchedFactions " , languageList [ i ] ) ;
2011-04-05 20:39:47 +02:00
}
mismatchedFactionText + = " [ " + intToStr ( factionCRCList . size ( ) ) + " ][ " + intToStr ( serverFactionCRCList . size ( ) ) + " ] - " ;
}
2011-04-18 05:00:15 +02:00
else {
mismatchedFactionText + = " , " ;
}
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " MismatchedFactionsMissing " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
mismatchedFactionText + = serverFaction . first + " " + lang . getString ( " MismatchedFactionsMissing " , languageList [ i ] ) ;
2011-04-05 20:39:47 +02:00
}
else {
2011-04-18 05:00:15 +02:00
mismatchedFactionText + = serverFaction . first + " (missing) " ;
2011-04-05 20:39:47 +02:00
}
2011-03-19 13:04:18 +01:00
}
}
2011-01-09 05:49:21 +01:00
2011-04-05 20:39:47 +02:00
for ( unsigned int clientFactionIdx = 0 ; clientFactionIdx < factionCRCList . size ( ) ; + + clientFactionIdx ) {
2012-07-07 04:46:57 +02:00
pair < string , uint32 > & clientFaction = factionCRCList [ clientFactionIdx ] ;
2011-04-05 20:39:47 +02:00
bool foundFaction = false ;
for ( unsigned int factionIdx = 0 ; factionIdx < serverFactionCRCList . size ( ) ; + + factionIdx ) {
2012-07-07 04:46:57 +02:00
pair < string , uint32 > & serverFaction = serverFactionCRCList [ factionIdx ] ;
2011-04-05 20:39:47 +02:00
if ( serverFaction . first = = clientFaction . first ) {
foundFaction = true ;
break ;
}
}
if ( foundFaction = = false ) {
2013-11-19 07:56:09 +01:00
if ( ( int ) mismatchedFactionText . length ( ) > MAX_CHAT_TEXT_LINE_LENGTH ) {
2011-04-18 04:22:26 +02:00
mismatchedFactionTextList . push_back ( mismatchedFactionText ) ;
mismatchedFactionText = " " ;
}
2011-04-05 20:39:47 +02:00
if ( mismatchedFactionText = = " " ) {
mismatchedFactionText = " The following factions are mismatched: " ;
if ( lang . hasString ( " MismatchedFactions " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
mismatchedFactionText = lang . getString ( " MismatchedFactions " , languageList [ i ] ) ;
2011-04-05 20:39:47 +02:00
}
mismatchedFactionText + = " [ " + intToStr ( factionCRCList . size ( ) ) + " ][ " + intToStr ( serverFactionCRCList . size ( ) ) + " ] - " ;
}
2011-04-18 05:00:15 +02:00
else {
mismatchedFactionText + = " , " ;
}
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " MismatchedFactionsExtra " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
mismatchedFactionText + = clientFaction . first + " " + lang . getString ( " MismatchedFactionsExtra " , languageList [ i ] ) ;
2011-04-05 20:39:47 +02:00
}
else {
2011-04-18 05:00:15 +02:00
mismatchedFactionText + = clientFaction . first + " (extra) " ;
2011-04-05 20:39:47 +02:00
}
2011-03-19 13:04:18 +01:00
}
}
2011-04-05 20:39:47 +02:00
if ( mismatchedFactionText ! = " " ) {
2011-09-01 01:10:43 +02:00
if ( mismatchedFactionTextList . empty ( ) = = false ) {
2011-04-18 04:31:36 +02:00
if ( mismatchedFactionText ! = " " ) {
2011-04-18 05:00:15 +02:00
mismatchedFactionText + = " . " ;
2011-04-18 04:31:36 +02:00
mismatchedFactionTextList . push_back ( mismatchedFactionText ) ;
}
2011-04-18 04:22:26 +02:00
for ( unsigned int splitIdx = 0 ; splitIdx < mismatchedFactionTextList . size ( ) ; + + splitIdx ) {
clientInterface - > sendTextMessage ( mismatchedFactionTextList [ splitIdx ] , - 1 , localEcho , languageList [ i ] ) ;
}
}
else {
2011-04-18 05:00:15 +02:00
mismatchedFactionText + = " . " ;
2011-04-18 04:22:26 +02:00
clientInterface - > sendTextMessage ( mismatchedFactionText , - 1 , localEcho , languageList [ i ] ) ;
}
2011-04-05 20:39:47 +02:00
}
}
2011-01-09 05:49:21 +01:00
}
}
updateDataSynchDetailText = false ;
labelDataSynchInfo . setText ( labelSynch ) ;
}
else {
labelDataSynchInfo . setText ( " " ) ;
}
}
2010-04-22 01:13:39 +02:00
if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = true & &
2010-08-22 10:00:05 +02:00
clientInterface - > getNetworkGameDataSynchCheckOk ( ) = = false ) {
label = label + " -synch mismatch for: " ;
if ( clientInterface - > getNetworkGameDataSynchCheckOkMap ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " map " ;
2010-08-22 10:00:05 +02:00
if ( updateDataSynchDetailText = = true & &
clientInterface - > getReceivedDataSynchCheck ( ) & &
2010-08-27 01:04:14 +02:00
lastMapDataSynchError ! = " map CRC mismatch, " + listBoxMap . getSelectedItem ( ) ) {
lastMapDataSynchError = " map CRC mismatch, " + listBoxMap . getSelectedItem ( ) ;
2011-04-05 20:39:47 +02:00
clientInterface - > sendTextMessage ( lastMapDataSynchError , - 1 , true , " " ) ;
2010-08-22 10:00:05 +02:00
}
2010-04-22 01:13:39 +02:00
}
2010-08-22 10:00:05 +02:00
if ( clientInterface - > getNetworkGameDataSynchCheckOkTile ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " tile " ;
2010-08-22 10:00:05 +02:00
if ( updateDataSynchDetailText = = true & &
clientInterface - > getReceivedDataSynchCheck ( ) & &
2010-08-27 01:04:14 +02:00
lastTileDataSynchError ! = " tile CRC mismatch, " + listBoxTileset . getSelectedItem ( ) ) {
lastTileDataSynchError = " tile CRC mismatch, " + listBoxTileset . getSelectedItem ( ) ;
2011-04-05 20:39:47 +02:00
clientInterface - > sendTextMessage ( lastTileDataSynchError , - 1 , true , " " ) ;
2010-08-22 10:00:05 +02:00
}
2010-04-22 01:13:39 +02:00
}
2010-08-22 10:00:05 +02:00
if ( clientInterface - > getNetworkGameDataSynchCheckOkTech ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " techtree " ;
2010-08-22 10:00:05 +02:00
if ( updateDataSynchDetailText = = true & &
clientInterface - > getReceivedDataSynchCheck ( ) ) {
string report = clientInterface - > getNetworkGameDataSynchCheckTechMismatchReport ( ) ;
if ( lastTechtreeDataSynchError ! = " techtree CRC mismatch " + report ) {
lastTechtreeDataSynchError = " techtree CRC mismatch " + report ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] report: %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , report . c_str ( ) ) ;
2010-08-22 10:00:05 +02:00
2011-04-05 20:39:47 +02:00
clientInterface - > sendTextMessage ( " techtree CRC mismatch " , - 1 , true , " " ) ;
2010-08-22 10:00:05 +02:00
vector < string > reportLineTokens ;
Tokenize ( report , reportLineTokens , " \n " ) ;
2013-11-19 07:14:06 +01:00
for ( int reportLine = 0 ; reportLine < ( int ) reportLineTokens . size ( ) ; + + reportLine ) {
2011-04-05 20:39:47 +02:00
clientInterface - > sendTextMessage ( reportLineTokens [ reportLine ] , - 1 , true , " " ) ;
2010-08-22 10:00:05 +02:00
}
}
}
}
if ( clientInterface - > getReceivedDataSynchCheck ( ) = = true ) {
updateDataSynchDetailText = false ;
2010-04-22 01:13:39 +02:00
}
}
2010-08-23 06:33:21 +02:00
else if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = true ) {
2010-04-22 01:13:39 +02:00
label + = " - data synch is ok " ;
}
2010-08-05 01:39:12 +02:00
labelStatus . setText ( label ) ;
2010-04-22 01:13:39 +02:00
}
2010-08-23 06:33:21 +02:00
else {
2013-10-29 07:13:38 +01:00
string label = lang . getString ( " ConnectedToServer " ) ;
2010-04-22 01:13:39 +02:00
2010-08-23 06:33:21 +02:00
if ( ! clientInterface - > getServerName ( ) . empty ( ) ) {
2010-04-22 01:13:39 +02:00
label = label + " " + clientInterface - > getServerName ( ) ;
}
if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = true & &
2010-09-11 08:08:50 +02:00
clientInterface - > getNetworkGameDataSynchCheckOk ( ) = = false ) {
2010-08-22 10:00:05 +02:00
label = label + " -waiting to synch: " ;
2010-09-11 08:08:50 +02:00
if ( clientInterface - > getNetworkGameDataSynchCheckOkMap ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " map " ;
}
2010-09-11 08:08:50 +02:00
if ( clientInterface - > getNetworkGameDataSynchCheckOkTile ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " tile " ;
}
2010-09-11 08:08:50 +02:00
if ( clientInterface - > getNetworkGameDataSynchCheckOkTech ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " techtree " ;
}
}
else if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = true )
{
label + = " - data synch is ok " ;
}
2010-08-05 01:39:12 +02:00
labelStatus . setText ( label ) ;
2010-04-22 01:13:39 +02:00
}
2010-09-02 23:40:43 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-04-22 01:13:39 +02:00
}
2010-07-08 10:29:51 +02:00
else {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-07-08 10:29:51 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) = = true ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
clientInterface - > close ( ) ;
}
2010-09-02 23:40:43 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-05-09 23:23:13 +02:00
returnToJoinMenu ( ) ;
2010-04-23 01:18:04 +02:00
return ;
2010-04-22 01:13:39 +02:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2010-04-22 01:13:39 +02:00
//process network messages
2010-08-26 18:03:54 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-08-26 18:03:54 +02:00
2010-09-17 10:26:22 +02:00
try {
2011-10-22 02:19:38 +02:00
if ( clientInterface - > getGameSettingsReceived ( ) & &
lastGameSettingsReceivedCount ! = clientInterface - > getGameSettingsReceivedCount ( ) ) {
2012-07-06 00:03:15 +02:00
broadCastGameSettingsToHeadlessServer ( needToBroadcastServerSettings ) ;
2011-10-22 02:19:38 +02:00
lastGameSettingsReceivedCount = clientInterface - > getGameSettingsReceivedCount ( ) ;
2010-09-17 10:26:22 +02:00
bool errorOnMissingData = ( clientInterface - > getAllowGameDataSynchCheck ( ) = = false ) ;
2011-12-26 07:29:14 +01:00
GameSettings * gameSettings = clientInterface - > getGameSettingsPtr ( ) ;
2013-02-16 11:07:36 +01:00
//printf("Menu got new settings thisfactionindex = %d startlocation: %d control = %d\n",gameSettings->getThisFactionIndex(),clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()),gameSettings->getFactionControl(clientInterface->getGameSettings()->getThisFactionIndex()));
2011-12-03 09:17:49 +01:00
setupUIFromGameSettings ( gameSettings , errorOnMissingData ) ;
2013-02-15 19:25:10 +01:00
}
// check if we are joining an in progress game
2013-02-27 07:46:42 +01:00
if ( clientInterface - > getJoinGameInProgress ( ) = = true & &
clientInterface - > getJoinGameInProgressLaunch ( ) = = true & &
clientInterface - > getReadyForInGameJoin ( ) = = true & &
2013-02-15 19:25:10 +01:00
ftpClientThread ! = NULL ) {
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
if ( readyToJoinInProgressGame = = false ) {
if ( getInProgressSavedGameFromFTPServer = = " " ) {
2013-05-31 17:33:01 +02:00
getInProgressSavedGameFromFTPServerInProgress = true ;
2013-05-01 22:56:19 +02:00
ftpClientThread - > addTempFileToRequests (
GameConstants : : saveNetworkGameFileClientCompressed ,
GameConstants : : saveNetworkGameFileServerCompressed ) ;
2013-02-16 20:11:36 +01:00
2013-06-02 01:55:21 +02:00
getInProgressSavedGameFromFTPServer = GameConstants : : saveNetworkGameFileServerCompressed ;
2013-02-15 19:25:10 +01:00
fileFTPProgressList [ getInProgressSavedGameFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
}
safeMutexFTPProgress . ReleaseLock ( ) ;
}
else {
safeMutexFTPProgress . ReleaseLock ( ) ;
2013-02-16 20:11:36 +01:00
string saveGameFile = " temp/ " + string ( GameConstants : : saveNetworkGameFileClient ) ;
2013-02-15 19:25:10 +01:00
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
saveGameFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + saveGameFile ;
}
else {
string userData = Config : : getInstance ( ) . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
saveGameFile = userData + saveGameFile ;
}
2013-02-16 20:11:36 +01:00
//printf("Loading saved game file [%s]\n",saveGameFile.c_str());
2013-02-15 19:25:10 +01:00
GameSettings gameSettings = * clientInterface - > getGameSettings ( ) ;
loadGameSettings ( & gameSettings ) ;
Game : : loadGame ( saveGameFile , program , false , & gameSettings ) ;
return ;
}
2010-08-31 08:38:27 +02:00
}
2010-09-02 23:40:43 +02:00
2010-09-17 10:26:22 +02:00
//update lobby
clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
clientInterface - > updateLobby ( ) ;
2010-08-21 15:04:52 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-17 10:26:22 +02:00
}
2010-09-03 00:34:25 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2010-09-17 10:26:22 +02:00
clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
if ( initialSettingsReceivedFromServer = = true & &
clientInterface - > getIntroDone ( ) = = true & &
( switchSetupRequestFlagType & ssrft_NetworkPlayerName ) = = ssrft_NetworkPlayerName ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] getHumanPlayerName() = [%s], clientInterface->getGameSettings()->getThisFactionIndex() = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , getHumanPlayerName ( ) . c_str ( ) , clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) ) ;
2011-04-05 07:32:35 +02:00
clientInterface - > sendSwitchSetupRequest (
" " ,
clientInterface - > getPlayerIndex ( ) ,
- 1 ,
- 1 ,
2011-03-11 12:11:46 +01:00
getHumanPlayerName ( ) ,
getNetworkPlayerStatus ( ) ,
2011-04-05 20:39:47 +02:00
switchSetupRequestFlagType ,
lang . getLanguage ( ) ) ;
2010-10-08 19:17:22 +02:00
2010-09-17 10:26:22 +02:00
switchSetupRequestFlagType = ssrft_None ;
}
2010-08-23 06:33:21 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-03 00:34:25 +02:00
2010-09-17 10:26:22 +02:00
//intro
if ( clientInterface - > getIntroDone ( ) ) {
2013-06-01 20:07:06 +02:00
if ( newLabelConnectionInfo ! = labelInfo . getText ( ) ) {
2013-06-01 19:51:42 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-06-01 20:07:06 +02:00
labelInfo . setText ( newLabelConnectionInfo ) ;
2013-06-01 19:51:42 +02:00
}
2010-09-17 10:26:22 +02:00
}
2010-04-22 01:13:39 +02:00
2010-09-17 10:26:22 +02:00
//launch
if ( clientInterface - > getLaunchGame ( ) ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-06-01 18:54:44 +02:00
2010-09-17 10:26:22 +02:00
assert ( clientInterface ! = NULL ) ;
2010-06-01 18:54:44 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-01-10 01:05:31 +01:00
2012-10-16 01:10:41 +02:00
if ( modHttpServerThread ! = NULL ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-06-01 08:28:03 +02:00
modHttpServerThread - > setSimpleTaskInterfaceValid ( false ) ;
2012-10-16 01:10:41 +02:00
modHttpServerThread - > signalQuit ( ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( modHttpServerThread - > canShutdown ( true ) = = true & &
modHttpServerThread - > shutdownAndWait ( ) = = true ) {
delete modHttpServerThread ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
modHttpServerThread = NULL ;
}
2011-01-10 01:05:31 +01:00
if ( ftpClientThread ! = NULL ) {
2013-01-29 01:10:27 +01:00
ftpClientThread - > setCallBackObject ( NULL ) ;
ftpClientThread - > signalQuit ( ) ;
sleep ( 0 ) ;
if ( ftpClientThread - > canShutdown ( true ) = = true & &
ftpClientThread - > shutdownAndWait ( ) = = true ) {
delete ftpClientThread ;
}
else {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] Error cannot shutdown ftpClientThread \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " %s " , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
}
ftpClientThread = NULL ;
2011-01-10 01:05:31 +01:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2013-05-23 09:12:29 +02:00
launchingNewGame = true ;
2011-09-24 23:07:15 +02:00
program - > setState ( new Game ( program , clientInterface - > getGameSettings ( ) , false ) ) ;
2010-09-17 10:26:22 +02:00
return ;
}
2010-07-08 10:29:51 +02:00
}
2010-12-30 21:48:39 +01:00
//call the chat manager
chatManager . updateNetwork ( ) ;
//console732
console . update ( ) ;
2012-06-14 01:01:10 +02:00
// check for need to switch music on again
2013-02-04 09:30:43 +01:00
if ( clientInterface ! = NULL ) {
GameSettings * gameSettings = clientInterface - > getGameSettingsPtr ( ) ;
int currentConnectionCount = 0 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
if ( gameSettings - > getFactionControl ( i ) = = ctNetwork & &
gameSettings - > getNetworkPlayerName ( i ) ! = " " & &
gameSettings - > getNetworkPlayerName ( i ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME )
{
currentConnectionCount + + ;
}
2012-06-14 01:01:10 +02:00
}
2013-02-04 09:30:43 +01:00
if ( currentConnectionCount > soundConnectionCount ) {
soundConnectionCount = currentConnectionCount ;
SoundRenderer : : getInstance ( ) . playFx ( CoreData : : getInstance ( ) . getAttentionSound ( ) ) ;
//switch on music again!!
Config & config = Config : : getInstance ( ) ;
float configVolume = ( config . getInt ( " SoundVolumeMusic " ) / 100.f ) ;
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( configVolume ) ;
}
2012-06-14 01:01:10 +02:00
soundConnectionCount = currentConnectionCount ;
2013-02-04 09:30:43 +01:00
}
2012-06-14 01:01:10 +02:00
2010-04-22 01:13:39 +02:00
}
2010-09-17 10:26:22 +02:00
catch ( const runtime_error & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-01-06 07:55:27 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , szBuf ) ;
2010-09-17 10:26:22 +02:00
showMessageBox ( szBuf , " Error " , false ) ;
}
2010-09-02 23:40:43 +02:00
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-04-22 01:13:39 +02:00
}
}
2011-12-28 05:46:36 +01:00
bool MenuStateConnectedGame : : loadFactions ( const GameSettings * gameSettings , bool errorOnNoFactions ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2013-11-06 00:35:11 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2010-06-04 00:52:56 +02:00
bool foundFactions = false ;
2010-04-22 01:13:39 +02:00
vector < string > results ;
2011-12-28 05:46:36 +01:00
string scenarioDir = Scenario : : getScenarioDir ( dirList , gameSettings - > getScenario ( ) ) ;
2011-03-19 13:04:18 +01:00
if ( gameSettings - > getTech ( ) ! = " " ) {
Config & config = Config : : getInstance ( ) ;
2011-12-28 05:46:36 +01:00
vector < string > techPaths = config . getPathListForType ( ptTechs , scenarioDir ) ;
2013-11-19 07:14:06 +01:00
for ( int idx = 0 ; idx < ( int ) techPaths . size ( ) ; idx + + ) {
2011-03-19 13:04:18 +01:00
string & techPath = techPaths [ idx ] ;
endPathWithSlash ( techPath ) ;
2011-04-18 04:22:26 +02:00
//findAll(techPath + gameSettings->getTech() + "/factions/*.", results, false, false);
findDirs ( techPath + gameSettings - > getTech ( ) + " /factions/ " , results , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( results . empty ( ) = = false ) {
2011-03-19 13:04:18 +01:00
break ;
2010-06-03 08:03:41 +02:00
}
2010-04-29 09:59:44 +02:00
}
2010-04-22 01:13:39 +02:00
2011-09-01 20:08:56 +02:00
if ( results . empty ( ) = = true ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-09-17 10:46:34 +02:00
2011-03-19 13:04:18 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = false ) {
if ( errorOnNoFactions = = true ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " (2) There are no factions for the tech tree [ " + gameSettings->getTech() + " ] " ) ;
2011-03-19 13:04:18 +01:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] (2)There are no factions for the tech tree [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , gameSettings - > getTech ( ) . c_str ( ) ) ;
2011-03-19 13:04:18 +01:00
}
2013-10-29 07:13:38 +01:00
results . push_back ( Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) ;
2011-03-19 13:04:18 +01:00
factionFiles = results ;
2013-06-13 10:55:48 +02:00
vector < string > translatedFactionNames ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) factionFiles . size ( ) ; + + i ) {
2013-11-03 22:55:50 +01:00
results [ i ] = formatString ( results [ i ] ) ;
2013-10-26 00:09:19 +02:00
string translatedString = techTree - > getTranslatedFactionName ( gameSettings - > getTech ( ) , factionFiles [ i ] ) ;
2013-11-03 22:55:50 +01:00
if ( toLower ( translatedString ) = = toLower ( results [ i ] ) ) {
translatedFactionNames . push_back ( results [ i ] ) ;
2013-10-26 00:09:19 +02:00
}
else {
2013-11-03 22:55:50 +01:00
translatedFactionNames . push_back ( results [ i ] + " ( " + translatedString + " ) " ) ;
2013-10-26 00:09:19 +02:00
}
2013-06-13 10:55:48 +02:00
}
2011-03-19 13:04:18 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2013-06-13 10:55:48 +02:00
listBoxFactions [ i ] . setItems ( results , translatedFactionNames ) ;
2011-03-19 13:04:18 +01:00
}
2010-06-03 08:03:41 +02:00
2011-03-19 13:04:18 +01:00
if ( lastMissingTechtree ! = gameSettings - > getTech ( ) & &
gameSettings - > getTech ( ) ! = " " ) {
lastMissingTechtree = gameSettings - > getTech ( ) ;
2010-09-03 09:12:40 +02:00
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingTechtree " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTechtree " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is missing the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2011-03-19 13:04:18 +01:00
}
2010-04-22 01:13:39 +02:00
2011-03-19 13:04:18 +01:00
foundFactions = false ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-04-29 09:59:44 +02:00
}
2011-03-19 13:04:18 +01:00
else {
lastMissingTechtree = " " ;
getMissingTechtreeFromFTPServer = " " ;
factionFiles = results ;
2013-06-13 10:55:48 +02:00
vector < string > translatedFactionNames ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) factionFiles . size ( ) ; + + i ) {
2013-11-03 22:55:50 +01:00
results [ i ] = formatString ( results [ i ] ) ;
2013-10-26 00:09:19 +02:00
string translatedString = techTree - > getTranslatedFactionName ( gameSettings - > getTech ( ) , factionFiles [ i ] ) ;
2013-11-03 22:55:50 +01:00
if ( toLower ( translatedString ) = = toLower ( results [ i ] ) ) {
translatedFactionNames . push_back ( results [ i ] ) ;
2013-10-26 00:09:19 +02:00
}
else {
2013-11-03 22:55:50 +01:00
translatedFactionNames . push_back ( results [ i ] + " ( " + translatedString + " ) " ) ;
2013-10-26 00:09:19 +02:00
}
2013-06-13 10:55:48 +02:00
}
2013-11-06 00:35:11 +01:00
results . push_back ( formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) ;
factionFiles . push_back ( formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) ;
translatedFactionNames . push_back ( " * " + lang . getString ( " Random " , " " , true ) + " * " ) ;
// Add special Observer Faction
if ( checkBoxAllowObservers . getValue ( ) = = 1 ) {
results . push_back ( formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ;
factionFiles . push_back ( formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ;
translatedFactionNames . push_back ( " * " + lang . getString ( " Observer " , " " , true ) + " * " ) ;
}
2011-03-19 13:04:18 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2013-06-13 10:55:48 +02:00
listBoxFactions [ i ] . setItems ( results , translatedFactionNames ) ;
2011-03-19 13:04:18 +01:00
}
2011-09-01 01:10:43 +02:00
foundFactions = ( results . empty ( ) = = false ) ;
2011-03-19 13:04:18 +01:00
}
2010-04-29 09:59:44 +02:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-06-04 00:52:56 +02:00
return foundFactions ;
2010-04-29 09:59:44 +02:00
}
2010-04-22 01:13:39 +02:00
// ============ PRIVATE ===========================
2013-06-01 19:23:51 +02:00
bool MenuStateConnectedGame : : hasNetworkGameSettings ( ) {
2010-04-22 01:13:39 +02:00
bool hasNetworkSlot = false ;
try {
2011-09-01 23:54:31 +02:00
for ( int i = 0 ; i < mapInfo . players ; + + i ) {
2010-04-22 01:13:39 +02:00
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
2011-09-01 23:54:31 +02:00
if ( ct ! = ctClosed ) {
if ( ct = = ctNetwork | | ct = = ctNetworkUnassigned ) {
2010-04-22 01:13:39 +02:00
hasNetworkSlot = true ;
break ;
}
}
}
2011-09-01 23:54:31 +02:00
if ( hasNetworkSlot = = false ) {
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct ! = ctClosed ) {
if ( ct = = ctNetworkUnassigned ) {
hasNetworkSlot = true ;
break ;
}
}
}
}
2010-04-22 01:13:39 +02:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2012-01-06 07:55:27 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , szBuf ) ;
2010-09-17 08:37:08 +02:00
showMessageBox ( szBuf , " Error " , false ) ;
2010-04-22 01:13:39 +02:00
}
return hasNetworkSlot ;
}
2011-06-26 03:55:08 +02:00
void MenuStateConnectedGame : : keyDown ( SDL_KeyboardEvent key ) {
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL ) {
2012-07-26 08:27:00 +02:00
bool handled = keyDownEditLabel ( key , & activeInputLabel ) ;
if ( handled = = true ) {
switchSetupRequestFlagType | = ssrft_NetworkPlayerName ;
needToSetChangedGameSettings = true ;
2010-08-21 15:04:52 +02:00
lastSetChangedGameSettings = time ( NULL ) ;
}
}
else {
//send key to the chat manager
2012-09-20 00:16:22 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( clientInterface ! = NULL & &
clientInterface - > isConnected ( ) = = true & &
clientInterface - > getIntroDone ( ) = = true ) {
chatManager . keyDown ( key ) ;
}
2012-11-17 02:04:04 +01:00
if ( chatManager . getEditEnabled ( ) = = false & &
2013-11-19 22:57:28 +01:00
( : : Shared : : Platform : : Window : : isKeyStateModPressed ( KMOD_SHIFT ) = = false ) ) {
2010-08-28 03:52:57 +02:00
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2011-06-26 03:55:08 +02:00
if ( isKeyPressed ( configKeys . getSDLKey ( " ShowFullConsole " ) , key ) = = true ) {
2010-08-28 03:52:57 +02:00
showFullConsole = true ;
}
2012-06-14 01:01:10 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " ToggleMusic " ) , key ) = = true ) {
Config & config = Config : : getInstance ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
float configVolume = ( config . getInt ( " SoundVolumeMusic " ) / 100.f ) ;
float currentVolume = CoreData : : getInstance ( ) . getMenuMusic ( ) - > getVolume ( ) ;
if ( currentVolume > 0 ) {
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( 0.f ) ;
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " GameMusic " ) + " " + lang . getString ( " Off " ) ) ;
2012-06-14 01:01:10 +02:00
}
else {
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( configVolume ) ;
//If the config says zero, use the default music volume
//gameMusic->setVolume(configVolume ? configVolume : 0.9);
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " GameMusic " ) ) ;
2012-06-14 01:01:10 +02:00
}
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("SaveGUILayout")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " SaveGUILayout " ) , key ) = = true ) {
2010-09-09 23:07:39 +02:00
bool saved = GraphicComponent : : saveAllCustomProperties ( containerName ) ;
Lang & lang = Lang : : getInstance ( ) ;
2013-10-29 07:13:38 +01:00
console . addLine ( lang . getString ( " GUILayoutSaved " ) + " [ " + ( saved ? lang . getString ( " Yes " ) : lang . getString ( " No " ) ) + " ] " ) ;
2010-09-09 23:07:39 +02:00
}
2010-08-21 15:04:52 +02:00
}
2010-06-09 00:50:37 +02:00
}
2010-04-22 01:13:39 +02:00
}
2011-06-26 03:55:08 +02:00
void MenuStateConnectedGame : : keyPress ( SDL_KeyboardEvent c ) {
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL ) {
2012-07-26 08:27:00 +02:00
bool handled = keyPressEditLabel ( c , & activeInputLabel ) ;
if ( handled = = true ) {
switchSetupRequestFlagType | = ssrft_NetworkPlayerName ;
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
2010-08-21 15:04:52 +02:00
}
else {
2012-09-20 00:16:22 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( clientInterface ! = NULL & &
clientInterface - > isConnected ( ) = = true & &
clientInterface - > getIntroDone ( ) = = true ) {
chatManager . keyPress ( c ) ;
}
2010-08-21 15:04:52 +02:00
}
2010-04-22 01:13:39 +02:00
}
2011-06-26 03:55:08 +02:00
void MenuStateConnectedGame : : keyUp ( SDL_KeyboardEvent key ) {
2010-08-21 15:04:52 +02:00
if ( activeInputLabel = = NULL ) {
2012-09-20 00:16:22 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( clientInterface ! = NULL & &
clientInterface - > isConnected ( ) = = true & &
clientInterface - > getIntroDone ( ) = = true ) {
chatManager . keyUp ( key ) ;
}
2010-08-28 03:52:57 +02:00
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2010-12-30 21:48:39 +01:00
if ( chatManager . getEditEnabled ( ) ) {
2010-08-21 15:04:52 +02:00
//send key to the chat manager
chatManager . keyUp ( key ) ;
}
2011-06-26 03:55:08 +02:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " ShowFullConsole " ) , key ) = = true ) {
2010-08-21 15:04:52 +02:00
showFullConsole = false ;
}
2010-06-09 00:50:37 +02:00
}
2010-08-21 15:04:52 +02:00
}
2010-08-23 06:33:21 +02:00
void MenuStateConnectedGame : : setActiveInputLabel ( GraphicLabel * newLable ) {
2012-07-26 08:27:00 +02:00
MenuState : : setActiveInputLabel ( newLable , & activeInputLabel ) ;
2010-08-21 15:04:52 +02:00
}
string MenuStateConnectedGame : : getHumanPlayerName ( ) {
2010-08-23 06:33:21 +02:00
string result = defaultPlayerName ;
2010-08-21 15:04:52 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
for ( int j = 0 ; j < GameConstants : : maxPlayers ; + + j ) {
2010-08-23 06:33:21 +02:00
if ( clientInterface ! = NULL & &
2010-10-08 03:41:53 +02:00
j = = clientInterface - > getPlayerIndex ( ) & &
2010-08-21 15:04:52 +02:00
labelPlayerNames [ j ] . getText ( ) ! = " " ) {
result = labelPlayerNames [ j ] . getText ( ) ;
2010-08-23 06:33:21 +02:00
if ( activeInputLabel ! = NULL ) {
size_t found = result . find_last_of ( " _ " ) ;
if ( found ! = string : : npos ) {
result = result . substr ( 0 , found ) ;
}
}
2010-08-21 15:04:52 +02:00
break ;
}
}
2010-10-08 19:17:22 +02:00
2010-08-21 15:04:52 +02:00
return result ;
2010-06-08 02:00:28 +02:00
}
2010-08-31 08:38:27 +02:00
void MenuStateConnectedGame : : loadFactionTexture ( string filepath ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-08-31 08:38:27 +02:00
2010-08-31 22:31:20 +02:00
if ( enableFactionTexturePreview = = true ) {
if ( filepath = = " " ) {
factionTexture = NULL ;
}
else {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] filepath = [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , filepath . c_str ( ) ) ;
2012-09-25 09:05:52 +02:00
factionTexture = Renderer : : findTexture ( filepath ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-08-31 22:31:20 +02:00
}
2010-08-31 08:38:27 +02:00
}
}
2010-09-17 10:26:22 +02:00
bool MenuStateConnectedGame : : loadMapInfo ( string file , MapInfo * mapInfo , bool loadMapPreview ) {
2011-12-05 06:26:48 +01:00
bool mapLoaded = false ;
try {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] map [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , file . c_str ( ) ) ;
2011-12-05 06:26:48 +01:00
if ( file ! = " " ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-05 06:26:48 +01:00
lastMissingMap = file ;
Lang & lang = Lang : : getInstance ( ) ;
2013-10-29 07:13:38 +01:00
if ( MapPreview : : loadMapInfo ( file , mapInfo , lang . getString ( " MaxPlayers " ) , lang . getString ( " Size " ) , true ) = = true ) {
2011-12-05 06:26:48 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
labelPlayers [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
labelPlayerNames [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
listBoxControls [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
2012-10-05 01:28:27 +02:00
listBoxRMultiplier [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
2011-12-05 06:26:48 +01:00
listBoxFactions [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
listBoxTeams [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
labelNetStatus [ i ] . setVisible ( i + 1 < = mapInfo - > players ) ;
}
// Not painting properly so this is on hold
if ( loadMapPreview = = true ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-05 06:26:48 +01:00
if ( mapPreview . getMapFileLoaded ( ) ! = file ) {
mapPreview . loadFromFile ( file . c_str ( ) ) ;
cleanupMapPreviewTexture ( ) ;
}
}
mapLoaded = true ;
}
}
else {
cleanupMapPreviewTexture ( ) ;
2013-10-29 07:13:38 +01:00
mapInfo - > desc = Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ;
2011-12-05 06:26:48 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
if ( lastMissingMap ! = gameSettings - > getMap ( ) ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-05 06:26:48 +01:00
lastMissingMap = gameSettings - > getMap ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-12-05 06:26:48 +01:00
if ( lang . hasString ( " DataMissingMap " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingMap " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getMap ( ) . c_str ( ) ) ;
2011-12-05 06:26:48 +01:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is missing the map: %s " , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getMap ( ) . c_str ( ) ) ;
2011-12-05 06:26:48 +01:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
}
}
}
catch ( exception & e ) {
2012-01-06 07:55:27 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] error [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
2011-12-05 06:26:48 +01:00
showMessageBox ( " Error loading map file: " + file + ' \n ' + e . what ( ) , " Error " , false ) ;
}
2010-09-17 10:26:22 +02:00
return mapLoaded ;
2010-09-17 08:37:08 +02:00
}
void MenuStateConnectedGame : : showMessageBox ( const string & text , const string & header , bool toggle ) {
if ( ! toggle ) {
mainMessageBox . setEnabled ( false ) ;
2010-09-11 08:08:50 +02:00
}
2010-09-17 08:37:08 +02:00
if ( ! mainMessageBox . getEnabled ( ) ) {
mainMessageBox . setText ( text ) ;
mainMessageBox . setHeader ( header ) ;
mainMessageBox . setEnabled ( true ) ;
}
else {
mainMessageBox . setEnabled ( false ) ;
}
2010-09-11 08:08:50 +02:00
}
2010-12-29 20:31:51 +01:00
void MenuStateConnectedGame : : showFTPMessageBox ( const string & text , const string & header , bool toggle ) {
if ( ! toggle ) {
ftpMessageBox . setEnabled ( false ) ;
}
if ( ! ftpMessageBox . getEnabled ( ) ) {
ftpMessageBox . setText ( text ) ;
ftpMessageBox . setHeader ( header ) ;
ftpMessageBox . setEnabled ( true ) ;
}
else {
ftpMessageBox . setEnabled ( false ) ;
}
}
2011-03-11 12:11:46 +01:00
int32 MenuStateConnectedGame : : getNetworkPlayerStatus ( ) {
int32 result = npst_None ;
switch ( listBoxPlayerStatus . getSelectedItemIndex ( ) ) {
case 2 :
result = npst_Ready ;
break ;
case 1 :
result = npst_BeRightBack ;
break ;
case 0 :
result = npst_PickSettings ;
break ;
}
return result ;
}
2011-04-13 03:11:23 +02:00
void MenuStateConnectedGame : : cleanupMapPreviewTexture ( ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-04-13 03:11:23 +02:00
if ( mapPreviewTexture ! = NULL ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-04-13 03:11:23 +02:00
mapPreviewTexture - > end ( ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-04-13 03:11:23 +02:00
delete mapPreviewTexture ;
mapPreviewTexture = NULL ;
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-04-13 03:11:23 +02:00
}
2011-04-20 18:25:16 +02:00
bool MenuStateConnectedGame : : isInSpecialKeyCaptureEvent ( ) {
bool result = ( chatManager . getEditEnabled ( ) | | activeInputLabel ! = NULL ) ;
return result ;
}
2011-03-25 11:11:16 +01:00
void MenuStateConnectedGame : : FTPClient_CallbackEvent ( string itemName ,
FTP_Client_CallbackType type , pair < FTP_Client_ResultType , string > result , void * userdata ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2010-12-29 09:10:22 +01:00
2011-01-04 09:44:00 +01:00
if ( type = = ftp_cct_DownloadProgress ) {
FTPClientCallbackInterface : : FtpProgressStats * stats = ( FTPClientCallbackInterface : : FtpProgressStats * ) userdata ;
if ( stats ! = NULL ) {
int fileProgress = 0 ;
if ( stats - > download_total > 0 ) {
2011-01-04 21:00:39 +01:00
fileProgress = ( ( stats - > download_now / stats - > download_total ) * 100.0 ) ;
2011-01-04 09:44:00 +01:00
}
2011-01-16 05:15:18 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] current file [%s] fileProgress = %d [now = %f, total = %f]\n",itemName.c_str(),stats->currentFilename.c_str(), fileProgress,stats->download_now,stats->download_total);
2011-01-04 09:44:00 +01:00
2011-03-15 16:30:28 +01:00
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-06-02 07:01:28 +02:00
pair < int , string > lastProgress ;
std : : map < string , pair < int , string > > : : iterator iterFind = fileFTPProgressList . find ( itemName ) ;
if ( iterFind = = fileFTPProgressList . end ( ) ) {
iterFind = fileFTPProgressList . find ( GameConstants : : saveNetworkGameFileServerCompressed ) ;
if ( iterFind = = fileFTPProgressList . end ( ) ) {
iterFind = fileFTPProgressList . find ( GameConstants : : saveNetworkGameFileClientCompressed ) ;
}
}
if ( iterFind ! = fileFTPProgressList . end ( ) ) {
lastProgress = iterFind - > second ;
fileFTPProgressList [ iterFind - > first ] = pair < int , string > ( fileProgress , stats - > currentFilename ) ;
}
2011-03-15 16:30:28 +01:00
safeMutexFTPProgress . ReleaseLock ( ) ;
2011-03-16 19:39:53 +01:00
2011-03-20 01:11:00 +01:00
if ( itemName ! = " " & & ( lastProgress . first / 25 ) < ( fileProgress / 25 ) ) {
2011-03-16 19:39:53 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " FileDownloadProgress " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " FileDownloadProgress " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , fileProgress ) ;
2011-04-05 20:39:47 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s download progress for [%s] is %d %% " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , fileProgress ) ;
2011-04-05 20:39:47 +02:00
}
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] szMsg [%s] lastProgress.first = %d, fileProgress = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , szMsg , lastProgress . first , fileProgress ) ;
2011-04-05 20:39:47 +02:00
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2011-03-16 19:39:53 +01:00
}
2011-01-04 09:44:00 +01:00
}
}
2012-09-27 07:54:37 +02:00
else if ( type = = ftp_cct_ExtractProgress ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Got FTP extract Callback for [%s] result = %d [%s] \n " , itemName . c_str ( ) , result . first , result . second . c_str ( ) ) ;
if ( userdata = = NULL ) {
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2012-09-27 07:54:37 +02:00
if ( lang . hasString ( " DataMissingExtractDownload " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingExtractDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
2012-09-27 07:54:37 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Please wait, player: %s is extracting: %s " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
2012-09-27 07:54:37 +02:00
}
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] szMsg [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , szMsg ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2012-09-27 07:54:37 +02:00
}
else {
char * szBuf = ( char * ) userdata ;
//printf("%s\n",szBuf);
2012-10-15 10:09:28 +02:00
//console.addLine(szBuf);
console . addLine ( szBuf , false , " " ) ;
2012-09-27 07:54:37 +02:00
}
}
2011-01-04 09:44:00 +01:00
else if ( type = = ftp_cct_Map ) {
2011-01-01 01:50:10 +01:00
getMissingMapFromFTPServerInProgress = false ;
2011-03-25 11:11:16 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Got FTP Callback for [%s] result = %d [%s] \n " , itemName . c_str ( ) , result . first , result . second . c_str ( ) ) ;
2010-12-29 09:16:26 +01:00
2011-03-15 16:30:28 +01:00
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-04 09:44:00 +01:00
fileFTPProgressList . erase ( itemName ) ;
safeMutexFTPProgress . ReleaseLock ( ) ;
2011-01-01 01:50:10 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
2010-12-29 09:16:26 +01:00
2011-03-25 11:11:16 +01:00
if ( result . first = = ftp_crt_SUCCESS ) {
2011-03-20 07:23:19 +01:00
// Clear the CRC file Cache
2013-12-17 08:54:33 +01:00
string file = Config : : getMapPath ( itemName , " " , false ) ;
2013-05-01 06:57:41 +02:00
2013-05-03 08:25:38 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Got map itemName [%s] file [%s] lastCheckedCRCMapName [%s] gameSettings->getMap() [%s] \n " ,
itemName . c_str ( ) , file . c_str ( ) , lastCheckedCRCMapName . c_str ( ) , gameSettings - > getMap ( ) . c_str ( ) ) ;
2013-05-01 06:57:41 +02:00
2013-05-03 08:25:38 +02:00
if ( gameSettings ! = NULL & & itemName = = gameSettings - > getMap ( ) & &
lastCheckedCRCMapName = = gameSettings - > getMap ( ) & &
2013-05-01 06:57:41 +02:00
gameSettings - > getMap ( ) ! = " " ) {
2013-05-03 08:25:38 +02:00
Checksum : : clearFileCache ( ) ;
Checksum checksum ;
2013-05-01 06:57:41 +02:00
checksum . addFile ( file ) ;
lastCheckedCRCMapValue = checksum . getSum ( ) ;
}
2011-03-20 07:23:19 +01:00
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingMapSuccessDownload " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingMapSuccessDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s SUCCESSFULLY downloaded the map: %s " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2011-01-01 01:50:10 +01:00
}
else {
2013-05-03 08:25:38 +02:00
printf ( " FAILED map itemName [%s] lastCheckedCRCMapName [%s] gameSettings->getMap() [%s] \n " ,
itemName . c_str ( ) , lastCheckedCRCMapName . c_str ( ) , gameSettings - > getMap ( ) . c_str ( ) ) ;
2011-01-20 16:56:30 +01:00
curl_version_info_data * curlVersion = curl_version_info ( CURLVERSION_NOW ) ;
2011-01-01 11:16:25 +01:00
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingMapFailDownload " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingMapFailDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
2011-04-05 20:39:47 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s FAILED to download the map: [%s] using CURL version [%s] " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
2011-04-05 20:39:47 +02:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
2012-10-16 02:58:49 +02:00
if ( result . first = = ftp_crt_HOST_NOT_ACCEPTING ) {
if ( lang . hasString ( " HostNotAcceptingDataConnections " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
clientInterface - > sendTextMessage ( lang . getString ( " HostNotAcceptingDataConnections " , languageList [ i ] ) , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
2012-10-16 02:58:49 +02:00
}
else {
clientInterface - > sendTextMessage ( " *Warning* the host is not accepting data connections. " , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
}
2011-04-05 20:39:47 +02:00
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2011-03-25 11:11:16 +01:00
console . addLine ( result . second , true ) ;
2011-01-01 01:50:10 +01:00
}
2010-12-29 09:16:26 +01:00
}
2011-01-01 04:12:28 +01:00
else if ( type = = ftp_cct_Tileset ) {
2011-01-01 01:50:10 +01:00
getMissingTilesetFromFTPServerInProgress = false ;
2011-03-25 11:11:16 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Got FTP Callback for [%s] result = %d [%s] \n " , itemName . c_str ( ) , result . first , result . second . c_str ( ) ) ;
2011-01-01 01:50:10 +01:00
2011-03-15 16:30:28 +01:00
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-04 09:44:00 +01:00
fileFTPProgressList . erase ( itemName ) ;
2011-01-10 08:32:12 +01:00
safeMutexFTPProgress . ReleaseLock ( true ) ;
2011-01-04 09:44:00 +01:00
2011-01-01 01:50:10 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
2011-03-25 11:11:16 +01:00
if ( result . first = = ftp_crt_SUCCESS ) {
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingTilesetSuccessDownload " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTilesetSuccessDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s SUCCESSFULLY downloaded the tileset: %s " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2011-01-01 04:12:28 +01:00
2011-01-04 09:44:00 +01:00
// START
// Clear the CRC Cache if it is populated
//
2011-01-10 08:32:12 +01:00
// Clear the CRC file Cache
safeMutexFTPProgress . Lock ( ) ;
Checksum : : clearFileCache ( ) ;
2011-01-04 09:44:00 +01:00
vector < string > paths = Config : : getInstance ( ) . getPathListForType ( ptTilesets ) ;
string pathSearchString = string ( " / " ) + itemName + string ( " /* " ) ;
const string filterFileExt = " .xml " ;
2011-03-10 22:38:43 +01:00
clearFolderTreeContentsCheckSum ( paths , pathSearchString , filterFileExt ) ;
clearFolderTreeContentsCheckSumList ( paths , pathSearchString , filterFileExt ) ;
2011-01-04 09:44:00 +01:00
2011-03-10 22:50:43 +01:00
// Refresh CRC
2013-05-01 06:57:41 +02:00
//printf("Got map itemName [%s] file [%s] lastCheckedCRCMapName [%s] gameSettings->getMap() [%s]\n",
// itemName.c_str(),file.c_str(),lastCheckedCRCMapName.c_str(),gameSettings->getMap().c_str());
2013-05-03 08:25:38 +02:00
if ( gameSettings ! = NULL & & itemName = = gameSettings - > getTileset ( ) & &
lastCheckedCRCTilesetName = = gameSettings - > getTileset ( ) & &
2013-05-01 06:57:41 +02:00
gameSettings - > getTileset ( ) ! = " " ) {
Config & config = Config : : getInstance ( ) ;
lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + itemName + string ( " /* " ) , " .xml " , NULL , true ) ;
}
2011-03-10 22:50:43 +01:00
2011-01-10 08:32:12 +01:00
safeMutexFTPProgress . ReleaseLock ( ) ;
2011-01-04 09:44:00 +01:00
// END
// Reload tilesets for the UI
2011-12-28 05:46:36 +01:00
string scenarioDir = Scenario : : getScenarioDir ( dirList , gameSettings - > getScenario ( ) ) ;
findDirs ( Config : : getInstance ( ) . getPathListForType ( ptTilesets , scenarioDir ) , tilesetFiles ) ;
2011-11-29 04:25:36 +01:00
std : : vector < string > tilesetsFormatted = tilesetFiles ;
std : : for_each ( tilesetsFormatted . begin ( ) , tilesetsFormatted . end ( ) , FormatString ( ) ) ;
listBoxTileset . setItems ( tilesetsFormatted ) ;
2011-01-01 01:50:10 +01:00
}
else {
2011-01-01 11:16:25 +01:00
curl_version_info_data * curlVersion = curl_version_info ( CURLVERSION_NOW ) ;
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingTilesetFailDownload " , languageList [ i ] ) = = true ) {
2013-11-09 02:14:32 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTilesetFailDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , ( itemName + " (.7z) " ) . c_str ( ) , curlVersion - > version ) ;
2011-04-05 20:39:47 +02:00
}
else {
2013-11-09 02:14:32 +01:00
snprintf ( szMsg , 8096 , " Player: %s FAILED to download the tileset: [%s] using CURL version [%s] " , getHumanPlayerName ( ) . c_str ( ) , ( itemName + " (.7z) " ) . c_str ( ) , curlVersion - > version ) ;
2011-04-05 20:39:47 +02:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
2012-10-16 02:58:49 +02:00
if ( result . first = = ftp_crt_HOST_NOT_ACCEPTING ) {
if ( lang . hasString ( " HostNotAcceptingDataConnections " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
clientInterface - > sendTextMessage ( lang . getString ( " HostNotAcceptingDataConnections " , languageList [ i ] ) , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
2012-10-16 02:58:49 +02:00
}
else {
clientInterface - > sendTextMessage ( " *Warning* the host is not accepting data connections. " , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
}
2011-04-05 20:39:47 +02:00
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2011-04-05 20:39:47 +02:00
2011-03-25 11:11:16 +01:00
console . addLine ( result . second , true ) ;
2011-01-01 01:50:10 +01:00
}
2010-12-30 21:48:39 +01:00
}
2011-03-10 00:09:32 +01:00
else if ( type = = ftp_cct_Techtree ) {
getMissingTechtreeFromFTPServerInProgress = false ;
2011-03-25 11:11:16 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Got FTP Callback for [%s] result = %d [%s] \n " , itemName . c_str ( ) , result . first , result . second . c_str ( ) ) ;
2011-03-10 00:09:32 +01:00
2011-03-15 16:30:28 +01:00
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-03-10 00:09:32 +01:00
fileFTPProgressList . erase ( itemName ) ;
safeMutexFTPProgress . ReleaseLock ( true ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
2011-03-25 11:11:16 +01:00
if ( result . first = = ftp_crt_SUCCESS ) {
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingTechtreeSuccessDownload " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTechtreeSuccessDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s SUCCESSFULLY downloaded the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
2011-04-05 20:39:47 +02:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2011-03-10 00:09:32 +01:00
// START
// Clear the CRC Cache if it is populated
//
// Clear the CRC file Cache
safeMutexFTPProgress . Lock ( ) ;
Checksum : : clearFileCache ( ) ;
vector < string > paths = Config : : getInstance ( ) . getPathListForType ( ptTechs ) ;
string pathSearchString = string ( " / " ) + itemName + string ( " /* " ) ;
const string filterFileExt = " .xml " ;
2011-03-10 22:38:43 +01:00
clearFolderTreeContentsCheckSum ( paths , pathSearchString , filterFileExt ) ;
clearFolderTreeContentsCheckSumList ( paths , pathSearchString , filterFileExt ) ;
2011-03-10 00:09:32 +01:00
2011-03-10 22:50:43 +01:00
// Refresh CRC
2013-05-03 08:25:38 +02:00
if ( gameSettings ! = NULL & & itemName = = gameSettings - > getTech ( ) & &
lastCheckedCRCTechtreeName = = gameSettings - > getTech ( ) & &
2013-05-01 06:57:41 +02:00
gameSettings - > getTech ( ) ! = " " ) {
Config & config = Config : : getInstance ( ) ;
lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , string ( " / " ) + itemName + string ( " /* " ) , " .xml " , NULL , true ) ;
}
2011-03-10 00:09:32 +01:00
safeMutexFTPProgress . ReleaseLock ( ) ;
// END
2012-09-27 07:54:37 +02:00
// Reload techs for the UI
2011-12-28 05:46:36 +01:00
string scenarioDir = Scenario : : getScenarioDir ( dirList , gameSettings - > getScenario ( ) ) ;
findDirs ( Config : : getInstance ( ) . getPathListForType ( ptTechs , scenarioDir ) , techTreeFiles ) ;
2011-11-29 04:25:36 +01:00
2013-06-13 03:37:15 +02:00
vector < string > translatedTechs ;
2011-11-29 04:25:36 +01:00
std : : vector < string > techsFormatted = techTreeFiles ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) techsFormatted . size ( ) ; i + + ) {
2011-11-29 04:25:36 +01:00
techsFormatted . at ( i ) = formatString ( techsFormatted . at ( i ) ) ;
2013-06-13 03:37:15 +02:00
string txTech = techTree - > getTranslatedName ( techTreeFiles . at ( i ) , true ) ;
2013-06-16 03:14:04 +02:00
translatedTechs . push_back ( formatString ( txTech ) ) ;
2011-11-29 04:25:36 +01:00
}
2013-06-13 03:37:15 +02:00
listBoxTechTree . setItems ( techsFormatted , translatedTechs ) ;
2011-03-10 00:09:32 +01:00
}
else {
curl_version_info_data * curlVersion = curl_version_info ( CURLVERSION_NOW ) ;
2011-04-05 20:39:47 +02:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
2013-11-19 07:14:06 +01:00
for ( unsigned int i = 0 ; i < ( unsigned int ) languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-04-05 20:39:47 +02:00
if ( lang . hasString ( " DataMissingTechtreeFailDownload " , languageList [ i ] ) = = true ) {
2013-11-09 02:14:32 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTechtreeFailDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , ( itemName + " (.7z) " ) . c_str ( ) , curlVersion - > version ) ;
2011-04-05 20:39:47 +02:00
}
else {
2013-11-09 02:14:32 +01:00
snprintf ( szMsg , 8096 , " Player: %s FAILED to download the techtree: [%s] using CURL version [%s] " , getHumanPlayerName ( ) . c_str ( ) , ( itemName + " (.7z) " ) . c_str ( ) , curlVersion - > version ) ;
2011-04-05 20:39:47 +02:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
2012-10-16 02:58:49 +02:00
if ( result . first = = ftp_crt_HOST_NOT_ACCEPTING ) {
if ( lang . hasString ( " HostNotAcceptingDataConnections " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
clientInterface - > sendTextMessage ( lang . getString ( " HostNotAcceptingDataConnections " , languageList [ i ] ) , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
2012-10-16 02:58:49 +02:00
}
else {
clientInterface - > sendTextMessage ( " *Warning* the host is not accepting data connections. " , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
}
2011-04-05 20:39:47 +02:00
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2011-04-05 20:39:47 +02:00
2011-03-25 11:11:16 +01:00
console . addLine ( result . second , true ) ;
2011-03-10 00:09:32 +01:00
}
}
2013-02-15 19:25:10 +01:00
else if ( type = = ftp_cct_TempFile ) {
getInProgressSavedGameFromFTPServerInProgress = false ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Got FTP Callback for [%s] result = %d [%s] \n " , itemName . c_str ( ) , result . first , result . second . c_str ( ) ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2013-06-02 07:01:28 +02:00
//fileFTPProgressList.erase(itemName);
std : : map < string , pair < int , string > > : : iterator iterFind = fileFTPProgressList . find ( itemName ) ;
if ( iterFind = = fileFTPProgressList . end ( ) ) {
iterFind = fileFTPProgressList . find ( GameConstants : : saveNetworkGameFileServerCompressed ) ;
if ( iterFind = = fileFTPProgressList . end ( ) ) {
iterFind = fileFTPProgressList . find ( GameConstants : : saveNetworkGameFileClientCompressed ) ;
}
}
if ( iterFind ! = fileFTPProgressList . end ( ) ) {
fileFTPProgressList . erase ( iterFind - > first ) ;
}
2013-02-15 19:25:10 +01:00
safeMutexFTPProgress . ReleaseLock ( ) ;
2013-02-16 20:11:36 +01:00
//printf("Status update downloading saved game file: [%s]\n",itemName.c_str());
2013-02-15 19:25:10 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
2013-11-19 07:14:06 +01:00
//const GameSettings *gameSettings = clientInterface->getGameSettings();
2013-02-15 19:25:10 +01:00
if ( result . first = = ftp_crt_SUCCESS ) {
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
char szMsg [ 8096 ] = " " ;
if ( lang . hasString ( " JoinPlayerToCurrentGameSuccessDownload " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " JoinPlayerToCurrentGameSuccessDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
2013-02-15 19:25:10 +01:00
}
else {
snprintf ( szMsg , 8096 , " Player: %s SUCCESSFULLY downloaded the saved game: %s " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2013-02-15 19:25:10 +01:00
2013-05-01 22:56:19 +02:00
if ( itemName = = GameConstants : : saveNetworkGameFileClientCompressed ) {
string saveGameFilePath = " temp/ " ;
string saveGameFile = saveGameFilePath + string ( GameConstants : : saveNetworkGameFileClientCompressed ) ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
saveGameFilePath = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + saveGameFilePath ;
saveGameFile = saveGameFilePath + string ( GameConstants : : saveNetworkGameFileClientCompressed ) ;
}
else {
string userData = Config : : getInstance ( ) . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
saveGameFilePath = userData + saveGameFilePath ;
saveGameFile = saveGameFilePath + string ( GameConstants : : saveNetworkGameFileClientCompressed ) ;
}
string extractedFileName = saveGameFilePath + string ( GameConstants : : saveNetworkGameFileClient ) ;
2013-06-02 01:55:21 +02:00
bool extract_result = extractFileFromZIPFile ( saveGameFile , extractedFileName ) ;
2013-05-01 22:56:19 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Saved game [%s] compressed to [%s] returned: %d \n " , saveGameFile . c_str ( ) , extractedFileName . c_str ( ) , extract_result ) ;
}
2013-02-15 19:25:10 +01:00
readyToJoinInProgressGame = true ;
2013-02-16 20:11:36 +01:00
//printf("Success downloading saved game file: [%s]\n",itemName.c_str());
2013-02-15 19:25:10 +01:00
}
else {
curl_version_info_data * curlVersion = curl_version_info ( CURLVERSION_NOW ) ;
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
char szMsg [ 8096 ] = " " ;
if ( lang . hasString ( " JoinPlayerToCurrentGameFailDownload " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " JoinPlayerToCurrentGameFailDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
2013-02-15 19:25:10 +01:00
}
else {
snprintf ( szMsg , 8096 , " Player: %s FAILED to download the saved game: [%s] using CURL version [%s] " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
if ( result . first = = ftp_crt_HOST_NOT_ACCEPTING ) {
if ( lang . hasString ( " HostNotAcceptingDataConnections " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
clientInterface - > sendTextMessage ( lang . getString ( " HostNotAcceptingDataConnections " , languageList [ i ] ) , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
2013-02-15 19:25:10 +01:00
}
else {
clientInterface - > sendTextMessage ( " *Warning* the host is not accepting data connections. " , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
}
}
2013-05-27 10:26:01 +02:00
sleep ( 1 ) ;
2013-02-15 19:25:10 +01:00
console . addLine ( result . second , true ) ;
}
}
2010-12-29 02:10:53 +01:00
}
2011-12-26 07:29:14 +01:00
void MenuStateConnectedGame : : setupUIFromGameSettings ( GameSettings * gameSettings , bool errorOnMissingData ) {
2011-12-03 09:17:49 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
updateDataSynchDetailText = true ;
vector < string > maps , tilesets , techtree ;
if ( gameSettings = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " gameSettings == NULL " ) ;
2011-12-03 09:17:49 +01:00
}
2011-12-26 07:29:14 +01:00
checkBoxScenario . setValue ( ( gameSettings - > getScenario ( ) ! = " " ) ) ;
if ( checkBoxScenario . getValue ( ) = = true ) {
2011-12-26 08:11:52 +01:00
int originalFOWValue = listBoxFogOfWar . getSelectedItemIndex ( ) ;
2011-12-26 07:29:14 +01:00
string scenario = gameSettings - > getScenario ( ) ;
listBoxScenario . setSelectedItem ( formatString ( scenario ) ) ;
string file = Scenario : : getScenarioPath ( dirList , scenario ) ;
2013-05-21 22:28:42 +02:00
bool isTutorial = Scenario : : isGameTutorial ( file ) ;
Scenario : : loadScenarioInfo ( file , & scenarioInfo , isTutorial ) ;
2011-12-26 07:29:14 +01:00
gameSettings - > setScenarioDir ( Scenario : : getScenarioPath ( dirList , scenarioInfo . name ) ) ;
2011-12-26 08:11:52 +01:00
gameSettings - > setDefaultResources ( scenarioInfo . defaultResources ) ;
gameSettings - > setDefaultUnits ( scenarioInfo . defaultUnits ) ;
gameSettings - > setDefaultVictoryConditions ( scenarioInfo . defaultVictoryConditions ) ;
if ( scenarioInfo . fogOfWar = = false & & scenarioInfo . fogOfWar_exploredFlag = = false ) {
listBoxFogOfWar . setSelectedItemIndex ( 2 ) ;
}
else if ( scenarioInfo . fogOfWar_exploredFlag = = true ) {
listBoxFogOfWar . setSelectedItemIndex ( 1 ) ;
}
else {
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ;
}
if ( originalFOWValue ! = listBoxFogOfWar . getSelectedItemIndex ( ) ) {
cleanupMapPreviewTexture ( ) ;
}
2011-12-26 07:29:14 +01:00
}
2011-12-28 05:46:36 +01:00
string scenarioDir = Scenario : : getScenarioDir ( dirList , gameSettings - > getScenario ( ) ) ;
setupMapList ( gameSettings - > getScenario ( ) ) ;
setupTechList ( gameSettings - > getScenario ( ) ) ;
setupTilesetList ( gameSettings - > getScenario ( ) ) ;
//listBoxMap.setItems(formattedPlayerSortedMaps[gameSettings.getMapFilterIndex()]);
2011-12-03 09:17:49 +01:00
//printf("A gameSettings->getTileset() [%s]\n",gameSettings->getTileset().c_str());
2011-12-28 05:46:36 +01:00
if ( getMissingTilesetFromFTPServerInProgress = = false & &
gameSettings - > getTileset ( ) ! = " " ) {
2011-12-03 09:17:49 +01:00
// tileset
tilesets = tilesetFiles ;
std : : for_each ( tilesets . begin ( ) , tilesets . end ( ) , FormatString ( ) ) ;
if ( std : : find ( tilesetFiles . begin ( ) , tilesetFiles . end ( ) , gameSettings - > getTileset ( ) ) ! = tilesetFiles . end ( ) ) {
lastMissingTileSet = " " ;
getMissingTilesetFromFTPServer = " " ;
listBoxTileset . setSelectedItem ( formatString ( gameSettings - > getTileset ( ) ) ) ;
}
else {
// try to get the tileset via ftp
2013-05-31 21:05:34 +02:00
if ( ftpClientThread ! = NULL & &
( getMissingTilesetFromFTPServer ! = gameSettings - > getTileset ( ) | |
difftime ( time ( NULL ) , getMissingTilesetFromFTPServerLastPrompted ) > REPROMPT_DOWNLOAD_SECONDS ) ) {
2011-12-03 09:17:49 +01:00
if ( ftpMessageBox . getEnabled ( ) = = false ) {
2013-05-31 21:05:34 +02:00
getMissingTilesetFromFTPServerLastPrompted = time ( NULL ) ;
2011-12-03 09:17:49 +01:00
getMissingTilesetFromFTPServer = gameSettings - > getTileset ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-10-29 07:13:38 +01:00
snprintf ( szBuf , 8096 , " %s %s ? " , lang . getString ( " DownloadMissingTilesetQuestion " ) . c_str ( ) , gameSettings - > getTileset ( ) . c_str ( ) ) ;
2011-12-03 09:17:49 +01:00
2012-10-16 00:41:26 +02:00
// Is the item in the mod center?
if ( tilesetCacheList . find ( getMissingMapFromFTPServer ) = = tilesetCacheList . end ( ) ) {
2013-10-29 07:13:38 +01:00
ftpMessageBox . init ( lang . getString ( " Yes " ) , lang . getString ( " NoDownload " ) ) ;
2012-10-16 00:41:26 +02:00
}
else {
2013-10-29 07:13:38 +01:00
ftpMessageBox . init ( lang . getString ( " ModCenter " ) , lang . getString ( " GameHost " ) ) ;
ftpMessageBox . addButton ( lang . getString ( " NoDownload " ) ) ;
2012-10-16 00:41:26 +02:00
}
2011-12-03 09:17:49 +01:00
ftpMissingDataType = ftpmsg_MissingTileset ;
2013-10-29 07:13:38 +01:00
showFTPMessageBox ( szBuf , lang . getString ( " Question " ) , false ) ;
2011-12-03 09:17:49 +01:00
}
}
2013-10-29 07:13:38 +01:00
tilesets . push_back ( Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) ;
2011-12-03 09:17:49 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
if ( lastMissingTileSet ! = gameSettings - > getTileset ( ) ) {
lastMissingTileSet = gameSettings - > getTileset ( ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-03 09:17:49 +01:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-12-03 09:17:49 +01:00
if ( lang . hasString ( " DataMissingTileset " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTileset " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTileset ( ) . c_str ( ) ) ;
2011-12-03 09:17:49 +01:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is missing the tileset: %s " , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTileset ( ) . c_str ( ) ) ;
2011-12-03 09:17:49 +01:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
}
listBoxTileset . setItems ( tilesets ) ;
2013-10-29 07:13:38 +01:00
listBoxTileset . setSelectedItem ( Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) ;
2011-12-03 09:17:49 +01:00
}
}
2011-12-28 05:46:36 +01:00
if ( getMissingTechtreeFromFTPServerInProgress = = false & &
gameSettings - > getTech ( ) ! = " " ) {
2011-12-03 09:17:49 +01:00
// techtree
techtree = techTreeFiles ;
std : : for_each ( techtree . begin ( ) , techtree . end ( ) , FormatString ( ) ) ;
if ( std : : find ( techTreeFiles . begin ( ) , techTreeFiles . end ( ) , gameSettings - > getTech ( ) ) ! = techTreeFiles . end ( ) ) {
lastMissingTechtree = " " ;
getMissingTechtreeFromFTPServer = " " ;
2011-12-28 05:46:36 +01:00
reloadFactions ( true , gameSettings - > getScenario ( ) ) ;
2011-12-03 09:17:49 +01:00
listBoxTechTree . setSelectedItem ( formatString ( gameSettings - > getTech ( ) ) ) ;
}
else {
// try to get the tileset via ftp
2013-05-31 21:05:34 +02:00
if ( ftpClientThread ! = NULL & & ( getMissingTechtreeFromFTPServer ! = gameSettings - > getTech ( ) | |
difftime ( time ( NULL ) , getMissingTechtreeFromFTPServerLastPrompted ) > REPROMPT_DOWNLOAD_SECONDS ) ) {
2011-12-03 09:17:49 +01:00
if ( ftpMessageBox . getEnabled ( ) = = false ) {
2013-05-31 21:05:34 +02:00
getMissingTechtreeFromFTPServerLastPrompted = time ( NULL ) ;
2011-12-03 09:17:49 +01:00
getMissingTechtreeFromFTPServer = gameSettings - > getTech ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-10-29 07:13:38 +01:00
snprintf ( szBuf , 8096 , " %s %s ? " , lang . getString ( " DownloadMissingTechtreeQuestion " ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
2011-12-03 09:17:49 +01:00
2012-10-16 00:41:26 +02:00
// Is the item in the mod center?
if ( techCacheList . find ( getMissingTechtreeFromFTPServer ) = = techCacheList . end ( ) ) {
2013-10-29 07:13:38 +01:00
ftpMessageBox . init ( lang . getString ( " Yes " ) , lang . getString ( " NoDownload " ) ) ;
2012-10-16 00:41:26 +02:00
}
else {
2013-10-29 07:13:38 +01:00
ftpMessageBox . init ( lang . getString ( " ModCenter " ) , lang . getString ( " GameHost " ) ) ;
ftpMessageBox . addButton ( lang . getString ( " NoDownload " ) ) ;
2012-10-16 00:41:26 +02:00
}
2011-12-03 09:17:49 +01:00
ftpMissingDataType = ftpmsg_MissingTechtree ;
2013-10-29 07:13:38 +01:00
showFTPMessageBox ( szBuf , lang . getString ( " Question " ) , false ) ;
2011-12-03 09:17:49 +01:00
}
}
2013-10-29 07:13:38 +01:00
techtree . push_back ( Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) ;
2011-12-03 09:17:49 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
if ( lastMissingTechtree ! = gameSettings - > getTech ( ) ) {
lastMissingTechtree = gameSettings - > getTech ( ) ;
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-03 09:17:49 +01:00
Lang & lang = Lang : : getInstance ( ) ;
const vector < string > languageList = clientInterface - > getGameSettings ( ) - > getUniqueNetworkPlayerLanguages ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szMsg [ 8096 ] = " " ;
2011-12-03 09:17:49 +01:00
if ( lang . hasString ( " DataMissingTechtree " , languageList [ i ] ) = = true ) {
2013-10-29 07:13:38 +01:00
snprintf ( szMsg , 8096 , lang . getString ( " DataMissingTechtree " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
2011-12-03 09:17:49 +01:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szMsg , 8096 , " Player: %s is missing the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
2011-12-03 09:17:49 +01:00
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
}
2013-06-13 03:37:15 +02:00
vector < string > translatedTechs ;
for ( unsigned int i = 0 ; i < techTreeFiles . size ( ) ; i + + ) {
string txTech = techTree - > getTranslatedName ( techTreeFiles . at ( i ) ) ;
translatedTechs . push_back ( txTech ) ;
}
listBoxTechTree . setItems ( techtree , translatedTechs ) ;
2013-10-29 07:13:38 +01:00
listBoxTechTree . setSelectedItem ( Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) ;
2011-12-03 09:17:49 +01:00
}
}
// factions
bool hasFactions = true ;
if ( currentFactionName ! = gameSettings - > getTech ( ) & & gameSettings - > getTech ( ) ! = " " ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] hasFactions = %d, currentFactionName [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , hasFactions , currentFactionName . c_str ( ) ) ;
2011-12-03 09:17:49 +01:00
currentFactionName = gameSettings - > getTech ( ) ;
hasFactions = loadFactions ( gameSettings , false ) ;
}
else {
// do this to process special faction types like observers
loadFactions ( gameSettings , false ) ;
}
2011-12-28 05:46:36 +01:00
if ( getMissingMapFromFTPServerInProgress = = false & &
gameSettings - > getMap ( ) ! = " " ) {
2011-12-03 09:17:49 +01:00
// map
string mapFile = gameSettings - > getMap ( ) ;
mapFile = formatString ( mapFile ) ;
maps = formattedMapFiles ;
if ( currentMap ! = gameSettings - > getMap ( ) ) { // load the setup again
currentMap = gameSettings - > getMap ( ) ;
}
2013-12-17 08:54:33 +01:00
bool mapLoaded = loadMapInfo ( Config : : getMapPath ( currentMap , scenarioDir , false ) , & mapInfo , true ) ;
2011-12-03 09:17:49 +01:00
if ( mapLoaded = = true ) {
if ( find ( maps . begin ( ) , maps . end ( ) , formatString ( gameSettings - > getMap ( ) ) ) = = maps . end ( ) ) {
maps . push_back ( formatString ( gameSettings - > getMap ( ) ) ) ;
}
}
else {
// try to get the map via ftp
2013-05-31 21:05:34 +02:00
if ( ftpClientThread ! = NULL & & ( getMissingMapFromFTPServer ! = currentMap | |
difftime ( time ( NULL ) , getMissingMapFromFTPServerLastPrompted ) > REPROMPT_DOWNLOAD_SECONDS ) ) {
2011-12-03 09:17:49 +01:00
if ( ftpMessageBox . getEnabled ( ) = = false ) {
2013-05-31 21:05:34 +02:00
getMissingMapFromFTPServerLastPrompted = time ( NULL ) ;
2011-12-03 09:17:49 +01:00
getMissingMapFromFTPServer = currentMap ;
Lang & lang = Lang : : getInstance ( ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-10-29 07:13:38 +01:00
snprintf ( szBuf , 8096 , " %s %s ? " , lang . getString ( " DownloadMissingMapQuestion " ) . c_str ( ) , currentMap . c_str ( ) ) ;
2012-10-16 00:41:26 +02:00
// Is the item in the mod center?
if ( mapCacheList . find ( getMissingTechtreeFromFTPServer ) = = mapCacheList . end ( ) ) {
2013-10-29 07:13:38 +01:00
ftpMessageBox . init ( lang . getString ( " Yes " ) , lang . getString ( " NoDownload " ) ) ;
2012-10-16 00:41:26 +02:00
}
else {
2013-10-29 07:13:38 +01:00
ftpMessageBox . init ( lang . getString ( " ModCenter " ) , lang . getString ( " GameHost " ) ) ;
ftpMessageBox . addButton ( lang . getString ( " NoDownload " ) ) ;
2012-10-16 00:41:26 +02:00
}
2011-12-03 09:17:49 +01:00
ftpMissingDataType = ftpmsg_MissingMap ;
2013-10-29 07:13:38 +01:00
showFTPMessageBox ( szBuf , lang . getString ( " Question " ) , false ) ;
2011-12-03 09:17:49 +01:00
}
}
2013-10-29 07:13:38 +01:00
maps . push_back ( Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ) ;
mapFile = Lang : : getInstance ( ) . getString ( " DataMissing " , " " , true ) ;
2011-12-03 09:17:49 +01:00
}
2013-06-01 20:07:06 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] listBoxMap.getSelectedItemIndex() = %d, mapFiles.size() = " MG_SIZE_T_SPECIFIER " , maps.size() = " MG_SIZE_T_SPECIFIER " , getCurrentMapFile() [%s] mapFile [%s] \n " ,
extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , listBoxMap . getSelectedItemIndex ( ) , mapFiles . size ( ) , maps . size ( ) , getCurrentMapFile ( ) . c_str ( ) , mapFile . c_str ( ) ) ;
2012-03-03 05:33:39 +01:00
2011-12-03 09:17:49 +01:00
listBoxMap . setItems ( maps ) ;
listBoxMap . setSelectedItem ( mapFile ) ;
labelMapInfo . setText ( mapInfo . desc ) ;
}
// FogOfWar
2011-12-26 08:11:52 +01:00
if ( checkBoxScenario . getValue ( ) = = false ) {
int originalFOWValue = listBoxFogOfWar . getSelectedItemIndex ( ) ;
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ; // default is 0!
if ( gameSettings - > getFogOfWar ( ) = = false ) {
listBoxFogOfWar . setSelectedItemIndex ( 2 ) ;
}
if ( ( gameSettings - > getFlagTypes1 ( ) & ft1_show_map_resources ) = = ft1_show_map_resources ) {
if ( gameSettings - > getFogOfWar ( ) = = true ) {
listBoxFogOfWar . setSelectedItemIndex ( 1 ) ;
}
}
if ( originalFOWValue ! = listBoxFogOfWar . getSelectedItemIndex ( ) ) {
cleanupMapPreviewTexture ( ) ;
2011-12-03 09:17:49 +01:00
}
}
// Allow Observers
if ( gameSettings - > getAllowObservers ( ) ) {
2012-10-22 19:53:48 +02:00
checkBoxAllowObservers . setValue ( true ) ;
2011-12-03 09:17:49 +01:00
}
else
{
2012-10-22 19:53:48 +02:00
checkBoxAllowObservers . setValue ( false ) ;
2011-12-03 09:17:49 +01:00
}
if ( ( gameSettings - > getFlagTypes1 ( ) & ft1_allow_team_switching ) = = ft1_allow_team_switching ) {
2012-10-22 19:53:48 +02:00
checkBoxEnableSwitchTeamMode . setValue ( true ) ;
2011-12-03 09:17:49 +01:00
}
else {
2012-10-22 19:53:48 +02:00
checkBoxEnableSwitchTeamMode . setValue ( false ) ;
2011-12-03 09:17:49 +01:00
}
listBoxAISwitchTeamAcceptPercent . setSelectedItem ( intToStr ( gameSettings - > getAiAcceptSwitchTeamPercentChance ( ) ) ) ;
2012-09-17 01:42:56 +02:00
listBoxFallbackCpuMultiplier . setSelectedItemIndex ( gameSettings - > getFallbackCpuMultiplier ( ) ) ;
2011-12-03 09:17:49 +01:00
// Control
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctClosed ) ;
2012-07-06 00:03:15 +02:00
if ( isHeadlessAdmin ( ) = = false ) {
2013-02-15 19:25:10 +01:00
if ( clientInterface - > getJoinGameInProgress ( ) = = false ) {
listBoxFactions [ i ] . setEditable ( false ) ;
listBoxTeams [ i ] . setEditable ( false ) ;
}
2011-12-03 09:17:49 +01:00
}
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ i ] . setTexture ( NULL ) ; ;
2011-12-03 09:17:49 +01:00
}
if ( hasFactions = = true & & gameSettings ! = NULL ) {
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
//for(int i=0; i < gameSettings->getFactionCount(); ++i){
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
int slot = gameSettings - > getStartLocationIndex ( i ) ;
2013-10-26 00:09:19 +02:00
if ( slot = = clientInterface - > getPlayerIndex ( ) ) {
labelPlayerNames [ slot ] . setEditable ( true ) ;
}
else {
labelPlayerNames [ slot ] . setEditable ( false ) ;
}
2011-12-03 09:17:49 +01:00
if ( i > = gameSettings - > getFactionCount ( ) ) {
if ( gameSettings - > getFactionControl ( i ) ! = ctNetworkUnassigned ) {
continue ;
}
else if ( clientInterface - > getPlayerIndex ( ) ! = slot ) {
continue ;
}
}
if ( gameSettings - > getFactionControl ( i ) = = ctNetwork | |
gameSettings - > getFactionControl ( i ) = = ctNetworkUnassigned | |
gameSettings - > getFactionControl ( i ) = = ctHuman ) {
switch ( gameSettings - > getNetworkPlayerStatuses ( i ) ) {
case npst_BeRightBack :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ slot ] . setTexture ( CoreData : : getInstance ( ) . getStatusBRBTexture ( ) ) ;
2011-12-03 09:17:49 +01:00
break ;
case npst_Ready :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ slot ] . setTexture ( CoreData : : getInstance ( ) . getStatusReadyTexture ( ) ) ;
2011-12-03 09:17:49 +01:00
break ;
case npst_PickSettings :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ slot ] . setTexture ( CoreData : : getInstance ( ) . getStatusNotReadyTexture ( ) ) ;
2011-12-03 09:17:49 +01:00
break ;
2012-09-21 17:03:13 +02:00
case npst_Disconnected :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ slot ] . setTexture ( NULL ) ;
2012-09-21 17:03:13 +02:00
break ;
2011-12-03 09:17:49 +01:00
default :
2013-10-27 17:13:27 +01:00
labelPlayerStatus [ slot ] . setTexture ( NULL ) ;
2011-12-03 09:17:49 +01:00
break ;
}
}
listBoxControls [ slot ] . setSelectedItemIndex ( gameSettings - > getFactionControl ( i ) , errorOnMissingData ) ;
2012-10-06 00:43:00 +02:00
listBoxRMultiplier [ slot ] . setSelectedItemIndex ( gameSettings - > getResourceMultiplierIndex ( i ) , errorOnMissingData ) ;
2011-12-03 09:17:49 +01:00
listBoxTeams [ slot ] . setSelectedItemIndex ( gameSettings - > getTeam ( i ) , errorOnMissingData ) ;
listBoxFactions [ slot ] . setSelectedItem ( formatString ( gameSettings - > getFactionTypeName ( i ) ) , false ) ;
if ( gameSettings - > getFactionControl ( i ) = = ctNetwork | |
gameSettings - > getFactionControl ( i ) = = ctNetworkUnassigned ) {
labelNetStatus [ slot ] . setText ( gameSettings - > getNetworkPlayerName ( i ) ) ;
if ( gameSettings - > getThisFactionIndex ( ) ! = i & &
gameSettings - > getNetworkPlayerName ( i ) ! = " " & &
gameSettings - > getNetworkPlayerName ( i ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
labelPlayerNames [ slot ] . setText ( gameSettings - > getNetworkPlayerName ( i ) ) ;
}
}
ControlType ct = gameSettings - > getFactionControl ( i ) ;
2012-10-06 01:03:05 +02:00
if ( ct = = ctHuman | | ct = = ctNetwork | | ct = = ctClosed ) {
2011-12-03 09:17:49 +01:00
listBoxRMultiplier [ slot ] . setEnabled ( false ) ;
listBoxRMultiplier [ slot ] . setVisible ( false ) ;
2012-10-06 00:43:00 +02:00
}
else {
2011-12-03 09:17:49 +01:00
listBoxRMultiplier [ slot ] . setEnabled ( true ) ;
listBoxRMultiplier [ slot ] . setVisible ( true ) ;
}
if ( ( gameSettings - > getFactionControl ( i ) = = ctNetwork | |
gameSettings - > getFactionControl ( i ) = = ctNetworkUnassigned ) & &
gameSettings - > getThisFactionIndex ( ) = = i ) {
// set my current slot to ctHuman
if ( gameSettings - > getFactionControl ( i ) ! = ctNetworkUnassigned ) {
listBoxControls [ slot ] . setSelectedItemIndex ( ctHuman ) ;
}
2012-05-11 07:11:46 +02:00
if ( checkBoxScenario . getValue ( ) = = false ) {
2013-02-15 19:25:10 +01:00
if ( clientInterface - > getJoinGameInProgress ( ) = = false ) {
listBoxFactions [ slot ] . setEditable ( true ) ;
listBoxTeams [ slot ] . setEditable ( true ) ;
}
2012-05-11 07:11:46 +02:00
}
2011-12-03 09:17:49 +01:00
if ( labelPlayerNames [ slot ] . getText ( ) = = " " & &
gameSettings - > getNetworkPlayerName ( i ) ! = " " & &
gameSettings - > getNetworkPlayerName ( i ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
labelPlayerNames [ slot ] . setText ( gameSettings - > getNetworkPlayerName ( i ) ) ;
}
}
settingsReceivedFromServer = true ;
initialSettingsReceivedFromServer = true ;
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
if ( enableFactionTexturePreview = = true ) {
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) & &
gameSettings ! = NULL ) {
if ( currentTechName_factionPreview ! = gameSettings - > getTech ( ) | |
currentFactionName_factionPreview ! = gameSettings - > getFactionTypeName ( gameSettings - > getThisFactionIndex ( ) ) ) {
currentTechName_factionPreview = gameSettings - > getTech ( ) ;
currentFactionName_factionPreview = gameSettings - > getFactionTypeName ( gameSettings - > getThisFactionIndex ( ) ) ;
2012-09-26 00:52:07 +02:00
initFactionPreview ( gameSettings ) ;
}
}
}
2013-06-19 03:03:51 +02:00
checkBoxAllowNativeLanguageTechtree . setValue ( gameSettings - > getNetworkAllowNativeLanguageTechtree ( ) ) ;
2012-09-26 00:52:07 +02:00
}
2012-05-26 08:19:30 +02:00
2012-09-26 00:52:07 +02:00
void MenuStateConnectedGame : : initFactionPreview ( const GameSettings * gameSettings ) {
string factionVideoUrl = " " ;
string factionVideoUrlFallback = " " ;
2012-05-26 08:19:30 +02:00
2012-09-26 00:52:07 +02:00
string factionDefinitionXML = Game : : findFactionLogoFile ( gameSettings , NULL , currentFactionName_factionPreview + " .xml " ) ;
if ( factionDefinitionXML ! = " " & & currentFactionName_factionPreview ! = GameConstants : : RANDOMFACTION_SLOTNAME & &
currentFactionName_factionPreview ! = GameConstants : : OBSERVER_SLOTNAME & & fileExists ( factionDefinitionXML ) = = true ) {
XmlTree xmlTree ;
std : : map < string , string > mapExtraTagReplacementValues ;
xmlTree . load ( factionDefinitionXML , Properties : : getTagReplacementValues ( & mapExtraTagReplacementValues ) ) ;
const XmlNode * factionNode = xmlTree . getRootNode ( ) ;
if ( factionNode - > hasAttribute ( " faction-preview-video " ) = = true ) {
factionVideoUrl = factionNode - > getAttribute ( " faction-preview-video " ) - > getValue ( ) ;
}
2012-05-26 08:19:30 +02:00
2012-09-26 00:52:07 +02:00
factionVideoUrlFallback = Game : : findFactionLogoFile ( gameSettings , NULL , " preview_video.* " ) ;
if ( factionVideoUrl = = " " ) {
factionVideoUrl = factionVideoUrlFallback ;
factionVideoUrlFallback = " " ;
}
}
2012-05-26 01:00:36 +02:00
2012-09-26 00:52:07 +02:00
if ( factionVideoUrl ! = " " ) {
if ( CoreData : : getInstance ( ) . getMenuMusic ( ) - > getVolume ( ) ! = 0 ) {
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( 0 ) ;
factionVideoSwitchedOffVolume = true ;
}
2012-05-26 08:19:30 +02:00
2012-09-26 00:52:07 +02:00
if ( currentFactionLogo ! = factionVideoUrl ) {
currentFactionLogo = factionVideoUrl ;
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false & &
2013-11-19 22:57:28 +01:00
: : Shared : : Graphics : : VideoPlayer : : hasBackEndVideoPlayer ( ) = = true ) {
2012-05-26 01:00:36 +02:00
2012-09-26 00:52:07 +02:00
if ( factionVideo ! = NULL ) {
factionVideo - > closePlayer ( ) ;
delete factionVideo ;
factionVideo = NULL ;
2011-12-03 09:17:49 +01:00
}
2012-09-26 00:52:07 +02:00
string introVideoFile = factionVideoUrl ;
string introVideoFileFallback = factionVideoUrlFallback ;
Context * c = GraphicsInterface : : getInstance ( ) . getCurrentContext ( ) ;
SDL_Surface * screen = static_cast < ContextGl * > ( c ) - > getPlatformContextGlPtr ( ) - > getScreen ( ) ;
string vlcPluginsPath = Config : : getInstance ( ) . getString ( " VideoPlayerPluginsPath " , " " ) ;
//printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
factionVideo = new VideoPlayer (
& Renderer : : getInstance ( ) ,
introVideoFile ,
introVideoFileFallback ,
screen ,
0 , 0 ,
screen - > w ,
screen - > h ,
screen - > format - > BitsPerPixel ,
2012-09-27 03:17:57 +02:00
true ,
2012-09-26 00:52:07 +02:00
vlcPluginsPath ,
SystemFlags : : VERBOSE_MODE_ENABLED ) ;
factionVideo - > initPlayer ( ) ;
2011-12-03 09:17:49 +01:00
}
}
}
2012-09-26 00:52:07 +02:00
else {
//switch on music again!!
Config & config = Config : : getInstance ( ) ;
float configVolume = ( config . getInt ( " SoundVolumeMusic " ) / 100.f ) ;
if ( factionVideoSwitchedOffVolume ) {
if ( CoreData : : getInstance ( ) . getMenuMusic ( ) - > getVolume ( ) ! = configVolume ) {
CoreData : : getInstance ( ) . getMenuMusic ( ) - > setVolume ( configVolume ) ;
}
factionVideoSwitchedOffVolume = false ;
}
if ( factionVideo ! = NULL ) {
factionVideo - > closePlayer ( ) ;
delete factionVideo ;
factionVideo = NULL ;
}
}
if ( factionVideo = = NULL ) {
2013-02-12 00:43:30 +01:00
string factionLogo = Game : : findFactionLogoFile ( gameSettings , NULL , GameConstants : : PREVIEW_SCREEN_FILE_FILTER ) ;
2012-09-26 00:52:07 +02:00
if ( factionLogo = = " " ) {
factionLogo = Game : : findFactionLogoFile ( gameSettings , NULL ) ;
}
if ( currentFactionLogo ! = factionLogo ) {
currentFactionLogo = factionLogo ;
loadFactionTexture ( currentFactionLogo ) ;
}
}
2011-12-03 09:17:49 +01:00
}
void MenuStateConnectedGame : : RestoreLastGameSettings ( ) {
// Ensure we have set the gamesettings at least once
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
GameSettings gameSettings = * clientInterface - > getGameSettings ( ) ;
CoreData : : getInstance ( ) . loadGameSettingsFromFile ( HEADLESS_SAVED_GAME_FILENAME , & gameSettings ) ;
if ( gameSettings . getMap ( ) = = " " ) {
2012-01-06 07:55:27 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2011-12-03 09:17:49 +01:00
loadGameSettings ( & gameSettings ) ;
}
setupUIFromGameSettings ( & gameSettings , false ) ;
needToBroadcastServerSettings = true ;
broadcastServerSettingsDelayTimer = time ( NULL ) ;
}
2011-12-28 05:46:36 +01:00
int MenuStateConnectedGame : : setupMapList ( string scenario ) {
int initialMapSelection = 0 ;
try {
Config & config = Config : : getInstance ( ) ;
vector < string > invalidMapList ;
string scenarioDir = Scenario : : getScenarioDir ( dirList , scenario ) ;
vector < string > pathList = config . getPathListForType ( ptMaps , scenarioDir ) ;
vector < string > allMaps = MapPreview : : findAllValidMaps ( pathList , scenarioDir , false , true , & invalidMapList ) ;
if ( scenario ! = " " ) {
vector < string > allMaps2 = MapPreview : : findAllValidMaps ( config . getPathListForType ( ptMaps , " " ) , " " , false , true , & invalidMapList ) ;
copy ( allMaps2 . begin ( ) , allMaps2 . end ( ) , std : : inserter ( allMaps , allMaps . begin ( ) ) ) ;
std : : sort ( allMaps . begin ( ) , allMaps . end ( ) ) ;
}
if ( allMaps . empty ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " No maps were found! " ) ;
2011-12-28 05:46:36 +01:00
}
vector < string > results ;
copy ( allMaps . begin ( ) , allMaps . end ( ) , std : : back_inserter ( results ) ) ;
mapFiles = results ;
for ( unsigned int i = 0 ; i < GameConstants : : maxPlayers + 1 ; + + i ) {
playerSortedMaps [ i ] . clear ( ) ;
formattedPlayerSortedMaps [ i ] . clear ( ) ;
}
copy ( mapFiles . begin ( ) , mapFiles . end ( ) , std : : back_inserter ( playerSortedMaps [ 0 ] ) ) ;
copy ( playerSortedMaps [ 0 ] . begin ( ) , playerSortedMaps [ 0 ] . end ( ) , std : : back_inserter ( formattedPlayerSortedMaps [ 0 ] ) ) ;
std : : for_each ( formattedPlayerSortedMaps [ 0 ] . begin ( ) , formattedPlayerSortedMaps [ 0 ] . end ( ) , FormatString ( ) ) ;
2012-07-06 02:16:48 +02:00
formattedMapFiles . clear ( ) ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) mapFiles . size ( ) ; i + + ) { // fetch info and put map in right list
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( mapFiles . at ( i ) , scenarioDir , false ) , & mapInfo , false ) ;
2011-12-28 05:46:36 +01:00
if ( GameConstants : : maxPlayers + 1 < = mapInfo . players ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2013-12-17 08:54:33 +01:00
snprintf ( szBuf , 8096 , " Sorted map list [%d] does not match \n current map playercount [%d] \n for file [%s] \n map [%s] " , GameConstants : : maxPlayers + 1 , mapInfo . players , Config : : getMapPath ( mapFiles . at ( i ) , " " , false ) . c_str ( ) , mapInfo . desc . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
}
playerSortedMaps [ mapInfo . players ] . push_back ( mapFiles . at ( i ) ) ;
formattedPlayerSortedMaps [ mapInfo . players ] . push_back ( formatString ( mapFiles . at ( i ) ) ) ;
if ( config . getString ( " InitialMap " , " Conflict " ) = = formattedPlayerSortedMaps [ mapInfo . players ] . back ( ) ) {
initialMapSelection = i ;
}
2012-03-03 05:33:39 +01:00
formattedMapFiles . push_back ( formatString ( mapFiles . at ( i ) ) ) ;
2011-12-28 05:46:36 +01:00
}
if ( scenario ! = " " ) {
string file = Scenario : : getScenarioPath ( dirList , scenario ) ;
loadScenarioInfo ( file , & scenarioInfo ) ;
2013-12-17 08:54:33 +01:00
loadMapInfo ( Config : : getMapPath ( scenarioInfo . mapName , scenarioDir , true ) , & mapInfo , false ) ;
2012-03-03 05:33:39 +01:00
2012-11-10 07:37:23 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] listBoxMap.getSelectedItemIndex() = %d, mapFiles.size() = " MG_SIZE_T_SPECIFIER " , mapInfo.players = %d, formattedPlayerSortedMaps[mapInfo.players].size() = " MG_SIZE_T_SPECIFIER " , scenarioInfo.mapName [%s] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , listBoxMap . getSelectedItemIndex ( ) , mapFiles . size ( ) , mapInfo . players , formattedPlayerSortedMaps [ mapInfo . players ] . size ( ) , scenarioInfo . mapName . c_str ( ) ) ;
2011-12-28 05:46:36 +01:00
listBoxMap . setItems ( formattedPlayerSortedMaps [ mapInfo . players ] ) ;
}
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-28 05:46:36 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
//abort();
}
return initialMapSelection ;
}
2013-06-13 03:37:15 +02:00
int MenuStateConnectedGame : : setupTechList ( string scenario , bool forceLoad ) {
2011-12-28 05:46:36 +01:00
int initialTechSelection = 0 ;
try {
Config & config = Config : : getInstance ( ) ;
string scenarioDir = Scenario : : getScenarioDir ( dirList , scenario ) ;
vector < string > results ;
vector < string > techPaths = config . getPathListForType ( ptTechs , scenarioDir ) ;
findDirs ( techPaths , results ) ;
if ( results . empty ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " No tech-trees were found! " ) ;
2011-12-28 05:46:36 +01:00
}
techTreeFiles = results ;
2013-10-26 00:09:19 +02:00
vector < string > translatedTechs ;
2011-12-28 05:46:36 +01:00
for ( unsigned int i = 0 ; i < results . size ( ) ; i + + ) {
2013-10-26 00:09:19 +02:00
//printf("TECHS i = %d results [%s] scenario [%s]\n",i,results[i].c_str(),scenario.c_str());
2011-12-28 05:46:36 +01:00
results . at ( i ) = formatString ( results . at ( i ) ) ;
if ( config . getString ( " InitialTechTree " , " Megapack " ) = = results . at ( i ) ) {
initialTechSelection = i ;
}
2013-06-13 03:37:15 +02:00
string txTech = techTree - > getTranslatedName ( techTreeFiles . at ( i ) , forceLoad ) ;
2013-06-16 03:14:04 +02:00
translatedTechs . push_back ( formatString ( txTech ) ) ;
2013-06-13 03:37:15 +02:00
}
2013-10-26 00:09:19 +02:00
2013-06-13 03:37:15 +02:00
listBoxTechTree . setItems ( results , translatedTechs ) ;
2011-12-28 05:46:36 +01:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-28 05:46:36 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
}
return initialTechSelection ;
}
void MenuStateConnectedGame : : setupTilesetList ( string scenario ) {
try {
Config & config = Config : : getInstance ( ) ;
string scenarioDir = Scenario : : getScenarioDir ( dirList , scenario ) ;
vector < string > results ;
findDirs ( config . getPathListForType ( ptTilesets , scenarioDir ) , results ) ;
if ( results . empty ( ) ) {
2013-11-16 04:33:13 +01:00
//throw megaglest_runtime_error("No tile-sets were found!");
showMessageBox ( " No tile-sets were found! " , " Error " , false ) ;
2011-12-28 05:46:36 +01:00
}
2013-11-16 04:33:13 +01:00
else {
tilesetFiles = results ;
std : : for_each ( results . begin ( ) , results . end ( ) , FormatString ( ) ) ;
2011-12-28 05:46:36 +01:00
2013-11-16 04:33:13 +01:00
listBoxTileset . setItems ( results ) ;
}
2011-12-28 05:46:36 +01:00
}
catch ( const std : : exception & ex ) {
2012-03-31 10:28:42 +02:00
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " In [%s::%s %d] \n Error detected: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-12-28 05:46:36 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-12-28 05:46:36 +01:00
}
}
void MenuStateConnectedGame : : loadScenarioInfo ( string file , ScenarioInfo * scenarioInfo ) {
2013-05-21 22:28:42 +02:00
bool isTutorial = Scenario : : isGameTutorial ( file ) ;
Scenario : : loadScenarioInfo ( file , scenarioInfo , isTutorial ) ;
2011-12-28 05:46:36 +01:00
previewLoadDelayTimer = time ( NULL ) ;
needToLoadTextures = true ;
}
2010-04-22 01:13:39 +02:00
} } //end namespace