formatting

This commit is contained in:
Dave Schuyler 2005-03-03 20:39:59 +00:00
parent 9774a2282e
commit 728483764d
2 changed files with 87 additions and 97 deletions

View File

@ -211,21 +211,21 @@ class ServerRepository:
type = dgi.getUint16() type = dgi.getUint16()
if type == CLIENT_DISCONNECT: if type == CLIENT_DISCONNECT:
self.handleClientDisconnect(datagram.getConnection()) self.handleClientDisconnect(datagram.getConnection())
elif type == CLIENT_SET_ZONE: elif type == CLIENT_SET_ZONE:
self.handleSetZone(dgi, datagram.getConnection()) self.handleSetZone(dgi, datagram.getConnection())
elif type == CLIENT_REMOVE_ZONE: elif type == CLIENT_REMOVE_ZONE:
self.handleRemoveZone(dgi, datagram.getConnection()) self.handleRemoveZone(dgi, datagram.getConnection())
elif type == CLIENT_CREATE_OBJECT_REQUIRED: elif type == CLIENT_CREATE_OBJECT_REQUIRED:
self.handleClientCreateObjectRequired(datagram, dgi) self.handleClientCreateObjectRequired(datagram, dgi)
elif type == CLIENT_OBJECT_UPDATE_FIELD: elif type == CLIENT_OBJECT_UPDATE_FIELD:
self.handleClientUpdateField(datagram, dgi) self.handleClientUpdateField(datagram, dgi)
elif type == CLIENT_OBJECT_DELETE: elif type == CLIENT_OBJECT_DELETE:
self.handleClientDeleteObject(datagram, dgi.getUint32()) self.handleClientDeleteObject(datagram, dgi.getUint32())
elif type == CLIENT_OBJECT_DISABLE: elif type == CLIENT_OBJECT_DISABLE:
self.handleClientDisable(datagram, dgi.getUint32()) self.handleClientDisable(datagram, dgi.getUint32())
else: else:
self.notify.error("unrecognized message") self.notify.error("unrecognized message")
# client wants to create an object, so we store appropriate data, # client wants to create an object, so we store appropriate data,
# and then pass message along to corresponding zones # and then pass message along to corresponding zones
@ -245,20 +245,19 @@ class ServerRepository:
datagram.appendData(rest) datagram.appendData(rest)
dclass = self.dclassesByNumber[classid] dclass = self.dclassesByNumber[classid]
if self.ClientObjects[connection].count(doid) == 0: if self.ClientObjects[connection].count(doid) == 0:
self.ClientObjects[connection].append(doid) self.ClientObjects[connection].append(doid)
self.DOIDtoZones[doid] = zone self.DOIDtoZones[doid] = zone
self.DOIDtoDClass[doid] = dclass self.DOIDtoDClass[doid] = dclass
if zone in self.ZonetoDOIDs: if zone in self.ZonetoDOIDs:
if self.ZonetoDOIDs[zone].count(doid)==0: if self.ZonetoDOIDs[zone].count(doid)==0:
self.ZonetoDOIDs[zone].append(doid) self.ZonetoDOIDs[zone].append(doid)
else: else:
self.ZonetoDOIDs[zone] = [doid] self.ZonetoDOIDs[zone] = [doid]
self.sendToZoneExcept(zone, datagram, connection) self.sendToZoneExcept(zone, datagram, connection)
return None
# client wants to update an object, forward message along # client wants to update an object, forward message along
# to corresponding zone # to corresponding zone
def handleClientUpdateField(self, datagram, dgi): def handleClientUpdateField(self, datagram, dgi):
connection = datagram.getConnection() connection = datagram.getConnection()
@ -282,28 +281,25 @@ class ServerRepository:
else: else:
self.notify.warning( self.notify.warning(
"Message is not broadcast, p2p, or broadcast+p2p") "Message is not broadcast, p2p, or broadcast+p2p")
return None
# client disables an object, let everyone know who is in # client disables an object, let everyone know who is in
# that zone know about it # that zone know about it
def handleClientDisable(self, datagram, doid): def handleClientDisable(self, datagram, doid):
# now send disable message to all clients that need to know # now send disable message to all clients that need to know
if doid in self.DOIDtoZones: if doid in self.DOIDtoZones:
self.sendToZoneExcept(self.DOIDtoZones[doid], datagram, 0) self.sendToZoneExcept(self.DOIDtoZones[doid], datagram, 0)
return None
# client deletes an object, let everyone who is in zone with # client deletes an object, let everyone who is in zone with
# object know about it # object know about it
def handleClientDeleteObject(self, datagram, doid): def handleClientDeleteObject(self, datagram, doid):
if doid in self.DOIDtoZones: if doid in self.DOIDtoZones:
self.sendToZoneExcept(self.DOIDtoZones[doid], datagram, 0) self.sendToZoneExcept(self.DOIDtoZones[doid], datagram, 0)
self.ClientObjects[datagram.getConnection()].remove(doid) self.ClientObjects[datagram.getConnection()].remove(doid)
self.ZonetoDOIDs[self.DOIDtoZones[doid]].remove(doid) self.ZonetoDOIDs[self.DOIDtoZones[doid]].remove(doid)
del self.DOIDtoZones[doid] del self.DOIDtoZones[doid]
del self.DOIDtoDClass[doid] del self.DOIDtoDClass[doid]
return None
def sendAvatarGenerate(self): def sendAvatarGenerate(self):
datagram = PyDatagram() datagram = PyDatagram()
@ -317,7 +313,7 @@ class ServerRepository:
datagram.addUint32(999) datagram.addUint32(999)
self.cw.send(datagram, self.lastConnection) self.cw.send(datagram, self.lastConnection)
# sends the client the range of doid's that the client can use # sends the client the range of doid's that the client can use
def sendDOIDrange(self, connection): def sendDOIDrange(self, connection):
# reuse DOID assignments if we can # reuse DOID assignments if we can
@ -331,87 +327,81 @@ class ServerRepository:
datagram.addUint32(self.DOIDrange) datagram.addUint32(self.DOIDrange)
print "Sending DOID range: ",id,self.DOIDrange print "Sending DOID range: ",id,self.DOIDrange
self.cw.send(datagram, connection) self.cw.send(datagram, connection)
return None
# a client disconnected from us, we need to update our data, also tell other clients to remove # a client disconnected from us, we need to update our data, also tell other clients to remove
# the disconnected clients objects # the disconnected clients objects
def handleClientDisconnect(self, connection): def handleClientDisconnect(self, connection):
if (self.ClientIP.has_key(connection)): if (self.ClientIP.has_key(connection)):
del self.DOIDtoClient[self.ClientDOIDbase[connection]] del self.DOIDtoClient[self.ClientDOIDbase[connection]]
for zone in self.ClientZones[connection]: for zone in self.ClientZones[connection]:
if len(self.ZonesToClients[zone]) == 1: if len(self.ZonesToClients[zone]) == 1:
del self.ZonesToClients[zone] del self.ZonesToClients[zone]
else: else:
self.ZonesToClients[zone].remove(connection) self.ZonesToClients[zone].remove(connection)
for obj in self.ClientObjects[connection]: for obj in self.ClientObjects[connection]:
#create and send delete message #create and send delete message
datagram = NetDatagram() datagram = NetDatagram()
datagram.addUint16(CLIENT_OBJECT_DELETE_RESP) datagram.addUint16(CLIENT_OBJECT_DELETE_RESP)
datagram.addUint32(obj) datagram.addUint32(obj)
self.sendToZoneExcept(self.DOIDtoZones[obj], datagram, 0) self.sendToZoneExcept(self.DOIDtoZones[obj], datagram, 0)
self.ZonetoDOIDs[self.DOIDtoZones[obj]].remove(obj) self.ZonetoDOIDs[self.DOIDtoZones[obj]].remove(obj)
del self.DOIDtoZones[obj] del self.DOIDtoZones[obj]
del self.DOIDtoDClass[obj] del self.DOIDtoDClass[obj]
del self.ClientIP[connection] del self.ClientIP[connection]
del self.ClientZones[connection] del self.ClientZones[connection]
del self.ClientDOIDbase[connection] del self.ClientDOIDbase[connection]
del self.ClientObjects[connection] del self.ClientObjects[connection]
return None
# client told us it's zone(s), store information # client told us it's zone(s), store information
def handleSetZone(self, dgi, connection): def handleSetZone(self, dgi, connection):
while dgi.getRemainingSize() > 0: while dgi.getRemainingSize() > 0:
ZoneID = dgi.getUint32() ZoneID = dgi.getUint32()
if self.ClientZones[connection].count(ZoneID) == 0: if self.ClientZones[connection].count(ZoneID) == 0:
self.ClientZones[connection].append(ZoneID) self.ClientZones[connection].append(ZoneID)
if ZoneID in self.ZonesToClients: if ZoneID in self.ZonesToClients:
if self.ZonesToClients[ZoneID].count(connection) == 0: if self.ZonesToClients[ZoneID].count(connection) == 0:
self.ZonesToClients[ZoneID].append(connection) self.ZonesToClients[ZoneID].append(connection)
else: else:
self.ZonesToClients[ZoneID] = [connection] self.ZonesToClients[ZoneID] = [connection]
# We have a new member, need to get all of the data from clients who may have objects in this zone # We have a new member, need to get all of the data from clients who may have objects in this zone
datagram = NetDatagram() datagram = NetDatagram()
datagram.addUint16(CLIENT_REQUEST_GENERATES) datagram.addUint16(CLIENT_REQUEST_GENERATES)
datagram.addUint32(ZoneID) datagram.addUint32(ZoneID)
self.sendToAll(datagram) self.sendToAll(datagram)
print "SENDING REQUEST GENERATES (",ZoneID,") TO ALL" print "SENDING REQUEST GENERATES (",ZoneID,") TO ALL"
return None
# client has moved zones, need to update them # client has moved zones, need to update them
def handleRemoveZone(self, dgi, connection): def handleRemoveZone(self, dgi, connection):
while dgi.getRemainingSize() > 0: while dgi.getRemainingSize() > 0:
ZoneID = dgi.getUint32() ZoneID = dgi.getUint32()
if self.ClientZones[connection].count(ZoneID) == 1: if self.ClientZones[connection].count(ZoneID) == 1:
self.ClientZones[connection].remove(ZoneID) self.ClientZones[connection].remove(ZoneID)
if ZoneID in self.ZonesToClients: if ZoneID in self.ZonesToClients:
if self.ZonesToClients[ZoneID].count(connection) == 1: if self.ZonesToClients[ZoneID].count(connection) == 1:
self.ZonesToClients[ZoneID].remove(connection) self.ZonesToClients[ZoneID].remove(connection)
for i in self.ZonetoDOIDs[ZoneID]: for i in self.ZonetoDOIDs[ZoneID]:
datagram = NetDatagram() datagram = NetDatagram()
datagram.addUint16(CLIENT_OBJECT_DELETE) datagram.addUint16(CLIENT_OBJECT_DELETE)
datagram.addUint32(i) datagram.addUint32(i)
self.cw.send(datagram, connection) self.cw.send(datagram, connection)
return None
# client did not tell us he was leaving but we lost connection to him, so we need to update our data and tell others # client did not tell us he was leaving but we lost connection to him, so we need to update our data and tell others
def clientHardDisconnectTask(self, task): def clientHardDisconnectTask(self, task):
for i in self.ClientIP.keys(): for i in self.ClientIP.keys():
if (not self.qcr.isConnectionOk(i)): if not self.qcr.isConnectionOk(i):
self.handleClientDisconnect(i) self.handleClientDisconnect(i)
return Task.cont return Task.cont
# sends a message to everyone who is in the zone # sends a message to everyone who is in the zone
def sendToZoneExcept(self, ZoneID, datagram, connection): def sendToZoneExcept(self, ZoneID, datagram, connection):
if ZoneID in self.ZonesToClients: if ZoneID in self.ZonesToClients:
for conn in self.ZonesToClients[ZoneID]: for conn in self.ZonesToClients[ZoneID]:
if (conn != connection): self.cw.send(datagram, conn) if (conn != connection):
return None self.cw.send(datagram, conn)
# sends a message to all connected clients # sends a message to all connected clients
def sendToAll(self, datagram): def sendToAll(self, datagram):
for client in self.ClientIP.keys(): for client in self.ClientIP.keys():
self.cw.send(datagram, client) self.cw.send(datagram, client)
return None