2010-04-22 01:13:39 +02:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Marti<74> o Figueroa
//
// 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"
2010-04-22 01:13:39 +02:00
# include "leak_dumper.h"
2011-02-08 04:50:59 +01:00
# include "map_preview.h"
2010-04-22 01:13:39 +02:00
namespace Glest { namespace Game {
2011-03-19 13:04:18 +01:00
static const string ITEM_MISSING = " ***missing*** " ;
2010-04-22 01:13:39 +02:00
using namespace Shared : : Util ;
struct FormatString {
void operator ( ) ( string & s ) {
s = formatString ( s ) ;
}
} ;
// =====================================================
// class MenuStateConnectedGame
// =====================================================
2010-05-09 23:23:13 +02:00
MenuStateConnectedGame : : MenuStateConnectedGame ( Program * program , MainMenu * mainMenu , JoinMenu joinMenuInfo , bool openNetworkSlots ) :
2010-09-09 23:07:39 +02:00
MenuState ( program , mainMenu , " connected-game " )
2010-04-22 01:13:39 +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 ;
2010-08-31 08:38:27 +02:00
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 = " " ;
getMissingMapFromFTPServerInProgress = false ;
getMissingTilesetFromFTPServer = " " ;
getMissingTilesetFromFTPServerInProgress = false ;
2011-03-10 23:00:59 +01:00
getMissingTechtreeFromFTPServer = " " ;
getMissingTechtreeFromFTPServerInProgress = false ;
2011-03-19 06:11:36 +01:00
lastCheckedCRCTilesetName = " " ;
lastCheckedCRCTechtreeName = " " ;
lastCheckedCRCMapName = " " ;
lastCheckedCRCTilesetValue = - 1 ;
lastCheckedCRCTechtreeValue = - 1 ;
lastCheckedCRCMapValue = - 1 ;
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 " ) ;
mainMessageBox . init ( lang . get ( " Ok " ) ) ;
mainMessageBox . setEnabled ( false ) ;
mainMessageBoxState = 0 ;
2010-12-29 20:31:51 +01:00
ftpMessageBox . registerGraphicComponent ( containerName , " ftpMessageBox " ) ;
2010-12-30 21:48:39 +01:00
ftpMessageBox . init ( lang . get ( " Yes " ) , lang . get ( " No " ) ) ;
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-03-11 12:11:46 +01:00
vector < string > teamItems , controlItems , results , rMultiplier , playerStatuses ;
2010-08-28 01:08:35 +02:00
int setupPos = 590 ;
int mapHeadPos = 330 ;
int mapPos = mapHeadPos - 30 ;
2010-09-11 08:08:50 +02:00
int aHeadPos = 245 ;
2010-08-28 01:08:35 +02:00
int aPos = aHeadPos - 30 ;
int networkHeadPos = 700 ;
int networkPos = networkHeadPos - 30 ;
int xoffset = 0 ;
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 " ) ;
2010-09-02 21:47:09 +02:00
labelStatus . init ( 350 , networkHeadPos + 30 ) ;
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 ( ) ) ;
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 ( ) ) ;
2010-04-22 01:13:39 +02:00
//create
2010-09-09 00:37:24 +02:00
buttonDisconnect . registerGraphicComponent ( containerName , " buttonDisconnect " ) ;
2011-03-26 14:40:22 +01:00
buttonDisconnect . init ( 350 , 180 , 125 ) ;
2010-09-09 00:37:24 +02:00
2010-04-22 01:13:39 +02:00
2010-08-28 01:08:35 +02:00
xoffset = 170 ;
2010-04-22 01:13:39 +02:00
// fog - o - war
// @350 ? 300 ?
2010-09-09 00:37:24 +02:00
labelFogOfWar . registerGraphicComponent ( containerName , " labelFogOfWar " ) ;
2010-12-20 22:59:46 +01:00
labelFogOfWar . init ( xoffset , aHeadPos , 130 ) ;
2010-08-28 01:08:35 +02:00
labelFogOfWar . setText ( lang . get ( " FogOfWar " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxFogOfWar . registerGraphicComponent ( containerName , " listBoxFogOfWar " ) ;
2010-12-20 22:59:46 +01:00
listBoxFogOfWar . init ( xoffset , aPos , 130 ) ;
listBoxFogOfWar . pushBackItem ( lang . get ( " Enabled " ) ) ;
listBoxFogOfWar . pushBackItem ( lang . get ( " Explored " ) ) ;
listBoxFogOfWar . pushBackItem ( lang . get ( " 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 " ) ;
2010-12-20 22:59:46 +01:00
labelAllowObservers . init ( xoffset + 150 , aHeadPos , 80 ) ;
2010-09-04 03:24:17 +02:00
labelAllowObservers . setText ( lang . get ( " AllowObservers " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxAllowObservers . registerGraphicComponent ( containerName , " listBoxAllowObservers " ) ;
2010-12-20 22:59:46 +01:00
listBoxAllowObservers . init ( xoffset + 150 , aPos , 80 ) ;
2010-09-04 03:24:17 +02:00
listBoxAllowObservers . pushBackItem ( lang . get ( " No " ) ) ;
listBoxAllowObservers . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxAllowObservers . setSelectedItemIndex ( 0 ) ;
listBoxAllowObservers . setEditable ( false ) ;
2010-08-05 01:39:12 +02:00
// Enable Observer Mode
2010-09-09 00:37:24 +02:00
labelEnableObserverMode . registerGraphicComponent ( containerName , " labelEnableObserverMode " ) ;
2010-08-28 01:08:35 +02:00
labelEnableObserverMode . init ( xoffset + 250 , aHeadPos , 80 ) ;
2010-09-09 00:37:24 +02:00
listBoxEnableObserverMode . registerGraphicComponent ( containerName , " listBoxEnableObserverMode " ) ;
2010-08-28 01:08:35 +02:00
listBoxEnableObserverMode . init ( xoffset + 250 , aPos , 110 ) ;
2010-08-05 01:39:12 +02:00
listBoxEnableObserverMode . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxEnableObserverMode . pushBackItem ( lang . get ( " No " ) ) ;
listBoxEnableObserverMode . setSelectedItemIndex ( 0 ) ;
listBoxEnableObserverMode . setEditable ( false ) ;
labelEnableObserverMode . setText ( lang . get ( " EnableObserverMode " ) ) ;
2010-09-09 00:37:24 +02:00
labelPathFinderType . registerGraphicComponent ( containerName , " labelPathFinderType " ) ;
2010-08-28 01:08:35 +02:00
labelPathFinderType . init ( xoffset + 450 , aHeadPos , 80 ) ;
2010-08-05 01:39:12 +02:00
labelPathFinderType . setText ( lang . get ( " PathFinderType " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxPathFinderType . registerGraphicComponent ( containerName , " listBoxPathFinderType " ) ;
2010-08-28 01:08:35 +02:00
listBoxPathFinderType . init ( xoffset + 450 , aPos , 150 ) ;
2010-08-05 01:39:12 +02:00
listBoxPathFinderType . pushBackItem ( lang . get ( " PathFinderTypeRegular " ) ) ;
2011-04-05 07:49:04 +02:00
if ( config . getBool ( " EnableRoutePlannerPathfinder " , " false " ) = = true ) {
listBoxPathFinderType . pushBackItem ( lang . get ( " PathFinderTypeRoutePlanner " ) ) ;
}
2010-08-05 01:39:12 +02:00
listBoxPathFinderType . setSelectedItemIndex ( 0 ) ;
listBoxPathFinderType . setEditable ( false ) ;
// Network Frame Period
2010-08-28 01:08:35 +02:00
xoffset = 0 ;
2010-09-09 00:37:24 +02:00
labelNetworkFramePeriod . registerGraphicComponent ( containerName , " labelNetworkFramePeriod " ) ;
2010-08-28 01:08:35 +02:00
labelNetworkFramePeriod . init ( xoffset + 170 , networkHeadPos , 80 ) ;
2010-08-05 01:39:12 +02:00
labelNetworkFramePeriod . setText ( lang . get ( " NetworkFramePeriod " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxNetworkFramePeriod . registerGraphicComponent ( containerName , " listBoxNetworkFramePeriod " ) ;
2010-08-28 01:08:35 +02:00
listBoxNetworkFramePeriod . init ( xoffset + 170 , networkPos , 80 ) ;
2010-08-05 01:39:12 +02:00
listBoxNetworkFramePeriod . pushBackItem ( " 10 " ) ;
listBoxNetworkFramePeriod . pushBackItem ( " 20 " ) ;
listBoxNetworkFramePeriod . pushBackItem ( " 30 " ) ;
listBoxNetworkFramePeriod . pushBackItem ( " 40 " ) ;
listBoxNetworkFramePeriod . setSelectedItem ( " 20 " ) ;
listBoxNetworkFramePeriod . setEditable ( false ) ;
// Network Frame Period
2010-09-09 00:37:24 +02:00
labelNetworkPauseGameForLaggedClients . registerGraphicComponent ( containerName , " labelNetworkPauseGameForLaggedClients " ) ;
2010-09-02 21:47:09 +02:00
labelNetworkPauseGameForLaggedClients . init ( xoffset + 420 , networkHeadPos , 80 ) ;
2010-08-05 01:39:12 +02:00
labelNetworkPauseGameForLaggedClients . setText ( lang . get ( " NetworkPauseGameForLaggedClients " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxNetworkPauseGameForLaggedClients . registerGraphicComponent ( containerName , " listBoxNetworkPauseGameForLaggedClients " ) ;
2010-09-02 21:47:09 +02:00
listBoxNetworkPauseGameForLaggedClients . init ( xoffset + 420 , networkPos , 80 ) ;
2010-08-05 01:39:12 +02:00
listBoxNetworkPauseGameForLaggedClients . pushBackItem ( lang . get ( " No " ) ) ;
listBoxNetworkPauseGameForLaggedClients . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxNetworkPauseGameForLaggedClients . setSelectedItem ( lang . get ( " No " ) ) ;
listBoxNetworkPauseGameForLaggedClients . setEditable ( false ) ;
// Enable Server Controlled AI
2010-09-09 00:37:24 +02:00
labelEnableServerControlledAI . registerGraphicComponent ( containerName , " labelEnableServerControlledAI " ) ;
2010-09-02 21:47:09 +02:00
labelEnableServerControlledAI . init ( xoffset + 640 , networkHeadPos , 80 ) ;
2010-08-05 01:39:12 +02:00
labelEnableServerControlledAI . setText ( lang . get ( " EnableServerControlledAI " ) ) ;
2010-09-09 00:37:24 +02:00
listBoxEnableServerControlledAI . registerGraphicComponent ( containerName , " listBoxEnableServerControlledAI " ) ;
2010-09-02 21:47:09 +02:00
listBoxEnableServerControlledAI . init ( xoffset + 640 , networkPos , 80 ) ;
2010-08-05 01:39:12 +02:00
listBoxEnableServerControlledAI . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxEnableServerControlledAI . pushBackItem ( lang . get ( " No " ) ) ;
listBoxEnableServerControlledAI . setSelectedItemIndex ( 0 ) ;
listBoxEnableServerControlledAI . setEditable ( false ) ;
2010-08-28 01:08:35 +02:00
xoffset = 70 ;
2010-09-11 08:08:50 +02:00
int labelOffset = 23 ;
2010-08-28 01:08:35 +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)
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 " ) ;
labelMapInfo . init ( xoffset + 100 , mapPos - labelOffset , 200 , 40 ) ;
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 ) ;
labelMap . setText ( lang . get ( " Map " ) ) ;
2010-08-05 01:39:12 +02:00
2010-04-22 01:13:39 +02:00
//tileset listBox
2010-08-05 01:39:12 +02:00
//listBoxTileset.init(500, 260, 150);
2010-09-09 00:37:24 +02:00
listBoxTileset . registerGraphicComponent ( containerName , " listBoxTileset " ) ;
2010-08-28 01:08:35 +02:00
listBoxTileset . init ( xoffset + 350 , mapPos , 150 ) ;
2010-04-22 01:13:39 +02:00
listBoxTileset . setEditable ( false ) ;
//listBoxTileset.setItems(results);
2010-08-05 01:39:12 +02:00
//labelTileset.init(500, 290);
2010-09-09 00:37:24 +02:00
labelTileset . registerGraphicComponent ( containerName , " labelTileset " ) ;
2010-08-28 01:08:35 +02:00
labelTileset . init ( xoffset + 350 , mapHeadPos ) ;
labelTileset . setText ( lang . get ( " Tileset " ) ) ;
2010-12-29 02:10:53 +01:00
2010-04-22 01:13:39 +02:00
//tech Tree listBox
2010-08-05 01:39:12 +02:00
//listBoxTechTree.init(700, 260, 150);
2010-04-22 01:13:39 +02:00
listBoxTechTree . setEditable ( false ) ;
//listBoxTechTree.setItems(results);
2010-08-05 01:39:12 +02:00
//labelTechTree.init(700, 290);
2010-09-09 00:37:24 +02:00
listBoxTechTree . registerGraphicComponent ( containerName , " listBoxTechTree " ) ;
2010-08-28 01:08:35 +02:00
listBoxTechTree . init ( xoffset + 550 , mapPos , 150 ) ;
2010-09-09 00:37:24 +02:00
labelTechTree . registerGraphicComponent ( containerName , " labelTechTree " ) ;
2010-08-28 01:08:35 +02:00
labelTechTree . init ( xoffset + 550 , mapHeadPos ) ;
labelTechTree . setText ( lang . get ( " TechTree " ) ) ;
2010-12-29 02:10:53 +01:00
2010-08-05 01:39:12 +02:00
2011-03-11 12:11:46 +01:00
listBoxPlayerStatus . registerGraphicComponent ( containerName , " listBoxPlayerStatus " ) ;
2011-03-26 14:40:22 +01:00
//listBoxPlayerStatus.init(10, 600, 150);
listBoxPlayerStatus . init ( 525 , 180 , 125 ) ;
2011-04-13 00:20:41 +02:00
listBoxPlayerStatus . setTextColor ( Vec3f ( 1.0f , 0.f , 0.f ) ) ;
listBoxPlayerStatus . setLighted ( true ) ;
2011-03-11 12:11:46 +01:00
playerStatuses . push_back ( lang . get ( " PlayerStatusSetup " ) ) ;
playerStatuses . push_back ( lang . get ( " PlayerStatusBeRightBack " ) ) ;
playerStatuses . push_back ( lang . get ( " PlayerStatusReady " ) ) ;
listBoxPlayerStatus . setItems ( playerStatuses ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
//list boxes
2010-11-09 00:15:50 +01:00
xoffset = 100 ;
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 ) {
2011-03-11 12:11:46 +01:00
labelPlayerStatus [ i ] . registerGraphicComponent ( containerName , " labelPlayerStatus " + intToStr ( i ) ) ;
labelPlayerStatus [ i ] . init ( 10 , setupPos - 30 - i * rowHeight , 60 ) ;
2010-09-09 00:37:24 +02:00
labelPlayers [ i ] . registerGraphicComponent ( containerName , " labelPlayers " + intToStr ( i ) ) ;
2010-11-09 00:15:50 +01:00
labelPlayers [ i ] . init ( xoffset + 0 , setupPos - 30 - i * rowHeight ) ;
2010-04-22 01:13:39 +02:00
labelPlayers [ i ] . setEditable ( false ) ;
2010-09-09 00:37:24 +02:00
labelPlayerNames [ i ] . registerGraphicComponent ( containerName , " labelPlayerNames " + intToStr ( i ) ) ;
2010-11-09 00:15:50 +01:00
labelPlayerNames [ i ] . init ( xoffset + 50 , 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 ) ) ;
2010-11-09 00:15:50 +01:00
listBoxControls [ i ] . init ( xoffset + 210 , 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 ) ) ;
listBoxRMultiplier [ i ] . init ( xoffset + 350 , setupPos - 30 - i * rowHeight , 70 ) ;
listBoxRMultiplier [ i ] . setEditable ( false ) ;
2010-09-09 00:37:24 +02:00
listBoxFactions [ i ] . registerGraphicComponent ( containerName , " listBoxFactions " + intToStr ( i ) ) ;
2010-11-09 00:15:50 +01:00
listBoxFactions [ i ] . init ( xoffset + 430 , setupPos - 30 - i * rowHeight ) ;
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 ) ) ;
2010-11-09 00:15:50 +01:00
listBoxTeams [ i ] . init ( xoffset + 590 , 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 ) ) ;
2010-11-09 00:15:50 +01:00
labelNetStatus [ i ] . init ( xoffset + 670 , setupPos - 30 - i * rowHeight , 60 ) ;
2010-09-09 00:37:24 +02:00
grabSlotButton [ i ] . registerGraphicComponent ( containerName , " grabSlotButton " + intToStr ( i ) ) ;
2010-11-09 00:15:50 +01:00
grabSlotButton [ i ] . init ( xoffset + 670 , 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 " ) ;
2010-11-09 00:15:50 +01:00
labelControl . init ( xoffset + 210 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2010-08-28 01:08:35 +02:00
labelControl . setText ( lang . get ( " Control " ) ) ;
2010-12-29 02:10:53 +01:00
2010-11-09 00:15:50 +01:00
labelRMultiplier . registerGraphicComponent ( containerName , " labelRMultiplier " ) ;
labelRMultiplier . init ( xoffset + 350 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
//labelRMultiplier.setText(lang.get("RMultiplier"));
2010-12-29 02:10:53 +01:00
2010-09-09 00:37:24 +02:00
labelFaction . registerGraphicComponent ( containerName , " labelFaction " ) ;
2010-11-09 00:15:50 +01:00
labelFaction . init ( xoffset + 430 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
2010-08-28 01:08:35 +02:00
labelFaction . setText ( lang . get ( " Faction " ) ) ;
2010-12-29 02:10:53 +01:00
2010-09-09 00:37:24 +02:00
labelTeam . registerGraphicComponent ( containerName , " labelTeam " ) ;
2010-11-09 00:15:50 +01:00
labelTeam . init ( xoffset + 590 , setupPos , 60 , GraphicListBox : : defH , true ) ;
2010-08-28 01:08:35 +02:00
labelTeam . setText ( lang . get ( " Team " ) ) ;
2010-08-06 00:27:26 +02:00
labelControl . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelFaction . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelTeam . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2010-04-22 01:13:39 +02:00
//texts
buttonDisconnect . setText ( lang . get ( " Return " ) ) ;
controlItems . push_back ( lang . get ( " Closed " ) ) ;
controlItems . push_back ( lang . get ( " CpuEasy " ) ) ;
controlItems . push_back ( lang . get ( " Cpu " ) ) ;
controlItems . push_back ( lang . get ( " CpuUltra " ) ) ;
controlItems . push_back ( lang . get ( " CpuMega " ) ) ;
controlItems . push_back ( lang . get ( " Network " ) ) ;
controlItems . push_back ( lang . get ( " Human " ) ) ;
2010-09-04 02:32:56 +02:00
2010-11-09 00:15:50 +01:00
for ( int i = 0 ; i < 45 ; + + i ) {
2010-12-01 22:18:29 +01:00
rMultiplier . push_back ( floatToStr ( 0.5f + 0.1f * i , 1 ) ) ;
2010-11-09 00:15:50 +01:00
}
2010-09-14 21:10:37 +02:00
if ( config . getBool ( " EnableNetworkCpu " , " false " ) = = true ) {
controlItems . push_back ( lang . get ( " NetworkCpuEasy " ) ) ;
controlItems . push_back ( lang . get ( " NetworkCpu " ) ) ;
controlItems . push_back ( lang . get ( " NetworkCpuUltra " ) ) ;
controlItems . push_back ( lang . get ( " NetworkCpuMega " ) ) ;
}
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 ( " " ) ;
2010-04-22 01:13:39 +02:00
labelPlayers [ i ] . setText ( lang . get ( " Player " ) + " " + intToStr ( i ) ) ;
2010-08-21 15:04:52 +02:00
labelPlayerNames [ i ] . setText ( " " ) ;
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 ) ;
listBoxRMultiplier [ i ] . setSelectedItemIndex ( 5 ) ;
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
}
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
//init controllers
listBoxControls [ 0 ] . setSelectedItemIndex ( ctHuman ) ;
2010-08-21 15:04:52 +02:00
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-03-10 00:09:32 +01:00
findDirs ( config . getPathListForType ( ptTilesets ) , tilesetFiles ) ;
findDirs ( config . getPathListForType ( ptTechs ) , techTreeFiles ) ;
2010-09-17 10:46:34 +02:00
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 = config.getInt("FTPServerPort",intToStr(ServerSocket::getFTPServerPort()).c_str());
int portNumber = clientInterface - > getServerFTPPort ( ) ;
2010-12-29 02:10:53 +01:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] Using FTP port #: %d \n " , __FILE__ , __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 ;
if ( mapPathList . size ( ) > 0 ) {
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 ) ;
if ( tilesetsList . size ( ) > 0 ) {
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 ;
vector < string > techtreesList = Config : : getInstance ( ) . getPathListForType ( ptTechs ) ;
if ( techtreesList . size ( ) > 0 ) {
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 ) ;
if ( scenariosList . size ( ) > 0 ) {
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
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 ,
2011-04-10 00:20:10 +02:00
fileArchiveExtractCommandParameters , fileArchiveExtractCommandSuccessResult ) ;
2010-12-29 02:10:53 +01:00
ftpClientThread - > start ( ) ;
}
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
}
2010-08-31 08:38:27 +02:00
MenuStateConnectedGame : : ~ MenuStateConnectedGame ( ) {
2010-12-29 02:10:53 +01:00
if ( ftpClientThread ! = NULL ) {
2011-01-10 01:05:31 +01:00
ftpClientThread - > setCallBackObject ( NULL ) ;
2010-12-31 22:02:06 +01:00
if ( ftpClientThread - > shutdownAndWait ( ) = = true ) {
delete ftpClientThread ;
ftpClientThread = NULL ;
}
2010-12-29 02:10:53 +01:00
}
2011-04-13 03:11:23 +02:00
cleanupMapPreviewTexture ( ) ;
2010-08-31 08:38:27 +02:00
}
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
2011-01-10 01:05:31 +01:00
if ( mainMessageBox . getEnabled ( ) ) {
2010-09-17 08:37:08 +02:00
int button = 1 ;
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 ( ) ) ;
2011-01-10 01:05:31 +01:00
if ( button = = 1 ) {
2010-09-17 08:37:08 +02:00
mainMessageBox . setEnabled ( false ) ;
}
}
}
2010-12-29 20:31:51 +01:00
else if ( ftpMessageBox . getEnabled ( ) ) {
int button = 1 ;
if ( ftpMessageBox . mouseClick ( x , y , button ) ) {
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
ftpMessageBox . setEnabled ( false ) ;
if ( button = = 1 ) {
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingMapNowDownloading " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingMapNowDownloading " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , getMissingMapFromFTPServer . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s is attempting to download the map: %s " , getHumanPlayerName ( ) . c_str ( ) , getMissingMapFromFTPServer . c_str ( ) ) ;
}
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 ) {
ftpClientThread - > addMapToRequests ( getMissingMapFromFTPServer ) ;
2011-01-04 23:14:42 +01:00
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-04 09:44:00 +01:00
fileFTPProgressList [ getMissingMapFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
2011-03-15 16:30:28 +01:00
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingTilesetNowDownloading " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingTilesetNowDownloading " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , getMissingTilesetFromFTPServer . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s is attempting to download the tileset: %s " , getHumanPlayerName ( ) . c_str ( ) , getMissingTilesetFromFTPServer . c_str ( ) ) ;
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
2011-01-01 01:50:10 +01:00
if ( ftpClientThread ! = NULL ) {
ftpClientThread - > addTilesetToRequests ( getMissingTilesetFromFTPServer ) ;
2011-01-04 23:14:42 +01:00
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-04 09:44:00 +01:00
fileFTPProgressList [ getMissingTilesetFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
2011-03-15 16:30:28 +01:00
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingTechtreeNowDownloading " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingTechtreeNowDownloading " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , getMissingTechtreeFromFTPServer . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s is attempting to download the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , getMissingTechtreeFromFTPServer . c_str ( ) ) ;
}
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , localEcho , languageList [ i ] ) ;
}
2011-03-10 00:09:32 +01:00
if ( ftpClientThread ! = NULL ) {
ftpClientThread - > addTechtreeToRequests ( getMissingTechtreeFromFTPServer ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
fileFTPProgressList [ getMissingTechtreeFromFTPServer ] = pair < int , string > ( 0 , " " ) ;
2011-03-15 16:30:28 +01:00
safeMutexFTPProgress . ReleaseLock ( ) ;
2011-01-01 01:50:10 +01:00
}
}
2010-12-29 20:31:51 +01:00
}
}
}
2010-09-17 08:37:08 +02:00
else if ( buttonDisconnect . mouseClick ( x , y ) ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
2011-01-10 01:05:31 +01:00
if ( clientInterface - > getSocket ( ) ! = NULL ) {
if ( clientInterface - > isConnected ( ) = = 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 ) {
string sQuitText = lang . get ( " QuitGame " , languageList [ i ] ) ;
clientInterface - > sendTextMessage ( sQuitText , - 1 , false , languageList [ i ] ) ;
2011-04-05 22:19:25 +02:00
//printf("~~~ langList[%s] localLang[%s] msg[%s]\n",languageList[i].c_str(),lang.getLanguage().c_str(), sQuitText.c_str());
2011-04-05 20:39:47 +02:00
}
2010-07-02 18:54:28 +02:00
sleep ( 1 ) ;
2010-04-22 01:13:39 +02:00
}
clientInterface - > close ( ) ;
}
clientInterface - > reset ( ) ;
networkManager . end ( ) ;
currentFactionName = " " ;
currentMap = " " ;
2010-05-09 23:23:13 +02:00
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
2011-01-10 01:05:31 +01:00
if ( initialSettingsReceivedFromServer = = false ) return ;
2010-08-05 02:48:46 +02:00
2010-06-30 16:51:30 +02:00
// Only allow changes after we get game settings from the server
2011-03-26 14:40:22 +01:00
if ( clientInterface - > isConnected ( ) = = true ) {
int myCurrentIndex = - 1 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) { // find my current index by looking at editable listBoxes
if ( listBoxFactions [ i ] . getEditable ( ) ) {
myCurrentIndex = i ;
}
2010-04-30 03:08:29 +02:00
}
2011-03-26 14:40:22 +01:00
if ( myCurrentIndex ! = - 1 )
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2010-06-30 16:51:30 +02:00
if ( listBoxFactions [ i ] . getEditable ( ) ) {
2011-03-26 14:40:22 +01:00
if ( listBoxFactions [ i ] . mouseClick ( x , y ) ) {
2010-06-30 16:51:30 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
ClientInterface * clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
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 ;
2010-04-29 01:59:37 +02:00
}
2010-04-30 03:08:29 +02:00
}
2011-03-26 14:40:22 +01:00
if ( listBoxTeams [ i ] . getEditable ( ) ) {
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 ;
}
}
2011-03-26 14:40:22 +01:00
if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) & & ( labelNetStatus [ i ] . getText ( )
= = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) ) {
if ( grabSlotButton [ i ] . mouseClick ( x , y ) ) {
2010-06-30 16:51:30 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
clientInterface - > setGameSettingsReceived ( false ) ;
2011-03-26 14:40:22 +01:00
settingsReceivedFromServer = false ;
2011-03-29 11:45:15 +02: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 " , __FILE__ , __FUNCTION__ , __LINE__ , clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) , i ) ;
2011-04-05 07:32:35 +02:00
clientInterface - > sendSwitchSetupRequest (
listBoxFactions [ myCurrentIndex ] . getSelectedItem ( ) ,
myCurrentIndex ,
i ,
listBoxTeams [ myCurrentIndex ] . getSelectedItemIndex ( ) ,
//labelPlayerNames[myCurrentIndex].getText(),
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 ) ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-03-11 12:11:46 +01:00
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __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 ( ) ;
if ( clientInterface - > isConnected ( ) ) {
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 ;
}
}
2010-04-22 01:13:39 +02:00
}
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
}
2010-07-02 18:54:28 +02:00
void MenuStateConnectedGame : : returnToJoinMenu ( ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-02 18:54:28 +02:00
2011-01-10 01:05:31 +01:00
if ( ftpClientThread ! = NULL ) {
ftpClientThread - > setCallBackObject ( NULL ) ;
if ( ftpClientThread - > shutdownAndWait ( ) = = true ) {
delete ftpClientThread ;
ftpClientThread = NULL ;
}
}
2010-07-02 18:54:28 +02:00
if ( returnMenuInfo = = jmSimple ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-09 23:23:13 +02:00
mainMenu - > setState ( new MenuStateJoinGame ( program , mainMenu ) ) ;
}
2010-07-02 18:54:28 +02:00
else {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
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 ) ;
}
2010-04-22 01:13:39 +02:00
buttonDisconnect . mouseMove ( x , y ) ;
2010-08-21 15:04:52 +02:00
bool editingPlayerName = false ;
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-08-21 15:04:52 +02:00
if ( labelPlayerNames [ i ] . mouseMove ( x , y ) = = true ) {
editingPlayerName = true ;
}
2010-04-22 01:13:39 +02:00
}
2010-08-21 15:04:52 +02:00
if ( editingPlayerName = = false ) {
setActiveInputLabel ( NULL ) ;
}
2010-04-22 01:13:39 +02:00
listBoxMap . mouseMove ( x , y ) ;
listBoxFogOfWar . mouseMove ( x , y ) ;
2010-09-04 03:24:17 +02:00
listBoxAllowObservers . 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 ) ;
2010-04-22 01:13:39 +02:00
}
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
if ( mainMessageBox . getEnabled ( ) ) {
2010-09-17 08:37:08 +02:00
renderer . renderMessageBox ( & mainMessageBox ) ;
}
2010-12-29 20:31:51 +01:00
2010-08-05 02:48:46 +02:00
if ( ! initialSettingsReceivedFromServer ) return ;
2010-07-08 10:29:51 +02:00
2010-08-31 08:38:27 +02:00
if ( factionTexture ! = NULL ) {
2010-09-02 21:47:09 +02:00
//renderer.renderTextureQuad(60+575+80,365,200,225,factionTexture,1);
renderer . renderTextureQuad ( 800 , 600 , 200 , 150 , factionTexture , 1 ) ;
2010-08-31 08:38:27 +02:00
}
2011-04-13 03:11:23 +02:00
if ( mapPreviewTexture ! = NULL ) {
renderer . renderTextureQuad ( 5 , 185 , 150 , 150 , mapPreviewTexture , 1.0f ) ;
//printf("=================> Rendering map preview texture\n");
}
2010-08-31 08:38:27 +02:00
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 ( ) ;
const FontMetrics * fontMetrics = CoreData : : getInstance ( ) . getMenuFontNormal ( ) - > getMetrics ( ) ;
if ( fontMetrics = = NULL ) {
throw runtime_error ( " fontMetrics == NULL " ) ;
}
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 ) ;
2010-10-22 09:28:55 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
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
Vec3f playerColor = crcPlayerTextureCache [ i ] - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ;
renderer . renderLabel ( & labelPlayers [ i ] , & playerColor ) ;
// 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 ] ) ;
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-04-23 01:18:04 +02:00
//renderer.renderLabel(&labelNetStatus[i]);
2010-12-29 02:10:53 +01:00
2010-06-29 08:50:35 +02:00
if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) & &
( labelNetStatus [ i ] . getText ( ) = = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) ) {
2010-04-29 01:59:37 +02:00
renderer . renderButton ( & grabSlotButton [ i ] ) ;
}
else if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) | |
2010-04-23 01:18:04 +02:00
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) ) {
renderer . renderLabel ( & labelNetStatus [ i ] ) ;
}
2010-08-21 15:04:52 +02:00
if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) | |
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) ) {
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
if ( difftime ( time ( NULL ) , timerLabelFlash ) < 1 ) {
renderer . renderLabel ( & labelDataSynchInfo , & RED ) ;
}
else {
renderer . renderLabel ( & labelDataSynchInfo , & WHITE ) ;
if ( difftime ( time ( NULL ) , timerLabelFlash ) > 2 ) {
timerLabelFlash = time ( NULL ) ;
}
}
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 ) ;
2010-04-22 01:13:39 +02:00
renderer . renderLabel ( & labelTileset ) ;
renderer . renderLabel ( & labelTechTree ) ;
renderer . renderLabel ( & labelControl ) ;
2010-11-09 00:15:50 +01:00
//renderer.renderLabel(&labelRMultiplier);
2010-04-22 01:13:39 +02:00
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 ) ;
2010-09-04 03:24:17 +02:00
renderer . renderListBox ( & listBoxAllowObservers ) ;
2010-04-22 01:13:39 +02:00
renderer . renderListBox ( & listBoxTileset ) ;
renderer . renderListBox ( & listBoxTechTree ) ;
2010-08-05 01:39:12 +02:00
renderer . renderLabel ( & labelEnableObserverMode ) ;
renderer . renderLabel ( & labelPathFinderType ) ;
renderer . renderListBox ( & listBoxEnableObserverMode ) ;
renderer . renderListBox ( & listBoxPathFinderType ) ;
renderer . renderListBox ( & listBoxEnableServerControlledAI ) ;
renderer . renderLabel ( & labelEnableServerControlledAI ) ;
renderer . renderLabel ( & labelNetworkFramePeriod ) ;
renderer . renderListBox ( & listBoxNetworkFramePeriod ) ;
renderer . renderLabel ( & labelNetworkPauseGameForLaggedClients ) ;
renderer . renderListBox ( & listBoxNetworkPauseGameForLaggedClients ) ;
2011-01-04 23:14:42 +01:00
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , string ( __FILE__ ) + " _ " + intToStr ( __LINE__ ) ) ;
2011-01-04 09:44:00 +01:00
if ( fileFTPProgressList . size ( ) > 0 ) {
2011-03-27 18:39:19 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2011-01-04 09:44:00 +01:00
int yLocation = buttonDisconnect . getY ( ) ;
for ( std : : map < string , pair < int , string > > : : iterator iterMap = fileFTPProgressList . begin ( ) ;
iterMap ! = fileFTPProgressList . end ( ) ; + + iterMap ) {
2011-03-27 18:39:19 +02:00
string progressLabelPrefix = lang . get ( " 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-01-04 09:44:00 +01:00
renderer . renderProgressBar (
iterMap - > second . first ,
10 ,
yLocation ,
CoreData : : getInstance ( ) . getDisplayFontSmall ( ) ,
2011-01-04 23:13:49 +01:00
350 , progressLabelPrefix ) ;
2011-01-04 09:44:00 +01:00
2011-01-09 06:59:35 +01:00
yLocation - = 10 ;
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 ) ;
bool renderAll = ( listBoxFogOfWar . getSelectedItemIndex ( ) = = 2 ) ;
renderer . renderMapPreview ( & mapPreview , renderAll , 10 , 350 , & mapPreviewTexture ) ;
}
2010-09-14 08:10:48 +02:00
}
2010-09-15 01:02:50 +02:00
renderer . renderChatManager ( & chatManager ) ;
renderer . renderConsole ( & console , showFullConsole , true ) ;
2010-04-22 01:13:39 +02:00
}
catch ( const std : : exception & ex ) {
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
2010-04-22 01:13:39 +02:00
throw runtime_error ( szBuf ) ;
}
}
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
ClientInterface * clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
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 ( ) ) {
if ( difftime ( time ( NULL ) , lastNetworkSendPing ) > = GameConstants : : networkPingInterval ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] about to sendPingMessage... \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-09 17:59:49 +02:00
2010-07-09 20:02:31 +02:00
lastNetworkSendPing = time ( NULL ) ;
clientInterface - > sendPingMessage ( GameConstants : : networkPingInterval , time ( NULL ) ) ;
2010-07-09 19:12:57 +02:00
2011-03-29 11:45:15 +02: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 " , __FILE__ , __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
2010-08-26 18:03:54 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) & &
pingCount > = 3 & & clientInterface - > getLastPingLag ( ) > = ( GameConstants : : networkPingInterval * 3 ) ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-08-26 18:03:54 +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 ) {
//string playerNameStr = getHumanPlayerName();
clientInterface - > sendTextMessage ( lang . get ( " ConnectionTimedOut " , languageList [ i ] ) , - 1 , false , languageList [ i ] ) ;
sleep ( 1 ) ;
clientInterface - > close ( ) ;
}
2010-07-09 20:02:31 +02:00
}
2010-07-09 20:49:01 +02:00
pingCount + + ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-09 19:12:57 +02:00
}
2010-07-09 17:01:49 +02:00
}
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
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 ( ) ) {
2010-04-22 01:13:39 +02:00
buttonDisconnect . setText ( lang . get ( " Disconnect " ) ) ;
2010-08-22 10:00:05 +02:00
if ( clientInterface - > getAllowDownloadDataSynch ( ) = = false ) {
2010-04-22 01:13:39 +02:00
string label = lang . get ( " ConnectedToServer " ) ;
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
int32 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() + "]");
2011-04-01 01:26:32 +02:00
tilesetCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + gameSettings - > getTileset ( ) + string ( " /* " ) , " .xml " , NULL , true ) ;
2011-03-19 06:11:36 +01:00
// Test data synch
//tilesetCRC++;
lastCheckedCRCTilesetValue = tilesetCRC ;
lastCheckedCRCTilesetName = gameSettings - > getTileset ( ) ;
}
int32 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-13 03:51:15 +02:00
if ( techCRC ! = 0 & & techCRC ! = gameSettings - > getTechCRC ( ) & &
listBoxTechTree . getSelectedItemIndex ( ) > = 0 & &
listBoxTechTree . getSelectedItem ( ) ! = ITEM_MISSING ) {
time_t now = time ( NULL ) ;
time_t lastUpdateDate = getFolderTreeContentsCheckSumRecursivelyLastGenerated ( config . getPathListForType ( ptTechs , " " ) , string ( " / " ) + gameSettings - > getTech ( ) + string ( " /* " ) , " .xml " ) ;
const time_t REFRESH_CRC_DAY_SECONDS = 60 * 60 * 24 ;
if ( lastUpdateDate < = 0 | |
difftime ( time ( NULL ) , lastUpdateDate ) > = REFRESH_CRC_DAY_SECONDS ) {
techCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , string ( " / " ) + gameSettings - > getTech ( ) + string ( " /* " ) , " .xml " , NULL , true ) ;
}
}
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
int32 factionCRC = 0 ;
if ( factionName ! = GameConstants : : RANDOMFACTION_SLOTNAME & &
factionName ! = GameConstants : : OBSERVER_SLOTNAME & &
factionName ! = ITEM_MISSING ) {
2011-04-03 09:09:54 +02:00
//factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true);
factionCRC = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + gameSettings - > getTech ( ) + " /factions/ " + factionName + " /* " , " .xml " , NULL ) ;
2011-03-19 19:05:13 +01:00
}
2011-03-19 13:04:18 +01:00
factionCRCList . push_back ( make_pair ( factionName , factionCRC ) ) ;
}
2011-03-20 01:11:00 +01:00
//console.addLine("Found factions: " + intToStr(factionCRCList.size()));
2011-03-19 06:11:36 +01:00
}
int32 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 ;
string file = Map : : 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 ) {
2011-01-14 18:57:37 +01:00
string labelSynch = lang . get ( " 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 & &
listBoxMap . getSelectedItem ( ) ! = ITEM_MISSING ) {
2011-01-14 18:57:37 +01:00
labelSynch = labelSynch + " " + lang . get ( " Map " ) ;
2011-01-09 05:49:21 +01:00
if ( updateDataSynchDetailText = = true & &
2011-01-14 18:57:37 +01:00
lastMapDataSynchError ! = lang . get ( " DataNotSynchedMap " ) + " " + listBoxMap . getSelectedItem ( ) ) {
lastMapDataSynchError = lang . get ( " 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 ) {
string msg = lang . get ( " DataNotSynchedMap " , languageList [ i ] ) + " " + listBoxMap . getSelectedItem ( ) ;
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 & &
listBoxTileset . getSelectedItem ( ) ! = ITEM_MISSING ) {
2011-01-14 18:57:37 +01:00
labelSynch = labelSynch + " " + lang . get ( " Tileset " ) ;
2011-01-09 05:49:21 +01:00
if ( updateDataSynchDetailText = = true & &
2011-01-14 18:57:37 +01:00
lastTileDataSynchError ! = lang . get ( " DataNotSynchedTileset " ) + " " + listBoxTileset . getSelectedItem ( ) ) {
lastTileDataSynchError = lang . get ( " 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 ) {
string msg = lang . get ( " DataNotSynchedTileset " , languageList [ i ] ) + " " + listBoxTileset . getSelectedItem ( ) ;
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 & &
listBoxTechTree . getSelectedItem ( ) ! = ITEM_MISSING ) {
2011-03-10 00:09:32 +01:00
labelSynch = labelSynch + " " + lang . get ( " TechTree " ) ;
if ( updateDataSynchDetailText = = true & &
lastTechtreeDataSynchError ! = lang . get ( " DataNotSynchedTechtree " ) + " " + listBoxTechTree . getSelectedItem ( ) ) {
lastTechtreeDataSynchError = lang . get ( " 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 ) {
string msg = lang . get ( " DataNotSynchedTechtree " , languageList [ i ] ) + " " + listBoxTechTree . getSelectedItem ( ) ;
bool localEcho = lang . isLanguageLocal ( languageList [ i ] ) ;
clientInterface - > sendTextMessage ( msg , - 1 , localEcho , languageList [ i ] ) ;
}
2011-01-09 05:49:21 +01:00
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 = " " ;
vector < pair < string , int32 > > serverFactionCRCList = gameSettings - > getFactionCRCList ( ) ;
for ( unsigned int factionIdx = 0 ; factionIdx < serverFactionCRCList . size ( ) ; + + factionIdx ) {
2011-03-19 13:04:18 +01:00
pair < string , int32 > & 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 ) {
pair < string , int32 > & clientFaction = factionCRCList [ clientFactionIdx ] ;
if ( serverFaction . first = = clientFaction . first ) {
foundFaction = true ;
if ( serverFaction . second ! = clientFaction . second ) {
if ( mismatchedFactionText = = " " ) {
mismatchedFactionText = " The following factions are mismatched: " ;
if ( lang . hasString ( " MismatchedFactions " , languageList [ i ] ) = = true ) {
mismatchedFactionText = lang . get ( " MismatchedFactions " , languageList [ i ] ) ;
}
mismatchedFactionText + = " [ " + intToStr ( factionCRCList . size ( ) ) + " ][ " + intToStr ( serverFactionCRCList . size ( ) ) + " ] - " ;
}
mismatchedFactionText + = serverFaction . first + " , " ;
}
break ;
}
}
if ( foundFaction = = false ) {
if ( mismatchedFactionText = = " " ) {
mismatchedFactionText = " The following factions are mismatched: " ;
if ( lang . hasString ( " MismatchedFactions " , languageList [ i ] ) = = true ) {
mismatchedFactionText = lang . get ( " MismatchedFactions " , languageList [ i ] ) ;
}
mismatchedFactionText + = " [ " + intToStr ( factionCRCList . size ( ) ) + " ][ " + intToStr ( serverFactionCRCList . size ( ) ) + " ] - " ;
}
if ( lang . hasString ( " MismatchedFactionsMissing " , languageList [ i ] ) = = true ) {
mismatchedFactionText + = serverFaction . first + " " + lang . get ( " MismatchedFactionsMissing " , languageList [ i ] ) + " , " ;
}
else {
mismatchedFactionText + = serverFaction . first + " (missing), " ;
}
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 ) {
pair < string , int32 > & clientFaction = factionCRCList [ clientFactionIdx ] ;
bool foundFaction = false ;
for ( unsigned int factionIdx = 0 ; factionIdx < serverFactionCRCList . size ( ) ; + + factionIdx ) {
pair < string , int32 > & serverFaction = serverFactionCRCList [ factionIdx ] ;
if ( serverFaction . first = = clientFaction . first ) {
foundFaction = true ;
break ;
}
}
if ( foundFaction = = false ) {
if ( mismatchedFactionText = = " " ) {
mismatchedFactionText = " The following factions are mismatched: " ;
if ( lang . hasString ( " MismatchedFactions " , languageList [ i ] ) = = true ) {
mismatchedFactionText = lang . get ( " MismatchedFactions " , languageList [ i ] ) ;
}
mismatchedFactionText + = " [ " + intToStr ( factionCRCList . size ( ) ) + " ][ " + intToStr ( serverFactionCRCList . size ( ) ) + " ] - " ;
}
if ( lang . hasString ( " MismatchedFactionsExtra " , languageList [ i ] ) = = true ) {
mismatchedFactionText + = clientFaction . first + " " + lang . get ( " MismatchedFactionsExtra " , languageList [ i ] ) + " , " ;
}
else {
mismatchedFactionText + = clientFaction . first + " (extra), " ;
}
2011-03-19 13:04:18 +01:00
}
}
2011-04-05 20:39:47 +02:00
if ( mismatchedFactionText ! = " " ) {
clientInterface - > sendTextMessage ( mismatchedFactionText , - 1 , localEcho , languageList [ i ] ) ;
}
}
2011-01-09 05:49:21 +01:00
}
}
//if(clientInterface->getReceivedDataSynchCheck() == true) {
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 ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] report: %s \n " , __FILE__ , __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 " ) ;
for ( int reportLine = 0 ; reportLine < 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-26 18:03:54 +02:00
2010-04-22 01:13:39 +02:00
//if(clientInterface->getNetworkGameDataSynchCheckOkFogOfWar() == false)
//{
// label = label + " FogOfWar == false";
//}
}
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
//std::string networkFrameString = lang.get("NetworkFramePeriod") + " " + intToStr(clientInterface->getGameSettings()->getNetworkFramePeriod());
2010-07-02 04:50:20 +02:00
//float pingTime = clientInterface->getThreadedPingMS(clientInterface->getServerIpAddress().c_str());
2010-08-05 01:39:12 +02:00
//char szBuf[1024]="";
2010-07-02 04:50:20 +02:00
//sprintf(szBuf,"%s, ping = %.2fms, %s",label.c_str(),pingTime,networkFrameString.c_str());
2010-08-05 01:39:12 +02:00
//sprintf(szBuf,"%s, %s",label.c_str(),networkFrameString.c_str());
2010-06-04 21:42:58 +02:00
2010-08-05 01:39:12 +02:00
//labelStatus.setText(szBuf);
labelStatus . setText ( label ) ;
2010-04-22 01:13:39 +02:00
}
2010-08-23 06:33:21 +02:00
else {
2010-04-22 01:13:39 +02:00
string label = lang . get ( " ConnectedToServer " ) ;
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 " ;
}
//if(clientInterface->getNetworkGameDataSynchCheckOkFogOfWar() == false)
//{
// label = label + " FogOfWar == false";
//}
}
else if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = true )
{
label + = " - data synch is ok " ;
}
2010-08-05 01:39:12 +02:00
//std::string networkFrameString = lang.get("NetworkFramePeriod") + " " + intToStr(clientInterface->getGameSettings()->getNetworkFramePeriod());
2010-07-02 04:50:20 +02:00
//float pingTime = clientInterface->getThreadedPingMS(clientInterface->getServerIpAddress().c_str());
2010-08-05 01:39:12 +02:00
//char szBuf[1024]="";
2010-07-02 04:50:20 +02:00
//sprintf(szBuf,"%s, ping = %.2fms, %s",label.c_str(),pingTime,networkFrameString.c_str());
2010-08-05 01:39:12 +02:00
//sprintf(szBuf,"%s, %s",label.c_str(),networkFrameString.c_str());
2010-06-04 21:42:58 +02:00
2010-08-05 01:39:12 +02:00
//labelStatus.setText(szBuf);
labelStatus . setText ( label ) ;
2010-04-22 01:13:39 +02:00
}
2010-09-02 23:40:43 +02:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
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 {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-08 10:29:51 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) = = true ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
clientInterface - > close ( ) ;
}
2010-09-02 23:40:43 +02:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-09-02 23:40:43 +02:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __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
}
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
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 ( ) ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
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 {
bool mustSwitchPlayerName = false ;
if ( clientInterface - > getGameSettingsReceived ( ) ) {
updateDataSynchDetailText = true ;
bool errorOnMissingData = ( clientInterface - > getAllowGameDataSynchCheck ( ) = = false ) ;
vector < string > maps , tilesets , techtree ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
2010-12-29 02:10:53 +01:00
2010-09-17 10:26:22 +02:00
if ( gameSettings = = NULL ) {
throw runtime_error ( " gameSettings == NULL " ) ;
}
2010-09-17 10:46:34 +02:00
2011-03-19 13:04:18 +01:00
if ( getMissingTilesetFromFTPServerInProgress = = false & &
gameSettings - > getTileset ( ) ! = " " ) {
2011-01-01 01:50:10 +01:00
// tileset
2011-03-10 00:09:32 +01:00
if ( std : : find ( tilesetFiles . begin ( ) , tilesetFiles . end ( ) , gameSettings - > getTileset ( ) ) ! = tilesetFiles . end ( ) ) {
2011-01-01 01:50:10 +01:00
lastMissingTileSet = " " ;
2011-03-19 13:04:18 +01:00
getMissingTilesetFromFTPServer = " " ;
2011-01-01 01:50:10 +01:00
tilesets . push_back ( formatString ( gameSettings - > getTileset ( ) ) ) ;
}
else {
2011-03-10 00:09:32 +01:00
// try to get the tileset via ftp
2011-01-01 01:50:10 +01:00
if ( ftpClientThread ! = NULL & & getMissingTilesetFromFTPServer ! = gameSettings - > getTileset ( ) ) {
if ( ftpMessageBox . getEnabled ( ) = = false ) {
getMissingTilesetFromFTPServer = gameSettings - > getTileset ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " %s %s ? " , lang . get ( " DownloadMissingTilesetQuestion " ) . c_str ( ) , gameSettings - > getTileset ( ) . c_str ( ) ) ;
ftpMissingDataType = ftpmsg_MissingTileset ;
showFTPMessageBox ( szBuf , lang . get ( " Question " ) , false ) ;
}
}
2010-09-17 10:46:34 +02:00
2011-03-19 13:04:18 +01:00
tilesets . push_back ( ITEM_MISSING ) ;
2010-09-17 10:46:34 +02:00
2011-01-01 01:50:10 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
2010-09-17 10:46:34 +02:00
2011-01-01 01:50:10 +01:00
if ( lastMissingTileSet ! = gameSettings - > getTileset ( ) ) {
lastMissingTileSet = gameSettings - > getTileset ( ) ;
2010-09-17 10:46:34 +02:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-01-01 01:50:10 +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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingTileset " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingTileset " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTileset ( ) . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s is missing the tileset: %s " , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTileset ( ) . c_str ( ) ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2011-01-01 01:50:10 +01:00
}
}
listBoxTileset . setItems ( tilesets ) ;
2010-09-17 10:46:34 +02:00
}
2010-12-29 02:10:53 +01:00
2011-03-19 13:04:18 +01:00
if ( getMissingTechtreeFromFTPServerInProgress = = false & &
gameSettings - > getTech ( ) ! = " " ) {
2011-03-10 00:09:32 +01:00
// techtree
if ( std : : find ( techTreeFiles . begin ( ) , techTreeFiles . end ( ) , gameSettings - > getTech ( ) ) ! = techTreeFiles . end ( ) ) {
lastMissingTechtree = " " ;
2011-03-19 13:04:18 +01:00
getMissingTechtreeFromFTPServer = " " ;
2011-03-10 00:09:32 +01:00
techtree . push_back ( formatString ( gameSettings - > getTech ( ) ) ) ;
}
else {
// try to get the tileset via ftp
if ( ftpClientThread ! = NULL & & getMissingTechtreeFromFTPServer ! = gameSettings - > getTech ( ) ) {
if ( ftpMessageBox . getEnabled ( ) = = false ) {
getMissingTechtreeFromFTPServer = gameSettings - > getTech ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " %s %s ? " , lang . get ( " DownloadMissingTechtreeQuestion " ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
ftpMissingDataType = ftpmsg_MissingTechtree ;
showFTPMessageBox ( szBuf , lang . get ( " Question " ) , false ) ;
}
}
2011-03-19 13:04:18 +01:00
techtree . push_back ( ITEM_MISSING ) ;
2011-03-10 00:09:32 +01:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
if ( lastMissingTechtree ! = gameSettings - > getTech ( ) ) {
lastMissingTechtree = gameSettings - > getTech ( ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-03-10 00:09:32 +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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingTechtree " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingTechtree " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s is missing the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2011-03-10 00:09:32 +01:00
}
}
listBoxTechTree . setItems ( techtree ) ;
// techtree
//techtree.push_back(formatString(gameSettings->getTech()));
//listBoxTechTree.setItems(techtree);
}
2010-12-29 02:10:53 +01:00
2010-09-17 10:26:22 +02:00
// factions
bool hasFactions = true ;
2011-03-19 13:04:18 +01:00
if ( currentFactionName ! = gameSettings - > getTech ( )
& & gameSettings - > getTech ( ) ! = " " ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] hasFactions = %d, currentFactionName [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , hasFactions , currentFactionName . c_str ( ) ) ;
2010-09-17 10:26:22 +02:00
currentFactionName = gameSettings - > getTech ( ) ;
hasFactions = loadFactions ( gameSettings , false ) ;
}
else {
2011-03-19 13:04:18 +01:00
// do this to process special faction types like observers
2010-09-17 10:26:22 +02:00
loadFactions ( gameSettings , false ) ;
}
2010-12-29 02:10:53 +01:00
2011-03-19 13:04:18 +01:00
if ( getMissingMapFromFTPServerInProgress = = false & &
gameSettings - > getMap ( ) ! = " " ) {
2010-12-29 09:10:22 +01:00
// map
if ( currentMap ! = gameSettings - > getMap ( ) ) { // load the setup again
currentMap = gameSettings - > getMap ( ) ;
}
bool mapLoaded = loadMapInfo ( Map : : getMapPath ( currentMap , " " , false ) , & mapInfo , true ) ;
if ( mapLoaded = = true ) {
maps . push_back ( formatString ( gameSettings - > getMap ( ) ) ) ;
2010-12-29 02:32:55 +01:00
}
2010-12-29 09:10:22 +01:00
else {
// try to get the map via ftp
if ( ftpClientThread ! = NULL & & getMissingMapFromFTPServer ! = currentMap ) {
2010-12-29 20:31:51 +01:00
if ( ftpMessageBox . getEnabled ( ) = = false ) {
getMissingMapFromFTPServer = currentMap ;
2010-12-29 21:28:25 +01:00
Lang & lang = Lang : : getInstance ( ) ;
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " %s %s ? " , lang . get ( " DownloadMissingMapQuestion " ) . c_str ( ) , currentMap . c_str ( ) ) ;
2011-01-01 01:50:10 +01:00
ftpMissingDataType = ftpmsg_MissingMap ;
2010-12-29 21:28:25 +01:00
showFTPMessageBox ( szBuf , lang . get ( " Question " ) , false ) ;
2010-12-29 20:31:51 +01:00
}
2010-12-29 09:10:22 +01:00
}
2011-03-19 13:04:18 +01:00
maps . push_back ( ITEM_MISSING ) ;
2010-12-29 09:10:22 +01:00
}
listBoxMap . setItems ( maps ) ;
labelMapInfo . setText ( mapInfo . desc ) ;
2010-09-17 10:26:22 +02:00
}
2010-12-29 02:10:53 +01:00
2010-09-17 10:26:22 +02:00
// FogOfWar
2010-12-20 22:59:46 +01:00
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ; // default is 0!
if ( gameSettings - > getFogOfWar ( ) = = false ) {
listBoxFogOfWar . setSelectedItemIndex ( 2 ) ;
2010-09-17 10:26:22 +02:00
}
2010-12-20 22:59:46 +01:00
if ( ( gameSettings - > getFlagTypes1 ( ) & ft1_show_map_resources ) = = ft1_show_map_resources ) {
2010-12-23 11:44:11 +01:00
if ( gameSettings - > getFogOfWar ( ) = = true ) {
listBoxFogOfWar . setSelectedItemIndex ( 1 ) ;
}
2010-09-17 10:26:22 +02:00
}
2010-12-29 02:10:53 +01:00
2010-09-17 10:26:22 +02:00
// Allow Observers
if ( gameSettings - > getAllowObservers ( ) ) {
listBoxAllowObservers . setSelectedItemIndex ( 1 ) ;
}
else
{
listBoxAllowObservers . setSelectedItemIndex ( 0 ) ;
}
2010-04-29 09:59:44 +02:00
2010-09-17 10:26:22 +02:00
if ( gameSettings - > getEnableObserverModeAtEndGame ( ) ) {
listBoxEnableObserverMode . setSelectedItemIndex ( 0 ) ;
}
else {
listBoxEnableObserverMode . setSelectedItemIndex ( 1 ) ;
}
if ( gameSettings - > getEnableServerControlledAI ( ) ) {
listBoxEnableServerControlledAI . setSelectedItemIndex ( 0 ) ;
}
else {
listBoxEnableServerControlledAI . setSelectedItemIndex ( 1 ) ;
}
if ( gameSettings - > getNetworkPauseGameForLaggedClients ( ) ) {
listBoxNetworkPauseGameForLaggedClients . setSelectedItemIndex ( 1 ) ;
}
else {
listBoxNetworkPauseGameForLaggedClients . setSelectedItemIndex ( 0 ) ;
}
if ( gameSettings - > getPathFinderType ( ) = = pfBasic ) {
listBoxPathFinderType . setSelectedItemIndex ( 0 ) ;
}
else {
listBoxPathFinderType . setSelectedItemIndex ( 1 ) ;
}
2010-04-29 09:59:44 +02:00
2010-09-17 10:26:22 +02:00
listBoxNetworkFramePeriod . setSelectedItem ( intToStr ( gameSettings - > getNetworkFramePeriod ( ) ) , false ) ;
2010-04-29 09:59:44 +02:00
2010-09-17 10:26:22 +02:00
// Control
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctClosed ) ;
listBoxFactions [ i ] . setEditable ( false ) ;
listBoxTeams [ i ] . setEditable ( false ) ;
2011-03-11 12:11:46 +01:00
labelPlayerStatus [ i ] . setText ( " " ) ;
2010-09-17 10:26:22 +02:00
}
2010-12-29 02:10:53 +01:00
2010-09-17 10:26:22 +02:00
if ( hasFactions = = true ) {
for ( int i = 0 ; i < gameSettings - > getFactionCount ( ) ; + + i ) {
2011-03-11 12:11:46 +01:00
int slot = gameSettings - > getStartLocationIndex ( i ) ;
if ( gameSettings ! = NULL ) {
if ( gameSettings - > getFactionControl ( i ) = = ctNetwork | |
gameSettings - > getFactionControl ( i ) = = ctHuman ) {
switch ( gameSettings - > getNetworkPlayerStatuses ( i ) ) {
case npst_BeRightBack :
labelPlayerStatus [ slot ] . setText ( lang . get ( " PlayerStatusBeRightBack " ) ) ;
2011-03-26 14:40:22 +01:00
labelPlayerStatus [ slot ] . setTextColor ( Vec3f ( 1.f , 0.8f , 0.f ) ) ;
2011-03-11 12:11:46 +01:00
break ;
case npst_Ready :
labelPlayerStatus [ slot ] . setText ( lang . get ( " PlayerStatusReady " ) ) ;
2011-03-26 14:40:22 +01:00
labelPlayerStatus [ slot ] . setTextColor ( Vec3f ( 0.f , 1.f , 0.f ) ) ;
2011-03-11 12:11:46 +01:00
break ;
case npst_PickSettings :
labelPlayerStatus [ slot ] . setText ( lang . get ( " PlayerStatusSetup " ) ) ;
2011-03-26 14:40:22 +01:00
labelPlayerStatus [ slot ] . setTextColor ( Vec3f ( 1.f , 0.f , 0.f ) ) ;
2011-03-11 12:11:46 +01:00
break ;
default :
labelPlayerStatus [ slot ] . setText ( " " ) ;
break ;
}
}
}
2010-09-17 10:26:22 +02:00
listBoxControls [ slot ] . setSelectedItemIndex ( gameSettings - > getFactionControl ( i ) , errorOnMissingData ) ;
2010-11-25 23:45:08 +01:00
listBoxRMultiplier [ slot ] . setSelectedItemIndex ( ( gameSettings - > getResourceMultiplierIndex ( i ) ) ) ;
2010-09-17 10:26:22 +02:00
listBoxTeams [ slot ] . setSelectedItemIndex ( gameSettings - > getTeam ( i ) , errorOnMissingData ) ;
//listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),errorOnMissingData);
listBoxFactions [ slot ] . setSelectedItem ( formatString ( gameSettings - > getFactionTypeName ( i ) ) , false ) ;
if ( gameSettings - > getFactionControl ( i ) = = ctNetwork ) {
labelNetStatus [ slot ] . setText ( gameSettings - > getNetworkPlayerName ( i ) ) ;
2011-03-11 12:11:46 +01:00
if ( gameSettings - > getThisFactionIndex ( ) ! = i & &
gameSettings - > getNetworkPlayerName ( i ) ! = " " & &
gameSettings - > getNetworkPlayerName ( i ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
2010-09-17 10:26:22 +02:00
labelPlayerNames [ slot ] . setText ( gameSettings - > getNetworkPlayerName ( i ) ) ;
}
}
2010-12-29 02:10:53 +01:00
2011-01-03 03:35:09 +01:00
ControlType ct = gameSettings - > getFactionControl ( i ) ;
if ( ct = = ctHuman | | ct = = ctNetwork | | ct = = ctClosed ) {
listBoxRMultiplier [ slot ] . setEnabled ( false ) ;
listBoxRMultiplier [ slot ] . setVisible ( false ) ;
} else {
listBoxRMultiplier [ slot ] . setEnabled ( true ) ;
listBoxRMultiplier [ slot ] . setVisible ( true ) ;
}
2010-09-17 10:26:22 +02:00
if ( gameSettings - > getFactionControl ( i ) = = ctNetwork & &
gameSettings - > getThisFactionIndex ( ) = = i ) {
// set my current slot to ctHuman
listBoxControls [ slot ] . setSelectedItemIndex ( ctHuman ) ;
listBoxFactions [ slot ] . setEditable ( true ) ;
listBoxTeams [ slot ] . setEditable ( true ) ;
if ( labelPlayerNames [ slot ] . getText ( ) = = " " & &
2010-08-26 07:30:17 +02:00
gameSettings - > getNetworkPlayerName ( i ) ! = " " & &
gameSettings - > getNetworkPlayerName ( i ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
2010-09-17 10:26:22 +02:00
labelPlayerNames [ slot ] . setText ( gameSettings - > getNetworkPlayerName ( i ) ) ;
}
2010-08-21 15:04:52 +02:00
}
2010-12-29 02:10:53 +01:00
2010-09-17 10:26:22 +02:00
settingsReceivedFromServer = true ;
initialSettingsReceivedFromServer = true ;
2010-08-21 15:04:52 +02:00
2010-09-17 10:26:22 +02:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
2010-08-21 15:04:52 +02:00
2010-09-17 10:26:22 +02:00
mustSwitchPlayerName = true ;
}
2010-08-21 15:04:52 +02:00
}
2010-08-31 08:38:27 +02:00
2010-09-17 10:26:22 +02:00
if ( enableFactionTexturePreview = = true ) {
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) & &
gameSettings ! = NULL ) {
2010-08-31 08:38:27 +02:00
2010-10-30 05:29:29 +02:00
if ( currentTechName_factionPreview ! = gameSettings - > getTech ( ) | |
currentFactionName_factionPreview ! = gameSettings - > getFactionTypeName ( gameSettings - > getThisFactionIndex ( ) ) ) {
currentTechName_factionPreview = gameSettings - > getTech ( ) ;
currentFactionName_factionPreview = gameSettings - > getFactionTypeName ( gameSettings - > getThisFactionIndex ( ) ) ;
string factionLogo = Game : : findFactionLogoFile ( gameSettings , NULL , " preview_screen.* " ) ;
if ( factionLogo = = " " ) {
factionLogo = Game : : findFactionLogoFile ( gameSettings , NULL ) ;
}
if ( currentFactionLogo ! = factionLogo ) {
currentFactionLogo = factionLogo ;
loadFactionTexture ( currentFactionLogo ) ;
}
2010-09-17 10:26:22 +02:00
}
2010-09-02 15:53:23 +02:00
}
2010-08-31 08:38:27 +02:00
}
2010-09-17 10:26:22 +02:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
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
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
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
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
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 ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] getHumanPlayerName() = [%s], clientInterface->getGameSettings()->getThisFactionIndex() = %d \n " , __FILE__ , __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
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
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 ( ) ) {
labelInfo . setText ( lang . get ( " WaitingHost " ) ) ;
//servers.setString(clientInterface->getServerName(), Ip(labelServerIp.getText()).getString());
}
2010-04-22 01:13:39 +02:00
2010-09-17 10:26:22 +02:00
//launch
if ( clientInterface - > getLaunchGame ( ) ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __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
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-01-10 01:05:31 +01:00
if ( ftpClientThread ! = NULL ) {
ftpClientThread - > setCallBackObject ( NULL ) ;
if ( ftpClientThread - > shutdownAndWait ( ) = = true ) {
delete ftpClientThread ;
ftpClientThread = NULL ;
}
}
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2010-09-17 10:26:22 +02:00
program - > setState ( new Game ( program , clientInterface - > getGameSettings ( ) ) ) ;
return ;
2010-04-22 01:13:39 +02:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-17 10:26:22 +02:00
}
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 ( ) ;
2010-04-22 01:13:39 +02:00
}
2010-09-17 10:26:22 +02:00
catch ( const runtime_error & ex ) {
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " Error [%s] " , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , szBuf ) ;
2010-09-17 10:26:22 +02:00
//throw runtime_error(szBuf);
showMessageBox ( szBuf , " Error " , false ) ;
}
2010-09-02 23:40:43 +02:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled & & chrono . getMillis ( ) > 0 ) chrono . start ( ) ;
2010-04-22 01:13:39 +02:00
}
}
2010-06-03 08:03:41 +02:00
bool MenuStateConnectedGame : : loadFactions ( const GameSettings * gameSettings , bool errorOnNoFactions ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2010-06-04 00:52:56 +02:00
bool foundFactions = false ;
2010-04-22 01:13:39 +02:00
vector < string > results ;
2011-03-19 13:04:18 +01:00
if ( gameSettings - > getTech ( ) ! = " " ) {
Config & config = Config : : getInstance ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
endPathWithSlash ( techPath ) ;
findAll ( techPath + gameSettings - > getTech ( ) + " /factions/*. " , results , false , false ) ;
if ( results . size ( ) > 0 ) {
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-03-19 13:04:18 +01:00
if ( results . size ( ) = = 0 ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __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 ) {
throw runtime_error ( " (2) There are no factions for the tech tree [ " + gameSettings->getTech() + " ] " ) ;
}
2011-03-29 11:45:15 +02: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 " , __FILE__ , __FUNCTION__ , __LINE__ , gameSettings - > getTech ( ) . c_str ( ) ) ;
2011-03-19 13:04:18 +01:00
}
results . push_back ( ITEM_MISSING ) ;
factionFiles = results ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxFactions [ i ] . setItems ( results ) ;
}
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingTechtree " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingTechtree " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s is missing the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
}
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 ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-29 09:59:44 +02:00
}
2011-03-19 13:04:18 +01:00
else {
lastMissingTechtree = " " ;
getMissingTechtreeFromFTPServer = " " ;
// Add special Observer Faction
//Lang &lang= Lang::getInstance();
if ( gameSettings - > getAllowObservers ( ) = = true ) {
results . push_back ( formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ;
}
results . push_back ( formatString ( GameConstants : : RANDOMFACTION_SLOTNAME ) ) ;
factionFiles = results ;
for ( int i = 0 ; i < results . size ( ) ; + + i ) {
results [ i ] = formatString ( results [ i ] ) ;
2010-06-04 00:52:56 +02:00
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " Tech [%s] has faction [%s] \n " , gameSettings - > getTech ( ) . c_str ( ) , results [ i ] . c_str ( ) ) ;
2011-03-19 13:04:18 +01:00
}
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxFactions [ i ] . setItems ( results ) ;
}
foundFactions = ( results . size ( ) > 0 ) ;
}
2010-04-29 09:59:44 +02:00
}
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __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 ===========================
bool MenuStateConnectedGame : : hasNetworkGameSettings ( )
{
bool hasNetworkSlot = false ;
try {
for ( int i = 0 ; i < mapInfo . players ; + + i )
{
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct ! = ctClosed )
{
if ( ct = = ctNetwork )
{
hasNetworkSlot = true ;
break ;
}
}
}
}
catch ( const std : : exception & ex ) {
char szBuf [ 1024 ] = " " ;
2010-09-17 10:26:22 +02:00
sprintf ( szBuf , " Error [%s] " , ex . what ( ) ) ;
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] %s \n " , __FILE__ , __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 ;
}
2010-08-21 15:04:52 +02:00
void MenuStateConnectedGame : : keyDown ( char key ) {
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL ) {
2010-10-08 18:19:09 +02:00
string text = activeInputLabel - > getText ( ) ;
if ( key = = vkBack & & text . length ( ) > 0 ) {
size_t found = text . find_last_of ( " _ " ) ;
if ( found = = string : : npos ) {
2010-10-08 03:41:53 +02:00
text . erase ( text . end ( ) - 1 ) ;
2010-06-09 00:50:37 +02:00
}
2010-10-08 18:19:09 +02:00
else {
if ( text . size ( ) > 1 ) {
text . erase ( text . end ( ) - 2 ) ;
}
}
2010-10-08 03:41:53 +02:00
2010-08-21 15:04:52 +02:00
activeInputLabel - > setText ( text ) ;
2010-08-23 06:33:21 +02:00
switchSetupRequestFlagType | = ssrft_NetworkPlayerName ;
2010-08-21 15:04:52 +02:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
else {
//send key to the chat manager
chatManager . keyDown ( key ) ;
2010-09-09 23:07:39 +02:00
if ( chatManager . getEditEnabled ( ) = = false ) {
2010-08-28 03:52:57 +02:00
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
if ( key = = configKeys . getCharKey ( " ShowFullConsole " ) ) {
showFullConsole = true ;
}
2010-09-09 23:07:39 +02:00
else if ( key = = configKeys . getCharKey ( " SaveGUILayout " ) ) {
bool saved = GraphicComponent : : saveAllCustomProperties ( containerName ) ;
Lang & lang = Lang : : getInstance ( ) ;
console . addLine ( lang . get ( " GUILayoutSaved " ) + " [ " + ( saved ? lang . get ( " Yes " ) : lang . get ( " No " ) ) + " ] " ) ;
}
2010-08-21 15:04:52 +02:00
}
2010-06-09 00:50:37 +02:00
}
2010-04-22 01:13:39 +02:00
}
2010-08-21 15:04:52 +02:00
void MenuStateConnectedGame : : keyPress ( char c ) {
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL ) {
2010-08-21 15:04:52 +02:00
int maxTextSize = 16 ;
2010-10-08 03:41:53 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
if ( & labelPlayerNames [ i ] = = activeInputLabel ) {
if ( ( c > = ' 0 ' & & c < = ' 9 ' ) | | ( c > = ' a ' & & c < = ' z ' ) | | ( c > = ' A ' & & c < = ' Z ' ) | |
( c = = ' - ' ) | | ( c = = ' ( ' ) | | ( c = = ' ) ' ) ) {
if ( activeInputLabel - > getText ( ) . size ( ) < maxTextSize ) {
2010-08-21 15:04:52 +02:00
string text = activeInputLabel - > getText ( ) ;
2010-10-08 03:41:53 +02:00
text . insert ( text . end ( ) - 1 , c ) ;
2010-08-21 15:04:52 +02:00
activeInputLabel - > setText ( text ) ;
2010-08-23 06:33:21 +02:00
switchSetupRequestFlagType | = ssrft_NetworkPlayerName ;
2010-08-21 15:04:52 +02:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
}
}
}
else {
chatManager . keyPress ( c ) ;
}
2010-04-22 01:13:39 +02:00
}
2010-08-21 15:04:52 +02:00
void MenuStateConnectedGame : : keyUp ( char key ) {
if ( activeInputLabel = = NULL ) {
2010-06-09 00:50:37 +02:00
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 ) ;
}
2010-08-28 03:52:57 +02:00
else if ( key = = configKeys . getCharKey ( " ShowFullConsole " ) ) {
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 ) {
2010-10-08 03:41:53 +02:00
if ( newLable ! = NULL ) {
2010-08-21 15:04:52 +02:00
string text = newLable - > getText ( ) ;
2010-10-08 03:41:53 +02:00
size_t found = text . find_last_of ( " _ " ) ;
if ( found = = string : : npos ) {
text + = " _ " ;
2010-08-21 15:04:52 +02:00
}
newLable - > setText ( text ) ;
2010-06-09 00:50:37 +02:00
}
2010-10-08 03:41:53 +02:00
if ( activeInputLabel ! = NULL & & activeInputLabel - > getText ( ) . empty ( ) = = false ) {
2010-08-21 15:04:52 +02:00
string text = activeInputLabel - > getText ( ) ;
2010-10-08 03:41:53 +02:00
size_t found = text . find_last_of ( " _ " ) ;
if ( found ! = string : : npos ) {
text = text . substr ( 0 , found ) ;
2010-08-21 15:04:52 +02:00
}
activeInputLabel - > setText ( text ) ;
}
2010-10-08 03:41:53 +02:00
activeInputLabel = newLable ;
2010-10-08 19:17:22 +02:00
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
2010-10-08 19:17:22 +02:00
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 ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __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 {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] filepath = [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , filepath . c_str ( ) ) ;
2011-01-26 10:09:59 +01:00
factionTexture = Renderer : : findFactionLogoTexture ( filepath ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __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 ) {
2010-09-11 08:08:50 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2010-09-17 10:26:22 +02:00
bool mapLoaded = false ;
try {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] map [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , file . c_str ( ) ) ;
2010-09-11 08:08:50 +02:00
2010-09-17 10:26:22 +02:00
if ( file ! = " " ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-11 08:08:50 +02:00
2010-09-17 10:26:22 +02:00
lastMissingMap = file ;
2010-09-11 08:08:50 +02:00
2010-09-17 10:26:22 +02:00
FILE * f = fopen ( file . c_str ( ) , " rb " ) ;
if ( f = = NULL ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-17 10:26:22 +02:00
throw runtime_error ( " [2]Can't open file " ) ;
}
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-11 08:08:50 +02:00
2010-09-17 10:26:22 +02:00
MapFileHeader header ;
size_t readBytes = fread ( & header , sizeof ( MapFileHeader ) , 1 , f ) ;
2010-09-11 08:08:50 +02:00
2010-09-17 10:26:22 +02:00
mapInfo - > size . x = header . width ;
mapInfo - > size . y = header . height ;
2011-02-08 04:50:59 +01:00
mapInfo - > players = header . maxFactions ;
2010-09-11 08:08:50 +02:00
2010-09-17 10:26:22 +02:00
mapInfo - > desc = lang . get ( " MaxPlayers " ) + " : " + intToStr ( mapInfo - > players ) + " \n " ;
mapInfo - > desc + = lang . get ( " Size " ) + " : " + intToStr ( mapInfo - > size . x ) + " x " + intToStr ( mapInfo - > size . y ) ;
fclose ( f ) ;
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 ) ;
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 ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-04-13 03:11:23 +02:00
if ( mapPreview . getMapFileLoaded ( ) ! = file ) {
mapPreview . loadFromFile ( file . c_str ( ) ) ;
cleanupMapPreviewTexture ( ) ;
}
2010-09-17 10:26:22 +02:00
}
mapLoaded = true ;
}
else {
2011-04-13 03:11:23 +02:00
cleanupMapPreviewTexture ( ) ;
2011-03-19 13:04:18 +01:00
mapInfo - > desc = ITEM_MISSING ;
2010-09-17 10:26:22 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
if ( lastMissingMap ! = gameSettings - > getMap ( ) ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-09-17 10:26:22 +02:00
lastMissingMap = gameSettings - > getMap ( ) ;
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingMap " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingMap " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getMap ( ) . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s is missing the map: %s " , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getMap ( ) . c_str ( ) ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2010-09-17 10:26:22 +02:00
}
}
2010-09-11 08:08:50 +02:00
}
2010-09-17 10:26:22 +02:00
catch ( exception & e ) {
2010-10-06 22:22:06 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
2010-09-17 10:26:22 +02:00
2010-09-17 08:37:08 +02: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 ( ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//printf("CLEANUP map preview texture\n");
if ( mapPreviewTexture ! = NULL ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
mapPreviewTexture - > end ( ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
delete mapPreviewTexture ;
mapPreviewTexture = NULL ;
}
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
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 ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-12-29 09:10:22 +01:00
2011-01-14 18:57:37 +01:00
Lang & lang = Lang : : getInstance ( ) ;
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__ ) ) ;
2011-03-16 19:39:53 +01:00
pair < int , string > lastProgress = fileFTPProgressList [ itemName ] ;
2011-01-04 09:44:00 +01:00
fileFTPProgressList [ itemName ] = 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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " FileDownloadProgress " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " FileDownloadProgress " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , fileProgress ) ;
}
else {
sprintf ( szMsg , " Player: %s download progress for [%s] is %d %% " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , fileProgress ) ;
}
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] szMsg [%s] lastProgress.first = %d, fileProgress = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , szMsg , lastProgress . first , fileProgress ) ;
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2011-03-16 19:39:53 +01: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
Checksum : : clearFileCache ( ) ;
//lastCheckedCRCMapValue = -1;
Checksum checksum ;
2011-03-29 10:45:56 +02:00
string file = Map : : getMapPath ( itemName , " " , false ) ;
2011-03-20 07:23:19 +01:00
//console.addLine("Checking map CRC [" + file + "]");
checksum . addFile ( file ) ;
lastCheckedCRCMapValue = checksum . getSum ( ) ;
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingMapSuccessDownload " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingMapSuccessDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s SUCCESSFULLY downloaded the map: %s " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2011-01-01 01:50:10 +01:00
}
else {
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingMapFailDownload " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingMapFailDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
}
else {
sprintf ( szMsg , " Player: %s FAILED to download the map: [%s] using CURL version [%s] " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingTilesetSuccessDownload " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingTilesetSuccessDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s SUCCESSFULLY downloaded the tileset: %s " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
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
Config & config = Config : : getInstance ( ) ;
2011-04-01 01:26:32 +02:00
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-03-10 00:09:32 +01:00
findDirs ( Config : : getInstance ( ) . getPathListForType ( ptTilesets ) , tilesetFiles ) ;
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingTilesetFailDownload " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingTilesetFailDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
}
else {
sprintf ( szMsg , " Player: %s FAILED to download the tileset: [%s] using CURL version [%s] " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
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 ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingTechtreeSuccessDownload " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingTechtreeSuccessDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
}
else {
sprintf ( szMsg , " Player: %s SUCCESSFULLY downloaded the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
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
Config & config = Config : : getInstance ( ) ;
2011-04-01 01:26:32 +02:00
lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , string ( " / " ) + itemName + string ( " /* " ) , " .xml " , NULL , true ) ;
2011-03-10 22:50:43 +01:00
2011-03-10 00:09:32 +01:00
safeMutexFTPProgress . ReleaseLock ( ) ;
// END
// Reload tilesets for the UI
findDirs ( Config : : getInstance ( ) . getPathListForType ( ptTechs ) , techTreeFiles ) ;
}
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 ( ) ;
for ( unsigned int i = 0 ; i < languageList . size ( ) ; + + i ) {
char szMsg [ 1024 ] = " " ;
if ( lang . hasString ( " DataMissingTechtreeFailDownload " , languageList [ i ] ) = = true ) {
sprintf ( szMsg , lang . get ( " DataMissingTechtreeFailDownload " , languageList [ i ] ) . c_str ( ) , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
}
else {
sprintf ( szMsg , " Player: %s FAILED to download the techtree: [%s] using CURL version [%s] " , getHumanPlayerName ( ) . c_str ( ) , itemName . c_str ( ) , curlVersion - > version ) ;
}
clientInterface - > sendTextMessage ( szMsg , - 1 , lang . isLanguageLocal ( languageList [ i ] ) , languageList [ i ] ) ;
}
2011-03-25 11:11:16 +01:00
console . addLine ( result . second , true ) ;
2011-03-10 00:09:32 +01:00
}
}
2010-12-29 02:10:53 +01:00
}
2010-04-22 01:13:39 +02:00
} } //end namespace