Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Yandex, Sogou, Bing, DotBot

Members: 0
Guests: 8
Stats
Files
Topics
Posts
Members
Newest Member
477
3,705
19,232
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SWFOTE FUSS » Problem with an old bugfix
Forum Rules | Mark all | Recent Posts

Problem with an old bugfix
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 May 14, 2006, 3:59 pm   Last edited May 14, 2006, 4:08 pm by Keberus
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

Quite some time ago Samson you posted a bugfix titled. "cedit will let you rename a command using a name that's taken". Which was true so I implemented your fix without even giving it a second glance. I had no problems until today. I realized that at least in FotE find command is written like so...
CMDTYPE *find_command( char *command )
{
    CMDTYPE *cmd;
    int hash;

    hash = LOWER(command[0]) % 126;

    for ( cmd = command_hash[hash]; cmd; cmd = cmd->next )
        if ( !str_prefix( command, cmd->name ) )
            return cmd;

    return NULL;
}


Notice the str_prefix part. Anyways I noticed this because I was trying to add in a function called simply "show" but the code kept already finding commands. The code would pick up showstarsystem, showship, etc... and then said that "The command already existed". Anyways the fix is hella simple. Add in another function that uses str_cmp for find_command and find_social.

So this is my find_command_exact that I only call in cedit.
CMDTYPE *find_command_exact( char *command )
{
    CMDTYPE *cmd;
    int hash;

    hash = LOWER(command[0]) % 126;

    for ( cmd = command_hash[hash]; cmd; cmd = cmd->next )
        if ( !str_cmp( command, cmd->name ) )
            return cmd;

    return NULL;
}


This is the find_social_exact only called in sedit:
SOCIALTYPE *find_social_exact( char *command )
{
    SOCIALTYPE *social;
    int hash;

    if ( command[0] < 'a' || command[0] > 'z' )
        hash = 0;
    else
        hash = (command[0] - 'a') + 1;

    for ( social = social_index[hash]; social; social = social->next )
        if ( !str_cmp( command, social->name ) )
            return social;

    return NULL;
}


EDIT: Almost forgot in sedit and cedit, in the creation part AND setting a diff name part, replace find_social and find_command with find_social_exact and find_command_exact.


Later,
KeB

       
Post is unread #2 May 14, 2006, 4:15 pm
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

After doing the above I was able to add in the command. But other commands were still being found in the hash table and getting returned first. So I went back and modified find_command and find_social to look like.

CMDTYPE *find_command( char *command )
{
    CMDTYPE *cmd;
    int hash;

    hash = LOWER(command[0]) % 126;

    for ( cmd = command_hash[hash]; cmd; cmd = cmd->next )
        if ( !str_cmp( command, cmd->name ) )
            return cmd;

    for ( cmd = command_hash[hash]; cmd; cmd = cmd->next )
        if ( !str_prefix( command, cmd->name ) )
            return cmd;

    return NULL;
}


SOCIALTYPE *find_social( char *command )
{
    SOCIALTYPE *social;
    int hash;

    if ( command[0] < 'a' || command[0] > 'z' )
        hash = 0;
    else
        hash = (command[0] - 'a') + 1;

    for ( social = social_index[hash]; social; social = social->next )
        if ( !str_cmp( command, social->name ) )
            return social;

    for ( social = social_index[hash]; social; social = social->next )
        if ( !str_prefix( command, social->name ) )
            return social;

    return NULL;
}


That way it will look for an exact match before looking for a prefix of the match.

Later,
KeB
       
Post is unread #3 May 14, 2006, 4:27 pm   Last edited May 15, 2006, 3:57 am by Keberus
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

Grrr....Lots of issues with this for some reason. Still didnt work. So I looked through interpret and found:

   for ( cmd = command_hash[LOWER(command[0])%126]; cmd; cmd = cmd->next )
            if ( !str_prefix( command, cmd->name )
            &&   (cmd->level <= trust
            ||  (!IS_NPC(ch) && ch->pcdata->bestowments && ch->pcdata->bestowments[0] != '\0'
            &&    is_name( cmd->name, ch->pcdata->bestowments )
            &&    cmd->level <= (trust+5)) ) )
            {
                found = TRUE;
                break;
            }


and changed it to:
        if( ( cmd = find_command( command ) ) != NULL )
        {
            if ( (cmd->level <= trust
            ||  (!IS_NPC(ch) && ch->pcdata->bestowments && ch->pcdata->bestowments[0] != '\0'
            &&    is_name( cmd->name, ch->pcdata->bestowments )
            &&    cmd->level <= (trust+5)) ) )
            {
                found = TRUE;
            }
        }


Now it FINALLY works. My biggest question. Is there anything wrong with what I did. Or should I change it in a different way. Does anyone think something wont work correctly now?

BTW: It looks like the same thing DOES NOT have to be done for socials(for this step).


Later,
KeB
       
Post is unread #4 May 14, 2006, 6:09 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

I don't think it was necessary to go to that much trouble to overcome the problem. The protection is only meant to stop you from renaming a command the same exact thing as another command. So it probably should be fine just altering the code for the original fix to check the exact name.
       
Post is unread #5 May 15, 2006, 3:17 am   Last edited May 15, 2006, 3:56 am by Keberus
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

Samson said:

I don't think it was necessary to go to that much trouble to overcome the problem. The protection is only meant to stop you from renaming a command the same exact thing as another command. So it probably should be fine just altering the code for the original fix to check the exact name.

Sorry, maybe I didn't fully explain. The first post fixed the adding of the command. which was good. But then the wrong command was still being retrieved via find_command because even though show was now in when I typed show...it would bring up the syntax for showship. I applied the second fix, thinking it would correct the problem. But to my surprise it didn't. So I found that the actual finding of the command isnt even ran through find_command at all in the interp function. Instead it just runs through the hash table trying to find any prefix that matches. Which it seems that showship was always found first. Even renaming showship to shipshow ...then typing show it found showstarsystem. I found that modifying the interp function, after the find_command modification was the only way to actually fix the problem. If you don't believe me though go ahead and try adding in a function with the full name being part of another functions name, then try usng that function.

Then again, I could be wrong.

KeB
       
Post is unread #6 May 15, 2006, 8:02 am   Last edited May 15, 2006, 8:30 am by Remcon
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,858
JoinedJul 26, 2005

Not sure about how that works on SWFOTE, but at least in Smaug you use cedit <command> [raise/lower] to modify where its at in the hash table :)
If your talking about when you change the command name it not redoing its spot in the hash table that part is only done if the first letter of the old name and the first letter of the new name arent the same. You could of course make it always relocate the command after the command name was changed. If your talking about when you create a new command then you probably need to make add_command insert it differently into the list so it ends up in the correct spot.
Smaug does have the same problem since the same find_command was used when creating etc...
Personaly for the create part of cedit I made it recheck arg1 for find_exact_command (function similar to your find_command_exact) before it told you the command was already used. If you just change find_command where it orginaly gets the command it will mean you always have to use the exact name to edit a command and some might find that annoying. On changing the name that was simple just changed find_command to find_exact command there. As for the list deal since in smaug you can already raise/lower it I didn't bother with making it always relocate it and it will only do so like i said if the first letter of the name has changed. As for on creation it already sorts it into the list.
Since socials dont have the raise/lower might be best to either add them or make it always relocate it after a name change :)
       
Post is unread #7 May 15, 2006, 1:31 pm
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

Ahh...just downloaded a copy of smaugfuss to understand exactly what you were talking about. FotE doesn't have a raise/lower option in cedit like smaugfuss has. Gonna put that in my mud now.

Later,
KeB
       
Pages:<< prev 1 next >>