/** * Gets a player. * * @param name The player name. * @return The player object. */ public PlayerData getPlayer(String name) { name = NameUtils.formatNameForProtocol(name); Node n = getPlayersNode(name); if (n == null) { return null; } return n.getPlayer(name); }
/** * Handles an incoming packet. * * @param packet The incoming packet. */ public void handlePacket(LoginPacket packet) { final IoBuffer buf = packet.getPayload(); switch (packet.getOpcode()) { case LoginPacket.CHECK_LOGIN: { final String name = NameUtils.formatNameForProtocol(IoBufferUtils.getRS2String(buf)); final String password = IoBufferUtils.getRS2String(buf); final LoginResult res = server.getLoader().checkLogin(new PlayerDetails(null, name, password, 0, null, null)); if (res.getReturnCode() == 2) { final PlayerData pd = new PlayerData(name, res.getPlayer().getRights().toInteger()); NodeManager.getNodeManager().register(pd, this); } final IoBuffer resp = IoBuffer.allocate(16); resp.setAutoExpand(true); IoBufferUtils.putRS2String(resp, name); resp.put((byte) res.getReturnCode()); resp.flip(); session.write(new LoginPacket(LoginPacket.CHECK_LOGIN_RESPONSE, resp)); break; } case LoginPacket.LOAD: { final String name = NameUtils.formatNameForProtocol(IoBufferUtils.getRS2String(buf)); final Player p = new Player(new PlayerDetails(null, name, "", 0, null, null)); final int code = server.getLoader().loadPlayer(p) ? 1 : 0; final IoBuffer resp = IoBuffer.allocate(1024); resp.setAutoExpand(true); IoBufferUtils.putRS2String(resp, name); resp.put((byte) code); if (code == 1) { final IoBuffer data = IoBuffer.allocate(16); data.setAutoExpand(true); p.serialize(data); data.flip(); resp.putShort((short) data.remaining()); resp.put(data); } resp.flip(); session.write(new LoginPacket(LoginPacket.LOAD_RESPONSE, resp)); break; } case LoginPacket.SAVE: { final String name = NameUtils.formatNameForProtocol(IoBufferUtils.getRS2String(buf)); final int dataLength = buf.getUnsignedShort(); final byte[] data = new byte[dataLength]; buf.get(data); final IoBuffer dataBuffer = IoBuffer.allocate(dataLength); dataBuffer.put(data); dataBuffer.flip(); final Player p = new Player(new PlayerDetails(null, name, "", 0, null, null)); p.deserialize(dataBuffer); final int code = server.getLoader().savePlayer(p) ? 1 : 0; final IoBuffer resp = IoBuffer.allocate(16); resp.setAutoExpand(true); IoBufferUtils.putRS2String(resp, name); resp.put((byte) code); resp.flip(); session.write(new LoginPacket(LoginPacket.SAVE_RESPONSE, resp)); break; } case LoginPacket.DISCONNECT: { final String name = NameUtils.formatNameForProtocol(IoBufferUtils.getRS2String(buf)); final PlayerData p = NodeManager.getNodeManager().getPlayer(name); if (p != null) { NodeManager.getNodeManager().unregister(p); } } break; } }