2
2
3
3
from direct .directnotify import DirectNotifyGlobal
4
4
from .ClientRepositoryBase import ClientRepositoryBase
5
- from .MsgTypes import *
5
+ from . import MsgTypes
6
6
from direct .distributed .PyDatagram import PyDatagram
7
7
from panda3d .direct import STUint16 , STUint32
8
8
9
+
9
10
class AstronClientRepository (ClientRepositoryBase ):
10
11
"""
11
12
The Astron implementation of a clients repository for
@@ -22,7 +23,7 @@ class AstronClientRepository(ClientRepositoryBase):
22
23
* LOST_CONNECTION ()
23
24
"""
24
25
25
- notify = DirectNotifyGlobal .directNotify .newCategory ("ClientRepository " )
26
+ notify = DirectNotifyGlobal .directNotify .newCategory ("AstronClientRepository " )
26
27
27
28
# This is required by DoCollectionManager, even though it's not
28
29
# used by this implementation.
@@ -31,37 +32,35 @@ class AstronClientRepository(ClientRepositoryBase):
31
32
def __init__ (self , * args , ** kwargs ):
32
33
ClientRepositoryBase .__init__ (self , * args , ** kwargs )
33
34
base .finalExitCallbacks .append (self .shutdown )
34
- self .message_handlers = {CLIENT_HELLO_RESP : self .handleHelloResp ,
35
- CLIENT_EJECT : self .handleEject ,
36
- CLIENT_ENTER_OBJECT_REQUIRED : self .handleEnterObjectRequired ,
37
- CLIENT_ENTER_OBJECT_REQUIRED_OWNER : self .handleEnterObjectRequiredOwner ,
38
- CLIENT_OBJECT_SET_FIELD : self .handleUpdateField ,
39
- CLIENT_OBJECT_SET_FIELDS : self .handleUpdateFields ,
40
- CLIENT_OBJECT_LEAVING : self .handleObjectLeaving ,
41
- CLIENT_OBJECT_LOCATION : self .handleObjectLocation ,
42
- CLIENT_ADD_INTEREST : self .handleAddInterest ,
43
- CLIENT_ADD_INTEREST_MULTIPLE : self .handleAddInterestMultiple ,
44
- CLIENT_REMOVE_INTEREST : self .handleRemoveInterest ,
45
- CLIENT_DONE_INTEREST_RESP : self .handleInterestDoneMessage ,
46
- }
35
+ self .message_handlers = {
36
+ MsgTypes .CLIENT_HELLO_RESP : self .handleHelloResp ,
37
+ MsgTypes .CLIENT_EJECT : self .handleEject ,
38
+ MsgTypes .CLIENT_ENTER_OBJECT_REQUIRED : self .handleEnterObjectRequired ,
39
+ MsgTypes .CLIENT_ENTER_OBJECT_REQUIRED_OWNER : self .handleEnterObjectRequiredOwner ,
40
+ MsgTypes .CLIENT_OBJECT_SET_FIELD : self .handleUpdateField ,
41
+ MsgTypes .CLIENT_OBJECT_SET_FIELDS : self .handleUpdateFields ,
42
+ MsgTypes .CLIENT_OBJECT_LEAVING : self .handleObjectLeaving ,
43
+ MsgTypes .CLIENT_OBJECT_LOCATION : self .handleObjectLocation ,
44
+ MsgTypes .CLIENT_ADD_INTEREST : self .handleAddInterest ,
45
+ MsgTypes .CLIENT_ADD_INTEREST_MULTIPLE : self .handleAddInterestMultiple ,
46
+ MsgTypes .CLIENT_REMOVE_INTEREST : self .handleRemoveInterest ,
47
+ MsgTypes .CLIENT_DONE_INTEREST_RESP : self .handleInterestDoneMessage ,
48
+ }
47
49
48
50
#
49
51
# Message Handling
50
52
#
51
53
52
54
def handleDatagram (self , di ):
53
55
msgType = self .getMsgType ()
54
- # self.handleMessageType(msgType, di)
55
- #
56
- #def handleMessageType(self, msgType, di):
57
56
if msgType in self .message_handlers :
58
57
self .message_handlers [msgType ](di )
59
58
else :
60
59
self .notify .error ("Got unknown message type %d!" % (msgType ,))
61
60
62
61
self .considerHeartbeat ()
63
62
64
- def handleHelloResp (self , di ):
63
+ def handleHelloResp (self , _ ):
65
64
messenger .send ("CLIENT_HELLO_RESP" , [])
66
65
67
66
def handleEject (self , di ):
@@ -127,19 +126,7 @@ def generateWithRequiredFieldsOwner(self, dclass, doId, di):
127
126
return distObj
128
127
129
128
def handleUpdateFields (self , di ):
130
- # Can't test this without the server actually sending it.
131
129
self .notify .error ("CLIENT_OBJECT_SET_FIELDS not implemented!" )
132
- # # Here's some tentative code and notes:
133
- # do_id = di.getUint32()
134
- # field_count = di.getUint16()
135
- # for i in range(0, field_count):
136
- # field_id = di.getUint16()
137
- # field = self.get_dc_file().get_field_by_index(field_id)
138
- # # print(type(field))
139
- # # print(field)
140
- # # FIXME: Get field type, unpack value, create and send message.
141
- # # value = di.get?()
142
- # # Assemble new message
143
130
144
131
def handleObjectLeaving (self , di ):
145
132
do_id = di .get_uint32 ()
@@ -201,35 +188,33 @@ def deleteObject(self, doId):
201
188
self .freeDoId (doId )
202
189
else :
203
190
# Otherwise, ignore it
204
- self .notify .warning (
205
- "Asked to delete non-existent DistObj " + str (doId ))
191
+ self .notify .warning ("Asked to delete non-existent DistObj " + str (doId ))
206
192
207
193
#
208
194
# Sending messages
209
195
#
210
196
211
197
def sendUpdate (self , distObj , fieldName , args ):
212
198
""" Sends a normal update for a single field. """
213
- dg = distObj .dclass .clientFormatUpdate (
214
- fieldName , distObj .doId , args )
199
+ dg = distObj .dclass .clientFormatUpdate (fieldName , distObj .doId , args )
215
200
self .send (dg )
216
201
217
202
# FIXME: The version string should default to a .prc variable.
218
203
def sendHello (self , version_string ):
219
204
dg = PyDatagram ()
220
- dg .add_uint16 (CLIENT_HELLO )
205
+ dg .add_uint16 (MsgTypes . CLIENT_HELLO )
221
206
dg .add_uint32 (self .get_dc_file ().get_hash ())
222
207
dg .add_string (version_string )
223
208
self .send (dg )
224
209
225
210
def sendHeartbeat (self ):
226
211
datagram = PyDatagram ()
227
- datagram .addUint16 (CLIENT_HEARTBEAT )
212
+ datagram .addUint16 (MsgTypes . CLIENT_HEARTBEAT )
228
213
self .send (datagram )
229
214
230
215
def sendAddInterest (self , context , interest_id , parent_id , zone_id ):
231
216
dg = PyDatagram ()
232
- dg .add_uint16 (CLIENT_ADD_INTEREST )
217
+ dg .add_uint16 (MsgTypes . CLIENT_ADD_INTEREST )
233
218
dg .add_uint32 (context )
234
219
dg .add_uint16 (interest_id )
235
220
dg .add_uint32 (parent_id )
@@ -238,7 +223,7 @@ def sendAddInterest(self, context, interest_id, parent_id, zone_id):
238
223
239
224
def sendAddInterestMultiple (self , context , interest_id , parent_id , zone_ids ):
240
225
dg = PyDatagram ()
241
- dg .add_uint16 (CLIENT_ADD_INTEREST_MULTIPLE )
226
+ dg .add_uint16 (MsgTypes . CLIENT_ADD_INTEREST_MULTIPLE )
242
227
dg .add_uint32 (context )
243
228
dg .add_uint16 (interest_id )
244
229
dg .add_uint32 (parent_id )
@@ -249,7 +234,7 @@ def sendAddInterestMultiple(self, context, interest_id, parent_id, zone_ids):
249
234
250
235
def sendRemoveInterest (self , context , interest_id ):
251
236
dg = PyDatagram ()
252
- dg .add_uint16 (CLIENT_REMOVE_INTEREST )
237
+ dg .add_uint16 (MsgTypes . CLIENT_REMOVE_INTEREST )
253
238
dg .add_uint32 (context )
254
239
dg .add_uint16 (interest_id )
255
240
self .send (dg )
0 commit comments