Example #1
0
        public void WithdrawMoney(Character withdrawer, GameObject bankObj, uint withdrawl)
        {
            if (!GuildBank.CheckBankObj(withdrawer, bankObj) || withdrawl == 0U || this.Guild.Money < (long)withdrawl)
            {
                return;
            }
            GuildMember guildMember = withdrawer.GuildMember;

            if (guildMember == null)
            {
                return;
            }
            this.Guild.Money -= (long)withdrawl;
            withdrawer.AddMoney(withdrawl);
            guildMember.BankMoneyWithdrawlAllowance -= withdrawl;
            this.BankLog.LogEvent(GuildBankLogEntryType.WithdrawMoney, withdrawer, withdrawl, (ItemRecord)null, 0,
                                  (GuildBankTab)null);
            GuildHandler.SendMemberRemainingDailyWithdrawlAllowance((IPacketReceiver)withdrawer,
                                                                    guildMember.BankMoneyWithdrawlAllowance);
            GuildHandler.SendGuildBankTabNames(withdrawer, bankObj);
            GuildHandler.SendGuildBankTabContents(withdrawer, bankObj, (byte)0);
            GuildHandler.SendGuildBankMoneyUpdate(withdrawer, bankObj);
        }
Example #2
0
 /// <summary>
 /// Creates a new GuildRecord row in the database with the given information.
 /// </summary>
 /// <param name="leader">leader's character record</param>
 /// <param name="name">the name of the new character</param>
 /// <returns>the <seealso cref="T:WCell.RealmServer.Guilds.Guild" /> object</returns>
 public Guild(CharacterRecord leader, string name)
     : this(true)
 {
     this._created     = DateTime.Now;
     this._id          = Guild._idGenerator.Next();
     this._leaderLowId = (int)leader.EntityLowId;
     this._name        = name;
     this._tabard      = new GuildTabard();
     this._MOTD        = "Default MOTD";
     this._info        = "Default info";
     this._level       = (byte)1;
     this.m_ranks      = GuildMgr.CreateDefaultRanks(this);
     foreach (ActiveRecordBase rank in this.m_ranks)
     {
         rank.CreateLater();
     }
     this.Register();
     this.m_leader         = this.AddMember(leader);
     this.Leader.Character = World.GetCharacter(leader.Name, true);
     this.m_leader.RankId  = 0;
     this._clanCrest       = new byte[40];
     this.CreateLater();
 }
Example #3
0
        public void WithdrawMoney(Character withdrawer, GameObject bankObj, uint withdrawl)
        {
            if (!CheckBankObj(withdrawer, bankObj) || withdrawl == 0U || Guild.Money < withdrawl)
            {
                return;
            }
            GuildMember guildMember = withdrawer.GuildMember;

            if (guildMember == null)
            {
                return;
            }
            Guild.Money -= withdrawl;
            withdrawer.AddMoney(withdrawl);
            guildMember.BankMoneyWithdrawlAllowance -= withdrawl;
            BankLog.LogEvent(GuildBankLogEntryType.WithdrawMoney, withdrawer, withdrawl, null, 0,
                             null);
            GuildHandler.SendMemberRemainingDailyWithdrawlAllowance(withdrawer,
                                                                    guildMember.BankMoneyWithdrawlAllowance);
            GuildHandler.SendGuildBankTabNames(withdrawer, bankObj);
            GuildHandler.SendGuildBankTabContents(withdrawer, bankObj, 0);
            GuildHandler.SendGuildBankMoneyUpdate(withdrawer, bankObj);
        }
Example #4
0
        /// <summary>
        /// Checks whether the given target exists in requester's guild and whether the given requestMember has needed privs
        /// Sends result of action to the requester
        /// </summary>
        /// <param name="reqChar">requester's character, can be null. If null, sending result is suppressed</param>
        /// <param name="targetChar">target's character, can be null</param>
        /// <param name="targetName">target character's name</param>
        /// <param name="commandId">executed command. Used for sending result</param>
        /// <param name="reqPrivs">priviliges required for executing this action</param>
        /// <param name="canAffectSelf">can this action be executed on self?</param>
        /// <returns>result of operation</returns>
        public static GuildResult CheckAction(Character reqChar, Character targetChar, string targetName,
                                              GuildCommandId commandId, GuildPrivileges reqPrivs, bool canAffectSelf)
        {
            GuildMember guildMember = reqChar.GuildMember;
            GuildResult resultCode;

            if (guildMember == null)
            {
                resultCode = GuildResult.PLAYER_NOT_IN_GUILD;
                targetName = string.Empty;
            }
            else if (targetChar == null)
            {
                resultCode = GuildResult.PLAYER_NOT_FOUND;
            }
            else if (!canAffectSelf && reqChar == targetChar)
            {
                resultCode = GuildResult.PERMISSIONS;
            }
            else if (reqChar.Guild != targetChar.Guild)
            {
                resultCode = GuildResult.PLAYER_NOT_IN_GUILD;
            }
            else
            {
                if (guildMember.HasRight(reqPrivs))
                {
                    return(GuildResult.SUCCESS);
                }
                resultCode = GuildResult.PERMISSIONS;
                targetName = string.Empty;
            }

            GuildHandler.SendResult((IPacketReceiver)reqChar.Client, commandId, targetName, resultCode);
            return(resultCode);
        }
Example #5
0
        public void SwapItemsManualBankToBank(Character chr, GameObject bankObj, byte fromBankTabId, byte fromTabSlot,
                                              byte toBankTabId, byte toTabSlot, uint itemEntryId, byte amount)
        {
            if (!GuildBank.CheckBankObj(chr, bankObj))
            {
                return;
            }
            GuildMember guildMember = chr.GuildMember;

            if (guildMember == null)
            {
                return;
            }
            GuildRank rank = guildMember.Rank;

            if (rank == null)
            {
                return;
            }
            GuildBankTab intoTab1 = this[(int)fromBankTabId];

            if (intoTab1 == null)
            {
                return;
            }
            GuildBankTab intoTab2 = this[(int)toBankTabId];

            if (intoTab2 == null || fromTabSlot >= (byte)98 || toTabSlot >= (byte)98)
            {
                return;
            }
            GuildBankTabRights[] bankTabRights = rank.BankTabRights;
            if (!bankTabRights[(int)fromBankTabId].Privileges.HasFlag((Enum)GuildBankTabPrivileges.ViewTab) ||
                bankTabRights[(int)fromBankTabId].WithdrawlAllowance <= 0U || !bankTabRights[(int)toBankTabId]
                .Privileges.HasFlag((Enum)GuildBankTabPrivileges.DepositItem))
            {
                return;
            }
            ItemRecord itemRecord1 = intoTab1[(int)fromTabSlot];

            if (itemRecord1 == null || (int)itemRecord1.EntryId != (int)itemEntryId ||
                itemRecord1.Amount < (int)amount)
            {
                return;
            }
            if (amount == (byte)0)
            {
                amount = (byte)itemRecord1.Amount;
            }
            bool flag = (int)fromBankTabId == (int)toBankTabId;

            if (flag)
            {
                if ((int)fromTabSlot == (int)toTabSlot)
                {
                    return;
                }
                ItemRecord itemRecord2 = intoTab2.StoreItemInSlot(itemRecord1, (int)amount, (int)toTabSlot, true);
                intoTab1[(int)fromTabSlot] = itemRecord2;
            }
            else
            {
                if (intoTab2.CheckStoreItemInSlot(itemRecord1, (int)amount, (int)toTabSlot, true))
                {
                    ItemRecord itemRecord2 = intoTab2.StoreItemInSlot(itemRecord1, (int)amount, (int)toTabSlot, true);
                    intoTab1[(int)fromTabSlot] = itemRecord2;
                }
                else
                {
                    if (!bankTabRights[(int)fromBankTabId].Privileges
                        .HasFlag((Enum)GuildBankTabPrivileges.DepositItem) ||
                        bankTabRights[(int)toBankTabId].WithdrawlAllowance <= 0U)
                    {
                        return;
                    }
                    ItemRecord itemRecord2 = intoTab2.StoreItemInSlot(itemRecord1, (int)amount, (int)toTabSlot, true);
                    intoTab1[(int)fromTabSlot] = itemRecord2;
                    if (itemRecord2 != itemRecord1)
                    {
                        --bankTabRights[(int)toTabSlot].WithdrawlAllowance;
                        --bankTabRights[(int)fromBankTabId].WithdrawlAllowance;
                        this.BankLog.LogEvent(GuildBankLogEntryType.MoveItem, chr, itemRecord1, (int)amount, intoTab2);
                        this.BankLog.LogEvent(GuildBankLogEntryType.MoveItem, chr, itemRecord2, intoTab1);
                        this.Guild.SendGuildBankTabContentUpdateToAll(fromBankTabId, (int)fromTabSlot);
                        this.Guild.SendGuildBankTabContentUpdateToAll(toBankTabId, (int)toTabSlot);
                        return;
                    }
                }

                --bankTabRights[(int)fromBankTabId].WithdrawlAllowance;
            }

            this.BankLog.LogEvent(GuildBankLogEntryType.MoveItem, chr, itemRecord1, (int)amount, intoTab2);
            this.Guild.SendGuildBankTabContentUpdateToAll(fromBankTabId, (int)fromTabSlot,
                                                          flag ? (int)toTabSlot : -1);
        }
Example #6
0
 /// <summary>Removes GuildMember from the guild</summary>
 /// <param name="member">member to remove</param>
 /// <param name="update">if true, sends event to the guild</param>
 public bool RemoveMember(GuildMember member)
 {
     return(this.RemoveMember(member, true, false));
 }
Example #7
0
		/// <summary>
		/// TODO: Fix for 3.3
		/// </summary>
		/// <param name="guild"></param>
		/// <param name="guildEvent"></param>
		/// <param name="affectedMember"></param>
		/// <param name="influencer"></param>
		/// <returns></returns>
		private static RealmPacketOut CreateEventPacket(Guild guild, GuildEvents guildEvent, GuildMember affectedMember, GuildMember influencer)
		{
			var packet = new RealmPacketOut(RealmServerOpCode.SMSG_GUILD_EVENT);

			packet.WriteByte((byte)guildEvent);

			// Next byte is strings count

			switch (guildEvent)
			{
				case GuildEvents.PROMOTION:
				case GuildEvents.DEMOTION:
					packet.Write((byte)3);
					packet.WriteCString(influencer.Name);
					packet.WriteCString(affectedMember.Name);
					packet.WriteCString(affectedMember.Rank.Name);
					break;

				case GuildEvents.MOTD:
					if (guild.MOTD != null)
					{
						packet.Write((byte)1);
						packet.WriteCString(guild.MOTD);
					}
					else
					{
						packet.Write((byte)0);
					}
					break;

				case GuildEvents.JOINED:
				case GuildEvents.LEFT:
				case GuildEvents.ONLINE:
				case GuildEvents.OFFLINE:
					packet.Write((byte)1);
					packet.WriteCString(affectedMember.Name);
					break;

				case GuildEvents.REMOVED:
					packet.Write((byte)2);
					packet.WriteCString(influencer.Name);
					packet.WriteCString(affectedMember.Name);
					break;

				case GuildEvents.LEADER_CHANGED:
					packet.Write((byte)2);
					packet.WriteCString(affectedMember.Name);
					packet.WriteCString(influencer.Name);
					break;

				default:
					packet.Write((byte)0);
					break;
			}

			return packet;
		}
Example #8
0
		private static RealmPacketOut CreateEventPacket(Guild guild, GuildEvents guildEvent, GuildMember affectedMember)
		{
			return CreateEventPacket(guild, guildEvent, affectedMember, null);
		}
Example #9
0
		/// <summary>
		/// Sends event connected with guilds to all guild members, except one
		/// </summary>
		/// <param name="guild">guild</param>
		/// <param name="guildEvent">event that happened</param>
		/// <param name="affectedMember">The <see cref="GuildMember"/> which was affected</param>
		/// <param name="ignoredCharacter">character to be ignored</param>
		public static void SendEventToGuild(Guild guild, GuildEvents guildEvent, GuildMember affectedMember, Character ignoredCharacter)
		{
			using (RealmPacketOut packet = CreateEventPacket(guild, guildEvent, affectedMember))
			{
				guild.Broadcast(packet, ignoredCharacter);
			}
		}
Example #10
0
		/// <summary>
		/// Sends event connected with guilds to all guild members
		/// </summary>
		/// <param name="guild">guild</param>
		/// <param name="guildEvent">event that happened</param>
		/// <param name="affectedMember">The <see cref="GuildMember"/> which was affected</param>
		public static void SendEventToGuild(Guild guild, GuildEvents guildEvent, GuildMember affectedMember)
		{
			using (var packet = CreateEventPacket(guild, guildEvent, affectedMember))
			{
				guild.Broadcast(packet);
			}
		}
Example #11
0
		/// <summary>
		/// Sends events connected with guilds
		/// </summary>
		/// <param name="client">the client to send to</param>
		/// <param name="guild">guild</param>
		/// <param name="guildEvent">event that happened</param>
		/// <param name="affectedMember">The <see cref="GuildMember"/> which was affected</param>
		public static void SendEvent(IPacketReceiver client, Guild guild, GuildEvents guildEvent, GuildMember affectedMember)
		{
			using (RealmPacketOut packet = CreateEventPacket(guild, guildEvent, affectedMember))
			{
				client.Send(packet);
			}
		}
Example #12
0
		/// <summary>
		/// Sends event connected with guilds to all guild members. Use this one for promotion/demotion events.
		/// </summary>
		/// <param name="guild">guild</param>
		/// <param name="guildEvent">event that happened</param>
		/// <param name="affectedMember">The <see cref="GuildMember"/> which was affected</param>
		/// <param name="influencer">one who caused this event</param>
		public static void SendEventToGuild(Guild guild, GuildEvents guildEvent, GuildMember affectedMember, GuildMember influencer)
		{
			using (var packet = CreateEventPacket(guild, guildEvent, affectedMember, influencer))
			{
				guild.SendAll(packet);
			}
		}
Example #13
0
		private static void SendGuildBankTabContentUpdate(GuildMember member, byte tabId, int slot1, int slot2)
		{
			// lock-free synchronization
			// don't mess with it, unless you know what you are doing
			var guild = member.Guild;
			if (guild == null) return;

			var rank = member.Rank;
			if (rank == null) return;


			using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_GUILD_BANK_LIST))
			{
				packet.Write(guild.Money);
				packet.Write(tabId);

				packet.Write(rank.BankTabRights[tabId].WithdrawlAllowance);
				packet.Write(false); // hasTabnames = false;

				var list = new List<int> 
				{
					slot1
                };

				if (slot2 != -1)
				{
					list.Add(slot2);
					list.Sort();
				}

				packet.WriteByte((byte)list.Count);
				foreach (var slot in list)
				{
					packet.Write((byte)slot);
					var item = guild.Bank[tabId][slot];

					if (item == null)
					{
						packet.Write(0);
						continue;
					}
					packet.Write(item.EntryId);
					packet.Write((uint)0);

					var randomPropId = item.RandomProperty;
					packet.Write(randomPropId);
					if (randomPropId != 0)
					{
						packet.Write(item.RandomSuffix);
					}

					packet.Write(item.Amount);
					packet.Write((uint)0);
					packet.Write((byte)0);

					if (item.EnchantIds == null)
					{
						packet.Write((byte)0);
						continue;
					}

					var pos = packet.Position;
					var count = 0;
					for (var i = 0; i < 3; ++i)
					{
						if (item.EnchantIds[i] == 0) continue;
						packet.Write((byte)i);
						packet.Write(item.EnchantIds[i]);
						count++;
					}
					packet.InsertByteAt((byte)count, pos, true);

				} // end foreach

				guild.Send(packet);
			} // end using
		}
Example #14
0
 internal void UnregisterGuildMember(GuildMember gm)
 {
     using (membersLock.EnterWriteLock())
         OfflineMembers.Remove(gm.Id);
 }