From 95a594c5f43c13972abcaaed9f1be5a04033fd28 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 27 Sep 2020 20:29:36 +0800 Subject: [PATCH] 1 --- server/imserver/dbhelper.cc | 37 +++++++++++++++++++++++++++++++++++++ server/imserver/dbhelper.h | 1 + server/imserver/player.cc | 3 +-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/server/imserver/dbhelper.cc b/server/imserver/dbhelper.cc index d167c84..cb1945d 100644 --- a/server/imserver/dbhelper.cc +++ b/server/imserver/dbhelper.cc @@ -117,6 +117,43 @@ void DBHelper::SetGuildApplyStatus( ); } +void DBHelper::ConfirmGuild(Player* hum, long long guild_id) +{ + auto on_ok = + [] (a8::XParams& param, const f8::DataSet* data_set) + { + Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(param.sender.GetString()); + if (hum) { + hum->UpdateGuildData(param.param1, kGuildOwner); + hum->SaveToDB(a8::XParams(), nullptr, nullptr); + } + }; + auto on_error = + [] (a8::XParams& param, int error_code, const std::string& error_msg) + { + + }; + + a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(guild_id); + DBEngine::Instance()->ExecAsyncScript + ( + conn_info, + "UPDATE `guild` SET status=%d, guild_data='%s', modifytime=%d WHERE guild_id=%d;", + { + kGuildCreated, + "", + App::Instance()->nowtime, + guild_id + }, + a8::XParams() + .SetSender(hum->AccountId()) + .SetParam1(guild_id), + on_ok, + on_error, + guild_id + ); +} + void DBHelper::AddFriendApply(Player* hum, const std::string& target_id) { auto on_ok = diff --git a/server/imserver/dbhelper.h b/server/imserver/dbhelper.h index 2647e7a..8396783 100644 --- a/server/imserver/dbhelper.h +++ b/server/imserver/dbhelper.h @@ -37,6 +37,7 @@ class DBHelper : public a8::Singleton const std::string& sender_id, long long guild_id, int status); + void ConfirmGuild(Player* hum, long long guild_id); void AddFriendApply(Player* hum, const std::string& target_id); void AddGuildApply(Guild* guild, const cs::MFUserInfo& user_info); void AddEvent(const std::string& sender_id, diff --git a/server/imserver/player.cc b/server/imserver/player.cc index 5f8f0ed..e72ddf6 100644 --- a/server/imserver/player.cc +++ b/server/imserver/player.cc @@ -676,8 +676,7 @@ void Player::_CMGuildCreate(f8::MsgHdr& hdr, const cs::CMGuildCreate& msg) respmsg.set_errcode(data.At("errcode")->AsXValue()); respmsg.set_errmsg(data.At("errmsg")->AsXValue()); if (data.At("errcode") == 0) { - hum->UpdateGuildData(msg_context->guild_id, kGuildOwner); - hum->SaveToDB(a8::XParams(), nullptr, nullptr); + DBHelper::Instance()->ConfirmGuild(hum, msg_context->guild_id); } else { hum->ShowErrorMsg(data.At("errmsg")->AsXValue().GetString()); }