Exemple #1
0
 public void delRspd(NetCmd pactetId)
 {
     if (_rspdTypeMap.ContainsKey(pactetId))
     {
         _rspdTypeMap.Remove(pactetId);
     }
 }
Exemple #2
0
        public void NetFrameGetDataSample()
        {
            NetFrame frame = new NetFrame();

            frame.Ctrl.RoutingInstruction = 1;
            frame.Ctrl.FrameType          = EmNetFrameType.Command;
            frame.Ctrl.TargetAddrMode     = EmAddrLen.Six;
            frame.Ctrl.SourceAddrMode     = EmAddrLen.Six;

            frame.TargetAddr.Value = new byte[] { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 };

            frame.SourceAddr.Value = new byte[] { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 };

            frame.Seq.Value = 13;
            frame.Radius    = 1;

            /*
             * frame.RouteInfo.Add(new NetAddr() { AddrMode = EmNetAddrLen.Six, Value = new byte[] {0x11, 0x11, 0x11, 0x11, 0x11, 0x22} });
             * frame.RouteInfo.RouteIndex = 0;
             */
            // 这里和上面两句有同样的效果
            frame.RouteInfo.SetData(Tools.HexStrToByteArr("01 FC FF 22 11 11 11 11 11", ' '));

            NetCmd netCmd = new NetCmd();

            netCmd.CmdID       = EmNetCmdID.ConfigChildNodes;
            netCmd.CmdDu.Value = new byte[] { 0x11, 0x22, 0x33 };
            frame.Du           = netCmd;


            byte[] data = frame.GetData();
            frame.ToString();
        }
Exemple #3
0
        public bool S2CDebugLog(NetCmd cmd, Cmd c)
        {
            string szLog = c.ReadString();

            Debug.Log(szLog);

            return(true);
        }
Exemple #4
0
    public void regRspd(NetCmd pactetId, Type type)
    {
        RspdType rspdType = null;

        if (!_rspdTypeMap.ContainsKey(pactetId))
        {
            MethodInfo method = JsonCodeMethod.MakeGenericMethod(type);
            rspdType = new RspdType(type, method);
            _rspdTypeMap.Add(pactetId, rspdType);
        }
    }
Exemple #5
0
        /// <summary>
        /// 打包数据
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] PackData(NetCmd cmd, byte[] data)   //打包数据
        {
            /* [0...3] + [4...7] + [8...]
             * Length  + NetCmd  + data
             * */
            byte[] CmdByte   = BitConverter.GetBytes((UInt32)cmd);
            byte[] dataBytes = data;
            int    Length    = CmdByte.Length + dataBytes.Length;

            byte[] LengthBytes = BitConverter.GetBytes(Length);
            byte[] PackBytes   = LengthBytes.Concat(CmdByte).ToArray <byte>();//Concat(dataBytes);
            return(PackBytes.Concat(dataBytes).ToArray <byte>());
        }
Exemple #6
0
 private void Update()
 {
     if (msgs.Count > 0)
     {
         string   msg = msgs.Dequeue();
         string[] lst = msg.Split(',');
         //0协议号        //1 playerid 没有是-1   2 3参数
         int     proId  = int.Parse(lst[0]);
         NetCmd  cmd    = (NetCmd)proId;
         Message netMsg = new Message(cmd.ToString(), this);
         netMsg["msg"] = msg;
         netMsg.Send();
     }
 }
Exemple #7
0
    private static byte[] ByteArrayConnetion(NetCmd netCmd, params string[] bytesArray)
    {
        List <byte> resultList = new List <byte>();

        resultList.Add((byte)netCmd);
        foreach (string bytes in bytesArray)
        {
            byte[] temp = Encoding.Default.GetBytes(bytes);
            for (int i = 0; i < temp.Length; i++)
            {
                resultList.Add(temp[i]);
            }
        }
        return(resultList.ToArray());
    }
Exemple #8
0
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public void ReadMessage(out NetCmd cmd, out byte[] data)   //读取一条消息,调用一次读一条
        {
            cmd  = NetCmd.RAWSTRING;
            data = null;
            if (msgs.Count == 0)
            {
                return;
            }
            byte[] msgdata = msgs.Dequeue();
            NetCmd netCmd  = (NetCmd)BitConverter.ToInt32(msgdata, 0);

            if (netCmd >= NetCmd.NetCmdMin && netCmd <= NetCmd.NetCmdMax)
            {
                cmd  = netCmd;
                data = msgdata.Skip(4).ToArray();
            }
        }
Exemple #9
0
    /// <summary>
    /// 发送时翻译把高层命令翻译为字节串,并发送给服务器,等待回应,等待过程处于阻塞状态
    /// </summary>
    /// <param name="errInfo">错误信息!</param>
    /// <param name="response">来自于服务器端的响应信息</param>
    /// <param name="netCmd">网络命令(网络请求)</param>
    /// <param name="datas">此网络命令需要的数据</param>
    /// <returns>成功执行返回true</returns>
    public static bool Request(out string errInfo, out object[] response, NetCmd netCmd, params object[] datas)
    {
        bool result = false;

        response = null;
        errInfo  = string.Empty;
        try{
            byte[] responseBytes = UdpClientWork.self.Send(Translate(netCmd, datas));
            Debug.Log("接收到:" + responseBytes.Length + "个字节!");
            Debug.Log(ByteArrayConvertor.BytesToString(responseBytes));
            response = Translate(responseBytes);
            result   = true;
        }catch (Exception ex) {
            errInfo = ex.ToString();
        }
        return(result);
    }
Exemple #10
0
    //private static void Echo(byte[] receiveBuffer, int receiveSize)
    //{
    //    Debug.Log("接收到服务器端命令:" + ((NetCmd)receiveBuffer[1]).ToString());
    //}

    private static byte[] ByteArrayConnetion(NetCmd netCmd, params byte[][] bytesArray)
    {
        List <byte> resultList = new List <byte>();

        resultList.Add((byte)netCmd);
        if (bytesArray != null && bytesArray.Length > 0)
        {
            foreach (byte[] bytes in bytesArray)
            {
                if (bytes == null)
                {
                    continue;
                }
                for (int i = 0; i < bytes.Length; i++)
                {
                    resultList.Add(bytes[i]);
                }
            }
        }
        return(resultList.ToArray());
    }
Exemple #11
0
        /*
         * public bool S2C_SetObjStatic(NetCmd cmd, Cmd c) {
         *  string szRecv = c.ReadString();
         *
         *  List<GameObj> rdGameObjs = RDDataBase.Deserializer<List<GameObj>>(szRecv);
         *  GameObj cacheRDGameObj = null;
         *
         *  foreach (GameObj rdGameObj in rdGameObjs) {
         *
         *      ShowPanelDataSet.ms_GameObjDict.TryGetValue(rdGameObj.nInstanceID, out cacheRDGameObj);
         *      if (cacheRDGameObj != null) {
         *          cacheRDGameObj.bStatic = rdGameObj.bStatic;
         *      }
         *  }
         *  if (OnUpdateData != null) {
         *      OnUpdateData();
         *  }
         *
         *  return true;
         * }
         *
         * public bool S2C_SetObjTag(NetCmd cmd, Cmd c) {
         *  string szRecv = c.ReadString();
         *
         *  List<GameObj> rdGameObjs = RDDataBase.Deserializer<List<GameObj>>(szRecv);
         *  GameObj cacheRDGameObj = null;
         *
         *  foreach (GameObj rdGameObj in rdGameObjs) {
         *      ShowPanelDataSet.ms_GameObjDict.TryGetValue(rdGameObj.nInstanceID, out cacheRDGameObj);
         *      if (cacheRDGameObj != null) {
         *          cacheRDGameObj.szTag = rdGameObj.szTag;
         *      }
         *  }
         *  if (OnUpdateData != null) {
         *      OnUpdateData();
         *  }
         *
         *  return true;
         * }
         */

        public bool S2C_SetObjLayer(NetCmd cmd, Cmd c)
        {
            string szRecv = c.ReadString();

            GameObj[] rdGameObjs     = IObject.DeSerializerArray <GameObj>(szRecv);
            GameObj   cacheRDGameObj = null;

            foreach (GameObj rdGameObj in rdGameObjs)
            {
                ShowPanelDataSet.ms_GameObjDict.TryGetValue(rdGameObj.m_nInstanceID, out cacheRDGameObj);
                if (cacheRDGameObj != null)
                {
                    cacheRDGameObj.m_nLayer = rdGameObj.m_nLayer;
                }
            }
            if (OnUpdateData != null)
            {
                OnUpdateData();
            }
            return(true);
        }
Exemple #12
0
        public bool S2C_SetObjActive(NetCmd cmd, Cmd c)
        {
            string  szRecv    = c.ReadString();
            GameObj rdGameObj = IObject.DeSerializer <GameObj>(szRecv);

            GameObj cacheRDGameObj = null;

            ShowPanelDataSet.ms_GameObjDict.TryGetValue(rdGameObj.m_nInstanceID, out cacheRDGameObj);

            if (cacheRDGameObj != null)
            {
                cacheRDGameObj.m_bActive = rdGameObj.m_bActive;
            }

            if (OnUpdateData != null)
            {
                OnUpdateData();
            }

            return(true);
        }
Exemple #13
0
        public bool S2C_GetComponentProperty(NetCmd cmd, Cmd c)
        {
            try {
                string szRecv = c.ReadString();

                PropertyObj[] PropertyObjs = IObject.DeSerializerArray <PropertyObj>(szRecv);

                ShowPanelDataSet.ms_remoteComponent.SetPropertys(PropertyObjs);

                if (OnUpdateData != null)
                {
                    OnUpdateData();
                }
            }
            catch (Exception ex) {
                Debug.Log(ex.ToString());
                return(false);
            }

            return(true);
        }
Exemple #14
0
    /// <summary>
    /// 发送时翻译把高层命令翻译为字节串
    /// </summary>
    /// <param name="netCmd">网络命令(网络请求)</param>
    /// <param name="datas">此网络命令需要的数据</param>
    /// <returns>翻译成为字节串</returns>
    public static byte[] Translate(NetCmd netCmd, params object[] datas)
    {
        byte[] result = null;
        switch (netCmd)
        {
        case NetCmd.Login:
        case NetCmd.SignIn:
            //result = ByteArrayConnetion(netCmd, (string)datas[0], "[End]", (string)datas[1], "[End]");
            //result = ByteArrayConnetion(netCmd,
            //    new String20((string)datas[0]).GetByteArray(),
            //    new String20((string)datas[1]).GetByteArray());
            result = ByteArrayConnetion(netCmd, NetDataTypeDictionary.GetByteArray(new ArrayList()
            {
                datas[0],
                datas[1],
            }));

            //result = ByteArrayConnetion(netCmd,
            //    new String20((string)datas[0]).GetByteArray(),
            //    new String20((string)datas[1]).GetByteArray());
            break;

        default:

            if (datas == null)
            {
                result = ByteArrayConnetion(netCmd,
                                            new String20(Player.self.playerName).GetByteArray());
            }
            else
            {
                result = ByteArrayConnetion(netCmd,
                                            new String20(Player.self.playerName).GetByteArray(),
                                            NetDataTypeDictionary.GetByteArray(new ArrayList(datas)));
            }
            break;
        }
        return(result);
    }
Exemple #15
0
        public bool S2C_QueryComponent(NetCmd cmd, Cmd c)
        {
            string data = c.ReadString();

            try {
                CompObj[] rdComps = IObject.DeSerializerArray <CompObj>(data);

                if (ShowPanelDataSet.ms_remoteGameObject != null)
                {
                    UnityEngine.Object.DestroyImmediate(ShowPanelDataSet.ms_remoteGameObject);
                }

                ShowPanelDataSet.ms_remoteGameObject = new GameObject("_RemoteDebugger");
                ShowPanelDataSet.ms_remoteGameObject.SetActive(false);

                for (int i = 0; i < rdComps.Length; ++i)
                {
                    if (ShowPanelDataSet.AddRemoteComponent(rdComps[i].m_szName))
                    {
                        ShowPanelDataSet.AddCompObj(rdComps[i]);
                    }
                }

                ShowPanelDataSet.ms_currentSelectComps = rdComps;
            }
            catch (Exception ex) {
                Debug.LogException(ex);
            }
            //ShowPanelDataSet.select_node_components.Add(JsonMapper.ToObject<CompNode>(data));
            if (OnUpdateData != null)
            {
                OnUpdateData();
            }

            return(true);
        }
Exemple #16
0
        public CmdExecResult Execute(Cmd c)
        {
            try {
                NetCmd     cmd = c.ReadNetCmd();
                CmdHandler handler;
                if (!m_handlers.TryGetValue(cmd, out handler))
                {
                    return(CmdExecResult.HandlerNotFound);
                }

                if (handler(cmd, c))
                {
                    return(CmdExecResult.Succ);
                }
                else
                {
                    return(CmdExecResult.Failed);
                }
            }
            catch (Exception ex) {
                Console.WriteLine("[cmd] Execution failed. ({0})", ex.Message);
                return(CmdExecResult.Failed);
            }
        }
Exemple #17
0
        public bool S2C_QueryAllObjs(NetCmd cmd, Cmd c)
        {
            string rdGameObjs = c.ReadString();

            try {
                ShowPanelDataSet.InitDataSet();
                GameObj[] arrRdObjs = IObject.DeSerializerArray <GameObj>(rdGameObjs);

                for (int i = 0; i < arrRdObjs.Length; ++i)
                {
                    ShowPanelDataSet.AddGameObj(arrRdObjs[i]);
                }

                if (OnUpdateData != null)
                {
                    OnUpdateData();
                }
            }
            catch (Exception ex) {
                Debug.LogException(ex);
            }

            return(true);
        }
Exemple #18
0
 public bool S2C_ModifyComponentProperty(NetCmd cmd, Cmd c)
 {
     return(true);
 }
Exemple #19
0
 public void RegisterHandler(NetCmd cmd, CmdHandler handler)
 {
     cmd_parser.RegisterHandler(cmd, handler);
 }
Exemple #20
0
 public void RegisterHandler(NetCmd cmd, CmdHandler handler)
 {
     m_handlers[cmd] = handler;
 }
Exemple #21
0
 public void WriteNetCmd(NetCmd cmd)
 {
     WritePrimitive((short)cmd);
 }
Exemple #22
0
 public bool S2CFinishWait(NetCmd cmd, Cmd c)
 {
     return(true);
 }
Exemple #23
0
 public void SetNetCmd(NetCmd cmd)
 {
     WriteUInt16((UInt16)cmd);
 }
Exemple #24
0
 public bool S2CEnableComponent(NetCmd cmd, Cmd c)
 {
     return(true);
 }