Ejemplo n.º 1
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            ChatNetworkMessage m = (ChatNetworkMessage)message;

            var receivedMessage = new ReceivedChatMessage() {
                RecieveTime = DateTime.Now,
                Sender = m.Sender,
                Content = m.Content
            };
            AllMessages.Add(receivedMessage);

            if (ShouldDisplay(m.Receivers)) {
                DisplayableMessages.Add(receivedMessage);
            }
        }
		/// <summary>
		/// Child implemented sending functionality. Sends a provided <see cref="INetworkMessage"/> strategy
		/// </summary>
		/// <param name="message">Network message to send.</param>
		/// <param name="deliveryMethod">Delivery method to send.</param>
		/// <param name="encrypt">Indicates if the message should be encrypted before being sent.</param>
		/// <param name="channel"></param>
		/// <returns></returns>
		protected override NetSendResult SendMessage(INetworkMessage message, DeliveryMethod deliveryMethod, bool encrypt, byte channel)
		{
			if (this.lidgrenNetworkConnection.Peer.Status != NetPeerStatus.Running)
#if DEBUG || DEBUGBUILD
				throw new InvalidOperationException($"The {this.lidgrenNetworkConnection.GetType().Name} is not currently running.");
#else
				return NetSendResult.FailedNotConnected;
#endif
			NetOutgoingMessage outgoingMessage = this.lidgrenNetworkConnection.Peer.CreateMessage(); //TODO: Create a system to estimate message size.

			//We only need to serialize and send for user-messages
			outgoingMessage.Write(message.SerializeWithVisitor(serializer));

			return this.lidgrenNetworkConnection.SendMessage(outgoingMessage, deliveryMethod.ToLidgren(), channel);
		}
Ejemplo n.º 3
0
        private async Task SendMessageAsync(INetworkMessage message)
        {
            int payloadLength;
            // todo: reuse stream and writer??
            using (var buffer = new MemoryStream(writeBuffer))
            using (var writer = new StreamWriter(buffer, utf8NoBom))
            {
                serializer.Serialize(writer, message);
                writer.Flush();
                payloadLength = (int)buffer.Position;
            }

            await socket.SendAsync(
                new ArraySegment<byte>(writeBuffer, 0, payloadLength),
                WebSocketMessageType.Text,
                true,
                CancellationToken.None);
        }
        /// <summary>
        /// Reads a packet from the given <see cref="INetworkMessage"/>.
        /// </summary>
        /// <param name="message">The message to read from.</param>
        /// <returns>The packet read from the message.</returns>
        public override IIncomingPacket ReadFromMessage(INetworkMessage message)
        {
            message.ThrowIfNull(nameof(message));

            return(new TurnOnDemandPacket(Direction.South));
        }
Ejemplo n.º 5
0
        public override void SendMessage(INetworkMessage message, IRemote recipient, DeliveryMethod method, int sequenceChannel)
        {
            var client = ((Client)recipient).Connection;

            Peer.SendMessage(PrepareMessage(message), client, (NetDeliveryMethod)method, sequenceChannel);
        }
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            if (message is LobbyNotReadyNetworkMessage) {
                _ready.Remove(sender);
                _notReady.Add(sender);
            }

            else if (message is LobbyReadyNetworkMessage) {
                _notReady.Remove(sender);
                _ready.Add(sender);
            }
        }
Ejemplo n.º 7
0
        public override void SendMessage(INetworkMessage message, IEnumerable<IRemote> recipients, DeliveryMethod method, int sequenceChannel)
        {
            if (!recipients.Any()) return;

            var clients = recipients
                .Cast<Client>()
                .Select(x => x.Connection)
                .ToArray();

            Peer.SendMessage(PrepareMessage(message), clients, (NetDeliveryMethod) method, sequenceChannel);
        }
Ejemplo n.º 8
0
 private bool IsFromCorrectPlayer(INetworkMessage message)
 {
     return(message.originConnection == GetCurrentPlayer().connection);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Writes a packet to the given <see cref="INetworkMessage"/>.
 /// </summary>
 /// <param name="packet">The packet to write.</param>
 /// <param name="message">The message to write into.</param>
 public abstract void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message);
Ejemplo n.º 10
0
 /// <summary>
 /// Handles the contents of a network message.
 /// </summary>
 /// <param name="message">The message to handle.</param>
 /// <param name="connection">A reference to the connection from where this message is comming from, for context.</param>
 /// <returns>A value tuple with a value indicating whether the handler intends to respond, and a collection of <see cref="IOutgoingPacket"/>s that compose that response.</returns>
 public abstract (bool IntendsToRespond, IEnumerable <IOutgoingPacket> ResponsePackets) HandleRequest(INetworkMessage message, IConnection connection);
Ejemplo n.º 11
0
 public void BroadcastMessage(INetworkMessage msg) {
     BroadcastMessage(msg, false);
 }
Ejemplo n.º 12
0
        public void SendMessage(INetworkMessage msg, NetConnection recipient, bool guaranteed) {
            NetDeliveryMethod method = (guaranteed ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.UnreliableSequenced);

            // opt - tell the peer the message size
            NetOutgoingMessage outgoing = _peer.CreateMessage();
            outgoing.Write((byte)msg.MessageType);
            msg.Encode(outgoing);

            _peer.SendMessage(outgoing, recipient, method);
        }
Ejemplo n.º 13
0
 public void SendMessage(INetworkMessage msg, NetConnection recipient) {
     SendMessage(msg, recipient, false);
 }
Ejemplo n.º 14
0
 public void SendMessage(INetworkMessage _message)
 {
     stream.BeginWrite(_message.GetBytes(), 0, _message.Size, new AsyncCallback(SentMessage), null);
 }
Ejemplo n.º 15
0
 private void SendMessageToAllListeners(INetworkMessage message)
 {
     foreach (var roomUser in roomUsers.Values)
         roomUser.UserController.QueueTransportMessage(message);
 }
Ejemplo n.º 16
0
        private NetOutgoingMessage PrepareMessage(INetworkMessage message)
        {
            _writerStream.Clear();
            MessageTable.Serialize(_writerStream, message);

            var length = (int) _writerStream.Length;

            var msg = Peer.CreateMessage(length);
            msg.Write(_writerStream.GetBuffer(), 0, length);

            return msg;
        }
Ejemplo n.º 17
0
 public abstract void Send(INetworkMessage message);
Ejemplo n.º 18
0
 /// <summary>
 /// Attempts to decrypt the message using XTea keys.
 /// </summary>
 /// <param name="message">The message to act on.</param>
 /// <param name="key">The key to use.</param>
 /// <returns>True if the message could be decrypted, false otherwise.</returns>
 public static bool XteaDecrypt(this INetworkMessage message, uint[] key)
 {
     var targetSpan = message.Buffer[0..message.Length];
Ejemplo n.º 19
0
 public void BroadcastMessage(INetworkMessage msg, bool guaranteed) {
     foreach(NetConnection connection in _peer.Connections)
         SendMessage(msg, connection, guaranteed);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteCreatureSpeechPacket(this);
 }
Ejemplo n.º 21
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            if (message is LobbyMapDownloadNetworkMessage) {
                var m = (LobbyMapDownloadNetworkMessage)message;
                _mapManager.Save(m.Map);
            }

            if (message is LobbyMapVerifyNetworkMessage) {
                var m = (LobbyMapVerifyNetworkMessage)message;
                _mapManager.HasMap(m.MapHash).ContinueWith(result => {
                    bool hasMap = result.Result;
                    if (hasMap == false) {
                        _context.SendMessage(NetworkMessageRecipient.Server,
                            new LobbyMapDownloadRequestedNetworkMessage());
                    }
                });
            }
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Handles the contents of a network message.
 /// </summary>
 /// <param name="message">The message to handle.</param>
 /// <param name="connection">A reference to the connection from where this message is comming from, for context.</param>
 public override void HandleRequest(INetworkMessage message, IConnection connection)
 {
 }
Ejemplo n.º 23
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            if (message is SubmitCommandsNetworkMessage) {
                SubmitCommandsNetworkMessage m = (SubmitCommandsNetworkMessage)message;

                int offset = Math.Min(_lastSentTurn, m.SubmittedOn + _turnDelay);
                _commands.Add(offset, m.Commands);
            }

            else if (message is AdjustTurnDelayNetworkMessage) {
                AdjustTurnDelayNetworkMessage m = (AdjustTurnDelayNetworkMessage)message;
                TurnDelay = m.NewDelay;
            }
        }
Ejemplo n.º 24
0
 public void HandleNetworkMessage(Player sender, INetworkMessage message) {
     if (message is LobbyMapDownloadRequestedNetworkMessage) {
         _context.SendMessage(sender, new LobbyMapDownloadNetworkMessage() {
             Map = _serializedMap
         });
     }
 }
Ejemplo n.º 25
0
        public override void SendMessage(INetworkMessage message, IRemote recipient, DeliveryMethod method, int sequenceChannel)
        {
            var client = ((Client) recipient).Connection;

            Peer.SendMessage(PrepareMessage(message), client, (NetDeliveryMethod) method, sequenceChannel);
        }
Ejemplo n.º 26
0
        private bool TryParseNetworkMessage(string messageText, out INetworkMessage message)
        {
            /* Let's assume message structure is:
             * {
             *      messagetype: short,
             *      version: byte,
             *      payload: {
             *      
             *          serialised form of message payload type
             *      } 
             */
            short messageType = 0;
            byte version = 0;
            long? correlationId = null;
            JObject payloadJson = null;
            message = null;

            using (var text = new StringReader(messageText))
            using (var reader = new JsonTextReader(text) {CloseInput = true})
            {
                while (reader.Read())
                {
                    if (reader.Value == null || reader.TokenType != JsonToken.PropertyName)
                        continue;

                    var propertyName = reader.Value.ToString();
                    switch (propertyName)
                    {
                        case "messageType":
                            messageType = (short)(reader.ReadAsInt32() ?? 0);
                            if (messageType == 0)
                                return false;
                            break;
                        case "version":
                            version = (byte)(reader.ReadAsInt32() ?? 0);
                            if (version == 0)
                                return false;
                            break;
                        case "correlationId":
                            var correlationAsDecimal = reader.ReadAsDecimal();
                            if (correlationAsDecimal.HasValue)
                                correlationId = (long)correlationAsDecimal.Value;
                            break;
                        case "payload":
                            reader.Read();
                            // todo: better solution to this???
                            payloadJson = JObject.Load(reader);
                            break;
                        default:
                            return false;
                    }
                }
            }

            if (messageType == 0 || version == 0 || payloadJson == null)
                return false;

            var payloadRegistration = MessageFactory.GetPayloadRegistration(messageType, version);
            message = payloadRegistration.CreateMessage(
                correlationId,
                (MessagePayload)serializer.Deserialize(
                    payloadJson.CreateReader(),
                    payloadRegistration.PayloadType));

            return true;
        }
Ejemplo n.º 27
0
 public void HandleNetworkMessage(Player sender, INetworkMessage message) {
     Contract.Requires(message is LobbyLaunchedNetworkMessage);
     IsLaunched = true;
 }
 public void AddMessageRecipient(INetworkMessage inst)
 {
     messageRecipients.Add(inst);
 }
Ejemplo n.º 29
0
 public override byte[] EncodingMessage(INetworkMessage message)
 {
     return(null);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteMessageOfTheDayPacket(this);
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteCharacterListPacket(this);
 }
Ejemplo n.º 32
0
 public PeerMessageReceived(IPEndPoint peerEndPoint, INetworkMessage message, int messageSize) : base(peerEndPoint)
 {
     this.Message     = message;
     this.MessageSize = messageSize;
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteUpdateTilePacket(this);
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Processes an incomming message from the connection.
        /// </summary>
        /// <param name="connection">The connection where the message is being read from.</param>
        /// <param name="inboundMessage">The message to process.</param>
        public override void ProcessMessage(IConnection connection, INetworkMessage inboundMessage)
        {
            connection.ThrowIfNull(nameof(connection));
            inboundMessage.ThrowIfNull(nameof(inboundMessage));

            byte packetType;

            if (!connection.IsAuthenticated || connection.XTeaKey.Sum(b => b) == 0)
            {
                // this is a new connection...
                packetType = inboundMessage.GetByte();

                if (packetType != (byte)IncomingGamePacketType.LogIn)
                {
                    // but this is not the packet we were expecting for a new connection.
                    connection.Close();
                    return;
                }

                // Make a copy of the message in case we fail to decrypt using the first set of keys.
                var messageCopy = inboundMessage.Copy();

                inboundMessage.RsaDecrypt(useCipKeys: this.ProtocolConfiguration.UsingCipsoftRsaKeys);

                if (inboundMessage.GetByte() != 0)
                {
                    // means the RSA decrypt was unsuccessful, lets try with the other set of RSA keys...
                    inboundMessage = messageCopy;

                    inboundMessage.RsaDecrypt(useCipKeys: !this.ProtocolConfiguration.UsingCipsoftRsaKeys);

                    if (inboundMessage.GetByte() != 0)
                    {
                        // These RSA keys are also usuccessful... so give up.
                        connection.Close();
                        return;
                    }
                }
            }
            else
            {
                // Decrypt message using XTea
                inboundMessage.XteaDecrypt(connection.XTeaKey);
                inboundMessage.GetUInt16();
                packetType = inboundMessage.GetByte();
            }

            var handler = this.HandlerSelector.SelectForType(packetType);

            if (handler == null)
            {
                return;
            }

            var(intendsToRespond, responsePackets) = handler.HandleRequest(inboundMessage, connection);

            if (intendsToRespond)
            {
                // Send any responses prepared for this.
                var responseMessage = handler.PrepareResponse(responsePackets);

                connection.Send(responseMessage);
            }
        }
Ejemplo n.º 35
0
 public Task Process(INetworkMessage message, AuthenticationNetworkContext context)
 {
     return(Task.CompletedTask);
 }
Ejemplo n.º 36
0
 protected abstract byte[] ParseMessage(INetworkMessage message);
Ejemplo n.º 37
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteNotationResultPacket(this);
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteInventorySetSlotPacket(this);
 }
Ejemplo n.º 39
0
        /// <summary>
        /// Send the given message to the given recipients.
        /// </summary>
        /// <param name="recipient">The computers that should receive the message.</param>
        /// <param name="message">The message to send.</param>
        public void SendMessage(NetworkMessageRecipient recipient, INetworkMessage message) {
            switch (recipient) {
                case NetworkMessageRecipient.All:
                    if (IsClient) {
                        var msg = CreateMessage(LocalPlayer, message, broadcast: true);
                        _client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
                    }
                    else {
                        var msg = CreateMessage(LocalPlayer, message, broadcast: false);
                        Log<NetworkContext>.Info("Sending message {0} to all connections ({1})",
                            SerializationHelpers.Serialize(message),
                            string.Join(", ", _server.Connections.Select(c => ((Player)c.Tag).Name).ToArray()));

                        _server.SendToAll(msg, NetDeliveryMethod.ReliableOrdered);
                        _dispatcher.InvokeHandlers(LocalPlayer, message);
                    }
                    break;

                case NetworkMessageRecipient.Clients: {
                        if (IsServer == false) {
                            throw new InvalidOperationException("Only the server can send messages to clients");
                        }

                        var msg = CreateMessage(LocalPlayer, message, broadcast: false);
                        NetPeer peer = Peer;

                        // only send the message if we have someone to send it to
                        if (peer.ConnectionsCount > 0) {
                            peer.SendMessage(msg, peer.Connections, NetDeliveryMethod.ReliableOrdered, 0);
                        }
                        break;
                    }

                case NetworkMessageRecipient.Server: {
                        if (IsServer) {
                            _dispatcher.InvokeHandlers(LocalPlayer, message);
                        }

                        else {
                            var msg = CreateMessage(LocalPlayer, message, broadcast: false);
                            _client.ServerConnection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, 0);
                        }
                        break;
                    }
            }
        }
Ejemplo n.º 40
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            Log<PlayerManager>.Info("PlayerManager got message " + message);

            if (message is PlayerJoinedNetworkMessage) {
                Player player = ((PlayerJoinedNetworkMessage)message).Player;
                _players.Add(player);
            }

            else if (message is PlayerLeftNetworkMessage) {
                Player player = ((PlayerLeftNetworkMessage)message).Player;
                _players.Remove(player);
            }
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Send the given message to only the specified recipient.
        /// </summary>
        /// <param name="recipient">The player that should receive the message.</param>
        /// <param name="message">Who to send the message to.</param>
        public void SendMessage(Player recipient, INetworkMessage message) {
            // If we're sending the message to ourselves (strange, but fine), then just directly
            // invoke the handlers -- there is not going to be a network connection
            if (recipient == LocalPlayer) {
                _dispatcher.InvokeHandlers(LocalPlayer, message);
            }

            // Otherwise, lookup the network connection and send the message to that connection
            else {
                NetOutgoingMessage msg = CreateMessage(LocalPlayer, message, broadcast: false);
                NetConnection connection = GetConnection(recipient);
                connection.SendMessage(msg, NetDeliveryMethod.ReliableOrdered, 0);
            }
        }
Ejemplo n.º 42
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WritePlayerStatsPacket(this);
 }
Ejemplo n.º 43
0
        /// <summary>
        /// Creates an outgoing message with the given sender, message, broadcast state.
        /// </summary>
        /// <param name="sender">The player who is sending this message.</param>
        /// <param name="message">The message to send.</param>
        /// <param name="broadcast">If the server receives this message, should it broadcast it out
        /// to all clients?</param>
        private NetOutgoingMessage CreateMessage(Player sender, INetworkMessage message, bool broadcast) {
            string serialized = SerializationHelpers.Serialize(new NetworkMessageFormat() {
                IfServerRebroadcast = broadcast,
                Sender = sender,
                NetworkMessage = message
            });

            NetPeer peer = Peer;
            NetOutgoingMessage msg = peer.CreateMessage();
            msg.Write(serialized);
            return msg;
        }
Ejemplo n.º 44
0
        /// <summary>
        /// Reads a packet from the given <see cref="INetworkMessage"/>.
        /// </summary>
        /// <param name="message">The message to read from.</param>
        /// <returns>The packet read from the message.</returns>
        public override IIncomingPacket ReadFromMessage(INetworkMessage message)
        {
            message.ThrowIfNull(nameof(message));

            return(message.ReadAsBytesInfo());
        }
Ejemplo n.º 45
0
 public Task Process(INetworkMessage message, GameNetworkContext context)
 {
     return(Task.CompletedTask);
 }
Ejemplo n.º 46
0
 public void ReceiveMessage(BaseProtocolChannel channel, INetworkMessage message)
 {
     messageQueue.Enqueue(message);
 }
Ejemplo n.º 47
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteRemoveAtStackposPacket(this);
 }
Ejemplo n.º 48
0
        /// <summary>
        /// Reads a packet from the given <see cref="INetworkMessage"/>.
        /// </summary>
        /// <param name="message">The message to read from.</param>
        /// <returns>The packet read from the message.</returns>
        public override IInboundPacket ReadFromMessage(INetworkMessage message)
        {
            message.ThrowIfNull(nameof(message));

            return(new WalkOnDemandPacket(Direction.NorthEast));
        }
Ejemplo n.º 49
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteAnimatedTextPacket(this);
 }
Ejemplo n.º 50
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            if (message is EndTurnNetworkMessage) {
                _updates.Enqueue(((EndTurnNetworkMessage)message).Commands);
            }

            if (message is AdjustTurnDelayNetworkMessage) {
                TurnDelay = ((AdjustTurnDelayNetworkMessage)message).NewDelay;
            }
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteAddItemPacket(this);
 }
Ejemplo n.º 52
0
        /// <summary>
        /// Invoke all registered INetworkMessageHandlers for the given message and sender.
        /// </summary>
        public void InvokeHandlers(Player sender, INetworkMessage message) {
            var handlers = GetHandlers(message.GetType());

            if (handlers.Count == 0) {
                Log<NetworkMessageDispatcher>.Warn("No handlers for message " + message);
            }

            for (int i = 0; i < handlers.Count; ++i) {
                handlers[i].HandleNetworkMessage(sender, message);
            }
        }
Ejemplo n.º 53
0
 public PeerMessageSendFailure(IPEndPoint peerEndPoint, INetworkMessage message, System.Exception exception) : base(peerEndPoint) {
    this.Message = message;
    this.Exception = exception;
 }
Ejemplo n.º 54
0
        public void QueueMessage(INetworkMessage message)
        {

            messageQueue.Post(message);
        }
Ejemplo n.º 55
0
        /// <summary>
        /// Handles the contents of a network message.
        /// </summary>
        /// <param name="message">The message to handle.</param>
        /// <param name="connection">A reference to the connection from where this message is comming from, for context.</param>
        /// <returns>A value tuple with a value indicating whether the handler intends to respond, and a collection of <see cref="IOutgoingPacket"/>s that compose that response.</returns>
        public override (bool IntendsToRespond, IEnumerable <IOutgoingPacket> ResponsePackets) HandleRequest(INetworkMessage message, IConnection connection)
        {
            var lookAtInfo = message.ReadLookAtInfo();

            IThing thing = null;

            var responsePackets = new List <IOutgoingPacket>();

            if (!(this.CreatureFinder.FindCreatureById(connection.PlayerId) is IPlayer player))
            {
                return(false, null);
            }

            this.Logger.Debug($"Player {player.Name} looking at thing with id: {lookAtInfo.ThingId}. {lookAtInfo.Location}");

            if (lookAtInfo.Location.Type != LocationType.Map || player.CanSee(lookAtInfo.Location))
            {
                IContainerItem container;

                // Get thing at location
                switch (lookAtInfo.Location.Type)
                {
                case LocationType.Map:
                    thing = this.TileAccessor.GetTileAt(lookAtInfo.Location, out ITile targetTile) ? targetTile.GetTopThingByOrder(this.CreatureFinder, lookAtInfo.StackPosition) : null;
                    break;

                case LocationType.InsideContainer:
                    container = player.GetContainerById(lookAtInfo.Location.ContainerId);

                    thing = container?[lookAtInfo.Location.ContainerIndex];
                    break;

                case LocationType.InventorySlot:
                    container = player.Inventory[lookAtInfo.Location.Slot] as IContainerItem;

                    thing = container?.Content.FirstOrDefault();
                    break;
                }

                if (thing != null)
                {
                    responsePackets.Add(new TextMessagePacket(MessageType.DescriptionGreen, $"You see {thing.InspectionText}."));
                }
            }

            return(responsePackets.Any(), responsePackets);
        }
 public void RemoveMessageRecipient(INetworkMessage inst)
 {
     messageRecipients.Remove(inst);
 }
Ejemplo n.º 57
0
 /// <summary>
 /// Writes the packet to the message provided.
 /// </summary>
 /// <param name="message">The message to write this packet to.</param>
 public void WriteToMessage(INetworkMessage message)
 {
     message.WriteAddCreaturePacket(this);
 }
Ejemplo n.º 58
0
        public override void SendMessage(INetworkMessage message, DeliveryMethod method, int sequenceChannel)
        {
            if (ConnectionStatus != Networking.ConnectionStatus.Connected) return;

            _writerStream.Clear();
            MessageTable.Serialize(_writerStream, message);

            var length = (int) _writerStream.Length;

            var msg = Peer.CreateMessage(length);
            msg.Write(_writerStream.GetBuffer(), 0, length);

            Peer.SendMessage(msg, (NetDeliveryMethod) method, sequenceChannel);
        }
Ejemplo n.º 59
0
 public virtual void AddNetworkMessageRecipient(INetworkMessage recipient)
 {
     networkInterface.AddMessageRecipient(recipient);
 }