Feat: add "Raise" command
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.game.raise;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandHandler;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.OkResponse;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.ErrorResponse;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimal handler for RAISE: validates and acknowledges the command.
|
||||||
|
*/
|
||||||
|
public class PlayerRaiseHandler extends CommandHandler<PlayerRaiseRequest> {
|
||||||
|
|
||||||
|
public PlayerRaiseHandler(ResponseDispatcher responseDispatcher) {
|
||||||
|
super(responseDispatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(PlayerRaiseRequest request) {
|
||||||
|
int amount = request.getAmount();
|
||||||
|
|
||||||
|
if (amount < 0) {
|
||||||
|
responseDispatcher
|
||||||
|
.dispatch(new ErrorResponse(request.getContext(), "INVALID_AMOUNT", "Amount must be non-negative"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
responseDispatcher.dispatch(new OkResponse(request.getContext()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.game.raise;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.CommandParser;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.PrimitiveRequest;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor.RequestParameterAccessor;
|
||||||
|
|
||||||
|
/** Parser for the RAISE command. */
|
||||||
|
public class PlayerRaiseParser implements CommandParser<PlayerRaiseRequest> {
|
||||||
|
@Override
|
||||||
|
public PlayerRaiseRequest parse(PrimitiveRequest primitiveRequest) {
|
||||||
|
RequestParameterAccessor accessor = new RequestParameterAccessor(primitiveRequest.parameters());
|
||||||
|
|
||||||
|
int amount = accessor.require("AMOUNT", Integer::parseInt);
|
||||||
|
|
||||||
|
return new PlayerRaiseRequest(primitiveRequest.context(), amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.game.raise;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Request;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
|
||||||
|
|
||||||
|
/** Request for RAISE command. */
|
||||||
|
public class PlayerRaiseRequest extends Request {
|
||||||
|
private final int amount;
|
||||||
|
|
||||||
|
public PlayerRaiseRequest(RequestContext context, int amount) {
|
||||||
|
super(context);
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user