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

            peer.SendMessage(msg, recipient, DeliveryMethod, SequenceChannel);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }