Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Core/GameEngine/Include/GameNetwork/ConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class ConnectionManager
void notifyOthersOfNewFrame(UnsignedInt frame);

UnsignedInt getNextPacketRouterSlot(UnsignedInt playerID); ///< returns the packet router player that comes after the given player.
Int getCurrentSenderSlot() const { return m_currentSenderSlot; }

Int getAverageFPS();
Int getSlotAverageFPS(Int slot);
Expand Down Expand Up @@ -174,6 +175,7 @@ class ConnectionManager
Real getMaximumLatency(); ///< Returns the average of the two highest average latencies between players.

void requestFrameDataResend(Int playerID, UnsignedInt frame); ///< request of this player that he send the specified frame's data.
Int getSlotOfAddress(UnsignedInt addr, UnsignedShort port);

// The connections are set up like the slot list. The connection corresponding to the local
// player's position in the slot list will be null. Connections corresponding to slots that
Expand All @@ -194,6 +196,7 @@ class ConnectionManager

NetCommandList *m_pendingCommands;
NetCommandList *m_relayedCommands;
Int m_currentSenderSlot;

FrameMetrics m_frameMetrics;

Expand Down
24 changes: 23 additions & 1 deletion Core/GameEngine/Include/GameNetwork/DisconnectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,20 @@ class DisconnectManager
void recalculatePacketRouterIndex(ConnectionManager *conMgr);
Bool allOnSameFrame(ConnectionManager *conMgr); ///< returns true if all players are stuck on the same frame.
Bool isLocalPlayerNextPacketRouter(ConnectionManager *conMgr); ///< returns true if the local player is next in line to be the packet router with all the players that have timed out being taken out of the picture.
#if !RETAIL_COMPATIBLE_NETWORKING
Int getActingPacketRouterSlot(ConnectionManager *conMgr, Int removedSlot);
Bool hasPlayerLeft(Int slot);
Bool isLeftPlayerConnected(ConnectionManager *conMgr);
void processHeldRemovals(ConnectionManager *conMgr); ///< removes the players whose held removal now comes from the acting packet router.
#endif
Bool hasPlayerTimedOut(Int slot); ///< returns true if this player has timed out.
void sendPlayerDestruct(Int slot, ConnectionManager *conMgr); ///< send a destruct player network message.
#if RETAIL_COMPATIBLE_NETWORKING
void sendPendingRelays(ConnectionManager *conMgr); ///< passes a leave on to the players that are stalled on its frame.
#endif
Bool isPlayerVotedOut(Int slot, ConnectionManager *conMgr); ///< returns true if this player has been voted out.
Bool isPlayerInGame(Int slot, ConnectionManager *conMgr); ///< returns true if the player has neither timed out or been voted out.
UnsignedInt getMaxDisconnectFrame(); ///< returns the highest frame that people have got to.
UnsignedInt getMaxDisconnectFrame(ConnectionManager *conMgr); ///< returns the highest frame that people have got to.
Int countVotesForPlayer(Int slot); ///< return the number of disconnect votes a player has.
void resetPlayersVotes(Int playerID, UnsignedInt frame, ConnectionManager *conMgr); ///< reset the votes for this player.

Expand All @@ -107,7 +116,16 @@ class DisconnectManager

time_t m_lastKeepAliveSendTime;

Bool m_destroySent[MAX_SLOTS];

time_t m_playerTimeouts[MAX_SLOTS - 1];
#if !RETAIL_COMPATIBLE_NETWORKING
Bool m_playerLeft[MAX_SLOTS - 1]; ///< The player of the translated slot has left and waits for its removal.
Bool m_ownLeaveReceived[MAX_SLOTS - 1]; ///< The leave came from the player itself, not from a notice of another player.
Bool m_leftPlayerHold;
Int m_heldRemovalFrom[MAX_SLOTS]; ///< The sender of a removal of the slot that came before it was the acting packet router here, or -1.
UnsignedInt m_heldRemovalFrame[MAX_SLOTS]; ///< The frame of that removal.
#endif
time_t m_packetRouterTimeout;

DisconnectVoteStruct m_playerVotes[MAX_SLOTS][MAX_SLOTS];
Expand All @@ -116,6 +134,10 @@ class DisconnectManager
UnsignedInt m_disconnectFrames[MAX_SLOTS];
Bool m_disconnectFramesReceived[MAX_SLOTS];
Bool m_haveNotifiedOtherPlayersOfCurrentFrame;
#if RETAIL_COMPATIBLE_NETWORKING
UnsignedInt m_relayFrame[MAX_SLOTS]; ///< The frame of the leave of the slot that is passed on.
UnsignedByte m_relayTo[MAX_SLOTS]; ///< The players the leave of the slot still has to be passed on to.
#endif

time_t m_timeOfDisconnectScreenOn;
Int m_pingsSent;
Expand Down
13 changes: 13 additions & 0 deletions Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ void ConnectionManager::init()
for (i = 0; i < MAX_SLOTS; ++i) {
m_packetRouterFallback[i] = -1;
}
m_currentSenderSlot = -1;

for (i = 0; i < MAX_SLOTS; ++i) {
deleteInstance(m_frameData[i]);
Expand Down Expand Up @@ -472,6 +473,7 @@ void ConnectionManager::doRelay() {

// Get the command list from the packet.
NetCommandList *cmdList = packet.getCommandList();
m_currentSenderSlot = getSlotOfAddress(m_transport->m_inBuffer[i].addr, m_transport->m_inBuffer[i].port);

// Iterate through the commands in this packet and send them to the proper connections.
for (NetCommandRef* cmd = cmdList->getFirstMessage(); cmd; cmd = cmd->getNext()) {
Expand All @@ -496,6 +498,8 @@ void ConnectionManager::doRelay() {
}
}

m_currentSenderSlot = -1;

NetCommandList *cmdList = m_netCommandWrapperList->getReadyCommands();
for (NetCommandRef* cmd = cmdList->getFirstMessage(); cmd; cmd = cmd->getNext()) {
if (CommandRequiresAck(cmd->getCommand())) {
Expand Down Expand Up @@ -2585,3 +2589,12 @@ void ConnectionManager::requestFrameDataResend(Int playerID, UnsignedInt frame)

msg->detach();
}

Int ConnectionManager::getSlotOfAddress(UnsignedInt addr, UnsignedShort port) {
for (Int i = 0; i < MAX_SLOTS; ++i) {
if ((m_connections[i] != nullptr) && (m_connections[i]->getUser()->GetIPAddr() == addr) && (m_connections[i]->getUser()->GetPort() == port)) {
return i;
}
}
return -1;
}
Loading
Loading