[SOLVED] Sim-eth-es chat service, where to hook for parsing commands

@pspeed : What would be the place in sim-eth-es to intercept client chat message and try parsing them (for commands that are not chat-messages). Say the client can send commands like /exitgame or /exittomainmenu etc.

I guess the server side hosted chat session that sends the message could parse and then decide to relay message to other chatters or not (based on being a chat or a command):

    @Override
    public void sendMessage(String message) {
        //Something like here
        postMessage(this, message);
    }

Also: I tried finding the reference to the getPlayerNames chat session interface, but I can’t seem to find where its called. I wondered if its a chat command of some sorts, that I could mimic in my case.

Cheers.

There is no built in support for this. If you wanted to intercept chat messages on the server then you’d fork the ChatHostedService to add this.

Okay. I guess the intercept should start on the client, in case the command is client-centric (if not, then call rmi on hostedchatservice). Adding a sendCommand rmi interface method.

I wouldn’t even bother with that. In Mythruna, if the client doesn’t handle it then I send it on through as a chat message. Start a change message with / and it will try the client first… then the server will get a crack. Start a command with ~ and the server always gets it.

…which was the advantage to not having a special sendCommand() since the client doesn’t even look for ~… and the server just looks for any change message starting with / or ~.

2 Likes

Reviving an old topic to see if I got this right (now that I get to this part in my game)

If I understand you right, I’d hook in here:

   public class ChatHostedService extends AbstractHostedConnectionService {
        ...
        protected void postMessage( ChatSessionImpl from, String message ) {
            //Test for command here <----
            log.info("chat> " + from.name + " said:" + message);
            for( ChatSessionImpl chatter : players ) {
                chatter.newMessage(from.conn.getId(), from.name, message);
            }
        }
        ...
    }

And here

public class ChatClientService
...
    @Override
    public void sendMessage( String message ) {
        //Test for command here <----
        getDelegate().sendMessage(message);
    }
...
}

On the client you’d only need to check for commands if there were client-side only commands. Else you send everything through to the server and let it sort things out.

In Mythruna, I do have both… with / indicating either a client or server command (if defined on client it will run on client else pass on) and ~ indicating always a server command (useful for disambiguating in cases like /mem or /gc where as an admin I can potentially run them on both).

1 Like

Clever :slight_smile: