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); } } }
public static void SV_NextDownload_f( ) { Int32 r; Int32 percent; Int32 size; if (SV_MAIN.sv_client.download == null) { return; } r = SV_MAIN.sv_client.downloadsize - SV_MAIN.sv_client.downloadcount; if (r > 1024) { r = 1024; } MSG.WriteByte(SV_MAIN.sv_client.netchan.message, Defines.svc_download); MSG.WriteShort(SV_MAIN.sv_client.netchan.message, r); SV_MAIN.sv_client.downloadcount += r; size = SV_MAIN.sv_client.downloadsize; if (size == 0) { size = 1; } percent = SV_MAIN.sv_client.downloadcount * 100 / size; MSG.WriteByte(SV_MAIN.sv_client.netchan.message, percent); SZ.Write(SV_MAIN.sv_client.netchan.message, SV_MAIN.sv_client.download, SV_MAIN.sv_client.downloadcount - r, r); if (SV_MAIN.sv_client.downloadcount != SV_MAIN.sv_client.downloadsize) { return; } FS.FreeFile(SV_MAIN.sv_client.download); SV_MAIN.sv_client.download = null; }
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); }
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 PF_Unicast(edict_t ent, bool reliable) { int p; client_t client; if (ent == null) { return; } p = ent.index; if (p < 1 || p > SV_MAIN.maxclients.value) { return; } client = SV_INIT.svs.clients[p - 1]; if (reliable) { SZ.Write(client.netchan.message, SV_INIT.sv.multicast.data, SV_INIT.sv.multicast.cursize); } else { SZ.Write(client.datagram, SV_INIT.sv.multicast.data, SV_INIT.sv.multicast.cursize); } SZ.Clear(SV_INIT.sv.multicast); }
public static void SV_WriteFrameToClient(client_t client, sizebuf_t msg) { client_frame_t frame, oldframe; Int32 lastframe; frame = client.frames[SV_INIT.sv.framenum & Defines.UPDATE_MASK]; if (client.lastframe <= 0) { oldframe = null; lastframe = -1; } else if (SV_INIT.sv.framenum - client.lastframe >= (Defines.UPDATE_BACKUP - 3)) { oldframe = null; lastframe = -1; } else { oldframe = client.frames[client.lastframe & Defines.UPDATE_MASK]; lastframe = client.lastframe; } MSG.WriteByte(msg, Defines.svc_frame); MSG.WriteLong(msg, SV_INIT.sv.framenum); MSG.WriteLong(msg, lastframe); MSG.WriteByte(msg, client.surpressCount); client.surpressCount = 0; MSG.WriteByte(msg, frame.areabytes); SZ.Write(msg, frame.areabits, frame.areabytes); SV_WritePlayerstateToClient(oldframe, frame, msg); SV_EmitPacketEntities(oldframe, frame, msg); }
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 Int32 SV_FindIndex(String name, Int32 start, Int32 max, Boolean create) { Int32 i; if (name == null || name.Length == 0) { return(0); } for (i = 1; i < max && sv.configstrings[start + i] != null; i++) { if (0 == Lib.Strcmp(sv.configstrings[start + i], name)) { return(i); } } if (!create) { return(0); } if (i == max) { Com.Error(Defines.ERR_DROP, "*Index: overflow"); } sv.configstrings[start + i] = name; if (sv.state != Defines.ss_loading) { SZ.Clear(sv.multicast); MSG.WriteChar(sv.multicast, Defines.svc_configstring); MSG.WriteShort(sv.multicast, start + i); MSG.WriteString(sv.multicast, name); SV_SEND.SV_Multicast(Globals.vec3_origin, Defines.MULTICAST_ALL_R); } return(i); }
/** * PF_Configstring */ public static void PF_Configstring(int index, string val) { if (index < 0 || index >= Defines.MAX_CONFIGSTRINGS) { Com.Error(Defines.ERR_DROP, "configstring: bad index " + index + "\n"); } if (val == null) { val = ""; } // change the string in sv SV_INIT.sv.configstrings[index] = val; if (SV_INIT.sv.state != Defines.ss_loading) { // send the update to // everyone SZ.Clear(SV_INIT.sv.multicast); MSG.WriteChar(SV_INIT.sv.multicast, Defines.svc_configstring); MSG.WriteShort(SV_INIT.sv.multicast, index); MSG.WriteString(SV_INIT.sv.multicast, val); SV_SEND.SV_Multicast(Globals.vec3_origin, Defines.MULTICAST_ALL_R); } }
/** * 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 void BindBone(SBBone Bone) { NameLabel.Text = Bone.Name; X.Bind(Bone, "X"); Y.Bind(Bone, "Y"); Z.Bind(Bone, "Z"); RX.Bind(Bone, "RX"); RY.Bind(Bone, "RY"); RZ.Bind(Bone, "RZ"); SX.Bind(Bone, "SX"); SY.Bind(Bone, "SY"); SZ.Bind(Bone, "SZ"); }
public void HideControl() { Visible = false; X.UnBind(); Y.UnBind(); Z.UnBind(); RX.UnBind(); RY.UnBind(); RZ.UnBind(); SX.UnBind(); SY.UnBind(); SZ.UnBind(); }
/** * Writes a frame to a client system. */ public static void SV_WriteFrameToClient(client_t client, sizebuf_t msg) { //ptr client_frame_t frame, oldframe; int lastframe; //Com.Printf ("%i . %i\n", new // Vargs().add(client.lastframe).add(sv.framenum)); // this is the frame we are creating frame = client.frames[SV_INIT.sv.framenum & Defines.UPDATE_MASK]; if (client.lastframe <= 0) { // client is asking for a retransmit oldframe = null; lastframe = -1; } else if (SV_INIT.sv.framenum - client.lastframe >= Defines.UPDATE_BACKUP - 3) { // client hasn't gotten a good message through in a long time // Com_Printf ("%s: Delta request from out-of-date packet.\n", // client.name); oldframe = null; lastframe = -1; } else { // we have a valid message to delta from oldframe = client.frames[client.lastframe & Defines.UPDATE_MASK]; lastframe = client.lastframe; } MSG.WriteByte(msg, Defines.svc_frame); MSG.WriteLong(msg, SV_INIT.sv.framenum); MSG.WriteLong(msg, lastframe); // what we are delta'ing from MSG.WriteByte(msg, client.surpressCount); // rate dropped packets client.surpressCount = 0; // send over the areabits MSG.WriteByte(msg, frame.areabytes); SZ.Write(msg, frame.areabits, frame.areabytes); // delta encode the playerstate SV_ENTS.SV_WritePlayerstateToClient(oldframe, frame, msg); // delta encode the entities SV_ENTS.SV_EmitPacketEntities(oldframe, frame, msg); }
public static void ForwardToServer( ) { String cmd; cmd = Cmd.Argv(0); if (Globals.cls.state <= Defines.ca_connected || cmd[0] == '-' || cmd[0] == '+') { Com.Printf("Unknown command \\\"" + cmd + "\\\"\\n"); return; } MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); SZ.Print(Globals.cls.netchan.message, cmd); if (Cmd.Argc() > 1) { SZ.Print(Globals.cls.netchan.message, " "); SZ.Print(Globals.cls.netchan.message, Cmd.Args()); } }
/** * 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); } } }
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); } }
/** * SV_FindIndex. */ public static int SV_FindIndex(string name, int start, int max, bool create) { int i; if (name == null || name.Length == 0) { return(0); } for (i = 1; i < max && SV_INIT.sv.configstrings[start + i] != null; i++) { if (0 == Lib.strcmp(SV_INIT.sv.configstrings[start + i], name)) { return(i); } } if (!create) { return(0); } if (i == max) { Com.Error(Defines.ERR_DROP, "*Index: overflow"); } SV_INIT.sv.configstrings[start + i] = name; if (SV_INIT.sv.state != Defines.ss_loading) { // send the update to everyone SZ.Clear(SV_INIT.sv.multicast); MSG.WriteChar(SV_INIT.sv.multicast, Defines.svc_configstring); MSG.WriteShort(SV_INIT.sv.multicast, start + i); MSG.WriteString(SV_INIT.sv.multicast, name); SV_SEND.SV_Multicast(Globals.vec3_origin, Defines.MULTICAST_ALL_R); } return(i); }
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); }
/** * 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_Multicast(Single[] origin, Int32 to) { client_t client; Byte[] mask = null; Int32 leafnum, cluster; Int32 j; Boolean reliable; Int32 area1, area2; reliable = false; if (to != Defines.MULTICAST_ALL_R && to != Defines.MULTICAST_ALL) { leafnum = CM.CM_PointLeafnum(origin); area1 = CM.CM_LeafArea(leafnum); } else { leafnum = 0; area1 = 0; } if (SV_INIT.svs.demofile != null) { SZ.Write(SV_INIT.svs.demo_multicast, SV_INIT.sv.multicast.data, SV_INIT.sv.multicast.cursize); } switch (to) { case Defines.MULTICAST_ALL_R: reliable = true; break; case Defines.MULTICAST_ALL: leafnum = 0; mask = null; break; case Defines.MULTICAST_PHS_R: reliable = true; break; case Defines.MULTICAST_PHS: leafnum = CM.CM_PointLeafnum(origin); cluster = CM.CM_LeafCluster(leafnum); mask = CM.CM_ClusterPHS(cluster); break; case Defines.MULTICAST_PVS_R: reliable = true; break; case Defines.MULTICAST_PVS: leafnum = CM.CM_PointLeafnum(origin); cluster = CM.CM_LeafCluster(leafnum); mask = CM.CM_ClusterPVS(cluster); break; default: mask = null; Com.Error(Defines.ERR_FATAL, "SV_Multicast: bad to:" + to + "\\n"); break; } for (j = 0; j < SV_MAIN.maxclients.value; j++) { client = SV_INIT.svs.clients[j]; if (client.state == Defines.cs_free || client.state == Defines.cs_zombie) { continue; } if (client.state != Defines.cs_spawned && !reliable) { continue; } if (mask != null) { leafnum = CM.CM_PointLeafnum(client.edict.s.origin); cluster = CM.CM_LeafCluster(leafnum); area2 = CM.CM_LeafArea(leafnum); if (!CM.CM_AreasConnected(area1, area2)) { continue; } if (cluster == -1) { continue; } if (mask != null && (0 == (mask[cluster >> 3] & (1 << (cluster & 7))))) { continue; } } if (reliable) { SZ.Write(client.netchan.message, SV_INIT.sv.multicast.data, SV_INIT.sv.multicast.cursize); } else { SZ.Write(client.datagram, SV_INIT.sv.multicast.data, SV_INIT.sv.multicast.cursize); } } SZ.Clear(SV_INIT.sv.multicast); }
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); } } } }
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); }
public static void ParseDownload( ) { Int32 size = MSG.ReadShort(Globals.net_message); var percent = MSG.ReadByte(Globals.net_message); if (size == -1) { Com.Printf("Server does not have this file.\\n"); if (Globals.cls.download != null) { try { Globals.cls.download.Close(); } catch (IOException e) { } Globals.cls.download = null; } CL.RequestNextDownload(); return; } if (Globals.cls.download == null) { var name = DownloadFileName(Globals.cls.downloadtempname).ToLower(); FS.CreatePath(name); Globals.cls.download = new QuakeFile(name, FileAccess.ReadWrite); if (Globals.cls.download == null) { Globals.net_message.readcount += size; Com.Printf("Failed to open " + Globals.cls.downloadtempname + "\\n"); CL.RequestNextDownload(); return; } } try { Globals.cls.download.Write(Globals.net_message.data, Globals.net_message.readcount, size); } catch (Exception e) { } Globals.net_message.readcount += size; if (percent != 100) { Globals.cls.downloadpercent = percent; MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); SZ.Print(Globals.cls.netchan.message, "nextdl"); } else { try { Globals.cls.download.Close(); } catch (IOException e) { } var oldn = DownloadFileName(Globals.cls.downloadtempname); var newn = DownloadFileName(Globals.cls.downloadname); var r = Lib.Rename(oldn, newn); if (r != 0) { Com.Printf("failed to rename.\\n"); } Globals.cls.download = null; Globals.cls.downloadpercent = 0; CL.RequestNextDownload(); } }
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(); } }
/* * ===================== CL_ParseDownload * * A download message has been received from the server * ===================== */ public static void ParseDownload() { // read the data int size = MSG.ReadShort(Globals.net_message); var percent = MSG.ReadByte(Globals.net_message); if (size == -1) { Com.Printf("Server does not have this file.\n"); if (Globals.cls.download != null) { // if here, we tried to resume a file but the server said no try { Globals.cls.download.Close(); } catch (IOException) { } Globals.cls.download = null; } Cl.RequestNextDownload(); return; } // open the file if not opened yet if (Globals.cls.download == null) { var name = CL_parse.DownloadFileName(Globals.cls.downloadtempname).ToLower(); FS.CreatePath(name); Globals.cls.download = File.OpenWrite(name); if (Globals.cls.download == null) { Globals.net_message.readcount += size; Com.Printf("Failed to open " + Globals.cls.downloadtempname + "\n"); Cl.RequestNextDownload(); return; } } try { Globals.cls.download.Write(Globals.net_message.data, Globals.net_message.readcount, size); } catch (Exception) { } Globals.net_message.readcount += size; if (percent != 100) { // request next block // change display routines by zoid Globals.cls.downloadpercent = percent; MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd); SZ.Print(Globals.cls.netchan.message, "nextdl"); } else { try { Globals.cls.download.Close(); } catch (IOException) { } // rename the temp file to it's final name var oldn = CL_parse.DownloadFileName(Globals.cls.downloadtempname); var newn = CL_parse.DownloadFileName(Globals.cls.downloadname); File.Move(oldn, newn); Globals.cls.download = null; Globals.cls.downloadpercent = 0; // get another file if needed Cl.RequestNextDownload(); } }