void do_play(CHAR_DATA *ch, char *argument) { OBJ_DATA *juke; char *str,arg[MAX_INPUT_LENGTH]; int song,i; bool global = FALSE; str = one_argument(argument,arg); for (juke = ch->in_room->contents; juke != NULL; juke = juke->next_content) if (juke->item_type == ITEM_JUKEBOX && can_see_obj(ch,juke)) break; if (argument[0] == '\0') { send_to_char("Play what?\n\r",ch); return; } if (juke == NULL) { send_to_char("You see nothing to play.\n\r",ch); return; } if (!str_cmp(arg,"list")) { BUFFER *buffer; char buf[MAX_STRING_LENGTH]; int col = 0; bool artist = FALSE, match = FALSE; buffer = new_buf(); argument = str; argument = one_argument(argument,arg); if (!str_cmp(arg,"artist")) artist = TRUE; if (argument[0] != '\0') match = TRUE; sprintf(buf,"%s has the following songs available:\n\r", juke->short_descr); add_buf(buffer,capitalize(buf)); for (i = 0; i < MAX_SONGS; i++) { if (song_table[i].name == NULL) break; if (artist && (!match || !str_prefix(argument,song_table[i].group))) sprintf(buf,"%-39s %-39s\n\r", song_table[i].group,song_table[i].name); else if (!artist && (!match || !str_prefix(argument,song_table[i].name))) sprintf(buf,"%-35s ",song_table[i].name); else continue; add_buf(buffer,buf); if (!artist && ++col % 2 == 0) add_buf(buffer,"\n\r"); } if (!artist && col % 2 != 0) add_buf(buffer,"\n\r"); page_to_char(buf_string(buffer),ch); free_buf(buffer); return; } if (!str_cmp(arg,"loud")) { argument = str; global = TRUE; } if (argument[0] == '\0') { send_to_char("Play what?\n\r",ch); return; } if ((global && channel_songs[MAX_GLOBAL] > -1) || (!global && juke->value[4] > -1)) { send_to_char("The jukebox is full up right now.\n\r",ch); return; } for (song = 0; song < MAX_SONGS; song++) { if (song_table[song].name == NULL) { send_to_char("That song isn't available.\n\r",ch); return; } if (!str_prefix(argument,song_table[song].name)) break; } if (song >= MAX_SONGS) { send_to_char("That song isn't available.\n\r",ch); return; } send_to_char("Coming right up.\n\r",ch); if (global) { for (i = 1; i <= MAX_GLOBAL; i++) if (channel_songs[i] < 0) { if (i == 1) channel_songs[0] = -1; channel_songs[i] = song; return; } } else { for (i = 1; i < 5; i++) if (juke->value[i] < 0) { if (i == 1) juke->value[0] = -1; juke->value[i] = song; return; } } }
void make_adminlist() { DIR *dp; struct dirent *dentry; char *word; FILE *gfp, *wfp; int ilevel; COUNCIL_DATA *council; ADMINENT *admin, *adminnext; char buf[MAX_STRING_LENGTH]; char arg[MAX_STRING_LENGTH]; char *arg2 = NULL; first_admin = NULL; last_admin = NULL; if ( (dp = opendir( GOD_DIR )) == NULL ) { bug("Error opening the god directory", 0 ); return; } ilevel = 0; dentry = readdir( dp ); while( dentry ) { if ( dentry->d_name[0] != '.' ) { sprintf (buf, "%s%s", GOD_DIR, dentry->d_name); gfp = fopen (buf, "r" ); if (gfp) { word = feof( gfp ) ? "End" : fread_word( gfp ); ilevel = fread_number( gfp ); fread_to_eol( gfp ); word = feof( gfp ) ? "End" : fread_word( gfp ); add_to_adminlist( dentry->d_name, ilevel ); fclose(gfp); } } dentry = readdir( dp ); } closedir( dp ); unlink( ADMINLIST_FILE ); if ( (wfp = fopen( ADMINLIST_FILE, "a" )) == NULL ) { bug("Error opening the Adminlist file", 0 ); return; } sprintf(buf, "%s Administrative Council List", sysdata.mud_name); toadminfile(buf, wfp); toadminfile(" ", wfp); for ( admin = first_admin; admin; admin = admin->next ) { sprintf (buf, "%s%c/%s", PLAYER_DIR, tolower(admin->name[0]), admin->name); gfp = fopen (buf, "r" ); if (gfp) { arg2 = NULL; do { fgets( buf, MAX_STRING_LENGTH, gfp); arg2 = one_argument(buf, arg); }while ( str_cmp(arg,"Council") && !feof(gfp)); } if (!str_cmp(arg, "Council") ) { remove_tilde(arg2); admin->council = str_dup (arg2); } fclose( gfp ); } sort_adminlist(); for (council = first_council; council; council = council->next) { sprintf( buf, "%s", council->name); sprintf( arg, "%c", ' ' ); toadminfile(buf, wfp); for ( admin = first_admin; admin; admin = admin->next ) { if(!str_cmp(admin->council, council->name) ) { if ( !str_cmp( admin->name, council->head) || ( council->head2 && !str_cmp( admin->name, council->head2) ) ) sprintf(buf, "*%s* ", admin->name); else sprintf(buf, "%s ", admin->name); if ((strlen (arg) + strlen (buf)) > 76 ) { toadminfile(arg, wfp); sprintf( arg, "%c", ' '); } strcat(arg, buf); } } toadminfile (arg, wfp); toadminfile (" ", wfp); } for ( admin = first_admin; admin; admin = adminnext ) { adminnext = admin->next; DISPOSE(admin->name); DISPOSE(admin); } fclose( wfp ); return; }
char *display_clan_ranks (CHAR_DATA *ch, CHAR_DATA *observer) { CLAN_DATA *clan = NULL; static char buf [MAX_STRING_LENGTH] = { '\0' }; char *argument = NULL, *argument2 = NULL; char ranks_list [MAX_STRING_LENGTH] = { '\0' }; char clan_name [MAX_STRING_LENGTH] = { '\0' }; char clan_name2 [MAX_STRING_LENGTH] = { '\0' }; char name [MAX_STRING_LENGTH] = { '\0' }; int flags = 0, flags2 = 0, clans = 0; bool first = TRUE; char *temp_arg = NULL; argument = observer->clans; *ranks_list = '\0'; snprintf (buf, MAX_STRING_LENGTH, "You recognize that %s carries the rank of", HSSH(ch)); while ( get_next_clan (&argument, clan_name, &flags) ) { argument2 = ch->clans; while ( get_next_clan (&argument2, clan_name2, &flags2) ) { if ( !str_cmp (clan_name, "osgi_citizens") || !str_cmp (clan_name, "mm_denizens") ) continue; clan = get_clandef (clan_name); if ( !clan ) continue; if ( !str_cmp (clan_name, clan_name2) ) { if ( *ranks_list ) { strcat (buf, ranks_list); if ( !first ) strcat (buf, ","); *ranks_list = '\0'; } snprintf (name, MAX_STRING_LENGTH, "%s", clan->literal); if ( !cmp_strn (clan->literal, "The ", 4) ) *name = tolower(*name); if ( cmp_strn (clan->literal, "the ", 4) ){ temp_arg = get_clan_rank_name (flags2); snprintf (name, MAX_STRING_LENGTH, "the %s", clan->literal); snprintf (ranks_list + strlen(ranks_list), MAX_STRING_LENGTH, " %s in %s", temp_arg, name); } first = FALSE; clans++; } } } if ( *ranks_list ) { if ( clans > 1 ) strcat (buf, " and"); strcat (buf, ranks_list); } strcat (buf, "."); if (clan) free(clan); /* clan = get_clandef (clan_name); */ if ( clans ) return buf; else return NULL; }
static int parse_attribute_candidate(struct sdp_attribute *output) { PARSE_DECL; char *ep; struct attribute_candidate *c; output->attr = ATTR_CANDIDATE; c = &output->u.candidate; PARSE_INIT; EXTRACT_TOKEN(u.candidate.cand_parsed.foundation); EXTRACT_TOKEN(u.candidate.component_str); EXTRACT_TOKEN(u.candidate.transport_str); EXTRACT_TOKEN(u.candidate.priority_str); EXTRACT_TOKEN(u.candidate.address_str); EXTRACT_TOKEN(u.candidate.port_str); EXTRACT_TOKEN(u.candidate.typ_str); EXTRACT_TOKEN(u.candidate.type_str); c->cand_parsed.component_id = strtoul(c->component_str.s, &ep, 10); if (ep == c->component_str.s) return -1; c->cand_parsed.transport = ice_transport(&c->transport_str); if (!c->cand_parsed.transport) return 0; c->cand_parsed.priority = strtoul(c->priority_str.s, &ep, 10); if (ep == c->priority_str.s) return -1; if (__parse_address(&c->cand_parsed.endpoint.ip46, NULL, NULL, &c->address_str)) return 0; c->cand_parsed.endpoint.port = strtoul(c->port_str.s, &ep, 10); if (ep == c->port_str.s) return -1; if (str_cmp(&c->typ_str, "typ")) return -1; c->cand_parsed.type = ice_candidate_type(&c->type_str); if (!c->cand_parsed.type) return 0; if (!ice_has_related(c->cand_parsed.type)) goto done; EXTRACT_TOKEN(u.candidate.raddr_str); EXTRACT_TOKEN(u.candidate.related_address_str); EXTRACT_TOKEN(u.candidate.rport_str); EXTRACT_TOKEN(u.candidate.related_port_str); if (str_cmp(&c->raddr_str, "raddr")) return -1; if (str_cmp(&c->rport_str, "rport")) return -1; if (__parse_address(&c->cand_parsed.related_address, NULL, NULL, &c->related_address_str)) return 0; c->cand_parsed.related_port = strtoul(c->related_port_str.s, &ep, 10); if (ep == c->related_port_str.s) return -1; done: c->parsed = 1; return 0; }
// --------------------------------------------------------------------- // Driver for Unpacking // // In a nutshell, unpacking consists of the following major steps: // // 1. fix the endianness of the version header (members of this class) // 2. fix up the virtual table function pointer for the object // 3. migrate an object of a previous version to the current version // 4. fix the endianness of all other members in the subclasses // 5. convert pointers in this object from offsets back to addresses // 5. initiate unpacking for other objects referenced by this object // 6. initialize new members added in the new version // // Parameters: // base is the base address (added to offset to get pointer) // vtblPtr (first form) is the pointer to the virtual function table // of the class // ptrToAnchorClass (second form, see below) is a pointer to an object // that has the desired virtual function pointer // --------------------------------------------------------------------- NA_EIDPROC NAVersionedObject *NAVersionedObject::driveUnpack( void *base, char *vtblPtr, void * reallocator) { // ----------------------------------------------------------------- // Make sure we are really dealing with a NAVersionedObject by // examining its eyeCatcher_. // ----------------------------------------------------------------- if (str_cmp(eyeCatcher_,VOBJ_EYE_CATCHER,VOBJ_EYE_CATCHER_SIZE)) return NULL; // ----------------------------------------------------------------- // If object has already been unpacked, just return either its own // address or the reallocated address if the object was reallocated // to somewhere else. // ----------------------------------------------------------------- if (!isPacked()) { if (reallocatedAddress_.isNull()) return this; else return reallocatedAddress_.getPointer(); } #ifdef NA_64BIT // dg64 - the 32-bit module files have junk in them, so let's try zero // at least in the high-order 32-bits else reallocatedAddress_ = (NAVersionedObjectPtr) NULL ; #endif // ----------------------------------------------------------------- // Fix the Version Header to the endianness of the local platform // if necessary. Correct classID_ field is necessary to determine // the right subclass the object belongs. // // *** DON'T DO THIS JUST YET: PLAN IS TO SUPPORT THIS ONLY FROM // *** SECOND RELEASE. // ----------------------------------------------------------------- #ifndef NA_LITTLE_ENDIAN // toggleEndiannessOfVersionHeader(); #endif // ----------------------------------------------------------------- // The method findVTblPtr() was called on an object of the Anthor // Class T to find out what subclass of the Anchor Class this object // belongs based on its classID_. Now, the virtual function table // pointer is used to fix up this object. // ----------------------------------------------------------------- if (vtblPtr == NULL) return NULL; // unknown class ID // else setVTblPtr(vtblPtr); // ----------------------------------------------------------------- // Call the virtual method migrateToNewVersion() so that older // objects can be migrated to fit in the new class template. // ----------------------------------------------------------------- NAVersionedObject *objPtr = NULL; // ----------------------------------------------------------------- // migrateToNewVersion() should either set objPtr to this or to an // reallocated image. // ----------------------------------------------------------------- if (migrateToNewVersion(objPtr)) return NULL; // version not supported // // ----------------------------------------------------------------- // Convert members of this object from reference platform to local // platform. // // *** DON'T DO THIS JUST YET: PLAN IS TO SUPPORT THIS ONLY FROM // *** SECOND RELEASE. // ----------------------------------------------------------------- // objPtr->convertToLocalPlatform(); // ----------------------------------------------------------------- // Mark object as not packed, despite it is not completely unpacked // yet. This is needed because the call that follows to the virtual // method unpack() drives the unpacking of all objects referenced by // this object. If this object is subsequently referenced by another // object down the row, driveUnpack() will be called on this object // again. At that point of time, we should see the packed flag set // to "not packed" so that "double-unpacking" can be avoided. // ----------------------------------------------------------------- markAsNotPacked(); objPtr->markAsNotPacked(); // ----------------------------------------------------------------- // After migration, the object might have been reallocated. In that // case objPtr will be changed to point to the reallocated object. // The following calls are then made on the reallocated object // instead of this. // ----------------------------------------------------------------- if(objPtr->unpack(base, reallocator)) return NULL; // Should this ever happen? Internal Error. objPtr->initNewMembers(); return objPtr; }
void note_remove( CHAR_DATA *ch, NOTE_DATA *pnote ) { FILE *fp; NOTE_DATA *prev; char *to_list; char to_new [ MAX_INPUT_LENGTH ]; char to_one [ MAX_INPUT_LENGTH ]; /* * Build a new to_list. * Strip out this recipient. */ to_new[0] = '\0'; to_list = pnote->to_list; while ( *to_list != '\0' ) { to_list = one_argument( to_list, to_one ); if ( to_one[0] != '\0' && str_cmp( ch->name, to_one ) ) { strcat( to_new, " " ); strcat( to_new, to_one ); } } /* * Just a simple recipient removal? */ if ( str_cmp( ch->name, pnote->sender ) && to_new[0] != '\0' ) { free_string( pnote->to_list ); pnote->to_list = str_dup( to_new + 1 ); return; } /* * Remove note from linked list. */ if ( pnote == note_list ) { note_list = pnote->next; } else { for ( prev = note_list; prev; prev = prev->next ) { if ( prev->next == pnote ) break; } if ( !prev ) { bug( "Note_remove: pnote not found.", 0 ); return; } prev->next = pnote->next; } free_string( pnote->text ); free_string( pnote->subject ); free_string( pnote->to_list ); free_string( pnote->date ); free_string( pnote->sender ); pnote->next = note_free; note_free = pnote; /* * Rewrite entire list. */ fclose( fpReserve ); if ( !( fp = fopen( NOTE_FILE, "w" ) ) ) { perror( NOTE_FILE ); } else { for ( pnote = note_list; pnote; pnote = pnote->next ) { fprintf( fp, "Sender %s~\n", pnote->sender ); fprintf( fp, "Date %s~\n", pnote->date ); fprintf( fp, "Stamp %ld\n", (unsigned long)pnote->date_stamp ); fprintf( fp, "To %s~\n", pnote->to_list ); fprintf( fp, "Subject %s~\n", pnote->subject ); fprintf( fp, "Text\n%s~\n\n", pnote->text ); } fclose( fp ); } fpReserve = fopen( NULL_FILE, "r" ); return; }
void do_finger( CHAR_DATA *ch, char *argument ) { char arg[MAX_INPUT_LENGTH]; char buf[MAX_STRING_LENGTH]; CHAR_DATA *victim; FILE *fp; bool fOld; one_argument( argument, arg ); if ( arg[0] == '\0' ) { send_to_char( "Finger whom?\n\r", ch ); return; } if ( ( victim = get_char_world( ch, arg ) ) != NULL) { if (!IS_NPC(victim)) { act( "$N is on right now!", ch, NULL, victim, TO_CHAR ); return; } } victim = new_char(); victim->pcdata = new_pcdata(); fOld = FALSE; sprintf( buf, "%s%s", PLAYER_DIR, capitalize( arg ) ); if ( ( fp = fopen( buf, "r" ) ) != NULL ) { int iNest; for ( iNest = 0; iNest < MAX_NEST; iNest++ ) rgObjNest[iNest] = NULL; fOld = TRUE; for ( ; ; ) { char letter; char *word; letter = fread_letter( fp ); if ( letter == '*' ) { fread_to_eol( fp ); continue; } if ( letter != '#' ) { bug( "Load_char_obj: # not found.", 0 ); break; } word = fread_word( fp ); if ( !str_cmp( word, "PLAYER" ) ) fread_char( victim, fp ); else if ( !str_cmp( word, "OBJECT" ) ) break; else if ( !str_cmp( word, "O" ) ) break; else if ( !str_cmp( word, "PET" ) ) break; else if ( !str_cmp( word, "END" ) ) break; else { bug( "Load_char_obj: bad section.", 0 ); break; } } fclose( fp ); } if ( !fOld ) { send_to_char("No player by that name exists.\n\r",ch); free_pcdata(victim->pcdata); free_char(victim); return; } if ( (victim->level > LEVEL_HERO) && (victim->level > ch->level) ) { send_to_char("The gods wouldn't like that.\n\r",ch); free_pcdata(victim->pcdata); free_char(victim); return; } sprintf(buf,"%s last logged off on %s", victim->name, (char *) ctime(&victim->llogoff)); send_to_char(buf,ch); free_pcdata(victim->pcdata); free_char(victim); return; }
static bool list_apply_handler(struct le *le, void *arg) { struct vidisp_st *st = le->data; return 0 == str_cmp(st->device, arg); }
int skill_ethereal_snake( int sn, int level, CHAR_DATA *ch, void *vo ) { AFFECT_DATA af; CHAR_DATA *victim; /* if ( !IS_NPC( ch ) && ( ( ch->level < skill_table[sn].skill_level[ch->class] ) && (ch->level < skill_table[sn].skill_level[ch->multied]))) { send_to_char(C_DEFAULT, "You can not perform that skill.\n\r", ch ); return SKPELL_MISSED; } */ // modified check so if NPCs have spell on already // they can use bite/devour/etc - Ahsile if ( IS_NPC(ch) || number_percent( ) > ( ch->pcdata->learned[sn] / 10 ) ) { if (IS_NPC(ch)) { if (!IS_AFFECTED4(ch, AFF_ETHEREAL_SNAKE)) { send_to_char( C_DEFAULT, "You failed.\n\r", ch ); return SKPELL_MISSED; } } else { send_to_char( C_DEFAULT, "You failed.\n\r", ch ); return SKPELL_MISSED; } } if ( !ch->fighting ) { if ( IS_AFFECTED4( ch, AFF_ETHEREAL_SNAKE ) ) { send_to_char( AT_DGREY, "You replace your ethereal snake with a new one.\n\r", ch ); return SKPELL_NO_DAMAGE; } /* TO DO: Mana costs */ af.type = sn; af.level = ch->level; af.duration = ch->level; af.location = APPLY_NONE; af.modifier = 0; af.bitvector = AFF_ETHEREAL_SNAKE; affect_to_char4(ch, &af); act( AT_DGREY, "$n summons an ethereal snake!", ch, NULL, NULL, TO_ROOM ); send_to_char( AT_DGREY, "You have summoned an ethereal snake to assist you.\n\r", ch ); WAIT_STATE( ch, skill_table[sn].beats ); return SKPELL_NO_DAMAGE; } /* Snake commands will go here */ victim = ch->fighting; if (target_name[0] == '\0') { send_to_char( AT_DGREY, "You get the attention of your snake.\n\r", ch ); act( AT_DGREY, "$n gets the attention of $m snake.", ch, NULL, NULL, TO_ROOM ); return SKPELL_NO_DAMAGE; } if ( !str_cmp( target_name, "bite" ) ) { send_to_char( AT_DGREY, "You order your snake to bite!\n\r", ch ); act( AT_DGREY, "$n orders $m ethereal snake to bite!", ch, NULL, NULL, TO_ROOM ); WAIT_STATE( ch, skill_table[skill_lookup("ethereal snake bite")].beats ); return spell_ethereal_snake_bite ( skill_lookup("ethereal snake bite"), ch->level, ch, victim ); } if ( !str_cmp( target_name, "strike" ) ) { send_to_char( AT_DGREY, "You order your snake to strike!\n\r", ch ); act( AT_DGREY, "$n orders $m ethereal snake to strike!", ch, NULL, NULL, TO_ROOM ); WAIT_STATE( ch, skill_table[skill_lookup("ethereal snake strike")].beats ); return spell_ethereal_snake_strike ( skill_lookup("ethereal snake strike"), ch->level, ch, victim ); } if ( !str_cmp( target_name, "devour" ) ) { send_to_char( AT_DGREY, "You order your snake to devour!\n\r", ch ); act( AT_DGREY, "$n orders $m ethereal snake to devour its target whole!", ch, NULL, NULL, TO_ROOM ); WAIT_STATE( ch, skill_table[skill_lookup("ethereal snake devour")].beats); return spell_ethereal_snake_devour ( skill_lookup("ethereal snake devour"), ch->level, ch, victim ); } send_to_char ( AT_DGREY, "You may only order your snake to BITE, STRIKE or DEVOUR.\n\r", ch ); return SKPELL_BOTCHED; }
void do_buy( CHAR_DATA *ch, char *argument ) { char arg[MAX_INPUT_LENGTH]; int maxgold; bool debit; OBJ_DATA *obj; argument = one_argument( argument, arg ); if ( arg[0] == '\0' ) { send_to_char( "Buy what?\n\r", ch ); return; } if ( IS_SET(ch->in_room->room_flags, ROOM_PET_SHOP) ) { char buf[MAX_STRING_LENGTH]; CHAR_DATA *pet; ROOM_INDEX_DATA *pRoomIndexNext; ROOM_INDEX_DATA *in_room; if ( argument[0] == '\0' ) debit = FALSE; else if ( !str_cmp( "atm", argument ) || !str_cmp( "debit", argument ) ) { bool has_card = FALSE; for ( obj = ch->last_carrying; obj; obj = obj->prev_content ) { if ( obj->item_type == ITEM_DEBIT_CARD ) has_card = TRUE; } if ( has_card == TRUE ) debit = TRUE; else { send_to_char( "You don't even have your card with you!\n\r", ch ); return; } } if ( IS_NPC(ch) ) return; pRoomIndexNext = get_room_index( ch->in_room->vnum + 1 ); if ( !pRoomIndexNext ) { bug( "Do_buy: bad pet shop at vnum %d.", ch->in_room->vnum ); send_to_char( "Sorry, you can't buy that here.\n\r", ch ); return; } in_room = ch->in_room; ch->in_room = pRoomIndexNext; pet = get_char_room( ch, arg ); ch->in_room = in_room; if ( pet == NULL || !IS_NPC( pet ) || !IS_SET(pet->act, ACT_PET) ) { send_to_char( "Sorry, you can't buy that here.\n\r", ch ); return; } if (( ch->gold < 10 * pet->top_level * pet->top_level ) && debit == FALSE) { send_to_char( "You can't afford it.\n\r", ch ); return; } else if ( (ch->pcdata->bank < 10 * pet->top_level * pet->top_level) && debit == TRUE ) { send_to_char( "You dont have enough money in your bank account for it.\n\r", ch ); return; } maxgold = 10 * pet->top_level * pet->top_level; if ( debit == FALSE ) ch->gold -= maxgold; /* this was already here, btw */ else ch->pcdata->bank -= maxgold; boost_economy( ch->in_room->area, maxgold ); pet = create_mobile( pet->pIndexData ); SET_BIT(pet->act, ACT_PET); SET_BIT(pet->affected_by, AFF_CHARM); argument = one_argument( argument, arg ); if ( arg[0] != '\0' ) { sprintf( buf, "%s %s", pet->name, arg ); STRFREE( pet->name ); pet->name = STRALLOC( buf ); } sprintf( buf, "%sA neck tag says 'I belong to %s'.\n\r", pet->description, ch->name ); STRFREE( pet->description ); pet->description = STRALLOC( buf ); char_to_room( pet, ch->in_room ); add_follower( pet, ch ); send_to_char( "Enjoy your pet.\n\r", ch ); act( AT_ACTION, "$n bought $N as a pet.", ch, NULL, pet, TO_ROOM ); return; } else { CHAR_DATA *keeper; int cost; int noi = 1; /* Number of items */ sh_int mnoi = 20; /* Max number of items to be bought at once */ if ( ( keeper = find_keeper( ch ) ) == NULL ) return; maxgold = keeper->top_level * 10; if ( is_number( arg ) ) { noi = atoi( arg ); argument = one_argument( argument, arg ); if ( noi > mnoi ) { act( AT_TELL, "$n tells you 'I don't sell that many items at" " once.'", keeper, NULL, ch, TO_VICT ); ch->reply = keeper; return; } } if ( argument[0] == '\0' ) debit = FALSE; else if ( !str_cmp( "atm", argument ) || !str_cmp( "debit", argument ) ) { bool has_card = FALSE; for ( obj = ch->last_carrying; obj; obj = obj->prev_content ) { if ( obj->item_type == ITEM_DEBIT_CARD ) has_card = TRUE; } if ( has_card == TRUE ) debit = TRUE; else { send_to_char( "You don't even have your card with you!\n\r", ch ); return; } } obj = get_obj_carry( keeper, arg ); if ( !obj && arg[0] == '#' ) { int onum, oref; bool ofound = FALSE; onum =0; oref = atoi(arg+1); for ( obj = keeper->last_carrying; obj; obj = obj->prev_content ) { if ( obj->wear_loc == WEAR_NONE && can_see_obj( ch, obj ) ) onum++; if ( onum == oref ) { ofound = TRUE; break; } else if ( onum > oref ) break; } if (!ofound) obj = NULL; } if (keeper->home != NULL && obj->cost > 0) cost= obj->cost; cost = ( get_cost( ch, keeper, obj, TRUE ) * noi ); if( !IS_NPC(ch) && ch->pcdata->learned[gsn_bargain] > 0 && ch->pcdata->learned[gsn_bargain] > number_percent()) { ch_printf(ch,"You are able to bargain from %d credits to %d credits!\n\r", cost, (cost/3)+(cost/2)); cost = (cost/3) + (cost/2); if(number_percent() > 50) learn_from_success(ch, gsn_bargain); } if ( cost <= 0 || !can_see_obj( ch, obj ) ) { act( AT_TELL, "$n tells you 'I don't sell that -- try 'list'.'", keeper, NULL, ch, TO_VICT ); ch->reply = keeper; return; } if ( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) && ( noi > 1 ) ) { interpret( keeper, "laugh" ); act( AT_TELL, "$n tells you 'I don't have enough of those in stock" " to sell more than one at a time.'", keeper, NULL, ch, TO_VICT ); ch->reply = keeper; return; } if ( ch->gold < cost && debit == FALSE) { act( AT_TELL, "$n tells you 'You can't afford to buy $p.'", keeper, obj, ch, TO_VICT ); ch->reply = keeper; return; } if ( ch->pcdata->bank < cost && debit == TRUE) { send_to_char( "You are almost slide your card through, but you remember you don't have enough money!\n\r", ch ); return; } if ( IS_SET(obj->extra_flags, ITEM_PROTOTYPE) && get_trust( ch ) < LEVEL_IMMORTAL ) { act( AT_TELL, "$n tells you 'This is a only a prototype! I can't sell you that...'", keeper, NULL, ch, TO_VICT ); ch->reply = keeper; return; } if ( ch->carry_number + get_obj_number( obj ) > can_carry_n( ch ) ) { send_to_char( "You can't carry that many items.\n\r", ch ); return; } if ( ch->carry_weight + ( get_obj_weight( obj ) * noi ) + (noi > 1 ? 2 : 0) > can_carry_w( ch ) ) { send_to_char( "You can't carry that much weight.\n\r", ch ); return; } if ( noi == 1 ) { if ( !IS_OBJ_STAT( obj, ITEM_INVENTORY ) ) separate_obj( obj ); act( AT_ACTION, "$n buys $p.", ch, obj, NULL, TO_ROOM ); act( AT_ACTION, "You buy $p.", ch, obj, NULL, TO_CHAR ); } else { sprintf( arg, "$n buys %d $p%s.", noi, ( obj->short_descr[strlen(obj->short_descr)-1] == 's' ? "" : "s" ) ); act( AT_ACTION, arg, ch, obj, NULL, TO_ROOM ); sprintf( arg, "You buy %d $p%s.", noi, ( obj->short_descr[strlen(obj->short_descr)-1] == 's' ? "" : "s" ) ); act( AT_ACTION, arg, ch, obj, NULL, TO_CHAR ); act( AT_ACTION, "$N puts them into a bag and hands it to you.", ch, NULL, keeper, TO_CHAR ); } if ( debit == FALSE ) ch->gold -= cost; /* this line was already here, btw */ else if ( debit == TRUE ) ch->pcdata->bank -= cost; keeper->gold += cost; if ( keeper->gold > maxgold ) { boost_economy( keeper->in_room->area, keeper->gold - maxgold/2 ); keeper->gold = maxgold/2; act( AT_ACTION, "$n puts some credits into a large safe.", keeper, NULL, NULL, TO_ROOM ); } if ( IS_OBJ_STAT( obj, ITEM_INVENTORY ) ) { OBJ_DATA *buy_obj, *bag; buy_obj = create_object( obj->pIndexData, obj->level ); /* * Due to grouped objects and carry limitations in SMAUG * The shopkeeper gives you a bag with multiple-buy, * and also, only one object needs be created with a count * set to the number bought. -Thoric */ if ( noi > 1 ) { bag = create_object( get_obj_index( OBJ_VNUM_SHOPPING_BAG ), 1 ); /* perfect size bag ;) */ bag->value[0] = bag->weight + (buy_obj->weight * noi); buy_obj->count = noi; obj->pIndexData->count += (noi - 1); numobjsloaded += (noi - 1); obj_to_obj( buy_obj, bag ); obj_to_char( bag, ch ); } else obj_to_char( buy_obj, ch ); } else { obj_from_char( obj ); obj_to_char( obj, ch ); } return; } }
void quest_stat(struct char_data *ch, char argument[MAX_STRING_LENGTH]) { qst_rnum rnum; mob_rnum qmrnum; char buf[MAX_STRING_LENGTH]; char targetname[MAX_STRING_LENGTH]; if (GET_ADMLEVEL(ch) < ADMLVL_IMMORT) send_to_char(ch, "Huh!?!\r\n"); else if (!*argument) send_to_char(ch, "%s\r\n", quest_imm_usage); else if ((rnum = real_quest(atoi(argument))) == NOTHING ) send_to_char(ch, "That quest does not exist.\r\n"); else { sprintbit(QST_FLAGS(rnum), aq_flags, buf, sizeof(buf)); switch (QST_TYPE(rnum)) { case AQ_OBJ_FIND: case AQ_OBJ_RETURN: snprintf(targetname, sizeof(targetname), "%s", real_object(QST_TARGET(rnum)) == NOTHING ? "An unknown object" : obj_proto[real_object(QST_TARGET(rnum))].short_description); break; case AQ_ROOM_FIND: case AQ_ROOM_CLEAR: snprintf(targetname, sizeof(targetname), "%s", real_room(QST_TARGET(rnum)) == NOWHERE ? "An unknown room" : world[real_room(QST_TARGET(rnum))].name); break; case AQ_MOB_FIND: case AQ_MOB_KILL: case AQ_MOB_SAVE: snprintf(targetname, sizeof(targetname), "%s", real_mobile(QST_TARGET(rnum)) == NOBODY ? "An unknown mobile" : GET_NAME(&mob_proto[real_mobile(QST_TARGET(rnum))])); break; default: snprintf(targetname, sizeof(targetname), "Unknown"); break; } qmrnum = real_mobile(QST_MASTER(rnum)); send_to_char(ch, "VNum : [\ty%5d\tn], RNum: [\ty%5d\tn] -- Questmaster: [\ty%5d\tn] \ty%s\tn\r\n" "Name : \ty%s\tn\r\n" "Desc : \ty%s\tn\r\n" "Accept Message:\r\n\tc%s\tn" "Completion Message:\r\n\tc%s\tn" "Quit Message:\r\n\tc%s\tn" "Type : \ty%s\tn\r\n" "Target: \ty%d\tn \ty%s\tn, Quantity: \ty%d\tn\r\n" "Value : \ty%d\tn, Penalty: \ty%d\tn, Min Level: \ty%2d\tn, Max Level: \ty%2d\tn\r\n" "Flags : \tc%s\tn\r\n", QST_NUM(rnum), rnum, QST_MASTER(rnum) == NOBODY ? -1 : QST_MASTER(rnum), (qmrnum == NOBODY) ? "(Invalid vnum)" : GET_NAME(&mob_proto[(qmrnum)]), QST_NAME(rnum), QST_DESC(rnum), QST_INFO(rnum), QST_DONE(rnum), (QST_QUIT(rnum) && (str_cmp(QST_QUIT(rnum), "undefined") != 0) ? QST_QUIT(rnum) : "Nothing\r\n"), quest_types[QST_TYPE(rnum)], QST_TARGET(rnum) == NOBODY ? -1 : QST_TARGET(rnum), targetname, QST_QUANTITY(rnum), QST_POINTS(rnum), QST_PENALTY(rnum), QST_MINLEVEL(rnum), QST_MAXLEVEL(rnum), buf); if (QST_PREREQ(rnum) != NOTHING) send_to_char(ch, "Preq : [\ty%5d\tn] \ty%s\tn\r\n", QST_PREREQ(rnum) == NOTHING ? -1 : QST_PREREQ(rnum), QST_PREREQ(rnum) == NOTHING ? "" : real_object(QST_PREREQ(rnum)) == NOTHING ? "an unknown object" : obj_proto[real_object(QST_PREREQ(rnum))].short_description); if (QST_TYPE(rnum) == AQ_OBJ_RETURN) send_to_char(ch, "Mob : [\ty%5d\tn] \ty%s\tn\r\n", QST_RETURNMOB(rnum), real_mobile(QST_RETURNMOB(rnum)) == NOBODY ? "an unknown mob" : mob_proto[real_mobile(QST_RETURNMOB(rnum))].player.short_descr); if (QST_TIME(rnum) != -1) send_to_char(ch, "Limit : There is a time limit of %d turn%s to complete.\r\n", QST_TIME(rnum), QST_TIME(rnum) == 1 ? "" : "s"); else send_to_char(ch, "Limit : There is no time limit on this quest.\r\n"); send_to_char(ch, "Prior :"); if (QST_PREV(rnum) == NOTHING) send_to_char(ch, " \tyNone.\tn\r\n"); else send_to_char(ch, " [\ty%5d\tn] \tc%s\tn\r\n", QST_PREV(rnum), QST_DESC(real_quest(QST_PREV(rnum)))); send_to_char(ch, "Next :"); if (QST_NEXT(rnum) == NOTHING) send_to_char(ch, " \tyNone.\tn\r\n"); else send_to_char(ch, " [\ty%5d\tn] \tc%s\tn\r\n", QST_NEXT(rnum), QST_DESC(real_quest(QST_NEXT(rnum)))); } }
void do_repairset( CHAR_DATA *ch, char *argument ) { REPAIR_DATA *repair; MOB_INDEX_DATA *mob, *mob2; char arg1[MAX_INPUT_LENGTH]; char arg2[MAX_INPUT_LENGTH]; int vnum; int value; argument = one_argument( argument, arg1 ); argument = one_argument( argument, arg2 ); if ( arg1[0] == '\0' || arg2[0] == '\0' ) { send_to_char( "Usage: repairset <mob vnum> <field> value\n\r", ch ); send_to_char( "\n\rField being one of:\n\r", ch ); send_to_char( " fix0 fix1 fix2 profit type open close keeper\n\r", ch ); return; } vnum = atoi( arg1 ); if ( (mob = get_mob_index(vnum)) == NULL ) { send_to_char( "Mobile not found.\n\r", ch ); return; } if ( !can_medit(ch, mob) ) return; if ( !mob->rShop ) { send_to_char( "This mobile doesn't keep a repair shop.\n\r", ch ); return; } repair = mob->rShop; value = atoi( argument ); if ( !str_cmp( arg2, "fix0" ) ) { if ( !is_number(argument) ) value = get_otype(argument); if ( value < 0 || value > MAX_ITEM_TYPE ) { send_to_char( "Invalid item type!\n\r", ch ); return; } repair->fix_type[0] = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "fix1" ) ) { if ( !is_number(argument) ) value = get_otype(argument); if ( value < 0 || value > MAX_ITEM_TYPE ) { send_to_char( "Invalid item type!\n\r", ch ); return; } repair->fix_type[1] = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "fix2" ) ) { if ( !is_number(argument) ) value = get_otype(argument); if ( value < 0 || value > MAX_ITEM_TYPE ) { send_to_char( "Invalid item type!\n\r", ch ); return; } repair->fix_type[2] = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "profit" ) ) { if ( value < 1 || value > 1000 ) { send_to_char( "Out of range.\n\r", ch ); return; } repair->profit_fix = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "type" ) ) { if ( value < 1 || value > 2 ) { send_to_char( "Out of range.\n\r", ch ); return; } repair->shop_type = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "open" ) ) { if ( value < 0 || value > 23 ) { send_to_char( "Out of range.\n\r", ch ); return; } repair->open_hour = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "close" ) ) { if ( value < 0 || value > 23 ) { send_to_char( "Out of range.\n\r", ch ); return; } repair->close_hour = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "keeper" ) ) { if ( (mob2 = get_mob_index(vnum)) == NULL ) { send_to_char( "Mobile not found.\n\r", ch ); return; } if ( !can_medit(ch, mob) ) return; if ( mob2->rShop ) { send_to_char( "That mobile already has a repair shop.\n\r", ch ); return; } mob->rShop = NULL; mob2->rShop = repair; repair->keeper = value; send_to_char( "Done.\n\r", ch ); return; } do_repairset( ch, "" ); return; }
void do_shopset( CHAR_DATA *ch, char *argument ) { SHOP_DATA *shop; MOB_INDEX_DATA *mob, *mob2; char arg1[MAX_INPUT_LENGTH]; char arg2[MAX_INPUT_LENGTH]; int vnum; int value; argument = one_argument( argument, arg1 ); argument = one_argument( argument, arg2 ); if ( arg1[0] == '\0' || arg2[0] == '\0' ) { send_to_char( "Usage: shopset <mob vnum> <field> value\n\r", ch ); send_to_char( "\n\rField being one of:\n\r", ch ); send_to_char( " buy0 buy1 buy2 buy3 buy4 buy sell open close keeper\n\r", ch ); return; } vnum = atoi( arg1 ); if ( (mob = get_mob_index(vnum)) == NULL ) { send_to_char( "Mobile not found.\n\r", ch ); return; } if ( !can_medit(ch, mob) ) return; if ( !mob->pShop ) { send_to_char( "This mobile doesn't keep a shop.\n\r", ch ); return; } shop = mob->pShop; value = atoi( argument ); if ( !str_cmp( arg2, "buy0" ) ) { if ( !is_number(argument) ) value = get_otype(argument); if ( value < 0 || value > MAX_ITEM_TYPE ) { send_to_char( "Invalid item type!\n\r", ch ); return; } shop->buy_type[0] = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "buy1" ) ) { if ( !is_number(argument) ) value = get_otype(argument); if ( value < 0 || value > MAX_ITEM_TYPE ) { send_to_char( "Invalid item type!\n\r", ch ); return; } shop->buy_type[1] = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "buy2" ) ) { if ( !is_number(argument) ) value = get_otype(argument); if ( value < 0 || value > MAX_ITEM_TYPE ) { send_to_char( "Invalid item type!\n\r", ch ); return; } shop->buy_type[2] = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "buy3" ) ) { if ( !is_number(argument) ) value = get_otype(argument); if ( value < 0 || value > MAX_ITEM_TYPE ) { send_to_char( "Invalid item type!\n\r", ch ); return; } shop->buy_type[3] = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "buy4" ) ) { if ( !is_number(argument) ) value = get_otype(argument); if ( value < 0 || value > MAX_ITEM_TYPE ) { send_to_char( "Invalid item type!\n\r", ch ); return; } shop->buy_type[4] = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "buy" ) ) { if ( value <= (shop->profit_sell+5) || value > 1000 ) { send_to_char( "Out of range.\n\r", ch ); return; } shop->profit_buy = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "sell" ) ) { if ( value < 0 || value >= (shop->profit_buy-5) ) { send_to_char( "Out of range.\n\r", ch ); return; } shop->profit_sell = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "open" ) ) { if ( value < 0 || value > 23 ) { send_to_char( "Out of range.\n\r", ch ); return; } shop->open_hour = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "close" ) ) { if ( value < 0 || value > 23 ) { send_to_char( "Out of range.\n\r", ch ); return; } shop->close_hour = value; send_to_char( "Done.\n\r", ch ); return; } if ( !str_cmp( arg2, "keeper" ) ) { if ( (mob2 = get_mob_index(vnum)) == NULL ) { send_to_char( "Mobile not found.\n\r", ch ); return; } if ( !can_medit(ch, mob) ) return; if ( mob2->pShop ) { send_to_char( "That mobile already has a shop.\n\r", ch ); return; } mob->pShop = NULL; mob2->pShop = shop; shop->keeper = value; send_to_char( "Done.\n\r", ch ); return; } do_shopset( ch, "" ); return; }
void load_char_objs(struct char_data *ch) { FILE *fl; bool found = FALSE; float timegold; struct obj_file_u st; char buf[200]; /* load in aliases and poofs first */ load_char_extra(ch); sprintf(buf, "rent/%s", lower(ch->player.name)); /* r+b is for Binary Reading/Writing */ if (!(fl = fopen(buf, "r+b"))) { log_msg("Char has no equipment"); return; } rewind(fl); if (!ReadObjs(fl, &st)) { log_msg("No objects found"); fclose(fl); return; } if (str_cmp(st.owner, GET_NAME(ch)) != 0) { log_msg("Hmm.. bad item-file write. someone is losing thier objects"); fclose(fl); return; } /* if the character has been out for 12 real hours, they are fully healed upon re-entry. if they stay out for 24 full hours, all affects are removed, including bad ones. */ if (st.last_update + 12*SECS_PER_REAL_HOUR < time(0)) RestoreChar(ch); if (st.last_update + 24*SECS_PER_REAL_HOUR < time(0)) RemAllAffects(ch); if (ch->in_room == NOWHERE && st.last_update + 1*SECS_PER_REAL_HOUR > time(0)) { /* you made it back from the crash in time, 1 hour grace period. */ log_msg("Character reconnecting."); found = TRUE; } else { char buf[MAX_STRING_LENGTH]; if (ch->in_room == NOWHERE) log_msg("Char reconnecting after autorent"); #if NEW_RENT timegold = (int) ((100*((float)time(0) - st.last_update)) / (SECS_PER_REAL_DAY)); #else timegold = (int) ((st.total_cost*((float)time(0) - st.last_update)) / (SECS_PER_REAL_DAY)); #endif sprintf(buf, "Char ran up charges of %g gold in rent", timegold); log_msg(buf); sprintf(buf, "You ran up charges of %g gold in rent.\n\r", timegold); send_to_char(buf, ch); GET_GOLD(ch) -= timegold; found = TRUE; if (GET_GOLD(ch) < 0) { log_msg("Char ran out of money in rent"); send_to_char("You ran out of money, you deadbeat.\n\r", ch); GET_GOLD(ch) = 0; found = FALSE; } } fclose(fl); if (found) obj_store_to_char(ch, &st); else { ZeroRent(GET_NAME(ch)); } /* Save char, to avoid strange data if crashing */ save_char(ch, AUTO_RENT); }
int main(int argc, char **argv) { int rc; umseconds_t milliseconds_taken; char *path = NULL; measure_func_t fn = NULL; int iteration; int iterations; char *log_str = NULL; char *test_type = NULL; char *endptr; if (argc < 5) { fprintf(stderr, NAME ": Error, argument missing.\n"); syntax_print(); return 1; } if (argc > 5) { fprintf(stderr, NAME ": Error, too many arguments.\n"); syntax_print(); return 1; } // Skip program name --argc; ++argv; iterations = strtol(*argv, &endptr, 10); if (*endptr != '\0') { printf(NAME ": Error, invalid argument (iterations).\n"); syntax_print(); return 1; } --argc; ++argv; test_type = *argv; --argc; ++argv; log_str = *argv; --argc; ++argv; path = *argv; if (str_cmp(test_type, "sequential-file-read") == 0) { fn = sequential_read_file; } else if (str_cmp(test_type, "sequential-dir-read") == 0) { fn = sequential_read_dir; } else { fprintf(stderr, "Error, unknown test type\n"); syntax_print(); return 1; } for (iteration = 0; iteration < iterations; iteration++) { rc = measure(fn, path, &milliseconds_taken); if (rc != EOK) { fprintf(stderr, "Error %d\n", rc); return 1; } printf("%s;%s;%s;%lu;ms\n", test_type, path, log_str, milliseconds_taken); } return 0; }
int skill_ethereal_wolf( int sn, int level, CHAR_DATA *ch, void *vo ) { AFFECT_DATA af; char arg [ MAX_INPUT_LENGTH ]; CHAR_DATA *victim; /* if ( !IS_NPC( ch ) && ( ( ch->level < skill_table[sn].skill_level[ch->class] ) && (ch->level < skill_table[sn].skill_level[ch->multied]))) { send_to_char(C_DEFAULT, "You can not perform that skill.\n\r", ch ); return SKPELL_MISSED; } */ // modified check so if NPCs have spell on already // they can use bite/howl/etc - Ahsile if ( IS_NPC(ch) || number_percent( ) > ( ch->pcdata->learned[sn] / 10 ) ) { if (IS_NPC(ch)) { if (!IS_AFFECTED4(ch, AFF_ETHEREAL_WOLF)) { send_to_char( C_DEFAULT, "You failed.\n\r", ch ); return SKPELL_MISSED; } } else { send_to_char( C_DEFAULT, "You failed.\n\r", ch ); return SKPELL_MISSED; } } if ( !ch->fighting ) { if ( IS_AFFECTED4( ch, AFF_ETHEREAL_WOLF ) ) { send_to_char( AT_DGREY, "You replace your ethereal wolf with a new one.\n\r", ch ); return SKPELL_NO_DAMAGE; } /* TO DO: Mana costs */ af.type = sn; af.level = ch->level; af.duration = ch->level; af.location = APPLY_NONE; af.modifier = 0; af.bitvector = AFF_ETHEREAL_WOLF; affect_to_char4(ch, &af); act( AT_DGREY, "$n summons an ethereal wolf!", ch, NULL, NULL, TO_ROOM ); send_to_char( AT_DGREY, "You have summoned an ethereal wolf to assist you.\n\r", ch ); WAIT_STATE( ch, skill_table[sn].beats ); return SKPELL_NO_DAMAGE; } /* Wolf commands will go here */ victim = ch->fighting; if (target_name[0] == '\0') { send_to_char( AT_DGREY, "You get the attention of your wolf.\n\r", ch ); act( AT_DGREY, "$n gets the attention of $m wolf.", ch, NULL, NULL, TO_ROOM ); return SKPELL_NO_DAMAGE; } if ( !str_cmp( target_name, "bite" ) ) { send_to_char( AT_DGREY, "You order your wolf to bite!\n\r", ch ); act( AT_DGREY, "$n orders $m ethereal wolf to bite!", ch, NULL, NULL, TO_ROOM ); WAIT_STATE( ch, skill_table[skill_lookup("ethereal wolf bite")].beats ); return spell_ethereal_wolf_bite ( skill_lookup("ethereal wolf bite"), ch->level, ch, victim ); } if ( !str_cmp( arg, "claw" ) ) { send_to_char( AT_DGREY, "You order your wolf to claw!\n\r", ch ); act( AT_DGREY, "$n orders $m ethereal wolf to claw!", ch, NULL, NULL, TO_ROOM ); WAIT_STATE( ch, skill_table[skill_lookup("ethereal wolf claw")].beats ); return spell_ethereal_wolf_claw ( skill_lookup("ethereal wolf claw"), ch->level, ch, victim ); } if ( !str_cmp( arg, "howl" ) ) { send_to_char( AT_DGREY, "You order your wolf to howl!\n\r", ch ); act( AT_DGREY, "$n orders $m ethereal wolf to howl!", ch, NULL, NULL, TO_ROOM ); spell_ethereal_wolf_howl ( skill_lookup("ethereal wolf howl"), ch->level, ch, victim ); WAIT_STATE( ch, skill_table[skill_lookup("ethereal wolf howl")].beats / 2); send_to_char( AT_DGREY, "You are terrified!\n\r", victim ); if( !saves_spell( ch->level, victim ) ) { WAIT_STATE( victim, skill_table[skill_lookup("ethereal wolf howl")].beats ); } return SKPELL_NO_DAMAGE; } send_to_char ( AT_DGREY, "You may only order your wolf to BITE, CLAW or HOWL.\n\r", ch ); return SKPELL_BOTCHED; }
/* Date stamp idea comes from Alander of ROM */ void do_note( CHAR_DATA *ch, const char *argument ) { NOTE_DATA *pnote; char buf [ MAX_STRING_LENGTH ]; char buf1 [ MAX_STRING_LENGTH*7 ]; char arg [ MAX_INPUT_LENGTH ]; int vnum; int anum; if ( IS_NPC( ch ) ) return; argument = one_argument( argument, arg ); smash_tilde( argument ); if ( arg[0] == '\0' ) { do_note( ch, "read" ); return; } if ( !str_cmp( arg, "list" ) ) { vnum = 0; buf1[0] = '\0'; for ( pnote = note_list; pnote; pnote = pnote->next ) { if ( is_note_to( ch, pnote ) ) { sprintf( buf, "[%3d%s] %s: %s\n\r", vnum, ( pnote->date_stamp > ch->last_note && str_cmp( pnote->sender, ch->name ) ) ? "N" : " ", pnote->sender, pnote->subject ); strcat( buf1, buf ); vnum++; } } send_to_char( buf1, ch ); return; } if ( !str_cmp( arg, "read" ) ) { bool fAll; if ( !str_cmp( argument, "all" ) ) { fAll = TRUE; anum = 0; } else if ( argument[0] == '\0' || !str_prefix( argument, "next" ) ) /* read next unread note */ { vnum = 0; buf1[0] = '\0'; for ( pnote = note_list; pnote; pnote = pnote->next ) { if ( is_note_to( ch, pnote ) && str_cmp( ch->name, pnote->sender ) && ch->last_note < pnote->date_stamp ) { break; } else { if ( is_note_to( ch, pnote ) ) vnum++; } } if ( pnote ) { sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r", vnum, pnote->sender, pnote->subject, pnote->date, pnote->to_list ); strcat( buf1, buf ); strcat( buf1, pnote->text ); ch->last_note = UMAX( ch->last_note, pnote->date_stamp ); send_to_char( buf1, ch ); return; } send_to_char( "You have no unread notes.\n\r", ch ); return; } else if ( is_number( argument ) ) { fAll = FALSE; anum = atoi( argument ); } else { send_to_char( "Note read which number?\n\r", ch ); return; } vnum = 0; buf1[0] = '\0'; for ( pnote = note_list; pnote; pnote = pnote->next ) { if ( is_note_to( ch, pnote ) ) { if ( vnum == anum || fAll ) { sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r", vnum, pnote->sender, pnote->subject, pnote->date, pnote->to_list ); strcat( buf1, buf ); strcat( buf1, pnote->text ); if ( !fAll ) send_to_char( buf1, ch ); else strcat( buf1, "\n\r" ); ch->last_note = UMAX( ch->last_note, pnote->date_stamp ); if ( !fAll ) return; } vnum++; } } if ( !fAll ) send_to_char( "No such note.\n\r", ch ); else send_to_char( buf1, ch ); return; } if ( !str_cmp( arg, "+" ) ) { note_attach( ch ); strcpy( buf, ch->pnote->text ); if ( strlen( buf ) + strlen( argument ) >= MAX_STRING_LENGTH - 200 ) { send_to_char( "Note too long.\n\r", ch ); return; } strcat( buf, argument ); strcat( buf, "\n\r" ); free_string( ch->pnote->text ); ch->pnote->text = str_dup( buf ); send_to_char( "Ok.\n\r", ch ); return; } if ( !str_cmp( arg, "subject" ) ) { note_attach( ch ); free_string( ch->pnote->subject ); ch->pnote->subject = str_dup( argument ); send_to_char( "Ok.\n\r", ch ); return; } if ( !str_cmp( arg, "to" ) ) { note_attach( ch ); free_string( ch->pnote->to_list ); ch->pnote->to_list = str_dup( argument ); send_to_char( "Ok.\n\r", ch ); return; } if ( !str_cmp( arg, "clear" ) ) { if ( ch->pnote ) { free_string( ch->pnote->text ); free_string( ch->pnote->subject ); free_string( ch->pnote->to_list ); free_string( ch->pnote->date ); free_string( ch->pnote->sender ); ch->pnote->next = note_free; note_free = ch->pnote; ch->pnote = NULL; } send_to_char( "Ok.\n\r", ch ); return; } if ( !str_cmp( arg, "show" ) ) { if ( !ch->pnote ) { send_to_char( "You have no note in progress.\n\r", ch ); return; } sprintf( buf, "%s: %s\n\rTo: %s\n\r", ch->pnote->sender, ch->pnote->subject, ch->pnote->to_list ); send_to_char( buf, ch ); send_to_char( ch->pnote->text, ch ); return; } if ( !str_cmp( arg, "post" ) || !str_prefix( arg, "send" ) ) { FILE *fp; char *strtime; if ( !ch->pnote ) { send_to_char( "You have no note in progress.\n\r", ch ); return; } if ( !str_cmp( ch->pnote->to_list, "" ) ) { send_to_char( "You need to provide a recipient (name, all, or immortal).\n\r", ch ); return; } if ( !str_cmp( ch->pnote->subject, "" ) ) { send_to_char( "You need to provide a subject.\n\r", ch ); return; } ch->pnote->next = NULL; strtime = ctime( ¤t_time ); strtime[strlen(strtime)-1] = '\0'; free_string( ch->pnote->date ); ch->pnote->date = str_dup( strtime ); ch->pnote->date_stamp = current_time; if ( !note_list ) { note_list = ch->pnote; } else { for ( pnote = note_list; pnote->next; pnote = pnote->next ) ; pnote->next = ch->pnote; } pnote = ch->pnote; ch->pnote = NULL; fclose( fpReserve ); if ( !( fp = fopen( NOTE_FILE, "a" ) ) ) { perror( NOTE_FILE ); } else { fprintf( fp, "Sender %s~\n", pnote->sender ); fprintf( fp, "Date %s~\n", pnote->date ); fprintf( fp, "Stamp %ld\n", (unsigned long)pnote->date_stamp ); fprintf( fp, "To %s~\n", pnote->to_list ); fprintf( fp, "Subject %s~\n", pnote->subject ); fprintf( fp, "Text\n%s~\n\n", pnote->text ); fclose( fp ); } fpReserve = fopen( NULL_FILE, "r" ); send_to_char( "Ok.\n\r", ch ); return; } if ( !str_cmp( arg, "remove" ) ) { if ( !is_number( argument ) ) { send_to_char( "Note remove which number?\n\r", ch ); return; } anum = atoi( argument ); vnum = 0; for ( pnote = note_list; pnote; pnote = pnote->next ) { if ( is_note_to( ch, pnote ) && vnum++ == anum ) { note_remove( ch, pnote ); send_to_char( "Ok.\n\r", ch ); return; } } send_to_char( "No such note.\n\r", ch ); return; } send_to_char( "Huh? Type 'help note' for usage.\n\r", ch ); return; }
void print_comparison(char *a, char *b) { int result = str_cmp(a, b); printf("%s == %s? %d:(%d)\n", a, b, (result == 0), result); }
/* Load the abits and qbits */ void load_bits( void ) { char buf[MAX_STRING_LENGTH]; char *word; bool fMatch; int mode = 0; BIT_DATA *bit = NULL; FILE *fp; sprintf( buf, "%sabit.lst", SYSTEM_DIR ); if( ( fp = fopen( buf, "r" ) ) == NULL ) { perror( buf ); return; } for( ;; ) { word = feof( fp ) ? "End" : fread_word( fp ); fMatch = FALSE; switch ( UPPER( word[0] ) ) { case '*': fMatch = TRUE; fread_to_eol( fp ); break; case '#': if( !str_cmp( word, "#END" ) ) { fclose( fp ); if( mode == 0 ) { mode = 1; /* We have two files to read, I reused the same code to read both */ sprintf( buf, "%sqbit.lst", SYSTEM_DIR ); if( ( fp = fopen( buf, "r" ) ) == NULL ) { perror( buf ); return; } } else return; fMatch = TRUE; } break; case 'D': if( !str_cmp( word, "Desc" ) ) { fMatch = TRUE; strcpy( bit->desc, fread_string( fp ) ); } break; case 'E': if( !strcmp( word, "End" ) ) { if( mode == 0 ) LINK( bit, first_abit, last_abit, next, prev ); else LINK( bit, first_qbit, last_qbit, next, prev ); bit = NULL; fMatch = TRUE; } break; case 'N': if( !strcmp( word, "Number" ) ) { CREATE( bit, BIT_DATA, 1 ); bit->number = fread_number( fp ); fMatch = TRUE; } break; } if( !fMatch ) { sprintf( buf, "load_bits: no match: %s", word ); bug( buf, 0 ); } } }
void do_plantbug( CHAR_DATA * ch, char *argument ) { CHAR_DATA *victim; BUG_DATA *pbug; BUG_DATA *cbug; OBJ_DATA *obj; bool checkbug = FALSE; int schance; if( IS_NPC( ch ) ) return; if( ( victim = get_char_room( ch, argument ) ) == NULL ) { send_to_char( "They aren't here.\n\r", ch ); return; } if( IS_NPC( victim ) ) { send_to_char( "You can't bug NPC's!\n\r", ch ); return; } if( IS_IMMORTAL( victim ) ) { send_to_char( "Don't try to plant bugs on immortals.\n\r", ch ); return; } if( in_arena( ch ) ) { send_to_char( "You're here to FIGHT, not spy.\n\r", ch ); return; } if( ch == victim ) { send_to_char( "You can't bug yourself!\n\r", ch ); return; } for( obj = ch->last_carrying; obj; obj = obj->prev_content ) if( obj->item_type == ITEM_BUG ) checkbug = TRUE; if( checkbug == FALSE ) { send_to_char( "You don't have any bugs to plant.\n\r", ch ); return; } for( cbug = victim->first_bug; cbug; cbug = cbug->next_in_bug ) if( !str_cmp( ch->name, cbug->name ) ) { send_to_char( "You have already planted a bug on this person.\n\r", ch ); return; } schance = number_percent( ) - UMIN( 0, ( get_curr_lck( ch ) - 14 ) ) + UMIN( 0, ( get_curr_lck( victim ) - 13 ) ); if( schance < ch->pcdata->learned[gsn_plantbug] ) { act( AT_WHITE, "You carefully reach into $N's pocket and place a bug.", ch, NULL, victim, TO_CHAR ); CREATE( pbug, BUG_DATA, 1 ); pbug->name = ch->name; LINK( pbug, victim->first_bug, victim->last_bug, next_in_bug, prev_in_bug ); learn_from_success( ch, gsn_plantbug ); for( obj = ch->last_carrying; obj; obj = obj->prev_content ) { if( obj->item_type == ITEM_BUG ) { separate_obj( obj ); obj_from_char( obj ); extract_obj( obj ); break; } } return; } else { send_to_char( "&RYou try to find a pocket to plant the bug in but fail!\n\r", ch ); learn_from_failure( ch, gsn_plantbug ); if( number_bits( 0 ) == 0 ) ch_printf( victim, "You feel a slight brush against your pocket to find %s's hand there.\n\r", PERS( ch, victim ) ); return; } }
static int parse_attribute_crypto(struct sdp_attribute *output) { PARSE_DECL; char *endp; struct attribute_crypto *c; int salt_key_len, enc_salt_key_len; int b64_state = 0; unsigned int b64_save = 0; gsize ret; str s; u_int32_t u32; const char *err; output->attr = ATTR_CRYPTO; PARSE_INIT; EXTRACT_TOKEN(u.crypto.tag_str); EXTRACT_TOKEN(u.crypto.crypto_suite_str); EXTRACT_TOKEN(u.crypto.key_params_str); c = &output->u.crypto; c->tag = strtoul(c->tag_str.s, &endp, 10); err = "invalid 'tag'"; if (endp == c->tag_str.s) goto error; c->crypto_suite = crypto_find_suite(&c->crypto_suite_str); err = "unknown crypto suite"; if (!c->crypto_suite) goto error; salt_key_len = c->crypto_suite->master_key_len + c->crypto_suite->master_salt_len; enc_salt_key_len = ceil((double) salt_key_len * 4.0/3.0); err = "invalid key parameter length"; if (c->key_params_str.len < 7 + enc_salt_key_len) goto error; err = "unknown key method"; if (strncasecmp(c->key_params_str.s, "inline:", 7)) goto error; c->key_base64_str = c->key_params_str; str_shift(&c->key_base64_str, 7); ret = g_base64_decode_step(c->key_base64_str.s, enc_salt_key_len, (guchar *) c->key_salt_buf, &b64_state, &b64_save); err = "invalid base64 encoding"; if (ret != salt_key_len) goto error; c->master_key.s = c->key_salt_buf; c->master_key.len = c->crypto_suite->master_key_len; c->salt.s = c->master_key.s + c->master_key.len; c->salt.len = c->crypto_suite->master_salt_len; c->lifetime_str = c->key_params_str; str_shift(&c->lifetime_str, 7 + enc_salt_key_len); if (c->lifetime_str.len >= 2) { err = "invalid key parameter syntax"; if (c->lifetime_str.s[0] != '|') goto error; str_shift(&c->lifetime_str, 1); str_chr_str(&c->mki_str, &c->lifetime_str, '|'); if (!c->mki_str.s) { if (str_chr(&c->lifetime_str, ':')) { c->mki_str = c->lifetime_str; c->lifetime_str = STR_NULL; } } else { c->lifetime_str.len = c->mki_str.s - c->lifetime_str.s; str_shift(&c->mki_str, 1); } } else c->lifetime_str = STR_NULL; if (c->lifetime_str.s) { if (c->lifetime_str.len >= 3 && !memcmp(c->lifetime_str.s, "2^", 2)) { c->lifetime = strtoull(c->lifetime_str.s + 2, NULL, 10); err = "invalid key lifetime"; if (!c->lifetime || c->lifetime > 64) goto error; c->lifetime = 1ULL << c->lifetime; } else c->lifetime = strtoull(c->lifetime_str.s, NULL, 10); err = "invalid key lifetime"; if (!c->lifetime || c->lifetime > c->crypto_suite->srtp_lifetime #ifdef STRICT_SDES_KEY_LIFETIME || c->lifetime > c->crypto_suite->srtcp_lifetime #endif ) goto error; } if (c->mki_str.s) { str_chr_str(&s, &c->mki_str, ':'); err = "invalid MKI specification"; if (!s.s) goto error; u32 = htonl(strtoul(c->mki_str.s, NULL, 10)); c->mki_len = strtoul(s.s + 1, NULL, 10); err = "MKI too long"; if (c->mki_len > sizeof(c->mki)) goto error; memset(c->mki, 0, c->mki_len); if (sizeof(u32) >= c->mki_len) memcpy(c->mki, ((void *) &u32) + (sizeof(u32) - c->mki_len), c->mki_len); else memcpy(c->mki + (c->mki_len - sizeof(u32)), &u32, sizeof(u32)); } while (extract_token(&start, end, &s) == 0) { if (!str_cmp(&s, "UNENCRYPTED_SRTCP")) c->unencrypted_srtcp = 1; else if (!str_cmp(&s, "UNENCRYPTED_SRTP")) c->unencrypted_srtp = 1; else if (!str_cmp(&s, "UNAUTHENTICATED_SRTP")) c->unauthenticated_srtp = 1; } return 0; error: ilog(LOG_ERROR, "Failed to parse a=crypto attribute: %s", err); return -1; }
//Contract System by Tawnos. void do_contract( CHAR_DATA * ch, char *argument ) { CHAR_DATA *victim; CHAR_DATA *target; char arg1[MAX_INPUT_LENGTH]; char arg2[MAX_INPUT_LENGTH]; char arg3[MAX_INPUT_LENGTH]; long amount = 0; CONTRACT_DATA *ccontract; CONTRACT_DATA *contract; argument = one_argument( argument, arg1 ); argument = one_argument( argument, arg2 ); argument = one_argument( argument, arg3 ); if( IS_NPC( ch ) ) return; if( arg1[0] == '\0' || arg2[0] == '\0' || arg3[0] == '\0' ) { send_to_char( "&RSyntax: contract <person> <target> <amount>\n\r", ch ); return; } if( ( victim = get_char_room( ch, arg1 ) ) == NULL ) { send_to_char( "They aren't here.\n\r", ch ); return; } if( ( target = get_char_world_ooc( ch, arg2 ) ) == NULL ) { send_to_char( "Your target is currently not online.\n\r", ch ); return; } if( ch == victim ) { send_to_char( "You can't contract yourself!\n\r", ch ); return; } if( IS_NPC( victim ) || IS_NPC( target ) ) { send_to_char( "You can't contract NPC's.\n\r", ch ); return; } if( ch == target ) { send_to_char( "You can't contract against yourself!\n\r", ch ); return; } if( target == victim ) { send_to_char( "You can't contract them to kill themself!\n\r", ch ); return; } amount = atoi( arg3 ); if( amount < 5000 ) { send_to_char( "&RYour contract must be for at least 5000 credits.\n\r", ch ); return; } if( ch->gold < amount ) { send_to_char( "&RYou don't have enough credits!\n\r", ch ); return; } for( ccontract = victim->first_contract; ccontract; ccontract = ccontract->next_in_contract ) { if( !str_cmp( ccontract->target, target->name ) ) { ch->gold -= amount; ccontract->amount += amount; ch_printf( ch, "&GYou have contracted %s to kill %s for an amount of %d credits.\n\r", PERS( victim, ch ), target->name, amount ); ch_printf( victim, "&G%s has contracted you to kill %s, raising your contract reward by %d credits.\n\r", PERS( ch, victim ), target->name, amount ); return; } } CREATE( contract, CONTRACT_DATA, 1 ); contract->target = target->name; contract->amount = amount; LINK( contract, victim->first_contract, victim->last_contract, next_in_contract, prev_in_contract ); ch->gold -= amount; ch_printf( ch, "&GYou have contracted %s to kill %s for an amount of %d credits.\n\r", PERS( victim, ch ), target->name, amount ); ch_printf( victim, "&G%s has contracted you to kill %s for an amount of %d credits.\n\r", PERS( ch, victim ), target->name, amount ); }
static int parse_attribute(struct sdp_attribute *a) { int ret; a->name = a->line_value; str_chr_str(&a->value, &a->name, ':'); if (a->value.s) { a->name.len -= a->value.len; a->value.s++; a->value.len--; a->key = a->name; str_chr_str(&a->param, &a->value, ' '); if (a->param.s) { a->key.len += 1 + (a->value.len - a->param.len); a->param.s++; a->param.len--; if (!a->param.len) a->param.s = NULL; } else a->key.len += 1 + a->value.len; } ret = 0; switch (a->name.len) { case 3: if (!str_cmp(&a->name, "mid")) a->attr = ATTR_MID; break; case 4: if (!str_cmp(&a->name, "rtcp")) ret = parse_attribute_rtcp(a); else if (!str_cmp(&a->name, "ssrc")) ret = parse_attribute_ssrc(a); break; case 5: if (!str_cmp(&a->name, "group")) ret = parse_attribute_group(a); else if (!str_cmp(&a->name, "setup")) ret = parse_attribute_setup(a); break; case 6: if (!str_cmp(&a->name, "crypto")) ret = parse_attribute_crypto(a); else if (!str_cmp(&a->name, "extmap")) a->attr = ATTR_EXTMAP; else if (!str_cmp(&a->name, "rtpmap")) ret = parse_attribute_rtpmap(a); break; case 7: if (!str_cmp(&a->name, "ice-pwd")) a->attr = ATTR_ICE_PWD; break; case 8: switch (a->name.s[0]) { case 'i': if (!str_cmp(&a->name, "ice-lite")) a->attr = ATTR_ICE_LITE; else if (!str_cmp(&a->name, "inactive")) a->attr = ATTR_INACTIVE; break; case 's': if (!str_cmp(&a->name, "sendrecv")) a->attr = ATTR_SENDRECV; else if (!str_cmp(&a->name, "sendonly")) a->attr = ATTR_SENDONLY; break; case 'r': if (!str_cmp(&a->name, "recvonly")) a->attr = ATTR_RECVONLY; if (!str_cmp(&a->name, "rtcp-mux")) a->attr = ATTR_RTCP_MUX; break; } break; case 9: if (!str_cmp(&a->name, "candidate")) ret = parse_attribute_candidate(a); else if (!str_cmp(&a->name, "ice-ufrag")) a->attr = ATTR_ICE_UFRAG; break; case 11: if (!str_cmp(&a->name, "ice-options")) a->attr = ATTR_ICE_OPTIONS; else if (!str_cmp(&a->name, "fingerprint")) ret = parse_attribute_fingerprint(a); break; case 12: if (!str_cmp(&a->name, "ice-mismatch")) a->attr = ATTR_ICE; break; case 17: if (!str_cmp(&a->name, "remote-candidates")) a->attr = ATTR_ICE; break; } return ret; }
void do_order( CHAR_DATA * ch, char * argument ) { CHAR_DATA * victim; CHAR_DATA * och; CHAR_DATA * och_next; char arg[ MAX_INPUT_LENGTH ]; bool found; bool fAll; argument = one_argument( argument, arg ); if ( arg[ 0 ] == '\0' || argument[ 0 ] == '\0' ) { send_to_char( AT_GREY, "Order whom to do what?\n\r", ch ); return; } if ( IS_AFFECTED( ch, AFF_CHARM ) ) { send_to_char( AT_GREY, "You feel like taking, not giving, orders.\n\r", ch ); return; } if ( !str_cmp( arg, "all" ) ) { fAll = TRUE; victim = NULL; } else { fAll = FALSE; if ( !( victim = get_char_room( ch, arg ) ) ) { send_to_char( AT_GREY, "They aren't here.\n\r", ch ); return; } if ( victim == ch ) { send_to_char( AT_GREY, "Aye aye, right away!\n\r", ch ); return; } if ( !IS_AFFECTED( victim, AFF_CHARM ) || victim->master != ch ) { send_to_char( AT_GREY, "Do it yourself!\n\r", ch ); return; } } found = FALSE; for ( och = ch->in_room->people; och; och = och_next ) { och_next = och->next_in_room; if ( och->deleted ) { continue; } /* You cannot order a newbie helper around period. Angi */ if ( IS_NPC( och ) ) { if ( CHECK_BIT( och->act, ACT_NEWBIE ) ) { continue; } } if ( IS_AFFECTED( och, AFF_CHARM ) && och->master == ch && ( fAll || och == victim ) ) { found = TRUE; act( AT_GREY, "$n orders you to '$t'.", ch, argument, och, TO_VICT ); interpret( och, argument ); } } if ( found ) { send_to_char( AT_GREY, "Ok.\n\r", ch ); } else { send_to_char( AT_GREY, "You have no followers here.\n\r", ch ); } return; }
void sort_adminlist( ) { ADMINENT *admin, *tmp, *next; COUNCIL_DATA *council; bool run = TRUE, head = FALSE, thead = FALSE; while ( run ) { run = FALSE; for ( admin = first_admin; admin; admin = admin->next ) { tmp = admin->next; if ( tmp ) { if ( strcmp( admin->name, tmp->name)>0) { if ( tmp->next ) tmp->next->last = admin; if ( admin->last ) admin->last->next = tmp; next = tmp->next; tmp->next = admin; tmp->last = admin->last; admin->next = next; admin->last = tmp; if ( last_admin == tmp ) last_admin = admin; if ( first_admin == admin ) first_admin = tmp; run = TRUE; } } } } run = TRUE; while ( run ) { run = FALSE; for ( admin = first_admin; admin; admin = admin->next ) { tmp = admin->next; if ( tmp ) { if ( tmp->level > admin->level ) { if ( tmp->next ) tmp->next->last = admin; if ( admin->last ) admin->last->next = tmp; next = tmp->next; tmp->next = admin; tmp->last = admin->last; admin->next = next; admin->last = tmp; if ( last_admin == tmp ) last_admin = admin; if ( first_admin == admin ) first_admin = tmp; run = TRUE; } } } } run = TRUE; while ( run ) { run = FALSE; for ( admin = first_admin; admin; admin = admin->next ) { head = FALSE; thead = FALSE; tmp = admin->next; if ( tmp ) { for ( council = first_council; council; council = council->next ) { if ( !str_cmp( council->head, admin->name) || ( council->head2 && !str_cmp( council->head2, admin->name) ) ) head = TRUE; if ( !str_cmp( council->head, tmp->name) || ( council->head2 && !str_cmp( council->head2, tmp->name) ) ) thead = TRUE; } if ( thead && !head ) { if ( tmp->next ) tmp->next->last = admin; if ( admin->last ) admin->last->next = tmp; next = tmp->next; tmp->next = admin; tmp->last = admin->last; admin->next = next; admin->last = tmp; if ( last_admin == tmp ) last_admin = admin; if ( first_admin == admin ) first_admin = tmp; run = TRUE; } } } } return; }
/* * 'Split' originally by Gnort, God of Chaos. */ void do_split( CHAR_DATA * ch, char * argument ) { CHAR_DATA * gch; char buf[ MAX_STRING_LENGTH ]; char arg[ MAX_INPUT_LENGTH ]; int members; int amount = 0; int share = 0; int extra = 0; MONEY_DATA amt; char arg2[ MAX_STRING_LENGTH ]; argument = one_argument( argument, arg ); argument = one_argument( argument, arg2 ); if ( arg[ 0 ] == '\0' ) { send_to_char( AT_YELLOW, "Split how much?\n\r", ch ); return; } /* split 5 copper,gold,silver */ amount = is_number( arg ) ? atoi( arg ) : 0; amt.gold = amt.silver = amt.copper = 0; if ( !str_cmp( arg2, "gold" ) ) { amt.gold = amount; } else if ( !str_cmp( arg2, "silver" ) ) { amt.silver = amount; } else if ( !str_cmp( arg2, "copper" ) ) { amt.copper = amount; } else { send_to_char( AT_WHITE, "&WSyntax: &Rsplit <amount> <currency type>\n\r", ch ); return; } if ( ( amt.gold < 0 ) || ( amt.silver < 0 ) || ( amt.copper < 0 ) ) { send_to_char( AT_YELLOW, "Your group wouldn't like that.\n\r", ch ); return; } if ( ( amt.gold == 0 ) && ( amt.silver == 0 ) && ( amt.copper == 0 ) ) { send_to_char( AT_YELLOW, "You hand out zero coins, but no one notices.\n\r", ch ); return; } if ( ( ch->money.gold < amt.gold ) || ( ch->money.silver < amt.silver ) || ( ch->money.copper < amt.copper ) ) { sprintf( buf, "You don't have that many %s coins.\n\r", arg2 ); send_to_char( AT_YELLOW, buf, ch ); return; } members = 0; for ( gch = ch->in_room->people; gch; gch = gch->next_in_room ) { if ( gch->deleted ) { continue; } if ( is_same_group( gch, ch ) ) { members++; } } if ( members < 2 ) { return; } share = amount / members; extra = amount % members; if ( share == 0 ) { send_to_char( AT_YELLOW, "Don't even bother, cheapskate.\n\r", ch ); return; } if ( !str_cmp( arg2, "gold" ) ) { ch->money.gold -= amount; ch->money.gold += share + extra; } else if ( !str_cmp( arg2, "silver" ) ) { ch->money.silver -= amount; ch->money.silver += share + extra; } else if ( !str_cmp( arg2, "copper" ) ) { ch->money.copper -= amount; ch->money.silver += share + extra; } sprintf( buf, "You split %s Your share is %d %s coins.\n\r", money_string( &amt ), share + extra, arg2 ); send_to_char( AT_YELLOW, buf, ch ); sprintf( buf, "$n splits %s Your share is %d %s coins.", money_string( &amt ), share, arg2 ); for ( gch = ch->in_room->people; gch; gch = gch->next_in_room ) { if ( gch->deleted ) { continue; } if ( gch != ch && is_same_group( gch, ch ) ) { act( C_DEFAULT, buf, ch, NULL, gch, TO_VICT ); gch->money.gold += ( !str_cmp( arg2, "gold" ) ) ? share : 0; gch->money.silver += ( !str_cmp( arg2, "silver" ) ) ? share : 0; gch->money.copper += ( !str_cmp( arg2, "copper" ) ) ? share : 0; } } return; }
/* internal function to construct a query structure from a given string (query) * of length len. At most maxterms will be read from the query. */ unsigned int index_querybuild(struct index *idx, struct query *query, const char *querystr, unsigned int len, unsigned int maxterms, unsigned int maxtermlen, int impacts) { struct queryparse *qp; /* structure to parse the query */ struct conjunct *current = NULL; /* pointer to a current conjunction */ char word[TERMLEN_MAX + 1]; /* buffer to hold words */ unsigned int i, /* counter */ wordlen, /* length of word */ words = 0, /* number of words parsed */ currmatch = 0; /* number of matches against current * entry */ /* veclen; */ int state = CONJUNCT_TYPE_WORD, /* state variable, can take on values * from conjunct types enum */ stopped = 0; /* whether the last word was stopped */ /* void *ve; */ /* compressed vocabulary entry for a * word */ enum queryparse_ret parse_ret; /* value returned by parser */ /* last modifier seen; also, are we in a modifier */ enum { MODIFIER_NONE, MODIFIER_SLOPPY, MODIFIER_CUTOFF } modifier = MODIFIER_NONE; void (*stem)(void *, char *) = index_stemmer(idx); assert(maxtermlen <= TERMLEN_MAX); if (!(qp = queryparse_new(maxtermlen, querystr, len))) { return 0; } query->terms = 0; printf("SENGOR: "); /* This bit of code builds a structure that represents a query from an * array, where the array of words will be filled from 0 upwards, and * conjunctions that require a linked list of words (phrase, AND) take * additional words from the end of the array. */ do { struct vocab_vector entry; int retval; char vec_buf[MAX_VOCAB_VECTOR_LEN]; parse_ret = queryparse_parse(qp, word, &wordlen); switch (parse_ret) { case QUERYPARSE_WORD_EXCLUDE: /* this functionality not included yet, just ignore the word for * now */ /* look up word in vocab */ /* ve = hFetch(word, idx->vocab, NULL); */ /* OPTIMIZE: search existing conjunctions for word and remove * them */ /* FIXME: stop word */ /* if (ve) { conjunct_add(query, ve, CONJUNCT_TYPE_EXCLUDE, &maxterms); } */ current = NULL; /* this can't be the start of a conjunction */ words++; break; case QUERYPARSE_WORD_NOSTOP: case QUERYPARSE_WORD: if (modifier != MODIFIER_NONE) { /* this is not a query term, but an argument to a modifier */ switch (modifier) { case MODIFIER_SLOPPY: if (query->terms > 0) query->term[query->terms - 1].sloppiness = atoi(word); break; case MODIFIER_CUTOFF: if (query->terms > 0) query->term[query->terms - 1].cutoff = atoi(word); break; default: /* FIXME WARN */ break; } break; } /* look up word in vocab */ /* FIXME: word needs to be looked up in in-memory postings as * well */ if (stem) { word[wordlen] = '\0'; stem(idx->stem, word); wordlen = str_len(word); printf(" %s ", word); } retval = get_vocab_vector(idx->vocab, &entry, word, wordlen, vec_buf, sizeof(vec_buf), impacts); if (retval < 0) { return 0; } else if (retval == 0) { stopped = 0; /* so we know that this term wasn't stopped */ currmatch = 1; /* so that we know that phrases have started */ if (current && (state == CONJUNCT_TYPE_AND)) { /* need to remove current conjunction, as it contains a word * that isn't in the collection */ if (current->f_qt > 1) { current->f_qt--; } else { state = CONJUNCT_TYPE_WORD; /* stop AND condition */ maxterms += current->terms - 1; query->terms--; } } else if (current && (state == CONJUNCT_TYPE_PHRASE)) { /* same, except phrase continues until end-phrase */ if (current->f_qt > 1) { current->f_qt--; } else { maxterms += current->terms - 1; query->terms--; } } current = NULL; } else if (state == CONJUNCT_TYPE_PHRASE) { /* OPTIMIZE: check word against excluded terms */ struct term *currterm; /* processing a phrase */ if (!currmatch) { /* first word in phrase, match or add a conjunction */ current = conjunct_add(query, &entry, /* ve, veclen, */ word, wordlen, CONJUNCT_TYPE_PHRASE, &maxterms); currmatch = 1; } else if (current && (current->f_qt > 1)) { /* we're matching an existing phrase */ /* iterate to next term we need to match */ for (i = 0, currterm = ¤t->term; i < currmatch; i++, currterm = currterm->next) ; if (currterm && !str_cmp(currterm->term, word)) { /* matched */ currmatch++; } else { /* didn't match, copy non-matching phrase */ current->f_qt--; current = conjunct_copy(query, current, currmatch, &entry, word, wordlen, &maxterms); currmatch++; } } else if (current) { /* we're building a new phrase, add next word on */ conjunct_append(query, current, &entry, /* ve, veclen, */ word, wordlen, &maxterms); currmatch++; } /* otherwise we're ignoring this phrase (because it contains a * word thats not in the vocab) */ } else if (state == CONJUNCT_TYPE_AND) { /* we are constructing an AND conjunction */ /* FIXME: stop word stopped = 1; current = NULL; */ /* OPTIMIZE: check word against excluded terms */ if (current) { if ((current->type == CONJUNCT_TYPE_AND) || (current->f_qt == 1)) { /* add to current conjunct */ conjunct_append(query, current, &entry, word, wordlen, &maxterms); current->type = CONJUNCT_TYPE_AND; } else { /* copy matched word to new location for AND conjunct */ current->f_qt--; current = conjunct_copy(query, current, 1, &entry, word, wordlen, &maxterms); current->type = CONJUNCT_TYPE_AND; } } else if (stopped) { /* first word(s) in conjunct was stopped, so start a new * one */ current = conjunct_add(query, &entry, word, wordlen, CONJUNCT_TYPE_WORD, &maxterms); } state = CONJUNCT_TYPE_WORD; /* stop AND condition */ } else if (state == CONJUNCT_TYPE_WORD) { /* its a single word */ stopped = 0; if (parse_ret != QUERYPARSE_WORD_NOSTOP) { word[wordlen] = '\0'; if (idx->qstop && stop_stop(idx->qstop, word) == STOP_STOPPED) { /* it is a stopword */ stopped = 1; current = NULL; } } if (!stopped) { current = conjunct_add(query, &entry, /* ve, veclen, */ word, wordlen, CONJUNCT_TYPE_WORD, &maxterms); currmatch = 1; } } words++; break; case QUERYPARSE_OR: state = CONJUNCT_TYPE_WORD; /* or is the default mode anyway */ break; case QUERYPARSE_AND: state = CONJUNCT_TYPE_AND; break; case QUERYPARSE_START_PHRASE: /* phrase starts */ state = CONJUNCT_TYPE_PHRASE; current = NULL; currmatch = 0; break; case QUERYPARSE_END_PHRASE: if (current && (current->terms != currmatch)) { /* partial match, need to copy phrase */ current->f_qt--; current = conjunct_copy(query, current, currmatch, NULL, NULL, 0, &maxterms); } /* treat single-word phrases as, well, words */ if (current && (current->terms == 1)) { struct conjunct *ret; /* see if this single-word occurred previously */ ret = conjunct_find(query, ¤t->term.vocab, current->term.term, str_len(current->term.term), CONJUNCT_TYPE_WORD); if (ret == NULL) { /* ok, this is the first occurence */ current->type = CONJUNCT_TYPE_WORD; } else { /* there was a previous occurence: increment its f_qt, and free this one */ ret->f_qt++; assert(current == &query->term[query->terms - 1]); free(current->term.term); if (current->term.vocab.location == VOCAB_LOCATION_VOCAB) { free(current->term.vecmem); } query->terms--; } } current = NULL; state = CONJUNCT_TYPE_WORD; break; case QUERYPARSE_END_SENTENCE: /* we're ignoring this at the moment - it might be used later if * we don't want to match phrases across sentence boundaries */ break; case QUERYPARSE_END_MODIFIER: modifier = MODIFIER_NONE; break; case QUERYPARSE_START_MODIFIER: if (str_casecmp(word, "sloppy") == 0) modifier = MODIFIER_SLOPPY; else if (str_casecmp(word, "cutoff") == 0) modifier = MODIFIER_CUTOFF; else /* FIXME WARN */ modifier = MODIFIER_NONE; break; case QUERYPARSE_EOF: break; /* this will finish the parse */ default: /* unexpected return code, error */ queryparse_delete(qp); return 0; } } while ((parse_ret != QUERYPARSE_EOF) && (query->terms < maxterms)); /* FIXME: temporary stopping condition */ queryparse_delete(qp); printf("\n"); /* returning word count confuses errors with empty queries. */ /* return words; */ return 1; }
void mpedit( CHAR_DATA *ch, char *argument ) { PROG_CODE * pMcode; char arg[ MAX_INPUT_LENGTH ]; char command[ MAX_INPUT_LENGTH ]; char log_buf[ MAX_STRING_LENGTH ]; int cmd; AREA_DATA *ad; smash_tilde( argument ); strcpy( arg, argument ); argument = one_argument( argument, command ); EDIT_MPCODE( ch, pMcode ); if ( pMcode ) { ad = pMcode->area; if ( ad == NULL ) /* ? */ { edit_done( ch ); return ; } if ( !IS_BUILDER( ch, ad ) ) { send_to_char( "MPEdit: Insufficient security to modify code.\n\r", ch ); edit_done( ch ); return ; } } if ( command[ 0 ] == '\0' ) { mpedit_show( ch, argument ); return ; } if ( !str_cmp( command, "done" ) ) { edit_done( ch ); return ; } for ( cmd = 0; mpedit_table[ cmd ].name != NULL; cmd++ ) { if ( !str_prefix( command, mpedit_table[ cmd ].name ) ) { if ( ( *mpedit_table[ cmd ].olc_fun ) ( ch, argument ) && pMcode ) { if ( ( ad = pMcode->area ) != NULL ) { SET_BIT( ad->area_flags, AREA_CHANGED ); } append_file_format_daily( ch, BUILD_LOG_FILE, "-> mpedit %s: %s", pMcode ? pMcode->name: "0", arg ); } return ; } } interpret( ch, arg ); return ; }
void do_recruit (CHAR_DATA *ch, char *argument, int cmd) { CHAR_DATA *pal = NULL; char buf [MAX_STRING_LENGTH]; argument = one_argument (argument, buf); if ( !*buf ) { for ( pal = ch->room->people; pal; pal = pal->next_in_room ) { if ( IS_NPC (pal) && pal->following != ch && is_leader (ch, pal) ) break; } if ( !pal ) { send_to_char ("Nobody else here will follow you.\n\r", ch); return; } pal->following = ch; act ("$N nods to you to follow.", FALSE, pal, 0, ch, TO_CHAR | TO_ACT_FORMAT); act ("$N motions to $S clanmates.", FALSE, pal, 0, ch, TO_NOTVICT | TO_ACT_FORMAT); act ("$n falls in.", FALSE, pal, 0, ch, TO_ROOM | TO_ACT_FORMAT); return; } if ( !str_cmp (buf, "all") ) { act ("$n motions to $s clanmates.", FALSE, ch, 0, 0, TO_ROOM | TO_ACT_FORMAT); for ( pal = ch->room->people; pal; pal = pal->next_in_room ) { if ( IS_NPC (pal) && pal->following != ch && is_leader (ch, pal) ) { pal->following = ch; act ("$N nods to you to follow.", FALSE, pal, 0, ch, TO_CHAR | TO_ACT_FORMAT); act ("$n falls in.", FALSE, pal, 0, ch, TO_ROOM | TO_ACT_FORMAT); } } if ( !pal ) { send_to_char ("Nobody else here will follow you.\n\r", ch); return; } return; } if ( !(pal = get_char_room_vis (ch, buf)) ) { send_to_char ("Nobody is here by that name.\n\r", ch); return; } if ( pal == ch ) { send_to_char ("Not yourself.\n\r", ch); return; } if ( !is_leader (ch, pal) ) { act ("You don't have the authority to recruit $N.", FALSE, ch, 0, pal, TO_CHAR); return; } if ( pal->following == ch ) { act ("$N is already following you.", FALSE, ch, 0, pal, TO_CHAR); return; } pal->following = ch; act ("$N motions to $S clanmates.", FALSE, pal, 0, ch, TO_NOTVICT | TO_ACT_FORMAT); act ("$n falls in.", FALSE, pal, 0, ch, TO_VICT | TO_ACT_FORMAT); act ("$N nods to you to follow.", FALSE, pal, 0, ch, TO_CHAR); return; }
SOCIAL_DATA *load_social( const char *social ) { SOCIAL_DATA *ret; list<SOCIAL_DATA *>::iterator li; FILE *fp; char tmp[MSL] = {'\0'}; char search[MSL] = {'0'}; const char *word; bool fMatch = false; /* Check the cache list before trying to load from file --Kline */ for( li = social_list.begin(); li != social_list.end(); li++ ) { ret = *li; if( ret->name.find(social) != string::npos ) { snprintf( log_buf, MIL, "load_social: using cached copy of (%s) which expires in (%d)", ret->name.c_str(), ret->cache_time ); monitor_chan( log_buf, MONITOR_DEBUG ); ret->cache_time = sysdata.pulse_cache; return ret; } } ret = new SOCIAL_DATA; snprintf( search, MSL, "find %s%s/ -iname %s\\*.%s -printf '%%p'", SOCIAL_DIR, initial(social), social, SOCIAL_EXT ); snprintf( tmp, MSL, "%s", _popen(search) ); fp = file_open( tmp, "r" ); snprintf( tmp, MSL, "ls -1 %s%s/%s*.%s | cut -d/ -f4 | cut -d. -f1", SOCIAL_DIR, initial(social), social, SOCIAL_EXT ); ret->name = _popen(tmp); ret->name.resize(ret->name.length()-1); /* Strip off the appended \n --Kline */ for ( ;; ) { word = feof(fp) ? "End" : fread_word(fp); fMatch = false; switch ( UPPER(word[0]) ) { case '*': fMatch = true; fread_to_eol(fp); break; case 'C': KEY("CharAuto", ret->char_auto, fread_string( fp ) ); KEY("CharFound", ret->char_found, fread_string( fp ) ); KEY("CharNoArg", ret->char_no_arg, fread_string( fp ) ); break; case 'E': if ( !str_cmp(word, "End") ) { file_close(fp); return ret; } break; case 'O': KEY("OtherAuto", ret->other_auto, fread_string( fp ) ); KEY("OtherFound", ret->other_found, fread_string( fp ) ); KEY("OtherNoArg", ret->other_no_arg, fread_string( fp ) ); break; case 'V': KEY("VictFound", ret->vict_found, fread_string( fp ) ); break; } } if ( !fMatch ) { snprintf( log_buf, (2 * MIL), "Loading in social :%s, no match for ( %s ).", social, word ); monitor_chan( log_buf, MONITOR_BAD ); fread_to_eol( fp ); } file_close(fp); return ret; }