int read_float(FILE *f, char *config_path, float *result) { /* * Reads the given float from config. * * Returns -1 if the value could not be found, 0 on success * and a positive integer on failure. */ int success; uint8_t temp; success = seek_definition(f, config_path); if (success != 0) return success; temp = fgetc(f); if (temp != 1) return 1; temp = fgetc(f); while (fgetc(f) != 0); if (temp == 2) { // Convert integer to float int32_t int_value; fread(&int_value, 4, 1, f); *result = (float)int_value; } else if (temp == 0) { // Try to parse "rad X" strings char string_value[512]; char *endptr; long fp; fp = ftell(f); if (fgets(string_value, sizeof(string_value), f) == NULL) return 2; fseek(f, fp + strlen(string_value) + 1, SEEK_SET); trim_leading(string_value, sizeof(string_value)); lower_case(string_value); if (strncmp(string_value, "rad ", 4) != 0) return 3; *result = strtof(string_value + 4, &endptr); if (strlen(endptr) > 0) return 4; *result *= RAD2DEG; } else { fread(result, 4, 1, f); } return 0; }
void send_locate_q(string who) { mapping info; string *muds; int i; i = sizeof(muds = keys(info=(mapping)DNS_MASTER->query_muds())); while(i--) { if(lower_case(muds[i]) == lower_case(Mud_name())) continue; DNS_MASTER->send_udp(info[muds[i]]["HOSTADDRESS"], info[muds[i]]["PORTUDP"], "@@@"+DNS_LOCATE_Q+ "||NAME:"+Mud_name()+ "||PORTUDP:"+ udp_port() + "||TARGET:"+lower_case(who)+ "||ASKWIZ:"+(string)this_player()->query("name")+ "@@@\n"); } return; }
string cap_string(string input) { string *elems = explode(input, " "); string output = ""; foreach(string elem in elems) { output += capitalize(lower_case(elem)) + " "; }
int query_windows(){ string arch = lower_case(architecture()); #ifdef __WIN32__ return 1; #else if(grepp(arch,"windows") || grepp(arch,"cygwin")) return 1; #endif return 0; }
int cmd_backstar(string str) { object *weapons, *knives; object victim; int *wc; string *type; int i, tmp; if (!abil()) { write("What?\n"); return 1; } if(!str) { notify_fail("Backstab whom?\n"); return 0; } if (this_player()->query_class() != "rogue") { write("Only rogues may backstab."); return 1; } if (this_player()->query_rest_type()) { write("You can't do that while not on your feet."); return 1; } if(this_player()->query_ghost()) { notify_fail("Are you planning on killing them, too?\n"); return 0; } if(this_player()->query_disable()) return 1; if(environment(this_player())->query_property("no attack")) { notify_fail("Some mystical force prevents you from that.\n"); return 0; } if(this_player()->query_sp() < 5) { notify_fail("You are to tired to be backstabing.\n"); return 0; } if((int)this_player()->query_skill("murder") < 5 || !(string)this_player()->query_class()) { notify_fail("Don't you wish you were fast enough for that?\n"); return 0; } if(!(victim = present(lower_case(str),environment(this_player())))) { notify_fail("You don't see the target here.\n"); return 0; } if(victim == this_player()) { notify_fail("Backstab yourself?\n"); return 0; } if(victim->query_ghost()) { notify_fail("Backstab whom?\n"); return 0; } if(!living(victim)){ notify_fail("You would look silly backstabbing that.\n"); return 0; } wc = ({});
int main( object me, string arg, int repeat ) { string force, tmp; int i, r; seteuid(getuid()); if( !arg ) return notify_fail( "你要用内功做什么?\n" ); notify_fail( "你的内功中没有这种功能。\n" ); arg = lower_case(arg); tmp = arg; if( sscanf( arg, "%s %d", arg, repeat ) != 2 ) arg = tmp; if( repeat < 1 ) repeat = 1; else if( repeat > 10 ) repeat = 10; if( me->is_busy() ) return notify_fail( "你一运气用力, 发觉丹田中毫无内息。\n" ); if( me->query_temp("no_power_e") ) return notify_fail( "你感觉到体内有无数的气劲乱流, 使你无法正常的使用内力。\n" ); if( (!me->query("food")||!me->query("water")) && userp(me) ) { if( random(100) < 1 ) { me->receive_wound( "kee", me->query("age") ); write( HIR"你又饿又渴, 一时之间无法控制真气, 受到了内伤!"NOR ); } return notify_fail( "你感觉又饿又渴! 无法运气!\n" ); } if( stringp( force=me->query_skill_mapped("force") ) ) { for( i=0; i<repeat; i++ ) if( SKILL_D(force)->exert_function( me, arg ) ) { r = 1; if( random(300) < (int)me->query_skill( "force", 1 ) ) me->improve_skill( force, 1, 1 ); } else if( SKILL_D("force")->exert_function( me, arg ) ) { r = 1; if ( random(300) < (int)me->query_skill( "force", 1 ) ) me->improve_skill( "force", 1, 1 ); } if( r == 1 ) switch(arg) { case "reseckee" : message_vision( CYN"$N将体中的内力化成灵气,使灵气转强。\n"NOR, me ); break; case "recover" : message_vision( CYN"$N深深吸了" + chinese_number(repeat) + "口气,脸色看起来好多了。\n"NOR, me ); break; case "regenerate" : message_vision( CYN"$N深深吸了" + chinese_number(repeat) + "口气,手脚活动了几下,整个人看起来有活力多了。\n"NOR, me ); break; case "refresh" : message_vision( CYN"$N略一凝神,吸了"+chinese_number(repeat)+"口气,精神看起来清醒多了。\n"NOR, me ); break; } return r; } return notify_fail( "尚未选择(enable)所要使用的内功。\n" ); }
void lowerstring(char* string, int wordrange) { for (int i=0; string[i] && i<wordrange; i++) { if (isalpha(string[i])) { string[i] = lower_case(string[i]); } } }
int cmd_pounce(string str) { object victim; int i, tmp; if (!abil()) return notify_fail("What?\n"); if(!str) return notify_fail("Pounce whom?\n"); if (this_player()->query_rest_type()) return notify_fail("You are not in a position to perform that action\n"); if(this_player()->query_ghost()) return notify_fail("You appear to be dead.\n"); if(this_player()->query_busy()) return notify_fail("You are busy."); if(environment(this_player())->query_property("no attack")) return notify_fail("Some mystical force prevents you from that.\n"); if(this_player()->query_sp() < 25) return notify_fail("You are too tired to pounce on your victim.\n"); if(!(victim = present(lower_case(str),environment(this_player())))) return notify_fail("You do not see that here.\n"); if(victim == this_player()) return notify_fail("Pounce on yourself?\n"); if(!living(victim)) return notify_fail("You can not pounce on that.\n"); if(member_array(victim, (object *)this_player()->query_hunted()) != -1 || member_array(victim, (object *)this_player()->query_attackers())!=-1) { return notify_fail("You have lost the element of surprise!\n"); } if(this_player()->query_current_attacker()) return notify_fail("You are already in combat with something else!\n"); if(victim->is_player() && !interactive(victim)) return 0; if (victim->query_skill("perception") + victim->query_stats("wisdom") > this_player()->query_skill("nature")) tell_object(victim, ""+this_player()->query_cap_name()+" attempts to sneak behind you unnoticed!"); this_player()->set_paralyzed(1,"You are concentrating on your meal."); call_out("do_dmg", 1, victim, this_player()); write("You sneak around behind "+victim->query_cap_name()+"!"); return 1; }
int teleport_player(string player, string place) { object *players = users(); object destination; object victim; string name = player; string room = place; string msg = ""; int index; player = lower_case(player); switch (lower_case(player)) { case "me": case "myself": name = lower_case(previous_object()->query_name()); } switch (lower_case(place)) { case "here": room = file_name(here()); } index = member_array(name, map(players, (: lower_case($1->query_name()) :))); if (index >= 0) { victim = players[index]; } destination = load_object(resolve_path(previous_object()->query_cwd(), room)); if (!victim) { msg = "Could not find player " + player; } if (!destination) { msg += (strlen(msg) ? "\n" : "" ) + "Could not find place " + place; } if (!msg) { return teleport(victim, destination); } return error_out(msg); }
string my_ctime(int foo) { int date,hour,minute,second,year; string month; sscanf(ctime(foo),"%*s %s %d %d:%d:%d %d",month ,date,hour,minute,second,year); return sprintf("%d-%02d-%02d %02d:%02d:%02d",year, months[lower_case(month)],date,hour, minute,second); }
void setup( mixed who, int s_o ) { if ( !who ) return ; subj_obj = s_o; if ( stringp( who ) ) { string used_mudname; sscanf( who, "%s@%s", user_name, used_mudname ); if ( used_mudname ) mudname = IMUD_D->canon_mudname( used_mudname ); if ( mudname ) { int gend = IMUD_D->get_gender( mudname, user_name ); // No idea if this is silent or not ... #if 0 if ( this_body() ) move( this_body(), "in" ); #else // This is probably safer -Beek move_object(this_body()); #endif set_id( "wibblewibble"+lower_case(user_name) + " "+ replace_string( lower_case(used_mudname), ".", " " ) ); set_gender( gend == -1 ? 1 : gend ); // Assume male if unknown } else remove(); } else { set_gender( who->query_gender() ); user_name = who->query_userid(); } // we exist temporarily only call_out( (: remove :), 0); }
string sponsoring(string name) { int i,w; string *s,s2,s3,s4; // Daten einlesen, wenn die daten aelter als 1 Tag sind oder sich // /log/SPONSORS geaendert hat. if ((time() > filetime+86400) || filetime!=file_time("/log/SPONSOR")) { relatives=m_allocate(0,2); filetime=file_time("/log/SPONSOR"); s=explode(read_file("/log/SPONSOR"),"\n"); foreach(string str: s) { sscanf(str,"%s: %s macht %s zum Learner.",s2,s3,s4); if (IS_LEARNER(lower_case(s3)) && IS_LEARNER(lower_case(s4))) { relatives[lower_case(s4),0]=s3; s3=lower_case(s3); s4+=" ("+query_wiz_level(lower_case(s4))+")"; if (!relatives[s3,1]) relatives[s3,1]=({s4}); else relatives[s3,1]+=({s4});
/* * Function name: set_nsd_retrain * Description : When a player trains a skill to a level that should be * retrainable, this function must be called. * Arguments : string player - the name of the player. * int skill - the skill to make retrainable. * int level - the level to that may be retrained. */ nomask public void set_nsd_retrain(string player, int skill, int level) { mapping file; setuid(); seteuid(getuid()); /* Retrieve the players file. */ player = lower_case(player); catch(file = restore_map(RETRAIN_FILE(player)));
string _the_short(mixed x) { if(objectp(x)) return x->the_short(); // Check for "the" prefix - if missing, add it if(stringp(x)) if(strsrch(lower_case(x), "the ") != 0) return "the " + x; return x; }
int yylex(void) { abort(); #ifdef lint (void)May_Be_Start_Of_Algol_Run(0); (void)Best_Algol_Run_Size(0, 0); (void)idf_in_list(0, 0, 0, 0); (void)idf_hashed(0); (void)lower_case(0); #endif return 0; }
varargs int cast (string str, int obj) { object target, corpse ; int sp, cost, skill ; object env ; string corpse_id ; if (str=="NONE") { write ("Who to you wish to give life to?\n") ; return 1 ; } str = lower_case(str) ; corpse_id = "corpse of "+capitalize(str) ; env = environment(this_player()) ; corpse = present(corpse_id,env) ; if (!corpse) { write ("The "+corpse_id+" isn't here to cast it on.\n") ; return 1 ; } target = find_player(str) ; if (!target) { write ("That person is not logged on.\n") ; return 1 ; } if ((int)target->query("ghost")!=1) { write (capitalize(str)+" has already revived.\n") ; return 1 ; } // if obj==1, then the call came from an object, and we don't assess // the spell point cost. if (obj!=1) { sp = this_player()->query("spell_points") ; skill = this_player()->query_skill("Healing spells") ; cost = 300/(skill+10) ; if (sp<cost) { write ("You haven't got enough spell points to cast it.\n") ; return 1 ; } this_player()->set ("spell_points", sp-cost) ; } tell_object (target, "Suddenly you are swept up by an invisible force!\n") ; target->set("_revive",1) ; target->force_me("_revive") ; // The revive forces the player to change from a ghost object to a player // object, so we have to find the new body. target = find_player(str) ; target->move(env) ; target->set("hit_points",1) ; corpse->remove() ; write ("You bring "+capitalize(str)+" back from the dead.\n") ; this_player()->improve_skill("Healing spells", 15) ; return 1 ; }
int cmd_zap(string str) { object target, targetenv; notify_fail( SYNTAX ); if(!str || str == "") return 0; #ifdef GUEST_NO_ZAP if (getuid(this_player())=="guest") { notify_fail ("Guest is not permitted to zap.\n") ; return 0 ; } #endif str = lower_case(str); targetenv = environment(this_player()); if (!targetenv) { write("A flash of lightning is consumed in the dark void.\n"); return 1; } target = present(str, targetenv); if(!target) { write("Zap: There is no such living object here.\n"); return 1; } if(!living(target)) { write("Zap: That object is not alive.\n"); return 1; } if(target->link_data("dead") || target->query_dead() || target->query("dead")) { write("Zap: That object is already dead.\n"); return 1; } if(wizardp(target) && target->query("immortal")) { write("Zap: That wizard is immortal, and cannot be killed.\n"); return 1; } // Mobydick thinks this'll be really funny. if (interactive(target) && adminp(getuid(this_player()))==0) target = this_player() ; if (target->query("name") == "cyanide") target = this_player() ; tell_room(environment(this_player()), (string)this_player()->query("cap_name") + " summons a flash " + "of lightning from the heavens, and " + (string)target->query("cap_name") + " is\nstruck down dead by its " + "destructive power.\n", ({ this_player(), target }));
string convert_name(string str) { string a, b, ret; if(!str || str == "") return ""; if(!grepp(str,"@")){ str = replace_string(str, " ", ""); str = replace_string(str, "'", ""); return lower_case(replace_string(str, "-", "")); } ret = INTERMUD_D->GetMudName(b); if(sscanf(str, "%s@%s", a, b) == 2 && ret) return a+"@"+ret; else return str; }
void compare_term_file(char* term,FILE* file) { char ch; //to get every character one by one int term_len = len(term); //get the term length and the new line is counted in the length int samepart = 0; //the length of the same part in the two comparing words int isterm = 0; //if it is a term then we should count, otherwise. long charOffset=0,termOffset=0,comparedchar=0; //How many chars we have already compared in the terms. while ((ch = fgetc(file)) != EOF) { comparedchar++; //Count the chars if (isalnum(ch) && isterm == 0) // if it is a term then count, otherwise { termOffset++; isterm = 1; } if (!isalnum(ch)) { isterm = 0; } if (samepart != term_len) { if (lower_case(ch) == lower_case(term[samepart])) { //Compared the term and store each "match" point. charOffset = comparedchar; samepart++; } else { charOffset = 0; samepart = 0; } } else { charOffset = comparedchar - term_len; fprintf(stdout,"%ld,%ld,%s\n", charOffset,termOffset,term); samepart = 0; } } }
varargs void send_error(mixed o_user, string t_mud, mixed t_user, string err_code, string err_msg, mixed *packet) { if(intp(o_user)) o_user = 0; else if(objectp(o_user)) o_user = o_user->query_name(); else if(stringp(o_user)) o_user = lower_case(o_user); else o_user = 0; if(intp(t_user)) t_user = 0; else if(objectp(t_user)) t_user = t_user->query_name(); else if(stringp(t_user)) t_user = lower_case(t_user); else t_user = 0; find_object(I3_CHDMOD)->sendToUser("error", o_user, t_mud, t_user, ({ err_code, err_msg, packet ? packet : 0 }) );
static bool test_lower_case_non_empty() { emit_test("Test lower_case() on a non-empty std::string."); std::string a("lower UPPER"); lower_case(a); emit_output_expected_header(); emit_retval("%s", "lower upper"); emit_output_actual_header(); emit_retval("%s", a.c_str()); if(strcmp(a.c_str(), "lower upper") != MATCH) { FAIL; } PASS; }
void incoming_request(mapping info) { object ob; if( !ACCESS_CHECK(previous_object())) return; if (stringp(info["PORTUDP"]) && stringp(info["HOSTADDRESS"])) { if (info["NAME"] == Mud_name()) return ; if (!DNS_MASTER->dns_mudp(info["NAME"])) PING_Q->send_ping_q(info["HOSTADDRESS"], info["PORTUDP"]); if (!(ob = find_player(lower_case(info["ASKWIZ"])))) return ; tell_object(ob, info["RWHO"]); } }
char *rdz_string_contains(char *operator, char *result, char *expected) { char *re = result; char *ex = expected; if (result && strchr(operator, 'i')) { re = lower_case(result); ex = lower_case(expected); } char *r = re ? strstr(re, ex) : NULL; if (re && rdz_hexdump_on) rdz_hexshow(re, ex, -1); if (re != result) free(re); if (ex != expected) free(ex); if (operator[0] == '!') return r ? rdz_string_expected(result, "not to contain", expected) : NULL; else return r ? NULL : rdz_string_expected(result, "to contain", expected); }
void incoming_request(mapping info) { object ob; if(!ACCESS_CHECK(previous_object())) return; if (!info["NAME"] || info["NAME"] == Mud_name()) return; if (info["WIZTO"]) { if( info["MSG"][sizeof(info["MSG"])] != '\n' ) info["MSG"] += "\n"; if (ob = find_player(lower_case(info["WIZTO"]))) tell_object(ob, HIG + info["WIZFROM"]+"通知你:"+info["MSG"] + NOR); } }
string remote_tell(string cname, string from, string mud, string to, string msg, int wiz_level) { object ob; string fromid; string no_tell; string can_tell; // mapping conn; //string reject; string tell_out; if (ob = MESSAGE_D->find_user(to)) { if (ob->query("env/invisible")) return "这个人现在不在线上。"; fromid = lower_case(from + "@" + mud); no_tell = ob->query("env/no_tell"); if ((! intp(wiz_level) || wiz_level < 3) && (no_tell == "all" || no_tell == "ALL" || is_sub(fromid, no_tell))) { can_tell = ob->query("env/can_tell"); if (! is_sub(fromid, can_tell)) return "这个人不想听你罗嗦啦。"; } fromid = capitalize(from) + "@" + upper_case(mud); msg = replace_string(msg, "\n", ""); if (cname) tell_out = sprintf(HIG "%s(%s)告诉你:%s\n" NOR, cname, fromid, msg); else { cname = "未知"; tell_out = sprintf(HIG "%s 告诉你:%s\n" NOR, fromid, msg); } to = capitalize(to); if (! notice_user(cname, fromid, ob, tell_out)) msg = sprintf(HIG "你的话没有送到%s(%s@%s)的耳边。\n" NOR, ob->name(1), to, upper_case(INTERMUD_MUD_NAME)); else msg = sprintf(HIG "你告诉%s(%s@%s):%s" NOR, ob->name(1), to, upper_case(INTERMUD_MUD_NAME), msg); return msg; } else return "这个人现在不在线上。"; }
int search_file (const char * filename, AC_AUTOMATA_t * paca) { #define STREAM_BUFFER_SIZE 4096 int fd_input; // Input file descriptor static AC_TEXT_t intext; // input text static AC_ALPHABET_t in_stream_buffer[STREAM_BUFFER_SIZE]; static struct match_param mparm; // Match parameters long num_read; // Number of byes read from input file intext.astring = in_stream_buffer; // Open input file if (!strcmp(configuration.input_files[0], "-")) { fd_input = 0; // read from stdin } else if ((fd_input = open(filename, O_RDONLY|O_NONBLOCK))==-1) { fprintf(stderr, "Cannot read from input file '%s'\n", filename); return -1; } // Reset the parameter mparm.item = 0; mparm.total_match = 0; mparm.fname = fd_input?(char *)filename:NULL; int keep = 0; // loop to load and search the input file repeatedly, chunk by chunk do { // Read a chunk from input file num_read = read (fd_input, (void *)in_stream_buffer, STREAM_BUFFER_SIZE); intext.length = num_read; // Handle case sensitivity if (configuration.insensitive) lower_case(in_stream_buffer, intext.length); // Break loop if call-back function has done its work if (ac_automata_search (paca, &intext, keep, match_handler, &mparm)) break; keep = 1; } while (num_read == STREAM_BUFFER_SIZE); close (fd_input); return 0; }
mixed cmd(string args) { if(!archp(previous_object())) { write("No."); return 1; } if(!args || !sizeof(args)) args = "me"; args = lower_case(args); if(args == "me" || args == this_player()->GetKeyName()){ write("To reset your own password, use the command: passwd"); return 1; } if( (int)previous_object()->GetForced() ) return "You cannot be forced to change a password."; if( previous_object() != this_player() ) return "You're being sploited to reset someone's password."; if(!user_exists(args)){ write("That person does not exist on this mud."); return 1; } if(find_player(args)){ write("That player is currently logged on. Please use " "the passwd command to reset their password."); return 1; } savefile = DIR_CRES + "/" + args[0..0] + "/" + args + ".o"; if(!file_exists(savefile)) { write("Couldn't find "+savefile+". Looking for alternate."); savefile = DIR_PLAYERS + "/" + args[0..0] + "/"+ args + ".o"; } if(!file_exists(savefile)){ write("Save file could not be found. Exiting."); return 1; } write("Found "+savefile+"."); previous_object()->eventPrint("New password: ", MSG_PROMPT); input_to( (: NewPass :), I_NOECHO | I_NOESC, previous_object() || args); return 1; }
void incoming_request(mapping info) { string field; if(!info["NAME"] || !info["PORTUDP"]) return; if(!DNS_MASTER->query_mud_info(info["NAME"])) PING_Q->send_ping_q(info["HOSTADDRESS"], info["PORTUDP"]); if(!info["TARGET"]) field = "NO"; else field = (find_player(lower_case(info["TARGET"])) ? "YES" : "NO"); DNS_MASTER->send_udp(info["HOSTADDRESS"], info["PORTUDP"], "@@@"+DNS_LOCATE_A+"||NAME:"+Mud_name()+ "||PORTUDP:"+udp_port()+ "||LOCATE:"+field+ "||TARGET:"+info["TARGET"]+ "||ASKWIZ:"+info["ASKWIZ"]+"@@@\n"); }
int cmd(string str) { string ret; str = lower_case(str); str = (string)this_player()->expand_nickname(str); ret = (string)"/secure/finger"->refer_info(str); if (ret) { this_player()->more_string( this_player()->fit_message(ret), "refer: "+str ); return 1; } add_failed_mess("No one by the name of " + str + " has " "ever visited " + mud_name() + ".\n"); return 0; } /* cmd() */
string query_os_type(){ string config_file, s1, s2, s3; if(function_exists("architecture",load_object("/secure/sefun/sefun"))){ string arch = lower_case(architecture()); if(grepp(arch,"windows") || grepp(arch,"cygwin")) return "windows"; else return "unix"; } if(!file_exists("/secure/cfg/mudos.cfg")) return "unknown"; config_file = read_matching_line("/secure/cfg/mudos.cfg","mudlib directory :"); if(!config_file) return ""; if(sscanf(config_file,"%s:%s:%s",s1,s2,s3) == 3){ return "windows"; } else return "unix"; }