Compare commits

..
5 Commits
Author SHA1 Message Date
MagicBot 490141b71b Case added for protectorate. 2026-05-10 08:22:58 -04:00
MagicBot 2487915a13 Case added for protectorate. 2026-05-10 08:21:34 -04:00
MagicBot e2909564a4 state updated properly 2026-05-10 08:08:18 -04:00
MagicBot c02564d7af state updated properly 2026-05-07 15:38:21 -04:00
MagicBot 945f85443d db call added 2026-05-07 15:20:24 -04:00
9 changed files with 93 additions and 438 deletions
-84
View File
@@ -1,84 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// 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,7 +123,6 @@ 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());
@@ -1,202 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// 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,21 +14,6 @@ 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() {
@@ -42,9 +27,6 @@ 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) {
@@ -58,16 +40,6 @@ 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,13 +25,6 @@ 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!");
@@ -43,8 +36,6 @@ public class MobRespawnThread implements Runnable {
while (true) {
long tickStart = System.currentTimeMillis();
try {
for (Zone zone : ZoneManager.getAllZones()) {
@@ -64,15 +55,6 @@ 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() {
@@ -15,6 +15,7 @@ import engine.Enum.GuildState;
import engine.exception.MsgSendException;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.gameManager.GuildManager;
import engine.gameManager.SessionManager;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
@@ -26,8 +27,6 @@ import engine.objects.Guild;
import engine.objects.GuildStatusController;
import engine.objects.PlayerCharacter;
import java.util.ArrayList;
public class AcceptSubInviteHandler extends AbstractClientMsgHandler {
public AcceptSubInviteHandler() {
@@ -38,69 +37,76 @@ public class AcceptSubInviteHandler extends AbstractClientMsgHandler {
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
AcceptSubInviteMsg msg = (AcceptSubInviteMsg) baseMsg;
PlayerCharacter sourcePlayer;
Guild sourceGuild;
Guild targetGuild;
PlayerCharacter playerCharacter;
Guild protectorate;
Guild nation;
Dispatch dispatch;
// get PlayerCharacter of person sending sub invite
sourcePlayer = SessionManager.getPlayerCharacter(origin);
playerCharacter = SessionManager.getPlayerCharacter(origin);
if (sourcePlayer == null)
if (playerCharacter == null)
return true;
sourceGuild = sourcePlayer.getGuild();
targetGuild = (Guild) DbManager.getObject(GameObjectType.Guild, msg.guildUUID());
protectorate = playerCharacter.getGuild();
nation = (Guild) DbManager.getObject(GameObjectType.Guild, msg.guildUUID());
//must be source guild to sub to
if (targetGuild == null) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild
if (nation == null) {
ErrorPopupMsg.sendErrorPopup(playerCharacter, 45); // Failure to swear guild
return true;
}
if (sourceGuild == null) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild
if (protectorate == null) {
ErrorPopupMsg.sendErrorPopup(playerCharacter, 45); // Failure to swear guild
return true;
}
if (sourceGuild.equals(targetGuild))
if (protectorate.equals(nation))
return true;
if (GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()) == false) {
ErrorPopupMsg.sendErrorMsg(sourcePlayer, "Only a guild leader can accept fealty!");
if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus()) == false) {
ErrorPopupMsg.sendErrorMsg(playerCharacter, "Only a guild leader can accept fealty!");
return true;
}
//source guild is limited to 7 subs
//TODO this should be based on TOL rank
if (!targetGuild.canSubAGuild(sourceGuild)) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild
if (!nation.canSubAGuild(protectorate)) {
ErrorPopupMsg.sendErrorPopup(playerCharacter, 45); // Failure to swear guild
return true;
}
//all tests passed, let's Handle code
//Update Target Guild State.
sourceGuild.upgradeGuildState(false);
// Update database
//Add sub so GuildMaster can Swear in.
if (!DbManager.GuildQueries.UPDATE_PARENT(protectorate.getObjectUUID(), nation.getObjectUUID())) {
ErrorPopupMsg.sendErrorMsg(playerCharacter, "A Serious error has occured. Please post details for to ensure transaction integrity");
return true;
}
ArrayList<Guild> subs = targetGuild.getSubGuildList();
subs.add(sourceGuild);
//update Guild states.
targetGuild.setGuildState(GuildState.Nation);
protectorate.setNation(nation);
GuildManager.updateAllGuildTags(protectorate);
protectorate.upgradeGuildState(false);
if (nation.getGuildState() == GuildState.Sovereign)
nation.upgradeGuildState(true);
nation.getSubGuildList().add(protectorate);
//Let's send the message back.
msg.setUnknown02(1);
msg.setResponse("Your guild is now a " + sourceGuild.getGuildState().name() + '.');
dispatch = Dispatch.borrow(sourcePlayer, msg);
msg.setResponse("Your guild is now a " + protectorate.getGuildState().name() + '.');
dispatch = Dispatch.borrow(playerCharacter, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
ChatManager.chatSystemInfo(sourcePlayer, "Your guild is now a " + sourceGuild.getGuildState().name() + '.');
ChatManager.chatSystemInfo(playerCharacter, "Your guild is now a " + protectorate.getGuildState().name() + '.');
return true;
}
}
@@ -26,6 +26,7 @@ import engine.net.client.msg.guild.SendGuildEntryMsg;
import engine.objects.*;
import engine.server.world.WorldServer;
import engine.session.Session;
import org.pmw.tinylog.Logger;
import java.util.ArrayList;
@@ -40,8 +41,8 @@ public class BreakFealtyHandler extends AbstractClientMsgHandler {
BreakFealtyMsg bfm;
PlayerCharacter player;
Guild toBreak;
Guild guild;
Guild nation;
Guild protectorate;
Dispatch dispatch;
bfm = (BreakFealtyMsg) baseMsg;
@@ -54,46 +55,50 @@ public class BreakFealtyHandler extends AbstractClientMsgHandler {
if (player == null)
return true;
toBreak = (Guild) DbManager.getObject(GameObjectType.Guild, bfm.getGuildUUID());
nation = (Guild) DbManager.getObject(GameObjectType.Guild, bfm.getGuildUUID());
if (toBreak == null) {
if (nation == null) {
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
return true;
}
guild = player.getGuild();
protectorate = player.getGuild();
if (guild == null) {
if (protectorate == null) {
ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!");
return true;
}
if (toBreak.isNPCGuild()) {
if (nation.isNPCGuild()) {
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) {
ErrorPopupMsg.sendErrorMsg(player, "Only guild leader can break fealty!");
return true;
}
if (!DbManager.GuildQueries.UPDATE_PARENT(guild.getObjectUUID(), WorldServer.worldUUID)) {
if (!DbManager.GuildQueries.UPDATE_PARENT(protectorate.getObjectUUID(), WorldServer.worldUUID)) {
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return true;
}
switch (guild.getGuildState()) {
switch (protectorate.getGuildState()) {
case Sworn:
guild.setNation(null);
GuildManager.updateAllGuildTags(guild);
GuildManager.updateAllGuildBinds(guild, null);
protectorate.setNation(Guild.getErrantGuild());
GuildManager.updateAllGuildTags(protectorate);
GuildManager.updateAllGuildBinds(protectorate, null);
break;
case Province:
guild.setNation(guild);
GuildManager.updateAllGuildTags(guild);
GuildManager.updateAllGuildBinds(guild, guild.getOwnedCity());
case Protectorate:
protectorate.setNation(protectorate);
GuildManager.updateAllGuildTags(protectorate);
GuildManager.updateAllGuildBinds(protectorate, protectorate.getOwnedCity());
break;
default:
Logger.error("Unhandled guild state");
break;
}
guild.downgradeGuildState();
protectorate.downgradeGuildState();
SendGuildEntryMsg msg = new SendGuildEntryMsg(player);
dispatch = Dispatch.borrow(player, msg);
@@ -106,16 +111,16 @@ public class BreakFealtyHandler extends AbstractClientMsgHandler {
City.lastCityUpdate = System.currentTimeMillis();
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(guild.getObjectUUID());
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(protectorate.getObjectUUID());
for (PlayerCharacter member : guildMembers) {
ChatManager.chatGuildInfo(member, guild.getName() + " has broke fealty from " + toBreak.getName() + '!');
ChatManager.chatGuildInfo(member, protectorate.getName() + " has broke fealty from " + nation.getName() + '!');
}
ArrayList<PlayerCharacter> breakFealtyMembers = SessionManager.getActivePCsInGuildID(toBreak.getObjectUUID());
ArrayList<PlayerCharacter> breakFealtyMembers = SessionManager.getActivePCsInGuildID(nation.getObjectUUID());
for (PlayerCharacter member : breakFealtyMembers) {
ChatManager.chatGuildInfo(member, guild.getName() + " has broken fealty from " + toBreak.getName() + '!');
ChatManager.chatGuildInfo(member, protectorate.getName() + " has broken fealty from " + nation.getName() + '!');
}
return true;
@@ -123,7 +128,7 @@ public class BreakFealtyHandler extends AbstractClientMsgHandler {
}
if (!toBreak.getSubGuildList().contains(guild)) {
if (!nation.getSubGuildList().contains(protectorate)) {
ErrorPopupMsg.sendErrorMsg(player, "Failure to break fealty!");
return true;
}
@@ -133,34 +138,34 @@ public class BreakFealtyHandler extends AbstractClientMsgHandler {
return true;
}
if (Bane.getBaneByAttackerGuild(guild) != null) {
if (Bane.getBaneByAttackerGuild(protectorate) != null) {
ErrorPopupMsg.sendErrorMsg(player, "You may break fealty with active bane!");
return true;
}
if (!DbManager.GuildQueries.UPDATE_PARENT(guild.getObjectUUID(), WorldServer.worldUUID)) {
if (!DbManager.GuildQueries.UPDATE_PARENT(protectorate.getObjectUUID(), WorldServer.worldUUID)) {
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return true;
}
switch (guild.getGuildState()) {
switch (protectorate.getGuildState()) {
case Sworn:
guild.setNation(null);
GuildManager.updateAllGuildTags(guild);
GuildManager.updateAllGuildBinds(guild, null);
protectorate.setNation(null);
GuildManager.updateAllGuildTags(protectorate);
GuildManager.updateAllGuildBinds(protectorate, null);
break;
case Province:
guild.setNation(guild);
GuildManager.updateAllGuildTags(guild);
GuildManager.updateAllGuildBinds(guild, guild.getOwnedCity());
protectorate.setNation(protectorate);
GuildManager.updateAllGuildTags(protectorate);
GuildManager.updateAllGuildBinds(protectorate, protectorate.getOwnedCity());
break;
}
guild.downgradeGuildState();
toBreak.getSubGuildList().remove(guild);
protectorate.downgradeGuildState();
nation.getSubGuildList().remove(protectorate);
if (toBreak.getSubGuildList().isEmpty())
toBreak.downgradeGuildState();
if (nation.getSubGuildList().isEmpty())
nation.downgradeGuildState();
SendGuildEntryMsg msg = new SendGuildEntryMsg(player);
dispatch = Dispatch.borrow(player, msg);
@@ -173,16 +178,16 @@ public class BreakFealtyHandler extends AbstractClientMsgHandler {
City.lastCityUpdate = System.currentTimeMillis();
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(guild.getObjectUUID());
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(protectorate.getObjectUUID());
for (PlayerCharacter member : guildMembers) {
ChatManager.chatGuildInfo(member, guild.getName() + " has broke fealty from " + toBreak.getName() + '!');
ChatManager.chatGuildInfo(member, protectorate.getName() + " has broke fealty from " + nation.getName() + '!');
}
ArrayList<PlayerCharacter> breakFealtyMembers = SessionManager.getActivePCsInGuildID(toBreak.getObjectUUID());
ArrayList<PlayerCharacter> breakFealtyMembers = SessionManager.getActivePCsInGuildID(nation.getObjectUUID());
for (PlayerCharacter member : breakFealtyMembers) {
ChatManager.chatGuildInfo(member, guild.getName() + " has broken fealty from " + toBreak.getName() + '!');
ChatManager.chatGuildInfo(member, protectorate.getName() + " has broken fealty from " + nation.getName() + '!');
}
return true;
+17 -35
View File
@@ -96,11 +96,6 @@ 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);
@@ -150,42 +145,29 @@ 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) {
java.net.ServerSocket probe = null;
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;
try {
probe = new java.net.ServerSocket();
probe.setReuseAddress(true);
probe.bind(new java.net.InetSocketAddress(port));
return false;
process = builder.start();
InputStream is = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
while ((line = reader.readLine()) != null) {
portInUse = true;
}
} catch (IOException e) {
return true;
} finally {
if (probe != null)
try {
probe.close();
} catch (IOException e) {
// the bind result is what matters; closing cannot change it
}
e.printStackTrace();
}
return portInUse;
}
private void exec() {
-5
View File
@@ -109,11 +109,6 @@ 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)