Bug - Fixed Long chat lines not split in /clan, truncated by KoL

Atheist Nutter

New member
KoL chat truncates long chat lines at the server (where "long" means "longer than about 256 characters"). The KoLmafia chat interface splits long lines into multiple shorter chat submissions to prevent this. This works in PMs or normal chat channels, but it does not happen in /clan, resulting in long chat lines being truncated. I think that the sender is unaware that this has happened (i.e. they see the entire message in their chat UI), but I haven't tested this.

This occurs around net/sourceforce/kolmafia/chat/ChatSender.java:268. If the message is being sent to /clan, then this condition passes regardless of the length of the line, which results in the chat line being sent in a single submission and therefore being truncated by KoL.
 

lostcalpolydude

Developer
Staff member
I think that line (now line 285) could just be a check of message.length() <= 256, but I don't know what KoL does with a long line with chained commands (using &&) and I really don't understand what circumstance would lead to contact == null, especially since that looks like it should result in an NPE in getGraf() and I don't think there are any bug reports for that.
 

Veracity

Developer
Staff member
As you point out:

Code:
		if ( message.length() <= 256 || contact == null || contact.equals( "/clan" ) || message.indexOf( " && " ) != -1 )
		{
			String graf = ChatSender.getGraf( contact, message );

			if ( graf != null )
			{
				grafs.add( graf );
			}

			return grafs;
		}
It is hardcoded to not split messages to /clan. We surely can remove that predicate from the conditional.
I'll think about the others.
 

Veracity

Developer
Staff member
I think that line (now line 285) could just be a check of message.length() <= 256, but I don't know what KoL does with a long line with chained commands (using &&) and I really don't understand what circumstance would lead to contact == null, especially since that looks like it should result in an NPE in getGraf() and I don't think there are any bug reports for that.
- contact can be null for internal requests like this:

Code:
			ChatSender.sendMessage( null, "/listen", true );
- I suspect that if KoL truncates its input at 256 characters that sending a too-long line of chained commands will not be successful. If we want to support that, we'd need to break up the line at an && or something. Until and unless we do that, perhaps we should just punt if given such a line which is too long.

- I see no reason to NOT split lines for /clan, as the OP requests.
 

Veracity

Developer
Staff member
I just did an experiment. With 1 tiny house in inventory:

/closet tiny house && /use tiny house && /uncloset tiny house

resulted in:

Closeting 1 tiny house.
Using 1 tiny house.
Un-closeting 1 tiny house.
in the chat pane, and:

Code:
Results:
You take something out of your closet.
You acquire an item: tiny house [use]

Results:
You don't have the item you're trying to use.

Results:
One tiny house placed in your closet.
in the main pane.

So, the "&&" is not actually a McCarthy AND (like ASH and other C-like languages have) but is just a command separator. Unlike KoLmafia's CLI, KoL does not seem to have a continuation code which will abort processing upon an error. (Admittedly, that's a very small test; I almost never use chat commands to do things that I can do in the gCLI.)

Now, if && had been a McCarthy AND, we'd have had to simply issue an error message or something if you tried to give too-long a line of chained commands, since we couldn't know whether it was going to abort in the middle. But if KoL just blithely executes chained commands regardless of the success or failure of previous one, we can split such a line on && boundaries. Or perhaps we could split the whole line into commands on " && " and reassemble a series of shorter lines with commands separated by &&.

Anybody here uses chat commands a lot and knows a reason we shouldn't split long lines of chained commands like this?
 

lostcalpolydude

Developer
Staff member
It's possible that someone has made a clever chat macro that depends on failures of stuff in the middle. I can't think of how that would be done, and it seems crazy and unlikely, and shouldn't be worried about.
 

Veracity

Developer
Staff member
Ha. I did this:

/closet tiny house && /use tiny house && /use tiny house && ... 20 in all ...

KoLmafia split it into two strings. The first one had the "/closet" command and 12 of the "/use" commands. The second one had the remaining 8 "/use" commands.

I got this:

Closeting 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.
Using 1 tiny house.

Sorry, I can't figure out which item you mean. That may be an item you don't have, or need to click directly. ("tiny house")
Sorry, I can't figure out which item you mean. That may be an item you don't have, or need to click directly. ("tiny house")
Sorry, I can't figure out which item you mean. That may be an item you don't have, or need to click directly. ("tiny house")
Sorry, I can't figure out which item you mean. That may be an item you don't have, or need to click directly. ("tiny house")
Sorry, I can't figure out which item you mean. That may be an item you don't have, or need to click directly. ("tiny house")
Sorry, I can't figure out which item you mean. That may be an item you don't have, or need to click directly. ("tiny house")
Sorry, I can't figure out which item you mean. That may be an item you don't have, or need to click directly. ("tiny house")
Sorry, I can't figure out which item you mean. That may be an item you don't have, or need to click directly. ("tiny house")
So, KoL does keep some funky state.

The first request:

Code:
Requesting: http://www.kingdomofloathing.com/submitnewchat.php?pwd&playerid=115875&graf=%2Fcloset+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house
Retrieved: http://www.kingdomofloathing.com/submitnewchat.php?pwd&playerid=115875&graf=%2Fcloset+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house
ResponseText has 1824 characters.
<font color=green>Closeting 1 tiny house.<!--js(dojax('inventory.php?whichitem=592&pwd=5e869f90b3419eaf37ada4bd4860833d&action=closetpush&qty=1&ajax=1');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br><font color=green>Using 1 tiny house.<!--js(dojax('inv_use.php?whichitem=592&ajax=1&pwd=5e869f90b3419eaf37ada4bd4860833d');)--></font><br>
...which resulted in the browser submitting the closetpush and 12 inv_use requests.

The second request:

Code:
Requesting: http://www.kingdomofloathing.com/submitnewchat.php?pwd&playerid=115875&graf=%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house
Retrieved: http://www.kingdomofloathing.com/submitnewchat.php?pwd&playerid=115875&graf=%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house+%26%26+%2Fuse+tiny+house
ResponseText has 1232 characters.
<font color=green>Sorry, I can't figure out which item you mean.  That may be an item you don't have, or need to click directly. ("tiny house")</font><br><font color=green>Sorry, I can't figure out which item you mean.  That may be an item you don't have, or need to click directly. ("tiny house")</font><br><font color=green>Sorry, I can't figure out which item you mean.  That may be an item you don't have, or need to click directly. ("tiny house")</font><br><font color=green>Sorry, I can't figure out which item you mean.  That may be an item you don't have, or need to click directly. ("tiny house")</font><br><font color=green>Sorry, I can't figure out which item you mean.  That may be an item you don't have, or need to click directly. ("tiny house")</font><br><font color=green>Sorry, I can't figure out which item you mean.  That may be an item you don't have, or need to click directly. ("tiny house")</font><br><font color=green>Sorry, I can't figure out which item you mean.  That may be an item you don't have, or need to click directly. ("tiny house")</font><br><font color=green>Sorry, I can't figure out which item you mean.  That may be an item you don't have, or need to click directly. ("tiny house")</font><br>
... resulted in error messages.

I think I'm OK with that; I assume that if all of the commands had been valid, KoL would have turned all of them into requests as expected.

This is definitely an abnormal case, anyway.
 

Lord_Kobel

Member
Is this why relay chat is now missing line breaks between the end of one persons chat and the name of the next person?
 

Ethelred

Member
Is this why relay chat is now missing line breaks between the end of one persons chat and the name of the next person?

I've started seeing that too, after updating to r14812. I also saw an instance when a private (blue) msg got tacked onto the end of another msg in the current chat pane instead of getting posted in the tab for the recipient. I should mention that I only use browser chat, not mafia chat, and that I use "Older Chat (an old friend)" in the KoL options and the ActiveChat 2 v3.01 greasemonkey script with Firefox 26.0 running on Mac OSX 10.9.5.
 

lostcalpolydude

Developer
Staff member
Can someone reproduce it without ActiveChat running? It might be making invalid assumptions about chat HTML that it isn't up to mafia to fix.

Edit: Never mind, I'm seeing that in Older Chat too.
 
Top