static cell_t SQL_TQuery(IPluginContext *pContext, const cell_t *params) { IDatabase *db = NULL; HandleError err; if ((err = g_DBMan.ReadHandle(params[1], DBHandle_Database, (void **)&db)) != HandleError_None) { return pContext->ThrowNativeError("Invalid database Handle %x (error: %d)", params[1], err); } if (!db->GetDriver()->IsThreadSafe()) { return pContext->ThrowNativeError("Driver \"%s\" is not thread safe!", db->GetDriver()->GetIdentifier()); } IPluginFunction *pf = pContext->GetFunctionById(params[2]); if (!pf) { return pContext->ThrowNativeError("Function id %x is invalid", params[2]); } char *query; pContext->LocalToString(params[3], &query); cell_t data = params[4]; PrioQueueLevel level = PrioQueue_Normal; if (params[5] == (cell_t)PrioQueue_High) { level = PrioQueue_High; } else if (params[5] == (cell_t)PrioQueue_Low) { level = PrioQueue_Low; } CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext()); TQueryOp *op = new TQueryOp(db, pf, query, data); if (pPlugin->GetProperty("DisallowDBThreads", NULL) || !g_DBMan.AddToThreadQueue(op, level)) { /* Do everything right now */ op->RunThreadPart(); op->RunThinkPart(); op->Destroy(); } return 1; }
void ConVarManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) { int argcount = command.ArgC(); if (argcount >= 3) { bool wantReset = false; /* Get plugin index that was passed */ const char *arg = command.Arg(2); if (argcount >= 4 && strcmp(arg, "reset") == 0) { wantReset = true; arg = command.Arg(3); } /* Get plugin object */ CPlugin *plugin = g_PluginSys.FindPluginByConsoleArg(arg); if (!plugin) { g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", arg); return; } /* Get plugin name */ const sm_plugininfo_t *plinfo = plugin->GetPublicInfo(); const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename(); ConVarList *pConVarList; ConVarList::iterator iter; /* If no convar list... */ if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) { g_RootMenu.ConsolePrint("[SM] No convars found for: %s", plname); return; } if (!wantReset) { g_RootMenu.ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); g_RootMenu.ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); } /* Iterate convar list and display/reset each one */ for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) { /*const */ConVar *pConVar = const_cast<ConVar *>(*iter); if (!wantReset) { g_RootMenu.ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); } else { pConVar->Revert(); } } if (wantReset) { g_RootMenu.ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname); } return; } /* Display usage of subcommand */ g_RootMenu.ConsolePrint("[SM] Usage: sm cvars [reset] <plugin #>"); }
static cell_t SQL_TConnect(IPluginContext *pContext, const cell_t *params) { IPluginFunction *pf = pContext->GetFunctionById(params[1]); if (!pf) { return pContext->ThrowNativeError("Function id %x is invalid", params[1]); } char *conf; pContext->LocalToString(params[2], &conf); IDBDriver *driver = NULL; const DatabaseInfo *pInfo = g_DBMan.FindDatabaseConf(conf); char error[255]; if (pInfo != NULL) { if (pInfo->driver[0] == '\0') { driver = g_DBMan.GetDefaultDriver(); } else { driver = g_DBMan.FindOrLoadDriver(pInfo->driver); } if (!driver) { UTIL_Format(error, sizeof(error), "Could not find driver \"%s\"", pInfo->driver[0] == '\0' ? g_DBMan.GetDefaultDriverName() : pInfo->driver); } else if (!driver->IsThreadSafe()) { UTIL_Format(error, sizeof(error), "Driver \"%s\" is not thread safe!", driver->GetIdentifier()); } } else { UTIL_Format(error, sizeof(error), "Could not find database conf \"%s\"", conf); } if (!pInfo || !driver) { pf->PushCell(BAD_HANDLE); pf->PushCell(BAD_HANDLE); pf->PushString(error); pf->PushCell(0); pf->Execute(NULL); return 0; } /* HACK! Add us to the dependency list */ CExtension *pExt = g_Extensions.GetExtensionFromIdent(driver->GetIdentity()); if (pExt) { g_Extensions.BindChildPlugin(pExt, g_PluginSys.GetPluginByCtx(pContext->GetContext())); } /* Finally, add to the thread if we can */ TConnectOp *op = new TConnectOp(pf, driver, conf, params[3]); CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext()); if (pPlugin->GetProperty("DisallowDBThreads", NULL) || !g_DBMan.AddToThreadQueue(op, PrioQueue_High)) { /* Do everything right now */ op->RunThreadPart(); op->RunThinkPart(); op->Destroy(); } return 1; }