vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 
2 local mod = klhtm
3 local me = { }
4 mod.netin = me
5  
6 me.myevents = { "CHAT_MSG_CHANNEL", "CHAT_MSG_SYSTEM", "CHAT_MSG_ADDON" }
7  
8 -- Special onevent function from Core.lua
9 me.onevent = function()
10  
11 if event == "CHAT_MSG_ADDON" then
12  
13 -- check the message is KLHTM, and comes from the party or raid
14 if (arg1 ~= "KLHTM") or ((arg3 ~= "PARTY") and (arg3 ~= "RAID")) then
15 me.logmessage("nonklhtm", string.len(arg1))
16 return
17 end
18  
19 -- ok
20 me.messagein(arg4, arg2, 1)
21  
22 elseif event == "CHAT_MSG_CHANNEL" then
23  
24 -- ignore messages outside our channel
25 if arg8 ~= mod.net.channelnumber then
26 return
27 end
28  
29 -- ignore non-KLHTM messages
30 if string.sub(arg1, 1, 6) ~= "KLHTM " then
31 me.logmessage("nonklhtm", string.len(arg1))
32 return
33 end
34  
35 -- ignore messages from people outside the raid group
36 if mod.unit.isplayeringroup(arg2) == nil then
37 me.logmessage("nonklhtm", string.len(arg1))
38 return
39 end
40  
41 -- remove " ...hic!" suffix, and localisations
42 local start
43 local finish
44 start, finish, body = string.find(arg1, "(.-) ?%.%.%..+")
45  
46 if finish == string.len(arg1) then
47 if mod.out.checktrace("info", me, "drunk") then
48 mod.out.printtrace(string.format("Trimming <drunk> from this message: %s", arg1))
49 end
50 arg1 = body
51 end
52  
53 -- to get here, it's fine
54 me.messagein(arg2, arg1, 7)
55  
56 elseif event == "CHAT_MSG_SYSTEM" then
57  
58 -- in 0.12 and higher, the mod is sending ADDON_MESSAGEs, so we don't care about afk
59 if mod.isnewwowversion == nil then
60 if string.find(arg1, string.format(MARKED_AFK_MESSAGE, "")) then
61 mod.my.setstate("afk", true)
62  
63 elseif string.find(arg1, CLEARED_AFK) then
64 mod.my.setstate("afk", false)
65 end
66 end
67 else
68  
69 return
70 end
71  
72 end
73  
74 --[[
75 me.messagein(author, message, startindex)
76 Processes a message from the chat channel.
77 <author> is the name of the player who sent the message.
78 <message> is the original string sent.
79 <startindex> is the 1-based string index where the message starts.
80 ]]
81 me.messagein = function(author, message, startindex)
82  
83 -- get first bit and rest
84 local command
85 local data
86  
87 _, _, command, data = string.find(message, "(%a+)(.*)", startindex)
88  
89 if (command == nil) or (me.commands[command] == nil) then
90  
91 -- log as invalid
92 me.logmessage("invalid", string.len(message))
93  
94 if mod.out.checktrace("warning", me, "badmessage") then
95 mod.out.printtrace(string.format("Received the invalid message '|cffffff00%s|r' from %s.", message, author))
96 end
97  
98 else
99 if me.commands[command](author, message, startindex + string.len(command)) then
100 -- log as good
101 me.logmessage("good", string.len(message))
102 else
103 -- log as invalid
104 me.logmessage("invalid", string.len(message))
105  
106 if mod.out.checktrace("warning", me, "badmessage") then
107 mod.out.printtrace(string.format("Received the invalid message '|cffffff00%s|r' from %s.", message, author))
108 end
109 end
110 end
111  
112 end
113  
114 --[[
115 me.officercheck(author, message)
116 Checks if the author of an officer-only command is an officer. Otherwise, prints an error to trace.
117 <author> is the name of the player who sent the message.
118 <message> is the complete text of the message.
119 Returns: non-nil iff <author> is an officer.
120 ]]
121 me.officercheck = function(author, message)
122  
123 if mod.unit.isplayerofficer(author) then
124 return true
125  
126 else
127 if mod.out.checktrace("warning", me, "badmessage") then
128 mod.out.printtrace(string.format("|cffffff00%s|r is not an officer, but sent the message |cffffff00%s|r.", author, message))
129 end
130  
131 return nil
132 end
133  
134 end
135  
136 --[[
137 each function is called with 1) author, 2) message, 3) index of first character after the command (probably a space)
138 they should return non-nil if the message was good, nil otherwise
139 ]]
140 me.commands =
141 {
142 -- clearing the raid threat
143 ["clear"] = function(author, message)
144  
145 -- author must be officer
146 if me.officercheck(author, message) then
147  
148 mod.out.print(string.format(mod.string.get("print", "network", "threatreset"), author))
149  
150 mod.table.resetraidthreat()
151 mod.table.clearraidtable()
152  
153 return true
154 end
155  
156 end,
157  
158 -- updating your threat value
159 ["threat"] = function(author, message, start)
160  
161 local value = tonumber(string.sub(message, start + 1))
162  
163 -- check for validity
164 if value == nil then
165 return
166 end
167  
168 mod.table.updateplayerthreat(author, value)
169 KLHTM_RequestRedraw("raid")
170  
171 return true
172  
173 end,
174  
175 -- 1.12: "t" is a synonym for "threat"
176 ["t"] = function(author, message, start)
177  
178 local value = tonumber(string.sub(message, start + 1))
179  
180 -- check for validity
181 if value == nil then
182 return
183 end
184  
185 mod.table.updateplayerthreat(author, value)
186 KLHTM_RequestRedraw("raid")
187  
188 return true
189  
190 end,
191  
192 -- setting the master target
193 ["target"] = function(author, message, start)
194  
195 -- check player is an officer
196 if me.officercheck(author, message) then
197  
198 local newmt = string.sub(message, start + 1)
199 -- check newmt makes sense
200  
201 if newmt ~= nil and string.len(newmt) > 0 then
202 mod.boss.newmastertarget(author, newmt)
203 KLHTM_RequestRedraw("raid")
204  
205 -- update poll values
206 mod.net.lastmtstring = newmt
207 mod.net.lastmtsender = author
208 mod.net.lastmttime = GetTime()
209  
210 return true
211 end
212 end
213 end,
214  
215 -- polling the master target
216 ["mtpoll"] = function(author, message, start)
217  
218 -- check player is an officer
219 if me.officercheck(author, message) then
220  
221 local newmt = string.sub(message, start + 1)
222 -- check newmt makes sense
223  
224 if newmt ~= nil and string.len(newmt) > 0 then
225  
226 -- check if this is different
227 if newmt ~= mod.net.lastmtstring then
228  
229 -- set the string as MT, but with a caution
230 mod.boss.mastertarget = newmt
231 mod.out.print(string.format(mod.string.get("print", "network", "mtpollwarning"), newmt, author))
232 KLHTM_RequestRedraw("raid")
233  
234 -- update poll values
235 mod.net.lastmtstring = newmt
236 mod.net.lastmtsender = author
237 mod.net.lastmttime = GetTime()
238  
239 end
240  
241 -- message was valid so return true
242 return true
243 end
244  
245 end
246  
247 end,
248  
249 -- clearing the master target
250 ["cleartarget"] = function(author, message)
251  
252 -- check player is an officer
253 if me.officercheck(author, message) then
254  
255 -- ignore polls / repeated clears
256 if mod.net.lastmtstring == "clear" then
257 -- do nothing
258  
259 else
260 mod.boss.clearmastertarget()
261 mod.out.print(string.format(mod.string.get("print", "network", "mtclear"), author))
262 KLHTM_RequestRedraw("raid")
263  
264 -- update poll values
265 mod.net.lastmtstring = "clear"
266 mod.net.lastmtsender = author
267 mod.net.lastmttime = GetTime()
268  
269 end
270  
271 -- message was valid so return true
272 return true
273 end
274 end,
275  
276 -- starting knockback discovery
277 ["spellstart"] = function(author, message)
278  
279 -- check author is an officer
280 if me.officercheck(author, message) == nil then
281 return
282 end
283  
284 mod.boss.isspellreportingactive = true
285  
286 if author == UnitName("player") then
287 mod.boss.istrackingspells = true
288 end
289  
290 -- only print out if you are a tracker
291 if mod.boss.istrackingspells == true then
292 mod.out.print(string.format(mod.string.get("print", "network", "knockbackstart"), author))
293 end
294  
295 return true
296  
297 end,
298  
299 -- stopping knockback discovery
300 ["spellstop"] = function(author, message)
301  
302 -- check author is an officer
303 if me.officercheck(author, message) == nil then
304 return
305 end
306  
307 mod.boss.isspellreportingactive = false
308  
309 if mod.boss.istrackingspells == true then
310 mod.out.print(string.format(mod.string.get("print", "network", "knockbackstop"), author))
311 end
312  
313 return true
314  
315 end,
316  
317 -- When boss spell reporting is enabled and someone suffers a boss spell
318 ["spelleffect"] = function(author, message, start)
319  
320 -- if we aren't monitoring reports, ignore
321 if mod.boss.istrackingspells == false then
322 return true -- we don't actually check correctness.
323 end
324  
325 local _, _, spell, mob, result, data = string.find(message, "\"(.+)\" \"(.*)\" (%l+) ?(.*)", start + 1)
326  
327 if spell == nil then
328 return
329 end
330  
331 if result == "miss" then
332 mod.out.print(string.format(mod.string.get("print", "boss", "reportmiss"), author, mob, spell))
333  
334 else
335 local value1, value2
336  
337 _, _, value1, value2 = string.find(tostring(data), "(-?%d+) (-?%d+)")
338  
339 if (tostring(number) == nil) or (tostring(number) == nil) then
340 return
341 end
342  
343 if result == "proc" then
344 mod.out.print(string.format(mod.string.get("print", "boss", "reportproc"), author, mob, spell, value1, value2))
345  
346 elseif result == "tick" then
347 mod.out.print(string.format(mod.string.get("print", "boss", "reporttick"), author, mob, spell, value1, value2))
348  
349 else
350 return
351 end
352 end
353  
354 return true
355 end,
356  
357 -- when someone changes a parameter of a boss spell
358 ["spellvalue"] = function(author, message, start)
359  
360 -- check author is an officer
361 if me.officercheck(author, message) == nil then
362 return
363 end
364  
365 -- argh!! Memory creation! 64 bytes for this method! ...
366 local arglist = {}
367 local x
368  
369 for x in string.gfind(message, "[^ ]+") do
370 table.insert(arglist, x)
371 end
372  
373 table.remove(arglist, 1)
374  
375 -- parse
376 local value, errormsg = mod.net.checkspellvaluesyntax(arglist)
377  
378 -- did it work?
379 if value then
380 if arglist[2] == "default" then
381  
382 --[[
383 suppose we receive the message "spellvalue timelapse default ticks 6". Then this would print out
384 "Kenco sets the ticks parameter of the Time Lapse ability to 6."
385 ]]
386 mod.out.print(string.format(mod.string.get("print", "boss", "spellsetall"), author, "|cffffff00" .. arglist[3] .. "|r", mod.string.get("boss", "spell", arglist[1]), value, mod.boss.bossattacks[arglist[1]][arglist[2]][arglist[3]]))
387  
388 else
389 mod.out.print(string.format(mod.string.get("print", "boss", "spellsetmob"), author, "|cffffff00" .. arglist[3] .. "|r", mod.string.get("boss", "spell", arglist[2]), mod.string.get("boss", "spell", arglist[1]), value, mod.boss.bossattacks[arglist[1]][arglist[2]][arglist[3]]))
390 end
391  
392 mod.boss.bossattacks[arglist[1]][arglist[2]][arglist[3]] = value
393  
394 return true
395 else
396  
397 if mod.out.checktrace("warning", me, "spellvalue") then
398 mod.out.printtrace(string.format("The error message was '%s'.", errormsg))
399 end
400  
401 return
402 end
403 end,
404  
405 -- telling people to upgrade to a new version
406 ["version"] = function(author, message, start)
407  
408 -- check author is an officer
409 if me.officercheck(author, message) == nil then
410 return
411 end
412  
413 -- next argument should be the version number
414 local release, revision
415 _, _, release, revision = string.find(message, "(%d+)%.?(%d*)", start + 1)
416  
417 release = tonumber(release)
418 revision = tonumber(revision)
419  
420 if release == nil then
421 return
422 end
423  
424 -- previously, only the release was sent as the version code. Therefore if someone sends in this format,
425 -- their version must be old.
426 if revision == nil then
427  
428 mod.out.print(string.format(mod.string.get("print", "network", "remoteoldversion"), author, release .. ".x", mod.release .. "." .. mod.revision))
429  
430 else
431  
432 -- newer versions send their release and revision numbers, in a dot delimited string.
433 if (release < mod.release) or (release == mod.release and revision < mod.revision) then
434 -- other guy has an old version
435 mod.out.print(string.format(mod.string.get("print", "network", "remoteoldversion"), author, release .. "." .. revision, mod.release .. "." .. mod.revision))
436  
437 elseif (release == mod.release) and (revision == mod.revision) then
438 -- we have the same version; do nothing
439  
440 else
441 -- we have an older version - upgrade!
442 mod.out.print(string.format(mod.string.get("print", "network", "upgraderequest"), author, release .. "." .. revision, mod.release .. "." .. mod.revision))
443 end
444 end
445  
446 return true
447  
448 end,
449  
450 -- asking the raid group what versions they are using
451 ["versionquery"] = function(author, message)
452  
453 -- check author is an officer
454 if me.officercheck(author, message) == nil then
455 return
456 end
457  
458 -- send our version
459 mod.net.sendmessage("versionresponse " .. mod.release .. "." .. mod.revision)
460  
461 return true
462  
463 end,
464  
465 -- response to versionquery
466 ["versionresponse"] = function(author, message, start)
467  
468 -- next argument should be the version number
469 local value = tonumber(string.sub(message, start + 1))
470 if value == nil then
471 return
472 end
473  
474 mod.net.addversionresponse(author, value)
475 return true
476  
477 end,
478  
479 -- Boss Spell Event
480 ["event"] = function(author, message, start)
481  
482 local eventid = string.sub(message, start + 1)
483  
484 -- check the event is valid
485 if (eventid == nil) or (mod.boss.bossevents[eventid] == nil) then
486 return
487 end
488  
489 -- it is valid. send it to boss handler
490 mod.boss.reportevent(eventid, author)
491 return true
492  
493 end
494  
495 }
496  
497  
498 ------------------------------------------------------------------------
499  
500 ---------------------------------
501 -- lololol Message Logging --
502 ---------------------------------
503  
504 me.messagelog =
505 {
506 ["nonklhtm"] =
507 {
508 ["count"] = 0,
509 ["bytes"] = 0,
510 },
511 ["invalid"] =
512 {
513 ["count"] = 0,
514 ["bytes"] = 0,
515 },
516 ["good"] =
517 {
518 ["count"] = 0,
519 ["bytes"] = 0,
520 },
521 ["total"] =
522 {
523 ["count"] = 0,
524 ["bytes"] = 0,
525 },
526 }
527  
528 --[[
529 me.logmessage(category, length)
530 Record a message from the mod's chat channel.
531 <category> is one of the keys in me.messagelog.
532 <length> is the lenght in bytes of the complete message.
533 ]]
534 me.logmessage = function(category, length)
535  
536 me.messagelog[category].count = me.messagelog[category].count + 1
537 me.messagelog[category].bytes = me.messagelog[category].bytes + length
538  
539 me.messagelog["total"].count = me.messagelog["total"].count + 1
540 me.messagelog["total"].bytes = me.messagelog["total"].bytes + length
541  
542 end