示例#1
0
        private static void ProcessInitializationState(BitStream message)
        {
            _svStateID = message.ReadInt32();

            // load the server's current map
            var mapName = message.ReadString();

            MapManager.Load(string.Format("Maps/{0}.gmp", mapName));
        }
示例#2
0
        public static void ExportMain(string[] args)
        {
            var filename = args[1];

            var outDir = "Export/QMaps/" + filename + ".gbh2map";

            Log.Initialize(LogLevel.All);
            Log.AddListener(new ConsoleLogListener());

            ConVar.Initialize();
            FileSystem.Initialize();
            MapManager.Load("Maps/" + filename + ".gmp");

            // export cell files
            var cellWidth  = 32;
            var cellHeight = 32;

            var blockScale = 4.5f;

            var mapFile   = File.Open(string.Format("{0}/cells.lua", outDir), FileMode.Create, FileAccess.Write);
            var mapWriter = new StreamWriter(mapFile);

            for (int x = 0; x < (256 / cellWidth); x++)
            {
                for (int y = 0; y < (256 / cellHeight); y++)
                {
                    var cellName   = string.Format("{0}_{1}_{2}", filename, x, y);
                    var cellFile   = File.OpenWrite(string.Format("{0}/cells/{1}.cell", outDir, cellName));
                    var cellWriter = new BinaryWriter(cellFile);

                    for (int c = 0; c < 7; c++)
                    {
                        for (int b = (y * cellHeight); b < (y * cellHeight) + cellHeight; b++)
                        {
                            for (int a = (x * cellWidth); a < (x * cellWidth) + cellWidth; a++)
                            {
                                var block = MapManager.GetBlock(a, b, c);

                                cellWriter.Write(block.Left.Value);
                                cellWriter.Write(block.Right.Value);
                                cellWriter.Write(block.Top.Value);
                                cellWriter.Write(block.Bottom.Value);
                                cellWriter.Write(block.Lid.Value);

                                cellWriter.Write(block.SlopeType.Value);
                            }
                        }
                    }

                    cellFile.Close();

                    mapWriter.WriteLine(string.Format("class \"cells/{0}\" (GBHClass) {{ castShadows = false, renderingDistance = {1} }}", cellName, 300));
                    mapWriter.WriteLine(string.Format("object \"cells/{0}\" ({1}, {2}, {3}) {{}}", cellName, (x * cellWidth * blockScale), -(y * cellWidth * blockScale), 0));
                }
            }
        }
示例#3
0
        private static void ProcessOutOfBand(NetAddress from, byte[] packet)
        {
            var message = Encoding.UTF8.GetString(packet, 4, packet.Length - 4);
            var args    = Command.Tokenize(message);

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

            switch (args[0])
            {
            case "challengeResponse":
                if (State != ClientState.Challenging)
                {
                    return;
                }

                _lastConnectPacketTime = -999999;
                _lastMessageReceivedAt = _clientTime;

                _challenge = int.Parse(args[1]);
                State      = ClientState.Connecting;
                break;

            case "connectResponse":
                if (State != ClientState.Connecting)
                {
                    return;
                }

                _clientNum = int.Parse(args[1]);

                if (!ConVar.GetValue <bool>("sv_running"))
                {
                    Server.CreatePhysicsWorld();
                    MapManager.Load(string.Format("Maps/{0}.gmp", args[2]));
                }

                _lastConnectPacketTime = -999999;
                _lastMessageReceivedAt = _clientTime;

                _serverChannel = new NetChannel(NetChannelType.ClientToServer, from);
                InitializeConnection();

                State = ClientState.Connected;
                break;
            }
        }
示例#4
0
        protected override void Initialize()
        {
            //EventInput.Initialize(this.Window);

            Log.Initialize(LogLevel.All);
            Log.AddListener(new ConsoleLogListener());
            Log.AddListener(new GameLogListener());

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

            base.Initialize();
        }
示例#5
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();*/
            }
        }
示例#6
0
        public static void ExportMain(string[] args)
        {
            var filename = args[1];

            var outDir = "Export/Maps/" + filename + "/";

            Directory.CreateDirectory(outDir);
            Directory.CreateDirectory(outDir + "cells");

            Log.Initialize(LogLevel.All);
            Log.AddListener(new ConsoleLogListener());

            ConVar.Initialize();
            FileSystem.Initialize();
            MapManager.Load("Maps/" + filename + ".gmp");

            // export cell files
            var cellWidth  = 32;
            var cellHeight = 32;

            var blockScale = 4.5f;

            var mapFile   = File.Open(string.Format("{0}/cells.lua", outDir), FileMode.Create, FileAccess.Write);
            var mapWriter = new StreamWriter(mapFile);

            for (int x = 0; x < (256 / cellWidth); x++)
            {
                for (int y = 0; y < (256 / cellHeight); y++)
                {
                    var cellName   = string.Format("{0}_{1}_{2}", filename, x, y);
                    var cellFile   = File.OpenWrite(string.Format("{0}/cells/{1}.cell", outDir, cellName));
                    var cellWriter = new BinaryWriter(cellFile);

                    for (int c = 0; c < 7; c++)
                    {
                        for (int b = (y * cellHeight); b < (y * cellHeight) + cellHeight; b++)
                        {
                            for (int a = (x * cellWidth); a < (x * cellWidth) + cellWidth; a++)
                            {
                                var block = MapManager.GetBlock(a, b, c);

                                cellWriter.Write(block.Left.Value);
                                cellWriter.Write(block.Right.Value);
                                cellWriter.Write(block.Top.Value);
                                cellWriter.Write(block.Bottom.Value);
                                cellWriter.Write(block.Lid.Value);

                                cellWriter.Write(block.SlopeType.Value);
                            }
                        }
                    }

                    cellFile.Close();

                    mapWriter.WriteLine(string.Format("class \"cells/{0}\" (GBHClass) {{ castShadows = false, renderingDistance = {1} }}", cellName, 300));
                    mapWriter.WriteLine(string.Format("object \"cells/{0}\" ({1}, {2}, {3}) {{}}", cellName, (x * cellWidth * blockScale), -(y * cellWidth * blockScale), 0));
                }
            }

            mapWriter.Close();

            // export lights
            mapFile   = File.Open(string.Format("{0}/lights.lua", outDir), FileMode.Create, FileAccess.Write);
            mapWriter = new StreamWriter(mapFile);

            mapWriter.WriteLine("local l");
            mapWriter.WriteLine("gbh_lights = {}");

            foreach (var light in MapManager.Lights)
            {
                mapWriter.WriteLine(string.Format("l = light_from_table({{ pos = vector3({0}, {1}, {2}), diff = vector3({3}, {4}, {5}), range = {6}, coronaColour = V_ZERO }})", light.Position.X * 4.5f, light.Position.Y * -4.5f, light.Position.Z * 4.5f, light.Color.R / 255.0f, light.Color.G / 255.0f, light.Color.B / 255.0f, light.Radius * 4.5f));
                mapWriter.WriteLine("l.enabled = true");
                mapWriter.WriteLine("table.insert(gbh_lights, l)");
                mapWriter.WriteLine();
            }

            mapWriter.Close();
        }