-- makefile - Chat System module installation file -- (component of Chat System) -- Template attachment: none -- Created by: Patrick Ferland -- Created on: 07/11/2008 -- Revision History -- 07/11/2008 P.Ferland - New script -- 07/24/2008 P.Ferland - Updated for publish -- 08/04/2008 P.Ferland - Improved resilience of import/upgrade process -- 08/08/2008 P.Ferland - DoCommand -> stylesheet.AttachTemplateScript -- 09/25/2008 P.Ferland - Reworked import/upgrade path to function with no user context -- 11/13/2008 P.Ferland - Added MCP notification on import -- Constants WORLD_CHAT_SCRIPT = '11302:9' WORLD_CHAT_HISTORY = '11302:24' PLAYER_CHAT_SCRIPT = '11302:10' CHAT_ENTITY = '11302:11' PLAYER_UI_SCRIPT = '13197:23' PLAYER_TEMPLATE = '0:1' WORLD_TEMPLATE = '0:3' CHAT_SYSTEM_TEMPLATE = '11302:4' -- ??? Bug hunting 10/14/2008 CHAT_EMOTE_SCRIPT = '11302:48' -- 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) if (user ~= nil) then notify_mcp(user) end 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() -- Check for singleton if (w.chat_system ~= nil) then DeleteFromDb(w.chat_system) UnpersistObject(w.chat_system) DestroyObject(w.chat_system) 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 player UI script') safe_attach_script(PLAYER_TEMPLATE, PLAYER_UI_SCRIPT) Log(SEV_INFO, 'Attaching world chat script') safe_attach_script(WORLD_TEMPLATE, WORLD_CHAT_SCRIPT) Log(SEV_INFO, 'Attaching world chat history script') safe_attach_script(WORLD_TEMPLATE, WORLD_CHAT_HISTORY) Log(SEV_INFO, 'Attaching player chat entity script') safe_attach_script(PLAYER_TEMPLATE, CHAT_ENTITY) Log(SEV_INFO, 'Attaching player chat script') safe_attach_script(PLAYER_TEMPLATE, PLAYER_CHAT_SCRIPT) -- Check for singleton if (w.chat_system == nil) then -- Create if needed local chat_system = CreateInContainerById(w, CHAT_SYSTEM_TEMPLATE) PersistObject(chat_system) SaveToDb(chat_system) end Log(SEV_INFO, 'Detaching and reattaching emote script - unknown bug/PF') safe_detach_script(CHAT_SYSTEM_TEMPLATE, CHAT_EMOTE_SCRIPT) safe_attach_script(CHAT_SYSTEM_TEMPLATE, CHAT_EMOTE_SCRIPT) Log(SEV_INFO, 'Reloading skin data') SendTo(w.chat_system, 'chat_init_skins', 0) Log(SEV_INFO, 'Performing object versioning') SendTo(w.chat_system, 'chat_system_version_check', 0) end function safe_detach_script(template_id, script_id, test_object) local safe_to_detach = 1 if (test_object ~= nil) then if (HasScriptById(test_object, script_id) == 0) then safe_to_detach = 0 end end if (safe_to_detach ~= 0) then Log(SEV_INFO, 'Detaching script ' .. script_id .. ' from template ' .. template_id) local result = stylesheet.DetachTemplateScript(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 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 function notify_mcp(user) local w = GetWorld() local st = w.singleton_tracker if (st ~= nil) then local mcp = st['mcp'] if (mcp ~= nil) then SendTo(mcp, 'mcp_notify', 0, 'You have added the Chat System to the Metaplace Control Panel (MCP)!

' .. 'Press Shift-M to bring up the MCP, and there will be a new button to configure your Chat System.', user) end end end