Ejemplo n.º 1
0
        private void Run(MemoryStream memoryStream)
        {
            memoryStream.Seek(Packet.MessageIndex, SeekOrigin.Begin);
            byte flag   = memoryStream.GetBuffer()[Packet.FlagIndex];
            int  opcode = BitConverter.ToInt32(memoryStream.GetBuffer(), Packet.OpcodeIndex);

            object message;

            try
            {
                object instance = componentNetMsg.GetInstance(opcode);
                message = this.network.MessagePacker.DeserializeFrom(instance, memoryStream);

                //Log.Debug("Recv: " + componentNetMsg. GetType((ushort)opcode).Name); // yuxj debug
                if (!componentNetMsg.HandleMsg(this, opcode, message))
                {
                    network.dispatcher?.Handle(this, opcode, message);
                }
                componentNetMsg.sessionTask.Response(message);
                componentNetMsg.messageTask.Response(opcode, message);
            }
            catch (Exception e)
            {
                // 出现任何消息解析异常都要断开Session,防止客户端伪造消息
                Log.Error($"opcode: {opcode} {this.network.Count} {e} ");
                this.Error = ErrorCode.ERR_PacketParserError;
                this.network.Remove(this.Id);
                return;
            }
        }
Ejemplo n.º 2
0
        private string OnMessage(Dictionary <string, string> map, HttpListenerRequest request, HttpListenerResponse response)
        {
            ComponentNetMsg componentNetMsg = Entity.Root.GetComponent <ComponentNetMsg>();
            HttpMessage     message         = new HttpMessage();

            message.map      = map;
            message.result   = "{\"ret\":\"failed\"}";
            message.request  = request;
            message.response = response;
            componentNetMsg.HandleMsg(null, NetOpcodeBase.HttpMessage, message);
            return(message.result);
        }