Skip to content

Commit

Permalink
Misc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
thetestgame committed Nov 12, 2024
1 parent a89d516 commit 9d2a7ce
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 117 deletions.
3 changes: 0 additions & 3 deletions panda3d_astron/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
from panda3d_astron import msgtypes
from panda3d_toolbox import runtime

# --------------------------------------------------------------------------------------------------------------------------------------------------------------------- #
# Panda3D ClientRepositoryBase implementation for implementing Astron clients

class AstronClientRepository(ClientRepositoryBase):
"""
The Astron implementation of a clients repository for
Expand Down
23 changes: 15 additions & 8 deletions panda3d_astron/interfaces/clientagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class ClientAgentInterface(object):
Network interface for the client agent.
"""

notify = DirectNotifyGlobal.directNotify.newCategory("client-agent")

def __init__(self, air: object):
"""
Initialize the client agent interface.
Expand All @@ -74,19 +72,28 @@ def __init__(self, air: object):
self.air = air
self.__callbacks = {}

@property
def notify(self) -> object:
"""
Retrieves the parent repositories notify object
"""

return self.air.notify

def handle_datagram(self, msg_type: int, di: object) -> None:
"""
Handles client agent datagrams
"""

if msg_type == msgtypes.CLIENTAGENT_GET_NETWORK_ADDRESS_RESP:
self.handle_get_network_address_resp(di)
elif msg_type == msgtypes.CLIENTAGENT_GET_CLIENTTLVS_RESP:
elif msg_type == msgtypes.CLIENTAGENT_GET_TLVS_RESP:
self.handle_get_tlvs_response(di)
elif msg_type == msgtypes.CLIENTAGENT_DONE_INTEREST_RESP:
self.handle_client_agent_interest_done_resp(di)
else:
self.notify.warning(f"Received unknown message type {msg_type} from client agent")
message_name = msgtypes.MsgId2Names.get(msg_type, str(msg_type))
self.notify.warning('Received unknown client agent message: %s' % message_name)

def set_client_state(self, clientChannel: int, state: int) -> None:
"""
Expand Down Expand Up @@ -150,7 +157,7 @@ def set_client_account_id(self, clientChannel: int, accountId: int) -> None:
"""

dg = PyDatagram()
dg.addServerHeader(clientChannel, self.air.ourChannel, msgtypes.CLIENTAGENT_SET_ACCOUNT_ID)
dg.addServerHeader(clientChannel, self.air.ourChannel, msgtypes.CLIENTAGENT_SET_CLIENT_ID)
dg.add_uint64(accountId << 32)

self.air.send(dg)
Expand All @@ -166,7 +173,7 @@ def set_client_avatar_id(self, clientChannel: int, avatarId: int) -> None:
"""

dg = PyDatagram()
dg.addServerHeader(clientChannel, self.air.ourChannel, msgtypes.CLIENTAGENT_SET_AVATAR_ID)
dg.addServerHeader(clientChannel, self.air.ourChannel, msgtypes.CLIENTAGENT_SET_CLIENT_ID)
dg.add_uint64(clientChannel << 32 | avatarId)

self.air.send(dg)
Expand All @@ -180,14 +187,14 @@ def remove_client_avatar_id(self, clientChannel: int) -> None:
"""

dg = PyDatagram()
dg.addServerHeader(clientChannel, self.air.ourChannel, msgtypes.CLIENTAGENT_SET_AVATAR_ID)
dg.addServerHeader(clientChannel, self.air.ourChannel, msgtypes.CLIENTAGENT_SET_CLIENT_ID)
dg.add_uint64(clientChannel << 32)

self.air.send(dg)

removeAvatarId = remove_client_avatar_id

def send_client_datagram(self, clientChannel: int, datagram: object) -> None:
def send_client_datagram(self, clientChannel: int, datagram: PyDatagram) -> None:
"""
Send a raw datagram down the pipe to the client. This is useful for sending app/game-specific messages to the client, debugging, etc.
"""
Expand Down
25 changes: 16 additions & 9 deletions panda3d_astron/interfaces/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class AstronDatabaseInterface:
dbInterface attribute.
"""

notify = DirectNotifyGlobal.directNotify.newCategory("AstronDatabaseInterface")

def __init__(self, air):
"""
Initialize the Astron database interface.
Expand All @@ -30,6 +28,14 @@ def __init__(self, air):
self._callbacks = {}
self._dclasses = {}

@property
def notify(self) -> object:
"""
Retrieves the parent repositories notify object
"""

return self.air.notify

def createObject(self, databaseId, dclass, fields={}, callback=None):
"""
Create an object in the specified database.
Expand Down Expand Up @@ -308,20 +314,21 @@ def handle_update_object_resp(self, di, multi):
finally:
del self._callbacks[ctx]

def handle_datagram(self, msgType: int, di: object) -> None:
def handle_datagram(self, msg_type: int, di: object) -> None:
"""
Handle a datagram from the database server.
"""

if msgType == DBSERVER_CREATE_OBJECT_RESP:
if msg_type == DBSERVER_CREATE_OBJECT_RESP:
self.handle_create_object_resp(di)
elif msgType in (DBSERVER_OBJECT_GET_ALL_RESP,
elif msg_type in (DBSERVER_OBJECT_GET_ALL_RESP,
DBSERVER_OBJECT_GET_FIELDS_RESP,
DBSERVER_OBJECT_GET_FIELD_RESP):
self.handle_query_object_resp(msgType, di)
elif msgType == DBSERVER_OBJECT_SET_FIELD_IF_EQUALS_RESP:
self.handle_query_object_resp(msg_type, di)
elif msg_type == DBSERVER_OBJECT_SET_FIELD_IF_EQUALS_RESP:
self.handle_update_object_resp(di, False)
elif msgType == DBSERVER_OBJECT_SET_FIELDS_IF_EQUALS_RESP:
elif msg_type == DBSERVER_OBJECT_SET_FIELDS_IF_EQUALS_RESP:
self.handle_update_object_resp(di, True)
else:
self.notify.warning('Received unknown database message: %d' % msgType)
message_name = MsgId2Names.get(msg_type, str(msg_type))
self.notify.warning('Received unknown database message: %s' % message_name)
8 changes: 8 additions & 0 deletions panda3d_astron/interfaces/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ def __init__(self, air: object):
else:
self.setEventLogHost(eventLogHost)

@property
def notify(self) -> object:
"""
Retrieves the parent repositories notify object
"""

return self.air.notify

def setEventLogHost(self, host, port=7197):
"""
Set the target host for Event Logger messaging. This should be pointed
Expand Down
Loading

0 comments on commit 9d2a7ce

Please sign in to comment.