Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
0
        public static Boolean SV_SendClientDatagram(client_t client)
        {
            SV_ENTS.SV_BuildClientFrame(client);
            SZ.Init(msg, msgbuf, msgbuf.Length);
            msg.allowoverflow = true;
            SV_ENTS.SV_WriteFrameToClient(client, msg);
            if (client.datagram.overflowed)
            {
                Com.Printf("WARNING: datagram overflowed for " + client.name + "\\n");
            }
            else
            {
                SZ.Write(msg, client.datagram.data, client.datagram.cursize);
            }
            SZ.Clear(client.datagram);
            if (msg.overflowed)
            {
                Com.Printf("WARNING: msg overflowed for " + client.name + "\\n");
                SZ.Clear(msg);
            }

            Netchan.Transmit(client.netchan, msg.cursize, msg.data);
            client.message_size[SV_INIT.sv.framenum % Defines.RATE_MESSAGES] = msg.cursize;
            return(true);
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
        public static void SV_SendClientMessages( )
        {
            Int32    i;
            client_t c;
            Int32    msglen;
            Int32    r;

            msglen = 0;
            if (SV_INIT.sv.state == Defines.ss_demo && SV_INIT.sv.demofile != null)
            {
                if (SV_MAIN.sv_paused.value != 0)
                {
                    msglen = 0;
                }
                else
                {
                    try
                    {
                        msglen = EndianHandler.SwapInt(SV_INIT.sv.demofile.ReadInt32());
                    }
                    catch (Exception e)
                    {
                        SV_DemoCompleted();
                        return;
                    }

                    if (msglen == -1)
                    {
                        SV_DemoCompleted();
                        return;
                    }

                    if (msglen > Defines.MAX_MSGLEN)
                    {
                        Com.Error(Defines.ERR_DROP, "SV_SendClientMessages: msglen > MAX_MSGLEN");
                    }
                    r = 0;
                    try
                    {
                        r = SV_INIT.sv.demofile.Read(msgbuf, 0, msglen);
                    }
                    catch (Exception e1)
                    {
                        Com.Printf("IOError: reading demo file, " + e1);
                    }

                    if (r != msglen)
                    {
                        SV_DemoCompleted();
                        return;
                    }
                }
            }

            for (i = 0; i < SV_MAIN.maxclients.value; i++)
            {
                c = SV_INIT.svs.clients[i];
                if (c.state == 0)
                {
                    continue;
                }
                if (c.netchan.message.overflowed)
                {
                    SZ.Clear(c.netchan.message);
                    SZ.Clear(c.datagram);
                    SV_BroadcastPrintf(Defines.PRINT_HIGH, c.name + " overflowed\\n");
                    SV_MAIN.SV_DropClient(c);
                }

                if (SV_INIT.sv.state == Defines.ss_cinematic || SV_INIT.sv.state == Defines.ss_demo || SV_INIT.sv.state == Defines.ss_pic)
                {
                    Netchan.Transmit(c.netchan, msglen, msgbuf);
                }
                else if (c.state == Defines.cs_spawned)
                {
                    if (SV_RateDrop(c))
                    {
                        continue;
                    }
                    SV_SendClientDatagram(c);
                }
                else
                {
                    if (c.netchan.message.cursize != 0 || Globals.curtime - c.netchan.last_sent > 1000)
                    {
                        Netchan.Transmit(c.netchan, 0, NULLBYTE);
                    }
                }
            }
        }
Esempio n. 5
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);
        }