tsc_result TSC_CALLTYPE tscGetVersion( TSC_VERSION_DATA* pData ) { tsc_func_init(); CModule* pM = CModule::GetInstance(); if (!pM) return Error_Internal_NullModulePtr(); if (!pData) return Error_ParamWasNull(); if (pData->cbSize != sizeof(TSC_VERSION_DATA)) return Error_StructSizeInvalid(); CVersionData d(*pData); tsc_result r = TSC_E_FAIL; r = pM->GetVersion(d); if (TSC_SUCCEEDED(r)) { *pData << d; } return r; }
IModule * CreateModule(const IRepository *rep, const std::_tstring &label, const ECLModule * data) { CModule * mod = CreateModuleRaw(rep, label.c_str(), false); ATLASSERT(mod); mod->Update(data); return mod; }
bool CUser::UpdateModule(const CString &sModule) { const map<CString,CUser*>& Users = CZNC::Get().GetUserMap(); map<CString,CUser*>::const_iterator it; map<CUser*, CString> Affected; map<CUser*, CString>::iterator it2; bool error = false; for (it = Users.begin(); it != Users.end(); ++it) { CModule *pMod = it->second->GetModules().FindModule(sModule); if (pMod) { Affected[it->second] = pMod->GetArgs(); it->second->GetModules().UnloadModule(pMod->GetModName()); } } CString sErr; for (it2 = Affected.begin(); it2 != Affected.end(); ++it2) { if (!it2->first->GetModules().LoadModule(sModule, it2->second, it2->first, sErr)) { error = true; DEBUG("Failed to reload [" << sModule << "] for [" << it2->first->GetUserName() << "]: " << sErr); } } return !error; }
const char *WINAPI MGetMsg(int PluginNumber,int MsgId) { CModule *module = (CModule *)PluginNumber; if (!module) return ""; return module->GetMsg(MsgId); }
bool CModules::UnloadModule(const CString& sModule, CString& sRetMsg) { CString sMod = sModule; // Make a copy incase the reference passed in is from CModule::GetModName() CModule* pModule = FindModule(sMod); sRetMsg = ""; if (!pModule) { sRetMsg = "Module [" + sMod + "] not loaded."; return false; } bool bSuccess; GLOBALMODULECALL(OnModuleUnloading(pModule, bSuccess, sRetMsg), pModule->GetUser(), NULL, return bSuccess); ModHandle p = pModule->GetDLL(); if (p) { delete pModule; for (iterator it = begin(); it != end(); ++it) { if (*it == pModule) { erase(it); break; } } dlclose(p); sRetMsg = "Module [" + sMod + "] unloaded"; return true; } sRetMsg = "Unable to unload module [" + sMod + "]"; return false; }
void CWell::HandleCollision(IEntity* other) { SGD::Vector dir; if ( tier >= 3 && (duration - timer) < 0.1f) { dir = other->GetPosition() - position; dir.Normalize(); other->AddGravity(dir * strength * 2); EntityType type = (EntityType)other->GetType(); if (type == EntityType::Asteroid) { CAsteroid* ast = dynamic_cast<CAsteroid*>(other); ast->TakeDamage(int(strength * 0.075f)); } else if (type >= EntityType::Player && type <= EntityType::Coordinator) { CShip* ship = dynamic_cast<CShip*>(other); ship->TakeDamage(int(strength * 0.075f)); } else if (type >= EntityType::BaseModule && type <= EntityType::WarpModule) { CModule* mod = dynamic_cast<CModule*>(other); mod->TakeDamage(int(strength * 0.075f)); } return; } dir = position - other->GetPosition(); if (dir.ComputeLength() < 1) dir.y += 1; dir.Normalize(); //float mass = other->GetSize().width * other->GetSize().height; other->AddGravity(dir * strength); }
int main(int argc, char *argv[]) { int i = 1; while (i < argc) { // scanning, parsing & semantical analysis CScanner *s = new CScanner(new ifstream(argv[i])); CParser *p = new CParser(s); cout << "parsing '" << argv[i] << "'..." << endl; CAstNode *ast = p->Parse(); if (p->HasError()) { const CToken *error = p->GetErrorToken(); cout << "parse error : at " << error->GetLineNumber() << ":" << error->GetCharPosition() << " : " << p->GetErrorMessage() << endl; } else { // AST to TAC conversion cout << "converting to TAC..." << endl; CModule *m = new CModule(ast); // print TAC to console cout << m << endl; cout << endl; // output TAC as .dot and generate a PDF file from it ofstream out(string(argv[i]) + ".dot"); out << "digraph IR {" << endl << " graph [fontname=\"Times New Roman\",fontsize=10];" << endl << " node [fontname=\"Courier New\",fontsize=10];" << endl << " edge [fontname=\"Times New Roman\",fontsize=10];" << endl << endl; m->toDot(out, 2); const vector<CScope*> &proc = m->GetSubscopes(); for (size_t p=0; p<proc.size(); p++) { proc[p]->toDot(out, 2); } out << "}" << endl; out.flush(); ostringstream cmd; cmd << "dot -Tpdf -o" << argv[i] << ".pdf " << argv[i] << ".dot"; cout << "run the following command to convert the .dot file into a PDF:" << endl << " " << cmd.str() << endl; delete m; } cout << endl << endl; i++; } cout << "Done." << endl; return EXIT_SUCCESS; }
void tsc_func_init() { s_szLastError = s_szErrNoErr; CModule* pM = CModule::GetInstance(); if (pM) pM->ClearLastError(); }
void CAppSignal::OnWorkspace(class CUIWorkspace* pUIWorkspace, const POINT& pt) { EnterCriticalSection(&m_csControls); { if ( pUIWorkspace == m_pUIWorkspace ) { POINT ptScreen = { pt.x, pt.y }; ClientToScreen(pUIWorkspace->GetHwnd(), &ptScreen); HMENU hMenu = CreatePopupMenu(); map<string, CFactory<CModule>::FACTORYSTRUCT*>& mapFactory = CFactory<CModule>::GetFactoryMap(); for ( map<string, CFactory<CModule>::FACTORYSTRUCT*>::iterator iter = mapFactory.begin() ; iter != mapFactory.end() ; ++iter ) { MODULEFACTORYDATA* pmfd = ((MODULEFACTORYDATA*)iter->second->pvData); if ( !pmfd ) continue; AppendMenu(hMenu, MF_STRING, (uint32)iter->second, pmfd->m_sCategory.c_str()); } uint32 nResult = TrackPopupMenu(hMenu, TPM_RETURNCMD|TPM_LEFTALIGN|TPM_LEFTBUTTON, ptScreen.x, ptScreen.y, 0, GetHwnd(), NULL); if ( nResult != 0 ) { CFactory<CModule>::FACTORYSTRUCT* pfs = (CFactory<CModule>::FACTORYSTRUCT*)nResult; MODULEFACTORYDATA* pmfd = ((MODULEFACTORYDATA*)pfs->pvData); CUIModule* pUIModule = (CUIModule*)CFactory<CUIWindow>::Create("CUIModule"); CModule* pModule = (CModule*)pfs->fnCreate(); pUIModule->SetModule(pModule); pModule->SetUIModule(pUIModule); pUIModule->SetParent(m_pUIWorkspace); m_pUIWorkspace->AddChild(pUIModule); MODULEINITSTRUCT mis; mis.pApp = this; pModule->Init(mis); pModule->PostInit(); CUIWindow::CREATESTRUCT cs; cs.x = pt.x; cs.y = pt.y; cs.hWndParent = m_pUIWorkspace->GetHwnd(); cs.pUIHost = pModule; cs.dict.SetString("title", pmfd->m_sCategory); pUIModule->Create(cs); m_listModules.push_back(pModule); m_listUIModules.push_back(pUIModule); } DestroyMenu(hMenu); } } LeaveCriticalSection(&m_csControls); }
IModule * CreateModule(const IRepository *rep, const ns2__ECLModule * data, bool noBroadcast) { ATLASSERT(data->Name); ATLASSERT(!data->Name->empty()); CModule * mod = CreateModuleRaw(rep, data->Name->c_str(), false); ATLASSERT(mod); mod->Update(data, noBroadcast); return mod; }
// Why MODHALTCHK works only with functions returning EModRet ? :( bool CModules::OnServerCapAvailable(const CString& sCap) { bool bResult = false; for (unsigned int a = 0; a < size(); ++a) { try { CModule* pMod = (*this)[a]; CClient* pOldClient = pMod->GetClient(); pMod->SetClient(m_pClient); if (m_pUser) { CUser* pOldUser = pMod->GetUser(); pMod->SetUser(m_pUser); bResult |= pMod->OnServerCapAvailable(sCap); pMod->SetUser(pOldUser); } else { // WTF? Is that possible? bResult |= pMod->OnServerCapAvailable(sCap); } pMod->SetClient(pOldClient); } catch (CModule::EModException e) { if (CModule::UNLOAD == e) { UnloadModule((*this)[a]->GetModName()); } } } return bResult; }
// Maybe create new macro for this? bool CModules::IsClientCapSupported(CClient* pClient, const CString& sCap, bool bState) { bool bResult = false; for (unsigned int a = 0; a < size(); ++a) { try { CModule* pMod = (CModule*) (*this)[a]; CClient* pOldClient = pMod->GetClient(); pMod->SetClient(m_pClient); if (m_pUser) { CUser* pOldUser = pMod->GetUser(); pMod->SetUser(m_pUser); bResult |= pMod->IsClientCapSupported(pClient, sCap, bState); pMod->SetUser(pOldUser); } else { // WTF? Is that possible? bResult |= pMod->IsClientCapSupported(pClient, sCap, bState); } pMod->SetClient(pOldClient); } catch (CModule::EModException e) { if (CModule::UNLOAD == e) { UnloadModule((*this)[a]->GetModName()); } } } return bResult; }
bool CModules::UnloadModule(const CString& sModule, CString& sRetMsg) { CString sMod = sModule; // Make a copy incase the reference passed in is from CModule::GetModName() CModule* pModule = FindModule(sMod); sRetMsg = ""; if (!pModule) { sRetMsg = "Module [" + sMod + "] not loaded."; return false; } if (pModule->IsFake()) { for (iterator it = begin(); it != end(); it++) { if (*it == pModule) { erase(it); sRetMsg = "Fake module [" + sMod + "] unloaded"; return true; } } sRetMsg = "Fake module [" + sMod + "] not loaded."; return false; } ModHandle p = pModule->GetDLL(); if (p) { typedef void (*fp)(CModule*); fp Unload = (fp)dlsym(p, "ZNCModUnload"); if (Unload) { Unload(pModule); for (iterator it = begin(); it != end(); it++) { if (*it == pModule) { erase(it); break; } } dlclose(p); sRetMsg = "Module [" + sMod + "] unloaded"; return true; } else { sRetMsg = "Unable to unload module [" + sMod + "] could not find ZNCModUnload()"; return false; } } sRetMsg = "Unable to unload module [" + sMod + "]"; return false; }
void CSession::FreeCurrentDictionary() { if (m_pEnchantDict) { CModule* pMod = CModule::GetInstance(); if (pMod) { pMod->FreeDictionary(m_pEnchantDict); m_pEnchantDict = NULL; } } }
tsc_result TSC_CALLTYPE tscDestroySession( tsc_cookie SessionID ) { tsc_func_init(); CModule* pM = CModule::GetInstance(); if (!pM) return Error_Internal_NullModulePtr(); tsc_result r = TSC_E_FAIL; r = pM->DestroySession(SessionID); return r; }
const char* TSC_CALLTYPE tscGetLastError() { if (s_szLastError != s_szErrNoErr) return s_szLastError; else { CModule* pM = CModule::GetInstance(); if (pM) return pM->GetLastError(); else return s_szErrErr; // catch-all error text } }
void CHijackChecker::check(CSysConfig& conf, CModule& mod) { WStrContainer libs; WStrContainer::iterator it; mod.get_import_libs(libs); mod.get_module_path(m_mod_dir); conf.get_search_dirs(m_search_dirs); for (it = libs.begin(); it != libs.end(); it++) { wstring& lib = *it; check_module(conf, lib, true); } }
CUser* GetUser(const CString& username) { if (username.Equals("$me")) return m_pUser; CUser *pUser = CZNC::Get().FindUser(username); if (!pUser) { PutModule("Error: User not found: " + username); return NULL; } if (pUser != m_pUser && !m_pUser->IsAdmin()) { PutModule("Error: You need to have admin rights to modify other users!"); return NULL; } return pUser; }
// rp_get_symbol(lib, const symbol[]) static cell AMX_NATIVE_CALL rp_get_symbol(AMX *amx, cell *params) { CModule* mod = (CModule *)params[1]; int len; const char* symbol = g_amxxapi.GetAmxString(amx, params[2], 0, &len); if (!mod) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid library handle provided in rp_get_symbol(0, \"%s\")", symbol); return NULL; } return (cell)mod->getSymbolAddress(symbol); }
// rp_find_signature(lib, const symbol[]) static cell AMX_NATIVE_CALL rp_find_signature(AMX *amx, cell *params) { CModule* mod = (CModule *)params[1]; int len; const char* sig = g_amxxapi.GetAmxString(amx, params[2], 0, &len); if (!mod) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid library handle provided in rp_find_signature(0, \"%s\")", sig); return NULL; } return (cell)mod->findPattern(sig, PARAMS_COUNT == 3 && params[3]); }
tsc_result TSC_CALLTYPE tscUninit( void ) { tsc_func_init(); CModule* pM = CModule::GetInstance(); if (!pM) return Error_Internal_NullModulePtr(); tsc_result r = TSC_E_FAIL; r = pM->Uninit(); return r; }
CModule * CDsnInfo::AddModule(string name, EClkRate clkRate) { m_modList.push_back(new CModule(name, clkRate, false)); CModule * pModule = m_modList.back(); if (g_appArgs.GetIqModName() == name) pModule->AddQueIntf("hif", "hifInQue", Pop, "5"); if (g_appArgs.GetOqModName() == name) pModule->AddQueIntf("hif", "hifOutQue", Push, "5"); return pModule; }
void SendNotification(CModule& module, const CString& sSender, const CString& sNotification, const CChan *pChannel) { // todo parse from m_sPushEndpoint bool bUseTLS = true; CString sHostname = "api.palaverapp.com"; unsigned short uPort = 443; CString sPath = "/1/push"; CString sJSON = "{"; sJSON += "\"message\": \"" + sNotification.Replace_n("\"", "\\\"") + "\""; sJSON += ",\"sender\": \"" + sSender.Replace_n("\"", "\\\"") + "\""; if (pChannel) { sJSON += ",\"channel\": \"" + pChannel->GetName().Replace_n("\"", "\\\"") + "\""; } sJSON += "}"; CSocket *pSocket = new CSocket(&module); pSocket->Connect(sHostname, uPort, bUseTLS); pSocket->Write("POST " + sPath + " HTTP/1.1\r\n"); pSocket->Write("Host: " + sHostname + "\r\n"); pSocket->Write("Authorization: Bearer " + GetToken() + "\r\n"); pSocket->Write("Connection: close\r\n"); pSocket->Write("User-Agent: ZNC\r\n"); pSocket->Write("Content-Type: application/json\r\n"); pSocket->Write("Content-Length: " + CString(sJSON.length()) + "\r\n"); pSocket->Write("\r\n"); pSocket->Write(sJSON); pSocket->Close(Csock::CLT_AFTERWRITE); module.AddSocket(pSocket); }
void ListUsers(const CString&) { if (!m_pUser->IsAdmin()) return; const map<CString, CUser*>& msUsers = CZNC::Get().GetUserMap(); CTable Table; Table.AddColumn("Username"); Table.AddColumn("Realname"); Table.AddColumn("IsAdmin"); Table.AddColumn("Nick"); Table.AddColumn("AltNick"); Table.AddColumn("Ident"); Table.AddColumn("VHost"); for (map<CString, CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); it++) { Table.AddRow(); Table.SetCell("Username", it->first); Table.SetCell("Realname", it->second->GetRealName()); if (!it->second->IsAdmin()) Table.SetCell("IsAdmin", "No"); else Table.SetCell("IsAdmin", "Yes"); Table.SetCell("Nick", it->second->GetNick()); Table.SetCell("AltNick", it->second->GetAltNick()); Table.SetCell("Ident", it->second->GetIdent()); Table.SetCell("VHost", it->second->GetVHost()); } PutModule(Table); }
void AddServer(const CString& sLine) { CString username = sLine.Token(1); CString server = sLine.Token(2, true); if (server.empty()) { PutModule("Usage: addserver <username> <server>"); return; } CUser* user = GetUser(username); if (!user) return; user->AddServer(server); PutModule("Added IRC Server: " + server); }
// read an IRC line and do token substitution // throws an exception if a required parameter is missing, and might also throw if you manage to make it bork CString Imprint(CString line) const { CString output; CString alias_data = GetCommands(); alias_data = parent->ExpandString(alias_data); size_t lastfound = 0, skip = 0; // it would be very inefficient to attempt to blindly replace every possible token // so let's just parse the line and replace when we find them // token syntax: // %[?]n[+]% // adding ? makes the substitution optional (you'll get "" if there are insufficient tokens, otherwise the alias will fail) // adding + makes the substitution contain all tokens from the nth to the end of the line while (true) { // if (found >= (int) alias_data.length()) break; // shouldn't be possible. size_t found = alias_data.find("%", lastfound + skip); if (found == CString::npos) break; // if we found nothing, break output.append(alias_data.substr(lastfound, found - lastfound)); // capture everything between the last stopping point and here ParseToken(alias_data, line, output, found, skip); // attempt to read a token, updates indices based on success/failure lastfound = found; } output += alias_data.substr(lastfound); // append from the final return output; }
tsc_result TSC_CALLTYPE tscCheckSpelling( tsc_cookie SessionID, TSC_CHECKSPELLING_DATA* pData ) { tsc_func_init(); CModule* pM = CModule::GetInstance(); if (!pM) return Error_Internal_NullModulePtr(); if (!pData) return Error_ParamWasNull(); tsc_result r = TSC_E_FAIL; r = pM->CheckSpelling(SessionID, pData); return r; }
void CDsnInfo::AddHostData(void * pHandle, HtdFile::EHostMsgDir msgDir, bool bMaxBw) { CModule * pModule = (CModule *)pHandle; switch (msgDir) { case HtdFile::Inbound: m_modList[0]->AddQueIntf(pModule->m_modName.AsStr(), "ihd", Push, "5", HtdFile::eDistRam, bMaxBw); pModule->AddQueIntf("hif", "ihd", Pop, "5", HtdFile::eDistRam, bMaxBw); break; case HtdFile::Outbound: m_modList[0]->AddQueIntf(pModule->m_modName.AsStr(), "ohd", Pop, "5"); pModule->AddQueIntf("hif", "ohd", Push, "5"); break; default: break; } }
CString GetModArgs(CUser* pUser, const CString& sModName, bool bGlobal = false) { if (!bGlobal && !pUser) { return ""; } CModules& Modules = (bGlobal) ? CZNC::Get().GetModules() : pUser->GetModules(); for (unsigned int a = 0; a < Modules.size(); a++) { CModule* pModule = Modules[a]; if (pModule->GetModName() == sModName) { return pModule->GetArgs(); } } return ""; }
tsc_result TSC_CALLTYPE tscCustomDic( tsc_cookie SessionID, TSC_CUSTOMDIC_DATA* pData ) { tsc_func_init(); CModule* pM = CModule::GetInstance(); if (!pM) return Error_Internal_NullModulePtr(); if (!pData) return Error_ParamWasNull(); tsc_result r = TSC_E_FAIL; r = pM->CustomDic(SessionID, pData); return r; }