Search in sources :

Example 1 with ProtocolType

use of net.glowstone.net.protocol.ProtocolType in project Glowstone by GlowstoneMC.

the class HandshakeHandler method handle.

@Override
public void handle(GlowSession session, HandshakeMessage message) {
    ProtocolType protocol;
    if (message.getState() == 1) {
        protocol = ProtocolType.STATUS;
    } else if (message.getState() == 2) {
        protocol = ProtocolType.LOGIN;
    } else {
        session.disconnect("Invalid state");
        return;
    }
    session.setVersion(message.getVersion());
    session.setHostname(message.getAddress() + ":" + message.getPort());
    // the client's UUID and (optionally) properties
    if (session.getServer().getProxySupport()) {
        try {
            session.setProxyData(new ProxyData(session, message.getAddress()));
        } catch (IllegalArgumentException ex) {
            session.disconnect("Invalid proxy data provided.");
            // protocol is still set here and below to prevent errors
            // trying to decode packets after this one under the wrong
            // protocol, even though client is kicked
            session.setProtocol(protocol);
            return;
        } catch (Exception ex) {
            GlowServer.logger.log(Level.SEVERE, "Error parsing proxy data for " + session, ex);
            session.disconnect("Failed to parse proxy data.");
            session.setProtocol(protocol);
            return;
        }
    }
    session.setProtocol(protocol);
    if (protocol == ProtocolType.LOGIN) {
        if (message.getVersion() < GlowServer.PROTOCOL_VERSION) {
            session.disconnect("Outdated client! I'm running " + GlowServer.GAME_VERSION);
        } else if (message.getVersion() > GlowServer.PROTOCOL_VERSION) {
            session.disconnect("Outdated server! I'm running " + GlowServer.GAME_VERSION);
        }
    }
}
Also used : ProxyData(net.glowstone.net.ProxyData) ProtocolType(net.glowstone.net.protocol.ProtocolType)

Aggregations

ProxyData (net.glowstone.net.ProxyData)1 ProtocolType (net.glowstone.net.protocol.ProtocolType)1