Bug - Fixed get_player_id() doesn't work for specific player

Geistbar

New member
I was writing a script to help skf manage her PvP contest, and I noticed that get_player_id() does not return the player ID for at least one player: mystik spiral.

It works as expected for every other name I run through it, including other names with spaces:

Code:
> ashq print(get_player_id($string[giestbar]))

118499

> ashq print(get_player_id($string[Honus Carbuncle]))

455727

But when I use her account name I get:
Code:
> ashq print(get_player_id($string[mystik spiral]))

mystik spiral (#2585449), fluffed her hair 29 times today
This player is currently online in channel newbie and listening to clan, games, pvp, talkie and trade.

mystik spiral

Ultimately the function just returns the string of her account name. I brute forced the proper integer for my own script, but I figured it would be best practice to report the bug.

Using mafia version r16908, and I've also seen the bug on earlier releases.
 

Bale

Minion
Confirmed, This really doesn't make much sense to me.

BTW, I noticed that the error was the only example that he managed to match the player's preferred capitalization, so I tried a new example at the end.

CLI said:

> ash get_player_id("giestbar")

Giestbar (#118499), Typed "Geistbar" wrong 255 times today
This player is currently online in channel clan and listening to dread.


Returned: 118499

> ash get_player_id("Honus Carbuncle")

hOnus carbuncle (#455727), Real Hero
This player is currently away from KoL in channel clan and listening to challenge, hardcore, newbie, pvp, talkie and trade.


Returned: 455727

> ash get_player_id("mystik spiral")

mystik spiral (#2585449), fluffed her hair 29 times today
This player is currently online in channel newbie and listening to clan, games, pvp, talkie and trade.


Returned: mystik spiral

> ash get_player_id("MYstik Spiral")

mystik spiral (#2585449), fluffed her hair 29 times today
This player is currently online in channel newbie and listening to clan, games, pvp, talkie and trade.


Returned: MYstik Spiral
 
Last edited:

Veracity

Developer
Staff member
Code:
[color=green]> ashq print( get_player_id( "mystik spiral" ) )

mystik spiral (#2585449), fluffed her hair 29 times today
This player is currently online in channel newbie and listening to clan, games, pvp, talkie and trade.[/color]

mystik spiral

[color=green]> ashq print( get_player_id( "mystik spiral " ) )[/color]

2585449
She has a space at the end and when you make a string literal using $string, it "trims" each string.

That said, I don't understand why it can't just parse the response and get the ID.
 

Bale

Minion
Huh. I didn't realize it was even possible for a player to have a space at the end of their name. How did you figure out she did that?
 

heeheehee

Developer
Staff member
She has a space at the end and when you make a string literal using $string, it "trims" each string.

That said, I don't understand why it can't just parse the response and get the ID.

Looking at the kolmafia.session.ContactManager, I see
Code:
	public static final String getPlayerId( final String playerName, boolean retrieveId )
	{
		if ( playerName == null )
		{
			return null;
		}

		String playerId = (String) ContactManager.seenPlayerIds.get( playerName.toLowerCase() );

		if ( playerId != null )
		{
			return playerId;
		}

		if ( !retrieveId )
		{
			return playerName;
		}

		ChatSender.executeMacro( "/whois " + playerName );

		return ContactManager.getPlayerId( playerName, false );
	}

It looks like Mafia's doing the /whois to retrieve the ID, storing the username as "mystik spiral ", and then failing to find "mystik spiral" in seenPlayerIds and therefore returning playerName.

I guess a hack for this particular instance would be to trim names before storing in seenPlayerIds (as done by registerPlayerId).
 

Ulti

Member
I ran into this issue with the player "I am I " due to his tailing space, so I wrote a workaround fix like so:
Code:
ash string safe_get_player_id(string playerName){string p = get_player_id(playerName);return (p == playerName)?get_player_id(playerName+" "):p;};safe_get_player_id("i am i")
It will suffice for now until this bug is fixed. Not sure if it's possible for there to be two players "I am I" and "I am I " but I know a player "I_AM_I" exists thus if someone tries to /msg "I am I" by converting the spaces to underscores, they wind up messaging "I_AM_I" a completely different player id.

Edit:
I just created a character "tailing space ". I then tried to create a character "tailing space" but it failed. I also tried "tailing_space" and "tailing_space_" and "tailing_space " and "tailing_space " all of which it said were taken.
I then created a character "tailing_space2". Then I tried creating "tailing_space2 " and "tailing space2" both of which said it was taken. Then I tried "tailing space2 " and "tailing_space2_" both were available. So I created "tailing space2 ".

Thus I now have "tailing_space2" (#2787840) and "tailing space2 " (#2787844).
Typing "/whois tailing_space2" as well as "/whois tailing_space2 " gives #2787840
Typing "/whois tailing space2" as well as "/whois tailing space2 " gives #2787844

Conclusion: you can't have two players existing, one with a tailing space and one without, unless they have some other kind of difference in their player name such as an underscore.
So trimming the tailing space for mafia storage seems like a valid solution as there can't exist another player without the tailing space, or just sending "get_player_id" a tailing extra space for any player is a valid workaround/solution as a player can't have two consecutive spaces in a row, but then that would be executing unnecessary /whois commands due to seenPlayerIds look up fails.

I guess a hack for this particular instance would be to trim names before storing in seenPlayerIds (as done by registerPlayerId).
That sounds like it would be a perfect solution as per my above research.
 
Last edited:
Top