예제 #1
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;
        }
예제 #2
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;
        }
예제 #3
0
        public static void HandleDelayedPacket(SilkroadServer server, string noticeText)
        {
            if (server.SessionCount > 0)
            {
                Packet notice = new Packet(0x3026);
                notice.WriteUInt8(7);
                notice.WriteAscii(noticeText,Global.TextEncodeCode);

                //Only chars which are logged in for 60 seconds will receive the message
                server.BroadcastToLoggedInChars(notice, Global.AutoNoticeSendBeginDelay);
            }
        }
예제 #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;
        }
        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;
        }
예제 #8
0
 public static PacketProcessResult HandleModule(Packet pck, RelaySession session, SilkroadServer server)
 {
     if (Global.EnableLoginNotice)
     {
         bool noticeDone = false;
         bool.TryParse(session.State["noticeDone"] as string, out noticeDone);
         if (!noticeDone)
         {
             foreach (string text in Global.LoginNotice)
             {
                 Packet notice = new Packet(0x3026);
                 notice.WriteUInt8(7);
                 notice.WriteAscii(text, Global.TextEncodeCode);
                 session.SendPacketToClient(notice);
             }
             session.State["noticeDone"] = true;
         }
     }
     return PacketProcessResult.DoNothing;
 }
예제 #9
0
        public static PacketProcessResult HandleClient(Packet pck, RelaySession session, SilkroadServer server)
        {
            if (Global.EnableItemMallBuyFix)
            {
                Packet MyResponse = new Packet(0xB566, true);

                string uname = session.State["username"] as string;

                if (uname.Length == 0)
                {
                    Global.logmgr.WriteLog(LogLevel.Warning, "username len == 0 !");
                    return PacketProcessResult.Disconnect;
                }

                if (uname.Contains("'"))
                {
                    Global.logmgr.WriteLog(LogLevel.Warning, "User trying to exploit shop ! Uname str: {0}", uname);
                    return PacketProcessResult.Disconnect;
                }

                List<string> query_res = Global.dbmgr.GetJidAndToken(uname);

                UInt32 jid = uint.Parse(query_res[0]);
                string token = query_res[1];

                MyResponse.WriteUInt8(1);
                MyResponse.WriteUInt32(jid);
                MyResponse.WriteAscii(token);

                session.SendPacketToClient(MyResponse);
                //   Global.g_LogManager.WriteLog(LogLevel.Notify, "Shop packet OK [{0}] JID [{1}] TOKEN [{2}]",uname,jid,token);

                return PacketProcessResult.ContinueLoop;
            }
            return PacketProcessResult.DoNothing;
        }
예제 #10
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();
                    }
                }
            }
        }
예제 #11
0
        void GenerateSecurity(SecurityFlags flags)
        {
            m_security_flag = FromSecurityFlags(flags);
            m_security_flags = flags;
            m_client_security = true;

            //don't need about solving problem CA2000
            Packet response = new Packet(0x5000);

            response.WriteUInt8(m_security_flag);

            if (m_security_flags.blowfish == 1)
            {
                m_initial_blowfish_key = NextUInt64();

                m_blowfish.Initialize(BitConverter.GetBytes(m_initial_blowfish_key));

                response.WriteUInt64(m_initial_blowfish_key);
            }
            if (m_security_flags.security_bytes == 1)
            {
                m_seed_count = NextUInt8();
                SetupCountByte(m_seed_count);
                m_crc_seed = NextUInt8();

                response.WriteUInt32(m_seed_count);
                response.WriteUInt32(m_crc_seed);
            }
            if (m_security_flags.handshake == 1)
            {
                m_handshake_blowfish_key = NextUInt64();
                m_value_x = NextUInt32() & 0x7FFFFFFF;
                m_value_g = NextUInt32() & 0x7FFFFFFF;
                m_value_p = NextUInt32() & 0x7FFFFFFF;
                m_value_A = G_pow_X_mod_P(m_value_p, m_value_x, m_value_g);

                response.WriteUInt64(m_handshake_blowfish_key);
                response.WriteUInt32(m_value_g);
                response.WriteUInt32(m_value_p);
                response.WriteUInt32(m_value_A);
            }

            m_outgoing_packets.Add(response);
        }
예제 #12
0
        void Handshake(ushort packet_opcode, PacketReader packet_data, bool packet_encrypted)
        {
            if (packet_encrypted)
            {
                throw (new Exception("[SecurityAPI::Handshake] Received an illogical (encrypted) handshake packet."));
            }
            if (m_client_security)
            {
                // If this object does not need a handshake
                if (m_security_flags.handshake == 0)
                {
                    // Client should only accept it then
                    if (packet_opcode == 0x9000)
                    {
                        if (m_accepted_handshake)
                        {
                            throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (duplicate 0x9000)."));
                        }
                        m_accepted_handshake = true; // Otherwise, all good here
                        return;
                    }
                    // Client should not send any 0x5000s!
                    else if (packet_opcode == 0x5000)
                    {
                        throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (0x5000 with no handshake)."));
                    }
                    // Programmer made a mistake in calling this function
                    else
                    {
                        throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (programmer error)."));
                    }
                }
                else
                {
                    // Client accepts the handshake
                    if (packet_opcode == 0x9000)
                    {
                        // Can't accept it before it's started!
                        if (!m_started_handshake)
                        {
                            throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (out of order 0x9000)."));
                        }
                        if (m_accepted_handshake) // Client error
                        {
                            throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (duplicate 0x9000)."));
                        }
                        // Otherwise, all good here
                        m_accepted_handshake = true;
                        return;
                    }
                    // Client sends a handshake response
                    else if (packet_opcode == 0x5000)
                    {
                        if (m_started_handshake) // Client error
                        {
                            throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (duplicate 0x5000)."));
                        }
                        m_started_handshake = true;
                    }
                    // Programmer made a mistake in calling this function
                    else
                    {
                        throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (programmer error)."));
                    }
                }

                ulong key_array = 0;
                byte[] tmp_bytes;

                m_value_B = packet_data.ReadUInt32();
                m_client_key = packet_data.ReadUInt64();

                m_value_K = G_pow_X_mod_P(m_value_p, m_value_x, m_value_B);

                key_array = MAKELONGLONG_(m_value_A, m_value_B);
                KeyTransformValue(ref key_array, m_value_K, (byte)(LOBYTE_(LOWORD_(m_value_K)) & 0x03));
                m_blowfish.Initialize(BitConverter.GetBytes(key_array));

                tmp_bytes = m_blowfish.Decode(BitConverter.GetBytes(m_client_key));
                m_client_key = BitConverter.ToUInt64(tmp_bytes, 0);

                key_array = MAKELONGLONG_(m_value_B, m_value_A);
                KeyTransformValue(ref key_array, m_value_K, (byte)(LOBYTE_(LOWORD_(m_value_B)) & 0x07));
                if (m_client_key != key_array)
                {
                    throw (new Exception("[SecurityAPI::Handshake] Client signature error."));
                }

                key_array = MAKELONGLONG_(m_value_A, m_value_B);
                KeyTransformValue(ref key_array, m_value_K, (byte)(LOBYTE_(LOWORD_(m_value_K)) & 0x03));
                m_blowfish.Initialize(BitConverter.GetBytes(key_array));

                m_challenge_key = MAKELONGLONG_(m_value_A, m_value_B);
                KeyTransformValue(ref m_challenge_key, m_value_K, (byte)(LOBYTE_(LOWORD_(m_value_A)) & 0x07));
                tmp_bytes = m_blowfish.Encode(BitConverter.GetBytes(m_challenge_key));
                m_challenge_key = BitConverter.ToUInt64(tmp_bytes, 0);

                KeyTransformValue(ref m_handshake_blowfish_key, m_value_K, 0x3);
                m_blowfish.Initialize(BitConverter.GetBytes(m_handshake_blowfish_key));

                SecurityFlags tmp_flags = new SecurityFlags();
                tmp_flags.handshake_response = 1;
                byte tmp_flag = FromSecurityFlags(tmp_flags);

                //CA2000 dont care
                Packet response = new Packet(0x5000);
                response.WriteUInt8(tmp_flag);
                response.WriteUInt64(m_challenge_key);
                m_outgoing_packets.Add(response);
            }
            else
            {
                if (packet_opcode != 0x5000)
                {
                    throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (programmer error)."));
                }

                byte flag = packet_data.ReadByte();

                SecurityFlags flags = ToSecurityFlags(flag);

                if (m_security_flag == 0)
                {
                    m_security_flag = flag;
                    m_security_flags = flags;
                }

                if (flags.blowfish == 1)
                {
                    m_initial_blowfish_key = packet_data.ReadUInt64();
                    m_blowfish.Initialize(BitConverter.GetBytes(m_initial_blowfish_key));
                }

                if (flags.security_bytes == 1)
                {
                    m_seed_count = packet_data.ReadUInt32();
                    m_crc_seed = packet_data.ReadUInt32();
                    SetupCountByte(m_seed_count);
                }

                if (flags.handshake == 1)
                {
                    m_handshake_blowfish_key = packet_data.ReadUInt64();
                    m_value_g = packet_data.ReadUInt32();
                    m_value_p = packet_data.ReadUInt32();
                    m_value_A = packet_data.ReadUInt32();

                    m_value_x = NextUInt32() & 0x7FFFFFFF;

                    m_value_B = G_pow_X_mod_P(m_value_p, m_value_x, m_value_g);
                    m_value_K = G_pow_X_mod_P(m_value_p, m_value_x, m_value_A);

                    ulong key_array = MAKELONGLONG_(m_value_A, m_value_B);
                    KeyTransformValue(ref key_array, m_value_K, (byte)(LOBYTE_(LOWORD_(m_value_K)) & 0x03));
                    m_blowfish.Initialize(BitConverter.GetBytes(key_array));

                    m_client_key = MAKELONGLONG_(m_value_B, m_value_A);
                    KeyTransformValue(ref m_client_key, m_value_K, (byte)(LOBYTE_(LOWORD_(m_value_B)) & 0x07));
                    byte[] tmp_bytes = m_blowfish.Encode(BitConverter.GetBytes(m_client_key));
                    m_client_key = BitConverter.ToUInt64(tmp_bytes, 0);
                }

                if (flags.handshake_response == 1)
                {
                    m_challenge_key = packet_data.ReadUInt64();

                    ulong expected_challenge_key = MAKELONGLONG_(m_value_A, m_value_B);
                    KeyTransformValue(ref expected_challenge_key, m_value_K, (byte)(LOBYTE_(LOWORD_(m_value_A)) & 0x07));
                    byte[] tmp_bytes = m_blowfish.Encode(BitConverter.GetBytes(expected_challenge_key));
                    expected_challenge_key = BitConverter.ToUInt64(tmp_bytes, 0);

                    if (m_challenge_key != expected_challenge_key)
                    {
                        throw (new Exception("[SecurityAPI::Handshake] Server signature error."));
                    }

                    KeyTransformValue(ref m_handshake_blowfish_key, m_value_K, 0x3);
                    m_blowfish.Initialize(BitConverter.GetBytes(m_handshake_blowfish_key));
                }

                // Generate the outgoing packet now
                if (flags.handshake == 1 && flags.handshake_response == 0)
                {
                    // Check to see if we already started a handshake
                    if (m_started_handshake || m_accepted_handshake)
                    {
                        throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (duplicate 0x5000)."));
                    }

                    // Handshake challenge
                    //CA2000 dont care
                    Packet response = new Packet(0x5000);
                    response.WriteUInt32(m_value_B);
                    response.WriteUInt64(m_client_key);
                    m_outgoing_packets.Insert(0, response);

                    // The handshake has started
                    m_started_handshake = true;
                }
                else
                {
                    // Check to see if we already accepted a handshake
                    if (m_accepted_handshake)
                    {
                        throw (new Exception("[SecurityAPI::Handshake] Received an illogical handshake packet (duplicate 0x5000)."));
                    }

                    // Handshake accepted
                    //CA2000 dont care
                    Packet response1 = new Packet(0x9000);

                    // Identify
                    //CA2000 dont care
                    Packet response2 = new Packet(0x2001, true, false);
                    response2.WriteAscii(m_identity_name);
                    response2.WriteUInt8(m_identity_flag);

                    // Insert at the front, we want 0x9000 first, then 0x2001
                    m_outgoing_packets.Insert(0, response2);
                    m_outgoing_packets.Insert(0, response1);

                    // Mark the handshake as accepted now
                    m_started_handshake = true;
                    m_accepted_handshake = true;
                }
            }
        }
예제 #13
0
        /// <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;
        }
예제 #14
0
        //-----------------------------------------------------------------------------
        public void SendNoticeToUsername(string cmd_str)
        {
            string[] cmd_args = cmd_str.Split(new char[] { ' ' });
            string username = cmd_args[1];

            string notice_str = string.Empty;
            for (int i = 2; i < cmd_args.Length; i++)
            {
                notice_str += string.Format("{0} ", cmd_args[i]);
            }

            Packet pck = new Packet(0x3026);
            pck.WriteUInt8(7);
            pck.WriteAscii(notice_str);

            bool send_res = Global.srvmgr.SendPacketToClientUsername(pck, ServerType.AgentServer, username);

            if (send_res)
            {
                Console.WriteLine("Message successfully sent to user");
            }
            else
            {
                Console.WriteLine("User with such username is not found");
            }
        }
예제 #15
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;
        }
예제 #16
0
 public void SendClientPM(string str)
 {
     Packet send = new Packet(0x3026);
     send.WriteUInt8(2);
     send.WriteAscii("[Сервер] Sairos",Global.TextEncodeCode);
     send.WriteAscii(str, Global.TextEncodeCode);
     SendPacketToClient(send);
 }
예제 #17
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);
 }