Exemplo n.º 1
0
        private static void HandleApplicationResponse(GameSession session, PacketReader packet)
        {
            long guildApplicationId = packet.ReadLong();
            byte response           = packet.ReadByte();

            Guild guild = GameServer.GuildManager.GetGuildById(session.Player.Guild.Id);

            if (guild == null)
            {
                return;
            }

            GuildApplication application = guild.Applications.FirstOrDefault(x => x.Id == guildApplicationId);

            if (application == null)
            {
                return;
            }

            Player applier = GameServer.Storage.GetPlayerById(application.CharacterId);

            session.Send(GuildPacket.ApplicationResponse(guildApplicationId, applier.Name, response));
            if (response == 1)
            {
                session.Send(GuildPacket.InviteNotification(applier.Name, response));
            }
            guild.BroadcastPacketGuild(GuildPacket.ApplicationResponseBroadcastNotice(session.Player.Name, applier.Name, response, guildApplicationId));
            application.Remove(applier, guild);

            if (applier.Session != null)
            {
                applier.Session.Send(GuildPacket.ApplicationResponseToApplier(guild.Name, guildApplicationId, response));
            }

            if (response == 0)
            {
                if (applier.Session != null)
                {
                    // TODO: Send System mail for rejection
                }
                return;
            }

            guild.AddMember(applier);
            if (applier.Session != null)
            {
                applier.Session.Send(GuildPacket.InviteResponseConfirm(session.Player, applier, guild, response));
                applier.Session.FieldManager.BroadcastPacket(GuildPacket.UpdateGuildTag2(applier, guild.Name));
            }

            GuildMember member = guild.Members.FirstOrDefault(x => x.Player == applier);

            guild.BroadcastPacketGuild(GuildPacket.MemberBroadcastJoinNotice(member, session.Player.Name, false));
            guild.BroadcastPacketGuild(GuildPacket.MemberJoin(applier));
            guild.BroadcastPacketGuild(GuildPacket.UpdateGuild(guild));
        }