19 Star 44 Fork 32

留天下 / CM-Server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
logicteam.cpp 4.12 KB
一键复制 编辑 原始数据 按行查看 历史
留天下 提交于 2019-03-17 12:48 . 修改
#include "logicteam.h"
#include"networkmanager.h"
#include"messageconst.h"
DEFINE_SINGLE_ATTRIBUTES(LogicTeam);
LogicTeam::LogicTeam()
{
NET_INSTANCE()->add(MESSAGE_TEAM_APPLY,handler(this,SEL_EVENTFUNC(LogicTeam::c2sTeamApply)));
NET_INSTANCE()->add(MESSAGE_AGREE_TEAM,handler(this,SEL_EVENTFUNC(LogicTeam::c2sAgreeTeam)));
NET_INSTANCE()->add(MESSAGE_DISSOLVE_TEAM,handler(this,SEL_EVENTFUNC(LogicTeam::c2sDissolveTeam)));
NET_INSTANCE()->add(MESSAGE_REFUSE_TEAM,handler(this,SEL_EVENTFUNC(LogicTeam::c2sRefuseTeam)));
NET_INSTANCE()->add(MESSAGE_TEAM_FIGHT,handler(this,SEL_EVENTFUNC(LogicTeam::c2sTeamFight)));
NET_INSTANCE()->add(MESSAGE_TEAM_GOTO_MAP,handler(this,SEL_EVENTFUNC(LogicTeam::c2sTeamGotoMap)));
NET_INSTANCE()->add(MESSAGE_TEAM_MOVE,handler(this,SEL_EVENTFUNC(LogicTeam::c2sTeamMove)));
}
void LogicTeam::c2sTeamApply(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<playermaps[fd].rolename<<" apply to make a team with "<<playermaps[dest].rolename<<endl;
NET_INSTANCE()->send(dest,MESSAGE_TEAM_APPLY,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(TeamApply_Msg));
}
}
void LogicTeam::c2sRefuseTeam(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<playermaps[fd].rolename<<" refused "<<playermaps[dest].rolename<<" team apply"<<endl;
NET_INSTANCE()->send(dest,MESSAGE_REFUSE_TEAM,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(RefuseTeam_Msg));
}
}
void LogicTeam::c2sAgreeTeam(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<playermaps[fd].rolename<<" agree "<<playermaps[dest].rolename<<" team apply"<<endl;
NET_INSTANCE()->send(dest,MESSAGE_AGREE_TEAM,msg);
// SendMsg(msg->dest,(char*)msg,sizeof(AgreeTeam_Msg));
}
}
void LogicTeam::c2sTeamMove(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<playermaps[fd].rolename<<" team header move "<<playermaps[dest].rolename<<" to ("<<msg["x"].asFloat()<<","<<msg["y"].asFloat()<<")"<<endl;
NET_INSTANCE()->send(dest,MESSAGE_TEAM_MOVE,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(TeamMove_Msg));
}
}
void LogicTeam::c2sTeamGotoMap(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())
{
cout<<playermaps[fd].rolename<<" team header move "<<playermaps[dest].rolename<<" to "<<msg["map"].asString()<<endl;
NET_INSTANCE()->send(dest,MESSAGE_TEAM_GOTO_MAP,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(TeamGotoMap_Msg));
}
}
void LogicTeam::c2sDissolveTeam(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<"Dissolve Team "<<playermaps[fd].rolename<<" and "<<playermaps[dest].rolename<<endl;
NET_INSTANCE()->send(dest,MESSAGE_DISSOLVE_TEAM,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(TeamManage_Msg));
}
}
void LogicTeam::c2sTeamFight(Json::Value& msg)
{
int fd=NET_INSTANCE()->getFd();
auto& playermaps=NET_SOCKET().m_playermaps;
msg["fd"]=fd;
int dest=msg["dest"].asInt();
if(playermaps.find(dest)!=playermaps.end())
{
cout<<playermaps[fd].rolename<<" leader "<<playermaps[dest].rolename<<" entry fight"<<endl;
NET_INSTANCE()->send(dest,MESSAGE_TEAM_FIGHT,msg);
//SendMsg(msg->dest,(char*)msg,sizeof(TeamFight_Msg));
}
}
C++
1
https://gitee.com/lsylovews/CM-Server.git
git@gitee.com:lsylovews/CM-Server.git
lsylovews
CM-Server
CM-Server
master

搜索帮助