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 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 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_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; }
/** * 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); } }
/** * 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 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_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); }