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

53 lines
1.5 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-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
Petition petition = new Petition(msg, origin);
2023-08-14 12:48:05 -04:00
if (petition == null)
2023-08-13 18:06:45 -05:00
return false;
2023-08-13 18:06:45 -05:00
try {
2023-08-14 14:33:19 -04:00
petitionReceivedMsg.petition = 2;
DbManager.PetitionQueries.WRITE_PETITION_TO_TABLE(petition);
2023-08-14 14:33:19 -04:00
Dispatch dispatch = Dispatch.borrow(playerCharacter, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
2023-08-14 12:48:05 -04:00
} catch (Exception e) {
2023-08-13 18:06:45 -05:00
return false;
}
return true;
}
2023-08-13 13:45:07 -05:00
}