/*********************************** * Different needed function calls * ***********************************/ #if defined(macintosh) #include <types.h> #else #include <sys/types.h> #endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> /* close */ #include <time.h> #include "merc.h" /* * This function have always been broken, perhaps * one day in the future I'll make a functionel * piece of code, but untill then, it's more * guessing the right size than anything else. */ char *get_dystopia_banner(char *title, int size) { int tSize = strlen(title); int patternsize, bufferspaces = 0, blockcount, i; static char buf[200]; /* just so we can use strcat */ buf[0] = '\0'; /* calculating the amount of patterns on each side of the title */ patternsize = (size - tSize)/2; if (!(patternsize % 4)) patternsize -= 4; else while(patternsize % 4) patternsize--; patternsize /= 4; /* calculating buffer spaces */ while ((tSize + bufferspaces) % 4) bufferspaces++; blockcount = bufferspaces/2; if (patternsize < 1) { strcat(buf, "#0<>== #G"); strcat(buf, title); strcat(buf, " #0==<>#n"); } else { /* first add patterns */ strcat(buf, "#0<>=="); for (i = 1; i < patternsize; i++) strcat(buf, "<>=="); /* add the title */ if (tSize) { strcat(buf, "#G "); while (bufferspaces > blockcount) { bufferspaces--; strcat(buf, " "); } } else strcat(buf, "<>"); strcat(buf, title); if (tSize) { strcat(buf, "#0 "); while (bufferspaces > 0) { bufferspaces--; strcat(buf, " "); } } /* add secondary patterns */ for (i = 0; i < patternsize; i++) strcat(buf, "==<>"); strcat(buf, "#n"); } return buf; } void strip_aggression(CHAR_DATA *ch) { if (IS_NPC(ch)) return; ch->pcdata->agg_counter = 0; ch->pcdata->aggress_towards = 0; ch->pcdata->aggress_from = 0; } /* * Is astr contained within bstr ? * */ bool is_contained( const char *astr, const char *bstr ) { int i, alen, blen, count; alen = strlen(astr); blen = strlen(bstr); if (alen > blen) return FALSE; for (i = 0; i <= (blen - alen); i++) { count = 0; while (count < alen && UPPER(astr[count]) == UPPER(bstr[i+count])) count++; if (count == alen) return TRUE; } return FALSE; } bool is_contained2( const char *astr, const char *bstr ) { int i, alen, blen, count; alen = strlen(astr); blen = strlen(bstr); if (alen > blen) return FALSE; for (i = 0; i <= (blen - alen); i++) { count = 0; while (count < alen && astr[count] == bstr[i+count]) count++; if (count == alen) return TRUE; } return FALSE; } int get_next_playerid() { top_playerid++; save_coreinfo(); return top_playerid; } int strlen2(const char *s) { int i, b, count=0; if (s[0] == '\0') return 0; b = strlen(s); for (i = 0; i < b; i++) { if (s[i] == '#') count++; } return (b + 7 * count); } void win_prize( CHAR_DATA *ch ) { int i,vnum; OBJ_DATA *obj; OBJ_INDEX_DATA *pIndex; if (IS_NPC(ch)) return; i = number_range(1,100); if (i < 50) vnum = OBJ_VNUM_PROTOPLASM; else if (i < 65) vnum = 33851; else if (i < 75) vnum = 33852; else if (i < 80) vnum = 33853; else if (i < 85) vnum = 33854; else if (i < 90) vnum = 33855; else if (i < 95) vnum = 33856; else vnum = 33857; if ((pIndex = get_obj_index(vnum)) == NULL) { bug("BAD PRIZE!!",0); return; } obj = create_object(pIndex, 50); if (vnum == OBJ_VNUM_PROTOPLASM) { obj->level = 1; free_string(obj->short_descr); free_string(obj->name); free_string(obj->description); obj->short_descr = str_dup("A prize token"); obj->description = str_dup("A token lies on the floor"); obj->name = str_dup("prize token"); obj->value[0] = number_range(100,300); obj->item_type = ITEM_QUEST; } obj_to_char(obj,ch); return; } void log_string2(const char *str) { char *strtime; strtime = ctime(¤t_time); strtime[strlen(strtime)-1] = '\0'; fprintf(stderr, "%s :: %s\n", strtime, str); return; } void init_vt100(DESCRIPTOR_DATA *d, char *xbuf) { CHAR_DATA *ch; char buf[MAX_STRING_LENGTH]; int i; if ((ch = d->character) == NULL) { bug("Init_vt100: No character", 0); return; } if ((i = atoi(xbuf)) < 10) { send_to_char("VT100 Failed.\n\r", ch); return; } ch->pcdata->vt100_size = i; SET_BIT(ch->pcdata->tempflag, TEMP_VT100); sprintf(buf, "\e[%d;1H%s%s\e[1;1H%s%s\e[1;%dr", i, VT_CLEAR_LINE, VT_SAVECURSOR, VT_SETWIN_CLEAR, VT_CLEAR_SCREEN, i - 2); send_to_char(buf, ch); send_to_char("VT100 Initialized.\n\r", ch); return; } void check_help_soundex(char *argument, CHAR_DATA *ch) { HELP_DATA *pHelp; char buf[MAX_STRING_LENGTH]; char tbuf[MAX_STRING_LENGTH]; char arg[MAX_INPUT_LENGTH]; char keyword[MAX_INPUT_LENGTH]; char *str; bool found = FALSE; one_argument(argument, arg); if (arg[0] == '\0') return; sprintf(buf, "\n\r[Perhaps:"); for (pHelp = first_help; pHelp; pHelp = pHelp->next) { if (pHelp->level > ch->level) continue; str = pHelp->keyword; str = one_argument(str, keyword); while (keyword[0] != '\0') { if (SoundexMatch(GetSoundexKey(arg), GetSoundexKey(keyword)) > 75) { found = TRUE; sprintf(tbuf, " %s", keyword); strcat(buf, tbuf); } str = one_argument(str, keyword); } } strcat(buf, "]\n\r"); if (found) send_to_char(buf, ch); } void do_clearstats2( CHAR_DATA *ch, char *argument ) { OBJ_DATA *obj; OBJ_DATA *obj_next; if (IS_NPC(ch)) return; powerdown(ch); /* remove class shit */ for ( obj = ch->carrying; obj != NULL; obj = obj_next ) { obj_next = obj->next_content; if ( obj->wear_loc != WEAR_NONE ) {obj_from_char(obj); obj_to_char(obj,ch);} } while ( ch->affected ) affect_remove( ch, ch->affected ); if (IS_SET(ch->affected_by, AFF_POLYMORPH)) REMOVE_BIT(ch->affected_by, AFF_POLYMORPH); if (IS_SET(ch->affected_by, AFF_ETHEREAL)) REMOVE_BIT(ch->affected_by, AFF_ETHEREAL); if (IS_EXTRA(ch,EXTRA_DRAGON)) REMOVE_BIT(ch->extra, EXTRA_DRAGON); ch->affected_by = 0; ch->armor = 100; ch->hit = UMAX( 1, ch->hit ); ch->mana = UMAX( 1, ch->mana ); ch->move = UMAX( 1, ch->move ); ch->hitroll = 0; ch->damroll = 0; ch->saving_throw = 0; ch->pcdata->mod_str = 0; ch->pcdata->mod_int = 0; ch->pcdata->mod_wis = 0; ch->pcdata->mod_dex = 0; ch->pcdata->mod_con = 0; ch->pcdata->followers = 0; if (IS_SET(ch->newbits, NEW_DFORM)) REMOVE_BIT(ch->newbits, NEW_DFORM); if (IS_POLYAFF(ch, POLY_ZULOFORM)) REMOVE_BIT(ch->polyaff, POLY_ZULOFORM); if (IS_SET(ch->newbits, NEW_CUBEFORM)) REMOVE_BIT(ch->newbits, NEW_CUBEFORM); if (IS_SET(ch->polyaff, POLY_DRAGON)) REMOVE_BIT(ch->polyaff, POLY_DRAGON); save_char_obj( ch ); send_to_char("Your stats have been cleared. Please rewear your equipment.\n\r",ch); return; } /* * If an item have a bad char in it's short/long/name desc, the mud * will freeze when the char with that item tries to log on, so use * this check on any renaming of items (glamour/reshape/etc). */ bool has_bad_chars(CHAR_DATA *ch, char *argument) { int i; if ( argument[0] == '\0' ) return FALSE; for (i = 0; argument[i] != '\0' ; i++) { if (argument[i] == '~') return TRUE; } return FALSE; } void ragnarok_stop() { DESCRIPTOR_DATA *d; ragnarok = FALSE; do_info(NULL,"#CPeace has been restored in the realms, the time of ragnarok is no more#n"); for (d = descriptor_list; d != NULL; d = d->next) { if (d->character && d->connected == CON_PLAYING) { d->character->fight_timer = 0; d->character->pcdata->safe_counter = 5; do_call(d->character,"all"); do_restore(d->character,"self"); } } return; } /* agrr_test by blade of E, version 1.31. */ void aggr_test(CHAR_DATA * ch) { char buf[60]; CHAR_DATA *wch; CHAR_DATA *wch_next; CHAR_DATA *victim; if (!IS_NPC(ch) && ch->level < 7 && ch->in_room != NULL && !IS_SET(ch->in_room->room_flags,ROOM_SAFE)) { for ( wch = ch->in_room->people; wch != NULL; wch = wch_next ) { wch_next = wch->next_in_room; if ( !IS_NPC(wch) || !IS_SET(wch->act, ACT_AGGRESSIVE) || wch->fighting != NULL || IS_AFFECTED(wch, AFF_CHARM) || !IS_AWAKE(wch) || ( IS_SET(wch->act, ACT_WIMPY) && IS_AWAKE(ch)) || !can_see( wch, ch ) || number_bits(2) == 0) { continue; } victim = wch; if ( victim == NULL ) continue; sprintf(buf,"%s screams and attacks!\n\r", victim->name); send_to_char(buf, ch); multi_hit( victim, ch, TYPE_UNDEFINED ); } } return; } void powerdown(CHAR_DATA *ch) { if (IS_NPC(ch)) return; if (IS_CLASS(ch, CLASS_DEMON) || IS_CLASS(ch, CLASS_HELLS_SOLDIER) || IS_CLASS(ch, CLASS_BETRAYER) || IS_CLASS(ch, CLASS_SHADOW_FIEND) || IS_CLASS(ch, CLASS_SHADOW_DRAGON)) { if (IS_POLYAFF(ch, POLY_ZULOFORM)) /* demonform */ { REMOVE_BIT(ch->polyaff, POLY_ZULOFORM); REMOVE_BIT(ch->affected_by, AFF_POLYMORPH); free_string( ch->morph ); ch->morph = str_dup( "" ); } } else if (IS_CLASS(ch, CLASS_DROW) || IS_CLASS(ch, CLASS_BLACK_ASSASSIN) || IS_CLASS(ch, CLASS_STALKER) || IS_CLASS(ch, CLASS_SHADOWBORN)) { if (IS_SET(ch->newbits,NEW_DFORM)) /* spiderform */ { free_string(ch->morph); ch->morph = str_dup(""); REMOVE_BIT(ch->newbits,NEW_DFORM); REMOVE_BIT(ch->newbits,THIRD_HAND); REMOVE_BIT(ch->newbits,FOURTH_HAND); } } else if (IS_CLASS(ch, CLASS_UNDEAD_LYCAN) || IS_CLASS(ch, CLASS_HELL_SPAWN) || IS_CLASS(ch, CLASS_VAMPIRIC_MIST) || IS_CLASS(ch, CLASS_VAMPIRE)) { if (IS_EXTRA(ch, EXTRA_DRAGON)) /* dragonform */ { REMOVE_BIT(ch->extra,EXTRA_DRAGON); free_string( ch->morph ); ch->morph = str_dup( "" ); } if (IS_POLYAFF(ch, POLY_ZULOFORM)) /* zuloform */ { REMOVE_BIT(ch->polyaff, POLY_ZULOFORM); REMOVE_BIT(ch->affected_by, AFF_POLYMORPH); free_string( ch->morph ); ch->morph = str_dup( "" ); } } else if (IS_CLASS(ch, CLASS_TANARRI) || IS_CLASS(ch, CLASS_DEVA) || IS_CLASS(ch, CLASS_HELL_SPAWN) || IS_CLASS(ch, CLASS_BAATEZU)) { if (ch->pcdata->powers[TANARRI_FURY_ON] == 1) /* fury */ ch->pcdata->powers[TANARRI_FURY_ON] = 0; } //else if (IS_CLASS(ch, CLASS_SHAPESHIFTER)) //{ // if (IS_SET(ch->affected_by, AFF_POLYMORPH)) /* reset form */ // { // ch->pcdata->powers[SHAPE_FORM]=0; // REMOVE_BIT(ch->affected_by, AFF_POLYMORPH); // free_string(ch->morph); // ch->morph=str_dup(""); // } //} //else if (IS_CLASS(ch, CLASS_DROID)) //{ // if (IS_SET(ch->newbits, NEW_CUBEFORM)) /* avatar of Lloth */ // { // REMOVE_BIT(ch->newbits, NEW_CUBEFORM); // REMOVE_BIT(ch->affected_by, AFF_POLYMORPH); // free_string(ch->morph); // ch->morph=str_dup(""); // } // else if (IS_CLASS(ch, CLASS_UNDEAD_KNIGHT) || IS_CLASS(ch, CLASS_UNDEAD_ASSASSIN) || IS_CLASS(ch, CLASS_NAZGUL) || IS_CLASS(ch, CLASS_NECROMANCER)) { if (IS_SET(ch->pcdata->powers[AURAS], MIGHT_AURA)) /* aura of might */ REMOVE_BIT(ch->pcdata->powers[AURAS], MIGHT_AURA); } else if (IS_CLASS(ch, CLASS_HEAVENS_SOLDIER) || IS_CLASS(ch, CLASS_TYPHON) || IS_CLASS(ch, CLASS_ANGEL) || IS_CLASS(ch, CLASS_SILVER_DRAGON)) { if (IS_SET(ch->newbits, NEW_CUBEFORM)) /* godly favor */ { REMOVE_BIT(ch->newbits, NEW_CUBEFORM); REMOVE_BIT(ch->affected_by, AFF_POLYMORPH); free_string(ch->morph); ch->morph=str_dup(""); } } return; } int needed (CHAR_DATA *ch) { int ratio; if (IS_NPC(ch)) return 0; //if ((ch->pkill + ch->pdeath) == 0) ratio = 0; if (ch->status == 0) ratio = 0; if (ch->status > 0) { ratio = (ch->status * 100); } return ratio; } int get_ratio(CHAR_DATA *ch) { int ratio; if (IS_NPC(ch)) return 0; if ((ch->pkill + ch->pdeath) == 0) ratio = 0; // to avoid divide by zero. else if (ch->pkill > 0) ratio = ch->pkill * 100 * ((ch->pkill * ch->pkill) - (ch->pdeath * ch->pdeath))/((ch->pkill + ch->pdeath) * (ch->pkill + ch->pdeath)); else ratio = 100 * ((ch->pkill * ch->pkill) - (ch->pdeath * ch->pdeath))/((ch->pkill + ch->pdeath) * (ch->pkill + ch->pdeath)); return ratio; } bool multicheck(CHAR_DATA *ch) { CHAR_DATA *gch; char buf[MAX_STRING_LENGTH]; for (gch = char_list; gch; gch = gch->next) { if (IS_NPC(gch)) continue; if (gch == ch) continue; if (strlen(gch->lasthost) > 2) { if (gch->desc) { if (!str_cmp(gch->desc->host, ch->desc->host)) { sprintf(buf,"%s has connected from the same IP as %s", ch->name, gch->name); log_string(buf); // sprintf(buf,"%s And %s Are MULTIPLAYING BITCHES!", ch->name, gch->name); // do_info(ch,buf); // do_quit(%s, gch-> ); return TRUE; } } else if (!str_cmp(gch->lasthost, ch->desc->host)) { sprintf(buf,"%s has connected from the same IP as %s", ch->name, gch->name); log_string(buf); return TRUE; } } } return FALSE; } bool reachedDecapLimit( CHAR_DATA *ch ) { AFFECT_DATA *paf; OBJ_DATA *obj; int limit = 0, objhps = 0, spellhps = 0; int hps, i; if (IS_NPC(ch)) return TRUE; if (ch->level > 6) return FALSE; //if (!IS_CLASS(ch, CLASS_SAMURAI)) //{ // for (paf = ch->affected; paf != NULL; paf = paf->next) // { // if (paf->location == APPLY_HIT) // spellhps += paf->modifier; // } //} for (i = 0; i < MAX_WEAR; i++) { if ((obj = get_eq_char(ch, i)) == NULL) continue; // if (IS_CLASS(ch, CLASS_SAMURAI) && obj->pIndexData->vnum != 33177) continue; for (paf = obj->pIndexData->affected; paf; paf = paf->next) { if (paf->location == APPLY_HIT) objhps += paf->modifier; } for (paf = obj->affected; paf; paf = paf->next) { if (paf->location == APPLY_HIT) objhps += paf->modifier; } } hps = (ch->max_hit - (spellhps + objhps)); if (hps > 10000) limit += 10; else limit += hps/1000; if ((hps -= 10000) > 10000) limit += 20; else if (hps > 0) limit += 2 * hps/1000; if ((hps -= 10000) > 10000) limit += 30; else if (hps > 0) limit += 3 * hps/1000; if ((hps -= 10000) > 10000) limit += 40; else if (hps > 0) limit += 4 * hps/1000; if ((hps -= 10000) > 10000) limit += 50; else if (hps > 0) limit += 5 * hps/1000; if ((hps -= 10000) > 10000) limit += 60; else if (hps > 0) limit += 6 * hps/1000; if (is_upgrade(ch)) limit *= (2 + ch->pcdata->upgrade_level); /* * For those with no skill */ limit += ch->pdeath; if (limit > ch->pkill) return FALSE; else return TRUE; } void death_info(char *str) { DESCRIPTOR_DATA *d; char buf[MAX_STRING_LENGTH]; if (str[0] == '\0') return; sprintf(buf, "#0/\\/\\ #RDe#Ya#Rth #0/\\/\\#n %s\n\r", str); for (d = descriptor_list; d != NULL; d = d->next) { if (d->connected == CON_PLAYING && d->character != NULL) send_to_char(buf, d->character); } return; } void avatar_info(char *str) { DESCRIPTOR_DATA *d; char buf[MAX_STRING_LENGTH]; if (str[0] == '\0') return; sprintf(buf, "#p-=#P[ #WAvatar #P]#p=-#n %s\n\r", str); for (d = descriptor_list; d != NULL; d = d->next) { if (d->connected == CON_PLAYING && d->character != NULL) send_to_char(buf, d->character); } return; } void leave_info(char *str) { DESCRIPTOR_DATA *d; if (str[0] == '\0') return; for (d = descriptor_list; d != NULL; d = d->next) { if (d->connected == CON_PLAYING && d->character != NULL) { send_to_char("#G+#g-#G+ #0Leaves #G+#g-#G+#n ", d->character); send_to_char(str, d->character); send_to_char("\n\r", d->character); } } return; } void enter_info(char *str) { DESCRIPTOR_DATA *d; if (str[0] == '\0') return; for (d = descriptor_list; d != NULL; d = d->next) { if (d->connected == CON_PLAYING && d->character != NULL) { send_to_char("#0=#w-#0= #WEnters #0=#w-#0=#n ", d->character); send_to_char(str, d->character); send_to_char("\n\r", d->character); } } return; } int getMight(CHAR_DATA *ch) { AFFECT_DATA *paf; OBJ_DATA *obj; int spellhps = 0; int objhps = 0; int might, temp, i; //if (!IS_CLASS(ch, CLASS_SAMURAI)) //{ // for (paf = ch->affected; paf != NULL; paf = paf->next) // { // if (paf->location == APPLY_HIT) // spellhps += paf->modifier; // } //} // for (i = 0; i < MAX_WEAR; i++) { if ((obj = get_eq_char(ch, i)) == NULL) continue; // if (IS_CLASS(ch, CLASS_SAMURAI) && obj->pIndexData->vnum != 33177) continue; for (paf = obj->pIndexData->affected; paf != NULL; paf = paf->next) { if (paf->location == APPLY_HIT) objhps += paf->modifier; } for (paf = obj->affected; paf; paf = paf->next) { if (paf->location == APPLY_HIT) objhps += paf->modifier; } } might = (ch->max_hit - (spellhps + objhps))/5500; might += (ch->pResist * 10); might += (ch->pRank * 10); if (ch->symbioteac > 0) might += ch->symbioteac / 10; if (ch->symbiotedc > 0) might += ch->symbiotedc / 10; if (ch->symbiotedr > 0) might += ch->symbiotedr / 5; if (ch->symbiotehr > 0) might += ch->symbiotehr / 5; for (i = 0; i < 5; i++) might += UMIN(2, ch->spl[i]/100); for (i = 0; i < 19; i++) might += UMIN(4, ch->wpn[i]/50); for (i = 1; i < 11; i++) might += UMIN(4, ch->stance[i]/50); if (IS_SET(ch->newbits, NEW_MASTERY)) might += 20; if (ch->stance[23] != -1) might += 250; else if (ch->stance[22] != -1) might += 100; else if (ch->stance[21] != -1) might += 50; else if (ch->stance[20] != -1) might += 50; else if (ch->stance[19] != -1) might += 50; if (ch->pcdata->powers[18] > 0) might += ch->pcdata->powers[18] * 50; if (ch->pcdata->powers[19] > 0) might += ch->pcdata->powers[19] * 50; if (might >= 150) { // if (ch->pcdata->rune_count > 0) might += UMIN(150, ch->pcdata->rune_count * 10); // if (ch->pcdata->platinum_count > 0) might += UMIN(350, ch->pcdata->platinum_count * 40); // if (ch->pcdata->arti_count > 0) might += UMIN(400, ch->pcdata->arti_count * 40); if ((temp = get_ratio(ch)) >= 500) might += UMIN(100, temp / 50); // 10 points for each pkpower. // if (ch->pcdata->upgrade_level > 0) might += ch->pcdata->upgrade_level * 270; if (ch->pStatus > 0) might += ch->pStatus * 100; } return might; } void forge_affect(OBJ_DATA *obj, int value) { AFFECT_DATA paf; paf.type = 0; paf.duration = -1; paf.location = APPLY_HITROLL; paf.modifier = value; paf.bitvector = 0; affect_to_obj(obj, &paf); paf.type = 0; paf.duration = -1; paf.location = APPLY_DAMROLL; paf.modifier = value; paf.bitvector = 0; affect_to_obj(obj, &paf); } void dump_last_command() { FILE *fp; char buf[MAX_STRING_LENGTH]; fp = fopen("../src/crash.txt","a"); fprintf (fp,"Last command typed : %s\n",last_command); fflush(fp); fclose(fp); /* * creates a note to the immortals */ sprintf(buf, "It seems we have crashed, the last command typed was\n\r\n\r"); strcat(buf, last_command); strcat(buf, "\n\r\n\rPlease remember that this doesn't mean that this caused the crash.\n\r\n\rRegards,\n\r\n\rThe Crash Code"); make_note("Immortal", "Crash Code", "imm", "We Crashed", 7, buf); } void update_revision(CHAR_DATA *ch) { OBJ_DATA *obj; int i; if (IS_NPC(ch)) return; if (ch->pcdata->revision == CURRENT_REVISION) return; /* * We don't end cases with break, since we want the player to be fully updated. */ switch (ch->pcdata->revision) { case 0: for (i = 0; i < MAX_WEAR; i++) { if ((obj = get_eq_char(ch, i)) == NULL) continue; if (obj->pIndexData->vnum >= 814 && obj->pIndexData->vnum <= 825) ch->pcdata->rune_count++; } ch->pcdata->revision++; default: break; } return; } bool in_fortress(CHAR_DATA *ch) { if (!ch->in_room) return FALSE; if (ch->in_room->vnum >= 151 && ch->in_room->vnum <= 170) return TRUE; return FALSE; } bool in_arena(CHAR_DATA *ch) { if (!ch->in_room) return FALSE; if (ch->in_room->vnum >= 50 && ch->in_room->vnum <= 67) return TRUE; return FALSE; } void logout_message(CHAR_DATA *ch) { static char * const he_she [] = { "XX", "he", "she" }; static char * const him_her [] = { "XX", "him", "her" }; static char * const his_her [] = { "XX", "his", "her" }; DESCRIPTOR_DATA *d; char buf[400]; // that should be plenty. const char *dmess; const char *i; char *ptr2; char *ptr; int size; size = strlen2(ch->pcdata->logoutmessage); if (size > 380) { bug("Bad logoutmessage.",0); return; } ptr2 = "#C<- #RLeaves #C->#n "; ptr = buf; dmess = ch->pcdata->logoutmessage; while ((*ptr = *ptr2) != '\0') ++ptr, ++ptr2; while (*dmess != '\0') { if ( *dmess != '$' ) { *ptr++ = *dmess++; continue; } ++dmess; switch (*dmess) { default: i = ""; break; case 'n': i = ch->name; break; case 'e': i = he_she [URANGE(1, ch->sex, 2)]; break; case 'm': i = him_her [URANGE(1, ch->sex, 2)]; break; case 's': i = his_her [URANGE(1, ch->sex, 2)]; break; } ++dmess; /* copying the data into the pointer */ while ((*ptr = *i) != '\0') ++ptr, ++i; } *ptr++ = '\n'; *ptr++ = '\r'; for (d = descriptor_list; d; d = d->next) { if (d->lookup_status != STATUS_DONE) continue; if (d->connected != CON_PLAYING ) continue; write_to_buffer( d, buf, ptr - buf ); } return; } void update_mudinfo() { DESCRIPTOR_DATA *d; int i, pcount = 0; /* * Each week, the data is stored to a file, and * the variable cleared. */ if (mudinfo[MUDINFO_UPDATED] > 20160) { write_mudinfo_database(); for (i = 0; i < (MUDINFO_MAX - 2); i++) { mudinfo[i] = 0; } log_string("Mudinfo database updated."); } /* * Increase update count */ mudinfo[MUDINFO_UPDATED]++; /* * Outdate the output data */ if (total_output > mudinfo[MUDINFO_DATA_PEAK]) mudinfo[MUDINFO_DATA_PEAK] = total_output; /* * The stored data */ if (mudinfo[MUDINFO_BYTE] > 1048576) // 1 megabyte { mudinfo[MUDINFO_MBYTE]++; mudinfo[MUDINFO_BYTE] -= 1048576; } mudinfo[MUDINFO_BYTE] += total_output; /* * The temp data */ if (mudinfo[MUDINFO_BYTE_S] > 1048576) // 1 megabyte { mudinfo[MUDINFO_MBYTE_S]++; mudinfo[MUDINFO_BYTE_S] -= 1048576; } mudinfo[MUDINFO_BYTE_S] += total_output; /* * We clear the counter */ total_output = 0; for (d = descriptor_list; d; d = d->next) { if (d->connected == CON_PLAYING && d->lookup_status == STATUS_DONE) { if (d->character) { if (d->character->level < 13) { pcount++; if (d->out_compress) mudinfo[MUDINFO_MCCP_USERS]++; else mudinfo[MUDINFO_OTHER_USERS]++; if (IS_SET (d->character->act, PLR_SOUND)) mudinfo[MUDINFO_MSP_USERS]++; } } } } if (pcount > mudinfo[MUDINFO_PEAK_USERS]) mudinfo[MUDINFO_PEAK_USERS] = pcount; save_mudinfo(); } void tie_message(CHAR_DATA *ch, CHAR_DATA *victim) { static char * const he_she [] = { "XX", "he", "she" }; static char * const him_her [] = { "XX", "him", "her" }; static char * const his_her [] = { "XX", "his", "her" }; DESCRIPTOR_DATA *d; char buf[400]; // that should be plenty. const char *dmess; const char *i; char *ptr2; char *ptr; int size; size = strlen2(ch->pcdata->tiemessage); if (size > 380) { bug("Bad tiemessage.",0); return; } ptr2 = "#C<- #RTie #C->#n "; ptr = buf; dmess = ch->pcdata->tiemessage; while ((*ptr = *ptr2) != '\0') ++ptr, ++ptr2; while (*dmess != '\0') { if ( *dmess != '$' ) { *ptr++ = *dmess++; continue; } ++dmess; switch (*dmess) { default: i = ""; break; case 'n': i = ch->name; break; case 'e': i = he_she [URANGE(1, ch->sex, 2)]; break; case 'm': i = him_her [URANGE(1, ch->sex, 2)]; break; case 's': i = his_her [URANGE(1, ch->sex, 2)]; break; case 'N': i = victim->name; break; case 'S': i = his_her [URANGE(1, victim->sex, 2)]; break; case 'M': i = him_her [URANGE(1, victim->sex, 2)]; break; case 'E': i = he_she [URANGE(1, victim->sex, 2)]; break; } ++dmess; /* copying the data into the pointer */ while ((*ptr = *i) != '\0') ++ptr, ++i; } *ptr++ = '\n'; *ptr++ = '\r'; for (d = descriptor_list; d; d = d->next) { if (d->lookup_status != STATUS_DONE) continue; if (d->connected != CON_PLAYING ) continue; write_to_buffer( d, buf, ptr - buf ); } return; } void login_message(CHAR_DATA *ch) { static char * const he_she [] = { "XX", "he", "she" }; static char * const him_her [] = { "XX", "him", "her" }; static char * const his_her [] = { "XX", "his", "her" }; DESCRIPTOR_DATA *d; char buf[400]; // that should be plenty. const char *dmess; const char *i; char *ptr2; char *ptr; int size; size = strlen2(ch->pcdata->loginmessage); if (size > 380) { bug("Bad loginmessage.",0); return; } ptr2 = "#C<- #REnters #C->#n "; ptr = buf; dmess = ch->pcdata->loginmessage; while ((*ptr = *ptr2) != '\0') ++ptr, ++ptr2; while (*dmess != '\0') { if ( *dmess != '$' ) { *ptr++ = *dmess++; continue; } ++dmess; switch (*dmess) { default: i = ""; break; case 'n': i = ch->name; break; case 'e': i = he_she [URANGE(1, ch->sex, 2)]; break; case 'm': i = him_her [URANGE(1, ch->sex, 2)]; break; case 's': i = his_her [URANGE(1, ch->sex, 2)]; break; } ++dmess; /* copying the data into the pointer */ while ((*ptr = *i) != '\0') ++ptr, ++i; } *ptr++ = '\n'; *ptr++ = '\r'; for (d = descriptor_list; d; d = d->next) { if (d->lookup_status != STATUS_DONE) continue; if (d->connected != CON_PLAYING ) continue; write_to_buffer( d, buf, ptr - buf ); } return; } void special_decap_message(CHAR_DATA *ch, CHAR_DATA *victim) { static char * const he_she [] = { "XX", "he", "she" }; static char * const him_her [] = { "XX", "him", "her" }; static char * const his_her [] = { "XX", "his", "her" }; DESCRIPTOR_DATA *d; char buf[400]; // that should be plenty. const char *dmess; const char *i; char *ptr2; char *ptr; int size; size = strlen2(ch->pcdata->decapmessage); if (size > 380) { bug("Bad decapmessage.",0); return; } ptr2 = "#C<- #RDeath #C->#n "; ptr = buf; dmess = ch->pcdata->decapmessage; while ((*ptr = *ptr2) != '\0') ++ptr, ++ptr2; while (*dmess != '\0') { if ( *dmess != '$' ) { *ptr++ = *dmess++; continue; } ++dmess; switch (*dmess) { default: i = ""; break; case 'n': i = ch->name; break; case 'e': i = he_she [URANGE(1, ch->sex, 2)]; break; case 'm': i = him_her [URANGE(1, ch->sex, 2)]; break; case 's': i = his_her [URANGE(1, ch->sex, 2)]; break; case 'N': i = victim->name; break; case 'S': i = his_her [URANGE(1, victim->sex, 2)]; break; case 'M': i = him_her [URANGE(1, victim->sex, 2)]; break; case 'E': i = he_she [URANGE(1, victim->sex, 2)]; break; } ++dmess; /* copying the data into the pointer */ while ((*ptr = *i) != '\0') ++ptr, ++i; } *ptr++ = '\n'; *ptr++ = '\r'; for (d = descriptor_list; d; d = d->next) { if (d->lookup_status != STATUS_DONE) continue; if (d->connected != CON_PLAYING ) continue; write_to_buffer( d, buf, ptr - buf ); } return; } void avatar_message(CHAR_DATA *ch) { static char * const he_she [] = { "XX", "he", "she" }; static char * const him_her [] = { "XX", "him", "her" }; static char * const his_her [] = { "XX", "his", "her" }; DESCRIPTOR_DATA *d; char buf[400]; // that should be plenty. const char *dmess; const char *i; char *ptr2; char *ptr; int size; size = strlen2(ch->pcdata->avatarmessage); if (size > 380) { bug("Bad avatarmessage.",0); return; } ptr2 = "#C<- #RAvatar #C->#n "; ptr = buf; dmess = ch->pcdata->avatarmessage; while ((*ptr = *ptr2) != '\0') ++ptr, ++ptr2; while (*dmess != '\0') { if ( *dmess != '$' ) { *ptr++ = *dmess++; continue; } ++dmess; switch (*dmess) { default: i = ""; break; case 'n': i = ch->name; break; case 'e': i = he_she [URANGE(0, ch->sex, 1)]; break; case 'm': i = him_her [URANGE(0, ch->sex, 1)]; break; case 's': i = his_her [URANGE(0, ch->sex, 1)]; break; } ++dmess; /* copying the data into the pointer */ while ((*ptr = *i) != '\0') ++ptr, ++i; } *ptr++ = '\n'; *ptr++ = '\r'; for (d = descriptor_list; d; d = d->next) { if (d->lookup_status != STATUS_DONE) continue; if (d->connected != CON_PLAYING ) continue; write_to_buffer( d, buf, ptr - buf ); } return; } char *strip_ansi(char *str) { static char buf[MAX_STRING_LENGTH]; char *ptr; buf[0] = '\0'; ptr = buf; while (*str != '\0') { if (*str != '#') *ptr++ = *str++; else if (*(++str) != '\0') str++; } *ptr = '\0'; return buf; } char *line_indent(char *text, int wBegin, int wMax) { static char buf[MAX_STRING_LENGTH]; char *ptr; char *ptr2; int count = 0; bool stop = FALSE; int wEnd = 0; buf[0] = '\0'; ptr = text; ptr2 = buf; while (!stop) { if (count == 0) { if (*ptr == '\0') wEnd = wMax - wBegin; else if (strlen(ptr) < (wMax - wBegin)) wEnd = wMax - wBegin; else { int x = 0; while (*(ptr + (wMax - wBegin - x)) != ' ') x++; wEnd = wMax - wBegin - (x - 1); if (wEnd < 1) wEnd = wMax - wBegin; } } if (count == 0 && *ptr == ' ') ptr++; else if (++count != wEnd) { if ((*ptr2++ = *ptr++) == '\0') stop = TRUE; } else if (*ptr == '\0') { stop = TRUE; *ptr2 = '\0'; } else { int k; count = 0; *ptr2++ = '\n'; *ptr2++ = '\r'; for (k = 0; k < wBegin; k++) *ptr2++ = ' '; } } return buf; } char *get_exits(CHAR_DATA *ch) { extern char *const dir_name[]; static char buf[MAX_STRING_LENGTH]; EXIT_DATA *pexit; bool found; int door; buf[0] = '\0'; if (!check_blind(ch)) return ""; sprintf(buf, "#c-#C=#r[#CExits#c:#C"); found = FALSE; for (door = 0; door <= 5; door++) { if ((pexit = ch->in_room->exit[door]) != NULL && pexit->to_room != NULL) { found = TRUE; if (IS_SET(pexit->exit_info, EX_CLOSED)) { strcat(buf, " #0(#C"); strcat(buf, dir_name[door]); strcat(buf, "#0)#C"); } else { strcat(buf, " "); strcat(buf, dir_name[door]); } } } if (!found) strcat(buf, " none"); strcat(buf, "#0]#n\n\r"); return buf; } void recycle_descriptors() { DESCRIPTOR_DATA *dclose; DESCRIPTOR_DATA *dclose_next; for (dclose = descriptor_list; dclose; dclose = dclose_next) { dclose_next = dclose->next; if (dclose->lookup_status != STATUS_CLOSED) continue; /* * First let's get it out of the descriptor list. */ if ( dclose == descriptor_list ) { descriptor_list = descriptor_list->next; } else { DESCRIPTOR_DATA *d; for (d = descriptor_list; d && d->next != dclose; d = d->next) ; if (d != NULL) d->next = dclose->next; else { bug( "Recycle_descriptors: dclose not found.", 0 ); continue; } } /* * Clear out that memory */ free_string( dclose->host ); free_mem( dclose->outbuf, dclose->outsize ); /* * Mccp */ if (dclose->out_compress) { deflateEnd(dclose->out_compress); free_mem(dclose->out_compress_buf, COMPRESS_BUF_SIZE); free_mem(dclose->out_compress, sizeof(z_stream)); } /* * Bye bye mr. Descriptor. */ close( dclose->descriptor ); /* * And then we recycle */ dclose->next = descriptor_free; descriptor_free = dclose; } } void update_ragnarok() { if (ragnarok_safe_timer > 0) ragnarok_safe_timer--; if (--ragnarok_on_timer <= 0 && ragnarok) { ragnarok_stop(); ragnarok_safe_timer = 120; /* 120 minutes of safe after a ragnarok */ } } void update_doubleexp() { if (pulse_doubleexp > 0) { if (--pulse_doubleexp == 0) { global_exp = FALSE; pulse_doubleexp = -1; do_info(NULL,"#GH#Ra#Gp#Rp#Gy #GH#Ro#Gu#Rr #0(#7ENDED#0)#n"); } } } void update_doubleqps() { if (pulse_doubleqp > 0) { if ( --pulse_doubleqp == 0) { global_qp = FALSE; pulse_doubleqp = -1; do_info(NULL,"#GQ#RU#GE#RS#GT#RO#GR#RS #GD#RE#GL#RI#GG#RH#GT #0(#7ENDED#0)#n"); } } } /* void update_doublecps() { if (pulse_doublecp > 0) { if ( --pulse_doublecp == 0) { global_cp = FALSE; pulse_doublecp = -1; do_info(NULL,"#GP#RO#GW#RE#GR #GH#RO#GU#RR#0(#7ENDED#0)#n"); } } } */ void update_maze() { /* char buf[MAX_STRING_LENGTH]; if ((pulse_mazelast > 0) && (mazestart)) { pulse_mazelast--; } if (pulse_mazelast == 0) { close_maze(); pulse_mazelast = -1; } if (mazeopen) { if (--pulse_mazetime <=1) { if (pulse_mazetime == 0) { clear_maze(); } } if (pulse_mazetime != 0 && (pulse_mazetime == 10 || pulse_mazetime == 5 || pulse_mazetime == 1) && (mazeopen)) { sprintf(buf,"Players in the maze have %d more minutes to find the exit.\n\r",pulse_mazetime); do_info(NULL,buf); } } if (--pulse_mazeopen <= 1) { if (pulse_mazeopen > 0) open_maze(); else if (pulse_mazeopen == 0) { pulse_mazeopen = -1; close_maze(); } } */ } void update_arena() { if (--pulse_arena <= 1) { if (pulse_arena > 0) open_arena(); else if (pulse_arena == 0) { pulse_arena = -1; close_arena(); } } } void recycle_dummys() { DUMMY_ARG *dummy; DUMMY_ARG *dummy_next; for (dummy = dummy_list; dummy; dummy = dummy_next) { dummy_next = dummy->next; if (dummy->status == 1) continue; // being used if (dummy == dummy_list) { dummy_list = dummy_list->next; } else { DUMMY_ARG *prev; /* we find the prev dummy arg */ for (prev = dummy_list; prev && prev->next != dummy; prev = prev->next) ; if (prev != NULL) prev->next = dummy->next; else { bug( "Recycle_dymmys: dummy not found.", 0 ); continue; } /* recycle */ dummy->next = dummy_free; dummy_free = dummy; } } }