Search in sources :

Example 1 with Release

use of org.apollo.net.release.Release in project apollo by apollo-rsps.

the class Server method init.

/**
 * Initialises the server.
 *
 * @param releaseName The class name of the current active {@link Release}.
 * @throws Exception If an error occurs.
 */
public void init(String releaseName) throws Exception {
    Class<?> clazz = Class.forName(releaseName);
    Release release = (Release) clazz.newInstance();
    int version = release.getReleaseNumber();
    logger.info("Initialized " + release + ".");
    serviceBootstrap.group(loopGroup);
    httpBootstrap.group(loopGroup);
    jaggrabBootstrap.group(loopGroup);
    World world = new World();
    ServiceManager services = new ServiceManager(world);
    IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs", Integer.toString(version)), true);
    ServerContext context = new ServerContext(release, services, fs);
    ApolloHandler handler = new ApolloHandler(context);
    ChannelInitializer<SocketChannel> service = new ServiceChannelInitializer(handler);
    serviceBootstrap.channel(NioServerSocketChannel.class);
    serviceBootstrap.childHandler(service);
    ChannelInitializer<SocketChannel> http = new HttpChannelInitializer(handler);
    httpBootstrap.channel(NioServerSocketChannel.class);
    httpBootstrap.childHandler(http);
    ChannelInitializer<SocketChannel> jaggrab = new JagGrabChannelInitializer(handler);
    jaggrabBootstrap.channel(NioServerSocketChannel.class);
    jaggrabBootstrap.childHandler(jaggrab);
    PluginManager manager = new PluginManager(world, new PluginContext(context));
    services.startAll();
    world.init(version, fs, manager);
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServiceChannelInitializer(org.apollo.net.ServiceChannelInitializer) PluginContext(org.apollo.game.plugin.PluginContext) World(org.apollo.game.model.World) PluginManager(org.apollo.game.plugin.PluginManager) HttpChannelInitializer(org.apollo.net.HttpChannelInitializer) IndexedFileSystem(org.apollo.cache.IndexedFileSystem) ApolloHandler(org.apollo.game.session.ApolloHandler) JagGrabChannelInitializer(org.apollo.net.JagGrabChannelInitializer) Release(org.apollo.net.release.Release)

Example 2 with Release

use of org.apollo.net.release.Release in project apollo by apollo-rsps.

the class LoginService method requiresUpdate.

/**
 * Checks if an update is required whenever a {@link Player} submits a login request.
 *
 * @param request The login request.
 * @return {@code true} if an update is required, otherwise return {@code false}.
 * @throws IOException If some I/O exception occurs.
 */
private boolean requiresUpdate(LoginRequest request) throws IOException {
    Release release = context.getRelease();
    if (release.getReleaseNumber() != request.getReleaseNumber()) {
        return true;
    }
    int[] clientCrcs = request.getArchiveCrcs();
    int[] serverCrcs = context.getFileSystem().getCrcs();
    return !Arrays.equals(clientCrcs, serverCrcs);
}
Also used : Release(org.apollo.net.release.Release)

Example 3 with Release

use of org.apollo.net.release.Release in project apollo by apollo-rsps.

the class LoginSession method sendLoginSuccess.

/**
 * Sends a succesfull {@link LoginResponse} to the client.
 *
 * @param player The {@link Player} that successfully logged in.
 */
public void sendLoginSuccess(Player player) {
    IsaacRandomPair randomPair = request.getRandomPair();
    boolean flagged = false;
    GameSession session = new GameSession(channel, context, player, request.isReconnecting());
    channel.attr(ApolloHandler.SESSION_KEY).set(session);
    player.setSession(session);
    int rights = player.getPrivilegeLevel().toInteger();
    channel.writeAndFlush(new LoginResponse(LoginConstants.STATUS_OK, rights, flagged));
    Release release = context.getRelease();
    channel.pipeline().addFirst("messageEncoder", new GameMessageEncoder(release));
    channel.pipeline().addBefore("messageEncoder", "gameEncoder", new GamePacketEncoder(randomPair.getEncodingRandom()));
    channel.pipeline().addBefore("handler", "gameDecoder", new GamePacketDecoder(randomPair.getDecodingRandom(), context.getRelease()));
    channel.pipeline().addAfter("gameDecoder", "messageDecoder", new GameMessageDecoder(release));
    channel.pipeline().remove("loginDecoder");
    channel.pipeline().remove("loginEncoder");
}
Also used : LoginResponse(org.apollo.net.codec.login.LoginResponse) GameMessageDecoder(org.apollo.net.codec.game.GameMessageDecoder) GamePacketEncoder(org.apollo.net.codec.game.GamePacketEncoder) GamePacketDecoder(org.apollo.net.codec.game.GamePacketDecoder) GameMessageEncoder(org.apollo.net.codec.game.GameMessageEncoder) IsaacRandomPair(org.apollo.util.security.IsaacRandomPair) Release(org.apollo.net.release.Release)

Aggregations

Release (org.apollo.net.release.Release)3 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 IndexedFileSystem (org.apollo.cache.IndexedFileSystem)1 World (org.apollo.game.model.World)1 PluginContext (org.apollo.game.plugin.PluginContext)1 PluginManager (org.apollo.game.plugin.PluginManager)1 ApolloHandler (org.apollo.game.session.ApolloHandler)1 HttpChannelInitializer (org.apollo.net.HttpChannelInitializer)1 JagGrabChannelInitializer (org.apollo.net.JagGrabChannelInitializer)1 ServiceChannelInitializer (org.apollo.net.ServiceChannelInitializer)1 GameMessageDecoder (org.apollo.net.codec.game.GameMessageDecoder)1 GameMessageEncoder (org.apollo.net.codec.game.GameMessageEncoder)1 GamePacketDecoder (org.apollo.net.codec.game.GamePacketDecoder)1 GamePacketEncoder (org.apollo.net.codec.game.GamePacketEncoder)1 LoginResponse (org.apollo.net.codec.login.LoginResponse)1 IsaacRandomPair (org.apollo.util.security.IsaacRandomPair)1