forked from MagicBane/Server
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2653c465d1 | ||
|
|
97eff6517e | ||
|
|
9f3ec7c553 |
@@ -24,5 +24,3 @@
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
@@ -14,7 +14,6 @@ import engine.gameManager.ChatManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.Item;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
|
||||
/**
|
||||
* @author Eighty
|
||||
@@ -47,10 +46,10 @@ public class AddGoldCmd extends AbstractDevCmd {
|
||||
throwbackError(pc, "Quantity must be a number, " + words[0] + " is invalid");
|
||||
return;
|
||||
}
|
||||
if (amt < 1 || amt > MBServerStatics.PLAYER_GOLD_LIMIT) {
|
||||
throwbackError(pc, "Quantity must be between 1 and " + MBServerStatics.PLAYER_GOLD_LIMIT);
|
||||
if (amt < 1 || amt > 10000000) {
|
||||
throwbackError(pc, "Quantity must be between 1 and 10000000 (10 million)");
|
||||
return;
|
||||
} else if ((curAmt + amt) > MBServerStatics.PLAYER_GOLD_LIMIT) {
|
||||
} else if ((curAmt + amt) > 10000000) {
|
||||
throwbackError(pc, "This would place your inventory over 10,000,000 gold.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.*;
|
||||
import engine.powers.EffectsBase;
|
||||
import engine.server.MBServerStatics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -32,82 +31,47 @@ public class MakeItemCmd extends AbstractDevCmd {
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
if (words[0].equals("resources")) {
|
||||
|
||||
int resourceAmount = 1000;
|
||||
|
||||
if (words.length > 1) {
|
||||
try {
|
||||
resourceAmount = Integer.parseInt(words[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pc, "Resource amount must be a number.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (resourceAmount < 1)
|
||||
resourceAmount = 1;
|
||||
|
||||
resourceAmount = Math.min(
|
||||
resourceAmount,
|
||||
MBServerStatics.RESOURCE_STACK_LIMIT
|
||||
);
|
||||
|
||||
for (int ibID : Warehouse.getMaxResources().keySet()) {
|
||||
|
||||
if (ibID == 7)
|
||||
continue;
|
||||
|
||||
ItemBase ib = ItemBase.getItemBase(ibID);
|
||||
|
||||
if (ib == null)
|
||||
continue;
|
||||
|
||||
short weight = ib.getWeight();
|
||||
|
||||
if (!pc.getCharItemManager().hasRoomInventory(weight)) {
|
||||
throwbackError(pc, "Not enough room in inventory for any more resources.");
|
||||
throwbackError(pc, "Not enough room in inventory for any more of this item");
|
||||
|
||||
pc.getCharItemManager().updateInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
Item item = new Item(
|
||||
ib,
|
||||
pc.getObjectUUID(),
|
||||
OwnerType.PlayerCharacter,
|
||||
(byte) 0,
|
||||
(byte) 0,
|
||||
(short) ib.getDurability(),
|
||||
(short) ib.getDurability(),
|
||||
true,
|
||||
false,
|
||||
ItemContainerType.INVENTORY,
|
||||
(byte) 0,
|
||||
new ArrayList<>(),
|
||||
""
|
||||
);
|
||||
boolean worked = false;
|
||||
Item item = new Item(ib, pc.getObjectUUID(),
|
||||
OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) ib.getDurability(), (short) ib.getDurability(),
|
||||
true, false, ItemContainerType.INVENTORY, (byte) 0,
|
||||
new ArrayList<>(), "");
|
||||
|
||||
item.setNumOfItems(resourceAmount);
|
||||
item.setNumOfItems(Warehouse.getMaxResources().get(ibID));
|
||||
|
||||
try {
|
||||
item = DbManager.ItemQueries.ADD_ITEM(item);
|
||||
worked = true;
|
||||
} catch (Exception e) {
|
||||
throwbackError(
|
||||
pc,
|
||||
"Unable to create resource " + ib.getName() + ": " + e.getMessage()
|
||||
);
|
||||
throwbackError(pc, "DB error 1: Unable to create item. " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
throwbackError(pc, "Unable to create resource " + ib.getName() + ".");
|
||||
if (item == null || !worked) {
|
||||
throwbackError(pc, "DB error 2: Unable to create item.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//add item to inventory
|
||||
pc.getCharItemManager().addItemToInventory(item);
|
||||
}
|
||||
|
||||
pc.getCharItemManager().updateInventory();
|
||||
return;
|
||||
}
|
||||
if (words.length < 3 || words.length > 5) {
|
||||
@@ -136,7 +100,7 @@ public class MakeItemCmd extends AbstractDevCmd {
|
||||
return;
|
||||
}
|
||||
numItems = (numItems < 1) ? 1 : numItems;
|
||||
numItems = Math.min(numItems, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
numItems = (numItems > 5000) ? 5000 : numItems;
|
||||
}
|
||||
|
||||
int itembaseID;
|
||||
|
||||
@@ -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]'";
|
||||
}
|
||||
}
|
||||
@@ -39,13 +39,6 @@ public class SlotTestCmd extends AbstractDevCmd {
|
||||
|
||||
Building building = (Building) target;
|
||||
|
||||
outString += "Rank: " + building.getRank() + "\r\n";
|
||||
outString += "MaxSlots: " + building.getBlueprint().getMaxSlots() + "\r\n";
|
||||
outString += "SlotsForRank: "
|
||||
+ building.getBlueprint().getSlotsForRank(building.getRank())
|
||||
+ "\r\n";
|
||||
outString += "Hireling Count: " + building.getHirelings().size() + "\r\n\r\n";
|
||||
|
||||
buildingLocations = BuildingManager._slotLocations.get(building.meshUUID);
|
||||
|
||||
if (buildingLocations == null) {
|
||||
|
||||
@@ -289,34 +289,6 @@ public enum BuildingManager {
|
||||
|
||||
// Method transfers ownership of all hirelings in a building
|
||||
|
||||
public static void reslotHirelings(Building building) {
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
|
||||
ArrayList<AbstractCharacter> hirelings =
|
||||
new ArrayList<>(building.getHirelings().keySet());
|
||||
|
||||
building.getHirelings().clear();
|
||||
|
||||
for (AbstractCharacter hireling : hirelings) {
|
||||
|
||||
int newSlot = NPCManager.slotCharacterInBuilding(hireling);
|
||||
|
||||
if (newSlot == -1) {
|
||||
Logger.error("Unable to re-slot hireling "
|
||||
+ hireling.getObjectUUID()
|
||||
+ " for building "
|
||||
+ building.getObjectUUID());
|
||||
continue;
|
||||
}
|
||||
|
||||
hireling.setLoc(hireling.getBindLoc());
|
||||
WorldGrid.updateObject(hireling);
|
||||
InterestManager.setObjectDirty(hireling);
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshHirelings(Building building) {
|
||||
|
||||
if (building == null)
|
||||
|
||||
@@ -123,6 +123,7 @@ public enum DevCmdManager {
|
||||
DevCmdManager.registerDevCmd(new ShowOffsetCmd());
|
||||
DevCmdManager.registerDevCmd(new RealmInfoCmd());
|
||||
DevCmdManager.registerDevCmd(new RebootCmd());
|
||||
DevCmdManager.registerDevCmd(new ShutdownCmd());
|
||||
DevCmdManager.registerDevCmd(new SetMineTypeCmd());
|
||||
DevCmdManager.registerDevCmd(new SetMineExpansion());
|
||||
DevCmdManager.registerDevCmd(new SetForceRenameCityCmd());
|
||||
|
||||
@@ -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,6 +14,21 @@ public class MobAIThread implements Runnable{
|
||||
public static int AI_PULSE_MOB_THRESHOLD = 200;
|
||||
public static int AI_PATROL_DIVISOR = 15;
|
||||
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
|
||||
|
||||
public MobAIThread() {
|
||||
@@ -27,6 +42,9 @@ public class MobAIThread implements Runnable{
|
||||
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()));
|
||||
while (true) {
|
||||
|
||||
long tickStart = System.currentTimeMillis();
|
||||
|
||||
for (Zone zone : ZoneManager.getAllZones()) {
|
||||
|
||||
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() {
|
||||
|
||||
@@ -25,6 +25,13 @@ import org.pmw.tinylog.Logger;
|
||||
|
||||
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() {
|
||||
Logger.info(" MobRespawnThread thread has started!");
|
||||
@@ -36,6 +43,8 @@ public class MobRespawnThread implements Runnable {
|
||||
|
||||
while (true) {
|
||||
|
||||
long tickStart = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
for (Zone zone : ZoneManager.getAllZones()) {
|
||||
|
||||
@@ -55,6 +64,15 @@ public class MobRespawnThread implements Runnable {
|
||||
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() {
|
||||
|
||||
@@ -1259,7 +1259,7 @@ public class ClientMessagePump implements NetMsgHandler {
|
||||
|
||||
cost *= profit;
|
||||
|
||||
if (gold.getNumOfItems() + cost > MBServerStatics.PLAYER_GOLD_LIMIT) {
|
||||
if (gold.getNumOfItems() + cost > 10000000) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -335,7 +335,7 @@ public class Blueprint {
|
||||
availableSlots = 3;
|
||||
break;
|
||||
case 8:
|
||||
availableSlots = Math.min(3, this.maxSlots);
|
||||
availableSlots = 1;
|
||||
break;
|
||||
default:
|
||||
availableSlots = 0;
|
||||
|
||||
@@ -427,10 +427,6 @@ public class Building extends AbstractWorldObject {
|
||||
|
||||
BuildingManager.cleanupHirelings(this);
|
||||
|
||||
if (this.getBlueprint().getBuildingGroup() == BuildingGroup.TOL
|
||||
&& this.rank == 8)
|
||||
BuildingManager.reslotHirelings(this);
|
||||
|
||||
this.isDeranking.compareAndSet(true, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -2335,14 +2335,15 @@ public class CharacterItemManager {
|
||||
}
|
||||
|
||||
|
||||
if (this.getGoldInventory().getNumOfItems() + goldFrom2 > MBServerStatics.PLAYER_GOLD_LIMIT) {
|
||||
if (this.getGoldInventory().getNumOfItems() + goldFrom2 > 10000000) {
|
||||
PlayerCharacter pc = (PlayerCharacter) this.absCharacter;
|
||||
if (pc.getClientConnection() != null)
|
||||
ErrorPopupMsg.sendErrorPopup(pc, 202);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tradingWith.getGoldInventory().getNumOfItems() + goldFrom1 > MBServerStatics.PLAYER_GOLD_LIMIT) {
|
||||
|
||||
if (tradingWith.getGoldInventory().getNumOfItems() + goldFrom1 > 10000000) {
|
||||
PlayerCharacter pc = (PlayerCharacter) tradingWith.absCharacter;
|
||||
if (pc.getClientConnection() != null)
|
||||
ErrorPopupMsg.sendErrorPopup(pc, 202);
|
||||
|
||||
@@ -674,6 +674,46 @@ public class Item extends AbstractWorldObject {
|
||||
public static Item newGoldItem(AbstractWorldObject awo, ItemBase ib, Enum.ItemContainerType containerType) {
|
||||
return newGoldItem(awo, ib, containerType, true);
|
||||
}
|
||||
|
||||
//used for vault!
|
||||
public static Item newGoldItem(int accountID, ItemBase ib, Enum.ItemContainerType containerType) {
|
||||
return newGoldItem(accountID, ib, containerType, true);
|
||||
}
|
||||
|
||||
private static Item newGoldItem(int accountID, ItemBase ib, Enum.ItemContainerType containerType, boolean persist) {
|
||||
|
||||
int ownerID;
|
||||
OwnerType ownerType;
|
||||
|
||||
ownerID = accountID;
|
||||
ownerType = OwnerType.Account;
|
||||
|
||||
|
||||
Item newGold = new Item(ib, ownerID, ownerType,
|
||||
(byte) 0, (byte) 0, (short) 0, (short) 0, true, false, containerType, (byte) 0,
|
||||
new ArrayList<>(), "");
|
||||
|
||||
synchronized (newGold) {
|
||||
newGold.numberOfItems = 0;
|
||||
}
|
||||
|
||||
if (persist) {
|
||||
try {
|
||||
newGold = DbManager.ItemQueries.ADD_ITEM(newGold);
|
||||
if (newGold != null) {
|
||||
synchronized (newGold) {
|
||||
newGold.numberOfItems = 0;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
DbManager.ItemQueries.ZERO_ITEM_STACK(newGold);
|
||||
}
|
||||
|
||||
return newGold;
|
||||
}
|
||||
|
||||
private static Item newGoldItem(AbstractWorldObject awo, ItemBase ib, Enum.ItemContainerType containerType, boolean persist) {
|
||||
|
||||
int ownerID;
|
||||
@@ -731,49 +771,10 @@ public class Item extends AbstractWorldObject {
|
||||
}
|
||||
DbManager.ItemQueries.ZERO_ITEM_STACK(newGold);
|
||||
}
|
||||
|
||||
newGold.containerType = containerType;
|
||||
|
||||
return newGold;
|
||||
}
|
||||
//used for vault!
|
||||
public static Item newGoldItem(int accountID, ItemBase ib, Enum.ItemContainerType containerType) {
|
||||
return newGoldItem(accountID, ib, containerType, true);
|
||||
}
|
||||
|
||||
private static Item newGoldItem(int accountID, ItemBase ib, Enum.ItemContainerType containerType, boolean persist) {
|
||||
|
||||
int ownerID;
|
||||
OwnerType ownerType;
|
||||
|
||||
ownerID = accountID;
|
||||
ownerType = OwnerType.Account;
|
||||
|
||||
|
||||
Item newGold = new Item(ib, ownerID, ownerType,
|
||||
(byte) 0, (byte) 0, (short) 0, (short) 0, true, false, containerType, (byte) 0,
|
||||
new ArrayList<>(), "");
|
||||
|
||||
synchronized (newGold) {
|
||||
newGold.numberOfItems = 0;
|
||||
}
|
||||
|
||||
if (persist) {
|
||||
try {
|
||||
newGold = DbManager.ItemQueries.ADD_ITEM(newGold);
|
||||
if (newGold != null) {
|
||||
synchronized (newGold) {
|
||||
newGold.numberOfItems = 0;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
DbManager.ItemQueries.ZERO_ITEM_STACK(newGold);
|
||||
}
|
||||
|
||||
return newGold;
|
||||
}
|
||||
|
||||
// This is to be used for trades - the new item is not stored in the database
|
||||
public static Item newGoldItemTemp(AbstractWorldObject awo, ItemBase ib) {
|
||||
|
||||
@@ -1239,17 +1239,12 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
playerCharacter.deactivateCharacter();
|
||||
return null;
|
||||
}
|
||||
// Ebonreach: give new characters starter gold.
|
||||
Item starterGold = Item.newGoldItem(playerCharacter, ItemBase.getItemBase(7), Enum.ItemContainerType.INVENTORY);
|
||||
|
||||
if (starterGold != null)
|
||||
DbManager.ItemQueries.UPDATE_GOLD(starterGold, 10000);
|
||||
|
||||
// Get any new skills that belong to the player
|
||||
playerCharacter.calculateSkills();
|
||||
|
||||
a.setLastCharacter(playerCharacter.getObjectUUID());
|
||||
playerCharacter.getCharItemManager().load();
|
||||
playerCharacter.charItemManager.load();
|
||||
|
||||
playerCharacter.activateCharacter();
|
||||
|
||||
|
||||
@@ -99,29 +99,29 @@ public class Warehouse extends AbstractWorldObject {
|
||||
|
||||
public static ConcurrentHashMap<Integer, Integer> getMaxResources() {
|
||||
if (maxResources.size() != 23) {
|
||||
maxResources.put(7, 1000000000);
|
||||
maxResources.put(1580000, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580001, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580002, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580003, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580004, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580005, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580006, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580007, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580008, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580009, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580010, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580011, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580012, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580013, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580014, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580015, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580016, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580017, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580018, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580019, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580020, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(1580021, MBServerStatics.RESOURCE_STACK_LIMIT);
|
||||
maxResources.put(7, 100000000);
|
||||
maxResources.put(1580000, 10000);
|
||||
maxResources.put(1580001, 2000);
|
||||
maxResources.put(1580002, 2000);
|
||||
maxResources.put(1580003, 1000);
|
||||
maxResources.put(1580004, 10000);
|
||||
maxResources.put(1580005, 3000);
|
||||
maxResources.put(1580006, 3000);
|
||||
maxResources.put(1580007, 1000);
|
||||
maxResources.put(1580008, 3000);
|
||||
maxResources.put(1580009, 2000);
|
||||
maxResources.put(1580010, 2000);
|
||||
maxResources.put(1580011, 1000);
|
||||
maxResources.put(1580012, 2000);
|
||||
maxResources.put(1580013, 3000);
|
||||
maxResources.put(1580014, 1000);
|
||||
maxResources.put(1580015, 1000);
|
||||
maxResources.put(1580016, 1000);
|
||||
maxResources.put(1580017, 500);
|
||||
maxResources.put(1580018, 500);
|
||||
maxResources.put(1580019, 500);
|
||||
maxResources.put(1580020, 500);
|
||||
maxResources.put(1580021, 500);
|
||||
}
|
||||
|
||||
return maxResources;
|
||||
|
||||
@@ -33,16 +33,15 @@ public class MBServerStatics {
|
||||
// hit box
|
||||
// calcs
|
||||
public static final boolean PRINT_INCOMING_OPCODES = false; // print
|
||||
public static final int BANK_GOLD_LIMIT = 1000000000;
|
||||
public static final int BANK_GOLD_LIMIT = 25000000;
|
||||
// incoming
|
||||
// opcodes to
|
||||
// console
|
||||
public static final int PLAYER_GOLD_LIMIT = 500000000;
|
||||
public static final int PLAYER_GOLD_LIMIT = 10000000;
|
||||
// buildings, npcs
|
||||
/*
|
||||
* Login cache flags
|
||||
*/
|
||||
public static final int RESOURCE_STACK_LIMIT = 1000000000;
|
||||
public static final boolean SKIP_CACHE_LOGIN = false; // skip caching // login server
|
||||
public static final boolean SKIP_CACHE_LOGIN_PLAYER = false; // skip caching // on login
|
||||
public static final boolean SKIP_CACHE_LOGIN_ITEM = false; // skip caching
|
||||
|
||||
@@ -96,6 +96,11 @@ public class LoginServer {
|
||||
// Start the Login Server
|
||||
|
||||
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();
|
||||
|
||||
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) {
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "lsof -i tcp:" + port + " | tail -n +2 | awk '{print $2}'");
|
||||
builder.redirectErrorStream(true);
|
||||
Process process = null;
|
||||
String line = null;
|
||||
boolean portInUse = false;
|
||||
java.net.ServerSocket probe = null;
|
||||
|
||||
try {
|
||||
process = builder.start();
|
||||
|
||||
InputStream is = process.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
portInUse = true;
|
||||
}
|
||||
|
||||
probe = new java.net.ServerSocket();
|
||||
probe.setReuseAddress(true);
|
||||
probe.bind(new java.net.InetSocketAddress(port));
|
||||
return false;
|
||||
} 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() {
|
||||
|
||||
@@ -109,6 +109,11 @@ public class WorldServer {
|
||||
|
||||
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();
|
||||
|
||||
if (retVal != 0)
|
||||
|
||||
Reference in New Issue
Block a user