Set a timeout on the lobby client to prevent blocking on connections to the lobby
git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@7095 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
846a21b8a7
commit
5694b99b90
|
@ -49,23 +49,27 @@ class masterserver_connection:
|
|||
|
||||
def list(self):
|
||||
with _socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.connect( (self.host, self.port) )
|
||||
|
||||
self._send(s, "list")
|
||||
(count,) = self._recv(s, "!I")
|
||||
games = []
|
||||
for i in xrange(0,count):
|
||||
(description, size, flags, host, maxPlayers, currentPlayers,
|
||||
user1, user2, user3, user4 ) = self._recv(s, "!64sII16sIIIIII")
|
||||
description = description.strip("\0")
|
||||
host = host.strip("\0")
|
||||
# Workaround for the fact that some of the
|
||||
# 2.0.x versions don't perform endian swapping
|
||||
if maxPlayers > 100:
|
||||
maxPlayers = _swap_endianness(maxPlayers)
|
||||
currentPlayers = _swap_endianness(currentPlayers)
|
||||
g = game(description, host, maxPlayers, currentPlayers)
|
||||
games.append(g)
|
||||
try:
|
||||
s.settimeout(10)
|
||||
s.connect( (self.host, self.port) )
|
||||
|
||||
self._send(s, "list\0")
|
||||
(count,) = self._recv(s, "!I")
|
||||
for i in xrange(0,count):
|
||||
(description, size, flags, host, maxPlayers, currentPlayers,
|
||||
user1, user2, user3, user4 ) = self._recv(s, "!64sII16sIIIIII")
|
||||
description = description.strip("\0")
|
||||
host = host.strip("\0")
|
||||
# Workaround for the fact that some of the
|
||||
# 2.0.x versions don't perform endian swapping
|
||||
if maxPlayers > 100:
|
||||
maxPlayers = _swap_endianness(maxPlayers)
|
||||
currentPlayers = _swap_endianness(currentPlayers)
|
||||
g = game(description, host, maxPlayers, currentPlayers)
|
||||
games.append(g)
|
||||
except socket.timeout:
|
||||
pass
|
||||
|
||||
return games
|
||||
|
||||
|
|
Loading…
Reference in New Issue