static int pushline(lua_State *L, int firstline) { char buf[LUA_MAXINPUT]; write_prompt(L, firstline); if (fgets(buf, LUA_MAXINPUT, stdin)) { size_t len = strlen(buf); if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; if (firstline && buf[0] == '=') lua_pushfstring(L, "return %s", buf+1); else lua_pushstring(L, buf); return 1; } return 0; }
static int conv_fn(int num_msg, PAM_CONST struct pam_message** msg_, struct pam_response** resp_, void* appdata_ptr) { if (num_msg <= 0 || num_msg > PAM_MAX_NUM_MSG) return PAM_CONV_ERR; debug("(%sPAM conversation called)", pam_conv_fd < 0 ? "Null " : ""); struct pam_response* resp = malloc(num_msg * sizeof(*resp)); if (!resp) return PAM_BUF_ERR; int i; for (i = 0; i < num_msg; ++i) { #ifdef SUN_PAM /* In Sun-derived libpam, "pam_message**" is a pointer to an array. */ struct pam_message* msg = &((*msg_)[i]); #else /* It's an array of pointers otherwise. */ PAM_CONST struct pam_message* msg = msg_[i]; #endif resp[i].resp_retcode = 0; resp[i].resp = 0; switch (msg->msg_style) { case PAM_PROMPT_ECHO_OFF: case PAM_PROMPT_ECHO_ON: debug(" Prompt(e=%d): %s", msg->msg_style==PAM_PROMPT_ECHO_OFF ? 0 : 1, msg->msg); if (pam_conv_fd >= 0) { if (conv_reject_prompts) goto bail; if (write_text(pam_conv_fd, msg->msg) < 0 || write_prompt(pam_conv_fd, msg->msg_style == PAM_PROMPT_ECHO_ON) < 0) goto bail; resp[i].resp = read_reply(pam_conv_fd); if (!resp[i].resp) goto bail; if (strlen(resp[i].resp)+1 > PAM_MAX_RESP_SIZE) goto bail; } break; case PAM_ERROR_MSG: case PAM_TEXT_INFO: debug(" %s: %s", msg->msg_style==PAM_ERROR_MSG ? "Error" : "Info", msg->msg); if (pam_conv_fd >= 0) { if (write_text(pam_conv_fd, msg->msg) < 0) goto bail; size_t len = strlen(msg->msg); if (len > 0 && msg->msg[len-1] != '\n' && write_text(pam_conv_fd, "\n") < 0) goto bail; } break; default: goto bail; } } if (pam_conv_fd >= 0) { *resp_ = resp; return PAM_SUCCESS; } if (i == num_msg) i = num_msg-1; bail: for (; i >= 0; --i) { if (!resp[i].resp) continue; buffer_scrub(resp[i].resp, strlen(resp[i].resp)); free(resp[i].resp); } buffer_scrub(resp, num_msg * sizeof(*resp)); free(resp); return PAM_CONV_ERR; }
void heart_beat() { int t; int period; int wimpy_ratio, cnd_flag; mapping my; object ob; object me; string prompt; int is_player; me = this_object(); my = query_entire_dbase(); if (userp(me) && living(me) && mapp(my["env"])) { // update prompt prompt = my["env"]["prompt"]; if ((prompt == "time" || prompt == "mud" || prompt == "hp") && is_waiting_command() && ! me->is_attach_system()) { write_prompt(); } } // If we're dying or falling unconcious? if (my["qi"] < 0 || my["jing"] < 0) { if (! living(me)) die(); else unconcious(); // Why does the living test? Because // The wizard may set immortal but his // qi was -1, so I don't want return, // or the continue_action will never be // called in such case. if (! me || ! living(me)) return; } if (is_p_busy()) { continue_p_busy(); } // Do attack if we are fighting. if (is_busy()) { continue_action(); // We don't want heart beat be halt eventually, so return here. } else if (living(me)) { string apply; object apply_ob; // Is it time to flee? if (is_fighting() && intp(wimpy_ratio = (int)query("env/wimpy")) && wimpy_ratio > 0 && (my["qi"] * 100 / my["max_qi"] <= wimpy_ratio || my["jing"] * 100 / my["max_jing"] <= wimpy_ratio)) { if (stringp(apply = query("env/wimpy_apply")) && objectp(apply_ob = present(apply, me)) && apply_ob->query("can_apply_for_wimpy")) { apply_ob->apply_for_wimpy(this_object()); } else GO_CMD->do_flee(this_object()); } if (query("auto_perform") || me->query_auto_perform()) { if (my["eff_jing"] > 0 && my["jing"] * 100 / my["eff_jing"] <= 70) SKILL_D("force/regenerate")->exert(me, me); if (my["eff_qi"] > 0 && my["qi"] * 100 / my["eff_qi"] <= 70) SKILL_D("force/recover")->exert(me, me); // 如果不在打架而且处于受伤状态,则自行疗伤 if (! is_fighting()) { if (my["eff_jing"] < my["max_jing"]) SKILL_D("force/inspire")->exert(me, me); if (my["eff_qi"] < my["max_qi"]) SKILL_D("force/heal")->exert(me, me); } } // Do attack or clean up enemy if we have fleed. if (is_busy()) continue_action(); else attack(); } if (my["doing"] == "scheme") // executing schedule now SCHEME_CMD->execute_schedule(me); if (! me) return; if (! (is_player = playerp(me))) { me->scan(); // scan() may do anything -- include destruct(this_object()) if (! me) return; } if ((t = time()) < next_beat) return; else next_beat = t + 5 + random(10); if (! my["not_living"]) cnd_flag = update_condition(); if (! me) return; if (! (cnd_flag & CND_NO_HEAL_UP)) cnd_flag = heal_up(); // If we are compeletely in peace, turn off heart beat. // heal_up() must be called prior to other two to make sure it is called // because the && operator is lazy :P if (! cnd_flag && ! is_player && ! keep_beat_flag && ! is_fighting() && ! is_busy() && ! interactive(this_object())) { if (environment() && query("chat_msg")) { ob = first_inventory(environment()); while (ob && ! interactive(ob)) ob = next_inventory(ob); } else ob = 0; if (! ob) set_heart_beat(0); } update_all_limb_damage(); if (! me || ! is_player) return; // Make us a bit older. Only player's update_age is defined. // Note: update_age() is no need to be called every heart_beat, it // remember how much time has passed since last call. me->update_age(); #ifdef AUTO_SAVE if (living(me)) { period = t - ((int) my["last_save"]); if (period < 0 || period > 15 * 60) { string msg; msg = HBCYN HIW "【档案存储】您的档案已经自动存盘," "欢迎访问论坛 http://bbs.mudbuilder.com/ 。\n" NOR; if (! me->save()) msg = HIR "【数据保护】由于数据异常,您的档" "案本次存盘失败。\n" NOR; set("last_save", t); tell_object(me, msg); } } #endif if (! interactive(me)) return; if (my["food"] <= 0 || my["water"] <= 0) { if (environment() && ! environment()->is_chat_room() && ! wizardp(me) && ! query_condition("hunger")) { // born & enter the world apply_condition("hunger", 1); } } if (query_idle(me) > IDLE_TIMEOUT && ! wizardp(me) && (! mapp(my["env"]) || ! my["env"]["keep_idle"])) me->user_dump(DUMP_IDLE); }