From ab97006ebbc0995417723e790bef14926b407c74 Mon Sep 17 00:00:00 2001 From: Open Toontown <57279094+opentoontown@users.noreply.github.com> Date: Sat, 1 Jan 2022 20:56:58 -0500 Subject: [PATCH] More work on OTP support --- direct/src/distributed/MsgTypesCMU.py | 9 +- .../src/distributed/cConnectionRepository.cxx | 97 +++++++++---------- 2 files changed, 51 insertions(+), 55 deletions(-) diff --git a/direct/src/distributed/MsgTypesCMU.py b/direct/src/distributed/MsgTypesCMU.py index e7c7501730..c86518d132 100644 --- a/direct/src/distributed/MsgTypesCMU.py +++ b/direct/src/distributed/MsgTypesCMU.py @@ -3,6 +3,8 @@ by the CMU ServerRepository/ClientRepository code in this directory. It replaces the MsgTypes module, which is not used by the CMU implementation. """ +from panda3d.core import ConfigVariableBool + from direct.showbase.PythonUtil import invertDictLossless MsgName2Id = { @@ -18,10 +20,13 @@ MsgName2Id = { 'OBJECT_SET_ZONE_CMU' : 9010, 'CLIENT_HEARTBEAT_CMU' : 9011, 'CLIENT_OBJECT_UPDATE_FIELD_TARGETED_CMU' : 9011, - - 'CLIENT_OBJECT_UPDATE_FIELD' : 120, # Matches MsgTypes.CLIENT_OBJECT_SET_FIELD } +if ConfigVariableBool('astron-support', True): + MsgName2Id['CLIENT_OBJECT_UPDATE_FIELD'] = 120 # Matches MsgTypes.CLIENT_OBJECT_SET_FIELD +else: + MsgName2Id['CLIENT_OBJECT_UPDATE_FIELD'] = 24 # Matches MsgTypes.CLIENT_OBJECT_UPDATE_FIELD + # create id->name table for debugging MsgId2Names = invertDictLossless(MsgName2Id) diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index 0182212759..771be2f5b9 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -303,61 +303,43 @@ check_datagram() { return true; } - // FIXME: This is despicable... - // There must be a better way of doing - // this... - if (astron_support) { // Astron - switch (_msg_type) { + unsigned int client_update_msg; + unsigned int stateserver_update_msg; + if (astron_support) + { + client_update_msg = CLIENT_OBJECT_SET_FIELD; + stateserver_update_msg = STATESERVER_OBJECT_SET_FIELD; + } + else + { + client_update_msg = CLIENT_OBJECT_UPDATE_FIELD; + stateserver_update_msg = STATESERVER_OBJECT_UPDATE_FIELD; + } + + switch (_msg_type) { #ifdef HAVE_PYTHON - case CLIENT_OBJECT_SET_FIELD: - case STATESERVER_OBJECT_SET_FIELD: - if (_handle_c_updates) { - if (_has_owner_view) { - if (!handle_update_field_owner()) { - return false; - } - } else { - if (!handle_update_field()) { - return false; - } + case client_update_msg: + case stateserver_update_msg: + if (_handle_c_updates) { + if (_has_owner_view) { + if (!handle_update_field_owner()) { + return false; } } else { - // Let the caller (Python) deal with this update. - return true; - } - break; -#endif // HAVE_PYTHON - - default: - // Some unknown message; let the caller deal with it. - return true; - } - } else { // OTP - switch (_msg_type) { -#ifdef HAVE_PYTHON - case CLIENT_OBJECT_UPDATE_FIELD: - case STATESERVER_OBJECT_UPDATE_FIELD: - if (_handle_c_updates) { - if (_has_owner_view) { - if (!handle_update_field_owner()) { - return false; - } - } else { - if (!handle_update_field()) { - return false; - } + if (!handle_update_field()) { + return false; } - } else { - // Let the caller (Python) deal with this update. - return true; } - break; -#endif // HAVE_PYTHON - - default: - // Some unknown message; let the caller deal with it. + } else { + // Let the caller (Python) deal with this update. return true; } + break; +#endif // HAVE_PYTHON + + default: + // Some unknown message; let the caller deal with it. + return true; } } @@ -522,7 +504,10 @@ send_message_bundle(unsigned int channel, unsigned int sender_channel) { dg.add_int8(1); dg.add_uint64(channel); dg.add_uint64(sender_channel); - //dg.add_uint16(STATESERVER_BOUNCE_MESSAGE); + if (!astron_support) + { + dg.add_uint16(STATESERVER_BOUNCE_MESSAGE); + } // add each bundled message BundledMsgVector::const_iterator bmi; for (bmi = _bundle_msgs.begin(); bmi != _bundle_msgs.end(); bmi++) { @@ -930,17 +915,23 @@ describe_message(std::ostream &out, const string &prefix, packer.RAW_UNPACK_CHANNEL(); // msg_sender msg_type = packer.raw_unpack_uint16(); - if (astron_support) { + if (astron_support) + { is_update = (msg_type == STATESERVER_OBJECT_SET_FIELD); - } else { + } + else + { is_update = (msg_type == STATESERVER_OBJECT_UPDATE_FIELD); } } else { msg_type = packer.raw_unpack_uint16(); - if (astron_support) { + if (astron_support) + { is_update = (msg_type == CLIENT_OBJECT_SET_FIELD); - } else { + } + else + { is_update = (msg_type == CLIENT_OBJECT_UPDATE_FIELD); } }