public void Ask() { if (NeedsSync && !Networker.IsServer) { Networker.SendToServer(Header, "Get", null, EntityID); } }
protected void Register() { try { Networker.RegisterHandler(Entity, Header, Receive); } catch (Exception Scrap) { LaserTools.SessionCore.LogError("Syncer.Register()", Scrap); } }
/// <summary> /// Before creating, make sure that Networker is initialized. /// </summary> public AutoSet(IMyEntity Entity, string DataID, T Default = default(T), Func <T, bool> Checker = null) { if (!Networker.Inited) { Networker.Init(Radars.SessionCore.ModID); } this.DataID = DataID; this.Checker = Checker; EntityID = Entity.EntityId; this.Entity = Entity; Header = $"AutoSet|{DataID}|{Default.GetType().ToString()}"; Register(); }
public void Set(T New) { if (IsValid(New)) { if (Networker.IsServer) { Underlying = New; Networker.SendToAll(Header, "Set", Serialize(Underlying), EntityID); } else { Networker.SendToServer(Header, "SetRequest", Serialize(New), EntityID); } } }
public void Set(T New) { if (IsValid(New)) { if (Networker.IsServer && !New.Equals(Underlying)) { Underlying = New; if (MyAPIGateway.Multiplayer.MultiplayerActive) { Networker.SendToAll(Header, "Set", Serialize(Underlying), EntityID); } } else { Networker.SendToServer(Header, "SetRequest", Serialize(New), EntityID); } } else { LaserTools.SessionCore.DebugWrite($"AutoSet[{Entity.DisplayName}]", $"Invalid value supplied: {New.ToString()}"); } }
protected void Receive(Networker.DataMessage Message) { if (Networker.IsServer) { if (Message.DataDesc == "SetRequest") { var New = Deserialize(Message.Data); Set(New); } else if (Message.DataDesc == "Get") { Networker.SendTo(Message.SenderClientID, Header, "Set", Serialize(Underlying), EntityID); } } else { if (Message.DataDesc == "Set" && Message.IsSentFromServer()) { var New = Deserialize(Message.Data); Underlying = New; } } }
public void Ask() { Networker.SendToServer(Header, "Get", null, EntityID); }
protected void Unregister() { Networker.UnregisterHandler(Entity, Header, Receive); }