forked from MagicBane/Server
FatBoy-DOTC
2 years ago
9 changed files with 268 additions and 78 deletions
@ -0,0 +1,106 @@ |
|||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// 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.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 { |
||||||
|
|
||||||
|
public static void handleRequest(MessageReceivedEvent event, String[] args) { |
||||||
|
|
||||||
|
String serverCommand; |
||||||
|
String commandArgument = ""; |
||||||
|
String commandString = ""; |
||||||
|
String logString = ""; |
||||||
|
|
||||||
|
ProcessBuilder processBuilder; |
||||||
|
|
||||||
|
// Early exit if database unavailable or is not an admin
|
||||||
|
|
||||||
|
if (MagicBot.isAdminEvent(event) == false) |
||||||
|
return; |
||||||
|
|
||||||
|
serverCommand = args[0].toLowerCase().trim(); |
||||||
|
|
||||||
|
if (args.length == 2) |
||||||
|
commandArgument = args[1].toLowerCase().trim(); |
||||||
|
|
||||||
|
switch (serverCommand) { |
||||||
|
|
||||||
|
case "build" : |
||||||
|
commandString = "./mbdevbuild.sh"; |
||||||
|
break; |
||||||
|
case "restart": |
||||||
|
commandString = "./mbdevrestart.sh"; |
||||||
|
break; |
||||||
|
case "debug": |
||||||
|
commandString = "./mbdevdebug.sh"; |
||||||
|
break; |
||||||
|
case "shutdown": |
||||||
|
commandString = "./mbdevkill.sh"; |
||||||
|
break; |
||||||
|
case "lastout": |
||||||
|
MagicBot.sendResponse(event, getLastOutput()); |
||||||
|
return; |
||||||
|
case "console": |
||||||
|
commandString = "./mbdevconsole.sh"; |
||||||
|
break; |
||||||
|
case "help": |
||||||
|
MagicBot.sendResponse(event, |
||||||
|
"#dev build <target> (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; |
||||||
|
} |
||||||
|
|
||||||
|
if (commandString.isEmpty()) { |
||||||
|
MagicBot.sendResponse(event, "Unrecognized Dev command: " + serverCommand + " " + commandArgument); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument + " > devLastOut"); |
||||||
|
logString = String.join(" ",processBuilder.command().toArray(new String[0])); |
||||||
|
|
||||||
|
try { |
||||||
|
processBuilder.start(); |
||||||
|
} catch (IOException e) { |
||||||
|
Logger.info(e.toString()); |
||||||
|
} |
||||||
|
|
||||||
|
MagicBot.sendResponse(event, "Executed on dev: " + logString + "\n" + |
||||||
|
"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; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,115 @@ |
|||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// 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.ErrorPopupMsg; |
||||||
|
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; |
||||||
|
|
||||||
|
import java.time.LocalDateTime; |
||||||
|
|
||||||
|
/* |
||||||
|
* @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; |
||||||
|
int newMineTime; |
||||||
|
|
||||||
|
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; |
||||||
|
|
||||||
|
newMineTime = mineWindowChangeMsg.getTime(); |
||||||
|
|
||||||
|
// Enforce 15hr restriction between WOO edits
|
||||||
|
|
||||||
|
if (LocalDateTime.now().isBefore(mineGuild.lastWooEditTime.plusHours(14))) { |
||||||
|
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 && |
||||||
|
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); |
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue