forked from MagicBane/Server
Merge remote-tracking branch 'origin/feature-json7.4' into feature-json7.4
This commit is contained in:
@@ -20,13 +20,11 @@ import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.MessageDispatcher;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.net.client.handlers.ClientAdminCommandMsgHandler;
|
||||
import engine.net.client.msg.chat.*;
|
||||
import engine.net.client.msg.commands.ClientAdminCommandMsg;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.server.world.WorldServer;
|
||||
import engine.session.Session;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -42,8 +40,8 @@ public enum ChatManager {
|
||||
// (FLOOD_TIME_THRESHOLD) ms will flag as a flood message
|
||||
// Example, set to 3 & 2000 to flag the 3rd message within 2000 ms.
|
||||
|
||||
private static final int FLOOD_QTY_THRESHOLD = 3;
|
||||
private static final int FLOOD_TIME_THRESHOLD = 2000;
|
||||
public static final int FLOOD_QTY_THRESHOLD = 3;
|
||||
public static final int FLOOD_TIME_THRESHOLD = 2000;
|
||||
private static final String FLOOD_USER_ERROR = "You talk too much!";
|
||||
private static final String SILENCED = "You find yourself mute!";
|
||||
private static final String UNKNOWN_COMMAND = "No such command.";
|
||||
@@ -51,74 +49,6 @@ public enum ChatManager {
|
||||
/**
|
||||
* This method used when handling a ChatMsg received from the network.
|
||||
*/
|
||||
public static void handleChatMsg(Session sender, AbstractChatMsg msg) {
|
||||
|
||||
if (msg == null) {
|
||||
Logger.warn(
|
||||
"null message: ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender == null) {
|
||||
Logger.warn(
|
||||
"null sender: ");
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerCharacter pc = sender.getPlayerCharacter();
|
||||
|
||||
if (pc == null) {
|
||||
Logger.warn(
|
||||
"invalid sender: ");
|
||||
return;
|
||||
}
|
||||
|
||||
Protocol protocolMsg = msg.getProtocolMsg();
|
||||
|
||||
// Flood control, implemented per channel
|
||||
|
||||
boolean isFlood = false;
|
||||
long curMsgTime = System.currentTimeMillis();
|
||||
long checkTime = pc.chatFloodTime(protocolMsg.opcode, curMsgTime, FLOOD_QTY_THRESHOLD - 1);
|
||||
|
||||
if ((checkTime > 0L) && (curMsgTime - checkTime < FLOOD_TIME_THRESHOLD))
|
||||
isFlood = true;
|
||||
|
||||
switch (protocolMsg) {
|
||||
case CHATSAY:
|
||||
ChatManager.chatSay(pc, msg.getMessage(), isFlood);
|
||||
return;
|
||||
case CHATCSR:
|
||||
ChatManager.chatCSR(msg);
|
||||
return;
|
||||
case CHATTELL:
|
||||
ChatTellMsg ctm = (ChatTellMsg) msg;
|
||||
ChatManager.chatTell(pc, ctm.getTargetName(), ctm.getMessage(), isFlood);
|
||||
return;
|
||||
case CHATSHOUT:
|
||||
ChatManager.chatShout(pc, msg.getMessage(), isFlood);
|
||||
return;
|
||||
case CHATGUILD:
|
||||
ChatManager.chatGuild(pc, (ChatGuildMsg) msg);
|
||||
return;
|
||||
case CHATGROUP:
|
||||
ChatManager.chatGroup(pc, (ChatGroupMsg) msg);
|
||||
return;
|
||||
case CHATIC:
|
||||
ChatManager.chatIC(pc, (ChatICMsg) msg);
|
||||
return;
|
||||
case LEADERCHANNELMESSAGE:
|
||||
ChatManager.chatGlobal(pc, msg.getMessage(), isFlood);
|
||||
return;
|
||||
case GLOBALCHANNELMESSAGE:
|
||||
case CHATPVP:
|
||||
case CHATCITY:
|
||||
case CHATINFO:
|
||||
case SYSTEMBROADCASTCHANNEL:
|
||||
default:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Channels
|
||||
@@ -190,7 +120,7 @@ public enum ChatManager {
|
||||
}
|
||||
|
||||
if (ChatManager.isDevCommand(text) == true) {
|
||||
ChatManager.processDevCommand(player, text);
|
||||
ClientAdminCommandMsgHandler.processDevCommand(player, text);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1083,94 +1013,4 @@ public enum ChatManager {
|
||||
return text.equalsIgnoreCase("lua_population()");
|
||||
}
|
||||
|
||||
private static boolean processDevCommand(AbstractWorldObject sender, String text) {
|
||||
|
||||
if (sender.getObjectType().equals(GameObjectType.PlayerCharacter)) {
|
||||
|
||||
PlayerCharacter pcSender = (PlayerCharacter) sender;
|
||||
|
||||
// first remove the DEV_CMD_PREFIX
|
||||
String[] words = text.split(MBServerStatics.DEV_CMD_PREFIX, 2);
|
||||
|
||||
if (words[1].length() == 0)
|
||||
return false;
|
||||
|
||||
// next get the command
|
||||
String[] commands = words[1].split(" ", 2);
|
||||
String cmd = commands[0].toLowerCase();
|
||||
String cmdArgument = "";
|
||||
|
||||
if (commands.length > 1)
|
||||
cmdArgument = commands[1].trim();
|
||||
|
||||
AbstractGameObject target = pcSender.getLastTarget();
|
||||
// return DevCmd.processDevCommand(pcSender, cmd, cmdArgument,
|
||||
// target);
|
||||
return DevCmdManager.handleDevCmd(pcSender, cmd,
|
||||
cmdArgument, target);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an Admin Command, which is a preset command sent from the client
|
||||
*/
|
||||
public static void HandleClientAdminCmd(ClientAdminCommandMsg data,
|
||||
ClientConnection cc) {
|
||||
|
||||
PlayerCharacter pcSender = SessionManager.getPlayerCharacter(cc);
|
||||
|
||||
if (pcSender == null)
|
||||
return;
|
||||
|
||||
Account acct = SessionManager.getAccount(pcSender);
|
||||
|
||||
if (acct == null)
|
||||
return;
|
||||
|
||||
// require minimal access to continue
|
||||
// specific accessLevel checks performed by the DevCmdManager
|
||||
if (acct.status.equals(Enum.AccountStatus.ADMIN) == false) {
|
||||
Logger.warn(pcSender.getFirstName() + " Attempted to use a client admin command");
|
||||
//wtf? ChatManager.chatSystemInfo(pcSender, "CHEATER!!!!!!!!!!!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
// First remove the initial slash
|
||||
String d = data.getMsgCommand();
|
||||
String[] words = d.split("/", 2);
|
||||
|
||||
if (words[1].length() == 0)
|
||||
return;
|
||||
|
||||
// Next get the command
|
||||
String[] commands = words[1].split(" ", 2);
|
||||
String cmd = commands[0].toLowerCase();
|
||||
String cmdArgument = "";
|
||||
|
||||
if (commands.length > 1)
|
||||
cmdArgument = commands[1].trim();
|
||||
|
||||
AbstractGameObject target = data.getTarget();
|
||||
|
||||
// Map to a DevCmd
|
||||
String devCmd = "";
|
||||
|
||||
if (cmd.compareTo("goto") == 0)
|
||||
devCmd = "goto";
|
||||
else if (cmd.compareTo("suspend") == 0)
|
||||
devCmd = "suspend";
|
||||
else if (cmd.compareTo("getinfo") == 0)
|
||||
devCmd = "info";
|
||||
else if (devCmd.isEmpty()) {
|
||||
Logger.info("Unhandled admin command was used: /"
|
||||
+ cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
DevCmdManager.handleDevCmd(pcSender, devCmd, cmdArgument,
|
||||
target);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@ import engine.Enum.ModType;
|
||||
import engine.Enum.SourceType;
|
||||
import engine.InterestManagement.InterestManager;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.job.JobContainer;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.jobs.StuckJob;
|
||||
import engine.math.Bounds;
|
||||
import engine.math.Vector3f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
@@ -30,7 +27,6 @@ import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static engine.math.FastMath.sqr;
|
||||
|
||||
@@ -474,26 +470,4 @@ public enum MovementManager {
|
||||
ac.teleport(ac.getLoc());
|
||||
}
|
||||
|
||||
public static void stuck(ClientConnection origin) {
|
||||
|
||||
PlayerCharacter sourcePlayer = origin.getPlayerCharacter();
|
||||
|
||||
if (sourcePlayer == null)
|
||||
return;
|
||||
|
||||
if (sourcePlayer.getTimers().containsKey("Stuck"))
|
||||
return;
|
||||
|
||||
StuckJob sj = new StuckJob(sourcePlayer);
|
||||
JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert
|
||||
ConcurrentHashMap<String, JobContainer> timers = sourcePlayer.getTimers();
|
||||
|
||||
if (timers != null) {
|
||||
if (timers.containsKey("Stuck")) {
|
||||
timers.get("Stuck").cancelJob();
|
||||
timers.remove("Stuck");
|
||||
}
|
||||
timers.put("Stuck", jc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@ import engine.job.AbstractJob;
|
||||
import engine.job.AbstractScheduleJob;
|
||||
import engine.job.JobContainer;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.jobs.*;
|
||||
import engine.jobs.AbstractEffectJob;
|
||||
import engine.jobs.FinishRecycleTimeJob;
|
||||
import engine.jobs.UseItemJob;
|
||||
import engine.jobs.UsePowerJob;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.Dispatch;
|
||||
@@ -28,7 +31,6 @@ import engine.net.client.msg.*;
|
||||
import engine.objects.*;
|
||||
import engine.powers.*;
|
||||
import engine.powers.poweractions.AbstractPowerAction;
|
||||
import engine.powers.poweractions.TrackPowerAction;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
@@ -1241,264 +1243,7 @@ public enum PowersManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void summon(SendSummonsRequestMsg msg, ClientConnection origin) {
|
||||
PlayerCharacter pc = SessionManager.getPlayerCharacter(
|
||||
origin);
|
||||
if (pc == null)
|
||||
return;
|
||||
|
||||
PlayerCharacter target = SessionManager
|
||||
.getPlayerCharacterByLowerCaseName(msg.getTargetName());
|
||||
if (target == null || target.equals(pc) || target.isCombat()) {
|
||||
|
||||
if (target == null) // Player not found. Send not found message
|
||||
ChatManager.chatInfoError(pc,
|
||||
"Cannot find that player to summon.");
|
||||
else if (target.isCombat())
|
||||
ChatManager.chatInfoError(pc,
|
||||
"Cannot summon player in combat.");
|
||||
// else trying to summon self, just fail
|
||||
|
||||
// recycle summon
|
||||
sendRecyclePower(msg.getPowerToken(), origin);
|
||||
|
||||
// TODO: client already subtracted 200 mana.. need to correct it
|
||||
// end cast
|
||||
PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(),
|
||||
msg.getTrains(), msg.getSourceType(), msg.getSourceID(), 0,
|
||||
0, 0f, 0f, 0f, 1, 0);
|
||||
sendPowerMsg(pc, 2, pam);
|
||||
|
||||
return;
|
||||
}
|
||||
if (ConfigManager.MB_RULESET.getValue() == "LORE") {
|
||||
if (pc.guild.getGuildType().equals(target.guild.getGuildType()) == false) {
|
||||
ChatManager.chatInfoError(pc,
|
||||
"Cannot summon player outside your charter.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), msg
|
||||
.getTrains(), msg.getSourceType(), msg.getSourceID(), target
|
||||
.getObjectType().ordinal(), target.getObjectUUID(), 0f, 0f, 0f, 1, 0);
|
||||
|
||||
// Client removes 200 mana on summon use.. so don't send message to self
|
||||
target.addSummoner(pc.getObjectUUID(), System.currentTimeMillis() + MBServerStatics.FOURTYFIVE_SECONDS);
|
||||
usePower(pam, origin, false);
|
||||
}
|
||||
|
||||
public static void recvSummon(RecvSummonsRequestMsg msg, ClientConnection origin) {
|
||||
PlayerCharacter pc = SessionManager.getPlayerCharacter(origin);
|
||||
if (pc == null)
|
||||
return;
|
||||
|
||||
PlayerCharacter source = PlayerCharacter.getFromCache(msg.getSourceID());
|
||||
if (source == null)
|
||||
return;
|
||||
|
||||
long tooLate = pc.getSummoner(source.getObjectUUID());
|
||||
if (tooLate < System.currentTimeMillis()) {
|
||||
ChatManager.chatInfoError(pc, "You waited too long to " + (msg.accepted() ? "accept" : "decline") + " the summons.");
|
||||
pc.removeSummoner(source.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
if (pc.getBonuses() != null && pc.getBonuses().getBool(ModType.BlockedPowerType, SourceType.SUMMON)) {
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "You have been blocked from receiving summons!");
|
||||
ErrorPopupMsg.sendErrorMsg(source, "Target is blocked from receiving summons!");
|
||||
pc.removeSummoner(source.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
pc.removeSummoner(source.getObjectUUID());
|
||||
|
||||
// Handle Accepting or Denying a summons.
|
||||
// set timer based on summon type.
|
||||
boolean wentThrough = false;
|
||||
if (msg.accepted())
|
||||
// summons accepted, let's move the player if within time
|
||||
if (source.isAlive()) {
|
||||
|
||||
// //make sure summons handled in time
|
||||
ConcurrentHashMap<String, JobContainer> timers = source.getTimers();
|
||||
// if (timers == null || !timers.containsKey("SummonSend")) {
|
||||
// ChatManager.chatInfoError(pc, "You waited too long to " + (msg.accepted() ? "accept" : "decline") + " the summons.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // clear last summons accept timer
|
||||
// timers.get("SummonSend").cancelJob();
|
||||
//timers.remove("SummonSend");
|
||||
// cancel any other summons waiting
|
||||
timers = pc.getTimers();
|
||||
if (timers != null && timers.containsKey("Summon"))
|
||||
timers.get("Summon").cancelJob();
|
||||
|
||||
// get time to wait before summons goes through
|
||||
BaseClass base = source.baseClass;
|
||||
PromotionClass promo = source.getPromotionClass();
|
||||
int duration;
|
||||
|
||||
|
||||
//determine if in combat with another player
|
||||
|
||||
|
||||
//comment out this block to disable combat timer
|
||||
// if (lastAttacked < 60000) {
|
||||
// if (pc.inSafeZone()) //player in safe zone, no need for combat timer
|
||||
// combat = false;
|
||||
// else if (source.inSafeZone()) //summoner in safe zone, apply combat timer
|
||||
// combat = true;
|
||||
// else if ((source.getLoc().distance2D(pc.getLoc())) > 6144f)
|
||||
// combat = true; //more than 1.5x width of zone, not tactical summons
|
||||
// }
|
||||
|
||||
if (promo != null && promo.getObjectUUID() == 2519)
|
||||
duration = 10000; // Priest summons, 10 seconds
|
||||
else if (base != null && base.getObjectUUID() == 2501)
|
||||
duration = 15000; // Healer Summons, 15 seconds
|
||||
else
|
||||
duration = 45000; // Belgosh Summons, 45 seconds
|
||||
|
||||
|
||||
// Teleport to summoners location
|
||||
FinishSummonsJob fsj = new FinishSummonsJob(source, pc);
|
||||
JobContainer jc = JobScheduler.getInstance().scheduleJob(fsj,
|
||||
duration);
|
||||
if (timers != null)
|
||||
timers.put("Summon", jc);
|
||||
wentThrough = true;
|
||||
}
|
||||
|
||||
// Summons failed
|
||||
if (!wentThrough)
|
||||
// summons refused. Let's be nice and reset recycle timer
|
||||
if (source != null) {
|
||||
|
||||
// Send summons refused Message
|
||||
ErrorPopupMsg.sendErrorPopup(source, 29);
|
||||
|
||||
// recycle summons power
|
||||
//finishRecycleTime(428523680, source, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void trackWindow(TrackWindowMsg msg, ClientConnection origin) {
|
||||
|
||||
PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(
|
||||
origin);
|
||||
|
||||
if (playerCharacter == null)
|
||||
return;
|
||||
|
||||
if (MBServerStatics.POWERS_DEBUG) {
|
||||
ChatManager.chatSayInfo(
|
||||
playerCharacter,
|
||||
"Using Power: " + Integer.toHexString(msg.getPowerToken())
|
||||
+ " (" + msg.getPowerToken() + ')');
|
||||
Logger.info("Using Power: "
|
||||
+ Integer.toHexString(msg.getPowerToken()) + " ("
|
||||
+ msg.getPowerToken() + ')');
|
||||
}
|
||||
|
||||
// get track power used
|
||||
PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerToken());
|
||||
|
||||
if (pb == null || !pb.isTrack())
|
||||
return;
|
||||
|
||||
//check track threshold timer to prevent spam
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long timestamp = playerCharacter.getTimeStamp("trackWindow");
|
||||
long dif = currentTime - timestamp;
|
||||
if (dif < MBServerStatics.TRACK_WINDOW_THRESHOLD)
|
||||
return;
|
||||
playerCharacter.setTimeStamp("trackWindow", currentTime);
|
||||
|
||||
ArrayList<ActionsBase> ablist = pb.getActions();
|
||||
if (ablist == null)
|
||||
return;
|
||||
|
||||
TrackPowerAction tpa = null;
|
||||
for (ActionsBase ab : ablist) {
|
||||
AbstractPowerAction apa = ab.getPowerAction();
|
||||
if (apa != null && apa instanceof TrackPowerAction)
|
||||
tpa = (TrackPowerAction) apa;
|
||||
}
|
||||
if (tpa == null)
|
||||
return;
|
||||
|
||||
// Check powers for normal users
|
||||
if (playerCharacter.getPowers() == null || !playerCharacter.getPowers().containsKey(msg.getPowerToken()))
|
||||
if (!playerCharacter.isCSR())
|
||||
if (!MBServerStatics.POWERS_DEBUG) {
|
||||
// ChatManager.chatSayInfo(pc, "You may not cast that spell!");
|
||||
// this.logEXPLOIT("usePowerA(): Cheat attempted? '" + msg.getPowerToken() + "' was not associated with " + pc.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
// Get search mask for track
|
||||
int mask = 0;
|
||||
if (pb.targetPlayer())
|
||||
if (tpa.trackVampire()) // track vampires
|
||||
mask = MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD;
|
||||
else
|
||||
// track all players
|
||||
mask = MBServerStatics.MASK_PLAYER;
|
||||
else if (pb.targetCorpse()) // track corpses
|
||||
mask = MBServerStatics.MASK_CORPSE;
|
||||
else if (tpa.trackNPC()) // Track NPCs
|
||||
mask = MBServerStatics.MASK_NPC;
|
||||
else if (tpa.trackUndead()) // Track Undead
|
||||
mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_UNDEAD;
|
||||
else
|
||||
// Track All
|
||||
mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_NPC;
|
||||
|
||||
// Find characters in range
|
||||
HashSet<AbstractWorldObject> allTargets;
|
||||
allTargets = WorldGrid.getObjectsInRangeContains(playerCharacter.getLoc(),
|
||||
pb.getRange(), mask);
|
||||
|
||||
//remove anyone who can't be tracked
|
||||
Iterator<AbstractWorldObject> it = allTargets.iterator();
|
||||
while (it.hasNext()) {
|
||||
AbstractWorldObject awo = it.next();
|
||||
if (awo == null)
|
||||
continue;
|
||||
else if (!awo.isAlive())
|
||||
it.remove();
|
||||
else if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) {
|
||||
PlayerBonuses bonus = ((PlayerCharacter) awo).getBonuses();
|
||||
if (bonus != null && bonus.getBool(ModType.CannotTrack, SourceType.NONE))
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// get max charcters for window
|
||||
int maxTargets = 20;
|
||||
PromotionClass promo = playerCharacter.getPromotionClass();
|
||||
if (promo != null) {
|
||||
int tableID = promo.getObjectUUID();
|
||||
if (tableID == 2512 || tableID == 2514 || tableID == 2515)
|
||||
maxTargets = 40;
|
||||
}
|
||||
|
||||
// create list of characters
|
||||
HashSet<AbstractCharacter> trackChars = RangeBasedAwo.getTrackList(
|
||||
allTargets, playerCharacter, maxTargets);
|
||||
|
||||
TrackWindowMsg trackWindowMsg = new TrackWindowMsg(msg);
|
||||
|
||||
// send track window
|
||||
trackWindowMsg.setSource(playerCharacter);
|
||||
trackWindowMsg.setCharacters(trackChars);
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(playerCharacter, trackWindowMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
}
|
||||
|
||||
private static void sendRecyclePower(int token, ClientConnection origin) {
|
||||
public static void sendRecyclePower(int token, ClientConnection origin) {
|
||||
RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token);
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), recyclePowerMsg);
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package engine.gameManager;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.objects.CharacterItemManager;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
public enum TradeManager {
|
||||
|
||||
TRADEMANAGER;
|
||||
|
||||
public static void tradeRequest(TradeRequestMsg msg, ClientConnection origin) {
|
||||
|
||||
PlayerCharacter source = origin.getPlayerCharacter();
|
||||
|
||||
if (source == null)
|
||||
return;
|
||||
|
||||
source.charItemManager.tradeRequest(msg);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void acceptTradeRequest(AcceptTradeRequestMsg msg, ClientConnection origin) {
|
||||
|
||||
PlayerCharacter source = origin.getPlayerCharacter();
|
||||
|
||||
if (source == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
source.charItemManager.acceptTradeRequest(msg);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
// TODO Auto-generated catch block
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void rejectTradeRequest(RejectTradeRequestMsg msg, ClientConnection origin) {
|
||||
// TODO Do nothing? If so, delete this method & case above
|
||||
}
|
||||
|
||||
public static void addItemToTradeWindow(AddItemToTradeWindowMsg msg, ClientConnection origin) {
|
||||
|
||||
|
||||
PlayerCharacter source = origin.getPlayerCharacter();
|
||||
if (source == null || !source.isAlive())
|
||||
return;
|
||||
try {
|
||||
source.charItemManager.addItemToTradeWindow(msg);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void addGoldToTradeWindow(AddGoldToTradeWindowMsg msg, ClientConnection origin) {
|
||||
|
||||
PlayerCharacter source = origin.getPlayerCharacter();
|
||||
|
||||
if (source == null || !source.isAlive())
|
||||
return;
|
||||
|
||||
|
||||
CharacterItemManager sourceItemMan = source.charItemManager;
|
||||
|
||||
if (sourceItemMan == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
sourceItemMan.addGoldToTradeWindow(msg);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void commitToTrade(CommitToTradeMsg msg, ClientConnection origin) {
|
||||
|
||||
PlayerCharacter source = origin.getPlayerCharacter();
|
||||
|
||||
if (source == null || !source.isAlive())
|
||||
return;
|
||||
|
||||
CharacterItemManager sourceItemMan = source.charItemManager;
|
||||
|
||||
if (sourceItemMan == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
sourceItemMan.commitToTrade(msg);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void uncommitToTrade(UncommitToTradeMsg msg, ClientConnection origin) {
|
||||
|
||||
PlayerCharacter source = origin.getPlayerCharacter();
|
||||
|
||||
if (source == null || !source.isAlive())
|
||||
return;
|
||||
|
||||
CharacterItemManager sourceItemMan = source.charItemManager;
|
||||
|
||||
if (sourceItemMan == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
sourceItemMan.uncommitToTrade(msg);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void closeTradeWindow(CloseTradeWindowMsg msg, ClientConnection origin) {
|
||||
|
||||
PlayerCharacter source = origin.getPlayerCharacter();
|
||||
|
||||
if (source == null)
|
||||
return;
|
||||
|
||||
CharacterItemManager sourceItemMan = source.charItemManager;
|
||||
|
||||
if (sourceItemMan == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
sourceItemMan.closeTradeWindow(msg, true);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void invalidTradeRequest(InvalidTradeRequestMsg msg) {
|
||||
PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID());
|
||||
Dispatch dispatch;
|
||||
|
||||
dispatch = Dispatch.borrow(requester, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user