📄 lobbyserver.cpp
字号:
#include "stdafx.h"
#include "LobbyServer.h"
#include "msgHandler.h"
#include "user.h"
#include "lobby.h"
#include "room.h"
#ifdef _LOG_GAMELOGIC
char log_result[1024];
char *log_mode[] = {"MODE_NONE", "MODE_NORMAL", "MODE_CLAN", "MODE_SURVIVAL", "MODE_DEATH", "MODE_FLAG", "MODE_STRIKE"};
#else ifdef _DBG_GAMELOGIC
char log_result[1024];
char *log_mode[] = {"MODE_NONE", "MODE_NORMAL", "MODE_CLAN", "MODE_SURVIVAL", "MODE_DEATH", "MODE_FLAG", "MODE_STRIKE"};
#endif
CLobbyServer g_cLobbyServer;
extern float fs_frame;
CLobbyServer::CLobbyServer()
{
m_cpLobby = NULL;
m_cpUser = NULL;
m_cpItemMap = NULL;
m_msgInfo = NULL;
}
CLobbyServer::~CLobbyServer()
{
net_free();
SAFE_DELETE(m_msgInfo);
SAFE_DELETE(m_cpItemMap);
SAFE_DELETE_ARRAY(m_cpLobby);
SAFE_DELETE_ARRAY(m_cpUser);
}
void CLobbyServer::LoadINI()
{
//辑滚矫胶袍
GetPrivateProfileString("SYSTEM", "MASTERSERVER_IP", NULL, m_cConfig.sys_master_ip, sizeof(m_cConfig.sys_master_ip), LSINIT);
m_cConfig.sys_master_port = GetPrivateProfileInt("SYSTEM", "MASTERSERVER_PORT", 0, LSINIT);
m_cConfig.sys_port_udp = GetPrivateProfileInt("SYSTEM", "UDP_PORT", 0, LSINIT);
m_cConfig.sys_port_tcp = GetPrivateProfileInt("SYSTEM", "TCP_PORT", 0, LSINIT);
m_cConfig.sys_maxlocal = GetPrivateProfileInt("SYSTEM", "MAX_LOCAL", 1, LSINIT);
m_cConfig.sys_maxuser = GetPrivateProfileInt("SYSTEM", "MAX_USER", 3000, LSINIT);
m_cConfig.sys_frame = GetPrivateProfileInt("SYSTEM", "FS_FRAME", 120, LSINIT);
m_cConfig.sys_account = GetPrivateProfileInt("SYSTEM", "ACCOUNT", 0, LSINIT);
//霸烙汲沥
m_cConfig.cfg_maxchannel = GetPrivateProfileInt("CONFIG", "MAX_CHANNEL", 1, LSINIT);
m_cConfig.cfg_maxchanneluser = GetPrivateProfileInt("CONFIG", "MAX_CHANNELUSER", m_cConfig.sys_maxuser, LSINIT);
m_cConfig.cfg_maxroom = GetPrivateProfileInt("CONFIG", "MAX_ROOM", m_cConfig.cfg_maxchanneluser, LSINIT);
m_cConfig.cfg_maxplayer = GetPrivateProfileInt("CONFIG", "MAX_PLAYER", 16, LSINIT);
m_cConfig.cfg_maxmap = GetPrivateProfileInt("CONFIG", "MAX_MAP", 0, LSINIT);
}
BOOL CLobbyServer::SetupSystem()
{
fs_frame = (float)m_cConfig.sys_frame;
return TRUE;
}
BOOL CLobbyServer::SetupNetwork()
{
net_init(m_cConfig.sys_maxuser, m_cConfig.sys_maxlocal, _printf);
net_setup(CallbackAccept, CallbackConnect, CallbackRecv, CallbackClose, NULL, NULL, 0);
m_cConfig.sys_udp_cnt = 1;
#ifdef _MODE_SERVICE
if(!net_startup(m_cConfig.sys_port_tcp, m_cConfig.sys_port_udp, m_cConfig.sys_udp_cnt, NET_COMMON, S_HEARTBEAT))
return FALSE;
#else
if(!net_startup(m_cConfig.sys_port_tcp, m_cConfig.sys_port_udp, m_cConfig.sys_udp_cnt, NET_FLAG(USE_SECURITYPACK), S_HEARTBEAT))
return FALSE;
#endif
m_msgInfo = new MSGINFO;
return TRUE;
}
BOOL CLobbyServer::Init()
{
LoadINI();
if(!SetupSystem())
{
_printf("InitError[CLobbyServer::SetupSystem() == false] CLobbyServer::Init()\n");
return FALSE;
}
if(!SetupNetwork())
{
_printf("InitError[CLobbyServer::SetupNetwork() == false] CLobbyServer::Init()\n");
return FALSE;
}
if(!CServer::Init(m_cConfig.sys_maxuser))
{
_printf("InitError[CServer::Init() == false] CLobbyServer::Init()\n");
return FALSE;
}
m_cpLobby = new CLobby[m_cConfig.cfg_maxchannel];
m_cpUser = new CUser[m_cConfig.sys_maxuser];
int i;
char line[LEN_LISTBUF+1];
FILE *fp;
if(!(fp = fopen(LSINIT, "rb"))) return false;
while(!feof(fp))
{
fgets(line, LEN_LISTBUF, fp);
sscanf(line, "%s", line);
if(!strcmp(line, "[LIST_CHANNEL]"))
{
i=0;
while(i < m_cConfig.cfg_maxchannel)
{
fgets(line, LEN_SVRNAME, fp);
m_cpLobby[i].Init(i, line);
++i;
}
}
}
fclose(fp);
i=m_cConfig.sys_maxuser;
while(i--) m_cpUser[i].Init(i);
#ifdef _MODE_SERVICE
if(!net_connect(m_cConfig.sys_master_ip, m_cConfig.sys_master_port, NET_COMMON, S_HEARTBEAT))
return FALSE;
#else
if(!net_connect(m_cConfig.sys_master_ip, m_cConfig.sys_master_port, USE_SECURITYPACK, S_HEARTBEAT))
return FALSE;
#endif
m_bRun = TRUE;
return TRUE;
}
CClient *CLobbyServer::OnAccept(int nSockIndex, DWORD dwAddr)
{
CUser *pUser = m_cpUser + nSockIndex;
void *ioc;
if(!pUser->Insert(dwAddr))
{
if((ioc = net_message(M_LOBBYSERVER, S_CLOSED, 0)))
{
if(!net_send(pUser->m_nIndex, ioc))
net_disconnect(pUser->m_nIndex, false);
}
return (CClient *)pUser;
}
if((ioc = net_message(M_LOBBYSERVER, S_AUTHOR, 0)))
{
if(!net_send(pUser->m_nIndex, ioc))
net_disconnect(pUser->m_nIndex, false);
}
return (CClient *)pUser;
}
void CLobbyServer::OnConnect(int nSockIndex, char *pAddr, WORD wPort)
{
m_cConfig.sys_master_server = (short)nSockIndex;
}
void CLobbyServer::OnClose(int nSockIndex, bool bNormal)
{
CUser *pUser = m_cpUser + nSockIndex;
CLobby *pLobby;
CRoom *pRoom;
short iGameServer;
short iGameUser;
bool bPlayer = false;
#ifdef _DBG_ENGINE
_printf("PC%d[CLOSE] 泅犁 蜡历惑怕[%s]\n", pUser->m_nIndex, pUser->GetStateLog());
#endif
switch(pUser->m_nState)
{
case CClient::STATE_CONNECT: //立加夸没捞 甸绢吭促
case CClient::STATE_BACKLOGIN: //盲澄急琶拳搁俊辑 辑滚急琶拳搁栏肺 捞悼吝..
return;
case CClient::STATE_JOINCHANNEL: //肺厚辑滚 柳涝吝..
case CClient::STATE_CHANNEL: //肺厚辑滚 柳涝苞沥捞 场车促(盲澄急琶拳搁)
case CClient::STATE_BACKCHANNEL: //肺厚俊辑 盲澄急琶拳搁栏肺 捞悼吝..
break;
case CClient::STATE_JOINGAME: //霸烙俊 柳涝吝..
case CClient::STATE_GAME: //霸烙狼 柳涝苞沥捞 场车促
case CClient::STATE_RESULT: //霸烙阑 场郴绰吝..
bPlayer = true;
case CClient::STATE_JOINROOM: //霸烙规俊 柳涝吝..
case CClient::STATE_ROOM: //霸烙规狼 柳涝苞沥捞 场车促
case CClient::STATE_BACKROOM: //霸烙阑 场郴绊 规栏肺 捞悼吝..
pRoom = m_cpLobby[pUser->m_iLobby].m_cpRoom + pUser->m_iRoom;
iGameServer = pRoom->m_iGameServer;
iGameUser = pUser->m_iGameUser;
pRoom->Quit(pUser->m_nIndex);
case CClient::STATE_JOINLOBBY: //肺厚肺 柳涝吝..
case CClient::STATE_LOBBY: //肺厚柳涝苞沥捞 场车促
case CClient::STATE_BACKLOBBY: //霸烙规俊辑 肺厚肺 捞悼吝..
pLobby = m_cpLobby + pUser->m_iLobby;
pLobby->Quit(pUser->m_nIndex);
break;
default:
_printf("**********************************exception************************************\n");
_log("PC%d StateError[state == default] CLobbyServer::OnClose() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
return;
}
if(pUser->m_nAccount == 0)
{
_printf("**********************************exception************************************\n");
_log("PC%d IndexError[account == 0] CLobbyServer::OnClose() > 泅犁 蜡历惑怕[%s]", pUser->m_nIndex, pUser->GetStateLog());
return;
}
void *ioc = net_message(M_LOBBYSERVER, S_USER_CNT, 0);
if(ioc)
{
net_packet(ioc, &m_nUserCnt, 1);
net_packet(ioc, &pUser->m_nAccount, 1);
net_packet(ioc, &bPlayer, 1);
if(bPlayer) //霸烙辑滚俊 立加茄 惑怕捞骨肺 谗变蜡历扼 舅妨霖促
{
net_packet(ioc, &iGameServer, 1);
net_packet(ioc, &iGameUser, 1);
}
SendMaster(ioc);
}
}
void CLobbyServer::OnRecv(int nSockIndex, int nMessage, DWORD dwErrCode, char *pPacket, DWORD *pSize)
{
switch(MAIN(nMessage))
{
case M_LOBBYSERVER: //努扼捞攫飘俊辑 柯 菩哦
switch(SUB(nMessage))
{
case CLS_AUTHOR_CODE:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_AUTHOR_CODE\n", nSockIndex, GetTickCount());
#endif
cls_author_code(nSockIndex, pPacket);
break;
case CLS_LOGIN_INFO:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_LOGIN_INFO\n", nSockIndex, GetTickCount());
#endif
cls_login_info(nSockIndex, pPacket);
break;
case CLS_CHANNEL_IN:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_CHANNEL_IN\n", nSockIndex, GetTickCount());
#endif
cls_channel_in(nSockIndex);
break;
case CLS_CHANNEL_REFRESH:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_CHANNEL_REFRESH\n", nSockIndex, GetTickCount());
#endif
lsc_channel_update(nSockIndex);
break;
case CLS_CHANNEL_SELECT:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_CHANNEL_SELECT\n", nSockIndex, GetTickCount());
#endif
cls_channel_select(nSockIndex, pPacket);
break;
case CLS_LOBBY_IN:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_LOBBY_IN\n", nSockIndex, GetTickCount());
#endif
cls_lobby_in(nSockIndex);
break;
case CLS_LOBBY_OUT:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_LOBBY_OUT\n", nSockIndex, GetTickCount());
#endif
cls_lobby_out(nSockIndex);
break;
case CLS_ROOM_REFRESH:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_ROOM_REFRESH\n", nSockIndex, GetTickCount());
#endif
lsc_room_update(nSockIndex, pPacket);
break;
case CLS_ROOM_CREATE:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_ROOM_CREATE\n", nSockIndex, GetTickCount());
#endif
cls_room_create(nSockIndex, pPacket);
break;
case CLS_ROOM_JOIN:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_ROOM_JOIN\n", nSockIndex, GetTickCount());
#endif
cls_room_join(nSockIndex, pPacket);
break;
case CLS_ROOM_QUICK:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_ROOM_QUICK\n", nSockIndex, GetTickCount());
#endif
cls_room_quick(nSockIndex, pPacket);
break;
case CLS_INVITE_INFO:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_INVITE_INFO\n", nSockIndex, GetTickCount());
#endif
//LSC_INVITE_INFO
//LSC_INVITE_LIST
break;
case CLS_INVITE_REQUEST:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_INVITE_REQUEST\n", nSockIndex, GetTickCount());
#endif
//LSC_INVITE_REQUEST
break;
case CLS_ROOM_INVITE:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_ROOM_INVITE\n", nSockIndex, GetTickCount());
#endif
//LSC_ROOM_IN
break;
case CLS_INVITE_REJECT:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_INVITE_REJECT\n", nSockIndex, GetTickCount());
#endif
//LSC_INVITE_REJECT
case CLS_ROOM_IN:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_ROOM_IN\n", nSockIndex, GetTickCount());
#endif
cls_room_in(nSockIndex);
break;
case CLS_ROOM_OUT:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_ROOM_OUT\n", nSockIndex, GetTickCount());
#endif
cls_room_out(nSockIndex);
break;
case CLS_ROOM_BLOCK:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_ROOM_BLOCK\n", nSockIndex, GetTickCount());
#endif
cls_room_block(nSockIndex, pPacket);
break;
case CLS_CHAT:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_CHAT\n", nSockIndex, GetTickCount());
#endif
cls_chat(nSockIndex, pPacket);
break;
case CLS_MAP_SELECT:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_MAP_SELECT\n", nSockIndex, GetTickCount());
#endif
cls_map_select(nSockIndex, pPacket);
break;
case CLS_PLAYLIMIT_SELECT:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_PLAYLIMIT_SELECT\n", nSockIndex, GetTickCount());
#endif
cls_playlimit_select(nSockIndex, pPacket);
break;
case CLS_PLAYTIME_SELECT:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_PLAYTIME_SELECT\n", nSockIndex, GetTickCount());
#endif
cls_playtime_select(nSockIndex, pPacket);
break;
case CLS_REPAIRCNT_SELECT:
#ifdef _DBG_ENGINE
_printf("[%d:%u] M_CLIENT::CLS_REPAIRCNT_SELECT\n", nSockIndex, GetTickCount());
#endif
cls_repaircnt_select(nSockIndex, pPacket);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -