Пример #1
0
        //---------------------------------------------------------------------
        internal void _onRpcMethod(RpcSession session, byte from_node, ushort method_id, Dictionary <byte, object> map_param)
        {
            if (!mMapRpcSlot.ContainsKey(from_node))
            {
                EbLog.Error("EntityDef._onRpcMethod() not found from_node. from_node = " + from_node);
                return;
            }

            Dictionary <ushort, RpcSlot> m = mMapRpcSlot[from_node];

            if (!m.ContainsKey(method_id))
            {
                EbLog.Error("EntityDef._onRpcMethod() not found method_id. method_id = " + method_id);
                return;
            }

            try
            {
                if (m[method_id] != null)
                {
                    m[method_id](session, map_param);
                }
            }
            catch (System.Exception ec)
            {
                EbLog.Error(ec.ToString());
            }
        }
Пример #2
0
        //---------------------------------------------------------------------
        void _sendRpcProxy(byte to_node, Entity proxy_entity, ref _tEntityRpcData data)
        {
            RpcSession session = proxy_entity.getSession(to_node);

            if (session != null)
            {
                session.sendEntityRpcData(ref data);
            }
        }
Пример #3
0
        //---------------------------------------------------------------------
        void _sendRpcOne(byte to_node, ref _tEntityRpcData data)
        {
            RpcSession s = Entity.getSession(to_node);

            if (s != null)
            {
                s.sendEntityRpcData(ref data);
            }
        }
Пример #4
0
 //---------------------------------------------------------------------
 internal void _rpcOnComponentSyncProp(RpcSession session, byte from_node, ushort component_id,
                                       ushort reason, Dictionary <string, string> map_prop)
 {
     foreach (var i in mMapComponent)
     {
         if (i.Value.getDef().getComponentId() == component_id)
         {
             i.Value._onRpcPropSync(session, from_node, reason, map_prop);
             return;
         }
     }
 }
Пример #5
0
        //---------------------------------------------------------------------
        void _sendRpcProxyGroup(byte to_node, List <Entity> list_proxy, ref _tEntityRpcData data)
        {
            if (list_proxy == null)
            {
                return;
            }

            foreach (var i in list_proxy)
            {
                RpcSession session = i.getSession(to_node);
                if (session != null)
                {
                    session.sendEntityRpcData(ref data);
                }
            }
        }
Пример #6
0
        //---------------------------------------------------------------------
        internal override void _onRpcPropSync(RpcSession session, byte from_node,
                                              ushort reason, Dictionary <string, string> map_prop)
        {
            if (map_prop != null)
            {
                foreach (var i in map_prop)
                {
                    IProp prop = mDef.getProp(i.Key);
                    if (prop == null)
                    {
                        continue;
                    }
                    prop.fromJsonString(i.Value);
                }
            }

            onRpcPropSync(session, from_node, reason);
        }
Пример #7
0
        //---------------------------------------------------------------------
        void _sendRpcProxyAll(byte to_node, ref _tEntityRpcData data)
        {
            Dictionary <ulong, Entity> m = Entity._getMapProxyEntity(to_node);

            if (m == null)
            {
                return;
            }

            foreach (var i in m)
            {
                RpcSession session = i.Value.getSession(to_node);
                if (session != null)
                {
                    session.sendEntityRpcData(ref data);
                }
            }
        }
Пример #8
0
        //---------------------------------------------------------------------
        public void rpc(RpcSession s, byte to_node, ushort method_id, Dictionary <byte, object> map_param)
        {
            uint  id = 0;
            byte  local_node_type = NodeType;
            ulong entity_rpcid    = 0xffffffffffffffff;

            entity_rpcid &= ((ulong)local_node_type) << 32;
            entity_rpcid |= (ulong)id;

            _tEntityRpcData data;

            data.rpc_id       = _tEntityRpcData.from((byte)_eRpcCmd.NodeMethod, to_node, entity_rpcid);
            data.from_node    = NodeType;
            data.method_id    = (short)method_id;
            data.map_param    = map_param;
            data.session_recv = null;

            if (s != null)
            {
                // 直接发送
                s.sendEntityRpcData(ref data);
            }
        }
Пример #9
0
 //---------------------------------------------------------------------
 //[EntityRpcMethod(_eEtNode.Anonymous)],定义NodeType,与Rpc委托比较校验函数参数
 public void cell2clientLogin(RpcSession s, Dictionary <byte, object> map_param)
 {
 }
Пример #10
0
 //---------------------------------------------------------------------
 internal abstract void _onRpcPropSync(RpcSession session, byte from_node,
                                       ushort reason, Dictionary <string, string> map_prop);
Пример #11
0
 //---------------------------------------------------------------------
 public abstract void onRpcPropSync(RpcSession session, byte from_node, ushort reason);
Пример #12
0
 //---------------------------------------------------------------------
 public override void onRpcPropSync(RpcSession session, byte from_node, ushort reason)
 {
 }
Пример #13
0
        //---------------------------------------------------------------------
        // 该函数执行在主线程中
        void _onEntityRpcData(ref _tEntityRpcData data)
        {
            byte  cmd_id       = 0;
            byte  to_node      = 0;
            ulong entity_rpcid = 0;

            _tEntityRpcData.to(data.rpc_id, out cmd_id, out to_node, out entity_rpcid);
            ushort   method_id = (ushort)data.method_id;
            _eRpcCmd c         = (_eRpcCmd)cmd_id;

            // 需要路由转发
            if (mEntityMgr.NodeType != to_node)
            {
                if (cmd_id == (byte)_eRpcCmd.NodeMethod)
                {
                    // log warning
                    return;
                }

                Entity et_proxy = data.session_recv.getProxyEntity();
                if (et_proxy != null)
                {
                    RpcSession s = et_proxy.getSession(to_node);
                    if (s == null)
                    {
                        return;
                    }
                    s.sendEntityRpcData(ref data);
                    return;
                }

                Entity et = mEntityMgr.findEntity(entity_rpcid);
                if (et != null)
                {
                    RpcSession s = et.getSession(to_node);
                    if (s == null)
                    {
                        return;
                    }
                    s.sendEntityRpcData(ref data);
                    return;
                }
            }

            // 无需路由转发
            if (cmd_id == (byte)_eRpcCmd.EntityMethod)
            {
                Entity et = mEntityMgr.findEntity(entity_rpcid);
                if (et == null)
                {
                    // log warning
                    return;
                }
                else
                {
                    et._rpcOnEntityMethod(data.session_recv, data.from_node, method_id, data.map_param);
                }
            }
            else if (cmd_id == (byte)_eRpcCmd.ComponentSyncProp)
            {
                Entity et = mEntityMgr.findEntity(entity_rpcid);
                if (et == null)
                {
                    // log warning
                    return;
                }
                else
                {
                    ushort reason = (ushort)(short)data.map_param[0];
                    Dictionary <string, string> map_prop = (Dictionary <string, string>)data.map_param[1];
                    et._rpcOnComponentSyncProp(data.session_recv, data.from_node, method_id, reason, map_prop);
                }
            }
            else if (cmd_id == (byte)_eRpcCmd.EntityCreate)
            {
                // 需要检查entity的创建权限,默认为不可远程创建

                Entity et = mEntityMgr.findEntity(entity_rpcid);
                if (et != null)
                {
                    // log warning
                    return;
                }

                EntityData entity_data = new EntityData();
                entity_data.entity_type      = (string)data.map_param[0];
                entity_data.entity_guid      = (string)data.map_param[1];
                entity_data.entity_rpcid     = (ulong)(long)data.map_param[2];
                entity_data.cache_data       = null;
                entity_data.entity_children  = null;
                entity_data.entity_transform = new EntityTransform();
                entity_data.entity_transform.fromDic((Dictionary <byte, object>)data.map_param[3]);
                entity_data.list_component = new List <ComponentData>();
                ComponentData co_data = new ComponentData();
                co_data.component_name = (string)data.map_param[4];
                co_data.def_propset    = null;
                entity_data.list_component.Add(co_data);

                EntityMgrListener listener = mEntityMgr._getListener();
                if (listener == null)
                {
                    return;
                }
                Entity et_new = listener.onRpcEntityCreateRemote(data.session_recv,
                                                                 entity_data, data.method_id == 0 ? false : true);

                var ev = mEntityMgr.getDefaultEventPublisher().genEvent <EvEntityCreateRemote>();
                ev.entity      = et_new;
                ev.entity_data = entity_data;
                ev.send(null);
            }
            else if (cmd_id == (byte)_eRpcCmd.EntityDestroy)
            {
                // 需要检查entity的销毁权限,默认为不可远程销毁

                Entity et = mEntityMgr.findEntity(entity_rpcid);
                if (et == null)
                {
                    return;
                }

                mEntityMgr.destroyEntity(entity_rpcid);
            }
            else if (cmd_id == (byte)_eRpcCmd.NodeMethod)
            {
                EntityMgrListener listener = mEntityMgr._getListener();
                if (listener == null)
                {
                    return;
                }
                listener.onRpcNodeMethod(data.session_recv, data.from_node, method_id, data.map_param);
            }
            else
            {
                EbLog.Error("RpcDispatch._onEntityRpcData() Error! cmd_id=" + cmd_id.ToString());
            }
        }
Пример #14
0
 //---------------------------------------------------------------------
 internal void _rpcOnEntityMethod(RpcSession session, byte from_node,
                                  ushort method_id, Dictionary <byte, object> map_param)
 {
     mEntityDef._onRpcMethod(session, from_node, method_id, map_param);
 }
Пример #15
0
 //---------------------------------------------------------------------
 public void setSession(byte to_node, RpcSession session)
 {
     mMapSessionOne2One[to_node] = session;
 }