bool is_known(ast_t* type) { switch(ast_id(type)) { case TK_UNIONTYPE: case TK_TUPLETYPE: return false; case TK_ISECTTYPE: { ast_t* child = ast_child(type); while(child != NULL) { if(is_known(child)) return true; child = ast_sibling(child); } return false; } case TK_NOMINAL: { ast_t* def = (ast_t*)ast_data(type); switch(ast_id(def)) { case TK_INTERFACE: case TK_TRAIT: return false; case TK_PRIMITIVE: case TK_CLASS: case TK_ACTOR: return true; default: {} } break; } case TK_ARROW: return is_known(ast_childidx(type, 1)); case TK_TYPEPARAMREF: { ast_t* def = (ast_t*)ast_data(type); ast_t* constraint = ast_childidx(def, 1); return is_known(constraint); } default: {} } assert(0); return false; }
read_inventory_preset( const player &p ) : pickup_inventory_preset( p ), p( p ) { static const std::string unknown( _( "<color_dark_gray>?</color>" ) ); static const std::string martial_arts( _( "martial arts" ) ); append_cell( [ this, &p ]( const item_location & loc ) -> std::string { if( loc->type->can_use( "MA_MANUAL" ) ) { return martial_arts; } if( !is_known( loc ) ) { return unknown; } const auto &book = get_book( loc ); if( book.skill && p.get_skill_level_object( book.skill ).can_train() ) { return string_format( _( "%s to %d" ), book.skill->name().c_str(), book.level ); } return std::string(); }, _( "TRAINS" ), unknown ); append_cell( [ this ]( const item_location & loc ) -> std::string { if( !is_known( loc ) ) { return unknown; } const auto &book = get_book( loc ); const int unlearned = book.recipes.size() - get_known_recipes( book ); return unlearned > 0 ? to_string( unlearned ) : std::string(); }, _( "RECIPES" ), unknown ); append_cell( [ this ]( const item_location & loc ) -> std::string { if( !is_known( loc ) ) { return unknown; } return good_bad_none( get_book( loc ).fun ); }, _( "FUN" ), unknown ); append_cell( [ this, &p ]( const item_location & loc ) -> std::string { if( !is_known( loc ) ) { return unknown; } std::vector<std::string> dummy; const player *reader = p.get_book_reader( *loc, dummy ); if( reader == nullptr ) { return std::string(); // Just to make sure } // Actual reading time (in turns). Can be penalized. const int actual_turns = p.time_to_read( *loc, *reader ) / MOVES( 1 ); // Theoretical reading time (in turns) based on the reader speed. Free of penalties. const int normal_turns = get_book( loc ).time * reader->read_speed() / MOVES( 1 ); const std::string duration = to_string_approx( time_duration::from_turns( actual_turns ), false ); if( actual_turns > normal_turns ) { // Longer - complicated stuff. return string_format( "<color_light_red>%s</color>", duration.c_str() ); } return duration; // Normal speed. }, _( "CHAPTER IN" ), unknown ); }
bool object_type::could_have_charges() { if (!has_charges()) return (FALSE); if (is_known()) return (TRUE); if (ident & (IDENT_EMPTY)) return (FALSE); return (TRUE); }
/******************************************************************* * NAME : void process_document(char *fname) * * DESCRIPTION : Procesa el documento fname, palabra por palabra, * consultando al usuario sobre la accion a realizar * si la palabra no es conocida. * PARAMETERS: * INPUT: * char *fname Nombre del archivo a procesar. * * RETURN : * Type: void *******************************************************************/ void process_document(char *fname) { char current_word[MAX_WORD_SIZE]; /* completar aca */ doc_in = fopen(fname,"r"); // Abrir documento de entrada. doc_out = fopen("out.txt","w"); // Abrir documento de salida. if (doc_in != NULL && doc_out != NULL) { while (get_word(current_word) == 1) { // Lee una palabra del documento de entrada, y establece si hay mas palabras para leer. if (is_known(current_word) == 0) { // Es una palabra desconocida? consult_user(current_word); // Tratamiento de palabra desconocida. } put_word(current_word); // Agrega palabra a documento de salida. } if (ignored_size != 0) { while (ignored_size != 0) { ignored_size--; free(dict_ignored[ignored_size]); } free(dict_ignored); } if (fclose(doc_in) != 0){ // Cierra documento de entrada. printf("Error al cerrar el archivo.\n"); exit(1); // Salida forzosa del programa. } if (fclose(doc_out) != 0){ // Cierra documento de salida. printf("Error al cerrar el archivo.\n"); exit(1); // Salida forzosa del programa. } } else { printf("Error al abrir el archivo.\n"); exit(1); // Salida forzosa del programa. } }
bool object_type::is_known_cursed() { if (!is_cursed()) return (FALSE); if (is_known()) return (TRUE); if (!was_sensed()) return (FALSE); return (TRUE); }
int ws_connect(wireless_scan *ws) { char *netfile = NULL; if (hook_preup) system(hook_preup); if (mode & MODE_SECURE) { netfile = (char *) calloc(strlen(netpath)+strlen(ws->b.essid)+2, sizeof(char)); strcpy(netfile,netpath); strcat(netfile,ws->b.essid); } if ( !is_known(ws) && (mode & MODE_SECURE)) { /* secure unknown network */ char psk[64]; fprintf(stdout,"Enter passkey for \"%s\"\n> ",ws->b.essid); fflush(stdout); scanf("%s",psk); sprintf(cmd,"wpa_passphrase \"%s\" \"%s\" > \"%s\"",ws->b.essid,psk,netfile); system(cmd); } if (mode & MODE_SECURE) { /* secure known/new */ spawn("wpa_supplicant",netfile); } else { /* unsecure network */ struct iwreq req; req.u.essid.flags = 1; req.u.essid.pointer = (caddr_t) ws->b.essid; req.u.essid.length = strlen(ws->b.essid); if (we_ver < 21) req.u.essid.length++; iw_set_ext(skfd,ifname,SIOCSIWESSID,&req); } if (!is_known(ws) && (mode & MODE_ADD)) { FILE *cfg; if ( (cfg=fopen(config,"ax")) ) /* no config file, create new */ fprintf(cfg,"\n[NETWORKS]\n%s\n",ws->b.essid); else if ( (cfg=fopen(config,"a")) ) /* normal append */ fprintf(cfg,"%s\n",ws->b.essid); if (cfg) fclose(cfg); } else if (!is_known(ws) && (mode & MODE_SECURE)) { sprintf(cmd,"rm \"%s\"",netfile); system(cmd); } if (netfile) { free(netfile); netfile = NULL; } spawn(dhcp,netfile); if (hook_postup) system(hook_postup); }
int Stick::Worth() const { int worth = Category()->worth(); worth += 20 * charges(); if (!is_known()) worth /= 2; return worth; }
/* * Record when an object type has been seen */ void object_type::has_been_seen() { k_info[k_idx].everseen = TRUE; if (ego_num && is_known()) { e_info[ego_num].everseen = TRUE; } }
static bool method_application(pass_opt_t* opt, ast_t* ast, bool partial) { AST_GET_CHILDREN(ast, positional, namedargs, question, lhs); if(!method_check_type_params(opt, &lhs)) return false; ast_t* type = ast_type(lhs); if(is_typecheck_error(type)) return false; AST_GET_CHILDREN(type, cap, typeparams, params, result); if(!extend_positional_args(opt, params, positional)) return false; if(!apply_named_args(opt, params, positional, namedargs)) return false; if(!check_arg_types(opt, params, positional, partial)) return false; switch(ast_id(lhs)) { case TK_FUNREF: case TK_FUNAPP: if(ast_id(ast_child(type)) != TK_AT) { if(!check_receiver_cap(opt, ast, NULL)) return false; if(!check_nonsendable_recover(opt, ast)) return false; } else { ast_t* receiver = ast_child(lhs); // Dig through function qualification. if((ast_id(receiver) == TK_FUNREF) || (ast_id(receiver) == TK_FUNAPP) || (ast_id(receiver) == TK_FUNCHAIN)) receiver = ast_child(receiver); ast_t* recv_type = ast_type(receiver); if(!is_known(recv_type) && (ast_id(receiver) == TK_TYPEREF)) { ast_error(opt->check.errors, lhs, "a bare method cannot be called on " "an abstract type reference"); return false; } } break; default: {} } return true; }
/* * Returns whether the object is known to be an artifact */ bool object_type::is_known_artifact() { if (!is_artifact()) return (FALSE); if (is_known()) return (TRUE); if (discount == INSCRIP_INDESTRUCTIBLE) return (TRUE); if (discount == INSCRIP_TERRIBLE) return (TRUE); if (discount == INSCRIP_SPECIAL) return (TRUE); return (FALSE); }
bool expr_field(pass_opt_t* opt, ast_t* ast) { AST_GET_CHILDREN(ast, id, type, init); // An embedded field must have a known, non-actor type. if(ast_id(ast) == TK_EMBED) { if(!is_known(type) || is_actor(type)) { ast_error(ast, "embedded fields must always be primitives or classes"); return false; } } if(ast_id(init) != TK_NONE) { // Initialiser type must match declared type. if(!coerce_literals(&init, type, opt)) return false; ast_t* init_type = ast_type(init); if(is_typecheck_error(init_type)) return false; init_type = alias(init_type); if(!is_subtype(init_type, type)) { ast_error(init, "field/param initialiser is not a subtype of the field/param type"); ast_error(type, "field/param type: %s", ast_print_type(type)); ast_error(init, "initialiser type: %s", ast_print_type(init_type)); ast_free_unattached(init_type); return false; } // If it's an embedded field, check for a constructor result. if(ast_id(ast) == TK_EMBED) { if((ast_id(init) != TK_CALL) || (ast_id(ast_childidx(init, 2)) != TK_NEWREF)) { ast_error(ast, "an embedded field must be initialised using a constructor"); return false; } } ast_free_unattached(init_type); } ast_settype(ast, type); return true; }
bool has_child(int sel) { int i; for (i = 1; i < max_s_idx; i++) { if ((s_info[i].father == sel) && (is_known(i))) return (TRUE); } return (FALSE); }
wireless_scan *get_best() { wireless_scan *best=NULL,*ws; unsigned short int known, sec, qual; for (ws = context.result; ws; ws = ws->next) { if (strlen(ws->b.essid) == 0) continue; known = is_known(ws); sec = (ws->b.key_flags == 2048); qual = ( best ? (ws->stats.qual.qual > best->stats.qual.qual) : True); if ( (qual && known) || (qual && (mode&MODE_ANY) && !sec) ) best = ws; } return best; }
int Ring::Worth() const { int worth = Category()->worth(); if (UsesBonuses()) { if (get_ring_level() > 0) worth += get_ring_level() * 100; else worth = 10; } if (!is_known()) worth /= 2; return worth; }
static void trace_static(compile_t* c, LLVMValueRef ctx, LLVMValueRef object, ast_t* src_type, ast_t* dst_type) { pony_assert(ast_id(src_type) == TK_NOMINAL); int mutability = trace_cap_nominal(c->opt, src_type, dst_type, NULL); pony_assert(mutability != -1); if(is_known(src_type)) trace_known(c, ctx, object, src_type, mutability); else trace_unknown(c, ctx, object, mutability); }
inline void enrol (TOOLImpl* typeKey) { Tag<TOOL>& index = Tag<TOOL>::get (typeKey); if (is_known (index)) return; else { Trampoline func = &callTrampoline<TOOLImpl>; storePtr (index, func); } }
static int check_call_send(ast_t* ast, bool in_final) { AST_GET_CHILDREN(ast, positional, named, question, lhs); AST_GET_CHILDREN(lhs, receiver, method); switch(ast_id(receiver)) { case TK_NEWREF: case TK_FUNREF: case TK_FUNCHAIN: // Qualified. Get the real receiver. receiver = ast_child(receiver); method = ast_sibling(receiver); break; default: {} } ast_t* type = ast_type(receiver); // If we don't know the final type, we can't be certain of what all // implementations of the method do. Leave it as might send. if(!is_known(type)) return FINAL_CAN_SEND; ast_t* def = receiver_def(type); pony_assert(def != NULL); const char* method_name = ast_name(method); ast_t* fun = ast_get(def, method_name, NULL); pony_assert(fun != NULL); AST_GET_CHILDREN(fun, cap, id, typeparams, params, result, can_error, body); int r = check_body_send(body, false); if(r == FINAL_NO_SEND) { // Mark the call as no send. ast_clearmightsend(ast); } else if(in_final && (r == FINAL_RECURSE)) { // If we're in the finaliser, which can't recurse, we treat a recurse as // a no send. ast_clearmightsend(ast); } else if((r & FINAL_CAN_SEND) != 0) { // Mark the call as can send. ast_setsend(ast); } return r; }
bool InsnSemanticsExpr::LeafNode::equivalent_to(const TreeNodePtr &other_) const { bool retval = false; LeafNodePtr other = other_->isLeafNode(); if (this==other.get()) { retval = true; } else if (other && get_nbits()==other->get_nbits()) { if (is_known()) { retval = other->is_known() && ival==other->ival; } else { retval = !other->is_known() && name==other->name; } } return retval; }
void init_table_aux(int table[MAX_SKILLS][2], int *idx, int father, int lev, bool full) { int j, i; for (j = 1; j < max_s_idx; j++) { i = get_idx(j); if (s_info[i].father != father) continue; if (s_info[i].hidden) continue; if (!is_known(i)) continue; table[*idx][0] = i; table[*idx][1] = lev; (*idx)++; if (s_info[i].dev || full) init_table_aux(table, idx, i, lev + 1, full); } }
void AdaptiveHuffman::insert(char sym) { Node* tba = NULL; if (!is_known(sym)) { Node* inner = new Node("", 1); Node* fresh = new Node(string(1, sym), 1); inner->set_left(nyt); inner->set_right(fresh); inner->set_parent(nyt->get_parent()); if (nyt->get_parent() != NULL) nyt->get_parent()->set_left(inner); else root = inner; nyt->set_parent(inner); fresh->set_parent(inner); nodes.insert(nodes.begin() + 1, inner); nodes.insert(nodes.begin() + 1, fresh); knownsym.push_back(sym); tba = inner->get_parent(); } else { tba = find_node(sym); } while (tba != NULL) { Node* bignode = find_bignode(tba->get_frequency()); if (tba != bignode && tba->get_parent() != bignode && bignode->get_parent() != tba) swap_node(tba, bignode); tba->set_frequency(tba->get_frequency() + 1); tba = tba->get_parent(); } }
void init_table_aux(s32b **table, s32b *idx, s32b father, s32b lev, bool full) { s32b j, i; for (j = 1; j < max_s_idx; j++) { i = get_idx(j); if (s_info[i].father != father) continue; if (s_info[i].hidden) continue; if (!is_known(i)) continue; table[*idx][0] = i; table[*idx][1] = lev; (*idx)++; if (s_info[i].dev || full) init_table_aux(table, idx, i, lev + 1, full); } }
void InsnSemanticsExpr::LeafNode::print(std::ostream &o, RenameMap *rmap/*NULL*/) const { if (is_known()) { if ((32==nbits || 64==nbits) && 0!=(ival & 0xffff0000) && 0xffff0000!=(ival & 0xffff0000)) { // probably an address, so print in hexadecimal. The comparison with 0 is for positive values, and the comparison // with 0xffff0000 is for negative values. o <<StringUtility::addrToString(ival); } else if (nbits>1 && (ival & ((uint64_t)1<<(nbits-1)))) { uint64_t sign_extended = ival | ~(((uint64_t)1<<nbits)-1); o <<(int64_t)sign_extended; } else { o <<ival; } } else { uint64_t renamed = name; if (rmap) { RenameMap::iterator found = rmap->find(name); if (found==rmap->end()) { renamed = rmap->size(); rmap->insert(std::make_pair(name, renamed)); } else { renamed = found->second; } } switch (leaf_type) { case MEMORY: o <<"m"; break; case BITVECTOR: o <<"v"; break; case CONSTANT: assert(!"handled above"); abort(); } o <<renamed; } o <<"[" <<nbits; if (!comment.empty()) o <<"," <<comment; o <<"]"; }
static bool is_known(int s_idx) { int i; if (wizard) return TRUE; if (s_info[s_idx].value || s_info[s_idx].mod) return TRUE; for (i = 0; i < max_s_idx; i++) { /* It is our child, if we don't know it we continue to search, if we know it it is enough*/ if (s_info[i].father == s_idx) { if (is_known(i)) return TRUE; } } /* Ok know none */ return FALSE; }
bool InsnSemanticsExpr::LeafNode::equal_to(const TreeNodePtr &other_, SMTSolver *solver) const { bool retval = false; if (solver) { InternalNodePtr assertion = InternalNode::create(1, OP_NE, shared_from_this(), other_); retval = SMTSolver::SAT_NO==solver->satisfiable(assertion); /*equal if there is no solution for inequality*/ } else { LeafNodePtr other = other_->isLeafNode(); if (this==other.get()) { retval = true; } else if (other) { if (is_known()) { retval = other->is_known() && ival==other->ival; } else { retval = !other->is_known() && name==other->name; } } } return retval; }
int draw_entry(wireless_scan *ws,int sel) { char *name = ws->b.essid; if (!strlen(name)) name = (char *) noname; /* known and/or currently connected */ if (strncmp(cur.essid,name,IW_ESSID_MAX_SIZE)==0) attrset(COLOR_PAIR(3)|A_BOLD); else if (ws->b.key_flags == 2048) attrset(COLOR_PAIR(1)|A_BOLD); else attrset(COLOR_PAIR(2)|A_BOLD); if (is_known(ws)) printw("=> "); else printw(" > "); /* ESSID & selection cursor */ if (sel) attrset(COLOR_PAIR(3)|A_BOLD|A_REVERSE); else attrset(COLOR_PAIR(0)); printw(" %-*s ",IW_ESSID_MAX_SIZE+2,name); /* Connection strength */ int perc = 100 * ws->stats.qual.qual / 70; if (perc > 94) attrset(COLOR_PAIR(2)|A_BOLD); else if (perc > 84) attrset(COLOR_PAIR(2)); else if (perc > 64) attrset(COLOR_PAIR(3)|A_BOLD); else attrset(COLOR_PAIR(1)|A_BOLD); printw("%3d%%\n",perc); return 1; }
static LLVMValueRef gen_digestof_value(compile_t* c, ast_t* type, LLVMValueRef value) { LLVMTypeRef impl_type = LLVMTypeOf(value); switch(LLVMGetTypeKind(impl_type)) { case LLVMFloatTypeKind: value = LLVMBuildBitCast(c->builder, value, c->i32, ""); return LLVMBuildZExt(c->builder, value, c->intptr, ""); case LLVMDoubleTypeKind: value = LLVMBuildBitCast(c->builder, value, c->i64, ""); return gen_digestof_int64(c, value); case LLVMIntegerTypeKind: { uint32_t width = LLVMGetIntTypeWidth(impl_type); if(width < 64) { return LLVMBuildZExt(c->builder, value, c->intptr, ""); } else if(width == 64) { return gen_digestof_int64(c, value); } else if(width == 128) { LLVMValueRef shift = LLVMConstInt(c->i128, 64, false); LLVMValueRef high = LLVMBuildLShr(c->builder, value, shift, ""); high = LLVMBuildTrunc(c->builder, high, c->i64, ""); value = LLVMBuildTrunc(c->builder, value, c->i64, ""); high = gen_digestof_int64(c, high); value = gen_digestof_int64(c, value); return LLVMBuildXor(c->builder, value, high, ""); } break; } case LLVMStructTypeKind: { uint32_t count = LLVMCountStructElementTypes(impl_type); LLVMValueRef result = LLVMConstInt(c->intptr, 0, false); ast_t* child = ast_child(type); for(uint32_t i = 0; i < count; i++) { LLVMValueRef elem = LLVMBuildExtractValue(c->builder, value, i, ""); elem = gen_digestof_value(c, child, elem); result = LLVMBuildXor(c->builder, result, elem, ""); child = ast_sibling(child); } pony_assert(child == NULL); return result; } case LLVMPointerTypeKind: if(!is_known(type)) { reach_type_t* t = reach_type(c->reach, type); int sub_kind = subtype_kind(t); if((sub_kind & SUBTYPE_KIND_BOXED) != 0) return gen_digestof_box(c, t, value, sub_kind); } return LLVMBuildPtrToInt(c->builder, value, c->intptr, ""); default: {} } pony_assert(0); return NULL; }
uint64_t InsnSemanticsExpr::LeafNode::get_value() const { assert(is_known()); return ival; }
void object_type::update_object_flags() { obj_flags_1 = obj_flags_2 = obj_flags_3 = obj_flags_native = 0L; known_obj_flags_1 = known_obj_flags_2 = known_obj_flags_3 = known_obj_flags_native = 0L; object_kind *k_ptr = &k_info[k_idx]; // Start with the actual object flags. The known flags will be figured out further below /* Base object */ obj_flags_1 = k_ptr->k_flags1; obj_flags_2 = k_ptr->k_flags2; obj_flags_3 = k_ptr->k_flags3; obj_flags_native = k_ptr->k_native; /* Artifact */ if (art_num) { artifact_type *a_ptr = &a_info[art_num]; obj_flags_1 |= a_ptr->a_flags1; obj_flags_2 |= a_ptr->a_flags2; obj_flags_3 |= a_ptr->a_flags3; obj_flags_native |= a_ptr->a_native; } /* Ego-item */ if (ego_num) { ego_item_type *e_ptr = &e_info[ego_num]; obj_flags_1 |= e_ptr->e_flags1; obj_flags_2 |= e_ptr->e_flags2; obj_flags_3 |= e_ptr->e_flags3; obj_flags_native |= e_ptr->e_native; } /*hack - chests use xtra1 to store the theme, don't give additional powers to chests*/ /* Extra powers */ if (!is_chest()) { switch (xtra1) { case OBJECT_XTRA_STAT_SUSTAIN: { /* Flag 2 */ obj_flags_2 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_SUSTAIN, OBJECT_XTRA_BASE_SUSTAIN); break; } case OBJECT_XTRA_TYPE_HIGH_RESIST: { /* Flag 2 */ obj_flags_2 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_HIGH_RESIST, OBJECT_XTRA_BASE_HIGH_RESIST); break; } case OBJECT_XTRA_TYPE_POWER: { /* Flag 3 */ obj_flags_3 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_POWER, OBJECT_XTRA_BASE_POWER); break; } case OBJECT_XTRA_TYPE_IMMUNITY: { /* Flag 2 */ obj_flags_2 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_IMMUNITY, OBJECT_XTRA_BASE_IMMUNITY); break; } case OBJECT_XTRA_TYPE_STAT_ADD: { /* Flag 1 */ obj_flags_1 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_STAT_ADD, OBJECT_XTRA_BASE_STAT_ADD); /*Stat add Also sustains*/ obj_flags_2 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_SUSTAIN, OBJECT_XTRA_BASE_SUSTAIN); break; } case OBJECT_XTRA_TYPE_SLAY: { /* Flag 1 */ obj_flags_1 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_SLAY, OBJECT_XTRA_BASE_SLAY); break; } case OBJECT_XTRA_TYPE_KILL: { /* Flag 1 */ obj_flags_1 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_KILL, OBJECT_XTRA_BASE_KILL); break; } case OBJECT_XTRA_TYPE_BRAND: { /* Flag 1 */ obj_flags_1 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_BRAND, OBJECT_XTRA_BASE_BRAND); /* * elemental brands also provide the appropriate resist * Note that the OBJECT_XTRA_SIZE_LOW_RESIST is not used. There * are only 4 base resists, but 5 base brands (+poison). Hence the * OBJECT_XTRA_SIZE_BRAND used here is deliberate and not a bug. */ obj_flags_2 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_BRAND, OBJECT_XTRA_BASE_LOW_RESIST); break; } case OBJECT_XTRA_TYPE_LOW_RESIST: { /* Flag 2 */ obj_flags_2 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_LOW_RESIST, OBJECT_XTRA_BASE_LOW_RESIST); break; } case OBJECT_XTRA_TYPE_NATIVE: { /* Flag native */ obj_flags_native |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_NATIVE, OBJECT_XTRA_BASE_NATIVE); break; } } /*Now add the ignores for any xtra above*/ if (obj_flags_2 & (TR2_RES_ACID)) obj_flags_3 |= TR3_IGNORE_ACID; if (obj_flags_2 & (TR2_RES_ELEC)) obj_flags_3 |= TR3_IGNORE_ELEC; if (obj_flags_2 & (TR2_RES_FIRE)) obj_flags_3 |= TR3_IGNORE_FIRE; if (obj_flags_2 & (TR2_RES_COLD)) obj_flags_3 |= TR3_IGNORE_COLD; if (obj_flags_native & (TN1_NATIVE_LAVA | TN1_NATIVE_FIRE)) obj_flags_3 |= TR3_IGNORE_FIRE; if (obj_flags_native & (TN1_NATIVE_ICE)) obj_flags_3 |= TR3_IGNORE_COLD; if (obj_flags_native & (TN1_NATIVE_ACID)) obj_flags_3 |= TR3_IGNORE_ACID; } // Now handle what flags the player is aware of // The simplest cases first, the player knows everything... if (is_known_fully() && !is_chest()) { known_obj_flags_1 = obj_flags_1; known_obj_flags_2 = obj_flags_2; known_obj_flags_3 = obj_flags_3; known_obj_flags_native = obj_flags_native; return; } // or the player knows nothing (includes chests with unknown traps) if (!is_known()) return; // Proceed with simple id'ed items /* Base object */ known_obj_flags_1 = k_ptr->k_flags1; known_obj_flags_2 = k_ptr->k_flags2; known_obj_flags_3 = k_ptr->k_flags3; known_obj_flags_native = k_ptr->k_native; /* Basic ego-item values are known*/ if (ego_num) { ego_item_type *e_ptr = &e_info[ego_num]; known_obj_flags_1 |= e_ptr->e_flags1; known_obj_flags_2 |= e_ptr->e_flags2; known_obj_flags_3 |= e_ptr->e_flags3; known_obj_flags_native |= e_ptr->e_native; } // Artifacts have some known flags if (art_num) { if (is_known()) { artifact_type *a_ptr = &a_info[art_num]; known_obj_flags_1 |= (a_ptr->a_flags1 & (TR1_PVAL_MASK)); known_obj_flags_3 |= (a_ptr->a_flags3 & (TR3_IGNORE_MASK)); } } // Chests use xtra1 to store the theme. Don't give them special powers if (is_chest() || has_hidden_powers()) return; // add known extra powers to id'ed items switch (xtra1) { case OBJECT_XTRA_TYPE_SLAY: { /* Flag 1 */ known_obj_flags_1 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_SLAY, OBJECT_XTRA_BASE_SLAY); break; } case OBJECT_XTRA_TYPE_KILL: { known_obj_flags_1 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_KILL, OBJECT_XTRA_BASE_KILL); break; } case OBJECT_XTRA_TYPE_BRAND: { /* Flag 1 */ known_obj_flags_1 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_BRAND, OBJECT_XTRA_BASE_BRAND); /* * elemental brands also provide the appropriate resist * Note that the OBJECT_XTRA_SIZE_LOW_RESIST is not used. There * are only 4 base resists, but 5 base brands (+poison). Hence the * OBJECT_XTRA_SIZE_BRAND used here is deliberate and not a bug. */ known_obj_flags_2 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_BRAND, OBJECT_XTRA_BASE_LOW_RESIST); break; } case OBJECT_XTRA_TYPE_LOW_RESIST: { /* Flag 2 */ known_obj_flags_2 |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_LOW_RESIST, OBJECT_XTRA_BASE_LOW_RESIST); break; } case OBJECT_XTRA_TYPE_NATIVE: { /* Flag native */ known_obj_flags_native |= add_xtra2_flags(xtra2, OBJECT_XTRA_SIZE_NATIVE, OBJECT_XTRA_BASE_NATIVE); break; } } /*Now add the ignores for any xtra above*/ if (known_obj_flags_2 & (TR2_RES_ACID)) known_obj_flags_3 |= TR3_IGNORE_ACID; if (known_obj_flags_2 & (TR2_RES_ELEC)) known_obj_flags_3 |= TR3_IGNORE_ELEC; if (known_obj_flags_2 & (TR2_RES_FIRE)) known_obj_flags_3 |= TR3_IGNORE_FIRE; if (known_obj_flags_2 & (TR2_RES_COLD)) known_obj_flags_3 |= TR3_IGNORE_COLD; if (known_obj_flags_native & (TN1_NATIVE_LAVA | TN1_NATIVE_FIRE)) known_obj_flags_3 |= TR3_IGNORE_FIRE; if (known_obj_flags_native & (TN1_NATIVE_ICE)) known_obj_flags_3 |= TR3_IGNORE_COLD; if (known_obj_flags_native & (TN1_NATIVE_ACID)) known_obj_flags_3 |= TR3_IGNORE_ACID; }
/* * Determine if an object has charges */ bool object_type::could_be_zapped() { if (!can_zap() && is_known()) return (FALSE); return (TRUE); }
int main( int argc, char** argv ) { #ifdef WIN32 BOOL console_ok = AllocConsole(); freopen("CONOUT$", "wb", stdout); freopen("CONOUT$", "wb", stderr); //freopen( "console.txt", "wb", stdout); //freopen( "console.txt", "wb", stderr); printf("testing stdout\n"); fprintf(stderr, "testing stderr\n"); #endif try { fc::tcp_server _tcp_serv; //maps keyhoteeId -> founderCode,points,publicKey bts::db::level_map<std::string,record> _known_names; _known_names.open( "reg_db" ); auto fix_itr = _known_names.begin(); while (fix_itr.valid()) { std::string kid = fix_itr.key(); std::string asciiName; convertToAscii(kid,&asciiName); if (kid != asciiName) { auto unchanged_record = fix_itr.value(); deb << kid << " to " << asciiName << std::endl; _known_names.remove(kid); _known_names.store(asciiName,unchanged_record); } ++fix_itr; } if (argc == 3) { //update records in goood dbase with matching records from messy database std::cerr << "update records with records from messy database" << std::endl; bts::db::level_map<std::string,record> _messy_names; _messy_names.open( "messy_db" ); //walkthrough all names in messydb, see if it matches record in good db, update good db with public key if so auto itr = _messy_names.begin(); while( itr.valid() ) { auto found_itr = _known_names.find( itr.key() ); if (found_itr.valid()) { auto id_record = itr.value(); auto found_record = found_itr.value(); found_record.pub_key = id_record.pub_key; ilog( "${key} => ${value}", ("key",itr.key())("value",found_record)); _known_names.store( itr.key(), found_record); } else //report couldn't be found in debug.txt { std::string lower_kid = itr.key(); boost::to_lower(lower_kid); found_itr = _known_names.find(lower_kid); if (found_itr.valid()) deb << "found " << itr.key() << " as " << lower_kid << std::endl; else deb << "missing " << itr.key() << std::endl; } ++itr; } } // TODO: import CSV list of new keyhoteeIds that can be registered else if( argc == 2 ) { FC_ASSERT( fc::exists(argv[1]) ); std::ifstream in(argv[1]); std::string line; std::getline(in, line); int num_commas = std::count(line.begin(), line.end(), ','); deb << "num_commas=" << num_commas << "\n"; std::cerr << "num_commas=" << num_commas << "\n"; if (num_commas == 1) { //fix badly transcribed keyhoteeIDs (replace 1st column names with 2nd column names) while( in.good() ) { std::stringstream ss(line); std::string original_name; //old keyhoteeId std::getline( ss, original_name, ',' ); std::string name; convertToAscii(original_name,&name); std::string original_new_name; //old keyhoteeId std::getline(ss, original_new_name); std::string new_name; convertToAscii(original_new_name,&new_name); try { auto itr = _known_names.find( name ); if (itr.valid()) { deb << "found " << name << " replacing with " << new_name << std::endl; auto rec = itr.value(); rec.key = new_name; _known_names.store( new_name, rec ); } else { deb << name << " NOT FOUND when trying to replace" << std::endl; } } catch (...) { deb << "Couldn't find name " << name << std::endl; } } deb << "FINISHED replacing bad KIDs" << std::endl; deb.flush(); } else if (num_commas == 2 || num_commas == 3) { while( in.good() ) { std::stringstream ss(line); std::string oname; //keyhoteeId std::getline( ss, oname, ',' ); std::string name; convertToAscii(oname,&name); //boost::to_lower(name); std::string key; //founderCode std::getline( ss, key, ',' ); std::string points; std::getline( ss, points, ',' ); deb << "OK"<< std::endl; try { auto itr = _known_names.find( name ); if (itr.valid()) { deb << "found " << name << std::endl; } else { deb << "adding " << name << "\t\t" << key << "\t\t'" << points << std::endl; double pointsd = atof( points.c_str() ); _known_names.store( name, record( key, pointsd ) ); } } catch (...) { deb << "Couldn't find name" << std::endl; } std::getline(in, line); } deb << "FINISHED importing more KIDs" << std::endl; deb.flush(); } else if (num_commas >= 5) { //update registered keyhoteeIds with public keys sent from web form while( in.good() ) { std::stringstream ss(line); std::string date; std::getline( ss, date, ',' ); std::string email; std::getline( ss, email, ',' ); std::string oname; //keyhoteeId std::getline( ss, oname, ',' ); std::string name; convertToAscii(oname,&name); //boost::to_lower(name); std::string key; //founderCode std::getline( ss, key, ',' ); std::string public_key; std::getline( ss, public_key, ',' ); auto itr = _known_names.find( name ); if (!itr.valid()) { std::string similar_name = name; boost::to_lower(similar_name); itr = _known_names.find( similar_name ); if (!itr.valid()) { boost::to_upper(similar_name); itr = _known_names.find( similar_name ); } } if( itr.valid() ) { auto record_to_update = itr.value(); if (!public_key.empty()) { record_to_update.pub_key = public_key; if (record_to_update.key == key) _known_names.store( name, record_to_update); else deb << "Founder code mismatch for " << name << std::endl; } else { deb << "Public key empty for " << name << std::endl; } } else { deb << "Looking for " << name << " "; std::string similar_name = name; boost::to_lower(similar_name); if (!is_known(_known_names,similar_name)) boost::to_upper(similar_name); if (!is_known(_known_names,similar_name)) deb << "NOT FOUND" << std::endl; deb.flush(); } std::getline(in, line); } } else { std::cerr << "Invalid file format: file should have 3 or 5+ fields, has " << num_commas << std::endl; return 1; } } else //argc != 2 { //configure logger to also write to log file fc::file_appender::config ac; /** \warning Use wstring to construct log file name since %TEMP% can point to path containing native chars. */ ac.filename = "log.txt"; ac.truncate = false; ac.flush = true; fc::logger::get().add_appender( fc::shared_ptr<fc::file_appender>( new fc::file_appender( fc::variant(ac) ) ) ); std::ofstream report_stream("report.txt"); int id_count = 0; int unregistered_count = 0; auto itr = _known_names.begin(); while( itr.valid() ) { auto id_record = itr.value(); //ilog( "${key} => ${value}", ("key",itr.key())("value",id_record)); ilog( "${key}, ${pub_key}, ${p}", ("key",itr.key())("pub_key",id_record.pub_key)("p",id_record.points)); report_stream << itr.key() << "," << id_record.pub_key << std::endl; ++id_count; if (id_record.pub_key.empty()) ++unregistered_count; ++itr; } report_stream.close(); ilog( "Total Id Count: ${id_count} Unregistered: ${unregistered_count}",("id_count",id_count)("unregistered_count",unregistered_count) ); } _tcp_serv.listen( 3879 ); //fc::future<void> _accept_loop_complete = fc::async( [&]() { while( true ) //!_accept_loop_complete.canceled() ) { fc::tcp_socket_ptr sock = std::make_shared<fc::tcp_socket>(); try { _tcp_serv.accept( *sock ); } catch ( const fc::exception& e ) { elog( "fatal: error opening socket for rpc connection: ${e}", ("e", e.to_detail_string() ) ); //exit(1); } auto buf_istream = std::make_shared<fc::buffered_istream>( sock ); auto buf_ostream = std::make_shared<fc::buffered_ostream>( sock ); auto json_con = std::make_shared<fc::rpc::json_connection>( std::move(buf_istream), std::move(buf_ostream) ); json_con->add_method( "register_key", [&]( const fc::variants& params ) -> fc::variant { FC_ASSERT( params.size() == 3 ); auto oname = params[0].as_string(); oname = fc::trim(oname); std::string name; convertToAscii(oname,&name); auto rec = _known_names.fetch( name ); //ensure founder code is correct if( rec.key != params[1].as_string() ) //, "Key ${key} != ${expected}", ("key",params[1])("expected",rec.key) ); { FC_ASSERT( !"Invalid Key" ); } //report if key is already registered, don't allow re-registering if( !(rec.pub_key.size() == 0 || rec.pub_key == params[2].as_string() ) ) { // FC_ASSERT( rec.pub_key.size() == 0 || rec.pub_key == params[2].as_string() ); FC_ASSERT( !"Key already Registered" ); } //register the public key rec.pub_key = params[2].as_string(); _known_names.store( name, rec ); return fc::variant( rec ); }); fc::async( [json_con]{ json_con->exec().wait(); } ); } // } // ); //_accept_loop_complete.wait(); return 0; } catch ( fc::exception& e ) { elog( "${e}", ("e",e.to_detail_string() ) ); } }