From ee12e48a861fa0aaacbac17436d6f7815cd1cd9c Mon Sep 17 00:00:00 2001 From: Jorens Shtekels Date: Sun, 10 Mar 2024 20:15:55 +0200 Subject: [PATCH] feat[lib]: validate action partial implementation Performed most checks. Added placeholders to functions called. --- src/lib.cpp | 48 ++++++++++++++++++++++++++++++++++++++++-------- src/lib.hh | 6 ++++-- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/lib.cpp b/src/lib.cpp index 3ab6cb5..128417f 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -1,7 +1,18 @@ +#include "lib.hh" + #include "prep/prep.hh" #include +enum VALIDATION_STATUS { + NO_PLAYER, + ROOM_NOT_IN_PROGRESS, + ACTION_PROHIBITED, + ACTION_NOT_ALLOWED, + NO_ROLE, + ACTION_VALID, +}; + void run() { Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS); Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED); @@ -10,19 +21,40 @@ void run() { Role role2(actions); } -enum VALIDATION_STATUS { - NO_PLAYER, - ROOM_NOT_IN_PROGRESS, - ACTION_PROHIBITED, - ACTION_NOT_ALLOWED, - ACTION_VALID, -}; - int validateAction( Player *actor, Action *action, Room *room, std::vector *relatedEvents, Player *target = nullptr) { + if (!actor) { + return NO_PLAYER; + } + // TODO: Check if action has a target + if (room->status != RoomStatus::IN_PROGRESS) { + return ROOM_NOT_IN_PROGRESS; + } + Role *role = &actor->role; + if (!role) { + return NO_ROLE; + } + if (!actionBelongsToRole(role, action)) { + return ACTION_NOT_ALLOWED; + } + if (!isActionAllowed(relatedEvents)) { + return ACTION_PROHIBITED; + } return ACTION_VALID; } +bool actionBelongsToRole(Role *role, Action *action) { + // TODO: implement + bool belongs = false; + return belongs; +} + +bool isActionAllowed(std::vector *relevantEvents) { + // TODO: implement + bool allowed = false; + return allowed; +} + int functionToTest(int a) { return a * 2; } diff --git a/src/lib.hh b/src/lib.hh index fc6a08b..440093d 100644 --- a/src/lib.hh +++ b/src/lib.hh @@ -1,6 +1,8 @@ #include "prep/prep.hh" void run(); -int validateAction( - Player *actor, Action *action, Room *room, std::vector *relatedEvents, Player *target = nullptr); + +bool actionBelongsToRole(Role *role, Action *action); +bool isActionAllowed(std::vector *relevantEvents); +int validateAction(Player *actor, Action *action, Room *room, std::vector *relatedEvents, Player *target); int functionToTest(int);