bool loadModules() { loadEmbeddedModules(L); ChangeDir cd; if (!cd.changeDir(L"modules")) { lua_register(L, "require", require_stub); return false; } tstring path(cd.getCurrentDir()); path.append(L"\\modules\\?.dll"); luaopen_package(L); lua_pushstring(L, "path"); lua_pushstring(L, ""); lua_settable(L, -3); lua_pushstring(L, "cpath"); lua_pushstring(L, TW2A(path.c_str())); lua_settable(L, -3); lua_setglobal(L, "package"); lua_pop(L, 1); std::vector<tstring> files; { WIN32_FIND_DATA fd; memset(&fd, 0, sizeof(WIN32_FIND_DATA)); HANDLE file = FindFirstFile(L"*.*", &fd); if (file != INVALID_HANDLE_VALUE) { do { if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (Module::isModule(fd.cFileName)) files.push_back(fd.cFileName); } } while (::FindNextFile(file, &fd)); ::FindClose(file); } } for (int j = 0, je = files.size(); j < je; ++j) { TW2A w2a(files[j].c_str()); if (luaL_dofile(L, w2a)) { tstring error(L"Ошибка при загрузке модуля: '"); error.append(files[j]); error.append(L"' - "); error.append(luaT_towstring(L, -1)); pluginOut(error.c_str()); } } return true; }
void MsdpNetwork::translate(DataQueue& msdp) { const tbyte* data = (const tbyte*)msdp.getData(); int len = msdp.getSize(); //OUTPUT_BYTES(data, len, len, "MSDP"); while (len > 0) { if (len < 3 || data[0] != IAC || data[2] != MSDP) { assert(false); msdp.clear(); return; } tbyte cmd = data[1]; if (cmd == SB) { const tbyte *p = data; for (int i=3; i<len; ++i) { if (p[i]==SE && p[i-1]==IAC && p[i-2]!=IAC) { run_plugins_msdp(p+3, i-4); len = i+1; break; } } msdp.truncate(len); } else if (cmd == DO) { m_state = true; msdp.truncate(3); send_varval("CLIENT_NAME", "TORTILLA"); send_varval("CLIENT_VERSION", TW2A(TORTILLA_VERSION)); tortilla::getPluginsManager()->processPluginsMethod("msdpon", 0); } else if (cmd == DONT) { m_state = false; msdp.truncate(3); tortilla::getPluginsManager()->processPluginsMethod("msdpoff", 0); releaseReports(); } else { assert(false); msdp.clear(); return; } data = (const tbyte*)msdp.getData(); len = msdp.getSize(); } }
bool Plugin::loadLuaPlugin(const wchar_t* fname) { tstring plugin_file(L"plugins\\"); plugin_file.append(fname); if (luaL_loadfile(L, TW2A(plugin_file.c_str()))) { pluginLoadError(lua_toerror(L)); lua_pop(L, 1); return false; } if (lua_pcall(L, 0, 1, 0)) { pluginLoadError(lua_toerror(L)); lua_pop(L, 1); return false; } return initLoadedPlugin(fname); }
bool Plugin::initLoadedPlugin(const wchar_t* fname) { file = fname; const wchar_t *ext = wcsrchr(fname, L'.'); filename.assign(fname, ext - fname); module = TW2A(filename.c_str()); if (!lua_istable(L, -1)) { lua_pop(L, 1); lua_pushnil(L); lua_setglobal(L, module.c_str()); tstring error(fname); error.append(L":plugin_open() did not return a table."); pluginLoadError(error.c_str()); return false; } lua_setglobal(L, module.c_str()); bool loaded = isLoadedPlugin(filename.c_str()); if (loaded) { getparam("name", &name); getparam("version", &version); getparam("description", &description); if (name.empty() || version.empty()) loaded = false; } if (!loaded) { lua_pushnil(L); lua_setglobal(L,module.c_str()); } return loaded; }