⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailmonitor.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 3 页
字号:
		-- results in in an immediate client side MAIL_INBOX_UPDATE event to change		-- the message to read.		local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(index);		messageWasRead = wasRead;		messageDaysLeft = daysLeft;		if (not messageWasRead) then			-- Queue a task for marking the message as read. We add this to the			-- front of the queue since its a client side operation.			addTask(createWaitForReadMessage(index), true);		end	endend--------------------------------------------------------------------------------- Hooks after reading a message.-------------------------------------------------------------------------------function MailMonitor_PostGetInboxTextHook(funcArgs, retVal, index)	debugPrint("MailMonitor_PostGetInboxTextHook("..nilSafe(index)..") called");	-- We are only interested in unread messages.	getInboxTextRecursionLevel = getInboxTextRecursionLevel - 1;	if (index ~= nil and index > 0 and index <= GetInboxNumItems() and getInboxTextRecursionLevel == 0 and not messageWasRead) then		local isInvoice = retVal[4];		-- If this task has an invoice, get it.		if (isInvoice) then			-- Wait for the invoice if we don't have it yet.			local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(index);			if (not playerName) then				addTask(createWaitForInvoiceTask(index));			end		end		-- Process the message.		local messageAgeInSeconds = math.floor((MAX_DAYS_LEFT - messageDaysLeft) * 24 * 60 * 60);		if (table.getn(InboxTasks) > 0) then			addTask(createProcessMessageTask(index, messageAgeInSeconds));		else			processMailMessage(index, messageAgeInSeconds);		end		-- Consider the message read now.		messageWasRead = true;	endend--------------------------------------------------------------------------------- Hooks deleting a message.-------------------------------------------------------------------------------function MailMonitor_DeleteInboxItemHook(funcArgs, retVal, index)	debugPrint("MailMonitor_DeleteInboxItemHook("..nilSafe(index)..") called");end--------------------------------------------------------------------------------- Adds a task.-------------------------------------------------------------------------------function addTask(task, front)	if (front) then		debugPrint("Added task to front: "..task.name);		table.insert(InboxTasks, 1, task);	else		debugPrint("Added task to back: "..task.name);		table.insert(InboxTasks, task);	endend--------------------------------------------------------------------------------- Hooks reading a message.-------------------------------------------------------------------------------function processMailMessage(index, messageAgeInSeconds)	if (index > 0) then		debugPrint("Processing message "..index);		local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(index);		if (sender and isSenderAuctionHouse(sender)) then			local timestamp = (time() - messageAgeInSeconds);			debugPrint("Message "..index.." was from an auction house (delivered at "..date("%c", timestamp)..")");			if (isSubjectAuctionSuccessful(subject) and money) then				local itemName = getItemNameFromSubject(subject);				debugPrint("Message "..index.." is an auction successful message: "..nilSafe(itemName));				if (itemName) then					-- Get the invoice info, which may or may not be present					-- depending on if it was fetched from the server.					local invoiceType, _, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(index);					local isBuyout = nil;					if (bid ~= nil and buyout ~= nil) then						isBuyout = (bid == buyout);					end					debugPrint("Auction Successful: "..						itemName..", "..						nilSafe(nil)..", "..						nilSafe(invoiceType)..", "..						nilSafe(playerName)..", "..						nilSafe(bid)..", "..						nilSafe(buyout)..", "..						nilSafe(deposit)..", "..						nilSafe(consignment));					BeanCounter.Sales.AddSuccessfulAuction(timestamp, itemName, money, bid, (bid == buyout), deposit, consignment, playerName);				end			elseif (isSubjectAuctionExpired(subject) and hasItem) then				local itemName, _, itemCount = GetInboxItem(index);				debugPrint("Message "..index.." is an auction expired message: "..nilSafe(itemName).. ", "..nilSafe(itemCount));				if (itemName and itemCount) then					debugPrint("Auction Expired: "..						itemName..", "..						nilSafe(itemCount));					BeanCounter.Sales.AddExpiredAuction(timestamp, itemName, itemCount);				end			elseif (isSubjectAuctionCancelled(subject) and hasItem) then				local itemName, _, itemCount = GetInboxItem(index);				debugPrint("Message "..index.." is an auction cancelled message: "..nilSafe(itemName).. ", "..nilSafe(itemCount));				if (itemName and itemCount) then					debugPrint("Auction Cancelled: "..						itemName..", "..						nilSafe(itemCount));					BeanCounter.Sales.AddExpiredAuction(timestamp, itemName, itemCount);				end			elseif (isSubjectAuctionWon(subject) and hasItem) then				local itemName, _, itemCount = GetInboxItem(index);				debugPrint("Message "..index.." is an auction won message: "..nilSafe(itemName).. ", "..itemCount);				if (itemName and itemCount) then					-- Get the invoice info, which may or may not be present					-- depending on if it was fetched from the server.					local invoiceType, _, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(index);					local isBuyout = nil;					if (bid ~= nil and buyout ~= nil) then						isBuyout = (bid == buyout);					end					debugPrint("Auction Won: "..						itemName..", "..						itemCount..", "..						nilSafe(invoiceType)..", "..						nilSafe(playerName)..", "..						nilSafe(bid)..", "..						nilSafe(buyout)..", "..						nilSafe(deposit)..", "..						nilSafe(consignment));					BeanCounter.Purchases.AddSuccessfulBid(timestamp, itemName, itemCount, bid, playerName, isBuyout);				end			elseif (isSubjectOutbidOn(subject) and money) then				local itemName = getItemNameFromSubject(subject);				debugPrint("Message "..index.." is an auction lost message: "..nilSafe(itemName).. ", "..money);				if (itemName and money) then					debugPrint("Out bid on: "..						itemName..", "..						nilSafe(money));					BeanCounter.Purchases.AddFailedBid(timestamp, itemName, money);				end			elseif (isSubjectAuctionCancelled(subject) and money) then				local itemName = getItemNameFromSubject(subject);				debugPrint("Message "..index.." is an auction canceled message: "..nilSafe(itemName).. ", "..money);				if (itemName and money) then					debugPrint("Auction Cancelled: "..						itemName..", "..						nilSafe(money));					BeanCounter.Purchases.AddFailedBid(timestamp, itemName, money);				end			else				debugPrint("Unknown subject: "..subject);			end		else			debugPrint("Message "..index.." was not from an auction house ("..nilSafe(sender)..")");		end	endend--------------------------------------------------------------------------------- Checks if the sender is the auction house-------------------------------------------------------------------------------function isSenderAuctionHouse(sender)	return (sender and (sender == _BC('MailAllianceAuctionHouse') or sender == _BC('MailHordeAuctionHouse')));end--------------------------------------------------------------------------------- Functions that check the subject-------------------------------------------------------------------------------function isSubjectAuctionExpired(subject)	return (string.find(subject, "^".._BC('MailAuctionExpiredSubject')..": .*") ~= nil);endfunction isSubjectAuctionCancelled(subject)	return (string.find(subject, "^".._BC('MailAuctionCancelledSubject')..": .*") ~= nil);endfunction isSubjectAuctionWon(subject)	return (string.find(subject, "^".._BC('MailAuctionWonSubject')..": .*") ~= nil);endfunction isSubjectAuctionSuccessful(subject)	return (string.find(subject, "^".._BC('MailAuctionSuccessfulSubject')..": .*") ~= nil);endfunction isSubjectOutbidOn(subject)	return (string.find(subject, "^".._BC('MailOutbidOnSubject').." .*") ~= nil);end--------------------------------------------------------------------------------- Gets the item name from the subject-------------------------------------------------------------------------------function getItemNameFromSubject(subject)	local itemName = nil;	if (isSubjectAuctionExpired(subject)) then		_, _, itemName = string.find(subject, "^".._BC('MailAuctionExpiredSubject')..": (.*)");	elseif (isSubjectAuctionCancelled(subject)) then		_, _, itemName = string.find(subject, "^".._BC('MailAuctionCancelledSubject')..": (.*)");	elseif (isSubjectAuctionWon(subject)) then		_, _, itemName = string.find(subject, "^".._BC('MailAuctionWonSubject')..": (.*)");	elseif (isSubjectAuctionSuccessful(subject)) then		_, _, itemName = string.find(subject, "^".._BC('MailAuctionSuccessfulSubject')..": (.*)");	elseif (isSubjectOutbidOn(subject)) then		_, _, itemName = string.find(subject, "^".._BC('MailOutbidOnSubject').." (.*)");	end	return itemName;end--------------------------------------------------------------------------------- Reconcile the purchase and sale databases. This should only be called when-- we know that all pending mail is currently in the inbox. In otherwords there-- is no server backlog of messages nor any pending messages yet to arrive in-- the inbox.-------------------------------------------------------------------------------function reconcileDatabases(reconcileTime)	debugPrint("reconcileDatabases("..date("%c", reconcileTime)..") called");	-- Tally up the number of pending e-mails in the inbox for each item. We	-- only care about unread messages since the read messages have already	-- been processed.	local pendingBidsForItem = {};	local pendingSalesForItem = {};	for index = 1, GetInboxNumItems() do		local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(index);		if (not wasRead and sender and isSenderAuctionHouse(sender)) then			if (isSubjectAuctionSuccessful(subject) and money) then				local itemName = getItemNameFromSubject(subject);				pendingSalesForItem[itemName] = true;			elseif (isSubjectAuctionExpired(subject) and hasItem) then				local itemName = GetInboxItem(index);				pendingSalesForItem[itemName] = true;			elseif (isSubjectAuctionCancelled(subject) and hasItem) then				local itemName = GetInboxItem(index);				pendingSalesForItem[itemName] = true;			elseif (isSubjectAuctionWon(subject) and hasItem) then				local itemName = GetInboxItem(index);				pendingBidsForItem[itemName] = true;			elseif (isSubjectOutbidOn(subject) and money) then				local itemName = getItemNameFromSubject(subject);				pendingBidsForItem[itemName] = true;			elseif (isSubjectAuctionCancelled(subject) and money) then				local itemName = getItemNameFromSubject(subject);				pendingBidsForItem[itemName] = true;			end		end	end	-- Perform the purchases database reconcilation.	local reconciledBids, pendingBidsDiscarded, completedBidsDiscarded = BeanCounter.Purchases.ReconcileBids(reconcileTime, pendingBidsForItem);	if (reconciledBids > 0 or pendingBidsDiscarded > 0) then		chatPrint("Reconciled "..reconciledBids.." auctions ("..pendingBidsDiscarded.. " discrepencies)");	end	-- Perform the sales database reconcilation.	local reconciledAuctions, pendingAuctionsDiscarded, completedAuctionsDiscarded = BeanCounter.Sales.ReconcileAuctions(reconcileTime, pendingSalesForItem);	if (reconciledAuctions > 0 or pendingAuctionsDiscarded > 0) then		chatPrint("Reconciled "..reconciledAuctions.." auctions ("..pendingAuctionsDiscarded.. " discrepencies)");	endend--------------------------------------------------------------------------------------------------------------------------------------------------------------function debugPrint(message)	BeanCounter.DebugPrint("[BeanCounter.MailMonitor] "..message);end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -