diff --git a/direct/src/distributed/AstronInternalRepository.py b/direct/src/distributed/AstronInternalRepository.py index 9d373cea84..0e8eb30869 100644 --- a/direct/src/distributed/AstronInternalRepository.py +++ b/direct/src/distributed/AstronInternalRepository.py @@ -244,6 +244,8 @@ class AstronInternalRepository(ConnectionRepository): self.handleGetLocationResp(di) elif msgType == STATESERVER_OBJECT_GET_ALL_RESP: self.handleGetObjectResp(di) + elif msgType == CLIENTAGENT_GET_NETWORK_ADDRESS_RESP: + self.handleGetNetworkAddressResp(di) elif msgType >= 20000: # These messages belong to the NetMessenger: self.netMessenger.handle(msgType, di) @@ -422,6 +424,39 @@ class AstronInternalRepository(ConnectionRepository): finally: del self.__callbacks[ctx] + def getNetworkAddress(self, clientId, callback): + """ + Get the endpoints of a client connection. + + You should already be sure the client actually exists, otherwise the + callback will never be called. + + Callback is called as: callback(remoteIp, remotePort, localIp, localPort) + """ + + ctx = self.getContext() + self.__callbacks[ctx] = callback + dg = PyDatagram() + dg.addServerHeader(clientId, self.ourChannel, CLIENTAGENT_GET_NETWORK_ADDRESS) + dg.addUint32(ctx) + self.send(dg) + + def handleGetNetworkAddressResp(self, di): + ctx = di.getUint32() + remoteIp = di.getString() + remotePort = di.getUint16() + localIp = di.getString() + localPort = di.getUint16() + + if ctx not in self.__callbacks: + self.notify.warning('Received unexpected CLIENTAGENT_GET_NETWORK_ADDRESS_RESP (ctx: %d)' % ctx) + return + + try: + self.__callbacks[ctx](remoteIp, remotePort, localIp, localPort) + finally: + del self.__callbacks[ctx] + def sendUpdate(self, do, fieldName, args): """ Send a field update for the given object. diff --git a/direct/src/distributed/MsgTypes.py b/direct/src/distributed/MsgTypes.py index 768294ac22..14ce6ba55e 100644 --- a/direct/src/distributed/MsgTypes.py +++ b/direct/src/distributed/MsgTypes.py @@ -123,6 +123,8 @@ MsgName2Id = { 'CLIENTAGENT_SEND_DATAGRAM': 1002, 'CLIENTAGENT_EJECT': 1004, 'CLIENTAGENT_DROP': 1005, + 'CLIENTAGENT_GET_NETWORK_ADDRESS': 1006, + 'CLIENTAGENT_GET_NETWORK_ADDRESS_RESP': 1007, 'CLIENTAGENT_DECLARE_OBJECT': 1010, 'CLIENTAGENT_UNDECLARE_OBJECT': 1011, 'CLIENTAGENT_ADD_SESSION_OBJECT': 1012,