Beispiel #1
0
        void HandlePacket(PacketBase packet, ulong senderSteamId, byte[] serialized = null)
        {
            // Server-side OriginalSender validation
            if (MyAPIGateway.Multiplayer.IsServer)
            {
                if (senderSteamId != packet.OriginalSenderSteamId)
                {
                    MyLog.Default.WriteLineAndConsole($"{ModName} WARNING: packet {packet.GetType().Name} from {senderSteamId.ToString()} has altered OriginalSenderSteamId to {packet.OriginalSenderSteamId.ToString()}. Replaced it with proper id, but if this triggers for everyone then it's a bug somewhere.");

                    packet.OriginalSenderSteamId = senderSteamId;
                    serialized = null; // force reserialize
                }
            }

            RelayMode relay = RelayMode.NoRelay;

            packet.Received(ref relay);

            if (MyAPIGateway.Multiplayer.IsServer && relay != RelayMode.NoRelay)
            {
                if (relay == RelayMode.RelayOriginal)
                {
                    RelayToClients(packet, senderSteamId, serialized);
                }
                else if (relay == RelayMode.RelayWithChanges)
                {
                    RelayToClients(packet, senderSteamId, null);
                }
                else
                {
                    throw new Exception($"{ModName}: Unknown relay mode: {relay.ToString()}");
                }
            }
        }
Beispiel #2
0
        void HandlePacket(PacketBase packet, ulong senderSteamId, byte[] serialized = null)
        {
            // validate OriginalSenderSteamId
            if (MyAPIGateway.Session.IsServer && senderSteamId != packet.OriginalSenderSteamId)
            {
                LogError($"{GetType().FullName} WARNING: packet {packet.GetType().Name} from {senderSteamId.ToString()} has altered SenderSteamId to {packet.OriginalSenderSteamId.ToString()}. I replaced it with the proper id, but if this triggers for everyone then it's a bug somewhere.");

                packet.OriginalSenderSteamId = senderSteamId;
                serialized = null; // force reserialize
            }

            RelayMode relay = RelayMode.NoRelay;

            packet.Received(ref relay, senderSteamId);

            if (MyAPIGateway.Session.IsServer && relay != RelayMode.NoRelay)
            {
                if (relay == RelayMode.RelayOriginal)
                {
                    RelayToOthers(packet, serialized, senderSteamId);
                }
                else if (relay == RelayMode.RelayWithChanges)
                {
                    RelayToOthers(packet, null, senderSteamId);
                }
                else
                {
                    throw new Exception($"Unknown relay mode: {relay.ToString()}");
                }
            }
        }