Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from ylmbtm:master #80

Merged
merged 2 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 145 additions & 145 deletions Server/Src/LogicServer/PlayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

CPlayerManager::CPlayerManager()
{
m_dwMaxCacheNum = CConfigFile::GetInstancePtr()->GetIntValue("max_cache_num");
if (m_dwMaxCacheNum <= 10)
{
m_dwMaxCacheNum = 3000;
}
TimerManager::GetInstancePtr()->AddFixTimer(0, 1, &CPlayerManager::ZeroTimer, this);
m_dwMaxCacheNum = CConfigFile::GetInstancePtr()->GetIntValue("max_cache_num");
if (m_dwMaxCacheNum <= 10)
{
m_dwMaxCacheNum = 3000;
}
TimerManager::GetInstancePtr()->AddFixTimer(0, 1, &CPlayerManager::ZeroTimer, this);
}

CPlayerManager::~CPlayerManager()
Expand All @@ -22,195 +22,195 @@ CPlayerManager::~CPlayerManager()

CPlayerManager* CPlayerManager::GetInstancePtr()
{
static CPlayerManager _PlayerManager;
static CPlayerManager _PlayerManager;

return &_PlayerManager;
return &_PlayerManager;
}

CPlayerObject* CPlayerManager::CreatePlayer(UINT64 u64RoleID)
{
CPlayerObject* pPlayer = CreatePlayerByID(u64RoleID);
return pPlayer;
CPlayerObject* pPlayer = CreatePlayerByID(u64RoleID);
return pPlayer;
}

CPlayerObject* CPlayerManager::GetPlayer( UINT64 u64RoleID )
{
return GetByKey(u64RoleID);
return GetByKey(u64RoleID);
}

CPlayerObject* CPlayerManager::CreatePlayerByID( UINT64 u64RoleID )
{
return InsertAlloc(u64RoleID);
return InsertAlloc(u64RoleID);
}

INT32 CPlayerManager::GetOnlineCount()
{
TNodeTypePtr pNode = MoveFirst();
if (pNode == NULL)
{
return 0;
}

INT32 nCount = 0;
CPlayerObject* pTempObj = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pTempObj = pNode->GetValue();
if (pTempObj == NULL)
{
continue;
}

if (!pTempObj->IsOnline())
{
continue;
}

nCount++;
}

return nCount;
TNodeTypePtr pNode = MoveFirst();
if (pNode == NULL)
{
return 0;
}

INT32 nCount = 0;
CPlayerObject* pTempObj = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pTempObj = pNode->GetValue();
if (pTempObj == NULL)
{
continue;
}

if (!pTempObj->IsOnline())
{
continue;
}

nCount++;
}

return nCount;
}

BOOL CPlayerManager::ReleasePlayer( UINT64 u64RoleID )
{
CPlayerObject* pPlayer = GetByKey(u64RoleID);
CPlayerObject* pPlayer = GetByKey(u64RoleID);

ERROR_RETURN_FALSE(pPlayer != NULL);
ERROR_RETURN_FALSE(pPlayer != NULL);

pPlayer->Uninit();
pPlayer->Uninit();

return Delete(u64RoleID);
return Delete(u64RoleID);
}

BOOL CPlayerManager::BroadMessageToAll(UINT32 dwMsgID, const google::protobuf::Message& pdata)
{
char szBuff[10240] = { 0 };
ERROR_RETURN_FALSE(pdata.ByteSize() < 10240);
ERROR_RETURN_FALSE(pdata.SerializePartialToArray(szBuff, pdata.ByteSize()));
char szBuff[10240] = { 0 };
ERROR_RETURN_FALSE(pdata.ByteSize() < 10240);
ERROR_RETURN_FALSE(pdata.SerializePartialToArray(szBuff, pdata.ByteSize()));

BroadMessageNotify Nty;
Nty.set_msgdata(szBuff, pdata.ByteSize());
Nty.set_msgid(dwMsgID);
BroadMessageNotify Nty;
Nty.set_msgdata(szBuff, pdata.ByteSize());
Nty.set_msgid(dwMsgID);

TNodeTypePtr pNode = MoveFirst();
ERROR_RETURN_FALSE(pNode != NULL);
TNodeTypePtr pNode = MoveFirst();
ERROR_RETURN_FALSE(pNode != NULL);

UINT32 dwProxyID = 0;
CPlayerObject* pTempObj = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pTempObj = pNode->GetValue();
ERROR_RETURN_FALSE(pTempObj != NULL);
UINT32 dwProxyID = 0;
CPlayerObject* pTempObj = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pTempObj = pNode->GetValue();
ERROR_RETURN_FALSE(pTempObj != NULL);

if (!pTempObj->IsOnline())
{
continue;
}
if (!pTempObj->IsOnline())
{
continue;
}

Nty.add_connid(pTempObj->m_dwClientConnID);
Nty.add_connid(pTempObj->m_dwClientConnID);

if(pTempObj->m_dwProxyConnID != 0)
{
dwProxyID = pTempObj->m_dwProxyConnID;
}
}
if(pTempObj->m_dwProxyConnID != 0)
{
dwProxyID = pTempObj->m_dwProxyConnID;
}
}

//因为所有玩家是一个ProxyID
ServiceBase::GetInstancePtr()->SendMsgProtoBuf(dwProxyID, MSG_BROAD_MESSAGE_NOTIFY, 0, 0, Nty);
//因为所有玩家是一个ProxyID
ServiceBase::GetInstancePtr()->SendMsgProtoBuf(dwProxyID, MSG_BROAD_MESSAGE_NOTIFY, 0, 0, Nty);

return TRUE;
return TRUE;
}

BOOL CPlayerManager::ZeroTimer(UINT32 nParam)
BOOL CPlayerManager::ZeroTimer(INT32 nParam)
{
TNodeTypePtr pNode = MoveFirst();
if (pNode == NULL) //一个人也没有
{
return TRUE;
}

CPlayerObject* pTempObj = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pTempObj = pNode->GetValue();
ERROR_RETURN_FALSE(pTempObj != NULL);

if (!pTempObj->IsOnline())
{
continue;
}

pTempObj->OnNewDay();
}

return TRUE;
TNodeTypePtr pNode = MoveFirst();
if (pNode == NULL) //一个人也没有
{
return TRUE;
}

CPlayerObject* pTempObj = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pTempObj = pNode->GetValue();
ERROR_RETURN_FALSE(pTempObj != NULL);

if (!pTempObj->IsOnline())
{
continue;
}

pTempObj->OnNewDay();
}

return TRUE;
}

BOOL CPlayerManager::OnUpdate(UINT64 uTick)
{
if (GetCount() <= 0)
{
return TRUE;
}

UINT64 uMinLeaveTime = 0x0fffffffff;
UINT64 uReleaseRoleID = 0;

TNodeTypePtr pNode = MoveFirst();
ERROR_RETURN_FALSE(pNode != NULL);

CPlayerObject* pTempObj = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pTempObj = pNode->GetValue();
ERROR_RETURN_FALSE(pTempObj != NULL);

if (pTempObj->IsOnline())
{
pTempObj->NotifyChange();
}
else
{
CRoleModule* pRoleModule = (CRoleModule*)pTempObj->GetModuleByType(MT_ROLE);
ERROR_RETURN_FALSE(pRoleModule != NULL);

if (uMinLeaveTime > pRoleModule->m_pRoleDataObject->m_uLogoffTime)
{
uMinLeaveTime = pRoleModule->m_pRoleDataObject->m_uLogoffTime;
uReleaseRoleID = pTempObj->GetRoleID();
}
}
}

if (uReleaseRoleID != 0 && GetCount() > m_dwMaxCacheNum)
{
//当内存中的人数超过人,就清理一个离线时间最长的玩家
ReleasePlayer(uReleaseRoleID);
}

return TRUE;
if (GetCount() <= 0)
{
return TRUE;
}

UINT64 uMinLeaveTime = 0x0fffffffff;
UINT64 uReleaseRoleID = 0;

TNodeTypePtr pNode = MoveFirst();
ERROR_RETURN_FALSE(pNode != NULL);

CPlayerObject* pTempObj = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pTempObj = pNode->GetValue();
ERROR_RETURN_FALSE(pTempObj != NULL);

if (pTempObj->IsOnline())
{
pTempObj->NotifyChange();
}
else
{
CRoleModule* pRoleModule = (CRoleModule*)pTempObj->GetModuleByType(MT_ROLE);
ERROR_RETURN_FALSE(pRoleModule != NULL);

if (uMinLeaveTime > pRoleModule->m_pRoleDataObject->m_uLogoffTime)
{
uMinLeaveTime = pRoleModule->m_pRoleDataObject->m_uLogoffTime;
uReleaseRoleID = pTempObj->GetRoleID();
}
}
}

if (uReleaseRoleID != 0 && GetCount() > m_dwMaxCacheNum)
{
//当内存中的人数超过人,就清理一个离线时间最长的玩家
ReleasePlayer(uReleaseRoleID);
}

return TRUE;
}

BOOL CPlayerManager::ReleaseAll()
{
TNodeTypePtr pNode = MoveFirst();
if (pNode == NULL)
{
return TRUE;
}
TNodeTypePtr pNode = MoveFirst();
if (pNode == NULL)
{
return TRUE;
}

CPlayerObject* pPlayer = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pPlayer = pNode->GetValue();
ERROR_TO_CONTINUE(pPlayer != NULL);
CPlayerObject* pPlayer = NULL;
for (; pNode != NULL; pNode = MoveNext(pNode))
{
pPlayer = pNode->GetValue();
ERROR_TO_CONTINUE(pPlayer != NULL);

pPlayer->Uninit();
}
pPlayer->Uninit();
}

Clear();
Clear();

return TRUE;
return TRUE;
}

Loading