@@ -192,7 +192,7 @@ void NetworkMesh::SendToMesh(NetworkPacket& packet, std::vector<int64_t> vecTarg
192192 }
193193 else
194194 {
195- NetworkLog (" Packet Failed To Send! %s:%d" , ip.c_str (), peer->address .port );
195+ NetworkLog (" Packet Failed To Send! %s:%d, result was %d " , ip.c_str (), peer->address .port , ret );
196196 }
197197 }
198198 }
@@ -430,6 +430,21 @@ void NetworkMesh::ConnectToSingleUser(ENetAddress addr, Int64 user_id, bool bIsR
430430 /* Initiate the connection, allocating the 3 channels. */
431431
432432 ENetPeer* peer = enet_host_connect (enetInstance, &addr, 3 , 0 );
433+ enet_peer_timeout (peer, 3 , 1000 , 1000 );
434+
435+ #if defined(NETWORK_CONNECTION_DEBUG)
436+ char ip1[INET_ADDRSTRLEN + 1 ] = { 0 };
437+ char ip2[INET_ADDRSTRLEN + 1 ] = { 0 };
438+ if (enet_address_get_host_ip (&peer->host ->receivedAddress , ip1, sizeof (ip1)) == 0 && enet_address_get_host_ip (&peer->host ->address , ip2, sizeof (ip2)) == 0 )
439+ {
440+ NetworkLog (" [DEBUG] New enet_host_connect with address %s:%u. and received address %s:%u" ,
441+ ip1,
442+ peer->host ->receivedAddress .port ,
443+ ip2,
444+ peer->address .port );
445+ }
446+ #endif
447+
433448
434449 // don't care about in-game
435450 if (!TheGameLogic->isInGame ())
@@ -1058,8 +1073,16 @@ void NetworkMesh::Tick()
10581073 {
10591074 if (pConnection->m_State == EConnectionState::CONNECTING_DIRECT )
10601075 {
1061- NetworkLog (" [SERVER] %d timed out while connecting directly, attempting to use relay\n " , pConnection->m_userID );
1062- ConnectToUserViaRelay (pConnection->m_userID );
1076+ if (pConnection->m_ConnectionAttempts < 3 )
1077+ {
1078+ NetworkLog (" [SERVER] Attempting to connect to %d, attempt number %d\n " , pConnection->m_userID , pConnection->m_ConnectionAttempts + 1 );
1079+ ConnectToSingleUser (pConnection->m_address , pConnection->m_userID , true );
1080+ }
1081+ else
1082+ {
1083+ NetworkLog (" [SERVER] %d timed out while connecting directly, attempting to use relay\n " , pConnection->m_userID );
1084+ ConnectToUserViaRelay (pConnection->m_userID );
1085+ }
10631086 }
10641087 else
10651088 {
@@ -1157,7 +1180,7 @@ PlayerConnection::PlayerConnection(int64_t userID, ENetAddress addr, ENetPeer* p
11571180 }
11581181 // otherwise, keep whatever start we were in, its just a connection update
11591182
1160- enet_peer_timeout (m_peer, 5 , 1000 , 1000 );
1183+ enet_peer_timeout (m_peer, 3 , 1000 , 1000 );
11611184
11621185 NetworkMesh* pMesh = NGMP_OnlineServicesManager::GetInstance ()->GetLobbyInterface ()->GetNetworkMesh ();
11631186 if (pMesh != nullptr )
@@ -1243,18 +1266,15 @@ int PlayerConnection::SendPacket(NetworkPacket& packet, int channel)
12431266 if (m_State != EConnectionState::CONNECTED_DIRECT && m_State != EConnectionState::CONNECTED_RELAY )
12441267 {
12451268 NetworkLog (" WARNING: Attempting to send packet before connected, state is %d" , m_State);
1246- return 0 ;
1269+ return - 7 ;
12471270 }
12481271 }
1249-
1272+
12501273 auto currentLobby = NGMP_OnlineServicesManager::GetInstance ()->GetLobbyInterface ()->GetCurrentLobby ();
12511274
1252- if (m_State == EConnectionState::NOT_CONNECTED
1253- || m_State == EConnectionState::CONNECTION_FAILED )
1254- {
1255- return -1 ;
1256- }
1257- else if (m_State == EConnectionState::CONNECTING_DIRECT || m_State == EConnectionState::CONNECTED_DIRECT )
1275+ // Allow handshake in all stages
1276+ if ((m_State == EConnectionState::CONNECTING_DIRECT || m_State == EConnectionState::CONNECTED_DIRECT ) || ((m_State == EConnectionState::NOT_CONNECTED
1277+ || m_State == EConnectionState::CONNECTION_FAILED ) && channel == 2 ))
12581278 {
12591279 CBitStream* pBitStream = packet.Serialize ();
12601280 pBitStream->Encrypt (currentLobby.EncKey , currentLobby.EncIV );
0 commit comments