示例#1
0
        public bool checkTrigger(int count, Client client)
        {
            if (count == countToTrigger)
            {
                PlayerData player = client.playerData;

                switch (actionName)
                {
                case "mute":
                    player.isMuted = true;
                    StarryboundServer.sendGlobalMessage("^#f75d5d;" + player.name + " has been muted automatically for spamming.");
                    break;

                case "kick":
                    client.kickClient(reason);
                    break;

                case "ban":
                    if (length != 0)
                    {
                        length = Utils.getTimestamp() + (length * 60);
                    }

                    Bans.addNewBan(player.name, player.uuid, player.ip, Utils.getTimestamp(), "[SYSTEM]", length, reason);

                    client.banClient(reason);
                    break;
                }

                return(true);
            }

            return(false);
        }
        static void Main(string[] args)
        {
#if DEBUG
            config.logLevel = LogType.Debug;
#endif
            startTime = Utils.getTimestamp();
            changeState(ServerState.Starting, "StarryboundServer::Main");
            Console.Title = "Loading... Starrybound Server (" + VersionNum + ") (" + ProtocolVersion + ")";

            try
            {
                int     processId = Convert.ToInt32(File.ReadAllText("starbound_server.pid"));
                Process proc      = Process.GetProcessById(processId);
                proc.Kill();
                File.Delete("starbound_server.pid");
            }
            catch (Exception) { }

            monitorThread = new Thread(new ThreadStart(crashMonitor));
            monitorThread.Start();

            if (IsMono)
            {
                Environment.CurrentDirectory = Path.GetDirectoryName(typeof(StarryboundServer).Assembly.Location);
            }

            AppDomain.CurrentDomain.ProcessExit        += new EventHandler(ProcessExit);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledException);

            if (!IsMono)
            {
                NativeMethods.SetConsoleCtrlHandler(new NativeMethods.HandlerRoutine(ConsoleCtrlCheck), true);
            }

            BootstrapConfig.SetupConfig();

            writeLog("", LogType.FileOnly);
            writeLog("-- Log Start: " + DateTime.Now + " --", LogType.FileOnly);

            logInfo("##############################################");
            logInfo("####   Avilance Ltd. Starrybound Server   ####");
            logInfo("####   Copyright (c) Avilance Ltd. 2013   ####");
            logInfo("####       Licensed under the GPLv3       ####");
            logInfo("##############################################");
            logInfo("Version: " + VersionNum + " (" + ProtocolVersion + ")");
            logInfo("Loading Starrybound Server...");

            Config.SetupConfig();
            ServerConfig.SetupConfig();
            Groups.SetupGroups();
            Users.SetupUsers();
#if !DEBUG
            if (config.logLevel == LogType.Debug)
            {
                logWarn("The logLevel in your config is currently set to DEBUG. This **WILL** flood your console and log file, if you do not want this please edit your config logLevel to INFO");
                logWarn("Launch will proceed in 5 seconds.");
                System.Threading.Thread.Sleep(5000);
            }
#endif
#if !NOSERVER
            if (config.proxyPort == config.serverPort)
            {
                logFatal("You cannot have the serverPort and proxyPort on the same port!");
                Thread.Sleep(5000);
                Environment.Exit(3);
            }
#endif
            var geoippath = Path.Combine(SavePath, "GeoIP.dat");
            if (config.enableGeoIP && File.Exists(geoippath))
            {
                Geo = new GeoIPCountry(geoippath);
            }

            foreach (string sector in config.sectors)
            {
                byte[] sectorBytes = Encoding.UTF8.GetBytes(sector);
                byte[] buffer      = new byte[sectorBytes.Length + 1];
                buffer[0] = (byte)sectorBytes.Length;
                Buffer.BlockCopy(sectorBytes, 0, buffer, 1, sectorBytes.Length);
                sectors.Add(sectorBytes);
            }
            Bans.ProcessBans();
            Claims.LoadClaims();

            logInfo("Starrybound Server initialization complete.");

            listener       = new ListenerThread();
            listenerThread = new Thread(new ThreadStart(listener.runTcp));
            listenerThread.Start();

            udpThread = new Thread(new ThreadStart(listener.runUdp));
            udpThread.Start();

            while (serverState != ServerState.ListenerReady)
            {
            }
            if ((int)serverState > 3)
            {
                return;
            }

            Console.Title = "Starting... Starrybound Server (" + VersionNum + ") (" + ProtocolVersion + ")";
#if !NOSERVER
            logInfo("Starting parent Starbound server - This may take a few moments...");
            sbServer       = new ServerThread();
            sbServerThread = new Thread(new ThreadStart(sbServer.run));
            sbServerThread.Start();
            while (serverState != ServerState.StarboundReady)
            {
            }
            if ((int)serverState > 3)
            {
                return;
            }
#endif
            logInfo("Parent Starbound server is ready. Starrybound Server now accepting connections.");
            changeState(ServerState.Running, "StarryboundServer::Main");
        }
示例#3
0
 public void remove()
 {
     Bans.allBans.Remove(banID);
     Bans.Write(Path.Combine(StarryboundServer.SavePath, "bans.json"));
 }