예제 #1
0
        private void Deserialize(byte[] dataBytes, int dataLen)
        {
            NetAdapter.DeserializeData deserializeData = adapter.Deserialize(dataBytes, dataLen);
            if (deserializeData != null)
            {
                //Debugger.Log("recv pmsg 2->" + deSerializationData.toScript + "^" + deSerializationData.Data);
                if (deserializeData.toScript)
                {
#if JSSCRIPT
                    MessagePool.ScriptSendMessage(null, MessagePool.OnNetMessageArrived, Message.FilterTypeNothing, (string)deSerializationData.Data);
#elif LUASCRIPT
                    //MessagePool.CSSendMessage(null, MessagePool.OnNetMessageArrived, Message.FilterTypeNothing, new RecvData() { node = this, data = deSerializationData });
                    ThreadTask.QueueOnMainThread(() =>
                    {
                        CallLuaRecvFunc(deserializeData);
                        NetMsgPool.RecycleMsg(deserializeData.data);
                        deserializeData.data = null;
                    });
#endif
                }
                else
                {
                    //MessagePool.CSSendMessage(null, csNetGID, Message.FilterTypeNothing, deserializeData.data);
                    NetMsgPool.RecycleMsg(deserializeData.data);
                    deserializeData.data = null;
                }
            }
        }
예제 #2
0
        public static void Init(int num)
        {
            NetMsgPool.Init(1024 * 1024 * 4);
            if (clients != null)
            {
                for (int i = 0; i < clients.Length; i++)
                {
                    if (clients[i] != null)
                    {
                        clients[i].Close();
                    }
                }
            }

            clients = new NetClient[num];

            for (int i = 0; i < num; i++)
            {
                clients[i] = NetClient.GenNetClient();
            }
        }
예제 #3
0
        private void Deserialize(byte[] dataBytes, int dataLen)
        {
            if (Config.Detail_Debug_Log())
            {
                Debug.Log("---------net client deserialize msg data 1->" + dataBytes + "^" + dataLen);
            }

            if (Config.Detail_Debug_Log())
            {
                Debug.LogError("/////////////////////////////////////////////////////////////////////");
                StringBuilder sb = new StringBuilder();
                if (dataBytes != null)
                {
                    int num = 0;
                    for (int i = 0; i < dataLen; i++)
                    {
                        sb.Append(dataBytes[i].ToString("X2"));
                        sb.Append(" ");
                        if (num >= 10)
                        {
                            sb.Append("\r\n");
                            num = 0;
                        }
                        num++;
                    }

                    Debug.LogError(sb.ToString());
                }
                Debug.LogError("*********************************************************************");
            }

            NetAdapter.DeserializeData deserializeData = adapter.Deserialize(dataBytes, dataLen);

            if (Config.Detail_Debug_Log())
            {
                Debug.Log("---------net client deserialize msg data 2->" + (deserializeData == null));
            }

            if (deserializeData != null)
            {
                if (deserializeData.toScript)
                {
#if JSSCRIPT
                    MessagePool.ScriptSendMessage(null, MessagePool.OnNetMessageArrived, Message.FilterTypeNothing, (string)deSerializationData.Data);
#elif LUASCRIPT
                    if (Config.Detail_Debug_Log())
                    {
                        Debug.Log("---------net client deserialize msg data 3->" + (deserializeData.data == null));

                        if (deserializeData.data != null)
                        {
                            Debug.Log("----------------------net client deserialize msg data 10->" + deserializeData.data.get_tid() + "^" + deserializeData.data.get_gid() + "^" + deserializeData.data.get_uid() + "^" + deserializeData.data.get_datalen());
                        }
                    }


                    ThreadTask.QueueOnMainThread(() =>
                    {
                        if (Config.Detail_Debug_Log())
                        {
                            Debug.Log("---------net client deserialize msg data 4->" + (deserializeData.data == null ? -1 : (deserializeData.data.get_data() == null ? -2 : 1)));
                            if (deserializeData.data != null)
                            {
                                Debug.Log("----------------------net client deserialize msg data 11->" + deserializeData.data.get_tid() + "^" + deserializeData.data.get_gid() + "^" + deserializeData.data.get_uid() + "^" + deserializeData.data.get_datalen());
                            }
                        }

                        CallLuaRecvFunc(deserializeData);
                        NetMsgPool.RecycleMsg(deserializeData.data);
                        deserializeData.data = null;
                    });
#endif
                }
                else
                {
                    NetMsgPool.RecycleMsg(deserializeData.data);
                    deserializeData.data = null;
                }
            }
        }
예제 #4
0
        public DeserializeData Deserialize(byte[] datas, int dataLen)
        {
            DeserializeData result = null;

            if (datas != null)
            {
                using (MemoryStream memoryStream = new MemoryStream(datas, 0, dataLen))
                    using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                    {
                        byte tID        = binaryReader.ReadByte();
                        int  bodyLength = binaryReader.ReadInt32();
                        if (!littleEnd)
                        {
                            bodyLength = bodyLength.SwapInt32();
                        }

                        byte gID = binaryReader.ReadByte();
                        byte uID = binaryReader.ReadByte();

                        if (Config.Detail_Debug_Log())
                        {
                            Debug.Log("---------net adapter deserialize msg data->" + dataLen + "^" + (bodyLength + NetUtils.MSG_HEADER_LEN));
                        }

                        if (dataLen == (bodyLength + NetUtils.MSG_HEADER_LEN))
                        {
                            result = new DeserializeData();
                            NetMsg msg = NetMsgPool.GenNetMsg(bodyLength);
                            if (msg == null)
                            {
                                Debugger.LogError("net adapter gen net msg failed->" + bodyLength);
                                return(null);
                            }
                            msg.set_tgu(tID, gID, uID);
                            if (Config.Detail_Debug_Log())
                            {
                                Debug.LogError("deserialize msg t g u->" + tID + "^" + gID + "^" + uID + "^" + bodyLength);
                            }
                            msg.copy_data(datas, NetUtils.MSG_HEADER_LEN, bodyLength);
                            result.data = msg;

                            if (gID <= NetUtils.SCRIPTTOP_GROUP)
                            {
#if JSSCRIPT
                                sb.Remove(0, sb.Length);
                                //sb.Append(protoNumber.ToString());
                                sb.Append(gID);
                                sb.Append(">");
                                sb.Append(uID);
                                sb.Append(">");
                                sb.Append(Convert.ToBase64String(rawBytes));

                                // util.Log.Log(sb.ToString());

                                result = new DeserializationData()
                                {
                                    Data     = sb.ToString(),
                                    toScript = true,
                                    gID      = gID,
                                    uID      = uID
                                               //protoNumber = protoNumber
                                };
#elif LUASCRIPT
                                result.toScript = true;
#endif
                            }
                            else
                            {
                                result.toScript = false;
                            }
                        }
                    }
            }

            return(result);
        }