349 lines
8.0 KiB
C++
349 lines
8.0 KiB
C++
#include "UserInGameServer.h"
|
|
#include "UserInfo.h"
|
|
|
|
UserInGameServer::UserInGameServer()
|
|
{
|
|
mMissionType = 0;
|
|
mMissionParameter = 0;
|
|
m_pInGameServerInfoSink = nullptr;
|
|
|
|
zeromemory(&m_GetUnionRoomInfo, sizeof(m_GetUnionRoomInfo));
|
|
}
|
|
|
|
UserInGameServer::~UserInGameServer()
|
|
{
|
|
|
|
}
|
|
|
|
// 设置回调接口
|
|
void UserInGameServer::setMissionSink(IUserInGameServerSink* pSink)
|
|
{
|
|
m_pInGameServerInfoSink = pSink;
|
|
}
|
|
|
|
//网络连接
|
|
void UserInGameServer::onEventTCPSocketLink()
|
|
{
|
|
switch (mMissionType)
|
|
{
|
|
case SUB_GP_QUERY_INGAME_SEVERID:
|
|
CB_InGameServerID(mMissionParameter);
|
|
break;
|
|
case SUB_GP_GET_ONLINE:
|
|
CB_GetServerOnLine();
|
|
break;
|
|
case SUB_GP_QUERY_IN_UNION:
|
|
CB_InUnion(mMissionParameter);
|
|
break;
|
|
case SUB_GP_GET_UNION_LIST:
|
|
CB_GetUnionList(mMissionParameter);
|
|
break;
|
|
case SUB_GP_GET_UNION_ROOM_LIST:
|
|
//CB_GetUnionRoomList(mMissionParameter);
|
|
CB_GetUnionRoomList(&m_GetUnionRoomInfo);
|
|
break;
|
|
case SUB_GP_GET_AUTO_ROOM_LIST:
|
|
CB_GetAutoRoomList(mMissionParameter);
|
|
break;
|
|
}
|
|
}
|
|
|
|
//网络关闭
|
|
void UserInGameServer::onEventTCPSocketShut()
|
|
{
|
|
|
|
}
|
|
|
|
//网络错误
|
|
void UserInGameServer::onEventTCPSocketError(int errorCode)
|
|
{
|
|
|
|
}
|
|
|
|
//网络消息读取
|
|
bool UserInGameServer::onEventTCPSocketRead(int main, int sub, void* data, int dataSize)
|
|
{
|
|
switch (main)
|
|
{
|
|
//登录消息
|
|
case MDM_GP_USER_SERVICE:
|
|
{
|
|
if (sub == SUB_GP_QUERY_INGAME_SEVERID)
|
|
{
|
|
Net_InGameServerID(data, dataSize);
|
|
}
|
|
else if (sub == SUB_GP_QUERY_IN_UNION)
|
|
{
|
|
Net_InUnion(data, dataSize);
|
|
}
|
|
else if (sub == SUB_GP_GET_UNION_LIST)
|
|
{
|
|
Net_UnionList(data, dataSize);
|
|
}
|
|
else if (sub == SUB_GP_GET_UNION_ROOM_LIST)
|
|
{
|
|
Net_UnionRoomList(data, dataSize);
|
|
}
|
|
else if (sub == SUB_GP_GET_AUTO_ROOM_LIST)
|
|
{
|
|
Net_AutoRoomList(data, dataSize);
|
|
}
|
|
break;
|
|
}
|
|
//用户信息
|
|
case MDM_GP_SERVER_LIST:
|
|
{
|
|
if (sub == SUB_GR_KINE_ONLINE)
|
|
{
|
|
onSocketKindOnline(data, dataSize);
|
|
}
|
|
else if (sub == SUB_GR_SERVER_ONLINE)
|
|
{
|
|
onSocketServerOnline(data, dataSize);
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void UserInGameServer::PerformInGameServerID(int iUserID)
|
|
{
|
|
mMissionType = SUB_GP_QUERY_INGAME_SEVERID;
|
|
mMissionParameter = iUserID;
|
|
start();
|
|
}
|
|
|
|
void UserInGameServer::GetServerOnLine()
|
|
{
|
|
mMissionType = SUB_GP_GET_ONLINE;
|
|
start();
|
|
}
|
|
|
|
void UserInGameServer::CB_InGameServerID(int iUserID)
|
|
{
|
|
CMD_GP_UserInGameServerID kNetInfo;
|
|
kNetInfo.dwUserID = iUserID;
|
|
send(MDM_GP_USER_SERVICE, SUB_GP_QUERY_INGAME_SEVERID, &kNetInfo, sizeof(kNetInfo));
|
|
}
|
|
|
|
void UserInGameServer::CB_GetServerOnLine()
|
|
{
|
|
CServerListData * pServerListData = CServerListData::shared();
|
|
if (pServerListData != nullptr)
|
|
{
|
|
CMD_GP_GetOnline GetOnline;
|
|
zeromemory(&GetOnline, sizeof(GetOnline));
|
|
|
|
// 获取serverid
|
|
CGameServerItem* pMinPlayerCoutServer = NULL;
|
|
CGameServerItemMap::iterator itor = pServerListData->GetServerItemMapBegin();
|
|
CGameServerItem* pListItem = pServerListData->EmunGameServerItem(itor);
|
|
|
|
while (pListItem != NULL)
|
|
{
|
|
CGameServerItem* pActListItem = pListItem;
|
|
pListItem = pServerListData->EmunGameServerItem(itor);
|
|
GetOnline.wOnLineServerID[GetOnline.wServerCount++] = pActListItem->m_GameServer.wServerID;
|
|
}
|
|
|
|
WORD wSendSize = sizeof(GetOnline.wServerCount) + GetOnline.wServerCount*sizeof(GetOnline.wOnLineServerID[0]);
|
|
send(MDM_GP_SERVER_LIST, SUB_GP_GET_ONLINE, &GetOnline, wSendSize);
|
|
}
|
|
}
|
|
|
|
void UserInGameServer::Net_InGameServerID(void* data, int dataSize)
|
|
{
|
|
ASSERT(dataSize == sizeof(CMD_GP_InGameSeverID));
|
|
if (dataSize != sizeof(CMD_GP_InGameSeverID)) return;
|
|
|
|
CMD_GP_InGameSeverID* pNetInfo = (CMD_GP_InGameSeverID*)data;
|
|
|
|
if (m_pInGameServerInfoSink)
|
|
{
|
|
m_pInGameServerInfoSink->onUserInGameServerID(pNetInfo);
|
|
}
|
|
|
|
stop();
|
|
}
|
|
|
|
// 在线更新完成
|
|
bool UserInGameServer::onSocketKindOnline(void* data, int size)
|
|
{
|
|
|
|
return true;
|
|
}
|
|
|
|
//房间在线
|
|
bool UserInGameServer::onSocketServerOnline(void* data, int wDataSize)
|
|
{
|
|
//变量定义
|
|
CMD_GP_ServerOnline * pServerOnline = (CMD_GP_ServerOnline *)data;
|
|
WORD wHeadSize = sizeof(pServerOnline->wServerCount);
|
|
|
|
//效验数据
|
|
ASSERT((wDataSize >= wHeadSize) && (wDataSize == (wHeadSize + pServerOnline->wServerCount*sizeof(tagOnLineInfoServer))));
|
|
if ((wDataSize < wHeadSize) || (wDataSize != (wHeadSize + pServerOnline->wServerCount*sizeof(tagOnLineInfoServer)))) return false;
|
|
|
|
CServerListData * pServerListData = CServerListData::shared();
|
|
if (pServerListData == nullptr) return false;
|
|
|
|
//获取房间
|
|
for (WORD i = 0; i < pServerOnline->wServerCount; i++)
|
|
{
|
|
//获取房间
|
|
WORD wServerID = pServerOnline->OnLineInfoServer[i].wServerID;
|
|
uint32 dwOnLineCount = pServerOnline->OnLineInfoServer[i].dwOnLineCount;
|
|
pServerListData->SetServerOnLineCount(wServerID, dwOnLineCount);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/********************************** 是否在工会 *****************************/
|
|
void UserInGameServer::PerformInUnion(int dwUnionCode)
|
|
{
|
|
mMissionType = SUB_GP_QUERY_IN_UNION;
|
|
mMissionParameter = dwUnionCode;
|
|
start();
|
|
}
|
|
|
|
void UserInGameServer::CB_InUnion(int dwUnionCode)
|
|
{
|
|
CMD_GP_UserInUnion kNetInfo;
|
|
kNetInfo.dwUserID = UserInfo::Instance().getUserID();
|
|
kNetInfo.dwUnionCode = dwUnionCode;
|
|
send(MDM_GP_USER_SERVICE, SUB_GP_QUERY_IN_UNION, &kNetInfo, sizeof(kNetInfo));
|
|
}
|
|
|
|
void UserInGameServer::Net_InUnion(void* data, int dataSize)
|
|
{
|
|
ASSERT(dataSize == sizeof(CMD_GP_InUnion));
|
|
if (dataSize != sizeof(CMD_GP_InUnion)) return;
|
|
|
|
CMD_GP_InUnion* pNetInfo = (CMD_GP_InUnion*)data;
|
|
|
|
if (m_pInGameServerInfoSink)
|
|
{
|
|
m_pInGameServerInfoSink->onUserInUnion(pNetInfo);
|
|
}
|
|
|
|
stop();
|
|
}
|
|
|
|
// 获取工会列表;
|
|
void UserInGameServer::PerformGetUnionList(int iUserID)
|
|
{
|
|
mMissionType = SUB_GP_GET_UNION_LIST;
|
|
mMissionParameter = iUserID;
|
|
start();
|
|
}
|
|
|
|
void UserInGameServer::CB_GetUnionList(int iUserID)
|
|
{
|
|
CMD_GP_GetUnionList kNetInfo;
|
|
kNetInfo.dwUserID = UserInfo::Instance().getUserID();
|
|
send(MDM_GP_USER_SERVICE, SUB_GP_GET_UNION_LIST, &kNetInfo, sizeof(kNetInfo));
|
|
}
|
|
|
|
bool UserInGameServer::Net_UnionList(void* data, int dataSize)
|
|
{
|
|
if (dataSize <= 0) return true;
|
|
|
|
DataStream kDataStream(data, dataSize);
|
|
tagUnionAndGameList kNetInfo;
|
|
kNetInfo.StreamValue(kDataStream, false);
|
|
|
|
if (m_pInGameServerInfoSink)
|
|
{
|
|
m_pInGameServerInfoSink->onUnionAndGameInfo(&kNetInfo);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// 获取工会房间列表;
|
|
void UserInGameServer::PerformGetUnionRoomList(int iUserID)
|
|
{
|
|
mMissionType = SUB_GP_GET_UNION_ROOM_LIST;
|
|
mMissionParameter = iUserID;
|
|
start();
|
|
}
|
|
|
|
void UserInGameServer::CB_GetUnionRoomList(int iUserID)
|
|
{
|
|
//CMD_GP_GetUnionList kNetInfo;
|
|
//kNetInfo.dwUserID = UserInfo::Instance().getUserID();
|
|
//send(MDM_GP_USER_SERVICE, SUB_GP_GET_UNION_ROOM_LIST, &kNetInfo, sizeof(kNetInfo));
|
|
}
|
|
|
|
void UserInGameServer::PerformGetUnionRoomList(CMD_GR_GetUnionRoomInfo* pkSendNet)
|
|
{
|
|
if (pkSendNet == nullptr) return;
|
|
|
|
CopyMemory(&m_GetUnionRoomInfo, pkSendNet, sizeof(CMD_GR_GetUnionRoomInfo));
|
|
mMissionType = SUB_GP_GET_UNION_ROOM_LIST;
|
|
start();
|
|
}
|
|
|
|
void UserInGameServer::CB_GetUnionRoomList(CMD_GR_GetUnionRoomInfo* pkSendNet)
|
|
{
|
|
CMD_GR_GetUnionRoomInfo kNetInfo;
|
|
kNetInfo.dwUserID = pkSendNet->dwUserID;
|
|
kNetInfo.dwUnionCode = pkSendNet->dwUnionCode;
|
|
send(MDM_GP_USER_SERVICE, SUB_GP_GET_UNION_ROOM_LIST, &kNetInfo, sizeof(kNetInfo));
|
|
}
|
|
|
|
bool UserInGameServer::Net_UnionRoomList(void* data, int dataSize)
|
|
{
|
|
if (dataSize <= 0) return true;
|
|
|
|
DataStream kDataStream(data, dataSize);
|
|
tagRoomItemList kNetInfo;
|
|
kNetInfo.StreamValue(kDataStream, false);
|
|
|
|
if (m_pInGameServerInfoSink)
|
|
{
|
|
m_pInGameServerInfoSink->onUnionRoomInfo(&kNetInfo);
|
|
}
|
|
|
|
stop();
|
|
|
|
return true;
|
|
}
|
|
|
|
// 获取自动房间列表;
|
|
void UserInGameServer::PerformGetAutoRoomList(int iUserID)
|
|
{
|
|
mMissionType = SUB_GP_GET_AUTO_ROOM_LIST;
|
|
mMissionParameter = iUserID;
|
|
start();
|
|
}
|
|
|
|
void UserInGameServer::CB_GetAutoRoomList(int iUserID)
|
|
{
|
|
CMD_GP_GetUnionList kNetInfo;
|
|
kNetInfo.dwUserID = UserInfo::Instance().getUserID();
|
|
send(MDM_GP_USER_SERVICE, SUB_GP_GET_AUTO_ROOM_LIST, &kNetInfo, sizeof(kNetInfo));
|
|
}
|
|
|
|
bool UserInGameServer::Net_AutoRoomList(void* data, int dataSize)
|
|
{
|
|
stop();
|
|
|
|
if (dataSize <= 0) return true;
|
|
|
|
DataStream kDataStream(data, dataSize);
|
|
tagAutoRoomItemList kNetInfo;
|
|
kNetInfo.StreamValue(kDataStream, false);
|
|
|
|
if (m_pInGameServerInfoSink)
|
|
{
|
|
m_pInGameServerInfoSink->onAutoRoomInfo(&kNetInfo);
|
|
}
|
|
|
|
return true;
|
|
} |