Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="vicinityChatMessage">
        /// </param>
        private void DistributeVicinityChat(VicinityChatMessage vicinityChatMessage)
        {
            byte[] packet = MsgVicinity.Create(
                (uint)vicinityChatMessage.SenderId,
                vicinityChatMessage.Text,
                (byte)vicinityChatMessage.MessageType);

            string lookup = CharacterDao.Instance.GetCharacterNameById(vicinityChatMessage.SenderId);

            byte[] nameLookup = NameLookupResult.Create((uint)vicinityChatMessage.SenderId, lookup);

            foreach (int charId in vicinityChatMessage.CharacterIds)
            {
                foreach (Client cli in this.ConnectedClients.Values)
                {
                    if (cli.Character.CharacterId == charId)
                    {
                        if (!cli.KnownClients.Contains((uint)vicinityChatMessage.SenderId))
                        {
                            // Name lookup
                            cli.Send(nameLookup);
                            cli.KnownClients.Add((uint)vicinityChatMessage.SenderId);
                        }

                        cli.Send(packet);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handler
        /// </summary>
        /// <param name="s">
        /// </param>
        /// <param name="a">
        /// </param>
        private void ISCClient_OnMessage(object s, OnMessageArgs a)
        {
            Console.WriteLine("[ISComm] Packet '" + a.ID + "' catched.");
            switch (a.ID)
            {
            case 0x0F:
            {
                MemoryStream stream = new MemoryStream(a.Data);
                BinaryReader reader = new BinaryReader(stream);

                uint   senderId        = reader.ReadUInt32();
                byte   msgType         = reader.ReadByte();
                short  receiversAmount = reader.ReadInt16();
                uint[] receivers       = new uint[receiversAmount];

                for (int i = 0; i < receiversAmount; i++)
                {
                    receivers[i] = reader.ReadUInt32();
                }

                string msg = reader.ReadString();
                stream.Close();
                reader.Close();

                string lookup = string.Empty;
                foreach (Client cli in this.server.Clients)
                {
                    if (cli.Character.characterId == senderId)
                    {
                        lookup = cli.Character.characterName;
                    }
                }

                byte[] namelookup = NameLookupResult.Create(senderId, lookup);

                Console.WriteLine("Got chat from ZoneEngine: " + msg);
                byte[] packet = MsgVicinity.Create(senderId, msg, msgType);

                foreach (uint sendto in receivers)
                {
                    foreach (Client cli in this.server.Clients)
                    {
                        if (cli.Character.characterId == sendto)
                        {
                            if (!cli.KnownClients.Contains(senderId))
                            {
                                cli.Send(namelookup);         // sending a namelookup ahead of the message
                                cli.KnownClients.Add(senderId);
                            }

                            cli.Send(packet);
                        }
                    }
                }
            }

            break;

            // Add characters to Team chat channel
            case 0xF0:
                PacketReader packetReader = new PacketReader(ref a.Data);

                List <uint> charIds       = new List <uint>();
                uint        numberofchars = packetReader.ReadUInt32();
                while (numberofchars > 0)
                {
                    charIds.Add(packetReader.ReadUInt32());
                }
                uint[] chars = charIds.ToArray();

                // Commented out to remove compile error.
                // Lists.ChatChannels.CreateTeamChannel(NextTeamId(),chars);


                break;
            }
        }