Exemple #1
0
 public void Send(Packet p)
 {
     if (this.clientSocket != null)
     {
         bool   encrypt = IsCrypted(p.PacketID);
         byte[] buffer  = p.Compile(this, encrypt);
         if (buffer != null)
         {
             int length = buffer.Length;
             if (length > 0)
             {
                 try
                 {
                     this.clientSocket.Send(buffer);
                 }
                 catch (Exception exception)
                 {
                     LogConsole.Show(LogType.DEBUG, exception.ToString());
                 }
             }
         }
         else
         {
         }
     }
 }
Exemple #2
0
 public static byte[] DecryptStaticBuffer(byte[] decryptme)
 {
     if (decryptme.Length != 0x10)
     {
         LogConsole.Show(LogType.DEBUG, "DecyryptStatic() is 128-bit only.");
         return(null);
     }
     return(DecryptStatic(decryptme));
 }
 public void WriteASCIIZ(string value)
 {
     if (value == null)
     {
         LogConsole.Show(LogType.DEBUG, "Null string in Network.PacketWriter.WriteASCIIZ");
         value = string.Empty;
     }
     byte[] bytes = Utils.GetBytes(value);
     this.m_Stream.Write(bytes, 0, bytes.Length);
     this.m_Stream.WriteByte(0);
 }
Exemple #4
0
            public static void Pack1(Client state, PacketReader2 pv)
            {
                LogConsole.Show(LogType.DEBUG, "OpCode->Pack1()");
                byte[] unk1    = pv.ReadBytes(0x10);
                byte[] buffer2 = pv.ReadBytes(0x10);
                byte[] xd2     = Crypto.DecryptStaticBuffer(unk1);
                string aSCIIZ  = Utils.GetASCIIZ(xd2);

                LogConsole.Show(LogType.DEBUG, "Login: {0}", aSCIIZ);

                //state.Send(new LoginResponse(LoginResponseCode.Prohibited, -1, "HAHAHAHAHAHAHAHA!!"));
                state.Send(new LoginResponse(LoginResponseCode.LoginSuccessful));
            }
 public static void ReleaseInstance(PacketWriter pw)
 {
     lock (m_Pool)
     {
         if (!m_Pool.Contains(pw))
         {
             m_Pool.Push(pw);
         }
         else
         {
             LogConsole.Show(LogType.DEBUG, "Packet.ReleaseInstance - Buffer pool already exists!! ");
         }
     }
 }
Exemple #6
0
            public bool PacketDecrypt(byte[] input, ref byte[] output, ushort packetid)
            {
                if (input.Length == 0)
                {
                    LogConsole.Show(LogType.DEBUG, "Empty buffer passed for decryption");
                    return(false);
                }
                if ((input.Length % 0x10) != 0)
                {
                    LogConsole.Show(LogType.DEBUG, "Decrypt failed. Input byte count is not a multiple of 16.");
                    return(false);
                }
                int num  = input.Length / 0x10;
                int num2 = num * 12;

                byte[] buffer  = new byte[input.Length];
                byte[] buffer2 = new byte[num2];
                buffer = this.DecryptDynamic(input);
                PacketReader2 reader = new PacketReader2(buffer, buffer.Length);
                uint          num3   = 0xa8c2e5c1;

                for (int i = 0; i < num; i++)
                {
                    reader.Seek(0x10 * i, SeekOrigin.Begin);
                    uint num5 = reader.ReadUInt32();
                    //if ((num5 - packetid) != num3)
                    if ((2831345089) != num3)
                    {
                        LogConsole.Show(LogType.DEBUG, "-----------------------------------");
                        LogConsole.Show(LogType.DEBUG, "Num5 = " + num5);
                        LogConsole.Show(LogType.DEBUG, "packetid = " + packetid);
                        LogConsole.Show(LogType.DEBUG, "num5 - packetid = " + (num5 - packetid));
                        LogConsole.Show(LogType.DEBUG, "num3 = " + num3);
                        LogConsole.Show(LogType.DEBUG, "ReadUInt32 = " + reader.ReadUInt32());
                        LogConsole.Show(LogType.DEBUG, "Bad Packet Signature. G: {0,8:X8} E: {1,8:X8}", new object[] { num5, num3 + packetid });
                        return(false);
                    }
                    for (int j = 4; j < 0x10; j++)
                    {
                        buffer2[(i * 12) + (j - 4)] = buffer[(i * 0x10) + j];
                    }
                }
                output = buffer2;
                return(true);
            }
 public void WriteASCIIFixed(string value, int length)
 {
     if (value == null)
     {
         LogConsole.Show(LogType.DEBUG, "Null string in Network.PacketWriter.WriteASCIIFixed");
         value = string.Empty;
     }
     byte[] bytes = Utils.GetBytes(value);
     if (bytes.Length >= length)
     {
         this.m_Stream.Write(bytes, 0, length);
     }
     else
     {
         this.m_Stream.Write(bytes, 0, bytes.Length);
         this.Fill(length - bytes.Length);
     }
 }
Exemple #8
0
            private void InternalCompile(Client state, bool encrypt)
            {
                if (state == null)
                {
                    LogConsole.Show(LogType.DEBUG, "Null NetState passed in Network.Packet.Compile()");
                }
                if (this.m_Length == 0)
                {
                    long num = this.m_Stream.Length;
                    this.m_Stream.Seek(0L, SeekOrigin.Begin);
                    this.m_Stream.Write((ushort)num);
                }
                else if (this.m_Stream.Length != this.m_Length)
                {
                    LogConsole.Show(LogType.DEBUG, "Packet {0:X2}: Bad packet length, Expected {1} , Stream {2}", new object[] { this.m_PacketID, this.m_Length, this.m_Stream.Length });
                }
                MemoryStream underlyingStream = this.m_Stream.UnderlyingStream;

                this.m_FinalBuffer = underlyingStream.GetBuffer();
                int length = (int)underlyingStream.Length;

                if (!encrypt)
                {
                    ControlCode sendControlCode = new ControlCode(true);
                    if (state.FirstPacketSent)
                    {
                        sendControlCode.Update(length - 4);
                    }
                    this.m_Stream.Seek(2L, SeekOrigin.Begin);
                    this.m_Stream.Write(sendControlCode.Value);
                }
                if (this.m_FinalBuffer != null)
                {
                    byte[] finalBuffer = this.m_FinalBuffer;
                    this.m_FinalBuffer = new byte[length];
                    Buffer.BlockCopy(finalBuffer, 0, this.m_FinalBuffer, 0, length);
                }
                this.m_Stream = null;
            }
Exemple #9
0
            //private UserInfo m_UserInfo;

            public void ReceiveData(IAsyncResult ar)
            {
                Socket wSocket = (Socket)ar.AsyncState;

                try
                {
                    if (wSocket.Connected)
                    {
                        int  recvSize  = wSocket.EndReceive(ar); // get the count of received bytes
                        bool checkData = true;
                        if (recvSize > 0)
                        {
                            if ((recvSize + bufCount) > MAX_BUFFER)  // that may be a try to force buffer overflow, we don't allow that ;)
                            {
                                checkData = false;
                                LocalDisconnect(wSocket);
                            }
                            else
                            {                                                            // we have something in input buffer and it is not beyond our limits
                                Buffer.BlockCopy(tmpbuf, 0, buffer, bufCount, recvSize); // copy the new data to our buffer
                                bufCount += recvSize;                                    // increase our buffer-counter
                            }
                        }
                        else
                        {   // 0 bytes received, this should be a disconnect
                            checkData = false;
                            LocalDisconnect(wSocket);
                        }

                        while (checkData) // repeat while we have
                        {
                            checkData = false;
                            if (bufCount >= 4)                                       // a minimum of 4 byte is required for us
                            {
                                Decode de = new Decode(buffer);                      // only get get the size first
                                LogConsole.Show(LogType.DEBUG, "Decode()");
                                if (bufCount >= (de.dataSize - 2))                   // that's a complete packet, lets call the handler
                                {
                                    de = new Decode(wSocket, buffer, this, Packets); // build up the Decode structure for next step
                                    LogConsole.Show(LogType.DEBUG, "Decode()->dataSize");
                                    queue.Enqueue(buffer, 0, bufCount);
                                    OnReceiveData(de, this);                                            // call the handling routine
                                    bufCount -= (de.dataSize);                                          // decrease buffer-counter
                                    if (bufCount > 0)                                                   // was the buffer greater than the packet needs ? then it may be the next packet
                                    {
                                        Buffer.BlockCopy(buffer, 2 + de.dataSize, buffer, 0, bufCount); // move the rest to buffer start
                                        checkData = true;                                               // loop for next packet
                                    }
                                }
                                de = null;
                            }
                        }
                        // start the next async read
                        if (wSocket != null && wSocket.Connected)
                        {
                            wSocket.BeginReceive(tmpbuf, 0, tmpbuf.Length, SocketFlags.None, new AsyncCallback(ReceiveData), wSocket);
                        }
                    }
                    else
                    {
                        LocalDisconnect(wSocket);
                    }
                }
                catch (SocketException)  // explicit handling of SocketException
                {
                    LocalDisconnect(wSocket);
                }
                catch (Exception) // other exceptions
                {
                    LocalDisconnect(wSocket);
                }
            }
        public static void OpCode(Decode state, Client ed)
        {
            try
            {
                LogConsole.Show(LogType.DEBUG, "OpCode()");
                Systems sys = (Systems)state.Packet;
                sys.PacketInformation = state;

                ByteQueue queue = ed.queue;

                int length = queue.Length;
                LogConsole.Show(LogType.DEBUG, "OpCode() {0}", length);
                while ((length > 0))
                {
                    byte[] buffer;
                    int    packetID          = queue.GetPacketID();
                    int    packetLength      = queue.GetPacketLength();
                    int    packetControlCode = queue.GetPacketControlCode();

                    LogConsole.Show(LogType.DEBUG, "PacketControl: {0} PacketID: 0x{1:X2} Length: {2}", packetControlCode, packetID, packetLength);
                    LogConsole.HexDump(state.buffer, "", 16);

                    PacketHandler handler = PacketHandlers.GetHandler(packetID);
                    if (handler == null)
                    {
                        byte[] buffer2 = new byte[length];
                        length = queue.Dequeue(buffer2, 0, length);
                        LogConsole.Show(LogType.DEBUG, "Client: {0}: Unhandled packet 0x{1:X2}", new object[] { state, packetID });
                        break;
                    }

                    int size = handler.Length;
                    if (length >= 4)
                    {
                        size = packetLength;
                        if (packetLength >= 4)
                        {
                            if (length < size)
                            {
                                break;
                            }

                            if (0x400 >= size)
                            {
                                buffer = m_Buffers.AquireBuffer();
                            }
                            else
                            {
                                buffer = new byte[size];
                            }

                            size = queue.Dequeue(buffer, 0, size);

                            ushort packetid = ByteQueue.GetPacketID(buffer);

                            bool flag = IsCrypted(packetid);
                            if (flag)
                            {
                                LogConsole.Show(LogType.DEBUG, "Crypted Packet 0x{0:X4}", new object[] { packetid });
                            }

                            try
                            {
                                PacketReader2 pr = new PacketReader2(buffer, size);
                                handler.OnReceive(ed, pr);
                            }
                            catch { break; }

                            length = queue.Length;
                            if ((0x400 >= size) && !flag)
                            {
                                m_Buffers.ReleaseBuffer(buffer);
                                break;
                            }
                        }
                    }

                    length = 0;
                }
            }
            catch (Exception)
            {
            }
        }
Exemple #11
0
        static void Main(string[] args)
        {
            Program pro = new Program();

            LogConsole._Load();
            Systems.Ini ini = null;

            #region Default Settings
            int    LSPort  = 8372;
            int    IPCPort = 8500;
            string LSIP    = "127.0.0.1";
            string IPCIP   = "127.0.0.1";

            string m_host = "localhost";
            string m_user = "******";
            string m_pass = "";
            string m_db   = "";
            int    m_port = 3306;
            #endregion

            #region Load Settings
            try
            {
                if (File.Exists(Environment.CurrentDirectory + @"\Settings\Settings.ini"))
                {
                    ini    = new Systems.Ini(Environment.CurrentDirectory + @"\Settings\Settings.ini");
                    LSPort = Convert.ToInt32(ini.GetValue("Server", "port", 8372));
                    LSIP   = ini.GetValue("Server", "ip", "127.0.0.1").ToString();
                    VER    = ini.GetValue("Server", "ver", 1);

                    IPCPort = Convert.ToInt32(ini.GetValue("IPC", "port", 8500));
                    IPCIP   = ini.GetValue("IPC", "ip", "127.0.0.1").ToString();
                    DEBUG   = Convert.ToBoolean(ini.GetValue("CONSOLE", "debug", "false"));

                    m_host = ini.GetValue("MySQL", "host", "localhost").ToString();
                    m_user = ini.GetValue("MySQL", "user", "root").ToString();
                    m_pass = ini.GetValue("MySQL", "pass", "").ToString();
                    m_db   = ini.GetValue("MySQL", "data", "").ToString();
                    m_port = Convert.ToInt32(ini.GetValue("MySQL", "port", 3306));

                    ini = null;
                    LogConsole.Show(LogType.INFO, "Has loaded your ip settings successfully");
                }
                else
                {
                    LogConsole.Show(LogType.ALERT, "Settings.ini could not be found, using default setting");
                }
            }
            catch (Exception excc)
            {
                LogConsole.Show(LogType.ERROR, " {0}", excc.ToString());
                return;
            }
            #endregion

            Systems.Crypto.Initialize();
            Systems.Server net = new Systems.Server();
            net.OnConnect += new Systems.Server.dConnect(pro._OnClientConnect);
            net.OnError   += new Systems.Server.dError(pro._ServerError);

            Systems.Client.OnReceiveData += new Systems.Client.dReceive(pro._OnReceiveData);
            Systems.Client.OnDisconnect  += new Systems.Client.dDisconnect(pro._OnClientDisconnect);

            try
            {
                net.Start(LSIP, LSPort);
            }
            catch (Exception ex)
            {
                LogConsole.Show(LogType.ERROR, "Starting Server error: {0}", ex);
            }



            _LoopThrreading          = new Thread(new ThreadStart(Program.LoopConsole));
            _LoopThrreading.Priority = ThreadPriority.BelowNormal;
            _LoopThrreading.Start();

            while (true)
            {
                Thread.Sleep(100);
            }
        }
Exemple #12
0
 public void _OnClientConnect(ref object de, Systems.Client net)
 {
     LogConsole.Show(LogType.DEBUG, "_OnClientConnect");
     de = new Systems(net);
 }