@@ -77,21 +77,36 @@ def run(self):
7777 self .queue_out_put (THREADSIG .FAILURE )
7878 return
7979
80- self .queue_out_put (THREADSIG .INFO_IDX_PARAM , 0 , f"Connecting to TF2 (port { self .port } )..." )
81- try :
82- potential_targets = socket .getaddrinfo (socket .getfqdn (), self .port , socket .AF_INET )
83- except OSError as error :
80+ self .queue_out_put (THREADSIG .INFO_IDX_PARAM , 0 , f"Connecting on port { self .port } ..." )
81+
82+ potential_targets = []
83+ target_gathering_errors = []
84+ for hostname in ("127.0.0.1" , "localhost" , None ):
85+ try :
86+ rhostname = socket .getfqdn () if hostname is None else hostname
87+ except OSError as error :
88+ target_gathering_errors .append (error )
89+ continue
90+
91+ try :
92+ potential_targets .extend (socket .getaddrinfo (rhostname , self .port , socket .AF_INET ))
93+ except OSError as error :
94+ target_gathering_errors .append (error )
95+ continue
96+
97+ if not potential_targets :
8498 self .queue_out_put (
8599 THREADSIG .INFO_IDX_PARAM ,
86100 0 ,
87- f"Obscure error getting machine address : { error } "
101+ f"Failed gathering connection candidates : { target_gathering_errors } " ,
88102 )
89103 self .queue_out_put (THREADSIG .FAILURE )
90104 return
91105
92- for idx , value in enumerate (potential_targets ):
93- af , type_ , proto , _ , addr = value
94- self ._socket = error = None
106+ error = None
107+ for idx , (af , type_ , proto , _ , addr ) in enumerate (potential_targets ):
108+ error = None
109+ self ._socket = None
95110 self .queue_out_put (
96111 THREADSIG .INFO_IDX_PARAM ,
97112 0 ,
@@ -116,7 +131,8 @@ def run(self):
116131
117132 if error is not None :
118133 self .queue_out_put (
119- THREADSIG .INFO_IDX_PARAM , 0 ,
134+ THREADSIG .INFO_IDX_PARAM ,
135+ 0 ,
120136 f"Failure establishing connection. { MAKE_SURE } : { error } "
121137 )
122138 self .queue_out_put (THREADSIG .FAILURE )
@@ -126,7 +142,7 @@ def run(self):
126142 self .__stopsock (THREADSIG .ABORTED )
127143 return
128144
129- self .queue_out_put (THREADSIG .INFO_IDX_PARAM , 0 , "Connected to TF2 " )
145+ self .queue_out_put (THREADSIG .INFO_IDX_PARAM , 0 , "Socket connected " )
130146 self .queue_out_put (THREADSIG .INFO_IDX_PARAM , 1 , "Authenticating..." )
131147 try :
132148 authpacket = RCONPacket (622521 , AUTH , encoded_pwd )
@@ -141,7 +157,7 @@ def run(self):
141157 self .queue_out_put (
142158 THREADSIG .INFO_IDX_PARAM ,
143159 1 ,
144- f"Failure sending auth packet. { MAKE_SURE } : { e } "
160+ f"Failure sending auth packet. { MAKE_SURE } : { e } " ,
145161 )
146162 self .__stopsock (THREADSIG .FAILURE )
147163 return
@@ -167,7 +183,7 @@ def run(self):
167183 self .queue_out_put (
168184 THREADSIG .INFO_IDX_PARAM ,
169185 1 ,
170- f"Error while authenticating. { MAKE_SURE } : { e } "
186+ f"Error while authenticating. { MAKE_SURE } : { e } " ,
171187 )
172188 self .__stopsock (THREADSIG .FAILURE )
173189 return
0 commit comments