Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2653c465d1 | ||
|
|
97eff6517e | ||
|
|
9f3ec7c553 |
No files matched your search
@@ -1,61 +0,0 @@
|
|||||||
package engine.devcmd.cmds;
|
|
||||||
|
|
||||||
import engine.devcmd.AbstractDevCmd;
|
|
||||||
import engine.gameManager.PowersManager;
|
|
||||||
import engine.gameManager.ZoneManager;
|
|
||||||
import engine.objects.*;
|
|
||||||
|
|
||||||
public class SetCampLevelCmd extends AbstractDevCmd {
|
|
||||||
public SetCampLevelCmd() { super("setcamplevel"); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void _doCmd(PlayerCharacter pcSender, String[] args, AbstractGameObject target) {
|
|
||||||
|
|
||||||
if (args.length > 1)
|
|
||||||
{
|
|
||||||
this.sendUsage(pcSender);
|
|
||||||
}
|
|
||||||
|
|
||||||
int targetLevel = 0;
|
|
||||||
if (args.length == 1) {
|
|
||||||
try {
|
|
||||||
targetLevel = Integer.parseInt(args[0]);
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
throwbackError(pcSender, "Argument MUST be integer. Received: " + args[0]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throwbackError(pcSender, "Unknown command parsing provided camp level: " + args[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((target instanceof Mob))
|
|
||||||
{
|
|
||||||
// Get the camp that owns the targeted Mob
|
|
||||||
Zone campZone = ((Mob) target).parentZone;
|
|
||||||
|
|
||||||
// Make sure that the zone we're targeting is valid for action
|
|
||||||
if (campZone == null ||
|
|
||||||
campZone.zoneMobSet.isEmpty() ||
|
|
||||||
campZone.isPlayerCity()) {
|
|
||||||
throwbackError(pcSender, "Current zone must own mobs, and NOT be a city.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
campZone.setCampLvl(targetLevel);
|
|
||||||
}
|
|
||||||
else if (target instanceof PlayerCharacter)
|
|
||||||
{
|
|
||||||
PlayerCharacter pc = (PlayerCharacter)target;
|
|
||||||
PowersManager.applyPower(pc, pc, pc.getLoc(), "CMP-001", targetLevel, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String _getUsageString() {
|
|
||||||
return "Sets the level of the currently occupied camp to the desired level";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String _getHelpString() {
|
|
||||||
return "'./setcamplevel levelNum'";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// Magicbane Emulator Project © 2013 - 2022
|
||||||
|
// www.magicbane.com
|
||||||
|
|
||||||
|
|
||||||
|
package engine.devcmd.cmds;
|
||||||
|
|
||||||
|
import engine.devcmd.AbstractDevCmd;
|
||||||
|
import engine.gameManager.GracefulShutdown;
|
||||||
|
import engine.objects.AbstractGameObject;
|
||||||
|
import engine.objects.PlayerCharacter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Devcmd: graceful shutdown.
|
||||||
|
*
|
||||||
|
* Announces a countdown to every player, writes all online characters to the
|
||||||
|
* database (skills/powers, stat modifiers, experience) and then stops the
|
||||||
|
* login and world servers. Unlike './reboot' - which simply runs mbrestart.sh
|
||||||
|
* and therefore kills the JVMs with SIGKILL - nothing still parked in a
|
||||||
|
* deferred database job is lost.
|
||||||
|
*
|
||||||
|
* Usage: ./shutdown [seconds] (default 60, maximum 3600)
|
||||||
|
*/
|
||||||
|
public class ShutdownCmd extends AbstractDevCmd {
|
||||||
|
|
||||||
|
private static final int DEFAULT_DELAY_SECONDS = 60;
|
||||||
|
private static final int MAX_DELAY_SECONDS = 3600;
|
||||||
|
|
||||||
|
public ShutdownCmd() {
|
||||||
|
super("shutdown");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void _doCmd(PlayerCharacter pcSender, String[] args, AbstractGameObject target) {
|
||||||
|
|
||||||
|
int delay = DEFAULT_DELAY_SECONDS;
|
||||||
|
|
||||||
|
if (args.length > 0 && args[0].isEmpty() == false) {
|
||||||
|
try {
|
||||||
|
delay = Integer.parseInt(args[0].trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
this.sendUsage(pcSender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delay < 0)
|
||||||
|
delay = 0;
|
||||||
|
|
||||||
|
if (delay > MAX_DELAY_SECONDS)
|
||||||
|
delay = MAX_DELAY_SECONDS;
|
||||||
|
|
||||||
|
throwbackInfo(pcSender, "Graceful shutdown started: player data will be saved in " + delay + " second(s).");
|
||||||
|
|
||||||
|
final int delaySeconds = delay;
|
||||||
|
|
||||||
|
// The countdown sleeps, so run it off the message handling thread.
|
||||||
|
|
||||||
|
Thread shutdownThread = new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
GracefulShutdown.gracefulStop(delaySeconds);
|
||||||
|
}
|
||||||
|
}, "gracefulShutdown");
|
||||||
|
|
||||||
|
shutdownThread.setDaemon(false);
|
||||||
|
shutdownThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String _getHelpString() {
|
||||||
|
return "Gracefully shuts the server down: warns the players, saves every online character, then stops the servers";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String _getUsageString() {
|
||||||
|
return "' /shutdown [seconds]'";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -123,6 +123,7 @@ public enum DevCmdManager {
|
|||||||
DevCmdManager.registerDevCmd(new ShowOffsetCmd());
|
DevCmdManager.registerDevCmd(new ShowOffsetCmd());
|
||||||
DevCmdManager.registerDevCmd(new RealmInfoCmd());
|
DevCmdManager.registerDevCmd(new RealmInfoCmd());
|
||||||
DevCmdManager.registerDevCmd(new RebootCmd());
|
DevCmdManager.registerDevCmd(new RebootCmd());
|
||||||
|
DevCmdManager.registerDevCmd(new ShutdownCmd());
|
||||||
DevCmdManager.registerDevCmd(new SetMineTypeCmd());
|
DevCmdManager.registerDevCmd(new SetMineTypeCmd());
|
||||||
DevCmdManager.registerDevCmd(new SetMineExpansion());
|
DevCmdManager.registerDevCmd(new SetMineExpansion());
|
||||||
DevCmdManager.registerDevCmd(new SetForceRenameCityCmd());
|
DevCmdManager.registerDevCmd(new SetForceRenameCityCmd());
|
||||||
@@ -143,7 +144,6 @@ public enum DevCmdManager {
|
|||||||
DevCmdManager.registerDevCmd(new ApplyBonusCmd());
|
DevCmdManager.registerDevCmd(new ApplyBonusCmd());
|
||||||
DevCmdManager.registerDevCmd(new AuditFailedItemsCmd());
|
DevCmdManager.registerDevCmd(new AuditFailedItemsCmd());
|
||||||
DevCmdManager.registerDevCmd(new SlotTestCmd());
|
DevCmdManager.registerDevCmd(new SlotTestCmd());
|
||||||
DevCmdManager.registerDevCmd(new SetCampLevelCmd());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// Magicbane Emulator Project © 2013 - 2022
|
||||||
|
// www.magicbane.com
|
||||||
|
|
||||||
|
|
||||||
|
package engine.gameManager;
|
||||||
|
|
||||||
|
import engine.objects.PlayerCharacter;
|
||||||
|
import engine.util.ThreadUtils;
|
||||||
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Graceful shutdown support.
|
||||||
|
*
|
||||||
|
* The stock devops scripts stop the game with SIGKILL (mbkill.sh runs
|
||||||
|
* 'kill -9'), which throws away everything still parked in a character's
|
||||||
|
* deferred database job: experience is written five minutes after it is
|
||||||
|
* earned and stats/skills thirty seconds after they change
|
||||||
|
* (see {@link engine.jobs.DatabaseUpdateJob}). This class adds the missing
|
||||||
|
* write-out:
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link #flushAllPlayers()} writes every online character's pending state
|
||||||
|
* (skills/powers, stat modifiers, experience) immediately.</li>
|
||||||
|
* <li>{@link #registerShutdownHook(String)} makes an orderly SIGTERM flush
|
||||||
|
* before the JVM exits. SIGKILL cannot be intercepted by design, so it is
|
||||||
|
* still the operator's job to log the players out first, or to use
|
||||||
|
* {@link #gracefulStop(int)}.</li>
|
||||||
|
* <li>{@link #gracefulStop(int)} announces a countdown to the players, flushes
|
||||||
|
* them and then stops the login and world servers.</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
public class GracefulShutdown {
|
||||||
|
|
||||||
|
private static final AtomicBoolean flushing = new AtomicBoolean(false);
|
||||||
|
private static final AtomicBoolean stopping = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
// Countdown marks, in seconds remaining, that are announced to the players.
|
||||||
|
|
||||||
|
private static final int[] ANNOUNCE_MARKS = {300, 180, 120, 60, 30, 10, 5, 3, 1};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write every online character's deferred state to the database now.
|
||||||
|
* Idempotent and safe to call from a shutdown hook or repeatedly.
|
||||||
|
*
|
||||||
|
* @return the number of characters that were written successfully
|
||||||
|
*/
|
||||||
|
public static int flushAllPlayers() {
|
||||||
|
|
||||||
|
if (flushing.compareAndSet(false, true) == false) {
|
||||||
|
Logger.warn("GracefulShutdown: a flush is already in progress, skipping");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int saved = 0;
|
||||||
|
int failed = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ArrayList<PlayerCharacter> online = new ArrayList<>(SessionManager.getAllActivePlayerCharacters());
|
||||||
|
|
||||||
|
Logger.info("GracefulShutdown: flushing " + online.size() + " online character(s)");
|
||||||
|
|
||||||
|
for (PlayerCharacter pc : online) {
|
||||||
|
|
||||||
|
if (pc == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
pc.updateSkillsAndPowersToDatabase();
|
||||||
|
DbManager.PlayerCharacterQueries.UPDATE_CHARACTER_STATS(pc);
|
||||||
|
DbManager.PlayerCharacterQueries.UPDATE_CHARACTER_EXPERIENCE(pc);
|
||||||
|
saved++;
|
||||||
|
Logger.info("GracefulShutdown: saved " + pc.getCombinedName() + " (" + pc.getObjectUUID() + ')');
|
||||||
|
} catch (Exception e) {
|
||||||
|
failed++;
|
||||||
|
Logger.error("GracefulShutdown: could not save character " + pc.getObjectUUID() + ": " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.info("GracefulShutdown: flush finished, saved=" + saved + " failed=" + failed);
|
||||||
|
System.out.println("GracefulShutdown: flush finished, saved=" + saved + " failed=" + failed);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.error("GracefulShutdown: flush aborted: " + e);
|
||||||
|
} finally {
|
||||||
|
flushing.set(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcast a system-wide flash message to every player.
|
||||||
|
*
|
||||||
|
* @param text - message to display
|
||||||
|
*/
|
||||||
|
public static void announce(String text) {
|
||||||
|
|
||||||
|
if (text == null || text.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ChatManager.chatSystemFlash(text);
|
||||||
|
Logger.info("GracefulShutdown: announced '" + text + '\'');
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.error("GracefulShutdown: unable to announce: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the JVM shutdown hook used by an orderly SIGTERM
|
||||||
|
* (kill -TERM on the process, i.e. the signal the servers currently never
|
||||||
|
* receive). The hook flushes every online character before the JVM exits.
|
||||||
|
*
|
||||||
|
* @param serverName - name used in the log lines
|
||||||
|
*/
|
||||||
|
public static void registerShutdownHook(final String serverName) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Logger.info("GracefulShutdown: " + serverName + " is terminating, flushing player data");
|
||||||
|
System.out.println("GracefulShutdown: " + serverName + " is terminating, flushing player data");
|
||||||
|
flushAllPlayers();
|
||||||
|
Logger.info("GracefulShutdown: " + serverName + " shutdown hook finished");
|
||||||
|
System.out.println("GracefulShutdown: " + serverName + " shutdown hook finished");
|
||||||
|
}
|
||||||
|
}, "gracefulShutdownHook"));
|
||||||
|
|
||||||
|
Logger.info("GracefulShutdown: shutdown hook registered for " + serverName);
|
||||||
|
System.out.println("GracefulShutdown: shutdown hook registered for " + serverName);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.error("GracefulShutdown: unable to register shutdown hook: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Announce a countdown, flush every online character and then stop the
|
||||||
|
* login and world servers. Only the first call has any effect.
|
||||||
|
*
|
||||||
|
* @param delaySeconds - seconds to wait before saving and stopping
|
||||||
|
* (0 stops immediately)
|
||||||
|
*/
|
||||||
|
public static void gracefulStop(final int delaySeconds) {
|
||||||
|
|
||||||
|
if (stopping.compareAndSet(false, true) == false) {
|
||||||
|
Logger.warn("GracefulShutdown: a shutdown is already in progress");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int remaining = Math.max(0, delaySeconds);
|
||||||
|
|
||||||
|
announce("Server is shutting down in " + remaining + " seconds. Please log out to save your character.");
|
||||||
|
|
||||||
|
while (remaining > 0) {
|
||||||
|
|
||||||
|
ThreadUtils.sleep(1000);
|
||||||
|
remaining--;
|
||||||
|
|
||||||
|
for (int mark : ANNOUNCE_MARKS)
|
||||||
|
if (mark == remaining)
|
||||||
|
announce("Server is shutting down in " + remaining + " second(s).");
|
||||||
|
}
|
||||||
|
|
||||||
|
announce("Server is shutting down now. Saving all characters...");
|
||||||
|
|
||||||
|
flushAllPlayers();
|
||||||
|
|
||||||
|
stopServers();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the login and world server processes the same way the devops
|
||||||
|
* scripts do. Called only after every character has been written out.
|
||||||
|
*/
|
||||||
|
private static void stopServers() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Logger.info("GracefulShutdown: stopping the login and world servers");
|
||||||
|
System.out.println("GracefulShutdown: player data saved, stopping the login and world servers");
|
||||||
|
Runtime.getRuntime().exec("./mbkill.sh");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.error("GracefulShutdown: unable to run mbkill.sh: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Give the script a moment to stop the login server before this JVM disappears.
|
||||||
|
|
||||||
|
ThreadUtils.sleep(2000);
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,6 @@ import engine.net.DispatchMessage;
|
|||||||
import engine.net.client.msg.ErrorPopupMsg;
|
import engine.net.client.msg.ErrorPopupMsg;
|
||||||
import engine.net.client.msg.chat.ChatSystemMsg;
|
import engine.net.client.msg.chat.ChatSystemMsg;
|
||||||
import engine.objects.*;
|
import engine.objects.*;
|
||||||
import engine.util.ZoneLevel;
|
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -101,16 +100,6 @@ public enum LootManager {
|
|||||||
boolean hotzoneWasRan = false;
|
boolean hotzoneWasRan = false;
|
||||||
float dropRate = 1.0f;
|
float dropRate = 1.0f;
|
||||||
|
|
||||||
if (mob.getSafeZone() == false)
|
|
||||||
dropRate = LootManager.NORMAL_DROP_RATE;
|
|
||||||
|
|
||||||
if (inHotzone == true)
|
|
||||||
dropRate = LootManager.HOTZONE_DROP_RATE;
|
|
||||||
|
|
||||||
// Adjust for camp scaling
|
|
||||||
Zone camp = mob.getParentZone();
|
|
||||||
dropRate = dropRate * ZoneLevel.getLootDropModifier(camp);
|
|
||||||
|
|
||||||
// Iterate all entries in this bootySet and process accordingly
|
// Iterate all entries in this bootySet and process accordingly
|
||||||
|
|
||||||
for (BootySetEntry bse : entries) {
|
for (BootySetEntry bse : entries) {
|
||||||
@@ -120,6 +109,12 @@ public enum LootManager {
|
|||||||
break;
|
break;
|
||||||
case "LOOT":
|
case "LOOT":
|
||||||
|
|
||||||
|
if (mob.getSafeZone() == false)
|
||||||
|
dropRate = LootManager.NORMAL_DROP_RATE;
|
||||||
|
|
||||||
|
if (inHotzone == true)
|
||||||
|
dropRate = LootManager.HOTZONE_DROP_RATE;
|
||||||
|
|
||||||
if (ThreadLocalRandom.current().nextInt(1, 100 + 1) < (bse.dropChance * dropRate))
|
if (ThreadLocalRandom.current().nextInt(1, 100 + 1) < (bse.dropChance * dropRate))
|
||||||
GenerateLootDrop(mob, bse.genTable, false); //generate normal loot drop
|
GenerateLootDrop(mob, bse.genTable, false); //generate normal loot drop
|
||||||
|
|
||||||
@@ -201,9 +196,6 @@ public enum LootManager {
|
|||||||
Logger.error("Failed to GenerateSuffix for item: " + outItem.getName());
|
Logger.error("Failed to GenerateSuffix for item: " + outItem.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't want to bother with identifying gear
|
|
||||||
outItem.setIsID(true);
|
|
||||||
return outItem;
|
return outItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,9 +306,6 @@ public enum LootManager {
|
|||||||
else
|
else
|
||||||
gold = (int) (gold * NORMAL_GOLD_RATE);
|
gold = (int) (gold * NORMAL_GOLD_RATE);
|
||||||
|
|
||||||
Zone camp = mob.getParentZone();
|
|
||||||
gold = (int) (gold * ZoneLevel.getGoldDropModifier(camp));
|
|
||||||
|
|
||||||
if (gold > 0) {
|
if (gold > 0) {
|
||||||
MobLoot goldAmount = new MobLoot(mob, gold);
|
MobLoot goldAmount = new MobLoot(mob, gold);
|
||||||
mob.getCharItemManager().addItemToInventory(goldAmount);
|
mob.getCharItemManager().addItemToInventory(goldAmount);
|
||||||
|
|||||||
@@ -14,6 +14,21 @@ public class MobAIThread implements Runnable{
|
|||||||
public static int AI_PULSE_MOB_THRESHOLD = 200;
|
public static int AI_PULSE_MOB_THRESHOLD = 200;
|
||||||
public static int AI_PATROL_DIVISOR = 15;
|
public static int AI_PATROL_DIVISOR = 15;
|
||||||
public static float AI_CAST_FREQUENCY;
|
public static float AI_CAST_FREQUENCY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixed-rate pacing for one full AI pass, in milliseconds (default 10 passes
|
||||||
|
* per second).
|
||||||
|
*
|
||||||
|
* The pass used to run with no delay whatsoever - `while (true)` straight into
|
||||||
|
* a sweep of every zone and every mob - which pinned one core for the entire
|
||||||
|
* lifetime of the world server (~100% of a core even in an empty world, two
|
||||||
|
* cores together with MobRespawnThread). Individual actions inside
|
||||||
|
* MobAI.DetermineAction are already gated by timestamps (lastAttackTime,
|
||||||
|
* nextCastTime, patrol delays), so running the sweep at a fixed rate removes
|
||||||
|
* the busy spin without changing behaviour. Raise this value to trade AI
|
||||||
|
* reaction time for CPU.
|
||||||
|
*/
|
||||||
|
public static int AI_TICK_INTERVAL_MS = 100;
|
||||||
// Thread constructor
|
// Thread constructor
|
||||||
|
|
||||||
public MobAIThread() {
|
public MobAIThread() {
|
||||||
@@ -27,6 +42,9 @@ public class MobAIThread implements Runnable{
|
|||||||
AI_CAST_FREQUENCY = Float.parseFloat(ConfigManager.MB_AI_CAST_FREQUENCY.getValue());
|
AI_CAST_FREQUENCY = Float.parseFloat(ConfigManager.MB_AI_CAST_FREQUENCY.getValue());
|
||||||
AI_BASE_AGGRO_RANGE = (int)(60 * Float.parseFloat(ConfigManager.MB_AI_AGGRO_RANGE.getValue()));
|
AI_BASE_AGGRO_RANGE = (int)(60 * Float.parseFloat(ConfigManager.MB_AI_AGGRO_RANGE.getValue()));
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
|
long tickStart = System.currentTimeMillis();
|
||||||
|
|
||||||
for (Zone zone : ZoneManager.getAllZones()) {
|
for (Zone zone : ZoneManager.getAllZones()) {
|
||||||
|
|
||||||
for (Mob mob : zone.zoneMobSet) {
|
for (Mob mob : zone.zoneMobSet) {
|
||||||
@@ -40,6 +58,16 @@ public class MobAIThread implements Runnable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long sleep = AI_TICK_INTERVAL_MS - (System.currentTimeMillis() - tickStart);
|
||||||
|
|
||||||
|
if (sleep > 0) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(sleep);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void startAIThread() {
|
public static void startAIThread() {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ package engine.mobileAI.Threads;
|
|||||||
import engine.gameManager.ZoneManager;
|
import engine.gameManager.ZoneManager;
|
||||||
import engine.objects.Mob;
|
import engine.objects.Mob;
|
||||||
import engine.objects.Zone;
|
import engine.objects.Zone;
|
||||||
import engine.util.ZoneLevel;
|
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,6 +25,14 @@ import org.pmw.tinylog.Logger;
|
|||||||
|
|
||||||
public class MobRespawnThread implements Runnable {
|
public class MobRespawnThread implements Runnable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fixed-rate pacing for one respawn sweep, in milliseconds. The sweep used to
|
||||||
|
* run with no delay at all, pinning a core for the lifetime of the world server
|
||||||
|
* (the 100 ms check below only throttles how often a mob may actually respawn,
|
||||||
|
* it never paused the loop). Keep this at or below the 100 ms respawn throttle.
|
||||||
|
*/
|
||||||
|
public static int RESPAWN_TICK_INTERVAL_MS = 100;
|
||||||
|
|
||||||
public MobRespawnThread() {
|
public MobRespawnThread() {
|
||||||
Logger.info(" MobRespawnThread thread has started!");
|
Logger.info(" MobRespawnThread thread has started!");
|
||||||
|
|
||||||
@@ -34,89 +41,38 @@ public class MobRespawnThread implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
long rollingKeepFraction = (Zone.rollingAvgMobsAliveDepth - 1) / Zone.rollingAvgMobsAliveDepth;
|
|
||||||
long rollingAddFraction = 1 / Zone.rollingAvgMobsAliveDepth;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
try {
|
long tickStart = System.currentTimeMillis();
|
||||||
|
|
||||||
|
try {
|
||||||
for (Zone zone : ZoneManager.getAllZones()) {
|
for (Zone zone : ZoneManager.getAllZones()) {
|
||||||
|
|
||||||
/*
|
if (zone.respawnQue.isEmpty() == false && zone.lastRespawn + 100 < System.currentTimeMillis()) {
|
||||||
if (zone.respawnQue.size() > ZoneLevel.queueLengthToLevelUp) {
|
|
||||||
zone.setCampLvl(zone.getCamplvl() + 1);
|
Mob respawner = zone.respawnQue.iterator().next();
|
||||||
|
|
||||||
|
if (respawner == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
respawner.respawn();
|
||||||
|
zone.respawnQue.remove(respawner);
|
||||||
|
zone.lastRespawn = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
else if (zone.respawnQue.isEmpty() &&
|
|
||||||
(zone.lastRespawn + ZoneLevel.msToLevelDown < System.currentTimeMillis()) &&
|
|
||||||
zone.getCamplvl() > 0) {
|
|
||||||
zone.setCampLvl(zone.getCamplvl() - 1);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
int aliveCount = 0;
|
|
||||||
int deadCount = 0;
|
|
||||||
for (Mob mob : zone.zoneMobSet) {
|
|
||||||
if (mob.isAlive()) {
|
|
||||||
aliveCount = aliveCount + 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
deadCount = deadCount + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
zone.rollingAvgMobsAlive =
|
|
||||||
((zone.rollingAvgMobsAlive * (Zone.rollingAvgMobsAliveDepth - 1) + aliveCount) / Zone.rollingAvgMobsAliveDepth);
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (startTime + ZoneLevel.msDelayToCampLevel < System.currentTimeMillis()) {
|
|
||||||
if (aliveCount > Math.floor(zone.zoneMobSet.size() / 2.0)) {
|
|
||||||
if (zone.levelUpTimer == 0) {
|
|
||||||
zone.levelUpTimer = System.currentTimeMillis();
|
|
||||||
} else if (zone.levelUpTimer + ZoneLevel.msTolevelUp < System.currentTimeMillis()) {
|
|
||||||
zone.setCampLvl(zone.getCampLvl() + 1);
|
|
||||||
|
|
||||||
zone.levelUpTimer = 0;
|
|
||||||
}
|
|
||||||
} else if (aliveCount == 0) {
|
|
||||||
|
|
||||||
if (zone.levelDownTimer == 0) {
|
|
||||||
zone.levelDownTimer = System.currentTimeMillis();
|
|
||||||
} else if (zone.levelDownTimer + ZoneLevel.msToLevelDown < System.currentTimeMillis()) {
|
|
||||||
if (zone.getCampLvl() > 0) {
|
|
||||||
zone.setCampLvl(zone.getCampLvl() + 1);
|
|
||||||
|
|
||||||
zone.levelDownTimer = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
zone.levelUpTimer = 0;
|
|
||||||
zone.levelDownTimer = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------
|
|
||||||
// Manage mob respawn
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------
|
|
||||||
if (!Zone.respawnQue.isEmpty() && Zone.lastRespawn + 100 < System.currentTimeMillis()) {
|
|
||||||
|
|
||||||
Mob respawner = Zone.respawnQue.iterator().next();
|
|
||||||
|
|
||||||
if (respawner == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
respawner.respawn();
|
|
||||||
Zone.respawnQue.remove(respawner);
|
|
||||||
Zone.lastRespawn = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.error(e);
|
Logger.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long sleep = RESPAWN_TICK_INTERVAL_MS - (System.currentTimeMillis() - tickStart);
|
||||||
|
|
||||||
|
if (sleep > 0) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(sleep);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void startRespawnThread() {
|
public static void startRespawnThread() {
|
||||||
|
|||||||
@@ -290,9 +290,7 @@ public class Mine extends AbstractGameObject {
|
|||||||
if (treeRank < 1)
|
if (treeRank < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// We check the limit against only the player guild right now
|
if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false) {
|
||||||
// each guild (even within a nation) is limited by the nation tree
|
|
||||||
if (guildUnderMineLimit(playerGuild, treeRank) == false) {
|
|
||||||
ErrorPopupMsg.sendErrorMsg(playerCharacter, "Your nation cannot support another mine.");
|
ErrorPopupMsg.sendErrorMsg(playerCharacter, "Your nation cannot support another mine.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -306,11 +304,10 @@ public class Mine extends AbstractGameObject {
|
|||||||
|
|
||||||
mineCnt += Mine.getMinesForGuild(playerGuild.getObjectUUID()).size();
|
mineCnt += Mine.getMinesForGuild(playerGuild.getObjectUUID()).size();
|
||||||
|
|
||||||
// Only count mines for a specific guild
|
for (Guild guild : playerGuild.getSubGuildList())
|
||||||
//for (Guild guild : playerGuild.getSubGuildList())
|
mineCnt += Mine.getMinesForGuild(guild.getObjectUUID()).size();
|
||||||
// mineCnt += Mine.getMinesForGuild(guild.getObjectUUID()).size();
|
|
||||||
|
|
||||||
return mineCnt <= (tolRank * 2);
|
return mineCnt <= tolRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean changeProductionType(Resource resource) {
|
public boolean changeProductionType(Resource resource) {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import engine.net.client.msg.PlaceAssetMsg;
|
|||||||
import engine.powers.EffectsBase;
|
import engine.powers.EffectsBase;
|
||||||
import engine.powers.MobPowerEntry;
|
import engine.powers.MobPowerEntry;
|
||||||
import engine.server.MBServerStatics;
|
import engine.server.MBServerStatics;
|
||||||
import engine.util.ZoneLevel;
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
@@ -102,8 +101,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
private DateTime upgradeDateTime = null;
|
private DateTime upgradeDateTime = null;
|
||||||
private boolean lootSync = false;
|
private boolean lootSync = false;
|
||||||
|
|
||||||
private String originalFirstName;
|
|
||||||
private String originalLastName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No Id Constructor
|
* No Id Constructor
|
||||||
@@ -132,9 +129,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
this.lastName = "the " + contract.getName();
|
this.lastName = "the " + contract.getName();
|
||||||
}
|
}
|
||||||
clearStatic();
|
clearStatic();
|
||||||
|
|
||||||
originalFirstName = this.firstName;
|
|
||||||
originalLastName = this.lastName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,9 +150,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
this.building = building;
|
this.building = building;
|
||||||
initializeMob(false, false, false);
|
initializeMob(false, false, false);
|
||||||
clearStatic();
|
clearStatic();
|
||||||
|
|
||||||
originalFirstName = this.firstName;
|
|
||||||
originalLastName = this.lastName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,9 +166,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
this.BehaviourType = Enum.MobBehaviourType.Pet1;
|
this.BehaviourType = Enum.MobBehaviourType.Pet1;
|
||||||
initializeMob(true, false, false);
|
initializeMob(true, false, false);
|
||||||
clearStatic();
|
clearStatic();
|
||||||
|
|
||||||
originalFirstName = this.firstName;
|
|
||||||
originalLastName = this.lastName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//SIEGE CONSTRUCTOR
|
//SIEGE CONSTRUCTOR
|
||||||
@@ -192,9 +180,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
this.equip = new HashMap<>();
|
this.equip = new HashMap<>();
|
||||||
initializeMob(false, true, isPlayerGuard);
|
initializeMob(false, true, isPlayerGuard);
|
||||||
clearStatic();
|
clearStatic();
|
||||||
|
|
||||||
originalFirstName = this.firstName;
|
|
||||||
originalLastName = this.lastName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -303,8 +288,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
Logger.error("Mobile:" + this.dbID + ": " + e);
|
Logger.error("Mobile:" + this.dbID + ": " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
originalFirstName = this.firstName;
|
|
||||||
originalLastName = this.lastName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serializeMobForClientMsgOtherPlayer(Mob mob, ByteBufferWriter writer) throws SerializationException {
|
public static void serializeMobForClientMsgOtherPlayer(Mob mob, ByteBufferWriter writer) throws SerializationException {
|
||||||
@@ -1399,12 +1382,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
|
|
||||||
NPCManager.applyRuneSetEffects(this);
|
NPCManager.applyRuneSetEffects(this);
|
||||||
|
|
||||||
// Set Name based on parent zone level
|
|
||||||
Zone camp = this.getParentZone();
|
|
||||||
this.lastName = this.originalLastName + ZoneLevel.getNameSuffix(camp);
|
|
||||||
|
|
||||||
//PowersManager.applyPower(this, this, this.getLoc(), "CMP-001", camp.getCamplvl(), false);
|
|
||||||
|
|
||||||
this.recalculateStats();
|
this.recalculateStats();
|
||||||
this.setHealth(this.healthMax);
|
this.setHealth(this.healthMax);
|
||||||
|
|
||||||
@@ -1518,10 +1495,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
s *= (1 + this.bonuses.getFloatPercentAll(ModType.StaminaFull, SourceType.None));
|
s *= (1 + this.bonuses.getFloatPercentAll(ModType.StaminaFull, SourceType.None));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify max health based on camp level - bad, we need to use effects for this
|
|
||||||
Zone camp = this.getParentZone();
|
|
||||||
h = h * ZoneLevel.getMaxHealthPctModifier(camp);
|
|
||||||
|
|
||||||
// Set max health, mana and stamina
|
// Set max health, mana and stamina
|
||||||
|
|
||||||
if (h > 0)
|
if (h > 0)
|
||||||
@@ -1622,11 +1595,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
Logger.error("Error: missing bonuses");
|
Logger.error("Error: missing bonuses");
|
||||||
|
|
||||||
defense = (defense < 1) ? 1 : defense;
|
defense = (defense < 1) ? 1 : defense;
|
||||||
|
|
||||||
// Modify defense for camp level - bad, we need to use effects for this
|
|
||||||
Zone camp = this.getParentZone();
|
|
||||||
defense = defense * ZoneLevel.getDefPctModifier(camp);
|
|
||||||
|
|
||||||
this.defenseRating = (short) (defense + 0.5f);
|
this.defenseRating = (short) (defense + 0.5f);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.info("Mobbase ID " + this.getMobBaseID() + " returned an error. Setting to Default Defense." + e.getMessage());
|
Logger.info("Mobbase ID " + this.getMobBaseID() + " returned an error. Setting to Default Defense." + e.getMessage());
|
||||||
@@ -1828,10 +1796,6 @@ public class Mob extends AbstractIntelligenceAgent {
|
|||||||
atr *= (1 + neg_Bonus);
|
atr *= (1 + neg_Bonus);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify atr for camp level - bad, we need to use effects for this
|
|
||||||
Zone camp = this.getParentZone();
|
|
||||||
atr = atr * ZoneLevel.getAtrPctModifier(camp);
|
|
||||||
|
|
||||||
atr = (atr < 1) ? 1 : atr;
|
atr = (atr < 1) ? 1 : atr;
|
||||||
|
|
||||||
// set atr
|
// set atr
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ import engine.math.Bounds;
|
|||||||
import engine.math.Vector2f;
|
import engine.math.Vector2f;
|
||||||
import engine.math.Vector3fImmutable;
|
import engine.math.Vector3fImmutable;
|
||||||
import engine.net.ByteBufferWriter;
|
import engine.net.ByteBufferWriter;
|
||||||
import engine.net.DispatchMessage;
|
|
||||||
import engine.net.client.msg.chat.ChatSystemMsg;
|
|
||||||
import engine.server.MBServerStatics;
|
import engine.server.MBServerStatics;
|
||||||
import engine.util.ZoneLevel;
|
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -64,13 +61,6 @@ public class Zone extends AbstractGameObject {
|
|||||||
//public static ArrayList<Mob> respawnQue = new ArrayList<>();
|
//public static ArrayList<Mob> respawnQue = new ArrayList<>();
|
||||||
public static final Set<Mob> respawnQue = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
public static final Set<Mob> respawnQue = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||||
public static long lastRespawn = 0;
|
public static long lastRespawn = 0;
|
||||||
|
|
||||||
private int campLvl = 0;
|
|
||||||
public long levelUpTimer = 0;
|
|
||||||
public long levelDownTimer = 0;
|
|
||||||
public int rollingAvgMobsAlive = 0;
|
|
||||||
public static final int rollingAvgMobsAliveDepth = 100;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ResultSet Constructor
|
* ResultSet Constructor
|
||||||
*/
|
*/
|
||||||
@@ -110,33 +100,8 @@ public class Zone extends AbstractGameObject {
|
|||||||
|
|
||||||
if (hash == null)
|
if (hash == null)
|
||||||
setHash();
|
setHash();
|
||||||
}
|
|
||||||
|
|
||||||
public void setCampLvl(int level)
|
|
||||||
{
|
|
||||||
this.campLvl = level;
|
|
||||||
|
|
||||||
if (this.campLvl > ZoneLevel.campMaxLvl)
|
|
||||||
{
|
|
||||||
this.campLvl = ZoneLevel.campMaxLvl;
|
|
||||||
}
|
|
||||||
else if (this.campLvl < 0)
|
|
||||||
{
|
|
||||||
this.campLvl = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (this.campLvl > ZoneLevel.campLvlAnnounceThreshold)
|
|
||||||
{
|
|
||||||
ChatSystemMsg chatMsg = new ChatSystemMsg(null, this.getName() + " has reached camp level " + this.campLvl + "! Will anyone contest?!");
|
|
||||||
chatMsg.setMessageType(2);
|
|
||||||
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
|
|
||||||
DispatchMessage.dispatchMsgToAll(chatMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCampLvl()
|
|
||||||
{
|
|
||||||
return this.campLvl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) {
|
public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) {
|
||||||
|
|||||||
@@ -96,6 +96,11 @@ public class LoginServer {
|
|||||||
// Start the Login Server
|
// Start the Login Server
|
||||||
|
|
||||||
loginServer.init();
|
loginServer.init();
|
||||||
|
|
||||||
|
// flush any cached character state on an orderly termination
|
||||||
|
// (the login server holds no players, so this normally logs 0).
|
||||||
|
|
||||||
|
GracefulShutdown.registerShutdownHook("LoginServer");
|
||||||
loginServer.exec();
|
loginServer.exec();
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -145,29 +150,42 @@ public class LoginServer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when something is already listening on the given TCP port.
|
||||||
|
*
|
||||||
|
* This used to shell out to `lsof -i tcp:<port>` through /bin/bash and read the
|
||||||
|
* child's output until EOF. With no timeout and no waitFor() a child that blocks
|
||||||
|
* is fatal: lsof has been observed stuck in uninterruptible I/O (D state) while
|
||||||
|
* scanning the busy world server inside the container, which left the login
|
||||||
|
* server permanently inside its startup path. LoginServer.exec() never returned
|
||||||
|
* from checkServerHealth(), the accept loop never started, and clients could open
|
||||||
|
* a TCP connection to the port and then wait forever for the 100 byte DH
|
||||||
|
* handshake - surfacing as "Failed to open a server connection" after the
|
||||||
|
* client's own timeout.
|
||||||
|
*
|
||||||
|
* A bind probe is equivalent for this purpose, needs no external tool and cannot
|
||||||
|
* hang. SO_REUSEADDR does not allow stealing a port that is actively listening,
|
||||||
|
* so a successful bind still means the port is free.
|
||||||
|
*/
|
||||||
public static boolean isPortInUse(int port) {
|
public static boolean isPortInUse(int port) {
|
||||||
|
|
||||||
ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "lsof -i tcp:" + port + " | tail -n +2 | awk '{print $2}'");
|
java.net.ServerSocket probe = null;
|
||||||
builder.redirectErrorStream(true);
|
|
||||||
Process process = null;
|
|
||||||
String line = null;
|
|
||||||
boolean portInUse = false;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
process = builder.start();
|
probe = new java.net.ServerSocket();
|
||||||
|
probe.setReuseAddress(true);
|
||||||
InputStream is = process.getInputStream();
|
probe.bind(new java.net.InetSocketAddress(port));
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
return false;
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
portInUse = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
return true;
|
||||||
|
} finally {
|
||||||
|
if (probe != null)
|
||||||
|
try {
|
||||||
|
probe.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// the bind result is what matters; closing cannot change it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return portInUse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exec() {
|
private void exec() {
|
||||||
|
|||||||
@@ -109,6 +109,11 @@ public class WorldServer {
|
|||||||
|
|
||||||
worldServer.init();
|
worldServer.init();
|
||||||
|
|
||||||
|
// flush every online character if the JVM is asked to terminate
|
||||||
|
// in an orderly way (kill -TERM); SIGKILL cannot be intercepted.
|
||||||
|
|
||||||
|
GracefulShutdown.registerShutdownHook("WorldServer");
|
||||||
|
|
||||||
int retVal = worldServer.exec();
|
int retVal = worldServer.exec();
|
||||||
|
|
||||||
if (retVal != 0)
|
if (retVal != 0)
|
||||||
@@ -288,7 +293,6 @@ public class WorldServer {
|
|||||||
|
|
||||||
private boolean init() {
|
private boolean init() {
|
||||||
|
|
||||||
Logger.info("Server Code: [NovaTest] Branch");
|
|
||||||
Logger.info("MAGICBANE SERVER GREETING:");
|
Logger.info("MAGICBANE SERVER GREETING:");
|
||||||
Logger.info(ConfigManager.MB_WORLD_GREETING.getValue());
|
Logger.info(ConfigManager.MB_WORLD_GREETING.getValue());
|
||||||
|
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
package engine.util;
|
|
||||||
|
|
||||||
import engine.objects.Zone;
|
|
||||||
|
|
||||||
public class ZoneLevel {
|
|
||||||
|
|
||||||
private static final float healthPctPerLevel = (float)0.2;
|
|
||||||
private static final float atrPctPerLevel = (float)0.2;
|
|
||||||
private static final float defPctPerLevel = (float)0.2;
|
|
||||||
private static final float lootPctPerLevel = (float)0.1;
|
|
||||||
private static final float goldPctPerLevel = (float)0.2;
|
|
||||||
|
|
||||||
public static final int campLvlAnnounceThreshold = 5;
|
|
||||||
public static final int campMaxLvl = 10;
|
|
||||||
|
|
||||||
public static final int queueLengthToLevelUp = 5;
|
|
||||||
public static final int msToLevelDown = 60 * 1000;
|
|
||||||
public static final int msTolevelUp = 60 * 1000;
|
|
||||||
public static final long msDelayToCampLevel = 60 * 1000;
|
|
||||||
|
|
||||||
private static final String[] nameMap =
|
|
||||||
{
|
|
||||||
"",
|
|
||||||
" I",
|
|
||||||
" II",
|
|
||||||
" III",
|
|
||||||
" IV",
|
|
||||||
" V",
|
|
||||||
" VI",
|
|
||||||
" VII",
|
|
||||||
" VIII",
|
|
||||||
" IX",
|
|
||||||
" X"
|
|
||||||
};
|
|
||||||
|
|
||||||
public static String getNameSuffix(Zone zone)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return nameMap[zone.getCampLvl()];
|
|
||||||
}
|
|
||||||
catch (Exception ignored)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getMaxHealthPctModifier(Zone zone)
|
|
||||||
{
|
|
||||||
return getGenericModifier(zone, healthPctPerLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getAtrPctModifier(Zone zone)
|
|
||||||
{
|
|
||||||
return getGenericModifier(zone, atrPctPerLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getDefPctModifier(Zone zone)
|
|
||||||
{
|
|
||||||
return getGenericModifier(zone, defPctPerLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getLootDropModifier(Zone zone)
|
|
||||||
{
|
|
||||||
return getGenericModifier(zone, lootPctPerLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getGoldDropModifier(Zone zone)
|
|
||||||
{
|
|
||||||
return getGenericModifier(zone, goldPctPerLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static float getGenericModifier(Zone zone, float modifierPerLevel)
|
|
||||||
{
|
|
||||||
float modifier = (float)1.0;
|
|
||||||
|
|
||||||
if (zone != null)
|
|
||||||
{
|
|
||||||
modifier += zone.getCampLvl() * modifierPerLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
return modifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -128,12 +128,10 @@ public class HourlyJobThread implements Runnable {
|
|||||||
if (mine.isActive == false)
|
if (mine.isActive == false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Logger.info(mine.getZoneName() + "'s Mine is now Closing");
|
|
||||||
|
|
||||||
Building mineBuilding = BuildingManager.getBuildingFromCache(mine.getBuildingID());
|
Building mineBuilding = BuildingManager.getBuildingFromCache(mine.getBuildingID());
|
||||||
|
|
||||||
if (mineBuilding == null) {
|
if (mineBuilding == null) {
|
||||||
Logger.info("Null mine building for Mine " + mine.getObjectUUID() + " Building " + mine.getBuildingID());
|
Logger.debug("Null mine building for Mine " + mine.getObjectUUID() + " Building " + mine.getBuildingID());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,8 +139,6 @@ public class HourlyJobThread implements Runnable {
|
|||||||
// We can early exit here.
|
// We can early exit here.
|
||||||
|
|
||||||
if (mineBuilding.getRank() > 0) {
|
if (mineBuilding.getRank() > 0) {
|
||||||
Logger.info("Mine still standing when closing window. Mine Object UUID: " + mine.getObjectUUID() + " Building Id: " + mine.getBuildingID());
|
|
||||||
|
|
||||||
mine.setActive(false);
|
mine.setActive(false);
|
||||||
mine.lastClaimer = null;
|
mine.lastClaimer = null;
|
||||||
return true;
|
return true;
|
||||||
@@ -153,8 +149,6 @@ public class HourlyJobThread implements Runnable {
|
|||||||
// and keep the window open.
|
// and keep the window open.
|
||||||
|
|
||||||
if (!Mine.validateClaimer(mine.lastClaimer)) {
|
if (!Mine.validateClaimer(mine.lastClaimer)) {
|
||||||
Logger.info("Mine has no valid claimer when closing window. Mine Object UUID: " + mine.getObjectUUID() + " Building Id: " + mine.getBuildingID());
|
|
||||||
|
|
||||||
mine.lastClaimer = null;
|
mine.lastClaimer = null;
|
||||||
mine.updateGuildOwner(null);
|
mine.updateGuildOwner(null);
|
||||||
mine.setActive(true);
|
mine.setActive(true);
|
||||||
@@ -163,8 +157,6 @@ public class HourlyJobThread implements Runnable {
|
|||||||
|
|
||||||
//Update ownership to map
|
//Update ownership to map
|
||||||
|
|
||||||
Logger.info("Mine ownership changing when closing window. Mine Object UUID: " + mine.getObjectUUID() + " Building Id: " + mine.getBuildingID() + " new owning guild: " + mine.getOwningGuild().getObjectUUID());
|
|
||||||
|
|
||||||
mine.guildName = mine.getOwningGuild().getName();
|
mine.guildName = mine.getOwningGuild().getName();
|
||||||
mine.guildTag = mine.getOwningGuild().getGuildTag();
|
mine.guildTag = mine.getOwningGuild().getGuildTag();
|
||||||
Guild nation = mine.getOwningGuild().getNation();
|
Guild nation = mine.getOwningGuild().getNation();
|
||||||
|
|||||||
Reference in new issue
Block a user