예제 #1
0
        public static SR_SendMessage ReadSendMessage(PacketReader reader)
        {
            var ret = new SR_SendMessage();
            ret.Message = reader.ReadUTF8String();

            return ret;
        }
예제 #2
0
 void OnCreatePlayer(NetState netstate, PacketReader reader)
 {
     if (!netstate.IsVerifyLogin) return;
     var p1 = reader.ReadUTF8String();
     var p2 = (TradeAge.Server.Entity.Character.Sex)reader.ReadByte();
     module.OnCreatePlayer(netstate,p1,p2);
 }
예제 #3
0
        public static SR_Login ReadLogin(PacketReader reader)
        {
            var ret = new SR_Login();
            ret.UserName = reader.ReadUTF8String();
            ret.Pwd = reader.ReadUTF8String();

            return ret;
        }
예제 #4
0
파일: Program.cs 프로젝트: RainsSoft/DogSE
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs<Session> e)
        {
            var session = e.Session.Data;
            session.RQ.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var packetlen = session.RQ.GetPacketLength();
            while (packetlen >= session.RQ.Length)
            {
                var dogBuffer = new DogBuffer();
                session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);

                var reader = new PacketReader();
                reader.SetBuffer(dogBuffer);

                var pid = reader.GetPacketID();
                var handler = packetHandlersManager.GetHandler(pid);
                if (handler == null)
                {
                    Logs.Error("未知消息ID {0}", pid);
                }
                else
                {
                    //  网络的消息包都会压入任务队列里等待执行
                    taskManager.AppendTask(session, handler, reader);
                }

                packetlen = session.RQ.GetPacketLength();
            }
        }
예제 #5
0
파일: Program.cs 프로젝트: RainsSoft/DogSE
        /// <summary>
        /// 给聊天室里的某人单独发消息
        /// </summary>
        /// <param name="session"></param>
        /// <param name="reader"></param>
        static void OnSendPrivateMessage(Session session, PacketReader reader)
        {
            var userName = reader.ReadUTF8String();
            var message = reader.ReadUTF8String();

            if (message == null)
                return;

            var target = sessions.FirstOrDefault(o => o.Name == userName);
            if (target == null)
                return;

            var writer = new PacketWriter();
            writer.SetNetCode((ushort) OpCode.RecvPrivateMessage);
            writer.WriteUTF8Null(session.Name);
            writer.WriteUTF8Null(message);

            target.Client.SendPackage(writer.GetBuffer());
        }
예제 #6
0
파일: Program.cs 프로젝트: RainsSoft/DogSE
        /// <summary>
        /// 给聊天室里的人都发消息
        /// </summary>
        /// <param name="session"></param>
        /// <param name="reader"></param>
        static void OnSendMessage(Session session, PacketReader reader)
        {
            var message = reader.ReadUTF8String();
            if (string.IsNullOrEmpty(message))
            {
                //  空消息
                return;
            }

            //  广播给所有在线的用户
            var writer = new PacketWriter();
            writer.SetNetCode((ushort)OpCode.RecvMessage);
            foreach (var ss in sessions)
            {
                ss.Client.SendPackage(writer.GetBuffer());
            }
        }
예제 #7
0
파일: Program.cs 프로젝트: RainsSoft/DogSE
        /// <summary>
        /// 登录服务器
        /// </summary>
        /// <param name="session"></param>
        /// <param name="reader"></param>
        static void OnLogin(Session session, PacketReader reader)
        {
            var userName = reader.ReadUTF8String();
            var pwd = reader.ReadUTF8String();

            if (string.IsNullOrEmpty(userName))
            {
                Logs.Error("连接的用户名是空");
                session.Client.CloseSocket();
            }

            if (pwd != "123")
            {
                Logs.Error("用户名 {0} 速度的密码错误", userName);
                var writer = new PacketWriter();
                writer.SetNetCode((ushort)OpCode.LoginResult);
                writer.Write(1);    //  0表示登录成功 1表示密码错误
                session.Client.SendPackage(writer.GetBuffer());
                return;
            }

            //  如果玩家之前登录过,则把之前的客户端踢下线
            var exists = sessions.FirstOrDefault(o => o.Name == userName);
            if (exists != null)
            {
                exists.IsLogin = false;
                sessions.Remove(exists);
                exists.Client.CloseSocket();
            }

            //  登录完成
            session.IsLogin = true;
            nologinSessions.Remove(session);
            sessions.Add(session);

            session.Name = userName;
            session.Pwd = pwd;
            session.BizId = clientIdSeq++;

            var writer2 = new PacketWriter();
            writer2.SetNetCode((ushort)OpCode.LoginResult);
            writer2.Write(0);    //  0表示登录成功 1表示密码错误
            session.Client.SendPackage(writer2.GetBuffer());
        }
예제 #8
0
            /// <summary>
            /// 
            /// </summary>
            /// <param name="reader"></param>
            /// <returns></returns>
            public static DogSE.Library.Maths.Quaternion Read(PacketReader reader)
            {
                DogSE.Library.Maths.Quaternion ret = new DogSE.Library.Maths.Quaternion();

                ret.X = reader.ReadFloat();
                ret.Y = reader.ReadFloat();
                ret.Z = reader.ReadFloat();
                ret.W = reader.ReadFloat();

                return ret;
            }
예제 #9
0
파일: test.cs 프로젝트: zaq1xsw/DogSE
 void OnReadTest(NetState netstate, PacketReader reader)
 {
     module.OnReadTest(netstate, reader);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static TradeAge.Server.Entity.Common.Vector3 Read(PacketReader reader)
        {
            TradeAge.Server.Entity.Common.Vector3 ret = new TradeAge.Server.Entity.Common.Vector3();

ret.X = reader.ReadFloat();
ret.Y = reader.ReadFloat();
ret.Z = reader.ReadFloat();


            return ret;
        }
예제 #11
0
 void Heartbeat(NetState netstate, PacketReader reader)
 {
     if (!netstate.IsVerifyLogin) return;
     var p1 = reader.ReadInt32();
     module.Heartbeat(netstate,p1);
 }
예제 #12
0
파일: Program.cs 프로젝트: RainsSoft/DogSE
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs<Session> e)
        {
            var session = e.Session.Data;
            session.RQ.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var packetlen = session.RQ.GetPacketLength();
            while (packetlen >= session.RQ.Length)
            {
                var dogBuffer = new DogBuffer();
                session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);

                var reader = new PacketReader();
                reader.SetBuffer(dogBuffer);

                /*
                var pid = (OpCode)reader.GetPacketID();

                switch (pid)
                {
                    case OpCode.Login:
                        OnLogin(session, reader);
                        break;
                    case OpCode.SendMessage:
                        OnSendMessage(session, reader);
                        break;
                    case OpCode.SendPriviteMessage:
                        OnSendPrivateMessage(session, reader);
                        break;
                    default:
                        Logs.Error("未知消息ID {0}", (int)pid);
                        break;
                }
                */

                var pid = reader.GetPacketID();
                var handler = packetHandlersManager.GetHandler(pid);
                if (handler == null)
                {
                    Logs.Error("未知消息ID {0}", pid);
                }
                else
                {
                    handler.OnReceive(session, reader);
                }

                packetlen = session.RQ.GetPacketLength();
            }
        }
예제 #13
0
 void OnMove(NetState netstate, PacketReader reader)
 {
     if (!netstate.IsVerifyLogin) return;
     var p1 = new DateTime(reader.ReadLong64());
      var p2 = Vector2ReadProxy.Read(reader);
      var p3 = Vector2ReadProxy.Read(reader);
     module.OnMove(netstate,p1,p2,p3);
 }
예제 #14
0
        /// <summary>
        /// 压入数据包至优先级处理列表
        /// </summary>
        public void Enqueue(PacketHandler packetHandler, PacketReader packetReader)
        {
            PacketExecuteInfo packetExecuteInfo = new PacketExecuteInfo { PacketHandler = packetHandler, PacketReader = packetReader };

            m_PacketHandlers.Add(packetHandler.PacketPriority, packetExecuteInfo);
        }
예제 #15
0
            /// <summary>
            /// 
            /// </summary>
            /// <param name="reader"></param>
            /// <returns></returns>
            public static DogSE.Library.Maths.Vector3 Read(PacketReader reader)
            {
                DogSE.Library.Maths.Vector3 ret = new DogSE.Library.Maths.Vector3();

                ret.X = reader.ReadFloat();
                ret.Y = reader.ReadFloat();
                ret.Z = reader.ReadFloat();

                return ret;
            }
예제 #16
0
파일: Program.cs 프로젝트: RainsSoft/DogSE
        /// <summary>
        /// 收到Socket数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSocketRecv(object sender, SocketRecvEventArgs<Session> e)
        {
            var session = e.Session.Data;
            session.RQ.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var packetlen = session.RQ.GetPacketLength();
            if (packetlen > 1024*64)
            {
                session.Client.CloseSocket();
                return;
            }

            while (packetlen >= session.RQ.Length)
            {
                var dogBuffer = new DogBuffer();
                session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);

                var reader = new PacketReader();
                reader.SetBuffer(dogBuffer);

                var pid = (OpCode)reader.GetPacketID();

                switch (pid)
                {
                    case OpCode.Login:
                    {
                        var userName = reader.ReadUTF8String();
                        var pwd = reader.ReadUTF8String();

                        if (string.IsNullOrEmpty(userName))
                        {
                            Logs.Error("连接的用户名是空");
                            session.Client.CloseSocket();
                        }

                        if (pwd != "123")
                        {
                            Logs.Error("用户名 {0} 速度的密码错误", userName);
                            var writer = new PacketWriter();
                            writer.SetNetCode((ushort) OpCode.LoginResult);
                            writer.Write(1); //  0表示登录成功 1表示密码错误
                            session.Client.SendPackage(writer.GetBuffer());
                            return;
                        }

                        //  如果玩家之前登录过,则把之前的客户端踢下线
                        var exists = sessions.FirstOrDefault(o => o.Name == userName);
                        if (exists != null)
                        {
                            exists.IsLogin = false;
                            sessions.Remove(exists);
                            exists.Client.CloseSocket();
                        }

                        //  登录完成
                        session.IsLogin = true;
                        nologinSessions.Remove(session);
                        sessions.Add(session);

                        session.Name = userName;
                        session.Pwd = pwd;
                        var writer2 = new PacketWriter();
                        writer2.SetNetCode((ushort) OpCode.LoginResult);
                        writer2.Write(0); //  0表示登录成功 1表示密码错误
                        session.Client.SendPackage(writer2.GetBuffer());
                    }
                        break;
                    case OpCode.SendMessage:
                    {
                        var message = reader.ReadUTF8String();
                        if (string.IsNullOrEmpty(message))
                        {
                            //  空消息
                            return;
                        }

                        //  广播给所有在线的用户
                        var writer = new PacketWriter();
                        writer.SetNetCode((ushort) OpCode.RecvMessage);
                        foreach (var ss in sessions)
                        {
                            ss.Client.SendPackage(writer.GetBuffer());
                        }
                    }
                        break;
                    case OpCode.SendPriviteMessage:
                    {
                        var userName = reader.ReadUTF8String();
                        var message = reader.ReadUTF8String();

                        if (message == null)
                            return;

                        var target = sessions.FirstOrDefault(o => o.Name == userName);
                        if (target == null)
                            return;

                        var writer = new PacketWriter();
                        writer.SetNetCode((ushort) OpCode.RecvPrivateMessage);
                        writer.WriteUTF8Null(session.Name);
                        writer.WriteUTF8Null(message);

                        target.Client.SendPackage(writer.GetBuffer());
                    }
                        break;
                    default:
                        Logs.Error("未知消息ID {0}", (int) pid);
                        break;
                }

                packetlen = session.RQ.GetPacketLength();
            }
        }
예제 #17
0
파일: Program.cs 프로젝트: RainsSoft/DogSE
        /// <summary>
        /// 登录服务器
        /// </summary>
        /// <param name="session"></param>
        /// <param name="reader"></param>
        static void OnLogin(Session session, PacketReader reader)
        {
            var packet = MessagePackageManager.ReadLogin(reader);

            if (string.IsNullOrEmpty(packet.UserName))
            {
                Logs.Error("连接的用户名是空");
                session.Client.CloseSocket();
            }

            if (packet.Pwd != "123")
            {
                Logs.Error("用户名 {0} 速度的密码错误", packet.UserName);
                var buffer = MessagePackageManager.WriteLoginResult(LoginResult.PwdError);
                session.Client.SendPackage(buffer);
                return;
            }

            //  如果玩家之前登录过,则把之前的客户端踢下线
            var exists = sessions.FirstOrDefault(o => o.Name == packet.UserName);
            if (exists != null)
            {
                exists.IsLogin = false;
                sessions.Remove(exists);
                exists.Client.CloseSocket();
            }

            //  登录完成
            session.IsLogin = true;
            nologinSessions.Remove(session);
            sessions.Add(session);

            session.Name = packet.UserName;
            session.Pwd = packet.Pwd;
            session.BizId = clientIdSeq++;

            var buffer2 = MessagePackageManager.WriteLoginResult(LoginResult.Success);
            session.Client.SendPackage(buffer2);
        }
void OnMove(NetState netstate, PacketReader reader){
if (!netstate.IsVerifyLogin) return;
 var p1 = Vector3ReadProxy.Read(reader);
 var p2 = Vector3ReadProxy.Read(reader);
module.OnMove(netstate,p1,p2);
}
예제 #19
0
 public void OnReadTest(NetState netstate, PacketReader reader)
 {
     IsTouchOnReadTest = true;
 }
void OnLoginServer(NetState netstate, PacketReader reader){
var p1 = reader.ReadUTF8String();
var p2 = reader.ReadUTF8String();
var p3 = reader.ReadInt32();
module.OnLoginServer(netstate,p1,p2,p3);
}
예제 #21
0
파일: WorldBase.cs 프로젝트: Jimlan/DogSE
        /// <summary>
        /// 收到网络消息包
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSocketRecv(object sender, SocketRecvEventArgs<NetState> e)
        {
            var netState = e.Session.Data;
            netState.ReceiveBuffer.Enqueue(e.Buffer.Bytes, 0, e.Buffer.Length);

            var len = netState.ReceiveBuffer.GetPacketLength();
            do
            {
                if (len <= netState.ReceiveBuffer.Length)
                {

                    DogBuffer readBuffer;
                    if (len < 1024*4)
                        readBuffer = DogBuffer.GetFromPool4K();
                    else
                        readBuffer = DogBuffer.GetFromPool32K();

                    var get = netState.ReceiveBuffer.Dequeue(readBuffer.Bytes, 0, len);
                    if (get == len)
                    {
                        readBuffer.Length = len;

                        var packageReader = new PacketReader(readBuffer);
                        var packetHandler = PacketHandlersManger.GetHandler(packageReader.GetPacketID());
                        if (packetHandler != null)
                        {
                            //  加入网络消息处理
                            taskManager.AppendTask(netState, packetHandler, packageReader);
                        }
                        else
                        {
                            Logs.Error("unknow packetid. code={0}", packageReader.GetPacketID().ToString());
                        }
                    }
                }
                //  一次网络消息可能会对应多个消息包,因此这里用循环获得消息包
                len = netState.ReceiveBuffer.GetPacketLength();
            } while (len > 0);
        }
예제 #22
0
파일: Program.cs 프로젝트: RainsSoft/DogSE
        /// <summary>
        /// 给聊天室里的人都发消息
        /// </summary>
        /// <param name="session"></param>
        /// <param name="reader"></param>
        static void OnSendMessage(Session session, PacketReader reader)
        {
            var message = reader.ReadUTF8String();
            if (string.IsNullOrEmpty(message))
            {
                //  空消息
                return;
            }

            //  广播给所有在线的用户
            var buffer = MessagePackageManager.WriteSendMessageResult(message);
            foreach (var ss in sessions)
            {
                ss.Client.SendPackage(buffer);
            }
        }
예제 #23
0
 void OnMove(NetState netstate, PacketReader reader)
 {
     if (!netstate.IsVerifyLogin) return;
     var p1 = new DateTime(reader.ReadLong64());
      var p2 = Vector3ReadProxy.Read(reader);
      var p3 = QuaternionReadProxy.Read(reader);
     var p4 = reader.ReadFloat();
     var p5 = reader.ReadFloat();
     var p6 = (TradeAge.Server.Entity.Ship.SpeedUpTypes)reader.ReadByte();
     module.OnMove(netstate,p1,p2,p3,p4,p5,p6);
 }
예제 #24
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="reader"></param>
 public void Read(PacketReader reader)
 {
     IsTouchRead = true;
 }
예제 #25
0
파일: Program.cs 프로젝트: RainsSoft/DogSE
        /// <summary>
        /// 给聊天室里的某人单独发消息
        /// </summary>
        /// <param name="session"></param>
        /// <param name="reader"></param>
        static void OnSendPrivateMessage(Session session, PacketReader reader)
        {
            var userName = reader.ReadUTF8String();
            var message = reader.ReadUTF8String();

            if (message == null)
                return;

            var target = sessions.FirstOrDefault(o => o.Name == userName);
            if (target == null)
                return;

            var buffer = MessagePackageManager.WriteSendPrivateMessageResult(session.Name, message);
            target.Client.SendPackage(buffer);
        }