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()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ûص<C3BB><D8B5>ӿ<EFBFBD>
|
|||
|
|
void UserInGameServer::setMissionSink(IUserInGameServerSink* pSink)
|
|||
|
|
{
|
|||
|
|
m_pInGameServerInfoSink = pSink;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>
|
|||
|
|
void UserInGameServer::onEventTCPSocketShut()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void UserInGameServer::onEventTCPSocketError(int errorCode)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ȡ
|
|||
|
|
bool UserInGameServer::onEventTCPSocketRead(int main, int sub, void* data, int dataSize)
|
|||
|
|
{
|
|||
|
|
switch (main)
|
|||
|
|
{
|
|||
|
|
//<2F><>¼<EFBFBD><C2BC>Ϣ
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
//<2F>û<EFBFBD><C3BB><EFBFBD>Ϣ
|
|||
|
|
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));
|
|||
|
|
|
|||
|
|
// <20><>ȡ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();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>߸<EFBFBD><DFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
bool UserInGameServer::onSocketKindOnline(void* data, int size)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
bool UserInGameServer::onSocketServerOnline(void* data, int wDataSize)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
CMD_GP_ServerOnline * pServerOnline = (CMD_GP_ServerOnline *)data;
|
|||
|
|
WORD wHeadSize = sizeof(pServerOnline->wServerCount);
|
|||
|
|
|
|||
|
|
//Ч<><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
for (WORD i = 0; i < pServerOnline->wServerCount; i++)
|
|||
|
|
{
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
WORD wServerID = pServerOnline->OnLineInfoServer[i].wServerID;
|
|||
|
|
uint32 dwOnLineCount = pServerOnline->OnLineInfoServer[i].dwOnLineCount;
|
|||
|
|
pServerListData->SetServerOnLineCount(wServerID, dwOnLineCount);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/********************************** <20>Ƿ<EFBFBD><C7B7>ڹ<EFBFBD><DAB9><EFBFBD> *****************************/
|
|||
|
|
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();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>;
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>᷿<EFBFBD><E1B7BF><EFBFBD>б<EFBFBD>;
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>;
|
|||
|
|
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;
|
|||
|
|
}
|