📄 lobby.cpp
字号:
#include "stdafx.h"
#include "LobbyServer.h"
#include "msgHandler.h"
#include "user.h"
#include "room.h"
#include "lobby.h"
CLobby::CLobby()
{
m_nUserIdx = NULL;
}
CLobby::~CLobby()
{
SAFE_DELETE_ARRAY(m_cpRoom);
SAFE_DELETE_ARRAY(m_nUserIdx);
}
void CLobby::Init(short nIndex, char *pCmdLine)
{
sscanf(pCmdLine, "%s", m_szTitle);
m_nIndex = nIndex;
m_nUserCnt = 0;
m_nPcCnt = 0;
m_nUserIdx = new short[g_cLobbyServer.m_cConfig.cfg_maxchanneluser];
m_cpRoom = new CRoom[g_cLobbyServer.m_cConfig.cfg_maxroom];
int i=g_cLobbyServer.m_cConfig.cfg_maxchanneluser;
while(i--) m_nUserIdx[i] = -1;
i=g_cLobbyServer.m_cConfig.cfg_maxroom;
while(i--) m_cpRoom[i].Init(m_nIndex, i);
}
BOOL CLobby::IsJoin()
{
if(m_nUserCnt >= g_cLobbyServer.m_cConfig.cfg_maxchanneluser)
return FALSE;
return TRUE;
}
BOOL CLobby::Join(short nUserIndex)
{
CUser *pUser = (CUser *)g_cLobbyServer.GetClient(nUserIndex);
if(!pUser)
{
_printf("**********************************exception************************************\n");
_log("PC%d IndexError[user == NULL] cls_channel_select()", nUserIndex);
return FALSE;
}
if(pUser->m_nState != CClient::STATE_CHANNEL)
{
_printf("**********************************exception************************************\n");
_log("PC%d StateError[state != STATE_CHANNEL] cls_channel_select() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
return FALSE;
}
int i=0;
while(i < g_cLobbyServer.m_cConfig.cfg_maxchanneluser)
{
if(m_nUserIdx[i] < 0)
{
m_nUserIdx[i] = pUser->m_nIndex;
pUser->m_iLobby = m_nIndex;
pUser->m_iLobbySlot = (short)i;
pUser->m_nState = CClient::STATE_JOINLOBBY;
++m_nUserCnt;
#ifdef _DBG_GAMELOGIC
_printf("CHANNLE%d:%s [LOBBYIN] count:%d(%d)/%d\n", m_nIndex, pUser->m_szNick, m_nPcCnt, m_nUserCnt, g_cLobbyServer.m_cConfig.cfg_maxchanneluser);
#endif
return TRUE;
}
++i;
}
return FALSE;
}
BOOL CLobby::Out(short nUserIndex)
{
if(m_nUserCnt <= 0)
{
_printf("**********************************exception************************************\n");
_log("CHANNEL%d CountError[UserCnt=%d] CLobby::Out()", m_nIndex, m_nUserCnt);
return FALSE;
}
CUser *pUser = (CUser *)g_cLobbyServer.GetClient(nUserIndex);
if(!pUser)
{
_printf("**********************************exception************************************\n");
_log("PC%d IndexError[user == NULL] CLobby::Out()", nUserIndex);
return FALSE;
}
if(pUser->m_nState != CClient::STATE_LOBBY)
{
_printf("**********************************exception************************************\n");
_log("PC%d StateError[state != STATE_LOBBY] CLobby::Out() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
return FALSE;
}
if(m_nUserIdx[pUser->m_iLobbySlot] != pUser->m_nIndex)
{
_printf("**********************************exception************************************\n");
_log("PC%d IndexError[lobby_userindex != %d] CLobby::Out() > LOBBY%d 浇吩牢郸胶[%d]", pUser->m_nIndex, m_nUserIdx[pUser->m_iLobbySlot], m_nIndex, pUser->m_iLobbySlot);
return FALSE;
}
--m_nUserCnt;
if(--m_nPcCnt)
{
//鞍篮 盲澄 蜡历甸俊霸 唱埃蜡历沥焊 傈价
lsc_user_delete(m_nIndex, pUser->m_nIndex);
}
#ifdef _DBG_GAMELOGIC
_printf("CHANNLE%d:%s [LOBBYOUT] count:%d(%d)/%d\n", m_nIndex, pUser->m_szNick, m_nPcCnt, m_nUserCnt, g_cLobbyServer.m_cConfig.cfg_maxchanneluser);
#endif
m_nUserIdx[pUser->m_iLobbySlot] = -1;
pUser->m_iLobbySlot = -1;
pUser->m_iLobby = -1;
pUser->m_nState = CClient::STATE_BACKCHANNEL; //捞贰具 促矫 'CLS_CHANNEL_IN' 阑 罐阑 荐 乐促
//唱哎赤籍俊霸 唱啊档 亮促绊 傈价
void *ioc = net_message(M_LOBBYSERVER, LSC_LOBBY_OUT, 0);
if(ioc)
{
if(!net_send(pUser->m_nIndex, ioc))
net_disconnect(pUser->m_nIndex, false);
}
return TRUE;
}
BOOL CLobby::Quit(short nUserIndex)
{
if(m_nUserCnt <= 0)
{
_printf("**********************************exception************************************\n");
_log("CHANNEL%d CountError[UserCnt=%d] CLobby::Quit()", m_nIndex, m_nUserCnt);
return FALSE;
}
CUser *pUser = (CUser *)g_cLobbyServer.GetClient(nUserIndex);
if(!pUser)
{
_printf("**********************************exception************************************\n");
_log("PC%d IndexError[user == NULL] CLobby::Quit()", nUserIndex);
return FALSE;
}
if(pUser->m_nState < CClient::STATE_JOINLOBBY)
{
_printf("**********************************exception************************************\n");
_log("PC%d StateError[state < STATE_JOINLOBBY] CLobby::Quit() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
return FALSE;
}
if(m_nUserIdx[pUser->m_iLobbySlot] != pUser->m_nIndex)
{
_printf("**********************************exception************************************\n");
_log("PC%d IndexError[lobby_userindex != %d] CLobby::Quit() > LOBBY%d 浇吩牢郸胶[%d]", pUser->m_nIndex, m_nUserIdx[pUser->m_iLobbySlot], m_nIndex, pUser->m_iLobbySlot);
return FALSE;
}
--m_nUserCnt;
if(pUser->m_nState != CClient::STATE_JOINLOBBY) //唱埃仇捞 规俊 乐绰 蜡历老锭档 器窃
{
//肺厚俊 蜡历啊 巢酒乐绊, 唱埃仇捞 肺厚俊 乐绰 蜡历老锭父
if(--m_nPcCnt && pUser->m_nState == CClient::STATE_LOBBY)
{
//鞍篮 盲澄 蜡历甸俊霸 唱埃蜡历沥焊 傈价
lsc_user_delete(m_nIndex, pUser->m_nIndex);
}
}
#ifdef _DBG_GAMELOGIC
_printf("CHANNLE%d:%s [LOBBYQUIT] count:%d(%d)/%d\n", m_nIndex, pUser->m_szNick, m_nPcCnt, m_nUserCnt, g_cLobbyServer.m_cConfig.cfg_maxchanneluser);
#endif
m_nUserIdx[pUser->m_iLobbySlot] = -1;
return TRUE;
}
void CLobby::SendAll(void *ioc)
{
CUser *pUser;
int i=0;
while(i < g_cLobbyServer.m_cConfig.cfg_maxchanneluser)
{
if(m_nUserIdx[i] != -1)
{
pUser = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
if(pUser->m_nState == CClient::STATE_LOBBY) //菩哦 罐阑 霖厚啊 登乐绰 蜡历甸
{
if(!net_broadcast(pUser->m_nIndex, ioc))
net_disconnect(pUser->m_nIndex, false);
}
}
++i;
}
net_endcast(ioc);
}
void CLobby::SendAll(void *ioc, int nUserIndex)
{
CUser *pUser;
int i=0;
while(i < g_cLobbyServer.m_cConfig.cfg_maxchanneluser)
{
if(m_nUserIdx[i] != -1)
{
pUser = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
if(pUser->m_nState == CClient::STATE_LOBBY && pUser->m_nIndex != nUserIndex)
{
if(!net_broadcast(pUser->m_nIndex, ioc))
net_disconnect(pUser->m_nIndex, false);
}
}
++i;
}
net_endcast(ioc);
}
void CLobby::SendClan(void *ioc, char *pClanName)
{
CUser *pUser;
int i=0;
while(i < g_cLobbyServer.m_cConfig.cfg_maxchanneluser)
{
if(m_nUserIdx[i] != -1)
{
pUser = g_cLobbyServer.m_cpUser + m_nUserIdx[i];
if((pUser->m_nState == CClient::STATE_LOBBY || pUser->m_nState == CClient::STATE_ROOM) && //菩哦 罐阑 霖厚啊 登乐绰 蜡历甸
!strcmp(pUser->m_szClan, pClanName))
{
if(!net_broadcast(pUser->m_nIndex, ioc))
net_disconnect(pUser->m_nIndex, false);
}
}
++i;
}
net_endcast(ioc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -