Example #1
0
 static void ImpulseCmd()
 {
     Impulse = Common.atoi(Cmd.Argv(1));
 }
Example #2
0
        /// <summary>
        /// SV_ReadClientMessage
        /// Returns false if the client should be killed
        /// </summary>
        private static bool ReadClientMessage()
        {
            while (true)
            {
                int ret = Net.GetMessage(Host.HostClient.netconnection);
                if (ret == -1)
                {
                    Con.DPrint("SV_ReadClientMessage: NET_GetMessage failed\n");
                    return(false);
                }
                if (ret == 0)
                {
                    return(true);
                }

                Net.Reader.Reset();

                bool flag = true;
                while (flag)
                {
                    if (!Host.HostClient.active)
                    {
                        return(false);   // a command caused an error
                    }
                    if (Net.Reader.IsBadRead)
                    {
                        Con.DPrint("SV_ReadClientMessage: badread\n");
                        return(false);
                    }

                    int cmd = Net.Reader.ReadChar();
                    switch (cmd)
                    {
                    case -1:
                        flag = false;     // end of message
                        ret  = 1;
                        break;

                    case Protocol.clc_nop:
                        break;

                    case Protocol.clc_stringcmd:
                        string s = Net.Reader.ReadString();
                        if (Host.HostClient.privileged)
                        {
                            ret = 2;
                        }
                        else
                        {
                            ret = 0;
                        }
                        if (Common.SameText(s, "status", 6))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "god", 3))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "notarget", 8))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "fly", 3))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "name", 4))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "noclip", 6))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "say", 3))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "say_team", 8))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "tell", 4))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "color", 5))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "kill", 4))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "pause", 5))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "spawn", 5))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "begin", 5))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "prespawn", 8))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "kick", 4))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "ping", 4))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "give", 4))
                        {
                            ret = 1;
                        }
                        else if (Common.SameText(s, "ban", 3))
                        {
                            ret = 1;
                        }
                        if (ret == 2)
                        {
                            Cbuf.InsertText(s);
                        }
                        else if (ret == 1)
                        {
                            Cmd.ExecuteString(s, cmd_source_t.src_client);
                        }
                        else
                        {
                            Con.DPrint("{0} tried to {1}\n", Host.HostClient.name, s);
                        }
                        break;

                    case Protocol.clc_disconnect:
                        return(false);

                    case Protocol.clc_move:
                        ReadClientMove(ref Host.HostClient.cmd);
                        break;

                    default:
                        Con.DPrint("SV_ReadClientMessage: unknown command char\n");
                        return(false);
                    }
                }

                if (ret != 1)
                {
                    break;
                }
            }

            return(true);
        }
Example #3
0
        /// <summary>
        /// Key_Console
        /// Interactive line editing and console scrollback
        /// </summary>
        private static void KeyConsole(int key)
        {
            if (key == K_ENTER)
            {
                string line = new String(_Lines[_EditLine]).TrimEnd('\0', ' ');
                string cmd  = line.Substring(1);
                Cbuf.AddText(cmd);      // skip the >
                Cbuf.AddText("\n");
                Con.Print("{0}\n", line);
                _EditLine            = (_EditLine + 1) & 31;
                _HistoryLine         = _EditLine;
                _Lines[_EditLine][0] = ']';
                Key.LinePos          = 1;
                if (Client.cls.state == cactive_t.ca_disconnected)
                {
                    Scr.UpdateScreen(); // force an update, because the command
                }
                // may take some time
                return;
            }

            if (key == K_TAB)
            {
                // command completion
                string   txt   = new String(_Lines[_EditLine], 1, MAXCMDLINE - 1).TrimEnd('\0', ' ');
                string[] cmds  = Cmd.Complete(txt);
                string[] vars  = Cvar.CompleteName(txt);
                string   match = null;
                if (cmds != null)
                {
                    if (cmds.Length > 1 || vars != null)
                    {
                        Con.Print("\nCommands:\n");
                        foreach (string s in cmds)
                        {
                            Con.Print("  {0}\n", s);
                        }
                    }
                    else
                    {
                        match = cmds[0];
                    }
                }
                if (vars != null)
                {
                    if (vars.Length > 1 || cmds != null)
                    {
                        Con.Print("\nVariables:\n");
                        foreach (string s in vars)
                        {
                            Con.Print("  {0}\n", s);
                        }
                    }
                    else if (match == null)
                    {
                        match = vars[0];
                    }
                }
                if (!String.IsNullOrEmpty(match))
                {
                    int len = Math.Min(match.Length, MAXCMDLINE - 3);
                    for (int i = 0; i < len; i++)
                    {
                        _Lines[_EditLine][i + 1] = match[i];
                    }
                    Key.LinePos = len + 1;
                    _Lines[_EditLine][Key.LinePos] = ' ';
                    Key.LinePos++;
                    _Lines[_EditLine][Key.LinePos] = '\0';
                    return;
                }
            }

            if (key == K_BACKSPACE || key == K_LEFTARROW)
            {
                if (Key.LinePos > 1)
                {
                    Key.LinePos--;
                }
                return;
            }

            if (key == K_UPARROW)
            {
                do
                {
                    _HistoryLine = (_HistoryLine - 1) & 31;
                } while(_HistoryLine != _EditLine && (_Lines[_HistoryLine][1] == 0));
                if (_HistoryLine == _EditLine)
                {
                    _HistoryLine = (_EditLine + 1) & 31;
                }
                Array.Copy(_Lines[_HistoryLine], _Lines[_EditLine], MAXCMDLINE);
                Key.LinePos = 0;
                while (_Lines[_EditLine][Key.LinePos] != '\0' && Key.LinePos < MAXCMDLINE)
                {
                    Key.LinePos++;
                }
                return;
            }

            if (key == K_DOWNARROW)
            {
                if (_HistoryLine == _EditLine)
                {
                    return;
                }
                do
                {
                    _HistoryLine = (_HistoryLine + 1) & 31;
                }while(_HistoryLine != _EditLine && (_Lines[_HistoryLine][1] == '\0'));
                if (_HistoryLine == _EditLine)
                {
                    _Lines[_EditLine][0] = ']';
                    Key.LinePos          = 1;
                }
                else
                {
                    Array.Copy(_Lines[_HistoryLine], _Lines[_EditLine], MAXCMDLINE);
                    Key.LinePos = 0;
                    while (_Lines[_EditLine][Key.LinePos] != '\0' && Key.LinePos < MAXCMDLINE)
                    {
                        Key.LinePos++;
                    }
                }
                return;
            }

            if (key == K_PGUP || key == K_MWHEELUP)
            {
                Con.BackScroll += 2;
                if (Con.BackScroll > Con.TotalLines - (Scr.vid.height >> 3) - 1)
                {
                    Con.BackScroll = Con.TotalLines - (Scr.vid.height >> 3) - 1;
                }
                return;
            }

            if (key == K_PGDN || key == K_MWHEELDOWN)
            {
                Con.BackScroll -= 2;
                if (Con.BackScroll < 0)
                {
                    Con.BackScroll = 0;
                }
                return;
            }

            if (key == K_HOME)
            {
                Con.BackScroll = Con.TotalLines - (Scr.vid.height >> 3) - 1;
                return;
            }

            if (key == K_END)
            {
                Con.BackScroll = 0;
                return;
            }

            if (key < 32 || key > 127)
            {
                return; // non printable
            }
            if (Key.LinePos < MAXCMDLINE - 1)
            {
                _Lines[_EditLine][Key.LinePos] = (char)key;
                Key.LinePos++;
                _Lines[_EditLine][Key.LinePos] = '\0';
            }
        }
Example #4
0
        // Draw_Init
        public static void Init()
        {
            for (int i = 0; i < _MenuCachePics.Length; i++)
            {
                _MenuCachePics[i] = new cachepic_t();
            }

            if (_glNoBind == null)
            {
                _glNoBind  = new Cvar("gl_nobind", "0");
                _glMaxSize = new Cvar("gl_max_size", "1024");
                _glPicMip  = new Cvar("gl_picmip", "0");
            }

            // 3dfx can only handle 256 wide textures
            string renderer = GL.GetString(StringName.Renderer);

            if (renderer.Contains("3dfx") || renderer.Contains("Glide"))
            {
                Cvar.Set("gl_max_size", "256");
            }

            Cmd.Add("gl_texturemode", TextureMode_f);

            // load the console background and the charset
            // by hand, because we need to write the version
            // string into the background before turning
            // it into a texture
            int offset = Wad.GetLumpNameOffset("conchars");

            byte[] draw_chars = Wad.Data; // draw_chars
            for (int i = 0; i < 256 * 64; i++)
            {
                if (draw_chars[offset + i] == 0)
                {
                    draw_chars[offset + i] = 255;   // proper transparent color
                }
            }

            // now turn them into textures
            _CharTexture = LoadTexture("charset", 128, 128, new ByteArraySegment(draw_chars, offset), false, true);

            byte[] buf = Common.LoadFile("gfx/conback.lmp");
            if (buf == null)
            {
                Sys.Error("Couldn't load gfx/conback.lmp");
            }

            dqpicheader_t cbHeader = Sys.BytesToStructure <dqpicheader_t>(buf, 0);

            Wad.SwapPic(cbHeader);

            // hack the version number directly into the pic
            string ver     = String.Format("(c# {0,7:F2}) {1,7:F2}", (float)QDef.CSQUAKE_VERSION, (float)QDef.VERSION);
            int    offset2 = Marshal.SizeOf(typeof(dqpicheader_t)) + 320 * 186 + 320 - 11 - 8 * ver.Length;
            int    y       = ver.Length;

            for (int x = 0; x < y; x++)
            {
                CharToConback(ver[x], new ByteArraySegment(buf, offset2 + (x << 3)), new ByteArraySegment(draw_chars, offset));
            }

            _ConBack        = new glpic_t();
            _ConBack.width  = cbHeader.width;
            _ConBack.height = cbHeader.height;
            int ncdataIndex = Marshal.SizeOf(typeof(dqpicheader_t)); // cb->data;

            SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest);

            _ConBack.texnum = LoadTexture("conback", _ConBack.width, _ConBack.height, new ByteArraySegment(buf, ncdataIndex), false, false);
            _ConBack.width  = Scr.vid.width;
            _ConBack.height = Scr.vid.height;

            // save a texture slot for translated picture
            _TranslateTexture = _TextureExtensionNumber++;

            // save slots for scraps
            _ScrapTexNum             = _TextureExtensionNumber;
            _TextureExtensionNumber += MAX_SCRAPS;

            //
            // get the other pics we need
            //
            _Disc     = PicFromWad("disc");
            _BackTile = PicFromWad("backtile");
        }
Example #5
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        = ClientActivityState.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);
        }
Example #6
0
        // Key_Init (void);
        public static void Init()
        {
            for (int i = 0; i < 32; i++)
            {
                _Lines[i]    = new char[MAXCMDLINE];
                _Lines[i][0] = ']'; // key_lines[i][0] = ']'; key_lines[i][1] = 0;
            }
            LinePos = 1;

            //
            // init ascii characters in console mode
            //
            for (int i = 32; i < 128; i++)
            {
                _ConsoleKeys[i] = true;
            }
            _ConsoleKeys[K_ENTER]      = true;
            _ConsoleKeys[K_TAB]        = true;
            _ConsoleKeys[K_LEFTARROW]  = true;
            _ConsoleKeys[K_RIGHTARROW] = true;
            _ConsoleKeys[K_UPARROW]    = true;
            _ConsoleKeys[K_DOWNARROW]  = true;
            _ConsoleKeys[K_BACKSPACE]  = true;
            _ConsoleKeys[K_PGUP]       = true;
            _ConsoleKeys[K_PGDN]       = true;
            _ConsoleKeys[K_SHIFT]      = true;
            _ConsoleKeys[K_MWHEELUP]   = true;
            _ConsoleKeys[K_MWHEELDOWN] = true;
            _ConsoleKeys['`']          = false;
            _ConsoleKeys['~']          = false;

            for (int i = 0; i < 256; i++)
            {
                _KeyShift[i] = i;
            }
            for (int i = 'a'; i <= 'z'; i++)
            {
                _KeyShift[i] = i - 'a' + 'A';
            }
            _KeyShift['1']  = '!';
            _KeyShift['2']  = '@';
            _KeyShift['3']  = '#';
            _KeyShift['4']  = '$';
            _KeyShift['5']  = '%';
            _KeyShift['6']  = '^';
            _KeyShift['7']  = '&';
            _KeyShift['8']  = '*';
            _KeyShift['9']  = '(';
            _KeyShift['0']  = ')';
            _KeyShift['-']  = '_';
            _KeyShift['=']  = '+';
            _KeyShift[',']  = '<';
            _KeyShift['.']  = '>';
            _KeyShift['/']  = '?';
            _KeyShift[';']  = ':';
            _KeyShift['\''] = '"';
            _KeyShift['[']  = '{';
            _KeyShift[']']  = '}';
            _KeyShift['`']  = '~';
            _KeyShift['\\'] = '|';

            _MenuBound[K_ESCAPE] = true;
            for (int i = 0; i < 12; i++)
            {
                _MenuBound[K_F1 + i] = true;
            }

            //
            // register our functions
            //
            Cmd.Add("bind", Bind_f);
            Cmd.Add("unbind", Unbind_f);
            Cmd.Add("unbindall", UnbindAll_f);
        }
Example #7
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 != ClientActivityState.Dedicated)
            {
                Client.EstablishConnection("local");
                Reconnect_f();
            }
        }
Example #8
0
        // VID_DescribeMode_f
        static void DescribeMode_f()
        {
            int modenum = Common.atoi(Cmd.Argv(1));

            Con.Print("{0}\n", GetExtModeDescription(modenum));
        }
Example #9
0
        /// <summary>
        /// Host_Give_f
        /// </summary>
        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;
            }
        }
Example #10
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");
        }
Example #11
0
        /// <summary>
        /// Host_Kick_f
        /// Kicks a user off of the server
        /// </summary>
        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 == ClientActivityState.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;
        }
Example #12
0
        // vcrSendMessage
        // NET_Init (void)
        public static void Init()
        {
            for (int i2 = 0; i2 < _HostCache.Length; i2++)
            {
                _HostCache[i2] = new hostcache_t();
            }

            if (_Drivers == null)
            {
                if (Common.HasParam("-playback"))
                {
                    _Drivers = new INetDriver[]
                    {
                        new NetVcr()
                    };
                }
                else
                {
                    _Drivers = new INetDriver[]
                    {
                        new NetLoop(),
                        NetDatagram.Instance
                    };
                }
            }

            if (_LanDrivers == null)
            {
                _LanDrivers = new INetLanDriver[]
                {
                    NetTcpIp.Instance
                };
            }

            if (Common.HasParam("-record"))
            {
                _IsRecording = true;
            }

            int i = Common.CheckParm("-port");

            if (i == 0)
            {
                i = Common.CheckParm("-udpport");
            }
            if (i == 0)
            {
                i = Common.CheckParm("-ipxport");
            }

            if (i > 0)
            {
                if (i < Common.Argc - 1)
                {
                    _DefHostPort = Common.atoi(Common.Argv(i + 1));
                }
                else
                {
                    Sys.Error("Net.Init: you must specify a number after -port!");
                }
            }
            HostPort = _DefHostPort;

            if (Common.HasParam("-listen") || Client.cls.state == cactive_t.ca_dedicated)
            {
                _IsListening = true;
            }
            int numsockets = Server.svs.maxclientslimit;

            if (Client.cls.state != cactive_t.ca_dedicated)
            {
                numsockets++;
            }

            _FreeSockets   = new List <qsocket_t>(numsockets);
            _ActiveSockets = new List <qsocket_t>(numsockets);

            for (i = 0; i < numsockets; i++)
            {
                _FreeSockets.Add(new qsocket_t());
            }

            SetNetTime();

            // allocate space for network message buffer
            Message = new MsgWriter(NET_MAXMESSAGE);   // SZ_Alloc (&net_message, NET_MAXMESSAGE);
            Reader  = new MsgReader(Net.Message);

            if (_MessageTimeout == null)
            {
                _MessageTimeout = new Cvar("net_messagetimeout", "300");
                _HostName       = new Cvar("hostname", "UNNAMED");
            }

            Cmd.Add("slist", Slist_f);
            Cmd.Add("listen", Listen_f);
            Cmd.Add("maxplayers", MaxPlayers_f);
            Cmd.Add("port", Port_f);

            // initialize all the drivers
            _DriverLevel = 0;
            foreach (INetDriver driver in _Drivers)
            {
                driver.Init();
                if (driver.IsInitialized && _IsListening)
                {
                    driver.Listen(true);
                }
                _DriverLevel++;
            }

            //if (*my_ipx_address)
            //    Con_DPrintf("IPX address %s\n", my_ipx_address);
            if (!String.IsNullOrEmpty(_MyTcpIpAddress))
            {
                Con.DPrint("TCP/IP address {0}\n", _MyTcpIpAddress);
            }
        }
Example #13
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 == ClientActivityState.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;
        }
Example #14
0
        static float _LastMsg;                 // static float lastmsg from CL_KeepaliveMessage


        /// <summary>
        /// CL_ParseServerMessage
        /// </summary>
        static void ParseServerMessage()
        {
            //
            // if recording demos, copy the message out
            //
            if (_ShowNet.Value == 1)
            {
                Con.Print("{0} ", Net.Message.Length);
            }
            else if (_ShowNet.Value == 2)
            {
                Con.Print("------------------\n");
            }

            Cl.onground = false;        // unless the server says otherwise

            //
            // parse the message
            //
            Net.Reader.Reset();
            int i;

            while (true)
            {
                if (Net.Reader.IsBadRead)
                {
                    Host.Error("CL_ParseServerMessage: Bad server message");
                }

                int cmd = Net.Reader.ReadByte();
                if (cmd == -1)
                {
                    ShowNet("END OF MESSAGE");
                    return;     // end of message
                }

                // if the high bit of the command byte is set, it is a fast update
                if ((cmd & 128) != 0)
                {
                    ShowNet("fast update");
                    ParseUpdate(cmd & 127);
                    continue;
                }

                ShowNet(_SvcStrings[cmd]);

                // other commands
                switch (cmd)
                {
                default:
                    Host.Error("CL_ParseServerMessage: Illegible server message\n");
                    break;

                case Protocol.svc_nop:
                    break;

                case Protocol.svc_time:
                    Cl.mtime[1] = Cl.mtime[0];
                    Cl.mtime[0] = Net.Reader.ReadFloat();
                    break;

                case Protocol.svc_clientdata:
                    i = Net.Reader.ReadShort();
                    ParseClientData(i);
                    break;

                case Protocol.svc_version:
                    i = Net.Reader.ReadLong();
                    if (i != Protocol.PROTOCOL_VERSION)
                    {
                        Host.Error("CL_ParseServerMessage: Server is protocol {0} instead of {1}\n", i, Protocol.PROTOCOL_VERSION);
                    }

                    break;

                case Protocol.svc_disconnect:
                    Host.EndGame("Server disconnected\n");
                    break;

                case Protocol.svc_print:
                    Con.Print(Net.Reader.ReadString());
                    break;

                case Protocol.svc_centerprint:
                    Scr.CenterPrint(Net.Reader.ReadString());
                    break;

                case Protocol.svc_stufftext:
                    Cbuf.AddText(Net.Reader.ReadString());
                    break;

                case Protocol.svc_damage:
                    View.ParseDamage();
                    break;

                case Protocol.svc_serverinfo:
                    ParseServerInfo();
                    Scr.vid.recalc_refdef = true;       // leave intermission full screen
                    break;

                case Protocol.svc_setangle:
                    Cl.viewangles.X = Net.Reader.ReadAngle();
                    Cl.viewangles.Y = Net.Reader.ReadAngle();
                    Cl.viewangles.Z = Net.Reader.ReadAngle();
                    break;

                case Protocol.svc_setview:
                    Cl.viewentity = Net.Reader.ReadShort();
                    break;

                case Protocol.svc_lightstyle:
                    i = Net.Reader.ReadByte();
                    if (i >= QDef.MAX_LIGHTSTYLES)
                    {
                        Sys.Error("svc_lightstyle > MAX_LIGHTSTYLES");
                    }

                    _LightStyle[i].map = Net.Reader.ReadString();
                    break;

                case Protocol.svc_sound:
                    ParseStartSoundPacket();
                    break;

                case Protocol.svc_stopsound:
                    i = Net.Reader.ReadShort();
                    Sound.StopSound(i >> 3, i & 7);
                    break;

                case Protocol.svc_updatename:
                    Sbar.Changed();
                    i = Net.Reader.ReadByte();
                    if (i >= Cl.maxclients)
                    {
                        Host.Error("CL_ParseServerMessage: svc_updatename > MAX_SCOREBOARD");
                    }

                    Cl.scores[i].name = Net.Reader.ReadString();
                    break;

                case Protocol.svc_updatefrags:
                    Sbar.Changed();
                    i = Net.Reader.ReadByte();
                    if (i >= Cl.maxclients)
                    {
                        Host.Error("CL_ParseServerMessage: svc_updatefrags > MAX_SCOREBOARD");
                    }

                    Cl.scores[i].frags = Net.Reader.ReadShort();
                    break;

                case Protocol.svc_updatecolors:
                    Sbar.Changed();
                    i = Net.Reader.ReadByte();
                    if (i >= Cl.maxclients)
                    {
                        Host.Error("CL_ParseServerMessage: svc_updatecolors > MAX_SCOREBOARD");
                    }

                    Cl.scores[i].colors = Net.Reader.ReadByte();
                    NewTranslation(i);
                    break;

                case Protocol.svc_particle:
                    Render.ParseParticleEffect();
                    break;

                case Protocol.svc_spawnbaseline:
                    i = Net.Reader.ReadShort();
                    // must use CL_EntityNum() to force cl.num_entities up
                    ParseBaseline(EntityNum(i));
                    break;

                case Protocol.svc_spawnstatic:
                    ParseStatic();
                    break;

                case Protocol.svc_temp_entity:
                    ParseTempEntity();
                    break;

                case Protocol.svc_setpause:
                {
                    Cl.paused = Net.Reader.ReadByte() != 0;

                    if (Cl.paused)
                    {
                        CDAudio.Pause();
                    }
                    else
                    {
                        CDAudio.Resume();
                    }
                }
                break;

                case Protocol.svc_signonnum:
                    i = Net.Reader.ReadByte();
                    if (i <= Cls.signon)
                    {
                        Host.Error("Received signon {0} when at {1}", i, Cls.signon);
                    }

                    Cls.signon = i;
                    SignonReply();
                    break;

                case Protocol.svc_killedmonster:
                    Cl.stats[QStats.STAT_MONSTERS]++;
                    break;

                case Protocol.svc_foundsecret:
                    Cl.stats[QStats.STAT_SECRETS]++;
                    break;

                case Protocol.svc_updatestat:
                    i = Net.Reader.ReadByte();
                    if (i < 0 || i >= QStats.MAX_CL_STATS)
                    {
                        Sys.Error("svc_updatestat: {0} is invalid", i);
                    }

                    Cl.stats[i] = Net.Reader.ReadLong();
                    break;

                case Protocol.svc_spawnstaticsound:
                    ParseStaticSound();
                    break;

                case Protocol.svc_cdtrack:
                    Cl.cdtrack   = Net.Reader.ReadByte();
                    Cl.looptrack = Net.Reader.ReadByte();
                    if ((Cls.demoplayback || Cls.demorecording) && (Cls.forcetrack != -1))
                    {
                        CDAudio.Play((byte)Cls.forcetrack, true);
                    }
                    else
                    {
                        CDAudio.Play((byte)Cl.cdtrack, true);
                    }

                    break;

                case Protocol.svc_intermission:
                    Cl.intermission       = 1;
                    Cl.completed_time     = (int)Cl.time;
                    Scr.vid.recalc_refdef = true;       // go to full screen
                    break;

                case Protocol.svc_finale:
                    Cl.intermission       = 2;
                    Cl.completed_time     = (int)Cl.time;
                    Scr.vid.recalc_refdef = true;       // go to full screen
                    Scr.CenterPrint(Net.Reader.ReadString());
                    break;

                case Protocol.svc_cutscene:
                    Cl.intermission       = 3;
                    Cl.completed_time     = (int)Cl.time;
                    Scr.vid.recalc_refdef = true;       // go to full screen
                    Scr.CenterPrint(Net.Reader.ReadString());
                    break;

                case Protocol.svc_sellscreen:
                    Cmd.ExecuteString("help", cmd_source_t.src_command);
                    break;
                }
            }
        }
Example #15
0
        /// <summary>
        /// Host_Say
        /// </summary>
        static void Say(bool teamonly)
        {
            bool fromServer = false;

            if (Cmd.Source == cmd_source_t.src_command)
            {
                if (Client.Cls.state == ClientActivityState.Dedicated)
                {
                    fromServer = true;
                    teamonly   = false;
                }
                else
                {
                    Cmd.ForwardToServer();
                    return;
                }
            }

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

            client_t save = Host.HostClient;

            string p = Cmd.Args;

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

            // turn on color set 1
            string text;

            if (!fromServer)
            {
                text = (char)1 + save.name + ": ";
            }
            else
            {
                text = (char)1 + "<" + Net.HostName + "> ";
            }

            text += p + "\n";

            for (int j = 0; j < Server.svs.maxclients; j++)
            {
                client_t client = Server.svs.clients[j];
                if (client == null || !client.active || !client.spawned)
                {
                    continue;
                }

                if (Host.TeamPlay != 0 && teamonly && client.edict.v.team != save.edict.v.team)
                {
                    continue;
                }

                Host.HostClient = client;
                Server.ClientPrint(text);
            }
            Host.HostClient = save;
        }
Example #16
0
        // VID_Init (unsigned char *palette)
        // Called at startup to set up translation tables, takes 256 8 bit RGB values
        // the palette data will go away after the call, so it must be copied off if
        // the video driver will need it again
        public static void Init(byte[] palette)
        {
            if (_glZTrick == null)
            {
                _glZTrick       = new Cvar("gl_ztrick", "1");
                _Mode           = new Cvar("vid_mode", "0", false);
                _DefaultMode    = new Cvar("_vid_default_mode", "0", true);
                _DefaultModeWin = new Cvar("_vid_default_mode_win", "3", true);
                _Wait           = new Cvar("vid_wait", "0");
                _NoPageFlip     = new Cvar("vid_nopageflip", "0", true);
                _WaitOverride   = new Cvar("_vid_wait_override", "0", true);
                _ConfigX        = new Cvar("vid_config_x", "800", true);
                _ConfigY        = new Cvar("vid_config_y", "600", true);
                _StretchBy2     = new Cvar("vid_stretch_by_2", "1", true);
                _WindowedMouse  = new Cvar("_windowed_mouse", "1", true);
            }

            Cmd.Add("vid_nummodes", NumModes_f);
            Cmd.Add("vid_describecurrentmode", DescribeCurrentMode_f);
            Cmd.Add("vid_describemode", DescribeMode_f);
            Cmd.Add("vid_describemodes", DescribeModes_f);

            DisplayDevice dev = MainForm.DisplayDevice;

            // Enumerate available modes, skip 8 bpp modes, and group by refresh rates
            List <mode_t> tmp = new List <mode_t>(dev.AvailableResolutions.Count);

            foreach (DisplayResolution res in dev.AvailableResolutions)
            {
                if (res.BitsPerPixel <= 8)
                {
                    continue;
                }

                Predicate <mode_t> SameMode = delegate(mode_t m)
                {
                    return(m.width == res.Width && m.height == res.Height && m.bpp == res.BitsPerPixel);
                };
                if (tmp.Exists(SameMode))
                {
                    continue;
                }

                mode_t mode = new mode_t();
                mode.width       = res.Width;
                mode.height      = res.Height;
                mode.bpp         = res.BitsPerPixel;
                mode.refreshRate = res.RefreshRate;
                tmp.Add(mode);
            }
            _Modes = tmp.ToArray();

            mode_t mode1 = new mode_t();

            mode1.width       = dev.Width;
            mode1.height      = dev.Height;
            mode1.bpp         = dev.BitsPerPixel;
            mode1.refreshRate = dev.RefreshRate;
            mode1.fullScreen  = true;

            int width = dev.Width, height = dev.Height;
            int i = Common.CheckParm("-width");

            if (i > 0 && i < Common.Argc - 1)
            {
                width = Common.atoi(Common.Argv(i + 1));

                foreach (DisplayResolution res in dev.AvailableResolutions)
                {
                    if (res.Width == width)
                    {
                        height = res.Height;
                        break;
                    }
                }
            }

            i = Common.CheckParm("-height");
            if (i > 0 && i < Common.Argc - 1)
            {
                height = Common.atoi(Common.Argv(i + 1));
            }

            mode1.width  = width;
            mode1.height = height;

            if (Common.HasParam("-window"))
            {
                _Windowed = true;
            }
            else
            {
                _Windowed = false;

                if (Common.HasParam("-current"))
                {
                    mode1.width  = dev.Width;
                    mode1.height = dev.Height;
                }
                else
                {
                    int bpp = mode1.bpp;
                    i = Common.CheckParm("-bpp");
                    if (i > 0 && i < Common.Argc - 1)
                    {
                        bpp = Common.atoi(Common.Argv(i + 1));
                    }
                    mode1.bpp = bpp;
                }
            }

            _IsInitialized = true;

            int i2 = Common.CheckParm("-conwidth");

            if (i2 > 0)
            {
                Scr.vid.conwidth = Common.atoi(Common.Argv(i2 + 1));
            }
            else
            {
                Scr.vid.conwidth = 640;
            }

            Scr.vid.conwidth &= 0xfff8; // make it a multiple of eight

            if (Scr.vid.conwidth < 320)
            {
                Scr.vid.conwidth = 320;
            }

            // pick a conheight that matches with correct aspect
            Scr.vid.conheight = Scr.vid.conwidth * 3 / 4;

            i2 = Common.CheckParm("-conheight");
            if (i2 > 0)
            {
                Scr.vid.conheight = Common.atoi(Common.Argv(i2 + 1));
            }

            if (Scr.vid.conheight < 200)
            {
                Scr.vid.conheight = 200;
            }

            Scr.vid.maxwarpwidth  = WARP_WIDTH;
            Scr.vid.maxwarpheight = WARP_HEIGHT;
            Scr.vid.colormap      = Host.ColorMap;
            int v = BitConverter.ToInt32(Host.ColorMap, 2048);

            Scr.vid.fullbright = 256 - Common.LittleLong(v);

            CheckGamma(palette);
            SetPalette(palette);

            mode1.fullScreen = !_Windowed;

            _DefModeNum = -1;
            for (i = 0; i < _Modes.Length; i++)
            {
                mode_t m = _Modes[i];
                if (m.width != mode1.width || m.height != mode1.height)
                {
                    continue;
                }

                _DefModeNum = i;

                if (m.bpp == mode1.bpp && m.refreshRate == mode1.refreshRate)
                {
                    break;
                }
            }
            if (_DefModeNum == -1)
            {
                _DefModeNum = 0;
            }

            SetMode(_DefModeNum, palette);

            InitOpenGL();

            Directory.CreateDirectory(Path.Combine(Common.GameDir, "glquake"));
        }
Example #17
0
        /// <summary>
        /// Host_Status_f
        /// </summary>
        static void Status_f()
        {
            bool flag = true;

            if (Cmd.Source == cmd_source_t.src_command)
            {
                if (!Server.sv.active)
                {
                    Cmd.ForwardToServer();
                    return;
                }
            }
            else
            {
                flag = false;
            }

            StringBuilder sb = new StringBuilder(256);

            sb.Append(String.Format("host:    {0}\n", Cvar.GetString("hostname")));
            sb.Append(String.Format("version: {0:F2}\n", QDef.VERSION));
            if (Net.TcpIpAvailable)
            {
                sb.Append("tcp/ip:  ");
                sb.Append(Net.MyTcpIpAddress);
                sb.Append('\n');
            }

            sb.Append("map:     ");
            sb.Append(Server.sv.name);
            sb.Append('\n');
            sb.Append(String.Format("players: {0} active ({1} max)\n\n", Net.ActiveConnections, Server.svs.maxclients));
            for (int j = 0; j < Server.svs.maxclients; j++)
            {
                client_t client = Server.svs.clients[j];
                if (!client.active)
                {
                    continue;
                }

                int seconds = (int)(Net.Time - client.netconnection.connecttime);
                int hours, minutes = seconds / 60;
                if (minutes > 0)
                {
                    seconds -= (minutes * 60);
                    hours    = minutes / 60;
                    if (hours > 0)
                    {
                        minutes -= (hours * 60);
                    }
                }
                else
                {
                    hours = 0;
                }

                sb.Append(String.Format("#{0,-2} {1,-16}  {2}  {2}:{4,2}:{5,2}",
                                        j + 1, client.name, (int)client.edict.v.frags, hours, minutes, seconds));
                sb.Append("   ");
                sb.Append(client.netconnection.address);
                sb.Append('\n');
            }

            if (flag)
            {
                Con.Print(sb.ToString());
            }
            else
            {
                Server.ClientPrint(sb.ToString());
            }
        }
Example #18
0
        }                                     // sb_lines scan lines to draw


        // Sbar_Init
        public static void Init()
        {
            for (int i = 0; i < 10; i++)
            {
                string str = i.ToString();
                _Nums[0, i] = Drawer.PicFromWad("num_" + str);
                _Nums[1, i] = Drawer.PicFromWad("anum_" + str);
            }

            _Nums[0, 10] = Drawer.PicFromWad("num_minus");
            _Nums[1, 10] = Drawer.PicFromWad("anum_minus");

            _Colon = Drawer.PicFromWad("num_colon");
            _Slash = Drawer.PicFromWad("num_slash");

            _Weapons[0, 0] = Drawer.PicFromWad("inv_shotgun");
            _Weapons[0, 1] = Drawer.PicFromWad("inv_sshotgun");
            _Weapons[0, 2] = Drawer.PicFromWad("inv_nailgun");
            _Weapons[0, 3] = Drawer.PicFromWad("inv_snailgun");
            _Weapons[0, 4] = Drawer.PicFromWad("inv_rlaunch");
            _Weapons[0, 5] = Drawer.PicFromWad("inv_srlaunch");
            _Weapons[0, 6] = Drawer.PicFromWad("inv_lightng");

            _Weapons[1, 0] = Drawer.PicFromWad("inv2_shotgun");
            _Weapons[1, 1] = Drawer.PicFromWad("inv2_sshotgun");
            _Weapons[1, 2] = Drawer.PicFromWad("inv2_nailgun");
            _Weapons[1, 3] = Drawer.PicFromWad("inv2_snailgun");
            _Weapons[1, 4] = Drawer.PicFromWad("inv2_rlaunch");
            _Weapons[1, 5] = Drawer.PicFromWad("inv2_srlaunch");
            _Weapons[1, 6] = Drawer.PicFromWad("inv2_lightng");

            for (int i = 0; i < 5; i++)
            {
                string s = "inva" + (i + 1).ToString();
                _Weapons[2 + i, 0] = Drawer.PicFromWad(s + "_shotgun");
                _Weapons[2 + i, 1] = Drawer.PicFromWad(s + "_sshotgun");
                _Weapons[2 + i, 2] = Drawer.PicFromWad(s + "_nailgun");
                _Weapons[2 + i, 3] = Drawer.PicFromWad(s + "_snailgun");
                _Weapons[2 + i, 4] = Drawer.PicFromWad(s + "_rlaunch");
                _Weapons[2 + i, 5] = Drawer.PicFromWad(s + "_srlaunch");
                _Weapons[2 + i, 6] = Drawer.PicFromWad(s + "_lightng");
            }

            _Ammo[0] = Drawer.PicFromWad("sb_shells");
            _Ammo[1] = Drawer.PicFromWad("sb_nails");
            _Ammo[2] = Drawer.PicFromWad("sb_rocket");
            _Ammo[3] = Drawer.PicFromWad("sb_cells");

            _Armor[0] = Drawer.PicFromWad("sb_armor1");
            _Armor[1] = Drawer.PicFromWad("sb_armor2");
            _Armor[2] = Drawer.PicFromWad("sb_armor3");

            _Items[0] = Drawer.PicFromWad("sb_key1");
            _Items[1] = Drawer.PicFromWad("sb_key2");
            _Items[2] = Drawer.PicFromWad("sb_invis");
            _Items[3] = Drawer.PicFromWad("sb_invuln");
            _Items[4] = Drawer.PicFromWad("sb_suit");
            _Items[5] = Drawer.PicFromWad("sb_quad");

            _Sigil[0] = Drawer.PicFromWad("sb_sigil1");
            _Sigil[1] = Drawer.PicFromWad("sb_sigil2");
            _Sigil[2] = Drawer.PicFromWad("sb_sigil3");
            _Sigil[3] = Drawer.PicFromWad("sb_sigil4");

            _Faces[4, 0] = Drawer.PicFromWad("face1");
            _Faces[4, 1] = Drawer.PicFromWad("face_p1");
            _Faces[3, 0] = Drawer.PicFromWad("face2");
            _Faces[3, 1] = Drawer.PicFromWad("face_p2");
            _Faces[2, 0] = Drawer.PicFromWad("face3");
            _Faces[2, 1] = Drawer.PicFromWad("face_p3");
            _Faces[1, 0] = Drawer.PicFromWad("face4");
            _Faces[1, 1] = Drawer.PicFromWad("face_p4");
            _Faces[0, 0] = Drawer.PicFromWad("face5");
            _Faces[0, 1] = Drawer.PicFromWad("face_p5");

            _FaceInvis       = Drawer.PicFromWad("face_invis");
            _FaceInvuln      = Drawer.PicFromWad("face_invul2");
            _FaceInvisInvuln = Drawer.PicFromWad("face_inv2");
            _FaceQuad        = Drawer.PicFromWad("face_quad");

            Cmd.Add("+showscores", ShowScores);
            Cmd.Add("-showscores", DontShowScores);

            _SBar     = Drawer.PicFromWad("sbar");
            _IBar     = Drawer.PicFromWad("ibar");
            _ScoreBar = Drawer.PicFromWad("scorebar");

            //MED 01/04/97 added new hipnotic weapons
            if (Common.GameKind == GameKind.Hipnotic)
            {
                _HWeapons[0, 0] = Drawer.PicFromWad("inv_laser");
                _HWeapons[0, 1] = Drawer.PicFromWad("inv_mjolnir");
                _HWeapons[0, 2] = Drawer.PicFromWad("inv_gren_prox");
                _HWeapons[0, 3] = Drawer.PicFromWad("inv_prox_gren");
                _HWeapons[0, 4] = Drawer.PicFromWad("inv_prox");

                _HWeapons[1, 0] = Drawer.PicFromWad("inv2_laser");
                _HWeapons[1, 1] = Drawer.PicFromWad("inv2_mjolnir");
                _HWeapons[1, 2] = Drawer.PicFromWad("inv2_gren_prox");
                _HWeapons[1, 3] = Drawer.PicFromWad("inv2_prox_gren");
                _HWeapons[1, 4] = Drawer.PicFromWad("inv2_prox");

                for (int i = 0; i < 5; i++)
                {
                    string s = "inva" + (i + 1).ToString();
                    _HWeapons[2 + i, 0] = Drawer.PicFromWad(s + "_laser");
                    _HWeapons[2 + i, 1] = Drawer.PicFromWad(s + "_mjolnir");
                    _HWeapons[2 + i, 2] = Drawer.PicFromWad(s + "_gren_prox");
                    _HWeapons[2 + i, 3] = Drawer.PicFromWad(s + "_prox_gren");
                    _HWeapons[2 + i, 4] = Drawer.PicFromWad(s + "_prox");
                }

                _HItems[0] = Drawer.PicFromWad("sb_wsuit");
                _HItems[1] = Drawer.PicFromWad("sb_eshld");
            }

            if (Common.GameKind == GameKind.Rogue)
            {
                _RInvBar[0] = Drawer.PicFromWad("r_invbar1");
                _RInvBar[1] = Drawer.PicFromWad("r_invbar2");

                _RWeapons[0] = Drawer.PicFromWad("r_lava");
                _RWeapons[1] = Drawer.PicFromWad("r_superlava");
                _RWeapons[2] = Drawer.PicFromWad("r_gren");
                _RWeapons[3] = Drawer.PicFromWad("r_multirock");
                _RWeapons[4] = Drawer.PicFromWad("r_plasma");

                _RItems[0] = Drawer.PicFromWad("r_shield1");
                _RItems[1] = Drawer.PicFromWad("r_agrav1");

                // PGM 01/19/97 - team color border
                _RTeamBord = Drawer.PicFromWad("r_teambord");
                // PGM 01/19/97 - team color border

                _RAmmo[0] = Drawer.PicFromWad("r_ammolava");
                _RAmmo[1] = Drawer.PicFromWad("r_ammomulti");
                _RAmmo[2] = Drawer.PicFromWad("r_ammoplasma");
            }
        }
Example #19
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;
            }
        }