<commit_before>﻿using Server.Command.Command;
using Server.Context;
using Server.Log;
using Server.Settings.Structures;
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;

namespace Server.Command
{
    public class CommandHandler
    {
        static CommandHandler() => RegisterCommands();

        public static readonly ConcurrentDictionary<string, CommandDefinition> Commands =
            new ConcurrentDictionary<string, CommandDefinition>();

        private static void RegisterCommands()
        {
            //Register the server Commands
            RegisterCommand("ban", new BanPlayerCommand().Execute, "Bans someone from the server");
            RegisterCommand("changesettings", new ChangeSettingsCommand().Execute, "Changes the server settings");
            RegisterCommand("clearvessels", new ClearVesselsCommand().Execute, "Clears ALL SPECIFIED vessels from universe");
            RegisterCommand("connectionstats", new ConnectionStatsCommand().Execute, "Displays network traffic usage");
            RegisterCommand("countclients", new CountClientsCommand().Execute, "Counts connected clients");
            RegisterCommand("dekessler", new DekesslerCommand().Execute, "Clears out debris from the server");
            RegisterCommand("help", new DisplayHelpCommand().Execute, "Displays this help");
            RegisterCommand("kick", new KickCommand().Execute, "Kicks a player from the server");
            RegisterCommand("listclients", new ListClientsCommand().Execute, "Lists connected clients");
            RegisterCommand("listlocks", new ListLocksCommand().Execute, "Lists current locks");
            RegisterCommand("nukeksc", new NukeCommand().Execute, "Clears ALL vessels from KSC and the runway");
            RegisterCommand("setfunds", new SetFundsCommand().Execute, "Set funds value");
            RegisterCommand("setscience", new SetScienceCommand().Execute, "Set science value");
            RegisterCommand("restartserver", new RestartServerCommand().Execute, "Restarts the server");
            RegisterCommand("say", new SayCommand().Execute, "Broadcasts a message to clients");
        }

        /// <summary>
        /// We receive the console inputs with a pipe
        /// </summary>
        public static async void ThreadMain()
        {
            try
            {
                while (ServerContext.ServerRunning)
                {
                    var input = Console.ReadLine();
                    if (string.IsNullOrEmpty(input))
                    {
                        continue;
                    }
                    LunaLog.Normal($"Command input: {input}");
                    if (!string.IsNullOrEmpty(input))
                    {
                        if (input.StartsWith("/"))
                        {
                            HandleServerInput(input.Substring(1));
                        }
                        else
                        {
                            Commands["say"].Func(input);
                        }
                    }
                    await Task.Delay(IntervalSettings.SettingsStore.MainTimeTick);
                }<commit_msg>We only accept a command every 500ms<commit_after>﻿using Server.Command.Command;
using Server.Context;
using Server.Log;
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;

namespace Server.Command
{
    public class CommandHandler
    {
        static CommandHandler() => RegisterCommands();

        public static readonly ConcurrentDictionary<string, CommandDefinition> Commands =
            new ConcurrentDictionary<string, CommandDefinition>();

        private static void RegisterCommands()
        {
            //Register the server Commands
            RegisterCommand("ban", new BanPlayerCommand().Execute, "Bans someone from the server");
            RegisterCommand("changesettings", new ChangeSettingsCommand().Execute, "Changes the server settings");
            RegisterCommand("clearvessels", new ClearVesselsCommand().Execute, "Clears ALL SPECIFIED vessels from universe");
            RegisterCommand("connectionstats", new ConnectionStatsCommand().Execute, "Displays network traffic usage");
            RegisterCommand("countclients", new CountClientsCommand().Execute, "Counts connected clients");
            RegisterCommand("dekessler", new DekesslerCommand().Execute, "Clears out debris from the server");
            RegisterCommand("help", new DisplayHelpCommand().Execute, "Displays this help");
            RegisterCommand("kick", new KickCommand().Execute, "Kicks a player from the server");
            RegisterCommand("listclients", new ListClientsCommand().Execute, "Lists connected clients");
            RegisterCommand("listlocks", new ListLocksCommand().Execute, "Lists current locks");
            RegisterCommand("nukeksc", new NukeCommand().Execute, "Clears ALL vessels from KSC and the runway");
            RegisterCommand("setfunds", new SetFundsCommand().Execute, "Set funds value");
            RegisterCommand("setscience", new SetScienceCommand().Execute, "Set science value");
            RegisterCommand("restartserver", new RestartServerCommand().Execute, "Restarts the server");
            RegisterCommand("say", new SayCommand().Execute, "Broadcasts a message to clients");
        }

        /// <summary>
        /// We receive the console inputs with a pipe
        /// </summary>
        public static async void ThreadMain()
        {
            try
            {
                while (ServerContext.ServerRunning)
                {
                    var input = Console.ReadLine();
                    if (string.IsNullOrEmpty(input))
                    {
                        continue;
                    }
                    LunaLog.Normal($"Command input: {input}");
                    if (!string.IsNullOrEmpty(input))
                    {
                        if (input.StartsWith("/"))
                        {
                            HandleServerInput(input.Substring(1));
                        }
                        else
                        {
                            Commands["say"].Func(input);
                        }
                    }

                    //We only accept a command once every 500ms
                    await Task.Delay(500);
                }
{'fraction_non_alphanumeric': 0.09742075823492853, 'fraction_numerical': 0.001709136109384711, 'mean_word_length': 2.074021012416428, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3723124', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1377, 'n_words': 386}