1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/lsylovews-CM-Server

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
logictalk.cpp 1.4 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
lsylovews Отправлено 22.02.2019 15:22 e234e9a
#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);
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/lsylovews-CM-Server.git
git@api.gitlife.ru:oschina-mirror/lsylovews-CM-Server.git
oschina-mirror
lsylovews-CM-Server
lsylovews-CM-Server
master