Пример #1
0
 internal void SendMessageTo(PacketBase data, ulong target)
 {
     if (!IsServer)
     {
         var targets = new[] { target };
         var res     = PreparePacket(data, SendTarget.Proxy, 0, targets, false);
         if (res != null)
         {
             SendMessageToServer(new PacketProxy {
                 Data = res, Targets = targets, IsBroadcast = false
             });
         }
     }
     else
     {
         var id = MyAPIGateway.Multiplayer.MyId;
         if (target == id)
         {
             data.Sender = id;
             data.HandlePacket(this);
         }
         else
         {
             var res = PreparePacket(data, SendTarget.ToTarget, target, null, false);
             if (res != null)
             {
                 SendMessageTo(res, target);
             }
         }
     }
 }
Пример #2
0
        public void MPMessageHandler(byte[] data)
        {
            PacketBase packet = null;

            try
            {
                packet = data.FromBinary <PacketBase>();
            }
            catch (Exception e)
            {
                $"MPMessageHandler FromBinary Exception: {e}".Log(true);
                return;
            }
            if (packet != null && packet.ModId == _modId)
            {
                try
                {
                    packet.HandlePacket(this);
                }
                catch (Exception e)
                {
                    $"MPMessageHandler Exception: {e}".Log(true);
                }
            }
        }
Пример #3
0
 internal void SendMessageToServer(PacketBase data)
 {
     if (IsServer)
     {
         data.Sender = MyAPIGateway.Multiplayer.MyId;
         data.HandlePacket(this);
     }
     else
     {
         var res = PreparePacket(data, SendTarget.ToServer, 0, null, false);
         if (res != null)
         {
             MyAPIGateway.Multiplayer.SendMessageToServer(_networkId, res);
         }
     }
 }