added client socket accept info to debug log as well as some change detection

This commit is contained in:
Mark Vejvoda 2010-05-17 06:41:05 +00:00
parent 5ea892ba1a
commit 272a072ec3
4 changed files with 34 additions and 6 deletions

View File

@ -49,6 +49,7 @@ struct FormatString {
MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots,bool parentMenuIsMasterserver):
MenuState(program, mainMenu, "new-game")
{
publishToMasterserverThread = NULL;
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
Config &config = Config::getInstance();
@ -545,8 +546,11 @@ void MenuStateCustomGame::update()
{
if(switchSetupRequests[i]!=NULL)
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
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());
@ -602,6 +606,8 @@ void MenuStateCustomGame::update()
if(connectionSlot->isConnected())
{
//printf("FYI we have at least 1 client connected, slot = %d'\n",i);
haveAtLeastOneNetworkClientConnected = true;
currentConnectionCount++;
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] B - ctNetwork\n",__FILE__,__FUNCTION__);
@ -827,11 +833,16 @@ void MenuStateCustomGame::simpleTask() {
if(needToBroadcastServerSettings)
{
needToBroadcastServerSettings=false;
GameSettings gameSettings;
loadGameSettings(&gameSettings);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setGameSettings(&gameSettings);
serverInterface->broadcastGameSetup(&gameSettings);
if(serverInterface->hasClientConnection() == true) {
//printf("Sending game settings broadcast since we have at least 1 client connected'\n");
GameSettings gameSettings;
loadGameSettings(&gameSettings);
serverInterface->setGameSettings(&gameSettings);
serverInterface->broadcastGameSetup(&gameSettings);
}
}
}

View File

@ -237,6 +237,18 @@ ConnectionSlot* ServerInterface::getSlot(int playerIndex){
return slots[playerIndex];
}
bool ServerInterface::hasClientConnection() {
bool result = false;
for(int i= 0; i<GameConstants::maxPlayers; ++i){
if(slots[i] != NULL && slots[i]->isConnected() == true) {
result = true;
break;
}
}
return result;
}
int ServerInterface::getConnectedSlotCount(){
int connectedSlotCount= 0;

View File

@ -121,6 +121,7 @@ public:
virtual bool getConnectHasHandshaked() const { return false; }
virtual void slotUpdateTask(ConnectionSlotEvent *event);
bool hasClientConnection();
private:
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1);

View File

@ -1567,7 +1567,9 @@ void ServerSocket::listen(int connectionQueueSize) {
Socket *ServerSocket::accept()
{
PLATFORM_SOCKET newSock= ::accept(sock, NULL, NULL);
struct sockaddr_in cli_addr;
socklen_t clilen = sizeof(cli_addr);
PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
if(isSocketValid(&newSock) == false)
{
char szBuf[1024]="";
@ -1582,7 +1584,9 @@ Socket *ServerSocket::accept()
}
else {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got connection, newSock = %d\n",__FILE__,__FUNCTION__,__LINE__,newSock);
char client_host[100]="";
sprintf(client_host, "%s",inet_ntoa(cli_addr.sin_addr));
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got connection, newSock = %d client_host [%s]\n",__FILE__,__FUNCTION__,__LINE__,newSock,client_host);
}
return new Socket(newSock);
}