private void SendGobUpdateMessageOnServer() { if ((DataEngine.ArenaFrameCount % 3) != 0) return; var gobUpdateMessage = new GobUpdateMessage(); PopulateGobUpdateMessage(gobUpdateMessage, DataEngine.Arena.GobsInRelevantLayers, SerializationModeFlags.VaryingDataFromServer); if (gobUpdateMessage.HasContent) foreach (var conn in NetworkEngine.GameClientConnections) conn.Send(gobUpdateMessage); }
private void HandleGobUpdateMessageOnServer(GobUpdateMessage mess, int framesAgo) { var arena = Game.DataEngine.Arena; var messOwner = Game.DataEngine.Spectators.SingleOrDefault(plr => plr.ConnectionID == mess.ConnectionID); if (messOwner == null) return; mess.ReadGobs(gobID => { var theGob = arena.Gobs[gobID]; return theGob == null || theGob.IsDisposed || theGob.Owner != messOwner ? null : theGob; }, SerializationModeFlags.VaryingDataFromClient, framesAgo); // Note: Game server intentionally doesn't call mess.ReadCollisionEvents. }
private void PopulateGobUpdateMessage(GobUpdateMessage gobMessage, IEnumerable<Gob> gobs, SerializationModeFlags serializationMode) { var now = DataEngine.ArenaTotalTime; var debugMessage = Settings.Net.HeavyDebugLog && gobs.OfType<AW2.Game.Gobs.Wall>().Any(wall => wall.ForcedNetworkUpdate) ? new System.Text.StringBuilder("Gob update ") : null; // DEBUG: catch a rare crash that seems to happen only when serializing walls. foreach (var gob in gobs) { if (!gob.ForcedNetworkUpdate) { if (!gob.IsRelevant) continue; if (gob.MoveType == MoveType.Static) continue; if (gob.NetworkUpdatePeriod == TimeSpan.Zero) continue; if (gob.LastNetworkUpdate + gob.NetworkUpdatePeriod > now) continue; } gob.ForcedNetworkUpdate = false; gob.LastNetworkUpdate = now; gobMessage.AddGob(gob.ID, gob, serializationMode); if (debugMessage != null) debugMessage.AppendFormat("{0} [{1}], ", gob.GetType().Name, gob.TypeName); // DEBUG: catch a rare crash that seems to happen only when serializing walls. } gobMessage.SetCollisionEvents(_collisionEventsToRemote, serializationMode); _collisionEventsToRemote = new List<CollisionEvent>(); if (debugMessage != null) // DEBUG: catch a rare crash that seems to happen only when serializing walls. { var writer = new NetworkBinaryWriter(new System.IO.MemoryStream(_debugBuffer)); gobMessage.Serialize(writer); debugMessage.Append(MiscHelper.BytesToString(new ArraySegment<byte>(_debugBuffer, 0, (int)writer.GetBaseStream().Position))); Log.Write(debugMessage.ToString()); } }
private void HandleGobUpdateMessageOnClient(GobUpdateMessage mess, int framesAgo) { var arena = Game.DataEngine.Arena; var updatedGobs = new Dictionary<int, Arena.GobUpdateData>(); var serializationMode = SerializationModeFlags.VaryingDataFromServer; mess.ReadGobs(gobID => { var theGob = arena.Gobs[gobID]; var result = theGob == null || theGob.IsDisposed ? null : theGob; if (result != null) updatedGobs.Add(result.ID, new Arena.GobUpdateData(result, framesAgo)); return result; }, serializationMode, framesAgo); foreach (var collisionEvent in mess.ReadCollisionEvents(id => arena.Gobs[id], serializationMode, framesAgo)) { collisionEvent.SkipReversibleSideEffects = true; collisionEvent.Handle(); } arena.FinalizeGobUpdatesOnClient(updatedGobs, framesAgo); }