mirror of
https://github.com/glest/glest-source.git
synced 2025-09-02 12:32:34 +02:00
clients can choose their slots
This commit is contained in:
@@ -174,6 +174,8 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
ClientInterface* clientInterface= networkManager.getClientInterface();
|
ClientInterface* clientInterface= networkManager.getClientInterface();
|
||||||
|
|
||||||
|
if (!settingsReceivedFromServer) return;
|
||||||
|
|
||||||
if(buttonDisconnect.mouseClick(x,y)){
|
if(buttonDisconnect.mouseClick(x,y)){
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
@@ -216,23 +218,46 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
int myCurrentIndex=-1;
|
||||||
|
for(int i=0; i<GameConstants::maxPlayers; ++i)
|
||||||
|
{// find my current index by looking at editable listBoxes
|
||||||
|
if(listBoxFactions[i].getEditable()){
|
||||||
|
myCurrentIndex=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (myCurrentIndex!=-1)
|
||||||
for(int i=0; i<GameConstants::maxPlayers; ++i)
|
for(int i=0; i<GameConstants::maxPlayers; ++i)
|
||||||
{
|
{
|
||||||
if(listBoxFactions[i].getEditable()){
|
if(listBoxFactions[i].getEditable()){
|
||||||
if(listBoxFactions[i].mouseClick(x, y)){
|
if(listBoxFactions[i].mouseClick(x, y)){
|
||||||
|
soundRenderer.playFx(coreData.getClickSoundA());
|
||||||
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
|
||||||
if(clientInterface->isConnected()){
|
if(clientInterface->isConnected()){
|
||||||
clientInterface->setGameSettingsReceived(false);
|
clientInterface->setGameSettingsReceived(false);
|
||||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),clientInterface->getGameSettings()->getThisFactionIndex(),-1,listBoxTeams[i].getSelectedItemIndex());
|
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex());
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(listBoxTeams[i].getEditable()){
|
if(listBoxTeams[i].getEditable()){
|
||||||
if(listBoxTeams[i].mouseClick(x, y)){
|
if(listBoxTeams[i].mouseClick(x, y)){
|
||||||
|
soundRenderer.playFx(coreData.getClickSoundA());
|
||||||
if(clientInterface->isConnected()){
|
if(clientInterface->isConnected()){
|
||||||
clientInterface->setGameSettingsReceived(false);
|
clientInterface->setGameSettingsReceived(false);
|
||||||
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),clientInterface->getGameSettings()->getThisFactionIndex(),-1,listBoxTeams[i].getSelectedItemIndex());
|
clientInterface->sendSwitchSetupRequest(listBoxFactions[i].getSelectedItem(),i,-1,listBoxTeams[i].getSelectedItemIndex());
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if((listBoxControls[i].getSelectedItemIndex()==ctNetwork) && (labelNetStatus[i].getText()=="???")){
|
||||||
|
if(grabSlotButton[i].mouseClick(x, y) )
|
||||||
|
{
|
||||||
|
soundRenderer.playFx(coreData.getClickSoundA());
|
||||||
|
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());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,6 +329,7 @@ void MenuStateConnectedGame::mouseMove(int x, int y, const MouseState *ms){
|
|||||||
listBoxControls[i].mouseMove(x, y);
|
listBoxControls[i].mouseMove(x, y);
|
||||||
listBoxFactions[i].mouseMove(x, y);
|
listBoxFactions[i].mouseMove(x, y);
|
||||||
listBoxTeams[i].mouseMove(x, y);
|
listBoxTeams[i].mouseMove(x, y);
|
||||||
|
grabSlotButton[i].mouseMove(x, y);
|
||||||
}
|
}
|
||||||
listBoxMap.mouseMove(x, y);
|
listBoxMap.mouseMove(x, y);
|
||||||
listBoxFogOfWar.mouseMove(x, y);
|
listBoxFogOfWar.mouseMove(x, y);
|
||||||
@@ -320,7 +346,7 @@ void MenuStateConnectedGame::render(){
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
renderer.renderButton(&buttonDisconnect);
|
renderer.renderButton(&buttonDisconnect);
|
||||||
renderer.renderButton(&buttonPlayNow);
|
//renderer.renderButton(&buttonPlayNow);
|
||||||
|
|
||||||
for(i=0; i<GameConstants::maxPlayers; ++i){
|
for(i=0; i<GameConstants::maxPlayers; ++i){
|
||||||
renderer.renderLabel(&labelPlayers[i]);
|
renderer.renderLabel(&labelPlayers[i]);
|
||||||
|
@@ -412,6 +412,57 @@ void MenuStateCustomGame::update()
|
|||||||
|
|
||||||
bool haveAtLeastOneNetworkClientConnected = false;
|
bool haveAtLeastOneNetworkClientConnected = false;
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
|
|
||||||
|
|
||||||
|
// handle setting changes from clients
|
||||||
|
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
|
||||||
|
for(int i= 0; i<mapInfo.players; ++i)
|
||||||
|
{
|
||||||
|
if(switchSetupRequests[i]!=NULL)
|
||||||
|
{
|
||||||
|
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
||||||
|
{
|
||||||
|
//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)
|
||||||
|
{
|
||||||
|
//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());
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
if(switchSetupRequests[i]->getSelectedFactionName()!=""){
|
||||||
|
listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
|
||||||
|
}
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete switchSetupRequests[i];
|
||||||
|
switchSetupRequests[i]=NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(int i= 0; i<mapInfo.players; ++i)
|
for(int i= 0; i<mapInfo.players; ++i)
|
||||||
{
|
{
|
||||||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
||||||
@@ -523,32 +574,6 @@ void MenuStateCustomGame::update()
|
|||||||
needToSetChangedGameSettings = false;
|
needToSetChangedGameSettings = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
|
|
||||||
for(int i= 0; i<mapInfo.players; ++i)
|
|
||||||
{
|
|
||||||
if(switchSetupRequests[i]!=NULL)
|
|
||||||
{
|
|
||||||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
|
||||||
{
|
|
||||||
//printf("switchSetupRequests[i]->getSelectedFactionName()=%s\n",switchSetupRequests[i]->getSelectedFactionName().c_str());
|
|
||||||
//printf("switchSetupRequests[i]->getToTeam()=%d\n",switchSetupRequests[i]->getToTeam());
|
|
||||||
|
|
||||||
try {
|
|
||||||
if(switchSetupRequests[i]->getSelectedFactionName()!=""){
|
|
||||||
listBoxFactions[i].setSelectedItem(switchSetupRequests[i]->getSelectedFactionName());
|
|
||||||
}
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete switchSetupRequests[i];
|
|
||||||
switchSetupRequests[i]=NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(difftime(time(NULL),lastSetChangedGameSettings) >= 2)
|
if(difftime(time(NULL),lastSetChangedGameSettings) >= 2)
|
||||||
{
|
{
|
||||||
GameSettings gameSettings;
|
GameSettings gameSettings;
|
||||||
|
@@ -366,7 +366,15 @@ void ClientInterface::updateLobby()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case nmtPlayerIndexMessage:
|
||||||
|
{
|
||||||
|
PlayerIndexMessage playerIndexMessage(-1);
|
||||||
|
if(receiveMessage(&playerIndexMessage))
|
||||||
|
{
|
||||||
|
playerIndex= playerIndexMessage.getPlayerIndex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
string sErr = string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType);
|
string sErr = string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType);
|
||||||
|
@@ -46,6 +46,8 @@ public:
|
|||||||
|
|
||||||
void update(bool checkForNewClients);
|
void update(bool checkForNewClients);
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
void setPlayerIndex(int value) { playerIndex = value; }
|
||||||
|
int getPlayerIndex() {return playerIndex;}
|
||||||
|
|
||||||
void setReady() {ready= true;}
|
void setReady() {ready= true;}
|
||||||
const string &getName() const {return name;}
|
const string &getName() const {return name;}
|
||||||
|
@@ -491,6 +491,27 @@ void SwitchSetupRequest::send(Socket* socket) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class PlayerIndexMessage
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
|
||||||
|
PlayerIndexMessage::PlayerIndexMessage(int16 playerIndex)
|
||||||
|
{
|
||||||
|
data.messageType= nmtPlayerIndexMessage;
|
||||||
|
data.playerIndex=playerIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlayerIndexMessage::receive(Socket* socket)
|
||||||
|
{
|
||||||
|
return NetworkMessage::receive(socket, &data, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerIndexMessage::send(Socket* socket) const
|
||||||
|
{
|
||||||
|
assert(data.messageType==nmtPlayerIndexMessage);
|
||||||
|
NetworkMessage::send(socket, &data, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -39,6 +39,7 @@ enum NetworkMessageType{
|
|||||||
nmtSynchNetworkGameDataFileGet,
|
nmtSynchNetworkGameDataFileGet,
|
||||||
nmtBroadCastSetup,
|
nmtBroadCastSetup,
|
||||||
nmtSwitchSetupRequest,
|
nmtSwitchSetupRequest,
|
||||||
|
nmtPlayerIndexMessage,
|
||||||
|
|
||||||
nmtCount
|
nmtCount
|
||||||
};
|
};
|
||||||
@@ -448,6 +449,32 @@ public:
|
|||||||
virtual void send(Socket* socket) const;
|
virtual void send(Socket* socket) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class SwitchSetupRequest
|
||||||
|
//
|
||||||
|
// Message sent from the server to the client
|
||||||
|
// when the client connects and vice versa
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class PlayerIndexMessage: public NetworkMessage{
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Data{
|
||||||
|
int8 messageType;
|
||||||
|
int16 playerIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
Data data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PlayerIndexMessage( int16 playerIndex);
|
||||||
|
|
||||||
|
int16 getPlayerIndex() const {return data.playerIndex;}
|
||||||
|
|
||||||
|
virtual bool receive(Socket* socket);
|
||||||
|
virtual void send(Socket* socket) const;
|
||||||
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
||||||
|
@@ -74,6 +74,29 @@ void ServerInterface::addSlot(int playerIndex){
|
|||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex){
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
||||||
|
bool result=false;
|
||||||
|
assert(fromPlayerIndex>=0 && fromPlayerIndex<GameConstants::maxPlayers);
|
||||||
|
assert(toPlayerIndex>=0 && toPlayerIndex<GameConstants::maxPlayers);
|
||||||
|
if(fromPlayerIndex==toPlayerIndex) return false;// doubleclicked or whatever
|
||||||
|
|
||||||
|
//printf(" checking if slot %d is free?\n",toPlayerIndex);
|
||||||
|
if( !slots[toPlayerIndex]->isConnected()) {
|
||||||
|
//printf(" yes, its free :)\n");
|
||||||
|
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
|
||||||
|
ConnectionSlot *tmp=slots[toPlayerIndex];
|
||||||
|
slots[toPlayerIndex]= slots[fromPlayerIndex];
|
||||||
|
slots[fromPlayerIndex]=tmp;
|
||||||
|
PlayerIndexMessage playerIndexMessage(toPlayerIndex);
|
||||||
|
slots[toPlayerIndex]->sendMessage(&playerIndexMessage);
|
||||||
|
result=true;
|
||||||
|
}
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void ServerInterface::removeSlot(int playerIndex){
|
void ServerInterface::removeSlot(int playerIndex){
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
||||||
|
@@ -69,6 +69,7 @@ public:
|
|||||||
ServerSocket* getServerSocket() {return &serverSocket;}
|
ServerSocket* getServerSocket() {return &serverSocket;}
|
||||||
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];}
|
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];}
|
||||||
void addSlot(int playerIndex);
|
void addSlot(int playerIndex);
|
||||||
|
bool switchSlot(int fromPlayerIndex,int toPlayerIndex);
|
||||||
void removeSlot(int playerIndex);
|
void removeSlot(int playerIndex);
|
||||||
ConnectionSlot* getSlot(int playerIndex);
|
ConnectionSlot* getSlot(int playerIndex);
|
||||||
int getConnectedSlotCount();
|
int getConnectedSlotCount();
|
||||||
|
Reference in New Issue
Block a user