void game::wishitem( player *p, int x, int y, int z) { if ( p == NULL && x <= 0 ) { debugmsg("game::wishitem(): invalid parameters"); return; } const std::vector<std::string> standard_itype_ids = item_controller->get_all_itype_ids(); int prev_amount, amount = 1; uimenu wmenu; wmenu.w_x = 0; wmenu.w_width = TERMX; wmenu.pad_right = ( TERMX / 2 > 40 ? TERMX - 40 : TERMX / 2 ); wmenu.return_invalid = true; wmenu.selected = uistate.wishitem_selected; wish_item_callback *cb = new wish_item_callback( standard_itype_ids ); wmenu.callback = cb; for (size_t i = 0; i < standard_itype_ids.size(); i++) { item ity( standard_itype_ids[i], 0 ); wmenu.addentry( i, true, 0, string_format(_("%s"), ity.tname(1, false).c_str()) ); wmenu.entries[i].extratxt.txt = string_format("%c", ity.symbol()); wmenu.entries[i].extratxt.color = ity.color(); wmenu.entries[i].extratxt.left = 1; } do { wmenu.query(); if ( wmenu.ret >= 0 ) { item granted(standard_itype_ids[wmenu.ret], calendar::turn); prev_amount = amount; if (p != NULL) { amount = std::atoi( string_input_popup(_("How many?"), 20, to_string( amount ), granted.tname()).c_str()); } if (dynamic_cast<wish_item_callback *>(wmenu.callback)->incontainer) { granted = granted.in_its_container(); } if ( p != NULL ) { for (int i = 0; i < amount; i++) { p->i_add(granted); } p->invalidate_crafting_inventory(); } else if ( x >= 0 && y >= 0 ) { m.add_item_or_charges( tripoint( x, y, z ), granted); wmenu.keypress = 'q'; } if ( amount > 0 ) { dynamic_cast<wish_item_callback *>(wmenu.callback)->msg = _("Wish granted. Wish for more or hit 'q' to quit."); } uistate.wishitem_selected = wmenu.ret; if ( !amount ) { amount = prev_amount; } } } while ( wmenu.keypress != 'q' && wmenu.keypress != KEY_ESCAPE && wmenu.keypress != ' ' ); delete wmenu.callback; wmenu.callback = NULL; return; }
ResourceManager::ResourceManager() : QObject(), m_resources(0), m_result(false), m_waiting(false) { qRegisterMetaType<ResourcePolicy::ResourceSet*>("ResourcePolicy::ResourceSet*"); qRegisterMetaType<ResourcePolicy::ResourceType>("ResourcePolicy::ResourceType"); qRegisterMetaType<QList<ResourcePolicy::ResourceType> >("QList<ResourcePolicy::ResourceType>"); m_resources = new ResourcePolicy::ResourceSet(QString::fromAscii("camera"), this); m_resources->setAlwaysReply(); m_resources->addResource(ResourcePolicy::VideoPlaybackType); m_resources->addResource(ResourcePolicy::VideoRecorderType); QObject::connect(m_resources, SIGNAL(resourcesDenied()), this, SLOT(denied())); QObject::connect(m_resources, SIGNAL(lostResources()), this, SLOT(lost())); QObject::connect(m_resources, SIGNAL(resourcesGranted(QList<ResourcePolicy::ResourceType>)), this, SLOT(granted())); }
void game::wishitem( player *p, int x, int y) { if ( p == NULL && x <= 0 ) { debugmsg("game::wishitem(): invalid parameters"); return; } int amount = 1; uimenu wmenu; wmenu.w_x = 0; wmenu.w_width = TERMX; wmenu.pad_right = ( TERMX / 2 > 40 ? TERMX - 40 : TERMX / 2 ); wmenu.return_invalid = true; wmenu.selected = uistate.wishitem_selected; wish_item_callback *cb = new wish_item_callback(); wmenu.callback = cb; for (int i = 0; i < standard_itype_ids.size(); i++) { itype *ity = item_controller->find_template(standard_itype_ids[i]); wmenu.addentry( i, true, 0, string_format(_("%s"), ity->nname(1).c_str()) ); wmenu.entries[i].extratxt.txt = string_format("%c", ity->sym); wmenu.entries[i].extratxt.color = ity->color; wmenu.entries[i].extratxt.left = 1; } do { wmenu.query(); if ( wmenu.ret >= 0 ) { item granted(standard_itype_ids[wmenu.ret], calendar::turn); if (p != NULL) { amount = helper::to_int( string_input_popup(_("How many?"), 20, helper::to_string_int( amount ), granted.tname())); } if (dynamic_cast<wish_item_callback *>(wmenu.callback)->incontainer) { granted = granted.in_its_container(); } if ( p != NULL ) { for (int i = 0; i < amount; i++) { p->i_add(granted); } } else if ( x >= 0 && y >= 0 ) { m.add_item_or_charges(x, y, granted); wmenu.keypress = 'q'; } dynamic_cast<wish_item_callback *>(wmenu.callback)->msg = _("Wish granted. Wish for more or hit 'q' to quit."); uistate.wishitem_selected = wmenu.ret; } } while ( wmenu.keypress != 'q' && wmenu.keypress != KEY_ESCAPE && wmenu.keypress != ' ' ); delete wmenu.callback; wmenu.callback = NULL; return; }
void sign_in(void) { //sign in char user[50], pwd[50], line[50]; printf("MENU ~ SIGN IN\n"); printf("--------------"); tRestart: printf("\nUsername: "******"%s", user); printf("PIN #: "); scanf("%s", pwd); system("clear"); FILE *file; file = fopen("accounts.csv", "r"); while (fgets(line, sizeof(line), file) != NULL) { char *USER = strtok(line, ","); char *PASSER = strtok(NULL, ","); int mUsername = strcmp(user, USER); int mPassword = strcmp(pwd, PASSER); if (mUsername == 0 && mPassword == 0) { fclose(file); granted(); exit(EXIT_SUCCESS); //leave function } } fclose(file); system("clear"); printf("\nINVALID USERNAME OR PIN #, TRY AGAIN...\n"); goto tRestart; }
void debug_menu::wishitem( player *p, int x, int y, int z ) { if( p == NULL && x <= 0 ) { debugmsg( "game::wishitem(): invalid parameters" ); return; } const auto opts = item_controller->all(); int prev_amount, amount = 1; uimenu wmenu; wmenu.w_x = 0; wmenu.w_width = TERMX; wmenu.pad_right = ( TERMX / 2 > 40 ? TERMX - 40 : TERMX / 2 ); wmenu.return_invalid = true; wmenu.selected = uistate.wishitem_selected; wish_item_callback cb( opts ); wmenu.callback = &cb; for( size_t i = 0; i < opts.size(); i++ ) { item ity( opts[i], 0 ); wmenu.addentry( i, true, 0, string_format( _( "%.*s" ), wmenu.pad_right - 5, ity.tname( 1, false ).c_str() ) ); wmenu.entries[i].extratxt.txt = ity.symbol(); wmenu.entries[i].extratxt.color = ity.color(); wmenu.entries[i].extratxt.left = 1; } do { wmenu.query(); if( wmenu.ret >= 0 ) { item granted( opts[wmenu.ret] ); prev_amount = amount; if( p != NULL ) { string_input_popup() .title( _( "How many?" ) ) .width( 20 ) .description( granted.tname() ) .edit( amount ); } if( dynamic_cast<wish_item_callback *>( wmenu.callback )->incontainer ) { granted = granted.in_its_container(); } if( p != NULL ) { for( int i = 0; i < amount; i++ ) { p->i_add( granted ); } p->invalidate_crafting_inventory(); } else if( x >= 0 && y >= 0 ) { g->m.add_item_or_charges( tripoint( x, y, z ), granted ); wmenu.keypress = 'q'; } if( amount > 0 ) { dynamic_cast<wish_item_callback *>( wmenu.callback )->msg = _( "Wish granted. Wish for more or hit 'q' to quit." ); } uistate.wishitem_selected = wmenu.ret; if( !amount ) { amount = prev_amount; } } } while( wmenu.keypress != 'q' && wmenu.keypress != KEY_ESCAPE && wmenu.keypress != ' ' ); }
void debug_menu::wishitem( player *p, int x, int y, int z ) { if( p == NULL && x <= 0 ) { debugmsg( "game::wishitem(): invalid parameters" ); return; } const auto opts = item_controller->all(); int prev_amount = 1; int amount = 1; uimenu wmenu; wmenu.w_x = 0; wmenu.w_width = TERMX; wmenu.pad_right = ( TERMX / 2 > 40 ? TERMX - 40 : TERMX / 2 ); wmenu.return_invalid = true; wmenu.selected = uistate.wishitem_selected; wish_item_callback cb( opts ); wmenu.callback = &cb; for( size_t i = 0; i < opts.size(); i++ ) { item ity( opts[i], 0 ); wmenu.addentry( i, true, 0, string_format( _( "%.*s" ), wmenu.pad_right - 5, ity.tname( 1, false ).c_str() ) ); wmenu.entries[i].extratxt.txt = ity.symbol(); wmenu.entries[i].extratxt.color = ity.color(); wmenu.entries[i].extratxt.left = 1; } do { wmenu.query(); if( wmenu.ret >= 0 ) { item granted( opts[wmenu.ret] ); if( cb.incontainer ) { granted = granted.in_its_container(); } if( cb.has_flag ) { granted.item_tags.insert( cb.flag ); } prev_amount = amount; bool canceled = false; if( p != NULL ) { string_input_popup popup; popup .title( _( "How many?" ) ) .width( 20 ) .description( granted.tname() ) .edit( amount ); canceled = popup.canceled(); } if( !canceled ) { if( p != NULL ) { for( int i = 0; i < amount; i++ ) { p->i_add( granted ); } p->invalidate_crafting_inventory(); } else if( x >= 0 && y >= 0 ) { g->m.add_item_or_charges( tripoint( x, y, z ), granted ); wmenu.ret = -1; } if( amount > 0 ) { input_context ctxt( "UIMENU" ); cb.msg = string_format( _( "Wish granted. Wish for more or hit [%s] to quit." ), ctxt.get_desc( "QUIT" ).c_str() ); } } uistate.wishitem_selected = wmenu.ret; if( canceled || amount <= 0 ) { amount = prev_amount; } } } while( wmenu.ret >= 0 ); }
int main(int argc, char* argv[]) { char *operand, *temp, *shell, tbuf[PATH_MAX]; char *newenv[10], *token[] = { NULL, NULL }; int aslogin, curropt; gid_t newgid; struct passwd *pwd; #ifdef USELIMITS int prio; #endif #ifndef DONTUSESYSLOG openlog(PROGNAME, LOG_CONS, 0); #endif /* * Process command line options. */ aslogin = 0; while ((curropt = getopt(argc, argv, "-ls")) != EOF) { switch(curropt) { case '-': case 'l': aslogin = 1; break; case 's': aslogin = 0; break; case '?': default: usage(); break; } } /* * Process command line operands. */ operand = NULL; if ((optind+1) < argc) { /* too many operands */ usage(); } else if ((optind < argc) && ((operand = (strlen(argv[optind]) > GRMAX) ? NULL : argv[optind]) == NULL)) { /* potential overrun, so ignore operand */ fprintf(stderr, "%s: Unknown group\n", PROGNAME); #ifndef DONTUSESYSLOG /* assume we are attacked and log message */ syslog(LOG_AUTH|LOG_ERR, "possible buffer overrun attack by uid %d%s\n", getuid(), ontty()); #endif } #ifdef USELIMITS /* * Be nice. */ errno = 0; prio = getpriority(PRIO_PROCESS, 0); if (errno) { prio = 0; } setpriority(PRIO_PROCESS, 0, -2); #endif /* * Do authorization, determine the new group id, attempt * to get passwd struct for user, and change the group id. */ pwd = NULL; if ((newgid = granted(operand, &pwd)) != -1) { setgid(newgid); } /* * Give up setuid-root status. If this fails, we cannot create * a new shell. */ if (setuid(getuid()) == -1) { /* must abort -- cannot create a superuser shell */ fprintf(stderr, "%s: setuid: Cannot change user id\n", PROGNAME); exit(1); } /* * Determine which shell to use. If the shell in the pwd entry * is illegible, then use default path. */ shell = (pwd && pwd->pw_shell && *pwd->pw_shell) ? pwd->pw_shell : _PATH_BSHELL; token[0] = (temp = strrchr(shell, '/')) ? (temp+1) : shell; /* Do any cleanup before the exec(). */ fflush(NULL); #ifdef USELIMITS setpriority(PRIO_PROCESS, 0, prio); #endif /* At user's request, reset environment */ if (aslogin) { extern char **environ; char *ndir, *nterm, *nuser; size_t len; /* reset environment variables */ nterm = ((nterm = getenv("TERM")) && *nterm) ? nterm : "unknown"; nuser = (pwd && pwd->pw_name && *pwd->pw_name) ? pwd->pw_name : (((nuser = getenv("USER")) && *nuser) ? nuser : "******"); ndir = (pwd && pwd->pw_dir && *pwd->pw_dir) ? pwd->pw_dir : "/"; newenv[0] = NULL; environ = newenv; setenv("TERM", nterm, 1); setenv("USER", nuser, 1); setenv("LOGNAME", nuser, 1); setenv("HOME", ndir, 1); setenv("SHELL", shell, 1); { char *newpath; int newplen; newpath = alloca((newplen = confstr(_CS_PATH, NULL, 0)) + 1); if (newpath && confstr(_CS_PATH, newpath, newplen + 1) > 0) { setenv("PATH", newpath, 1); } } tbuf[0] = '-'; if ((len = strlen(token[0])) > (sizeof tbuf -2)) { fprintf(stderr, "%s: You have no shell\n", PROGNAME); exit(1); } memcpy(tbuf + 1, token[0], len+1); token[0] = tbuf; } /* Start the new shell. */ execvp(shell, token); /* could not exec a new shell */ fprintf(stderr, "%s: You have no shell\n", PROGNAME); exit(1); }