Quantcast

Fix loading for neutral monks.

Coren[m] [12-15-13 - 21:21]
Fix loading for neutral monks.
Fix a bug when trying to update a (pretty old) database.
Filename
Karma/karma.lua
Karma/karmaChat.lua
Karma/karmaDB.lua
diff --git a/Karma/karma.lua b/Karma/karma.lua
index 4038ba4..6d075ce 100755
--- a/Karma/karma.lua
+++ b/Karma/karma.lua
@@ -1132,7 +1132,9 @@ function	Karma_FullInitialise()
 		KarmaModuleLocal.ColorSpaces.Time = KCfg.Get("COLORSPACE_TIME");
 		KarmaModuleLocal.ColorSpaces.XP = KCfg.Get("COLORSPACE_XP");

-		KarmaObj.DB.Create();
+		if (KarmaObj.DB.Create() == -1) then
+			return -1;
+		end
 		if (KarmaObj.DB.Upgrade() == -1) then
 			return -1;
 		end
@@ -1150,7 +1152,7 @@ function	Karma_FullInitialise()
 		KARMA_LOADED = 1;

 		-- 2nd call: now charspecific choices are available
-		Karma_SetupChatWindows();
+		KarmaObj.UIChat.SetupChatWindows();

 		-- We want this to show up in the main chat window.
 		if (DEFAULT_CHAT_FRAME) then
@@ -1275,10 +1277,10 @@ function	Karma_QueueFullInitialise(self)

 	elseif (iBad == -1) then
 		DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8080Karma: FAILED TO INITIALIZE DATABASE PROPERLY!|r");
-		DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8080Karma: Load-On-Demand is enabled for the database, but at least one database (KarmaAlliance or KarmaHorde) cannot be loaded.|r");
-		DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8080Karma: Please enable KarmaAlliance and KarmaHorde, or disable Load-On-Demand.|r");
+		DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8080Karma: Load-On-Demand is enabled for the database, but at least the necessary database (KarmaAlliance or KarmaHorde) cannot be loaded.|r");
+		DEFAULT_CHAT_FRAME:AddMessage("|cFFFF8080Karma: Please enable KarmaAlliance/KarmaHorde (depending on your characters), or disable Load-On-Demand.|r");
 	else
-		-- queue command: any other queued command has to be dropped for self
+		-- queue command: any other queued command has to be dropped for this
 		KarmaModuleLocal.Timers.CmdQ = GetTime() + 10;

 		local	oCmd = { sName = "init", func = Karma_QueueFullInitialise, args = self };
@@ -1492,13 +1494,20 @@ local	function	Karma_InitHelper(self, event, ...)
 		KARMA_ININIT = bit.bor(KARMA_ININIT, 32);
 		self:UnregisterEvent(event);

+		if (0 == bit.band(KARMA_ININIT, 16)) then
+			local	sFaction = UnitFactionGroup("player");
+			if (sFaction == "Neutral") then
+				KARMA_ININIT = bit.bor(KARMA_ININIT, 16);
+			end
+		end
+
 		bResult = true;
 	end

 	if (0 == bit.band(KARMA_ININIT, 8)) then
 		if (7 == bit.band(KARMA_ININIT, 7)) then
 			-- uses global config only! => silent
-			Karma_SetupChatWindows(1);
+			KarmaObj.UIChat.SetupChatWindows(1);

 			KARMA_ININIT = bit.bor(KARMA_ININIT, 8);
 		end
@@ -6384,58 +6393,59 @@ function	KarmaWindow_OnUpdateEventDo()
 			-- we want to be as close to PlayerRegen as possible!
 			return
 		end
-	end

-	if (not KarmaModuleLocal.RegionsByAreaID.Done) then
-		local	_, iAreaIDStored = KarmaObj.DB.CG.LocaleRegions();
-		iAreaIDStored = iAreaIDStored or 0;
-		if (iAreaIDStored >= 1000) then
-			KarmaChatDebug("Acquired all outdoor areaID <=> zoneName mappings.");
-			KarmaModuleLocal.RegionsByAreaID.Done = true;
-		elseif (not KarmaModuleLocal.RegionsByAreaID.TimeAt) then
-			if (not WorldMapFrame:IsShown()) then
-				if (not KarmaModuleLocal.RegionsByAreaID.AreaID) then
-					KarmaChatDebug("Starting to acquire areaID <=> zoneName mappings...");
-					SetMapZoom(-1);
-				end
-				iAreaIDStored = math.max(0, iAreaIDStored - 5);
-				KarmaModuleLocal.RegionsByAreaID.AreaID = (KarmaModuleLocal.RegionsByAreaID.AreaID or iAreaIDStored or 0) + 1;
-				KarmaModuleLocal.RegionsByAreaID.Valid = true;
-				KarmaModuleLocal.RegionsByAreaID.TimeAt = TimeNow;
-				SetMapByID(KarmaModuleLocal.RegionsByAreaID.AreaID);
-			end
-		elseif (TimeNow - KarmaModuleLocal.RegionsByAreaID.TimeAt > 0.5) then
-			if (not KarmaModuleLocal.RegionsByAreaID.Valid) then
-				KarmaChatDebug("Was interfered in acquiring mapping for areaID " .. KarmaModuleLocal.RegionsByAreaID.AreaID .. "...");
-				KarmaModuleLocal.RegionsByAreaID.AreaID = KarmaModuleLocal.RegionsByAreaID.AreaID - 1;
-				KarmaModuleLocal.RegionsByAreaID.TimeAt = nil;
-			else
-				local	iContinent = GetCurrentMapContinent();
-				if (iContinent > 0) then
-					if (KarmaModuleLocal.RegionsByAreaID.Continent2Zones[iContinent] == nil) then
-						KarmaChatDebug("Loading zone names for continent " .. iContinent .. "...");
-						KarmaModuleLocal.RegionsByAreaID.Continent2Zones[iContinent] = { GetMapZones(iContinent) };
+		-- fetch area IDs
+		if (not KarmaModuleLocal.RegionsByAreaID.Done) then
+			local	_, iAreaIDStored = KarmaObj.DB.CG.LocaleRegions();
+			iAreaIDStored = iAreaIDStored or 0;
+			if (iAreaIDStored >= 1000) then
+				KarmaChatDebug("Acquired all outdoor areaID <=> zoneName mappings.");
+				KarmaModuleLocal.RegionsByAreaID.Done = true;
+			elseif (not KarmaModuleLocal.RegionsByAreaID.TimeAt) then
+				if (not WorldMapFrame:IsShown()) then
+					if (not KarmaModuleLocal.RegionsByAreaID.AreaID) then
+						KarmaChatDebug("Starting to acquire areaID <=> zoneName mappings...");
+						SetMapZoom(-1);
 					end
-					local	iZone = GetCurrentMapZone();
-					local	sName = KarmaModuleLocal.RegionsByAreaID.Continent2Zones[iContinent][iZone];
-					if (sName) then
-						if (not KarmaModuleLocal.RegionsByAreaID.Name2ID[sName]) then
-							local	iAreaID = GetCurrentMapAreaID();
-							if (iAreaID == KarmaModuleLocal.RegionsByAreaID.AreaID) then
-								KarmaChatDebug("Area2Name: " .. iContinent .. "." .. iZone .. " - " .. (sName or "???") .. " => " .. KarmaModuleLocal.RegionsByAreaID.AreaID);
-								KarmaObj.DB.CG.LocaleRegions(iAreaID, iContinent, iZone, sName);
-								KarmaModuleLocal.RegionsByAreaID.Name2ID[sName] = iAreaID;
-								KarmaModuleLocal.RegionsByAreaID.ID2Name[iAreaID] = sName;
+					iAreaIDStored = math.max(0, iAreaIDStored - 5);
+					KarmaModuleLocal.RegionsByAreaID.AreaID = (KarmaModuleLocal.RegionsByAreaID.AreaID or iAreaIDStored or 0) + 1;
+					KarmaModuleLocal.RegionsByAreaID.Valid = true;
+					KarmaModuleLocal.RegionsByAreaID.TimeAt = TimeNow;
+					SetMapByID(KarmaModuleLocal.RegionsByAreaID.AreaID);
+				end
+			elseif (TimeNow - KarmaModuleLocal.RegionsByAreaID.TimeAt > 0.5) then
+				if (not KarmaModuleLocal.RegionsByAreaID.Valid) then
+					KarmaChatDebug("Was interfered in acquiring mapping for areaID " .. KarmaModuleLocal.RegionsByAreaID.AreaID .. "...");
+					KarmaModuleLocal.RegionsByAreaID.AreaID = KarmaModuleLocal.RegionsByAreaID.AreaID - 1;
+					KarmaModuleLocal.RegionsByAreaID.TimeAt = nil;
+				else
+					local	iContinent = GetCurrentMapContinent();
+					if (iContinent > 0) then
+						if (KarmaModuleLocal.RegionsByAreaID.Continent2Zones[iContinent] == nil) then
+							KarmaChatDebug("Loading zone names for continent " .. iContinent .. "...");
+							KarmaModuleLocal.RegionsByAreaID.Continent2Zones[iContinent] = { GetMapZones(iContinent) };
+						end
+						local	iZone = GetCurrentMapZone();
+						local	sName = KarmaModuleLocal.RegionsByAreaID.Continent2Zones[iContinent][iZone];
+						if (sName) then
+							if (not KarmaModuleLocal.RegionsByAreaID.Name2ID[sName]) then
+								local	iAreaID = GetCurrentMapAreaID();
+								if (iAreaID == KarmaModuleLocal.RegionsByAreaID.AreaID) then
+									KarmaChatDebug("Area2Name: " .. iContinent .. "." .. iZone .. " - " .. (sName or "???") .. " => " .. KarmaModuleLocal.RegionsByAreaID.AreaID);
+									KarmaObj.DB.CG.LocaleRegions(iAreaID, iContinent, iZone, sName);
+									KarmaModuleLocal.RegionsByAreaID.Name2ID[sName] = iAreaID;
+									KarmaModuleLocal.RegionsByAreaID.ID2Name[iAreaID] = sName;
+								end
 							end
 						end
 					end
-				end

-				KarmaObj.DB.CG.LocaleRegions(- KarmaModuleLocal.RegionsByAreaID.AreaID);
-				if (KarmaModuleLocal.RegionsByAreaID.AreaID < 1000) then
-					KarmaModuleLocal.RegionsByAreaID.TimeAt = nil;
-				else
-					KarmaModuleLocal.RegionsByAreaID.Done = true;
+					KarmaObj.DB.CG.LocaleRegions(- KarmaModuleLocal.RegionsByAreaID.AreaID);
+					if (KarmaModuleLocal.RegionsByAreaID.AreaID < 1000) then
+						KarmaModuleLocal.RegionsByAreaID.TimeAt = nil;
+					else
+						KarmaModuleLocal.RegionsByAreaID.Done = true;
+					end
 				end
 			end
 		end
diff --git a/Karma/karmaChat.lua b/Karma/karmaChat.lua
index bea4ee3..03a25a3 100755
--- a/Karma/karmaChat.lua
+++ b/Karma/karmaChat.lua
@@ -280,7 +280,7 @@ function	KarmaObj.UIChat.DebugNameGet()
 end


-function	Karma_SetupChatWindows(silent)
+function	KarmaObj.UIChat.SetupChatWindows(silent)
 	KARMA_ChatWindowSecondary = nil;
 	KARMA_ChatWindowDebug = nil;

@@ -363,4 +363,3 @@ function	Karma_SetupChatWindows(silent)
 		end
 	end
 end
-
diff --git a/Karma/karmaDB.lua b/Karma/karmaDB.lua
index 4966501..3ed0f8e 100755
--- a/Karma/karmaDB.lua
+++ b/Karma/karmaDB.lua
@@ -308,6 +308,9 @@ local	KARMA_DB_L1 = {
 			XFACTIONHOLD = "XFACTIONHOLD",		-- moved to here in version 12

 			RELOCATIONS = "RELOCATIONS",
+
+			NEUTRAL = "NEUTRAL",			-- added in v14: neutral server container (for monks)
+								-- TODO: add something to move the contents if we hit those chars, and to timeout the contents if very old
 		};

 --------- COMMON LEVEL --------------------------
@@ -635,6 +638,7 @@ function	KarmaObj.DB.Create()
 	end

 	local	sPlayerFaction = UnitFactionGroup("player");
+
 	if ((sRealm == nil) or (sPlayerFaction == nil)) then
 		local	s = "";
 		if (sRealm == nil) then
@@ -646,19 +650,20 @@ function	KarmaObj.DB.Create()

 		DEFAULT_CHAT_FRAME:AddMessage("Karma: |cFFFF8080Fatal initialization error! Couldn't determine your " .. strsub(s, 2) .. "!! DB remains uninitialized.|r");

-		return -1
+		return -1;
 	end

-	local	oFactionDB = _G["KarmaAvEnK" .. sPlayerFaction];
-	if (type(oFactionDB) ~= "table") then
-		DEFAULT_CHAT_FRAME:AddMessage("Karma: |cFFFF8080Fatal initialization error! Couldn't initialize the load-on demand module for your faction (" .. sPlayerFaction .. ")!! DB remains uninitialized.|r (Make sure the module KarmaDB" .. sPlayerFaction .. " is enabled.)");
+	if (sPlayerFaction ~= "Neutral") then
+		KDBC.Faction = _G["KarmaAvEnK" .. sPlayerFaction];
+		if (type(KDBC.Faction) ~= "table") then
+			DEFAULT_CHAT_FRAME:AddMessage("Karma: |cFFFF8080Fatal initialization error! Couldn't initialize the load-on demand module for your faction (" .. sPlayerFaction .. ")!! DB remains uninitialized.|r (Make sure the module KarmaDB" .. sPlayerFaction .. " is enabled.)");

-		return -1
+			return -1;
+		end
 	end

 	local	sPlayername = UnitName("player");

-	KDBC.Faction = oFactionDB;
 	KDBC.Realm = sRealm;
 	KDBC.PlayerFaction = sPlayerFaction;
 	KDBC.PlayerName = sPlayername;
@@ -679,6 +684,19 @@ function	KarmaObj.DB.Create()
 	end
 	Karma_FieldInitialize(KarmaData, KARMA_DB_L1.VERSION, KARMA_SUPPORTEDDATABASEVERSION);

+	if (sPlayerFaction == "Neutral") then
+		KOH.TableInit(KarmaData, KARMA_DB_L1.NEUTRAL);
+		KDBC.Faction = KarmaData[KARMA_DB_L1.NEUTRAL];
+	end
+
+	if (type(KDBC.Faction) ~= "table") then
+		DEFAULT_CHAT_FRAME:AddMessage("Karma: |cFFFF8080Fatal initialization error! Something went wrong in an unexpected and therefore unhandled way. Sorry!)");
+
+		return -1;
+	end
+
+	local oFactionDB = KDBC.Faction;
+
 	------------------------------------------------------------------------
 	------------------------------------------------------------------------
 	------------------------------------------------------------------------
@@ -1670,27 +1688,27 @@ function KarmaObj.DB.CF.QuestListAdd(Quest, Faction, ExtID)
 	end

 	local	oCommonFaction = KDBC.CommonFactionObject;
-	if (FactionKey and (FactionKey ~= KDBC.PlayerFaction)) then
+	if (Faction and (Faction ~= KDBC.PlayerFaction)) then
 		--[[
-		if (KarmaData[KARMA_DB_L1.COMMONLIST][KARMA_DB_L2_C.FACTION][FactionKey] == nil) then
+		if (KarmaData[KARMA_DB_L1.COMMONLIST][KARMA_DB_L2_C.FACTION][Faction] == nil) then
 			-- happens at database conversion for the faction the current char is NOT on
-			KOH.TableInit(KarmaData[KARMA_DB_L1.COMMONLIST][KARMA_DB_L2_C.FACTION], FactionKey);
-			KOH.TableInit(KarmaData[KARMA_DB_L1.COMMONLIST][KARMA_DB_L2_C.FACTION][FactionKey], KARMA_DB_L3_CF_QUESTNAMES);
-			KOH.TableInit(KarmaData[KARMA_DB_L1.COMMONLIST][KARMA_DB_L2_C.FACTION][FactionKey], KARMA_DB_L3_CF_QUESTINFOS);
+			KOH.TableInit(KarmaData[KARMA_DB_L1.COMMONLIST][KARMA_DB_L2_C.FACTION], Faction);
+			KOH.TableInit(KarmaData[KARMA_DB_L1.COMMONLIST][KARMA_DB_L2_C.FACTION][Faction], KARMA_DB_L3_CF_QUESTNAMES);
+			KOH.TableInit(KarmaData[KARMA_DB_L1.COMMONLIST][KARMA_DB_L2_C.FACTION][Faction], KARMA_DB_L3_CF_QUESTINFOS);
 		end
 		]]--
-		if (not IsAddOnLoaded("KarmaDB" .. FactionKey)) then
-			local	iLoaded, sWhyNot = LoadAddOn("KarmaDB" .. FactionKey);
+		if (not IsAddOnLoaded("KarmaDB" .. Faction)) then
+			local	iLoaded, sWhyNot = LoadAddOn("KarmaDB" .. Faction);
 			if (not iLoaded) then
-				KarmaChatDefault("Cannot access database for faction " .. FactionKey .. ": Failed to load load-on-demand module. (" .. sWhyNot .. ")");
+				KarmaChatDefault("Cannot access database for faction " .. Faction .. ": Failed to load load-on-demand module. (" .. sWhyNot .. ")");
 				KarmaChatDebug(debugstack());
 				return
 			end
 		end

-		local	xFactionDB = _G["KarmaAvEnK" .. FactionKey];
+		local	xFactionDB = _G["KarmaAvEnK" .. Faction];
 		if (type(xFactionDB) ~= "table") then
-			KarmaChatDefault("Cannot access database for faction " .. FactionKey .. ": Failed to initialize load-on-demand module properly.");
+			KarmaChatDefault("Cannot access database for faction " .. Faction .. ": Failed to initialize load-on-demand module properly.");
 			KarmaChatDebug(debugstack());
 			return
 		end
@@ -1862,9 +1880,8 @@ end
 function	KarmaObj.DB.FactionCacheInit(bInit)
 	local	bSet = KDBC.FactionObjectCache == nil;
 	if (KDBC.Realm and KDBC.PlayerFaction) then
-		local	oFactionDB = _G["KarmaAvEnK" .. KDBC.PlayerFaction];
-		if (type(oFactionDB) == "table") then
-			KDBC.FactionObjectCache = oFactionDB[KARMA_DB_L1.REALMLIST][KDBC.Realm];
+		if (type(KDBC.Faction) == "table") then
+			KDBC.FactionObjectCache = KDBC.Faction[KARMA_DB_L1.REALMLIST][KDBC.Realm];
 		end
 	end