Move game-related methods to GameManager.
This commit is contained in:
parent
d395c2496e
commit
5c59a10418
|
@ -6,8 +6,194 @@
|
|||
//
|
||||
#include "td/telegram/GameManager.h"
|
||||
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/InlineQueriesManager.h"
|
||||
#include "td/telegram/MessageId.h"
|
||||
#include "td/telegram/MessagesManager.h"
|
||||
#include "td/telegram/net/DcId.h"
|
||||
#include "td/telegram/net/NetActor.h"
|
||||
#include "td/telegram/net/NetQueryCreator.h"
|
||||
#include "td/telegram/SequenceDispatcher.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/UpdatesManager.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/Status.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class SetGameScoreActor final : public NetActorOnce {
|
||||
Promise<Unit> promise_;
|
||||
DialogId dialog_id_;
|
||||
|
||||
public:
|
||||
explicit SetGameScoreActor(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, MessageId message_id, bool edit_message,
|
||||
tl_object_ptr<telegram_api::InputUser> input_user, int32 score, bool force, uint64 sequence_dispatcher_id) {
|
||||
int32 flags = 0;
|
||||
if (edit_message) {
|
||||
flags |= telegram_api::messages_setGameScore::EDIT_MESSAGE_MASK;
|
||||
}
|
||||
if (force) {
|
||||
flags |= telegram_api::messages_setGameScore::FORCE_MASK;
|
||||
}
|
||||
|
||||
dialog_id_ = dialog_id;
|
||||
|
||||
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Edit);
|
||||
if (input_peer == nullptr) {
|
||||
on_error(0, Status::Error(400, "Can't access the chat"));
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK(input_user != nullptr);
|
||||
auto query = G()->net_query_creator().create(
|
||||
telegram_api::messages_setGameScore(flags, false /*ignored*/, false /*ignored*/, std::move(input_peer),
|
||||
message_id.get_server_message_id().get(), std::move(input_user), score));
|
||||
|
||||
LOG(INFO) << "Set game score to " << score;
|
||||
|
||||
query->debug("send to MultiSequenceDispatcher");
|
||||
send_closure(td->messages_manager_->sequence_dispatcher_, &MultiSequenceDispatcher::send_with_callback,
|
||||
std::move(query), actor_shared(this), sequence_dispatcher_id);
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_setGameScore>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for SetGameScore: " << to_string(ptr);
|
||||
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) final {
|
||||
LOG(INFO) << "Receive error for SetGameScore: " << status;
|
||||
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "SetGameScoreActor");
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class SetInlineGameScoreQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SetInlineGameScoreQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(tl_object_ptr<telegram_api::inputBotInlineMessageID> input_bot_inline_message_id, bool edit_message,
|
||||
tl_object_ptr<telegram_api::InputUser> input_user, int32 score, bool force) {
|
||||
CHECK(input_bot_inline_message_id != nullptr);
|
||||
CHECK(input_user != nullptr);
|
||||
|
||||
int32 flags = 0;
|
||||
if (edit_message) {
|
||||
flags |= telegram_api::messages_setInlineGameScore::EDIT_MESSAGE_MASK;
|
||||
}
|
||||
if (force) {
|
||||
flags |= telegram_api::messages_setInlineGameScore::FORCE_MASK;
|
||||
}
|
||||
|
||||
auto dc_id = DcId::internal(input_bot_inline_message_id->dc_id_);
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_setInlineGameScore(flags, false /*ignored*/, false /*ignored*/,
|
||||
std::move(input_bot_inline_message_id), std::move(input_user), score),
|
||||
dc_id));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_setInlineGameScore>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
LOG_IF(ERROR, !result_ptr.ok()) << "Receive false in result of setInlineGameScore";
|
||||
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) final {
|
||||
LOG(INFO) << "Receive error for SetInlineGameScoreQuery: " << status;
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetGameHighScoresQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> promise_;
|
||||
DialogId dialog_id_;
|
||||
|
||||
public:
|
||||
explicit GetGameHighScoresQuery(Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, MessageId message_id, tl_object_ptr<telegram_api::InputUser> input_user) {
|
||||
dialog_id_ = dialog_id;
|
||||
|
||||
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
CHECK(input_user != nullptr);
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getGameHighScores(
|
||||
std::move(input_peer), message_id.get_server_message_id().get(), std::move(input_user))));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_getGameHighScores>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
promise_.set_value(td->game_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) final {
|
||||
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGameHighScoresQuery");
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetInlineGameHighScoresQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> promise_;
|
||||
|
||||
public:
|
||||
explicit GetInlineGameHighScoresQuery(Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(tl_object_ptr<telegram_api::inputBotInlineMessageID> input_bot_inline_message_id,
|
||||
tl_object_ptr<telegram_api::InputUser> input_user) {
|
||||
CHECK(input_bot_inline_message_id != nullptr);
|
||||
CHECK(input_user != nullptr);
|
||||
|
||||
auto dc_id = DcId::internal(input_bot_inline_message_id->dc_id_);
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_getInlineGameHighScores(std::move(input_bot_inline_message_id), std::move(input_user)),
|
||||
dc_id));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_getInlineGameHighScores>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
promise_.set_value(td->game_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
GameManager::GameManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||
}
|
||||
|
||||
|
@ -17,4 +203,111 @@ void GameManager::tear_down() {
|
|||
parent_.reset();
|
||||
}
|
||||
|
||||
void GameManager::set_game_score(FullMessageId full_message_id, bool edit_message, UserId user_id, int32 score,
|
||||
bool force, Promise<Unit> &&promise) {
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
|
||||
if (!td_->messages_manager_->have_message_force(full_message_id, "set_game_score")) {
|
||||
return promise.set_error(Status::Error(5, "Message not found"));
|
||||
}
|
||||
|
||||
auto dialog_id = full_message_id.get_dialog_id();
|
||||
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Edit)) {
|
||||
return promise.set_error(Status::Error(5, "Can't access the chat"));
|
||||
}
|
||||
|
||||
auto input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
if (input_user == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Invalid user identifier specified"));
|
||||
}
|
||||
|
||||
if (!td_->messages_manager_->can_set_game_score(full_message_id)) {
|
||||
return promise.set_error(Status::Error(5, "Game score can't be set"));
|
||||
}
|
||||
|
||||
send_closure(td_->create_net_actor<SetGameScoreActor>(std::move(promise)), &SetGameScoreActor::send, dialog_id,
|
||||
full_message_id.get_message_id(), edit_message, std::move(input_user), score, force,
|
||||
MessagesManager::get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
|
||||
}
|
||||
|
||||
void GameManager::set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score,
|
||||
bool force, Promise<Unit> &&promise) {
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
|
||||
auto input_bot_inline_message_id = td_->inline_queries_manager_->get_input_bot_inline_message_id(inline_message_id);
|
||||
if (input_bot_inline_message_id == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
|
||||
}
|
||||
|
||||
auto input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
if (input_user == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Wrong user identifier specified"));
|
||||
}
|
||||
|
||||
td_->create_handler<SetInlineGameScoreQuery>(std::move(promise))
|
||||
->send(std::move(input_bot_inline_message_id), edit_message, std::move(input_user), score, force);
|
||||
}
|
||||
|
||||
void GameManager::get_game_high_scores(FullMessageId full_message_id, UserId user_id,
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise) {
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
|
||||
if (!td_->messages_manager_->have_message_force(full_message_id, "get_game_high_scores")) {
|
||||
return promise.set_error(Status::Error(5, "Message not found"));
|
||||
}
|
||||
|
||||
auto dialog_id = full_message_id.get_dialog_id();
|
||||
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
|
||||
return promise.set_error(Status::Error(5, "Can't access the chat"));
|
||||
}
|
||||
auto message_id = full_message_id.get_message_id();
|
||||
if (message_id.is_scheduled() || !message_id.is_server()) {
|
||||
return promise.set_error(Status::Error(5, "Wrong message identifier specified"));
|
||||
}
|
||||
|
||||
auto input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
if (input_user == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Wrong user identifier specified"));
|
||||
}
|
||||
|
||||
td_->create_handler<GetGameHighScoresQuery>(std::move(promise))->send(dialog_id, message_id, std::move(input_user));
|
||||
}
|
||||
|
||||
void GameManager::get_inline_game_high_scores(const string &inline_message_id, UserId user_id,
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise) {
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
|
||||
auto input_bot_inline_message_id = td_->inline_queries_manager_->get_input_bot_inline_message_id(inline_message_id);
|
||||
if (input_bot_inline_message_id == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
|
||||
}
|
||||
|
||||
auto input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
if (input_user == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Wrong user identifier specified"));
|
||||
}
|
||||
|
||||
td_->create_handler<GetInlineGameHighScoresQuery>(std::move(promise))
|
||||
->send(std::move(input_bot_inline_message_id), std::move(input_user));
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::gameHighScores> GameManager::get_game_high_scores_object(
|
||||
telegram_api::object_ptr<telegram_api::messages_highScores> &&high_scores) {
|
||||
td_->contacts_manager_->on_get_users(std::move(high_scores->users_), "get_game_high_scores_object");
|
||||
|
||||
auto result = td_api::make_object<td_api::gameHighScores>();
|
||||
for (const auto &high_score : high_scores->scores_) {
|
||||
int32 position = high_score->pos_;
|
||||
UserId user_id(high_score->user_id_);
|
||||
int32 score = high_score->score_;
|
||||
if (position <= 0 || !user_id.is_valid() || score < 0) {
|
||||
LOG(ERROR) << "Receive wrong " << to_string(high_score);
|
||||
continue;
|
||||
}
|
||||
result->scores_.push_back(make_tl_object<td_api::gameHighScore>(
|
||||
position, td_->contacts_manager_->get_user_id_object(user_id, "get_game_high_scores_object"), score));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
|
|
@ -6,7 +6,15 @@
|
|||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/FullMessageId.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/UserId.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
|
@ -21,6 +29,21 @@ class GameManager final : public Actor {
|
|||
GameManager &operator=(GameManager &&) = delete;
|
||||
~GameManager() final;
|
||||
|
||||
void set_game_score(FullMessageId full_message_id, bool edit_message, UserId user_id, int32 score, bool force,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score,
|
||||
bool force, Promise<Unit> &&promise);
|
||||
|
||||
void get_game_high_scores(FullMessageId full_message_id, UserId user_id,
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise);
|
||||
|
||||
void get_inline_game_high_scores(const string &inline_message_id, UserId user_id,
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise);
|
||||
|
||||
td_api::object_ptr<td_api::gameHighScores> get_game_high_scores_object(
|
||||
telegram_api::object_ptr<telegram_api::messages_highScores> &&high_scores);
|
||||
|
||||
private:
|
||||
void tear_down() final;
|
||||
|
||||
|
|
|
@ -3532,176 +3532,6 @@ class EditInlineMessageQuery final : public Td::ResultHandler {
|
|||
}
|
||||
};
|
||||
|
||||
class SetGameScoreActor final : public NetActorOnce {
|
||||
Promise<Unit> promise_;
|
||||
DialogId dialog_id_;
|
||||
|
||||
public:
|
||||
explicit SetGameScoreActor(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, MessageId message_id, bool edit_message,
|
||||
tl_object_ptr<telegram_api::InputUser> input_user, int32 score, bool force, uint64 sequence_dispatcher_id) {
|
||||
int32 flags = 0;
|
||||
if (edit_message) {
|
||||
flags |= telegram_api::messages_setGameScore::EDIT_MESSAGE_MASK;
|
||||
}
|
||||
if (force) {
|
||||
flags |= telegram_api::messages_setGameScore::FORCE_MASK;
|
||||
}
|
||||
|
||||
dialog_id_ = dialog_id;
|
||||
|
||||
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Edit);
|
||||
if (input_peer == nullptr) {
|
||||
on_error(0, Status::Error(400, "Can't access the chat"));
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK(input_user != nullptr);
|
||||
auto query = G()->net_query_creator().create(
|
||||
telegram_api::messages_setGameScore(flags, false /*ignored*/, false /*ignored*/, std::move(input_peer),
|
||||
message_id.get_server_message_id().get(), std::move(input_user), score));
|
||||
|
||||
LOG(INFO) << "Set game score to " << score;
|
||||
|
||||
query->debug("send to MessagesManager::MultiSequenceDispatcher");
|
||||
send_closure(td->messages_manager_->sequence_dispatcher_, &MultiSequenceDispatcher::send_with_callback,
|
||||
std::move(query), actor_shared(this), sequence_dispatcher_id);
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_setGameScore>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for SetGameScore: " << to_string(ptr);
|
||||
td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) final {
|
||||
LOG(INFO) << "Receive error for SetGameScore: " << status;
|
||||
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "SetGameScoreActor");
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class SetInlineGameScoreQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SetInlineGameScoreQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(tl_object_ptr<telegram_api::inputBotInlineMessageID> input_bot_inline_message_id, bool edit_message,
|
||||
tl_object_ptr<telegram_api::InputUser> input_user, int32 score, bool force) {
|
||||
CHECK(input_bot_inline_message_id != nullptr);
|
||||
CHECK(input_user != nullptr);
|
||||
|
||||
int32 flags = 0;
|
||||
if (edit_message) {
|
||||
flags |= telegram_api::messages_setInlineGameScore::EDIT_MESSAGE_MASK;
|
||||
}
|
||||
if (force) {
|
||||
flags |= telegram_api::messages_setInlineGameScore::FORCE_MASK;
|
||||
}
|
||||
|
||||
LOG(INFO) << "Set inline game score to " << score;
|
||||
auto dc_id = DcId::internal(input_bot_inline_message_id->dc_id_);
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_setInlineGameScore(flags, false /*ignored*/, false /*ignored*/,
|
||||
std::move(input_bot_inline_message_id), std::move(input_user), score),
|
||||
dc_id));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_setInlineGameScore>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
LOG_IF(ERROR, !result_ptr.ok()) << "Receive false in result of setInlineGameScore";
|
||||
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) final {
|
||||
LOG(INFO) << "Receive error for SetInlineGameScoreQuery: " << status;
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetGameHighScoresQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> promise_;
|
||||
DialogId dialog_id_;
|
||||
|
||||
public:
|
||||
explicit GetGameHighScoresQuery(Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, MessageId message_id, tl_object_ptr<telegram_api::InputUser> input_user) {
|
||||
dialog_id_ = dialog_id;
|
||||
|
||||
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
CHECK(input_user != nullptr);
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_getGameHighScores(
|
||||
std::move(input_peer), message_id.get_server_message_id().get(), std::move(input_user))));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_getGameHighScores>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
promise_.set_value(td->messages_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) final {
|
||||
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGameHighScoresQuery");
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class GetInlineGameHighScoresQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> promise_;
|
||||
|
||||
public:
|
||||
explicit GetInlineGameHighScoresQuery(Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(tl_object_ptr<telegram_api::inputBotInlineMessageID> input_bot_inline_message_id,
|
||||
tl_object_ptr<telegram_api::InputUser> input_user) {
|
||||
CHECK(input_bot_inline_message_id != nullptr);
|
||||
CHECK(input_user != nullptr);
|
||||
|
||||
auto dc_id = DcId::internal(input_bot_inline_message_id->dc_id_);
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_getInlineGameHighScores(std::move(input_bot_inline_message_id), std::move(input_user)),
|
||||
dc_id));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_getInlineGameHighScores>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
promise_.set_value(td->messages_manager_->get_game_high_scores_object(result_ptr.move_as_ok()));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ForwardMessagesActor final : public NetActorOnce {
|
||||
Promise<Unit> promise_;
|
||||
vector<int64> random_ids_;
|
||||
|
@ -25793,10 +25623,17 @@ int32 MessagesManager::get_message_flags(const Message *m) {
|
|||
return flags;
|
||||
}
|
||||
|
||||
bool MessagesManager::can_set_game_score(FullMessageId full_message_id) const {
|
||||
return can_set_game_score(full_message_id.get_dialog_id(), get_message(full_message_id));
|
||||
}
|
||||
|
||||
bool MessagesManager::can_set_game_score(DialogId dialog_id, const Message *m) const {
|
||||
if (m == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (m->content->get_type() != MessageContentType::Game) {
|
||||
return false;
|
||||
}
|
||||
if (m->message_id.is_scheduled()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -25855,131 +25692,7 @@ bool MessagesManager::can_set_game_score(DialogId dialog_id, const Message *m) c
|
|||
return false;
|
||||
}
|
||||
|
||||
return m->content->get_type() == MessageContentType::Game;
|
||||
}
|
||||
|
||||
void MessagesManager::set_game_score(FullMessageId full_message_id, bool edit_message, UserId user_id, int32 score,
|
||||
bool force, Promise<Unit> &&promise) {
|
||||
if (!td_->auth_manager_->is_bot()) {
|
||||
return promise.set_error(Status::Error(3, "Method is available only for bots"));
|
||||
}
|
||||
|
||||
LOG(INFO) << "Begin to set game score of " << user_id << " in " << full_message_id;
|
||||
auto dialog_id = full_message_id.get_dialog_id();
|
||||
Dialog *d = get_dialog_force(dialog_id, "set_game_score");
|
||||
if (d == nullptr) {
|
||||
return promise.set_error(Status::Error(5, "Chat not found"));
|
||||
}
|
||||
|
||||
if (!have_input_peer(dialog_id, AccessRights::Edit)) {
|
||||
return promise.set_error(Status::Error(5, "Can't access the chat"));
|
||||
}
|
||||
|
||||
const Message *m = get_message_force(d, full_message_id.get_message_id(), "set_game_score");
|
||||
if (m == nullptr) {
|
||||
return promise.set_error(Status::Error(5, "Message not found"));
|
||||
}
|
||||
|
||||
auto input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
if (input_user == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Invalid user identifier specified"));
|
||||
}
|
||||
|
||||
if (!can_set_game_score(dialog_id, m)) {
|
||||
return promise.set_error(Status::Error(5, "Game score can't be set"));
|
||||
}
|
||||
|
||||
send_closure(td_->create_net_actor<SetGameScoreActor>(std::move(promise)), &SetGameScoreActor::send, dialog_id,
|
||||
m->message_id, edit_message, std::move(input_user), score, force,
|
||||
get_sequence_dispatcher_id(dialog_id, MessageContentType::None));
|
||||
}
|
||||
|
||||
void MessagesManager::set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id,
|
||||
int32 score, bool force, Promise<Unit> &&promise) {
|
||||
if (!td_->auth_manager_->is_bot()) {
|
||||
return promise.set_error(Status::Error(3, "Method is available only for bots"));
|
||||
}
|
||||
|
||||
auto input_bot_inline_message_id = td_->inline_queries_manager_->get_input_bot_inline_message_id(inline_message_id);
|
||||
if (input_bot_inline_message_id == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
|
||||
}
|
||||
|
||||
auto input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
if (input_user == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Wrong user identifier specified"));
|
||||
}
|
||||
|
||||
td_->create_handler<SetInlineGameScoreQuery>(std::move(promise))
|
||||
->send(std::move(input_bot_inline_message_id), edit_message, std::move(input_user), score, force);
|
||||
}
|
||||
|
||||
void MessagesManager::get_game_high_scores(FullMessageId full_message_id, UserId user_id,
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise) {
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
|
||||
auto dialog_id = full_message_id.get_dialog_id();
|
||||
Dialog *d = get_dialog_force(dialog_id, "get_game_high_scores");
|
||||
if (d == nullptr) {
|
||||
return promise.set_error(Status::Error(5, "Chat not found"));
|
||||
}
|
||||
|
||||
if (!have_input_peer(dialog_id, AccessRights::Read)) {
|
||||
return promise.set_error(Status::Error(5, "Can't access the chat"));
|
||||
}
|
||||
|
||||
const Message *m = get_message_force(d, full_message_id.get_message_id(), "get_game_high_scores");
|
||||
if (m == nullptr) {
|
||||
return promise.set_error(Status::Error(5, "Message not found"));
|
||||
}
|
||||
if (m->message_id.is_scheduled() || !m->message_id.is_server()) {
|
||||
return promise.set_error(Status::Error(5, "Wrong message identifier specified"));
|
||||
}
|
||||
|
||||
auto input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
if (input_user == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Wrong user identifier specified"));
|
||||
}
|
||||
|
||||
td_->create_handler<GetGameHighScoresQuery>(std::move(promise))
|
||||
->send(dialog_id, m->message_id, std::move(input_user));
|
||||
}
|
||||
|
||||
void MessagesManager::get_inline_game_high_scores(const string &inline_message_id, UserId user_id,
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise) {
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
|
||||
auto input_bot_inline_message_id = td_->inline_queries_manager_->get_input_bot_inline_message_id(inline_message_id);
|
||||
if (input_bot_inline_message_id == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Invalid inline message identifier specified"));
|
||||
}
|
||||
|
||||
auto input_user = td_->contacts_manager_->get_input_user(user_id);
|
||||
if (input_user == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Wrong user identifier specified"));
|
||||
}
|
||||
|
||||
td_->create_handler<GetInlineGameHighScoresQuery>(std::move(promise))
|
||||
->send(std::move(input_bot_inline_message_id), std::move(input_user));
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::gameHighScores> MessagesManager::get_game_high_scores_object(
|
||||
telegram_api::object_ptr<telegram_api::messages_highScores> &&high_scores) {
|
||||
td_->contacts_manager_->on_get_users(std::move(high_scores->users_), "get_game_high_scores_object");
|
||||
|
||||
auto result = td_api::make_object<td_api::gameHighScores>();
|
||||
for (const auto &high_score : high_scores->scores_) {
|
||||
int32 position = high_score->pos_;
|
||||
UserId user_id(high_score->user_id_);
|
||||
int32 score = high_score->score_;
|
||||
if (position <= 0 || !user_id.is_valid() || score < 0) {
|
||||
LOG(ERROR) << "Receive wrong " << to_string(high_score);
|
||||
continue;
|
||||
}
|
||||
result->scores_.push_back(make_tl_object<td_api::gameHighScore>(
|
||||
position, td_->contacts_manager_->get_user_id_object(user_id, "get_game_high_scores_object"), score));
|
||||
}
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MessagesManager::is_forward_info_sender_hidden(const MessageForwardInfo *forward_info) {
|
||||
|
|
|
@ -461,21 +461,6 @@ class MessagesManager final : public Actor {
|
|||
td_api::object_ptr<td_api::MessageSchedulingState> &&scheduling_state,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void set_game_score(FullMessageId full_message_id, bool edit_message, UserId user_id, int32 score, bool force,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void set_inline_game_score(const string &inline_message_id, bool edit_message, UserId user_id, int32 score,
|
||||
bool force, Promise<Unit> &&promise);
|
||||
|
||||
void get_game_high_scores(FullMessageId full_message_id, UserId user_id,
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise);
|
||||
|
||||
void get_inline_game_high_scores(const string &inline_message_id, UserId user_id,
|
||||
Promise<td_api::object_ptr<td_api::gameHighScores>> &&promise);
|
||||
|
||||
td_api::object_ptr<td_api::gameHighScores> get_game_high_scores_object(
|
||||
telegram_api::object_ptr<telegram_api::messages_highScores> &&high_scores);
|
||||
|
||||
void send_dialog_action(DialogId dialog_id, MessageId top_thread_message_id, DialogAction action,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
|
@ -912,10 +897,14 @@ class MessagesManager final : public Actor {
|
|||
|
||||
Result<ServerMessageId> get_payment_successful_message_id(FullMessageId full_message_id);
|
||||
|
||||
bool can_set_game_score(FullMessageId full_message_id) const;
|
||||
|
||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||
|
||||
ActorOwn<MultiSequenceDispatcher> sequence_dispatcher_;
|
||||
|
||||
static uint64 get_sequence_dispatcher_id(DialogId dialog_id, MessageContentType message_content_type);
|
||||
|
||||
private:
|
||||
class PendingPtsUpdate {
|
||||
public:
|
||||
|
@ -2958,8 +2947,6 @@ class MessagesManager final : public Actor {
|
|||
|
||||
void set_sponsored_dialog(DialogId dialog_id, DialogSource source);
|
||||
|
||||
static uint64 get_sequence_dispatcher_id(DialogId dialog_id, MessageContentType message_content_type);
|
||||
|
||||
Dialog *get_service_notifications_dialog();
|
||||
|
||||
void save_auth_notification_ids();
|
||||
|
|
|
@ -1273,8 +1273,7 @@ class SetGameScoreRequest final : public RequestOnceActor {
|
|||
bool force_;
|
||||
|
||||
void do_run(Promise<Unit> &&promise) final {
|
||||
td->messages_manager_->set_game_score(full_message_id_, edit_message_, user_id_, score_, force_,
|
||||
std::move(promise));
|
||||
td->game_manager_->set_game_score(full_message_id_, edit_message_, user_id_, score_, force_, std::move(promise));
|
||||
}
|
||||
|
||||
void do_send_result() final {
|
||||
|
@ -5726,24 +5725,22 @@ void Td::on_request(uint64 id, td_api::setInlineGameScore &request) {
|
|||
CHECK_IS_BOT();
|
||||
CLEAN_INPUT_STRING(request.inline_message_id_);
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
messages_manager_->set_inline_game_score(std::move(request.inline_message_id_), request.edit_message_,
|
||||
UserId(request.user_id_), request.score_, request.force_,
|
||||
std::move(promise));
|
||||
game_manager_->set_inline_game_score(std::move(request.inline_message_id_), request.edit_message_,
|
||||
UserId(request.user_id_), request.score_, request.force_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getGameHighScores &request) {
|
||||
CHECK_IS_BOT();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
messages_manager_->get_game_high_scores({DialogId(request.chat_id_), MessageId(request.message_id_)},
|
||||
UserId(request.user_id_), std::move(promise));
|
||||
game_manager_->get_game_high_scores({DialogId(request.chat_id_), MessageId(request.message_id_)},
|
||||
UserId(request.user_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getInlineGameHighScores &request) {
|
||||
CHECK_IS_BOT();
|
||||
CLEAN_INPUT_STRING(request.inline_message_id_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
messages_manager_->get_inline_game_high_scores(request.inline_message_id_, UserId(request.user_id_),
|
||||
std::move(promise));
|
||||
game_manager_->get_inline_game_high_scores(request.inline_message_id_, UserId(request.user_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::deleteChatReplyMarkup &request) {
|
||||
|
|
Loading…
Reference in New Issue