1 Star 0 Fork 32

MichaelFeng/CM-Server

forked from 留天下/CM-Server 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
friendlogic.cpp 2.90 KB
一键复制 编辑 原始数据 按行查看 历史
留天下 提交于 2019-03-17 12:48 . 修改
#include "friendlogic.h"
#include"networkmanager.h"
#include"messageconst.h"
DEFINE_SINGLE_ATTRIBUTES(FriendLogic);
FriendLogic::FriendLogic()
{
NET_INSTANCE()->add(MESSAGE_REJECT_FRIEND,handler(this,SEL_EVENTFUNC(FriendLogic::c2sRejectFriend)));
NET_INSTANCE()->add(MESSAGE_DEL_FRIEND,handler(this,SEL_EVENTFUNC(FriendLogic::c2sDelFriend)));
NET_INSTANCE()->add(MESSAGE_APPLY_FRIEND,handler(this,SEL_EVENTFUNC(FriendLogic::c2sApplyFriend)));
NET_INSTANCE()->add(MESSAGE_AGREE_FRIEND,handler(this,SEL_EVENTFUNC(FriendLogic::c2sAgreeFriend)));
}
void FriendLogic::c2sApplyFriend(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
std::string rolename=msg["rolename"].asString();
for(auto var:playermaps)
{
if(var.second.rolename==rolename)
{
auto info=playermaps[fd];
msg.clear();
msg["playername"]=info.playername;
msg["rolename"]=info.rolename;
msg["playertype"]=info.playertype;
msg["grade"]=info.grade;
NET_INSTANCE()->send(var.first,MESSAGE_APPLY_FRIEND,msg);
}
}
}
void FriendLogic::c2sAgreeFriend(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
std::string rolename=msg["rolename"].asString();
for(auto var:playermaps)
{
if(var.second.rolename==rolename)
{
auto info=playermaps[fd];
msg.clear();
msg["playername"]=info.playername;
msg["rolename"]=info.rolename;
msg["playertype"]=info.playertype;
msg["grade"]=info.grade;
NET_INSTANCE()->send(var.first,MESSAGE_AGREE_FRIEND,msg);
}
}
}
void FriendLogic::c2sRejectFriend(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
std::string rolename=msg["rolename"].asString();
for(auto var:playermaps)
{
if(var.second.rolename==rolename)
{
auto info=playermaps[fd];
msg.clear();
msg["playername"]=info.playername;
msg["rolename"]=info.rolename;
msg["playertype"]=info.playertype;
msg["grade"]=info.grade;
NET_INSTANCE()->send(var.first,MESSAGE_REJECT_FRIEND,msg);
}
}
}
void FriendLogic::c2sDelFriend(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
std::string rolename=msg["rolename"].asString();
for(auto var:playermaps)
{
if(var.second.rolename==rolename)
{
auto info=playermaps[fd];
msg.clear();
msg["playername"]=info.playername;
msg["rolename"]=info.rolename;
msg["playertype"]=info.playertype;
msg["grade"]=info.grade;
NET_INSTANCE()->send(var.first,MESSAGE_DEL_FRIEND,msg);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/michael_fengjun/CM-Server.git
git@gitee.com:michael_fengjun/CM-Server.git
michael_fengjun
CM-Server
CM-Server
master

搜索帮助