Changes to support messaging to multi target channels

This commit is contained in:
Roger Hughston 2005-07-07 00:10:57 +00:00
parent 18f7fa0d2e
commit 82fa7ab1e4
9 changed files with 79 additions and 27 deletions

View File

@ -869,9 +869,10 @@ ai_format_generate(PyObject *distobj, int do_id,
PyObject *optional_fields) const {
DCPacker packer;
packer.raw_pack_uint8(1);
packer.RAW_PACK_CHANNEL(district_channel_id);
packer.RAW_PACK_CHANNEL(from_channel_id);
packer.raw_pack_uint8('A');
//packer.raw_pack_uint8('A');
bool has_optional_fields = (PyObject_IsTrue(optional_fields) != 0);
@ -952,9 +953,10 @@ ai_database_generate_context(
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_uint8('A');
packer.raw_pack_uint16(STATESERVER_OBJECT_CREATE_WITH_REQUIRED_CONTEXT);
packer.raw_pack_uint32(parent_id);
packer.raw_pack_uint32(zone_id);

View File

@ -634,9 +634,10 @@ Datagram DCField::
ai_format_update(int do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyObject *args) const {
DCPacker packer;
packer.raw_pack_uint8(1);
packer.RAW_PACK_CHANNEL(to_id);
packer.RAW_PACK_CHANNEL(from_id);
packer.raw_pack_uint8('A');
//packer.raw_pack_uint8('A');
packer.raw_pack_uint16(STATESERVER_OBJECT_UPDATE_FIELD);
packer.raw_pack_uint32(do_id);
packer.raw_pack_uint16(_number);

View File

@ -62,12 +62,13 @@ class NetMessenger(Messenger):
assert self.notify.debugCall()
datagram = PyDatagram()
# To:
datagram.addUint8(1)
datagram.addChannel(self.channels[0])
# From:
datagram.addChannel(self.air.ourChannel)
if 1: # We send this just because the air expects it:
# Add an 'A' for AI
datagram.addUint8(ord('A'))
#if 1: # We send this just because the air expects it:
# # Add an 'A' for AI
# datagram.addUint8(ord('A'))
messageType=MESSAGE_STRINGS.get(message, 0)
datagram.addUint16(messageType)

View File

@ -6,6 +6,8 @@
from pandac.PandaModules import *
# Import the type numbers
from otp.ai.AIMsgTypes import *
class PyDatagram(Datagram):
# This is a little helper Dict to replace the huge <if> statement
@ -29,6 +31,30 @@ class PyDatagram(Datagram):
addChannel = Datagram.addUint64
def AddServerHeader(self, channel, sender, code):
self.addInt8(1)
self.addChannel(channel)
self.addChannel(sender)
self.addUint16(code)
def AddOldServerHeader(self, channel, sender, code):
self.addChannel(channel)
self.addChannel(sender)
self.addChannel('A')
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 putArg(self, arg, subatomicType, divisor=1):
if (divisor == 1):
funcSpecs = self.FuncDict.get(subatomicType)

View File

@ -142,8 +142,14 @@ get_datagram_iterator(DatagramIterator &di) {
// information is not available to the client.
////////////////////////////////////////////////////////////////////
INLINE CHANNEL_TYPE CConnectionRepository::
get_msg_channel() const {
return _msg_channel;
get_msg_channel(int offset) const {
nassertr(offset < (int)_msg_channels.size(),0);
return _msg_channels[offset];
}
INLINE int CConnectionRepository::
get_msg_channel_count() const {
return _msg_channels.size();
}
////////////////////////////////////////////////////////////////////
@ -165,10 +171,10 @@ get_msg_sender() const {
// message, according to the datagram headers. This
// information is not available to the client.
////////////////////////////////////////////////////////////////////
INLINE unsigned char CConnectionRepository::
get_sec_code() const {
return _sec_code;
}
//INLINE unsigned char CConnectionRepository::
//get_sec_code() const {
// return _sec_code;
//}
////////////////////////////////////////////////////////////////////
// Function: CConnectionRepository::get_msg_type

View File

@ -55,9 +55,8 @@ CConnectionRepository() :
_client_datagram(true),
_simulated_disconnect(false),
_verbose(distributed_cat.is_spam()),
_msg_channel(0),
// _msg_channels(),
_msg_sender(0),
_sec_code(0),
_msg_type(0)
{
#if defined(HAVE_NSPR) && defined(SIMULATE_NETWORK_DELAY)
@ -145,10 +144,16 @@ check_datagram() {
// Start breaking apart the datagram.
_di = DatagramIterator(_dg);
if (!_client_datagram) {
_msg_channel = _di.get_uint64();
if (!_client_datagram)
{
unsigned char wc_cnt;
wc_cnt = _di.get_uint8();
for(unsigned char lp1 = 0; lp1 < wc_cnt; lp1++)
{
CHANNEL_TYPE schan = _di.get_uint64();
_msg_channels.push_back(schan);
}
_msg_sender = _di.get_uint64();
_sec_code = _di.get_uint8();
#ifdef HAVE_PYTHON
// For now, we need to stuff this field onto the Python
@ -459,10 +464,13 @@ describe_message(ostream &out, const string &prefix,
int msg_type;
bool is_update = false;
if (!_client_datagram) {
packer.RAW_UNPACK_CHANNEL(); // msg_channel
if (!_client_datagram)
{
unsigned char mcnt = packer.raw_unpack_uint8();
for( ;mcnt > 0; mcnt--)
packer.RAW_UNPACK_CHANNEL(); // msg_channel
packer.RAW_UNPACK_CHANNEL(); // msg_sender
packer.raw_unpack_uint8(); // sec_code
msg_type = packer.raw_unpack_uint16();
is_update = (msg_type == STATESERVER_OBJECT_UPDATE_FIELD);

View File

@ -81,9 +81,10 @@ PUBLISHED:
bool check_datagram();
INLINE void get_datagram(Datagram &dg);
INLINE void get_datagram_iterator(DatagramIterator &di);
INLINE CHANNEL_TYPE get_msg_channel() const;
INLINE CHANNEL_TYPE get_msg_channel(int offset = 0) const;
INLINE int get_msg_channel_count() const;
INLINE CHANNEL_TYPE get_msg_sender() const;
INLINE unsigned char get_sec_code() const;
// INLINE unsigned char get_sec_code() const;
INLINE unsigned int get_msg_type() const;
INLINE static const string &get_overflow_event_name();
@ -137,10 +138,10 @@ private:
Datagram _dg;
DatagramIterator _di;
CHANNEL_TYPE _msg_channel;
CHANNEL_TYPE _msg_sender;
unsigned char _sec_code;
unsigned int _msg_type;
std::vector<CHANNEL_TYPE> _msg_channels;
CHANNEL_TYPE _msg_sender;
unsigned int _msg_type;
static const string _overflow_event_name;

View File

@ -248,9 +248,11 @@ begin_send_update(DCPacker &packer, const string &field_name) {
nassertv(field != (DCField *)NULL);
if (_is_ai) {
packer.raw_pack_uint8(1);
packer.RAW_PACK_CHANNEL(_do_id);
packer.RAW_PACK_CHANNEL(_ai_id);
packer.raw_pack_uint8('A');
//packer.raw_pack_uint8('A');
packer.raw_pack_uint16(STATESERVER_OBJECT_UPDATE_FIELD);
packer.raw_pack_uint32(_do_id);
packer.raw_pack_uint16(field->get_number());

View File

@ -196,6 +196,11 @@ class Messenger:
self.__methodRepr(method),
tuple(extraArgs + sentArgs))
#print "Messenger: \"%s\" --> %s%s"%(
# event,
# self.__methodRepr(method),
# tuple(extraArgs + sentArgs))
# It is important to make the actual call here, after
# we have cleaned up the accept hook, because the
# method itself might call accept() or acceptOnce()