Handler created for ViewResourcesMsg

This commit is contained in:
2024-03-29 06:14:19 -04:00
parent fbec206389
commit 80c11db80b
8 changed files with 83 additions and 48 deletions
+5 -35
View File
@@ -22,15 +22,16 @@ import engine.net.NetMsgHandler;
import engine.net.client.handlers.AbstractClientMsgHandler;
import engine.net.client.msg.*;
import engine.net.client.msg.chat.AbstractChatMsg;
import engine.objects.*;
import engine.objects.AbstractCharacter;
import engine.objects.Mob;
import engine.objects.NPC;
import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;
import engine.server.world.WorldServer;
import engine.session.Session;
import engine.util.StringUtils;
import org.pmw.tinylog.Logger;
import java.sql.SQLException;
/**
* @author:
* @summary: This class is the mainline router for application protocol
@@ -167,34 +168,6 @@ public class ClientMessagePump implements NetMsgHandler {
}
private static void ViewResourcesMessage(ViewResourcesMessage msg, ClientConnection origin) throws SQLException {
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
if (player == null)
return;
Guild guild = player.getGuild();
City city = guild.getOwnedCity();
if (city == null)
return;
Building warehouse = BuildingManager.getBuilding(city.getWarehouseBuildingID());
if (warehouse == null)
return;
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
vrm.setWarehouseBuilding(warehouse);
vrm.setGuild(player.getGuild());
vrm.configure();
Dispatch dispatch = Dispatch.borrow(player, vrm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
}
protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException {
PlayerCharacter pc = SessionManager.getPlayerCharacter(conn);
@@ -337,9 +310,6 @@ public class ClientMessagePump implements NetMsgHandler {
break;
case OPENVAULT:
break;
case VIEWRESOURCES:
ViewResourcesMessage((ViewResourcesMessage) msg, origin);
break;
case RAISEATTR:
modifyStat((ModifyStatMsg) msg, origin);
break;
@@ -423,7 +393,7 @@ public class ClientMessagePump implements NetMsgHandler {
}
} catch (MsgSendException | SQLException e) {
} catch (Exception e) {
Logger.error("handler for " + protocolMsg + " failed: " + e);
return false;
}
+1 -1
View File
@@ -241,7 +241,7 @@ public enum Protocol {
VENDORSELLWINDOW(0x267DAB90, VendorSellWindowMsg.class, VendorSellWindowMsgHandler.class), //open Sell to NPC Window
VENDORBUYWINDOW(0x682DAB4D, VendorBuyWindowMsg.class, VendorBuyWindowMsgHandler.class), // Open Buy From NPC Window
VERSIONINFO(0x4B7EE463, VersionInfoMsg.class, null), // Version Information
VIEWRESOURCES(0xCEFD0346, ViewResourcesMessage.class, null),
VIEWRESOURCES(0xCEFD0346, ViewResourcesMsg.class, ViewResourcesMsgHandler.class),
VISUALUPDATE(0x33402fd2, null, null),
WEIGHTINVENTORY(0xF1B6A85C, LootWindowResponseMsg.class, null), // MoveObjectToContainer Window Response
WHOREQUEST(0xF431CCE9, WhoRequestMsg.class, WhoRequestMsgHandler.class), // Request /who
@@ -428,7 +428,7 @@ public class MerchantMsgHandler extends AbstractClientMsgHandler {
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
break;
case 16:
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
ViewResourcesMsg vrm = new ViewResourcesMsg(player);
warehouse = npc.getBuilding();
vrm.setGuild(player.getGuild());
vrm.setWarehouseBuilding(warehouse);
@@ -10,7 +10,7 @@ import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.TaxCityMsg;
import engine.net.client.msg.ViewResourcesMessage;
import engine.net.client.msg.ViewResourcesMsg;
import engine.objects.*;
/*
@@ -109,7 +109,7 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler {
// return true;
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
ViewResourcesMsg vrm = new ViewResourcesMsg(player);
vrm.setGuild(building.getGuild());
vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().warehouse.building.getObjectUUID()));
vrm.configure();
@@ -0,0 +1,65 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.Enum.DispatchChannel;
import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ViewResourcesMsg;
import engine.objects.Building;
import engine.objects.City;
import engine.objects.Guild;
import engine.objects.PlayerCharacter;
public class ViewResourcesMsgHandler extends AbstractClientMsgHandler {
public ViewResourcesMsgHandler() {
super(ViewResourcesMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
// Member variable declaration
ViewResourcesMsg msg;
// Member variable assignment
msg = (ViewResourcesMsg) baseMsg;
Guild guild = playerCharacter.getGuild();
City city = guild.getOwnedCity();
if (city == null)
return true;
Building warehouse = BuildingManager.getBuilding(city.getWarehouseBuildingID());
if (warehouse == null)
return true;
ViewResourcesMsg vrm = new ViewResourcesMsg(playerCharacter);
vrm.setWarehouseBuilding(warehouse);
vrm.setGuild(playerCharacter.getGuild());
vrm.configure();
Dispatch dispatch = Dispatch.borrow(playerCharacter, vrm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
}
}
@@ -18,7 +18,7 @@ import engine.net.client.Protocol;
import engine.objects.*;
public class ViewResourcesMessage extends ClientNetMsg {
public class ViewResourcesMsg extends ClientNetMsg {
//resource hashes
//0001240F
@@ -55,7 +55,7 @@ public class ViewResourcesMessage extends ClientNetMsg {
* This is the general purpose constructor.
*/
public ViewResourcesMessage(PlayerCharacter player) {
public ViewResourcesMsg(PlayerCharacter player) {
super(Protocol.VIEWRESOURCES);
this.guild = null;
this.player = player;
@@ -64,7 +64,7 @@ public class ViewResourcesMessage extends ClientNetMsg {
/**
* This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller.
*/
public ViewResourcesMessage(AbstractConnection origin, ByteBufferReader reader) {
public ViewResourcesMsg(AbstractConnection origin, ByteBufferReader reader) {
super(Protocol.VIEWRESOURCES, origin, reader);
}