- bugfixes for playername change in lobby screen

This commit is contained in:
Mark Vejvoda 2010-08-23 04:33:21 +00:00
parent 401a39c3e1
commit 0509b5d643
9 changed files with 230 additions and 147 deletions

View File

@ -48,6 +48,7 @@ struct FormatString {
MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots):
MenuState(program, mainMenu, "connected-game") //← set on connected-game
{
switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
updateDataSynchDetailText = false;
activeInputLabel = NULL;
lastNetworkSendPing = 0;
@ -65,6 +66,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
Config &config = Config::getInstance();
defaultPlayerName = config.getString("NetPlayerName",Socket::getHostName().c_str());
labelMapInfo.setText("?");
@ -298,23 +300,25 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
if (myCurrentIndex!=-1)
for(int i=0; i<GameConstants::maxPlayers; ++i)
{
if(listBoxFactions[i].getEditable()){
if(listBoxFactions[i].mouseClick(x, y)){
if(listBoxFactions[i].getEditable()) {
if(listBoxFactions[i].mouseClick(x, y)) {
soundRenderer.playFx(coreData.getClickSoundA());
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
if(clientInterface->isConnected()){
if(clientInterface->isConnected()) {
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;
}
}
if(listBoxTeams[i].getEditable()){
if(listBoxTeams[i].mouseClick(x, y)){
if(listBoxTeams[i].getEditable()) {
if(listBoxTeams[i].mouseClick(x, y)) {
soundRenderer.playFx(coreData.getClickSoundA());
if(clientInterface->isConnected()){
if(clientInterface->isConnected()) {
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;
}
@ -327,7 +331,8 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
clientInterface->setGameSettingsReceived(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);
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;
}
}
@ -474,8 +479,7 @@ void MenuStateConnectedGame::render(){
}
}
void MenuStateConnectedGame::update()
{
void MenuStateConnectedGame::update() {
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
Lang &lang= Lang::getInstance();
@ -576,8 +580,7 @@ void MenuStateConnectedGame::update()
// label = label + " FogOfWar == false";
//}
}
else if(clientInterface->getAllowGameDataSynchCheck() == true)
{
else if(clientInterface->getAllowGameDataSynchCheck() == true) {
label += " - data synch is ok";
}
@ -591,12 +594,10 @@ void MenuStateConnectedGame::update()
//labelStatus.setText(szBuf);
labelStatus.setText(label);
}
else
{
else {
string label = lang.get("ConnectedToServer");
if(!clientInterface->getServerName().empty())
{
if(!clientInterface->getServerName().empty()) {
label = label + " " + clientInterface->getServerName();
}
@ -651,7 +652,7 @@ void MenuStateConnectedGame::update()
//process network messages
if(clientInterface->isConnected()) {
bool mustSwitchPlayerName = false;
if(clientInterface->getGameSettingsReceived()){
if(clientInterface->getGameSettingsReceived()) {
updateDataSynchDetailText = true;
bool errorOnMissingData = (clientInterface->getAllowGameDataSynchCheck() == false);
//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
clientInterface->updateLobby();
clientInterface= NetworkManager::getInstance().getClientInterface();
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
chatManager.updateNetwork();
@ -926,9 +921,7 @@ bool MenuStateConnectedGame::hasNetworkGameSettings()
return hasNetworkSlot;
}
void MenuStateConnectedGame::reloadFactions(){
void MenuStateConnectedGame::reloadFactions() {
vector<string> results;
@ -980,6 +973,7 @@ void MenuStateConnectedGame::keyDown(char key) {
}
activeInputLabel->setText(text);
switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
@ -1002,11 +996,12 @@ void MenuStateConnectedGame::keyPress(char c) {
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){
if(activeInputLabel->getText().size()<maxTextSize) {
string text= activeInputLabel->getText();
text.insert(text.end()-1, c);
activeInputLabel->setText(text);
switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
@ -1032,24 +1027,21 @@ void MenuStateConnectedGame::keyUp(char key) {
}
}
void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable)
{
if(newLable!=NULL){
void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable) {
if(newLable!=NULL) {
string text= newLable->getText();
size_t found;
found=text.find_last_of("_");
if (found==string::npos)
{
if (found==string::npos) {
text=text+"_";
}
newLable->setText(text);
}
if(activeInputLabel!=NULL && !activeInputLabel->getText().empty()){
if(activeInputLabel!=NULL && !activeInputLabel->getText().empty()) {
string text= activeInputLabel->getText();
size_t found;
found=text.find_last_of("_");
if (found!=string::npos)
{
if (found!=string::npos) {
text=text.substr(0,found);
}
activeInputLabel->setText(text);
@ -1058,15 +1050,24 @@ void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable)
}
string MenuStateConnectedGame::getHumanPlayerName() {
string result = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
string result = defaultPlayerName;
NetworkManager &networkManager= NetworkManager::getInstance();
ClientInterface* clientInterface= networkManager.getClientInterface();
for(int j=0; j<GameConstants::maxPlayers; ++j) {
if(clientInterface != NULL &&
if( clientInterface != NULL &&
clientInterface->getGameSettings() != NULL &&
j == clientInterface->getGameSettings()->getThisFactionIndex() &&
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;
}
}

View File

@ -97,6 +97,9 @@ private:
string lastTileDataSynchError;
string lastTechtreeDataSynchError;
int8 switchSetupRequestFlagType;
string defaultPlayerName;
public:
MenuStateConnectedGame(Program *program, MainMenu *mainMenu, JoinMenu joinMenuInfo=jmSimple, bool openNetworkSlots= false);

View File

@ -58,6 +58,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
Config &config = Config::getInstance();
defaultPlayerName = config.getString("NetPlayerName",Socket::getHostName().c_str());
showFullConsole=false;
@ -645,39 +646,54 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
for(int i=0; i<mapInfo.players; ++i) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
//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
int humanIndex1= -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());
if(ct==ctHuman){
if(humanIndex1==-1){
if(ct == ctHuman) {
if(humanIndex1 == -1) {
humanIndex1= j;
}
else{
else {
humanIndex2= j;
}
}
}
//no human
if(humanIndex1==-1 && humanIndex2==-1){
listBoxControls[i].setSelectedItemIndex(ctHuman);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] humanIndex1 = %d, humanIndex2 = %d\n",__FILE__,__FUNCTION__,__LINE__,humanIndex1,humanIndex2);
//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
if(humanIndex1!=-1 && humanIndex2!=-1){
listBoxControls[humanIndex1==i? humanIndex2: humanIndex1].setSelectedItemIndex(ctClosed);
else if(humanIndex1 != -1 && humanIndex2 != -1) {
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();
needToRepublishToMasterserver = true;
if(hasNetworkGameSettings() == true)
{
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);;
lastSetChangedGameSettings = time(NULL);
}
}
else if(listBoxFactions[i].mouseClick(x, y)){
@ -686,7 +702,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
if(hasNetworkGameSettings() == true)
{
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);;
lastSetChangedGameSettings = time(NULL);
}
}
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__);
// handle setting changes from clients
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
for(int i= 0; i<mapInfo.players; ++i) {
SwitchSetupRequest ** switchSetupRequests = serverInterface->getSwitchSetupRequests();
for(int i= 0; i< mapInfo.players; ++i) {
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) {
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]->getToTeam()=%d\n",switchSetupRequests[i]->getToTeam());
if(switchSetupRequests[i]->getToFactionIndex()!=-1) {
int k=switchSetupRequests[i]->getToFactionIndex();
labelPlayerNames[k].setText(switchSetupRequests[i]->getNetworkPlayerName());
if(switchSetupRequests[i]->getToFactionIndex() != -1) {
int newFactionIdx = switchSetupRequests[i]->getToFactionIndex();
/*
if(switchSetupRequests[i]->getNetworkPlayerName() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) {
labelPlayerNames[k].setText(switchSetupRequests[i]->getNetworkPlayerName());
}
else {
labelPlayerNames[k].setText("");
}
*/
//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 {
if(switchSetupRequests[i]->getSelectedFactionName()!=""){
listBoxFactions[k].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
if(switchSetupRequests[i]->getSelectedFactionName() != ""){
listBoxFactions[newFactionIdx].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
}
if(switchSetupRequests[i]->getToTeam()!=-1) {
listBoxTeams[k].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
if(switchSetupRequests[i]->getToTeam() != -1) {
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) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
}
}
}
else
{
else {
try {
labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName());
if(switchSetupRequests[i]->getSelectedFactionName()!=""){
if(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());
}
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) {
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);
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__);
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
{
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
@ -1371,8 +1402,11 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
gameSettings->setFactionControl(slotIndex, ct);
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->setNetworkPlayerName(slotIndex, getHumanPlayerName(slotIndex));
gameSettings->setNetworkPlayerName(slotIndex, getHumanPlayerName(i));
labelPlayerNames[i].setText(getHumanPlayerName(i));
}
gameSettings->setTeam(slotIndex, listBoxTeams[i].getSelectedItemIndex());
gameSettings->setStartLocationIndex(slotIndex, i);
@ -1381,22 +1415,32 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
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());
labelPlayerNames[slotIndex].setText(connectionSlot->getName());
labelPlayerNames[i].setText(connectionSlot->getName());
}
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);
labelPlayerNames[slotIndex].setText("");
labelPlayerNames[i].setText("");
}
}
else if (listBoxControls[i].getSelectedItemIndex() != ctHuman) {
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));
labelPlayerNames[slotIndex].setText(string("AI") + intToStr(AIPlayerCount));
labelPlayerNames[i].setText("");
}
factionCount++;
}
else {
//gameSettings->setNetworkPlayerName("");
labelPlayerNames[i].setText("");
}
}
// Next save closed slots
int closedCount = 0;
@ -1521,7 +1565,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
gameSettings.setTeam(i,properties.getInt(string("FactionTeamForIndex") + intToStr(i),"0") );
gameSettings.setStartLocationIndex(i,properties.getInt(string("FactionStartLocationForIndex") + intToStr(i),intToStr(i).c_str()) );
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__);
@ -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());
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();
@ -1609,8 +1657,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
// ============ PRIVATE ===========================
bool MenuStateCustomGame::hasNetworkGameSettings()
{
bool MenuStateCustomGame::hasNetworkGameSettings() {
bool hasNetworkSlot = false;
try {
@ -1752,15 +1799,13 @@ void MenuStateCustomGame::closeUnusedSlots(){
}
}
void MenuStateCustomGame::updateNetworkSlots()
{
void MenuStateCustomGame::updateNetworkSlots() {
try {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
for(int i= 0; i<GameConstants::maxPlayers; ++i)
{
if(serverInterface->getSlot(i) == NULL && listBoxControls[i].getSelectedItemIndex() == ctNetwork)
{
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
if(serverInterface->getSlot(i) == NULL &&
listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
try {
serverInterface->addSlot(i);
}
@ -1777,11 +1822,11 @@ void MenuStateCustomGame::updateNetworkSlots()
}
// 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);
}
}
@ -1799,7 +1844,7 @@ void MenuStateCustomGame::updateNetworkSlots()
void MenuStateCustomGame::keyDown(char key) {
if(activeInputLabel!=NULL) {
if(key==vkBack){
if(key==vkBack) {
string text= activeInputLabel->getText();
if(text.size()>1){
text.erase(text.end()-2);
@ -1807,8 +1852,7 @@ void MenuStateCustomGame::keyDown(char key) {
activeInputLabel->setText(text);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(hasNetworkGameSettings() == true)
{
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
@ -1817,8 +1861,8 @@ void MenuStateCustomGame::keyDown(char key) {
else {
//send key to the chat manager
chatManager.keyDown(key);
if(!chatManager.getEditEnabled()){
if(key=='M'){
if(!chatManager.getEditEnabled()) {
if(key=='M') {
showFullConsole= true;
}
}
@ -1828,18 +1872,17 @@ void MenuStateCustomGame::keyDown(char key) {
void MenuStateCustomGame::keyPress(char c) {
if(activeInputLabel!=NULL) {
int maxTextSize= 16;
for(int i=0; i<GameConstants::maxPlayers; ++i){
if(&labelPlayerNames[i] == activeInputLabel){
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){
if(activeInputLabel->getText().size()<maxTextSize) {
string text= activeInputLabel->getText();
text.insert(text.end()-1, c);
activeInputLabel->setText(text);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
if(hasNetworkGameSettings() == true)
{
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
@ -1881,9 +1924,8 @@ void MenuStateCustomGame::showMessageBox(const string &text, const string &heade
}
}
void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable)
{
if(newLable!=NULL){
void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable) {
if(newLable!=NULL) {
string text= newLable->getText();
size_t found;
found=text.find_last_of("_");
@ -1907,17 +1949,19 @@ void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable)
}
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);
//fflush(stdout);
if(index < 0) {
for(int j=0; j<GameConstants::maxPlayers; ++j) {
ControlType ct= static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
if(ct == ctHuman) {
index = j;
break;
for(int j = 0; j < GameConstants::maxPlayers; ++j) {
if(listBoxControls[j].getSelectedItemIndex() >= 0) {
ControlType ct = static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
if(ct == ctHuman) {
index = j;
break;
}
}
}
}
@ -1925,8 +1969,17 @@ string MenuStateCustomGame::getHumanPlayerName(int index) {
//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);
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();
if(activeInputLabel != NULL) {
size_t found = result.find_last_of("_");
if (found != string::npos) {
result = result.substr(0,found);
}
}
}
return result;

View File

@ -107,6 +107,9 @@ private:
string lastTileDataSynchError;
string lastTechtreeDataSynchError;
string defaultPlayerName;
int8 switchSetupRequestFlagType;
public:
MenuStateCustomGame(Program *program, MainMenu *mainMenu ,bool openNetworkSlots= false, bool parentMenuIsMasterserver=false);
~MenuStateCustomGame();

View File

@ -913,11 +913,12 @@ void ClientInterface::stopServerDiscovery() {
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__);
//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);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}

View File

@ -91,7 +91,9 @@ public:
void discoverServers(DiscoveredServersInterface *cb);
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; }
std::string getServerIpAddress();

View File

@ -302,7 +302,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
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) {
NetworkMessageText networkMessageText;
@ -320,7 +320,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
//command list
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");
@ -571,16 +571,21 @@ void ConnectionSlot::update(bool checkForNewClients) {
case nmtSwitchSetupRequest:
{
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtSwitchSetupRequest gotIntro = %d\n",__FILE__,__FUNCTION__,__LINE__,gotIntro);
if(gotIntro == true) {
SwitchSetupRequest switchSetupRequest;
if(receiveMessage(&switchSetupRequest)) {
Mutex *mutex = getServerSynchAccessor();
if(mutex != NULL) mutex->p();
if(serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]==NULL) {
serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]= new SwitchSetupRequest();
int factionIdx = switchSetupRequest.getCurrentFactionIndex();
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();
}
@ -594,7 +599,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
}
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) {
//throw runtime_error("Unexpected message in connection slot: " + intToStr(networkMessageType));

View File

@ -824,28 +824,29 @@ void NetworkMessageSynchNetworkGameDataFileGet::send(Socket* socket) const {
// =====================================================
// class NetworkMessageSynchNetworkGameDataFileGet
// class SwitchSetupRequest
// =====================================================
SwitchSetupRequest::SwitchSetupRequest()
{
SwitchSetupRequest::SwitchSetupRequest() {
data.messageType= nmtSwitchSetupRequest;
data.selectedFactionName="";
data.currentFactionIndex=-1;
data.toFactionIndex=-1;
data.toTeam = -1;
data.networkPlayerName="";
data.switchFlags = ssrft_None;
}
SwitchSetupRequest::SwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam,string networkPlayerName)
{
SwitchSetupRequest::SwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex,
int8 toFactionIndex,int8 toTeam,string networkPlayerName,
int8 flags) {
data.messageType= nmtSwitchSetupRequest;
data.selectedFactionName=selectedFactionName;
data.currentFactionIndex=currentFactionIndex;
data.toFactionIndex=toFactionIndex;
data.toTeam = toTeam;
data.networkPlayerName=networkPlayerName;
data.switchFlags = flags;
}
bool SwitchSetupRequest::receive(Socket* socket) {
@ -857,13 +858,11 @@ bool SwitchSetupRequest::receive(Socket* socket) {
return result;
}
void SwitchSetupRequest::send(Socket* socket) const
{
void SwitchSetupRequest::send(Socket* socket) const {
assert(data.messageType==nmtSwitchSetupRequest);
NetworkMessage::send(socket, &data, sizeof(data));
}
// =====================================================
// class PlayerIndexMessage
// =====================================================

View File

@ -546,10 +546,21 @@ public:
// 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)
class SwitchSetupRequest: public NetworkMessage{
private:
static const int maxStringSize= 256;
static const int maxPlayernameStringSize= 80;
private:
struct Data{
@ -558,7 +569,8 @@ private:
int8 currentFactionIndex;
int8 toFactionIndex;
int8 toTeam;
NetworkString<maxStringSize> networkPlayerName;
NetworkString<maxPlayernameStringSize> networkPlayerName;
int8 switchFlags;
};
private:
@ -566,13 +578,17 @@ private:
public:
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();}
int getCurrentFactionIndex() const {return data.currentFactionIndex;}
int getToFactionIndex() const {return data.toFactionIndex;}
int getToTeam() const {return data.toTeam;}
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 void send(Socket* socket) const;