Пример #1
0
        public virtual void SendPacket(MaplePacket pPacket)
        {
            if (_disconnected)
            {
                return;
            }
            try
            {
                byte[] data     = pPacket.ToArray();
                int    checksum = data.CalculateChecksum();
                if (_sendKey != null)
                {
                    data = Crypto.Encrypt(data, _sendKey);
                }

                byte[] completeData = new byte[data.Length + 4 + 4];
                Buffer.BlockCopy(BitConverter.GetBytes(pPacket.Length), 0, completeData, 0, 4);
                Buffer.BlockCopy(BitConverter.GetBytes(checksum), 0, completeData, 4, 4);
                Buffer.BlockCopy(data, 0, completeData, 8, data.Length);

                _socket.Send(completeData, 0, completeData.Length, SocketFlags.None);
            }
            catch (Exception)
            {
                Logger.WriteLine("Internal Packet Sending Exception @ SendPacket");
                Disconnect();
            }
        }
Пример #2
0
            public DumpPacket(MaplePacket pPacket)
            {
                pPacket.Reset();
                MaplePacket.CommunicationType type = (MaplePacket.CommunicationType)pPacket.ReadByte();
                Outboud = type == MaplePacket.CommunicationType.ClientPacket;
                Opcode = pPacket.ReadUShort();

                Data = new byte[pPacket.Length - 3];
                Buffer.BlockCopy(pPacket.ToArray(), 3, Data, 0, Data.Length); // byte + short (header)
                ArrivalTime = MasterThread.CurrentDate;
                pPacket.Reset();
            }
Пример #3
0
        static void Main(string[] args)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;
            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnexpectedExHandler);
            Console.CancelKeyPress += Console_CancelKeyPress;

            Logger.SetLogfile(false);

            MasterThread.Load("MPLRServer");

            try
            {
                MySQL_Connection.Initialize();
            }
            catch
            {
                Environment.Exit(12);
            }

            AccountDataCache.Initialize();
#if LOCALE_GMS
            GMSKeys.Initialize();
#endif

            CommandHandler.Initialize();
            Timeline.Init();

            Random = new System.Random();
            {
                InitializeValidHeaders();
                AcceptedIPs = new List<string>();
#if LOCALE_GMS
                AcceptedIPs.Add("8.31.9"); // GMS
#elif LOCALE_EMS
                AcceptedIPs.Add("109.234.77"); // EMS
#endif

                Clients = new List<ClientConnection>();
                StartPinger();
                StartCharacterDeleteQueue();
            }

            EXPTable.Load();

            SessionRestartCache.Start();

            // For clients
            Acceptor accept = new Acceptor(ServerMapleInfo.MAPLER_PORT, sock =>
            {
                new ClientConnection(sock);
            });

            // For online check!
            byte[] OnlineCheckInfo = null;
            {
                MaplePacket packet = new MaplePacket(ServerMapleInfo.VERSION);
                packet.WriteByte(ServerMapleInfo.LOCALE);

                byte[] temp = packet.ToArray();

                OnlineCheckInfo = new byte[temp.Length + 1];
                Buffer.BlockCopy(temp, 0, OnlineCheckInfo, 1, temp.Length);
                OnlineCheckInfo[0] = (byte)(temp.Length + 4);

                packet.Dispose();
                packet = null;
            }
            Acceptor acceptCheck = new Acceptor(ServerMapleInfo.MAPLER_PORT_SERVER_INFO, sock =>
            {
                sock.Send(OnlineCheckInfo);
                sock.Send(BitConverter.GetBytes(Clients.Count));
                sock.Shutdown(System.Net.Sockets.SocketShutdown.Both);
                sock.Close();
            });


            Logger.WriteLine("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
            Logger.WriteLine("|                                             |");
            Logger.WriteLine("|              Mapler.me Server               |");
            Logger.WriteLine("|                                             |");
#if LOCALE_GMS
            Logger.WriteLine("|                   GLOBAL                    |");
#elif LOCALE_EMS
            Logger.WriteLine("|                   EUROPE                    |");
#elif LOCALE_KMS
            Logger.WriteLine("|                   KOREA                     |");
#endif
            Logger.WriteLine("|                                             |");
            Logger.WriteLine("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
            Logger.WriteLine("|           Build For: {0,3} Locale {1,1}           |", ServerMapleInfo.VERSION, ServerMapleInfo.LOCALE);
            Logger.WriteLine("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
            Logger.WriteLine("Accepting connections on {0}, and info requests on {1}", ServerMapleInfo.MAPLER_PORT, ServerMapleInfo.MAPLER_PORT_SERVER_INFO);


            while (true)
            {
                string cmd = Console.ReadLine();
                if (cmd == null) break; // CTRL + C
                string[] arguments = cmd.Split(' ');
                if (arguments.Length >= 1)
                {
                    switch (arguments[0])
                    {
#if LOCALE_GMS
                        case "getkeys":
                            {
                                GMSKeys.Initialize();
                                break;
                            }
#endif
                        case "reload_store":
                            {
                                MasterThread.Instance.AddCallback(a =>
                                {
                                    AccountDataCache.Instance.Load();
                                });

                                break;
                            }
                        case "request_screenshots":
                            {
                                MasterThread.Instance.AddCallback(a =>
                                {
                                    var tmp = new List<ClientConnection>(Clients);
                                    foreach (var client in tmp)
                                    {
                                        using (MaplePacket pack = new MaplePacket(MaplePacket.CommunicationType.ServerPacket, 0xEEFE))
                                        {
                                            pack.SwitchOver();
                                            client.SendPacket(pack);
                                        }
                                    }
                                });

                                break;
                            }
                        case "testsession":
                            {
                                int accountid = arguments.Length > 1 ? Int32.Parse(arguments[1]) : -1;
                                bool raw = arguments.Length > 2;
                                var verp = new MSBLoader();
                                var connection = new ClientConnection(verp);
                                connection.AccountID = accountid;
                                verp.Parse("Savefile.msb", raw);

                                break;
                            }
                        case "players":
                            {
                                string names = string.Join(", ", Clients);
                                Console.WriteLine("Players online:\r\n{0}", names);
                                break;
                            }
                        case "close":
                        case "stop":
                        case "exit":
                            {

                                MasterThread.Instance.AddCallback(a =>
                                {
                                    var tmp = new List<ClientConnection>(Clients);
                                    foreach (var client in tmp)
                                    {
                                        // client.Save(true, true);
                                        client.Disconnect();
                                    }

                                    MySQL_Connection.Instance.Stop = true;
                                    MasterThread.Instance.Stop = true;
                                });
                                break;
                            }
                        default:
                            Console.WriteLine("Command not found");
                            break;
                    }
                }
            }
        }
Пример #4
0
 public override void SendPacket(MaplePacket pPacket)
 {
     if (IsFake) return;
     using (MaplePacket tmp = new MaplePacket(pPacket.ToArray()))
     {
         _exporter.AddPacket(tmp);
     }
     base.SendPacket(pPacket);
 }
Пример #5
0
        public virtual void SendPacket(MaplePacket pPacket)
        {
            if (_disconnected) return;
            try
            {

                byte[] data = pPacket.ToArray();
                int checksum = data.CalculateChecksum();
                if (_sendKey != null)
                    data = Crypto.Encrypt(data, _sendKey);

                byte[] completeData = new byte[data.Length + 4 + 4];
                Buffer.BlockCopy(BitConverter.GetBytes(pPacket.Length), 0, completeData, 0, 4);
                Buffer.BlockCopy(BitConverter.GetBytes(checksum), 0, completeData, 4, 4);
                Buffer.BlockCopy(data, 0, completeData, 8, data.Length);

                _socket.Send(completeData, 0, completeData.Length, SocketFlags.None);
            }
            catch (Exception)
            {
                Logger.WriteLine("Internal Packet Sending Exception @ SendPacket");
                Disconnect();
            }
        }