Ejemplo n.º 1
0
        public void Send(MessageTypeMap messageTypeMap, NetConnection recipient)
        {
            var peer = recipient.Peer;
            var msg  = Write(messageTypeMap, peer);

            peer.SendMessage(msg, recipient, DeliveryMethod, SequenceChannel);
        }
Ejemplo n.º 2
0
        public NetOutgoingMessage Write(MessageTypeMap messageTypeMap, NetPeer peer)
        {
            NetOutgoingMessage outgoingMessage;

            lock (MessageBufferLock)
            {
                if (_messageBuffer == null)
                {
                    _messageBuffer = peer.CreateMessage(128);
                }
                else
                {
                    _messageBuffer.LengthBytes = 0;
                    var buffer = _messageBuffer.PeekDataBuffer();
                    Array.Clear(buffer, 0, buffer.Length);
                }

                var messageTypeId = messageTypeMap.GetMessageTypeId(this);
                _messageBuffer.Write(messageTypeId);

                WriteTo(_messageBuffer);

                outgoingMessage = peer.CreateMessage(_messageBuffer.LengthBytes);
                outgoingMessage.Write(_messageBuffer);
            }

            return(outgoingMessage);
        }
Ejemplo n.º 3
0
        public void Send(MessageTypeMap messageTypeMap, NetServer server, List <NetConnection> sendTo)
        {
            if (server.ConnectionsCount == 0)
            {
                return;
            }
            var msg = Write(messageTypeMap, server);

            server.SendMessage(msg, sendTo, DeliveryMethod, SequenceChannel);
        }
Ejemplo n.º 4
0
        public void SendToAll(MessageTypeMap messageTypeMap, NetServer server, NetConnection except)
        {
            if (server.ConnectionsCount == 0)
            {
                return;
            }
            var msg = Write(messageTypeMap, server);

            server.SendToAll(msg, except, DeliveryMethod, SequenceChannel);
        }
Ejemplo n.º 5
0
        public static Message Read(MessageTypeMap messageTypeMap, NetIncomingMessage incomingMessage)
        {
            var id          = incomingMessage.ReadByte();
            var messageType = messageTypeMap.GetMessageType(id);
            var message     = (Message)Activator.CreateInstance(messageType);

            message.ReadFrom(incomingMessage);

            return(message);
        }