minor changes

This commit is contained in:
Dave Schuyler 2005-03-03 20:31:35 +00:00
parent 6ea8f2e856
commit dd93d996e4

View File

@ -1,6 +1,7 @@
from cPickle import dumps, loads from cPickle import dumps, loads
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.PyDatagram import PyDatagram from direct.distributed.PyDatagram import PyDatagram
from direct.showbase.Messenger import Messenger from direct.showbase.Messenger import Messenger
@ -13,13 +14,15 @@ from direct.showbase.Messenger import Messenger
MESSAGE_TYPES=( MESSAGE_TYPES=(
"avatarOnline", "avatarOnline",
"avatarOffline", "avatarOffline",
"create",
"needUberdogCreates",
) )
# This is the reverse look up for the recipient of the # This is the reverse look up for the recipient of the
# datagram: # datagram:
MESSAGE_STRINGS={} MESSAGE_STRINGS={}
for mt, i in MESSAGE_TYPES, range(1, len(MESSAGE_TYPES)+1): for i in zip(MESSAGE_TYPES, range(1, len(MESSAGE_TYPES)+1)):
MESSAGE_STRINGS[mt]=i MESSAGE_STRINGS[i[0]]=i[1]
class NetMessenger(Messenger): class NetMessenger(Messenger):
@ -28,6 +31,9 @@ class NetMessenger(Messenger):
are sent over the network and (possibly) handled (accepted) on a are sent over the network and (possibly) handled (accepted) on a
remote machine (server). remote machine (server).
""" """
if __debug__:
notify = DirectNotifyGlobal.directNotify.newCategory('NetMessenger')
def __init__(self, air, channels): def __init__(self, air, channels):
""" """
air is the AI Repository. air is the AI Repository.
@ -61,8 +67,10 @@ class NetMessenger(Messenger):
messageType=MESSAGE_STRINGS.get(message, 0) messageType=MESSAGE_STRINGS.get(message, 0)
datagram.addUint16(messageType) datagram.addUint16(messageType)
if messageType:
datagram.addString(str(dumps((message, sentArgs)))) datagram.addString(str(dumps(sentArgs)))
else:
datagram.addString(str(dumps((message, sentArgs))))
self.air.send(datagram) self.air.send(datagram)
def handle(self, pickleData): def handle(self, pickleData):