From 9b609f894eeb36bcd8829fd08f6ed457b6e10430 Mon Sep 17 00:00:00 2001 From: Rene Jochum Date: Tue, 25 Jan 2011 17:41:08 +0100 Subject: [PATCH] Fixes the wzlobby.protocl.ProtocolSwitcher and adds some spelling fixes. --- README.md | 4 ++-- wzlobby/game.py | 3 --- wzlobby/protocol.py | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 99d445e..c311cf7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ TODO - It should rebase the protocol not proxy it * Protocol v4 - - This needs to implemented + - This needs to be implemented Requirements ----------- @@ -35,7 +35,7 @@ start cd ./bin/wzlobbyserver.py -stop it +stop ---- cd diff --git a/wzlobby/game.py b/wzlobby/game.py index 7abd8eb..621452e 100644 --- a/wzlobby/game.py +++ b/wzlobby/game.py @@ -79,9 +79,6 @@ class Game(UserDict.IterableUserDict): } - # Read only property "hosts", simplfies things - hosts = property(fget = lambda self: [self.data['host1'], self.data['host2'], self.data['host3']]) - def __init__(self, lobbyVer, gameId = None): self.data['lobbyVer'] = lobbyVer if gameId: diff --git a/wzlobby/protocol.py b/wzlobby/protocol.py index 2ca5615..e75506d 100644 --- a/wzlobby/protocol.py +++ b/wzlobby/protocol.py @@ -59,14 +59,14 @@ def dataReceived(self, data): # Try to detect the protocol version = self._detectProtocolVersion(data) - if version: + if version != False: # Creates a new Protocol based on the version id try: - cls = getattr(globals(), 'Protocol%d' % version) - self.protocol = cls(self.factory, self.transport) + self.protocol = globals()['Protocol%d' % version]() except AttributeError: - log.msg('Cant find protocol version %d' % version) - self.transport.loseConection() + log.msg('Can\'t find protocol version %d (Protocol%d)' % (version, version)) + self.transport.loseConnection() + return False else: # Detection failed assume v3 self.protocol = Protocol3() @@ -82,6 +82,8 @@ def dataReceived(self, data): self.protocol.makeConnection(self.transport) if isV3: self.protocol.dataReceived(data) + elif len(data) > 12: + self.protocol.dataReceived(data[12:]) # Now switch the protocol # self.transport.protocol = self.protocol @@ -91,7 +93,7 @@ def _detectProtocolVersion(self, data): """ I detect a "version\0" Packet """ try: - data = struct.unpack('!8sI', data) + data = struct.unpack('!8sI', data[0:12]) if data[0] == "version\0": return data[1] else: @@ -194,8 +196,6 @@ def dataReceived(self, data): """ Handles an incoming command and forwards its to the do_X handler. """ - - if not self.waitData: if len(data) == 5: cmd = 'do_%s' % data[:4].lower() @@ -317,7 +317,7 @@ def do_updateGame(self, data): try: # Extract the data from the gamestruct data = self.gameStruct.unpack(data) - # Create a dict from while using self.gameStructVars as keys + # Create a dict from it while using self.gameStructVars as keys data = dict(izip(self.gameStructVars, data)) # Remove unused keys @@ -334,8 +334,10 @@ def do_updateGame(self, data): except struct.error: return False + # Now update the game self.gameDB.updateGame(data['gameId'], data) + # Fix for bogus clients (<=2.3.7) which connect twice if not self.game: self.game = self.gameDB.getGaidGame(data['gameId'])