Fixed alias saving bug and oedit setting to type undefined --Rumble

This commit is contained in:
Rumble
2010-07-03 02:24:47 +00:00
parent 4b44a1a097
commit ab4d9c618e
3 changed files with 35 additions and 30 deletions

View File

@@ -35,6 +35,9 @@ export (QQ's a zone into a tarball)
Xlist (mlist, olist, rlist, zlist, slist, tlist, qlist) Xlist (mlist, olist, rlist, zlist, slist, tlist, qlist)
(lots of major bugfixes too) (lots of major bugfixes too)
@ @
[Jul 03 2010] - Rumble
Fixed oedit to allow setting of UNDEFINED object type. (thanks Tink)
Fixed alias bug from using * as first character. (thanks Dio)
[Jun 20 2010] - Rumble [Jun 20 2010] - Rumble
Fixed two memory leaks. (thanks Dio) Fixed two memory leaks. (thanks Dio)
[Jum 19 2010] - Fizban [Jum 19 2010] - Fizban

View File

@@ -868,7 +868,7 @@ void oedit_parse(struct descriptor_data *d, char *arg)
case OEDIT_TYPE: case OEDIT_TYPE:
number = atoi(arg); number = atoi(arg);
if ((number < 1) || (number >= NUM_ITEM_TYPES)) { if ((number < 0) || (number >= NUM_ITEM_TYPES)) {
write_to_output(d, "Invalid choice, try again : "); write_to_output(d, "Invalid choice, try again : ");
return; return;
} else } else

View File

@@ -912,7 +912,6 @@ static void load_HMVS(struct char_data *ch, const char *line, int mode)
} }
} }
/* Aliases are now saved in pfiles only. */
static void write_aliases_ascii(FILE *file, struct char_data *ch) static void write_aliases_ascii(FILE *file, struct char_data *ch)
{ {
struct alias_data *temp; struct alias_data *temp;
@@ -925,45 +924,48 @@ static void write_aliases_ascii(FILE *file, struct char_data *ch)
count++; count++;
fprintf(file, "Alis: %d\n", count); fprintf(file, "Alis: %d\n", count);
/* the +1 thing below is due to alias replacements having a space prepended
* * in memory. The reason for this escapes me. Welcor 27/12/06 */ for (temp = GET_ALIASES(ch); temp; temp = temp->next)
for (temp = GET_ALIASES(ch); temp; temp = temp->next) { fprintf(file, " %s\n" /* Alias: prepend a space in order to avoid issues with aliases beginning
fprintf(file, "%s\n" /* Alias */ * with * (get_line treats lines beginning with * as comments and ignores them */
"%s\n" /* Replacement */ "%s\n" /* Replacement: always prepended with a space in memory anyway */
"%d\n", /* Type */ "%d\n", /* Type */
temp->alias, temp->alias,
temp->replacement+1, temp->replacement,
temp->type); temp->type);
} }
}
static void read_aliases_ascii(FILE *file, struct char_data *ch, int count) static void read_aliases_ascii(FILE *file, struct char_data *ch, int count)
{ {
int i; int i;
struct alias_data *temp;
char abuf[MAX_INPUT_LENGTH], rbuf[MAX_INPUT_LENGTH+1], tbuf[MAX_INPUT_LENGTH];
if (count == 0) { if (count == 0) {
GET_ALIASES(ch) = NULL; GET_ALIASES(ch) = NULL;
return; /* No aliases in the list. */ return; /* No aliases in the list. */
} }
/* This code goes both ways for the old format (where alias and replacement start at the
* first character on the line) and the new (where they are prepended by a space in order
* to avoid the possibility of a * at the start of the line */
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
char abuf[MAX_INPUT_LENGTH+1], rbuf[MAX_INPUT_LENGTH+1], tbuf[MAX_INPUT_LENGTH];
/* Read the aliased command. */ /* Read the aliased command. */
get_line(file, abuf); get_line(file, abuf);
/* Read the replacement. */ /* Read the replacement. This needs to have a space prepended before placing in
get_line(file, tbuf); * the in-memory struct. The space may be there already, but we can't be certain! */
strcpy(rbuf, " "); rbuf[0] = ' ';
strcat(rbuf, tbuf); /* strcat: OK */ get_line(file, rbuf+1);
/* read the type */ /* read the type */
get_line(file, tbuf); get_line(file, tbuf);
if (*abuf && *tbuf && *rbuf) { if (abuf[0] && rbuf[1] && *tbuf) {
struct alias_data *temp;
CREATE(temp, struct alias_data, 1); CREATE(temp, struct alias_data, 1);
temp->alias = strdup(abuf); temp->alias = strdup(abuf[0] == ' ' ? abuf+1 : abuf);
temp->replacement = strdup(rbuf); temp->replacement = strdup(rbuf[1] == ' ' ? rbuf+1 : rbuf);
temp->type = atoi(tbuf); temp->type = atoi(tbuf);
temp->next = GET_ALIASES(ch); temp->next = GET_ALIASES(ch);
GET_ALIASES(ch) = temp; GET_ALIASES(ch) = temp;