/* Finger Daemon 9/30/92 * For GumbiMud: minkowski.geom.umn.edu 3000 * * by Jubal - with help from Kestrel :-) * and finger code from Kestrel's other mud (I forget where ;-) * * This is the finger daemon for the "finger" command. It must be a * seperate file from player.c so it can restore_object without * affecting the player. * */ #include "/include/level.h" /*#define FACADE /* standalone facade */ #define DEST "/players/jubal/workroom" /* necessary if FACADE */ #define PAGER_SIZE 22 /* vars for the pager */ static string pager_array; /* ARRAY of lines for start_pager(), etc. */ static int pager_start; /* current screen's starting line (first=0) */ static int pager_max; /* last array index from pager_array to use */ /* player.c stuff */ string pretitle; string title; string al_title; string Gender; int s_inv; int lastlogin; string called_from_ip; string quests; string guild_string; string real_name; string mailaddr; string access_list; string description; string plan; string edtitle; string edalign; /* living.c stuff */ string spouse; int magic_resist; int savings; int money; string name; string msgin,msgout,mmsgout,mmsgin,mclone,mdest,msgtrans,msghome,invisname; int level; int guild_level; int hit_point; int max_hp, max_sp; int experience; int spell_points; int age; int is_invis; int frog; int dead; int informed; int alignment; int gender; int Str,Int,Wis,Con,Dex; /* mail_reader.c stuff */ int new_mail; int last_read; string messages; /* to find number of messages */ /* finger daemon stuff */ static int mylev; static int iswiz; static object ob; static string info; static string tmpstr; static int tmpint; static int num_messages; #ifdef FACADE /* For testing -- let it stand as a facade */ inherit "obj/treasure"; reset(arg) { if (arg) return; set_id("fin"); set_short("Finger Demon"); set_long("This is the Finger Demon. Use 'finger NAME' to get\n" + "information about a player or wizard.\n"); set_weight(0); set_value(0); /* move_object(this_object(), DEST); /* Does not work.. */ } #endif FACADE init() { if(environment(this_object())!=this_player()) return 1; add_action("finger", "finger"); } id(str) { return str=="fingerd"; } query_name() { return "fingerd"; } drop() { return 1; } is_fingerd() { return 1; } finger(str) { if (!str) { write("Usage: finger \n"); return 1; } clear_all(); info=""; tmpstr=""; tmpint=0; mylev=this_player()->query_level(); iswiz=mylev>=WIZ; ob=find_player(str); if(ob) ob->save_me(-1); /* never hurts to save */ if (!restore_object("players/"+str)) { write("No such player: " + str + "\n"); return 1; } if(!name) name=str; if (!restore_object("room/post_dir/" + str)) { num_messages=0; new_mail=0; } else num_messages=sizeof(explode(messages, "\n**\n"))/2; if((ob)&&(!is_invis)&&(iswiz)) info+=ob->short(); else { if((is_invis) && (iswiz)) info+="#"; if ((dead) || (frog)) { if (dead) info+= "ghost of "; info+=capitalize(name); if (frog) info+= " the frog"; } else { if((pretitle) && (pretitle!="")) info+=pretitle+" "; info+=capitalize(name); if((title) && (title!="")) info+=" "+title; if((al_title) && (al_title!="")) info+=" ("+al_title+") "; } } /* got short */ info+="\n"; info+="Level: "; if(level>=WIZ) info+=levelstr(level)+formatint(level,5); else info+=levelstr(level)+" "; info+=" Gender: " + ({"Neuter", "Male ", "Female"})[gender]; if((real_name) && (real_name!="")) if(iswiz) info+=" In real life: "+real_name; info+="\n"; if ((guild_string) && (guild_string!="") && (guild_string!="no")) { info+="Guild: "+formatstr(guild_string,13); if (guild_level) "Guild Level: "+guild_level; info+="\n"; } if(iswiz) { info+="Money: "+formatint(money,13)+"Savings: "+formatint(savings,10); info+="Experience: "+experience+"\n"; info+="HP: "+hit_point+"/"+max_hp+" SP: "+spell_points+"/"+max_sp; info+=" Align: "+alignment+"\n"; info+="Str: "+Str+" Int: "+Int+" Wis: "+Wis+" Dex: "+Dex+" Con: "+Con; info+="\n"; if(quests) info+="Quests: "+implode(explode(quests,"#"),",")+"\n"; } if(lastlogin) { if((ob) && ((!is_invis) || (iswiz))) info+="On since "; else info+="Last login "; info+=ctime(lastlogin); } if (iswiz) { info+=" from "; if(ob && query_ip_name(ob) && query_ip_name(ob)!=called_from_ip) info+= query_ip_name(ob)+" ("+called_from_ip+")"; else info+= called_from_ip; if(ob) info+="\nLocation: /"+file_name(environment(ob)); } info+="\n"; if(iswiz) info+="Age: "+dms(age)+" "; if((!is_invis) || (iswiz)) { if((ob)&&(!interactive(ob))) info+="(Netdead) "; else if((ob)&&(query_idle(ob)>60)) info+="Idle: "+dms(query_idle(ob)/2); } info+="\n"; if(iswiz) if((mailaddr)&&(mailaddr!="")) info+="Email address: "+mailaddr+"\n"; if (last_read) { if(new_mail) info+="New mail since "; else info+="Mail last read "; info+=ctime(last_read); /* might be a tipoff that someone is logged in and invis if last_read is recent.. might change.. !! */ } else { if(new_mail) info+="New mail"; else info+="No new mail"; } info+=" ("+num_messages+" message"; if (num_messages!=1) info+="s"; info+=")"; info+="\n"; if (informed) info+="Informed of logins.\n"; if((description)&&(description!="")) info+="Description:\n"+description; info+=get_plan(); pager_count(info); if (pager_max > PAGER_SIZE) start_pager(info, 0); else write(info); return 1; } get_plan() { int i; string filename; string file; string tmp; tmp="\nPlan:\n"; if((plan)&&(plan!="")&&(plan!=" ")) tmp+=plan+"\n"; filename="/players/"+name+"/.plan"; file=read_file(filename,i); if (file) return tmp+file+"\n"; if((plan)&&(plan!="")&&(plan!=" ")) return tmp; return "\n"; } /* start_pager(text, start_idx) * text = string to display a page at a time * (trailing blank lines are never shown) * start_idx = index of line to start at (0=top, 1=2nd line, etc.; * NEGATIVE start_idx is relative to END: -1=last line, * -2=second-to-last line, etc.) */ start_pager(text, start_idx) { if (start_idx > pager_max) start_idx = pager_max; else if (start_idx < 0) { start_idx += pager_max + 1; if (start_idx < 0) start_idx = 0; } pager_start = start_idx; pager_display(); } /* hack by Shadowfire -- separated this out from previous routine */ pager_count(text) { pager_array = explode(text+"\n", "\n"); pager_max = sizeof(pager_array) - 1; /* -------- Eliminate trailing blank lines -------- */ while (pager_max > 0 && pager_array[pager_max] == "") pager_max--; } pager_display() { int i, end; if (!pager_array) return; if (pager_start < 0) pager_start = 0; end = pager_start + PAGER_SIZE - 1; if (end > pager_max) end = pager_max; for (i=pager_start; i<=end; i++) if(extract(pager_array[i],0,0)==" ") write(""); /* want to cause a page */ else write(pager_array[i]+"\n"); if (end == pager_max) return; write("Finger info : " + (pager_start+1) + "-" + (end+1)); write(" -- [,b(back),q] "); input_to("pager_continue"); } pager_continue(str) { if (str == "q" || str == "x") { write("Ok.\n"); pager_array = 0; return; } else if (str == "u" || str == "p" || str == "b") { pager_start -= PAGER_SIZE; if (pager_start < 0) pager_start = 0; } else { pager_start += PAGER_SIZE; if (pager_start > pager_max) { pager_array = 0; return 1; } } pager_display(); /* has input_to("pager_continue") */ return 1; } formatint(num,spc) { int len; int tmp; string pad; pad=""; len=0; tmp=num; while (tmp>9) { len++; tmp/=10; } tmp=spc-len; while(tmp>0) { pad+=" "; tmp--; } return num+pad; } formatstr(str,spc) { int tmp; string pad; pad=""; tmp=spc-strlen(str); while(tmp>0) { pad+=" "; tmp--; } return str+pad; } dms(sec) { string out; out=""; if (sec/86400) { out+=sec/86400 + " days "; sec = sec - (sec/86400)*86400; } if (sec/3600) { out+=sec/3600 + " hours "; sec = sec - (sec/3600)*3600; } if (sec/60) { out+=sec/60 + " minutes "; sec = sec - (sec/60)*60; } return out+ sec + " seconds."; } clear_all() { /* Guess what it does ;-) */ pretitle=0; title=0; al_title=0; Gender=0; s_inv=0; lastlogin=0; called_from_ip=0; quests=0; guild_string=0; real_name=0; mailaddr=0; access_list=0; description=0; plan=0; edtitle=0; edalign=0; spouse=0; magic_resist=0; savings=0; money=0; name=0; msgin=0; msgout=0; mmsgout=0; mmsgin=0; mclone=0; mdest=0; msgtrans=0; msghome=0; invisname=0; level=0; guild_level=0; hit_point=0; max_hp=0; max_sp=0; experience=0; spell_points=0; age=0; is_invis=0; frog=0; dead=0; informed=0; alignment=0; gender=0; Str=0; Int=0; Wis=0; Con=0; Dex=0; new_mail=0; num_messages=0; last_read=0; }