Exemplo n.º 1
0
        public WorldManager()
        {
            m_server = new GameServer(Settings.settingsStore.port, new Messages.ClientServerMessageFactory());

            m_clients = new SafeList <ClientObject>();

            subspaces                       = new Dictionary <int, Subspace>();
            playerSubspace                  = new Dictionary <string, int>();
            playerChatChannels              = new Dictionary <string, List <string> >();
            serverAdmins                    = new List <string>();
            serverWhitelist                 = new List <string>();
            playerUploadedScreenshotIndex   = new Dictionary <string, int>();
            playerDownloadedScreenshotIndex = new Dictionary <string, Dictionary <string, int> >();
            playerWatchScreenshot           = new Dictionary <string, string>();
            lockSystem                      = new LockSystem();

            m_banList = new BanList();

            LoadSavedSubspace();
            Server.serverRunning = true;
        }
Exemplo n.º 2
0
        public static void ThreadMain()
        {
            try
            {
                addClients = new Queue<ClientObject>();
                clients = new List<ClientObject>().AsReadOnly();
                deleteClients = new ConcurrentQueue<ClientObject>();
                subspaces = new Dictionary<int, Subspace>();
                playerSubspace = new Dictionary<string, int>();
                playerChatChannels = new Dictionary<string, List<string>>();
                bannedNames = new List<string>();
                bannedIPs = new List<IPAddress>();
                bannedPublicKeys = new List<string>();
                banReasons = new List<string>();
                serverAdmins = new List<string>();
                serverWhitelist = new List<string>();
                playerUploadedScreenshotIndex = new Dictionary<string, int>();
                playerDownloadedScreenshotIndex = new Dictionary<string, Dictionary <string, int>>();
                playerWatchScreenshot = new Dictionary<string, string>();
                lockSystem = new LockSystem();
                LoadSavedSubspace();
                LoadBans();
                LoadAdmins();
                LoadWhitelist();
                SetupTCPServer();

                while (Server.serverRunning)
                {
                    //Add new clients
                    while (addClients.Count > 0)
                    {
                        //Create a new readonly collection from the current list and set clients. This prevents CollectionModified exceptions.
                        ClientObject addClient = addClients.Dequeue();
                        if (addClient != null)
                        {
                            List<ClientObject> newList = new List<ClientObject>(clients);
                            newList.Add(addClient);
                            clients = newList.AsReadOnly();
                            Server.playerCount = GetActiveClientCount();
                            Server.players = GetActivePlayerNames();
                            DarkLog.Debug("Online players is now: " + Server.playerCount + ", connected: " + clients.Count);
                        }
                    }
                    //Process current clients
                    foreach (ClientObject client in clients)
                    {
                        CheckHeartBeat(client);
                    }
                    //Check timers
                    NukeKSC.CheckTimer();
                    Dekessler.CheckTimer();
                    //Run plugin update
                    DMPPluginHandler.FireOnUpdate();
                    //Delete old clients
                    while (deleteClients.Count > 0)
                    {
                        ClientObject deleteClient;
                        if (deleteClients.TryDequeue(out deleteClient))
                        {
                            List<ClientObject> newList = new List<ClientObject>(clients);
                            newList.Remove(deleteClient);
                            clients = newList.AsReadOnly();
                            Server.playerCount = GetActiveClientCount();
                            Server.players = GetActivePlayerNames();
                            DarkLog.Debug("Online players is now: " + Server.playerCount + ", connected: " + clients.Count);
                            if (!Settings.settingsStore.keepTickingWhileOffline && clients.Count == 0)
                            {
                                UpdateSubspace(GetLatestSubspace());
                                SaveLatestSubspace();
                            }
                        }
                    }
                    Thread.Sleep(10);
                }
            }
            catch (Exception e)
            {
                DarkLog.Error("Fatal error thrown, exception: " + e);
                Server.ShutDown("Crashed!");
            }
            try
            {
                long disconnectTime = DateTime.UtcNow.Ticks;
                bool sendingHighPriotityMessages = true;
                while (sendingHighPriotityMessages)
                {
                    if ((DateTime.UtcNow.Ticks - disconnectTime) > 50000000)
                    {
                        DarkLog.Debug("Shutting down with " + Server.playerCount + " players, " + clients.Count + " connected clients");
                        break;
                    }
                    while (deleteClients.Count > 0)
                    {
                        ClientObject deleteClient = null;
                        if (deleteClients.TryDequeue(out deleteClient))
                        {
                            List<ClientObject> newList = new List<ClientObject>(clients);
                            newList.Remove(deleteClient);
                            clients = newList.AsReadOnly();
                            Server.playerCount = GetActiveClientCount();
                            Server.players = GetActivePlayerNames();
                        }
                    }
                    sendingHighPriotityMessages = false;
                    foreach (ClientObject client in clients)
                    {
                        if (client.authenticated && (client.sendMessageQueueHigh.Count > 0))
                        {
                            sendingHighPriotityMessages = true;
                        }
                    }
                    Thread.Sleep(10);
                }
                ShutdownTCPServer();
            }
            catch (Exception e)
            {
                DarkLog.Fatal("Fatal error thrown during shutdown, exception: " + e);
                throw;
            }
        }
Exemplo n.º 3
0
        public static void ThreadMain()
        {
            try
            {
                addClients = new Queue<ClientObject>();
                clients = new List<ClientObject>();
                deleteClients = new Queue<ClientObject>();
                subspaces = new Dictionary<int, Subspace>();
                playerChatChannels = new Dictionary<string, List<string>>();
                bannedNames = new List<string>();
                bannedIPs = new List<IPAddress>();
                bannedGUIDs = new List<Guid>();
                banReasons = new List<string>();
                playerUploadedScreenshotIndex = new Dictionary<string, int>();
                playerDownloadedScreenshotIndex = new Dictionary<string, Dictionary <string, int>>();
                playerWatchScreenshot = new Dictionary<string, string>();
                lockSystem = new LockSystem();
                LoadSavedSubspace();
                LoadModFile();
                LoadBans();
                SetupTCPServer();

                while (Server.serverRunning)
                {
                    lock (clientLock)
                    {
                        //Add new clients
                        while (addClients.Count > 0)
                        {
                            clients.Add(addClients.Dequeue());
                            Server.playerCount = GetActiveClientCount();
                            Server.players = GetActivePlayerNames();
                        }
                        //Process current clients
                        foreach (ClientObject client in clients)
                        {
                            CheckHeartBeat(client);
                            SendOutgoingMessages(client);
                        }
                        //Check timers
                        NukeKSC.CheckTimer();
                        Dekessler.CheckTimer();
                        //Delete old clients
                        while (deleteClients.Count > 0)
                        {
                            clients.Remove(deleteClients.Dequeue());
                            Server.playerCount = GetActiveClientCount();
                            Server.players = GetActivePlayerNames();
                        }
                    }
                    Thread.Sleep(10);
                }
            }
            catch (Exception e)
            {
                DarkLog.Error("Fatal error thrown, exception: " + e);
                Server.ShutDown("Crashed!");
            }
            try
            {
                bool sendingHighPriotityMessages = true;
                while (sendingHighPriotityMessages)
                {
                    while (deleteClients.Count > 0)
                    {
                        clients.Remove(deleteClients.Dequeue());
                        Server.playerCount = GetActiveClientCount();
                        Server.players = GetActivePlayerNames();
                    }
                    sendingHighPriotityMessages = false;
                    foreach (ClientObject client in clients)
                    {
                        if (client.authenticated)
                        {
                            if (client.sendMessageQueueHigh != null ? client.sendMessageQueueHigh.Count > 0 : false)
                            {
                                SendOutgoingHighPriorityMessages(client);
                                sendingHighPriotityMessages = true;
                            }
                        }
                    }
                    Thread.Sleep(10);
                }
                ShutdownTCPServer();
            }
            catch (Exception e)
            {
                DarkLog.Fatal("Fatal error thrown during shutdown, exception: " + e);
                throw;
            }
        }