From af605f41a0fae302351e25dc8b89204023dd4315 Mon Sep 17 00:00:00 2001 From: shiver474 Date: Tue, 3 Mar 2015 14:39:54 -0500 Subject: [PATCH 1/5] Fix small issue with door plugin. --- data/plugins/navigation/door/door.rb | 2 +- data/plugins/navigation/door/util.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/plugins/navigation/door/door.rb b/data/plugins/navigation/door/door.rb index 7ee1af49..8d27002d 100644 --- a/data/plugins/navigation/door/door.rb +++ b/data/plugins/navigation/door/door.rb @@ -18,7 +18,7 @@ class OpenDoorAction < DistancedAction end def equals(other) - return (get_class == other.get_class && @position == other.position) + return (get_class == other.get_class && @door_object == other.door_object) end end diff --git a/data/plugins/navigation/door/util.rb b/data/plugins/navigation/door/util.rb index 33d35725..cd1fb4a4 100644 --- a/data/plugins/navigation/door/util.rb +++ b/data/plugins/navigation/door/util.rb @@ -88,7 +88,7 @@ module DoorUtil # Gets the door object at the given position, if it exists. def self.get_door_object(position, object_id) game_objects = $world.sector_repository.from_position(position).get_entities(position, EntityType::GAME_OBJECT) - game_objects.each { |game_object| return game_object if game_object.get_id == object_id } + game_objects.each { |game_object| return game_object if game_object.id == object_id } return nil end From 26d1def1c6c8aa4daa462f8a721cf33baac136e2 Mon Sep 17 00:00:00 2001 From: Ryley Kimmel Date: Tue, 3 Mar 2015 21:12:32 -0500 Subject: [PATCH 2/5] Fix, format and rebase wilderness and player-action plugins. --- data/plugins/areas/wilderness.rb | 33 +++++++++++---------- data/plugins/player-action/player-action.rb | 6 ++-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/data/plugins/areas/wilderness.rb b/data/plugins/areas/wilderness.rb index 746c5e4f..5e97dc0f 100644 --- a/data/plugins/areas/wilderness.rb +++ b/data/plugins/areas/wilderness.rb @@ -1,35 +1,35 @@ require 'java' java_import 'org.apollo.game.model.entity.Player' -java_import 'org.apollo.game.message.impl.OpenOverlayMessage' java_import 'org.apollo.game.message.impl.SetWidgetTextMessage' +java_import 'org.apollo.game.message.impl.OpenOverlayMessage' +# Constants constants related to the wilderness +module WildernessConstants -private + # The wilderness level overlay interface id + OVERLAY_INTERFACE_ID = 197 -MIN_X = 2945 -MIN_Y = 3522 -MAX_X = 3390 -MAX_Y = 3972 + # The wilderness level string id + LEVEL_STRING_ID = 199 -OVERLAY_INTERFACE_ID = 197 -LEVEL_STRING_ID = 199 +end declare_attribute(:wilderness_level, 0, :transient) # Determines the wilderness level for the specified player's position def wilderness_level(player) - return (player.position.y - (MIN_Y - 1) / 8).ceil + return ((player.position.y - 3520) / 8).ceil end area_action :wilderness_level do on_entry do |player| player.wilderness_level = wilderness_level(player) - player.interface_set.open_overlay(OVERLAY_INTERFACE_ID) - player.send(SetWidgetTextMessage.new(LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) - show_action(ATTACK_ACTION) + player.interface_set.open_overlay(WildernessConstants::OVERLAY_INTERFACE_ID) + player.send(SetWidgetTextMessage.new(WildernessConstants::LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) + show_action(player, ATTACK_ACTION) end while_in do |player| @@ -37,16 +37,17 @@ area_action :wilderness_level do updated = wilderness_level(player) if (current != updated) player.wilderness_level = updated - player.send(SetWidgetTextMessage.new(LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) + player.send(SetWidgetTextMessage.new(WildernessConstants::LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) end end on_exit do |player| player.wilderness_level = 0 - player.interface_set.close() # TODO: Will this cause issues with other potentially open interfaces? - hide_action(ATTACK_ACTION) + player.interface_set.close() + player.send(OpenOverlayMessage.new(-1)) + hide_action(player, ATTACK_ACTION) end end -area :name => :wilderness, :coordinates => [ MIN_X, MIN_Y, MAX_X, MAX_Y, 0 ], :actions => :wilderness_level \ No newline at end of file +area :name => :wilderness, :coordinates => [ 2945, 3522, 3390, 3972, 0 ], :actions => :wilderness_level \ No newline at end of file diff --git a/data/plugins/player-action/player-action.rb b/data/plugins/player-action/player-action.rb index 46144a49..edd914e4 100644 --- a/data/plugins/player-action/player-action.rb +++ b/data/plugins/player-action/player-action.rb @@ -3,6 +3,8 @@ require 'java' java_import 'org.apollo.game.message.impl.SetPlayerActionMessage' java_import 'org.apollo.game.model.entity.Player' + + class PlayerAction attr_reader :slot, :primary, :name @@ -24,7 +26,7 @@ FOLLOW_ACTION = PlayerAction.new(:fifth, true, 'Follow') # Shows multiple context menu action for the specified player def show_actions(player, *actions) - raise 'Must specify at least one action to show' if actions.nil? + raise 'Must specify at least one action' if actions.nil? actions.each do |action| player.add_action(action) @@ -39,7 +41,7 @@ end # Hides a context menu action for the specified player def hide_action(player, action) - show_action(player, PlayerAction.new('null', action.slot, action.primary)) + show_action(player, PlayerAction.new(action.slot, action.primary, 'null')) end class Player From 6f95ba8d2ec42548040c07f8050b541ec4eb00a5 Mon Sep 17 00:00:00 2001 From: Ryley Kimmel Date: Tue, 3 Mar 2015 21:18:52 -0500 Subject: [PATCH 3/5] Fix potential latency issue with on-demand and login writes, constantly writing and flushing is an expensive syscall and should only be done when the channel has been fully read, other instant flushes such as for the game session or initializing HTTP requests must remain untouched as it will potentially block the entire server (and it's nice to have in-game actions done instantly anyway). --- src/org/apollo/net/ApolloHandler.java | 5 +++++ src/org/apollo/net/JagGrabChannelInitializer.java | 4 +++- src/org/apollo/net/codec/login/LoginDecoder.java | 4 ++-- src/org/apollo/net/session/LoginSession.java | 2 +- src/org/apollo/update/OnDemandRequestWorker.java | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/org/apollo/net/ApolloHandler.java b/src/org/apollo/net/ApolloHandler.java index 3a3a8065..78b029e6 100644 --- a/src/org/apollo/net/ApolloHandler.java +++ b/src/org/apollo/net/ApolloHandler.java @@ -100,4 +100,9 @@ public final class ApolloHandler extends ChannelInboundHandlerAdapter { } } + @Override + public void channelReadComplete(ChannelHandlerContext ctx) { + ctx.flush(); + } + } \ No newline at end of file diff --git a/src/org/apollo/net/JagGrabChannelInitializer.java b/src/org/apollo/net/JagGrabChannelInitializer.java index ca2980d9..ae860c85 100644 --- a/src/org/apollo/net/JagGrabChannelInitializer.java +++ b/src/org/apollo/net/JagGrabChannelInitializer.java @@ -14,6 +14,8 @@ import java.nio.charset.Charset; import org.apollo.net.codec.jaggrab.JagGrabRequestDecoder; import org.apollo.net.codec.jaggrab.JagGrabResponseEncoder; +import com.google.common.base.Charsets; + /** * A {@link ChannelInitializer} for the JAGGRAB protocol. * @@ -29,7 +31,7 @@ public final class JagGrabChannelInitializer extends ChannelInitializer response.writeByte(LoginConstants.STATUS_EXCHANGE_DATA); response.writeLong(0); response.writeLong(serverSeed); - ctx.channel().writeAndFlush(response); + ctx.channel().write(response); setState(LoginDecoderState.LOGIN_HEADER); } @@ -210,7 +210,7 @@ public final class LoginDecoder extends StatefulFrameDecoder ByteBuf buffer = ctx.alloc().buffer(1); buffer.writeByte(response); - ctx.writeAndFlush(buffer).addListener(ChannelFutureListener.CLOSE); + ctx.write(buffer).addListener(ChannelFutureListener.CLOSE); } } \ No newline at end of file diff --git a/src/org/apollo/net/session/LoginSession.java b/src/org/apollo/net/session/LoginSession.java index 754f1b99..61584ecc 100644 --- a/src/org/apollo/net/session/LoginSession.java +++ b/src/org/apollo/net/session/LoginSession.java @@ -107,7 +107,7 @@ public final class LoginSession extends Session { } } - ChannelFuture future = channel.writeAndFlush(new LoginResponse(status, rights, flagged)); + ChannelFuture future = channel.write(new LoginResponse(status, rights, flagged)); destroy(); diff --git a/src/org/apollo/update/OnDemandRequestWorker.java b/src/org/apollo/update/OnDemandRequestWorker.java index 7a28a0a8..949549d8 100644 --- a/src/org/apollo/update/OnDemandRequestWorker.java +++ b/src/org/apollo/update/OnDemandRequestWorker.java @@ -57,7 +57,7 @@ public final class OnDemandRequestWorker extends RequestWorker Date: Tue, 3 Mar 2015 23:28:15 -0500 Subject: [PATCH 4/5] Improve UpdateService by making it use a Logger and method referencing. - Use correct thrown exception. - Use forEach and method referencing where possible. --- src/org/apollo/update/UpdateService.java | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/org/apollo/update/UpdateService.java b/src/org/apollo/update/UpdateService.java index 47bc5b56..aa9862be 100644 --- a/src/org/apollo/update/UpdateService.java +++ b/src/org/apollo/update/UpdateService.java @@ -1,11 +1,14 @@ package org.apollo.update; +import java.io.FileNotFoundException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apollo.Service; import org.apollo.fs.IndexedFileSystem; @@ -27,6 +30,11 @@ public final class UpdateService extends Service { */ private static final int THREADS_PER_REQUEST_TYPE = Runtime.getRuntime().availableProcessors(); + /** + * The logger for this class. + */ + private static final Logger logger = Logger.getLogger(UpdateService.class.getName()); + /** * The update dispatcher. */ @@ -59,9 +67,6 @@ public final class UpdateService extends Service { return dispatcher; } - /** - * Starts the threads in the pool. - */ @Override public void start() { int release = getContext().getRelease().getReleaseNumber(); @@ -72,23 +77,18 @@ public final class UpdateService extends Service { workers.add(new OnDemandRequestWorker(dispatcher, new IndexedFileSystem(base, true))); workers.add(new HttpRequestWorker(dispatcher, new IndexedFileSystem(base, true))); } - - for (RequestWorker worker : workers) { - service.submit(worker); - } - } catch (Exception ex) { - System.err.println("Error adding request workers - " + ex.getMessage()); + } catch (FileNotFoundException reason) { + logger.log(Level.SEVERE, "Unable to find index or data files from the file system.", reason); } + + workers.forEach(service::submit); } /** * Stops the threads in the pool. */ public void stop() { - for (RequestWorker worker : workers) { - worker.stop(); - } - + workers.forEach(RequestWorker::stop); service.shutdownNow(); } From 723fbac591572be741fdffc6faa3d451fef9296a Mon Sep 17 00:00:00 2001 From: Major- Date: Wed, 4 Mar 2015 05:05:04 +0000 Subject: [PATCH 5/5] Improve error message when attempting to access an illegal index in CollisionMatrix. --- .../apollo/game/model/area/collision/CollisionMatrix.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/org/apollo/game/model/area/collision/CollisionMatrix.java b/src/org/apollo/game/model/area/collision/CollisionMatrix.java index d56c6ff3..f043fbc7 100644 --- a/src/org/apollo/game/model/area/collision/CollisionMatrix.java +++ b/src/org/apollo/game/model/area/collision/CollisionMatrix.java @@ -161,7 +161,8 @@ public final class CollisionMatrix { @Override public String toString() { - return MoreObjects.toStringHelper(this).add("width", width).add("length", length).add("matrix", Arrays.toString(matrix)).toString(); + return MoreObjects.toStringHelper(this).add("width", width).add("length", length).add("matrix", Arrays.toString(matrix)) + .toString(); } /** @@ -209,8 +210,9 @@ public final class CollisionMatrix { * @throws ArrayIndexOutOfBoundsException If the specified coordinate pair does not fit in this matrix. */ private int indexOf(int x, int y) { + Preconditions.checkElementIndex(x, width, "X coordinate must be [0, " + width + "), received " + x + "."); + Preconditions.checkElementIndex(y, length, "Y coordinate must be [0, " + length + "), received " + y + "."); int index = y * width + x; - Preconditions.checkElementIndex(index, matrix.length, "Index out of bounds."); return index; }