mirror of
https://github.com/glest/glest-source.git
synced 2025-08-18 06:01:17 +02:00
- bugfixes for playername change in lobby screen
This commit is contained in:
@@ -48,6 +48,7 @@ struct FormatString {
|
|||||||
MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots):
|
MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots):
|
||||||
MenuState(program, mainMenu, "connected-game") //← set on connected-game
|
MenuState(program, mainMenu, "connected-game") //← set on connected-game
|
||||||
{
|
{
|
||||||
|
switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
|
||||||
updateDataSynchDetailText = false;
|
updateDataSynchDetailText = false;
|
||||||
activeInputLabel = NULL;
|
activeInputLabel = NULL;
|
||||||
lastNetworkSendPing = 0;
|
lastNetworkSendPing = 0;
|
||||||
@@ -65,6 +66,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
|
defaultPlayerName = config.getString("NetPlayerName",Socket::getHostName().c_str());
|
||||||
|
|
||||||
labelMapInfo.setText("?");
|
labelMapInfo.setText("?");
|
||||||
|
|
||||||
@@ -298,23 +300,25 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
if (myCurrentIndex!=-1)
|
if (myCurrentIndex!=-1)
|
||||||
for(int i=0; i<GameConstants::maxPlayers; ++i)
|
for(int i=0; i<GameConstants::maxPlayers; ++i)
|
||||||
{
|
{
|
||||||
if(listBoxFactions[i].getEditable()){
|
if(listBoxFactions[i].getEditable()) {
|
||||||
if(listBoxFactions[i].mouseClick(x, y)){
|
if(listBoxFactions[i].mouseClick(x, y)) {
|
||||||
soundRenderer.playFx(coreData.getClickSoundA());
|
soundRenderer.playFx(coreData.getClickSoundA());
|
||||||
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||||
if(clientInterface->isConnected()){
|
if(clientInterface->isConnected()) {
|
||||||
clientInterface->setGameSettingsReceived(false);
|
clientInterface->setGameSettingsReceived(false);
|
||||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex(),getHumanPlayerName());
|
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex(),getHumanPlayerName(),switchSetupRequestFlagType);
|
||||||
|
switchSetupRequestFlagType=ssrft_None;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(listBoxTeams[i].getEditable()){
|
if(listBoxTeams[i].getEditable()) {
|
||||||
if(listBoxTeams[i].mouseClick(x, y)){
|
if(listBoxTeams[i].mouseClick(x, y)) {
|
||||||
soundRenderer.playFx(coreData.getClickSoundA());
|
soundRenderer.playFx(coreData.getClickSoundA());
|
||||||
if(clientInterface->isConnected()){
|
if(clientInterface->isConnected()) {
|
||||||
clientInterface->setGameSettingsReceived(false);
|
clientInterface->setGameSettingsReceived(false);
|
||||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex(),getHumanPlayerName());
|
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex(),getHumanPlayerName(),switchSetupRequestFlagType);
|
||||||
|
switchSetupRequestFlagType=ssrft_None;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -327,7 +331,8 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
clientInterface->setGameSettingsReceived(false);
|
clientInterface->setGameSettingsReceived(false);
|
||||||
settingsReceivedFromServer=false;
|
settingsReceivedFromServer=false;
|
||||||
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);
|
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);
|
||||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[myCurrentIndex].getSelectedItem(),myCurrentIndex,i,listBoxTeams[myCurrentIndex].getSelectedItemIndex(),getHumanPlayerName());
|
clientInterface->sendSwitchSetupRequest(listBoxFactions[myCurrentIndex].getSelectedItem(),myCurrentIndex,i,listBoxTeams[myCurrentIndex].getSelectedItemIndex(),getHumanPlayerName(),switchSetupRequestFlagType);
|
||||||
|
switchSetupRequestFlagType=ssrft_None;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -474,8 +479,7 @@ void MenuStateConnectedGame::render(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateConnectedGame::update()
|
void MenuStateConnectedGame::update() {
|
||||||
{
|
|
||||||
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
@@ -576,8 +580,7 @@ void MenuStateConnectedGame::update()
|
|||||||
// label = label + " FogOfWar == false";
|
// label = label + " FogOfWar == false";
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
else if(clientInterface->getAllowGameDataSynchCheck() == true)
|
else if(clientInterface->getAllowGameDataSynchCheck() == true) {
|
||||||
{
|
|
||||||
label += " - data synch is ok";
|
label += " - data synch is ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,12 +594,10 @@ void MenuStateConnectedGame::update()
|
|||||||
//labelStatus.setText(szBuf);
|
//labelStatus.setText(szBuf);
|
||||||
labelStatus.setText(label);
|
labelStatus.setText(label);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
string label = lang.get("ConnectedToServer");
|
string label = lang.get("ConnectedToServer");
|
||||||
|
|
||||||
if(!clientInterface->getServerName().empty())
|
if(!clientInterface->getServerName().empty()) {
|
||||||
{
|
|
||||||
label = label + " " + clientInterface->getServerName();
|
label = label + " " + clientInterface->getServerName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,7 +652,7 @@ void MenuStateConnectedGame::update()
|
|||||||
//process network messages
|
//process network messages
|
||||||
if(clientInterface->isConnected()) {
|
if(clientInterface->isConnected()) {
|
||||||
bool mustSwitchPlayerName = false;
|
bool mustSwitchPlayerName = false;
|
||||||
if(clientInterface->getGameSettingsReceived()){
|
if(clientInterface->getGameSettingsReceived()) {
|
||||||
updateDataSynchDetailText = true;
|
updateDataSynchDetailText = true;
|
||||||
bool errorOnMissingData = (clientInterface->getAllowGameDataSynchCheck() == false);
|
bool errorOnMissingData = (clientInterface->getAllowGameDataSynchCheck() == false);
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -776,29 +777,23 @@ void MenuStateConnectedGame::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mustSwitchPlayerName == true ||
|
|
||||||
(needToSetChangedGameSettings == true &&
|
|
||||||
difftime(time(NULL),lastSetChangedGameSettings) >= 2)) {
|
|
||||||
needToSetChangedGameSettings = false;
|
|
||||||
lastSetChangedGameSettings = time(NULL);
|
|
||||||
|
|
||||||
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
|
||||||
if(clientInterface->isConnected()){
|
|
||||||
for(int i=0; i<GameConstants::maxPlayers; ++i) {
|
|
||||||
if(clientInterface->getGameSettings() != NULL &&
|
|
||||||
i == clientInterface->getGameSettings()->getThisFactionIndex()) {
|
|
||||||
clientInterface->setGameSettingsReceived(false);
|
|
||||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex(),getHumanPlayerName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//update lobby
|
//update lobby
|
||||||
clientInterface->updateLobby();
|
clientInterface->updateLobby();
|
||||||
|
|
||||||
clientInterface= NetworkManager::getInstance().getClientInterface();
|
clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||||
if(clientInterface != NULL && clientInterface->isConnected()) {
|
if(clientInterface != NULL && clientInterface->isConnected()) {
|
||||||
|
//if(mustSwitchPlayerName == true ||
|
||||||
|
// (needToSetChangedGameSettings == true &&
|
||||||
|
// difftime(time(NULL),lastSetChangedGameSettings) >= 2)) {
|
||||||
|
if(clientInterface->getIntroDone() == true &&
|
||||||
|
(switchSetupRequestFlagType & ssrft_NetworkPlayerName) == ssrft_NetworkPlayerName) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
//needToSetChangedGameSettings = false;
|
||||||
|
//lastSetChangedGameSettings = time(NULL);
|
||||||
|
clientInterface->sendSwitchSetupRequest("",clientInterface->getPlayerIndex(),-1,-1,getHumanPlayerName(),switchSetupRequestFlagType);
|
||||||
|
switchSetupRequestFlagType=ssrft_None;
|
||||||
|
}
|
||||||
|
|
||||||
//call the chat manager
|
//call the chat manager
|
||||||
chatManager.updateNetwork();
|
chatManager.updateNetwork();
|
||||||
|
|
||||||
@@ -926,9 +921,7 @@ bool MenuStateConnectedGame::hasNetworkGameSettings()
|
|||||||
return hasNetworkSlot;
|
return hasNetworkSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuStateConnectedGame::reloadFactions() {
|
||||||
|
|
||||||
void MenuStateConnectedGame::reloadFactions(){
|
|
||||||
|
|
||||||
vector<string> results;
|
vector<string> results;
|
||||||
|
|
||||||
@@ -980,6 +973,7 @@ void MenuStateConnectedGame::keyDown(char key) {
|
|||||||
}
|
}
|
||||||
activeInputLabel->setText(text);
|
activeInputLabel->setText(text);
|
||||||
|
|
||||||
|
switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
|
||||||
needToSetChangedGameSettings = true;
|
needToSetChangedGameSettings = true;
|
||||||
lastSetChangedGameSettings = time(NULL);
|
lastSetChangedGameSettings = time(NULL);
|
||||||
}
|
}
|
||||||
@@ -1002,11 +996,12 @@ void MenuStateConnectedGame::keyPress(char c) {
|
|||||||
if(&labelPlayerNames[i] == activeInputLabel){
|
if(&labelPlayerNames[i] == activeInputLabel){
|
||||||
if((c>='0' && c<='9')||(c>='a' && c<='z')||(c>='A' && c<='Z')||
|
if((c>='0' && c<='9')||(c>='a' && c<='z')||(c>='A' && c<='Z')||
|
||||||
(c=='-')||(c=='(')||(c==')')){
|
(c=='-')||(c=='(')||(c==')')){
|
||||||
if(activeInputLabel->getText().size()<maxTextSize){
|
if(activeInputLabel->getText().size()<maxTextSize) {
|
||||||
string text= activeInputLabel->getText();
|
string text= activeInputLabel->getText();
|
||||||
text.insert(text.end()-1, c);
|
text.insert(text.end()-1, c);
|
||||||
activeInputLabel->setText(text);
|
activeInputLabel->setText(text);
|
||||||
|
|
||||||
|
switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
|
||||||
needToSetChangedGameSettings = true;
|
needToSetChangedGameSettings = true;
|
||||||
lastSetChangedGameSettings = time(NULL);
|
lastSetChangedGameSettings = time(NULL);
|
||||||
}
|
}
|
||||||
@@ -1032,24 +1027,21 @@ void MenuStateConnectedGame::keyUp(char key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable)
|
void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable) {
|
||||||
{
|
if(newLable!=NULL) {
|
||||||
if(newLable!=NULL){
|
|
||||||
string text= newLable->getText();
|
string text= newLable->getText();
|
||||||
size_t found;
|
size_t found;
|
||||||
found=text.find_last_of("_");
|
found=text.find_last_of("_");
|
||||||
if (found==string::npos)
|
if (found==string::npos) {
|
||||||
{
|
|
||||||
text=text+"_";
|
text=text+"_";
|
||||||
}
|
}
|
||||||
newLable->setText(text);
|
newLable->setText(text);
|
||||||
}
|
}
|
||||||
if(activeInputLabel!=NULL && !activeInputLabel->getText().empty()){
|
if(activeInputLabel!=NULL && !activeInputLabel->getText().empty()) {
|
||||||
string text= activeInputLabel->getText();
|
string text= activeInputLabel->getText();
|
||||||
size_t found;
|
size_t found;
|
||||||
found=text.find_last_of("_");
|
found=text.find_last_of("_");
|
||||||
if (found!=string::npos)
|
if (found!=string::npos) {
|
||||||
{
|
|
||||||
text=text.substr(0,found);
|
text=text.substr(0,found);
|
||||||
}
|
}
|
||||||
activeInputLabel->setText(text);
|
activeInputLabel->setText(text);
|
||||||
@@ -1058,15 +1050,24 @@ void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
string MenuStateConnectedGame::getHumanPlayerName() {
|
string MenuStateConnectedGame::getHumanPlayerName() {
|
||||||
string result = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
string result = defaultPlayerName;
|
||||||
|
|
||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
ClientInterface* clientInterface= networkManager.getClientInterface();
|
ClientInterface* clientInterface= networkManager.getClientInterface();
|
||||||
for(int j=0; j<GameConstants::maxPlayers; ++j) {
|
for(int j=0; j<GameConstants::maxPlayers; ++j) {
|
||||||
if(clientInterface != NULL &&
|
if( clientInterface != NULL &&
|
||||||
|
clientInterface->getGameSettings() != NULL &&
|
||||||
j == clientInterface->getGameSettings()->getThisFactionIndex() &&
|
j == clientInterface->getGameSettings()->getThisFactionIndex() &&
|
||||||
labelPlayerNames[j].getText() != "") {
|
labelPlayerNames[j].getText() != "") {
|
||||||
result = labelPlayerNames[j].getText();
|
result = labelPlayerNames[j].getText();
|
||||||
|
|
||||||
|
if(activeInputLabel != NULL) {
|
||||||
|
size_t found = result.find_last_of("_");
|
||||||
|
if (found != string::npos) {
|
||||||
|
result = result.substr(0,found);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -97,6 +97,9 @@ private:
|
|||||||
string lastTileDataSynchError;
|
string lastTileDataSynchError;
|
||||||
string lastTechtreeDataSynchError;
|
string lastTechtreeDataSynchError;
|
||||||
|
|
||||||
|
int8 switchSetupRequestFlagType;
|
||||||
|
string defaultPlayerName;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MenuStateConnectedGame(Program *program, MainMenu *mainMenu, JoinMenu joinMenuInfo=jmSimple, bool openNetworkSlots= false);
|
MenuStateConnectedGame(Program *program, MainMenu *mainMenu, JoinMenu joinMenuInfo=jmSimple, bool openNetworkSlots= false);
|
||||||
|
|
||||||
|
@@ -58,6 +58,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
|
defaultPlayerName = config.getString("NetPlayerName",Socket::getHostName().c_str());
|
||||||
|
|
||||||
showFullConsole=false;
|
showFullConsole=false;
|
||||||
|
|
||||||
@@ -645,39 +646,54 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
for(int i=0; i<mapInfo.players; ++i) {
|
for(int i=0; i<mapInfo.players; ++i) {
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
//ensure thet only 1 human player is present
|
//ensure thet only 1 human player is present
|
||||||
if(listBoxControls[i].mouseClick(x, y))
|
if(listBoxControls[i].mouseClick(x, y)) {
|
||||||
{
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//look for human players
|
//look for human players
|
||||||
int humanIndex1= -1;
|
int humanIndex1= -1;
|
||||||
int humanIndex2= -1;
|
int humanIndex2= -1;
|
||||||
for(int j=0; j<GameConstants::maxPlayers; ++j){
|
for(int j=0; j<GameConstants::maxPlayers; ++j) {
|
||||||
ControlType ct= static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
|
ControlType ct= static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
|
||||||
if(ct==ctHuman){
|
if(ct == ctHuman) {
|
||||||
if(humanIndex1==-1){
|
if(humanIndex1 == -1) {
|
||||||
humanIndex1= j;
|
humanIndex1= j;
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
humanIndex2= j;
|
humanIndex2= j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//no human
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] humanIndex1 = %d, humanIndex2 = %d\n",__FILE__,__FUNCTION__,__LINE__,humanIndex1,humanIndex2);
|
||||||
if(humanIndex1==-1 && humanIndex2==-1){
|
|
||||||
listBoxControls[i].setSelectedItemIndex(ctHuman);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//no human
|
||||||
|
if(humanIndex1 == -1 && humanIndex2 == -1) {
|
||||||
|
listBoxControls[i].setSelectedItemIndex(ctHuman);
|
||||||
|
//labelPlayerNames[i].setText("");
|
||||||
|
//labelPlayerNames[i].setText(getHumanPlayerName());
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[i].getText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,labelPlayerNames[i].getText().c_str());
|
||||||
|
}
|
||||||
//2 humans
|
//2 humans
|
||||||
if(humanIndex1!=-1 && humanIndex2!=-1){
|
else if(humanIndex1 != -1 && humanIndex2 != -1) {
|
||||||
listBoxControls[humanIndex1==i? humanIndex2: humanIndex1].setSelectedItemIndex(ctClosed);
|
int closeSlotIndex = (humanIndex1 == i ? humanIndex2: humanIndex1);
|
||||||
|
int humanSlotIndex = (closeSlotIndex == humanIndex1 ? humanIndex2 : humanIndex1);
|
||||||
|
|
||||||
|
string origPlayName = labelPlayerNames[closeSlotIndex].getText();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] closeSlotIndex = %d, origPlayName [%s]\n",__FILE__,__FUNCTION__,__LINE__,closeSlotIndex,origPlayName.c_str());
|
||||||
|
|
||||||
|
listBoxControls[closeSlotIndex].setSelectedItemIndex(ctClosed);
|
||||||
|
//labelPlayerNames[closeSlotIndex].setText("");
|
||||||
|
|
||||||
|
labelPlayerNames[humanSlotIndex].setText((origPlayName != "" ? origPlayName : getHumanPlayerName()));
|
||||||
}
|
}
|
||||||
updateNetworkSlots();
|
updateNetworkSlots();
|
||||||
|
|
||||||
needToRepublishToMasterserver = true;
|
needToRepublishToMasterserver = true;
|
||||||
if(hasNetworkGameSettings() == true)
|
if(hasNetworkGameSettings() == true) {
|
||||||
{
|
|
||||||
needToSetChangedGameSettings = true;
|
needToSetChangedGameSettings = true;
|
||||||
lastSetChangedGameSettings = time(NULL);;
|
lastSetChangedGameSettings = time(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(listBoxFactions[i].mouseClick(x, y)){
|
else if(listBoxFactions[i].mouseClick(x, y)){
|
||||||
@@ -686,7 +702,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
if(hasNetworkGameSettings() == true)
|
if(hasNetworkGameSettings() == true)
|
||||||
{
|
{
|
||||||
needToSetChangedGameSettings = true;
|
needToSetChangedGameSettings = true;
|
||||||
lastSetChangedGameSettings = time(NULL);;
|
lastSetChangedGameSettings = time(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(listBoxTeams[i].mouseClick(x, y))
|
else if(listBoxTeams[i].mouseClick(x, y))
|
||||||
@@ -881,49 +897,66 @@ void MenuStateCustomGame::update() {
|
|||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
// handle setting changes from clients
|
// handle setting changes from clients
|
||||||
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
|
SwitchSetupRequest ** switchSetupRequests = serverInterface->getSwitchSetupRequests();
|
||||||
for(int i= 0; i<mapInfo.players; ++i) {
|
for(int i= 0; i< mapInfo.players; ++i) {
|
||||||
if(switchSetupRequests[i] != NULL) {
|
if(switchSetupRequests[i] != NULL) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switchSetupRequests[i]->getSwitchFlags() = %d\n",__FILE__,__FUNCTION__,__LINE__,switchSetupRequests[i]->getSwitchFlags());
|
||||||
|
|
||||||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
|
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
//printf("switchSetupRequests[i]->getSelectedFactionName()=%s\n",switchSetupRequests[i]->getSelectedFactionName().c_str());
|
//printf("switchSetupRequests[i]->getSelectedFactionName()=%s\n",switchSetupRequests[i]->getSelectedFactionName().c_str());
|
||||||
//printf("switchSetupRequests[i]->getToTeam()=%d\n",switchSetupRequests[i]->getToTeam());
|
//printf("switchSetupRequests[i]->getToTeam()=%d\n",switchSetupRequests[i]->getToTeam());
|
||||||
|
|
||||||
if(switchSetupRequests[i]->getToFactionIndex()!=-1) {
|
if(switchSetupRequests[i]->getToFactionIndex() != -1) {
|
||||||
int k=switchSetupRequests[i]->getToFactionIndex();
|
int newFactionIdx = switchSetupRequests[i]->getToFactionIndex();
|
||||||
|
/*
|
||||||
|
if(switchSetupRequests[i]->getNetworkPlayerName() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) {
|
||||||
labelPlayerNames[k].setText(switchSetupRequests[i]->getNetworkPlayerName());
|
labelPlayerNames[k].setText(switchSetupRequests[i]->getNetworkPlayerName());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
labelPlayerNames[k].setText("");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
//printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex());
|
//printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex());
|
||||||
if(serverInterface->switchSlot(switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex())){
|
int switchFactionIdx = switchSetupRequests[i]->getCurrentFactionIndex();
|
||||||
|
if(serverInterface->switchSlot(switchFactionIdx,newFactionIdx)) {
|
||||||
try {
|
try {
|
||||||
if(switchSetupRequests[i]->getSelectedFactionName()!=""){
|
if(switchSetupRequests[i]->getSelectedFactionName() != ""){
|
||||||
listBoxFactions[k].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
|
listBoxFactions[newFactionIdx].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
|
||||||
}
|
}
|
||||||
if(switchSetupRequests[i]->getToTeam()!=-1) {
|
if(switchSetupRequests[i]->getToTeam() != -1) {
|
||||||
listBoxTeams[k].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
|
listBoxTeams[newFactionIdx].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
|
||||||
|
}
|
||||||
|
if(switchSetupRequests[i]->getNetworkPlayerName() != "") {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, labelPlayerNames[newFactionIdx].getText() [%s] switchSetupRequests[i]->getNetworkPlayerName() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,labelPlayerNames[newFactionIdx].getText().c_str(),switchSetupRequests[i]->getNetworkPlayerName().c_str());
|
||||||
|
labelPlayerNames[newFactionIdx].setText(switchSetupRequests[i]->getNetworkPlayerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
labelPlayerNames[k].setText(switchSetupRequests[i]->getNetworkPlayerName());
|
|
||||||
}
|
}
|
||||||
catch(const runtime_error &e) {
|
catch(const runtime_error &e) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
|
if(switchSetupRequests[i]->getSelectedFactionName() != "") {
|
||||||
labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName());
|
|
||||||
|
|
||||||
if(switchSetupRequests[i]->getSelectedFactionName()!=""){
|
|
||||||
listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
|
listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
|
||||||
}
|
}
|
||||||
if(switchSetupRequests[i]->getToTeam()!=-1) {
|
if(switchSetupRequests[i]->getToTeam() != -1) {
|
||||||
listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
|
listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((switchSetupRequests[i]->getSwitchFlags() & ssrft_NetworkPlayerName) == ssrft_NetworkPlayerName) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, switchSetupRequests[i]->getSwitchFlags() = %d, switchSetupRequests[i]->getNetworkPlayerName() [%s], labelPlayerNames[i].getText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,switchSetupRequests[i]->getSwitchFlags(),switchSetupRequests[i]->getNetworkPlayerName().c_str(),labelPlayerNames[i].getText().c_str());
|
||||||
|
if(switchSetupRequests[i]->getNetworkPlayerName() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) {
|
||||||
|
labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
labelPlayerNames[i].setText("");
|
||||||
|
}
|
||||||
|
//switchSetupRequests[i]->clearSwitchFlag(ssrft_NetworkPlayerName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(const runtime_error &e) {
|
catch(const runtime_error &e) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||||
@@ -938,12 +971,10 @@ void MenuStateCustomGame::update() {
|
|||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
|
||||||
|
|
||||||
for(int i= 0; i<mapInfo.players; ++i)
|
for(int i= 0; i<mapInfo.players; ++i) {
|
||||||
{
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
|
||||||
{
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
|
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
|
||||||
@@ -1371,8 +1402,11 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
|||||||
|
|
||||||
gameSettings->setFactionControl(slotIndex, ct);
|
gameSettings->setFactionControl(slotIndex, ct);
|
||||||
if(ct == ctHuman) {
|
if(ct == ctHuman) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, slotIndex = %d, getHumanPlayerName(i) [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,slotIndex,getHumanPlayerName(i).c_str());
|
||||||
|
|
||||||
gameSettings->setThisFactionIndex(slotIndex);
|
gameSettings->setThisFactionIndex(slotIndex);
|
||||||
gameSettings->setNetworkPlayerName(slotIndex, getHumanPlayerName(slotIndex));
|
gameSettings->setNetworkPlayerName(slotIndex, getHumanPlayerName(i));
|
||||||
|
labelPlayerNames[i].setText(getHumanPlayerName(i));
|
||||||
}
|
}
|
||||||
gameSettings->setTeam(slotIndex, listBoxTeams[i].getSelectedItemIndex());
|
gameSettings->setTeam(slotIndex, listBoxTeams[i].getSelectedItemIndex());
|
||||||
gameSettings->setStartLocationIndex(slotIndex, i);
|
gameSettings->setStartLocationIndex(slotIndex, i);
|
||||||
@@ -1381,22 +1415,32 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
|||||||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
|
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
|
||||||
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
|
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, connectionSlot->getName() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,connectionSlot->getName().c_str());
|
||||||
|
|
||||||
gameSettings->setNetworkPlayerName(slotIndex, connectionSlot->getName());
|
gameSettings->setNetworkPlayerName(slotIndex, connectionSlot->getName());
|
||||||
labelPlayerNames[slotIndex].setText(connectionSlot->getName());
|
labelPlayerNames[i].setText(connectionSlot->getName());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, playername unconnected\n",__FILE__,__FUNCTION__,__LINE__,i);
|
||||||
|
|
||||||
gameSettings->setNetworkPlayerName(slotIndex, GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME);
|
gameSettings->setNetworkPlayerName(slotIndex, GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME);
|
||||||
labelPlayerNames[slotIndex].setText("");
|
labelPlayerNames[i].setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (listBoxControls[i].getSelectedItemIndex() != ctHuman) {
|
else if (listBoxControls[i].getSelectedItemIndex() != ctHuman) {
|
||||||
AIPlayerCount++;
|
AIPlayerCount++;
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, playername is AI (blank)\n",__FILE__,__FUNCTION__,__LINE__,i);
|
||||||
|
|
||||||
gameSettings->setNetworkPlayerName(slotIndex, string("AI") + intToStr(AIPlayerCount));
|
gameSettings->setNetworkPlayerName(slotIndex, string("AI") + intToStr(AIPlayerCount));
|
||||||
labelPlayerNames[slotIndex].setText(string("AI") + intToStr(AIPlayerCount));
|
labelPlayerNames[i].setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
factionCount++;
|
factionCount++;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
//gameSettings->setNetworkPlayerName("");
|
||||||
|
labelPlayerNames[i].setText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Next save closed slots
|
// Next save closed slots
|
||||||
int closedCount = 0;
|
int closedCount = 0;
|
||||||
@@ -1521,7 +1565,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
|||||||
gameSettings.setTeam(i,properties.getInt(string("FactionTeamForIndex") + intToStr(i),"0") );
|
gameSettings.setTeam(i,properties.getInt(string("FactionTeamForIndex") + intToStr(i),"0") );
|
||||||
gameSettings.setStartLocationIndex(i,properties.getInt(string("FactionStartLocationForIndex") + intToStr(i),intToStr(i).c_str()) );
|
gameSettings.setStartLocationIndex(i,properties.getInt(string("FactionStartLocationForIndex") + intToStr(i),intToStr(i).c_str()) );
|
||||||
gameSettings.setFactionTypeName(i,properties.getString(string("FactionTypeNameForIndex") + intToStr(i),"?") );
|
gameSettings.setFactionTypeName(i,properties.getString(string("FactionTypeNameForIndex") + intToStr(i),"?") );
|
||||||
gameSettings.setNetworkPlayerName(i,properties.getString(string("FactionPlayerNameForIndex") + intToStr(i),"?") );
|
gameSettings.setNetworkPlayerName(i,properties.getString(string("FactionPlayerNameForIndex") + intToStr(i),"") );
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -1583,6 +1627,10 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,factionName.c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,factionName.c_str());
|
||||||
|
|
||||||
listBoxFactions[i].setSelectedItem(factionName);
|
listBoxFactions[i].setSelectedItem(factionName);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, gameSettings.getNetworkPlayerName(i) [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,gameSettings.getNetworkPlayerName(i).c_str());
|
||||||
|
|
||||||
|
labelPlayerNames[i].setText(gameSettings.getNetworkPlayerName(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateControlers();
|
updateControlers();
|
||||||
@@ -1609,8 +1657,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
|||||||
|
|
||||||
// ============ PRIVATE ===========================
|
// ============ PRIVATE ===========================
|
||||||
|
|
||||||
bool MenuStateCustomGame::hasNetworkGameSettings()
|
bool MenuStateCustomGame::hasNetworkGameSettings() {
|
||||||
{
|
|
||||||
bool hasNetworkSlot = false;
|
bool hasNetworkSlot = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -1752,15 +1799,13 @@ void MenuStateCustomGame::closeUnusedSlots(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateCustomGame::updateNetworkSlots()
|
void MenuStateCustomGame::updateNetworkSlots() {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
|
|
||||||
for(int i= 0; i<GameConstants::maxPlayers; ++i)
|
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
||||||
{
|
if(serverInterface->getSlot(i) == NULL &&
|
||||||
if(serverInterface->getSlot(i) == NULL && listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
serverInterface->addSlot(i);
|
serverInterface->addSlot(i);
|
||||||
}
|
}
|
||||||
@@ -1777,11 +1822,11 @@ void MenuStateCustomGame::updateNetworkSlots()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Revert network to CPU
|
// Revert network to CPU
|
||||||
listBoxControls[i].setSelectedItemIndex(2);
|
listBoxControls[i].setSelectedItemIndex(ctCpu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(serverInterface->getSlot(i) != NULL && listBoxControls[i].getSelectedItemIndex() != ctNetwork)
|
if(serverInterface->getSlot(i) != NULL &&
|
||||||
{
|
listBoxControls[i].getSelectedItemIndex() != ctNetwork) {
|
||||||
serverInterface->removeSlot(i);
|
serverInterface->removeSlot(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1799,7 +1844,7 @@ void MenuStateCustomGame::updateNetworkSlots()
|
|||||||
|
|
||||||
void MenuStateCustomGame::keyDown(char key) {
|
void MenuStateCustomGame::keyDown(char key) {
|
||||||
if(activeInputLabel!=NULL) {
|
if(activeInputLabel!=NULL) {
|
||||||
if(key==vkBack){
|
if(key==vkBack) {
|
||||||
string text= activeInputLabel->getText();
|
string text= activeInputLabel->getText();
|
||||||
if(text.size()>1){
|
if(text.size()>1){
|
||||||
text.erase(text.end()-2);
|
text.erase(text.end()-2);
|
||||||
@@ -1807,8 +1852,7 @@ void MenuStateCustomGame::keyDown(char key) {
|
|||||||
activeInputLabel->setText(text);
|
activeInputLabel->setText(text);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
if(hasNetworkGameSettings() == true)
|
if(hasNetworkGameSettings() == true) {
|
||||||
{
|
|
||||||
needToSetChangedGameSettings = true;
|
needToSetChangedGameSettings = true;
|
||||||
lastSetChangedGameSettings = time(NULL);
|
lastSetChangedGameSettings = time(NULL);
|
||||||
}
|
}
|
||||||
@@ -1817,8 +1861,8 @@ void MenuStateCustomGame::keyDown(char key) {
|
|||||||
else {
|
else {
|
||||||
//send key to the chat manager
|
//send key to the chat manager
|
||||||
chatManager.keyDown(key);
|
chatManager.keyDown(key);
|
||||||
if(!chatManager.getEditEnabled()){
|
if(!chatManager.getEditEnabled()) {
|
||||||
if(key=='M'){
|
if(key=='M') {
|
||||||
showFullConsole= true;
|
showFullConsole= true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1828,18 +1872,17 @@ void MenuStateCustomGame::keyDown(char key) {
|
|||||||
void MenuStateCustomGame::keyPress(char c) {
|
void MenuStateCustomGame::keyPress(char c) {
|
||||||
if(activeInputLabel!=NULL) {
|
if(activeInputLabel!=NULL) {
|
||||||
int maxTextSize= 16;
|
int maxTextSize= 16;
|
||||||
for(int i=0; i<GameConstants::maxPlayers; ++i){
|
for(int i=0; i<GameConstants::maxPlayers; ++i) {
|
||||||
if(&labelPlayerNames[i] == activeInputLabel){
|
if(&labelPlayerNames[i] == activeInputLabel) {
|
||||||
if((c>='0' && c<='9')||(c>='a' && c<='z')||(c>='A' && c<='Z')||
|
if((c>='0' && c<='9')||(c>='a' && c<='z')||(c>='A' && c<='Z')||
|
||||||
(c=='-')||(c=='(')||(c==')')){
|
(c=='-')||(c=='(')||(c==')')){
|
||||||
if(activeInputLabel->getText().size()<maxTextSize){
|
if(activeInputLabel->getText().size()<maxTextSize) {
|
||||||
string text= activeInputLabel->getText();
|
string text= activeInputLabel->getText();
|
||||||
text.insert(text.end()-1, c);
|
text.insert(text.end()-1, c);
|
||||||
activeInputLabel->setText(text);
|
activeInputLabel->setText(text);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
|
||||||
if(hasNetworkGameSettings() == true)
|
if(hasNetworkGameSettings() == true) {
|
||||||
{
|
|
||||||
needToSetChangedGameSettings = true;
|
needToSetChangedGameSettings = true;
|
||||||
lastSetChangedGameSettings = time(NULL);
|
lastSetChangedGameSettings = time(NULL);
|
||||||
}
|
}
|
||||||
@@ -1881,9 +1924,8 @@ void MenuStateCustomGame::showMessageBox(const string &text, const string &heade
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable)
|
void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable) {
|
||||||
{
|
if(newLable!=NULL) {
|
||||||
if(newLable!=NULL){
|
|
||||||
string text= newLable->getText();
|
string text= newLable->getText();
|
||||||
size_t found;
|
size_t found;
|
||||||
found=text.find_last_of("_");
|
found=text.find_last_of("_");
|
||||||
@@ -1907,26 +1949,37 @@ void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
string MenuStateCustomGame::getHumanPlayerName(int index) {
|
string MenuStateCustomGame::getHumanPlayerName(int index) {
|
||||||
string result = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
string result = defaultPlayerName;
|
||||||
|
|
||||||
//printf("\nIn [%s::%s Line: %d] index = %d\n",__FILE__,__FUNCTION__,__LINE__,index);
|
//printf("\nIn [%s::%s Line: %d] index = %d\n",__FILE__,__FUNCTION__,__LINE__,index);
|
||||||
//fflush(stdout);
|
//fflush(stdout);
|
||||||
|
|
||||||
if(index < 0) {
|
if(index < 0) {
|
||||||
for(int j=0; j<GameConstants::maxPlayers; ++j) {
|
for(int j = 0; j < GameConstants::maxPlayers; ++j) {
|
||||||
ControlType ct= static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
|
if(listBoxControls[j].getSelectedItemIndex() >= 0) {
|
||||||
|
ControlType ct = static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
|
||||||
if(ct == ctHuman) {
|
if(ct == ctHuman) {
|
||||||
index = j;
|
index = j;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//printf("\nIn [%s::%s Line: %d] index = %d, labelPlayerNames[index].getText() = [%s]\n",__FILE__,__FUNCTION__,__LINE__,index,(index >= 0 ? labelPlayerNames[index].getText().c_str() : "?"));
|
//printf("\nIn [%s::%s Line: %d] index = %d, labelPlayerNames[index].getText() = [%s]\n",__FILE__,__FUNCTION__,__LINE__,index,(index >= 0 ? labelPlayerNames[index].getText().c_str() : "?"));
|
||||||
//fflush(stdout);
|
//fflush(stdout);
|
||||||
|
|
||||||
if(index >= 0 && labelPlayerNames[index].getText() != "") {
|
if(index >= 0 && index < GameConstants::maxPlayers &&
|
||||||
|
labelPlayerNames[index].getText() != "" &&
|
||||||
|
labelPlayerNames[index].getText() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) {
|
||||||
result = labelPlayerNames[index].getText();
|
result = labelPlayerNames[index].getText();
|
||||||
|
|
||||||
|
if(activeInputLabel != NULL) {
|
||||||
|
size_t found = result.find_last_of("_");
|
||||||
|
if (found != string::npos) {
|
||||||
|
result = result.substr(0,found);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@@ -107,6 +107,9 @@ private:
|
|||||||
string lastTileDataSynchError;
|
string lastTileDataSynchError;
|
||||||
string lastTechtreeDataSynchError;
|
string lastTechtreeDataSynchError;
|
||||||
|
|
||||||
|
string defaultPlayerName;
|
||||||
|
int8 switchSetupRequestFlagType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MenuStateCustomGame(Program *program, MainMenu *mainMenu ,bool openNetworkSlots= false, bool parentMenuIsMasterserver=false);
|
MenuStateCustomGame(Program *program, MainMenu *mainMenu ,bool openNetworkSlots= false, bool parentMenuIsMasterserver=false);
|
||||||
~MenuStateCustomGame();
|
~MenuStateCustomGame();
|
||||||
|
@@ -913,11 +913,12 @@ void ClientInterface::stopServerDiscovery() {
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientInterface::sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam, string networkPlayerName)
|
void ClientInterface::sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex,
|
||||||
{
|
int8 toFactionIndex,int8 toTeam, string networkPlayerName,
|
||||||
|
int8 flags) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
//printf("string-cuf-tof-team= %s-%d-%d-%d\n",selectedFactionName.c_str(),currentFactionIndex,toFactionIndex,toTeam);
|
//printf("string-cuf-tof-team= %s-%d-%d-%d\n",selectedFactionName.c_str(),currentFactionIndex,toFactionIndex,toTeam);
|
||||||
SwitchSetupRequest message=SwitchSetupRequest(selectedFactionName, currentFactionIndex, toFactionIndex,toTeam,networkPlayerName);
|
SwitchSetupRequest message=SwitchSetupRequest(selectedFactionName, currentFactionIndex, toFactionIndex,toTeam,networkPlayerName, flags);
|
||||||
sendMessage(&message);
|
sendMessage(&message);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
@@ -91,7 +91,9 @@ public:
|
|||||||
void discoverServers(DiscoveredServersInterface *cb);
|
void discoverServers(DiscoveredServersInterface *cb);
|
||||||
void stopServerDiscovery();
|
void stopServerDiscovery();
|
||||||
|
|
||||||
void sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex, int8 toTeam,string networkPlayerName);
|
void sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex,
|
||||||
|
int8 toFactionIndex, int8 toTeam,string networkPlayerName,
|
||||||
|
int8 flags);
|
||||||
virtual bool getConnectHasHandshaked() const { return gotIntro; }
|
virtual bool getConnectHasHandshaked() const { return gotIntro; }
|
||||||
std::string getServerIpAddress();
|
std::string getServerIpAddress();
|
||||||
|
|
||||||
|
@@ -302,7 +302,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
|
|
||||||
case nmtText:
|
case nmtText:
|
||||||
{
|
{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtText gotIntro = %d\n",__FILE__,__FUNCTION__,__LINE__,gotIntro);
|
||||||
|
|
||||||
if(gotIntro == true) {
|
if(gotIntro == true) {
|
||||||
NetworkMessageText networkMessageText;
|
NetworkMessageText networkMessageText;
|
||||||
@@ -320,7 +320,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
//command list
|
//command list
|
||||||
case nmtCommandList: {
|
case nmtCommandList: {
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtCommandList\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtCommandList gotIntro = %d\n",__FILE__,__FUNCTION__,__LINE__,gotIntro);
|
||||||
|
|
||||||
//throw runtime_error("test");
|
//throw runtime_error("test");
|
||||||
|
|
||||||
@@ -571,16 +571,21 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
|
|
||||||
case nmtSwitchSetupRequest:
|
case nmtSwitchSetupRequest:
|
||||||
{
|
{
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtSwitchSetupRequest gotIntro = %d\n",__FILE__,__FUNCTION__,__LINE__,gotIntro);
|
||||||
|
|
||||||
if(gotIntro == true) {
|
if(gotIntro == true) {
|
||||||
SwitchSetupRequest switchSetupRequest;
|
SwitchSetupRequest switchSetupRequest;
|
||||||
if(receiveMessage(&switchSetupRequest)) {
|
if(receiveMessage(&switchSetupRequest)) {
|
||||||
Mutex *mutex = getServerSynchAccessor();
|
Mutex *mutex = getServerSynchAccessor();
|
||||||
if(mutex != NULL) mutex->p();
|
if(mutex != NULL) mutex->p();
|
||||||
|
|
||||||
if(serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]==NULL) {
|
int factionIdx = switchSetupRequest.getCurrentFactionIndex();
|
||||||
serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]= new SwitchSetupRequest();
|
if(serverInterface->getSwitchSetupRequests()[factionIdx] == NULL) {
|
||||||
|
serverInterface->getSwitchSetupRequests()[factionIdx]= new SwitchSetupRequest();
|
||||||
}
|
}
|
||||||
*(serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()])=switchSetupRequest;
|
*(serverInterface->getSwitchSetupRequests()[factionIdx]) = switchSetupRequest;
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] factionIdx = %d, switchSetupRequest.getNetworkPlayerName() = %s\n",__FILE__,__FUNCTION__,__LINE__,factionIdx,switchSetupRequest.getNetworkPlayerName().c_str());
|
||||||
|
|
||||||
if(mutex != NULL) mutex->v();
|
if(mutex != NULL) mutex->v();
|
||||||
}
|
}
|
||||||
@@ -594,7 +599,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] networkMessageType = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageType);
|
||||||
|
|
||||||
if(gotIntro == true) {
|
if(gotIntro == true) {
|
||||||
//throw runtime_error("Unexpected message in connection slot: " + intToStr(networkMessageType));
|
//throw runtime_error("Unexpected message in connection slot: " + intToStr(networkMessageType));
|
||||||
|
@@ -824,28 +824,29 @@ void NetworkMessageSynchNetworkGameDataFileGet::send(Socket* socket) const {
|
|||||||
|
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class NetworkMessageSynchNetworkGameDataFileGet
|
// class SwitchSetupRequest
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
SwitchSetupRequest::SwitchSetupRequest()
|
SwitchSetupRequest::SwitchSetupRequest() {
|
||||||
{
|
|
||||||
data.messageType= nmtSwitchSetupRequest;
|
data.messageType= nmtSwitchSetupRequest;
|
||||||
data.selectedFactionName="";
|
data.selectedFactionName="";
|
||||||
data.currentFactionIndex=-1;
|
data.currentFactionIndex=-1;
|
||||||
data.toFactionIndex=-1;
|
data.toFactionIndex=-1;
|
||||||
data.toTeam = -1;
|
data.toTeam = -1;
|
||||||
data.networkPlayerName="";
|
data.networkPlayerName="";
|
||||||
|
data.switchFlags = ssrft_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SwitchSetupRequest::SwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex,
|
||||||
SwitchSetupRequest::SwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam,string networkPlayerName)
|
int8 toFactionIndex,int8 toTeam,string networkPlayerName,
|
||||||
{
|
int8 flags) {
|
||||||
data.messageType= nmtSwitchSetupRequest;
|
data.messageType= nmtSwitchSetupRequest;
|
||||||
data.selectedFactionName=selectedFactionName;
|
data.selectedFactionName=selectedFactionName;
|
||||||
data.currentFactionIndex=currentFactionIndex;
|
data.currentFactionIndex=currentFactionIndex;
|
||||||
data.toFactionIndex=toFactionIndex;
|
data.toFactionIndex=toFactionIndex;
|
||||||
data.toTeam = toTeam;
|
data.toTeam = toTeam;
|
||||||
data.networkPlayerName=networkPlayerName;
|
data.networkPlayerName=networkPlayerName;
|
||||||
|
data.switchFlags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SwitchSetupRequest::receive(Socket* socket) {
|
bool SwitchSetupRequest::receive(Socket* socket) {
|
||||||
@@ -857,13 +858,11 @@ bool SwitchSetupRequest::receive(Socket* socket) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchSetupRequest::send(Socket* socket) const
|
void SwitchSetupRequest::send(Socket* socket) const {
|
||||||
{
|
|
||||||
assert(data.messageType==nmtSwitchSetupRequest);
|
assert(data.messageType==nmtSwitchSetupRequest);
|
||||||
NetworkMessage::send(socket, &data, sizeof(data));
|
NetworkMessage::send(socket, &data, sizeof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class PlayerIndexMessage
|
// class PlayerIndexMessage
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@@ -546,10 +546,21 @@ public:
|
|||||||
// to switch its settings
|
// to switch its settings
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
|
// Each bit represents which item in the packet has a changed value
|
||||||
|
enum SwitchSetupRequestFlagType {
|
||||||
|
ssrft_None = 0x00,
|
||||||
|
ssrft_SelectedFactionName = 0x01,
|
||||||
|
ssrft_CurrentFactionIndex = 0x02,
|
||||||
|
ssrft_ToFactionIndex = 0x04,
|
||||||
|
ssrft_ToTeam = 0x08,
|
||||||
|
ssrft_NetworkPlayerName = 0x10
|
||||||
|
};
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
class SwitchSetupRequest: public NetworkMessage{
|
class SwitchSetupRequest: public NetworkMessage{
|
||||||
private:
|
private:
|
||||||
static const int maxStringSize= 256;
|
static const int maxStringSize= 256;
|
||||||
|
static const int maxPlayernameStringSize= 80;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Data{
|
struct Data{
|
||||||
@@ -558,7 +569,8 @@ private:
|
|||||||
int8 currentFactionIndex;
|
int8 currentFactionIndex;
|
||||||
int8 toFactionIndex;
|
int8 toFactionIndex;
|
||||||
int8 toTeam;
|
int8 toTeam;
|
||||||
NetworkString<maxStringSize> networkPlayerName;
|
NetworkString<maxPlayernameStringSize> networkPlayerName;
|
||||||
|
int8 switchFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -566,13 +578,17 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
SwitchSetupRequest();
|
SwitchSetupRequest();
|
||||||
SwitchSetupRequest( string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam,string networkPlayerName);
|
SwitchSetupRequest( string selectedFactionName, int8 currentFactionIndex,
|
||||||
|
int8 toFactionIndex,int8 toTeam,string networkPlayerName, int8 flags);
|
||||||
|
|
||||||
string getSelectedFactionName() const {return data.selectedFactionName.getString();}
|
string getSelectedFactionName() const {return data.selectedFactionName.getString();}
|
||||||
int getCurrentFactionIndex() const {return data.currentFactionIndex;}
|
int getCurrentFactionIndex() const {return data.currentFactionIndex;}
|
||||||
int getToFactionIndex() const {return data.toFactionIndex;}
|
int getToFactionIndex() const {return data.toFactionIndex;}
|
||||||
int getToTeam() const {return data.toTeam;}
|
int getToTeam() const {return data.toTeam;}
|
||||||
string getNetworkPlayerName() const {return data.networkPlayerName.getString(); }
|
string getNetworkPlayerName() const {return data.networkPlayerName.getString(); }
|
||||||
|
int getSwitchFlags() const {return data.switchFlags;}
|
||||||
|
int addSwitchFlag(SwitchSetupRequestFlagType flag) { data.switchFlags |= flag;}
|
||||||
|
int clearSwitchFlag(SwitchSetupRequestFlagType flag) { data.switchFlags &= ~flag;}
|
||||||
|
|
||||||
virtual bool receive(Socket* socket);
|
virtual bool receive(Socket* socket);
|
||||||
virtual void send(Socket* socket) const;
|
virtual void send(Socket* socket) const;
|
||||||
|
Reference in New Issue
Block a user