public static void Gotnewcl(Int32 i, Int32 challenge, String userinfo, netadr_t adr, Int32 qport) { SV_MAIN.sv_client = SV_INIT.svs.clients[i]; var edictnum = i + 1; edict_t ent = GameBase.g_edicts[edictnum]; SV_INIT.svs.clients[i].edict = ent; SV_INIT.svs.clients[i].challenge = challenge; if (!(PlayerClient.ClientConnect(ent, userinfo))) { if (Info.Info_ValueForKey(userinfo, "rejmsg") != null) { Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "print\\n" + Info.Info_ValueForKey(userinfo, "rejmsg") + "\\nConnection refused.\\n"); } else { Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "print\\nConnection refused.\\n"); } Com.DPrintf("Game rejected a connection.\\n"); return; } SV_INIT.svs.clients[i].userinfo = userinfo; SV_UserinfoChanged(SV_INIT.svs.clients[i]); Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "client_connect"); Netchan.Setup(Defines.NS_SERVER, SV_INIT.svs.clients[i].netchan, adr, qport); SV_INIT.svs.clients[i].state = Defines.cs_connected; SZ.Init(SV_INIT.svs.clients[i].datagram, SV_INIT.svs.clients[i].datagram_buf, SV_INIT.svs.clients[i].datagram_buf.Length); SV_INIT.svs.clients[i].datagram.allowoverflow = true; SV_INIT.svs.clients[i].lastmessage = SV_INIT.svs.realtime; SV_INIT.svs.clients[i].lastconnect = SV_INIT.svs.realtime; Com.DPrintf("new client added.\\n"); }
public static void SV_Init( ) { SV_CCMDS.SV_InitOperatorCommands(); SV_MAIN.rcon_password = Cvar.Get("rcon_password", "", 0); Cvar.Get("skill", "1", 0); Cvar.Get("deathmatch", "0", Defines.CVAR_LATCH); Cvar.Get("coop", "0", Defines.CVAR_LATCH); Cvar.Get("dmflags", "" + Defines.DF_INSTANT_ITEMS, Defines.CVAR_SERVERINFO); Cvar.Get("fraglimit", "0", Defines.CVAR_SERVERINFO); Cvar.Get("timelimit", "0", Defines.CVAR_SERVERINFO); Cvar.Get("cheats", "0", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH); Cvar.Get("protocol", "" + Defines.PROTOCOL_VERSION, Defines.CVAR_SERVERINFO | Defines.CVAR_NOSET); SV_MAIN.maxclients = Cvar.Get("maxclients", "1", Defines.CVAR_SERVERINFO | Defines.CVAR_LATCH); SV_MAIN.hostname = Cvar.Get("hostname", "noname", Defines.CVAR_SERVERINFO | Defines.CVAR_ARCHIVE); SV_MAIN.timeout = Cvar.Get("timeout", "125", 0); SV_MAIN.zombietime = Cvar.Get("zombietime", "2", 0); SV_MAIN.sv_showclamp = Cvar.Get("showclamp", "0", 0); SV_MAIN.sv_paused = Cvar.Get("paused", "0", 0); SV_MAIN.sv_timedemo = Cvar.Get("timedemo", "0", 0); SV_MAIN.sv_enforcetime = Cvar.Get("sv_enforcetime", "0", 0); SV_MAIN.allow_download = Cvar.Get("allow_download", "1", Defines.CVAR_ARCHIVE); SV_MAIN.allow_download_players = Cvar.Get("allow_download_players", "0", Defines.CVAR_ARCHIVE); SV_MAIN.allow_download_models = Cvar.Get("allow_download_models", "1", Defines.CVAR_ARCHIVE); SV_MAIN.allow_download_sounds = Cvar.Get("allow_download_sounds", "1", Defines.CVAR_ARCHIVE); SV_MAIN.allow_download_maps = Cvar.Get("allow_download_maps", "1", Defines.CVAR_ARCHIVE); SV_MAIN.sv_noreload = Cvar.Get("sv_noreload", "0", 0); SV_MAIN.sv_airaccelerate = Cvar.Get("sv_airaccelerate", "0", Defines.CVAR_LATCH); SV_MAIN.public_server = Cvar.Get("public", "0", 0); SV_MAIN.sv_reconnect_limit = Cvar.Get("sv_reconnect_limit", "3", Defines.CVAR_ARCHIVE); SZ.Init(Globals.net_message, Globals.net_message_buffer, Globals.net_message_buffer.Length); }
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); }
/** * 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); } }
/** * Initializes player structures after successfull connection. */ public static void gotnewcl(int i, int challenge, string userinfo, netadr_t adr, int qport) { // build a new connection // accept the new client // this is the only place a client_t is ever initialized SV_MAIN.sv_client = SV_INIT.svs.clients[i]; var edictnum = i + 1; var ent = GameBase.g_edicts[edictnum]; SV_INIT.svs.clients[i].edict = ent; // save challenge for checksumming SV_INIT.svs.clients[i].challenge = challenge; // get the game a chance to reject this connection or modify the // userinfo if (!PlayerClient.ClientConnect(ent, userinfo)) { if (Info.Info_ValueForKey(userinfo, "rejmsg") != null) { Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "print\n" + Info.Info_ValueForKey(userinfo, "rejmsg") + "\nConnection refused.\n"); } else { Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "print\nConnection refused.\n"); } Com.DPrintf("Game rejected a connection.\n"); return; } // parse some info from the info strings SV_INIT.svs.clients[i].userinfo = userinfo; SV_MAIN.SV_UserinfoChanged(SV_INIT.svs.clients[i]); // send the connect packet to the client Netchan.OutOfBandPrint(Defines.NS_SERVER, adr, "client_connect"); Netchan.Setup(Defines.NS_SERVER, SV_INIT.svs.clients[i].netchan, adr, qport); SV_INIT.svs.clients[i].state = Defines.cs_connected; SZ.Init(SV_INIT.svs.clients[i].datagram, SV_INIT.svs.clients[i].datagram_buf, SV_INIT.svs.clients[i].datagram_buf.Length); SV_INIT.svs.clients[i].datagram.allowoverflow = true; SV_INIT.svs.clients[i].lastmessage = SV_INIT.svs.realtime; // don't timeout SV_INIT.svs.clients[i].lastconnect = SV_INIT.svs.realtime; Com.DPrintf("new client added.\n"); }
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); } }
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(); } }
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); }
/** * SV_SpawnServer. * * Change the server to a new map, taking all connected clients along with * it. */ public static void SV_SpawnServer(string server, string spawnpoint, int serverstate, bool attractloop, bool loadgame) { int i; var checksum = 0; if (attractloop) { Cvar.Set("paused", "0"); } Com.Printf("------- Server Initialization -------\n"); Com.DPrintf("SpawnServer: " + server + "\n"); if (SV_INIT.sv.demofile != null) { try { SV_INIT.sv.demofile.Close(); } catch (Exception) { } } // any partially connected client will be restarted SV_INIT.svs.spawncount++; SV_INIT.sv.state = Defines.ss_dead; Globals.server_state = SV_INIT.sv.state; // wipe the entire per-level structure SV_INIT.sv = new(); SV_INIT.svs.realtime = 0; SV_INIT.sv.loadgame = loadgame; SV_INIT.sv.attractloop = attractloop; // save name for levels that don't set message SV_INIT.sv.configstrings[Defines.CS_NAME] = server; if (Cvar.VariableValue("deathmatch") != 0) { SV_INIT.sv.configstrings[Defines.CS_AIRACCEL] = "" + SV_MAIN.sv_airaccelerate.value; PMove.pm_airaccelerate = SV_MAIN.sv_airaccelerate.value; } else { SV_INIT.sv.configstrings[Defines.CS_AIRACCEL] = "0"; PMove.pm_airaccelerate = 0; } SZ.Init(SV_INIT.sv.multicast, SV_INIT.sv.multicast_buf, SV_INIT.sv.multicast_buf.Length); SV_INIT.sv.name = server; // leave slots at start for clients only for (i = 0; i < SV_MAIN.maxclients.value; i++) { // needs to reconnect if (SV_INIT.svs.clients[i].state > Defines.cs_connected) { SV_INIT.svs.clients[i].state = Defines.cs_connected; } SV_INIT.svs.clients[i].lastframe = -1; } SV_INIT.sv.time = 1000; SV_INIT.sv.name = server; SV_INIT.sv.configstrings[Defines.CS_NAME] = server; int[] iw = { checksum }; if (serverstate != Defines.ss_game) { SV_INIT.sv.models[1] = CM.CM_LoadMap("", false, iw); // no real map } else { SV_INIT.sv.configstrings[Defines.CS_MODELS + 1] = "maps/" + server + ".bsp"; SV_INIT.sv.models[1] = CM.CM_LoadMap(SV_INIT.sv.configstrings[Defines.CS_MODELS + 1], false, iw); } checksum = iw[0]; SV_INIT.sv.configstrings[Defines.CS_MAPCHECKSUM] = "" + checksum; // clear physics interaction links SV_WORLD.SV_ClearWorld(); for (i = 1; i < CM.CM_NumInlineModels(); i++) { SV_INIT.sv.configstrings[Defines.CS_MODELS + 1 + i] = "*" + i; // copy references SV_INIT.sv.models[i + 1] = CM.InlineModel(SV_INIT.sv.configstrings[Defines.CS_MODELS + 1 + i]); } // spawn the rest of the entities on the map // precache and static commands can be issued during // map initialization SV_INIT.sv.state = Defines.ss_loading; Globals.server_state = SV_INIT.sv.state; // load and spawn all other entities GameSpawn.SpawnEntities(SV_INIT.sv.name, CM.CM_EntityString(), spawnpoint); // run two frames to allow everything to settle GameBase.G_RunFrame(); GameBase.G_RunFrame(); // all precaches are complete SV_INIT.sv.state = serverstate; Globals.server_state = SV_INIT.sv.state; // create a baseline for more efficient communications SV_INIT.SV_CreateBaseline(); // check for a savegame SV_INIT.SV_CheckForSavegame(); // set serverinfo variable Cvar.FullSet("mapname", SV_INIT.sv.name, Defines.CVAR_SERVERINFO | Defines.CVAR_NOSET); }
public static void SV_SpawnServer(String server, String spawnpoint, Int32 serverstate, Boolean attractloop, Boolean loadgame) { Int32 i; var checksum = 0; if (attractloop) { Cvar.Set("paused", "0"); } Com.Printf("------- Server Initialization -------\\n"); Com.DPrintf("SpawnServer: " + server + "\\n"); if (sv.demofile != null) { try { sv.demofile.Close(); } catch (Exception e) { } } svs.spawncount++; sv.state = Defines.ss_dead; Globals.server_state = sv.state; sv = new server_t(); svs.realtime = 0; sv.loadgame = loadgame; sv.attractloop = attractloop; sv.configstrings[Defines.CS_NAME] = server; if (Cvar.VariableValue("deathmatch") != 0) { sv.configstrings[Defines.CS_AIRACCEL] = "" + SV_MAIN.sv_airaccelerate.value; PMove.pm_airaccelerate = SV_MAIN.sv_airaccelerate.value; } else { sv.configstrings[Defines.CS_AIRACCEL] = "0"; PMove.pm_airaccelerate = 0; } SZ.Init(sv.multicast, sv.multicast_buf, sv.multicast_buf.Length); sv.name = server; for (i = 0; i < SV_MAIN.maxclients.value; i++) { if (svs.clients[i].state > Defines.cs_connected) { svs.clients[i].state = Defines.cs_connected; } svs.clients[i].lastframe = -1; } sv.time = 1000; sv.name = server; sv.configstrings[Defines.CS_NAME] = server; Int32[] iw = new[] { checksum }; if (serverstate != Defines.ss_game) { sv.models[1] = CM.CM_LoadMap("", false, iw); } else { sv.configstrings[Defines.CS_MODELS + 1] = "maps/" + server + ".bsp"; sv.models[1] = CM.CM_LoadMap(sv.configstrings[Defines.CS_MODELS + 1], false, iw); } checksum = iw[0]; sv.configstrings[Defines.CS_MAPCHECKSUM] = "" + checksum; SV_WORLD.SV_ClearWorld(); for (i = 1; i < CM.CM_NumInlineModels(); i++) { sv.configstrings[Defines.CS_MODELS + 1 + i] = "*" + i; sv.models[i + 1] = CM.InlineModel(sv.configstrings[Defines.CS_MODELS + 1 + i]); } sv.state = Defines.ss_loading; Globals.server_state = sv.state; GameSpawn.SpawnEntities(sv.name, CM.CM_EntityString(), spawnpoint); GameBase.G_RunFrame(); GameBase.G_RunFrame(); sv.state = serverstate; Globals.server_state = sv.state; SV_CreateBaseline(); SV_CheckForSavegame(); Cvar.FullSet("mapname", sv.name, Defines.CVAR_SERVERINFO | Defines.CVAR_NOSET); }