Files
Server/src/engine/net/client/handlers/PetitionReceivedMsgHandler.java
T

61 lines
1.8 KiB
Java
Raw Normal View History

2023-08-13 13:45:07 -05:00
package engine.net.client.handlers;
2023-08-14 14:33:19 -04:00
import engine.Enum;
2023-08-13 13:45:07 -05:00
import engine.exception.MsgSendException;
import engine.gameManager.DbManager;
2023-08-14 14:33:19 -04:00
import engine.net.Dispatch;
import engine.net.DispatchMessage;
2023-08-13 13:45:07 -05:00
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.PetitionReceivedMsg;
2023-08-13 18:06:45 -05:00
import engine.objects.Petition;
2023-08-14 14:33:19 -04:00
import engine.objects.PlayerCharacter;
2023-08-13 13:45:07 -05:00
public class PetitionReceivedMsgHandler extends AbstractClientMsgHandler {
2023-08-14 16:09:06 -04:00
public static final int PETITION_NEW = 1;
public static final int PETITION_CANCEL = 2;
public static final int PETITION_CLOSE = 4;
2023-08-13 15:45:11 -05:00
public PetitionReceivedMsgHandler() {
super(PetitionReceivedMsg.class);
2023-08-13 13:45:07 -05:00
}
@Override
protected boolean _handleNetMsg(ClientNetMsg msg, ClientConnection origin) throws MsgSendException {
2023-08-14 14:33:19 -04:00
2023-08-14 12:48:05 -04:00
if (msg == null)
2023-08-14 14:33:19 -04:00
return true;
PetitionReceivedMsg petitionReceivedMsg = (PetitionReceivedMsg) msg;
2023-08-13 18:06:45 -05:00
2023-08-14 12:48:05 -04:00
if (origin == null)
2023-08-14 14:33:19 -04:00
return true;
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
if (playerCharacter == null)
return true;
2023-08-13 18:06:45 -05:00
2023-08-16 15:04:52 -04:00
Petition petition = new Petition(petitionReceivedMsg, origin);
2023-08-14 12:48:05 -04:00
2023-08-14 14:34:26 -04:00
// Write petition to database
2023-08-14 16:09:06 -04:00
if (petitionReceivedMsg.petition == PETITION_NEW)
DbManager.PetitionQueries.WRITE_PETITION_TO_TABLE(petition);
2023-08-14 14:34:26 -04:00
// Close the petition window
2023-08-14 16:09:06 -04:00
if (petitionReceivedMsg.petition == PETITION_NEW)
petitionReceivedMsg.petition = PETITION_CLOSE;
2023-08-14 15:56:47 -04:00
2023-08-14 15:42:05 -04:00
petitionReceivedMsg.unknownByte01 = 0;
petitionReceivedMsg.unknown04 = 0;
Dispatch dispatch = Dispatch.borrow(playerCharacter, petitionReceivedMsg);
2023-08-14 14:33:19 -04:00
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
2023-08-13 18:06:45 -05:00
return true;
}
2023-08-13 13:45:07 -05:00
}