Browse Source

Handler created for ViewResourcesMsg

combat-2
MagicBot 8 months ago
parent
commit
80c11db80b
  1. 40
      src/engine/net/client/ClientMessagePump.java
  2. 2
      src/engine/net/client/Protocol.java
  3. 2
      src/engine/net/client/handlers/MerchantMsgHandler.java
  4. 4
      src/engine/net/client/handlers/TaxCityMsgHandler.java
  5. 65
      src/engine/net/client/handlers/ViewResourcesMsgHandler.java
  6. 6
      src/engine/net/client/msg/ViewResourcesMsg.java
  7. 4
      src/engine/objects/City.java
  8. 8
      src/engine/objects/Warehouse.java

40
src/engine/net/client/ClientMessagePump.java

@ -22,15 +22,16 @@ import engine.net.NetMsgHandler; @@ -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 { @@ -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 { @@ -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 { @@ -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;
}

2
src/engine/net/client/Protocol.java

@ -241,7 +241,7 @@ public enum Protocol { @@ -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

2
src/engine/net/client/handlers/MerchantMsgHandler.java

@ -428,7 +428,7 @@ public class MerchantMsgHandler extends AbstractClientMsgHandler { @@ -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);

4
src/engine/net/client/handlers/TaxCityMsgHandler.java

@ -10,7 +10,7 @@ import engine.net.client.ClientConnection; @@ -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 { @@ -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();

65
src/engine/net/client/handlers/ViewResourcesMsgHandler.java

@ -0,0 +1,65 @@ @@ -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;
}
}

6
src/engine/net/client/msg/ViewResourcesMessage.java → src/engine/net/client/msg/ViewResourcesMsg.java

@ -18,7 +18,7 @@ import engine.net.client.Protocol; @@ -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 { @@ -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 { @@ -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);
}

4
src/engine/objects/City.java

@ -25,7 +25,7 @@ import engine.net.Dispatch; @@ -25,7 +25,7 @@ import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.TaxResourcesMsg;
import engine.net.client.msg.ViewResourcesMessage;
import engine.net.client.msg.ViewResourcesMsg;
import engine.powers.EffectsBase;
import engine.server.MBServerStatics;
import engine.server.world.WorldServer;
@ -1387,7 +1387,7 @@ public class City extends AbstractWorldObject { @@ -1387,7 +1387,7 @@ public class City extends AbstractWorldObject {
// Member variable assignment
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();

8
src/engine/objects/Warehouse.java

@ -118,7 +118,7 @@ public class Warehouse { @@ -118,7 +118,7 @@ public class Warehouse {
return;
}
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
ViewResourcesMsg vrm = new ViewResourcesMsg(player);
vrm.setGuild(player.getGuild());
vrm.setWarehouseBuilding(warehouseBuilding);
vrm.configure();
@ -164,7 +164,7 @@ public class Warehouse { @@ -164,7 +164,7 @@ public class Warehouse {
return;
}
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
ViewResourcesMsg vrm = new ViewResourcesMsg(player);
vrm.setGuild(player.getGuild());
vrm.setWarehouseBuilding(warehouseBuilding);
vrm.configure();
@ -205,7 +205,7 @@ public class Warehouse { @@ -205,7 +205,7 @@ public class Warehouse {
worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
if (worked) {
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
ViewResourcesMsg vrm = new ViewResourcesMsg(player);
vrm.setGuild(player.getGuild());
vrm.setWarehouseBuilding(warehouseBuilding);
vrm.configure();
@ -222,7 +222,7 @@ public class Warehouse { @@ -222,7 +222,7 @@ public class Warehouse {
worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
if (worked) {
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
ViewResourcesMsg vrm = new ViewResourcesMsg(player);
vrm.setGuild(player.getGuild());
vrm.setWarehouseBuilding(warehouseBuilding);
vrm.configure();

Loading…
Cancel
Save