diff --git a/contracts/casino/include/casino/casino.hpp b/contracts/casino/include/casino/casino.hpp index ca520c9..1b93f6f 100644 --- a/contracts/casino/include/casino/casino.hpp +++ b/contracts/casino/include/casino/casino.hpp @@ -182,7 +182,7 @@ struct [[eosio::table("gameparams"), eosio::contract("casino")]] game_params_row }; using game_params_table = eosio::multi_index<"gameparams"_n, game_params_row>; - + class [[eosio::contract("casino")]] casino: public eosio::contract { public: using eosio::contract::contract; @@ -328,7 +328,7 @@ class [[eosio::contract("casino")]] casino: public eosio::contract { global_tokens_state gtokens; player_tokens_table player_tokens; game_params_table game_params; - + name get_owner() const { return gstate.owner; } diff --git a/contracts/platform/include/platform/platform.hpp b/contracts/platform/include/platform/platform.hpp index e05e862..c65d9dd 100644 --- a/contracts/platform/include/platform/platform.hpp +++ b/contracts/platform/include/platform/platform.hpp @@ -82,6 +82,14 @@ struct [[eosio::table("token"), eosio::contract("platform")]] token_row { using token_table = eosio::multi_index<"token"_n, token_row>; +struct [[eosio::table("banlist"), eosio::contract("platform")]] ban_list_row { + name player; + + uint64_t primary_key() const { return player.value; } +}; + +using ban_list_table = eosio::multi_index<"banlist"_n, ban_list_row>; + class [[eosio::contract("platform")]] platform: public eosio::contract { public: using eosio::contract::contract; @@ -137,12 +145,19 @@ class [[eosio::contract("platform")]] platform: public eosio::contract { [[eosio::action("deltoken")]] void del_token(std::string token_name); + [[eosio::action("banplayer")]] + void ban_player(name player); + + [[eosio::action("unbanplayer")]] + void unban_player(name player); + private: version_singleton version; global_singleton global; casino_table casinos; game_table games; token_table tokens; + ban_list_table ban_list; }; diff --git a/contracts/platform/src/platform.cpp b/contracts/platform/src/platform.cpp index 57fe84e..67ddd49 100644 --- a/contracts/platform/src/platform.cpp +++ b/contracts/platform/src/platform.cpp @@ -9,7 +9,8 @@ platform::platform(name receiver, name code, eosio::datastream ds): global(_self, _self.value), casinos(_self, _self.value), games(_self, _self.value), - tokens(_self, _self.value) + tokens(_self, _self.value), + ban_list(_self, _self.value) { version.set(version_row {CONTRACT_VERSION}, _self); } @@ -162,4 +163,20 @@ void platform::del_token(std::string token_name) { tokens.erase(tokens.require_find(get_token_pk(token_name), "del token: no token found")); } +void platform::ban_player(name player) { + require_auth(get_self()); + const auto it = ban_list.find(player.value); + eosio::check(it == ban_list.end(), "player is already banned"); + ban_list.emplace(get_self(), [&](auto& row) { + row.player = player; + }); +} + +void platform::unban_player(name player) { + require_auth(get_self()); + const auto it = ban_list.find(player.value); + eosio::check(it != ban_list.end(), "player is not banned"); + ban_list.erase(it); +} + } // namespace platform diff --git a/tests/platform_test.cpp b/tests/platform_test.cpp index 836bab8..958576c 100644 --- a/tests/platform_test.cpp +++ b/tests/platform_test.cpp @@ -47,6 +47,11 @@ class platform_tester : public basic_tester { vector data = get_row_by_account(platform_name, platform_name, N(token), pk); return data.empty() ? fc::variant() : abi_ser[platform_name].binary_to_variant("token_row", data, abi_serializer_max_time); } + + bool is_player_banned(const name player) { + vector data = get_row_by_account(platform_name, platform_name, N(banlist), player.value ); + return data.empty() ? false : true; + } }; const account_name platform_tester::platform_name = N(platform); @@ -503,5 +508,25 @@ BOOST_FIXTURE_TEST_CASE(add_del_token, platform_tester) try { } FC_LOG_AND_RETHROW() +BOOST_FIXTURE_TEST_CASE(ban_player_test, platform_tester) try { + const name player = N(player); + + BOOST_REQUIRE_EQUAL(false, is_player_banned(player)); + + BOOST_REQUIRE_EQUAL( + success(), + push_action(platform_name, N(banplayer), platform_name, mvo()("player", player)) + ); + + BOOST_REQUIRE_EQUAL(true, is_player_banned(player)); + + BOOST_REQUIRE_EQUAL( + success(), + push_action(platform_name, N(unbanplayer), platform_name, mvo()("player", player)) + ); + + BOOST_REQUIRE_EQUAL(false, is_player_banned(player)); +} FC_LOG_AND_RETHROW() + BOOST_AUTO_TEST_SUITE_END() } // namespace testing