Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Logger.Write("[ EclipseSharp Server ]");

            // Set up some basic runtime variables.
            Logger.Write("Setting up initial variables...");
            Data.AppPath = AppDomain.CurrentDomain.BaseDirectory;

            // Load our server settings!
            Logger.Write("Loading server settings...");
            Data.LoadSettings(Data.AppPath + "settings.xml");

            // Apply some settings to our window.
            Console.Title = String.Format("{0} - Running on Port {1}", Data.Settings.GameName, Data.Settings.Port);

            // Check and Create our data structure.
            Logger.Write("Checking data structure...");
            Data.CheckDirectories();
            Data.InitData();

            // Create our Server instance.
            // We're also setting up our event handlers that the server produces here.
            Logger.Write("Creating server objects...");
            Server = new Networking.Server(Data.Settings.MaxPlayers, Data.Settings.Port);
            Server.ConnectHandler    += PacketHandler.ClientConnected;
            Server.DisconnectHandler += PacketHandler.ClientDisconnected;
            Server.PacketHandler     += PacketHandler.Handle;

            // Create our logic handlers.
            PingClients    = new Timer(new TimerCallback(PacketHandler.PingClients), null, 0, 2000);
            HandleMovement = new Timer(new TimerCallback(Players.HandleMovement), null, 0, 10);
            SyncPlayers    = new Timer(new TimerCallback(Players.SyncPlayers), null, 0, 500);
            MOTD           = new Timer(new TimerCallback(Players.SendMOTD), null, 0, 1000);     // The excuse for this is that with the way the client loads and the sockets being a seperate thread an MOTD at MapOK does not always arrive after the UI loaded, but sometimes before. Eep.
            SavePlayers    = new Timer(new TimerCallback(Players.SavePlayers), null, 0, 300000);

            // Open the server to players!
            Logger.Write("Opening server...");
            Server.Open();
            Logger.Write("--- Normal Operations Below ---");

            // Keep the console open for as long as the program can run.
            while (Program.Running)
            {
                var input = Console.ReadLine().Trim().ToLower();
                if (input.Length > 0)
                {
                    Input.Process(input);
                }
            }

            // Close down the server! We no longer need it.
            Server.Close();

            // Time to get rid of everything! .. Or well, save it to prevent data loss.
            Data.SavePlayers();
            Data.SaveClasses();
            Data.SaveMaps();
        }
Exemplo n.º 2
0
        private void ServerForm_Load(object sender, EventArgs e)
        {
            _server = new Networking.Server();
            _server.Start();

            _server.ClientConnected    += _server_ClientConnected;
            _server.ClientDisconnected += _server_ClientDisconnected;
            _server.ClientUpdated      += _server_ClientUpdated;
        }
Exemplo n.º 3
0
 private void StartConnection()
 {
     server = new Networking.Server();
     server.Start();
 }