Skip to content

Commit

Permalink
Fixes the wzlobby.protocl.ProtocolSwitcher and
Browse files Browse the repository at this point in the history
adds some spelling fixes.
  • Loading branch information
jochumdev committed Jan 25, 2011
1 parent 9f584c9 commit 9b609f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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
-----------
Expand All @@ -35,7 +35,7 @@ start
cd <your clone>
./bin/wzlobbyserver.py

stop it
stop
----

cd <your clone>
Expand Down
3 changes: 0 additions & 3 deletions wzlobby/game.py
Expand Up @@ -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:
Expand Down
20 changes: 11 additions & 9 deletions wzlobby/protocol.py
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -91,7 +93,7 @@ def _detectProtocolVersion(self, data):
""" I detect a "version\0<version#>" Packet
"""
try:
data = struct.unpack('!8sI', data)
data = struct.unpack('!8sI', data[0:12])
if data[0] == "version\0":
return data[1]
else:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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'])

Expand Down

0 comments on commit 9b609f8

Please sign in to comment.