From d3e05ec2477f1c7ee87a58474eded8899e1ee3a1 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 1 Jan 2023 15:48:17 -0600 Subject: [PATCH 01/35] subs limited to cap rank --- .../client/handlers/AcceptSubInviteHandler.java | 2 +- .../net/client/handlers/InviteToSubHandler.java | 2 +- src/engine/objects/Guild.java | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/engine/net/client/handlers/AcceptSubInviteHandler.java b/src/engine/net/client/handlers/AcceptSubInviteHandler.java index 38fbb3ef..cf7a0507 100644 --- a/src/engine/net/client/handlers/AcceptSubInviteHandler.java +++ b/src/engine/net/client/handlers/AcceptSubInviteHandler.java @@ -75,7 +75,7 @@ public class AcceptSubInviteHandler extends AbstractClientMsgHandler { //source guild is limited to 7 subs //TODO this should be based on TOL rank - if (!targetGuild.canSubAGuild(sourceGuild)) { + if (!targetGuild.canSubAGuild(sourceGuild,targetGuild)) { ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild return true; } diff --git a/src/engine/net/client/handlers/InviteToSubHandler.java b/src/engine/net/client/handlers/InviteToSubHandler.java index 9c16ce90..992799eb 100644 --- a/src/engine/net/client/handlers/InviteToSubHandler.java +++ b/src/engine/net/client/handlers/InviteToSubHandler.java @@ -103,7 +103,7 @@ public class InviteToSubHandler extends AbstractClientMsgHandler { //TODO this should be based on TOL rank - if (!sourceGuild.canSubAGuild(targetGuild)) { + if (!sourceGuild.canSubAGuild(targetGuild, null)) { sendChat(source, "This Guild can't be subbed."); return true; } diff --git a/src/engine/objects/Guild.java b/src/engine/objects/Guild.java index e28009af..8bf11f6b 100644 --- a/src/engine/objects/Guild.java +++ b/src/engine/objects/Guild.java @@ -559,17 +559,21 @@ public class Guild extends AbstractWorldObject { } - public boolean canSubAGuild(Guild toSub){ + public boolean canSubAGuild(Guild toSub, Guild nation){ boolean canSub; if (this.equals(toSub)) return false; - - switch(this.guildState){ - case Nation: - case Sovereign: - canSub = true; + City nationCap = City.getCity(nation.cityUUID); + if (nation.getSubGuildList().size() >= nationCap.getRank()) { + canSub = false; + return canSub; + } + switch(this.guildState) { + case Nation: + case Sovereign: + canSub = true; break; default: canSub = false; From 6cf7b88025f67a2c109fd599f51b8e1d48ab28d3 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 1 Jan 2023 15:53:05 -0600 Subject: [PATCH 02/35] NPCs buy at base cost only --- src/engine/net/client/ClientMessagePump.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 07ede49c..1d9a9977 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -1746,10 +1746,6 @@ boolean updateCity = false; cost = sell.getBaseValue(); - - if (sell.isID()) - cost = sell.getMagicValue(); - float bargain = player.getBargain(); float profit = npc.getBuyPercent(player) + bargain; From 5f0803eec421069a2bbe363740c93b2a732aaaeb Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 1 Jan 2023 21:56:49 -0600 Subject: [PATCH 03/35] nation sub limits added --- .../net/client/handlers/AcceptSubInviteHandler.java | 2 +- .../net/client/handlers/InviteToSubHandler.java | 2 +- src/engine/objects/Guild.java | 12 +++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/engine/net/client/handlers/AcceptSubInviteHandler.java b/src/engine/net/client/handlers/AcceptSubInviteHandler.java index cf7a0507..38fbb3ef 100644 --- a/src/engine/net/client/handlers/AcceptSubInviteHandler.java +++ b/src/engine/net/client/handlers/AcceptSubInviteHandler.java @@ -75,7 +75,7 @@ public class AcceptSubInviteHandler extends AbstractClientMsgHandler { //source guild is limited to 7 subs //TODO this should be based on TOL rank - if (!targetGuild.canSubAGuild(sourceGuild,targetGuild)) { + if (!targetGuild.canSubAGuild(sourceGuild)) { ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild return true; } diff --git a/src/engine/net/client/handlers/InviteToSubHandler.java b/src/engine/net/client/handlers/InviteToSubHandler.java index 992799eb..9c16ce90 100644 --- a/src/engine/net/client/handlers/InviteToSubHandler.java +++ b/src/engine/net/client/handlers/InviteToSubHandler.java @@ -103,7 +103,7 @@ public class InviteToSubHandler extends AbstractClientMsgHandler { //TODO this should be based on TOL rank - if (!sourceGuild.canSubAGuild(targetGuild, null)) { + if (!sourceGuild.canSubAGuild(targetGuild)) { sendChat(source, "This Guild can't be subbed."); return true; } diff --git a/src/engine/objects/Guild.java b/src/engine/objects/Guild.java index 8bf11f6b..81249142 100644 --- a/src/engine/objects/Guild.java +++ b/src/engine/objects/Guild.java @@ -559,17 +559,12 @@ public class Guild extends AbstractWorldObject { } - public boolean canSubAGuild(Guild toSub, Guild nation){ + public boolean canSubAGuild(Guild toSub){ boolean canSub; if (this.equals(toSub)) return false; - City nationCap = City.getCity(nation.cityUUID); - if (nation.getSubGuildList().size() >= nationCap.getRank()) { - canSub = false; - return canSub; - } switch(this.guildState) { case Nation: case Sovereign: @@ -587,7 +582,10 @@ public class Guild extends AbstractWorldObject { default: canSub = false; } - + City nationCap = City.getCity(nation.cityUUID); + if (nation.getSubGuildList().size() >= nationCap.getRank()) { + canSub = false; + } return canSub; } From 2f22b3b91b59c6c8515982ffc560d5d8af7f72bf Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 7 Jan 2023 09:44:51 -0500 Subject: [PATCH 04/35] Protocol Handler created for ArcMineWindowChangeMsg --- src/engine/db/handlers/dbMineHandler.java | 13 --- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../handlers/MineWindowChangeHandler.java | 88 +++++++++++++++++++ 4 files changed, 89 insertions(+), 17 deletions(-) create mode 100644 src/engine/net/client/handlers/MineWindowChangeHandler.java diff --git a/src/engine/db/handlers/dbMineHandler.java b/src/engine/db/handlers/dbMineHandler.java index acc8384b..43753937 100644 --- a/src/engine/db/handlers/dbMineHandler.java +++ b/src/engine/db/handlers/dbMineHandler.java @@ -6,19 +6,6 @@ // Magicbane Emulator Project © 2013 - 2022 // www.magicbane.com - - - - -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - package engine.db.handlers; import engine.Enum; diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 07ede49c..d3e08a08 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -265,9 +265,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCMINEWINDOWAVAILABLETIME: MineWindowAvailableTime((ArcMineWindowAvailableTimeMsg) msg, origin); break; - case ARCMINEWINDOWCHANGE: - MineWindowChange((ArcMineWindowChangeMsg) msg, origin); - break; case ARCOWNEDMINESLIST: ListOwnedMines((ArcOwnedMinesListMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index d95becd3..38965bb8 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -36,7 +36,7 @@ public enum Protocol { ARCMINECHANGEPRODUCTION(0x1EAA993F, ArcMineChangeProductionMsg.class, null), ARCMINETOWERCRESTUPDATE(0x34164D0D, null, null), ARCMINEWINDOWAVAILABLETIME(0x6C909DE7, ArcMineWindowAvailableTimeMsg.class, null), - ARCMINEWINDOWCHANGE(0x92B2148A, ArcMineWindowChangeMsg.class, null), + ARCMINEWINDOWCHANGE(0x92B2148A, ArcMineWindowChangeMsg.class, MineWindowChangeHandler.class), ARCOWNEDMINESLIST(0x59184455, ArcOwnedMinesListMsg.class, null), ARCPETATTACK(0x18CD61AD, PetAttackMsg.class, null), // Pet Attack ARCPETCMD(0x4E80E001, PetCmdMsg.class, null), // Stop ArcPetAttack, Toggle Assist, Toggle Rest diff --git a/src/engine/net/client/handlers/MineWindowChangeHandler.java b/src/engine/net/client/handlers/MineWindowChangeHandler.java new file mode 100644 index 00000000..1ef1bb50 --- /dev/null +++ b/src/engine/net/client/handlers/MineWindowChangeHandler.java @@ -0,0 +1,88 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.gameManager.BuildingManager; +import engine.gameManager.ChatManager; +import engine.gameManager.DbManager; +import engine.gameManager.SessionManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ArcMineWindowChangeMsg; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.KeepAliveServerClientMsg; +import engine.objects.Building; +import engine.objects.Guild; +import engine.objects.GuildStatusController; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +/* + * @Author: + * @Summary: Processes requests to change a mine's opendate + */ + +public class MineWindowChangeHandler extends AbstractClientMsgHandler { + + public MineWindowChangeHandler() { + super(ArcMineWindowChangeMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); + ArcMineWindowChangeMsg mineWindowChangeMsg = (ArcMineWindowChangeMsg)baseMsg; + + if (playerCharacter == null) + return true; + + Building treeOfLife = BuildingManager.getBuildingFromCache(mineWindowChangeMsg.getBuildingID()); + + if (treeOfLife == null) + return true; + + if (treeOfLife.getBlueprintUUID() == 0) + return true; + + if (treeOfLife.getBlueprint().getBuildingGroup() != Enum.BuildingGroup.TOL) + return true; + + Guild mineGuild = treeOfLife.getGuild(); + if (mineGuild == null) + return true; + + if (!Guild.sameGuild(mineGuild, playerCharacter.getGuild())) + return true; //must be same guild + + if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL? + return true; + + //hodge podge sanity check to make sure they don't set it before early window and is not set at late window. + if (mineWindowChangeMsg.getTime() < MBServerStatics.MINE_EARLY_WINDOW && + mineWindowChangeMsg.getTime() != MBServerStatics.MINE_LATE_WINDOW) + return true; //invalid mine time, must be in range + + if (!DbManager.GuildQueries.UPDATE_MINETIME(mineGuild.getObjectUUID(), mineWindowChangeMsg.getTime())) { + Logger.error("MineWindowChange", "Failed to update mine time for guild " + mineGuild.getObjectUUID()); + ChatManager.chatGuildError(playerCharacter, "Failed to update the mine time"); + return true; + } + mineGuild.setMineTime(mineWindowChangeMsg.getTime()); + ChatManager.chatGuildInfo(playerCharacter, "Mine time updated."); + + return true; + } + +} \ No newline at end of file From 83b514a05fa3d1355b3ae12b9490d698694b300e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 7 Jan 2023 10:35:00 -0500 Subject: [PATCH 05/35] Class cleanup. --- .../net/client/handlers/MineWindowChangeHandler.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/engine/net/client/handlers/MineWindowChangeHandler.java b/src/engine/net/client/handlers/MineWindowChangeHandler.java index 1ef1bb50..4edc8a2b 100644 --- a/src/engine/net/client/handlers/MineWindowChangeHandler.java +++ b/src/engine/net/client/handlers/MineWindowChangeHandler.java @@ -44,6 +44,7 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(origin); ArcMineWindowChangeMsg mineWindowChangeMsg = (ArcMineWindowChangeMsg)baseMsg; + int newMineTime; if (playerCharacter == null) return true; @@ -69,17 +70,19 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL? return true; + newMineTime = mineWindowChangeMsg.getTime(); + //hodge podge sanity check to make sure they don't set it before early window and is not set at late window. - if (mineWindowChangeMsg.getTime() < MBServerStatics.MINE_EARLY_WINDOW && - mineWindowChangeMsg.getTime() != MBServerStatics.MINE_LATE_WINDOW) + if (newMineTime < MBServerStatics.MINE_EARLY_WINDOW && + newMineTime != MBServerStatics.MINE_LATE_WINDOW) return true; //invalid mine time, must be in range - if (!DbManager.GuildQueries.UPDATE_MINETIME(mineGuild.getObjectUUID(), mineWindowChangeMsg.getTime())) { + if (!DbManager.GuildQueries.UPDATE_MINETIME(mineGuild.getObjectUUID(), newMineTime)) { Logger.error("MineWindowChange", "Failed to update mine time for guild " + mineGuild.getObjectUUID()); ChatManager.chatGuildError(playerCharacter, "Failed to update the mine time"); return true; } - mineGuild.setMineTime(mineWindowChangeMsg.getTime()); + mineGuild.setMineTime(newMineTime); ChatManager.chatGuildInfo(playerCharacter, "Mine time updated."); return true; From 302358e31c9adbe65a108e2b3a85e99565312496 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 7 Jan 2023 11:03:07 -0500 Subject: [PATCH 06/35] Storing lastWooEditTime for guilds in obj_guild table. Requires Schema Change. --- src/engine/net/client/handlers/MineWindowChangeHandler.java | 6 ++++++ src/engine/objects/Guild.java | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/engine/net/client/handlers/MineWindowChangeHandler.java b/src/engine/net/client/handlers/MineWindowChangeHandler.java index 4edc8a2b..5be628c6 100644 --- a/src/engine/net/client/handlers/MineWindowChangeHandler.java +++ b/src/engine/net/client/handlers/MineWindowChangeHandler.java @@ -28,6 +28,8 @@ import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; +import java.time.LocalDateTime; + /* * @Author: * @Summary: Processes requests to change a mine's opendate @@ -73,15 +75,19 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { newMineTime = mineWindowChangeMsg.getTime(); //hodge podge sanity check to make sure they don't set it before early window and is not set at late window. + if (newMineTime < MBServerStatics.MINE_EARLY_WINDOW && newMineTime != MBServerStatics.MINE_LATE_WINDOW) return true; //invalid mine time, must be in range + // Update guild mine time + if (!DbManager.GuildQueries.UPDATE_MINETIME(mineGuild.getObjectUUID(), newMineTime)) { Logger.error("MineWindowChange", "Failed to update mine time for guild " + mineGuild.getObjectUUID()); ChatManager.chatGuildError(playerCharacter, "Failed to update the mine time"); return true; } + mineGuild.setMineTime(newMineTime); ChatManager.chatGuildInfo(playerCharacter, "Mine time updated."); diff --git a/src/engine/objects/Guild.java b/src/engine/objects/Guild.java index e28009af..2f7abea2 100644 --- a/src/engine/objects/Guild.java +++ b/src/engine/objects/Guild.java @@ -36,11 +36,14 @@ import engine.net.client.msg.UpdateClientAlliancesMsg; import engine.net.client.msg.guild.GuildInfoMsg; import engine.server.MBServerStatics; import org.joda.time.DateTime; +import org.joda.time.LocalDateTime; import org.pmw.tinylog.Logger; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; @@ -79,6 +82,7 @@ public class Guild extends AbstractWorldObject { private String hash; private boolean ownerIsNPC; + public Timestamp lastWooEditTime; public HashMap guildAlliances = new HashMap<>(); /** @@ -176,8 +180,8 @@ public class Guild extends AbstractWorldObject { this.teleportMax = rs.getInt("teleportMax"); this.mineTime = rs.getInt("mineTime"); + this.lastWooEditTime = rs.getTimestamp("lastWooEditTime"); this.hash = rs.getString("hash"); - } public void setNation(Guild nation) { From 4b5ce5bdb1f223220355c3856d05e8d7d845b8a4 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 7 Jan 2023 11:22:38 -0500 Subject: [PATCH 07/35] 15hr WOO restriction check added. --- .../net/client/handlers/MineWindowChangeHandler.java | 8 ++++++++ src/engine/objects/Guild.java | 11 ++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/engine/net/client/handlers/MineWindowChangeHandler.java b/src/engine/net/client/handlers/MineWindowChangeHandler.java index 5be628c6..141981eb 100644 --- a/src/engine/net/client/handlers/MineWindowChangeHandler.java +++ b/src/engine/net/client/handlers/MineWindowChangeHandler.java @@ -20,6 +20,7 @@ import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.ArcMineWindowChangeMsg; import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.ErrorPopupMsg; import engine.net.client.msg.KeepAliveServerClientMsg; import engine.objects.Building; import engine.objects.Guild; @@ -74,6 +75,13 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { newMineTime = mineWindowChangeMsg.getTime(); + // Enforce 15hr restriction between WOO edits + + if (LocalDateTime.now().isBefore(mineGuild.lastWooEditTime.plusHours(15))) { + ErrorPopupMsg.sendErrorMsg(playerCharacter, "You must wait 15 hours between WOO changes."); + return true; + } + //hodge podge sanity check to make sure they don't set it before early window and is not set at late window. if (newMineTime < MBServerStatics.MINE_EARLY_WINDOW && diff --git a/src/engine/objects/Guild.java b/src/engine/objects/Guild.java index 2f7abea2..fd1a386c 100644 --- a/src/engine/objects/Guild.java +++ b/src/engine/objects/Guild.java @@ -36,12 +36,12 @@ import engine.net.client.msg.UpdateClientAlliancesMsg; import engine.net.client.msg.guild.GuildInfoMsg; import engine.server.MBServerStatics; import org.joda.time.DateTime; -import org.joda.time.LocalDateTime; import org.pmw.tinylog.Logger; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -82,7 +82,7 @@ public class Guild extends AbstractWorldObject { private String hash; private boolean ownerIsNPC; - public Timestamp lastWooEditTime; + public LocalDateTime lastWooEditTime; public HashMap guildAlliances = new HashMap<>(); /** @@ -180,7 +180,12 @@ public class Guild extends AbstractWorldObject { this.teleportMax = rs.getInt("teleportMax"); this.mineTime = rs.getInt("mineTime"); - this.lastWooEditTime = rs.getTimestamp("lastWooEditTime"); + + Timestamp lastWooRequest = rs.getTimestamp("lastWooEditTime"); + + if (lastWooRequest != null) + this.lastWooEditTime = lastWooRequest.toLocalDateTime(); + this.hash = rs.getString("hash"); } From 860d4d9b31d1b8fbc1b015ed0eeff8a812e09b4f Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 7 Jan 2023 11:31:41 -0500 Subject: [PATCH 08/35] Bugfix: setting lastwoocheck field after update. --- src/engine/net/client/handlers/MineWindowChangeHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/engine/net/client/handlers/MineWindowChangeHandler.java b/src/engine/net/client/handlers/MineWindowChangeHandler.java index 141981eb..351faed7 100644 --- a/src/engine/net/client/handlers/MineWindowChangeHandler.java +++ b/src/engine/net/client/handlers/MineWindowChangeHandler.java @@ -97,6 +97,7 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { } mineGuild.setMineTime(newMineTime); + mineGuild.lastWooEditTime = LocalDateTime.now(); ChatManager.chatGuildInfo(playerCharacter, "Mine time updated."); return true; From 7bc09d86bd5d8008a50d06a8cde1af6617e9fe86 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 7 Jan 2023 12:31:22 -0500 Subject: [PATCH 09/35] Saving WOO timer to database for reboot persist. --- src/engine/db/handlers/dbGuildHandler.java | 9 +++++++-- .../net/client/handlers/MineWindowChangeHandler.java | 11 ++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/engine/db/handlers/dbGuildHandler.java b/src/engine/db/handlers/dbGuildHandler.java index 43d43593..b21ad7d1 100644 --- a/src/engine/db/handlers/dbGuildHandler.java +++ b/src/engine/db/handlers/dbGuildHandler.java @@ -19,6 +19,7 @@ import org.pmw.tinylog.Logger; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.LocalDateTime; import java.util.ArrayList; public class dbGuildHandler extends dbHandlerBase { @@ -114,8 +115,12 @@ public class dbGuildHandler extends dbHandlerBase { return outputStr; } - - + public boolean SET_LAST_WOO_UPDATE(Guild guild, LocalDateTime lastEditTime) { + prepareCallable("UPDATE `obj_guild` SET `lastWooEditTime`=? WHERE `UID`=?"); + setLocalDateTime(1, lastEditTime); + setLong(2, (long) guild.getObjectUUID()); + return (executeUpdate() > 0); + } public ArrayList GET_GUILD_ALLIES(final int id) { prepareCallable("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l " diff --git a/src/engine/net/client/handlers/MineWindowChangeHandler.java b/src/engine/net/client/handlers/MineWindowChangeHandler.java index 351faed7..96312545 100644 --- a/src/engine/net/client/handlers/MineWindowChangeHandler.java +++ b/src/engine/net/client/handlers/MineWindowChangeHandler.java @@ -77,7 +77,7 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { // Enforce 15hr restriction between WOO edits - if (LocalDateTime.now().isBefore(mineGuild.lastWooEditTime.plusHours(15))) { + if (LocalDateTime.now().isBefore(mineGuild.lastWooEditTime.plusHours(14))) { ErrorPopupMsg.sendErrorMsg(playerCharacter, "You must wait 15 hours between WOO changes."); return true; } @@ -98,6 +98,15 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { mineGuild.setMineTime(newMineTime); mineGuild.lastWooEditTime = LocalDateTime.now(); + + // Update guild WOO timer for reboot persistence + + if (!DbManager.GuildQueries.SET_LAST_WOO_UPDATE(mineGuild, mineGuild.lastWooEditTime)) { + Logger.error("MineWindowChange", "Failed to update woo timer for guild " + mineGuild.getObjectUUID()); + ChatManager.chatGuildError(playerCharacter, "A Serious error has for to occurred."); + return true; + } + ChatManager.chatGuildInfo(playerCharacter, "Mine time updated."); return true; From 52d3d8ee3a8824bc1eb432821c15752d9ed738f4 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 7 Jan 2023 13:26:47 -0500 Subject: [PATCH 10/35] Not adding an extraneous day each reboot. --- src/engine/objects/Mine.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index e53c6d86..e2b435f1 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -166,17 +166,11 @@ public class Mine extends AbstractGameObject { if (LocalDateTime.now().isAfter(this.openDate.plusHours(1))) this.openDate = this.openDate.plusDays(1); return; - }else{ + }else this.openDate = mineTimeStamp.toLocalDateTime().withHour(mineTime); - - if (LocalDateTime.now().isAfter(this.openDate.plusHours(1))){ - this.openDate = this.openDate.plusDays(1); - return; - } - } - + //after 1 day... - if(this.openDate.getDayOfYear() - LocalDateTime.now().getDayOfYear() > 1){ + if (this.openDate.getDayOfYear() - LocalDateTime.now().getDayOfYear() > 1){ this.openDate = this.openDate.withDayOfYear(LocalDateTime.now().getDayOfYear()); if (LocalDateTime.now().isAfter(this.openDate.plusHours(1))) this.openDate = this.openDate.plusDays(1); From df09b6e38b74db78eb44451041639e4e2420a85d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 7 Jan 2023 13:49:31 -0500 Subject: [PATCH 11/35] Removed 30 lines of logic that had no business in a result set constructor. --- src/engine/objects/Mine.java | 43 +++++------------------------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index e2b435f1..cd367251 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -35,6 +35,7 @@ import org.pmw.tinylog.Logger; import java.net.UnknownHostException; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; @@ -141,41 +142,11 @@ public class Mine extends AbstractGameObject { this.lastClaimerID = 0; this.lastClaimerSessionID = null; - java.sql.Timestamp mineTimeStamp = rs.getTimestamp("mine_openDate"); - - - Building building = BuildingManager.getBuildingFromCache(this.buildingID); - - if (mineTimeStamp == null && (this.owningGuild == null || this.owningGuild.isErrant() || building.getRank() < 1)){ - if (building != null){ - String zoneName = building.getParentZone().getName(); - String parentZoneName = building.getParentZone().getParent().getName(); - Logger.info(zoneName + " in " + parentZoneName + " has a dirty mine, setting active."); - } - this.dirtyMine = true; - openDate = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0); - return; - }else if (this.owningGuild.isErrant() || nation.isErrant()){ - openDate = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0); - return; - }else if (mineTimeStamp == null){ - - this.openDate = LocalDateTime.now().withHour(mineTime).withMinute(0).withSecond(0).withNano(0); - - if (LocalDateTime.now().isAfter(this.openDate.plusHours(1))) - this.openDate = this.openDate.plusDays(1); - return; - }else - this.openDate = mineTimeStamp.toLocalDateTime().withHour(mineTime); - - //after 1 day... - if (this.openDate.getDayOfYear() - LocalDateTime.now().getDayOfYear() > 1){ - this.openDate = this.openDate.withDayOfYear(LocalDateTime.now().getDayOfYear()); - if (LocalDateTime.now().isAfter(this.openDate.plusHours(1))) - this.openDate = this.openDate.plusDays(1); - return; - } + Timestamp mineOpenDateTime = rs.getTimestamp("mine_openDate"); + + if (mineOpenDateTime != null) + this.openDate = mineOpenDateTime.toLocalDateTime(); } @@ -252,10 +223,6 @@ try{ */ private void initializeMineTime(){ - //Mine time has already been set at loading from the database. skip. - - if (this.openDate != null) - return; Guild nation = null; From 0fd5d09e3eda03fb34071751f6ce15e844e35afe Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 8 Jan 2023 12:27:40 -0500 Subject: [PATCH 12/35] Command added to remote build on Dev server. --- src/discord/MagicBot.java | 6 ++- src/discord/handlers/DevBuildHandler.java | 48 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/discord/handlers/DevBuildHandler.java diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index 8744e3e4..571442e7 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -226,6 +226,9 @@ public class MagicBot extends ListenerAdapter { case "#trash": TrashRequestHandler.handleRequest(event, args); break; + case "#devbuild": + DevBuildHandler.handleRequest(event, args); + break; default: junkbot(command, args); break; @@ -302,7 +305,8 @@ public class MagicBot extends ListenerAdapter { "#setavail true/false Toggle status of database access.\n" + "#server reboot/shutdown are your options.\n" + "#logs magicbot/world/login n (tail)\n" + - "#flash send flash message\n" + + "#flash Send flash message\n" + + "#devbuild Builds on Dev server.\n" + "#trash /detail/flush"; sendResponse(event, helpString); } diff --git a/src/discord/handlers/DevBuildHandler.java b/src/discord/handlers/DevBuildHandler.java new file mode 100644 index 00000000..a1fd5fa6 --- /dev/null +++ b/src/discord/handlers/DevBuildHandler.java @@ -0,0 +1,48 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package discord.handlers; + +import discord.MagicBot; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import org.pmw.tinylog.Logger; + +import java.io.IOException; + +public class DevBuildHandler { + + public static void handleRequest(MessageReceivedEvent event, String[] args) { + + String buildTarget; + String execString = ""; + + // Early exit if database unavailable or is not an admin + + if (MagicBot.isAdminEvent(event) == false) + return; + + // No command supplied? + + if (args.length != 1) + return; + + buildTarget = args[0].toLowerCase().trim(); + execString = "/bin/sh -c ./mbdevbuild.sh " + buildTarget; + + + if (execString.isEmpty() == false) { + try { + Runtime.getRuntime().exec(execString); + } catch (IOException e) { + e.printStackTrace(); + } + MagicBot.sendResponse(event, "MagicBot has for to built " + buildTarget + "on Dev"); + Logger.info(event.getAuthor().getName() + " built " + buildTarget + " on Dev"); + } + } +} \ No newline at end of file From c002eec8bda4166e20793895e1edef675e7f5e36 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 8 Jan 2023 12:44:16 -0500 Subject: [PATCH 13/35] Consolidated all into one command #dev. --- src/discord/MagicBot.java | 4 +- ...ildHandler.java => DevRequestHandler.java} | 38 ++++++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) rename src/discord/handlers/{DevBuildHandler.java => DevRequestHandler.java} (57%) diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index 571442e7..bb1351a6 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -227,7 +227,7 @@ public class MagicBot extends ListenerAdapter { TrashRequestHandler.handleRequest(event, args); break; case "#devbuild": - DevBuildHandler.handleRequest(event, args); + DevRequestHandler.handleRequest(event, args); break; default: junkbot(command, args); @@ -306,7 +306,7 @@ public class MagicBot extends ListenerAdapter { "#server reboot/shutdown are your options.\n" + "#logs magicbot/world/login n (tail)\n" + "#flash Send flash message\n" + - "#devbuild Builds on Dev server.\n" + + "#dev build /restart/debug/shutdown\n" + "#trash /detail/flush"; sendResponse(event, helpString); } diff --git a/src/discord/handlers/DevBuildHandler.java b/src/discord/handlers/DevRequestHandler.java similarity index 57% rename from src/discord/handlers/DevBuildHandler.java rename to src/discord/handlers/DevRequestHandler.java index a1fd5fa6..4a856db9 100644 --- a/src/discord/handlers/DevBuildHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -14,11 +14,12 @@ import org.pmw.tinylog.Logger; import java.io.IOException; -public class DevBuildHandler { +public class DevRequestHandler { public static void handleRequest(MessageReceivedEvent event, String[] args) { - String buildTarget; + String serverCommand; + String buildTarget = ""; String execString = ""; // Early exit if database unavailable or is not an admin @@ -31,9 +32,34 @@ public class DevBuildHandler { if (args.length != 1) return; - buildTarget = args[0].toLowerCase().trim(); - execString = "/bin/sh -c ./mbdevbuild.sh " + buildTarget; + serverCommand = args[0].toLowerCase().trim(); + if (args.length == 2) + buildTarget = args[1].toLowerCase().trim(); + + + // only reboot or shutdown + + if ("rebootshutdown".contains(serverCommand) == false) + return; + + switch (serverCommand) { + + case "build" : + execString = "/bin/sh -c ./mbdevbuild.sh " + buildTarget; + break; + case "reboot": + execString = "/bin/sh -c ./mbdevrestart.sh"; + break; + case "debug": + execString = "/bin/sh -c ./mbdevdebug.sh"; + break; + case "shutdown": + execString = "/bin/sh -c ./mbdevkill.sh"; + break; + default: + break; + } if (execString.isEmpty() == false) { try { @@ -41,8 +67,8 @@ public class DevBuildHandler { } catch (IOException e) { e.printStackTrace(); } - MagicBot.sendResponse(event, "MagicBot has for to built " + buildTarget + "on Dev"); - Logger.info(event.getAuthor().getName() + " built " + buildTarget + " on Dev"); + MagicBot.sendResponse(event, "MagicBot has executed your " + serverCommand); + Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + buildTarget); } } } \ No newline at end of file From 825d1897cbf07e3d2bcd3a5e3a9c577787fa685e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 8 Jan 2023 17:18:57 -0500 Subject: [PATCH 14/35] Removal of vestigial string restriction. Command renamed to #dev --- src/discord/MagicBot.java | 6 +++--- src/discord/handlers/DevRequestHandler.java | 8 +------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index bb1351a6..6a94647c 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -217,6 +217,9 @@ public class MagicBot extends ListenerAdapter { case "#server": ServerRequestHandler.handleRequest(event, args); break; + case "#dev": + DevRequestHandler.handleRequest(event, args); + break; case "#logs": LogsRequestHandler.handleRequest(event, args); break; @@ -226,9 +229,6 @@ public class MagicBot extends ListenerAdapter { case "#trash": TrashRequestHandler.handleRequest(event, args); break; - case "#devbuild": - DevRequestHandler.handleRequest(event, args); - break; default: junkbot(command, args); break; diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 4a856db9..e4240e44 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -37,12 +37,6 @@ public class DevRequestHandler { if (args.length == 2) buildTarget = args[1].toLowerCase().trim(); - - // only reboot or shutdown - - if ("rebootshutdown".contains(serverCommand) == false) - return; - switch (serverCommand) { case "build" : @@ -67,7 +61,7 @@ public class DevRequestHandler { } catch (IOException e) { e.printStackTrace(); } - MagicBot.sendResponse(event, "MagicBot has executed your " + serverCommand); + MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + buildTarget); Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + buildTarget); } } From 23f44f1fb8bc50f608681a34f775b4b9fde2d51d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 01:01:43 -0500 Subject: [PATCH 15/35] Command name is restart not reboot. --- src/discord/handlers/DevRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index e4240e44..35af5e9b 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -42,7 +42,7 @@ public class DevRequestHandler { case "build" : execString = "/bin/sh -c ./mbdevbuild.sh " + buildTarget; break; - case "reboot": + case "restart": execString = "/bin/sh -c ./mbdevrestart.sh"; break; case "debug": From d4d24c94436764cc4e314bf7df85cfc84610c19f Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 01:11:27 -0500 Subject: [PATCH 16/35] Fixed argument passing to unix runtime. --- src/discord/handlers/DevRequestHandler.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 35af5e9b..0506dd34 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -19,7 +19,7 @@ public class DevRequestHandler { public static void handleRequest(MessageReceivedEvent event, String[] args) { String serverCommand; - String buildTarget = ""; + String commandArgument = ""; String execString = ""; // Early exit if database unavailable or is not an admin @@ -35,12 +35,12 @@ public class DevRequestHandler { serverCommand = args[0].toLowerCase().trim(); if (args.length == 2) - buildTarget = args[1].toLowerCase().trim(); + commandArgument = args[1].toLowerCase().trim(); switch (serverCommand) { case "build" : - execString = "/bin/sh -c ./mbdevbuild.sh " + buildTarget; + execString = "/bin/sh -c ./mbdevbuild.sh "; break; case "restart": execString = "/bin/sh -c ./mbdevrestart.sh"; @@ -57,12 +57,12 @@ public class DevRequestHandler { if (execString.isEmpty() == false) { try { - Runtime.getRuntime().exec(execString); + Runtime.getRuntime().exec(new String[]{execString, commandArgument}); } catch (IOException e) { e.printStackTrace(); } - MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + buildTarget); - Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + buildTarget); + MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + commandArgument); + Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + commandArgument); } } } \ No newline at end of file From 701bf85c8b3a5814e2c2139ca83a804813e50999 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 01:14:54 -0500 Subject: [PATCH 17/35] Fixed argument passing to unix runtime. --- src/discord/handlers/DevRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 0506dd34..524f8ee0 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -40,7 +40,7 @@ public class DevRequestHandler { switch (serverCommand) { case "build" : - execString = "/bin/sh -c ./mbdevbuild.sh "; + execString = "/bin/sh -c ./mbdevbuild.sh"; break; case "restart": execString = "/bin/sh -c ./mbdevrestart.sh"; From fe87253a86eddc021b058bbca7cc13fe12a0e205 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 01:22:11 -0500 Subject: [PATCH 18/35] Fixed argument passing to unix runtime. --- src/discord/handlers/DevRequestHandler.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 524f8ee0..9331375e 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -40,16 +40,16 @@ public class DevRequestHandler { switch (serverCommand) { case "build" : - execString = "/bin/sh -c ./mbdevbuild.sh"; + execString = "mbdevbuild.sh"; break; case "restart": - execString = "/bin/sh -c ./mbdevrestart.sh"; + execString = "mbdevrestart.sh"; break; case "debug": - execString = "/bin/sh -c ./mbdevdebug.sh"; + execString = "mbdevdebug.sh"; break; case "shutdown": - execString = "/bin/sh -c ./mbdevkill.sh"; + execString = "mbdevkill.sh"; break; default: break; From eea13b22a004beff9a078eddd564e2e345a55d33 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 01:32:57 -0500 Subject: [PATCH 19/35] Using ProcessBuilding instead of exec() --- src/discord/handlers/DevRequestHandler.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 9331375e..69e040cf 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -20,7 +20,8 @@ public class DevRequestHandler { String serverCommand; String commandArgument = ""; - String execString = ""; + String commandString = ""; + ProcessBuilder processBuilder; // Early exit if database unavailable or is not an admin @@ -40,27 +41,30 @@ public class DevRequestHandler { switch (serverCommand) { case "build" : - execString = "mbdevbuild.sh"; + commandString = "mbdevbuild.sh"; break; case "restart": - execString = "mbdevrestart.sh"; + commandString = "mbdevrestart.sh"; break; case "debug": - execString = "mbdevdebug.sh"; + commandString = "mbdevdebug.sh"; break; case "shutdown": - execString = "mbdevkill.sh"; + commandString = "mbdevkill.sh"; break; default: break; } - if (execString.isEmpty() == false) { + if (commandString.isEmpty() == false) { + + processBuilder = new ProcessBuilder("sh", "-c", commandString, commandArgument); try { - Runtime.getRuntime().exec(new String[]{execString, commandArgument}); + processBuilder.start(); } catch (IOException e) { - e.printStackTrace(); + throw new RuntimeException(e); } + MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + commandArgument); Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + commandArgument); } From 9268fa8b01f2c805bcad8bcac879ecc4383025de Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 01:39:14 -0500 Subject: [PATCH 20/35] Using ProcessBuilding instead of exec() --- src/discord/handlers/DevRequestHandler.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 69e040cf..aec38f01 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -41,16 +41,16 @@ public class DevRequestHandler { switch (serverCommand) { case "build" : - commandString = "mbdevbuild.sh"; + commandString = "./mbdevbuild.sh"; break; case "restart": - commandString = "mbdevrestart.sh"; + commandString = "./mbdevrestart.sh"; break; case "debug": - commandString = "mbdevdebug.sh"; + commandString = "./mbdevdebug.sh"; break; case "shutdown": - commandString = "mbdevkill.sh"; + commandString = "./mbdevkill.sh"; break; default: break; @@ -58,7 +58,7 @@ public class DevRequestHandler { if (commandString.isEmpty() == false) { - processBuilder = new ProcessBuilder("sh", "-c", commandString, commandArgument); + processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString, commandArgument); try { processBuilder.start(); } catch (IOException e) { From 0c874100180751b213129552ad1f3b4c8fd35e3b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 01:47:59 -0500 Subject: [PATCH 21/35] Using ProcessBuilding instead of exec() --- src/discord/handlers/DevRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index aec38f01..41677cd7 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -58,7 +58,7 @@ public class DevRequestHandler { if (commandString.isEmpty() == false) { - processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString, commandArgument); + processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument); try { processBuilder.start(); } catch (IOException e) { From ee676a08ea40a6da0033b54e798f0c25587f9d44 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 01:59:18 -0500 Subject: [PATCH 22/35] Better logging and error reporting. --- src/discord/handlers/DevRequestHandler.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 41677cd7..f0eb5398 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -56,17 +56,20 @@ public class DevRequestHandler { break; } - if (commandString.isEmpty() == false) { + if (commandString.isEmpty()) { + MagicBot.sendResponse(event, "Unrecognized Dev command: " + serverCommand + " " + commandArgument); + return; + } + + processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument); - processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument); - try { + try { processBuilder.start(); } catch (IOException e) { - throw new RuntimeException(e); + Logger.info(e.toString()); } MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + commandArgument); Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + commandArgument); } - } } \ No newline at end of file From 1493d3ad45e9c6df3bf81d4c10b633827287120c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 02:01:29 -0500 Subject: [PATCH 23/35] Support for more than one argument. --- src/discord/handlers/DevRequestHandler.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index f0eb5398..982e3be4 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -28,11 +28,6 @@ public class DevRequestHandler { if (MagicBot.isAdminEvent(event) == false) return; - // No command supplied? - - if (args.length != 1) - return; - serverCommand = args[0].toLowerCase().trim(); if (args.length == 2) From a460a201e14ea237cd00e0b221c1ce0efa06f419 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 09:07:40 -0500 Subject: [PATCH 24/35] Logging string contains exec command. --- src/discord/handlers/DevRequestHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 982e3be4..c45b72d6 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -12,7 +12,9 @@ import discord.MagicBot; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.pmw.tinylog.Logger; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; public class DevRequestHandler { @@ -21,6 +23,8 @@ public class DevRequestHandler { String serverCommand; String commandArgument = ""; String commandString = ""; + String logString = ""; + ProcessBuilder processBuilder; // Early exit if database unavailable or is not an admin @@ -64,7 +68,7 @@ public class DevRequestHandler { Logger.info(e.toString()); } - MagicBot.sendResponse(event, "Executed on dev: " + serverCommand + " " + commandArgument); - Logger.info(event.getAuthor().getName() + " told dev to " + serverCommand + " " + commandArgument); + logString = String.join(" ",processBuilder.command().toArray(new String[0])); + MagicBot.sendResponse(event, "Executed on dev: " + logString); } } \ No newline at end of file From 9ce06da271f81386f381d8efba1935232e1a8b76 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 09:43:03 -0500 Subject: [PATCH 25/35] Capturing output of remote exec() to file. --- src/discord/handlers/DevRequestHandler.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index c45b72d6..292017ee 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -13,6 +13,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.pmw.tinylog.Logger; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; @@ -26,6 +27,7 @@ public class DevRequestHandler { String logString = ""; ProcessBuilder processBuilder; + File outFile; // Early exit if database unavailable or is not an admin @@ -61,14 +63,17 @@ public class DevRequestHandler { } processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument); + outFile = new File("devLastOut"); + logString = String.join(" ",processBuilder.command().toArray(new String[0])); try { processBuilder.start(); + processBuilder.redirectOutput(outFile); } catch (IOException e) { Logger.info(e.toString()); } - logString = String.join(" ",processBuilder.command().toArray(new String[0])); - MagicBot.sendResponse(event, "Executed on dev: " + logString); + MagicBot.sendResponse(event, "Executed on dev: " + logString); + } } \ No newline at end of file From 93b33ce37e21658a5db0d73725e27d820446b0af Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 09:58:51 -0500 Subject: [PATCH 26/35] Capturing output of remote exec() to file. --- src/discord/handlers/DevRequestHandler.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 292017ee..492d448f 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -63,7 +63,17 @@ public class DevRequestHandler { } processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument); + outFile = new File("devLastOut"); + if (outFile.exists()) + outFile.delete(); + + try { + outFile.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } + logString = String.join(" ",processBuilder.command().toArray(new String[0])); try { From 8904fb882874aa47fb94e9113731d809cba1aaaa Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 10:06:37 -0500 Subject: [PATCH 27/35] Removed file redirect; better to do that within the shell. --- src/discord/handlers/DevRequestHandler.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 492d448f..fbeff612 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -27,7 +27,6 @@ public class DevRequestHandler { String logString = ""; ProcessBuilder processBuilder; - File outFile; // Early exit if database unavailable or is not an admin @@ -63,22 +62,10 @@ public class DevRequestHandler { } processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument); - - outFile = new File("devLastOut"); - if (outFile.exists()) - outFile.delete(); - - try { - outFile.createNewFile(); - } catch (IOException e) { - throw new RuntimeException(e); - } - logString = String.join(" ",processBuilder.command().toArray(new String[0])); try { processBuilder.start(); - processBuilder.redirectOutput(outFile); } catch (IOException e) { Logger.info(e.toString()); } From 72cbcb13fc5c2adc3173ca0352a395599eb2f70a Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 10:09:43 -0500 Subject: [PATCH 28/35] Change to response string after exec() --- src/discord/handlers/DevRequestHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index fbeff612..d50cb78e 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -70,7 +70,8 @@ public class DevRequestHandler { Logger.info(e.toString()); } - MagicBot.sendResponse(event, "Executed on dev: " + logString); + MagicBot.sendResponse(event, "Executed on dev: " + logString + "\n" + + "Use #dev lastout to view results"); } } \ No newline at end of file From a71bf4330b68c9e4227f70046cdcc04307d3440c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 10:12:45 -0500 Subject: [PATCH 29/35] Redirecting output via the shell. --- src/discord/handlers/DevRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index d50cb78e..e747d73e 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -61,7 +61,7 @@ public class DevRequestHandler { return; } - processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument); + processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument + " > devLastOut"); logString = String.join(" ",processBuilder.command().toArray(new String[0])); try { From d6a505fd009b17dc43a3714d6b9d21c7d67880e5 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 9 Jan 2023 10:22:35 -0500 Subject: [PATCH 30/35] Added lastout sub command. --- src/discord/handlers/DevRequestHandler.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index e747d73e..3fd95655 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -16,6 +16,9 @@ import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.stream.Collectors; public class DevRequestHandler { @@ -52,6 +55,9 @@ public class DevRequestHandler { case "shutdown": commandString = "./mbdevkill.sh"; break; + case "lastout": + MagicBot.sendResponse(event, getLastOutput()); + return; default: break; } @@ -74,4 +80,15 @@ public class DevRequestHandler { "Use #dev lastout to view results"); } + private static String getLastOutput() { + + String outString = null; + try { + outString = Files.lines(Paths.get("devLastOut")) + .collect(Collectors.joining(System.lineSeparator())); + } catch (IOException e) { + e.printStackTrace(); + } + return outString; + } } \ No newline at end of file From 81b72594236e4d4287a60f77844c32716b06e09b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 10 Jan 2023 08:34:11 -0500 Subject: [PATCH 31/35] Added remote console output. --- src/discord/handlers/DevRequestHandler.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index 3fd95655..b0d3f0ad 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -58,6 +58,8 @@ public class DevRequestHandler { case "lastout": MagicBot.sendResponse(event, getLastOutput()); return; + case "console": + commandString = "./mbdevconsole.sh"; default: break; } From 98470d4b1af85eb41691266d295c47544f489e2c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 10 Jan 2023 08:51:00 -0500 Subject: [PATCH 32/35] Added help for #dev subcommands --- src/discord/MagicBot.java | 2 +- src/discord/handlers/DevRequestHandler.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/discord/MagicBot.java b/src/discord/MagicBot.java index 6a94647c..8be071ee 100644 --- a/src/discord/MagicBot.java +++ b/src/discord/MagicBot.java @@ -306,7 +306,7 @@ public class MagicBot extends ListenerAdapter { "#server reboot/shutdown are your options.\n" + "#logs magicbot/world/login n (tail)\n" + "#flash Send flash message\n" + - "#dev build /restart/debug/shutdown\n" + + "#dev help (list dev subcommands)\n" + "#trash /detail/flush"; sendResponse(event, helpString); } diff --git a/src/discord/handlers/DevRequestHandler.java b/src/discord/handlers/DevRequestHandler.java index b0d3f0ad..a9b741d1 100644 --- a/src/discord/handlers/DevRequestHandler.java +++ b/src/discord/handlers/DevRequestHandler.java @@ -60,6 +60,16 @@ public class DevRequestHandler { return; case "console": commandString = "./mbdevconsole.sh"; + break; + case "help": + MagicBot.sendResponse(event, + "#dev build (blank==master) \n" + + "#dev shutdown (Shutdown dev server)\n" + + "#dev restart (Restarts the server)\n"+ + "#dev debug (Restarts server in debug mode)\n" + + "#dev console # (Displays # lines from console)\n" + + "#dev lastout (Displays output from last command) \n"); + return; default: break; } From af7d801388806c81e0302c09751f12576d3e7e94 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 10 Jan 2023 12:27:54 -0500 Subject: [PATCH 33/35] bugfix: not overriding mine open date on boot. --- src/engine/objects/Mine.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index cd367251..6482ead9 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -231,7 +231,7 @@ try{ int mineTime = (nation != null && !nation.isErrant()) ? nation.getMineTime() : MBServerStatics.MINE_EARLY_WINDOW; - LocalDateTime openDate = LocalDateTime.now().withHour(mineTime).withMinute(0).withSecond(0).withNano(0); + this.openDate = this.openDate.withHour(mineTime).withMinute(0).withSecond(0).withNano(0); //Failed to Update Database, default mine time. @@ -242,8 +242,6 @@ try{ return; } - this.openDate = openDate; - } public boolean changeProductionType(Resource resource){ From 3ec985e3d9360effdb5a95baa579cca9239629f4 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 11 Jan 2023 15:00:52 -0500 Subject: [PATCH 34/35] bugfix: window should not end for a mine not opened. --- src/engine/objects/Mine.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index 6482ead9..de26a814 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -519,6 +519,11 @@ try{ public boolean handleEndMineWindow(){ + // No need to end the window of a mine which never opened. + + if (this.isActive == false) + return false; + Building mineBuilding = BuildingManager.getBuildingFromCache(this.buildingID); if (mineBuilding == null){ From 4b8e0cb04168cc0481a8c8b3ef1b4ec68c7be213 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 11 Jan 2023 16:27:01 -0500 Subject: [PATCH 35/35] Bump old opendate during reboot to current +1 when mine window has passed. --- src/engine/objects/Mine.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index de26a814..39564bd2 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -147,7 +147,12 @@ public class Mine extends AbstractGameObject { if (mineOpenDateTime != null) this.openDate = mineOpenDateTime.toLocalDateTime(); - + + // Set opendate to tomorrow if window has passed + + if (LocalDateTime.now().isAfter(this.openDate.plusHours(1))) + this.openDate = LocalDateTime.now().plusDays(1).withHour(this.openDate.getHour()).withMinute(0).withSecond(0).withNano(0); + } public static void SendMineAttackMessage(Building mine){