2385 lines
76 KiB
C++
2385 lines
76 KiB
C++
#include "precompile.h"
|
|
|
|
#include <math.h>
|
|
|
|
#include <a8/openssl.h>
|
|
#include <a8/timer.h>
|
|
#include <a8/mutable_xobject.h>
|
|
|
|
#include "player.h"
|
|
#include "playermgr.h"
|
|
#include "dbengine.h"
|
|
#include "MSConnMgr.h"
|
|
#include "dbengine.h"
|
|
#include "dbhelper.h"
|
|
#include "synchelper.h"
|
|
#include "app.h"
|
|
#include "typeconvert.h"
|
|
#include "playermgr.h"
|
|
#include "gamelog.h"
|
|
#include "asynctaskmgr.h"
|
|
|
|
#include "IMConn.h"
|
|
#include "IMConnMgr.h"
|
|
#include "IMListener.h"
|
|
#include "MSConn.h"
|
|
#include "MSConnMgr.h"
|
|
#include "handlermgr.h"
|
|
#include "jsondatamgr.h"
|
|
#include "chatmgr.h"
|
|
#include "metamgr.h"
|
|
|
|
#include "ss_msgid.pb.h"
|
|
#include "framework/cpp/httpclientpool.h"
|
|
|
|
static const int MAX_DAILY_APPPLY_GUILD_TIMES = 100;
|
|
static const int MAX_DAILY_CREATE_GUILD_TIMES = 20;
|
|
|
|
void Player::Init()
|
|
{
|
|
myself.hum = this;
|
|
myself.crc32_code = a8::openssl::Crc32
|
|
(
|
|
(unsigned char*)myself.base_data.account_id.data(),
|
|
myself.base_data.account_id.size()
|
|
);
|
|
user_sign_ = a8::openssl::md5(AccountId());
|
|
a8::Timer::Instance()->AddRepeatTimerAndAttach
|
|
(
|
|
1000 * 3 + (rand() % 3000),
|
|
a8::XParams()
|
|
.SetSender(this),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->ProcessEventTimerFunc();
|
|
},
|
|
&timer_attacher.timer_list_
|
|
);
|
|
if (App::Instance()->IsTimeToReset(role_data.last_save_time)) {
|
|
OnDailyReset();
|
|
}
|
|
RecalcRedPoint();
|
|
RefreshFriendData();
|
|
NotifyOnline();
|
|
#if 1
|
|
if (DBHelper::Instance()->shua_users_offline_times <= 1) {
|
|
DBHelper::Instance()->ShuaOfflineUsers(this);
|
|
}
|
|
#endif
|
|
SyncGuildMemberInfo();
|
|
a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
|
(
|
|
1000 * 2 + (rand() % 3000),
|
|
a8::XParams()
|
|
.SetSender(this),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->SyncGuildMemberInfo();
|
|
hum->SyncGuildRedPoint();
|
|
},
|
|
&timer_attacher.timer_list_
|
|
);
|
|
a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
|
(
|
|
1000 * 2 + (rand() % 3000),
|
|
a8::XParams()
|
|
.SetSender(this),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
cs::SMUpdateChatRedPointNotify msg;
|
|
ChatMgr::Instance()->FillSMUpdateChatRedPointNotify(hum, msg);
|
|
hum->SendMsg(msg);
|
|
},
|
|
&timer_attacher.timer_list_
|
|
);
|
|
ChatMgr::Instance()->OnPlayerOnline(this);
|
|
}
|
|
|
|
void Player::UnInit()
|
|
{
|
|
ChatMgr::Instance()->OnPlayerOffline(this);
|
|
SaveToDB(a8::XParams(), nullptr, nullptr);
|
|
timer_attacher.ClearTimerList();
|
|
for (auto& pair : friend_hash_) {
|
|
if (!list_empty(&pair.second->watch_node)) {
|
|
PlayerMgr::Instance()->UnWatchPlayer(pair.second);
|
|
delete pair.second;
|
|
}
|
|
}
|
|
for (auto& pair : apply_hash_) {
|
|
delete pair.second;
|
|
}
|
|
friend_hash_.clear();
|
|
}
|
|
|
|
void Player::Deserialize(const ss::MFUserDB& user_db)
|
|
{
|
|
for (auto& friend_db : user_db.friends()) {
|
|
Friend* friendobj = new Friend;
|
|
TypeConvert::Convert(friend_db.base_data(), friendobj->base_data);
|
|
AddFriend(friendobj);
|
|
}
|
|
for (auto& friend_db : user_db.black_list()) {
|
|
Friend* friendobj = new Friend;
|
|
TypeConvert::Convert(friend_db.base_data(), friendobj->base_data);
|
|
AddBlackList(friendobj);
|
|
}
|
|
role_data.today_apply_times = user_db.role_data().today_apply_times();
|
|
role_data.today_apply_guild_times = user_db.role_data().today_apply_guild_times();
|
|
role_data.today_create_guild_times = user_db.role_data().today_create_guild_times();
|
|
role_data.save_count = user_db.role_data().save_count();
|
|
role_data.last_save_time = user_db.role_data().last_save_time();
|
|
for (auto& pair : user_db.role_data().applyed_guild_list()) {
|
|
if (a8::BetweenDays(App::Instance()->nowtime, pair.val()) < 10) {
|
|
applyed_guild_hash_[pair.key()] = pair.val();
|
|
}
|
|
}
|
|
if (GuildId() != 0) {
|
|
applyed_guild_hash_.clear();
|
|
}
|
|
db_private_chat_last_id_ = user_db.private_chat_last_id();
|
|
if (db_private_chat_last_id_ <= 10000) {
|
|
db_private_chat_last_id_ = 10000;
|
|
}
|
|
}
|
|
|
|
void Player::Serialize(ss::MFUserDB& user_db)
|
|
{
|
|
for (auto& pair : friend_hash_) {
|
|
auto p = user_db.add_friends();
|
|
TypeConvert::Convert(pair.second->base_data, *(p->mutable_base_data()));
|
|
}
|
|
for (auto& pair : black_hash_) {
|
|
auto p = user_db.add_black_list();
|
|
TypeConvert::Convert(pair.second->base_data, *(p->mutable_base_data()));
|
|
}
|
|
user_db.mutable_role_data()->set_today_apply_times(role_data.today_apply_times);
|
|
user_db.mutable_role_data()->set_today_apply_guild_times(role_data.today_apply_guild_times);
|
|
user_db.mutable_role_data()->set_today_create_guild_times(role_data.today_create_guild_times);
|
|
user_db.mutable_role_data()->set_save_count(role_data.save_count);
|
|
user_db.mutable_role_data()->set_last_save_time(role_data.last_save_time);
|
|
for (auto& pair : applyed_guild_hash_) {
|
|
auto p = user_db.mutable_role_data()->add_applyed_guild_list();
|
|
p->set_key(pair.first);
|
|
p->set_val(pair.second);
|
|
}
|
|
if (GuildId() != 0) {
|
|
applyed_guild_hash_.clear();
|
|
}
|
|
user_db.set_private_chat_last_id(db_private_chat_last_id_);
|
|
}
|
|
|
|
void Player::_CMPing(f8::MsgHdr& hdr, const cs::CMPing& msg)
|
|
{
|
|
cs::SMPing respmsg;
|
|
SendMsg(respmsg);
|
|
}
|
|
|
|
void Player::_CMUpdateUserInfo(f8::MsgHdr& hdr, const cs::CMUpdateUserInfo& msg)
|
|
{
|
|
if (msg.has_nickname()) {
|
|
myself.base_data.nickname = msg.nickname();
|
|
}
|
|
if (msg.has_avatar_url()) {
|
|
myself.base_data.avatar_url = msg.avatar_url();
|
|
}
|
|
if (msg.has_sex()) {
|
|
myself.base_data.sex = msg.sex();
|
|
}
|
|
if (msg.has_vip_lv()) {
|
|
myself.base_data.vip_lv = msg.vip_lv();
|
|
}
|
|
if (msg.has_head()) {
|
|
myself.base_data.head = msg.head();
|
|
}
|
|
if (msg.contribute()) {
|
|
myself.base_data.contribute = msg.contribute();
|
|
}
|
|
if (msg.has_user_value1()) {
|
|
myself.base_data.user_value1 = msg.user_value1();
|
|
}
|
|
if (msg.has_user_value2()) {
|
|
myself.base_data.user_value2 = msg.user_value2();
|
|
}
|
|
if (msg.has_user_value3()) {
|
|
myself.base_data.user_value3 = msg.user_value3();
|
|
}
|
|
OnDataVersion1Change();
|
|
SyncGuildMemberInfo();
|
|
}
|
|
|
|
void Player::_CMUpdateTempCustomData(f8::MsgHdr& hdr, const cs::CMUpdateTempCustomData& msg)
|
|
{
|
|
if (msg.temp_custom_data().has_value1()) {
|
|
myself.temp_custom_data.value1 = msg.temp_custom_data().value1();
|
|
}
|
|
if (msg.temp_custom_data().has_value2()) {
|
|
myself.temp_custom_data.value2 = msg.temp_custom_data().value2();
|
|
}
|
|
if (msg.temp_custom_data().has_value3()) {
|
|
myself.temp_custom_data.value2 = msg.temp_custom_data().value3();
|
|
}
|
|
OnTempCustomDataChange();
|
|
SyncGuildMemberInfo();
|
|
}
|
|
|
|
void Player::_CMFriendList(f8::MsgHdr& hdr, const cs::CMFriendList& msg)
|
|
{
|
|
PushFriendList();
|
|
}
|
|
|
|
void Player::_CMFriendApply(f8::MsgHdr& hdr, const cs::CMFriendApply& msg)
|
|
{
|
|
cs::SMFriendApply respmsg;
|
|
if (GetBlackListById(msg.friend_id())) {
|
|
respmsg.set_errcode(0);
|
|
respmsg.set_errmsg(TEXT("you_permission_denied", "没有权限"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
if (GetFriendById(msg.friend_id())) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("already_has_friend", "已经是好友"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
if (msg.friend_id() == AccountId()) {
|
|
respmsg.set_errcode(2);
|
|
respmsg.set_errmsg(TEXT("cant_invite_self", "不能邀请自己"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
if (f8::ExtractGameIdFromAccountId(AccountId()) !=
|
|
f8::ExtractGameIdFromAccountId(msg.friend_id())) {
|
|
respmsg.set_errcode(3);
|
|
respmsg.set_errmsg(TEXT("cant_invite_other_game_player", "不能邀请其他游戏玩家"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
if (role_data.today_apply_times > DAILY_APPLY_FRIEND_TIMES) {
|
|
respmsg.set_errcode(4);
|
|
respmsg.set_errmsg(TEXT("today_invite_times_not_enough", "今天邀请次数已经用完不能再邀请"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
++role_data.today_apply_times;
|
|
SendMsg(respmsg);
|
|
QueryUserOnline({msg.friend_id()});
|
|
DBHelper::Instance()->AddFriendApply(this, msg.friend_id());
|
|
GameLog::Instance()->FriendApply(this, msg.friend_id());
|
|
}
|
|
|
|
void Player::_CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& msg)
|
|
{
|
|
#if 0
|
|
if (last_apply_idx_ > 0 &&
|
|
last_apply_idx_ >= DBEngine::Instance()->GetFriendApplyCurrIdx(myself.crc32_code)) {
|
|
cs::SMFriendApplyList respmsg;
|
|
FillApplyList(msg.paging(), respmsg);
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
auto on_ok =
|
|
[] (a8::XParams& param, const f8::DataSet* data_set)
|
|
{
|
|
cs::MFPaging* paging = (cs::MFPaging*)param.param2.GetUserData();
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(param.sender.GetString());
|
|
if (hum && hum->socket_handle == param.param1.GetInt()) {
|
|
for (auto& row : *data_set) {
|
|
FriendApply* apply = new FriendApply;
|
|
apply->idx = a8::XValue(row[0]);
|
|
apply->applyid = a8::XValue(row[1]);
|
|
apply->target_id = row[2];
|
|
apply->base_data.account_id = row[3];
|
|
apply->base_data.nickname = row[4];
|
|
apply->base_data.avatar_url = row[5];
|
|
apply->base_data.sex = a8::XValue(row[6]);
|
|
apply->base_data.base_data_version = a8::XValue(row[7]);
|
|
apply->base_data.user_value1 = a8::XValue(row[8]);
|
|
apply->base_data.user_value2 = a8::XValue(row[9]);
|
|
apply->base_data.user_value3 = a8::XValue(row[10]);
|
|
apply->base_data.vip_lv = a8::XValue(row[12]);
|
|
apply->base_data.head = a8::XValue(row[13]);
|
|
hum->apply_hash_[apply->idx] = apply;
|
|
if (apply->idx > hum->last_apply_idx_) {
|
|
hum->last_apply_idx_ = apply->idx;
|
|
}
|
|
}
|
|
cs::SMFriendApplyList respmsg;
|
|
hum->FillApplyList(*paging, respmsg);
|
|
hum->SendMsg(respmsg);
|
|
a8::UnSetBitFlag(hum->red_point_flags_, RPF_FriendApply);
|
|
hum->SyncRedPoint();
|
|
}
|
|
delete paging;
|
|
};
|
|
auto on_error =
|
|
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
|
{
|
|
cs::MFPaging* paging = (cs::MFPaging*)param.param2.GetUserData();
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(param.sender.GetString());
|
|
if (hum && hum->socket_handle == param.param1.GetInt()) {
|
|
cs::SMFriendApplyList respmsg;
|
|
hum->FillApplyList(*paging, respmsg);
|
|
hum->SendMsg(respmsg);
|
|
}
|
|
delete paging;
|
|
};
|
|
|
|
cs::MFPaging* paging_copy = new cs::MFPaging;
|
|
*paging_copy = msg.paging();
|
|
#if 1
|
|
paging_copy->set_curr_page(0);
|
|
paging_copy->set_page_size(20);
|
|
#endif
|
|
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(myself.crc32_code);
|
|
std::string fmtstr = "SELECT '' AS account_id";
|
|
std::vector<a8::XValue> sql_params;
|
|
{
|
|
for (auto& pair : black_hash_) {
|
|
fmtstr += " UNION SELECT '%s'";
|
|
sql_params.push_back(a8::XValue(pair.second->base_data.account_id));
|
|
}
|
|
sql_params.push_back(a8::XValue(last_apply_idx_));
|
|
sql_params.push_back(a8::XValue(myself.base_data.account_id));
|
|
}
|
|
DBEngine::Instance()->ExecAsyncQuery
|
|
(
|
|
conn_info,
|
|
(
|
|
"SELECT A.idx, A.applyid, A.target_id, A.sender_id, A.sender_nickname, "
|
|
" A.sender_avatar_url, A.sender_sex, A.sender_data_version1, "
|
|
" A.sender_user_value1, A.sender_user_value2, A.sender_user_value3, A.status, "
|
|
" A.sender_vip_lv, A.sender_head "
|
|
"FROM friend_apply A "
|
|
" LEFT JOIN (" + fmtstr + ") AS B ON B.account_id = A.sender_id "
|
|
"WHERE A.idx > %d AND A.target_id='%s' AND A.status=0 AND "
|
|
" B.account_id IS NULL;"
|
|
).c_str(),
|
|
sql_params,
|
|
a8::XParams()
|
|
.SetSender(myself.base_data.account_id)
|
|
.SetParam1(hdr.socket_handle)
|
|
.SetParam2(paging_copy),
|
|
on_ok,
|
|
on_error,
|
|
myself.crc32_code
|
|
);
|
|
}
|
|
|
|
void Player::_CMFriendAgree(f8::MsgHdr& hdr, const cs::CMFriendAgree& msg)
|
|
{
|
|
cs::SMFriendAgree respmsg;
|
|
if (GetFriendById(msg.apply().base_data().account_id())) {
|
|
respmsg.set_errcode(0);
|
|
respmsg.set_errmsg(TEXT("you_permission_denied", "没有权限"));
|
|
SendMsg(respmsg);
|
|
DBHelper::Instance()->SetFriendApplyStatus(
|
|
myself.crc32_code,
|
|
msg.apply().target_id(),
|
|
AccountId(),
|
|
1
|
|
);
|
|
return;
|
|
}
|
|
if (msg.apply().base_data().account_id() == AccountId()) {
|
|
respmsg.set_errcode(2);
|
|
respmsg.set_errmsg(TEXT("cant_add_self", "不能添加自己"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
if (!CanAddFriend(msg.apply().base_data().account_id())) {
|
|
respmsg.set_errcode(3);
|
|
respmsg.set_errmsg(TEXT("friend_member_upper_limit", "您的好友数已达到上限"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
Friend* friendobj = new Friend;
|
|
TypeConvert::Convert(msg.apply().base_data(), friendobj->base_data);
|
|
if (AddFriend(friendobj) == 0) {
|
|
NotifyUserInfoUpdate(friendobj);
|
|
SyncHelper::Instance()->SyncNewFriend(this, friendobj->base_data.account_id);
|
|
MarkDirty();
|
|
QueryUserOnline({friendobj->base_data.account_id});
|
|
} else {
|
|
A8_SAFE_DELETE(friendobj);
|
|
}
|
|
SendMsg(respmsg);
|
|
DBHelper::Instance()->SetFriendApplyStatus
|
|
(
|
|
myself.crc32_code,
|
|
msg.apply().base_data().account_id(),
|
|
AccountId(),
|
|
1
|
|
);
|
|
ClearApplyBySenderId(msg.apply().base_data().account_id());
|
|
GameLog::Instance()->FriendAgree(this, msg.apply().idx(), msg.apply().base_data().account_id());
|
|
}
|
|
|
|
void Player::_CMFriendRefuse(f8::MsgHdr& hdr, const cs::CMFriendRefuse& msg)
|
|
{
|
|
cs::SMFriendRefuse respmsg;
|
|
SendMsg(respmsg);
|
|
|
|
DBHelper::Instance()->SetFriendApplyStatus
|
|
(
|
|
myself.crc32_code,
|
|
msg.apply().idx(),
|
|
msg.apply().base_data().account_id(),
|
|
AccountId(),
|
|
2
|
|
);
|
|
ClearApplyByIdx(msg.apply().idx());
|
|
GameLog::Instance()->FriendRefuse(this, msg.apply().idx(), msg.apply().base_data().account_id());
|
|
}
|
|
|
|
void Player::_CMFriendDelete(f8::MsgHdr& hdr, const cs::CMFriendDelete& msg)
|
|
{
|
|
cs::SMFriendDelete respmsg;
|
|
Friend* p = GetFriendById(msg.friend_id());
|
|
if (p) {
|
|
RemoveFriend(p->base_data.account_id, true);
|
|
}
|
|
respmsg.set_friend_id(msg.friend_id());
|
|
SendMsg(respmsg);
|
|
{
|
|
cs::SMDeleteFriendNotify notifymsg;
|
|
notifymsg.add_user_list(msg.friend_id());
|
|
SendMsg(notifymsg);
|
|
}
|
|
GameLog::Instance()->FriendDelete(this, msg.friend_id());
|
|
}
|
|
|
|
void Player::_CMFriendBlackList(f8::MsgHdr& hdr, const cs::CMFriendBlackList& msg)
|
|
{
|
|
PushBlackList();
|
|
}
|
|
|
|
void Player::_CMFriendAddBlack(f8::MsgHdr& hdr, const cs::CMFriendAddBlack& msg)
|
|
{
|
|
if (black_hash_.size() >= MAX_BLACKLIST_NUM) {
|
|
ShowErrorMsg(TEXT("add_error_blacklist_isfull", "添加失败,黑名单已满"));
|
|
return;
|
|
}
|
|
if (GetBlackListById(msg.user_info().base_data().account_id())) {
|
|
cs::SMFriendAddBlack respmsg;
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
Friend* p = GetFriendById(msg.user_info().base_data().account_id());
|
|
if (p) {
|
|
{
|
|
cs::SMAddBlackListNotify notifymsg;
|
|
auto user_info = notifymsg.add_user_infos();
|
|
TypeConvert::Convert(p->base_data, *user_info->mutable_base_data());
|
|
TypeConvert::Convert(p->temp_custom_data, *user_info->mutable_temp_custom_data());
|
|
{
|
|
int target_channel = f8::ExtractChannelIdFromAccountId
|
|
(user_info->base_data().account_id());
|
|
App::Instance()->PreProcAvatarUrl
|
|
(channel,
|
|
target_channel,
|
|
*user_info->mutable_base_data()->mutable_avatar_url());
|
|
}
|
|
SendMsg(notifymsg);
|
|
}
|
|
black_hash_[p->base_data.account_id] = p;
|
|
InternalRemoveFriend(p->base_data.account_id, true, false);
|
|
MarkDirty();
|
|
ShowErrorMsg(TEXT("blacklist_add_success", "成功添加到黑名单"));
|
|
} else {
|
|
if (msg.user_info().base_data().account_id().empty()) {
|
|
return;
|
|
}
|
|
if (msg.user_info().base_data().account_id() == AccountId()) {
|
|
return;
|
|
}
|
|
p = new Friend();
|
|
TypeConvert::Convert(msg.user_info().base_data(), p->base_data);
|
|
AddBlackList(p);
|
|
{
|
|
cs::SMAddBlackListNotify notifymsg;
|
|
auto user_info = notifymsg.add_user_infos();
|
|
TypeConvert::Convert(p->base_data, *user_info->mutable_base_data());
|
|
TypeConvert::Convert(p->temp_custom_data, *user_info->mutable_temp_custom_data());
|
|
{
|
|
int target_channel = f8::ExtractChannelIdFromAccountId
|
|
(user_info->base_data().account_id());
|
|
App::Instance()->PreProcAvatarUrl
|
|
(channel,
|
|
target_channel,
|
|
*user_info->mutable_base_data()->mutable_avatar_url());
|
|
}
|
|
SendMsg(notifymsg);
|
|
}
|
|
MarkDirty();
|
|
}
|
|
cs::SMFriendAddBlack respmsg;
|
|
SendMsg(respmsg);
|
|
}
|
|
|
|
void Player::_CMFriendDeleteBlack(f8::MsgHdr& hdr, const cs::CMFriendDeleteBlack& msg)
|
|
{
|
|
Friend* friend_data = GetBlackListById(msg.account_id());
|
|
if (friend_data) {
|
|
{
|
|
cs::SMDeleteBlackListNotify notifymsg;
|
|
notifymsg.add_user_list(msg.account_id());
|
|
SendMsg(notifymsg);
|
|
}
|
|
PlayerMgr::Instance()->UnWatchPlayer(friend_data);
|
|
black_hash_.erase(friend_data->base_data.account_id);
|
|
A8_SAFE_DELETE(friend_data);
|
|
MarkDirty();
|
|
cs::SMFriendDeleteBlack respmsg;
|
|
SendMsg(respmsg);
|
|
}
|
|
}
|
|
|
|
void Player::_CMQueryUserStatus(f8::MsgHdr& hdr, const cs::CMQueryUserStatus& msg)
|
|
{
|
|
std::vector<std::string> account_ids;
|
|
for (auto& account_id : msg.user_list()) {
|
|
if (account_ids.size() < 20) {
|
|
account_ids.push_back(account_id);
|
|
}
|
|
}
|
|
AsyncTaskMgr::Instance()->CreateQueryUserStatusTask(this, account_ids);
|
|
}
|
|
|
|
void Player::_CMRecommandFriend(f8::MsgHdr& hdr, const cs::CMRecommandFriend& msg)
|
|
{
|
|
AsyncTaskMgr::Instance()->CreateRecommandFriendTask(this);
|
|
}
|
|
|
|
void Player::_CMFriendIdList(f8::MsgHdr& hdr, const cs::CMFriendIdList& msg)
|
|
{
|
|
cs::SMFriendIdList respmsg;
|
|
for (auto& pair : friend_hash_) {
|
|
respmsg.add_friends(pair.first);
|
|
}
|
|
for (auto& pair : black_hash_) {
|
|
respmsg.add_blacklist(pair.first);
|
|
}
|
|
SendMsg(respmsg);
|
|
}
|
|
|
|
void Player::_CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg)
|
|
{
|
|
if (!IsValidChatChannel(msg.chat_channel())) {
|
|
return;
|
|
}
|
|
cs::CMSendChatMsg* mutable_msg = (cs::CMSendChatMsg*)&msg;
|
|
mutable_msg->set_msg_body(MetaMgr::Instance()->ReplaceDirtyWord(msg.msg_body(), '*'));
|
|
switch (msg.chat_channel()) {
|
|
case kCCWorld:
|
|
ChatMgr::Instance()->ProcWorldChat(this, msg);
|
|
break;
|
|
case kCCPrivate:
|
|
ChatMgr::Instance()->ProcPrivateChat(this, msg);
|
|
break;
|
|
case kCCGuild:
|
|
ChatMgr::Instance()->ProcGuildChat(this, msg);
|
|
break;
|
|
case kCCTeam:
|
|
ChatMgr::Instance()->ProcTeamChat(this, msg);
|
|
break;
|
|
case kCCBigHorn:
|
|
ChatMgr::Instance()->ProcBigHornChat(this, msg);
|
|
break;
|
|
case kCCLoopMsg:
|
|
ChatMgr::Instance()->ProcLoopMsgChat(this, msg);
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
void Player::_CMReadMsgAndOpenChatNotify(f8::MsgHdr& hdr, const cs::CMReadMsgAndOpenChatNotify& msg)
|
|
{
|
|
if (IsValidChatChannel(msg.curr_channel())) {
|
|
chat_channel = msg.curr_channel();
|
|
if (chat_channel == kCCPrivate) {
|
|
SyncPrivateChatRedPoint();
|
|
}
|
|
|
|
for (auto& pair : msg.last_ids()) {
|
|
if (IsValidChatChannel(pair.key())) {
|
|
switch (pair.key()) {
|
|
case kCCWorld:
|
|
{
|
|
world_channel_last_id = pair.val();
|
|
ChatMgr::Instance()->SyncWorldChatMsg(this);
|
|
}
|
|
break;
|
|
case kCCPrivate:
|
|
{
|
|
}
|
|
break;
|
|
case kCCGuild:
|
|
{
|
|
guild_channel_last_id = pair.val();
|
|
ChatMgr::Instance()->SyncGuildChatMsg(this);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
a8::UnSetBitFlag(red_point_flags_, RPF_Chat);
|
|
SyncRedPoint();
|
|
}
|
|
}
|
|
|
|
void Player::_CMSetCurrPrivateChatTarget(f8::MsgHdr& hdr, const cs::CMSetCurrPrivateChatTarget& msg)
|
|
{
|
|
private_target = msg.private_target();
|
|
ChatMgr::Instance()->SyncPrivateChatMsg(this);
|
|
}
|
|
|
|
void Player::_CMCloseChatNotify(f8::MsgHdr& hdr, const cs::CMCloseChatNotify& msg)
|
|
{
|
|
chat_channel = -1;
|
|
private_target = TEXT("you_permission_denied", "没有权限");
|
|
}
|
|
|
|
void Player::_CMSendCustomMsg(f8::MsgHdr& hdr, const cs::CMSendCustomMsg& msg)
|
|
{
|
|
ss::SS_IM_SendCustomMsg ss_msg;
|
|
FillIMMsgConext(ss_msg.mutable_context());
|
|
ss_msg.set_msg(msg.msg());
|
|
ss_msg.set_param1(msg.param1());
|
|
ss_msg.set_param2(msg.param2());
|
|
ss_msg.set_param3(msg.param3());
|
|
for (auto& target_id : msg.target_list()) {
|
|
#if 1
|
|
ss_msg.set_target(target_id);
|
|
SyncHelper::Instance()->BroadcastIMConnMsg(ss_msg);
|
|
#else
|
|
Friend* friend_data = GetFriendById(target_id);
|
|
if (friend_data) {
|
|
ss_msg.set_target(target_id);
|
|
SendSSMsg(*friend_data, ss_msg);
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void Player::_CMDirtyWordCheck(f8::MsgHdr& hdr, const cs::CMDirtyWordCheck& msg)
|
|
{
|
|
std::string ip;
|
|
int port = 0;
|
|
JsonDataMgr::Instance()->GetRankServerConf(ip, port);
|
|
|
|
a8::MutableXObject* params = a8::MutableXObject::NewObject();
|
|
params->SetVal("text", msg.text());
|
|
f8::HttpClientPool::Instance()->HttpGet
|
|
(
|
|
a8::XParams()
|
|
.SetSender(AccountId())
|
|
.SetParam1(hdr.socket_handle),
|
|
[] (a8::XParams& param, a8::XObject& data)
|
|
{
|
|
cs::SMDirtyWordCheck respmsg;
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(param.sender);
|
|
if (hum) {
|
|
if (data.At("errcode")->AsXValue().GetInt() == 0) {
|
|
hum->SendMsg(respmsg);
|
|
} else {
|
|
respmsg.set_errcode(data.At("errcode")->AsXValue());
|
|
respmsg.set_errmsg(data.At("errmsg")->AsXValue());
|
|
hum->SendMsg(respmsg);
|
|
}
|
|
}
|
|
},
|
|
[] (a8::XParams& param, const std::string& response)
|
|
{
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(param.sender);
|
|
if (hum) {
|
|
#if 0
|
|
hum->ShowErrorMsg(TEXT("server_internal_error", "服务器内部错误"));
|
|
#endif
|
|
}
|
|
},
|
|
a8::Format("http://%s:%d/webapp/index.php?c=Guild&a=dirtyWordCheck", {ip, port}).c_str(),
|
|
*params,
|
|
rand()
|
|
);
|
|
delete params;
|
|
}
|
|
|
|
void Player::_CMTeamCreate(f8::MsgHdr& hdr, const cs::CMTeamCreate& msg)
|
|
{
|
|
#if 0
|
|
if (myself.base_data.group_id != 0) {
|
|
cs::SMTeamCreate respmsg;
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_already_has_group", "你已经有群"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGroupCMMsg(hdr, App::Instance()->NewUUID());
|
|
#endif
|
|
}
|
|
|
|
void Player::_CMTeamJoin(f8::MsgHdr& hdr, const cs::CMTeamJoin& msg)
|
|
{
|
|
#if 0
|
|
if (myself.base_data.group_id != 0) {
|
|
cs::SMTeamJoin respmsg;
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_already_has_group", "你已经有群"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGroupCMMsg(hdr, myself.base_data.group_id);
|
|
#endif
|
|
}
|
|
|
|
void Player::_CMTeamAgree(f8::MsgHdr& hdr, const cs::CMTeamAgree& msg)
|
|
{
|
|
#if 0
|
|
if (myself.base_data.group_id == 0) {
|
|
cs::SMTeamAgree respmsg;
|
|
respmsg.set_errcode(2);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_group", "你还没有群"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGroupCMMsg(hdr, myself.base_data.group_id);
|
|
#endif
|
|
}
|
|
|
|
void Player::_CMTeamKick(f8::MsgHdr& hdr, const cs::CMTeamKick& msg)
|
|
{
|
|
#if 0
|
|
if (myself.base_data.group_id == 0) {
|
|
cs::SMTeamKick respmsg;
|
|
respmsg.set_errcode(2);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_group", "你还没有群"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGroupCMMsg(hdr, myself.base_data.group_id);
|
|
#endif
|
|
}
|
|
|
|
void Player::_CMTeamQuit(f8::MsgHdr& hdr, const cs::CMTeamQuit& msg)
|
|
{
|
|
#if 0
|
|
if (myself.base_data.group_id == 0) {
|
|
cs::SMTeamQuit respmsg;
|
|
respmsg.set_errcode(2);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_group", "你还没有群"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGroupCMMsg(hdr, myself.base_data.group_id);
|
|
#endif
|
|
}
|
|
|
|
void Player::_CMTeamDismiss(f8::MsgHdr& hdr, const cs::CMTeamDismiss& msg)
|
|
{
|
|
#if 0
|
|
if (myself.base_data.group_id == 0) {
|
|
cs::SMTeamQuit respmsg;
|
|
respmsg.set_errcode(2);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_group", "你还没有群"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGroupCMMsg(hdr, myself.base_data.group_id);
|
|
#endif
|
|
}
|
|
|
|
void Player::_CMTeamRename(f8::MsgHdr& hdr, const cs::CMTeamRename& msg)
|
|
{
|
|
#if 0
|
|
if (myself.base_data.group_id == 0) {
|
|
cs::SMTeamRename respmsg;
|
|
respmsg.set_errcode(2);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_group", "你还没有群"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGroupCMMsg(hdr, myself.base_data.group_id);
|
|
#endif
|
|
}
|
|
|
|
void Player::_CMGuildInfo(f8::MsgHdr& hdr, const cs::CMGuildInfo& msg)
|
|
{
|
|
cs::SMGuildInfo respmsg;
|
|
if (msg.guild_id() == 0 && GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, msg.guild_id());
|
|
}
|
|
|
|
void Player::_CMGuildCreate(f8::MsgHdr& hdr, const cs::CMGuildCreate& msg)
|
|
{
|
|
cs::SMGuildCreate respmsg;
|
|
if (GuildId() != 0) {
|
|
ShowErrorMsg(TEXT("you_already_has_guild", "你已经有战队"));
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_already_has_guild", "你已经有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
if (App::Instance()->nowtime - last_create_guild_time_ < 5) {
|
|
ShowErrorMsg(TEXT("operation_is_too_requent", "您的操作太过频繁,请稍后再试"));
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("operation_is_too_requent", "您的操作太过频繁,请稍后再试"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
if (role_data.today_create_guild_times >= MAX_DAILY_CREATE_GUILD_TIMES) {
|
|
ShowErrorMsg(TEXT("today_create_guild_times_not_enough", "今日创建战队次数已达上限"));
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("today_create_guild_times_not_enough", "今日创建战队次数已达上限"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
++role_data.today_create_guild_times;
|
|
|
|
std::string ip;
|
|
int port = 0;
|
|
JsonDataMgr::Instance()->GetRankServerConf(ip, port);
|
|
|
|
struct MsgContext
|
|
{
|
|
int socket_handle = 0;
|
|
std::string account_id;
|
|
cs::CMGuildCreate msg;
|
|
long long guild_id = 0;
|
|
};
|
|
MsgContext* msg_context = new MsgContext;
|
|
msg_context->socket_handle = socket_handle;
|
|
msg_context->account_id = AccountId();
|
|
msg_context->msg = msg;
|
|
msg_context->guild_id = App::Instance()->NewUUID();
|
|
a8::MutableXObject* params = a8::MutableXObject::NewObject();
|
|
params->SetVal("gameid", gameid);
|
|
params->SetVal("guild_id", msg_context->guild_id);
|
|
params->SetVal("guild_name", msg.guild_name());
|
|
params->SetVal("guild_badge", msg.guild_badge());
|
|
params->SetVal("guild_lv", 1);
|
|
params->SetVal("guild_exp", 0);
|
|
params->SetVal("guild_declaration", msg.guild_declaration());
|
|
params->SetVal("owner_id", AccountId());
|
|
params->SetVal("owner_name", NickName());
|
|
params->SetVal("owner_avatar_url", AvatarUrl());
|
|
params->SetVal("owner_vip_lv", VipLv());
|
|
params->SetVal("owner_head", Head());
|
|
params->SetVal("owner_sex", Sex());
|
|
params->SetVal("join_unlimited", msg.join_unlimited());
|
|
params->SetVal("join_cond1", msg.join_cond1());
|
|
params->SetVal("join_cond2", msg.join_cond2());
|
|
last_create_guild_time_ = App::Instance()->nowtime;
|
|
f8::HttpClientPool::Instance()->HttpGet
|
|
(
|
|
a8::XParams()
|
|
.SetSender(msg_context)
|
|
.SetParam1(msg.guild_name()),
|
|
[] (a8::XParams& param, a8::XObject& data)
|
|
{
|
|
MsgContext* msg_context = (MsgContext*)param.sender.GetUserData();
|
|
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(msg_context->account_id);
|
|
if (hum) {
|
|
if (data.At("errcode")->AsXValue().GetInt() == 0) {
|
|
DBHelper::Instance()->ConfirmGuild(hum, msg_context->guild_id);
|
|
GameLog::Instance()->GuildCreate(hum,
|
|
msg_context->guild_id,
|
|
param.param1);
|
|
} else {
|
|
hum->last_create_guild_time_ = 0;
|
|
hum->ShowErrorMsg(data.At("errmsg")->AsXValue().GetString());
|
|
}
|
|
}
|
|
|
|
A8_SAFE_DELETE(msg_context);
|
|
},
|
|
[] (a8::XParams& param, const std::string& response)
|
|
{
|
|
MsgContext* msg_context = (MsgContext*)param.sender.GetUserData();
|
|
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(msg_context->account_id);
|
|
if (hum) {
|
|
hum->last_create_guild_time_ = 0;
|
|
hum->ShowErrorMsg(TEXT("server_internal_error", "服务器内部错误"));
|
|
}
|
|
|
|
A8_SAFE_DELETE(msg_context);
|
|
},
|
|
a8::Format("http://%s:%d/webapp/index.php?c=Guild&a=create", {ip, port}).c_str(),
|
|
*params,
|
|
msg_context->guild_id
|
|
);
|
|
delete params;
|
|
}
|
|
|
|
void Player::_CMGuildJoin(f8::MsgHdr& hdr, const cs::CMGuildJoin& msg)
|
|
{
|
|
cs::SMGuildJoin respmsg;
|
|
if (msg.guild_id() == 0 && GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_already_has_guild", "你已经有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
if (role_data.today_apply_guild_times >= MAX_DAILY_APPPLY_GUILD_TIMES) {
|
|
ShowErrorMsg(TEXT("today_join_guild_times_not_enough", "今日申请战队次数已达上限"));
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("today_join_guild_times_not_enough", "今日申请战队次数已达上限"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
++role_data.today_apply_guild_times;
|
|
ForwardGuildCMMsg(hdr, msg.guild_id());
|
|
a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
|
(
|
|
1000 * 2 + (rand() % 3000),
|
|
a8::XParams()
|
|
.SetSender(this)
|
|
.SetParam1(msg.guild_id()),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->SyncGuildNewApply(param.param1);
|
|
},
|
|
&timer_attacher.timer_list_
|
|
);
|
|
}
|
|
|
|
void Player::_CMGuildAgree(f8::MsgHdr& hdr, const cs::CMGuildAgree& msg)
|
|
{
|
|
cs::SMGuildAgree respmsg;
|
|
if (GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildRefuse(f8::MsgHdr& hdr, const cs::CMGuildRefuse& msg)
|
|
{
|
|
cs::SMGuildRefuse respmsg;
|
|
if (GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildKick(f8::MsgHdr& hdr, const cs::CMGuildKick& msg)
|
|
{
|
|
cs::SMGuildKick respmsg;
|
|
if (GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildQuit(f8::MsgHdr& hdr, const cs::CMGuildQuit& msg)
|
|
{
|
|
cs::SMGuildQuit respmsg;
|
|
if (GuildId() == 0) {
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildDismiss(f8::MsgHdr& hdr, const cs::CMGuildDismiss& msg)
|
|
{
|
|
cs::SMGuildDismiss respmsg;
|
|
if (GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildChange(f8::MsgHdr& hdr, const cs::CMGuildChange& msg)
|
|
{
|
|
cs::SMGuildChange respmsg;
|
|
if (GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildSearch(f8::MsgHdr& hdr, const cs::CMGuildSearch& msg)
|
|
{
|
|
std::string ip;
|
|
int port = 0;
|
|
JsonDataMgr::Instance()->GetRankServerConf(ip, port);
|
|
|
|
struct MsgContext
|
|
{
|
|
int socket_handle = 0;
|
|
std::string account_id;
|
|
cs::CMGuildSearch msg;
|
|
};
|
|
MsgContext* msg_context = new MsgContext;
|
|
msg_context->socket_handle = socket_handle;
|
|
msg_context->account_id = AccountId();
|
|
msg_context->msg = msg;
|
|
|
|
a8::MutableXObject* params = a8::MutableXObject::NewObject();
|
|
params->SetVal("account_id", AccountId());
|
|
params->SetVal("gameid", gameid);
|
|
params->SetVal("guild_name", msg.guild_name());
|
|
params->SetVal("curr_page", msg.paging().curr_page());
|
|
params->SetVal("page_size", msg.paging().page_size());
|
|
{
|
|
std::string applyed_guilds;
|
|
for (auto& pair : applyed_guild_hash_) {
|
|
applyed_guilds += a8::XValue(pair.first).GetString() + ",";
|
|
}
|
|
params->SetVal("applyed_guilds", applyed_guilds);
|
|
}
|
|
f8::HttpClientPool::Instance()->HttpGet
|
|
(
|
|
a8::XParams().
|
|
SetSender(msg_context),
|
|
[] (a8::XParams& param, a8::XObject& data)
|
|
{
|
|
MsgContext* msg_context = (MsgContext*)param.sender.GetUserData();
|
|
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(msg_context->socket_handle);
|
|
if (hum && hum->AccountId() == msg_context->account_id) {
|
|
cs::SMGuildSearch respmsg;
|
|
respmsg.set_errcode(data.At("errcode")->AsXValue());
|
|
respmsg.set_errmsg(data.At("errmsg")->AsXValue());
|
|
if (respmsg.errcode() == 0) {
|
|
TypeConvert::Convert(data, respmsg.mutable_paging());
|
|
auto guild_list = data.At("guild_list");
|
|
for (int i = 0; i < guild_list->Size(); ++i) {
|
|
auto guild = guild_list->At(i);
|
|
auto guild_pb = respmsg.add_guild_list();
|
|
TypeConvert::Convert(*guild, guild_pb);
|
|
}
|
|
}
|
|
hum->SendMsg(respmsg);
|
|
}
|
|
|
|
A8_SAFE_DELETE(msg_context);
|
|
},
|
|
[] (a8::XParams& param, const std::string& response)
|
|
{
|
|
MsgContext* msg_context = (MsgContext*)param.sender.GetUserData();
|
|
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(msg_context->socket_handle);
|
|
if (hum && hum->AccountId() == msg_context->account_id) {
|
|
hum->ShowErrorMsg(TEXT("server_internal_error", "服务器内部错误"));
|
|
}
|
|
|
|
A8_SAFE_DELETE(msg_context);
|
|
},
|
|
a8::Format("http://%s:%d/webapp/index.php?c=Guild&a=search", {ip, port}).c_str(),
|
|
*params,
|
|
rand()
|
|
);
|
|
delete params;
|
|
}
|
|
|
|
void Player::_CMGuildRank(f8::MsgHdr& hdr, const cs::CMGuildRank& msg)
|
|
{
|
|
std::string ip;
|
|
int port = 0;
|
|
JsonDataMgr::Instance()->GetRankServerConf(ip, port);
|
|
|
|
struct MsgContext
|
|
{
|
|
int socket_handle = 0;
|
|
std::string account_id;
|
|
cs::CMGuildRank msg;
|
|
};
|
|
MsgContext* msg_context = new MsgContext;
|
|
msg_context->socket_handle = socket_handle;
|
|
msg_context->account_id = AccountId();
|
|
msg_context->msg = msg;
|
|
|
|
a8::MutableXObject* params = a8::MutableXObject::NewObject();
|
|
params->SetVal("gameid", gameid);
|
|
f8::HttpClientPool::Instance()->HttpGet
|
|
(
|
|
a8::XParams()
|
|
.SetSender(msg_context),
|
|
[] (a8::XParams& param, a8::XObject& data)
|
|
{
|
|
MsgContext* msg_context = (MsgContext*)param.sender.GetUserData();
|
|
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(msg_context->socket_handle);
|
|
if (hum) {
|
|
cs::SMGuildRank respmsg;
|
|
respmsg.set_errcode(data.At("errcode")->AsXValue());
|
|
respmsg.set_errmsg(data.At("errmsg")->AsXValue());
|
|
if (respmsg.errcode() == 0) {
|
|
TypeConvert::Convert(data, respmsg.mutable_paging());
|
|
auto guild_list = data.At("guild_list");
|
|
for (int i = 0; i < guild_list->Size(); ++i) {
|
|
auto guild = guild_list->At(i);
|
|
auto guild_pb = respmsg.add_guild_list();
|
|
TypeConvert::Convert(*guild, guild_pb);
|
|
}
|
|
}
|
|
hum->SendMsg(respmsg);
|
|
}
|
|
|
|
A8_SAFE_DELETE(msg_context);
|
|
},
|
|
[] (a8::XParams& param, const std::string& response)
|
|
{
|
|
MsgContext* msg_context = (MsgContext*)param.sender.GetUserData();
|
|
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(msg_context->socket_handle);
|
|
if (hum && hum->AccountId() == msg_context->account_id) {
|
|
hum->ShowErrorMsg(TEXT("server_internal_error", "服务器内部错误"));
|
|
}
|
|
|
|
A8_SAFE_DELETE(msg_context);
|
|
},
|
|
a8::Format("http://%s:%d/webapp/index.php?c=Guild&a=rank", {ip, port}).c_str(),
|
|
*params,
|
|
rand()
|
|
);
|
|
delete params;
|
|
}
|
|
|
|
void Player::_CMGuildMemberList(f8::MsgHdr& hdr, const cs::CMGuildMemberList& msg)
|
|
{
|
|
cs::SMGuildMemberList respmsg;
|
|
if (GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildLog(f8::MsgHdr& hdr, const cs::CMGuildLog& msg)
|
|
{
|
|
cs::SMGuildLog respmsg;
|
|
if (GuildId() == 0) {
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildApplyList(f8::MsgHdr& hdr, const cs::CMGuildApplyList& msg)
|
|
{
|
|
cs::SMGuildApplyList respmsg;
|
|
if (GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
a8::UnSetBitFlag(red_point_flags_, RPF_GuildApply);
|
|
SyncRedPoint();
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildMemberSetJob(f8::MsgHdr& hdr, const cs::CMGuildMemberSetJob& msg)
|
|
{
|
|
cs::SMGuildMemberSetJob respmsg;
|
|
if (GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_CMGuildAgreeInvite(f8::MsgHdr& hdr, const cs::CMGuildAgreeInvite& msg)
|
|
{
|
|
cs::SMGuildAgreeInvite respmsg;
|
|
if (GuildId() != 0) {
|
|
if (GuildId() == msg.guild_id()) {
|
|
NotifyUserInfoUpdate(&myself);
|
|
SendMsg(respmsg);
|
|
} else {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_already_has_guild", "你已经有战队"));
|
|
SendMsg(respmsg);
|
|
}
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, msg.guild_id());
|
|
}
|
|
|
|
void Player::_CMGuildGainExp(f8::MsgHdr& hdr, const cs::CMGuildGainExp& msg)
|
|
{
|
|
cs::SMGuildGainExp respmsg;
|
|
if (GuildId() == 0) {
|
|
respmsg.set_errcode(1);
|
|
respmsg.set_errmsg(TEXT("you_not_yet_guild", "你还没有战队"));
|
|
SendMsg(respmsg);
|
|
return;
|
|
}
|
|
ForwardGuildCMMsg(hdr, GuildId());
|
|
}
|
|
|
|
void Player::_SS_IM_FriendAgreeRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendAgreeRequest& msg)
|
|
{
|
|
if (!GetFriendById(msg.context().user_info().base_data().account_id())) {
|
|
if (CanAddFriend(msg.context().user_info().base_data().account_id())) {
|
|
Friend* friendobj = new Friend;
|
|
TypeConvert::Convert(msg.context().user_info().base_data(), friendobj->base_data);
|
|
TypeConvert::Convert(msg.context().user_info().temp_custom_data(), friendobj->temp_custom_data);
|
|
if (AddFriend(friendobj) != 0) {
|
|
delete friendobj;
|
|
return;
|
|
}
|
|
QueryUserOnline({friendobj->base_data.account_id});
|
|
} else {
|
|
SyncHelper::Instance()->SyncDeleteFriend
|
|
(this,
|
|
msg.context().user_info().base_data().account_id(),
|
|
1);
|
|
}
|
|
}
|
|
RemoveHandledApply();
|
|
f8::MsgHdr* hdr_copy = hdr.Clone();
|
|
ss::SS_IM_FriendAgreeRequest* msg_copy = new ss::SS_IM_FriendAgreeRequest;
|
|
*msg_copy = msg;
|
|
SaveToDB
|
|
(
|
|
a8::XParams()
|
|
.SetSender(hdr_copy)
|
|
.SetParam1(msg_copy),
|
|
[] (a8::XParams& param, const f8::DataSet* data_set)
|
|
{
|
|
f8::MsgHdr* hdr_copy = (f8::MsgHdr*)param.sender.GetUserData();
|
|
ss::SS_IM_FriendAgreeRequest* msg_copy = (ss::SS_IM_FriendAgreeRequest*)param.param1.GetUserData();
|
|
|
|
ss::SS_IM_FriendAgreeResponse respmsg;
|
|
*respmsg.mutable_context() = msg_copy->context();
|
|
respmsg.set_target_id(msg_copy->target_id());
|
|
IMListener::Instance()->SendMsg(hdr_copy->socket_handle, respmsg);
|
|
|
|
f8::MsgHdr::Destroy(hdr_copy);
|
|
delete msg_copy;
|
|
},
|
|
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
|
{
|
|
f8::MsgHdr* hdr_copy = (f8::MsgHdr*)param.sender.GetUserData();
|
|
ss::SS_IM_FriendAgreeRequest* msg_copy = (ss::SS_IM_FriendAgreeRequest*)param.param1.GetUserData();
|
|
f8::MsgHdr::Destroy(hdr_copy);
|
|
delete msg_copy;
|
|
}
|
|
);
|
|
}
|
|
|
|
void Player::_SS_IM_FriendDeleteRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendDeleteRequest& msg)
|
|
{
|
|
if (GetFriendById(msg.context().user_info().base_data().account_id())) {
|
|
#ifdef DEBUG
|
|
a8::UdpLog::Instance()->Debug("SS_IM_FriendDeleteRequest %s",
|
|
{
|
|
msg.context().user_info().base_data().account_id()
|
|
});
|
|
#endif
|
|
RemoveFriend(msg.context().user_info().base_data().account_id(), false);
|
|
if (msg.reason() == 1) {
|
|
a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
|
(
|
|
1000 * 2,
|
|
a8::XParams()
|
|
.SetSender(this),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
cs::SMFriendAgree respmsg;
|
|
respmsg.set_errcode(4);
|
|
respmsg.set_errmsg(TEXT("add_error_target_friend_num_upper_limit", "添加失败,对方的好友数已达到上限"));
|
|
hum->SendMsg(respmsg);
|
|
#ifdef DEBUG
|
|
a8::UdpLog::Instance()->Debug("添加失败,对方的好友数已达到上限 %s",
|
|
{
|
|
hum->AccountId()
|
|
});
|
|
#endif
|
|
},
|
|
&timer_attacher.timer_list_
|
|
);
|
|
}
|
|
}
|
|
f8::MsgHdr* hdr_copy = hdr.Clone();
|
|
ss::SS_IM_FriendDeleteRequest* msg_copy = new ss::SS_IM_FriendDeleteRequest;
|
|
*msg_copy = msg;
|
|
SaveToDB
|
|
(
|
|
a8::XParams()
|
|
.SetSender(hdr_copy)
|
|
.SetParam1(msg_copy),
|
|
[] (a8::XParams& param, const f8::DataSet* data_set)
|
|
{
|
|
f8::MsgHdr* hdr_copy = (f8::MsgHdr*)param.sender.GetUserData();
|
|
ss::SS_IM_FriendDeleteRequest* msg_copy = (ss::SS_IM_FriendDeleteRequest*)param.param1.GetUserData();
|
|
|
|
ss::SS_IM_FriendDeleteResponse respmsg;
|
|
*respmsg.mutable_context() = msg_copy->context();
|
|
respmsg.set_target_id(msg_copy->target_id());
|
|
IMListener::Instance()->SendMsg(hdr_copy->socket_handle, respmsg);
|
|
|
|
f8::MsgHdr::Destroy(hdr_copy);
|
|
delete msg_copy;
|
|
},
|
|
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
|
{
|
|
f8::MsgHdr* hdr_copy = (f8::MsgHdr*)param.sender.GetUserData();
|
|
ss::SS_IM_FriendDeleteRequest* msg_copy = (ss::SS_IM_FriendDeleteRequest*)param.param1.GetUserData();
|
|
f8::MsgHdr::Destroy(hdr_copy);
|
|
delete msg_copy;
|
|
}
|
|
);
|
|
}
|
|
|
|
void Player::_SS_IM_FriendApply(f8::MsgHdr& hdr, const ss::SS_IM_FriendApply& msg)
|
|
{
|
|
RecalcRedPoint();
|
|
}
|
|
|
|
void Player::ReLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg)
|
|
{
|
|
cs::SMLogin respmsg;
|
|
FillSMLogin(respmsg);
|
|
WSListener::Instance()->SendToClient(hdr.socket_handle, 0, respmsg);
|
|
PlayerMgr::Instance()->ReBindSocket(hdr.socket_handle, this);
|
|
SyncGuildMemberInfo();
|
|
}
|
|
|
|
void Player::FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* friend_list)
|
|
{
|
|
{
|
|
auto p = friend_list->Add();
|
|
TypeConvert::Convert(myself.base_data, *(p->mutable_base_data()));
|
|
TypeConvert::Convert(myself.temp_custom_data, *(p->mutable_temp_custom_data()));
|
|
}
|
|
for (auto& pair : friend_hash_) {
|
|
auto p = friend_list->Add();
|
|
TypeConvert::Convert(pair.second->base_data, *(p->mutable_base_data()));
|
|
TypeConvert::Convert(pair.second->temp_custom_data, *(p->mutable_temp_custom_data()));
|
|
{
|
|
int target_channel = f8::ExtractChannelIdFromAccountId
|
|
(p->base_data().account_id());
|
|
App::Instance()->PreProcAvatarUrl
|
|
(channel,
|
|
target_channel,
|
|
*p->mutable_base_data()->mutable_avatar_url());
|
|
}
|
|
}
|
|
}
|
|
|
|
void Player::FillBlackList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* black_list)
|
|
{
|
|
for (auto& pair : black_hash_) {
|
|
auto p = black_list->Add();
|
|
TypeConvert::Convert(pair.second->base_data, *(p->mutable_base_data()));
|
|
TypeConvert::Convert(pair.second->temp_custom_data, *(p->mutable_temp_custom_data()));
|
|
{
|
|
int target_channel = f8::ExtractChannelIdFromAccountId
|
|
(p->base_data().account_id());
|
|
App::Instance()->PreProcAvatarUrl
|
|
(channel,
|
|
target_channel,
|
|
*p->mutable_base_data()->mutable_avatar_url());
|
|
}
|
|
}
|
|
}
|
|
|
|
void Player::FillIMMsgConext(ss::MFIMMsgConext* context)
|
|
{
|
|
FillMFUserInfo(context->mutable_user_info());
|
|
context->set_seqid(App::Instance()->NewSeqId());
|
|
context->set_socket_handle(socket_handle);
|
|
}
|
|
|
|
void Player::ForwardGroupCMMsg(f8::MsgHdr& hdr, long long hash_code)
|
|
{
|
|
ss::SS_MS_ForwardGroupCMMsg msg;
|
|
FillIMMsgConext(msg.mutable_context());
|
|
if (hdr.buflen > 0) {
|
|
msg.mutable_payload()->assign(hdr.buf, hdr.buflen);
|
|
}
|
|
MSConnMgr::Instance()->SendMsg(msg, hash_code);
|
|
}
|
|
|
|
void Player::ForwardGuildCMMsg(f8::MsgHdr& hdr, long long guild_id)
|
|
{
|
|
ss::SS_IM_ForwardGuildCMMsg msg;
|
|
FillIMMsgConext(msg.mutable_context());
|
|
msg.set_guild_id(guild_id);
|
|
msg.set_msgid(hdr.msgid);
|
|
if (hdr.buflen > 0) {
|
|
msg.mutable_payload()->assign(hdr.buf, hdr.buflen);
|
|
}
|
|
SyncHelper::Instance()->SendIMConnMsg(JsonDataMgr::Instance()->GetIMInstanceId(guild_id),
|
|
msg);
|
|
}
|
|
|
|
void Player::SendGSMsg(int msgid, ::google::protobuf::Message& msg)
|
|
{
|
|
if (GuildId() != 0) {
|
|
SyncHelper::Instance()->SendIMConnMsg(JsonDataMgr::Instance()->GetIMInstanceId(GuildId()),
|
|
msgid,
|
|
msg);
|
|
}
|
|
}
|
|
|
|
void Player::FillMFUserInfo(cs::MFUserInfo* user_info)
|
|
{
|
|
TypeConvert::Convert(myself.base_data, *(user_info->mutable_base_data()));
|
|
TypeConvert::Convert(myself.temp_custom_data, *(user_info->mutable_temp_custom_data()));
|
|
{
|
|
int target_channel = f8::ExtractChannelIdFromAccountId(user_info->base_data().account_id());
|
|
App::Instance()->PreProcAvatarUrl
|
|
(channel,
|
|
target_channel,
|
|
*user_info->mutable_base_data()->mutable_avatar_url());
|
|
}
|
|
}
|
|
|
|
std::set<std::string>& Player::GetExcludeAccountIds()
|
|
{
|
|
for (auto& pair : friend_hash_) {
|
|
exclude_account_ids_.insert(pair.first);
|
|
}
|
|
for (auto& pair : black_hash_) {
|
|
exclude_account_ids_.insert(pair.first);
|
|
}
|
|
exclude_account_ids_.insert(AccountId());
|
|
return exclude_account_ids_;
|
|
}
|
|
|
|
void Player::MarkDirty()
|
|
{
|
|
if (!dirty_) {
|
|
dirty_ = true;
|
|
dirty_timer_ = a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
|
(1000 * 60,
|
|
a8::XParams()
|
|
.SetSender((void*)this),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->SaveToDB(a8::XParams(), nullptr, nullptr);
|
|
},
|
|
&timer_attacher.timer_list_,
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->dirty_timer_ = nullptr;
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
void Player::SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error)
|
|
{
|
|
ss::MFUserDB user_db;
|
|
Serialize(user_db);
|
|
std::string friend_data;
|
|
user_db.SerializeToString(&friend_data);
|
|
|
|
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(myself.crc32_code);
|
|
DBEngine::Instance()->ExecAsyncScript
|
|
(
|
|
conn_info,
|
|
"UPDATE `user` SET friend_data='%s', modifytime=%d, "
|
|
" nickname='%s', avatar_url='%s', sex=%d, data_version1=%d, "
|
|
" user_value1=%d, user_value2=%d, user_value3=%d, "
|
|
" vip_lv=%d, head=%d, contribute=%d, "
|
|
" guild_id=%d, guild_job=%d, last_logintime=%d "
|
|
"WHERE account_id='%s';",
|
|
{
|
|
friend_data,
|
|
App::Instance()->nowtime,
|
|
myself.base_data.nickname,
|
|
myself.base_data.avatar_url,
|
|
myself.base_data.sex,
|
|
myself.base_data.base_data_version,
|
|
myself.base_data.user_value1,
|
|
myself.base_data.user_value2,
|
|
myself.base_data.user_value3,
|
|
myself.base_data.vip_lv,
|
|
myself.base_data.head,
|
|
myself.base_data.contribute,
|
|
myself.base_data.guild_id,
|
|
myself.base_data.guild_job,
|
|
App::Instance()->nowtime,
|
|
myself.base_data.account_id
|
|
},
|
|
param,
|
|
on_ok,
|
|
on_error,
|
|
myself.crc32_code
|
|
);
|
|
++role_data.save_count;
|
|
role_data.last_save_time = App::Instance()->nowtime;
|
|
}
|
|
|
|
void Player::MarkNewMsg()
|
|
{
|
|
cs::SMUpdateChatRedPointNotify msg;
|
|
ChatMgr::Instance()->FillSMUpdateChatRedPointNotify(this, msg);
|
|
SendMsg(msg);
|
|
}
|
|
|
|
Friend* Player::GetFriendById(const std::string& friend_id)
|
|
{
|
|
auto itr = friend_hash_.find(friend_id);
|
|
return itr != friend_hash_.end() ? itr->second : nullptr;
|
|
}
|
|
|
|
Friend* Player::GetBlackListById(const std::string& friend_id)
|
|
{
|
|
auto itr = black_hash_.find(friend_id);
|
|
return itr != black_hash_.end() ? itr->second : nullptr;
|
|
}
|
|
|
|
void Player::UpdateGuildData(long long guild_id, int guild_job)
|
|
{
|
|
myself.base_data.guild_id = guild_id;
|
|
myself.base_data.guild_job = guild_job;
|
|
OnDataVersion1Change();
|
|
NotifyUserInfoUpdate(&myself);
|
|
SaveToDB(a8::XParams(), nullptr, nullptr);
|
|
}
|
|
|
|
void Player::FillSMLogin(cs::SMLogin& respmsg)
|
|
{
|
|
FillMFUserInfo(respmsg.mutable_account_info()->mutable_user_info());
|
|
respmsg.mutable_account_info()->set_user_sign(user_sign_);
|
|
}
|
|
|
|
void Player::UpdateGuildRedPoint(long long guild_id, int has_apply)
|
|
{
|
|
if (has_apply) {
|
|
a8::SetBitFlag(red_point_flags_, RPF_GuildApply);
|
|
SyncRedPoint();
|
|
}
|
|
}
|
|
|
|
void Player::FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg)
|
|
{
|
|
RemoveHandledApply();
|
|
int i = 0;
|
|
int start = paging.curr_page() * paging.page_size();
|
|
for (auto& pair : apply_hash_) {
|
|
if (i >= start && i < start + paging.page_size()) {
|
|
if (pair.second->flag == 1) {
|
|
continue;
|
|
}
|
|
if (GetBlackListById(pair.second->base_data.account_id)) {
|
|
continue;
|
|
}
|
|
cs::MFFriendApply* apply_pb = respmsg.add_apply_list();
|
|
TypeConvert::Convert(*pair.second, *apply_pb);
|
|
{
|
|
int target_channel = f8::ExtractChannelIdFromAccountId
|
|
(apply_pb->base_data().account_id());
|
|
App::Instance()->PreProcAvatarUrl
|
|
(channel,
|
|
target_channel,
|
|
*apply_pb->mutable_base_data()->mutable_avatar_url());
|
|
}
|
|
}
|
|
++i;
|
|
}
|
|
*respmsg.mutable_paging() = paging;
|
|
if (paging.page_size() > 0) {
|
|
respmsg.mutable_paging()->set__total_page(ceil(i / paging.page_size()));
|
|
} else {
|
|
respmsg.mutable_paging()->set__total_page(1);
|
|
}
|
|
}
|
|
|
|
void Player::NotifyOnline()
|
|
{
|
|
{
|
|
ss::SS_IM_OnUserOnline msg;
|
|
msg.add_account_ids(AccountId());
|
|
SendSSMsg(myself, msg);
|
|
SyncOtherFriend();
|
|
}
|
|
{
|
|
ss::SS_IM_QueryUserOnlineState msg;
|
|
FillIMMsgConext(msg.mutable_context());
|
|
for (auto& pair : friend_hash_) {
|
|
msg.add_account_ids(pair.second->base_data.account_id);
|
|
}
|
|
SendSSMsg(myself, msg);
|
|
}
|
|
}
|
|
|
|
void Player::NotifyOffline()
|
|
{
|
|
ss::SS_IM_OnUserOffline msg;
|
|
msg.add_account_ids(AccountId());
|
|
SendSSMsg(myself, msg);
|
|
SyncGuildMemberInfo();
|
|
}
|
|
|
|
void Player::OnDataVersion1Change()
|
|
{
|
|
++myself.base_data.base_data_version;
|
|
if (!update_user_info_timer_) {
|
|
update_user_info_timer_ = a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
|
(
|
|
1000 * 3,
|
|
a8::XParams()
|
|
.SetSender(this),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->InternalUpdateUserInfo();
|
|
hum->SyncOtherFriend();
|
|
},
|
|
&timer_attacher.timer_list_,
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->update_user_info_timer_ = nullptr;
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
void Player::OnTempCustomDataChange()
|
|
{
|
|
if (!update_user_info_timer_) {
|
|
update_user_info_timer_ = a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
|
(
|
|
1000 * 3,
|
|
a8::XParams()
|
|
.SetSender(this),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->InternalUpdateUserInfo();
|
|
hum->SyncOtherFriend();
|
|
},
|
|
&timer_attacher.timer_list_,
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->update_user_info_timer_ = nullptr;
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
void Player::InternalSendSSMsg(const Friend& friend_data,
|
|
int msgid,
|
|
::google::protobuf::Message& msg)
|
|
{
|
|
SyncHelper::Instance()->BroadcastIMConnMsg(msgid, msg);
|
|
}
|
|
|
|
int Player::AddFriend(Friend* friendobj)
|
|
{
|
|
if (friendobj->base_data.account_id == AccountId()) {
|
|
return -2;
|
|
}
|
|
if (!GetFriendById(friendobj->base_data.account_id)) {
|
|
INIT_LIST_HEAD(&friendobj->watch_node);
|
|
friendobj->crc32_code = a8::openssl::Crc32
|
|
(
|
|
(unsigned char*)friendobj->base_data.account_id.data(),
|
|
friendobj->base_data.account_id.size()
|
|
);
|
|
friendobj->hum = this;
|
|
friend_hash_[friendobj->base_data.account_id] = friendobj;
|
|
NotifyUserInfoUpdate(friendobj);
|
|
PlayerMgr::Instance()->WatchPlayer(friendobj);
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void Player::AddBlackList(Friend* friendobj)
|
|
{
|
|
if (friendobj->base_data.account_id == AccountId()) {
|
|
return;
|
|
}
|
|
INIT_LIST_HEAD(&friendobj->watch_node);
|
|
friendobj->crc32_code = a8::openssl::Crc32
|
|
(
|
|
(unsigned char*)friendobj->base_data.account_id.data(),
|
|
friendobj->base_data.account_id.size()
|
|
);
|
|
friendobj->hum = this;
|
|
black_hash_[friendobj->base_data.account_id] = friendobj;
|
|
PlayerMgr::Instance()->WatchPlayer(friendobj);
|
|
}
|
|
|
|
void Player::RemoveFriend(const std::string& account_id, bool need_sync)
|
|
{
|
|
InternalRemoveFriend(account_id, need_sync, true);
|
|
}
|
|
|
|
void Player::Update(long long tick)
|
|
{
|
|
last_run_tick_ = tick;
|
|
ProcessEvent();
|
|
if (App::Instance()->nowtime - role_data.last_save_time > 1000 * 60) {
|
|
role_data.last_save_time = App::Instance()->nowtime;
|
|
SaveToDB(a8::XParams(), nullptr, nullptr);
|
|
}
|
|
if (App::Instance()->IsTimeToReset(role_data.last_save_time)) {
|
|
OnDailyReset();
|
|
}
|
|
}
|
|
|
|
void Player::AddGuildApplyed(long long guild_id)
|
|
{
|
|
if (applyed_guild_hash_.size() < 100) {
|
|
applyed_guild_hash_[guild_id] = App::Instance()->nowtime;
|
|
}
|
|
}
|
|
|
|
void Player::RemoveGuildApplyed(long long guild_id)
|
|
{
|
|
applyed_guild_hash_.erase(guild_id);
|
|
}
|
|
|
|
const std::string Player::AccountId()
|
|
{
|
|
return myself.base_data.account_id;
|
|
}
|
|
|
|
const std::string Player::SessionId()
|
|
{
|
|
return role_data.session_id;
|
|
}
|
|
|
|
const std::string Player::NickName()
|
|
{
|
|
return myself.base_data.nickname;
|
|
}
|
|
|
|
const std::string Player::AvatarUrl()
|
|
{
|
|
return myself.base_data.avatar_url;
|
|
}
|
|
|
|
long long Player::GuildId()
|
|
{
|
|
return myself.base_data.guild_id;
|
|
}
|
|
|
|
int Player::VipLv()
|
|
{
|
|
return myself.base_data.vip_lv;
|
|
}
|
|
|
|
int Player::Head()
|
|
{
|
|
return myself.base_data.head;
|
|
}
|
|
|
|
int Player::Sex()
|
|
{
|
|
return myself.base_data.sex;
|
|
}
|
|
|
|
int Player::GuildJob()
|
|
{
|
|
return myself.base_data.guild_job;
|
|
}
|
|
|
|
int Player::GetFriendNum()
|
|
{
|
|
return friend_hash_.size();
|
|
}
|
|
|
|
long long Player::GetDBPrivateChatLastId()
|
|
{
|
|
return db_private_chat_last_id_;
|
|
}
|
|
|
|
long long Player::IncDBPrivateChatLastId()
|
|
{
|
|
++db_private_chat_last_id_;
|
|
MarkDirty();
|
|
return db_private_chat_last_id_;
|
|
}
|
|
|
|
void Player::InternalUpdateUserInfo()
|
|
{
|
|
ss::SS_IM_UpdateUserInfo ss_msg;
|
|
FillMFUserInfo(ss_msg.mutable_user_info());
|
|
MSConnMgr::Instance()->TraverseMSConn
|
|
(
|
|
[&ss_msg] (MSConn* conn)
|
|
{
|
|
conn->SendMsg(ss_msg);
|
|
return true;
|
|
}
|
|
);
|
|
IMConnMgr::Instance()->TraverseIMConn
|
|
(
|
|
[&ss_msg] (IMConn* conn)
|
|
{
|
|
conn->SendMsg(ss_msg);
|
|
return true;
|
|
}
|
|
);
|
|
NotifyUserInfoUpdate(&myself);
|
|
MarkDirty();
|
|
}
|
|
|
|
void Player::NotifyUserInfoUpdate(Friend* friend_data)
|
|
{
|
|
if (GetFriendById(friend_data->base_data.account_id) || friend_data == &myself) {
|
|
cs::SMUserInfoUpdate msg;
|
|
auto p = msg.add_user_infos();
|
|
TypeConvert::Convert(friend_data->base_data, *p->mutable_base_data());
|
|
TypeConvert::Convert(friend_data->temp_custom_data, *p->mutable_temp_custom_data());
|
|
{
|
|
int target_channel = f8::ExtractChannelIdFromAccountId
|
|
(p->base_data().account_id());
|
|
App::Instance()->PreProcAvatarUrl
|
|
(channel,
|
|
target_channel,
|
|
*p->mutable_base_data()->mutable_avatar_url());
|
|
}
|
|
SendMsg(msg);
|
|
}
|
|
}
|
|
|
|
void Player::PushFriendList()
|
|
{
|
|
cs::SMFriendList respmsg;
|
|
FillFriendList(respmsg.mutable_friend_list());
|
|
SendMsg(respmsg);
|
|
}
|
|
|
|
void Player::PushBlackList()
|
|
{
|
|
cs::SMFriendBlackList respmsg;
|
|
FillBlackList(respmsg.mutable_black_list());
|
|
SendMsg(respmsg);
|
|
}
|
|
|
|
void Player::SyncOtherFriend()
|
|
{
|
|
cs::SMUserInfoUpdate msg;
|
|
auto p = msg.add_user_infos();
|
|
TypeConvert::Convert(myself.base_data, *p->mutable_base_data());
|
|
TypeConvert::Convert(myself.temp_custom_data, *p->mutable_temp_custom_data());
|
|
{
|
|
int target_channel = f8::ExtractChannelIdFromAccountId
|
|
(p->base_data().account_id());
|
|
App::Instance()->PreProcAvatarUrl
|
|
(channel,
|
|
target_channel,
|
|
*p->mutable_base_data()->mutable_avatar_url());
|
|
}
|
|
|
|
for (auto& pair : friend_hash_) {
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(pair.second->base_data.account_id);
|
|
if (hum) {
|
|
Friend* friend_data = hum->GetFriendById(AccountId());
|
|
if (friend_data) {
|
|
list_head node_copy = friend_data->watch_node;
|
|
*friend_data = myself;
|
|
friend_data->watch_node = node_copy;
|
|
}
|
|
hum->SendMsg(msg);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Player::ProcessEventTimerFunc()
|
|
{
|
|
if (curr_max_event_idx_ >= DBEngine::Instance()->GetEventCurrIdx(myself.crc32_code)) {
|
|
return;
|
|
}
|
|
if (event_fetching_) {
|
|
return;
|
|
}
|
|
if (last_event_idx_ >= curr_max_event_idx_) {
|
|
curr_max_event_idx_ = DBEngine::Instance()->GetEventCurrIdx(myself.crc32_code);
|
|
}
|
|
if (last_event_idx_ >= curr_max_event_idx_) {
|
|
return;
|
|
}
|
|
|
|
auto on_ok =
|
|
[] (a8::XParams& param, const f8::DataSet* data_set)
|
|
{
|
|
std::string account_id = param.sender.GetString();
|
|
long long curr_max_event_idx = param.param1;
|
|
#if 0
|
|
long long last_event_idx = param.param2;
|
|
#endif
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(account_id);
|
|
if (hum) {
|
|
hum->event_fetching_ = false;
|
|
hum->last_event_idx_ = curr_max_event_idx;
|
|
hum->OnFetchEvent(data_set);
|
|
}
|
|
};
|
|
auto on_error =
|
|
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
|
{
|
|
std::string account_id = param.sender.GetString();
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(account_id);
|
|
if (hum) {
|
|
hum->event_fetching_ = false;
|
|
}
|
|
};
|
|
|
|
event_fetching_ = true;
|
|
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(myself.crc32_code);
|
|
DBEngine::Instance()->ExecAsyncQuery
|
|
(
|
|
conn_info,
|
|
"SELECT idx, sender_id, target_id, event_name, param1, param2, "
|
|
" param3, event_data, status, createtime "
|
|
"FROM `event` WHERE idx > %d AND idx <= %d AND target_id='%s' AND status=0;",
|
|
{
|
|
last_event_idx_,
|
|
curr_max_event_idx_,
|
|
myself.base_data.account_id
|
|
},
|
|
a8::XParams()
|
|
.SetSender(myself.base_data.account_id)
|
|
.SetParam1(curr_max_event_idx_)
|
|
.SetParam2(last_event_idx_),
|
|
on_ok,
|
|
on_error,
|
|
myself.crc32_code
|
|
);
|
|
}
|
|
|
|
void Player::OnFetchEvent(const f8::DataSet* data_set)
|
|
{
|
|
if (data_set) {
|
|
for (auto& row : *data_set) {
|
|
Event event;
|
|
event.idx = a8::XValue(row[0]);
|
|
event.sender_id = row[1];
|
|
event.target_id = row[2];
|
|
event.event_name = row[3];
|
|
event.param1 = row[4];
|
|
event.param2 = row[5];
|
|
event.param3 = row[6];
|
|
event.event_data = row[7];
|
|
event.status = a8::XValue(row[8]);
|
|
event.createtime = a8::XValue(row[9]);
|
|
event_hash_[event.idx] = event;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Player::ProcessEvent()
|
|
{
|
|
if (event_hash_.empty()) {
|
|
return;
|
|
}
|
|
std::vector<long long> processed_events;
|
|
processed_events.reserve(100);
|
|
for (auto& pair : event_hash_) {
|
|
if (processed_events.size() > 100) {
|
|
break;
|
|
}
|
|
Event& event = pair.second;
|
|
#ifdef DEBUG
|
|
a8::UdpLog::Instance()->Debug("event idx:%d event_name:%s sender_id:%s target_id:%s",
|
|
{
|
|
event.idx,
|
|
event.event_name,
|
|
event.sender_id,
|
|
event.target_id,
|
|
});
|
|
#endif
|
|
if (event.event_name == EVENT_FRIEND_AGREE) {
|
|
OnFriendAgreeEvent(event);
|
|
DBHelper::Instance()->SetEventStatus(event.idx, AccountId(), 1);
|
|
} else if (event.event_name == EVENT_FRIEND_DELETE) {
|
|
OnFriendDeleteEvent(event);
|
|
DBHelper::Instance()->SetEventStatus(event.idx, AccountId(), 1);
|
|
} else if (event.event_name == EVENT_GUILD_REFUSE) {
|
|
OnGuildRefuseEvent(event);
|
|
DBHelper::Instance()->SetEventStatus(event.idx, AccountId(), 1);
|
|
}
|
|
processed_events.push_back(pair.first);
|
|
}
|
|
for (long long event_id : processed_events) {
|
|
event_hash_.erase(event_id);
|
|
}
|
|
}
|
|
|
|
void Player::OnFriendAgreeEvent(Event& event)
|
|
{
|
|
if (GetFriendById(event.sender_id)) {
|
|
return;
|
|
}
|
|
if (!CanAddFriend(event.sender_id)) {
|
|
SyncHelper::Instance()->SyncDeleteFriend(this, event.sender_id, 0);
|
|
return;
|
|
}
|
|
Friend* friendobj = new Friend;
|
|
{
|
|
cs::MFUserInfo user_db;
|
|
user_db.ParseFromString(event.event_data);
|
|
TypeConvert::Convert(user_db.base_data(), friendobj->base_data);
|
|
}
|
|
QueryUserOnline({friendobj->base_data.account_id});
|
|
friendobj->base_data.account_id = event.sender_id;
|
|
AddFriend(friendobj);
|
|
}
|
|
|
|
void Player::OnFriendDeleteEvent(Event& event)
|
|
{
|
|
if (!GetFriendById(event.sender_id)) {
|
|
return;
|
|
}
|
|
RemoveFriend(event.sender_id, false);
|
|
}
|
|
|
|
void Player::OnGuildRefuseEvent(Event& event)
|
|
{
|
|
long long refuse_guild_id = a8::XValue(event.param1);
|
|
RemoveGuildApplyed(refuse_guild_id);
|
|
}
|
|
|
|
bool Player::CanAddFriend(const std::string& account_id)
|
|
{
|
|
if (GetFriendNum() >= MAX_FRIEND_NUM) {
|
|
return false;
|
|
}
|
|
if (GetFriendById(account_id)) {
|
|
return false;
|
|
}
|
|
int target_gameid = f8::ExtractGameIdFromAccountId(account_id);
|
|
if (target_gameid != gameid) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void Player::SyncRedPoint()
|
|
{
|
|
cs::SMUpdateRedPointNotify notifymsg;
|
|
notifymsg.set_red_point_flags(red_point_flags_);
|
|
SendMsg(notifymsg);
|
|
}
|
|
|
|
void Player::OnDailyReset()
|
|
{
|
|
role_data.today_apply_times = 0;
|
|
role_data.today_apply_guild_times = 0;
|
|
role_data.today_create_guild_times = 0;
|
|
}
|
|
|
|
void Player::RecalcRedPoint()
|
|
{
|
|
auto on_ok =
|
|
[] (a8::XParams& param, const f8::DataSet* data_set)
|
|
{
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(param.sender.GetString());
|
|
if (hum) {
|
|
if (data_set && data_set->size() > 0) {
|
|
a8::SetBitFlag(hum->red_point_flags_, RPF_FriendApply);
|
|
hum->SyncRedPoint();
|
|
}
|
|
}
|
|
};
|
|
auto on_error =
|
|
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
|
{
|
|
};
|
|
|
|
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(myself.crc32_code);
|
|
std::string fmtstr = "SELECT '' AS account_id";
|
|
std::vector<a8::XValue> sql_params;
|
|
{
|
|
for (auto& pair : black_hash_) {
|
|
fmtstr += " UNION SELECT '%s'";
|
|
sql_params.push_back(a8::XValue(pair.second->base_data.account_id));
|
|
}
|
|
sql_params.push_back(a8::XValue(last_apply_idx_));
|
|
sql_params.push_back(a8::XValue(myself.base_data.account_id));
|
|
}
|
|
DBEngine::Instance()->ExecAsyncQuery
|
|
(
|
|
conn_info,
|
|
(
|
|
"SELECT A.idx, A.applyid "
|
|
"FROM friend_apply A "
|
|
" LEFT JOIN (" + fmtstr + ") AS B ON B.account_id = A.sender_id "
|
|
"WHERE A.idx > %d AND A.target_id='%s' AND A.status=0 AND "
|
|
" B.account_id IS NULL LIMIT 1;"
|
|
).c_str(),
|
|
sql_params,
|
|
a8::XParams()
|
|
.SetSender(myself.base_data.account_id),
|
|
on_ok,
|
|
on_error,
|
|
myself.crc32_code
|
|
);
|
|
}
|
|
|
|
void Player::ClearApplyByIdx(long long idx)
|
|
{
|
|
auto itr = apply_hash_.find(idx);
|
|
if (itr != apply_hash_.end()) {
|
|
delete itr->second;
|
|
apply_hash_.erase(itr);
|
|
}
|
|
}
|
|
|
|
void Player::ClearApplyBySenderId(const std::string& sender_id)
|
|
{
|
|
std::vector<long long> deleted_applys;
|
|
for (auto& pair : apply_hash_) {
|
|
if (pair.second->base_data.account_id == sender_id) {
|
|
deleted_applys.push_back(pair.first);
|
|
}
|
|
}
|
|
for (auto idx : deleted_applys) {
|
|
ClearApplyByIdx(idx);
|
|
}
|
|
}
|
|
|
|
void Player::RefreshFriendData()
|
|
{
|
|
{
|
|
ss::SS_IM_QueryUserOnlineState msg;
|
|
for (auto& pair : friend_hash_) {
|
|
msg.add_account_ids(pair.second->base_data.account_id);
|
|
}
|
|
SendSSMsg(myself, msg);
|
|
}
|
|
a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
|
(
|
|
1000 * 3,
|
|
a8::XParams()
|
|
.SetSender(this),
|
|
[] (const a8::XParams& param)
|
|
{
|
|
Player* hum = (Player*)param.sender.GetUserData();
|
|
hum->QueryUserFromDB();
|
|
},
|
|
&timer_attacher.timer_list_
|
|
);
|
|
}
|
|
|
|
void Player::RemoveHandledApply()
|
|
{
|
|
std::vector<long long> handled_idxs;
|
|
for (auto& pair : apply_hash_) {
|
|
if (GetFriendById(pair.second->base_data.account_id)) {
|
|
handled_idxs.push_back(pair.first);
|
|
}
|
|
}
|
|
for (long long idx : handled_idxs) {
|
|
auto itr = apply_hash_.find(idx);
|
|
if (itr != apply_hash_.end()) {
|
|
auto& apply = itr->second;
|
|
DBHelper::Instance()->SetFriendApplyStatus
|
|
(
|
|
myself.crc32_code,
|
|
apply->idx,
|
|
apply->base_data.account_id,
|
|
AccountId(),
|
|
3
|
|
);
|
|
delete itr->second;
|
|
apply_hash_.erase(itr);
|
|
}
|
|
}
|
|
CombineRepeatApply();
|
|
}
|
|
|
|
void Player::CombineRepeatApply()
|
|
{
|
|
std::map<std::string, std::vector<FriendApply*>> num_hash;
|
|
for (auto& pair : apply_hash_) {
|
|
auto itr = num_hash.find(pair.second->base_data.account_id);
|
|
if (itr != num_hash.end()) {
|
|
itr->second.push_back(pair.second);
|
|
} else {
|
|
num_hash[pair.second->base_data.account_id] = std::vector<FriendApply*>({pair.second});
|
|
}
|
|
}
|
|
for (auto& pair : num_hash) {
|
|
for (size_t i = 0; i + 1 < pair.second.size(); ++i) {
|
|
pair.second[i]->flag = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Player::QueryUserOnline(std::vector<std::string> account_ids)
|
|
{
|
|
ss::SS_IM_QueryUserOnlineState msg;
|
|
for (auto& account_id : account_ids) {
|
|
msg.add_account_ids(account_id);
|
|
}
|
|
SendSSMsg(myself, msg);
|
|
}
|
|
|
|
void Player::QueryUserFromDB()
|
|
{
|
|
auto on_ok =
|
|
[] (a8::XParams& param, const f8::DataSet* data_set)
|
|
{
|
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(param.sender.GetString());
|
|
if (hum && data_set && !data_set->empty()) {
|
|
for (auto& row : *data_set) {
|
|
std::string account_id = row[0];
|
|
std::string nickname = row[1];
|
|
std::string avatar_url = row[2];
|
|
int sex = a8::XValue(row[3]);
|
|
long long data_version1 = a8::XValue(row[4]);
|
|
long long user_value1 = a8::XValue(row[5]);
|
|
long long user_value2 = a8::XValue(row[6]);
|
|
long long user_value3 = a8::XValue(row[7]);
|
|
long long last_login_time = a8::XValue(row[8]);
|
|
Friend* friend_data = hum->GetFriendById(account_id);
|
|
if (friend_data && friend_data->base_data.base_data_version != data_version1) {
|
|
friend_data->base_data.nickname = nickname;
|
|
friend_data->base_data.avatar_url = avatar_url;
|
|
friend_data->base_data.sex = sex;
|
|
friend_data->base_data.base_data_version = data_version1;
|
|
friend_data->base_data.user_value1 = user_value1;
|
|
friend_data->base_data.user_value2 = user_value2;
|
|
friend_data->base_data.user_value3 = user_value3;
|
|
friend_data->base_data.last_login_time = last_login_time;
|
|
hum->NotifyUserInfoUpdate(friend_data);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
auto on_error =
|
|
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
|
{
|
|
};
|
|
|
|
for (auto& pair : friend_hash_) {
|
|
Friend* friend_data = pair.second;
|
|
if (!friend_data->base_data.online) {
|
|
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(friend_data->crc32_code);
|
|
DBEngine::Instance()->ExecAsyncQuery
|
|
(
|
|
conn_info,
|
|
"SELECT account_id, nickname, avatar_url, sex, "
|
|
" data_version1, user_value1, user_value2, user_value3, last_logintime "
|
|
"FROM `user` WHERE account_id='%s';",
|
|
{
|
|
friend_data->base_data.account_id
|
|
},
|
|
a8::XParams()
|
|
.SetSender(myself.base_data.account_id)
|
|
.SetParam1(friend_data->base_data.account_id),
|
|
on_ok,
|
|
on_error,
|
|
friend_data->crc32_code
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Player::ShowErrorMsg(const std::string& msg)
|
|
{
|
|
cs::SMShowErrorMsg notifymsg;
|
|
notifymsg.set_msg(msg);
|
|
SendMsg(notifymsg);
|
|
}
|
|
|
|
void Player::InternalRemoveFriend(const std::string& account_id, bool need_sync, bool auto_delete)
|
|
{
|
|
Friend* friendobj = GetFriendById(account_id);
|
|
if (friendobj) {
|
|
{
|
|
cs::SMDeleteFriendNotify notifymsg;
|
|
notifymsg.add_user_list(account_id);
|
|
SendMsg(notifymsg);
|
|
}
|
|
if (need_sync) {
|
|
SyncHelper::Instance()->SyncDeleteFriend(this, friendobj->base_data.account_id, 0);
|
|
}
|
|
PlayerMgr::Instance()->UnWatchPlayer(friendobj);
|
|
friend_hash_.erase(account_id);
|
|
if (auto_delete) {
|
|
delete friendobj;
|
|
}
|
|
MarkDirty();
|
|
}
|
|
}
|
|
|
|
void Player::SyncGuildMemberInfo()
|
|
{
|
|
ss::SS_IM_RefeshGuildMemberInfo msg;
|
|
FillIMMsgConext(msg.mutable_context());
|
|
SendGSMsg(msg);
|
|
}
|
|
|
|
void Player::SyncGuildRedPoint()
|
|
{
|
|
if (GuildId() != 0 && (GuildJob() == kGuildOwner || GuildJob() == kGuildAdmin)) {
|
|
ss::SS_IM_GuildRecalcRedPoint msg;
|
|
FillIMMsgConext(msg.mutable_context());
|
|
msg.set_guild_id(GuildId());
|
|
SendGSMsg(msg);
|
|
}
|
|
}
|
|
|
|
void Player::SyncGuildNewApply(long long guild_id)
|
|
{
|
|
ss::SS_IM_GuildNewApply msg;
|
|
FillIMMsgConext(msg.mutable_context());
|
|
msg.set_guild_id(guild_id);
|
|
SyncHelper::Instance()->SendIMConnMsg(
|
|
JsonDataMgr::Instance()->GetIMInstanceId(guild_id),
|
|
ss::SSMessageId_e::_SS_IM_GuildNewApply,
|
|
msg);
|
|
}
|
|
|
|
bool Player::IsValidChatChannel(int chat_channel)
|
|
{
|
|
if (chat_channel > kCCBegin && chat_channel < kCCEnd) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void Player::SyncPrivateChatRedPoint()
|
|
{
|
|
cs::SMUpdatePrivateChatRedPointNotify msg;
|
|
ChatMgr::Instance()->FillSMUpdatePrivateChatRedPointNotify(this, msg);
|
|
}
|