示例#1
0
        /// <summary>
        /// Read and send back Player name lookup packet
        /// </summary>
        /// <param name="client">
        /// Client sending
        /// </param>
        /// <param name="packet">
        /// Packet data
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16(); // packet ID
            reader.ReadUInt16(); // data length
            uint   playerId   = uint.MaxValue;
            string playerName = reader.ReadString();

            if (playerName == string.Empty)
            {
                return;
            }

            if (playerName == ConfigReadWrite.Instance.CurrentConfig.RelayBotNick)
            {
                byte[] botlookup = NameLookupResult.Create(
                    0x80000000,
                    ConfigReadWrite.Instance.CurrentConfig.RelayBotNick);
                client.Send(botlookup);
                client.Send(BuddyOnlineStatus.Create(0x80000000, 1, new byte[] { 0x00, 0x01, 0x00 }));
                return;
            }

            client.Server.Debug(
                client,
                "{0} >> PlayerNameLookup: PlayerName: {1}",
                client.Character.characterName,
                playerName);
            reader.Finish();

            DBCharacter character = CharacterDao.GetByCharName(playerName);

            if (character != null)
            {
                playerId = (uint)character.Id;
            }

            byte[] namelookup = NameLookupResult.Create(playerId, playerName);
            client.Send(namelookup);
            client.Send(
                BuddyOnlineStatus.Create(
                    playerId,
                    (uint)OnlineDao.IsOnline((int)playerId).Online,
                    new byte[] { 0x00, 0x01, 0x00 }));
            client.KnownClients.Add(playerId);
        }
示例#2
0
        /// <summary>
        /// Read and process Tell message
        /// </summary>
        /// <param name="client">
        /// Client sending
        /// </param>
        /// <param name="packet">
        /// Packet data
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16();
            reader.ReadUInt16();
            uint   playerId = reader.ReadUInt32();
            string message  = reader.ReadString();

            client.Server.Debug(client, "{0} >> Tell: PlayerId: {1}", client.Character.characterName, playerId);
            reader.Finish();
            if (client.ChatServer().ConnectedClients.ContainsKey(playerId))
            {
                Client tellClient = (Client)client.ChatServer().ConnectedClients[playerId];
                if (!tellClient.KnownClients.Contains(client.Character.CharacterId))
                {
                    byte[] pname = PlayerName.Create(client, client.Character.CharacterId);
                    tellClient.Send(pname);
                    tellClient.KnownClients.Add(client.Character.CharacterId);

                    // TODO: Check if status bytes are correct even for offline chars
                    client.Send(
                        BuddyOnlineStatus.Create(
                            (uint)tellClient.Character.CharacterId,
                            (uint)OnlineDao.IsOnline((int)tellClient.Character.CharacterId).Online,
                            new byte[] { 0x00, 0x01, 0x00 }));
                }

                byte[] pgroup = MsgPrivateGroup.Create(client.Character.CharacterId, message, string.Empty);
                tellClient.Send(pgroup);
            }
            else
            {
                byte[] sysmsg = MsgSystem.Create("Player not online.");
                client.Send(sysmsg);
            }
        }