19 Star 44 Fork 32

留天下 / CM-Server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
logictalk.cpp 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
留天下 提交于 2019-02-22 13:22 . net redo done!
#include "logictalk.h"
#include"networkmanager.h"
#include"messageconst.h"
DEFINE_SINGLE_ATTRIBUTES(LogicTalk);
LogicTalk::LogicTalk()
{
NET_INSTANCE()->add(MESSAGE_WORLD_TALK,handler(this,SEL_EVENTFUNC(LogicTalk::c2sWorldTalk)));
NET_INSTANCE()->add(MESSAGE_PRIVATE_TALK,handler(this,SEL_EVENTFUNC(LogicTalk::c2sPrivateTalk)));
}
void LogicTalk::c2sWorldTalk(Json::Value& msg)
{
cout<<"LogicTalk::c2sWorldTalk"<<msg.toStyledString()<<endl;
int fd=NET_INSTANCE()->getFd();
auto& playermaps= NET_SOCKET().m_playermaps;
cout<<playermaps[fd].rolename<<" in the world say: "<<msg["msg"].asString()<<endl;
msg["fd"]=fd;
for(auto var:playermaps)
{
if(var.first==fd)
msg["fd"]=-1;
NET_INSTANCE()->send(var.first,MESSAGE_WORLD_TALK,msg);
//write(var.first,(char*)msg,sizeof(WorldTalk_Msg));
}
}
void LogicTalk::c2sPrivateTalk(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps= NET_SOCKET().m_playermaps;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
msg["fd"]=fd;
cout<<playermaps[fd].rolename<<" say "<<msg["msg"].asString()<<" to "<<playermaps[dest].rolename<<endl;
NET_INSTANCE()->send(dest,MESSAGE_PRIVATE_TALK,msg);
//write(msg->dest,(char*)msg,sizeof(PrivateTalk_Msg));
}
msg["fd"]=-1;
NET_INSTANCE()->send(fd,MESSAGE_PRIVATE_TALK,msg);
}
C++
1
https://gitee.com/lsylovews/CM-Server.git
git@gitee.com:lsylovews/CM-Server.git
lsylovews
CM-Server
CM-Server
master

搜索帮助