std::vector < std::string > human_getset::get_vector(std::vector < std::string > names, int element){ for(unsigned int i = 0; i < names.size(); i++){ names[i] = get_single(names[i], element); } return names; }
static void menu_friend_quick_add() { char command; char *name; char old[L_USERNAME + 1]; friend_t f; int i; unsigned int id2; nox = 1; menu_friend_list(FRIEND); cprintf("\1gWhich slot do you want to edit\1w: \1c"); command = get_single("0123456789 \r\n"); if (command == '\r' || command == ' ' || command == '\n' || command == 'q') return; i = command - '0'; if (mono_sql_uu_quickx2user(usersupp->usernum, i, &id2) == -1) { strcpy(old, ""); } else if (mono_cached_sql_u_id2name(id2, old) == -1) { strcpy(old, ""); } if (strlen(old) != 0) { cprintf("\1gDo you want to remove \1y%s \1gfrom slot \1w(\1g%d\1w)\1g ?\1c ", old, i); if (yesno() == NO) return; mono_sql_uu_remove_quickx(usersupp->usernum, id2); } /* ask new name! */ cprintf("\1f\1gEnter username\1w: \1c"); name = get_name(5); if (strlen(name) == 0) return; if (strchr(name, '@') != NULL) { cprintf("\1f\1rSorry, InterBBS names are not allowed.\n"); return; } else if (mono_cached_sql_u_name2id(name, &id2) == -1) { cprintf("\1f\1rNo such user.\n"); return; } if (!is_cached_friend(name)) { strcpy(f.name, name); f.quickx = i; mono_sql_uu_add_entry(usersupp->usernum, id2, L_FRIEND); } else mono_sql_uu_add_quickx(usersupp->usernum, id2, i); cprintf("\1f\1gUser \1y%s \1gwas added to slot \1w(\1g%d\1w)\1g.\n", name, i); return; }
EXPORT_C TInt bases::GetBaseId(TInt id) { cell_list_node *n=0; n=get_single(id); while (n && n->merged_to != n->id) { id=n->merged_to; n=get_single(id); } if (n->is_base == true) { return n->id; } else { return -1; } }
void bases::NewSensorEventL(const TTupleName& aTuple, const TDesC& , const CBBSensorEvent& aEvent) { CALLSTACKITEM_N(_CL("bases"), _CL("NewSensorEventL")); #ifdef __WINS__ //User::Leave(KErrGeneral); //return; #endif const TBBCellId* cell=bb_cast<TBBCellId>(aEvent.iData()); if (aEvent.iPriority()!=CBBSensorEvent::VALUE || !cell) return; if (!testing) now=aEvent.iStamp(); bool missing_data=false; if ( cell->iLocationAreaCode()==0 ) { if (started) { if (aTuple==KNoTuple) { now_at_location(cell, -1, false, false, aEvent.iStamp()); } return; } missing_data=true; } TInt id=cell->iMappedId(); current_cell_value=*cell; cell_list_node *n=0; n=get_single(id); while (n && n->merged_to != n->id) { id=n->merged_to; n=get_single(id); } if (started && current) { // see if we have a gap between stop and start if (current->id!=id) { // different cell, allow 10 minute difference TTimeIntervalMinutes d(10); if (previous_time+d < now && !missed_data ) { current->f++; update_database(current, false); current=0; } } else { // same cell, allow 30 minute difference TTimeIntervalMinutes d(30); if (previous_time+d < now) { current->f++; update_database(current, false); current=0; } } if (!current) iCandidates->reset(); } started=false; bool same_loc=true; if (current) { if (current->id != id) { current->f++; same_loc=false; iGraph->AddEdge(current->id, id); } #ifdef __S60V3__ TInt64 diff=now.Int64()-previous_time.Int64(); double unaged_spent=I64REAL(diff)/(1024.0*1024.0); #else double unaged_spent=(now.Int64()-previous_time.Int64()).GetTReal()/(1024.0*1024.0); #endif if (unaged_spent<0.0) unaged_spent=0.0; double spent=scale*unaged_spent; current->unaged_t+=unaged_spent; MergeEvent(current, unaged_spent, !same_loc); previous_time=now; move_into_place(current, spent); update_database(current, same_loc); } else { previous_time=now; same_loc=false; } if (missing_data ) { now_at_location(cell, -1, false, false, aEvent.iStamp()); started=true; missed_data=true; return; } else { missed_data=false; } if (!n) { n=new (ELeave) cell_list_node(id, now); CC_TRAPD(err, cell_hash->AddDataL(id, n)); if (err!=KErrNone) { delete n; User::Leave(1); } n->prev=last_cell; if (last_cell) { last_cell->next=n; n->pos=last_cell->pos+1; } last_cell=n; } if (!first_cell) { first_cell=n; n->pos=0; } while (n && n->merged_to != n->id) { id=n->merged_to; n=(cell_list_node*)cell_hash->GetData(id); } current=n; n->last_seen=now; update_database(n, true); if (now.DayNoInYear()!=previous_day.DayNoInYear()) { scale*=(1.0/aging); if (scale>1024.0) { rescale(); } previous_day=now; bases_info->t=scale; update_database(bases_info, false); } if (!testing) { now_at_location(cell, id, n->is_base, !same_loc, aEvent.iStamp()); } }
void bases::read_from_database(bool aConvertOnly, CCellMap* aCellMap) { CALLSTACKITEM_N(_CL("bases"), _CL("read_from_database")); TInt dbver=0; Settings().GetSettingL(SETTING_BASEDB_VERSION, dbver); if (!aConvertOnly) { clear(); User::LeaveIfError(table.SetIndex(idx_id)); bases_info=get_single(0); TInt rescalings=0; if (bases_info) { first_time=bases_info->last_seen; scale=bases_info->t; rescalings=bases_info->rescaled; } User::LeaveIfError(table.SetIndex(idx_t)); TBool rows_left=table.LastL(); cell_list_node* previous=0; int pos=0; total_t=0.0; double t; while (rows_left) { table.GetL(); TInt id; id=table.ColUint32(colno_id); t=table.ColReal(colno_t); /* * This doesn't quite work. We should still * update the total with the smaller items as well. * And to do that they should be scaled here, and * maybe rewritten to the db, which might take a lot of time. * So leave it for now - MR 20041215 if (t < limit ) { // not reading very small items will allow // us lower memory consumption with little // accuracy loss in the base decision. They'll // still be read by get_single() as necessary rows_left=table.PreviousL(); continue; } */ cell_list_node *n=new (ELeave) cell_list_node(id, table.ColTime(colno_last_seen)); n->t=t; n->f=table.ColUint32(colno_f); n->in_db=true; n->rescaled=table.ColUint32(colno_rescaled); if (table.ColUint32(colno_isbase)==1) { n->is_base=true; } else { n->is_base=false; } if (n->id==0) { // bases info, got it already delete n; } else { // actual cell if (table.ColUint32(colno_iscurrent)==1) { current=n; previous_time=n->last_seen; previous_day=previous_time; } if (dbver<3) { n->merged_to=n->id; n->unaged_t=0.0; n->f=0; } else { n->merged_to=table.ColUint32(colno_merged_to); if (n->merged_to == 0) n->merged_to=n->id; n->unaged_t=table.ColReal(colno_unaged_t); } if (n->t < 0.0) { n->t=0.0; } if (n->unaged_t < 0.0) { n->unaged_t=0.0; } if (previous) { previous->next=n; n->cum_t=previous->cum_t+n->t; } else { first_cell=n; n->cum_t=n->t; } n->prev=previous; previous=n; n->pos=pos++; total_t+=n->t; cell_hash->AddDataL(n->id, n); } rows_left=table.PreviousL(); } Settings().WriteSettingL(SETTING_BASEDB_VERSION, LATEST_DBVER); User::LeaveIfError(table.SetIndex(idx_id)); bool needed_rescaling=false; db.Begin(); RDebug::Print(_L("scaling db...")); cell_list_node *n=first_cell; while (n) { TInt i=1; if (n->rescaled < bases_info->rescaled && n->t>0) { TReal scale; TReal pow=bases_info->rescaled-n->rescaled; Math::Pow(scale, 1024.0, pow); n->t/=scale; n->rescaled=bases_info->rescaled; update_database(n, false); needed_rescaling=true; if (i % 50 == 0) { db.Commit(); db.Compact(); } } i++; n=n->next; } db.Commit(); db.Compact(); RDebug::Print(_L("scaling db done.")); last_cell=previous; if (needed_rescaling) { RDebug::Print(_L("sorting...")); sort(); RDebug::Print(_L("done sorting.")); previous=last_cell; } if (previous) { previous->next=0; up_to_date_cum_pos=previous->pos; last_cell=previous; } else { total_t=0; up_to_date_cum_pos=0; } } else { table.SetNoIndex(); TBool rows_left=table.FirstL(); while (rows_left) { table.GetL(); TInt id; id=table.ColUint32(colno_id); if (dbver<2 && id>0) { aCellMap->SetId(table.ColDes(colno_cellid), id); } rows_left=table.NextL(); } } }
void edit_room_field(room_t * QRedit, unsigned int forum_id, int fieldnum) { int loop, i, j = 0; char *quad_name; switch (fieldnum) { case '1': cprintf("%s%s%s%s", "\1rPlease keep length of name to under 36 characters.\n", "\1w ", "|------------------------------------|\n", "\1rEnter new quadrant name\1w: \1c"); quad_name = get_name(3); if (strlen(quad_name) < 1) { cprintf("\1gOk, name not changed.\n"); break; } if (get_room_number(quad_name) != -1) { cprintf("\1rThat name is already taken, sorry.\n"); } else { log_sysop_action("changed %ss name into %s.", QRedit->name, quad_name); strcpy(QRedit->name, quad_name); mono_sql_f_rename_forum(forum_id, quad_name); /* if we rename a guessname, up the generation no */ if ( QRedit->flags & QR_GUESSNAME ) QRedit->generation++; need_rewrite = TRUE; } break; /*-------------------------------------------------------------------*/ case '3': /* room type */ cprintf("\1g%s Type: \1w<\1r1\1w> \1gPublic \1w<\1r2\1w> \1rPrivate \1w: \1c", config.forum); loop = get_single("12"); if (loop == '1') { cprintf("\1g%s set to PUBLIC.\n\n", config.forum); QRedit->flags &= ~QR_PRIVATE; } else if (loop == '2') { cprintf("\1r%s set to INVITE ONLY.\n\n", config.forum); QRedit->flags |= QR_PRIVATE; cprintf("Kick out all users? "); if (yesno() == YES) { QRedit->generation++; if (QRedit->generation == 100) QRedit->generation = 10; if (invite(who_am_i(NULL), curr_rm) == -1) cprintf("Error inviting yourself.\n"); } } need_rewrite = TRUE; break; /*--------------------------------------------------------------------*/ case '4': cprintf("\1gPostType: \1w<\1y1\1w> \1gNormal \1w<\1y2\1w>\1pAnon-only \1w<\1y3\1w>\1pAnon-option \1w: \1c"); loop = get_single("123"); if (loop == '1') { /* normal room, remove flags */ QRedit->flags &= ~QR_ANONONLY; QRedit->flags &= ~QR_ANON2; } if (loop == '2') { /* anononly room, set & unset proper flags */ QRedit->flags |= QR_ANONONLY; QRedit->flags &= ~QR_ANON2; } if (loop == '3') { /* anonopt room */ QRedit->flags |= QR_ANON2; QRedit->flags &= ~QR_ANONONLY; } if (QRedit->flags & (QR_ANONONLY | QR_ANON2)) { cprintf("\1gShould the users be able to use Aliasnames? (y/n) "); if (yesno() == YES) QRedit->flags |= QR_ALIASNAME; else QRedit->flags &= ~QR_ALIASNAME; } else QRedit->flags &= ~QR_ALIASNAME; need_rewrite = TRUE; break; /*--------------------------------------------------------------------*/ case '5': QRedit->flags ^= QR_SUBJECTLINE; need_rewrite = TRUE; break; /*--------------------------------------------------------------------*/ case '6': QRedit->flags ^= QR_DESCRIBED; need_rewrite = TRUE; break; /*--------------------------------------------------------------------*/ case '7': QRedit->flags ^= QR_READONLY; need_rewrite = TRUE; break; /*--------------------------------------------------------------------*/ case '8': QRedit->flags ^= QR_NOZAP; need_rewrite = TRUE; break; /*--------------------------------------------------------------------*/ case '9': QRedit->flags ^= QR_INUSE; need_rewrite = TRUE; break; /*--------------------------------------------------------------------*/ case '0': QRedit->flags ^= QR_GUESSNAME; need_rewrite = TRUE; break; /*--------------------------------------------------------------------*/ case 'a': case 'A': cprintf("\1rEnter the new maximum number of messages\1w(\1r%d\1w): \1c", QRedit->maxmsg); j = qc_get_pos_int('\0', 4); if (j < 10) { cprintf("\1rDon't be daft! 10 messages is the minimum.\n"); break; } else if (j > 1000) { cprintf("\1rDon't be daft! 1000 messages is the maximum.\n"); break; } else { QRedit->maxmsg = j; need_rewrite = TRUE; break; } /*--------------------------------------------------------------------*/ case 'b': case 'B': cprintf("\1rEnter the new highest %s\1w: \1c", config.message); j = qc_get_pos_int('\0', 7); cprintf("\1f\1gAre you \1rSURE\1g you want to set the highest for `\1y%s\1g` to \1w%ld\1g? \1c", QRedit->name, j); if (yesno() == YES) { QRedit->highest = j; cprintf("\1gIf you say so... done.\n"); need_rewrite = TRUE; } break; /*--------------------------------------------------------------------*/ case 'c': case 'C': cprintf("\1rEnter the new lowest %s\1w: \1c", config.message); j = qc_get_pos_int('\0', 7); cprintf("\1f\1gAre you \1rSURE\1g you want to set the lowest for `\1y%s\1g` to \1w%ld\1g? \1c", QRedit->name, j); if (yesno() == YES) { QRedit->lowest = j; cprintf("\1gIf you say so... done.\n"); need_rewrite = TRUE; } break; /*--------------------------------------------------------------------*/ case 'd': case 'D': for (i = 0; i < CATEGORIES; i++) cprintf("\1w<\1r%2d\1w>\1g %s\n", i, fish[i]); cprintf("\1gEnter the new category number\1w: \1c"); if ((i = qc_get_pos_int('\0', 2)) < 0) break; else { if (i >= CATEGORIES) { cprintf("\n\1r+++ OUT OF CHEESE ERROR - REDO FROM START +++\n\n"); break; } else { strcpy(QRedit->category, fish[i]); need_rewrite = TRUE; break; } cprintf("\1r\1nUm, what?\n\n"); } break; /*--------------------------------------------------------------------*/ default: break; } /* end switch */ }
void editroom() { char command; int done; /* don't mung Lobby>, Mail> or Yells> if you're 'only' Sysop */ if ((curr_rm <= 5) && (usersupp->priv < PRIV_WIZARD)) { cprintf("\1f\1rNope. Only %ss can edit this %s.\1a\n", config.wizard, config.forum); return; } need_rewrite = done = FALSE; quickroom = readquad(curr_rm); /* read in current settings */ while (!done) { /* display room information */ cprintf("\1w\1f------------------------------------------------------------------\n"); cprintf("\n\1r[\1w1\1r] \1gEdit %s Name\1w : \1%c%s\1g.", config.forum, (quickroom.flags & QR_PRIVATE) ? 'r' : (quickroom.flags & (QR_ANONONLY | QR_ANON2)) ? 'p' : 'g', quickroom.name); cprintf("\n\1r[\1w3\1r] \1gEdit %s Type\1w: ", config.forum); cprintf("%s", (quickroom.flags & QR_PRIVATE) ? "\1rPRIVATE " : "\1gPUBLIC "); cprintf("\1g %s.", config.forum); cprintf("\n\1r[\1w4\1r] \1gEdit Message Type\1w: "); cprintf("%s %s", (quickroom.flags & QR_ANONONLY) ? "\1bANONYMOUS ONLY" : ((quickroom.flags & QR_ANON2) ? "\1bANONYMOUS OPTION" : "\1gNORMAL"), (quickroom.flags & QR_ALIASNAME) ? "\1w(\1bALIASNAME\1w)" : ""); cprintf("\n\1r[\1w5\1r] \1gSubjectLines \1w: "); cprintf("%s", (quickroom.flags & QR_SUBJECTLINE) ? "\1gYEP." : "\1rNOOOOOOOOO!"); cprintf("\n\1r[\1w6\1r] \1gDescribed \1w: "); cprintf("%s", (quickroom.flags & QR_DESCRIBED) ? "\1gYEP." : "\1rNOOOOOOOOO!"); IFSYSOP { cprintf("\n\1r[\1w7\1r] \1gReadOnly \1w: "); cprintf("%s", (quickroom.flags & QR_READONLY) ? "\1gYEP." : "\1rNOOOOOOOOO!"); cprintf("\n\1r[\1w8\1r] \1gNoZap \1w: "); cprintf("%s", (quickroom.flags & QR_NOZAP) ? "\1gYEP." : "\1rNOOOOOOOOO!"); cprintf("\n\1r[\1w9\1r] \1gIN-USE \1w: "); cprintf("%s", (quickroom.flags & QR_INUSE) ? "\1gYEP." : "\1rNOOOOOOOOO!"); cprintf("\n\1r[\1w0\1r] \1gGuessname \1w: "); cprintf("%s", (quickroom.flags & QR_GUESSNAME) ? "\1gYEP." : "\1rNOOOOOOOOO!"); cprintf("\n\1r[\1wA\1r] \1gMaximum number of messages\1w: %d.", quickroom.maxmsg); cprintf("\n\1r[\1wB\1r] \1gHighest message number\1w: %ld.", quickroom.highest); cprintf("\n\1r[\1wC\1r] \1gLowest message number \1w: %ld.", quickroom.lowest); cprintf("\n\1r[\1wD\1r] \1g%s category \1w: \1y%s.", config.forum, quickroom.category); cprintf("\n\n\1wDon't fiddle with A, B, and C unless you KNOW what you're doing!\n"); } cprintf("\1rField to change \1w:\n"); cprintf("\1w<\1renter\1w>\1g to exit. "); command = get_single("134567890ABCD\n\r"); if (command == '\n' || command == '\r') done = TRUE; else edit_room_field(&quickroom, curr_rm, command); } /* end while */ if (need_rewrite == TRUE) { cprintf("\1rSave changes \1w(\1ry/n\1w)\1r? "); if (yesno() == NO) { /* reload old quickroom and return */ quickroom = readquad(curr_rm); } else { write_quad(quickroom, curr_rm); log_sysop_action("roomedited %s>", quickroom.name); } } }
void create_room() { int number; char command, *quad_name; for (number = 0; number < MAXQUADS; number++) if (!(readquad(number).flags & QR_INUSE)) { cprintf("\n\1f\1gFound an unused %s at slot \1y%d\1g.\n", config.forum, number); cprintf("\1gStop searching and use this position? \1w(\1rY\1w/\1rn\1w): \1c"); if (yesno_default(YES) == YES) { cprintf("\1f\1gInstall %s into slot \1y%d\1g? \1w(\1rY\1w/\1rn\1w): \1c", config.forum, number); if (yesno_default(YES) == NO) return; else break; } else continue; } if (number >= MAXQUADS) { cprintf("\1f\1rNo unused %s was found.\n", config.forum); return; } cprintf("\1f\1rPlease keep the length of the name under 36 characters.\n |------------------------------------|\n\1f\1gName for new %s\1w: \1c", config.forum); quad_name = get_name(3); if (strlen(quad_name) == 0) return; if (get_room_number(quad_name) != -1) { cprintf("\1rA %s named '%s' already exists.\n", config.forum, quad_name); return; } curr_rm = number; quickroom = readquad(curr_rm); strcpy(quickroom.name, quad_name); quickroom.generation++; quickroom.lowest = ++quickroom.highest; quickroom.maxmsg = 100; quickroom.flags = QR_INUSE; cprintf("\1f\1g%s%s ", config.forum, "Type: \1w<\1y1\1w> \1gPublic \1w<\1y2\1w> \1rPrivate : \1c"); command = get_single("12"); if (command == '1') { /* public room */ cprintf("\1rThe %s will be PUBLIC.\n\n", config.forum); quickroom.flags &= ~QR_PRIVATE; } else { /* invite -- just private flag, guessname off */ cprintf("\1rThe %s will be INVITE ONLY.\n\n", config.forum); quickroom.flags |= QR_PRIVATE; if (quickroom.generation >= 100) quickroom.generation = 10; } write_quad(quickroom, curr_rm); gotocurr(); /* takes care of self invite.. no matter, sysop anyways */ log_sysop_action("created %s: %s> ", config.forum, quickroom.name); editroom(); change_forum_info(); qc_edit_room(); }