Ejemplo n.º 1
0
        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="formatType">The broadcast format type</param>
        /// <param name="text">The specific area details based on the type</param>
        public broadcast_area_identifier(BroadcastArea formatType, string text)
            : base(TlvTag)
        {
            SmppWriter writer = new SmppWriter(Data, true);

            writer.Add((byte)formatType);
            if (text.Length > (MAX_LENGTH - 1))
            {
                text = text.Substring(0, MAX_LENGTH - 1);
            }
            writer.Add(text, false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a packet to clients
        /// </summary>
        /// <param name="target">the target from which area will be calculated</param>
        /// <param name="packet">packet data</param>
        /// <param name="area">the target area</param>
        public void Send(GameObject target, PacketStream packet, BroadcastArea area)
        {
            byte[] data = packet.GetPacket().ToArray();

            ConsoleUtils.HexDump(data, "Sent to Client");

            List<Player> players = new List<Player>();
            // Gets the list of players who will receive this packet
            switch (area)
            {
                case BroadcastArea.Self:
                    if (target.ObjType != ObjectType.Player)
                    {
                        ConsoleUtils.ShowError("Trying to send packet to a non-player object.");
                        return;
                    }
                    players.Add((Player)target);
                    break;
                case BroadcastArea.Region:
                    // TODO : Get players in region
                    if (target.ObjType == ObjectType.Player)
                        players.Add((Player)target);
                    break;
                case BroadcastArea.World:
                    // TODO : Get all players in the server
                    if (target.ObjType == ObjectType.Player)
                        players.Add((Player)target);
                    break;
                default:
                    ConsoleUtils.ShowError("Unknown Broadcast Area.");
                    return;
            }

            // Sends data to every client in the list
            foreach (Player client in players)
            {
                client.NetData.ClSocket.BeginSend(
                    client.NetData.OutCipher.DoCipher(ref data),
                    0,
                    data.Length,
                    0,
                    new AsyncCallback(SendCallback),
                    client
                );
            }
        }