-- makefile - MCP module installation file -- (component of MCP) -- Template attachment: none -- Created by: Patrick Ferland -- Created on: 07/11/2008 -- Revision History -- 07/11/2008 P.Ferland - New script -- 07/14/2008 P.Ferland - Tweaks per server update -- 07/24/2008 P.Ferland - Enabled auto-install -- 07/31/2008 P.Ferland - Added world tracker/autospawn installation -- 08/04/2008 P.Ferland - Improved resilience of import/upgrade process -- 09/25/2008 P.Ferland - Reworked import/upgrade path to function with no user context -- Constants PLAYER_TEMPLATE = '0:1' PLACE_TEMPLATE = '0:2' WORLD_TEMPLATE = '0:3' PLAYER_MCP_SCRIPT = '11832:7' WORLD_SINGLETON_SCRIPT = '11661:5' WORLD_MCP_SCRIPT = '11832:14' MCP_TEMPLATE = '11832:4' -- Script Properties -- no properties -- Triggers Trigger module_import(module_world_id, module_name, user) Log(SEV_INFO, 'Importing module ' .. module_name .. '(' .. module_world_id .. ')') import_or_upgrade(module_world_id, module_name, user) Log(SEV_INFO, 'Import complete') end Trigger module_upgrade(module_world_id, module_name, user) Log(SEV_INFO, 'Upgrading module ' .. module_name .. '(' .. module_world_id .. ')') import_or_upgrade(module_World_id, module_name, user) Log(SEV_INFO, 'Upgrade complete') end Trigger module_unimport(module_world_id, module_name, user) Log(SEV_INFO, 'Unimporting module ' .. module_name .. '(' .. module_world_id .. ')') local w = GetWorld() local st = w.singleton_Tracker -- Check for singleton if (st ~= nil) then local mcp = st['mcp'] if (mcp ~= nil) then DeleteFromDb(mcp) UnpersistObject(mcp) DestroyObject(mcp) end end Log(SEV_INFO, 'Unimport complete') end -- Local functions function import_or_upgrade(module_world_id, module_name, user) local user_name = 'Metaplace (system)' if (user ~= nil) then user_name = user.name end Log(SEV_INFO, 'Executing in the context of ' .. user_name) local w = GetWorld() Log(SEV_INFO, 'Attaching world singleton tracker') safe_attach_script(WORLD_TEMPLATE, WORLD_SINGLETON_SCRIPT) Log(SEV_INFO, 'Attaching world MCP script') safe_attach_script(WORLD_TEMPLATE, WORLD_MCP_SCRIPT) Log(SEV_INFO, 'Testing for singleton tracker') local st = w.singleton_tracker if (st == nil) then Log(SEV_INFO, 'Could not find singleton tracker; aborting.') return end Log(SEV_INFO, 'Testing for MCP singleton') if (st['mcp'] == nil) then Log(SEV_INFO, 'Creating MCP singleton') Log(SEV_INFO, MCP_TEMPLATE) local mcp = CreateInContainerById(w, MCP_TEMPLATE) Log(SEV_INFO, mcp.id) PersistObject(mcp) SaveToDb(mcp) end Log(SEV_INFO, 'Attaching Player MCP UI script') safe_attach_script(PLAYER_TEMPLATE, PLAYER_MCP_SCRIPT) end function safe_attach_script(template_id, script_id, test_object) local safe_to_attach = 1 if (test_object ~= nil) then if (HasScriptById(test_object, script_id) == 1) then safe_to_attach = 0 end end if (safe_to_attach ~= 0) then Log(SEV_INFO, 'Attaching script ' .. script_id .. ' to template ' .. template_id) local result = stylesheet.AttachTemplateScript(template_id, script_id) if (result ~= true) then Log(SEV_INFO, 'An error was encountered. ' .. 'The most likely cause is that the script was already attached, and this error can be safely ignored.') end end end