SendUnreliableMessage() public static method

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
public static SendUnreliableMessage ( qsocket_t sock, MsgWriter data ) : int
sock qsocket_t
data MsgWriter
return int
Example #1
0
        /// <summary>
        /// SV_SendClientDatagram
        /// </summary>
        static bool SendClientDatagram(client_t client)
        {
            MsgWriter msg = new MsgWriter(QDef.MAX_DATAGRAM); // Uze todo: make static?

            msg.WriteByte(Protocol.svc_time);
            msg.WriteFloat((float)sv.time);

            // add the client specific data to the datagram
            WriteClientDataToMessage(client.edict, msg);

            WriteEntitiesToClient(client.edict, msg);

            // copy the server datagram if there is space
            if (msg.Length + sv.datagram.Length < msg.Capacity)
            {
                msg.Write(sv.datagram.Data, 0, sv.datagram.Length);
            }

            // send the datagram
            if (Net.SendUnreliableMessage(client.netconnection, msg) == -1)
            {
                DropClient(true);// if the message couldn't send, kick off
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// SV_SendNop
        /// Send a nop message without trashing or sending the accumulated client
        /// message buffer
        /// </summary>
        static void SendNop(client_t client)
        {
            MsgWriter msg = new MsgWriter(4);

            msg.WriteChar(Protocol.svc_nop);

            if (Net.SendUnreliableMessage(client.netconnection, msg) == -1)
            {
                DropClient(true);       // if the message couldn't send, kick off
            }
            client.last_message = Host.RealTime;
        }
Example #3
0
        /// <summary>
        /// CL_Disconnect
        ///
        /// Sends a disconnect message to the server
        /// This is also called on Host_Error, so it shouldn't cause any errors
        /// </summary>
        public static void Disconnect()
        {
            // stop sounds (especially looping!)
            Sound.StopAllSounds(true);

            // bring the console down and fade the colors back to normal
            //	SCR_BringDownConsole ();

            // if running a local server, shut it down
            if (Cls.demoplayback)
            {
                StopPlayback();
            }
            else if (Cls.state == ClientActivityState.Connected)
            {
                if (Cls.demorecording)
                {
                    Stop_f();
                }

                Con.DPrint("Sending clc_disconnect\n");
                Cls.message.Clear();
                Cls.message.WriteByte(Protocol.clc_disconnect);
                Net.SendUnreliableMessage(Cls.netcon, Cls.message);
                Cls.message.Clear();
                Net.Close(Cls.netcon);

                Cls.state = ClientActivityState.Disconnected;
                if (Server.sv.active)
                {
                    Host.ShutdownServer(false);
                }
            }

            Cls.demoplayback = Cls.timedemo = false;
            Cls.signon       = 0;
        }
Example #4
0
        // CL_SendMove
        public static void SendMove(ref UserCommand cmd)
        {
            Cl.cmd = cmd; // cl.cmd = *cmd - struct copying!!!

            MessageWriter msg = new MessageWriter(128);

            //
            // send the movement message
            //
            msg.WriteByte(Protocol.clc_move);

            msg.WriteFloat((float)Cl.mtime[0]); // so server can get ping times

            msg.WriteAngle(Cl.viewangles.X);
            msg.WriteAngle(Cl.viewangles.Y);
            msg.WriteAngle(Cl.viewangles.Z);

            msg.WriteShort((short)cmd.forwardmove);
            msg.WriteShort((short)cmd.sidemove);
            msg.WriteShort((short)cmd.upmove);

            //
            // send button bits
            //
            int bits = 0;

            if ((ClientInput.AttackBtn.state & 3) != 0)
            {
                bits |= 1;
            }

            ClientInput.AttackBtn.state &= ~2;

            if ((ClientInput.JumpBtn.state & 3) != 0)
            {
                bits |= 2;
            }

            ClientInput.JumpBtn.state &= ~2;

            msg.WriteByte(bits);

            msg.WriteByte(ClientInput.Impulse);
            ClientInput.Impulse = 0;

            //
            // deliver the message
            //
            if (Cls.demoplayback)
            {
                return;
            }

            //
            // allways dump the first two message, because it may contain leftover inputs
            // from the last level
            //
            if (++Cl.movemessages <= 2)
            {
                return;
            }

            if (Net.SendUnreliableMessage(Cls.netcon, msg) == -1)
            {
                Con.Print("CL_SendMove: lost server connection\n");
                Disconnect();
            }
        }