I play at work a lot and have my game window resized very small so I can just see whats going on - but cannot read names / chats etc. So I usually have the bot grinding out waypoints, or just sitting there so I can keep an eye on guild chat etc (I resize to make the font large enough to read and then sit it behind a 'always on top' window - process explorer - so I can only see the chat portion). Unfortunately this is still relatively noticeable and I'd rather not have the rom window visible at all (in fact I hide it completely off task bars etc too).
Anyway. I figured to do something about it and write a .net app that has tabs for each chat channel and somehow get rom bot to send me the chats - I use the newish Monitor stuff to get rom to get all chat messages. This is easy enough, but it took me a while to get a UDP client working to do the IPC stuff to get the chats back to my .net app (being very new to lua) and now I'm using luasocket library to do this and have a UDP server in my .net app - this all works okish - I have the monitors starting up via the onLoad event of my characters profile. i.e.:
Code: Select all
<onLoad><![CDATA[
-- Additional Lua code to execute after loading the profile
-- and before the bot starts. e.g. You could overwrite profile settings here
-- like: changeProfileOption("HP_REST", 60);
--registerTimer("AutoCombat", 11, SendF11);
startChatMonitors();
registerTimer("ChatMonitor", 500, monitorChats);
]]></onLoad>
function startChatMonitors()
EventMonitorStart("allGuild", "CHAT_MSG_GUILD")
EventMonitorStart("allSay", "CHAT_MSG_SAY")
EventMonitorStart("allWhisper", "CHAT_MSG_WHISPER")
EventMonitorStart("allZone", "CHAT_MSG_ZONE")
EventMonitorStart("allWorld", "CHAT_MSG_YELL")
EventMonitorStart("allParty", "CHAT_MSG_PARTY")
EventMonitorStart("allTrade", "CHAT_MSG_TRADE")
EventMonitorStart("allCombat", "CHAT_MSG_COMBAT")
EventMonitorStart("allGM", "CHAT_MSG_GM")
EventMonitorStart("allSale", "CHAT_MSG_SALE")
EventMonitorStart("allSystem", "CHAT_MSG_SYSTEM")
end
function monitorChats()
c = socket.udp()
c:settimeout(0)
c:setpeername('192.168.100.128', 60000)
--cprintf(cli.red, "checking guild")
printEvents("Guild", cli.green)
printEvents("Whisper", cli.turquoise)
printEvents("Say", cli.white)
printEvents("World", cli.red)
printEvents("Zone", cli.purple)
printEvents("Party", cli.lightgreen)
printEvents("Trade", cli.lightblue)
printEvents("Combat", cli.lightgray)
printEvents("GM", cli.lightblue)
printEvents("Sale", cli.lightblue)
printEvents("System", cli.lightgray)
c:close()
end
function printEvents(channel, color)
local _time, more, msg, name = EventMonitorCheck("all"..channel)
repeat
if (_time ~= nil) then
cprintf(color, "[%s - %s] %s: %s\n", channel, os.date(), getPlayerNameFromLink(name), stripColorCodes(msg))
local st = sprintf("%s\1%s\1%s\1%s", channel, getPlayerNameFromLink(name), stripColorCodes(msg), os.date())
c:send(st)
end
if (more) then _time, more, msg, name = EventMonitorCheck("all"..channel) end
until (not more)
end
function getPlayerNameFromLink(playerLink)
if playerLink == "" or playerLink == nil then
return "";
end
local s,e, name = string.find(playerLink, "|Hplayer:(.+).*|h%[");
name = name or "<unknown>";
return name;
end
function stripColorCodes(source)
if (source == "") or (source == nil) then
return "";
end
source = string.gsub(source, "|H|h|c%x%x%x%x%x%x%x%x", "");
source = string.gsub(source, "|c%x%x%x%x%x%x%x%x", "");
return string.gsub(source, "|h", "");
end
Code: Select all
romSocket = socket.udp()
romSocket:setsockname('*', 60002)
function listenForMessages()
romSocket:settimeout(0)
local recv = romSocket:receive()
if (recv ~= nil) then
local res = SplitString(recv, '\1', 4)
local style = string.upper(res[1])
local channel = string.upper(res[2])
local p1 = res[3]
local p1 = string.gsub(res[3], "'", "")
local p2 = nil
if (style=="CHAT") then
cprintf(cli.white, "Channel: %s Message: %s\n", channel, p1);
cprintf(cli.white, "Sending [%s] %s\n", channel, p1);
if (not(channel == nil or channel =="")) then
if ((channel == "WHISPER") and not(p2 == nil or p2 == "")) then
gameText(p1,channel,p2);
else
gameText(p1,channel);
end
end
else
if (style == "COMMAND") then
funct=loadstring(p1)
if type(funct) == "function" then
local status,err = pcall(funct);
if status == false then
printf("onLoad error: %s\n", err);
end
else
print ("Invalid Command")
end
end
end
end
end
function SplitString(str, delim, maxNb)
-- Eliminate bad cases...
if string.find(str, delim) == nil then
return { str }
end
if maxNb == nil or maxNb < 1 then
maxNb = 0 -- No limit
end
local result = {}
local pat = "(.-)" .. delim .. "()"
local nb = 0
local lastPos
for part, pos in string.gfind(str, pat) do
nb = nb + 1
result[nb] = part
lastPos = pos
if nb == maxNb then break end
end
-- Handle the last field
if nb ~= maxNb then
result[nb + 1] = string.sub(str, lastPos)
end
return result
end
This all works ok, but I'm questioning the way I have implemented it all via timers and am wondering if there is a better way of doing this? i.e. a better design.