lotrointerface.com
Search Downloads

LoTROInterface SVN Reminders

[/] [trunk/] [Thurallor/] [Common/] [Utils/] [ServerID.lua] - Rev 2

Compare with Previous | Blame | View Log

import "Turbine";
import "Turbine.UI";
import "Turbine.UI.Lotro";

local serverData = Turbine.PluginData.Load(Turbine.DataScope.Server, "Thurallor_ServerID") or {};
local accountData = Turbine.PluginData.Load(Turbine.DataScope.Account, "Thurallor_ServerIDs") or {};

if (not serverData.ID) then
    local nextID = 1;
    while (accountData["Server" .. nextID]) do
        nextID = nextID + 1;
    end
    serverData.ID = "Server" .. nextID;
    Turbine.PluginData.Save(Turbine.DataScope.Server, "Thurallor_ServerID", serverData);
    accountData[serverData.ID] = "(unknown)";
    Turbine.PluginData.Save(Turbine.DataScope.Account, "Thurallor_ServerIDs", accountData);
end

Turbine.Engine._serverID = serverData.ID;
Turbine.Engine._serverNames = accountData;

-- Returns the server name, or nil if unknown.
-- If the serverID arg is omitted, returns the name for the current server.
function Turbine.Engine.GetServerName(_, serverID)
    local name = Turbine.Engine._serverNames[Turbine.Engine._serverID];
    if (serverID) then
        name = Turbine.Engine._serverNames[serverID];
    end
    if (name ~= "(unknown)") then
        return name;
    end
end

-- Returns a string that is a unique identifier for the server, even if the name is unknown.
function Turbine.Engine.GetServerID()
    return Turbine.Engine._serverID;
end

-- Returns a list of server IDs for all known servers.
function Turbine.Engine.GetServerIDs()
    local serverIDs = {};
    for ID, name in pairs(Turbine.Engine._serverNames) do
        table.insert(serverIDs, ID);
    end
    table.sort(serverIDs);
    return serverIDs;
end

-- Saves the server name for future reference.
function Turbine.Engine.SetServerName(_, serverName)
    if (type(serverName) ~= "string") then
        error("serverName must be a string", 2);
    end
    Turbine.Engine._serverNames[Turbine.Engine._serverID] = serverName;
    Turbine.PluginData.Save(Turbine.DataScope.Account, "Thurallor_ServerIDs", Turbine.Engine._serverNames);
end

-- An enumeration of all currently-existing server names.
Turbine.ServerName = {
    Anor = 1,
    Arkenstone = 2,
    Belegaer = 3,
    Bombadil = 4,
    Bullroarer = 5,
    Brandywine = 6,
    Crickhollow = 7,
    Evernight = 8,
    Gladden = 9,
    Gwaihir = 10,
    Ithil = 11,
    Landroval = 12,
    Laurelin = 13,
    Palantir = 14,
    Shadowfax = 17,
    Sirannon = 15,
    Treebeard = 16
};

-- The directory name in PluginData/<account> for each server:
Turbine.ServerDirectoryName = {
    Anor =        "Anor",
    Arkenstone =  "Arkenstone",
    Belegaer =    "[DE-RP] Belegaer",
    Bombadil =    "Bombadil",
    Bullroarer =  "Bullroarer",
    Brandywine =  "Brandywine",
    Crickhollow = "Crickhollow",
    Evernight =   "[EN] Evernight",
    Gladden =     "Gladden",
    Gwaihir =     "[DE] Gwaihir",
    Ithil =       "Ithil",
    Landroval =   "Landroval",
    Laurelin =    "[EN-RP] Laurelin",
    Palantir =    "Palantir",
    Shadowfax =   "Shadowfax",
    Sirannon =    "[FR] Sirannon",
    Treebeard =   "Treebeard"
};

Compare with Previous | Blame


All times are GMT -5. The time now is 12:27 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui