예제 #1
0
        public static void ExecuteNow(string command)
        {
            string[] args = Tokenize(command);

            if (args.Length == 0)
            {
                return;
            }

            ConVar.HandleCommand(args);

            // some quick commands
            if (args[0] == "a")
            {
                args = new[] { "map", "mp1-comp" };
            }
            else if (args[0] == "b")
            {
                args = new[] { "connect", "192.168.178.83:29960" };
            }

            // quick hack to allow a connect command
            if (args[0] == "connect")
            {
                Client.Connect_f(args);
            }
            else if (args[0] == "map")
            {
                if (args.Length != 2)
                {
                    Log.Write(LogLevel.Error, "Please enter the map name you want.");
                    return;
                }
                var mapName = args[1];

                MapManager.Load(string.Format("Maps/{0}.gmp", mapName));
                Server.InitializeMap(mapName);

                Client.Connect_f(new[] { "connect", "localhost" });
            }
            else if (args[0] == "say")
            {
                Client.SendReliableCommand(command);
            }

            if (args[0] == "quit")
            {
                Log.Write(LogLevel.Info, "Client shutting down..");
                Environment.Exit(1);
            }

            // status command, mmk?
            if (args[0] == "status")
            {
                Server.Status_f();
            }

            if (args[0] == "kick")
            {
                if (args.Length != 2)
                {
                    Log.Write(LogLevel.Error, "Please enter the nickname of the user you want to kick.");
                    return;
                }

                Server.Kick_f(args[1]);
            }

            if (args[0] == "clear")
            {
                Client.ClearConsole();
            }

            // isn't this an odd place to do it
            if (args[0] == "nickname")
            {
                // TODO: Introduce a config saving system based on the quake one.
                if (args[1].Length > 18)
                {
                    Log.Write(LogLevel.Error, "Your nickname is to long.");
                    return;
                }
                ConVar.SetValue <string>("nicknamee", args[1]);
                var     path = Directory.GetCurrentDirectory() + "\\config.ini";
                IniFile ini  = new IniFile(path);
                ini.IniWriteValue("CONFIG", "nickname", args[1]);
            }

            if (args[0] == "kill")
            {
                if (args.Length != 2)
                {
                    Log.Write(LogLevel.Error, "You didn't specify the user to 'kill'.");
                    return;
                }
                Server.KillClient(args[1]);

                /*SendReliableCommand(null, "print \"{0} drowned...\"", client.Name);
                 * //client.Entity.Die();
                 * client.Entity.Spawn();*/
            }
        }