Exemplo n.º 1
0
 public static void SV_KillServer_f( )
 {
     if (!SV_INIT.svs.initialized)
     {
         return;
     }
     SV_MAIN.SV_Shutdown("Server was killed.\\n", false);
     NET.Config(false);
 }
Exemplo n.º 2
0
        public static void SV_Kick_f( )
        {
            if (!SV_INIT.svs.initialized)
            {
                Com.Printf("No server running.\\n");
                return;
            }

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

            if (!SV_SetPlayer())
            {
                return;
            }
            SV_SEND.SV_BroadcastPrintf(Defines.PRINT_HIGH, SV_MAIN.sv_client.name + " was kicked\\n");
            SV_SEND.SV_ClientPrintf(SV_MAIN.sv_client, Defines.PRINT_HIGH, "You were kicked from the game\\n");
            SV_MAIN.SV_DropClient(SV_MAIN.sv_client);
            SV_MAIN.sv_client.lastmessage = SV_INIT.svs.realtime;
        }
Exemplo n.º 3
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);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void SV_InitGame( )
        {
            Int32   i;
            edict_t ent;
            String  idmaster;

            if (svs.initialized)
            {
                SV_MAIN.SV_Shutdown("Server restarted\\n", true);
            }
            else
            {
                CL.Drop();
                SCR.BeginLoadingPlaque();
            }

            Cvar.GetLatchedVars();
            svs.initialized = true;
            if (Cvar.VariableValue("coop") != 0 && Cvar.VariableValue("deathmatch") != 0)
            {
                Com.Printf("Deathmatch and Coop both set, disabling Coop\\n");
                Cvar.FullSet("coop", "0", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
            }

            if (Globals.dedicated.value != 0)
            {
                if (0 == Cvar.VariableValue("coop"))
                {
                    Cvar.FullSet("deathmatch", "1", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
                }
            }

            if (Cvar.VariableValue("deathmatch") != 0)
            {
                if (SV_MAIN.maxclients.value <= 1)
                {
                    Cvar.FullSet("maxclients", "8", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
                }
                else if (SV_MAIN.maxclients.value > Defines.MAX_CLIENTS)
                {
                    Cvar.FullSet("maxclients", "" + Defines.MAX_CLIENTS, Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
                }
            }
            else if (Cvar.VariableValue("coop") != 0)
            {
                if (SV_MAIN.maxclients.value <= 1 || SV_MAIN.maxclients.value > 4)
                {
                    Cvar.FullSet("maxclients", "4", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
                }
            }
            else
            {
                Cvar.FullSet("maxclients", "1", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH);
            }

            svs.spawncount = Lib.Rand();
            svs.clients    = new client_t[( Int32 )SV_MAIN.maxclients.value];
            for (var n = 0; n < svs.clients.Length; n++)
            {
                svs.clients[n]             = new client_t();
                svs.clients[n].serverindex = n;
            }

            svs.num_client_entities = (( Int32 )SV_MAIN.maxclients.value) * Defines.UPDATE_BACKUP * 64;
            svs.client_entities     = new entity_state_t[svs.num_client_entities];
            for (var n = 0; n < svs.client_entities.Length; n++)
            {
                svs.client_entities[n] = new entity_state_t(null);
            }
            NET.Config((SV_MAIN.maxclients.value > 1));
            svs.last_heartbeat = -99999;
            idmaster           = "192.246.40.37:" + Defines.PORT_MASTER;
            NET.StringToAdr(idmaster, SV_MAIN.master_adr[0]);
            SV_GAME.SV_InitGameProgs();
            for (i = 0; i < SV_MAIN.maxclients.value; i++)
            {
                ent = GameBase.g_edicts[i + 1];
                svs.clients[i].edict   = ent;
                svs.clients[i].lastcmd = new usercmd_t();
            }
        }
Exemplo n.º 5
0
        public static void SV_ExecuteClientMessage(client_t cl)
        {
            Int32     c;
            String    s;
            usercmd_t nullcmd = new usercmd_t();
            usercmd_t oldest = new usercmd_t(), oldcmd = new usercmd_t(), newcmd = new usercmd_t();
            Int32     net_drop;
            Int32     stringCmdCount;
            Int32     checksum, calculatedChecksum;
            Int32     checksumIndex;
            Boolean   move_issued;
            Int32     lastframe;

            SV_MAIN.sv_client = cl;
            SV_USER.sv_player = SV_MAIN.sv_client.edict;
            move_issued       = false;
            stringCmdCount    = 0;
            while (true)
            {
                if (Globals.net_message.readcount > Globals.net_message.cursize)
                {
                    Com.Printf("SV_ReadClientMessage: bad read:\\n");
                    Com.Printf(Lib.HexDump(Globals.net_message.data, 32, false));
                    SV_MAIN.SV_DropClient(cl);
                    return;
                }

                c = MSG.ReadByte(Globals.net_message);
                if (c == -1)
                {
                    break;
                }
                switch (c)

                {
                default:
                    Com.Printf("SV_ReadClientMessage: unknown command char\\n");
                    SV_MAIN.SV_DropClient(cl);
                    return;

                case Defines.clc_nop:
                    break;

                case Defines.clc_userinfo:
                    cl.userinfo = MSG.ReadString(Globals.net_message);
                    SV_MAIN.SV_UserinfoChanged(cl);
                    break;

                case Defines.clc_move:
                    if (move_issued)
                    {
                        return;
                    }
                    move_issued   = true;
                    checksumIndex = Globals.net_message.readcount;
                    checksum      = MSG.ReadByte(Globals.net_message);
                    lastframe     = MSG.ReadLong(Globals.net_message);
                    if (lastframe != cl.lastframe)
                    {
                        cl.lastframe = lastframe;
                        if (cl.lastframe > 0)
                        {
                            cl.frame_latency[cl.lastframe & (Defines.LATENCY_COUNTS - 1)] = SV_INIT.svs.realtime - cl.frames[cl.lastframe & Defines.UPDATE_MASK].senttime;
                        }
                    }

                    nullcmd = new usercmd_t();
                    MSG.ReadDeltaUsercmd(Globals.net_message, nullcmd, oldest);
                    MSG.ReadDeltaUsercmd(Globals.net_message, oldest, oldcmd);
                    MSG.ReadDeltaUsercmd(Globals.net_message, oldcmd, newcmd);
                    if (cl.state != Defines.cs_spawned)
                    {
                        cl.lastframe = -1;
                        break;
                    }

                    calculatedChecksum = Com.BlockSequenceCRCByte(Globals.net_message.data, checksumIndex + 1, Globals.net_message.readcount - checksumIndex - 1, cl.netchan.incoming_sequence);
                    if ((calculatedChecksum & 0xff) != checksum)
                    {
                        Com.DPrintf("Failed command checksum for " + cl.name + " (" + calculatedChecksum + " != " + checksum + ")/" + cl.netchan.incoming_sequence + "\\n");
                        return;
                    }

                    if (0 == SV_MAIN.sv_paused.value)
                    {
                        net_drop = cl.netchan.dropped;
                        if (net_drop < 20)
                        {
                            while (net_drop > 2)
                            {
                                SV_ClientThink(cl, cl.lastcmd);
                                net_drop--;
                            }

                            if (net_drop > 1)
                            {
                                SV_ClientThink(cl, oldest);
                            }
                            if (net_drop > 0)
                            {
                                SV_ClientThink(cl, oldcmd);
                            }
                        }

                        SV_ClientThink(cl, newcmd);
                    }

                    cl.lastcmd.Set(newcmd);
                    break;

                case Defines.clc_stringcmd:
                    s = MSG.ReadString(Globals.net_message);
                    if (++stringCmdCount < SV_USER.MAX_STRINGCMDS)
                    {
                        SV_ExecuteUserCommand(s);
                    }
                    if (cl.state == Defines.cs_zombie)
                    {
                        return;
                    }
                    break;
                }
            }
        }
Exemplo n.º 6
0
 public static void SV_Disconnect_f( )
 {
     SV_MAIN.SV_DropClient(SV_MAIN.sv_client);
 }