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->ready = false;
|
||||||
this->gotIntro = false;
|
this->gotIntro = false;
|
||||||
|
this->connectedTime = 0;
|
||||||
|
|
||||||
networkGameDataSynchCheckOkMap = false;
|
networkGameDataSynchCheckOkMap = false;
|
||||||
networkGameDataSynchCheckOkTile = false;
|
networkGameDataSynchCheckOkTile = false;
|
||||||
@@ -222,9 +223,20 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
//send intro message when connected
|
//send intro message when connected
|
||||||
if(socket != NULL) {
|
if(socket != NULL) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] accepted new client connection, serverInterface->getOpenSlotCount() = %d\n",__FILE__,__FUNCTION__,serverInterface->getOpenSlotCount());
|
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->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) {
|
if(hasOpenSlots == false) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] no open slots, disconnecting client\n",__FILE__,__FUNCTION__);
|
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__);
|
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;
|
NetworkMessagePing networkMessagePing;
|
||||||
if(receiveMessage(&networkMessagePing)) {
|
if(receiveMessage(&networkMessagePing)) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
lastPingInfo = networkMessagePing;
|
lastPingInfo = networkMessagePing;
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -281,6 +297,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
{
|
{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__);
|
||||||
|
|
||||||
|
if(gotIntro == true) {
|
||||||
NetworkMessageText networkMessageText;
|
NetworkMessageText networkMessageText;
|
||||||
if(receiveMessage(&networkMessageText)) {
|
if(receiveMessage(&networkMessageText)) {
|
||||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex());
|
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);
|
//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;
|
break;
|
||||||
|
|
||||||
//command list
|
//command list
|
||||||
@@ -299,6 +317,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
|
|
||||||
//throw runtime_error("test");
|
//throw runtime_error("test");
|
||||||
|
|
||||||
|
if(gotIntro == true) {
|
||||||
NetworkMessageCommandList networkMessageCommandList;
|
NetworkMessageCommandList networkMessageCommandList;
|
||||||
if(receiveMessage(&networkMessageCommandList)) {
|
if(receiveMessage(&networkMessageCommandList)) {
|
||||||
currentFrameCount = networkMessageCommandList.getFrameCount();
|
currentFrameCount = networkMessageCommandList.getFrameCount();
|
||||||
@@ -311,6 +330,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//process intro messages
|
//process intro messages
|
||||||
@@ -343,6 +363,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
{
|
{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataStatus\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataStatus\n",__FILE__,__FUNCTION__);
|
||||||
|
|
||||||
|
if(gotIntro == true) {
|
||||||
NetworkMessageSynchNetworkGameDataStatus networkMessageSynchNetworkGameDataStatus;
|
NetworkMessageSynchNetworkGameDataStatus networkMessageSynchNetworkGameDataStatus;
|
||||||
if(receiveMessage(&networkMessageSynchNetworkGameDataStatus))
|
if(receiveMessage(&networkMessageSynchNetworkGameDataStatus))
|
||||||
{
|
{
|
||||||
@@ -434,6 +455,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nmtSynchNetworkGameDataFileCRCCheck:
|
case nmtSynchNetworkGameDataFileCRCCheck:
|
||||||
@@ -441,6 +463,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck\n",__FILE__,__FUNCTION__);
|
||||||
|
|
||||||
|
if(gotIntro == true) {
|
||||||
NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck;
|
NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck;
|
||||||
if(receiveMessage(&networkMessageSynchNetworkGameDataFileCRCCheck))
|
if(receiveMessage(&networkMessageSynchNetworkGameDataFileCRCCheck))
|
||||||
{
|
{
|
||||||
@@ -449,6 +472,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
sendMessage(&networkMessageSynchNetworkGameDataFileCRCCheck);
|
sendMessage(&networkMessageSynchNetworkGameDataFileCRCCheck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nmtSynchNetworkGameDataFileGet:
|
case nmtSynchNetworkGameDataFileGet:
|
||||||
@@ -456,6 +480,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileGet\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileGet\n",__FILE__,__FUNCTION__);
|
||||||
|
|
||||||
|
if(gotIntro == true) {
|
||||||
NetworkMessageSynchNetworkGameDataFileGet networkMessageSynchNetworkGameDataFileGet;
|
NetworkMessageSynchNetworkGameDataFileGet networkMessageSynchNetworkGameDataFileGet;
|
||||||
if(receiveMessage(&networkMessageSynchNetworkGameDataFileGet)) {
|
if(receiveMessage(&networkMessageSynchNetworkGameDataFileGet)) {
|
||||||
FileTransferInfo fileInfo;
|
FileTransferInfo fileInfo;
|
||||||
@@ -468,10 +493,12 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
fileXferThread->start();
|
fileXferThread->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nmtSwitchSetupRequest:
|
case nmtSwitchSetupRequest:
|
||||||
{
|
{
|
||||||
|
if(gotIntro == true) {
|
||||||
SwitchSetupRequest switchSetupRequest;
|
SwitchSetupRequest switchSetupRequest;
|
||||||
if(receiveMessage(&switchSetupRequest)) {
|
if(receiveMessage(&switchSetupRequest)) {
|
||||||
Mutex *mutex = getServerSynchAccessor();
|
Mutex *mutex = getServerSynchAccessor();
|
||||||
@@ -484,6 +511,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
|
|
||||||
if(mutex != NULL) mutex->v();
|
if(mutex != NULL) mutex->v();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case nmtReady:
|
case nmtReady:
|
||||||
@@ -511,10 +539,7 @@ void ConnectionSlot::update(bool checkForNewClients) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gotIntro == false && difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) {
|
validateConnection();
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime));
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] calling close...\n",__FILE__,__FUNCTION__,__LINE__);
|
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() {
|
void ConnectionSlot::close() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@@ -157,6 +157,8 @@ public:
|
|||||||
|
|
||||||
const string &getVersionString() const {return versionString;}
|
const string &getVersionString() const {return versionString;}
|
||||||
|
|
||||||
|
void validateConnection();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Mutex * getServerSynchAccessor();
|
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() {
|
void ServerInterface::update() {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
std::vector<string> errorMsgList;
|
std::vector<string> errorMsgList;
|
||||||
try {
|
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;
|
std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
|
||||||
//update all slots
|
//update all slots
|
||||||
updateSocketTriggeredList(socketTriggeredList);
|
updateSocketTriggeredList(socketTriggeredList);
|
||||||
|
@@ -105,6 +105,7 @@ private:
|
|||||||
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
|
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
|
||||||
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);
|
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);
|
||||||
void updateSlot(ConnectionSlotEvent *event);
|
void updateSlot(ConnectionSlotEvent *event);
|
||||||
|
void validateConnectedClients();
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
Reference in New Issue
Block a user