Example #1
0
        protected void SendControlMessage <T>(ulong user, ref T message) where T : struct
        {
            ITransportCallback   handler;
            MyControlMessageEnum messageEnum;

            m_controlMessageTypes.TryGetValue(typeof(T), out messageEnum);
            m_controlMessageHandlers.TryGetValue((int)messageEnum, out handler);

            var callback = ((MyControlMessageCallback <T>)handler);

            if (!MySyncLayer.CheckSendPermissions(user, callback.Permission))
            {
                return;
            }


            m_controlSendStream.Position = 0;
            m_controlSendStream.WriteUShort((ushort)messageEnum);
            callback.Write(m_controlSendStream, ref message);

            if (!Peer2Peer.SendPacket(user, m_controlSendStream.Data, (int)m_controlSendStream.Position, P2PMessageEnum.Reliable, MyMultiplayer.ControlChannel))
            {
                System.Diagnostics.Debug.Fail("P2P packet not sent");
            }

            // Peer2Peer.SendPacket(user, (byte*)&msg, sizeof(ControlMessageStruct), P2PMessageEnum.Reliable, MyMultiplayer.ControlChannel);
        }
Example #2
0
        protected void SendControlMessage <T>(ulong user, ref T message, bool reliable = true) where T : struct
        {
            ITransportCallback   callback;
            MyControlMessageEnum enum2;

            this.m_controlMessageTypes.TryGetValue(typeof(T), out enum2);
            this.m_controlMessageHandlers.TryGetValue((int)enum2, out callback);
            MyControlMessageCallback <T> callback2 = (MyControlMessageCallback <T>)callback;

            if (MySyncLayer.CheckSendPermissions(user, callback2.Permission))
            {
                MyNetworkWriter.MyPacketDescriptor packet = MyNetworkWriter.GetPacketDescriptor(new EndpointId(user), reliable ? MyP2PMessageEnum.ReliableWithBuffering : MyP2PMessageEnum.Unreliable, 0);
                packet.Header.WriteUShort((ushort)enum2);
                callback2.Write(packet.Header, ref message);
                MyNetworkWriter.SendPacket(packet);
            }
        }