Beispiel #1
0
 static void ShowNet(string s)
 {
     if (_ShowNet.Value == 2)
     {
         Con.Print("{0,3}:{1}\n", Net.Reader.Position - 1, s);
     }
 }
Beispiel #2
0
        static void Test5_f()
        {
            entity_t p = Client.ViewEntity;

            if (p == null)
            {
                return;
            }

            OpenTK.Vector3 org = p.origin;

            for (int i = 0; i < Server.sv.edicts.Length; i++)
            {
                edict_t ed = Server.sv.edicts[i];

                if (ed.free)
                {
                    continue;
                }

                OpenTK.Vector3 vmin, vmax;
                Mathlib.Copy(ref ed.v.absmax, out vmax);
                Mathlib.Copy(ref ed.v.absmin, out vmin);

                if (org.X >= vmin.X && org.Y >= vmin.Y && org.Z >= vmin.Z &&
                    org.X <= vmax.X && org.Y <= vmax.Y && org.Z <= vmax.Z)
                {
                    Con.Print("{0}\n", i);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// NET_SendUnreliableMessage
        /// returns 0 if the message connot be delivered reliably, but the connection
        ///		is still considered valid
        /// returns 1 if the message was sent properly
        /// returns -1 if the connection died
        /// </summary>
        public static int SendUnreliableMessage(qsocket_t sock, MsgWriter data)
        {
            if (sock == null)
            {
                return(-1);
            }

            if (sock.disconnected)
            {
                Con.Print("NET_SendMessage: disconnected socket\n");
                return(-1);
            }

            SetNetTime();

            int r = _Drivers[sock.driver].SendUnreliableMessage(sock, data);

            if (r == 1 && sock.driver != 0)
            {
                _UnreliableMessagesSent++;
            }

            if (_IsRecording)
            {
                _VcrSendMessage.time    = Host.Time;
                _VcrSendMessage.op      = VcrOp.VCR_OP_SENDMESSAGE;
                _VcrSendMessage.session = 1;// (long)sock; Uze todo: ???????
                _VcrSendMessage.ret     = r;
                byte[] buf = Sys.StructureToBytes(ref _VcrSendMessage);
                Host.VcrWriter.Write(buf);
            }

            return(r);
        }
Beispiel #4
0
        // S_SoundList
        static void SoundList()
        {
            int total = 0;

            for (int i = 0; i < _NumSfx; i++)
            {
                sfx_t      sfx = _KnownSfx[i];
                sfxcache_t sc  = (sfxcache_t)Cache.Check(sfx.cache);
                if (sc == null)
                {
                    continue;
                }

                int size = sc.length * sc.width * (sc.stereo + 1);
                total += size;
                if (sc.loopstart >= 0)
                {
                    Con.Print("L");
                }
                else
                {
                    Con.Print(" ");
                }
                Con.Print("({0:d2}b) {1:g6} : {2}\n", sc.width * 8, size, sfx.name);
            }
            Con.Print("Total resident: {0}\n", total);
        }
Beispiel #5
0
        // ED_Count
        //
        // For debugging
        static void EdictCount()
        {
            int active = 0, models = 0, solid = 0, step = 0;

            for (int i = 0; i < Server.sv.num_edicts; i++)
            {
                edict_t ent = Server.EdictNum(i);
                if (ent.free)
                {
                    continue;
                }
                active++;
                if (ent.v.solid != 0)
                {
                    solid++;
                }
                if (ent.v.model != 0)
                {
                    models++;
                }
                if (ent.v.movetype == Movetypes.MOVETYPE_STEP)
                {
                    step++;
                }
            }

            Con.Print("num_edicts:{0}\n", Server.sv.num_edicts);
            Con.Print("active    :{0}\n", active);
            Con.Print("view      :{0}\n", models);
            Con.Print("touch     :{0}\n", solid);
            Con.Print("step      :{0}\n", step);
        }
Beispiel #6
0
        // Con_Init (void)
        public static void Init()
        {
            _DebugLog = (Common.CheckParm("-condebug") > 0);
            if (_DebugLog)
            {
                string path = Path.Combine(Common.GameDir, LOG_FILE_NAME);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                _Log = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
            }

            _LineWidth = -1;
            CheckResize();

            Con.Print("Console initialized.\n");

            //
            // register our commands
            //
            if (_NotifyTime == null)
            {
                _NotifyTime = new Cvar("con_notifytime", "3");
            }

            Cmd.Add("toggleconsole", ToggleConsole_f);
            Cmd.Add("messagemode", MessageMode_f);
            Cmd.Add("messagemode2", MessageMode2_f);
            Cmd.Add("clear", Clear_f);

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

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

            writer.WriteByte(Protocol.clc_stringcmd);
            if (!Cmd.Argv(0).Equals("cmd"))
            {
                writer.Print(Cmd.Argv(0) + " ");
            }
            if (Cmd.Argc > 1)
            {
                writer.Print(Cmd.Args);
            }
            else
            {
                writer.Print("\n");
            }
        }
Beispiel #8
0
        // PR_Profile_f
        static void Profile_f()
        {
            if (_Functions == null)
            {
                return;
            }

            dfunction_t best;
            int         num = 0;

            do
            {
                int max = 0;
                best = null;
                for (int i = 0; i < _Functions.Length; i++)
                {
                    dfunction_t f = _Functions[i];
                    if (f.profile > max)
                    {
                        max  = f.profile;
                        best = f;
                    }
                }
                if (best != null)
                {
                    if (num < 10)
                    {
                        Con.Print("{0,7} {1}\n", best.profile, GetString(best.s_name));
                    }
                    num++;
                    best.profile = 0;
                }
            } while (best != null);
        }
Beispiel #9
0
        // Cmd_Alias_f
        // Creates a new command that executes a command string (possibly ; seperated)
        static void Alias_f()
        {
            if (_Argc == 1)
            {
                Con.Print("Current alias commands:\n");
                foreach (KeyValuePair <string, string> alias in _Aliases)
                {
                    Con.Print("{0} : {1}\n", alias.Key, alias.Value);
                }
                return;
            }

            string name = _Argv[1];

            if (name.Length >= MAX_ALIAS_NAME)
            {
                Con.Print("Alias name is too long\n");
                return;
            }

            // copy the rest of the command line
            StringBuilder sb = new StringBuilder(1024);

            for (int i = 2; i < _Argc; i++)
            {
                sb.Append(_Argv[i]);
                if (i + 1 < _Argc)
                {
                    sb.Append(" ");
                }
            }
            sb.AppendLine();
            _Aliases[name] = sb.ToString();
        }
Beispiel #10
0
        /// <summary>
        /// CL_Stop_f
        /// stop recording a demo
        /// </summary>
        static void Stop_f()
        {
            if (Cmd.Source != cmd_source_t.src_command)
            {
                return;
            }

            if (!cls.demorecording)
            {
                Con.Print("Not recording a demo.\n");
                return;
            }

            // write a disconnect message to the demo file
            Net.Message.Clear();
            Net.Message.WriteByte(Protocol.svc_disconnect);
            WriteDemoMessage();

            // finish up
            if (cls.demofile != null)
            {
                cls.demofile.Dispose();
                cls.demofile = null;
            }
            cls.demorecording = false;
            Con.Print("Completed demo\n");
        }
Beispiel #11
0
        /// <summary>
        /// Host_Error
        /// This shuts down both the client and server
        /// </summary>
        public static void Error(string error, params object[] args)
        {
            _ErrorDepth++;
            try
            {
                if (_ErrorDepth > 1)
                {
                    Sys.Error("Host_Error: recursively entered. " + error, args);
                }

                Scr.EndLoadingPlaque();         // reenable screen updates

                string message = (args.Length > 0 ? String.Format(error, args) : error);
                Con.Print("Host_Error: {0}\n", message);

                if (Server.sv.active)
                {
                    ShutdownServer(false);
                }

                if (Client.cls.state == cactive_t.ca_dedicated)
                {
                    Sys.Error("Host_Error: {0}\n", message);    // dedicated servers exit
                }
                Client.Disconnect();
                Client.cls.demonum = -1;

                throw new EndGameException(); // longjmp (host_abortserver, 1);
            }
            finally
            {
                _ErrorDepth--;
            }
        }
Beispiel #12
0
 // VID_DescribeModes_f
 static void DescribeModes_f()
 {
     for (int i = 0; i < _Modes.Length; i++)
     {
         Con.Print("{0}:{1}\n", i, GetExtModeDescription(i));
     }
 }
Beispiel #13
0
        // Host_Startdemos_f
        static void Startdemos_f()
        {
            if (Client.cls.state == cactive_t.ca_dedicated)
            {
                if (!Server.sv.active)
                {
                    Cbuf.AddText("map start\n");
                }
                return;
            }

            int c = Cmd.Argc - 1;

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

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

            if (!Server.sv.active && Client.cls.demonum != -1 && !Client.cls.demoplayback)
            {
                Client.cls.demonum = 0;
                Client.NextDemo();
            }
            else
            {
                Client.cls.demonum = -1;
            }
        }
Beispiel #14
0
        /// <summary>
        /// CL_KeepaliveMessage
        /// When the client is taking a long time to load stuff, send keepalive messages
        /// so the server doesn't disconnect.
        /// </summary>
        static void KeepaliveMessage()
        {
            if (Server.IsActive)
            {
                return; // no need if server is local
            }
            if (cls.demoplayback)
            {
                return;
            }

            // read messages from server, should just be nops
            Net.Message.SaveState(ref _MsgState);

            int ret;

            do
            {
                ret = GetMessage();
                switch (ret)
                {
                default:
                    Host.Error("CL_KeepaliveMessage: CL_GetMessage failed");
                    break;

                case 0:
                    break;      // nothing waiting

                case 1:
                    Host.Error("CL_KeepaliveMessage: received a message");
                    break;

                case 2:
                    if (Net.Reader.ReadByte() != Protocol.svc_nop)
                    {
                        Host.Error("CL_KeepaliveMessage: datagram wasn't a nop");
                    }
                    break;
                }
            } while (ret != 0);

            Net.Message.RestoreState(_MsgState);

            // check time
            float time = (float)Sys.GetFloatTime();

            if (time - _LastMsg < 5)
            {
                return;
            }

            _LastMsg = time;

            // write out a nop
            Con.Print("--> client to server keepalive\n");

            cls.message.WriteByte(Protocol.clc_nop);
            Net.SendMessage(cls.netcon, cls.message);
            cls.message.Clear();
        }
Beispiel #15
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");
            }
        }
Beispiel #16
0
        // SCR_ScreenShot_f
        static void ScreenShot_f()
        {
            //
            // find a file name to save it to
            //
            string path = null;
            int    i;

            for (i = 0; i <= 999; i++)
            {
                path = Path.Combine(Common.GameDir, String.Format("quake{0:D3}.tga", i));
                if (Sys.GetFileTime(path) == DateTime.MinValue)
                {
                    break;      // file doesn't exist
                }
            }
            if (i == 100)
            {
                Con.Print("SCR_ScreenShot_f: Couldn't create a file\n");
                return;
            }

            FileStream fs = Sys.FileOpenWrite(path, true);

            if (fs == null)
            {
                Con.Print("SCR_ScreenShot_f: Couldn't create a file\n");
                return;
            }
            using (BinaryWriter writer = new BinaryWriter(fs))
            {
                // Write tga header (18 bytes)
                writer.Write((ushort)0);
                writer.Write((byte)2); //buffer[2] = 2; uncompressed type
                writer.Write((byte)0);
                writer.Write((uint)0);
                writer.Write((uint)0);
                writer.Write((byte)(glWidth & 0xff));
                writer.Write((byte)(glWidth >> 8));
                writer.Write((byte)(glHeight & 0xff));
                writer.Write((byte)(glHeight >> 8));
                writer.Write((byte)24); // pixel size
                writer.Write((ushort)0);

                byte[] buffer = new byte[glWidth * glHeight * 3];
                GL.ReadPixels(glX, glY, glWidth, glHeight, PixelFormat.Rgb, PixelType.UnsignedByte, buffer);

                // swap 012 to 102
                int c = glWidth * glHeight * 3;
                for (i = 0; i < c; i += 3)
                {
                    byte temp = buffer[i + 0];
                    buffer[i + 0] = buffer[i + 1];
                    buffer[i + 1] = temp;
                }
                writer.Write(buffer, 0, buffer.Length);
            }
            Con.Print("Wrote {0}\n", Path.GetFileName(path));
        }
Beispiel #17
0
 /// <summary>
 /// CheckMultiTextureExtensions
 /// </summary>
 static void CheckMultiTextureExtensions()
 {
     if (_glExtensions.Contains("GL_SGIS_multitexture ") && !Common.HasParam("-nomtex"))
     {
         Con.Print("Multitexture extensions found.\n");
         _glMTexable = true;
     }
 }
Beispiel #18
0
 // Cmd_Echo_f
 // Just prints the rest of the line to the console
 static void Echo_f()
 {
     for (int i = 1; i < _Argc; i++)
     {
         Con.Print("{0} ", _Argv[i]);
     }
     Con.Print("\n");
 }
Beispiel #19
0
 // ED_PrintEdicts
 //
 // For debugging, prints all the entities in the current server
 public static void PrintEdicts()
 {
     Con.Print("{0} entities\n", Server.sv.num_edicts);
     for (int i = 0; i < Server.sv.num_edicts; i++)
     {
         PrintNum(i);
     }
 }
Beispiel #20
0
        // Host_Name_f
        static void Name_f()
        {
            if (Cmd.Argc == 1)
            {
                Con.Print("\"name\" is \"{0}\"\n", Client.Name);
                return;
            }

            string newName;

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

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

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

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

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

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

            msg.WriteByte(Protocol.svc_updatename);
            msg.WriteByte(Host.ClientNum);
            msg.WriteString(newName);
        }
Beispiel #21
0
        // Host_Begin_f
        static void Begin_f()
        {
            if (Cmd.Source == cmd_source_t.src_command)
            {
                Con.Print("begin is not valid from the console\n");
                return;
            }

            Host.HostClient.spawned = true;
        }
Beispiel #22
0
        /// <summary>
        /// PR_RunError
        /// Aborts the currently executing function
        /// </summary>
        public static void RunError(string fmt, params object[] args)
        {
            PrintStatement(ref _Statements[_xStatement]);
            StackTrace();
            Con.Print(fmt, args);

            _Depth = 0;         // dump the stack so host_error can shutdown functions

            Host.Error("Program error");
        }
Beispiel #23
0
        // Host_Color_f
        static void Color_f()
        {
            if (Cmd.Argc == 1)
            {
                Con.Print("\"color\" is \"{0} {1}\"\n", ((int)Client.Color) >> 4, ((int)Client.Color) & 0x0f);
                Con.Print("color <0-13> [0-13]\n");
                return;
            }

            int top, bottom;

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

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

            int playercolor = top * 16 + bottom;

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


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

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

            msg.WriteByte(Protocol.svc_updatecolors);
            msg.WriteByte(Host.ClientNum);
            msg.WriteByte(Host.HostClient.colors);
        }
Beispiel #24
0
        /// <summary>
        /// PF_errror
        /// This is a TERMINAL error, which will kill off the entire server.
        /// Dumps self.
        /// error(value)
        /// </summary>
        static void PF_error()
        {
            string s = PF_VarString(0);

            Con.Print("======SERVER ERROR in {0}:\n{1}\n",
                      Progs.GetString(Progs.xFunction.s_name), s);
            edict_t ed = Server.ProgToEdict(Progs.GlobalStruct.self);

            Progs.Print(ed);
            Host.Error("Program error");
        }
Beispiel #25
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);
        }
Beispiel #26
0
 static void PrintSlistTrailer()
 {
     if (HostCacheCount != 0)
     {
         Con.Print("== end list ==\n\n");
     }
     else
     {
         Con.Print("No Quake servers found.\n\n");
     }
 }
Beispiel #27
0
        static void PrintFrameName(model_t m, int frame)
        {
            aliashdr_t hdr = Mod.GetExtraData(m);

            if (hdr == null)
            {
                return;
            }

            Con.Print("frame {0}: {1}\n", frame, hdr.frames[frame].name);
        }
Beispiel #28
0
        // Cvar_Set()
        public static void Set(string name, string value)
        {
            Cvar var = Find(name);

            if (var == null)
            {
                // there is an error in C code if this happens
                Con.Print("Cvar.Set: variable {0} not found\n", name);
                return;
            }
            var.Set(value);
        }
Beispiel #29
0
        /// <summary>
        /// ED_Print
        /// For debugging
        /// </summary>
        public unsafe static void Print(edict_t ed)
        {
            if (ed.free)
            {
                Con.Print("FREE\n");
                return;
            }

            Con.Print("\nEDICT {0}:\n", Server.NumForEdict(ed));
            for (int i = 1; i < _Progs.numfielddefs; i++)
            {
                ddef_t d    = _FieldDefs[i];
                string name = GetString(d.s_name);

                if (name.Length > 2 && name[name.Length - 2] == '_')
                {
                    continue; // skip _x, _y, _z vars
                }
                int type = d.type & ~DEF_SAVEGLOBAL;
                int offset;
                if (ed.IsV(d.ofs, out offset))
                {
                    fixed(void *ptr = &ed.v)
                    {
                        int *v = (int *)ptr + offset;

                        if (IsEmptyField(type, v))
                        {
                            continue;
                        }

                        Con.Print("{0,15} ", name);
                        Con.Print("{0}\n", ValueString((etype_t)d.type, (void *)v));
                    }
                }
                else
                {
                    fixed(void *ptr = ed.fields)
                    {
                        int *v = (int *)ptr + offset;

                        if (IsEmptyField(type, v))
                        {
                            continue;
                        }

                        Con.Print("{0,15} ", name);
                        Con.Print("{0}\n", ValueString((etype_t)d.type, (void *)v));
                    }
                }
            }
        }
Beispiel #30
0
        // VID_NumModes_f
        static void NumModes_f()
        {
            int nummodes = _Modes.Length;

            if (nummodes == 1)
            {
                Con.Print("{0} video mode is available\n", nummodes);
            }
            else
            {
                Con.Print("{0} video modes are available\n", nummodes);
            }
        }