예제 #1
0
        public static PacketProcessResult HandleClient(Packet pck, RelaySession session)
        {
            byte locale = pck.ReadUInt8();
            string username = pck.ReadAscii();
            string password = pck.ReadAscii();
            ushort ServerID = pck.ReadUInt16();
            //проверить
            if (Global.EnableIpAccountLimitation)
            {

                int nResult = Global.dbmgr.GetIpLimitationResult(username, Utility.GetRemoteEpString(session.Arguments.ClientSocket));
                if (nResult == 0)
                {
                    Packet login_response = new Packet(0xA102, false);
                    login_response.WriteUInt8(0x02);
                    login_response.WriteUInt8(12);
                    session.SendPacketToClient(login_response);
                    //drop conn
                    return PacketProcessResult.Disconnect;
                }
            }
            if (Global.EnableLoginProcessing)
            {

                Packet login = new Packet(0x6102);
                login.WriteUInt8(Global.OriginalLocale > 0 && locale > 0 ? Global.OriginalLocale : locale);
                login.WriteAscii(username);
                login.WriteAscii(Global.EnableUseSha1Salt ? Utility.HashPassword(username, password) : password);
                login.WriteUInt16(ServerID);
                session.SendPacketToModule(login);
                //return PacketProcessResult.DoNothing;
                return PacketProcessResult.ContinueLoop;
            }
            return PacketProcessResult.DoNothing;
        }
예제 #2
0
        public static PacketProcessResult HandleClient(Packet pck, RelaySession session, SilkroadServer server)
        {
            byte locale = pck.ReadUInt8();
            string username = pck.ReadAscii();
            string password = pck.ReadAscii();
            ushort ServerID = pck.ReadUInt16();

            if (Global.EnableServerInspection && !Global.InspectionLoginIgnore.Contains(username))
            {
                Packet login_response = new Packet(0xA102, false);
                login_response.WriteUInt8(0x02);
                login_response.WriteUInt8(0x02);
                login_response.WriteUInt8(0x02);
                session.SendPacketToClient(login_response);

                return PacketProcessResult.Disconnect;
            }

            if (Global.EnableIpAccountLimitation)
            {
                //We use Utility.GetRemoteEpString because username is assigned after AgentServer.UserAuth
                string clientAddr = Utility.GetRemoteEpString(session.Arguments.ClientSocket);
                int connectionCount = Global.srvmgr.GetUserCountByIpForAgent(clientAddr);

                if (connectionCount >= Global.AccountIpLimitCount)
                {
                    Packet login_resp = new Packet(0xA102, false);
                    login_resp.WriteUInt8(0x02);
                    login_resp.WriteUInt8(12);
                    session.SendPacketToClient(login_resp);

                    return PacketProcessResult.Disconnect;
                }
            }

            int serverOnline = 0;
            int.TryParse(session.State["server_" + ServerID] as string, out serverOnline);
            if (Global.ShardMaxOnline > 0 && Global.ShardMaxOnline <= serverOnline)
            {
                Packet login_response = new Packet(0xA102, false);
                login_response.WriteUInt8(0x02);
                login_response.WriteUInt8(5);
                session.SendPacketToClient(login_response);
                return PacketProcessResult.Disconnect;
            }

            if (Global.EnableLoginProcessing)
            {

                Packet login = new Packet(0x6102);
                login.WriteUInt8(Global.OriginalLocale > 0 && locale > 0 ? Global.OriginalLocale : locale);
                login.WriteAscii(username);
                login.WriteAscii(Global.EnableUseSha1Salt ? Utility.HashPassword(username, password) : password);
                login.WriteUInt16(ServerID);
                session.SendPacketToModule(login);
                //return PacketProcessResult.DoNothing;
                return PacketProcessResult.ContinueLoop;
            }
            return PacketProcessResult.DoNothing;
        }
        public static PacketProcessResult HandleModule(Packet pck, RelaySession session, SilkroadServer server)
        {
            Packet ServerList = new Packet(0xA101);
            byte GlobalOperationFlag = pck.ReadUInt8();

            ServerList.WriteUInt8(GlobalOperationFlag);

            while (GlobalOperationFlag == 1)
            {
                byte GlobalOperationType = pck.ReadUInt8();
                string GlobalOperationName = pck.ReadAscii();

                GlobalOperationFlag = pck.ReadUInt8();
                ServerList.WriteUInt8(GlobalOperationType);
                ServerList.WriteAscii(GlobalOperationName);
                ServerList.WriteUInt8(GlobalOperationFlag);
            }
            byte ShardFlag = pck.ReadUInt8();

            ServerList.WriteUInt8(ShardFlag);

            while (ShardFlag == 1)
            {
                uint ShardID = pck.ReadUInt16();
                string ShardName = pck.ReadAscii();
                uint ShardCurrent = pck.ReadUInt16();
                uint ShardCapacity = pck.ReadUInt16();
                byte ShardStatus = pck.ReadUInt8();
                byte GlobalOperationID = pck.ReadUInt8();
                ShardFlag = pck.ReadUInt8();
                session.State["server_" + ShardID] = ShardCurrent;

                ServerList.WriteUInt16(ShardID);
                ServerList.WriteAscii("Возрождение", Global.TextEncodeCode);
                ServerList.WriteUInt16(ShardCurrent + Global.ShardFakeOnline);
                ServerList.WriteUInt16(Global.ShardMaxOnline > 0 ? (uint)Global.ShardMaxOnline : ShardCapacity);
                ServerList.WriteUInt8(ShardStatus);
                ServerList.WriteUInt8(GlobalOperationID);
                ServerList.WriteUInt8(ShardFlag);

            }
            session.SendPacketToClient(ServerList);
            return PacketProcessResult.ContinueLoop;
        }
예제 #4
0
        public static PacketProcessResult HandleModule(Packet pck, RelaySession session, SilkroadServer server)
        {
            if (server.HasAgentRedirectRules())
            {
                string src_host;
                int src_port;
                byte flag1 = pck.ReadUInt8();

                if (flag1 == 1)
                {
                    UInt32 uint1 = pck.ReadUInt32();
                    src_host = pck.ReadAscii();
                    src_port = pck.ReadUInt16();

                    bool redirectRuleFound = false;
                    for (int j = 0; j < server.RedirectRules.Count; j++)
                    {

                        if (server.RedirectRules[j].OriginalIp == src_host && server.RedirectRules[j].OriginalPort == src_port)
                        {
                            Packet mypck = new Packet(0xA102, false);
                            mypck.WriteUInt8(flag1);
                            mypck.WriteUInt32(uint1);
                            mypck.WriteAscii(server.RedirectRules[j].NewIp);
                            mypck.WriteUInt16((ushort)server.RedirectRules[j].NewPort);

                            //  m_ClientSecurity.Send(mypck);
                            session.SendPacketToClient(mypck);
                            redirectRuleFound = true;

                            break;

                        }

                    }
                    if (!redirectRuleFound)
                    {
                        Global.logmgr.WriteLog(LogLevel.Warning, "Agent redirect rules given, but [{0}:{1}] is unknown agent server", src_host, src_port);
                    }
                    else
                    {
                        return PacketProcessResult.ContinueLoop;
                    }

                }

            }
            return PacketProcessResult.DoNothing;
        }
예제 #5
0
        public static PacketProcessResult HandleClient(Packet pck, RelaySession session, SilkroadServer server)
        {
            UInt32 uint32_1 = pck.ReadUInt32();
            string uname = pck.ReadAscii();
            string passw = pck.ReadAscii();
            byte locale = pck.ReadUInt8();
            uint ukn1 = pck.ReadUInt32();
            uint ukn = pck.ReadUInt16();
            if (uname.Contains("'"))
            {
                Global.logmgr.WriteLog(LogLevel.Error, "User trying to exploit username: {0}", uname);
                return PacketProcessResult.Disconnect;
            }
            //инициализурем данные
            session.State["username"] = uname;
            session.State["isBot"] = false;
            session.State["isSafe"] = false;
            session.State["noticeDone"] = false;
            session.State["lastExchange"] = DateTime.Now;
            session.State["lastLogOut"] = DateTime.Now;
            session.State["lastStall"] = DateTime.Now;
            session.State["proper_logout"] = false;
            session.State["level"] = 0;
            //пишем в базу что юзер залогинился
            Global.dbmgr.AnticheatAuthLog(uname, session.State["ip_address"] as string);

            Global.logmgr.WriteLog(LogLevel.Notify, "User logged in [{0}]", uname);

            if (Global.EnableBotDetected && locale == Global.OriginalLocale)
            {
                session.State["isBot"] = true;
            }
            if (Global.EnableLoginProcessing)
            {
                Packet p = new Packet(0x6103);
                p.WriteUInt32(uint32_1);
                p.WriteAscii(uname);
                p.WriteAscii(Global.EnableUseSha1Salt ? Utility.HashPassword(uname, passw) : passw);
                p.WriteUInt8(Global.OriginalLocale > 0 && locale > 0 ? Global.OriginalLocale : locale);
                p.WriteUInt32(ukn1);
                p.WriteUInt16(ukn);
                // m_ModuleSecurity.Send(p);
                session.SendPacketToModule(p);
                return PacketProcessResult.ContinueLoop;
            }
            return PacketProcessResult.DoNothing;
        }
예제 #6
0
        public static PacketProcessResult HandleClient(Packet pck, RelaySession session, SilkroadServer server)
        {
            if (Global.EnableGmAccessControl)
            {
                //Делаем запрос в базу и проверяем разрешеная ли команда
                uint commandID = pck.ReadUInt16();

                string uname = session.State["username"] as string;
                if (Global.dbmgr.checkGmAccessControl(uname, commandID) == 1)
                {

                    if (commandID == 6 || commandID == 7)
                    {
                        //Делаем проверку на разрешение использовать этот ID
                        uint obj_id = pck.ReadUInt32();
                        uint amountOrOptLevel = pck.ReadUInt8();

                        if (Global.dbmgr.checkGmObjAccessControl(uname, obj_id, amountOrOptLevel) == 0)
                        {
                            session.SendClientNotice("UIIT_STT_ANTICHEAT_GM_USE_CREATE");
                            return PacketProcessResult.ContinueLoop;

                        }
                    }
                    //Убираем возможность полноценно килять мобов гму.
                    if (commandID == 20)
                    {
                        uint k_mob_id = pck.ReadUInt32();
                        Packet p = new Packet(0x7010);
                        p.WriteUInt16(20);
                        p.WriteUInt32(k_mob_id);
                        p.WriteUInt8(1);
                        session.SendPacketToModule(p);
                        return PacketProcessResult.ContinueLoop;
                    }
                }
                else
                {
                    session.SendClientNotice("UIIT_STT_ANTICHEAT_GM_USE_COMMAND");
                    return PacketProcessResult.ContinueLoop;
                }
            }

            return PacketProcessResult.DoNothing;
        }
예제 #7
0
        private void HandleTransferIncoming()
        {
            foreach (Context context in _contexts) // Logic event processing
            {
                _incomingPackets = context.MySecurity.TransferIncoming();

                if (_incomingPackets != null)
                {
                    foreach (Packet packet in _incomingPackets)
                    {
                        if (context == _remoteContext)
                        {

                            if (packet.Opcode == 0x9000 || packet.Opcode == 0x5000)
                            {
                                continue;
                            }

                            if (packet.Opcode == 0xA102)
                            {
                                byte result = packet.ReadUInt8();
                                if (result == 1)
                                {
                                    uint id = packet.ReadUInt32();
                                    string ip = packet.ReadAscii();
                                    ushort port = packet.ReadUInt16();

                                    lock (_silkroadProxy)
                                    {
                                        _silkroadProxy.AcceptAgentConnection(ip, port);
                                    }

                                    //CA2000 don't care
                                    Packet new_packet = new Packet(0xA102, true);
                                    new_packet.WriteUInt8(result);
                                    new_packet.WriteUInt32(id);
                                    new_packet.WriteAscii("127.0.0.1");
                                    new_packet.WriteUInt16(15779);

                                    context.MyRelaySecurity.Send(new_packet);
                                    continue;
                                }
                            }

                            if (packet.Opcode == 0x2322)
                            {
                                CapchaKiller killer = new CapchaKiller(packet.GetBytes());
                                string result = killer.GetStringCapcha();

                                Packet new_packet = new Packet(0x6323, false);
                                new_packet.WriteAscii(result, 20127);
                                context.MySecurity.Send(new_packet);
                                continue;
                            }

                            if (ServerPacketHandler(context, packet))
                            {
                                continue;
                            }

                            context.MyRelaySecurity.Send(packet);
                        }

                        if (context == _localContext)
                        {
                            if (packet.Opcode == 0x9000 || packet.Opcode == 0x5000 || packet.Opcode == 0x2001)
                            {
                                continue;
                            }

                            if (ClientPacketHandler(context, packet))
                            {
                                continue;
                            }

                            context.MyRelaySecurity.Send(packet);
                        }

                        GC.Collect();
                    }
                }
            }
        }
        /// <summary>
        /// DownloadServer info / patch info request packet (Module -> Client)
        /// </summary>
        /// <param name="pck"></param>
        /// <param name="session"></param>
        /// <returns></returns>
        public static PacketProcessResult HandleModule(Packet pck, RelaySession session, SilkroadServer server)
        {
            if (server.HasDownloadRedirectRules())
            {
                //Read original data
                byte result = pck.ReadUInt8();

                //UpdateInfo
                if (result == 0x02)
                {
                    byte errorCode = pck.ReadUInt8();

                    if (errorCode == 0x02)
                    {
                        Packet myPacket = new Packet(0xA100, false, true);

                        string tmpIp = pck.ReadAscii();
                        ushort tmpPort = pck.ReadUInt16();

                        bool redirectRuleFound = false;
                        for (int i = 0; i < server.RedirectRules.Count; i++)
                        {
                            if (server.RedirectRules[i].OriginalIp == tmpIp && server.RedirectRules[i].OriginalPort == tmpPort)
                            {
                                tmpIp = server.RedirectRules[i].NewIp;
                                tmpPort = (ushort)server.RedirectRules[i].NewPort;
                                redirectRuleFound = true;
                            }
                        }

                        if (!redirectRuleFound)
                        {
                            Global.logmgr.WriteLog(LogLevel.Warning, "Download redirect rules given, but [{0}:{1}] is unknown download server", tmpIp, tmpPort);
                        }

                        uint version = pck.ReadUInt32();
                        byte fileFlag = pck.ReadUInt8();

                        myPacket.WriteUInt8(result);
                        myPacket.WriteUInt8(errorCode);

                        myPacket.WriteAscii(tmpIp);
                        myPacket.WriteUInt16(tmpPort);
                        myPacket.WriteUInt32(version);
                        myPacket.WriteUInt8(fileFlag);

                        while (fileFlag == 0x01)
                        {
                            uint fileId = pck.ReadUInt32();
                            string fileName = pck.ReadAscii();
                            string filePath = pck.ReadAscii();
                            uint fileLength = pck.ReadUInt32();
                            byte doPack = pck.ReadUInt8();

                            fileFlag = pck.ReadUInt8();

                            myPacket.WriteUInt32(fileId);
                            myPacket.WriteAscii(fileName);
                            myPacket.WriteAscii(filePath);
                            myPacket.WriteUInt32(fileLength);
                            myPacket.WriteUInt8(doPack);
                            myPacket.WriteUInt8(fileFlag);
                        }
                        session.SendPacketToClient(myPacket);
                    }
                    //Do not send original packet
                    return PacketProcessResult.ContinueLoop;
                }
            }
            return PacketProcessResult.DoNothing;
        }
예제 #9
0
 public void SendClientNotice(string str)
 {
     Packet err = new Packet(0x300C);
     err.WriteUInt16(3100);
     err.WriteUInt8(1);
     err.WriteAscii(str);
     SendPacketToClient(err);
     //Инфа с боку
     Packet err_2 = new Packet(0x300C);
     err_2.WriteUInt16(3100);
     err_2.WriteUInt8(2);
     err_2.WriteAscii(str);
     SendPacketToClient(err_2);
 }
예제 #10
0
        public static PacketProcessResult HandleClient(Packet pck, RelaySession session, SilkroadServer server)
        {
            if (Global.EnableItemMallBuyFix)
            {
                string uname = session.State["username"] as string;

                if (uname.Length == 0)
                {
                    Global.logmgr.WriteLog(LogLevel.Error, "username len == 0 (request buy mall item)");
                    return PacketProcessResult.Disconnect;

                }

                byte ShopType = pck.ReadUInt8();

                if (ShopType == 24)
                {
                    //------------------------------------------
                    UInt16 uint1 = pck.ReadUInt16();
                    byte b1 = pck.ReadUInt8();
                    byte b2 = pck.ReadUInt8();
                    byte b3 = pck.ReadUInt8();
                    string package_item_codename = pck.ReadAscii();
                    ushort nItems = pck.ReadUInt16();
                    pck.ReadUInt64();
                    uint refpackage_id = pck.ReadUInt32();
                    //------------------------------------------

                    string charname = session.State["charname"] as string;

                    if (charname.Length == 0)
                    {
                        Global.logmgr.WriteLog(LogLevel.Error, "charname len == 0 (buy in item mall)");
                        return PacketProcessResult.Disconnect;
                    }

                    int res = Global.dbmgr.GetBuyMallResult(charname, package_item_codename, nItems);

                    if (res == -1)
                    {
                        //------------------------------------------
                        session.SendClientNotice("UIIT_STT_ANTICHEAT_ITEM_MALL_ERROR");
                        //------------------------------------------
                    }
                    else
                    {
                        //update silk
                        List<int> silk_info = Global.dbmgr.GetSilkDataByUsername(uname);

                        //------------------------------------------
                        Packet resp = new Packet(0x3153);

                        resp.WriteUInt32(silk_info[0]);
                        resp.WriteUInt32(silk_info[1]);
                        resp.WriteUInt32(silk_info[2]);
                        // m_ClientSecurity.Send(resp);
                        session.SendPacketToClient(resp);

                        //------------------------------------------
                        Packet inventory = new Packet(0xB034);
                        inventory.WriteUInt8(1);
                        inventory.WriteUInt8(24);
                        inventory.WriteUInt16(uint1);
                        inventory.WriteUInt8(b1);
                        inventory.WriteUInt8(b2);
                        inventory.WriteUInt8(b3);
                        inventory.WriteUInt8(1);
                        inventory.WriteUInt8(res);
                        inventory.WriteUInt16(nItems);
                        inventory.WriteUInt32(0);
                        //m_ClientSecurity.Send(inventory);
                        session.SendPacketToClient(inventory);
                        //------------------------------------------

                        Packet inventory2 = new Packet(0xB034);
                        inventory2.WriteUInt8(1);
                        inventory2.WriteUInt8(7);
                        inventory2.WriteUInt8((byte)(res));
                        //  m_ClientSecurity.Send(inventory2);
                        session.SendPacketToClient(inventory2);

                        //------------------------------------------

                        //  Global.g_LogManager.WriteLog(LogLevel.Notify, "GetBuyMallResult OK slot {0}", res);
                    }
                    return PacketProcessResult.ContinueLoop;
                }
            }

            return PacketProcessResult.DoNothing;
        }