Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Fingerprint"/> class.
        /// </summary>
        public static void Initialize()
        {
            try
            {
                if (!Patches())
                {
                    if (File.Exists(@"Gamefiles\fingerprint.json"))
                    {
                        Fingerprint.Json = File.ReadAllText(Directory.GetCurrentDirectory() + @"\Gamefiles\fingerprint.json");
                        JObject _Json = JObject.Parse(Fingerprint.Json);
                        Fingerprint.Sha     = _Json["sha"].ToObject <string>();
                        Fingerprint.Version = _Json["version"].ToObject <string>().Split('.');

                        Debug.WriteLine("[*] " + ConsolePad.Padding(typeof(Fingerprint).Name, 15) + " : " + "The Fingerprint has been loaded, with version " + string.Join(".", Fingerprint.Version) + ".");
                    }
                    else
                    {
                        Debug.WriteLine("[*] " + ConsolePad.Padding(typeof(Fingerprint).Name, 15) + " : " + "The Fingerprint cannot be loaded, the file does not exist.");
                    }
                }
                else
                {
                    Debug.WriteLine("[*] " + ConsolePad.Padding(typeof(Fingerprint).Name, 15) + " : " + "The Fingerprint is loaded and custom, with version " + string.Join(".", Fingerprint.Version) + ".");
                }
            }
            catch (Exception Exception)
            {
                Debug.WriteLine("[*] " + ConsolePad.Padding(typeof(Fingerprint).Name, 15) + " : " + Exception.GetType().Name + " while parsing the fingerprint.");
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Packet"/> class.
        /// </summary>
        /// <param name="Buffer">The buffer.</param>
        /// <param name="Destination">The destination.</param>
        /// <param name="Client">The client.</param>
        public Packet(byte[] Buffer, Destination Destination, Socket Client)
        {
            this.Client = Client;
            this.Device = Resources.Devices[Client.Handle];

            using (Reader PacketReader = new Reader(Buffer))
            {
                this.Destination = Destination;

                this.Identifier = PacketReader.ReadUInt16();
                this.Length     = PacketReader.ReadInt24();
                this.Version    = PacketReader.ReadUInt16();

                this.Payload = PacketReader.ReadBytes(this.Length);
            }

            this.Name = PacketType.GetName(this.Identifier);

            Logging.Info(this.GetType(), "Processing packet (" + ConsolePad.Padding(this.Name, 20) + " | " + this.Identifier + ") " + Destination.ToString().Replace("_", " ").ToLower() + ", with version " + this.Version + ".");

            this.Decrypted_Data = this.Device.EnDecrypt.Decrypt(this);
            this.Encrypted_Data = this.Device.EnDecrypt.Encrypt(this);

            File.AppendAllText("Logs\\" + ((IPEndPoint)this.Client.RemoteEndPoint).Address + "\\" + this.Name + "_" + this.Identifier + ".bin", BitConverter.ToString(this.RebuiltDecrypted) + Environment.NewLine);
        }
Example #3
0
        internal void Parse()
        {
            while (true)
            {
                int CursorTop2 = Console.CursorTop = Console.WindowTop + Console.WindowHeight - 1;
                Console.Write("root@localhost > ");

                string Command = Console.ReadLine();

                Console.SetCursorPosition(0, CursorTop2 - 1);
                Console.WriteLine(new string(' ', Console.BufferWidth));
                Console.SetCursorPosition(0, CursorTop2 - 2);

                switch (Command)
                {
                case "/stats":
                {
                    if (Resources.Started)
                    {
                        Console.WriteLine();
                        Console.WriteLine("# " + DateTime.Now.ToString("d") + " ---- STATS ---- " + DateTime.Now.ToString("T") + " #");
                        Console.WriteLine("# ----------------------------------- #");
                        Console.WriteLine("# In-Memory Players # " + ConsolePad.Padding(Resources.Players.Count.ToString(), 15) + " #");
                        Console.WriteLine("# In-Memory Saea    # " + ConsolePad.Padding(Resources.Gateway.ReadPool.Pool.Count + " - " + Resources.Gateway.WritePool.Pool.Count, 15) + " #");
                        Console.WriteLine("# ----------------------------------- #");
                    }

                    break;
                }

                case "/test":
                {
                    break;
                }

                case "/clear":
                {
                    Console.Clear();
                    break;
                }

                case "/exit":
                case "/shutdown":
                case "/stop":
                {
                    Resources.Events.ExitHandler();
                    break;
                }

                default:
                {
                    Console.WriteLine();
                    break;
                }
                }
            }
        }
Example #4
0
        internal static void Info(Type Type, string Message)
        {
            Resources.Logger.Info(Type.Name + " : " + Message);
#if Console
            Console.WriteLine("[*] " + ConsolePad.Padding(Type.Name, 15) + " : " + Message);
#else
            //Debug.WriteLine("[*] " + ConsolePad.Padding(Type.Name, 15) + " : " + Message);
#endif
        }
Example #5
0
        internal static void Error(Type Type, string Message)
        {
            _logger.Error(Type.Name + " : " + Message);
#if Console
            Console.WriteLine("[*] " + ConsolePad.Padding(Type.Name, 15) + " : " + Message);
#else
            //Debug.WriteLine("[*] " + ConsolePad.Padding(Type.Name, 15) + " : " + Message);
#endif
        }
Example #6
0
        /// <summary>
        /// Shows the values.
        /// </summary>
        internal void ShowValues()
        {
            Logging.Info(this.GetType(), string.Empty);

            foreach (FieldInfo Field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (Field != null)
                {
                    Logging.Info(this.GetType(), ConsolePad.Padding(Field.Name) + " : " + ConsolePad.Padding(!string.IsNullOrEmpty(Field.Name) ? (Field.GetValue(this) != null ? (Field.GetValue(this).ToString().Length > 40 ? string.Join("", Field.GetValue(this).ToString().Take(37).Concat("...")) : Field.GetValue(this).ToString()) : "(null)") : "(null)", 40));
                }
            }
        }
Example #7
0
        private static void SendCallback(IAsyncResult _Ar)
        {
            Message _Message = _Ar.AsyncState as Message;

            if (Settings.Settings.Debug)
            {
                Console.WriteLine("SERVER                  -> " + ConsolePad.Padding(_Message.GetType().Name) + " -> "
                                  + ConsolePad.Padding(
                                      ((IPEndPoint)_Message.Client.Connection.RemoteEndPoint).Address
                                      .ToString())
                                  + " -> " + _Message.Client.Interface);
            }
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PacketUDP"/> class.
        /// </summary>
        public PacketUDP(byte[] Buffer, Device Device)
        {
            if (Buffer.Length > 0)
            {
                using (Reader Reader = new Reader(Buffer))
                {
                    this.Type = Reader.ReadVInt();
                    this.Data = Reader.ReadBytes((int)(Reader.BaseStream.Length - Reader.BaseStream.Position));
                }

                Device.Receive(this.Type, ref this.Data);

                string Name = PacketType.GetName(this.Type);

                Logging.Info(this.GetType(), "Processing packet (" + ConsolePad.Padding(Name, 20) + " | " + this.Type + ") from UDP socket.");
                File.AppendAllText("Logs\\" + ((IPEndPoint)Device.Client.RemoteEndPoint).Address + "\\UDP\\" + Name + "_" + this.Type + ".bin", BitConverter.ToString(this.ToBytes) + Environment.NewLine);
            }
        }
        /// <summary>
        /// Sends the specified message.
        /// </summary>
        internal void SendMessage(Message Message)
        {
            if (Message.Device.Connected)
            {
                if (Message.IsServerToClientMessage)
                {
                    byte[] Bytes = Message.Data.ToArray();

                    if (this.SendEncrypter == null)
                    {
                        if (this.PepperInit.State > 0)
                        {
                            if (this.PepperInit.State == 1)
                            {
                                Bytes = PepperCrypto.SendPepperAuthentificationResponse(ref this.PepperInit, Bytes);
                            }
                            else
                            {
                                if (this.PepperInit.State == 3)
                                {
                                    Bytes = PepperCrypto.SendPepperLoginResponse(ref this.PepperInit, out this.SendEncrypter, out this.ReceiveEncrypter, Bytes);
                                }
                            }
                        }
                    }
                    else
                    {
                        Bytes = this.SendEncrypter.Encrypt(Bytes);
                    }

                    Message.Data.SetByteArray(Bytes);

                    Resources.TCPGateway.Send(Message);
                    Logging.Info(this.GetType(), "Packet " + ConsolePad.Padding(Message.GetType().Name) + "    sent to    " + Message.Device.Socket.RemoteEndPoint + ".");
                }
                else
                {
                    Logging.Info(this.GetType(), "SendMessage() - Trying to send a client to server message. (" + Message.Type + ")");
                }
            }
        }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Calendar"/> class.
        /// </summary>
        public static void Initialize()
        {
            if (Directory.Exists("Gamefiles/offlinedata/"))
            {
                if (File.Exists("Gamefiles/offlinedata/calendar.json"))
                {
                    Calendar.JSON = File.ReadAllText("Gamefiles/offlinedata/calendar.json", Encoding.UTF8);
                    Calendar.JSON = Regex.Replace(Calendar.JSON, "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1");

                    Debug.WriteLine("[*] " + ConsolePad.Padding(typeof(Home).Name, 15) + " : " + "The Calendar JSON has been loaded.");
                }
                else
                {
                    Debug.WriteLine("[*] " + ConsolePad.Padding(typeof(Home).Name, 15) + " : " + "Couldn't load the starting home json file, the file is missing.");
                }
            }
            else
            {
                Debug.WriteLine("[*] " + ConsolePad.Padding(typeof(Home).Name, 15) + " : " + "Couldn't load the starting home json file, the folder is missing.");
            }
        }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Parser"/> class.
        /// </summary>
        internal static void Initialize()
        {
            new Thread(() =>
            {
                while (true)
                {
                    int CursorTop2 = Console.CursorTop = Console.WindowTop + Console.WindowHeight - 1;
                    Console.Write("root@localhost > ");

                    string Command = Console.ReadLine();

                    Console.SetCursorPosition(0, CursorTop2 - 1);
                    Console.WriteLine(new string(' ', Console.BufferWidth));
                    Console.SetCursorPosition(0, CursorTop2 - 2);

                    switch (Command)
                    {
                    case "/stats":
                        {
                            if (Resources.Started)
                            {
                                Console.WriteLine();
                                Console.WriteLine("# " + DateTime.Now.ToString("d") + " ---- STATS ---- " + DateTime.Now.ToString("T") + " #");
                                Console.WriteLine("# ----------------------------------- #");
                                Console.WriteLine("# In-Memory Players # " + ConsolePad.Padding(Resources.Players.Count.ToString(), 15) + " #");
                                Console.WriteLine("# In-Memory Clans   # " + ConsolePad.Padding(Resources.Clans.Count.ToString(), 15) + " #");
                                Console.WriteLine("# In-Memory Battles # " + ConsolePad.Padding(Resources.Battles.Count + " - " + Resources.Battles.Waiting.Count, 15) + " #");
                                Console.WriteLine("# In-Memory Saea    # " + ConsolePad.Padding(Resources.TCPGateway.ReadPool.Pool.Count + " - " + Resources.TCPGateway.WritePool.Pool.Count, 15) + " #");
                                Console.WriteLine("# ----------------------------------- #");
                            }

                            break;
                        }

                    case "/test":
                        {
                            if (Resources.Started)
                            {
                                foreach (Player Player in Resources.Players.Values.ToList())
                                {
                                }
                            }

                            break;
                        }

                    case "/clear":
                        {
                            Console.Clear();
                            break;
                        }

                    case "/exit":
                    case "/shutdown":
                    case "/stop":
                        {
                            EventsHandler.Process();
                            break;
                        }

                    default:
                        {
                            Console.WriteLine();
                            break;
                        }
                    }
                }
            }).Start();
        }
Example #12
0
        /// <summary>
        /// Processes the specified buffer.
        /// </summary>
        /// <param name="Buffer">The buffer.</param>
        internal void Process(byte[] Buffer)
        {
            if (this.State != State.DISCONNECTED)
            {
                if (Buffer.Length >= 7 && Buffer.Length <= Constants.ReceiveBuffer)
                {
                    using (Reader Reader = new Reader(Buffer))
                    {
                        short Identifier = Reader.ReadInt16();
                        int   Length     = Reader.ReadInt24();
                        short Version    = Reader.ReadInt16();

                        if (Buffer.Length - 7 >= Length)
                        {
                            if (this.ReceiveEncrypter == null)
                            {
                                this.InitializeEncrypter(Identifier);
                            }

                            byte[] Packet = this.ReceiveEncrypter.Decrypt(Identifier, Reader.ReadBytes(Length));

                            Message Message = Factory.CreateMessage(Identifier, this, null);

                            if (Message != null)
                            {
                                Message.Length  = Length;
                                Message.Version = Version;

                                Message.Reader = new Reader(Packet);

                                Logging.Info(this.GetType(), "Packet " + ConsolePad.Padding(Message.GetType().Name) + " received from " + this.Socket.RemoteEndPoint + ".");

                                try
                                {
                                    Message.Decode();
                                    Message.Process();
                                }
                                catch (Exception Exception)
                                {
                                    Logging.Error(this.GetType(), Exception.GetType().Name + " when handling the following message : ID " + Identifier + ", Length " + Length + ", Version " + Version + ".");
                                    // Logging.Error(Exception.GetType(), Exception.Message + " [" + (this.Player != null ? this.Player.HighID + ":" + this.Player.LowID : "---") + ']' + Environment.NewLine + Exception.StackTrace);
                                }
                            }

                            if (!this.Token.Aborting)
                            {
                                this.Token.Packet.RemoveRange(0, Length + 7);

                                if (Buffer.Length - 7 - Length >= 7)
                                {
                                    this.Process(Reader.ReadBytes(Buffer.Length - 7 - Length));
                                }
                            }
                        }
                        else
                        {
                            Logging.Error(this.GetType(), "The received buffer length is inferior the header length.");
                        }
                    }
                }
                else
                {
                    Resources.TCPGateway.Disconnect(this.Token.Args);
                }
            }
            else
            {
                if (this.Connected)
                {
                    Resources.TCPGateway.Disconnect(this.Token.Args);
                }
            }
        }
Example #13
0
 /// <summary>
 /// Debugs this instance.
 /// </summary>
 internal void Debug()
 {
     Console.WriteLine(ConsolePad.Padding(this.GetType().Name, 15) + " : " + BitConverter.ToString(this.Reader.ReadBytes((int)(this.Reader.BaseStream.Length - this.Reader.BaseStream.Position))));
 }
Example #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Parser"/> class.
        /// </summary>
        internal static void Initialize()
        {
            new Thread(() =>
            {
                while (true)
                {
                    int CursorTop2 = Console.CursorTop = Console.WindowTop + Console.WindowHeight - 1;
                    Console.Write("root@localhost > ");

                    string Command = Console.ReadLine();

                    Console.SetCursorPosition(0, CursorTop2 - 1);
                    Console.WriteLine(new string(' ', Console.BufferWidth));
                    Console.SetCursorPosition(0, CursorTop2 - 2);

                    switch (Command)
                    {
                    case "/stats":
                        {
                            if (Resources.Started)
                            {
                                Console.WriteLine();
                                Console.WriteLine("# " + DateTime.Now.ToString("d") + " ---- STATS ---- " + DateTime.Now.ToString("T") + " #");
                                Console.WriteLine("# ----------------------------------- #");
                                Console.WriteLine("# In-Memory Players # " + ConsolePad.Padding(Resources.Players.Count.ToString(), 15) + " #");
                                Console.WriteLine("# In-Memory Clans   # " + ConsolePad.Padding(Resources.Clans.Count.ToString(), 15) + " #");
                                Console.WriteLine("# In-Memory Saea    # " + ConsolePad.Padding(Resources.TCPGateway.ReadPool.Pool.Count + " - " + Resources.TCPGateway.WritePool.Pool.Count, 15) + " #");
                                Console.WriteLine("# ----------------------------------- #");
                            }

                            break;
                        }

                    case "/test":
                        {
                            if (Resources.Started)
                            {
                                foreach (Player Player in Resources.Players.Values.ToList())
                                {
                                    new Sector_State_Message(Player.GameMode.Device, Player.GameMode).Send();
                                }
                            }

                            break;
                        }

                    case "/clear":
                        {
                            Console.Clear();
                            break;
                        }

                    case "/exit":
                    case "/shutdown":
                    case "/stop":
                        {
                            EventsHandler.Process();
                            break;
                        }

                    case "/debug":
                        {
                            string[] Names = LogicDebug.GetListOfCommands();

                            for (int i = 0; i < Names.Length; i++)
                            {
                                Console.WriteLine("[DEBUG] Logic : " + ConsolePad.Padding(Names[i]));
                            }

                            break;
                        }

                    default:
                        {
                            LogicDebug.Execute(Command, Resources.Players.Values.ToArray());
                            Console.WriteLine();
                            break;
                        }
                    }
                }
            }).Start();
        }
Example #15
0
        /// <summary>
        /// Processes the specified buffer.
        /// </summary>
        /// <param name="Buffer">The buffer.</param>
        internal void Process(byte[] Buffer)
        {
            if (Buffer.Length >= 7 && Buffer.Length <= Constants.ReceiveBuffer)
            {
                using (Reader Reader = new Reader(Buffer))
                {
                    ushort Identifier = Reader.ReadUInt16();
                    uint   Length     = Reader.ReadUInt24();
                    ushort Version    = Reader.ReadUInt16();

                    if (this.State <= State.LOGIN)
                    {
                        if (Identifier > 10108)
                        {
                            Logging.Error(this.GetType(), "   " + "Packet " + Identifier + " received from " + this.Socket.RemoteEndPoint + ", aborted because client is not logged.");

                            Resources.TCPGateway.Disconnect(this.Token.Args);
                            return;
                        }
                    }

                    if (Buffer.Length - 7 >= Length)
                    {
                        if (Factory.Messages.ContainsKey(Identifier))
                        {
                            Message Message = Activator.CreateInstance(Factory.Messages[Identifier], this, Reader) as Message;

                            Message.Identifier = Identifier;
                            Message.Length     = Length;
                            Message.Version    = Version;

                            Message.Reader = Reader;

                            Logging.Info(this.GetType(), "Packet " + ConsolePad.Padding(Message.GetType().Name) + " received from " + this.Socket.RemoteEndPoint + ".");

                            try
                            {
                                Message.Decrypt();
                                Message.Decode();
                                Message.Process();
                            }
                            catch (Exception Exception)
                            {
                                Logging.Error(this.GetType(), Exception.GetType().Name + " when handling the following message : ID " + Identifier + ", Length " + Length + ", Version " + Version + ".");
                                Logging.Error(Exception.GetType(), Exception.Message + " [" + (this.Player != null ? this.Player.HighID + ":" + this.Player.LowID : "---") + ']' + Environment.NewLine + Exception.StackTrace);
                            }
                        }
                        else
                        {
                            Logging.Info(this.GetType(), "Can't handle the following message : ID " + Identifier + ", Length " + Length + ", Version " + Version + ".");

                            byte[] AltBuffer = Reader.ReadBytes((int)Length);
                            this.Crypto.Decrypt(ref AltBuffer);
                            AltBuffer = null;
                        }

                        if (!this.Token.Aborting)
                        {
                            this.Token.Packet.RemoveRange(0, (int)(Length + 7));

                            if (Buffer.Length - 7 - Length >= 7)
                            {
                                this.Process(Reader.ReadBytes((int)(Buffer.Length - 7 - Length)));
                            }
                        }
                    }
                    else
                    {
                        Logging.Error(this.GetType(), "The received buffer length is inferior the header length.");
                    }
                }
            }
            else
            {
                Resources.TCPGateway.Disconnect(this.Token.Args);
            }
        }
Example #16
0
        /// <summary>
        ///     <see cref="Process" /> the data in the specified range.
        /// </summary>
        /// <param name="_Range">The data range.</param>
        /// <exception cref="TargetInvocationException">
        ///     El constructor que se llama inicia una excepción.
        /// </exception>
        public void Process(int _Range)
        {
            int[] _Header = new int[3];

            if (_Range >= 7)
            {
                using (Reader _Reader = new Reader(this.Stream.ToArray()))
                {
                    _Header[0] = _Reader.ReadUInt16(); // ID
                    _Reader.BaseStream.Seek(1, SeekOrigin.Current);

                    _Header[1] = _Reader.ReadUInt16(); // Length
                    _Header[2] = _Reader.ReadUInt16(); // Version
                    //Debug.Write("_Header[0]: " +_Header[0]);
                    //Debug.Write("_Header[1]: " + _Header[1]);
                    //Debug.Write("_Header[2]: " + _Header[2]);
                    if (this.Stream.Count - 7 >= _Header[1])
                    {
                        if (MessageFactory.m_vMessages.ContainsKey(_Header[0]))
                        {
                            Message _Message =
                                Activator.CreateInstance(MessageFactory.m_vMessages[_Header[0]], this, _Reader, _Header)
                                as Message;
                            Debug.Write("Instancia: " + _Header[0] + " Creanda");
                            if (_Message != null)
                            {
                                if (Core.Settings.Settings.Debug)
                                {
                                    Debug.Write(
                                        ConsolePad.Padding(
                                            ((IPEndPoint)this.Connection.RemoteEndPoint).Address.ToString()) + " -> "
                                        + ConsolePad.Padding(_Message.GetType().Name)
                                        + " -> SERVER                  -> " + this.Interface);
                                }

                                try
                                {
                                    if (_Header[0] != 10108 && _Header[0] != 10107)
                                    {
                                        Debug.Write(
                                            "Decrypt: " + _Header[0] + " " + _Message.GetType().Name + "  Iniciado...");
                                    }
                                    _Message.Decrypt();
                                    if (_Header[0] != 10108 && _Header[0] != 10107)
                                    {
                                        Debug.Write(
                                            "Decrypt: " + _Header[0] + " " + _Message.GetType().Name + "  terminado");
                                    }
                                    if (_Header[0] != 10108 && _Header[0] != 10107)
                                    {
                                        Debug.Write(
                                            "Decode: " + _Header[0] + " " + _Message.GetType().Name + "  Iniciado...");
                                    }

                                    _Message.Decode();
                                    if (_Header[0] != 10108 && _Header[0] != 10107)
                                    {
                                        Debug.Write(
                                            "Decode: " + _Header[0] + " " + _Message.GetType().Name + "  terminado");
                                    }
                                    if (_Header[0] != 10108 && _Header[0] != 10107)
                                    {
                                        Debug.Write(
                                            "Process: " + _Header[0] + " " + _Message.GetType().Name + "  Iniciado...");
                                    }

                                    _Message.Process(_Message.Client.GetLevel());
                                    if (_Header[0] != 10108 && _Header[0] != 10107)
                                    {
                                        Debug.Write("Process: " + _Header[0] + "  terminado");
                                    }
                                }
                                catch (Exception _Error)
                                {
                                    Debug.Write("The player " + (string.IsNullOrEmpty(_Message.Client.GetLevel().GetPlayerAvatar().GetAvatarName()) ? "with ID " + _Message.Client.GetLevel().GetPlayerAvatar().GetId() : "with name '" + _Message.Client.GetLevel().GetPlayerAvatar().GetAvatarName()) + " throwed an exception." + _Error);
                                    Debug.Write(Debug.FlattenException(_Error));
                                    if (this.SNonce != null)
                                    {
                                        Debug.Write("this.SNonce != null");
                                        if (this.State >= State.LOGGED)
                                        {
                                            Debug.Write("this.State >= State.LOGGED" + this.State);
                                            // this.SNonce.Increment();
                                        }
                                        else
                                        {
                                            Debug.Write("Login Failed");
                                            // Login Failed.
                                        }
                                    }
                                    else
                                    {
                                        Debug.Write("SNonce=Null");
                                        if (this.Errors > 5)
                                        {
                                            Debug.Write("this.Errors: " + this.Errors);
                                            ResourcesManager.Remove(this);
                                        }
                                        else
                                        {
                                            this.Errors = this.Errors + 1;
                                            Debug.Write("this.Errors: " + this.Errors);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Debug.Write("Message is null!!");
                            }
                        }
                        else
                        {
                            Debug.Write("Message Factory no contain: " + _Header[0] + " can't be processed.");
                            this.SNonce.Increment();
                            Debug.Write("The message " + _Header[0] + " can't be processed.");
                        }

                        this.Stream.RemoveRange(0, _Header[1] + 7);
                    }
                    else
                    {
                        Debug.Write("this.Stream.Count - 7 >= _Header[1] = false");
                    }
                }
            }
            else
            {
                Debug.Write("_Range > 7 NADA QUE HACER!");
            }
        }
Example #17
0
        public void Process(int _Range)
        {
            int[] _Header = new int[3];

            if (_Range >= 7)
            {
                using (Reader _Reader = new Reader(DataStream.ToArray()))
                {
                    _Header[0] = _Reader.ReadUInt16(); // ID

                    _Reader.BaseStream.Seek(1, SeekOrigin.Current);

                    _Header[1] = _Reader.ReadUInt16(); // Length
                    _Header[2] = _Reader.ReadUInt16(); // Version

                    if (DataStream.Count - 7 >= _Header[1])
                    {
                        if (MessageFactory.m_vMessages.ContainsKey(_Header[0]))
                        {
                            Message _Message = Activator.CreateInstance(MessageFactory.m_vMessages[_Header[0]], this, _Reader, _Header) as Message;
                            Level   pl       = _Message.Client.GetLevel();
                            if (_Message != null)
                            {
                                if (Core.Settings.Settings.Debug)
                                {
                                    Console.WriteLine(ConsolePad.Padding(((IPEndPoint)Connection.RemoteEndPoint).Address.ToString()) + " -> " + ConsolePad.Padding(_Message.GetType().Name) + " -> SERVER                  -> " + Interface);
                                }

                                try
                                {
                                    _Message.Decrypt();
                                    _Message.Decode();
                                    _Message.Process();
                                }
                                catch (Exception _Error)
                                {
                                    Console.WriteLine("The player " + (string.IsNullOrEmpty(pl.GetPlayerAvatar().GetAvatarName()) ? "with ID " + pl.GetPlayerAvatar().GetId() : "with name '" + pl.GetPlayerAvatar().GetAvatarName()) + " throwed an exception.");

                                    if (SNonce != null)
                                    {
                                        if (State >= State.LOGGED)
                                        {
                                            // this.SNonce.Increment();
                                        }
                                        else
                                        {
                                            // Login Failed.
                                        }
                                    }
                                    else
                                    {
                                        if (Errors > 5)
                                        {
                                            ResourcesManager.DropClient(this.m_vSocketHandle);
                                        }
                                        else
                                        {
                                            Errors = Errors + 1;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            SNonce.Increment();
                            Console.WriteLine("The message " + _Header[0] + " can't be processed.");
                        }

                        DataStream.RemoveRange(0, _Header[1] + 7);
                    }
                }
            }
        }
Example #18
0
        /// <summary>
        /// Processes the specified buffer.
        /// </summary>
        /// <param name="Buffer">The buffer.</param>
        internal void Process(byte[] Buffer)
        {
            if (Buffer.Length >= 7 && Buffer.Length <= Constants.ReceiveBuffer && this.CanProcessed)
            {
                using (Reader Reader = new Reader(Buffer))
                {
                    ushort Identifier = Reader.ReadUInt16();
                    uint   Length     = Reader.ReadUInt24();
                    ushort Version    = Reader.ReadUInt16();

                    Logging.Error(this.GetType(), "Packet " + Identifier + " received from " + this.Socket.RemoteEndPoint + ".");

                    if (Buffer.Length - 7 >= Length)
                    {
                        if (Factory.Messages.ContainsKey(Identifier))
                        {
                            Message Message = Activator.CreateInstance(Factory.Messages[Identifier], this, Reader) as Message;

                            Message.Identifier = Identifier;
                            Message.Length     = Length;
                            Message.Version    = Version;

                            Message.Reader = Reader;

                            try
                            {
                                Message.Decrypt();
                                Message.Decode();
                                Message.Process();
                            }
                            catch (Exception Exception)
                            {
                                Resources.Sentry.Catch(Exception, this.Model, this.OS, this.OSVersion);
                                Resources.Logger.Error(Exception, "We got an error (" + Exception.GetType().Name + ") when handling the following message : ID " + Identifier + ", Length " + Length + ", Version " + Version + ".");
                                System.Diagnostics.Debug.WriteLine(ConsolePad.Padding(Exception.GetType().Name, 15) + " : " + Exception.Message + ". [" + (this.Player != null ? this.Player.HighID + ":" + this.Player.LowID : "---") + ']' + Environment.NewLine + Exception.StackTrace);
                            }
                        }
                        else
                        {
                            Resources.Logger.Debug(this.GetType().Name + " : " + "We can't handle the following message : ID " + Identifier + ", Length " + Length + ", Version " + Version + ".");

                            byte[] AltBuffer = Reader.ReadBytes((int)Length);
                            this.Crypto.Decrypt(ref AltBuffer);
                            AltBuffer = null;
                        }

                        if (!this.Token.Aborting)
                        {
                            this.Token.Packet.RemoveRange(0, (int)(Length + 7));

                            if (Buffer.Length - 7 - Length >= 7)
                            {
                                this.Process(Reader.ReadBytes((int)(Buffer.Length - 7 - Length)));
                            }
                        }
                    }
                    else
                    {
                        Resources.Gateway.Disconnect(this.Token.Args);
                    }
                }
            }
            else
            {
                Resources.Gateway.Disconnect(this.Token.Args);
            }
        }
 /// <summary>
 /// Writes the line.
 /// </summary>
 /// <param name="Message">The message.</param>
 public override void WriteLine(string Message)
 {
     Debug.WriteLine("[*] " + ConsolePad.Padding("Redis", 15) + " : " + Message);
 }