void environment::spawn_player(point2 location) { // player props auto weapon = std::make_shared<body_component::item_type>(); weapon->add({ rl::effect::weapon_damage, 0x00, 50 }); weapon->add({ rl::effect::equipment, static_cast<unsigned int>(rl::equipment_slot::hand_main) }); weapon->set_name("Copper Sword"); weapon->set_tag("copper_sword"); // make player auto task = m_factory->produce(); auto img = task->add_appearance('@', { 1, 1, 1 }); auto pawn = task->add_location(location); auto body = task->add_body(100, 100); auto character = task->add_character(); // setup body->set_name("You"); body->set_tag("player"); body->join_faction(1); body->add(weapon); body->equip(weapon); character->add_skill("sk_bash"); character->add_skill("sk_panacea"); character->add_skill("sk_teleport"); character->add_skill("sk_fireball"); character->add_skill("sk_indigo"); m_terrain.add(task->assemble(persistency::permanent)); impersonate(pawn); }
ActivePet::ActivePet(wchar_t* user_password, std::wstring petname, FileEventLoop* files) : m_petname(petname), m_files(files), m_session(INVALID_HANDLE_VALUE), m_profile(INVALID_HANDLE_VALUE), m_job(CreateJobObject(NULL, NULL)), m_next_editable_name(1), m_ticks_while_invisible(0) { // Create a new logon session for the pet. std::wstring petRegistryPath = Constants::registryPets() + L"\\" + m_petname; RegKey petkey = RegKey::HKCU.open(petRegistryPath); std::wstring accountName = petkey.getValue(L"accountName"); std::wstring accountRegistryPath = Constants::registryAccounts() + L"\\" + accountName; RegKey accountKey = RegKey::HKCU.open(accountRegistryPath); std::wstring password = accountKey.getValue(L"password"); if (!LogonUser(accountName.c_str(), NULL, password.c_str(), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &m_session)) { printf("LogonUser() failed: %d\n", GetLastError()); return; } // Tweak the Winsta0 and desktop ACLs to allow the pet to create windows. auto_buffer<PSID> logon_sid = GetLogonSID(m_session.get()); if (NULL == logon_sid.get()) { return; } auto_close<HWINSTA, &::CloseWindowStation> winsta0(OpenWindowStation(L"winsta0", FALSE, READ_CONTROL | WRITE_DAC)); if (NULL == winsta0.get()) { printf("OpenWindowStation() failed: %d\n", GetLastError()); return; } if (!AddAceToWindowStation(winsta0.get(), logon_sid.get())) { printf("AddAceToWindowStation() failed: %d", GetLastError()); return; } auto_close<HDESK, &::CloseDesktop> desktop(OpenDesktop(L"default", 0, FALSE, READ_CONTROL | WRITE_DAC | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS)); if (NULL == desktop.get()) { printf("OpenDesktop() failed: %d\n", GetLastError()); return; } if (!AddAceToDesktop(desktop.get(), logon_sid.get())) { printf("AddAceToDesktop() failed: %d\n", GetLastError()); return; } // Load the pet account's registry hive. wchar_t account[128] = {}; wcsncpy(account, accountName.c_str(), 128); PROFILEINFO profile = { sizeof(PROFILEINFO), 0, account }; if (!LoadUserProfile(m_session.get(), &profile)) { printf("LoadUserProfile() failed: %d\n", GetLastError()); return; } m_profile = profile.hProfile; // Initialize the pet job. if (NULL == m_job.get()) { printf("CreateJobObject() failed: %d\n", GetLastError()); return; } JOBOBJECT_BASIC_UI_RESTRICTIONS buir = { JOB_OBJECT_UILIMIT_HANDLES }; if (!SetInformationJobObject(m_job.get(), JobObjectBasicUIRestrictions, &buir, sizeof buir)) { printf("SetInformationJobObject() failed: %d\n", GetLastError()); } // Some apps fail to launch without access to the desktop window. if (!UserHandleGrantAccess(GetDesktopWindow(), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } // Give apps access to all the standard cursors. if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_ARROW), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_IBEAM), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_WAIT), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_CROSS), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_UPARROW), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_SIZE), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_ICON), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_SIZENWSE), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_SIZENESW), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_SIZEWE), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_SIZENS), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_SIZEALL), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_NO), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_HAND), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_APPSTARTING), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } if (!UserHandleGrantAccess(LoadCursor(NULL, IDC_HELP), m_job.get(), TRUE)) { printf("UserHandleGrantAccess() failed: %d\n", GetLastError()); } // Setup the use records for the printers. std::set<std::wstring> servers; RegKey printers = RegKey::HKCU.open(L"Printers\\Connections"); for (int i = 0; true; ++i) { RegKey printer = printers.getSubKey(i); if (!printer.isGood()) { break; } std::wstring server = printer.getValue(L"Server"); if (servers.count(server) == 0) { std::wstring resource = server + L"\\IPC$"; auto_array<wchar_t> remote(resource.length() + 1); lstrcpy(remote.get(), resource.c_str()); USE_INFO_2 use = {}; use.ui2_remote = remote.get(); use.ui2_domainname = _wgetenv(L"USERDOMAIN"); use.ui2_username = _wgetenv(L"USERNAME");; use.ui2_password = user_password; use.ui2_asg_type = USE_WILDCARD; auto_impersonation impersonate(m_session.get()); DWORD arg_error; NET_API_STATUS error = NetUseAdd(NULL, 2, (BYTE*)&use, &arg_error); if (error) { printf("NetUseAdd() failed: %d\n", error); } else { servers.insert(server); } } } // Add the message handlers. //m_requestFolderPath = accountKey.getValue(Constants::petDataPathName()) + Constants::requestPath(); m_requestFolderPath = Constants::requestsPath(Constants::polarisDataPath(Constants::userProfilePath(accountName))); m_dispatcher = new MessageDispatcher(m_requestFolderPath); m_files->watch(m_requestFolderPath, m_dispatcher); m_dispatcher->add("sendmail",makeSendMailHandler()); // TODO m_dispatcher->add("GetOpenFileNameA", makeGetOpenFileNameAHandler(this)); m_dispatcher->add("GetOpenFileNameW", makeGetOpenFileNameWHandler(this)); m_dispatcher->add("GetClipboardData", makeGetClipboardDataHandler()); }
Win32NamedPipeImpersonator::Win32NamedPipeImpersonator() { impersonate(); }
int main( int argc, char * argv[] ) { int result=0; #ifdef Q_OS_WIN hMutex = CreateMutex( NULL, true, L"FreezerSingleProcessMutex"); if (hMutex == NULL) { LOG_5( "Error: Couldn't create mutex, exiting" ); return false; } if( GetLastError() == ERROR_ALREADY_EXISTS ) { LOG_5( "Error: Another process owns the mutex, exiting" ); QList<int> pids; if( pidsByName( "freezer.exe", &pids ) ) { int otherProcessId = pids[0]; if( otherProcessId == processID() ) { if( pids.size() < 2 ) return false; otherProcessId = pids[1]; } LOG_5( "Trying to find window with process pid of " + QString::number( otherProcessId ) ); EnumWindows( AFEnumWindowsProc, LPARAM(otherProcessId) ); } return false; } QLibrary excdll( "exchndl.dll" ); if( !excdll.load() ) { qWarning( excdll.errorString().toLatin1().constData() ); } disableWindowsErrorReporting( "assburner.exe" ); #endif signal(SIGSEGV, oops_handler); signal(SIGABRT, oops_handler); QApplication a(argc, argv); if( !initConfig( "freezer.ini" ) ) { #ifndef Q_OS_WIN // Fallback if the config file does not exist in the current folder if( !initConfig( "/etc/ab/freezer.ini" ) ) #endif return -1; } #ifdef Q_OS_WIN QString cp = "h:/public/" + getUserName() + "/Blur"; if( !QDir( cp ).exists() ) cp = "C:/Documents and Settings/" + getUserName(); initUserConfig( cp + "/freezer.ini" ); #else initUserConfig( QDir::homePath() + "/.freezer" ); #endif initStone( argc, argv ); classes_loader(); initStoneGui(); { JobList showJobs; bool showTime = false; QString currentView; QStringList loadViewFiles; for( int i = 1; i<argc; i++ ){ QString arg( argv[i] ); if( arg == "-h" || arg == "--help" ) { LOG_1( QString("Freezer v") + VERSION ); LOG_1( "Options:" ); LOG_1( "-current-render" ); LOG_1( "\tShow the current job that is rendering on this machine\n" ); LOG_1( "-show-time" ); LOG_1( "\tOutputs summary of time executed for all sql statement at program close\n" ); LOG_1( "-user USER" ); LOG_1( "\tSet the logged in user to USER: Requires Admin Privs" ); LOG_1( "-current-view VIEWNAME" ); LOG_1( "\tMake VIEWNAME the active view, once they are all loaded" ); LOG_1( "-load-view FILE" ); LOG_1( "\tRead a saved view config from FILE" ); LOG_1( stoneOptionsHelp() ); return 0; } else if( arg.endsWith("-show-time") ) showTime = true; else if( arg.endsWith( "-current-render" ) ) { showJobs = Host::currentHost().activeAssignments().jobs(); } else if( arg.endsWith("-user") && (i+1 < argc) ) { QString impersonate( argv[++i] ); if( User::hasPerms( "User", true ) ) // If you can edit users, you can login as anyone User::setCurrentUser( impersonate ); } else if( arg.endsWith("-current-view") && (i+1 < argc) ) { currentView = QString( argv[++i] ); } else if( arg.endsWith("-load-view") && (i+1 < argc) ) { loadViewFiles << QString(argv[++i]); } } // Share the database across threads, each with their own connection FreezerCore::setDatabaseForThread( classesDb(), Connection::createFromIni( config(), "Database" ) ); { loadPythonPlugins(); MainWindow m; IniConfig & cfg = userConfig(); cfg.pushSection( "MainWindow" ); QStringList fg = cfg.readString( "FrameGeometry", "" ).split(','); cfg.popSection(); if( fg.size()==4 ) { m.resize( QSize( fg[2].toInt(), fg[3].toInt() ) ); m.move( QPoint( fg[0].toInt(), fg[1].toInt() ) ); } if( showJobs.size() ) m.jobPage()->setJobList( showJobs ); foreach( QString viewFile, loadViewFiles ) m.loadViewFromFile( viewFile ); if( !currentView.isEmpty() ) m.setCurrentView( currentView ); m.show(); result = a.exec(); if( showTime ){ Database * tm = Database::current(); LOG_5( " Sql Time Elapsed" ); LOG_5( "| Select | Update | Insert | Delete | Total |" ); LOG_5( "-----------------------------------------------" ); LOG_5( QString( "| %1 | %2 | %3 | %4 | %5 |\n") .arg( tm->elapsedSqlTime( Table::SqlSelect ) ) .arg( tm->elapsedSqlTime( Table::SqlUpdate ) ) .arg( tm->elapsedSqlTime( Table::SqlInsert ) ) .arg( tm->elapsedSqlTime( Table::SqlDelete ) ) .arg( tm->elapsedSqlTime() ) ); LOG_5( " Index Time Elapsed" ); LOG_5( "| Added | Updated | Incoming | Deleted | Search | Total |" ); LOG_5( "-----------------------------------------------" ); LOG_5( QString( "| %1 | %2 | %3 | %4 | %5 | %6 |\n") .arg( tm->elapsedIndexTime( Table::IndexAdded ) ) .arg( tm->elapsedIndexTime( Table::IndexUpdated ) ) .arg( tm->elapsedIndexTime( Table::IndexIncoming ) ) .arg( tm->elapsedIndexTime( Table::IndexRemoved ) ) .arg( tm->elapsedIndexTime( Table::IndexSearch ) ) .arg( tm->elapsedIndexTime() ) ); tm->printStats(); } } } shutdown(); #ifdef Q_OS_WIN CloseHandle( hMutex ); #endif return result; }
Win32NamedPipeImpersonator::Win32NamedPipeImpersonator(Win32NamedPipeNetworkSession & session) : mPipeSession(session) { impersonate(); }
Win32NamedPipeImpersonator::Win32NamedPipeImpersonator() : mPipeSession( dynamic_cast<Win32NamedPipeNetworkSession &>( RCF::getTlsRcfSessionPtr()->getNetworkSession())) { impersonate(); }