Skip to content

Commit 190862e

Browse files
committed
Battle.net IP addresses are uncached so that they are resolved again after several disconnections. This allows bot to reconnect in case IP address changes.
1 parent fd1f92d commit 190862e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ghost/bnet.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ CBNET :: CBNET( CGHost *nGHost, string nServer, string nServerAlias, string nBNL
133133
m_HoldFriends = nHoldFriends;
134134
m_HoldClan = nHoldClan;
135135
m_PublicCommands = nPublicCommands;
136+
m_ServerReconnectCount = 0;
136137
}
137138

138139
CBNET :: ~CBNET( )
@@ -587,6 +588,7 @@ bool CBNET :: Update( void *fd, void *send_fd )
587588
m_Socket->DoSend( (fd_set *)send_fd );
588589
m_LastNullTime = GetTime( );
589590
m_LastOutPacketTicks = GetTicks( );
591+
m_ServerReconnectCount = 0;
590592

591593
boost::mutex::scoped_lock packetsLock( m_PacketsMutex );
592594

@@ -622,6 +624,14 @@ bool CBNET :: Update( void *fd, void *send_fd )
622624
if( !m_GHost->m_BindAddress.empty( ) )
623625
CONSOLE_Print( "[BNET: " + m_ServerAlias + "] attempting to bind to address [" + m_GHost->m_BindAddress + "]" );
624626

627+
// clear the cached IP address if we've disconnected several times
628+
// although resolving is blocking, it's not a big deal because games are anyway in separate threads
629+
if( m_ServerReconnectCount > 10 )
630+
{
631+
m_ServerReconnectCount = 0;
632+
m_ServerIP = string( );
633+
}
634+
625635
if( m_ServerIP.empty( ) )
626636
{
627637
m_Socket->Connect( m_GHost->m_BindAddress, m_Server, 6112 );
@@ -638,6 +648,8 @@ bool CBNET :: Update( void *fd, void *send_fd )
638648

639649
CONSOLE_Print( "[BNET: " + m_ServerAlias + "] using cached server IP address " + m_ServerIP );
640650
m_Socket->Connect( m_GHost->m_BindAddress, m_ServerIP, 6112 );
651+
652+
m_ServerReconnectCount++;
641653
}
642654

643655
m_WaitingToConnect = false;

ghost/bnet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class CBNET
8686
string m_Server; // battle.net server to connect to
8787
string m_ServerIP; // battle.net server to connect to (the IP address so we don't have to resolve it every time we connect)
8888
string m_ServerAlias; // battle.net server alias (short name, e.g. "USEast")
89+
uint32_t m_ServerReconnectCount; // counts how many times we have reconnected to the server and failed; when it's high, we resolve ServerIP again
8990
string m_BNLSServer; // BNLS server to connect to (for warden handling)
9091
uint16_t m_BNLSPort; // BNLS port
9192
uint32_t m_BNLSWardenCookie; // BNLS warden cookie

0 commit comments

Comments
 (0)