Commit a7448f36 authored by Scott T's avatar Scott T

Merge remote-tracking branch 'upstream/2.0.0' into 2.0.0

parents 80e43cc8 dc30b153
......@@ -463,7 +463,7 @@ public final class SuperModerator implements CommandListener {
GameLogging.addQuery(new StaffLog(player, 11, p, player.getUsername() + " was banned by " + player.getUsername() + " " + (time == -1 ? "permanently" : " for " + time + " minutes")));
}
player.message(messagePrefix + Server.getPlayerDataProcessor().getDatabase().banPlayer(usernameToBan, time)); // Disabled as it doesn't compile with PlayerDatabaseExecutor extending ThrottleFilter
player.message(messagePrefix + Server.getServer().getPlayerDataProcessor().getDatabase().banPlayer(usernameToBan, time)); // Disabled as it doesn't compile with PlayerDatabaseExecutor extending ThrottleFilter
} else if (cmd.equalsIgnoreCase("ipcount")) {
Player p = args.length > 0 ?
world.getPlayer(DataConversions.usernameToHash(args[0])) :
......
......@@ -5,6 +5,7 @@ import com.openrsc.server.event.custom.BatchEvent;
import com.openrsc.server.external.EntityHandler;
import com.openrsc.server.external.ItemId;
import com.openrsc.server.external.ObjectMiningDef;
import com.openrsc.server.model.Skills;
import com.openrsc.server.model.Skills.SKILLS;
import com.openrsc.server.model.container.Item;
import com.openrsc.server.model.entity.GameObject;
......@@ -12,6 +13,7 @@ import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.model.world.World;
import com.openrsc.server.plugins.listeners.action.ObjectActionListener;
import com.openrsc.server.plugins.listeners.executive.ObjectActionExecutiveListener;
import com.openrsc.server.util.rsc.DataConversions;
import com.openrsc.server.util.rsc.Formulae;
import static com.openrsc.server.plugins.Functions.*;
......@@ -105,7 +107,8 @@ public class GemMining implements ObjectActionListener,
p.playSound("mine");
showBubble(p, new Item(ItemId.IRON_PICKAXE.id()));
p.message("You have a swing at the rock!");
p.setBatchEvent(new BatchEvent(p, 1800, "Gem Mining", 1000 + retrytimes, true) {
retrytimes = Constants.GameServer.BATCH_PROGRESSION ? Formulae.getRepeatTimes(p, Skills.MINING) : retrytimes + 1000;
p.setBatchEvent(new BatchEvent(p, 1800, "Gem Mining", retrytimes, true) {
@Override
public void action() {
if (getGem(p, 40, getOwner().getSkills().getLevel(SKILLS.MINING.id()), axeId) && mineLvl >= 40) { // always 40 required mining.
......@@ -119,12 +122,14 @@ public class GemMining implements ObjectActionListener,
getOwner().incExp(SKILLS.MINING.id(), 200, true); // always 50XP
getOwner().getInventory().add(gem);
}
interrupt();
if (object != null && object.getID() == obj.getID()) {
GameObject newObject = new GameObject(obj.getLocation(), 98, obj.getDirection(), obj.getType());
World.getWorld().replaceGameObject(obj, newObject);
World.getWorld().delayedSpawnObject(object.getLoc(), 120 * 1000); // 2 minute respawn time
if (!Constants.GameServer.MINING_ROCKS_EXTENDED || DataConversions.random(1, 100) <= 39) {
interrupt();
if (object != null && object.getID() == obj.getID()) {
GameObject newObject = new GameObject(obj.getLocation(), 98, obj.getDirection(), obj.getType());
World.getWorld().replaceGameObject(obj, newObject);
World.getWorld().delayedSpawnObject(object.getLoc(), 120 * 1000); // 2 minute respawn time
}
}
} else {
getOwner().message("You only succeed in scratching the rock");
......
......@@ -35,6 +35,8 @@ public class PlayerDatabaseExecutor extends ThrottleFilter implements Runnable {
private DatabasePlayerLoader database = new DatabasePlayerLoader();
private boolean running = false;
@Override
public void run() {
try {
......@@ -94,7 +96,16 @@ public class PlayerDatabaseExecutor extends ThrottleFilter implements Runnable {
}
public void start() {
scheduledExecutor.scheduleAtFixedRate(this, 50, 50, TimeUnit.MILLISECONDS);
running = true;
scheduledExecutor.scheduleAtFixedRate(this, 0, 50, TimeUnit.MILLISECONDS);
}
public void stop() {
running = false;
scheduledExecutor.shutdown();
}
public boolean isRunning() {
return running;
}
}
This diff is collapsed.
package com.openrsc.server.event.custom;
import com.openrsc.server.Constants;
import com.openrsc.server.Server;
import com.openrsc.server.event.rsc.GameTickEvent;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.model.world.World;
import com.openrsc.server.util.rsc.MessageType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Author: Kenix
*/
// Send monitoring info as a game event so that it can be profiled.
public class MonitoringEvent extends GameTickEvent {
private static final Logger LOGGER = LogManager.getLogger();
public MonitoringEvent() {
super(null, 0, "Server Monitoring");
}
public void run() {
// Processing game events and state took longer than the tick
if(Server.getServer().getLastTickDuration() >= Constants.GameServer.GAME_TICK) {
final String message = "Can't keep up: " +
Server.getServer().getLastTickDuration() + "ms " +
Server.getServer().getLastIncomingPacketsDuration() + "ms " +
Server.getServer().getLastEventsDuration() + "ms " +
Server.getServer().getLastGameStateDuration() + "ms " +
Server.getServer().getLastOutgoingPacketsDuration() + "ms";
// Warn logged in developers
for (Player p : World.getWorld().getPlayers()) {
if (!p.isDev()) {
continue;
}
p.playerServerMessage(MessageType.QUEST, Constants.GameServer.MESSAGE_PREFIX + message);
}
}
final long ticksLate = Server.getServer().getTimeLate() / Constants.GameServer.GAME_TICK;
final boolean isServerLate = ticksLate >= 1;
// Server fell behind, skip ticks
if (isServerLate) {
Server.getServer().skipTicks(ticksLate);
final String message = "Can't keep up, we are " + Server.getServer().getTimeLate() + "ms behind; Skipping " + ticksLate + " ticks";
// Send monitoring info as a game event so that it can be profiled.
Server.getServer().getGameEventHandler().add(new GameTickEvent(null, 0, "Server Fell Behind") {
@Override
public void run() {
// Warn logged in developers
for (Player p : World.getWorld().getPlayers()) {
if (!p.isDev()) {
continue;
}
p.playerServerMessage(MessageType.QUEST, Constants.GameServer.MESSAGE_PREFIX + message);
}
Server.getServer().getDiscordSender().monitoringSendServerBehind(message);
stop();
}
});
if (Constants.GameServer.DEBUG) {
LOGGER.warn(message);
}
}
}
}
......@@ -10,7 +10,6 @@ public abstract class GameTickEvent {
protected boolean running = true;
private Mob owner;
private int delayTicks;
private boolean immediate;
private int ticksBeforeRun = -1;
private String descriptor;
private long lastEventDuration = 0;
......@@ -73,14 +72,6 @@ public abstract class GameTickEvent {
this.delayTicks = delayTicks;
}
public boolean isImmediate() {
return immediate;
}
public void setImmediate(boolean b) {
this.immediate = b;
}
protected Player getPlayerOwner() {
return owner != null && owner.isPlayer() ? (Player) owner : null;
}
......
......@@ -6,12 +6,10 @@ public abstract class ImmediateEvent extends GameTickEvent {
protected ImmediateEvent(String descriptor) {
super(null, 0, descriptor);
setImmediate(true);
}
public ImmediateEvent(Mob mob, String descriptor) {
super(mob, 0, descriptor);
setImmediate(true);
}
@Override
......
......@@ -71,7 +71,6 @@ public class RangeEvent extends GameTickEvent {
public RangeEvent(Player owner, Mob victim) {
super(owner, 1, "Range Event");
this.setImmediate(true);
this.target = victim;
this.deliveredFirstProjectile = false;
}
......
......@@ -58,7 +58,6 @@ public class RangeEventNpc extends GameTickEvent {
public RangeEventNpc(Npc owner, Mob victim) {
super(owner, 1, "Range Event NPC");
this.setImmediate(true);
this.target = victim;
this.deliveredFirstProjectile = false;
}
......
......@@ -28,7 +28,6 @@ public class ThrowingEvent extends GameTickEvent {
public ThrowingEvent(Player owner, Mob victim) {
super(owner, 1, "Throwing Event");
this.setImmediate(true);
this.target = victim;
}
......
......@@ -935,7 +935,6 @@ public abstract class Mob extends Entity {
cure();
}
PoisonEvent poisonEvent = new PoisonEvent(this, poisonDamage);
poisonEvent.setImmediate(true);
setAttribute("poisonEvent", poisonEvent);
Server.getServer().getGameEventHandler().add(poisonEvent);
}
......
......@@ -528,7 +528,7 @@ public class Npc extends Mob {
groundItem.setAttribute("npcdrop", true);
world.registerItem(groundItem);
}
Server.getPlayerDataProcessor().getDatabase().addNpcDrop(
Server.getServer().getPlayerDataProcessor().getDatabase().addNpcDrop(
owner, this, rare.getID(), rare.getAmount());
}
......@@ -580,7 +580,7 @@ public class Npc extends Mob {
if (!EntityHandler.getItemDef(dropID).isStackable()) {
Server.getPlayerDataProcessor().getDatabase().addNpcDrop(
Server.getServer().getPlayerDataProcessor().getDatabase().addNpcDrop(
owner, this, dropID, amount);
GroundItem groundItem;
......@@ -622,7 +622,7 @@ public class Npc extends Mob {
}
}
Server.getPlayerDataProcessor().getDatabase().addNpcDrop(
Server.getServer().getPlayerDataProcessor().getDatabase().addNpcDrop(
owner, this, dropID, amount);
if (!handleRingOfAvarice(owner, new Item(drop.getID(), amount))) {
GroundItem groundItem = new GroundItem(dropID, getX(), getY(), amount, owner);
......
......@@ -1971,7 +1971,7 @@ public final class Player extends Mob {
}
public void save() {
Server.getPlayerDataProcessor().addSaveRequest(this);
Server.getServer().getPlayerDataProcessor().addSaveRequest(this);
}
public void logout() {
......@@ -2019,7 +2019,7 @@ public final class Player extends Mob {
ClanManager.checkAndUnattachFromClan(this);
PartyManager.checkAndUnattachFromParty(this);
Server.getPlayerDataProcessor().addRemoveRequest(this);
Server.getServer().getPlayerDataProcessor().addRemoveRequest(this);
}
public void sendMemberErrorMessage() {
......
......@@ -26,14 +26,14 @@ public class Social {
}
public boolean addFriend(long id, int world, String friendName) {
boolean added = Server.getPlayerDataProcessor().getDatabase().addFriend(player.getDatabaseID(), id, friendName);
boolean added = Server.getServer().getPlayerDataProcessor().getDatabase().addFriend(player.getDatabaseID(), id, friendName);
if (added)
friendList.put(id, world);
return added;
}
public boolean addIgnore(long id, int i, String friendName) {
boolean added = Server.getPlayerDataProcessor().getDatabase().addIgnore(player.getDatabaseID(), id, friendName);
boolean added = Server.getServer().getPlayerDataProcessor().getDatabase().addIgnore(player.getDatabaseID(), id, friendName);
if (added)
ignoreList.add(id);
return added;
......@@ -41,12 +41,12 @@ public class Social {
public void removeFriend(long id) {
friendList.remove(id);
Server.getPlayerDataProcessor().getDatabase().removeFriend(player.getDatabaseID(), id);
Server.getServer().getPlayerDataProcessor().getDatabase().removeFriend(player.getDatabaseID(), id);
}
public void removeIgnore(long id) {
ignoreList.remove(id);
Server.getPlayerDataProcessor().getDatabase().removeIgnore(player.getDatabaseID(), id);
Server.getServer().getPlayerDataProcessor().getDatabase().removeIgnore(player.getDatabaseID(), id);
}
public boolean isFriendsWith(long usernameHash) {
......
......@@ -555,7 +555,7 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
players.add(player);
player.updateRegion();
if (Server.getPlayerDataProcessor() != null) {
if (Server.getServer().getPlayerDataProcessor() != null) {
GameLogging.addQuery(new PlayerOnlineFlagQuery(player.getDatabaseID(), player.getCurrentIP(), true));
GameLogging.addQuery(new LoginLog(player.getDatabaseID(), player.getCurrentIP()));
}
......@@ -721,7 +721,7 @@ public final class World implements SimpleSubscriber<FishingTrawler> {
*/
public void unregisterPlayer(final Player player) {
try {
if (Server.getPlayerDataProcessor() != null) {
if (Server.getServer().getPlayerDataProcessor() != null) {
GameLogging.addQuery(new PlayerOnlineFlagQuery(player.getDatabaseID(), false));
if (Constants.GameServer.AVATAR_GENERATOR)
avatarGenerator.generateAvatar(player.getDatabaseID(), player.getSettings().getAppearance(), player.getWornItems());
......
package com.openrsc.server.net;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.openrsc.server.Constants;
import com.openrsc.server.Server;
import com.openrsc.server.content.market.MarketItem;
......@@ -12,11 +13,23 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class DiscordSender implements Runnable{
private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("PlayerDataProcessorThread").build());
private Queue<String> auctionRequests = new ConcurrentLinkedQueue<String>();
private Queue<String> monitoringRequests = new ConcurrentLinkedQueue<String>();
public class DiscordSender {
private static final Logger LOGGER = LogManager.getLogger();
private long monitoringLastUpdate = 0;
private boolean running = false;
public void auctionAdd(MarketItem addItem) {
String pluralHandlerMessage = addItem.getAmount() > 1
......@@ -30,11 +43,8 @@ public class DiscordSender {
addItem.getSellerName(),
addItem.getHoursLeft()
);
try {
auctionSendToDiscord(addMessage);
} catch(Exception e) {
LOGGER.catching(e);
}
auctionSendToDiscord(addMessage);
}
public void auctionBuy(MarketItem buyItem) {
......@@ -43,11 +53,8 @@ public class DiscordSender {
buyItem.getSellerName(),
buyItem.getAmountLeft()
);
try {
auctionSendToDiscord(buyMessage);
} catch(Exception e) {
LOGGER.catching(e);
}
auctionSendToDiscord(buyMessage);
}
public void auctionCancel(MarketItem cancelItem) {
......@@ -56,11 +63,8 @@ public class DiscordSender {
EntityHandler.getItemDef(cancelItem.getItemID()).getName(),
cancelItem.getSellerName()
);
try {
auctionSendToDiscord(cancelMessage);
} catch(Exception e) {
LOGGER.catching(e);
}
auctionSendToDiscord(cancelMessage);
}
public void auctionModDelete(MarketItem deleteItem) {
......@@ -69,11 +73,8 @@ public class DiscordSender {
EntityHandler.getItemDef(deleteItem.getItemID()).getName(),
deleteItem.getSellerName()
);
try {
auctionSendToDiscord(cancelMessage);
} catch(Exception e) {
LOGGER.catching(e);
}
auctionSendToDiscord(cancelMessage);
}
public void monitoringSendServerBehind(String message) {
......@@ -84,18 +85,18 @@ public class DiscordSender {
}
}
private void auctionSendToDiscord(String message) throws Exception {
private void auctionSendToDiscord(String message) {
if(Constants.GameServer.WANT_DISCORD_AUCTION_UPDATES) {
sendToDiscord(Constants.GameServer.DISCORD_MONITORING_WEBHOOK_URL, message);
auctionRequests.add(message);
}
}
private void monitoringSendToDiscord(String message) throws Exception {
final long now = System.currentTimeMillis();
private void monitoringSendToDiscord(String message) {
final long now = System.currentTimeMillis();
if(now >= (monitoringLastUpdate + 3600) && Constants.GameServer.WANT_DISCORD_MONITORING_UPDATES) {
sendToDiscord(Constants.GameServer.DISCORD_MONITORING_WEBHOOK_URL, message);
monitoringLastUpdate = now;
if(Constants.GameServer.WANT_DISCORD_MONITORING_UPDATES && now >= (monitoringLastUpdate + 3600)) {
monitoringRequests.add(message);
monitoringLastUpdate = now;
}
}
......@@ -122,4 +123,35 @@ public class DiscordSender {
os.write(out);
}
}
@Override
public void run() {
String message = null;
try {
while ((message = auctionRequests.poll()) != null) {
sendToDiscord(Constants.GameServer.DISCORD_AUCTION_WEBHOOK_URL, message);
}
while ((message = monitoringRequests.poll()) != null) {
sendToDiscord(Constants.GameServer.DISCORD_MONITORING_WEBHOOK_URL, message);
}
} catch(Exception e) {
LOGGER.catching(e);
}
}
public void start() {
running = true;
scheduledExecutor.scheduleAtFixedRate(this, 0, 50, TimeUnit.MILLISECONDS);
}
public void stop() {
running = false;
scheduledExecutor.shutdown();
}
public boolean isRunning() {
return running;
}
}
......@@ -111,7 +111,7 @@ public class LoginPacketHandler {
ActionSender.sendLogin(loadedPlayer);
}
};
Server.getPlayerDataProcessor().addLoginRequest(request);
Server.getServer().getPlayerDataProcessor().addLoginRequest(request);
break;
/* Registering */
......
......@@ -294,7 +294,6 @@ public class PlayerDuelHandler implements PacketHandler {
CombatEvent combatEvent = new CombatEvent(attacker, opponent);
attacker.setCombatEvent(combatEvent);
opponent.setCombatEvent(combatEvent);
combatEvent.setImmediate(true);
Server.getServer().getGameEventHandler().add(combatEvent);
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment