mirror of
https://github.com/glest/glest-source.git
synced 2025-08-29 10:49:48 +02:00
- attempt to protect a little against spurious network activity
This commit is contained in:
@@ -166,6 +166,7 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex
|
||||
|
||||
this->ready = false;
|
||||
this->gotIntro = false;
|
||||
this->connectedTime = 0;
|
||||
|
||||
networkGameDataSynchCheckOkMap = false;
|
||||
networkGameDataSynchCheckOkTile = false;
|
||||
@@ -222,9 +223,20 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
//send intro message when connected
|
||||
if(socket != NULL) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] accepted new client connection, serverInterface->getOpenSlotCount() = %d\n",__FILE__,__FUNCTION__,serverInterface->getOpenSlotCount());
|
||||
connectedTime = time(NULL);
|
||||
|
||||
this->connectedTime = time(NULL);
|
||||
this->clearChatInfo();
|
||||
this->name = "";
|
||||
this->ready = false;
|
||||
this->vctFileList.clear();
|
||||
this->receivedNetworkGameStatus = false;
|
||||
this->gotIntro = false;
|
||||
this->vctPendingNetworkCommandList.clear();
|
||||
this->currentFrameCount = 0;
|
||||
this->currentLagCount = 0;
|
||||
this->lastReceiveCommandListTime = 0;
|
||||
this->gotLagCountWarning = false;
|
||||
this->versionString = "";
|
||||
|
||||
|
||||
if(hasOpenSlots == false) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] no open slots, disconnecting client\n",__FILE__,__FUNCTION__);
|
||||
@@ -269,11 +281,15 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtPing\n",__FILE__,__FUNCTION__);
|
||||
|
||||
// client REQUIRES a ping before completing intro
|
||||
// authentication
|
||||
//if(gotIntro == true) {
|
||||
NetworkMessagePing networkMessagePing;
|
||||
if(receiveMessage(&networkMessagePing)) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
lastPingInfo = networkMessagePing;
|
||||
}
|
||||
//}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -281,6 +297,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__);
|
||||
|
||||
if(gotIntro == true) {
|
||||
NetworkMessageText networkMessageText;
|
||||
if(receiveMessage(&networkMessageText)) {
|
||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
||||
@@ -290,6 +307,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//command list
|
||||
@@ -299,6 +317,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
|
||||
//throw runtime_error("test");
|
||||
|
||||
if(gotIntro == true) {
|
||||
NetworkMessageCommandList networkMessageCommandList;
|
||||
if(receiveMessage(&networkMessageCommandList)) {
|
||||
currentFrameCount = networkMessageCommandList.getFrameCount();
|
||||
@@ -311,6 +330,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//process intro messages
|
||||
@@ -343,6 +363,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataStatus\n",__FILE__,__FUNCTION__);
|
||||
|
||||
if(gotIntro == true) {
|
||||
NetworkMessageSynchNetworkGameDataStatus networkMessageSynchNetworkGameDataStatus;
|
||||
if(receiveMessage(&networkMessageSynchNetworkGameDataStatus))
|
||||
{
|
||||
@@ -434,6 +455,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case nmtSynchNetworkGameDataFileCRCCheck:
|
||||
@@ -441,6 +463,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck\n",__FILE__,__FUNCTION__);
|
||||
|
||||
if(gotIntro == true) {
|
||||
NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck;
|
||||
if(receiveMessage(&networkMessageSynchNetworkGameDataFileCRCCheck))
|
||||
{
|
||||
@@ -449,6 +472,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
sendMessage(&networkMessageSynchNetworkGameDataFileCRCCheck);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case nmtSynchNetworkGameDataFileGet:
|
||||
@@ -456,6 +480,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileGet\n",__FILE__,__FUNCTION__);
|
||||
|
||||
if(gotIntro == true) {
|
||||
NetworkMessageSynchNetworkGameDataFileGet networkMessageSynchNetworkGameDataFileGet;
|
||||
if(receiveMessage(&networkMessageSynchNetworkGameDataFileGet)) {
|
||||
FileTransferInfo fileInfo;
|
||||
@@ -468,10 +493,12 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
fileXferThread->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case nmtSwitchSetupRequest:
|
||||
{
|
||||
if(gotIntro == true) {
|
||||
SwitchSetupRequest switchSetupRequest;
|
||||
if(receiveMessage(&switchSetupRequest)) {
|
||||
Mutex *mutex = getServerSynchAccessor();
|
||||
@@ -484,6 +511,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
|
||||
if(mutex != NULL) mutex->v();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case nmtReady:
|
||||
@@ -511,10 +539,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
}
|
||||
}
|
||||
|
||||
if(gotIntro == false && difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime));
|
||||
close();
|
||||
}
|
||||
validateConnection();
|
||||
}
|
||||
else {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] calling close...\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
@@ -532,6 +557,14 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionSlot::validateConnection() {
|
||||
if(gotIntro == false && connectedTime > 0 &&
|
||||
difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime));
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionSlot::close() {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
@@ -157,6 +157,8 @@ public:
|
||||
|
||||
const string &getVersionString() const {return versionString;}
|
||||
|
||||
void validateConnection();
|
||||
|
||||
protected:
|
||||
|
||||
Mutex * getServerSynchAccessor();
|
||||
|
@@ -415,11 +415,27 @@ void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &
|
||||
}
|
||||
}
|
||||
|
||||
void ServerInterface::validateConnectedClients() {
|
||||
for(int i= 0; i<GameConstants::maxPlayers; ++i) {
|
||||
ConnectionSlot* connectionSlot = slots[i];
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Slot # %d\n",__FILE__,__FUNCTION__,__LINE__,i);
|
||||
|
||||
if(connectionSlot != NULL) {
|
||||
connectionSlot->validateConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerInterface::update() {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
std::vector<string> errorMsgList;
|
||||
try {
|
||||
// The first thing we will do is check all clients to ensure they have
|
||||
// properly identified themselves within the alloted time period
|
||||
validateConnectedClients();
|
||||
|
||||
std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
|
||||
//update all slots
|
||||
updateSocketTriggeredList(socketTriggeredList);
|
||||
|
@@ -105,6 +105,7 @@ private:
|
||||
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
|
||||
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);
|
||||
void updateSlot(ConnectionSlotEvent *event);
|
||||
void validateConnectedClients();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
Reference in New Issue
Block a user