void show_db_hdr_msg_detail(struct lsa_hdr *lsa) { printf("LS age: %d\n", ntohs(lsa->age)); printf("LS Type: %s\n", print_ls_type(lsa->type)); switch (ntohs(lsa->type)) { case LSA_TYPE_ROUTER: case LSA_TYPE_INTER_A_PREFIX: case LSA_TYPE_INTER_A_ROUTER: case LSA_TYPE_INTRA_A_PREFIX: case LSA_TYPE_EXTERNAL: printf("Link State ID: %s\n", log_id(lsa->ls_id)); break; case LSA_TYPE_LINK: printf("Link State ID: %s (Interface ID of Advertising " "Router)\n", log_id(lsa->ls_id)); break; case LSA_TYPE_NETWORK: printf("Link State ID: %s (Interface ID of Designated " "Router)\n", log_id(lsa->ls_id)); break; } printf("Advertising Router: %s\n", log_adv_rtr(lsa->adv_rtr)); printf("LS Seq Number: 0x%08x\n", ntohl(lsa->seq_num)); printf("Checksum: 0x%04x\n", ntohs(lsa->ls_chksum)); printf("Length: %d\n", ntohs(lsa->len)); }
/** * Performs a build of this to the indicated stage. */ void unit_type::build(BUILD_STATUS status, const movement_type_map &movement_types, const race_map &races, const config::const_child_itors &traits) { DBG_UT << "Building unit type " << log_id() << ", level " << status << '\n'; switch (status) { case NOT_BUILT: // Already done in the constructor. return; case CREATED: // Build the basic data. build_created(movement_types, races, traits); return; case VARIATIONS: // Implemented as part of HELP_INDEXED case HELP_INDEXED: // Build the data needed to feed the help index. build_help_index(movement_types, races, traits); return; case FULL: build_full(movement_types, races, traits); return; default: ERR_UT << "Build of unit_type to unrecognized status (" << status << ") requested." << std::endl; // Build as much as possible. build_full(movement_types, races, traits); return; } }
int main(object me, string arg) { object ob; mapping my; if (! SECURITY_D->valid_grant(me, "(immortal)")) return 0; seteuid(getuid(me)); if (! arg) ob = me; else { ob = present(arg, environment(me)); if (! ob) ob = find_player(arg); if (! ob) ob = find_living(arg); } if (! ob) return notify_fail("你要恢复谁的状态?\n"); if (ob != me) { if (wiz_level(me) < wiz_level("(wizard)")) return notify_fail("你没有权限恢复" + ob->name() + "。\n"); if (! me->is_admin()) message_system(sprintf("%s(%s)为%s(%s)恢复了状态。\n", me->name(1), me->query("id"), ob->name(1), ob->query("id"))); } my = ob->query_entire_dbase(); my["jing"] = my["eff_jing"] = my["max_jing"]; my["jingli"] = my["eff_jingli"] = my["max_jingli"]; my["qi"] = my["eff_qi"] = my["max_qi"]; my["neili"] = my["max_neili"]; my["food"] = ob->max_food_capacity(); my["water"] = ob->max_water_capacity(); if (me == ob) { message_vision(HIY "$N" HIY "口中念念有词,不一会儿就变得" "精神焕发,神采奕奕。\n" NOR, me); if (me->is_ghost()) me->reincarnate(); me->clear_condition(); } else { message_vision(HIY "$N" HIY "伸手一指,$n" HIY "立刻精神焕" "发,神采奕奕。\n" NOR, me, ob); if (! living(ob)) ob->revive(); if (ob->is_ghost()) ob->reincarnate(); ob->clear_condition(); log_file("static/recover", sprintf("%s %s recover %s(%s)\n", log_time(), log_id(me), ob->name(1), ob->query("id"))); } return 1; }
/* this has to be the first function called by a new thread */ TLS_DATA *tls_alloc(CLI *c, TLS_DATA *inherited, char *txt) { TLS_DATA *tls_data; if(inherited) { /* reuse the thread-local storage after fork() */ tls_data=inherited; str_free(tls_data->id); } else { tls_data=calloc(1, sizeof(TLS_DATA)); if(!tls_data) fatal("Out of memory"); if(c) c->tls=tls_data; str_init(tls_data); tls_data->c=c; tls_data->opt=c?c->opt:&service_options; } tls_data->id="unconfigured"; tls_set(tls_data); /* str.c functions can be used below this point */ if(txt) { tls_data->id=str_dup(txt); str_detach(tls_data->id); /* it is deallocated after str_stats() */ } else if(c) { tls_data->id=log_id(c); str_detach(tls_data->id); /* it is deallocated after str_stats() */ } return tls_data; }
int show_database_msg(struct imsg *imsg) { static struct in_addr area_id; static char ifname[IF_NAMESIZE]; static u_int16_t lasttype; struct area *area; struct iface *iface; struct lsa_hdr *lsa; switch (imsg->hdr.type) { case IMSG_CTL_SHOW_DATABASE: case IMSG_CTL_SHOW_DB_SELF: lsa = imsg->data; if (lsa->type != lasttype) { show_database_head(area_id, ifname, lsa->type); printf("%-15s %-15s %-4s %-10s %-8s\n", "Link ID", "Adv Router", "Age", "Seq#", "Checksum"); } printf("%-15s %-15s %-4d 0x%08x 0x%04x\n", log_id(lsa->ls_id), log_adv_rtr(lsa->adv_rtr), ntohs(lsa->age), ntohl(lsa->seq_num), ntohs(lsa->ls_chksum)); lasttype = lsa->type; break; case IMSG_CTL_AREA: area = imsg->data; area_id = area->id; lasttype = 0; break; case IMSG_CTL_IFACE: iface = imsg->data; strlcpy(ifname, iface->name, sizeof(ifname)); lasttype = 0; break; case IMSG_CTL_END: printf("\n"); return (1); default: break; } return (0); }
/** * Load the most needed data into an empty unit_type (build to CREATE). * This creates the gender-specific types (if needed) and also defines how much * experience is needed to advance as well as what this advances to. */ void unit_type::build_created(const movement_type_map &mv_types, const race_map &races, const config::const_child_itors &traits) { // Don't build twice. if ( CREATED <= build_status_ ) return; // There is no preceding build level (other than being constructed). // These should still be nullptr from the constructor. assert(gender_types_[0] == nullptr); assert(gender_types_[1] == nullptr); if ( const config &male_cfg = cfg_.child("male") ) { gender_types_[0] = new unit_type(male_cfg, id_); gender_types_[0]->debug_id_ = debug_id_ + " (male)"; } if ( const config &female_cfg = cfg_.child("female") ) { gender_types_[1] = new unit_type(female_cfg, id_); gender_types_[1]->debug_id_ = debug_id_ + " (female)"; } for (int i = 0; i < 2; ++i) { if (gender_types_[i]) gender_types_[i]->build_created(mv_types, races, traits); } const std::string& advances_to_val = cfg_["advances_to"]; if(advances_to_val != "null" && advances_to_val != "") advances_to_ = utils::split(advances_to_val); DBG_UT << "unit_type '" << log_id() << "' advances to : " << advances_to_val << "\n"; experience_needed_ = cfg_["experience"].to_int(500); build_status_ = CREATED; }
void operator()(const std::string &reliable_storage_local_root, const std::string &reliable_storage_remote_root, const std::string &listen_endpoint, Input_Stream &input, Output_Stream &output, const std::vector<rel::rlang::token> &tokens) { log_info("Reading headers and compiling expression against headers."); /* Get the headers. */ record headings(input.parse_headings()); // Compile, just to check that the headings & tokens are likely to work // when we distribute. record empty_headings; rlang::vm vm = rlang::compiler::compile_single_expression( tokens, headings.ref(), empty_headings.ref()); // Check that the expression is actually a boolean expression. NP1_ASSERT(vm.return_type() == rlang::dt::TYPE_BOOL, "Expression is not a boolean expression"); // Do the distribution. distributed::distribute(log_id(), headings, headings, "rel.where", reliable_storage_local_root, reliable_storage_remote_root, listen_endpoint, input, output, tokens); }
void show_db_hdr_msg_detail(struct lsa_hdr *lsa) { printf("LS age: %d\n", ntohs(lsa->age)); printf("Options: %s\n", print_ospf_options(lsa->opts)); printf("LS Type: %s\n", print_ls_type(lsa->type)); switch (lsa->type) { case LSA_TYPE_ROUTER: printf("Link State ID: %s\n", log_id(lsa->ls_id)); break; case LSA_TYPE_NETWORK: printf("Link State ID: %s (address of Designated Router)\n", log_id(lsa->ls_id)); break; case LSA_TYPE_SUM_NETWORK: printf("Link State ID: %s (Network ID)\n", log_id(lsa->ls_id)); break; case LSA_TYPE_SUM_ROUTER: printf("Link State ID: %s (ASBR Router ID)\n", log_id(lsa->ls_id)); break; case LSA_TYPE_EXTERNAL: printf("Link State ID: %s (External Network Number)\n", log_id(lsa->ls_id)); break; case LSA_TYPE_LINK_OPAQ: case LSA_TYPE_AREA_OPAQ: case LSA_TYPE_AS_OPAQ: printf("Link State ID: %s Type %d ID %d\n", log_id(lsa->ls_id), LSA_24_GETHI(ntohl(lsa->ls_id)), LSA_24_GETLO(ntohl(lsa->ls_id))); break; } printf("Advertising Router: %s\n", log_adv_rtr(lsa->adv_rtr)); printf("LS Seq Number: 0x%08x\n", ntohl(lsa->seq_num)); printf("Checksum: 0x%04x\n", ntohs(lsa->ls_chksum)); printf("Length: %d\n", ntohs(lsa->len)); }
void unit_type::add_advancement(const unit_type &to_unit,int xp) { const std::string &to_id = to_unit.id_; // Add extra advancement path to this unit type LOG_CONFIG << "adding advancement from " << log_id() << " to " << to_unit.log_id() << "\n"; if(std::find(advances_to_.begin(), advances_to_.end(), to_id) == advances_to_.end()) { advances_to_.push_back(to_id); } else { LOG_CONFIG << "advancement from " << log_id() << " to " << to_unit.log_id() << " already known, ignoring.\n"; return; } if(xp > 0) { //xp is 0 in case experience= wasn't given. if(!in_advancefrom_) { //This function is called for and only for an [advancefrom] tag in a unit_type referencing this unit_type. in_advancefrom_ = true; experience_needed_ = xp; DBG_UT << "Changing experience_needed from " << experience_needed_ << " to " << xp << " due to (first) [advancefrom] of " << to_unit.log_id() << "\n"; } else if(experience_needed_ > xp) { experience_needed_ = xp; DBG_UT << "Lowering experience_needed from " << experience_needed_ << " to " << xp << " due to (multiple, lower) [advancefrom] of " << to_unit.log_id() << "\n"; } else DBG_UT << "Ignoring experience_needed change from " << experience_needed_ << " to " << xp << " due to (multiple, higher) [advancefrom] of " << to_unit.log_id() << "\n"; } // Add advancements to gendered subtypes, if supported by to_unit for(int gender=0; gender<=1; ++gender) { if(gender_types_[gender] == nullptr) continue; if(to_unit.gender_types_[gender] == nullptr) { WRN_CF << to_unit.log_id() << " does not support gender " << gender << std::endl; continue; } LOG_CONFIG << "gendered advancement " << gender << ": "; gender_types_[gender]->add_advancement(*(to_unit.gender_types_[gender]),xp); } if ( cfg_.has_child("variation") ) { // Make sure the variations are created. unit_types.build_unit_type(*this, VARIATIONS); // Add advancements to variation subtypes. // Since these are still a rare and special-purpose feature, // we assume that the unit designer knows what they're doing, // and don't block advancements that would remove a variation. for(variations_map::iterator v=variations_.begin(); v!=variations_.end(); ++v) { LOG_CONFIG << "variation advancement: "; v->second->add_advancement(to_unit,xp); } } }
int show_db_msg_detail(struct imsg *imsg) { static struct in_addr area_id; static char ifname[IF_NAMESIZE]; static u_int16_t lasttype; struct in6_addr ia6; struct in_addr addr, data; struct area *area; struct iface *iface; struct lsa *lsa; struct lsa_rtr_link *rtr_link; struct lsa_net_link *net_link; struct lsa_prefix *prefix; struct lsa_asext *asext; u_int32_t ext_tag; u_int16_t i, nlinks, off; /* XXX sanity checks! */ switch (imsg->hdr.type) { case IMSG_CTL_SHOW_DB_EXT: lsa = imsg->data; if (lsa->hdr.type != lasttype) show_database_head(area_id, ifname, lsa->hdr.type); show_db_hdr_msg_detail(&lsa->hdr); asext = (struct lsa_asext *)((char *)lsa + sizeof(lsa->hdr)); printf(" Flags: %s\n", print_asext_flags(ntohl(lsa->data.asext.metric))); printf(" Metric: %d Type: ", ntohl(asext->metric) & LSA_METRIC_MASK); if (ntohl(lsa->data.asext.metric) & LSA_ASEXT_E_FLAG) printf("2\n"); else printf("1\n"); prefix = &asext->prefix; bzero(&ia6, sizeof(ia6)); bcopy(prefix + 1, &ia6, LSA_PREFIXSIZE(prefix->prefixlen)); printf(" Prefix: %s/%d%s\n", log_in6addr(&ia6), prefix->prefixlen, print_prefix_opt(prefix->options)); off = sizeof(*asext) + LSA_PREFIXSIZE(prefix->prefixlen); if (ntohl(lsa->data.asext.metric) & LSA_ASEXT_F_FLAG) { bcopy((char *)asext + off, &ia6, sizeof(ia6)); printf(" Forwarding Address: %s\n", log_in6addr(&ia6)); off += sizeof(ia6); } if (ntohl(lsa->data.asext.metric) & LSA_ASEXT_T_FLAG) { bcopy((char *)asext + off, &ext_tag, sizeof(ext_tag)); printf(" External Route Tag: %d\n", ntohl(ext_tag)); } printf("\n"); lasttype = lsa->hdr.type; break; case IMSG_CTL_SHOW_DB_LINK: lsa = imsg->data; if (lsa->hdr.type != lasttype) show_database_head(area_id, ifname, lsa->hdr.type); show_db_hdr_msg_detail(&lsa->hdr); printf("Options: %s\n", print_ospf_options(LSA_24_GETLO( ntohl(lsa->data.link.opts)))); printf("Link Local Address: %s\n", log_in6addr(&lsa->data.link.lladdr)); nlinks = ntohl(lsa->data.link.numprefix); printf("Number of Prefixes: %d\n", nlinks); off = sizeof(lsa->hdr) + sizeof(struct lsa_link); for (i = 0; i < nlinks; i++) { prefix = (struct lsa_prefix *)((char *)lsa + off); bzero(&ia6, sizeof(ia6)); bcopy(prefix + 1, &ia6, LSA_PREFIXSIZE(prefix->prefixlen)); printf(" Prefix: %s/%d%s\n", log_in6addr(&ia6), prefix->prefixlen, print_prefix_opt(prefix->options)); off += sizeof(struct lsa_prefix) + LSA_PREFIXSIZE(prefix->prefixlen); } printf("\n"); lasttype = lsa->hdr.type; break; case IMSG_CTL_SHOW_DB_NET: lsa = imsg->data; if (lsa->hdr.type != lasttype) show_database_head(area_id, ifname, lsa->hdr.type); show_db_hdr_msg_detail(&lsa->hdr); printf("Options: %s\n", print_ospf_options(LSA_24_GETLO(ntohl(lsa->data.net.opts)))); nlinks = (ntohs(lsa->hdr.len) - sizeof(struct lsa_hdr) - sizeof(struct lsa_net)) / sizeof(struct lsa_net_link); net_link = (struct lsa_net_link *)((char *)lsa + sizeof(lsa->hdr) + sizeof(lsa->data.net)); printf("Number of Routers: %d\n", nlinks); for (i = 0; i < nlinks; i++) { addr.s_addr = net_link->att_rtr; printf(" Attached Router: %s\n", inet_ntoa(addr)); net_link++; } printf("\n"); lasttype = lsa->hdr.type; break; case IMSG_CTL_SHOW_DB_RTR: lsa = imsg->data; if (lsa->hdr.type != lasttype) show_database_head(area_id, ifname, lsa->hdr.type); show_db_hdr_msg_detail(&lsa->hdr); printf("Flags: %s\n", print_ospf_flags(LSA_24_GETHI(ntohl(lsa->data.rtr.opts)))); printf("Options: %s\n", print_ospf_options(LSA_24_GETLO(ntohl(lsa->data.rtr.opts)))); nlinks = (ntohs(lsa->hdr.len) - sizeof(struct lsa_hdr) - sizeof(u_int32_t)) / sizeof(struct lsa_rtr_link); printf("Number of Links: %d\n\n", nlinks); off = sizeof(lsa->hdr) + sizeof(struct lsa_rtr); for (i = 0; i < nlinks; i++) { rtr_link = (struct lsa_rtr_link *)((char *)lsa + off); printf(" Link (Interface ID %s) connected to: %s\n", log_id(rtr_link->iface_id), print_rtr_link_type(rtr_link->type)); addr.s_addr = rtr_link->nbr_rtr_id; data.s_addr = rtr_link->nbr_iface_id; switch (rtr_link->type) { case LINK_TYPE_POINTTOPOINT: case LINK_TYPE_VIRTUAL: printf(" Router ID: %s\n", inet_ntoa(addr)); printf(" Interface ID: %s\n", inet_ntoa(data)); break; case LINK_TYPE_TRANSIT_NET: printf(" Designated Router ID: %s\n", inet_ntoa(addr)); printf(" DR Interface ID: %s\n", inet_ntoa(data)); break; default: printf(" Link ID (Unknown type %d): %s\n", rtr_link->type, inet_ntoa(addr)); printf(" Link Data (Unknown): %s\n", inet_ntoa(data)); break; } printf(" Metric: %d\n\n", ntohs(rtr_link->metric)); off += sizeof(struct lsa_rtr_link); } lasttype = lsa->hdr.type; break; case IMSG_CTL_SHOW_DB_INTRA: lsa = imsg->data; if (lsa->hdr.type != lasttype) show_database_head(area_id, ifname, lsa->hdr.type); show_db_hdr_msg_detail(&lsa->hdr); printf("Referenced LS Type: %s\n", print_ls_type(lsa->data.pref_intra.ref_type)); addr.s_addr = lsa->data.pref_intra.ref_ls_id; printf("Referenced Link State ID: %s\n", inet_ntoa(addr)); addr.s_addr = lsa->data.pref_intra.ref_adv_rtr; printf("Referenced Advertising Router: %s\n", inet_ntoa(addr)); nlinks = ntohs(lsa->data.pref_intra.numprefix); printf("Number of Prefixes: %d\n", nlinks); off = sizeof(lsa->hdr) + sizeof(struct lsa_intra_prefix); for (i = 0; i < nlinks; i++) { prefix = (struct lsa_prefix *)((char *)lsa + off); bzero(&ia6, sizeof(ia6)); bcopy(prefix + 1, &ia6, LSA_PREFIXSIZE(prefix->prefixlen)); printf(" Prefix: %s/%d%s\n", log_in6addr(&ia6), prefix->prefixlen, print_prefix_opt(prefix->options)); off += sizeof(struct lsa_prefix) + LSA_PREFIXSIZE(prefix->prefixlen); } printf("\n"); lasttype = lsa->hdr.type; break; case IMSG_CTL_SHOW_DB_SUM: lsa = imsg->data; if (lsa->hdr.type != lasttype) show_database_head(area_id, ifname, lsa->hdr.type); show_db_hdr_msg_detail(&lsa->hdr); printf("Prefix: XXX\n"); printf("Metric: %d\n", ntohl(lsa->data.pref_sum.metric) & LSA_METRIC_MASK); lasttype = lsa->hdr.type; break; case IMSG_CTL_SHOW_DB_ASBR: lsa = imsg->data; if (lsa->hdr.type != lasttype) show_database_head(area_id, ifname, lsa->hdr.type); show_db_hdr_msg_detail(&lsa->hdr); addr.s_addr = lsa->data.rtr_sum.dest_rtr_id; printf("Destination Router ID: %s\n", inet_ntoa(addr)); printf("Options: %s\n", print_ospf_options(ntohl(lsa->data.rtr_sum.opts))); printf("Metric: %d\n\n", ntohl(lsa->data.rtr_sum.metric) & LSA_METRIC_MASK); case IMSG_CTL_AREA: area = imsg->data; area_id = area->id; lasttype = 0; break; case IMSG_CTL_IFACE: iface = imsg->data; strlcpy(ifname, iface->name, sizeof(ifname)); lasttype = 0; break; case IMSG_CTL_END: return (1); default: break; } return (0); }
void log_info(const char *description) { io::log::info(log_id(), description); }