示例#1
0
        public static void Connect_f(string[] args)
        {
            if (ConVar.GetValue <string>("nicknamee") == ("")) // baddd
            {
                Log.Write(LogLevel.Info, "You haven't set a nickname, set one now:)");
                return;
            }
            if (args.Length != 2)
            {
                Log.Write(LogLevel.Info, "usage: connect [ip]");
                return;
            }

            if (args[1] != "localhost")
            {
                ConVar.SetValue <bool>("sv_running", false);
            }

            var server = NetAddress.Resolve(args[1]);

            if (_currentServer != server)
            {
                _currentServer = server;

                State = ClientState.Challenging;

                _lastMessageReceivedAt = _clientTime;
                _lastConnectPacketTime = -999999;
            }
        }
示例#2
0
        public static void Load(string filename)
        {
            if (filename.ToLowerInvariant() == _currentMap)
            {
                return;
            }

            _currentMap = filename.ToLowerInvariant();

            ConVar.SetValue("mapname", Path.GetFileNameWithoutExtension(filename));

            Stream       mapFile = FileSystem.OpenCopy(filename);
            BinaryReader reader  = new BinaryReader(mapFile);

            GBMPHeader header = new GBMPHeader();

            header.Read(reader);

            if (header.Magic != 0x504D4247 || header.Version != 500)
            {
                throw new InvalidOperationException("this isn't a GBMP v.500");
            }

            while (!mapFile.EndOfStream())
            {
                GBMPChunk chunk = new GBMPChunk();
                chunk.Read(reader);

                if (chunk.Type == 0x50414D44) // DMAP
                {
                    LoadCompressedMap(mapFile);
                }
                else if (chunk.Type == 0x5448474C) // LGHT
                {
                    LoadLights(mapFile, (chunk.Size / 16));
                }
                else
                {
                    mapFile.Position += chunk.Size;
                }
            }

            mapFile.Close();

            CellManager.InitializeFromMap();
        }
示例#3
0
        public static void HandleCommand(string[] args)
        {
            ConVar command = Find(args[0]);

            if (command == null)
            {
                return;
            }

            if (args.Length == 1)
            {
                Log.Write(LogLevel.Info, "\"{0}\" is:\"{1}^7\" default:\"{2}^7\"", command.Name, command.GetValue <string>(), command._defaultValue.ToString());
                return;
            }

            command.SetValue <string>(args[1], false);
        }
示例#4
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();*/
            }
        }
示例#5
0
        public static void Initialize()
        {
            // set the current culture to the invariant culture
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // initialize the logging service
            Log.Initialize(LogLevel.All);
            Log.AddListener(new ConsoleLogListener());
            Log.AddListener(new GameLogListener());
            Log.AddListener(new FileLogListener("GBHGame.log", false));

            Log.Write(LogLevel.Info, "GBH2 v0 initializing");
            Log.Write(LogLevel.Critical, "jeremych is an egghead and a nabsalad");

            ConVar.Initialize();
            FileSystem.Initialize();
            Win32System.Initialize();
            MapGeometry.Initialize();
            //StyleManager.Load("Styles/bil.sty");
            //MapManager.Load("Maps/MP1-comp.gmp");
            Camera.Initialize();
            NetManager.Initialize(29960);
            Client.Initialize();
            Server.Initialize();

            GameWindow.Initialize();

            com_maxFPS      = ConVar.Register("com_maxFPS", 0, "Maximum framerate for the game loop.", ConVarFlags.Archived);
            timescale       = ConVar.Register("timescale", 1.0f, "Scale time by this amount", ConVarFlags.Cheat);
            sv_running      = ConVar.Register("sv_running", true, "Is the server running?", ConVarFlags.ReadOnly);
            cl_running      = ConVar.Register("cl_running", false, "Is the client running?", ConVarFlags.ReadOnly);
            sv_paused       = ConVar.Register("sv_paused", false, "Is the server paused?", ConVarFlags.ReadOnly);
            cl_paused       = ConVar.Register("cl_paused", false, "Is the client paused?", ConVarFlags.ReadOnly);
            net_showpackets = ConVar.Register("net_showpackets", false, "Show network packets.", ConVarFlags.None);
            mapname         = ConVar.Register("mapname", "", "Current mapname", ConVarFlags.ReadOnly);
            nickname        = ConVar.Register("nickname", Environment.GetEnvironmentVariable("username"), "Your nickname", ConVarFlags.Archived);

            Renderer.Initialize();
            MaterialManager.ReadMaterialFile("base.material");
            MaterialManager.ReadMaterialFile("Styles/bil.material");
            ConsoleRenderer.Initialize();
            //StyleManager.CreateTextures(Renderer.Device);
            MapRenderer.Initialize(Renderer.Device);
            DeferredRenderer.Initialize(Renderer.Device);
            Renderer2D.Initialize(Renderer.Device);

            // jeez, people these days just need to get a *proper* nickname
            if (ConVar.GetValue <string>("nicknamee") == Environment.GetEnvironmentVariable("username"))
            {
                Log.Write(LogLevel.Info, "It looks it's your first time running GBH2. Please type 'nickname <WANTED NICKNAME>' to set your nickname.");
            }

            var     path  = Directory.GetCurrentDirectory() + "\\config.ini";
            IniFile ini   = new IniFile(path);
            var     value = ini.IniReadValue("CONFIG", "nickname");

            if (value != null)
            {
                ConVar.SetValue <string>("nicknamee", value);
            }
        }