void CSocket::TriggerEvent(const string eventName, const string arg1) { CLuaArguments args; args.PushString(eventName.c_str()); lua_getglobal(m_pLuaVM, "root"); CLuaArgument RootElement(m_pLuaVM, -1); args.PushUserData(RootElement.GetLightUserData()); args.PushUserData(m_pUserdata); if (arg1.length() > 0) args.PushString(arg1.c_str()); args.Call(m_pLuaVM, "triggerEvent"); }
void CBanManager::DoPulse ( void ) { time_t tTime = time ( NULL ); if ( tTime > m_tUpdate ) { list < CBan* > ::const_iterator iter = m_BanManager.begin (); while ( iter != m_BanManager.end () ) { if ( (*iter)->GetTimeOfUnban () > 0 ) { if ( tTime >= (*iter)->GetTimeOfUnban () ) { // Trigger the event CLuaArguments Arguments; Arguments.PushUserData ( *iter ); g_pGame->GetMapManager()->GetRootElement()->CallEvent ( "onUnban", Arguments ); RemoveBan ( *iter ); iter = m_BanManager.begin (); continue; } } iter++; } m_tUpdate = tTime + 1; } }
void CResource::Load ( CClientEntity *pRootEntity ) { m_pRootEntity = pRootEntity; if ( m_pRootEntity ) { // Set the GUI parent to the resource root entity m_pResourceCOLRoot->SetParent ( m_pResourceEntity ); m_pResourceDFFEntity->SetParent ( m_pResourceEntity ); m_pResourceGUIEntity->SetParent ( m_pResourceEntity ); m_pResourceTXDRoot->SetParent ( m_pResourceEntity ); } CLogger::LogPrintf ( "> Starting resource '%s'", m_szResourceName ); char szBuffer [ MAX_PATH ] = { 0 }; list < CResourceConfigItem* >::iterator iterc = m_ConfigFiles.begin (); for ( ; iterc != m_ConfigFiles.end (); iterc++ ) { if ( !(*iterc)->Start() ) { CLogger::LogPrintf ( "Failed to start resource item %s in %s\n", (*iterc)->GetName(), m_szResourceName ); } } // Load the files that are queued in the list "to be loaded" list < CResourceFile* > ::iterator iter = m_ResourceFiles.begin (); for ( ; iter != m_ResourceFiles.end (); iter++ ) { CResourceFile* pResourceFile = *iter; // Only load the resource file if it is a client script if ( pResourceFile->GetResourceType () == CDownloadableResource::RESOURCE_FILE_TYPE_CLIENT_SCRIPT ) { // Load the file std::vector < char > buffer; FileLoad ( pResourceFile->GetName (), buffer ); // Check the contents if ( buffer.size () > 0 && CChecksum::GenerateChecksumFromBuffer ( &buffer.at ( 0 ), buffer.size () ).CompareWithLegacy ( pResourceFile->GetServerChecksum () ) ) { // Load the resource text m_pLuaVM->LoadScriptFromBuffer ( &buffer.at ( 0 ), buffer.size (), pResourceFile->GetName () ); } else { SString strBuffer ( "ERROR: File '%s' in resource '%s' - CRC mismatch.", pResourceFile->GetShortName (), m_szResourceName ); g_pCore->ChatEchoColor ( strBuffer, 255, 0, 0 ); } } else if ( CheckFileForCorruption ( pResourceFile->GetName () ) ) { SString strBuffer ( "WARNING: File '%s' in resource '%s' is invalid.", pResourceFile->GetShortName (), m_szResourceName ); g_pCore->DebugEchoColor ( strBuffer, 255, 0, 0 ); } } // Set active flag m_bActive = true; // Did we get a resource root entity? if ( m_pResourceEntity ) { // Call the Lua "onClientResourceStart" event CLuaArguments Arguments; Arguments.PushUserData ( this ); m_pResourceEntity->CallEvent ( "onClientResourceStart", Arguments, true ); } else assert ( 0 ); }