Exemplo n.º 1
0
        public void Initialize(string ip, int port)
        {
            DateTime startTime = DateTime.Now;

            Out.Info("Initializing server...");
            try
            {
                socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                socket.Bind(new IPEndPoint(IPAddress.Parse(ip), port));
                socket.Listen(100);
                Ip   = ip;
                Port = port;
            }
            catch (SocketException e)
            {
                Out.Error(e.Message);
                Dispose();
                return;
            }
            Clients = new Dictionary <Socket, IBaseClient>();
            Servers = new Dictionary <int, WorldServer>();
            Out.Info("Loading Config...");
            if (!File.Exists("config.txt"))
            {
                Out.Error("Can't load 'config.txt' !");
                Dispose();
                return;
            }
            Config = ConfigManager.GetConfig();
            if (Config.ContainsKey("Debug") && Config["Debug"] == "true")
            {
                Out.DebugMode = true;
            }
            if (Config.ContainsKey("Maintenance") && Config["Maintenance"] == "true")
            {
                onMaintenance = true;
            }
            ProtocolVersion = int.Parse(Config["ProtocolVersion"]);
            if (!ConfigManager.CheckConfig(Config))
            {
                Dispose();
                return;
            }
            Out.Info("Initializing database...");
            DatabaseManager.Initialize(Config["Database_Host"], Config["Database_User"], Config["Database_Password"], Config["Database_Auth"]);
            if (Config.ContainsKey("AuthServer_Name"))
            {
                Console.Title = Config["AuthServer_Name"];
            }
            AccountManager.Initialize(DatabaseManager.connection);
            ServersManager.Initialize(DatabaseManager.connection);
            LoadData();

            Out.Info($"Server started successfuly (Elapsed time : {DateTime.Now.Subtract(startTime).TotalMilliseconds.ToString("### ###")} ms)");
            socket.BeginAccept(AcceptCallBack, null);
            Out.Debug("Waiting for clients...");
        }
Exemplo n.º 2
0
        static void HandleCommand(string[] cmd)
        {
            switch (cmd[0])
            {
            case "rl":
                ServersManager.Initialize(DatabaseManager.connection);
                auth.Servers = ServersManager.GetServers();
                foreach (AuthClient client in auth.Clients.Values)
                {
                    foreach (Common.Database.Modeles.Auth.WorldServer s in auth.Servers.Values)
                    {
                        client.Send(new ServerStatusUpdateMessage(new Protocol.Types.GameServerInformations(s.ServerId, s.Status, s.Completion, true, 14)));
                    }
                }
                break;

            case "test":
                Out.WriteLine("TEST !!!", ConsoleColor.Yellow);
                break;

            case "exit":
                auth.Dispose();
                Out.WriteLine("Auth server stopped successfully", ConsoleColor.Cyan);
                break;

            case "start":
                if (auth.Clients != null)
                {
                    Out.Error("Server already started");
                    break;
                }
                auth.Initialize(ip, port);
                break;

            case "world":
                if (cmd.Length > 1 && cmd[1] == "start")
                {
                    world = new WorldServer();
                }
                break;

            default:
                Out.WriteLine($"Unknown command {cmd[0]}", ConsoleColor.Red);
                break;
            }
        }