Exemplo n.º 1
0
        /// <summary>
        /// Drops an item from the inventory onto the ground.
        /// </summary>
        /// <param name="slot">The slot of the item to drop.</param>
        /// <param name="amount">The amount of the item in the slot to drop.</param>
        public void Drop(InventorySlot slot, byte amount)
        {
            // Check for a valid item
            var item = this[slot];

            if (item == null)
            {
                return;
            }

            // Drop
            using (var pw = ClientPacket.DropInventoryItem(slot, amount))
            {
                _socket.Send(pw, ClientMessageType.GUIItems);
            }
        }
Exemplo n.º 2
0
        internal virtual void SendPacket(RtpPacket rtpPacket)
        {
            rtpPacket.SSRC     = ssrc;
            rtpPacket.Sequence = seq++;

            rtpNetworkSender.Send((BufferChunk)rtpPacket);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Synchronizes the User's stat values to the client.
        /// </summary>
        public void UpdateClient(INetworkSender sendTo)
        {
            if (!_anyStatsChanged)
            {
                return;
            }

            // Check if any stat values have changed
            var statsToUpdate = _changedStats.GetChangedStats();

            if (statsToUpdate.IsEmpty())
            {
                return;
            }

            // Build a packet containing all the new stat values and send it to the user
            using (var pw = ServerPacket.GetWriter())
            {
                foreach (var stat in statsToUpdate)
                {
                    ServerPacket.UpdateStat(pw, stat, StatCollectionType);
                }

                sendTo.Send(pw, ServerMessageType.GUIUserStats);
            }

            _anyStatsChanged = false;
        }
 /// <summary>
 /// Sends data to the <see cref="INetworkSender"/>. This method is thread-safe.
 /// </summary>
 /// <param name="sender">The <see cref="INetworkSender"/> to use to send the data.</param>
 /// <param name="message">GameMessage to send to the User.</param>
 /// <param name="messageType">The <see cref="ServerMessageType"/> to use for sending the <paramref name="message"/>.</param>
 /// <param name="parameters">Message parameters.</param>
 public static void Send(this INetworkSender sender, GameMessage message, ServerMessageType messageType,
                         params object[] parameters)
 {
     using (var pw = ServerPacket.SendMessage(message, parameters))
     {
         sender.Send(pw, messageType);
     }
 }
Exemplo n.º 5
0
            /// <summary>
            /// Handles synchronizing the paper-doll information to a single client.
            /// </summary>
            /// <param name="client">The client to send the information to</param>
            internal void SynchronizeBodyLayersTo(INetworkSender client)
            {
                // Get the values to send
                var bodiesToSend = _bodies.Where(x => x != null);

                if (bodiesToSend.Count() == 0)
                {
                    return;
                }

                // Send the paper-doll information
                using (var pw = ServerPacket.SetCharacterPaperDoll(_character.MapEntityIndex, bodiesToSend))
                {
                    client.Send(pw, ServerMessageType.MapDynamicEntityProperty);
                }
            }
Exemplo n.º 6
0
        /// <summary>
        /// Sends a list of guild member names and ranks to a <see cref="User"/>.
        /// </summary>
        /// <param name="user">The user to send the information to.</param>
        /// <param name="header">The heading to give the list.</param>
        /// <param name="members">The guild members and their ranks to include in the list.</param>
        static void SendGuildMemberList(INetworkSender user, string header, IEnumerable <GuildMemberNameRank> members)
        {
            // Build the string
            var sb = new StringBuilder();

            sb.AppendLine(header);

            foreach (var member in members)
            {
                sb.AppendLine(string.Format("{0}: {1}", member.Name, member.Rank));
            }

            // Send
            using (var pw = ServerPacket.Chat(sb.ToString()))
            {
                user.Send(pw, ServerMessageType.GUI);
            }
        }
        /// <summary>
        /// Sends data to the <see cref="INetworkSender"/>. This method is thread-safe.
        /// </summary>
        /// <param name="sender">The <see cref="INetworkSender"/> to use to send the data.</param>
        /// <param name="data">BitStream containing the data to send to the User.</param>
        /// <param name="messageType">The <see cref="ServerMessageType"/> to use for sending the <paramref name="data"/>.</param>
        public static void Send(this INetworkSender sender, BitStream data, ServerMessageType messageType)
        {
            if (!sender.IsConnected)
            {
                const string errmsg = "Send to `{0}` failed - not connected.";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, sender);
                }
                return;
            }

            NetDeliveryMethod method;
            int seqChannel;

            messageType.GetDeliveryMethod(out method, out seqChannel);

            sender.Send(data, method, seqChannel);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Collects the Rtcp data from the session, assembles it into CompoundPackets (via the
        /// CompoundPacketBuilder) and sends the packets
        ///
        /// The current design has a "forced" Send occurring on the thread that makes the call, and
        /// a normal Send occurring on the dedicated RtcpSender thread.
        ///
        /// To make sure that multiple threads aren't making the call at the same time, which can
        /// lead to data access exceptions (e.g. Queue empty), we lock here.
        /// </summary>
        /// <param name="forced">Is Send being called due to timing rules, or forced?</param>
        private void Send(bool forced)
        {
            lock (this)
            {
                try
                {
                    // We're Sending despite timing rules
                    if (forced)
                    {
                        lastSendForced = true;
                    }
                    else // We're Sending due to timing rules
                    {
                        // The timing rules may now be in conflict with a previous forced Send
                        // Ask the timing rules to reconsider again before Sending
                        if (lastSendForced)
                        {
                            lastSendForced = false;
                            return;
                        }
                    }

                    CompoundPacketBuilder cpb = rtpSession.RtcpReportIntervalReached();
                    cpb.BuildCompoundPackets();

                    Debug.Assert(cpb.PacketCount > 0);

                    // Send all compound packets (in case there is more than 1)
                    short packetCount = cpb.PacketCount;
                    int   bytes       = 0;

                    foreach (CompoundPacket cp in cpb)
                    {
                        BufferChunk data = cp.Data;
                        bytes += data.Length;
                        rtcpNetworkSender.Send(data);

                        if (diagnosticSender != null)
                        {
                            // andrew: send a "carbon-copy" to the diagnostic server
                            // this is done over unicast to avoid entangling diagnosis with multicast
                            diagnosticSender.Send(data);
                        }
                    }

                    // How long between the last send time and now
                    TimeSpan interval = DateTime.Now - lastSendTime;

                    // Update lastSendTime
                    lastSendTime = DateTime.Now;

                    // Update performance data
                    // Packets before bytes, since packets doesn't have any dependencies
                    // but BytesPerPacket requires a correct reading on the packet count
                    UpdatePerformancePackets(packetCount);
                    UpdatePerformanceBytes(bytes);
                    UpdatePerformanceInterval(interval, forced);
                }
                catch (ThreadAbortException) {}
                catch (Exception e)
                {
                    // AAA debugging only
                    System.Console.WriteLine(e.StackTrace);

                    if (e is System.Net.Sockets.SocketException)
                    {
                        Object[] args = new Object[] { this, new RtpEvents.HiddenSocketExceptionEventArgs((RtpSession)rtpSession,
                                                                                                          (System.Net.Sockets.SocketException)e) };
                        EventThrower.QueueUserWorkItem(new RtpEvents.RaiseEvent(RtpEvents.RaiseHiddenSocketExceptionEvent), args);
                    }

                    rtpSession.LogEvent("RtcpSender", e.ToString(), EventLogEntryType.Error, (int)RtpEL.ID.Error);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Sends a list of guild member names and ranks to a <see cref="User"/>.
        /// </summary>
        /// <param name="user">The user to send the information to.</param>
        /// <param name="header">The heading to give the list.</param>
        /// <param name="members">The guild members and their ranks to include in the list.</param>
        static void SendGuildMemberList(INetworkSender user, string header, IEnumerable<GuildMemberNameRank> members)
        {
            // Build the string
            var sb = new StringBuilder();
            sb.AppendLine(header);

            foreach (var member in members)
            {
                sb.AppendLine(string.Format("{0}: {1}", member.Name, member.Rank));
            }

            // Send
            using (var pw = ServerPacket.Chat(sb.ToString()))
            {
                user.Send(pw, ServerMessageType.GUI);
            }
        }
 /// <summary>
 /// Sends data to the <see cref="INetworkSender"/>. This method is thread-safe.
 /// </summary>
 /// <param name="sender">The <see cref="INetworkSender"/> to use to send the data.</param>
 /// <param name="message">GameMessage to send to the User.</param>
 /// <param name="messageType">The <see cref="ServerMessageType"/> to use for sending the <paramref name="message"/>.</param>
 public static void Send(this INetworkSender sender, GameMessage message, ServerMessageType messageType)
 {
     sender.Send(message, messageType, null);
 }