Esempio n. 1
0
        public static void Main()
        {
            try
            {
                Console.Title = $"LMPServer {LmpVersioning.CurrentVersion}";
#if DEBUG
                Console.Title += " DEBUG";
#endif
                Console.OutputEncoding  = Encoding.Unicode;
                ServerContext.StartTime = LunaTime.UtcNow.Ticks;

                if (!Common.PlatformIsWindows())
                {
                    LunaLog.Warning("Remember! Quit the server by using Control+C so the vessels are saved to the hard drive!");
                }


                if (Common.PlatformIsWindows())
                {
                    ExitSignal.Exit += (sender, args) => Exit();
                }
                else
                {
                    //Register the ctrl+c event and exit signal if we are on linux
                    Console.CancelKeyPress += (sender, args) => Exit();
                }

                //We disable quick edit as otherwise when you select some text for copy/paste then you can't write to the console and server freezes
                //This just happens on windows....
                if (Common.PlatformIsWindows())
                {
                    ConsoleUtil.DisableConsoleQuickEdit();
                }

                //We cannot run more than 6 instances ofd servers + clients as otherwise the sync time will fail (30 seconds / 5 seconds = 6) but we use 3 for safety
                if (GetRunningInstances() > 3)
                {
                    throw new HandledException("Cannot run more than 3 servers at a time!");
                }

                //Start the server clock
                ServerContext.ServerClock.Start();

                //Set the last player activity time to server start
                ServerContext.LastPlayerActivity = ServerContext.ServerClock.ElapsedMilliseconds;

                ServerContext.ServerStarting = true;

                //Set day for log change
                ServerContext.Day = LunaTime.Now.Day;

                LunaLog.Normal($"Luna Server version: {LmpVersioning.CurrentVersion} ({Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)})");

                Universe.CheckUniverse();
                LoadSettingsAndGroups();
                VesselStoreSystem.LoadExistingVessels();
                ScenarioSystem.GenerateDefaultScenarios();
                ScenarioStoreSystem.LoadExistingScenarios();
                LmpPluginHandler.LoadPlugins();
                WarpSystem.Reset();

                LunaLog.Normal($"Starting '{GeneralSettings.SettingsStore.ServerName}' on Port {ConnectionSettings.SettingsStore.Port}... ");

                LmpPortMapper.OpenPort().Wait();
                ServerContext.ServerRunning = true;
                LidgrenServer.SetupLidgrenServer();

                //Do not add the command handler thread to the TaskContainer as it's a blocking task
                LongRunTaskFactory.StartNew(() => new CommandHandler().ThreadMain(), CancellationTokenSrc.Token);

                TaskContainer.Add(LongRunTaskFactory.StartNew(LmpPortMapper.RefreshUpnpPort, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(LogThread.RunLogThread, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(() => new ClientMainThread().ThreadMain(), CancellationTokenSrc.Token));

                TaskContainer.Add(LongRunTaskFactory.StartNew(() => BackupSystem.PerformBackups(CancellationTokenSrc.Token), CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(LidgrenServer.StartReceiveingMessages, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(LidgrenMasterServer.RefreshMasterServersList, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(LidgrenMasterServer.RegisterWithMasterServer, CancellationTokenSrc.Token));

                TaskContainer.Add(LongRunTaskFactory.StartNew(VesselRelaySystem.RelayOldVesselMessages, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(VersionChecker.RefreshLatestVersion, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(VersionChecker.DisplayNewVersionMsg, CancellationTokenSrc.Token));

                while (ServerContext.ServerStarting)
                {
                    Thread.Sleep(500);
                }

                LunaLog.Normal("All systems up and running. Поехали!");
                LmpPluginHandler.FireOnServerStart();

                QuitEvent.WaitOne();

                LmpPluginHandler.FireOnServerStop();

                LunaLog.Normal("So long and thanks for all the fish!");
            }
            catch (Exception e)
            {
                if (e is HandledException)
                {
                    LunaLog.Fatal(e.Message);
                }
                else
                {
                    LunaLog.Fatal($"Error in main server thread, Exception: {e}");
                }
                Console.ReadLine(); //Avoid closing automatically
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
#if WINDOWS
            this.IsMouseVisible = true;
#endif

            // Initialize the GoblinXNA framework
            State.InitGoblin(graphics, Content, "");

            // Initialize the scene graph
            scene = new Scene();

            State.EnableNetworking = true;
            State.IsServer         = isServer;

            State.ShowNotifications = true;
            State.ShowFPS           = true;
            Notifier.FadeOutTime    = 2000;

            // Set up the lights used in the scene
            CreateLights();

            // Set up the camera, which defines the eye location and viewing frustum
            CreateCamera();

            // Create 3D objects
            CreateObject();

            // Create a network object that contains mouse press information to be
            // transmitted over network
            // mouseNetworkObj = new MouseNetworkObject();
            networkExchange = new NetworkExchangeWrapper();

            // When a mouse press event is sent from the other side, then call "ShootBox"
            // function
            //mouseNetworkObj.CallbackFunc = ShootBox;
            networkExchange.CallbackFunc = ShootBox;

            // Create a network handler for handling the network transfers
            INetworkHandler networkHandler = null;

#if USE_SOCKET_NETWORK || WINDOWS_PHONE
            networkHandler = new SocketNetworkHandler();
#else
            networkHandler = new NetworkHandler();
#endif

            if (true)//(State.IsServer)
            {
                IServer server = null;
#if WINDOWS
#if USE_SOCKET_NETWORK
                server = new SocketServer(14242);
#else
                server = new LidgrenServer("Tutorial8_Phone", 14242);
#endif
                State.NumberOfClientsToWait = 1;
                scene.PhysicsEngine         = new NewtonPhysics();
#else
                scene.PhysicsEngine = new MataliPhysics();
                ((MataliPhysics)scene.PhysicsEngine).SimulationTimeStep = 1 / 30f;
#endif

                scene.PhysicsEngine.Gravity  = 0;
                server.ClientConnected      += new HandleClientConnection(ClientConnected);
                server.ClientDisconnected   += new HandleClientDisconnection(ClientDisconnected);
                networkHandler.NetworkServer = server;
            }

            // Assign the network handler used for this scene
            scene.NetworkHandler = networkHandler;

            // Add the mouse network object to the scene graph, so it'll be sent over network
            // whenever ReadyToSend is set to true.
            scene.NetworkHandler.AddNetworkObject(networkExchange);
        }
Esempio n. 3
0
        public static void Main()
        {
            try
            {
                if (Common.PlatformIsWindows())
                {
                    Console.Title = $"LMP {LmpVersioning.CurrentVersion}";
                }

                Console.OutputEncoding = Encoding.UTF8;

                LunaLog.Info("Remember! Quit the server by using 'Control + C' so a backup is properly made before closing!");

                if (Common.PlatformIsWindows())
                {
                    ExitSignal.Exit += (sender, args) => Exit();
                }
                else
                {
                    //Register the ctrl+c event and exit signal if we are on linux
                    Console.CancelKeyPress += (sender, args) => Exit();
                }

                //We disable quick edit as otherwise when you select some text for copy/paste then you can't write to the console and server freezes
                //This just happens on windows....
                if (Common.PlatformIsWindows())
                {
                    ConsoleUtil.DisableConsoleQuickEdit();
                }

                //We cannot run more than 6 instances ofd servers + clients as otherwise the sync time will fail (30 seconds / 5 seconds = 6) but we use 3 for safety
                if (GetRunningInstances() > 3)
                {
                    throw new HandledException("Cannot run more than 3 servers at a time!");
                }

                //Start the server clock
                ServerContext.ServerClock.Start();

                ServerContext.ServerStarting = true;

                //Set day for log change
                ServerContext.Day = LunaNetworkTime.Now.Day;

                LunaLog.Normal($"Luna Server version: {LmpVersioning.CurrentVersion} ({AppContext.BaseDirectory})");

                Universe.CheckUniverse();
                LoadSettingsAndGroups();
                VesselStoreSystem.LoadExistingVessels();
                var scenariosCreated = ScenarioSystem.GenerateDefaultScenarios();
                ScenarioStoreSystem.LoadExistingScenarios(scenariosCreated);
                LmpPluginHandler.LoadPlugins();
                WarpSystem.Reset();
                TimeSystem.Reset();

                LunaLog.Normal($"Starting '{GeneralSettings.SettingsStore.ServerName}' on Address {ConnectionSettings.SettingsStore.ListenAddress} Port {ConnectionSettings.SettingsStore.Port}... ");

                LidgrenServer.SetupLidgrenServer();
                LmpPortMapper.OpenLmpPort().Wait();
                LmpPortMapper.OpenWebPort().Wait();
                ServerContext.ServerRunning = true;
                WebServer.StartWebServer();

                //Do not add the command handler thread to the TaskContainer as it's a blocking task
                LongRunTaskFactory.StartNew(CommandHandler.ThreadMain, CancellationTokenSrc.Token);

                TaskContainer.Add(LongRunTaskFactory.StartNew(WebServer.RefreshWebServerInformation, CancellationTokenSrc.Token));

                TaskContainer.Add(LongRunTaskFactory.StartNew(LmpPortMapper.RefreshUpnpPort, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(LogThread.RunLogThread, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(ClientMainThread.ThreadMain, CancellationTokenSrc.Token));

                TaskContainer.Add(LongRunTaskFactory.StartNew(() => BackupSystem.PerformBackups(CancellationTokenSrc.Token), CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(LidgrenServer.StartReceivingMessages, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(LidgrenMasterServer.RegisterWithMasterServer, CancellationTokenSrc.Token));

                TaskContainer.Add(LongRunTaskFactory.StartNew(VersionChecker.RefreshLatestVersion, CancellationTokenSrc.Token));
                TaskContainer.Add(LongRunTaskFactory.StartNew(VersionChecker.DisplayNewVersionMsg, CancellationTokenSrc.Token));

                TaskContainer.Add(LongRunTaskFactory.StartNew(() => GcSystem.PerformGarbageCollection(CancellationTokenSrc.Token), CancellationTokenSrc.Token));

                while (ServerContext.ServerStarting)
                {
                    Thread.Sleep(500);
                }

                LunaLog.Normal("All systems up and running. Поехали!");
                LmpPluginHandler.FireOnServerStart();

                QuitEvent.WaitOne();

                LmpPluginHandler.FireOnServerStop();

                LunaLog.Normal("So long and thanks for all the fish!");
            }
            catch (Exception e)
            {
                LunaLog.Fatal(e is HandledException ? e.Message : $"Error in main server thread, Exception: {e}");
                Console.ReadLine(); //Avoid closing automatically
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
#if WINDOWS
            this.IsMouseVisible = true;
#endif

            // Initialize the GoblinXNA framework
            State.InitGoblin(graphics, Content, "");

            // Initialize the scene graph
            scene = new Scene();

            State.EnableNetworking = true;
            State.IsServer         = isServer;

            State.ShowNotifications = true;
            State.ShowFPS           = true;
            Notifier.FadeOutTime    = 2000;

            // Set up the lights used in the scene
            CreateLights();

            // Set up the camera, which defines the eye location and viewing frustum
            CreateCamera();

            // Create 3D objects
            CreateObject();

            // Create a network object that contains mouse press information to be
            // transmitted over network
            mouseNetworkObj = new MouseNetworkObject();

            // When a mouse press event is sent from the other side, then call "ShootBox"
            // function
            mouseNetworkObj.CallbackFunc = ShootBox;

            // Create a network handler for handling the network transfers
            INetworkHandler networkHandler = null;

#if USE_SOCKET_NETWORK || WINDOWS_PHONE
            networkHandler = new SocketNetworkHandler();
#else
            networkHandler = new NetworkHandler();
#endif

            if (State.IsServer)
            {
                IServer server = null;
#if WINDOWS
#if USE_SOCKET_NETWORK
                server = new SocketServer(14242);
#else
                server = new LidgrenServer("Tutorial10", 14242);
#endif
                State.NumberOfClientsToWait = 1;
                scene.PhysicsEngine         = new NewtonPhysics();
#else
                scene.PhysicsEngine = new MataliPhysics();
                ((MataliPhysics)scene.PhysicsEngine).SimulationTimeStep = 1 / 30f;
#endif
                scene.PhysicsEngine.Gravity  = 30;
                server.ClientConnected      += new HandleClientConnection(ClientConnected);
                server.ClientDisconnected   += new HandleClientDisconnection(ClientDisconnected);
                networkHandler.NetworkServer = server;
            }
            else
            {
                IClient client = null;
                // Create a client that connects to the local machine assuming that both
                // the server and client will be running on the same machine. In order to
                // connect to a remote machine, you need to either pass the host name or
                // the IP address of the remote machine in the 3rd parameter.
#if WINDOWS
                client = new LidgrenClient("Tutorial10", 14242, "Localhost");
#else
                client = new SocketClient("10.0.0.2", 14242);
#endif

                // If the server is not running when client is started, then wait for the
                // server to start up.
                client.WaitForServer          = true;
                client.ConnectionTrialTimeOut = 60 * 1000; // 1 minute timeout

                client.ServerConnected    += new HandleServerConnection(ServerConnected);
                client.ServerDisconnected += new HandleServerDisconnection(ServerDisconnected);

                networkHandler.NetworkClient = client;
            }

            // Assign the network handler used for this scene
            scene.NetworkHandler = networkHandler;

            // Add the mouse network object to the scene graph, so it'll be sent over network
            // whenever ReadyToSend is set to true.
            scene.NetworkHandler.AddNetworkObject(mouseNetworkObj);

            MouseInput.Instance.MousePressEvent += new HandleMousePress(MouseInput_MousePressEvent);
        }