private static void HandleOnUserConnect(int index, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            try
            {
                buffer.Write(data);
                var packetNum = buffer.ReadInteger();
                ServerHandleNetworkData.HandleOnUserConnect(index);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { buffer.Dispose(); }
        }
        public static void HandleOtherPlayerCharacterListRequest(int index, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            try
            {
                buffer.Write(data);
                var packetNum = buffer.ReadInteger();
                ServerHandleNetworkData.HandleOtherPlayerCharacterListRequest(index);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { buffer.Dispose(); }
        }
        public static void HandleLoginPositionRequest(int index, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            try
            {
                buffer.Write(data);
                var packetNum = buffer.ReadInteger();
                var playerID  = buffer.ReadString();
                ServerHandleNetworkData.HandleLoginPositionRequest(index, playerID);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { buffer.Dispose(); }
        }
        public static void HandlePlayerCharacterMovedPosition(int index, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            try
            {
                buffer.Write(data);
                var packetNum = buffer.ReadInteger();
                var newPosX   = buffer.ReadInteger();
                var newPosY   = buffer.ReadInteger();
                ServerHandleNetworkData.HandlePlayerCharacterMovedPosition(index, newPosX, newPosY);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { buffer.Dispose(); }
        }
        private static void HandleAccountCreateQuery(int index, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            try
            {
                buffer.Write(data);
                var packetNum = buffer.ReadInteger();
                var username  = buffer.ReadString();
                var password  = buffer.ReadString();
                ServerHandleNetworkData.HandleAccountCreateQuery(index, username, password);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { buffer.Dispose(); }
        }
        private static void HandleMoveQuery(int index, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            try
            {
                buffer.Write(data);
                var packetNum = buffer.ReadInteger();
                var pointX    = buffer.ReadFloat();
                var pointY    = buffer.ReadFloat();
                var ID        = buffer.ReadInteger();
                ServerHandleNetworkData.TellOPCsAPlayerIsMoving(index, new Vector2(pointX, pointY));
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { buffer.Dispose(); }
        }
        private static void HandleUserLoginQuery(int index, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            try
            {
                buffer.Write(data);
                var packetNum = buffer.ReadInteger();
                var username  = buffer.ReadString();
                var password  = buffer.ReadString();
                var result    = CommonMongo.GetPlayerPasswordAndID(username);
                ServerHandleNetworkData.HandleUserLoginQuery(index, username, password, result);
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { buffer.Dispose(); }
        }
Beispiel #8
0
        public void ReceiveCallback(IAsyncResult ar)
        {
            Socket socket = (Socket)ar.AsyncState;

            try
            {
                int receive = socket.EndReceive(ar);
                if (receive <= 0)
                {
                    CloseClient(index);
                }
                else
                {
                    byte[] databuffer = new byte[receive];
                    Array.Copy(_buffer, databuffer, receive);
                    ServerHandleNetworkData.HandleNetworkInfromation(index, databuffer);
                    socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), socket);
                }
            }
            catch
            {
                CloseClient(index);
            }
        }