Quantcast

AddonComm update.

F16Gaming [02-10-12 - 19:29]
AddonComm update.
Filename
AddonComm.lua
Command.lua
String.lua
diff --git a/AddonComm.lua b/AddonComm.lua
index 74d64a3..d116f1b 100644
--- a/AddonComm.lua
+++ b/AddonComm.lua
@@ -26,8 +26,7 @@ local CET = C.Extensions.Table
 local log = C.Logger

 C.AddonComm = {
-	GroupMaster = true, -- Whether or not we are currently the "master" instance in group
-	GuildMaster = true, -- Whether or not we are currently the "master" instance in guild
+	Halted = false,
 	Type = {
 		VersionUpdate = "COMM_VU",
 		HandleCommand = "COMM_DO"
@@ -57,22 +56,24 @@ function AC:LoadSavedVars()
 end

 function AC:Receive(msgType, msg, channel, sender)
+	if sender == UnitName("player") then return end
 	if msgType == self.Type.VersionUpdate then
-		local t = CES:Split(msg, ":")
-		if #t < 1 then return end
-		local ver = tonumber(t[1])
-		if type(t[1]) ~= "number" then return end
+		local ver = tonumber(msg)
+		if type(ver) ~= "number" then return end
 		C:CheckVersion(ver)
 	elseif msgType == self.Type.HandleCommand then
 		local t = CES:Split(msg, ";&")
+		for i,v in ipairs(t) do log:Normal(i .. ": " .. tostring(v)) end
 		if #t < 3 then return end
 		local name = tostring(t[1])
 		local sent = tostring(t[2])
 		local chan = tostring(t[3])
 		if type(t[1]) ~= "string" or type(t[2]) ~= "string" or type(t[3]) ~= "string" then return end
+		log:Normal("Received HandleCommand from " .. sender)
 		self.Last.Sender = name
 		self.Last.Message = sent
 		self.Last.Channel = chan
+		--self.Halted = true
 	end
 end

@@ -83,10 +84,14 @@ function AC:Send(msgType, msg, channel, target)
 		return
 	end
 	SendAddonMessage(msgType, msg, channel, target)
+	if msgType == self.Type.HandleCommand then
+		SendAddonMessage(self.Type.VersionUpdate, self.Format.VersionUpdate:format(C.VersionNum), channel)
+	end
 end

 function AC:Handled(msg, sender, channel)
-	if channel == "WHISPER" then return end
+	if self.Halted then return false end
+	if channel == "WHISPER" then return true end
 	if self:IsHandled(msg, sender, channel) then return false end
 	self:Send(self.Type.HandleCommand, self.Format.HandleCommand:format(sender, msg, channel), channel)
 	return true
@@ -99,3 +104,10 @@ function AC:IsHandled(msg, sender, channel)
 	end
 	return false
 end
+
+function AC:Reset()
+	self.Last.Sender = nil
+	self.Last.Message = nil
+	self.Last.Channel = nil
+	self.Halted = false
+end
diff --git a/Command.lua b/Command.lua
index 90208fb..e819f67 100644
--- a/Command.lua
+++ b/Command.lua
@@ -32,7 +32,7 @@
 Command = {
 	Name = "Command",
 	Version = GetAddOnMetadata("Command", "Version"),
-	VersionNum = 1, -- Increment on every release
+	VersionNum = 2, -- Increment on every release
 	VersionChecked = false, -- Prevent spam of "New Version" notice
 	Loaded = false,
 	VarVersion = 2,
@@ -104,7 +104,7 @@ function C:CheckVersion(ver)
 	if self.VersionChecked then return end
 	ver = ver or 0
 	if ver > self.VersionNum then
-		log:Normal("A new version of " .. self.Name .. " is available! Check the site you downloaded from for the updated version.")
+		log:Normal("\124cffFF0000A new version of \124cff00FFFF" .. self.Name .. "\124cffFF0000 is available! \124cffFFFF00Check the site you downloaded from for the updated version.")
 		self.VersionChecked = true
 	end
 end
diff --git a/String.lua b/String.lua
index 76655f2..56adca8 100644
--- a/String.lua
+++ b/String.lua
@@ -61,13 +61,27 @@ end

 --- Split a string with space as delimiter.
 -- @param s String to be split.
+-- @param d Delimiter
 -- @return Table containing the individual words.
 --
-function CES:Split(s)
-	s = s or " "
+function CES:Split(s, d)
+	if not s then return nil end
 	local t = {}
-	for token in string.gmatch(s, "[^%s]+") do
-		table.insert(t, token)
+	if not d then
+		for token in s:gmatch("[^%s]+") do
+			table.insert(t, token)
+		end
+	else
+		if not s:find(d) then return {s} end
+		local p = "(.-)" .. d .. "()"
+		local nb = 0
+		local lastPos
+		for part,pos in s:gmatch(p) do
+			nb = nb + 1
+			t[nb] = part
+			lastPos = pos
+		end
+		t[nb + 1] = s:sub(lastPos)
 	end
 	return t
 end