- inspired by brazil boy. added a temp block feature for server player to temp block players from the current game in the lobby
This commit is contained in:
parent
7bf40db4ce
commit
1858240879
|
@ -128,6 +128,9 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
||||||
buttonReturn.registerGraphicComponent(containerName,"buttonReturn");
|
buttonReturn.registerGraphicComponent(containerName,"buttonReturn");
|
||||||
buttonReturn.init(250, 180, 125);
|
buttonReturn.init(250, 180, 125);
|
||||||
|
|
||||||
|
buttonClearBlockedPlayers.registerGraphicComponent(containerName,"buttonClearBlockedPlayers");
|
||||||
|
buttonClearBlockedPlayers.init(427, 590, 125);
|
||||||
|
|
||||||
buttonRestoreLastSettings.registerGraphicComponent(containerName,"buttonRestoreLastSettings");
|
buttonRestoreLastSettings.registerGraphicComponent(containerName,"buttonRestoreLastSettings");
|
||||||
buttonRestoreLastSettings.init(250+130, 180, 200);
|
buttonRestoreLastSettings.init(250+130, 180, 200);
|
||||||
|
|
||||||
|
@ -366,7 +369,6 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
||||||
listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("Yes"));
|
listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("Yes"));
|
||||||
listBoxNetworkPauseGameForLaggedClients.setSelectedItem(lang.get("Yes"));
|
listBoxNetworkPauseGameForLaggedClients.setSelectedItem(lang.get("Yes"));
|
||||||
|
|
||||||
|
|
||||||
// Enable Server Controlled AI
|
// Enable Server Controlled AI
|
||||||
//labelEnableServerControlledAI.registerGraphicComponent(containerName,"labelEnableServerControlledAI");
|
//labelEnableServerControlledAI.registerGraphicComponent(containerName,"labelEnableServerControlledAI");
|
||||||
//labelEnableServerControlledAI.init(xoffset+550, networkHeadPos, 80);
|
//labelEnableServerControlledAI.init(xoffset+550, networkHeadPos, 80);
|
||||||
|
@ -395,6 +397,10 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
||||||
listBoxControls[i].registerGraphicComponent(containerName,"listBoxControls" + intToStr(i));
|
listBoxControls[i].registerGraphicComponent(containerName,"listBoxControls" + intToStr(i));
|
||||||
listBoxControls[i].init(xoffset+210, setupPos-30-i*rowHeight);
|
listBoxControls[i].init(xoffset+210, setupPos-30-i*rowHeight);
|
||||||
|
|
||||||
|
buttonBlockPlayers[i].registerGraphicComponent(containerName,"buttonBlockPlayers" + intToStr(i));
|
||||||
|
buttonBlockPlayers[i].init(xoffset+355, setupPos-30-i*rowHeight, 70);
|
||||||
|
buttonBlockPlayers[i].setText(lang.get("BlockPlayer"));
|
||||||
|
|
||||||
listBoxRMultiplier[i].registerGraphicComponent(containerName,"listBoxRMultiplier" + intToStr(i));
|
listBoxRMultiplier[i].registerGraphicComponent(containerName,"listBoxRMultiplier" + intToStr(i));
|
||||||
listBoxRMultiplier[i].init(xoffset+350, setupPos-30-i*rowHeight,70);
|
listBoxRMultiplier[i].init(xoffset+350, setupPos-30-i*rowHeight,70);
|
||||||
|
|
||||||
|
@ -430,6 +436,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
||||||
labelTeam.setFont(CoreData::getInstance().getMenuFontBig());
|
labelTeam.setFont(CoreData::getInstance().getMenuFontBig());
|
||||||
|
|
||||||
//texts
|
//texts
|
||||||
|
buttonClearBlockedPlayers.setText(lang.get("BlockPlayerClear"));
|
||||||
buttonReturn.setText(lang.get("Return"));
|
buttonReturn.setText(lang.get("Return"));
|
||||||
buttonPlayNow.setText(lang.get("PlayNow"));
|
buttonPlayNow.setText(lang.get("PlayNow"));
|
||||||
buttonRestoreLastSettings.setText(lang.get("ReloadLastGameSettings"));
|
buttonRestoreLastSettings.setText(lang.get("ReloadLastGameSettings"));
|
||||||
|
@ -898,6 +905,44 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
}
|
}
|
||||||
updateResourceMultiplier(i);
|
updateResourceMultiplier(i);
|
||||||
}
|
}
|
||||||
|
else if(buttonClearBlockedPlayers.mouseClick(x, y)) {
|
||||||
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
|
if(serverInterface != NULL) {
|
||||||
|
ServerSocket *serverSocket = serverInterface->getServerSocket();
|
||||||
|
if(serverSocket != NULL) {
|
||||||
|
serverSocket->clearBlockedIPAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(buttonBlockPlayers[i].mouseClick(x, y)) {
|
||||||
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
|
if(serverInterface != NULL) {
|
||||||
|
if(serverInterface->getSlot(i) != NULL &&
|
||||||
|
serverInterface->getSlot(i)->isConnected()) {
|
||||||
|
|
||||||
|
ServerSocket *serverSocket = serverInterface->getServerSocket();
|
||||||
|
if(serverSocket != NULL) {
|
||||||
|
serverSocket->addIPAddressToBlockedList(serverInterface->getSlot(i)->getIpAddress());
|
||||||
|
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
|
const vector<string> languageList = serverInterface->getGameSettings()->getUniqueNetworkPlayerLanguages();
|
||||||
|
for(unsigned int j = 0; j < languageList.size(); ++j) {
|
||||||
|
char szMsg[1024]="";
|
||||||
|
if(lang.hasString("BlockPlayerServerMsg",languageList[j]) == true) {
|
||||||
|
sprintf(szMsg,lang.get("BlockPlayerServerMsg",languageList[j]).c_str(),serverInterface->getSlot(i)->getIpAddress().c_str());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sprintf(szMsg,"The server has temporarily blocked IP Address [%s] from this game.",serverInterface->getSlot(i)->getIpAddress().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
serverInterface->sendTextMessage(szMsg,-1, true,languageList[j]);
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
serverInterface->getSlot(i)->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else if(listBoxFactions[i].mouseClick(x, y)) {
|
else if(listBoxFactions[i].mouseClick(x, y)) {
|
||||||
// Disallow CPU players to be observers
|
// Disallow CPU players to be observers
|
||||||
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] == formatString(GameConstants::OBSERVER_SLOTNAME) &&
|
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] == formatString(GameConstants::OBSERVER_SLOTNAME) &&
|
||||||
|
@ -1211,11 +1256,13 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms){
|
||||||
buttonReturn.mouseMove(x, y);
|
buttonReturn.mouseMove(x, y);
|
||||||
buttonPlayNow.mouseMove(x, y);
|
buttonPlayNow.mouseMove(x, y);
|
||||||
buttonRestoreLastSettings.mouseMove(x, y);
|
buttonRestoreLastSettings.mouseMove(x, y);
|
||||||
|
buttonClearBlockedPlayers.mouseMove(x, y);
|
||||||
|
|
||||||
bool editingPlayerName = false;
|
bool editingPlayerName = false;
|
||||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||||
listBoxRMultiplier[i].mouseMove(x, y);
|
listBoxRMultiplier[i].mouseMove(x, y);
|
||||||
listBoxControls[i].mouseMove(x, y);
|
listBoxControls[i].mouseMove(x, y);
|
||||||
|
buttonBlockPlayers[i].mouseMove(x, y);
|
||||||
listBoxFactions[i].mouseMove(x, y);
|
listBoxFactions[i].mouseMove(x, y);
|
||||||
listBoxTeams[i].mouseMove(x, y);
|
listBoxTeams[i].mouseMove(x, y);
|
||||||
|
|
||||||
|
@ -1296,10 +1343,25 @@ void MenuStateCustomGame::render() {
|
||||||
renderer.renderListBox(&listBoxPlayerStatus);
|
renderer.renderListBox(&listBoxPlayerStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
|
if( serverInterface != NULL &&
|
||||||
|
serverInterface->getServerSocket() != NULL &&
|
||||||
|
serverInterface->getServerSocket()->hasBlockedIPAddresses() == true) {
|
||||||
|
renderer.renderButton(&buttonClearBlockedPlayers);
|
||||||
|
}
|
||||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||||
if( hasNetworkGameSettings() == true &&
|
if( hasNetworkGameSettings() == true &&
|
||||||
listBoxControls[i].getSelectedItemIndex() != ctClosed) {
|
listBoxControls[i].getSelectedItemIndex() != ctClosed) {
|
||||||
renderer.renderLabel(&labelPlayerStatus[i]);
|
renderer.renderLabel(&labelPlayerStatus[i]);
|
||||||
|
|
||||||
|
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
|
||||||
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
|
if( serverInterface != NULL &&
|
||||||
|
serverInterface->getSlot(i) != NULL &&
|
||||||
|
serverInterface->getSlot(i)->isConnected()) {
|
||||||
|
renderer.renderButton(&buttonBlockPlayers[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(crcPlayerTextureCache[i] != NULL) {
|
if(crcPlayerTextureCache[i] != NULL) {
|
||||||
|
|
|
@ -61,12 +61,15 @@ private:
|
||||||
GraphicLabel labelPlayers[GameConstants::maxPlayers];
|
GraphicLabel labelPlayers[GameConstants::maxPlayers];
|
||||||
GraphicLabel labelPlayerNames[GameConstants::maxPlayers];
|
GraphicLabel labelPlayerNames[GameConstants::maxPlayers];
|
||||||
GraphicListBox listBoxControls[GameConstants::maxPlayers];
|
GraphicListBox listBoxControls[GameConstants::maxPlayers];
|
||||||
|
GraphicButton buttonBlockPlayers[GameConstants::maxPlayers];
|
||||||
GraphicListBox listBoxRMultiplier[GameConstants::maxPlayers];
|
GraphicListBox listBoxRMultiplier[GameConstants::maxPlayers];
|
||||||
GraphicListBox listBoxFactions[GameConstants::maxPlayers];
|
GraphicListBox listBoxFactions[GameConstants::maxPlayers];
|
||||||
GraphicListBox listBoxTeams[GameConstants::maxPlayers];
|
GraphicListBox listBoxTeams[GameConstants::maxPlayers];
|
||||||
GraphicLabel labelNetStatus[GameConstants::maxPlayers];
|
GraphicLabel labelNetStatus[GameConstants::maxPlayers];
|
||||||
MapInfo mapInfo;
|
MapInfo mapInfo;
|
||||||
|
|
||||||
|
GraphicButton buttonClearBlockedPlayers;
|
||||||
|
|
||||||
GraphicLabel labelPublishServer;
|
GraphicLabel labelPublishServer;
|
||||||
GraphicListBox listBoxPublishServer;
|
GraphicListBox listBoxPublishServer;
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,7 @@ public:
|
||||||
|
|
||||||
virtual Socket* getSocket() {return &serverSocket;}
|
virtual Socket* getSocket() {return &serverSocket;}
|
||||||
|
|
||||||
const virtual Socket *getSocket() const
|
const virtual Socket *getSocket() const {
|
||||||
{
|
|
||||||
return &serverSocket;
|
return &serverSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,6 +230,7 @@ protected:
|
||||||
BroadCastSocketThread *broadCastThread;
|
BroadCastSocketThread *broadCastThread;
|
||||||
void startBroadCastThread();
|
void startBroadCastThread();
|
||||||
bool isBroadCastThreadRunning();
|
bool isBroadCastThreadRunning();
|
||||||
|
vector<string> blockIPList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ServerSocket();
|
ServerSocket();
|
||||||
|
@ -239,6 +240,12 @@ public:
|
||||||
Socket *accept();
|
Socket *accept();
|
||||||
void stopBroadCastThread();
|
void stopBroadCastThread();
|
||||||
|
|
||||||
|
void addIPAddressToBlockedList(string value);
|
||||||
|
bool isIPAddressBlocked(string value) const;
|
||||||
|
void removeBlockedIPAddress(string value);
|
||||||
|
void clearBlockedIPAddress();
|
||||||
|
bool hasBlockedIPAddresses() const;
|
||||||
|
|
||||||
void setBindPort(int port) { boundPort = port; }
|
void setBindPort(int port) { boundPort = port; }
|
||||||
int getBindPort() const { return boundPort; }
|
int getBindPort() const { return boundPort; }
|
||||||
bool isPortBound() const { return portBound; }
|
bool isPortBound() const { return portBound; }
|
||||||
|
|
|
@ -1949,7 +1949,6 @@ void ServerSocket::listen(int connectionQueueSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket *ServerSocket::accept() {
|
Socket *ServerSocket::accept() {
|
||||||
|
|
||||||
if(isSocketValid() == false) {
|
if(isSocketValid() == false) {
|
||||||
throwException("socket is invalid!");
|
throwException("socket is invalid!");
|
||||||
}
|
}
|
||||||
|
@ -1977,6 +1976,13 @@ Socket *ServerSocket::accept() {
|
||||||
sprintf(client_host, "%s",inet_ntoa(cli_addr.sin_addr));
|
sprintf(client_host, "%s",inet_ntoa(cli_addr.sin_addr));
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got connection, newSock = %d client_host [%s]\n",__FILE__,__FUNCTION__,__LINE__,newSock,client_host);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got connection, newSock = %d client_host [%s]\n",__FILE__,__FUNCTION__,__LINE__,newSock,client_host);
|
||||||
}
|
}
|
||||||
|
if(isIPAddressBlocked(client_host) == true) {
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] BLOCKING connection, newSock = %d client_host [%s]\n",__FILE__,__FUNCTION__,__LINE__,newSock,client_host);
|
||||||
|
|
||||||
|
close(newSock);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
Socket *result = new Socket(newSock);
|
Socket *result = new Socket(newSock);
|
||||||
result->setIpAddress(client_host);
|
result->setIpAddress(client_host);
|
||||||
return result;
|
return result;
|
||||||
|
@ -2454,4 +2460,29 @@ std::string Socket::getIpAddress() {
|
||||||
return ipAddress;
|
return ipAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerSocket::addIPAddressToBlockedList(string value) {
|
||||||
|
if(isIPAddressBlocked(value) == false) {
|
||||||
|
blockIPList.push_back(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool ServerSocket::isIPAddressBlocked(string value) const {
|
||||||
|
bool result = (std::find(blockIPList.begin(),blockIPList.end(),value) != blockIPList.end());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerSocket::removeBlockedIPAddress(string value) {
|
||||||
|
vector<string>::iterator iterFind = std::find(blockIPList.begin(),blockIPList.end(),value);
|
||||||
|
if(iterFind != blockIPList.end()) {
|
||||||
|
blockIPList.erase(iterFind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerSocket::clearBlockedIPAddress() {
|
||||||
|
blockIPList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServerSocket::hasBlockedIPAddresses() const {
|
||||||
|
return(blockIPList.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
Loading…
Reference in New Issue