Exemple #1
0
        public static void SV_BroadcastPrintf(Int32 level, String s)
        {
            client_t cl;

            if (Globals.dedicated.value != 0)
            {
                Com.Printf(s);
            }

            for (var i = 0; i < SV_MAIN.maxclients.value; i++)
            {
                cl = SV_INIT.svs.clients[i];
                if (level < cl.messagelevel)
                {
                    continue;
                }
                if (cl.state != Defines.cs_spawned)
                {
                    continue;
                }
                MSG.WriteByte(cl.netchan.message, Defines.svc_print);
                MSG.WriteByte(cl.netchan.message, level);
                MSG.WriteString(cl.netchan.message, s);
            }
        }
Exemple #2
0
            public override void Execute( )
            {
                String filename;

                if (Cmd.Argc() != 2)
                {
                    Com.Printf("Usage: download <filename>\\n");
                    return;
                }

                filename = Cmd.Argv(1);
                if (filename.IndexOf("..") != -1)
                {
                    Com.Printf("Refusing to download a path with ..\\n");
                    return;
                }

                if (FS.LoadFile(filename) != null)
                {
                    Com.Printf("File already exists.\\n");
                    return;
                }

                Globals.cls.downloadname = filename;
                Com.Printf("Downloading " + Globals.cls.downloadname + "\\n");
                Globals.cls.downloadtempname  = Com.StripExtension(Globals.cls.downloadname);
                Globals.cls.downloadtempname += ".tmp";
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
                MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname);
                Globals.cls.downloadnumber++;
            }
Exemple #3
0
        public static void SV_FinalMessage(String message, Boolean reconnect)
        {
            Int32    i;
            client_t cl;

            SZ.Clear(Globals.net_message);
            MSG.WriteByte(Globals.net_message, Defines.svc_print);
            MSG.WriteByte(Globals.net_message, Defines.PRINT_HIGH);
            MSG.WriteString(Globals.net_message, message);
            if (reconnect)
            {
                MSG.WriteByte(Globals.net_message, Defines.svc_reconnect);
            }
            else
            {
                MSG.WriteByte(Globals.net_message, Defines.svc_disconnect);
            }
            for (i = 0; i < SV_INIT.svs.clients.Length; i++)
            {
                cl = SV_INIT.svs.clients[i];
                if (cl.state >= Defines.cs_connected)
                {
                    Netchan.Transmit(cl.netchan, Globals.net_message.cursize, Globals.net_message.data);
                }
            }

            for (i = 0; i < SV_INIT.svs.clients.Length; i++)
            {
                cl = SV_INIT.svs.clients[i];
                if (cl.state >= Defines.cs_connected)
                {
                    Netchan.Transmit(cl.netchan, Globals.net_message.cursize, Globals.net_message.data);
                }
            }
        }
Exemple #4
0
        public static void SV_NextDownload_f( )
        {
            Int32 r;
            Int32 percent;
            Int32 size;

            if (SV_MAIN.sv_client.download == null)
            {
                return;
            }
            r = SV_MAIN.sv_client.downloadsize - SV_MAIN.sv_client.downloadcount;
            if (r > 1024)
            {
                r = 1024;
            }
            MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_download);
            MSG.WriteShort(SV_MAIN.sv_client.netchan.message, r);
            SV_MAIN.sv_client.downloadcount += r;
            size = SV_MAIN.sv_client.downloadsize;
            if (size == 0)
            {
                size = 1;
            }
            percent = SV_MAIN.sv_client.downloadcount * 100 / size;
            MSG.WriteByte(SV_MAIN.sv_client.netchan.message, percent);
            SZ.Write(SV_MAIN.sv_client.netchan.message, SV_MAIN.sv_client.download, SV_MAIN.sv_client.downloadcount - r, r);
            if (SV_MAIN.sv_client.downloadcount != SV_MAIN.sv_client.downloadsize)
            {
                return;
            }
            FS.FreeFile(SV_MAIN.sv_client.download);
            SV_MAIN.sv_client.download = null;
        }
Exemple #5
0
        public static void SV_WriteFrameToClient(client_t client, sizebuf_t msg)
        {
            client_frame_t frame, oldframe;
            Int32          lastframe;

            frame = client.frames[SV_INIT.sv.framenum & Defines.UPDATE_MASK];
            if (client.lastframe <= 0)
            {
                oldframe  = null;
                lastframe = -1;
            }
            else if (SV_INIT.sv.framenum - client.lastframe >= (Defines.UPDATE_BACKUP - 3))
            {
                oldframe  = null;
                lastframe = -1;
            }
            else
            {
                oldframe  = client.frames[client.lastframe & Defines.UPDATE_MASK];
                lastframe = client.lastframe;
            }

            MSG.WriteByte(msg, Defines.svc_frame);
            MSG.WriteLong(msg, SV_INIT.sv.framenum);
            MSG.WriteLong(msg, lastframe);
            MSG.WriteByte(msg, client.surpressCount);
            client.surpressCount = 0;
            MSG.WriteByte(msg, frame.areabytes);
            SZ.Write(msg, frame.areabits, frame.areabytes);
            SV_WritePlayerstateToClient(oldframe, frame, msg);
            SV_EmitPacketEntities(oldframe, frame, msg);
        }
Exemple #6
0
        /**
         * Save everything in the world out without deltas. Used for recording
         * footage for merged or assembled demos.
         */
        public static void SV_RecordDemoMessage()
        {
            if (SV_INIT.svs.demofile == null)
            {
                return;
            }

            //memset (nostate, 0, sizeof(nostate));
            entity_state_t nostate = new(null);
            sizebuf_t      buf     = new();

            SZ.Init(buf, SV_ENTS.buf_data, SV_ENTS.buf_data.Length);

            // write a frame message that doesn't contain a player_state_t
            MSG.WriteByte(buf, Defines.svc_frame);
            MSG.WriteLong(buf, SV_INIT.sv.framenum);

            MSG.WriteByte(buf, Defines.svc_packetentities);

            var e   = 1;
            var ent = GameBase.g_edicts[e];

            while (e < GameBase.num_edicts)
            {
                // ignore ents without visible models unless they have an effect
                if (ent.inuse &&
                    ent.s.number != 0 &&
                    (ent.s.modelindex != 0 || ent.s.effects != 0 || ent.s.sound != 0 || ent.s.@event != 0) &&
                    0 == (ent.svflags & Defines.SVF_NOCLIENT))
                {
                    MSG.WriteDeltaEntity(nostate, ent.s, buf, false, true);
                }

                e++;
                ent = GameBase.g_edicts[e];
            }

            MSG.WriteShort(buf, 0);             // end of packetentities

            // now add the accumulated multicast information
            SZ.Write(buf, SV_INIT.svs.demo_multicast.data, SV_INIT.svs.demo_multicast.cursize);
            SZ.Clear(SV_INIT.svs.demo_multicast);

            // now write the entire message to the file, prefixed by the length
            var len = EndianHandler.swapInt(buf.cursize);

            try
            {
                //fwrite (len, 4, 1, svs.demofile);
                SV_INIT.svs.demofile.Write(len);

                //fwrite (buf.data, buf.cursize, 1, svs.demofile);
                SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize);
            }
            catch (Exception)
            {
                Com.Printf("Error writing demo file:" + e);
            }
        }
Exemple #7
0
 public static void SV_ClientPrintf(client_t cl, Int32 level, String s)
 {
     if (level < cl.messagelevel)
     {
         return;
     }
     MSG.WriteByte(cl.netchan.message, Defines.svc_print);
     MSG.WriteByte(cl.netchan.message, level);
     MSG.WriteString(cl.netchan.message, s);
 }
Exemple #8
0
 public static void SV_BroadcastCommand(String s)
 {
     if (SV_INIT.sv.state == 0)
     {
         return;
     }
     MSG.WriteByte(SV_INIT.sv.multicast, Defines.svc_stufftext);
     MSG.WriteString(SV_INIT.sv.multicast, s);
     SV_Multicast(null, Defines.MULTICAST_ALL_R);
 }
Exemple #9
0
        public static void SV_BeginDownload_f( )
        {
            String name;
            var    offset = 0;

            name = Cmd.Argv(1);
            if (Cmd.Argc() > 2)
            {
                offset = Lib.Atoi(Cmd.Argv(2));
            }
            if (name.IndexOf("..") != -1 || SV_MAIN.allow_download.value == 0 || name[0] == '.' || name[0] == '/' || (name.StartsWith("players/") && 0 == SV_MAIN.allow_download_players.value) || (name.StartsWith("models/") && 0 == SV_MAIN.allow_download_models.value) || (name.StartsWith("sound/") && 0 == SV_MAIN.allow_download_sounds.value) || (name.StartsWith("maps/") && 0 == SV_MAIN.allow_download_maps.value) || name.IndexOf('/') == -1)
            {
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_download);
                MSG.WriteShort(SV_MAIN.sv_client.netchan.message, -1);
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, 0);
                return;
            }

            if (SV_MAIN.sv_client.download != null)
            {
                FS.FreeFile(SV_MAIN.sv_client.download);
            }
            SV_MAIN.sv_client.download = FS.LoadFile(name);
            if (SV_MAIN.sv_client.download == null)
            {
                return;
            }

            SV_MAIN.sv_client.downloadsize  = SV_MAIN.sv_client.download.Length;
            SV_MAIN.sv_client.downloadcount = offset;
            if (offset > SV_MAIN.sv_client.downloadsize)
            {
                SV_MAIN.sv_client.downloadcount = SV_MAIN.sv_client.downloadsize;
            }
            if (SV_MAIN.sv_client.download == null || (name.StartsWith("maps/") && FS.file_from_pak != 0))
            {
                Com.DPrintf("Couldn't download " + name + " to " + SV_MAIN.sv_client.name + "\\n");
                if (SV_MAIN.sv_client.download != null)
                {
                    FS.FreeFile(SV_MAIN.sv_client.download);
                    SV_MAIN.sv_client.download = null;
                }

                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_download);
                MSG.WriteShort(SV_MAIN.sv_client.netchan.message, -1);
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, 0);
                return;
            }

            SV_NextDownload_f();
            Com.DPrintf("Downloading " + name + " to " + SV_MAIN.sv_client.name + "\\n");
        }
Exemple #10
0
        public static void PF_centerprintf(edict_t ent, string fmt)
        {
            int n;

            n = ent.index;
            if (n < 1 || n > SV_MAIN.maxclients.value)
            {
                return;
            }
            MSG.WriteByte(SV_INIT.sv.multicast, Defines.svc_centerprint);
            MSG.WriteString(SV_INIT.sv.multicast, fmt);
            PF_Unicast(ent, true);
        }
Exemple #11
0
        /**
         * PF_centerprintf
         *
         * centerprint to a single client.
         */
        public static void PF_centerprintf(edict_t ent, string fmt)
        {
            int n;

            n = ent.index;

            if (n < 1 || n > SV_MAIN.maxclients.value)
            {
                return;                 // Com_Error (ERR_DROP, "centerprintf to a non-client");
            }
            MSG.WriteByte(SV_INIT.sv.multicast, Defines.svc_centerprint);
            MSG.WriteString(SV_INIT.sv.multicast, fmt);
            SV_GAME.PF_Unicast(ent, true);
        }
Exemple #12
0
 public static void SV_FlushRedirect(Int32 sv_redirected, Byte[] outputbuf)
 {
     if (sv_redirected == Defines.RD_PACKET)
     {
         var s = ("print\\n" + Lib.CtoJava(outputbuf));
         Netchan.Netchan_OutOfBand(Defines.NS_SERVER, Globals.net_from, s.Length, Lib.StringToBytes(s));
     }
     else if (sv_redirected == Defines.RD_CLIENT)
     {
         MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_print);
         MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.PRINT_HIGH);
         MSG.WriteString(SV_MAIN.sv_client.netchan.message, outputbuf);
     }
 }
Exemple #13
0
        /**
         * Writes a frame to a client system.
         */
        public static void SV_WriteFrameToClient(client_t client, sizebuf_t msg)
        {
            //ptr
            client_frame_t frame, oldframe;
            int            lastframe;

            //Com.Printf ("%i . %i\n", new
            // Vargs().add(client.lastframe).add(sv.framenum));
            // this is the frame we are creating
            frame = client.frames[SV_INIT.sv.framenum & Defines.UPDATE_MASK];

            if (client.lastframe <= 0)
            {
                // client is asking for a retransmit
                oldframe  = null;
                lastframe = -1;
            }
            else if (SV_INIT.sv.framenum - client.lastframe >= Defines.UPDATE_BACKUP - 3)
            {
                // client hasn't gotten a good message through in a long time
                // Com_Printf ("%s: Delta request from out-of-date packet.\n",
                // client.name);
                oldframe  = null;
                lastframe = -1;
            }
            else
            {
                // we have a valid message to delta from
                oldframe  = client.frames[client.lastframe & Defines.UPDATE_MASK];
                lastframe = client.lastframe;
            }

            MSG.WriteByte(msg, Defines.svc_frame);
            MSG.WriteLong(msg, SV_INIT.sv.framenum);
            MSG.WriteLong(msg, lastframe);             // what we are delta'ing from
            MSG.WriteByte(msg, client.surpressCount);  // rate dropped packets
            client.surpressCount = 0;

            // send over the areabits
            MSG.WriteByte(msg, frame.areabytes);
            SZ.Write(msg, frame.areabits, frame.areabytes);

            // delta encode the playerstate
            SV_ENTS.SV_WritePlayerstateToClient(oldframe, frame, msg);

            // delta encode the entities
            SV_ENTS.SV_EmitPacketEntities(oldframe, frame, msg);
        }
Exemple #14
0
        public static void SV_DropClient(client_t drop)
        {
            MSG.WriteByte(drop.netchan.message, Defines.svc_disconnect);
            if (drop.state == Defines.cs_spawned)
            {
                PlayerClient.ClientDisconnect(drop.edict);
            }

            if (drop.download != null)
            {
                FS.FreeFile(drop.download);
                drop.download = null;
            }

            drop.state = Defines.cs_zombie;
            drop.name  = "";
        }
Exemple #15
0
        public static void SV_Baselines_f( )
        {
            Int32          start;
            entity_state_t nullstate;
            entity_state_t base_renamed;

            Com.DPrintf("Baselines() from " + SV_MAIN.sv_client.name + "\\n");
            if (SV_MAIN.sv_client.state != Defines.cs_connected)
            {
                Com.Printf("baselines not valid -- already spawned\\n");
                return;
            }

            if (Lib.Atoi(Cmd.Argv(1)) != SV_INIT.svs.spawncount)
            {
                Com.Printf("SV_Baselines_f from different level\\n");
                SV_New_f();
                return;
            }

            start     = Lib.Atoi(Cmd.Argv(2));
            nullstate = new entity_state_t(null);
            while (SV_MAIN.sv_client.netchan.message.cursize < Defines.MAX_MSGLEN / 2 && start < Defines.MAX_EDICTS)
            {
                base_renamed = SV_INIT.sv.baselines[start];
                if (base_renamed.modelindex != 0 || base_renamed.sound != 0 || base_renamed.effects != 0)
                {
                    MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_spawnbaseline);
                    MSG.WriteDeltaEntity(nullstate, base_renamed, SV_MAIN.sv_client.netchan.message, true, true);
                }

                start++;
            }

            if (start == Defines.MAX_EDICTS)
            {
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext);
                MSG.WriteString(SV_MAIN.sv_client.netchan.message, "precache " + SV_INIT.svs.spawncount + "\\n");
            }
            else
            {
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext);
                MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd baselines " + SV_INIT.svs.spawncount + " " + start + "\\n");
            }
        }
Exemple #16
0
        public static Boolean CheckOrDownloadFile(String filename)
        {
            if (filename.IndexOf("..") != -1)
            {
                Com.Printf("Refusing to download a path with ..\\n");
                return(true);
            }

            if (FS.FileLength(filename) > 0)
            {
                return(true);
            }

            Globals.cls.downloadname      = filename;
            Globals.cls.downloadtempname  = Com.StripExtension(Globals.cls.downloadname);
            Globals.cls.downloadtempname += ".tmp";
            var       name = DownloadFileName(Globals.cls.downloadtempname);
            QuakeFile fp   = new QuakeFile(name, FileAccess.ReadWrite);

            if (fp != null)
            {
                Int64 len = 0;
                try
                {
                    len = fp.Length;
                }
                catch (IOException e)
                {
                }

                Globals.cls.download = fp;
                Com.Printf("Resuming " + Globals.cls.downloadname + "\\n");
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
                MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname + " " + len);
            }
            else
            {
                Com.Printf("Downloading " + Globals.cls.downloadname + "\\n");
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
                MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname);
            }

            Globals.cls.downloadnumber++;
            return(false);
        }
Exemple #17
0
        public static void SV_New_f( )
        {
            String  gamedir;
            Int32   playernum;
            edict_t ent;

            Com.DPrintf("New() from " + SV_MAIN.sv_client.name + "\\n");
            if (SV_MAIN.sv_client.state != Defines.cs_connected)
            {
                Com.Printf("New not valid -- already spawned\\n");
                return;
            }

            if (SV_INIT.sv.state == Defines.ss_demo)
            {
                SV_BeginDemoserver();
                return;
            }

            gamedir = Cvar.VariableString("gamedir");
            MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_serverdata);
            MSG.WriteInt(SV_MAIN.sv_client.netchan.message, Defines.PROTOCOL_VERSION);
            MSG.WriteLong(SV_MAIN.sv_client.netchan.message, SV_INIT.svs.spawncount);
            MSG.WriteByte(SV_MAIN.sv_client.netchan.message, SV_INIT.sv.attractloop ? 1 : 0);
            MSG.WriteString(SV_MAIN.sv_client.netchan.message, gamedir);
            if (SV_INIT.sv.state == Defines.ss_cinematic || SV_INIT.sv.state == Defines.ss_pic)
            {
                playernum = -1;
            }
            else
            {
                playernum = SV_MAIN.sv_client.serverindex;
            }
            MSG.WriteShort(SV_MAIN.sv_client.netchan.message, playernum);
            MSG.WriteString(SV_MAIN.sv_client.netchan.message, SV_INIT.sv.configstrings[Defines.CS_NAME]);
            if (SV_INIT.sv.state == Defines.ss_game)
            {
                ent                       = GameBase.g_edicts[playernum + 1];
                ent.s.number              = playernum + 1;
                SV_MAIN.sv_client.edict   = ent;
                SV_MAIN.sv_client.lastcmd = new usercmd_t();
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext);
                MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd configstrings " + SV_INIT.svs.spawncount + " 0\\n");
            }
        }
Exemple #18
0
        public static void ForwardToServer( )
        {
            String cmd;

            cmd = Cmd.Argv(0);
            if (Globals.cls.state <= Defines.ca_connected || cmd[0] == '-' || cmd[0] == '+')
            {
                Com.Printf("Unknown command \\\"" + cmd + "\\\"\\n");
                return;
            }

            MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
            SZ.Print(Globals.cls.netchan.message, cmd);
            if (Cmd.Argc() > 1)
            {
                SZ.Print(Globals.cls.netchan.message, " ");
                SZ.Print(Globals.cls.netchan.message, Cmd.Args());
            }
        }
Exemple #19
0
        public static void SV_Configstrings_f( )
        {
            Int32 start;

            Com.DPrintf("Configstrings() from " + SV_MAIN.sv_client.name + "\\n");
            if (SV_MAIN.sv_client.state != Defines.cs_connected)
            {
                Com.Printf("configstrings not valid -- already spawned\\n");
                return;
            }

            if (Lib.Atoi(Cmd.Argv(1)) != SV_INIT.svs.spawncount)
            {
                Com.Printf("SV_Configstrings_f from different level\\n");
                SV_New_f();
                return;
            }

            start = Lib.Atoi(Cmd.Argv(2));
            while (SV_MAIN.sv_client.netchan.message.cursize < Defines.MAX_MSGLEN / 2 && start < Defines.MAX_CONFIGSTRINGS)
            {
                if (SV_INIT.sv.configstrings[start] != null && SV_INIT.sv.configstrings[start].Length != 0)
                {
                    MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_configstring);
                    MSG.WriteShort(SV_MAIN.sv_client.netchan.message, start);
                    MSG.WriteString(SV_MAIN.sv_client.netchan.message, SV_INIT.sv.configstrings[start]);
                }

                start++;
            }

            if (start == Defines.MAX_CONFIGSTRINGS)
            {
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext);
                MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd baselines " + SV_INIT.svs.spawncount + " 0\\n");
            }
            else
            {
                MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_stufftext);
                MSG.WriteString(SV_MAIN.sv_client.netchan.message, "cmd configstrings " + SV_INIT.svs.spawncount + " " + start + "\\n");
            }
        }
Exemple #20
0
        /**
         * Used by SV_Shutdown to send a final message to all connected clients
         * before the server goes down. The messages are sent immediately, not just
         * stuck on the outgoing message list, because the server is going to
         * totally exit after returning from this function.
         */
        public static void SV_FinalMessage(string message, bool reconnect)
        {
            int      i;
            client_t cl;

            SZ.Clear(Globals.net_message);
            MSG.WriteByte(Globals.net_message, Defines.svc_print);
            MSG.WriteByte(Globals.net_message, Defines.PRINT_HIGH);
            MSG.WriteString(Globals.net_message, message);

            if (reconnect)
            {
                MSG.WriteByte(Globals.net_message, Defines.svc_reconnect);
            }
            else
            {
                MSG.WriteByte(Globals.net_message, Defines.svc_disconnect);
            }

            // send it twice
            // stagger the packets to crutch operating system limited buffers

            for (i = 0; i < SV_INIT.svs.clients.Length; i++)
            {
                cl = SV_INIT.svs.clients[i];

                if (cl.state >= Defines.cs_connected)
                {
                    Netchan.Transmit(cl.netchan, Globals.net_message.cursize, Globals.net_message.data);
                }
            }

            for (i = 0; i < SV_INIT.svs.clients.Length; i++)
            {
                cl = SV_INIT.svs.clients[i];

                if (cl.state >= Defines.cs_connected)
                {
                    Netchan.Transmit(cl.netchan, Globals.net_message.cursize, Globals.net_message.data);
                }
            }
        }
Exemple #21
0
        public static void SV_RecordDemoMessage( )
        {
            if (SV_INIT.svs.demofile == null)
            {
                return;
            }
            entity_state_t nostate = new entity_state_t(null);
            sizebuf_t      buf     = new sizebuf_t();

            SZ.Init(buf, buf_data, buf_data.Length);
            MSG.WriteByte(buf, Defines.svc_frame);
            MSG.WriteLong(buf, SV_INIT.sv.framenum);
            MSG.WriteByte(buf, Defines.svc_packetentities);
            var     e   = 1;
            edict_t ent = GameBase.g_edicts[e];

            while (e < GameBase.num_edicts)
            {
                if (ent.inuse && ent.s.number != 0 && (ent.s.modelindex != 0 || ent.s.effects != 0 || ent.s.sound != 0 || ent.s.event_renamed != 0) && 0 == (ent.svflags & Defines.SVF_NOCLIENT))
                {
                    MSG.WriteDeltaEntity(nostate, ent.s, buf, false, true);
                }
                e++;
                ent = GameBase.g_edicts[e];
            }

            MSG.WriteShort(buf, 0);
            SZ.Write(buf, SV_INIT.svs.demo_multicast.data, SV_INIT.svs.demo_multicast.cursize);
            SZ.Clear(SV_INIT.svs.demo_multicast);
            var len = EndianHandler.SwapInt(buf.cursize);

            try
            {
                SV_INIT.svs.demofile.Write(len);
                SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize);
            }
            catch (Exception e1)
            {
                Com.Printf("Error writing demo file:" + e);
            }
        }
Exemple #22
0
        /**
         * Called when the player is totally leaving the server, either willingly or
         * unwillingly. This is NOT called if the entire server is quiting or
         * crashing.
         */
        public static void SV_DropClient(client_t drop)
        {
            // add the disconnect
            MSG.WriteByte(drop.netchan.message, Defines.svc_disconnect);

            if (drop.state == Defines.cs_spawned)
            {
                // call the prog function for removing a client
                // this will remove the body, among other things
                PlayerClient.ClientDisconnect(drop.edict);
            }

            if (drop.download != null)
            {
                FS.FreeFile(drop.download);
                drop.download = null;
            }

            drop.state = Defines.cs_zombie;             // become free in a few seconds
            drop.name  = "";
        }
Exemple #23
0
        public static void ParseDownload( )
        {
            Int32 size    = MSG.ReadShort(Globals.net_message);
            var   percent = MSG.ReadByte(Globals.net_message);

            if (size == -1)
            {
                Com.Printf("Server does not have this file.\\n");
                if (Globals.cls.download != null)
                {
                    try
                    {
                        Globals.cls.download.Close();
                    }
                    catch (IOException e)
                    {
                    }

                    Globals.cls.download = null;
                }

                CL.RequestNextDownload();
                return;
            }

            if (Globals.cls.download == null)
            {
                var name = DownloadFileName(Globals.cls.downloadtempname).ToLower();
                FS.CreatePath(name);
                Globals.cls.download = new QuakeFile(name, FileAccess.ReadWrite);
                if (Globals.cls.download == null)
                {
                    Globals.net_message.readcount += size;
                    Com.Printf("Failed to open " + Globals.cls.downloadtempname + "\\n");
                    CL.RequestNextDownload();
                    return;
                }
            }

            try
            {
                Globals.cls.download.Write(Globals.net_message.data, Globals.net_message.readcount, size);
            }
            catch (Exception e)
            {
            }

            Globals.net_message.readcount += size;
            if (percent != 100)
            {
                Globals.cls.downloadpercent = percent;
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
                SZ.Print(Globals.cls.netchan.message, "nextdl");
            }
            else
            {
                try
                {
                    Globals.cls.download.Close();
                }
                catch (IOException e)
                {
                }

                var oldn = DownloadFileName(Globals.cls.downloadtempname);
                var newn = DownloadFileName(Globals.cls.downloadname);
                var r    = Lib.Rename(oldn, newn);
                if (r != 0)
                {
                    Com.Printf("failed to rename.\\n");
                }
                Globals.cls.download        = null;
                Globals.cls.downloadpercent = 0;
                CL.RequestNextDownload();
            }
        }
Exemple #24
0
        static void SV_WritePlayerstateToClient(client_frame_t from, client_frame_t to, sizebuf_t msg)
        {
            player_state_t ps, ops;
            player_state_t dummy;

            ps = to.ps;
            if (from == null)
            {
                dummy = new player_state_t();
                ops   = dummy;
            }
            else
            {
                ops = from.ps;
            }

            var pflags = 0;

            if (ps.pmove.pm_type != ops.pmove.pm_type)
            {
                pflags |= Defines.PS_M_TYPE;
            }
            if (ps.pmove.origin[0] != ops.pmove.origin[0] || ps.pmove.origin[1] != ops.pmove.origin[1] || ps.pmove.origin[2] != ops.pmove.origin[2])
            {
                pflags |= Defines.PS_M_ORIGIN;
            }
            if (ps.pmove.velocity[0] != ops.pmove.velocity[0] || ps.pmove.velocity[1] != ops.pmove.velocity[1] || ps.pmove.velocity[2] != ops.pmove.velocity[2])
            {
                pflags |= Defines.PS_M_VELOCITY;
            }
            if (ps.pmove.pm_time != ops.pmove.pm_time)
            {
                pflags |= Defines.PS_M_TIME;
            }
            if (ps.pmove.pm_flags != ops.pmove.pm_flags)
            {
                pflags |= Defines.PS_M_FLAGS;
            }
            if (ps.pmove.gravity != ops.pmove.gravity)
            {
                pflags |= Defines.PS_M_GRAVITY;
            }
            if (ps.pmove.delta_angles[0] != ops.pmove.delta_angles[0] || ps.pmove.delta_angles[1] != ops.pmove.delta_angles[1] || ps.pmove.delta_angles[2] != ops.pmove.delta_angles[2])
            {
                pflags |= Defines.PS_M_DELTA_ANGLES;
            }
            if (ps.viewoffset[0] != ops.viewoffset[0] || ps.viewoffset[1] != ops.viewoffset[1] || ps.viewoffset[2] != ops.viewoffset[2])
            {
                pflags |= Defines.PS_VIEWOFFSET;
            }
            if (ps.viewangles[0] != ops.viewangles[0] || ps.viewangles[1] != ops.viewangles[1] || ps.viewangles[2] != ops.viewangles[2])
            {
                pflags |= Defines.PS_VIEWANGLES;
            }
            if (ps.kick_angles[0] != ops.kick_angles[0] || ps.kick_angles[1] != ops.kick_angles[1] || ps.kick_angles[2] != ops.kick_angles[2])
            {
                pflags |= Defines.PS_KICKANGLES;
            }
            if (ps.blend[0] != ops.blend[0] || ps.blend[1] != ops.blend[1] || ps.blend[2] != ops.blend[2] || ps.blend[3] != ops.blend[3])
            {
                pflags |= Defines.PS_BLEND;
            }
            if (ps.fov != ops.fov)
            {
                pflags |= Defines.PS_FOV;
            }
            if (ps.rdflags != ops.rdflags)
            {
                pflags |= Defines.PS_RDFLAGS;
            }
            if (ps.gunframe != ops.gunframe)
            {
                pflags |= Defines.PS_WEAPONFRAME;
            }
            pflags |= Defines.PS_WEAPONINDEX;
            MSG.WriteByte(msg, Defines.svc_playerinfo);
            MSG.WriteShort(msg, pflags);
            if ((pflags & Defines.PS_M_TYPE) != 0)
            {
                MSG.WriteByte(msg, ps.pmove.pm_type);
            }
            if ((pflags & Defines.PS_M_ORIGIN) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.origin[0]);
                MSG.WriteShort(msg, ps.pmove.origin[1]);
                MSG.WriteShort(msg, ps.pmove.origin[2]);
            }

            if ((pflags & Defines.PS_M_VELOCITY) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.velocity[0]);
                MSG.WriteShort(msg, ps.pmove.velocity[1]);
                MSG.WriteShort(msg, ps.pmove.velocity[2]);
            }

            if ((pflags & Defines.PS_M_TIME) != 0)
            {
                MSG.WriteByte(msg, ps.pmove.pm_time);
            }
            if ((pflags & Defines.PS_M_FLAGS) != 0)
            {
                MSG.WriteByte(msg, ps.pmove.pm_flags);
            }
            if ((pflags & Defines.PS_M_GRAVITY) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.gravity);
            }
            if ((pflags & Defines.PS_M_DELTA_ANGLES) != 0)
            {
                MSG.WriteShort(msg, ps.pmove.delta_angles[0]);
                MSG.WriteShort(msg, ps.pmove.delta_angles[1]);
                MSG.WriteShort(msg, ps.pmove.delta_angles[2]);
            }

            if ((pflags & Defines.PS_VIEWOFFSET) != 0)
            {
                MSG.WriteChar(msg, ps.viewoffset[0] * 4);
                MSG.WriteChar(msg, ps.viewoffset[1] * 4);
                MSG.WriteChar(msg, ps.viewoffset[2] * 4);
            }

            if ((pflags & Defines.PS_VIEWANGLES) != 0)
            {
                MSG.WriteAngle16(msg, ps.viewangles[0]);
                MSG.WriteAngle16(msg, ps.viewangles[1]);
                MSG.WriteAngle16(msg, ps.viewangles[2]);
            }

            if ((pflags & Defines.PS_KICKANGLES) != 0)
            {
                MSG.WriteChar(msg, ps.kick_angles[0] * 4);
                MSG.WriteChar(msg, ps.kick_angles[1] * 4);
                MSG.WriteChar(msg, ps.kick_angles[2] * 4);
            }

            if ((pflags & Defines.PS_WEAPONINDEX) != 0)
            {
                MSG.WriteByte(msg, ps.gunindex);
            }

            if ((pflags & Defines.PS_WEAPONFRAME) != 0)
            {
                MSG.WriteByte(msg, ps.gunframe);
                MSG.WriteChar(msg, ps.gunoffset[0] * 4);
                MSG.WriteChar(msg, ps.gunoffset[1] * 4);
                MSG.WriteChar(msg, ps.gunoffset[2] * 4);
                MSG.WriteChar(msg, ps.gunangles[0] * 4);
                MSG.WriteChar(msg, ps.gunangles[1] * 4);
                MSG.WriteChar(msg, ps.gunangles[2] * 4);
            }

            if ((pflags & Defines.PS_BLEND) != 0)
            {
                MSG.WriteByte(msg, ps.blend[0] * 255);
                MSG.WriteByte(msg, ps.blend[1] * 255);
                MSG.WriteByte(msg, ps.blend[2] * 255);
                MSG.WriteByte(msg, ps.blend[3] * 255);
            }

            if ((pflags & Defines.PS_FOV) != 0)
            {
                MSG.WriteByte(msg, ps.fov);
            }
            if ((pflags & Defines.PS_RDFLAGS) != 0)
            {
                MSG.WriteByte(msg, ps.rdflags);
            }
            var statbits = 0;

            for (var i = 0; i < Defines.MAX_STATS; i++)
            {
                if (ps.stats[i] != ops.stats[i])
                {
                    statbits |= 1 << i;
                }
            }
            MSG.WriteLong(msg, statbits);
            for (var i = 0; i < Defines.MAX_STATS; i++)
            {
                if ((statbits & (1 << i)) != 0)
                {
                    MSG.WriteShort(msg, ps.stats[i]);
                }
            }
        }
Exemple #25
0
 public static void PF_WriteByte(int c)
 {
     MSG.WriteByte(SV_INIT.sv.multicast, c);
 }
Exemple #26
0
        public static void SendCmd()
        {
            int       i;
            usercmd_t cmd, oldcmd;
            int       checksumIndex;

            i   = Globals.cls.netchan.outgoing_sequence & (Defines.CMD_BACKUP - 1);
            cmd = Globals.cl.cmds[i];
            Globals.cl.cmd_time[i] = (int)Globals.cls.realtime;
            CreateCmd(cmd);
            Globals.cl.cmd.Set(cmd);
            if (Globals.cls.state == Defines.ca_disconnected || Globals.cls.state == Defines.ca_connecting)
            {
                return;
            }
            if (Globals.cls.state == Defines.ca_connected)
            {
                if (Globals.cls.netchan.message.cursize != 0 || Globals.curtime - Globals.cls.netchan.last_sent > 1000)
                {
                    Netchan.Transmit(Globals.cls.netchan, 0, new byte[0]);
                }
                return;
            }

            if (Globals.userinfo_modified)
            {
                CL.FixUpGender();
                Globals.userinfo_modified = false;
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_userinfo);
                MSG.WriteString(Globals.cls.netchan.message, Cvar.Userinfo());
            }

            SZ.Init(buf, data, data.Length);
            if (cmd.buttons != 0 && Globals.cl.cinematictime > 0 && !Globals.cl.attractloop && Globals.cls.realtime - Globals.cl.cinematictime > 1000)
            {
                SCR.FinishCinematic();
            }

            MSG.WriteByte(buf, Defines.clc_move);
            checksumIndex = buf.cursize;
            MSG.WriteByte(buf, 0);
            if (cl_nodelta.value != 0F || !Globals.cl.frame.valid || Globals.cls.demowaiting)
            {
                MSG.WriteLong(buf, -1);
            }
            else
            {
                MSG.WriteLong(buf, Globals.cl.frame.serverframe);
            }
            i   = (Globals.cls.netchan.outgoing_sequence - 2) & (Defines.CMD_BACKUP - 1);
            cmd = Globals.cl.cmds[i];
            nullcmd.Clear();
            MSG.WriteDeltaUsercmd(buf, nullcmd, cmd);
            oldcmd = cmd;
            i      = (Globals.cls.netchan.outgoing_sequence - 1) & (Defines.CMD_BACKUP - 1);
            cmd    = Globals.cl.cmds[i];
            MSG.WriteDeltaUsercmd(buf, oldcmd, cmd);
            oldcmd = cmd;
            i      = (Globals.cls.netchan.outgoing_sequence) & (Defines.CMD_BACKUP - 1);
            cmd    = Globals.cl.cmds[i];
            MSG.WriteDeltaUsercmd(buf, oldcmd, cmd);
            buf.data[checksumIndex] = Com.BlockSequenceCRCByte(buf.data, checksumIndex + 1, buf.cursize - checksumIndex - 1, Globals.cls.netchan.outgoing_sequence);
            Netchan.Transmit(Globals.cls.netchan, buf.cursize, buf.data);
        }
Exemple #27
0
        public static void SV_StartSound(Single[] origin, edict_t entity, Int32 channel, Int32 soundindex, Single volume, Single attenuation, Single timeofs)
        {
            Int32   sendchan;
            Int32   flags;
            Int32   i;
            Int32   ent;
            Boolean use_phs;

            if (volume < 0 || volume > 1)
            {
                Com.Error(Defines.ERR_FATAL, "SV_StartSound: volume = " + volume);
            }
            if (attenuation < 0 || attenuation > 4)
            {
                Com.Error(Defines.ERR_FATAL, "SV_StartSound: attenuation = " + attenuation);
            }
            if (timeofs < 0 || timeofs > 0.255)
            {
                Com.Error(Defines.ERR_FATAL, "SV_StartSound: timeofs = " + timeofs);
            }
            ent = entity.index;
            if ((channel & 8) != 0)
            {
                use_phs  = false;
                channel &= 7;
            }
            else
            {
                use_phs = true;
            }
            sendchan = (ent << 3) | (channel & 7);
            flags    = 0;
            if (volume != Defines.DEFAULT_SOUND_PACKET_VOLUME)
            {
                flags |= Defines.SND_VOLUME;
            }
            if (attenuation != Defines.DEFAULT_SOUND_PACKET_ATTENUATION)
            {
                flags |= Defines.SND_ATTENUATION;
            }
            if ((entity.svflags & Defines.SVF_NOCLIENT) != 0 || (entity.solid == Defines.SOLID_BSP) || origin != null)
            {
                flags |= Defines.SND_POS;
            }
            flags |= Defines.SND_ENT;
            if (timeofs != 0)
            {
                flags |= Defines.SND_OFFSET;
            }
            if (origin == null)
            {
                origin = origin_v;
                if (entity.solid == Defines.SOLID_BSP)
                {
                    for (i = 0; i < 3; i++)
                    {
                        origin_v[i] = entity.s.origin[i] + 0.5F * (entity.mins[i] + entity.maxs[i]);
                    }
                }
                else
                {
                    Math3D.VectorCopy(entity.s.origin, origin_v);
                }
            }

            MSG.WriteByte(SV_INIT.sv.multicast, Defines.svc_sound);
            MSG.WriteByte(SV_INIT.sv.multicast, flags);
            MSG.WriteByte(SV_INIT.sv.multicast, soundindex);
            if ((flags & Defines.SND_VOLUME) != 0)
            {
                MSG.WriteByte(SV_INIT.sv.multicast, volume * 255);
            }
            if ((flags & Defines.SND_ATTENUATION) != 0)
            {
                MSG.WriteByte(SV_INIT.sv.multicast, attenuation * 64);
            }
            if ((flags & Defines.SND_OFFSET) != 0)
            {
                MSG.WriteByte(SV_INIT.sv.multicast, timeofs * 1000);
            }
            if ((flags & Defines.SND_ENT) != 0)
            {
                MSG.WriteShort(SV_INIT.sv.multicast, sendchan);
            }
            if ((flags & Defines.SND_POS) != 0)
            {
                MSG.WritePos(SV_INIT.sv.multicast, origin);
            }
            if (attenuation == Defines.ATTN_NONE)
            {
                use_phs = false;
            }
            if ((channel & Defines.CHAN_RELIABLE) != 0)
            {
                if (use_phs)
                {
                    SV_Multicast(origin, Defines.MULTICAST_PHS_R);
                }
                else
                {
                    SV_Multicast(origin, Defines.MULTICAST_ALL_R);
                }
            }
            else
            {
                if (use_phs)
                {
                    SV_Multicast(origin, Defines.MULTICAST_PHS);
                }
                else
                {
                    SV_Multicast(origin, Defines.MULTICAST_ALL);
                }
            }
        }
Exemple #28
0
        /**
         * CL_CheckOrDownloadFile returns true if the file exists,
         * otherwise it attempts to start a
         * download from the server.
         */
        public static bool CheckOrDownloadFile(string filename)
        {
            if (filename.IndexOf("..") != -1)
            {
                Com.Printf("Refusing to download a path with ..\n");

                return(true);
            }

            if (FS.FileLength(filename) > 0)
            {
                // it exists, no need to download
                return(true);
            }

            Globals.cls.downloadname = filename;

            // download to a temp name, and only rename
            // to the real name when done, so if interrupted
            // a runt file wont be left
            Globals.cls.downloadtempname  = Com.StripExtension(Globals.cls.downloadname);
            Globals.cls.downloadtempname += ".tmp";

            //	  ZOID
            // check to see if we already have a tmp for this file, if so, try to
            // resume
            // open the file if not opened yet
            var    name = CL_parse.DownloadFileName(Globals.cls.downloadtempname);
            Stream fp   = File.OpenWrite(name);

            if (fp != null)
            {
                // it exists
                long len = 0;

                try
                {
                    len = fp.Length;
                }
                catch (IOException)
                {
                }

                Globals.cls.download = fp;

                // give the server an offset to start the download
                Com.Printf("Resuming " + Globals.cls.downloadname + "\n");
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
                MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname + " " + len);
            }
            else
            {
                Com.Printf("Downloading " + Globals.cls.downloadname + "\n");
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
                MSG.WriteString(Globals.cls.netchan.message, "download " + Globals.cls.downloadname);
            }

            Globals.cls.downloadnumber++;

            return(false);
        }
Exemple #29
0
        public static void SV_ServerRecord_f( )
        {
            String name;

            Byte[]    buf_data = new Byte[32768];
            sizebuf_t buf      = new sizebuf_t();
            Int32     len;
            Int32     i;

            if (Cmd.Argc() != 2)
            {
                Com.Printf("serverrecord <demoname>\\n");
                return;
            }

            if (SV_INIT.svs.demofile != null)
            {
                Com.Printf("Already recording.\\n");
                return;
            }

            if (SV_INIT.sv.state != Defines.ss_game)
            {
                Com.Printf("You must be in a level to record.\\n");
                return;
            }

            name = FS.Gamedir() + "/demos/" + Cmd.Argv(1) + ".dm2";
            Com.Printf("recording to " + name + ".\\n");
            FS.CreatePath(name);
            try
            {
                SV_INIT.svs.demofile = new QuakeFile(name, FileAccess.ReadWrite);
            }
            catch (Exception e)
            {
                Com.Printf("ERROR: couldn't open.\\n");
                return;
            }

            SZ.Init(SV_INIT.svs.demo_multicast, SV_INIT.svs.demo_multicast_buf, SV_INIT.svs.demo_multicast_buf.Length);
            SZ.Init(buf, buf_data, buf_data.Length);
            MSG.WriteByte(buf, Defines.svc_serverdata);
            MSG.WriteLong(buf, Defines.PROTOCOL_VERSION);
            MSG.WriteLong(buf, SV_INIT.svs.spawncount);
            MSG.WriteByte(buf, 2);
            MSG.WriteString(buf, Cvar.VariableString("gamedir"));
            MSG.WriteShort(buf, -1);
            MSG.WriteString(buf, SV_INIT.sv.configstrings[Defines.CS_NAME]);
            for (i = 0; i < Defines.MAX_CONFIGSTRINGS; i++)
            {
                if (SV_INIT.sv.configstrings[i].Length == 0)
                {
                    MSG.WriteByte(buf, Defines.svc_configstring);
                    MSG.WriteShort(buf, i);
                    MSG.WriteString(buf, SV_INIT.sv.configstrings[i]);
                }
            }

            Com.DPrintf("signon message length: " + buf.cursize + "\\n");
            len = EndianHandler.SwapInt(buf.cursize);
            try
            {
                SV_INIT.svs.demofile.Write(len);
                SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize);
            }
            catch (IOException e1)
            {
                e1.PrintStackTrace();
            }
        }
Exemple #30
0
        /*
         * ===================== CL_ParseDownload
         *
         * A download message has been received from the server
         * =====================
         */
        public static void ParseDownload()
        {
            // read the data
            int size    = MSG.ReadShort(Globals.net_message);
            var percent = MSG.ReadByte(Globals.net_message);

            if (size == -1)
            {
                Com.Printf("Server does not have this file.\n");

                if (Globals.cls.download != null)
                {
                    // if here, we tried to resume a file but the server said no
                    try
                    {
                        Globals.cls.download.Close();
                    }
                    catch (IOException)
                    {
                    }

                    Globals.cls.download = null;
                }

                Cl.RequestNextDownload();

                return;
            }

            // open the file if not opened yet
            if (Globals.cls.download == null)
            {
                var name = CL_parse.DownloadFileName(Globals.cls.downloadtempname).ToLower();
                FS.CreatePath(name);
                Globals.cls.download = File.OpenWrite(name);

                if (Globals.cls.download == null)
                {
                    Globals.net_message.readcount += size;
                    Com.Printf("Failed to open " + Globals.cls.downloadtempname + "\n");
                    Cl.RequestNextDownload();

                    return;
                }
            }

            try
            {
                Globals.cls.download.Write(Globals.net_message.data, Globals.net_message.readcount, size);
            }
            catch (Exception)
            {
            }

            Globals.net_message.readcount += size;

            if (percent != 100)
            {
                // request next block
                //	   change display routines by zoid
                Globals.cls.downloadpercent = percent;
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
                SZ.Print(Globals.cls.netchan.message, "nextdl");
            }
            else
            {
                try
                {
                    Globals.cls.download.Close();
                }
                catch (IOException)
                {
                }

                // rename the temp file to it's final name
                var oldn = CL_parse.DownloadFileName(Globals.cls.downloadtempname);
                var newn = CL_parse.DownloadFileName(Globals.cls.downloadname);
                File.Move(oldn, newn);
                Globals.cls.download        = null;
                Globals.cls.downloadpercent = 0;

                // get another file if needed
                Cl.RequestNextDownload();
            }
        }