📄 processmsg.cpp
字号:
#include "StdInc.h"
#include "Common.h"
//-----------------------------------------------------------------------------
// Message Structure Instances declaration
//-----------------------------------------------------------------------------
// Account Server <-> Client
MSG_C2S_CHAR_LOGIN Msg_C2S_Char_Login;
MSG_S2C_CHAR_LIST Msg_S2C_Char_List;
MSG_S2C_CHAR_LOGIN_OK Msg_S2C_Char_Login_Ok;
MSG_C2S_ASK_CREATE_PLAYER Msg_C2S_Ask_Create_Player;
MSG_S2C_ANS_CREATE_PLAYER Msg_S2C_Ans_Create_Player;
MSG_C2S_ASK_DELETE_PLAYER Msg_C2S_Ask_Delete_Player;
MSG_S2C_ANS_DELETE_PLAYER Msg_S2C_Ans_Delete_Player;
MSG_S2C_ERROR Msg_S2C_Error;
// Account Server <-> Main Server
MSG_M2S_ERROR Msg_M2S_Error;
MSG_S2M_SVR_LOGIN Msg_S2M_Svr_Login;
MSG_S2M_CHAR_LOGIN Msg_S2M_Char_Login;
MSG_M2S_CHAR_LOGIN Msg_M2S_Char_Login;
MSG_M2S_CHAR_UPDATE Msg_M2S_Char_Update;
MSG_S2M_ASK_CREATE_PLAYER Msg_S2M_Ask_Create_Player;
MSG_M2S_ANS_CREATE_PLAYER Msg_M2S_Ans_Create_Player;
MSG_S2M_ASK_DELETE_PLAYER Msg_S2M_Ask_Delete_Player;
MSG_M2S_ANS_DELETE_PLAYER Msg_M2S_Ans_Delete_Player;
// Account Server <-> Gate Server
MSG_G2S_SVR_LOGIN Msg_G2S_Svr_Login;
MSG_G2S_NEW_CLIENT Msg_G2S_New_Client;
MSG_G2S_DISCONNECT Msg_G2S_Disconnect;
MSG_S2G_DISCONNECT Msg_S2G_Disconnect;
MSG_S2G_SWITCH_ZONE Msg_S2G_Switch_Zone;
MSG_S2G_BROADCAST Msg_S2G_Broadcast;
BOOL FindOneOf(LPTSTR psz, LPCTSTR pszBanChars)
{
int len1 = strlen(psz);
int len2 = strlen(pszBanChars);
for (int i = 0 ; i < len1 ; i++)
{
for (int j = 0 ; j < len2 ; j++)
{
if (psz[i] == pszBanChars[j])
{
return TRUE;
}
}
}
return FALSE;
}
void StrTrim(char * psz, const char * pszTrimChars)
{
int len1 = strlen(psz);
int len2 = strlen(pszTrimChars);
int n = 0;
char * buf = new char [len1 + 1]; // Incluede Null Termination
for (int i = 0 ; i < len1 ; i++)
{
for (int j = 0 ; j < len2 ; j++)
{
if (psz[i] == pszTrimChars[j]) break;
}
if (j == len2)
buf[n++] = psz[i];
}
buf[n] = NULL;
strcpy (psz, buf);
delete [] buf;
}
//----------------------------------------------------------------------------------------------
// Gate Server to Zone Server Packet Processing Functions
//----------------------------------------------------------------------------------------------
void Func_G2S_SVR_LOGIN(MSG_G2S_SVR_LOGIN * pMsg, BYTE iGate)
{
if (GateManage.IsInvalidSvrID(pMsg->byThisServerID))
{
GateManage.m_pStandbyServer[iGate]->OnClose();
}
else
{
if (GateManage.RunServer((GateManage.m_pStandbyServer[iGate]), pMsg->byThisServerID) == FALSE)
{
GateManage.m_pStandbyServer[iGate]->OnClose();
}
}
}
void Func_G2S_NEW_CLIENT(MSG_G2S_NEW_CLIENT * pMsg, BYTE iGate)
{
ACCOUNT_INFO *pNewAccount = new ACCOUNT_INFO;
if (pNewAccount == NULL)
{
Print("Memory allocation failure!\n" );
}
if (FindOneOf(pMsg->szAccountName, " ") == TRUE)
{
return;
}
if (FDB.LoadAccInfo(pMsg->szAccountName, &(pNewAccount->AccountCharInfo)))
{
strncpy(pNewAccount->szAccountName, pMsg->szAccountName, sizeof(pNewAccount->szAccountName));
pNewAccount->szAccountName[sizeof(pNewAccount->szAccountName) - 1] = NULL;
// added by aliceblue.10.28
strncpy(pNewAccount->szIP, pMsg->szIP, sizeof(pNewAccount->szIP));
pNewAccount->szIP[sizeof(pNewAccount->szIP) - 1] = NULL;
AccountManage.Insert(pMsg->MsgHeader.dwPCID, pNewAccount);
Msg_S2C_Char_List.MsgHeader.dwPCID = pMsg->MsgHeader.dwPCID;
memcpy(Msg_S2C_Char_List.CharInfo, &(pNewAccount->AccountCharInfo), sizeof(ACCOUNT_CHAR_INFO));
if (GateManage.SendMsg(iGate, &Msg_S2C_Char_List, sizeof(Msg_S2C_Char_List)))
{
//printf("Send Ok - Msg_S2C_Char_List\n");
}
else
{
// Error Processing
//printf("Send Error - Msg_S2C_Char_List, iGate = %d Error = %d\n", iGate, WSAGetLastError());
}
}
}
void Func_G2S_DISCONNECT(MSG_G2S_DISCONNECT * pMsg, BYTE iGate)
{
if(AccountManage.Remove(pMsg->MsgHeader.dwPCID))
{
//printf("Remove Account Map - TRUE!\n");
}
else
{
//printf("Remove Account Map - FALSE!\n");
}
switch(pMsg->byReason)
{
case 1: // Verify Timeout : S2G_DISCONNECT 傈价 鞘夸
break;
case 2: // Speed Hack : S2G_DISCONNECT 傈价 鞘夸
break;
case 3: // Packet Error : S2G_DISCONNECT 傈价 鞘夸
break;
case 4: // Network Timeout : S2G_DISCONNECT 傈价 鞘夸
break;
case 5: // Client Socket FD_CLOSE : S2G_DISCONNECT 鞘夸 绝澜
break;
default:
break;
}
}
//----------------------------------------------------------------------------------------------
// Client to Account Server Packet Processing Functions
//----------------------------------------------------------------------------------------------
void Func_C2S_CHAR_LOGIN(MSG_C2S_CHAR_LOGIN * pMsg, BYTE iGate)
{
/* if (pMsg->CurVersion < g_ServerVersion)
{
Msg_S2C_Error.MsgHeader.dwPCID = pMsg->MsgHeader.dwPCID;
Msg_S2C_Error.wErrCode = INVALID_VERSION;
strcpy(Msg_S2C_Error.szErrStr, "滚傈捞 老摹窍瘤 臼嚼聪促.");
GateManage.SendMsg(iGate, &Msg_S2C_Error, sizeof(Msg_S2C_Error));
// 捞逞篮 努扼捞攫飘啊 谗阑 巴捞促.
// AccountManage.Remove(pMsg->dwPCID);
return;
}
*/
StrTrim(pMsg->szPCName, " ");
ACCOUNT_INFO * pInfo = AccountManage.GetAccountInfo(pMsg->MsgHeader.dwPCID);
if (pInfo == NULL)
{
MiraDebug("GetAccountInfo() return FALSE (%s), %s\n", pMsg->szPCName, TickManage.GetAscTime());
return;
}
if (AccountManage.SetCurrentPCIndex(pMsg->MsgHeader.dwPCID, pMsg->szPCName) == FALSE)
{
MiraDebug("SetCurrentPCIndex() return FALSE (%s), %s\n", pMsg->szPCName, TickManage.GetAscTime());
return;
}
strncpy(Msg_S2M_Char_Login.szAccountName, AccountManage.GetAccountName(pMsg->MsgHeader.dwPCID), sizeof(Msg_S2M_Char_Login.szAccountName));
Msg_S2M_Char_Login.szAccountName[sizeof(Msg_S2M_Char_Login.szAccountName) - 1] = NULL;
strncpy(Msg_S2M_Char_Login.szPCName, pMsg->szPCName, sizeof(Msg_S2M_Char_Login.szPCName));
Msg_S2M_Char_Login.szPCName[sizeof(Msg_S2M_Char_Login.szPCName) - 1] = NULL;
strncpy(Msg_S2M_Char_Login.szIP, pInfo->szIP, sizeof(Msg_S2M_Char_Login.szIP));
Msg_S2M_Char_Login.szIP[sizeof(Msg_S2M_Char_Login.szIP) - 1] = NULL;
Msg_S2M_Char_Login.dwPCID = pMsg->MsgHeader.dwPCID;
Msg_S2M_Char_Login.byGateSvrID = iGate;
if (MainServer.SendMsg(&Msg_S2M_Char_Login, sizeof(Msg_S2M_Char_Login)))
{
Print("Sent <CharLogin:%s>\n", Msg_S2M_Char_Login.szPCName);
}
/*
if (AccountManage.SetCurrentPCIndex(pMsg->MsgHeader.dwPCID, pMsg->szPCName))
{
if (AccountManage.IsValidAccount(pMsg->MsgHeader.dwPCID, pMsg->szPCName))
{
memcpy(Msg_S2M_Char_Login.szPCName, pMsg->szPCName, sizeof(Msg_S2M_Char_Login.szPCName));
Msg_S2M_Char_Login.szPCName[sizeof(Msg_S2M_Char_Login.szPCName) - 1] = NULL;
memcpy(Msg_S2M_Char_Login.szAccountName, AccountManage.GetAccountName(pMsg->MsgHeader.dwPCID), sizeof(Msg_S2M_Char_Login.szAccountName));
Msg_S2M_Char_Login.szAccountName[sizeof(Msg_S2M_Char_Login.szAccountName) - 1] = NULL;
Msg_S2M_Char_Login.dwPCID = pMsg->MsgHeader.dwPCID;
Msg_S2M_Char_Login.byGateSvrID = iGate;
if (MainServer.SendMsg(&Msg_S2M_Char_Login, sizeof(Msg_S2M_Char_Login)))
{
//printf("Send Ok - Msg_S2M_Char_Login\n");
}
else
{
// SendMsg Error Processing
}
}
else
{
// Invaild Account Error Processing
}
}
else
{
// AccountManage.SetCurrentPCIndex() Error Processing
}
*/
}
void Func_C2S_ASK_CREATE_PLAYER(MSG_C2S_ASK_CREATE_PLAYER * pMsg, BYTE iGate)
{
pMsg->szCharacterName[12] = NULL;
//printf("C2S_ASK_CREATE_PLAYER : (%s)\n", pMsg->szCharacterName);
if (FindOneOf(pMsg->szCharacterName, " `~!@#$%^&*()_-=+|\\[]{}:;'\"?/<>,."))
{
Msg_S2C_Error.MsgHeader.dwPCID = pMsg->MsgHeader.dwPCID;
Msg_S2C_Error.wErrCode = ALREADY_EXIST_CHAR;
strncpy(Msg_S2C_Error.szErrStr, "傍归捞唱 漂荐 扁龋绰 荤侩且 荐 绝嚼聪促.", sizeof(Msg_S2C_Error.szErrStr));
Msg_S2C_Error.szErrStr[sizeof(Msg_S2C_Error.szErrStr) - 1] = NULL;
GateManage.SendMsg(iGate, &Msg_S2C_Error, sizeof(Msg_S2C_Error));
return;
}
StrTrim(pMsg->szCharacterName, " ");
if (AccountManage.CreateNewCharacter(pMsg->MsgHeader.dwPCID, pMsg->byClassIndex, pMsg->szCharacterName))
{
if (AccountManage.IsValidAccount(pMsg->MsgHeader.dwPCID, pMsg->szCharacterName))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -