Echo of input command break the output line

Posted by Jcl on Wed 29 Jul 2015 09:04 AM — 10 posts, 32,945 views.

#0
When receiving plenty of lines from the server, the echo of the input command probebly break a output line into two.
USA Global Moderator #1
Probably?
Australia Forum Administrator #2
Input lines arrive in packets. It is possible that if you type something, and have it echoed, the client would think that the last packet has finished, terminate that line, and then echo your command.

There is no way it can know there is more data coming "soon".

What you could do is make a plugin which handles OnPluginPacketReceived, and batch up incoming lines as they arrive, and only "release" them once a newline is found. That would stop lines being split up.

The bad part is that you wouldn't see "prompts", like when you first connect and it asks your name and password. You could disable the plugin on world connect, or have a flag to tell it not to do it until 20 seconds after connecting, or until a certain line has arrived, for example.

There are examples of batching up lines on this site.
#3
Although there is no way it can know there is more data coming "soon", but you have the ability to know if the packets is coming currently or not.
If not coming currently then echo it immediately, otherwise echo it after a newline.
Australia Forum Administrator #4
User input (command input) is not echoed back during the processing of a packet.
#5
Nick Gammon said:

User input (command input) is not echoed back during the processing of a packet.


I think you should be able to judge whether there was a packet arrived within the past one millisecond.
If not so then echo it immediately, otherwise echo it after a newline.
Australia Forum Administrator #6
What? You want me to know whether a packet arrives in the future, not the past.

I can't tell whether or not another packet will arrive in one millisecond, 100 ms or 5 minutes. And if I build in any sort of delay everyone is going to whine that the client does not show data as soon as it arrives.
#7
I said that "arrived within the past one millisecond."
Is it ambiguous? I am very sorry for that.
I meant the past, not the future.
Australia Forum Administrator #8
Quote:

If not so then echo it immediately, otherwise echo it after a newline.


If I understand you correctly, you are saying to wait for a newline before echoing the packet. However that won't work for prompts when the MUD asks:


What is your name?


With no newline.

And it's no good saying "only do that if another packet is going to come in a millisecond" - how do I know that?
#9
I am very sorry for the ambiguous meaning. I try to express more clearly.

When user typed input command, If no packets were received in the past one millisecond, the input command should be echoed immediately. If there were any packets received in the past one millisecond, the input command should be echoed after a newline.

I write some simple code to explain.

On Packet Received:

long lastPacketTime = GetSystemTimeInMilliseconds();
if (cacheOfInputCommand.size() > 0) {
    int newLinePos = packetStr.find_first_of(NEW_LINE_CHAR);
    if (newLinePos != string:npos) {
        DisplayOutput(packetStr, 0, newLinePos);
        DisplayNewLine();
        EchoInputCommand(); // echo the input command after the newline.
        DisplayOutput(packetStr, newLinePos, packetStrLength);
    } else {
        DisplayOutput(packetStr, 0, packetStrLength);
    }
} else {
    DisplayOutput(packetStr, 0, packetStrLength);
}


On Input Command:

if (lastPacketTime < GetSystemTimeInMilliseconds() - 1) {
    EchoInputCommand(); // echo the input command immediately
} else {
    CacheInputCommand(); // put the input command into cacheOfInputCommand for later use. see OnPacketReceived.
}