Beispiel #1
0
    public static bool SV_SendClientDatagram(client_t client)
    {
        MsgWriter msg = new MsgWriter(q_shared.MAX_DATAGRAM); // Uze todo: make static?

        msg.MSG_WriteByte(q_shared.svc_time);
        msg.MSG_WriteFloat((float)sv.time);

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

        SV_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)
        {
            SV_DropClient(true);// if the message couldn't send, kick off
            return(false);
        }

        return(true);
    }
Beispiel #2
0
    public static void Host_Spawn_f()
    {
        if (cmd_source == cmd_source_t.src_command)
        {
            Con_Printf("spawn is not valid from the console\n");
            return;
        }

        if (host_client.spawned)
        {
            Con_Printf("Spawn not valid -- allready spawned\n");
            return;
        }

        edict_t ent;

        // run the entrance script
        if (sv.loadgame)
        {
            // loaded games are fully inited allready
            // if this is the last client to be connected, unpause
            sv.paused = false;
        }
        else
        {
            // set up the edict
            ent = host_client.edict;

            ent.Clear(); //memset(&ent.v, 0, progs.entityfields * 4);
            ent.v.colormap = NUM_FOR_EDICT(ent);
            ent.v.team     = (host_client.colors & 15) + 1;
            ent.v.netname  = ED_NewString(host_client.name);

            // copy spawn parms out of the client_t
            pr_global_struct.SetParams(host_client.spawn_parms);

            // call the spawn function

            pr_global_struct.time = (float)sv.time;
            pr_global_struct.self = EDICT_TO_PROG(sv_player);
            PR_ExecuteProgram(pr_global_struct.ClientConnect);

            if ((Sys_FloatTime() - host_client.netconnection.connecttime) <= sv.time)
            {
                Con_DPrintf("{0} entered the game\n", host_client.name);
            }

            PR_ExecuteProgram(pr_global_struct.PutClientInServer);
        }


        // send all current names, colors, and frag counts
        MsgWriter msg = host_client.message;

        msg.Clear();

        // send time of update
        msg.MSG_WriteByte(q_shared.svc_time);
        msg.MSG_WriteFloat((float)sv.time);

        for (int i = 0; i < svs.maxclients; i++)
        {
            client_t client = svs.clients[i];
            msg.MSG_WriteByte(q_shared.svc_updatename);
            msg.MSG_WriteByte(i);
            msg.MSG_WriteString(client.name);
            msg.MSG_WriteByte(q_shared.svc_updatefrags);
            msg.MSG_WriteByte(i);
            msg.MSG_WriteShort(client.old_frags);
            msg.MSG_WriteByte(q_shared.svc_updatecolors);
            msg.MSG_WriteByte(i);
            msg.MSG_WriteByte(client.colors);
        }

        // send all current light styles
        for (int i = 0; i < q_shared.MAX_LIGHTSTYLES; i++)
        {
            msg.MSG_WriteByte(q_shared.svc_lightstyle);
            msg.MSG_WriteByte((char)i);
            msg.MSG_WriteString(sv.lightstyles[i]);
        }

        //
        // send some stats
        //
        msg.MSG_WriteByte(q_shared.svc_updatestat);
        msg.MSG_WriteByte(q_shared.STAT_TOTALSECRETS);
        msg.MSG_WriteLong((int)pr_global_struct.total_secrets);

        msg.MSG_WriteByte(q_shared.svc_updatestat);
        msg.MSG_WriteByte(q_shared.STAT_TOTALMONSTERS);
        msg.MSG_WriteLong((int)pr_global_struct.total_monsters);

        msg.MSG_WriteByte(q_shared.svc_updatestat);
        msg.MSG_WriteByte(q_shared.STAT_SECRETS);
        msg.MSG_WriteLong((int)pr_global_struct.found_secrets);

        msg.MSG_WriteByte(q_shared.svc_updatestat);
        msg.MSG_WriteByte(q_shared.STAT_MONSTERS);
        msg.MSG_WriteLong((int)pr_global_struct.killed_monsters);


        //
        // send a fixangle
        // Never send a roll angle, because savegames can catch the server
        // in a state where it is expecting the client to correct the angle
        // and it won't happen if the game was just loaded, so you wind up
        // with a permanent head tilt
        ent = EDICT_NUM(1 + ClientNum);
        msg.MSG_WriteByte(q_shared.svc_setangle);
        msg.MSG_WriteAngle(ent.v.angles.x);
        msg.MSG_WriteAngle(ent.v.angles.y);
        msg.MSG_WriteAngle(0);

        SV_WriteClientdataToMessage(sv_player, host_client.message);

        msg.MSG_WriteByte(q_shared.svc_signonnum);
        msg.MSG_WriteByte(3);
        host_client.sendsignon = true;
    }
Beispiel #3
0
    public static void CL_SendMove(ref usercmd_t cmd)
    {
        cl.cmd = cmd; // cl.cmd = *cmd - struct copying!!!

        MsgWriter msg = new MsgWriter(128);

        //
        // send the movement message
        //
        msg.MSG_WriteByte(q_shared.clc_move);

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

        msg.MSG_WriteAngle(cl.viewangles.X);
        msg.MSG_WriteAngle(cl.viewangles.Y);
        msg.MSG_WriteAngle(cl.viewangles.Z);

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

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

        if ((in_attack.state & 3) != 0)
        {
            bits |= 1;
        }
        in_attack.state &= ~2;

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

        msg.MSG_WriteByte(bits);

        msg.MSG_WriteByte(in_impulse);
        in_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_Printf("CL_SendMove: lost server connection\n");
            CL_Disconnect();
        }
    }