public void Ask()
 {
     if (NeedsSync && !Networker.IsServer)
     {
         Networker.SendToServer(Header, "Get", null, EntityID);
     }
 }
示例#2
0
 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();
 }
示例#4
0
 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);
         }
     }
 }
示例#5
0
 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;
         }
     }
 }
示例#7
0
 public void Ask()
 {
     Networker.SendToServer(Header, "Get", null, EntityID);
 }
示例#8
0
 protected void Unregister()
 {
     Networker.UnregisterHandler(Entity, Header, Receive);
 }