コード例 #1
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;
                    }
                }
            }
        }
コード例 #2
0
ファイル: Store.cs プロジェクト: diamondo25/mapler.me
 public static void Initialize()
 {
     Instance = new AccountDataCache();
     Instance.Load();
 }
コード例 #3
0
ファイル: Store.cs プロジェクト: diamondo25/mapler.me
 public static void Initialize()
 {
     Instance = new AccountDataCache();
     Instance.Load();
 }