distributed: Replace the OTP protocol format with Astron's

Again, all this does is affect the 4-years-disused OTP system, leaving
the CMU system entirely untouched.

This changes the packet formatting in several of distributed's helper
classes.
This commit is contained in:
Sam Edwards 2018-02-23 16:45:50 -07:00
parent 167c6dcafa
commit f76b8a6ad8
6 changed files with 31 additions and 122 deletions

View File

@ -514,15 +514,9 @@ receive_update_broadcast_required_owner(PyObject *distobj,
for (int i = 0; i < num_fields && !PyErr_Occurred(); ++i) {
DCField *field = get_inherited_field(i);
if (field->as_molecular_field() == (DCMolecularField *)NULL &&
field->is_required()) {
field->is_required() && (field->is_ownrecv() || field->is_broadcast())) {
packer.begin_unpack(field);
if (field->is_ownrecv()) {
field->receive_update(packer, distobj);
} else {
// It's not an ownrecv field; skip over it. It's difficult to filter
// this on the server, ask Roger for the reason.
packer.unpack_skip();
}
if (!packer.end_unpack()) {
break;
}
@ -951,14 +945,12 @@ ai_format_generate(PyObject *distobj, DOID_TYPE do_id,
packer.raw_pack_uint16(STATESERVER_CREATE_OBJECT_WITH_REQUIRED);
}
packer.raw_pack_uint32(do_id);
// Parent is a bit overloaded; this parent is not about inheritance, this
// one is about the visibility container parent, i.e. the zone parent:
if (parent_id) {
packer.raw_pack_uint32(parent_id);
}
packer.raw_pack_uint32(zone_id);
packer.raw_pack_uint16(_number);
packer.raw_pack_uint32(do_id);
// Specify all of the required fields.
int num_fields = get_num_inherited_fields();
@ -1009,77 +1001,6 @@ ai_format_generate(PyObject *distobj, DOID_TYPE do_id,
return Datagram(packer.get_data(), packer.get_length());
}
#endif // HAVE_PYTHON
#ifdef HAVE_PYTHON
/**
* Generates a datagram containing the message necessary to create a new
* database distributed object from the AI.
*
* First Pass is to only include required values (with Defaults).
*/
Datagram DCClass::
ai_database_generate_context(
unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id,
CHANNEL_TYPE owner_channel,
CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const
{
DCPacker packer;
packer.raw_pack_uint8(1);
packer.RAW_PACK_CHANNEL(database_server_id);
packer.RAW_PACK_CHANNEL(from_channel_id);
// packer.raw_pack_uint8('A');
packer.raw_pack_uint16(STATESERVER_OBJECT_ENTER_WITH_REQUIRED_CONTEXT);
packer.raw_pack_uint32(parent_id);
packer.raw_pack_uint32(zone_id);
packer.RAW_PACK_CHANNEL(owner_channel);
packer.raw_pack_uint16(_number); // DCD class ID
packer.raw_pack_uint32(context_id);
// Specify all of the required fields.
int num_fields = get_num_inherited_fields();
for (int i = 0; i < num_fields; ++i) {
DCField *field = get_inherited_field(i);
if (field->is_required() && field->as_molecular_field() == NULL) {
packer.begin_pack(field);
packer.pack_default_value();
packer.end_pack();
}
}
return Datagram(packer.get_data(), packer.get_length());
}
#endif // HAVE_PYTHON
#ifdef HAVE_PYTHON
Datagram DCClass::
ai_database_generate_context_old(
unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id,
CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const
{
DCPacker packer;
packer.raw_pack_uint8(1);
packer.RAW_PACK_CHANNEL(database_server_id);
packer.RAW_PACK_CHANNEL(from_channel_id);
// packer.raw_pack_uint8('A');
packer.raw_pack_uint16(STATESERVER_OBJECT_ENTER_WITH_REQUIRED_CONTEXT);
packer.raw_pack_uint32(parent_id);
packer.raw_pack_uint32(zone_id);
packer.raw_pack_uint16(_number); // DCD class ID
packer.raw_pack_uint32(context_id);
// Specify all of the required fields.
int num_fields = get_num_inherited_fields();
for (int i = 0; i < num_fields; ++i) {
DCField *field = get_inherited_field(i);
if (field->is_required() && field->as_molecular_field() == NULL) {
packer.begin_pack(field);
packer.pack_default_value();
packer.end_pack();
}
}
return Datagram(packer.get_data(), packer.get_length());
}
#endif // HAVE_PYTHON
/**
* Write a string representation of this instance to <out>.

View File

@ -117,11 +117,6 @@ PUBLISHED:
Datagram client_format_generate_CMU(PyObject *distobj, DOID_TYPE do_id,
ZONEID_TYPE zone_id, PyObject *optional_fields) const;
Datagram ai_database_generate_context(unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id, CHANNEL_TYPE owner_channel,
CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const;
Datagram ai_database_generate_context_old(unsigned int context_id, DOID_TYPE parent_id, ZONEID_TYPE zone_id,
CHANNEL_TYPE database_server_id, CHANNEL_TYPE from_channel_id) const;
#endif
public:

View File

@ -146,8 +146,6 @@ class DistributedObjectAI(DistributedObjectBase):
barrier.cleanup()
self.__barriers = {}
self.air.stopTrackRequestDeletedDO(self)
# DCR: I've re-enabled this block of code so that Toontown's
# AI won't leak channels.
# Let me know if it causes trouble.
@ -155,9 +153,8 @@ class DistributedObjectAI(DistributedObjectBase):
### block until a solution is thought out of how to prevent
### this delete message or to handle this message better
# TODO: do we still need this check?
if not hasattr(self, "doNotDeallocateChannel"):
if self.air and not hasattr(self.air, "doNotDeallocateChannel"):
if self.air.minChannel <= self.doId <= self.air.maxChannel:
if not getattr(self, "doNotDeallocateChannel", False):
if self.air:
self.air.deallocateChannel(self.doId)
self.air = None
@ -200,9 +197,6 @@ class DistributedObjectAI(DistributedObjectBase):
"""
pass
def addInterest(self, zoneId, note="", event=None):
self.air.addInterest(self.doId, zoneId, note, event)
def b_setLocation(self, parentId, zoneId):
self.d_setLocation(parentId, zoneId)
self.setLocation(parentId, zoneId)
@ -274,9 +268,6 @@ class DistributedObjectAI(DistributedObjectBase):
dclass.receiveUpdateOther(self, di)
def sendSetZone(self, zoneId):
self.air.sendSetZone(self, zoneId)
def startMessageBundle(self, name):
self.air.startMessageBundle(name)
def sendMessageBundle(self):
@ -349,10 +340,10 @@ class DistributedObjectAI(DistributedObjectBase):
self.air.sendUpdate(self, fieldName, args)
def GetPuppetConnectionChannel(self, doId):
return doId + (1 << 32)
return doId + (1001L << 32)
def GetAccountConnectionChannel(self, doId):
return doId + (3 << 32)
return doId + (1003L << 32)
def GetAccountIDFromChannelCode(self, channel):
return channel >> 32
@ -482,7 +473,6 @@ class DistributedObjectAI(DistributedObjectBase):
(self.__class__, doId))
return
self.air.requestDelete(self)
self.air.startTrackRequestDeletedDO(self)
self._DOAI_requestedDelete = True
def taskName(self, taskString):
@ -581,3 +571,5 @@ class DistributedObjectAI(DistributedObjectBase):
""" This is a no-op on the AI. """
pass
def setAI(self, aiChannel):
self.air.setAI(self.doId, aiChannel)

View File

@ -270,10 +270,10 @@ class DistributedObjectUD(DistributedObjectBase):
self.air.sendUpdate(self, fieldName, args)
def GetPuppetConnectionChannel(self, doId):
return doId + (1 << 32)
return doId + (1001L << 32)
def GetAccountConnectionChannel(self, doId):
return doId + (3 << 32)
return doId + (1003L << 32)
def GetAccountIDFromChannelCode(self, channel):
return channel >> 32

View File

@ -111,7 +111,7 @@ class DoInterestManager(DirectObject.DirectObject):
self._allInterestsCompleteCallbacks = []
def __verbose(self):
return self.InterestDebug or self.getVerbose()
return self.InterestDebug.getValue() or self.getVerbose()
def _getAnonymousEvent(self, desc):
return 'anonymous-%s-%s' % (desc, DoInterestManager._SerialGen.next())
@ -504,17 +504,22 @@ class DoInterestManager(DirectObject.DirectObject):
'trying to set interest to invalid parent: %s' % parentId)
datagram = PyDatagram()
# Add message type
datagram.addUint16(CLIENT_ADD_INTEREST)
datagram.addUint16(handle)
datagram.addUint32(contextId)
datagram.addUint32(parentId)
if isinstance(zoneIdList, list):
vzl = list(zoneIdList)
vzl.sort()
uniqueElements(vzl)
datagram.addUint16(CLIENT_ADD_INTEREST_MULTIPLE)
datagram.addUint32(contextId)
datagram.addUint16(handle)
datagram.addUint32(parentId)
datagram.addUint16(len(vzl))
for zone in vzl:
datagram.addUint32(zone)
else:
datagram.addUint16(CLIENT_ADD_INTEREST)
datagram.addUint32(contextId)
datagram.addUint16(handle)
datagram.addUint32(parentId)
datagram.addUint32(zoneIdList)
self.send(datagram)
@ -530,9 +535,8 @@ class DoInterestManager(DirectObject.DirectObject):
datagram = PyDatagram()
# Add message type
datagram.addUint16(CLIENT_REMOVE_INTEREST)
datagram.addUint16(handle)
if contextId != 0:
datagram.addUint32(contextId)
datagram.addUint16(handle)
self.send(datagram)
if __debug__:
state = DoInterestManager._interests[handle]
@ -583,8 +587,8 @@ class DoInterestManager(DirectObject.DirectObject):
This handles the interest done messages and may dispatch an event
"""
assert DoInterestManager.notify.debugCall()
handle = di.getUint16()
contextId = di.getUint32()
handle = di.getUint16()
if self.__verbose():
print('CR::INTEREST.interestDone(handle=%s)' % handle)
DoInterestManager.notify.debug(

View File

@ -7,7 +7,7 @@ from panda3d.core import Datagram
from panda3d.direct import *
# Import the type numbers
#from otp.ai.AIMsgTypes import *
from direct.distributed.MsgTypes import *
class PyDatagram(Datagram):
@ -47,13 +47,10 @@ class PyDatagram(Datagram):
self.addUint16(code)
# def addServerControlHeader(self, code):
# self.addInt8(1)
# self.addChannel(CONTROL_MESSAGE)
# self.addUint16(code)
# def addOldServerControlHeader(self, code):
# self.addChannel(CONTROL_MESSAGE)
# self.addUint16(code)
def addServerControlHeader(self, code):
self.addInt8(1)
self.addChannel(CONTROL_CHANNEL)
self.addUint16(code)
def putArg(self, arg, subatomicType, divisor=1):
if (divisor == 1):