Exemple #1
0
        // NET_Port_f
        static void Port_f()
        {
            if (Cmd.Argc != 2)
            {
                Con.Print("\"port\" is \"{0}\"\n", HostPort);
                return;
            }

            int n = Common.atoi(Cmd.Argv(1));

            if (n < 1 || n > 65534)
            {
                Con.Print("Bad value, must be between 1 and 65534\n");
                return;
            }

            _DefHostPort = n;
            HostPort     = n;

            if (_IsListening)
            {
                // force a change to the new port
                Cbuf.AddText("listen 0\n");
                Cbuf.AddText("listen 1\n");
            }
        }
Exemple #2
0
        // void	Cmd_ForwardToServer (void);
        // adds the current command line as a clc_stringcmd to the client message.
        // things like godmode, noclip, etc, are commands directed to the server,
        // so when they are typed in at the console, they will need to be forwarded.
        //
        // Sends the entire command line over to the server
        public static void ForwardToServer()
        {
            if (Client.cls.state != cactive_t.ca_connected)
            {
                Con.Print("Can't \"{0}\", not connected\n", Cmd.Argv(0));
                return;
            }

            if (Client.cls.demoplayback)
            {
                return;         // not really connected
            }
            MsgWriter writer = Client.cls.message;

            writer.WriteByte(Protocol.clc_stringcmd);
            if (!Cmd.Argv(0).Equals("cmd"))
            {
                writer.Print(Cmd.Argv(0) + " ");
            }
            if (Cmd.Argc > 1)
            {
                writer.Print(Cmd.Args);
            }
            else
            {
                writer.Print("\n");
            }
        }
Exemple #3
0
        // Host_Map_f
        //
        // handle a
        // map <servername>
        // command from the console.  Active clients are kicked off.
        static void Map_f()
        {
            if (Cmd.Source != cmd_source_t.src_command)
            {
                return;
            }

            Client.cls.demonum = -1;            // stop demo loop in case this fails

            Client.Disconnect();
            ShutdownServer(false);

            Key.Destination = keydest_t.key_game;                       // remove console or menu
            Scr.BeginLoadingPlaque();

            Client.cls.mapstring = Cmd.JoinArgv() + "\n";

            Server.svs.serverflags = 0;                 // haven't completed an episode yet
            string name = Cmd.Argv(1);

            Server.SpawnServer(name);

            if (!Server.IsActive)
            {
                return;
            }

            if (Client.cls.state != cactive_t.ca_dedicated)
            {
                Client.cls.spawnparms = Cmd.JoinArgv();
                Cmd.ExecuteString("connect local", cmd_source_t.src_command);
            }
        }
Exemple #4
0
 // V_cshift_f
 static void CShift_f()
 {
     int.TryParse(Cmd.Argv(1), out _CShift_empty.destcolor[0]);
     int.TryParse(Cmd.Argv(2), out _CShift_empty.destcolor[1]);
     int.TryParse(Cmd.Argv(3), out _CShift_empty.destcolor[2]);
     int.TryParse(Cmd.Argv(4), out _CShift_empty.percent);
 }
Exemple #5
0
        // Host_Startdemos_f
        static void Startdemos_f()
        {
            if (Client.cls.state == cactive_t.ca_dedicated)
            {
                if (!Server.sv.active)
                {
                    Cbuf.AddText("map start\n");
                }
                return;
            }

            int c = Cmd.Argc - 1;

            if (c > Client.MAX_DEMOS)
            {
                Con.Print("Max {0} demos in demoloop\n", Client.MAX_DEMOS);
                c = Client.MAX_DEMOS;
            }
            Con.Print("{0} demo(s) in loop\n", c);

            for (int i = 1; i < c + 1; i++)
            {
                Client.cls.demos[i - 1] = Common.Copy(Cmd.Argv(i), Client.MAX_DEMONAME);
            }

            if (!Server.sv.active && Client.cls.demonum != -1 && !Client.cls.demoplayback)
            {
                Client.cls.demonum = 0;
                Client.NextDemo();
            }
            else
            {
                Client.cls.demonum = -1;
            }
        }
Exemple #6
0
        // Host_Name_f
        static void Name_f()
        {
            if (Cmd.Argc == 1)
            {
                Con.Print("\"name\" is \"{0}\"\n", Client.Name);
                return;
            }

            string newName;

            if (Cmd.Argc == 2)
            {
                newName = Cmd.Argv(1);
            }
            else
            {
                newName = Cmd.Args;
            }

            if (newName.Length > 16)
            {
                newName = newName.Remove(15);
            }

            if (Cmd.Source == cmd_source_t.src_command)
            {
                if (Client.Name == newName)
                {
                    return;
                }
                Cvar.Set("_cl_name", newName);
                if (Client.cls.state == cactive_t.ca_connected)
                {
                    Cmd.ForwardToServer();
                }
                return;
            }

            if (!String.IsNullOrEmpty(Host.HostClient.name) && Host.HostClient.name != "unconnected")
            {
                if (Host.HostClient.name != newName)
                {
                    Con.Print("{0} renamed to {1}\n", Host.HostClient.name, newName);
                }
            }

            Host.HostClient.name            = newName;
            Host.HostClient.edict.v.netname = Progs.NewString(newName);

            // send notification to all clients
            MsgWriter msg = Server.sv.reliable_datagram;

            msg.WriteByte(Protocol.svc_updatename);
            msg.WriteByte(Host.ClientNum);
            msg.WriteString(newName);
        }
Exemple #7
0
        // Host_Color_f
        static void Color_f()
        {
            if (Cmd.Argc == 1)
            {
                Con.Print("\"color\" is \"{0} {1}\"\n", ((int)Client.Color) >> 4, ((int)Client.Color) & 0x0f);
                Con.Print("color <0-13> [0-13]\n");
                return;
            }

            int top, bottom;

            if (Cmd.Argc == 2)
            {
                top = bottom = Common.atoi(Cmd.Argv(1));
            }
            else
            {
                top    = Common.atoi(Cmd.Argv(1));
                bottom = Common.atoi(Cmd.Argv(2));
            }

            top &= 15;
            if (top > 13)
            {
                top = 13;
            }
            bottom &= 15;
            if (bottom > 13)
            {
                bottom = 13;
            }

            int playercolor = top * 16 + bottom;

            if (Cmd.Source == cmd_source_t.src_command)
            {
                Cvar.Set("_cl_color", playercolor);
                if (Client.cls.state == cactive_t.ca_connected)
                {
                    Cmd.ForwardToServer();
                }
                return;
            }


            Host.HostClient.colors       = playercolor;
            Host.HostClient.edict.v.team = bottom + 1;

            // send notification to all clients
            MsgWriter msg = Server.sv.reliable_datagram;

            msg.WriteByte(Protocol.svc_updatecolors);
            msg.WriteByte(Host.ClientNum);
            msg.WriteByte(Host.HostClient.colors);
        }
Exemple #8
0
        /// <summary>
        /// ED_PrintEdict_f
        /// For debugging, prints a single edict
        /// </summary>
        static void PrintEdict_f()
        {
            int i = Common.atoi(Cmd.Argv(1));

            if (i >= Server.sv.num_edicts)
            {
                Con.Print("Bad edict number\n");
                return;
            }
            Progs.PrintNum(i);
        }
Exemple #9
0
        /// <summary>
        /// Host_Connect_f
        /// User command to connect to server
        /// </summary>
        static void Connect_f()
        {
            Client.cls.demonum = -1;            // stop demo loop in case this fails
            if (Client.cls.demoplayback)
            {
                Client.StopPlayback();
                Client.Disconnect();
            }
            string name = Cmd.Argv(1);

            Client.EstablishConnection(name);
            Reconnect_f();
        }
Exemple #10
0
        // S_Play
        static void Play()
        {
            for (int i = 1; i < Cmd.Argc; i++)
            {
                string name = Cmd.Argv(i);
                int    k    = name.IndexOf('.');
                if (k == -1)
                {
                    name += ".wav";
                }

                sfx_t sfx = PrecacheSound(name);
                StartSound(_PlayHash++, 0, sfx, ref _ListenerOrigin, 1.0f, 1.0f);
            }
        }
Exemple #11
0
        // S_PlayVol
        static void PlayVol()
        {
            for (int i = 1; i < Cmd.Argc; i += 2)
            {
                string name = Cmd.Argv(i);
                int    k    = name.IndexOf('.');
                if (k == -1)
                {
                    name += ".wav";
                }

                sfx_t sfx = PrecacheSound(name);
                float vol = float.Parse(Cmd.Argv(i + 1));
                StartSound(_PlayVolHash++, 0, sfx, ref _ListenerOrigin, vol, 1.0f);
            }
        }
Exemple #12
0
        //Key_Bind_f
        static void Bind_f()
        {
            int c = Cmd.Argc;

            if (c != 2 && c != 3)
            {
                Con.Print("bind <key> [command] : attach a command to a key\n");
                return;
            }

            int b = StringToKeynum(Cmd.Argv(1));

            if (b == -1)
            {
                Con.Print("\"{0}\" isn't a valid key\n", Cmd.Argv(1));
                return;
            }

            if (c == 2)
            {
                if (!String.IsNullOrEmpty(_Bindings[b]))// keybindings[b])
                {
                    Con.Print("\"{0}\" = \"{1}\"\n", Cmd.Argv(1), _Bindings[b]);
                }
                else
                {
                    Con.Print("\"{0}\" is not bound\n", Cmd.Argv(1));
                }
                return;
            }

            // copy the rest of the command line
            // start out with a null string
            StringBuilder sb = new StringBuilder(1024);

            for (int i = 2; i < c; i++)
            {
                if (i > 2)
                {
                    sb.Append(" ");
                }
                sb.Append(Cmd.Argv(i));
            }

            SetBinding(b, sb.ToString());
        }
Exemple #13
0
        /// <summary>
        /// Host_Changelevel_f
        /// Goes to a new map, taking all clients along
        /// </summary>
        static void Changelevel_f()
        {
            if (Cmd.Argc != 2)
            {
                Con.Print("changelevel <levelname> : continue game on a new level\n");
                return;
            }
            if (!Server.sv.active || Client.cls.demoplayback)
            {
                Con.Print("Only the server may changelevel\n");
                return;
            }
            Server.SaveSpawnparms();
            string level = Cmd.Argv(1);

            Server.SpawnServer(level);
        }
Exemple #14
0
        // MaxPlayers_f
        static void MaxPlayers_f()
        {
            if (Cmd.Argc != 2)
            {
                Con.Print("\"maxplayers\" is \"%u\"\n", Server.svs.maxclients);
                return;
            }

            if (Server.sv.active)
            {
                Con.Print("maxplayers can not be changed while a server is running.\n");
                return;
            }

            int n = Common.atoi(Cmd.Argv(1));

            if (n < 1)
            {
                n = 1;
            }
            if (n > Server.svs.maxclientslimit)
            {
                n = Server.svs.maxclientslimit;
                Con.Print("\"maxplayers\" set to \"{0}\"\n", n);
            }

            if (n == 1 && _IsListening)
            {
                Cbuf.AddText("listen 0\n");
            }

            if (n > 1 && !_IsListening)
            {
                Cbuf.AddText("listen 1\n");
            }

            Server.svs.maxclients = n;
            if (n == 1)
            {
                Cvar.Set("deathmatch", "0");
            }
            else
            {
                Cvar.Set("deathmatch", "1");
            }
        }
Exemple #15
0
        /// <summary>
        /// Draw_TextureMode_f
        /// </summary>
        static void TextureMode_f()
        {
            int i;

            if (Cmd.Argc == 1)
            {
                for (i = 0; i < 6; i++)
                {
                    if (_MinFilter == _Modes[i].minimize)
                    {
                        Con.Print("{0}\n", _Modes[i].name);
                        return;
                    }
                }
                Con.Print("current filter is unknown???\n");
                return;
            }

            for (i = 0; i < _Modes.Length; i++)
            {
                if (Common.SameText(_Modes[i].name, Cmd.Argv(1)))
                {
                    break;
                }
            }
            if (i == _Modes.Length)
            {
                Con.Print("bad filter name!\n");
                return;
            }

            _MinFilter = _Modes[i].minimize;
            _MagFilter = _Modes[i].maximize;

            // change all the existing mipmap texture objects
            for (i = 0; i < _NumTextures; i++)
            {
                gltexture_t glt = _glTextures[i];
                if (glt.mipmap)
                {
                    Bind(glt.texnum);
                    SetTextureFilters(_MinFilter, _MagFilter);
                }
            }
        }
Exemple #16
0
        // NET_Listen_f
        static void Listen_f()
        {
            if (Cmd.Argc != 2)
            {
                Con.Print("\"listen\" is \"{0}\"\n", _IsListening ? 1 : 0);
                return;
            }

            _IsListening = (Common.atoi(Cmd.Argv(1)) != 0);

            foreach (INetDriver driver in _Drivers)
            {
                if (driver.IsInitialized)
                {
                    driver.Listen(_IsListening);
                }
            }
        }
Exemple #17
0
        //Key_Unbind_f
        static void Unbind_f()
        {
            if (Cmd.Argc != 2)
            {
                Con.Print("unbind <key> : remove commands from a key\n");
                return;
            }

            int b = StringToKeynum(Cmd.Argv(1));

            if (b == -1)
            {
                Con.Print("\"{0}\" isn't a valid key\n", Cmd.Argv(1));
                return;
            }

            SetBinding(b, null);
        }
Exemple #18
0
        // Host_Tell_f
        static void Tell_f()
        {
            if (Cmd.Source == cmd_source_t.src_command)
            {
                Cmd.ForwardToServer();
                return;
            }

            if (Cmd.Argc < 3)
            {
                return;
            }

            string text = Host.HostClient.name + ": ";
            string p    = Cmd.Args;

            // remove quotes if present
            if (p.StartsWith("\""))
            {
                p = p.Substring(1, p.Length - 2);
            }

            text += p + "\n";

            client_t save = Host.HostClient;

            for (int j = 0; j < Server.svs.maxclients; j++)
            {
                client_t client = Server.svs.clients[j];
                if (!client.active || !client.spawned)
                {
                    continue;
                }
                if (client.name == Cmd.Argv(1))
                {
                    continue;
                }
                Host.HostClient = client;
                Server.ClientPrint(text);
                break;
            }
            Host.HostClient = save;
        }
Exemple #19
0
        // Host_Viewmodel_f
        static void Viewmodel_f()
        {
            edict_t e = FindViewthing();

            if (e == null)
            {
                return;
            }

            model_t m = Mod.ForName(Cmd.Argv(1), false);

            if (m == null)
            {
                Con.Print("Can't load {0}\n", Cmd.Argv(1));
                return;
            }

            e.v.frame = 0;
            Client.cl.model_precache[(int)e.v.modelindex] = m;
        }
Exemple #20
0
        /// <summary>
        /// Host_Viewframe_f
        /// </summary>
        static void Viewframe_f()
        {
            edict_t e = FindViewthing();

            if (e == null)
            {
                return;
            }

            model_t m = Client.cl.model_precache[(int)e.v.modelindex];

            int f = Common.atoi(Cmd.Argv(1));

            if (f >= m.numframes)
            {
                f = m.numframes - 1;
            }

            e.v.frame = f;
        }
Exemple #21
0
        // Cvar_Command()
        // Handles variable inspection and changing from the console
        public static bool Command()
        {
            // check variables
            Cvar var = Find(Cmd.Argv(0));

            if (var == null)
            {
                return(false);
            }

            // perform a variable print or set
            if (Cmd.Argc == 1)
            {
                Con.Print("\"{0}\" is \"{1}\"\n", var._Name, var._String);
            }
            else
            {
                var.Set(Cmd.Argv(1));
            }
            return(true);
        }
Exemple #22
0
        static void KeyUp(ref kbutton_t b)
        {
            int k;
            string c = Cmd.Argv(1);

            if (!String.IsNullOrEmpty(c))
            {
                k = int.Parse(c);
            }
            else
            {
                // typed manually at the console, assume for unsticking, so clear all
                b.down0 = b.down1 = 0;
                b.state = 4;    // impulse up
                return;
            }

            if (b.down0 == k)
            {
                b.down0 = 0;
            }
            else if (b.down1 == k)
            {
                b.down1 = 0;
            }
            else
            {
                return; // key up without coresponding down (menu pass through)
            }
            if (b.down0 != 0 || b.down1 != 0)
            {
                return; // some other key is still holding it down
            }
            if ((b.state & 1) == 0)
            {
                return;         // still up (this should not happen)
            }
            b.state &= ~1;      // now up
            b.state |= 4;       // impulse up
        }
Exemple #23
0
        static void KeyDown(ref kbutton_t b)
        {
            int k;
            string c = Cmd.Argv(1);

            if (!String.IsNullOrEmpty(c))
            {
                k = int.Parse(c);
            }
            else
            {
                k = -1; // typed manually at the console for continuous down
            }
            if (k == b.down0 || k == b.down1)
            {
                return;         // repeating key
            }
            if (b.down0 == 0)
            {
                b.down0 = k;
            }
            else if (b.down1 == 0)
            {
                b.down1 = k;
            }
            else
            {
                Con.Print("Three keys down for a button!\n");
                return;
            }

            if ((b.state & 1) != 0)
            {
                return;       // still down
            }
            b.state |= 1 + 2; // down + impulse down
        }
Exemple #24
0
        // VID_DescribeMode_f
        static void DescribeMode_f()
        {
            int modenum = Common.atoi(Cmd.Argv(1));

            Con.Print("{0}\n", GetExtModeDescription(modenum));
        }
Exemple #25
0
        /// <summary>
        /// Host_Savegame_f
        /// </summary>
        static void Savegame_f()
        {
            if (Cmd.Source != cmd_source_t.src_command)
            {
                return;
            }

            if (!Server.sv.active)
            {
                Con.Print("Not playing a local game.\n");
                return;
            }

            if (Client.cl.intermission != 0)
            {
                Con.Print("Can't save in intermission.\n");
                return;
            }

            if (Server.svs.maxclients != 1)
            {
                Con.Print("Can't save multiplayer games.\n");
                return;
            }

            if (Cmd.Argc != 2)
            {
                Con.Print("save <savename> : save a game\n");
                return;
            }

            if (Cmd.Argv(1).Contains(".."))
            {
                Con.Print("Relative pathnames are not allowed.\n");
                return;
            }

            for (int i = 0; i < Server.svs.maxclients; i++)
            {
                if (Server.svs.clients[i].active && (Server.svs.clients[i].edict.v.health <= 0))
                {
                    Con.Print("Can't savegame with a dead player\n");
                    return;
                }
            }

            string name = Path.ChangeExtension(Path.Combine(Common.GameDir, Cmd.Argv(1)), ".sav");

            Con.Print("Saving game to {0}...\n", name);
            FileStream fs = Sys.FileOpenWrite(name, true);

            if (fs == null)
            {
                Con.Print("ERROR: couldn't open.\n");
                return;
            }
            using (StreamWriter writer = new StreamWriter(fs, Encoding.ASCII))
            {
                writer.WriteLine(SAVEGAME_VERSION);
                writer.WriteLine(SavegameComment());

                for (int i = 0; i < Server.NUM_SPAWN_PARMS; i++)
                {
                    writer.WriteLine(Server.svs.clients[0].spawn_parms[i].ToString("F6",
                                                                                   CultureInfo.InvariantCulture.NumberFormat));
                }

                writer.WriteLine(Host.CurrentSkill);
                writer.WriteLine(Server.sv.name);
                writer.WriteLine(Server.sv.time.ToString("F6",
                                                         CultureInfo.InvariantCulture.NumberFormat));

                // write the light styles

                for (int i = 0; i < QDef.MAX_LIGHTSTYLES; i++)
                {
                    if (!String.IsNullOrEmpty(Server.sv.lightstyles[i]))
                    {
                        writer.WriteLine(Server.sv.lightstyles[i]);
                    }
                    else
                    {
                        writer.WriteLine("m");
                    }
                }

                Progs.WriteGlobals(writer);
                for (int i = 0; i < Server.sv.num_edicts; i++)
                {
                    Progs.WriteEdict(writer, Server.EdictNum(i));
                    writer.Flush();
                }
            }
            Con.Print("done.\n");
        }
Exemple #26
0
        /// <summary>
        /// CL_Record_f
        /// record <demoname> <map> [cd track]
        /// </summary>
        static void Record_f()
        {
            if (Cmd.Source != cmd_source_t.src_command)
            {
                return;
            }

            int c = Cmd.Argc;

            if (c != 2 && c != 3 && c != 4)
            {
                Con.Print("record <demoname> [<map> [cd track]]\n");
                return;
            }

            if (Cmd.Argv(1).Contains(".."))
            {
                Con.Print("Relative pathnames are not allowed.\n");
                return;
            }

            if (c == 2 && cls.state == cactive_t.ca_connected)
            {
                Con.Print("Can not record - already connected to server\nClient demo recording must be started before connecting\n");
                return;
            }

            // write the forced cd track number, or -1
            int track;

            if (c == 4)
            {
                track = Common.atoi(Cmd.Argv(3));
                Con.Print("Forcing CD track to {0}\n", track);
            }
            else
            {
                track = -1;
            }

            string name = Path.Combine(Common.GameDir, Cmd.Argv(1));

            //
            // start the map up
            //
            if (c > 2)
            {
                Cmd.ExecuteString(String.Format("map {0}", Cmd.Argv(2)), cmd_source_t.src_command);
            }

            //
            // open the demo file
            //
            name = Path.ChangeExtension(name, ".dem");

            Con.Print("recording to {0}.\n", name);
            FileStream fs = Sys.FileOpenWrite(name, true);

            if (fs == null)
            {
                Con.Print("ERROR: couldn't open.\n");
                return;
            }
            BinaryWriter writer = new BinaryWriter(fs, Encoding.ASCII);

            cls.demofile   = new DisposableWrapper <BinaryWriter>(writer, true);
            cls.forcetrack = track;
            byte[] tmp = Encoding.ASCII.GetBytes(cls.forcetrack.ToString());
            writer.Write(tmp);
            writer.Write('\n');
            cls.demorecording = true;
        }
Exemple #27
0
        // CL_PlayDemo_f
        //
        // play [demoname]
        static void PlayDemo_f()
        {
            if (Cmd.Source != cmd_source_t.src_command)
            {
                return;
            }

            if (Cmd.Argc != 2)
            {
                Con.Print("play <demoname> : plays a demo\n");
                return;
            }

            //
            // disconnect from server
            //
            Client.Disconnect();

            //
            // open the demo file
            //
            string name = Path.ChangeExtension(Cmd.Argv(1), ".dem");

            Con.Print("Playing demo from {0}.\n", name);
            if (cls.demofile != null)
            {
                cls.demofile.Dispose();
            }
            DisposableWrapper <BinaryReader> reader;

            Common.FOpenFile(name, out reader);
            cls.demofile = reader;
            if (cls.demofile == null)
            {
                Con.Print("ERROR: couldn't open.\n");
                cls.demonum = -1;               // stop demo loop
                return;
            }

            cls.demoplayback = true;
            cls.state        = cactive_t.ca_connected;
            cls.forcetrack   = 0;

            BinaryReader s = reader.Object;
            int          c;
            bool         neg = false;

            while (true)
            {
                c = s.ReadByte();
                if (c == '\n')
                {
                    break;
                }

                if (c == '-')
                {
                    neg = true;
                }
                else
                {
                    cls.forcetrack = cls.forcetrack * 10 + (c - '0');
                }
            }

            if (neg)
            {
                cls.forcetrack = -cls.forcetrack;
            }
            // ZOID, fscanf is evil
            //	fscanf (cls.demofile, "%i\n", &cls.forcetrack);
        }
Exemple #28
0
        /// <summary>
        /// Host_Loadgame_f
        /// </summary>
        static void Loadgame_f()
        {
            if (Cmd.Source != cmd_source_t.src_command)
            {
                return;
            }

            if (Cmd.Argc != 2)
            {
                Con.Print("load <savename> : load a game\n");
                return;
            }

            Client.cls.demonum = -1;            // stop demo loop in case this fails

            string name = Path.ChangeExtension(Path.Combine(Common.GameDir, Cmd.Argv(1)), ".sav");

            // we can't call SCR_BeginLoadingPlaque, because too much stack space has
            // been used.  The menu calls it before stuffing loadgame command
            //	SCR_BeginLoadingPlaque ();

            Con.Print("Loading game from {0}...\n", name);
            FileStream fs = Sys.FileOpenRead(name);

            if (fs == null)
            {
                Con.Print("ERROR: couldn't open.\n");
                return;
            }

            using (StreamReader reader = new StreamReader(fs, Encoding.ASCII))
            {
                string line    = reader.ReadLine();
                int    version = Common.atoi(line);
                if (version != SAVEGAME_VERSION)
                {
                    Con.Print("Savegame is version {0}, not {1}\n", version, SAVEGAME_VERSION);
                    return;
                }
                line = reader.ReadLine();

                float[] spawn_parms = new float[Server.NUM_SPAWN_PARMS];
                for (int i = 0; i < spawn_parms.Length; i++)
                {
                    line           = reader.ReadLine();
                    spawn_parms[i] = Common.atof(line);
                }
                // this silliness is so we can load 1.06 save files, which have float skill values
                line = reader.ReadLine();
                float tfloat = Common.atof(line);
                Host.CurrentSkill = (int)(tfloat + 0.1);
                Cvar.Set("skill", (float)Host.CurrentSkill);

                string mapname = reader.ReadLine();
                line = reader.ReadLine();
                float time = Common.atof(line);

                Client.Disconnect_f();
                Server.SpawnServer(mapname);

                if (!Server.sv.active)
                {
                    Con.Print("Couldn't load map\n");
                    return;
                }
                Server.sv.paused   = true;              // pause until all clients connect
                Server.sv.loadgame = true;

                // load the light styles

                for (int i = 0; i < QDef.MAX_LIGHTSTYLES; i++)
                {
                    line = reader.ReadLine();
                    Server.sv.lightstyles[i] = line;
                }

                // load the edicts out of the savegame file
                int           entnum = -1;      // -1 is the globals
                StringBuilder sb     = new StringBuilder(32768);
                while (!reader.EndOfStream)
                {
                    line = reader.ReadLine();
                    if (line == null)
                    {
                        Sys.Error("EOF without closing brace");
                    }

                    sb.AppendLine(line);
                    int idx = line.IndexOf('}');
                    if (idx != -1)
                    {
                        int    length = 1 + sb.Length - (line.Length - idx);
                        string data   = Common.Parse(sb.ToString(0, length));
                        if (String.IsNullOrEmpty(Common.Token))
                        {
                            break; // end of file
                        }
                        if (Common.Token != "{")
                        {
                            Sys.Error("First token isn't a brace");
                        }

                        if (entnum == -1)
                        {
                            // parse the global vars
                            Progs.ParseGlobals(data);
                        }
                        else
                        {
                            // parse an edict
                            edict_t ent = Server.EdictNum(entnum);
                            ent.Clear();
                            Progs.ParseEdict(data, ent);

                            // link it into the bsp tree
                            if (!ent.free)
                            {
                                Server.LinkEdict(ent, false);
                            }
                        }

                        entnum++;
                        sb.Remove(0, length);
                    }
                }

                Server.sv.num_edicts = entnum;
                Server.sv.time       = time;

                for (int i = 0; i < Server.NUM_SPAWN_PARMS; i++)
                {
                    Server.svs.clients[0].spawn_parms[i] = spawn_parms[i];
                }
            }

            if (Client.cls.state != cactive_t.ca_dedicated)
            {
                Client.EstablishConnection("local");
                Reconnect_f();
            }
        }
Exemple #29
0
 static void ImpulseCmd()
 {
     Impulse = Common.atoi(Cmd.Argv(1));
 }
Exemple #30
0
        static void CD_f()
        {
            if (Cmd.Argc < 2)
            {
                return;
            }

            string command = Cmd.Argv(1);

            if (Common.SameText(command, "on"))
            {
                _Controller.IsEnabled = true;
                return;
            }

            if (Common.SameText(command, "off"))
            {
                if (_Controller.IsPlaying)
                {
                    _Controller.Stop();
                }
                _Controller.IsEnabled = false;
                return;
            }

            if (Common.SameText(command, "reset"))
            {
                _Controller.IsEnabled = true;
                if (_Controller.IsPlaying)
                {
                    _Controller.Stop();
                }

                _Controller.ReloadDiskInfo();
                return;
            }

            if (Common.SameText(command, "remap"))
            {
                int    ret   = Cmd.Argc - 2;
                byte[] remap = _Controller.Remap;
                if (ret <= 0)
                {
                    for (int n = 1; n < 100; n++)
                    {
                        if (remap[n] != n)
                        {
                            Con.Print("  {0} -> {1}\n", n, remap[n]);
                        }
                    }
                    return;
                }
                for (int n = 1; n <= ret; n++)
                {
                    remap[n] = (byte)Common.atoi(Cmd.Argv(n + 1));
                }
                return;
            }

            if (Common.SameText(command, "close"))
            {
                _Controller.CloseDoor();
                return;
            }

            if (!_Controller.IsValidCD)
            {
                _Controller.ReloadDiskInfo();
                if (!_Controller.IsValidCD)
                {
                    Con.Print("No CD in player.\n");
                    return;
                }
            }

            if (Common.SameText(command, "play"))
            {
                _Controller.Play((byte)Common.atoi(Cmd.Argv(2)), false);
                return;
            }

            if (Common.SameText(command, "loop"))
            {
                _Controller.Play((byte)Common.atoi(Cmd.Argv(2)), true);
                return;
            }

            if (Common.SameText(command, "stop"))
            {
                _Controller.Stop();
                return;
            }

            if (Common.SameText(command, "pause"))
            {
                _Controller.Pause();
                return;
            }

            if (Common.SameText(command, "resume"))
            {
                _Controller.Resume();
                return;
            }

            if (Common.SameText(command, "eject"))
            {
                if (_Controller.IsPlaying)
                {
                    _Controller.Stop();
                }
                _Controller.Edject();
                return;
            }

            if (Common.SameText(command, "info"))
            {
                Con.Print("%u tracks\n", _Controller.MaxTrack);
                if (_Controller.IsPlaying)
                {
                    Con.Print("Currently {0} track {1}\n", _Controller.IsLooping ? "looping" : "playing", _Controller.CurrentTrack);
                }
                else if (_Controller.IsPaused)
                {
                    Con.Print("Paused {0} track {1}\n", _Controller.IsLooping ? "looping" : "playing", _Controller.CurrentTrack);
                }
                Con.Print("Volume is {0}\n", _Controller.Volume);
                return;
            }
        }