Skip to content

Commit

Permalink
Merge pull request #43 from DaoCasino/dpm-1002
Browse files Browse the repository at this point in the history
[DPM-1002] player ban mechanic
  • Loading branch information
alrxy authored Feb 3, 2021
2 parents 10498c3 + be2660c commit b2cea67
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
4 changes: 2 additions & 2 deletions contracts/casino/include/casino/casino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions contracts/platform/include/platform/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};


Expand Down
19 changes: 18 additions & 1 deletion contracts/platform/src/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ platform::platform(name receiver, name code, eosio::datastream<const char*> 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);
}
Expand Down Expand Up @@ -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
25 changes: 25 additions & 0 deletions tests/platform_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class platform_tester : public basic_tester {
vector<char> 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<char> 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);
Expand Down Expand Up @@ -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

0 comments on commit b2cea67

Please sign in to comment.