/***************************************************************************** Name: flag_string( table, flags/stat ) Purpose: Returns string with name(s) of the flags or stat entered. Called by: act_olc.c, olc.c, and olc_save.c. ****************************************************************************/ char *flag_string( const struct flag_type *flag_table, int bits ) { static char buf[2][512]; static int cnt = 0; int flag; if ( ++cnt > 1 ) cnt = 0; buf[cnt][0] = '\0'; for (flag = 0; flag_table[flag].name != NULL; flag++) { if ( !is_stat( flag_table ) && IS_SET(bits, flag_table[flag].bit) ) { strcat( buf[cnt], " " ); strcat( buf[cnt], flag_table[flag].name ); } else if ( flag_table[flag].bit == bits ) { strcat( buf[cnt], " " ); strcat( buf[cnt], flag_table[flag].name ); break; } } return (buf[cnt][0] != '\0') ? buf[cnt]+1 : "none"; }
/***************************************************************************** * Name: flag_value(table, flag) * Purpose: Returns the value of the flags entered. Multi-flags accepted. * Called by: olc.c and olc_act.c. ****************************************************************************/ long flag_value(const struct flag_type *flag_table, const char *argument) { char word[MAX_INPUT_LENGTH]; long bit; long marked = 0; bool found = false; if (is_stat(flag_table)) return flag_lookup(argument, flag_table); /* * Accept multiple flags. */ for (;; ) { argument = one_argument(argument, word); if (word[0] == '\0') break; if ((bit = flag_lookup(word, flag_table)) != NO_FLAG) { SET_BIT(marked, bit); found = true; } } return (found) ? marked : NO_FLAG; }
/***************************************************************************** Name: flag_value( table, flag ) Purpose: Returns the value of the flags entered. Multi-flags accepted. Called by: olc.c and olc_act.c. ****************************************************************************/ int flag_value( const struct flag_type *flag_table, char *argument) { char word[MAX_INPUT_LENGTH]; int bit; int marked = 0; bool found = FALSE; if ( is_stat( flag_table ) ) return flag_lookup(argument, flag_table); /* * Accept multiple flags. */ for (; ;) { argument = one_argument( argument, word ); if ( word[0] == '\0' ) break; if ( ( bit = flag_lookup( word, flag_table ) ) != NO_FLAG ) { SET_BIT( marked, bit ); found = TRUE; } } if ( found ) return marked; else return NO_FLAG; }
/* * Takes a file ptr and checks if any parent is under watch * fileptr can be obtained from an fd and from a file name too and then * passed to this function * Assumes filePtr is a valid file pointer */ unsigned long check_if_any_parent_is_watched_filp(struct file *filePtr) { unsigned long parentInodeNo = 0, tempno = 0; struct dentry *parentPtr = NULL; /* To Prevent the parent dentry loop from going in an infinite loop */ int i = 0; /* Get the dentry of the parent of the open file */ parentPtr = filePtr->f_path.dentry->d_parent; while (parentPtr != NULL && i < 20) { tempno = parentPtr->d_inode->i_ino; if (is_stat(tempno)) { parentInodeNo = tempno; break; } else if (IS_ROOT(parentPtr)) { break; } else { i++; parentPtr = parentPtr->d_parent; } } return parentInodeNo; }
/***************************************************************************** Name: flag_value_complete( table, flag ) Purpose: Returns the value of the flags entered. Multi-flags accepted. Called by: olc.c and olc_act.c. ****************************************************************************/ long flag_value_complete( struct flag_type *flag_table, const char *argument) { char word[MAX_INPUT_LENGTH]; long bit; //int marked = 0; long marked = 0; bool found = FALSE; if ( flag_table == NULL ) { bug("flag_value_complete called with a NULL flag_table"); return NO_FLAG; } if ( fBootDb ) return flag_value_complete_init( flag_table, argument ); if ( is_stat( flag_table ) ) return flag_lookup3(argument,flag_table); if ( !str_cmp(argument,"none") ) // SinaC 2003, easy way to clear a flag return 0; // after is_stat because we only want to do this on a flag for (; ;) { argument = one_argument( argument, word ); if ( word[0] == '\0' ) return found?marked:NO_FLAG; if ( ( bit = flag_lookup3( word, flag_table ) ) != NO_FLAG ) { SET_BIT( marked, bit ); found = TRUE; } else return NO_FLAG; } }
/***************************************************************************** Name: flag_value_maximum( table, flag ) Purpose: Returns the value of the flags entered. Multi-flags accepted. if a bit doesn't exist, we don't return NO_FLAG, we continue Called by: olc.c and olc_act.c. ****************************************************************************/ long flag_value_maximum( struct flag_type *flag_table, const char *argument) { char word[MAX_INPUT_LENGTH]; long bit; long marked = 0; bool found = FALSE; FLAG_VALUE_ERROR = FALSE; if ( flag_table == NULL ) { bug("flag_value_maximum called with a NULL flag_table"); return NO_FLAG; } if ( fBootDb ) return flag_value_maximum_init( flag_table, argument ); if ( is_stat( flag_table ) ) return flag_lookup2(argument,flag_table); for (; ;) { argument = one_argument( argument, word ); if ( word[0] == '\0' ) return found?marked:NO_FLAG; if ( ( bit = flag_lookup2( word, flag_table ) ) != NO_FLAG ) { SET_BIT( marked, bit ); found = TRUE; } else FLAG_VALUE_ERROR = TRUE; } return marked; }
/***************************************************************************** Name: flag_string( table, flags/stat ) Purpose: Returns string with name(s) of the flags or stat entered. Called by: affects.c, act_olc.c, olc.c, and olc_save.c. ****************************************************************************/ const char *flag_string( struct flag_type *flag_table, long bits ) { static char buf[512]; int countBit = count_bit( bits ); int countWord = 0; buf[0] = '\0'; bool is_st = is_stat(flag_table); for (int flag = 0; flag_table[flag].name != NULL; flag++) { //if ( !is_stat( flag_table ) && IS_SET(bits, flag_table[flag].bit) ) { if ( !is_st && IS_SET(bits, flag_table[flag].bit) ) { strcat( buf, " " ); strcat( buf, flag_table[flag].name ); countWord++; } else if ( flag_table[flag].bit == bits ) { strcat( buf, " " ); strcat( buf, flag_table[flag].name ); countWord = countBit; // artifically set countWord to avoid entering bug test break; } } if ( countWord != countBit ) bug("Flag_String: invalid number of word: %d [%s], number of bits %d [flag = %ld (%s)] [table: %s]", countWord, buf[0] != 0 ? buf+1: "none", countBit, bits, convert_flag( bits), get_flag_table_name(flag_table) ); return (buf[0] != '\0') ? buf+1 : "none"; }
// format restrictions into a buffer void restrstring( char *buf, RESTR_DATA *restr ) { // Added by SinaC 2000 for skill/spell restriction //if ( restr->ability_r ) { if ( restr->type == RESTR_ABILITY ) { if ( restr->not_r == FALSE ) sprintf( buf, "requires at least %4d%% in %22s\n\r", restr->value, ability_table[restr->sn].name ); else sprintf( buf, "requires less than %4d%% in %22s\n\r", restr->value, ability_table[restr->sn].name ); } else { // Modified by SinaC 2000 // >= str, int, wis, dex, con if not_r not set // < if not_r set if ( restr_table[restr->type].bits == NULL ) { if ( restr->not_r == FALSE ) sprintf( buf, "requires at least %5d in %22s\n\r", restr->value, restr_table[restr->type].name ); else sprintf( buf, "requires less than %5d in %22s\n\r", restr->value, restr_table[restr->type].name ); } // = race, sex, [--size] if not_r not set // != if not_r set else if ( is_stat( restr_table[restr->type].bits ) ) { if ( restr->not_r == FALSE ) sprintf( buf, "requires %14s equals to %17s\n\r", restr_table[restr->type].name, flag_string( restr_table[restr->type].bits, restr->value ) ); else sprintf( buf, "requires %14s not equals to %16s\n\r", restr_table[restr->type].name, flag_string( restr_table[restr->type].bits, restr->value ) ); } // or parts, classes, form if not_r not set // nor if not_r set else { if ( restr->not_r == FALSE ) sprintf( buf, "requires %14s has %21s\n\r", restr_table[restr->type].name, flag_string( restr_table[restr->type].bits, restr->value )); else sprintf( buf, "requires %14s has not %21s\n\r", restr_table[restr->type].name, flag_string( restr_table[restr->type].bits, restr->value )); } } }
// Convert a flag into a string each word inside '' and separated by , const char *list_flag_string( const long flag, struct flag_type *flag_table, const char *quote, const char *separator ) { char buf2[MAX_STRING_LENGTH]; static char buf[MAX_STRING_LENGTH]; strcpy( buf2, flag_string( flag_table, flag ) ); if ( !str_cmp( buf2, "none") ) return str_dup( quotify("none",quote) ); int nb_space = 1; // if not bitvector -> only 1 value if ( !is_stat( flag_table ) ) // if bitvector -> count bit nb_space = count_bit( flag ); // number of words // log_stringf("table: %s nb_space: %d buf2: %s flag: %ld", get_flag_table_name(flag_table), nb_space, buf2, flag ); buf[0] = '\0'; char *s = buf2; char* tok = strsep(&s, " " ); int i = 0; while ( tok != NULL ) { if ( tok[0] != '\0' ) { //strcat( buf, bracket); //strcat( buf, tok ); //strcat( buf, bracket); strcat( buf, quotify( tok, quote ) ); if ( i < nb_space-1 ) // && tok != NULL && tok[0] != NULL ) strcat( buf, separator ); i++; } tok = strsep(&s, " " ); } if ( i != nb_space && !is_stat(flag_table) ) { bug("List_Flag_String: invalid number of word: %d, number of bits %d [flag = %ld] [table: %s]", i, nb_space, flag, get_flag_table_name(flag_table) ); buf[strlen(buf)-strlen(separator)] = '\0'; } return str_dup(buf); }
// Modified by SinaC 2001 bool check_one_restriction( CHAR_DATA *ch, RESTR_DATA *restr ) { // Added by SinaC 2000 for restriction on ability //if ( restr->ability_r ) { if ( restr->type == RESTR_ABILITY ) { if ( restr->not_r == FALSE ) { if ( get_ability( ch, restr->sn ) < restr->value ) return FALSE; } else if ( get_ability( ch, restr->sn ) >= restr->value ) return FALSE; } // If not an restriction on ability than it's a restriction on a stat else { // Modified by SinaC 2000 for NOT restriction // >= str, int, wis, dex, con, alig if not_r not set // < if not_r set if ( restr_table[restr->type].bits == NULL ) { if ( restr->not_r == FALSE ) { if ( ch->curattr[restr_attr[restr->type].bit] < restr->value ) return FALSE; } else if ( ch->curattr[restr_attr[restr->type].bit] >= restr->value ) return FALSE; } // = race, sex, etho if not_r not set // != if not_r set else if ( is_stat( restr_table[restr->type].bits ) ) { if ( restr->not_r == FALSE ) { if ( ch->curattr[restr_attr[restr->type].bit] != restr->value ) return FALSE; } else if ( ch->curattr[restr_attr[restr->type].bit] == restr->value ) return FALSE; } // or parts, classes, form if not_r not set // nor if not_r set else { if ( restr->not_r == FALSE ) { if (( ch->curattr[restr_attr[restr->type].bit] & restr->value ) != restr->value) return FALSE; } else if (( ch->curattr[restr_attr[restr->type].bit] & restr->value ) == restr->value) return FALSE; } } return TRUE; }
/***************************************************************************** Name: flag_string( table, flags/stat ) Purpose: Returns string with name(s) of the flags or stat entered. Called by: act_olc.c, olc.c, and olc_save.c. ****************************************************************************/ char *flag_string( const struct flag_type *flag_table, int bits ) { static char buf[512]; int flag; buf[0] = '\0'; for (flag = 0; *flag_table[flag].name; flag++) /* OLC 1.1b */ { if ( !is_stat( flag_table ) && IS_SET(bits, flag_table[flag].bit) ) { strcat( buf, " " ); strcat( buf, flag_table[flag].name ); } else if ( flag_table[flag].bit == bits ) { strcat( buf, " " ); strcat( buf, flag_table[flag].name ); break; } } return (buf[0] != '\0') ? buf+1 : "none"; }
// Return TRUE if the item can be worn, FALSE otherwise // if many restriction are done on an attributes requiring strict equality // we consider char must have one of this attributes // examples: restriction race == high-elf // race == grey-elf // race == sylvan-elf // if char's race is high-elf or grey-elf or sylvan-elf the test will be passed // restriction etho == lawful // etho == neutral // only chaotic char will not be able to wear this, equivalent to restriction etho != chaotic bool check_restriction( CHAR_DATA *ch, OBJ_DATA *obj ) { const int MAX_RESTRICTION = 16; // max 16 restrictions, first column gives nuber of restrictions long restriction_or[ATTR_NUMBER][1+MAX_RESTRICTION]; memset( restriction_or, 0, ATTR_NUMBER * (1+MAX_RESTRICTION) * sizeof(long) ); bool found = FALSE; // obj restriction: check non-stat restriction and store stat restriction // for ( RESTR_DATA *restr = obj->restriction; restr != NULL; restr = restr->next ) { // int type = restr->type; // // stat restriction: race, sex, etho // if ( restr_table[type].bits != NULL && is_stat( restr_table[type].bits ) ) { // int loc = restr_attr[type].bit; // if ( restr->not_r == FALSE ) {// if non not-restriction: store value // found = TRUE; // restriction_or[loc][++restriction_or[loc][0]] = restr->value; // } // else if ( ch->curattr[restr_attr[restr->type].bit] == restr->value ) // if not-restriction: just test // return FALSE; // } // else if (!check_one_restriction( ch, restr )) // return FALSE; // } // objIndex restriction: check non-stat restriction and store stat restriction // if (!obj->enchanted) for ( RESTR_DATA *restr = obj->pIndexData->restriction; restr != NULL; restr = restr->next ) { int type = restr->type; // stat restriction: race, sex, etho, ... if ( restr_table[type].bits != NULL && is_stat( restr_table[type].bits ) ) { int loc = restr_attr[type].bit; if ( restr->not_r == FALSE ) { // if non not-restriction: store value found = TRUE; restriction_or[loc][++restriction_or[loc][0]] = restr->value; } else if ( ch->curattr[restr_attr[restr->type].bit] == restr->value ) // if not-restriction: just test return FALSE; } // non-stat restriction else if (!check_one_restriction( ch, restr )) return FALSE; } if ( !found ) return TRUE; // Check stored stat-restriction for ( int i = 0; i < ATTR_NUMBER; i++ ) if ( restriction_or[i][0] > 0 ) { bool ok = FALSE; // stat-restriction for ( int j = 0; j < restriction_or[i][0]; j++ ) if ( ch->curattr[i] == restriction_or[i][1+j] ) { // value equal, 1+ because first column gives # ok = TRUE; break; } if ( !ok ) // if current char value is not in stored stat-restriction, restriction test failed return FALSE; } return TRUE; }