Argv() public static method

public static Argv ( int arg ) : string
arg int
return string
コード例 #1
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        // Host_Map_f
        //
        // handle a
        // map <servername>
        // command from the console.  Active clients are kicked off.
        private 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);
            }
        }
コード例 #2
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        // Host_Startdemos_f
        private 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;
            }
        }
コード例 #3
0
ファイル: View.cs プロジェクト: polytronicgr/SharpQuake
 // 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);
 }
コード例 #4
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");
            }
        }
コード例 #5
0
ファイル: Cmd.cs プロジェクト: multiguy18/SharpQuake
        // 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");
            }
        }
コード例 #6
0
ファイル: NetDatagram.cs プロジェクト: multiguy18/SharpQuake
        // NET_Stats_f
        private void Stats_f()
        {
            if (Cmd.Argc == 1)
            {
                Con.Print("unreliable messages sent   = %i\n", Net.UnreliableMessagesSent);
                Con.Print("unreliable messages recv   = %i\n", Net.UnreliableMessagesReceived);
                Con.Print("reliable messages sent     = %i\n", Net.MessagesSent);
                Con.Print("reliable messages received = %i\n", Net.MessagesReceived);
                Con.Print("packetsSent                = %i\n", packetsSent);
                Con.Print("packetsReSent              = %i\n", packetsReSent);
                Con.Print("packetsReceived            = %i\n", packetsReceived);
                Con.Print("receivedDuplicateCount     = %i\n", receivedDuplicateCount);
                Con.Print("shortPacketCount           = %i\n", shortPacketCount);
                Con.Print("droppedDatagrams           = %i\n", droppedDatagrams);
            }
            else if (Cmd.Argv(1) == "*")
            {
                foreach (qsocket_t s in Net.ActiveSockets)
                {
                    PrintStats(s);
                }

                foreach (qsocket_t s in Net.FreeSockets)
                {
                    PrintStats(s);
                }
            }
            else
            {
                qsocket_t sock    = null;
                string    cmdAddr = Cmd.Argv(1);

                foreach (qsocket_t s in Net.ActiveSockets)
                {
                    if (Common.SameText(s.address, cmdAddr))
                    {
                        sock = s;
                        break;
                    }
                }

                if (sock == null)
                {
                    foreach (qsocket_t s in Net.FreeSockets)
                    {
                        if (Common.SameText(s.address, cmdAddr))
                        {
                            sock = s;
                            break;
                        }
                    }
                }
                if (sock == null)
                {
                    return;
                }
                PrintStats(sock);
            }
        }
コード例 #7
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 == ClientActivityState.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
            MessageWriter msg = Server.sv.reliable_datagram;

            msg.WriteByte(Protocol.svc_updatename);
            msg.WriteByte(Host.ClientNum);
            msg.WriteString(newName);
        }
コード例 #8
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 == ClientActivityState.Connected)
                {
                    Cmd.ForwardToServer();
                }

                return;
            }


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

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

            msg.WriteByte(Protocol.svc_updatecolors);
            msg.WriteByte(Host.ClientNum);
            msg.WriteByte(Host.HostClient.colors);
        }
コード例 #9
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);
        }
コード例 #10
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        /// <summary>
        /// Host_Connect_f
        /// User command to connect to server
        /// </summary>
        private 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();
        }
コード例 #11
0
ファイル: Sound.cs プロジェクト: JakeSmokie/SharpQuake
        // 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 sfx = PrecacheSound(name);
                StartSound(_PlayHash++, 0, sfx, ref _ListenerOrigin, 1.0f, 1.0f);
            }
        }
コード例 #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());
        }
コード例 #13
0
ファイル: Sound.cs プロジェクト: JakeSmokie/SharpQuake
        // 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   sfx = PrecacheSound(name);
                float vol = float.Parse(Cmd.Argv(i + 1));
                StartSound(_PlayVolHash++, 0, sfx, ref _ListenerOrigin, vol, 1.0f);
            }
        }
コード例 #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");
            }
        }
コード例 #15
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        /// <summary>
        /// Host_Changelevel_f
        /// Goes to a new map, taking all clients along
        /// </summary>
        private 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);
        }
コード例 #16
0
ファイル: Draw.cs プロジェクト: JakeSmokie/SharpQuake
        /// <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);
                }
            }
        }
コード例 #17
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;
        }
コード例 #18
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);
        }
コード例 #19
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);
                }
            }
        }
コード例 #20
0
ファイル: ClientInput.cs プロジェクト: JakeSmokie/SharpQuake
        static void KeyUp(ref KeyButton 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
        }
コード例 #21
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        /// <summary>
        /// Host_Viewframe_f
        /// </summary>
        private 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;
        }
コード例 #22
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        // Host_Viewmodel_f
        private 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;
        }
コード例 #23
0
ファイル: Cvar.cs プロジェクト: JakeSmokie/SharpQuake
        // 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);
        }
コード例 #24
0
ファイル: ClientInput.cs プロジェクト: JakeSmokie/SharpQuake
        static void KeyDown(ref KeyButton 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
        }
コード例 #25
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        /// <summary>
        /// Host_Loadgame_f
        /// </summary>
        private 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();
            }
        }
コード例 #26
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        /// <summary>
        /// Host_Savegame_f
        /// </summary>
        private 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");
        }
コード例 #27
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        /// <summary>
        /// Host_Give_f
        /// </summary>
        private static void Give_f()
        {
            if (Cmd.Source == cmd_source_t.src_command)
            {
                Cmd.ForwardToServer();
                return;
            }

            if (Progs.GlobalStruct.deathmatch != 0 && !Host.HostClient.privileged)
            {
                return;
            }

            string t = Cmd.Argv(1);
            int    v = Common.atoi(Cmd.Argv(2));

            if (String.IsNullOrEmpty(t))
            {
                return;
            }

            switch (t[0])
            {
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                // MED 01/04/97 added hipnotic give stuff
                if (Common.GameKind == GameKind.Hipnotic)
                {
                    if (t[0] == '6')
                    {
                        if (t[1] == 'a')
                        {
                            Server.Player.v.items = (int)Server.Player.v.items | QItems.HIT_PROXIMITY_GUN;
                        }
                        else
                        {
                            Server.Player.v.items = (int)Server.Player.v.items | QItems.IT_GRENADE_LAUNCHER;
                        }
                    }
                    else if (t[0] == '9')
                    {
                        Server.Player.v.items = (int)Server.Player.v.items | QItems.HIT_LASER_CANNON;
                    }
                    else if (t[0] == '0')
                    {
                        Server.Player.v.items = (int)Server.Player.v.items | QItems.HIT_MJOLNIR;
                    }
                    else if (t[0] >= '2')
                    {
                        Server.Player.v.items = (int)Server.Player.v.items | (QItems.IT_SHOTGUN << (t[0] - '2'));
                    }
                }
                else
                {
                    if (t[0] >= '2')
                    {
                        Server.Player.v.items = (int)Server.Player.v.items | (QItems.IT_SHOTGUN << (t[0] - '2'));
                    }
                }
                break;

            case 's':
                if (Common.GameKind == GameKind.Rogue)
                {
                    Progs.SetEdictFieldFloat(Server.Player, "ammo_shells1", v);
                }

                Server.Player.v.ammo_shells = v;
                break;

            case 'n':
                if (Common.GameKind == GameKind.Rogue)
                {
                    if (Progs.SetEdictFieldFloat(Server.Player, "ammo_nails1", v))
                    {
                        if (Server.Player.v.weapon <= QItems.IT_LIGHTNING)
                        {
                            Server.Player.v.ammo_nails = v;
                        }
                    }
                }
                else
                {
                    Server.Player.v.ammo_nails = v;
                }
                break;

            case 'l':
                if (Common.GameKind == GameKind.Rogue)
                {
                    if (Progs.SetEdictFieldFloat(Server.Player, "ammo_lava_nails", v))
                    {
                        if (Server.Player.v.weapon > QItems.IT_LIGHTNING)
                        {
                            Server.Player.v.ammo_nails = v;
                        }
                    }
                }
                break;

            case 'r':
                if (Common.GameKind == GameKind.Rogue)
                {
                    if (Progs.SetEdictFieldFloat(Server.Player, "ammo_rockets1", v))
                    {
                        if (Server.Player.v.weapon <= QItems.IT_LIGHTNING)
                        {
                            Server.Player.v.ammo_rockets = v;
                        }
                    }
                }
                else
                {
                    Server.Player.v.ammo_rockets = v;
                }
                break;

            case 'm':
                if (Common.GameKind == GameKind.Rogue)
                {
                    if (Progs.SetEdictFieldFloat(Server.Player, "ammo_multi_rockets", v))
                    {
                        if (Server.Player.v.weapon > QItems.IT_LIGHTNING)
                        {
                            Server.Player.v.ammo_rockets = v;
                        }
                    }
                }
                break;

            case 'h':
                Server.Player.v.health = v;
                break;

            case 'c':
                if (Common.GameKind == GameKind.Rogue)
                {
                    if (Progs.SetEdictFieldFloat(Server.Player, "ammo_cells1", v))
                    {
                        if (Server.Player.v.weapon <= QItems.IT_LIGHTNING)
                        {
                            Server.Player.v.ammo_cells = v;
                        }
                    }
                }
                else
                {
                    Server.Player.v.ammo_cells = v;
                }
                break;

            case 'p':
                if (Common.GameKind == GameKind.Rogue)
                {
                    if (Progs.SetEdictFieldFloat(Server.Player, "ammo_plasma", v))
                    {
                        if (Server.Player.v.weapon > QItems.IT_LIGHTNING)
                        {
                            Server.Player.v.ammo_cells = v;
                        }
                    }
                }
                break;
            }
        }
コード例 #28
0
ファイル: HostCmd.cs プロジェクト: multiguy18/SharpQuake
        /// <summary>
        /// Host_Kick_f
        /// Kicks a user off of the server
        /// </summary>
        private static void Kick_f()
        {
            if (Cmd.Source == cmd_source_t.src_command)
            {
                if (!Server.sv.active)
                {
                    Cmd.ForwardToServer();
                    return;
                }
            }
            else if (Progs.GlobalStruct.deathmatch != 0 && !Host.HostClient.privileged)
            {
                return;
            }

            client_t save     = Host.HostClient;
            bool     byNumber = false;
            int      i;

            if (Cmd.Argc > 2 && Cmd.Argv(1) == "#")
            {
                i = (int)Common.atof(Cmd.Argv(2)) - 1;
                if (i < 0 || i >= Server.svs.maxclients)
                {
                    return;
                }
                if (!Server.svs.clients[i].active)
                {
                    return;
                }

                Host.HostClient = Server.svs.clients[i];
                byNumber        = true;
            }
            else
            {
                for (i = 0; i < Server.svs.maxclients; i++)
                {
                    Host.HostClient = Server.svs.clients[i];
                    if (!Host.HostClient.active)
                    {
                        continue;
                    }
                    if (Common.SameText(Host.HostClient.name, Cmd.Argv(1)))
                    {
                        break;
                    }
                }
            }

            if (i < Server.svs.maxclients)
            {
                string who;
                if (Cmd.Source == cmd_source_t.src_command)
                {
                    if (Client.cls.state == cactive_t.ca_dedicated)
                    {
                        who = "Console";
                    }
                    else
                    {
                        who = Client.Name;
                    }
                }
                else
                {
                    who = save.name;
                }

                // can't kick yourself!
                if (Host.HostClient == save)
                {
                    return;
                }

                string message = null;
                if (Cmd.Argc > 2)
                {
                    message = Common.Parse(Cmd.Args);
                    if (byNumber)
                    {
                        message = message.Substring(1);                  // skip the #
                        message = message.Trim();                        // skip white space
                        message = message.Substring(Cmd.Argv(2).Length); // skip the number
                    }
                    message = message.Trim();
                }
                if (!String.IsNullOrEmpty(message))
                {
                    Server.ClientPrint("Kicked by {0}: {1}\n", who, message);
                }
                else
                {
                    Server.ClientPrint("Kicked by {0}\n", who);
                }
                Server.DropClient(false);
            }

            Host.HostClient = save;
        }
コード例 #29
0
        // CL_PlayDemo_f
        //
        // play [demoname]
        private 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);
        }
コード例 #30
0
        /// <summary>
        /// CL_Record_f
        /// record <demoname> <map> [cd track]
        /// </summary>
        private 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;
        }