public static void ReceiveInvocation(Stream s) { BinaryReader br = new BinaryReader(s); string ss = br.ReadString(); byte[] b = Convert.FromBase64String(ss); NetDemo.log("RPC size : " + b.Length); MemoryStream ms = new MemoryStream(b); BinaryFormatter bf = new BinaryFormatter() { TypeFormat = System.Runtime.Serialization.Formatters.FormatterTypeStyle.TypesWhenNeeded }; { try { (bf.Deserialize(ms) as Modification).Apply(s); } catch (Exception ee) { NetDemo.log(ee.ToString()); } finally { } } }
public static void TryDistributeData(int tickID) { List <SyncTickData> sdl = new List <SyncTickData>(); DateTime dt = DateTime.Now; if (HasFullData(tickID, NetDemo.desiredPlayerCount) /* && playerStateTable[clientID] < tickID*/) { NetDemo.log("dictionary lookup took " + (DateTime.Now - dt).TotalMilliseconds + ", update at " + DateTime.Now); sdl = new List <SyncTickData>(data[tickID]); int? randomV = null; List <string> jobsToVerify = null; desyncReason desyncReason = desyncReason.None; foreach (var __ns in NetDemo.allClients) { foreach (var a in sdl) { { if (!randomV.HasValue) { randomV = a.randomToVerify[0]; } else { NetDemo.log(randomV.Value + " == " + a.randomToVerify[0]); if (randomV.Value != a.randomToVerify[0]) { desyncReason = desyncReason.Rng; } } if (jobsToVerify == null) { jobsToVerify = a.colonistJobsToVerify; } else { if (jobsToVerify.Count != a.colonistJobsToVerify.Count || !jobsToVerify.All(__data => a.colonistJobsToVerify.Any(uu => uu.SequenceEqual(__data)))) { if (jobsToVerify.Count != a.colonistJobsToVerify.Count) { NetDemo.log("JOBS COUNT IS DIFFERENT!" + jobsToVerify.Count + " != " + a.colonistJobsToVerify.Count); } else { string ds = ""; for (int i = 0; i < jobsToVerify.Count; i++) { ds += ("JOBSDUMP : " + jobsToVerify[i] + " != " + a.colonistJobsToVerify[i]) + "\r\n"; } NetDemo.log(ds); } desyncReason = desyncReason.Jobs; //throw new Exception("Session jobs desynced!"); } } } a.DebugLog(); } DateTime _dt = DateTime.Now; switch (desyncReason) { case desyncReason.None: PirateRPC.PirateRPC.SendInvocation(__ns, GetCallback(sdl.ToArray())); break; case desyncReason.Jobs: PirateRPC.PirateRPC.SendInvocation(__ns, uuu => { Messages.Message("Session desynchronized! Reason : different colonist jobs", RimWorld.MessageTypeDefOf.ThreatBig, true); getValuePatch.DumpFramelistData(uuu); }); break; case desyncReason.Rng: NetDemo.log("Session desynchronized! Reason : different control random numbers"); PirateRPC.PirateRPC.SendInvocation(__ns, uuu => { Messages.Message("Session desynchronized! Reason : different control random numbers", RimWorld.MessageTypeDefOf.ThreatBig, true); getValuePatch.DumpFramelistData(uuu); }); break; } NetDemo.log("invocation took " + (DateTime.Now - dt).TotalMilliseconds); } //data.Remove(tickID); } }