2010-03-20 00:26:00 +01:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
2010-03-24 00:32:25 +01:00
|
|
|
|
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
2010-03-20 00:26:00 +01:00
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#include "menu_state_join_game.h"
|
|
|
|
|
|
2010-04-22 01:13:39 +02:00
|
|
|
|
#include "menu_state_connected_game.h"
|
2010-03-20 00:26:00 +01:00
|
|
|
|
#include "renderer.h"
|
|
|
|
|
#include "sound_renderer.h"
|
|
|
|
|
#include "core_data.h"
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "menu_state_root.h"
|
|
|
|
|
#include "metrics.h"
|
|
|
|
|
#include "network_manager.h"
|
|
|
|
|
#include "network_message.h"
|
|
|
|
|
#include "client_interface.h"
|
|
|
|
|
#include "conversion.h"
|
|
|
|
|
#include "game.h"
|
|
|
|
|
#include "socket.h"
|
|
|
|
|
|
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
using namespace Shared::Util;
|
|
|
|
|
|
|
|
|
|
// ===============================
|
|
|
|
|
// class MenuStateJoinGame
|
|
|
|
|
// ===============================
|
|
|
|
|
|
|
|
|
|
const int MenuStateJoinGame::newServerIndex= 0;
|
2010-04-30 08:45:30 +02:00
|
|
|
|
const int MenuStateJoinGame::newPrevServerIndex= 1;
|
|
|
|
|
const int MenuStateJoinGame::foundServersIndex= 2;
|
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
const string MenuStateJoinGame::serverFileName= "servers.ini";
|
|
|
|
|
|
2010-04-22 01:13:39 +02:00
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool connect, Ip serverIp):
|
|
|
|
|
MenuState(program, mainMenu, "join-game")
|
|
|
|
|
{
|
2010-06-22 17:03:57 +02:00
|
|
|
|
abortAutoFind = false;
|
|
|
|
|
autoConnectToServer = false;
|
2010-03-20 00:26:00 +01:00
|
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
|
Config &config= Config::getInstance();
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
2010-04-22 01:13:39 +02:00
|
|
|
|
networkManager.end();
|
2010-05-13 23:47:14 +02:00
|
|
|
|
networkManager.init(nrClient);
|
2010-06-22 17:03:57 +02:00
|
|
|
|
|
2010-03-22 00:40:35 +01:00
|
|
|
|
serversSavedFile = serverFileName;
|
|
|
|
|
if(getGameReadWritePath() != "") {
|
|
|
|
|
serversSavedFile = getGameReadWritePath() + serversSavedFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
servers.load(serversSavedFile);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
|
|
|
|
//buttons
|
2010-04-02 04:33:32 +02:00
|
|
|
|
buttonReturn.init(300, 300, 125);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
buttonReturn.setText(lang.get("Return"));
|
|
|
|
|
|
2010-04-02 04:33:32 +02:00
|
|
|
|
buttonConnect.init(450, 300, 125);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
buttonConnect.setText(lang.get("Connect"));
|
|
|
|
|
|
2010-04-02 04:33:32 +02:00
|
|
|
|
buttonAutoFindServers.init(595, 300, 125);
|
|
|
|
|
buttonAutoFindServers.setText(lang.get("FindLANGames"));
|
2010-04-11 06:29:23 +02:00
|
|
|
|
buttonAutoFindServers.setEnabled(true);
|
2010-04-02 04:33:32 +02:00
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
//server type label
|
2010-04-03 19:17:15 +02:00
|
|
|
|
labelServerType.init(330, 490);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
labelServerType.setText(lang.get("ServerType") + ":");
|
|
|
|
|
|
|
|
|
|
//server type list box
|
2010-04-03 19:17:15 +02:00
|
|
|
|
listBoxServerType.init(465, 490);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
listBoxServerType.pushBackItem(lang.get("ServerTypeNew"));
|
|
|
|
|
listBoxServerType.pushBackItem(lang.get("ServerTypePrevious"));
|
2010-04-30 08:45:30 +02:00
|
|
|
|
listBoxServerType.pushBackItem(lang.get("ServerTypeFound"));
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
|
|
|
|
//server label
|
2010-04-03 19:17:15 +02:00
|
|
|
|
labelServer.init(330, 460);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
labelServer.setText(lang.get("Server") + ": ");
|
|
|
|
|
|
|
|
|
|
//server listbox
|
2010-04-03 19:17:15 +02:00
|
|
|
|
listBoxServers.init(465, 460);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
for(int i= 0; i<servers.getPropertyCount(); ++i){
|
|
|
|
|
listBoxServers.pushBackItem(servers.getKey(i));
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-30 08:45:30 +02:00
|
|
|
|
// found servers listbox
|
|
|
|
|
listBoxFoundServers.init(465, 460);
|
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
//server ip
|
2010-04-03 19:17:15 +02:00
|
|
|
|
labelServerIp.init(465, 460);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// server port
|
|
|
|
|
labelServerPortLabel.init(330,430);
|
|
|
|
|
labelServerPortLabel.setText(lang.get("ServerPort"));
|
|
|
|
|
labelServerPort.init(465,430);
|
|
|
|
|
string port=intToStr(config.getInt("ServerPort"));
|
|
|
|
|
if(port!="61357"){
|
|
|
|
|
port=port +" ("+lang.get("NonStandardPort")+")";
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
port=port +" ("+lang.get("StandardPort")+")";
|
|
|
|
|
}
|
|
|
|
|
labelServerPort.setText(port);
|
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
labelStatus.init(330, 400);
|
|
|
|
|
labelStatus.setText("");
|
|
|
|
|
|
|
|
|
|
labelInfo.init(330, 370);
|
|
|
|
|
labelInfo.setText("");
|
|
|
|
|
|
|
|
|
|
connected= false;
|
|
|
|
|
playerIndex= -1;
|
|
|
|
|
|
|
|
|
|
//server ip
|
|
|
|
|
if(connect)
|
|
|
|
|
{
|
|
|
|
|
labelServerIp.setText(serverIp.getString() + "_");
|
2010-08-21 08:47:00 +02:00
|
|
|
|
|
|
|
|
|
autoConnectToServer = true;
|
2010-03-20 00:26:00 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
labelServerIp.setText(config.getString("ServerIp") + "_");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chatManager.init(&console, -1);
|
|
|
|
|
}
|
2010-08-21 08:47:00 +02:00
|
|
|
|
|
2010-04-02 04:33:32 +02:00
|
|
|
|
MenuStateJoinGame::~MenuStateJoinGame() {
|
2010-05-13 23:47:14 +02:00
|
|
|
|
abortAutoFind = true;
|
2010-04-02 04:33:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateJoinGame::DiscoveredServers(std::vector<string> serverList) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-05-13 23:47:14 +02:00
|
|
|
|
if(abortAutoFind == true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-04-30 08:45:30 +02:00
|
|
|
|
// Testing multi-server
|
|
|
|
|
//serverList.push_back("test1");
|
|
|
|
|
//serverList.push_back("test2");
|
|
|
|
|
//
|
|
|
|
|
|
2010-06-22 17:03:57 +02:00
|
|
|
|
autoConnectToServer = false;
|
2010-04-11 06:29:23 +02:00
|
|
|
|
buttonAutoFindServers.setEnabled(true);
|
2010-04-02 04:33:32 +02:00
|
|
|
|
if(serverList.size() > 0) {
|
|
|
|
|
string bestIPMatch = "";
|
|
|
|
|
std::vector<std::string> localIPList = Socket::getLocalIPAddressList();
|
2010-04-30 08:45:30 +02:00
|
|
|
|
|
2010-04-02 04:33:32 +02:00
|
|
|
|
for(int idx = 0; idx < serverList.size(); idx++) {
|
|
|
|
|
bestIPMatch = serverList[idx];
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] bestIPMatch = [%s] localIPList[0] = [%s]\n",__FILE__,__FUNCTION__,__LINE__,bestIPMatch.c_str(),localIPList[0].c_str());
|
|
|
|
|
if(strncmp(localIPList[0].c_str(),serverList[idx].c_str(),4) == 0) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
labelServerIp.setText(bestIPMatch);
|
2010-04-30 08:45:30 +02:00
|
|
|
|
|
|
|
|
|
if(serverList.size() > 1) {
|
|
|
|
|
listBoxServerType.setSelectedItemIndex(MenuStateJoinGame::foundServersIndex);
|
|
|
|
|
listBoxFoundServers.setItems(serverList);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-06-22 17:03:57 +02:00
|
|
|
|
autoConnectToServer = true;
|
2010-04-30 08:45:30 +02:00
|
|
|
|
}
|
2010-04-02 04:33:32 +02:00
|
|
|
|
}
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
}
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
|
|
|
|
void MenuStateJoinGame::mouseClick(int x, int y, MouseButton mouseButton)
|
|
|
|
|
{
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
|
|
|
|
|
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
|
|
|
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
|
|
|
|
ClientInterface* clientInterface= networkManager.getClientInterface();
|
|
|
|
|
|
2010-04-30 08:45:30 +02:00
|
|
|
|
if(clientInterface->isConnected() == false) {
|
2010-03-20 00:26:00 +01:00
|
|
|
|
//server type
|
|
|
|
|
if(listBoxServerType.mouseClick(x, y)){
|
|
|
|
|
if(!listBoxServers.getText().empty()){
|
|
|
|
|
labelServerIp.setText(servers.getString(listBoxServers.getText())+"_");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//server list
|
2010-04-30 08:45:30 +02:00
|
|
|
|
else if(listBoxServerType.getSelectedItemIndex() == newPrevServerIndex){
|
|
|
|
|
if(listBoxServers.mouseClick(x, y)) {
|
2010-03-20 00:26:00 +01:00
|
|
|
|
labelServerIp.setText(servers.getString(listBoxServers.getText())+"_");
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-30 08:45:30 +02:00
|
|
|
|
else if(listBoxServerType.getSelectedItemIndex() == foundServersIndex){
|
|
|
|
|
if(listBoxFoundServers.mouseClick(x, y)) {
|
|
|
|
|
labelServerIp.setText(listBoxFoundServers.getText());
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-20 00:26:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//return
|
|
|
|
|
if(buttonReturn.mouseClick(x, y))
|
|
|
|
|
{
|
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundA());
|
|
|
|
|
|
2010-05-13 23:47:14 +02:00
|
|
|
|
clientInterface->stopServerDiscovery();
|
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
if(clientInterface->getSocket() != NULL)
|
|
|
|
|
{
|
|
|
|
|
if(clientInterface->isConnected() == true)
|
|
|
|
|
{
|
2010-03-24 00:32:25 +01:00
|
|
|
|
string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!";
|
2010-03-20 00:26:00 +01:00
|
|
|
|
clientInterface->sendTextMessage(sQuitText,-1);
|
|
|
|
|
}
|
|
|
|
|
clientInterface->close();
|
|
|
|
|
}
|
2010-05-13 23:47:14 +02:00
|
|
|
|
abortAutoFind = true;
|
2010-03-20 00:26:00 +01:00
|
|
|
|
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//connect
|
|
|
|
|
else if(buttonConnect.mouseClick(x, y))
|
|
|
|
|
{
|
|
|
|
|
ClientInterface* clientInterface= networkManager.getClientInterface();
|
|
|
|
|
|
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundA());
|
|
|
|
|
labelInfo.setText("");
|
|
|
|
|
|
|
|
|
|
if(clientInterface->isConnected())
|
|
|
|
|
{
|
|
|
|
|
clientInterface->reset();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
connectToServer();
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-11 06:29:23 +02:00
|
|
|
|
else if(buttonAutoFindServers.mouseClick(x, y) && buttonAutoFindServers.getEnabled() == true) {
|
2010-04-02 04:33:32 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
ClientInterface* clientInterface= networkManager.getClientInterface();
|
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundA());
|
|
|
|
|
|
|
|
|
|
// Triggers a thread which calls back into MenuStateJoinGame::DiscoveredServers
|
|
|
|
|
// with the results
|
2010-04-11 06:29:23 +02:00
|
|
|
|
if(clientInterface->isConnected() == false) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
buttonAutoFindServers.setEnabled(false);
|
|
|
|
|
clientInterface->discoverServers(this);
|
|
|
|
|
}
|
2010-04-02 04:33:32 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
}
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateJoinGame::mouseMove(int x, int y, const MouseState *ms){
|
|
|
|
|
buttonReturn.mouseMove(x, y);
|
|
|
|
|
buttonConnect.mouseMove(x, y);
|
2010-04-02 04:33:32 +02:00
|
|
|
|
buttonAutoFindServers.mouseMove(x, y);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
listBoxServerType.mouseMove(x, y);
|
|
|
|
|
|
|
|
|
|
//hide-show options depending on the selection
|
2010-04-30 08:45:30 +02:00
|
|
|
|
if(listBoxServers.getSelectedItemIndex() == newServerIndex) {
|
2010-03-20 00:26:00 +01:00
|
|
|
|
labelServerIp.mouseMove(x, y);
|
|
|
|
|
}
|
2010-04-30 08:45:30 +02:00
|
|
|
|
else if(listBoxServers.getSelectedItemIndex() == newPrevServerIndex) {
|
2010-03-20 00:26:00 +01:00
|
|
|
|
listBoxServers.mouseMove(x, y);
|
|
|
|
|
}
|
2010-04-30 08:45:30 +02:00
|
|
|
|
else {
|
|
|
|
|
listBoxFoundServers.mouseMove(x, y);
|
|
|
|
|
}
|
2010-03-20 00:26:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateJoinGame::render(){
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
|
|
|
|
|
renderer.renderButton(&buttonReturn);
|
|
|
|
|
renderer.renderLabel(&labelServer);
|
|
|
|
|
renderer.renderLabel(&labelServerType);
|
|
|
|
|
renderer.renderLabel(&labelStatus);
|
|
|
|
|
renderer.renderLabel(&labelInfo);
|
2010-04-03 19:17:15 +02:00
|
|
|
|
renderer.renderLabel(&labelServerPort);
|
|
|
|
|
renderer.renderLabel(&labelServerPortLabel);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
renderer.renderButton(&buttonConnect);
|
2010-04-02 04:33:32 +02:00
|
|
|
|
renderer.renderButton(&buttonAutoFindServers);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
renderer.renderListBox(&listBoxServerType);
|
|
|
|
|
|
2010-04-30 08:45:30 +02:00
|
|
|
|
if(listBoxServerType.getSelectedItemIndex() == newServerIndex) {
|
2010-03-20 00:26:00 +01:00
|
|
|
|
renderer.renderLabel(&labelServerIp);
|
|
|
|
|
}
|
2010-04-30 08:45:30 +02:00
|
|
|
|
else if(listBoxServerType.getSelectedItemIndex() == newPrevServerIndex) {
|
2010-03-20 00:26:00 +01:00
|
|
|
|
renderer.renderListBox(&listBoxServers);
|
|
|
|
|
}
|
2010-04-30 08:45:30 +02:00
|
|
|
|
else {
|
|
|
|
|
renderer.renderListBox(&listBoxFoundServers);
|
|
|
|
|
}
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
|
|
|
|
renderer.renderChatManager(&chatManager);
|
|
|
|
|
renderer.renderConsole(&console);
|
2010-07-08 10:29:51 +02:00
|
|
|
|
|
|
|
|
|
if(program != NULL) program->renderProgramMsgBox();
|
2010-03-20 00:26:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateJoinGame::update()
|
|
|
|
|
{
|
|
|
|
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
|
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
|
|
|
|
|
|
//update status label
|
|
|
|
|
if(clientInterface->isConnected())
|
|
|
|
|
{
|
|
|
|
|
buttonConnect.setText(lang.get("Disconnect"));
|
|
|
|
|
|
|
|
|
|
if(clientInterface->getAllowDownloadDataSynch() == false)
|
|
|
|
|
{
|
|
|
|
|
string label = lang.get("ConnectedToServer");
|
|
|
|
|
|
|
|
|
|
if(!clientInterface->getServerName().empty())
|
|
|
|
|
{
|
|
|
|
|
label = label + " " + clientInterface->getServerName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(clientInterface->getAllowGameDataSynchCheck() == true &&
|
|
|
|
|
clientInterface->getNetworkGameDataSynchCheckOk() == false)
|
|
|
|
|
{
|
|
|
|
|
label = label + " - warning synch mismatch for:";
|
|
|
|
|
if(clientInterface->getNetworkGameDataSynchCheckOkMap() == false)
|
|
|
|
|
{
|
|
|
|
|
label = label + " map";
|
|
|
|
|
}
|
|
|
|
|
if(clientInterface->getNetworkGameDataSynchCheckOkTile() == false)
|
|
|
|
|
{
|
|
|
|
|
label = label + " tile";
|
|
|
|
|
}
|
|
|
|
|
if(clientInterface->getNetworkGameDataSynchCheckOkTech() == false)
|
|
|
|
|
{
|
|
|
|
|
label = label + " techtree";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(clientInterface->getAllowGameDataSynchCheck() == true)
|
|
|
|
|
{
|
|
|
|
|
label += " - data synch is ok";
|
|
|
|
|
}
|
|
|
|
|
labelStatus.setText(label);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string label = lang.get("ConnectedToServer");
|
|
|
|
|
|
|
|
|
|
if(!clientInterface->getServerName().empty())
|
|
|
|
|
{
|
|
|
|
|
label = label + " " + clientInterface->getServerName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(clientInterface->getAllowGameDataSynchCheck() == true &&
|
|
|
|
|
clientInterface->getNetworkGameDataSynchCheckOk() == false)
|
|
|
|
|
{
|
|
|
|
|
label = label + " - waiting to synch:";
|
|
|
|
|
if(clientInterface->getNetworkGameDataSynchCheckOkMap() == false)
|
|
|
|
|
{
|
|
|
|
|
label = label + " map";
|
|
|
|
|
}
|
|
|
|
|
if(clientInterface->getNetworkGameDataSynchCheckOkTile() == false)
|
|
|
|
|
{
|
|
|
|
|
label = label + " tile";
|
|
|
|
|
}
|
|
|
|
|
if(clientInterface->getNetworkGameDataSynchCheckOkTech() == false)
|
|
|
|
|
{
|
|
|
|
|
label = label + " techtree";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(clientInterface->getAllowGameDataSynchCheck() == true)
|
|
|
|
|
{
|
|
|
|
|
label += " - data synch is ok";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
labelStatus.setText(label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buttonConnect.setText(lang.get("Connect"));
|
2010-04-11 06:29:23 +02:00
|
|
|
|
string connectedStatus = lang.get("NotConnected");
|
|
|
|
|
if(buttonAutoFindServers.getEnabled() == false) {
|
|
|
|
|
connectedStatus += " - searching for servers, please wait...";
|
|
|
|
|
}
|
|
|
|
|
labelStatus.setText(connectedStatus);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
labelInfo.setText("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//process network messages
|
|
|
|
|
if(clientInterface->isConnected())
|
|
|
|
|
{
|
2010-04-11 03:25:06 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
//update lobby
|
|
|
|
|
clientInterface->updateLobby();
|
|
|
|
|
|
2010-07-08 10:29:51 +02:00
|
|
|
|
clientInterface= NetworkManager::getInstance().getClientInterface();
|
|
|
|
|
if(clientInterface != NULL && clientInterface->isConnected()) {
|
|
|
|
|
//call the chat manager
|
|
|
|
|
chatManager.updateNetwork();
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
2010-07-08 10:29:51 +02:00
|
|
|
|
//console
|
|
|
|
|
console.update();
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
2010-07-08 10:29:51 +02:00
|
|
|
|
//intro
|
|
|
|
|
if(clientInterface->getIntroDone())
|
|
|
|
|
{
|
|
|
|
|
labelInfo.setText(lang.get("WaitingHost"));
|
|
|
|
|
servers.setString(clientInterface->getServerName(), Ip(labelServerIp.getText()).getString());
|
|
|
|
|
}
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
2010-07-08 10:29:51 +02:00
|
|
|
|
//launch
|
|
|
|
|
if(clientInterface->getLaunchGame())
|
|
|
|
|
{
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - A\n",__FILE__,__FUNCTION__);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
2010-07-08 10:29:51 +02:00
|
|
|
|
servers.save(serversSavedFile);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
2010-07-08 10:29:51 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - B\n",__FILE__,__FUNCTION__);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
2010-07-08 10:29:51 +02:00
|
|
|
|
abortAutoFind = true;
|
|
|
|
|
clientInterface->stopServerDiscovery();
|
|
|
|
|
program->setState(new Game(program, clientInterface->getGameSettings()));
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
2010-07-08 10:29:51 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - C\n",__FILE__,__FUNCTION__);
|
|
|
|
|
}
|
2010-03-20 00:26:00 +01:00
|
|
|
|
}
|
2010-04-11 03:25:06 +02:00
|
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
}
|
2010-06-22 17:03:57 +02:00
|
|
|
|
else if(autoConnectToServer == true) {
|
|
|
|
|
autoConnectToServer = false;
|
|
|
|
|
connectToServer();
|
|
|
|
|
}
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
2010-07-08 10:29:51 +02:00
|
|
|
|
if(clientInterface != NULL && clientInterface->getLaunchGame()) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] clientInterface->getLaunchGame() - D\n",__FILE__,__FUNCTION__);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateJoinGame::keyDown(char key){
|
|
|
|
|
|
2010-04-01 08:31:10 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c][%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key);
|
|
|
|
|
|
|
|
|
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
2010-03-20 00:26:00 +01:00
|
|
|
|
if(!clientInterface->isConnected())
|
|
|
|
|
{
|
2010-04-01 08:31:10 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
if(key==vkBack) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-03-20 00:26:00 +01:00
|
|
|
|
string text= labelServerIp.getText();
|
|
|
|
|
|
|
|
|
|
if(text.size()>1){
|
|
|
|
|
text.erase(text.end()-2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
labelServerIp.setText(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-04-01 08:31:10 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
//send key to the chat manager
|
|
|
|
|
chatManager.keyDown(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateJoinGame::keyPress(char c){
|
|
|
|
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
|
|
|
|
|
|
|
|
|
if(!clientInterface->isConnected())
|
|
|
|
|
{
|
|
|
|
|
int maxTextSize= 16;
|
|
|
|
|
|
|
|
|
|
if(c>='0' && c<='9'){
|
|
|
|
|
|
|
|
|
|
if(labelServerIp.getText().size()<maxTextSize){
|
|
|
|
|
string text= labelServerIp.getText();
|
|
|
|
|
|
|
|
|
|
text.insert(text.end()-1, c);
|
|
|
|
|
|
|
|
|
|
labelServerIp.setText(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (c=='.'){
|
|
|
|
|
if(labelServerIp.getText().size()<maxTextSize){
|
|
|
|
|
string text= labelServerIp.getText();
|
|
|
|
|
|
|
|
|
|
text.insert(text.end()-1, '.');
|
|
|
|
|
|
|
|
|
|
labelServerIp.setText(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
chatManager.keyPress(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateJoinGame::connectToServer()
|
|
|
|
|
{
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
|
|
|
|
|
|
|
|
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
|
|
|
|
Config& config= Config::getInstance();
|
|
|
|
|
Ip serverIp(labelServerIp.getText());
|
|
|
|
|
|
2010-05-17 22:41:18 +02:00
|
|
|
|
clientInterface->connect(serverIp, Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()));
|
2010-03-20 00:26:00 +01:00
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] server - [%s]\n",__FILE__,__FUNCTION__,serverIp.getString().c_str());
|
|
|
|
|
|
|
|
|
|
labelServerIp.setText(serverIp.getString()+'_');
|
|
|
|
|
labelInfo.setText("");
|
|
|
|
|
|
|
|
|
|
//save server ip
|
|
|
|
|
config.setString("ServerIp", serverIp.getString());
|
|
|
|
|
config.save();
|
2010-04-22 01:13:39 +02:00
|
|
|
|
|
2010-05-13 23:47:14 +02:00
|
|
|
|
abortAutoFind = true;
|
|
|
|
|
clientInterface->stopServerDiscovery();
|
2010-04-22 01:13:39 +02:00
|
|
|
|
mainMenu->setState(new MenuStateConnectedGame(program, mainMenu));
|
|
|
|
|
|
2010-03-20 00:26:00 +01:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|