- added the ability to change your playername from the game lobbies inline
This commit is contained in:
parent
6530600516
commit
455876a3c0
|
@ -114,9 +114,10 @@ void ChatManager::keyDown(char key){
|
|||
|
||||
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
|
||||
if(!text.empty()) {
|
||||
console->addLine(Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + ": " + text);
|
||||
gameNetworkInterface->sendTextMessage(Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + ": "+
|
||||
text, teamMode? thisTeamIndex: -1);
|
||||
string playerName = gameNetworkInterface->getHumanPlayerName();
|
||||
|
||||
console->addLine(playerName + ": " + text);
|
||||
gameNetworkInterface->sendTextMessage(text, teamMode? thisTeamIndex: -1);
|
||||
if(!inMenu) editEnabled= false;
|
||||
}
|
||||
else
|
||||
|
@ -180,7 +181,8 @@ void ChatManager::updateNetwork() {
|
|||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] got nmtText [%s] for team = %d\n",__FILE__,__FUNCTION__,msg.chatText.c_str(),teamIndex);
|
||||
|
||||
if(teamIndex==-1 || teamIndex==thisTeamIndex){
|
||||
console->addLine(msg.chatText, true);
|
||||
//console->addLine(msg.chatText, true);
|
||||
console->addLine(msg.chatSender + ": " + msg.chatText, true);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Added text to console\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
|
|
|
@ -56,8 +56,9 @@ private:
|
|||
public:
|
||||
|
||||
|
||||
GameSettings() {
|
||||
fogOfWar = true;
|
||||
GameSettings() {
|
||||
thisFactionIndex = 0;
|
||||
fogOfWar = true;
|
||||
enableObserverModeAtEndGame = false;
|
||||
enableServerControlledAI = false;
|
||||
networkFramePeriod = GameConstants::networkFramePeriod;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
activeInputLabel = NULL;
|
||||
lastNetworkSendPing = 0;
|
||||
pingCount = 0;
|
||||
needToSetChangedGameSettings = false;
|
||||
|
@ -175,8 +176,10 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//list boxes
|
||||
for(int i=0; i<GameConstants::maxPlayers; ++i){
|
||||
labelPlayers[i].init(100, setupPos-30-i*30);
|
||||
labelPlayers[i].init(50, setupPos-30-i*30);
|
||||
labelPlayers[i].setEditable(false);
|
||||
labelPlayerNames[i].init(100,setupPos-30-i*30);
|
||||
|
||||
listBoxControls[i].init(200, setupPos-30-i*30);
|
||||
listBoxControls[i].setEditable(false);
|
||||
listBoxFactions[i].init(400, setupPos-30-i*30);
|
||||
|
@ -217,6 +220,8 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
teamItems.push_back("8");
|
||||
for(int i=0; i<GameConstants::maxPlayers; ++i){
|
||||
labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i));
|
||||
labelPlayerNames[i].setText("");
|
||||
|
||||
listBoxTeams[i].setItems(teamItems);
|
||||
listBoxTeams[i].setSelectedItemIndex(i);
|
||||
listBoxControls[i].setItems(controlItems);
|
||||
|
@ -236,6 +241,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
|
||||
//init controllers
|
||||
listBoxControls[0].setSelectedItemIndex(ctHuman);
|
||||
|
||||
chatManager.init(&console, -1,true);
|
||||
}
|
||||
|
||||
|
@ -254,7 +260,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||
{
|
||||
if(clientInterface->isConnected() == true)
|
||||
{
|
||||
string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!";
|
||||
string sQuitText = "has chosen to leave the game!";
|
||||
clientInterface->sendTextMessage(sQuitText,-1);
|
||||
sleep(1);
|
||||
}
|
||||
|
@ -297,7 +303,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||
if(clientInterface->isConnected()){
|
||||
clientInterface->setGameSettingsReceived(false);
|
||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex());
|
||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex(),getHumanPlayerName());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -307,7 +313,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||
soundRenderer.playFx(coreData.getClickSoundA());
|
||||
if(clientInterface->isConnected()){
|
||||
clientInterface->setGameSettingsReceived(false);
|
||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex());
|
||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex(),getHumanPlayerName());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -320,10 +326,17 @@ 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());
|
||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[myCurrentIndex].getSelectedItem(),myCurrentIndex,i,listBoxTeams[myCurrentIndex].getSelectedItemIndex(),getHumanPlayerName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(labelPlayerNames[i].mouseClick(x, y) && ( activeInputLabel != &labelPlayerNames[i] )){
|
||||
if(clientInterface->getGameSettings() != NULL &&
|
||||
i == clientInterface->getGameSettings()->getThisFactionIndex()) {
|
||||
setActiveInputLabel(&labelPlayerNames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -348,12 +361,22 @@ void MenuStateConnectedGame::mouseMove(int x, int y, const MouseState *ms){
|
|||
buttonDisconnect.mouseMove(x, y);
|
||||
buttonPlayNow.mouseMove(x, y);
|
||||
|
||||
bool editingPlayerName = false;
|
||||
for(int i=0; i<GameConstants::maxPlayers; ++i){
|
||||
listBoxControls[i].mouseMove(x, y);
|
||||
listBoxFactions[i].mouseMove(x, y);
|
||||
listBoxTeams[i].mouseMove(x, y);
|
||||
grabSlotButton[i].mouseMove(x, y);
|
||||
|
||||
if(labelPlayerNames[i].mouseMove(x, y) == true) {
|
||||
editingPlayerName = true;
|
||||
}
|
||||
|
||||
}
|
||||
if(editingPlayerName == false) {
|
||||
setActiveInputLabel(NULL);
|
||||
}
|
||||
|
||||
listBoxMap.mouseMove(x, y);
|
||||
listBoxFogOfWar.mouseMove(x, y);
|
||||
listBoxTileset.mouseMove(x, y);
|
||||
|
@ -398,6 +421,13 @@ void MenuStateConnectedGame::render(){
|
|||
(listBoxControls[i].getSelectedItemIndex()==ctHuman)){
|
||||
renderer.renderLabel(&labelNetStatus[i]);
|
||||
}
|
||||
|
||||
if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) ||
|
||||
(listBoxControls[i].getSelectedItemIndex()==ctHuman)){
|
||||
if(labelNetStatus[i].getText() != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) {
|
||||
renderer.renderLabel(&labelPlayerNames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
@ -459,8 +489,8 @@ void MenuStateConnectedGame::update()
|
|||
|
||||
// Starting checking timeout after sending at least 3 pings to server
|
||||
if(pingCount >= 3 && clientInterface->getLastPingLag() >= (GameConstants::networkPingInterval * 3)) {
|
||||
string playerNameStr = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
clientInterface->sendTextMessage(playerNameStr + "'s connection timed out communicating with server.",-1);
|
||||
string playerNameStr = getHumanPlayerName();
|
||||
clientInterface->sendTextMessage("connection timed out communicating with server.",-1);
|
||||
clientInterface->close();
|
||||
}
|
||||
|
||||
|
@ -577,8 +607,8 @@ void MenuStateConnectedGame::update()
|
|||
}
|
||||
|
||||
//process network messages
|
||||
if(clientInterface->isConnected())
|
||||
{
|
||||
if(clientInterface->isConnected()) {
|
||||
bool mustSwitchPlayerName = false;
|
||||
if(clientInterface->getGameSettingsReceived()){
|
||||
bool errorOnMissingData = (clientInterface->getAllowGameDataSynchCheck() == false);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
@ -673,20 +703,54 @@ void MenuStateConnectedGame::update()
|
|||
|
||||
if(gameSettings->getFactionControl(i) == ctNetwork ){
|
||||
labelNetStatus[slot].setText(gameSettings->getNetworkPlayerName(i));
|
||||
if(gameSettings->getThisFactionIndex() != i &&
|
||||
gameSettings->getNetworkPlayerName(i) != "") {
|
||||
labelPlayerNames[slot].setText(gameSettings->getNetworkPlayerName(i));
|
||||
}
|
||||
}
|
||||
|
||||
if(gameSettings->getFactionControl(i) == ctNetwork && gameSettings->getThisFactionIndex() == i){
|
||||
if(gameSettings->getFactionControl(i) == ctNetwork &&
|
||||
gameSettings->getThisFactionIndex() == i){
|
||||
// set my current slot to ctHuman
|
||||
listBoxControls[slot].setSelectedItemIndex(ctHuman);
|
||||
listBoxFactions[slot].setEditable(true);
|
||||
listBoxTeams[slot].setEditable(true);
|
||||
|
||||
if(labelPlayerNames[slot].getText() == "" &&
|
||||
gameSettings->getNetworkPlayerName(i) != "") {
|
||||
labelPlayerNames[slot].setText(gameSettings->getNetworkPlayerName(i));
|
||||
}
|
||||
}
|
||||
|
||||
settingsReceivedFromServer=true;
|
||||
initialSettingsReceivedFromServer=true;
|
||||
|
||||
needToSetChangedGameSettings = true;
|
||||
lastSetChangedGameSettings = time(NULL);
|
||||
|
||||
mustSwitchPlayerName = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
@ -695,7 +759,8 @@ void MenuStateConnectedGame::update()
|
|||
//call the chat manager
|
||||
chatManager.updateNetwork();
|
||||
|
||||
//console
|
||||
//console732
|
||||
|
||||
console.update();
|
||||
|
||||
//intro
|
||||
|
@ -765,7 +830,7 @@ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings, bool
|
|||
}
|
||||
|
||||
char szMsg[1024]="";
|
||||
sprintf(szMsg,"Player: %s is missing the techtree: %s",Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()).c_str(),gameSettings->getTech().c_str());
|
||||
sprintf(szMsg,"Player: %s is missing the techtree: %s",getHumanPlayerName().c_str(),gameSettings->getTech().c_str());
|
||||
clientInterface->sendTextMessage(szMsg,-1, true);
|
||||
|
||||
foundFactions = false;
|
||||
|
@ -863,32 +928,107 @@ void MenuStateConnectedGame::reloadFactions(){
|
|||
|
||||
|
||||
|
||||
void MenuStateConnectedGame::keyDown(char key)
|
||||
{
|
||||
//send key to the chat manager
|
||||
chatManager.keyDown(key);
|
||||
if(!chatManager.getEditEnabled()){
|
||||
if(key=='M'){
|
||||
showFullConsole= true;
|
||||
void MenuStateConnectedGame::keyDown(char key) {
|
||||
if(activeInputLabel!=NULL) {
|
||||
if(key==vkBack){
|
||||
string text= activeInputLabel->getText();
|
||||
if(text.size()>1){
|
||||
text.erase(text.end()-2);
|
||||
}
|
||||
activeInputLabel->setText(text);
|
||||
|
||||
needToSetChangedGameSettings = true;
|
||||
lastSetChangedGameSettings = time(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MenuStateConnectedGame::keyPress(char c)
|
||||
{
|
||||
chatManager.keyPress(c);
|
||||
}
|
||||
|
||||
void MenuStateConnectedGame::keyUp(char key)
|
||||
{
|
||||
chatManager.keyUp(key);
|
||||
if(chatManager.getEditEnabled()){
|
||||
else {
|
||||
//send key to the chat manager
|
||||
chatManager.keyDown(key);
|
||||
if(!chatManager.getEditEnabled()){
|
||||
if(key=='M'){
|
||||
showFullConsole= true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MenuStateConnectedGame::keyPress(char c) {
|
||||
if(activeInputLabel!=NULL) {
|
||||
int maxTextSize= 16;
|
||||
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){
|
||||
string text= activeInputLabel->getText();
|
||||
text.insert(text.end()-1, c);
|
||||
activeInputLabel->setText(text);
|
||||
|
||||
needToSetChangedGameSettings = true;
|
||||
lastSetChangedGameSettings = time(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
chatManager.keyPress(c);
|
||||
}
|
||||
}
|
||||
|
||||
void MenuStateConnectedGame::keyUp(char key) {
|
||||
if(activeInputLabel==NULL) {
|
||||
chatManager.keyUp(key);
|
||||
if(chatManager.getEditEnabled()){
|
||||
//send key to the chat manager
|
||||
chatManager.keyUp(key);
|
||||
}
|
||||
else if(key== 'M'){
|
||||
showFullConsole= false;
|
||||
}
|
||||
}
|
||||
else if(key== 'M'){
|
||||
showFullConsole= false;
|
||||
}
|
||||
|
||||
void MenuStateConnectedGame::setActiveInputLabel(GraphicLabel *newLable)
|
||||
{
|
||||
if(newLable!=NULL){
|
||||
string text= newLable->getText();
|
||||
size_t found;
|
||||
found=text.find_last_of("_");
|
||||
if (found==string::npos)
|
||||
{
|
||||
text=text+"_";
|
||||
}
|
||||
newLable->setText(text);
|
||||
}
|
||||
if(activeInputLabel!=NULL && !activeInputLabel->getText().empty()){
|
||||
string text= activeInputLabel->getText();
|
||||
size_t found;
|
||||
found=text.find_last_of("_");
|
||||
if (found!=string::npos)
|
||||
{
|
||||
text=text.substr(0,found);
|
||||
}
|
||||
activeInputLabel->setText(text);
|
||||
}
|
||||
activeInputLabel=newLable;
|
||||
}
|
||||
|
||||
string MenuStateConnectedGame::getHumanPlayerName() {
|
||||
string result = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
|
||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||
ClientInterface* clientInterface= networkManager.getClientInterface();
|
||||
for(int j=0; j<GameConstants::maxPlayers; ++j) {
|
||||
if(clientInterface != NULL &&
|
||||
j == clientInterface->getGameSettings()->getThisFactionIndex() &&
|
||||
labelPlayerNames[j].getText() != "") {
|
||||
result = labelPlayerNames[j].getText();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -66,11 +66,15 @@ private:
|
|||
vector<string> tilesetFiles;
|
||||
vector<string> factionFiles;
|
||||
GraphicLabel labelPlayers[GameConstants::maxPlayers];
|
||||
GraphicLabel labelPlayerNames[GameConstants::maxPlayers];
|
||||
GraphicListBox listBoxControls[GameConstants::maxPlayers];
|
||||
GraphicListBox listBoxFactions[GameConstants::maxPlayers];
|
||||
GraphicListBox listBoxTeams[GameConstants::maxPlayers];
|
||||
GraphicLabel labelNetStatus[GameConstants::maxPlayers];
|
||||
GraphicButton grabSlotButton[GameConstants::maxPlayers];
|
||||
|
||||
GraphicLabel *activeInputLabel;
|
||||
|
||||
MapInfo mapInfo;
|
||||
|
||||
bool needToSetChangedGameSettings;
|
||||
|
@ -109,6 +113,8 @@ private:
|
|||
void reloadFactions();
|
||||
bool loadFactions(const GameSettings *gameSettings,bool errorOnNoFactions);
|
||||
void returnToJoinMenu();
|
||||
string getHumanPlayerName();
|
||||
void setActiveInputLabel(GraphicLabel *newLable);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -882,44 +882,48 @@ void MenuStateCustomGame::update() {
|
|||
|
||||
// handle setting changes from clients
|
||||
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
|
||||
for(int i= 0; i<mapInfo.players; ++i)
|
||||
{
|
||||
if(switchSetupRequests[i]!=NULL)
|
||||
{
|
||||
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__);
|
||||
|
||||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if(switchSetupRequests[i]->getToFactionIndex()!=-1) {
|
||||
int k=switchSetupRequests[i]->getToFactionIndex();
|
||||
labelPlayerNames[k].setText(switchSetupRequests[i]->getNetworkPlayerName());
|
||||
|
||||
//printf("switchSlot request from %d to %d\n",switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex());
|
||||
if(serverInterface->switchSlot(switchSetupRequests[i]->getCurrentFactionIndex(),switchSetupRequests[i]->getToFactionIndex())){
|
||||
int k=switchSetupRequests[i]->getToFactionIndex();
|
||||
try {
|
||||
if(switchSetupRequests[i]->getSelectedFactionName()!=""){
|
||||
listBoxFactions[k].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
|
||||
}
|
||||
if(switchSetupRequests[i]->getToTeam()!=-1)
|
||||
listBoxTeams[k].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
|
||||
if(switchSetupRequests[i]->getToTeam()!=-1) {
|
||||
listBoxTeams[k].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
try {
|
||||
|
||||
labelPlayerNames[i].setText(switchSetupRequests[i]->getNetworkPlayerName());
|
||||
|
||||
if(switchSetupRequests[i]->getSelectedFactionName()!=""){
|
||||
listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
|
||||
}
|
||||
if(switchSetupRequests[i]->getToTeam()!=-1)
|
||||
listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
|
||||
if(switchSetupRequests[i]->getToTeam()!=-1) {
|
||||
listBoxTeams[i].setSelectedItemIndex(switchSetupRequests[i]->getToTeam());
|
||||
}
|
||||
}
|
||||
catch(const runtime_error &e) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caught exception error = [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||
|
@ -951,8 +955,9 @@ void MenuStateCustomGame::update() {
|
|||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__);
|
||||
|
||||
if(connectionSlot->isConnected())
|
||||
{
|
||||
if(connectionSlot->isConnected()) {
|
||||
connectionSlot->setName(labelPlayerNames[i].getText());
|
||||
|
||||
//printf("FYI we have at least 1 client connected, slot = %d'\n",i);
|
||||
|
||||
haveAtLeastOneNetworkClientConnected = true;
|
||||
|
@ -1166,7 +1171,7 @@ void MenuStateCustomGame::publishToMasterserver()
|
|||
publishToServerInfo["binaryCompileDate"] = getCompileDateTime();
|
||||
|
||||
//game info:
|
||||
publishToServerInfo["serverTitle"] = Config::getInstance().getString("NetPlayerName") + "'s game";
|
||||
publishToServerInfo["serverTitle"] = getHumanPlayerName() + "'s game";
|
||||
//ip is automatically set
|
||||
|
||||
//game setup info:
|
||||
|
@ -1246,19 +1251,23 @@ void MenuStateCustomGame::simpleTask() {
|
|||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
|
||||
GameSettings gameSettings;
|
||||
loadGameSettings(&gameSettings);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
serverInterface->setGameSettings(&gameSettings);
|
||||
safeMutex2.ReleaseLock();
|
||||
|
||||
if(hasClientConnection == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
GameSettings gameSettings;
|
||||
|
||||
MutexSafeWrapper safeMutex2(&masterServerThreadAccessor);
|
||||
loadGameSettings(&gameSettings);
|
||||
MutexSafeWrapper safeMutex3(&masterServerThreadAccessor);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
serverInterface->setGameSettings(&gameSettings);
|
||||
serverInterface->broadcastGameSetup(&gameSettings);
|
||||
safeMutex2.ReleaseLock();
|
||||
safeMutex3.ReleaseLock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1304,10 +1313,11 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
|||
if(ct != ctClosed) {
|
||||
int slotIndex = factionCount;
|
||||
|
||||
gameSettings->setFactionControl(slotIndex, ct);
|
||||
if(ct == ctHuman) {
|
||||
gameSettings->setThisFactionIndex(slotIndex);
|
||||
gameSettings->setNetworkPlayerName(slotIndex, getHumanPlayerName(slotIndex));
|
||||
}
|
||||
gameSettings->setFactionControl(slotIndex, ct);
|
||||
gameSettings->setTeam(slotIndex, listBoxTeams[i].getSelectedItemIndex());
|
||||
gameSettings->setStartLocationIndex(slotIndex, i);
|
||||
gameSettings->setFactionTypeName(slotIndex, factionFiles[listBoxFactions[i].getSelectedItemIndex()]);
|
||||
|
@ -1316,17 +1326,17 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
|||
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||
gameSettings->setNetworkPlayerName(slotIndex, connectionSlot->getName());
|
||||
labelPlayerNames[slotIndex].setText(connectionSlot->getName());
|
||||
}
|
||||
else {
|
||||
gameSettings->setNetworkPlayerName(slotIndex, GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME);
|
||||
labelPlayerNames[slotIndex].setText("");
|
||||
}
|
||||
}
|
||||
else if (listBoxControls[i].getSelectedItemIndex() == ctHuman) {
|
||||
gameSettings->setNetworkPlayerName(slotIndex, getHumanPlayerName());
|
||||
}
|
||||
else {
|
||||
else if (listBoxControls[i].getSelectedItemIndex() != ctHuman) {
|
||||
AIPlayerCount++;
|
||||
gameSettings->setNetworkPlayerName(slotIndex, string("AI") + intToStr(AIPlayerCount));
|
||||
labelPlayerNames[slotIndex].setText(string("AI") + intToStr(AIPlayerCount));
|
||||
}
|
||||
|
||||
factionCount++;
|
||||
|
@ -1788,7 +1798,7 @@ void MenuStateCustomGame::keyPress(char c) {
|
|||
}
|
||||
|
||||
void MenuStateCustomGame::keyUp(char key) {
|
||||
if(activeInputLabel!=NULL) {
|
||||
if(activeInputLabel==NULL) {
|
||||
chatManager.keyUp(key);
|
||||
if(chatManager.getEditEnabled()){
|
||||
//send key to the chat manager
|
||||
|
@ -1840,16 +1850,29 @@ void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable)
|
|||
activeInputLabel=newLable;
|
||||
}
|
||||
|
||||
string MenuStateCustomGame::getHumanPlayerName() {
|
||||
string MenuStateCustomGame::getHumanPlayerName(int index) {
|
||||
string result = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
for(int j=0; j<GameConstants::maxPlayers; ++j) {
|
||||
ControlType ct= static_cast<ControlType>(listBoxControls[j].getSelectedItemIndex());
|
||||
if(ct == ctHuman && labelPlayerNames[j].getText() != "") {
|
||||
result = labelPlayerNames[j].getText();
|
||||
break;
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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() != "") {
|
||||
result = labelPlayerNames[index].getText();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ private:
|
|||
void saveGameSettingsToFile(std::string fileName);
|
||||
GameSettings loadGameSettingsFromFile(std::string fileName);
|
||||
void setActiveInputLabel(GraphicLabel *newLable);
|
||||
string getHumanPlayerName();
|
||||
string getHumanPlayerName(int index=-1);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -63,7 +63,7 @@ ClientInterface::~ClientInterface()
|
|||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!";
|
||||
string sQuitText = "has chosen to leave the game!";
|
||||
sendTextMessage(sQuitText,-1);
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ void ClientInterface::reset()
|
|||
{
|
||||
if(getSocket() != NULL)
|
||||
{
|
||||
string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!";
|
||||
string sQuitText = "has chosen to leave the game!";
|
||||
sendTextMessage(sQuitText,-1);
|
||||
close();
|
||||
}
|
||||
|
@ -135,14 +135,11 @@ void ClientInterface::update()
|
|||
char szBuf[1024]="";
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,requestedCommands.size());
|
||||
|
||||
string sMsg = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " may go out of synch: client requestedCommands.size() = " + intToStr(requestedCommands.size());
|
||||
string sMsg = "may go out of synch: client requestedCommands.size() = " + intToStr(requestedCommands.size());
|
||||
sendTextMessage(sMsg,-1, true);
|
||||
}
|
||||
|
||||
//clear chat variables
|
||||
//chatText.clear();
|
||||
//chatSender.clear();
|
||||
//chatTeamIndex= -1;
|
||||
clearChatInfo();
|
||||
}
|
||||
|
||||
|
@ -153,9 +150,6 @@ std::string ClientInterface::getServerIpAddress() {
|
|||
void ClientInterface::updateLobby()
|
||||
{
|
||||
//clear chat variables
|
||||
//chatText.clear();
|
||||
//chatSender.clear();
|
||||
//chatTeamIndex= -1;
|
||||
clearChatInfo();
|
||||
|
||||
NetworkMessageType networkMessageType = getNextMessageType(true);
|
||||
|
@ -171,6 +165,8 @@ void ClientInterface::updateLobby()
|
|||
if(receiveMessage(&networkMessageIntro)) {
|
||||
gotIntro = true;
|
||||
versionString = networkMessageIntro.getVersionString();
|
||||
playerIndex= networkMessageIntro.getPlayerIndex();
|
||||
serverName= networkMessageIntro.getName();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got NetworkMessageIntro, networkMessageIntro.getGameState() = %d, versionString [%s]\n",__FILE__,__FUNCTION__,__LINE__,networkMessageIntro.getGameState(),versionString.c_str());
|
||||
|
||||
|
@ -183,7 +179,7 @@ void ClientInterface::updateLobby()
|
|||
string sErr = "";
|
||||
|
||||
if(strncmp(platformFreeVersion.c_str(),networkMessageIntro.getVersionString().c_str(),strlen(platformFreeVersion.c_str())) != 0) {
|
||||
string playerNameStr = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
string playerNameStr = getHumanPlayerName();
|
||||
sErr = "Server and client binary mismatch!\nYou have to use the exactly same binaries!\n\nServer: " + networkMessageIntro.getVersionString() +
|
||||
"\nClient: " + getNetworkVersionString() + " player [" + playerNameStr + "]";
|
||||
printf("%s\n",sErr.c_str());
|
||||
|
@ -196,7 +192,7 @@ void ClientInterface::updateLobby()
|
|||
else {
|
||||
versionMatched = true;
|
||||
|
||||
string playerNameStr = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
string playerNameStr = getHumanPlayerName();
|
||||
sErr = "Warning, Server and client are using the same version but different platforms.\n\nServer: " + networkMessageIntro.getVersionString() +
|
||||
"\nClient: " + getNetworkVersionString() + " player [" + playerNameStr + "]";
|
||||
printf("%s\n",sErr.c_str());
|
||||
|
@ -222,10 +218,7 @@ void ClientInterface::updateLobby()
|
|||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//send intro message
|
||||
NetworkMessageIntro sendNetworkMessageIntro(getNetworkVersionString(), Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()), -1, nmgstOk);
|
||||
|
||||
playerIndex= networkMessageIntro.getPlayerIndex();
|
||||
serverName= networkMessageIntro.getName();
|
||||
NetworkMessageIntro sendNetworkMessageIntro(getNetworkVersionString(), getHumanPlayerName(), -1, nmgstOk);
|
||||
sendMessage(&sendNetworkMessageIntro);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
@ -547,7 +540,7 @@ void ClientInterface::updateKeyframe(int frameCount)
|
|||
chrono.start();
|
||||
//check that we are in the right frame
|
||||
if(networkMessageCommandList.getFrameCount() != frameCount) {
|
||||
string sErr = "Player: " + Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) +
|
||||
string sErr = "Player: " + getHumanPlayerName() +
|
||||
" got a Network synchronization error, frame counts do not match, server frameCount = " +
|
||||
intToStr(networkMessageCommandList.getFrameCount()) + ", local frameCount = " +
|
||||
intToStr(frameCount);
|
||||
|
@ -742,7 +735,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
|||
string sErr = "Checksum error, you don't have the same data as the server";
|
||||
sendTextMessage(sErr,-1, true);
|
||||
|
||||
string playerNameStr = "Player with error is [" + Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + "]";
|
||||
string playerNameStr = "Player with error is [" + getHumanPlayerName() + "]";
|
||||
sendTextMessage(playerNameStr,-1, true);
|
||||
|
||||
string sErr1 = "Client Checksum: " + intToStr(checksum->getSum());
|
||||
|
@ -779,7 +772,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
|||
}
|
||||
|
||||
void ClientInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal){
|
||||
NetworkMessageText networkMessageText(text, getHostName(), teamIndex);
|
||||
NetworkMessageText networkMessageText(text, getHumanPlayerName(), teamIndex);
|
||||
sendMessage(&networkMessageText);
|
||||
|
||||
if(echoLocal == true) {
|
||||
|
@ -862,7 +855,7 @@ void ClientInterface::quitGame(bool userManuallyQuit)
|
|||
if(clientSocket != NULL && userManuallyQuit == true)
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
string sQuitText = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " has chosen to leave the game!";
|
||||
string sQuitText = "has chosen to leave the game!";
|
||||
sendTextMessage(sQuitText,-1);
|
||||
close();
|
||||
}
|
||||
|
@ -898,11 +891,11 @@ 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)
|
||||
void ClientInterface::sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam, string networkPlayerName)
|
||||
{
|
||||
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);
|
||||
SwitchSetupRequest message=SwitchSetupRequest(selectedFactionName, currentFactionIndex, toFactionIndex,toTeam,networkPlayerName);
|
||||
sendMessage(&message);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
@ -999,4 +992,19 @@ bool ClientInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess
|
|||
return discard;
|
||||
}
|
||||
|
||||
string ClientInterface::getHumanPlayerName(int index) {
|
||||
string result = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
|
||||
if(index >= 0 || playerIndex >= 0) {
|
||||
if(index < 0) {
|
||||
index = playerIndex;
|
||||
}
|
||||
if(gameSettings.getNetworkPlayerName(index) != "") {
|
||||
result = gameSettings.getNetworkPlayerName(index);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
void discoverServers(DiscoveredServersInterface *cb);
|
||||
void stopServerDiscovery();
|
||||
|
||||
void sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex, int8 toTeam);
|
||||
void sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex, int8 toTeam,string networkPlayerName);
|
||||
virtual bool getConnectHasHandshaked() const { return gotIntro; }
|
||||
std::string getServerIpAddress();
|
||||
|
||||
|
@ -100,6 +100,7 @@ public:
|
|||
virtual void sendPingMessage(int32 pingFrequency, int64 pingTime);
|
||||
|
||||
const string &getVersionString() const {return versionString;}
|
||||
virtual string getHumanPlayerName(int index=-1);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -241,7 +241,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] no open slots, disconnecting client\n",__FILE__,__FUNCTION__);
|
||||
|
||||
if(socket != NULL) {
|
||||
NetworkMessageIntro networkMessageIntro(getNetworkVersionString(), socket->getHostName(), playerIndex, nmgstNoSlots);
|
||||
NetworkMessageIntro networkMessageIntro(getNetworkVersionString(), getHostName(), playerIndex, nmgstNoSlots);
|
||||
sendMessage(&networkMessageIntro);
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||
string sErr = "";
|
||||
|
||||
if(strncmp(platformFreeVersion.c_str(),networkMessageIntro.getVersionString().c_str(),strlen(platformFreeVersion.c_str())) != 0) {
|
||||
string playerNameStr = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
string playerNameStr = name;
|
||||
sErr = "Server and client binary mismatch!\nYou have to use the exactly same binaries!\n\nServer: " + getNetworkVersionString() +
|
||||
"\nClient: " + networkMessageIntro.getVersionString() + " player [" + playerNameStr + "]";
|
||||
printf("%s\n",sErr.c_str());
|
||||
|
@ -370,7 +370,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||
else {
|
||||
versionMatched = true;
|
||||
|
||||
string playerNameStr = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
string playerNameStr = name;
|
||||
sErr = "Warning, Server and client are using the same version but different platforms.\n\nServer: " + getNetworkVersionString() +
|
||||
"\nClient: " + networkMessageIntro.getVersionString() + " player [" + playerNameStr + "]";
|
||||
printf("%s\n",sErr.c_str());
|
||||
|
@ -667,4 +667,8 @@ void ConnectionSlot::sendMessage(const NetworkMessage* networkMessage) {
|
|||
safeMutex.ReleaseLock();
|
||||
}
|
||||
|
||||
string ConnectionSlot::getHumanPlayerName(int index) {
|
||||
return serverInterface->getHumanPlayerName(index);
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -122,6 +122,7 @@ public:
|
|||
|
||||
void setReady() {ready= true;}
|
||||
const string &getName() const {return name;}
|
||||
void setName(string value) {name = value;}
|
||||
bool isReady() const {return ready;}
|
||||
|
||||
virtual Socket* getSocket() {return socket;}
|
||||
|
@ -158,6 +159,7 @@ public:
|
|||
const string &getVersionString() const {return versionString;}
|
||||
|
||||
void validateConnection();
|
||||
virtual string getHumanPlayerName(int index=-1);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ public:
|
|||
virtual Socket* getSocket()= 0;
|
||||
virtual const Socket* getSocket() const= 0;
|
||||
virtual void close()= 0;
|
||||
virtual string getHumanPlayerName(int index=-1) = 0;
|
||||
|
||||
static void setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage) { pCB_DisplayMessage = pDisplayMessage; }
|
||||
static DisplayMessageFunction getDisplayMessageFunction() { return pCB_DisplayMessage; }
|
||||
|
@ -145,7 +146,6 @@ public:
|
|||
|
||||
std::string getIpAddress();
|
||||
float getThreadedPingMS(std::string host);
|
||||
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
|
|
@ -589,22 +589,25 @@ SwitchSetupRequest::SwitchSetupRequest()
|
|||
data.currentFactionIndex=-1;
|
||||
data.toFactionIndex=-1;
|
||||
data.toTeam = -1;
|
||||
data.networkPlayerName="";
|
||||
}
|
||||
|
||||
|
||||
SwitchSetupRequest::SwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam)
|
||||
SwitchSetupRequest::SwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam,string networkPlayerName)
|
||||
{
|
||||
data.messageType= nmtSwitchSetupRequest;
|
||||
data.selectedFactionName=selectedFactionName;
|
||||
data.currentFactionIndex=currentFactionIndex;
|
||||
data.toFactionIndex=toFactionIndex;
|
||||
data.toTeam = toTeam;
|
||||
data.networkPlayerName=networkPlayerName;
|
||||
}
|
||||
|
||||
bool SwitchSetupRequest::receive(Socket* socket) {
|
||||
bool result = NetworkMessage::receive(socket, &data, sizeof(data));
|
||||
|
||||
data.selectedFactionName.nullTerminate();
|
||||
data.networkPlayerName.nullTerminate();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -508,6 +508,7 @@ private:
|
|||
int8 currentFactionIndex;
|
||||
int8 toFactionIndex;
|
||||
int8 toTeam;
|
||||
NetworkString<maxStringSize> networkPlayerName;
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -515,12 +516,13 @@ private:
|
|||
|
||||
public:
|
||||
SwitchSetupRequest();
|
||||
SwitchSetupRequest( string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam);
|
||||
SwitchSetupRequest( string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam,string networkPlayerName);
|
||||
|
||||
string getSelectedFactionName() const {return data.selectedFactionName.getString();}
|
||||
int getCurrentFactionIndex() const {return data.currentFactionIndex;}
|
||||
int getToFactionIndex() const {return data.toFactionIndex;}
|
||||
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(); }
|
||||
|
||||
virtual bool receive(Socket* socket);
|
||||
virtual void send(Socket* socket) const;
|
||||
|
|
|
@ -723,7 +723,7 @@ void ServerInterface::updateKeyframe(int frameCount){
|
|||
char szBuf[1024]="";
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,requestedCommands.size());
|
||||
|
||||
string sMsg = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()) + " may go out of synch: server requestedCommands.size() = " + intToStr(requestedCommands.size());
|
||||
string sMsg = "may go out of synch: server requestedCommands.size() = " + intToStr(requestedCommands.size());
|
||||
sendTextMessage(sMsg,-1, true);
|
||||
}
|
||||
|
||||
|
@ -928,7 +928,7 @@ void ServerInterface::waitUntilReady(Checksum* checksum){
|
|||
void ServerInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d\n",__FILE__,__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal);
|
||||
|
||||
NetworkMessageText networkMessageText(text, Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()), teamIndex);
|
||||
NetworkMessageText networkMessageText(text, getHumanPlayerName().c_str(), teamIndex);
|
||||
broadcastMessage(&networkMessageText);
|
||||
|
||||
if(echoLocal == true) {
|
||||
|
@ -1225,6 +1225,8 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
|||
|
||||
MutexSafeWrapper safeMutex(&serverSynchAccessor);
|
||||
|
||||
gameSettings = *serverGameSettings;
|
||||
|
||||
if(getAllowGameDataSynchCheck() == true)
|
||||
{
|
||||
if(waitForClientAck == true && gameSettingsUpdateCount > 0)
|
||||
|
@ -1261,8 +1263,6 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
|||
}
|
||||
}
|
||||
|
||||
gameSettings = *serverGameSettings;
|
||||
|
||||
NetworkMessageSynchNetworkGameData networkMessageSynchNetworkGameData(getGameSettings());
|
||||
broadcastMessageToConnectedClients(&networkMessageSynchNetworkGameData);
|
||||
|
||||
|
@ -1304,4 +1304,25 @@ void ServerInterface::close()
|
|||
//serverSocket = ServerSocket();
|
||||
}
|
||||
|
||||
string ServerInterface::getHumanPlayerName(int index) {
|
||||
string result = Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
|
||||
//printf("\nIn [%s::%s Line: %d] index = %d, gameSettings.getThisFactionIndex() = %d\n",__FILE__,__FUNCTION__,__LINE__,index,gameSettings.getThisFactionIndex());
|
||||
//fflush(stdout);
|
||||
|
||||
if(index >= 0 || gameSettings.getThisFactionIndex() >= 0) {
|
||||
if(index < 0) {
|
||||
index = gameSettings.getThisFactionIndex();
|
||||
}
|
||||
|
||||
//printf("\nIn [%s::%s Line: %d] gameSettings.getNetworkPlayerName(index) = %s\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getNetworkPlayerName(index).c_str());
|
||||
//fflush(stdout);
|
||||
|
||||
if(gameSettings.getNetworkPlayerName(index) != "") {
|
||||
result = gameSettings.getNetworkPlayerName(index);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -95,6 +95,8 @@ public:
|
|||
this->broadcastMessage(networkMessage,excludeSlot);
|
||||
}
|
||||
|
||||
virtual string getHumanPlayerName(int index=-1);
|
||||
|
||||
public:
|
||||
|
||||
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }
|
||||
|
|
Loading…
Reference in New Issue