if (!(m instanceof ProtocolSelectionMessage)) {
sendError(m, "Only ProtcolSelectionMessage allowed");
return;
}
ProtocolSelectionMessage psm = (ProtocolSelectionMessage) m;
CommsManager cm = WonderlandContext.getCommsManager();
// see if we have a protocol to match the request
CommunicationsProtocol cp = cm.getProtocol(psm.getProtocolName());
if (cp == null) {
sendError(m, "Protocol " + psm.getProtocolName() + " not found");
return;
}
// see if the versions match
if (!cp.getVersion().isCompatible(psm.getProtocolVersion())) {
sendError(m, "Client version incompatible with server " +
"version " + cp.getVersion());
}
ClientSession session = getSession();
logger.info("Session " + session.getName() + " connected with " +
"protocol " + cp.getName());
// all set -- set the wrapped session
wrapped = cp.createSessionListener(session, psm.getProtocolVersion());
if (wrapped instanceof ManagedObject) {
wrapped = new ManagedClientSessionWrapper(wrapped);
}
// TODO: is this the right thing to do, or should we only
// do this automatically for the Wonderland protocol?
WonderlandClientID clientID = new WonderlandClientID(session);
WonderlandContext.getUserManager().login(clientID);
// record the client connection
this.protocol = cp;
recordConnect(cp, session);
// send an OK message
sendToSession(new OKMessage(psm.getMessageID()));
} catch (PackerException eme) {
sendError(eme.getMessageID(), null, eme);
}
}