- added the ability for admin player to disconnect other network players in game from a new popup menu

This commit is contained in:
Mark Vejvoda 2012-09-21 05:45:09 +00:00
parent 684c35e25a
commit b7f72be930
5 changed files with 206 additions and 2 deletions

View File

@ -469,6 +469,11 @@ void Commander::trySwitchTeamVote(const Faction* faction, SwitchTeamVote *vote)
pushNetworkCommand(&command);
}
void Commander::tryDisconnectNetworkPlayer(const Faction* faction, int playerIndex) const {
NetworkCommand command(this->world,nctDisconnectNetworkPlayer, faction->getIndex(), playerIndex);
pushNetworkCommand(&command);
}
void Commander::tryPauseGame() const {
NetworkCommand command(this->world,nctPauseResume, 1);
pushNetworkCommand(&command);
@ -511,7 +516,8 @@ CommandResult Commander::pushNetworkCommand(const NetworkCommand* networkCommand
if( networkCommand->getNetworkCommandType() != nctSwitchTeam &&
networkCommand->getNetworkCommandType() != nctSwitchTeamVote &&
networkCommand->getNetworkCommandType() != nctPauseResume &&
networkCommand->getNetworkCommandType() != nctPlayerStatusChange) {
networkCommand->getNetworkCommandType() != nctPlayerStatusChange &&
networkCommand->getNetworkCommandType() != nctDisconnectNetworkPlayer) {
unit= world->findUnitById(networkCommand->getUnitId());
if(unit == NULL) {
char szBuf[1024]="";
@ -809,6 +815,48 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
}
break;
case nctDisconnectNetworkPlayer: {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctDisconnectNetworkPlayer\n",__FILE__,__FUNCTION__,__LINE__);
commandWasHandled = true;
NetworkManager &networkManager= NetworkManager::getInstance();
NetworkRole role = networkManager.getNetworkRole();
GameSettings *settings = world->getGameSettingsPtr();
if(role == nrServer) {
int factionIndex = networkCommand->getUnitId();
int playerIndex = networkCommand->getCommandTypeId();
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
if(gameNetworkInterface != NULL) {
//
// Lang &lang= Lang::getInstance();
// const vector<string> languageList = settings->getUniqueNetworkPlayerLanguages();
// for(unsigned int i = 0; i < languageList.size(); ++i) {
// char szMsg[1024]="";
// if(lang.hasString("DisconnectNetorkPlayerIndexConfirmed",languageList[i]) == true) {
// sprintf(szMsg,lang.get("DisconnectNetorkPlayerIndexConfirmed",languageList[i]).c_str(),playerIndex,settings->getNetworkPlayerName(factionIndex).c_str());
// }
// else {
// sprintf(szMsg,"Notice - Admin is disconnecting player #%d - %s",playerIndex,settings->getNetworkPlayerName(factionIndex).c_str());
// }
// bool localEcho = lang.isLanguageLocal(languageList[i]);
// gameNetworkInterface->sendTextMessage(szMsg,-1, localEcho,languageList[i]);
// }
//
// sleep(10);
ServerInterface *server = networkManager.getServerInterface();
if(server->isClientConnected(playerIndex) == true) {
ConnectionSlot *slot = server->getSlot(playerIndex);
slot->close();
}
}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctDisconnectNetworkPlayer\n",__FILE__,__FUNCTION__,__LINE__);
}
break;
case nctPauseResume:
{
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctPauseResume\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -111,6 +111,7 @@ public:
void trySetMeetingPoint(const Unit* unit, const Vec2i &pos) const;
void trySwitchTeam(const Faction* faction, int teamIndex) const;
void trySwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) const;
void tryDisconnectNetworkPlayer(const Faction* faction, int playerIndex) const;
void tryPauseGame() const;
void tryResumeGame() const;
void tryNetworkPlayerDisconnected(int factionIndex) const;

View File

@ -48,6 +48,8 @@ const float PHOTO_MODE_MAXHEIGHT = 500.0;
const int CREATE_NEW_TEAM = -100;
const int CANCEL_SWITCH_TEAM = -1;
const int CANCEL_DISCONNECT_PLAYER = -1;
const float Game::highlightTime= 0.5f;
int fadeMusicMilliseconds = 3500;
@ -110,7 +112,14 @@ Game::Game() : ProgramState(NULL) {
popupMenuSwitchTeams.setEnabled(false);
popupMenuSwitchTeams.setVisible(false);
popupMenuDisconnectPlayer.setEnabled(false);
popupMenuDisconnectPlayer.setVisible(false);
switchTeamConfirmMessageBox.setEnabled(false);
disconnectPlayerConfirmMessageBox.setEnabled(false);
disconnectPlayerIndexMap.clear();
exitGamePopupMenuIndex = -1;
joinTeamPopupMenuIndex = -1;
pauseGamePopupMenuIndex = -1;
@ -119,6 +128,7 @@ Game::Game() : ProgramState(NULL) {
markCellPopupMenuIndex = -1;
unmarkCellPopupMenuIndex = -1;
keyboardSetupPopupMenuIndex = -1;
disconnectPlayerPopupMenuIndex = -1;
isMarkCellEnabled = false;
isMarkCellTextEnabled = false;
@ -167,7 +177,14 @@ void Game::resetMembers() {
popupMenuSwitchTeams.setEnabled(false);
popupMenuSwitchTeams.setVisible(false);
popupMenuDisconnectPlayer.setEnabled(false);
popupMenuDisconnectPlayer.setVisible(false);
switchTeamConfirmMessageBox.setEnabled(false);
disconnectPlayerConfirmMessageBox.setEnabled(false);
disconnectPlayerIndexMap.clear();
exitGamePopupMenuIndex = -1;
joinTeamPopupMenuIndex = -1;
pauseGamePopupMenuIndex = -1;
@ -176,6 +193,7 @@ void Game::resetMembers() {
markCellPopupMenuIndex = -1;
unmarkCellPopupMenuIndex = -1;
keyboardSetupPopupMenuIndex = -1;
disconnectPlayerPopupMenuIndex = -1;
isMarkCellEnabled = false;
isMarkCellTextEnabled = false;
@ -1300,9 +1318,15 @@ void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
// menuItems.push_back(lang.get("LoadGame"));
// loadGamePopupMenuIndex= menuItems.size() - 1;
}
if(gameSettings.isNetworkGame() == true){
menuItems.push_back(lang.get("DisconnectNetorkPlayer"));
disconnectPlayerPopupMenuIndex= menuItems.size() - 1;
}
}
menuItems.push_back(lang.get("Keyboardsetup"));
keyboardSetupPopupMenuIndex = menuItems.size()-1;
menuItems.push_back(lang.get("Cancel"));
popupMenu.setW(100);
@ -1313,6 +1337,9 @@ void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
popupMenuSwitchTeams.setEnabled(false);
popupMenuSwitchTeams.setVisible(false);
popupMenuDisconnectPlayer.setEnabled(false);
popupMenuDisconnectPlayer.setVisible(false);
}
}
@ -2199,6 +2226,42 @@ void Game::mouseDownLeft(int x, int y) {
popupMenuSwitchTeams.setEnabled(true);
popupMenuSwitchTeams.setVisible(true);
}
else if(result.first == disconnectPlayerPopupMenuIndex) {
Lang &lang= Lang::getInstance();
disconnectPlayerIndexMap.clear();
std::vector<string> menuItems;
for(unsigned int i = 0; i < world.getFactionCount(); ++i) {
Faction *faction = world.getFaction(i);
//printf("faction->getPersonalityType() = %d index [%d,%d] control [%d]\n",faction->getPersonalityType(),world.getThisFaction()->getIndex(),faction->getIndex(),faction->getControlType());
if(faction->getPersonalityType() != fpt_Observer &&
world.getThisFaction()->getIndex() != faction->getIndex() &&
faction->getControlType() == ctNetwork) {
char szBuf[1024]="";
if(lang.hasString("DisconnectNetorkPlayerIndex") == true) {
sprintf(szBuf,lang.get("DisconnectNetorkPlayerIndex").c_str(),faction->getIndex()+1,this->gameSettings.getNetworkPlayerName(i).c_str());
}
else {
sprintf(szBuf,"Disconnect player #%d - %s:",faction->getIndex()+1,this->gameSettings.getNetworkPlayerName(i).c_str());
}
menuItems.push_back(szBuf);
disconnectPlayerIndexMap[menuItems.size()-1] = faction->getStartLocationIndex();
}
}
menuItems.push_back(lang.get("Cancel"));
disconnectPlayerIndexMap[menuItems.size()-1] = CANCEL_DISCONNECT_PLAYER;
popupMenuDisconnectPlayer.setW(100);
popupMenuDisconnectPlayer.setH(100);
popupMenuDisconnectPlayer.init(lang.get("DisconnectNetorkPlayer"),menuItems);
popupMenuDisconnectPlayer.setEnabled(true);
popupMenuDisconnectPlayer.setVisible(true);
}
else if(result.first == keyboardSetupPopupMenuIndex) {
MainMenu *newMenu = new MainMenu(program); // open keyboard shortcuts setup screen
currentUIState = newMenu;
@ -2302,6 +2365,70 @@ void Game::mouseDownLeft(int x, int y) {
break;
}
}
else if(popupMenuDisconnectPlayer.mouseClick(x, y)) {
//popupMenuSwitchTeams
std::pair<int,string> result = popupMenuDisconnectPlayer.mouseClickedMenuItem(x, y);
//printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first);
popupMenuDisconnectPlayer.setEnabled(false);
popupMenuDisconnectPlayer.setVisible(false);
//bool isNetworkGame = this->gameSettings.isNetworkGame();
int playerIndex = disconnectPlayerIndexMap[result.first];
switch(playerIndex) {
case CANCEL_DISCONNECT_PLAYER:
break;
default:
// if(isNetworkGame == true) {
// const Faction *faction = world.getThisFaction();
// commander.trySwitchTeam(faction,teamIndex);
// }
// else {
// const Faction *faction = world.getThisFaction();
// commander.trySwitchTeam(faction,teamIndex);
// }
GameSettings *settings = world.getGameSettingsPtr();
Lang &lang= Lang::getInstance();
char szBuf[1024]="";
if(lang.hasString("DisconnectNetorkPlayerIndexConfirm") == true) {
sprintf(szBuf,lang.get("DisconnectNetorkPlayerIndexConfirm").c_str(),playerIndex,settings->getNetworkPlayerName(playerIndex).c_str());
}
else {
sprintf(szBuf,"Confirm disconnection for player #%d - %s?",playerIndex,settings->getNetworkPlayerName(playerIndex).c_str());
}
disconnectPlayerConfirmMessageBox.setText(szBuf);
disconnectPlayerConfirmMessageBox.init(lang.get("Yes"), lang.get("No"));
disconnectPlayerConfirmMessageBox.setEnabled(true);
playerIndexDisconnect = playerIndex;
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
if(gameNetworkInterface != NULL) {
Lang &lang= Lang::getInstance();
const vector<string> languageList = settings->getUniqueNetworkPlayerLanguages();
for(unsigned int i = 0; i < languageList.size(); ++i) {
char szMsg[1024]="";
if(lang.hasString("DisconnectNetorkPlayerIndexConfirmed",languageList[i]) == true) {
sprintf(szMsg,lang.get("DisconnectNetorkPlayerIndexConfirmed",languageList[i]).c_str(),playerIndex,settings->getNetworkPlayerName(playerIndex).c_str());
}
else {
sprintf(szMsg,"Notice - Admin is warning to disconnect player #%d - %s!",playerIndex+1,settings->getNetworkPlayerName(playerIndex).c_str());
}
bool localEcho = lang.isLanguageLocal(languageList[i]);
gameNetworkInterface->sendTextMessage(szMsg,-1, localEcho,languageList[i]);
}
sleep(10);
}
break;
}
}
if(switchTeamConfirmMessageBox.getEnabled() == true) {
int button= -1;
@ -2316,6 +2443,17 @@ void Game::mouseDownLeft(int x, int y) {
commander.trySwitchTeamVote(faction,vote);
}
}
else if(disconnectPlayerConfirmMessageBox.getEnabled() == true) {
int button= -1;
if(disconnectPlayerConfirmMessageBox.mouseClick(x,y,button)) {
disconnectPlayerConfirmMessageBox.setEnabled(false);
if(button == 0) {
const Faction *faction = world.getThisFaction();
commander.tryDisconnectNetworkPlayer(faction,playerIndexDisconnect);
}
}
}
//scrip message box, only if the exit box is not enabled
if( mainMessageBox.getEnabled() == false &&
@ -2717,6 +2855,7 @@ void Game::mouseMove(int x, int y, const MouseState *ms) {
popupMenu.mouseMove(x, y);
popupMenuSwitchTeams.mouseMove(x, y);
popupMenuDisconnectPlayer.mouseMove(x, y);
const Metrics &metrics = Metrics::getInstance();
@ -2802,6 +2941,10 @@ void Game::mouseMove(int x, int y, const MouseState *ms) {
switchTeamConfirmMessageBox.mouseMove(x,y);
}
if(disconnectPlayerConfirmMessageBox.getEnabled() == true) {
disconnectPlayerConfirmMessageBox.mouseMove(x,y);
}
if (mainMessageBox.getEnabled()) {
mainMessageBox.mouseMove(x, y);
}
@ -3665,6 +3808,10 @@ void Game::render2d() {
renderer.renderMessageBox(&switchTeamConfirmMessageBox);
}
if(disconnectPlayerConfirmMessageBox.getEnabled() == true) {
renderer.renderMessageBox(&disconnectPlayerConfirmMessageBox);
}
//exit message box
if(errorMessageBox.getEnabled()) {
renderer.renderMessageBox(&errorMessageBox);
@ -3700,6 +3847,7 @@ void Game::render2d() {
renderer.renderPopupMenu(&popupMenu);
renderer.renderPopupMenu(&popupMenuSwitchTeams);
renderer.renderPopupMenu(&popupMenuDisconnectPlayer);
if(program != NULL) program->renderProgramMsgBox();

View File

@ -141,10 +141,15 @@ private:
PopupMenu popupMenu;
PopupMenu popupMenuSwitchTeams;
PopupMenu popupMenuDisconnectPlayer;
std::map<int,int> switchTeamIndexMap;
GraphicMessageBox switchTeamConfirmMessageBox;
std::map<int,int> disconnectPlayerIndexMap;
int playerIndexDisconnect;
GraphicMessageBox disconnectPlayerConfirmMessageBox;
int exitGamePopupMenuIndex;
int joinTeamPopupMenuIndex;
int pauseGamePopupMenuIndex;
@ -153,6 +158,7 @@ private:
int markCellPopupMenuIndex;
int unmarkCellPopupMenuIndex;
int keyboardSetupPopupMenuIndex;
int disconnectPlayerPopupMenuIndex;
//GLuint statelist3dMenu;
ProgramState *currentUIState;

View File

@ -75,7 +75,8 @@ enum NetworkCommandType {
nctSwitchTeam,
nctSwitchTeamVote,
nctPauseResume,
nctPlayerStatusChange
nctPlayerStatusChange,
nctDisconnectNetworkPlayer
//nctNetworkCommand
};