|
- #include "StdAfx.h"
- #include "ServiceUnits.h"
- #include "ControlPacket.h"
- #include "AttemperEngineSink.h"
- #include "LogonServer.h"
- #include "LogonServerDlg.h"
- #include "HttpThread.h"
- #include <strsafe.h>
- #include <unordered_map>
- #include "ChineseCode.h"
- #include <algorithm>
- #include "../../GlobalDef/Util.h"
- #include "ZBase64.h"
- #include "../../MessageDef/Pb_LogonServer.pb.h"
-
- const WORD wConnectTime = 5;
- extern CLogonServerApp theApp;
- //////////////////////////////////////////////////////////////////////////////////
-
- //时间标识
- #define IDI_LOAD_GAME_LIST 1 //加载列表
- #define IDI_CONNECT_CORRESPOND 2 //重连标识
- #define IDI_COLLECT_ONLINE_INFO 3 //统计在线
- #define IDI_SERVICE 4 //通道检测
- #define IDI_JULI 7 //距离清空
- ///[---add by yd
- #define ID_TIMER_HEARTBEAT 5 //与协调的心跳定时器
- ///---]
- //////////////////////////////////////////////////////////////////////////////////
- //通道检测
- #define MDM_GR_CHECK 999 //通道检测
-
- #define DBO_GR_UPTONGDAO 217 //更新通道
- #define DBO_GR_UPTONGDAOACK 218 //更新通道处理完成
-
- //客户端发送 我原封不动回复
- struct CHECK
- {
- DWORD connkey;
- DWORD dCheckID; //检测编号
- DWORD dTime[4]; //时间戳 16字节
- };
- //构造函数
- CAttemperEngineSink::CAttemperEngineSink()
- {
- //状态变量
- m_bNeekCorrespond = true;
- m_bShowServerStatus = false;
-
- //状态变量
- m_pInitParameter = NULL;
- m_pBindParameter = NULL;
-
- //组件变量
- m_pITimerEngine = NULL;
- m_pIDataBaseEngine = NULL;
- m_pITCPNetworkEngine = NULL;
- m_pITCPSocketService = NULL;
-
- //视频配置
- m_wAVServerPort = 0;
- m_dwAVServerAddr = 0;
-
- //缓存变量
- m_wTaskCount = 0;
- m_wLevelCount = 0;
- m_wMemberCount = 0;
- m_wTaskCountBuffer = 0;
- ZeroMemory(m_lCheckInReward, sizeof(m_lCheckInReward));
- ZeroMemory(m_TaskParameter, sizeof(m_TaskParameter));
- ZeroMemory(m_MemberParameter, sizeof(m_MemberParameter));
- ZeroMemory(m_GrowLevelConfig, sizeof(m_GrowLevelConfig));
- ZeroMemory(&m_PlatformParameter, sizeof(m_PlatformParameter));
- ZeroMemory(m_TaskParameterBuffer, sizeof(m_TaskParameterBuffer));
- ZeroMemory(&m_BaseEnsureParameter, sizeof(m_BaseEnsureParameter));
-
- m_MapServerUserID.InitHashTable(PRIME_PLATFORM_USER);
-
- ///[---add by yd
- m_wServerID = 0;
- m_dwHearbeatTime = 0;
- ///---]
-
- return;
- }
-
- //析构函数
- CAttemperEngineSink::~CAttemperEngineSink()
- {
- m_MapServerUserID.RemoveAll();
- }
-
- //接口查询
- VOID * CAttemperEngineSink::QueryInterface(REFGUID Guid, DWORD dwQueryVer)
- {
- QUERYINTERFACE(IAttemperEngineSink, Guid, dwQueryVer);
- QUERYINTERFACE_IUNKNOWNEX(IAttemperEngineSink, Guid, dwQueryVer);
- return NULL;
- }
-
- //启动事件
- bool CAttemperEngineSink::OnAttemperEngineStart(IUnknownEx * pIUnknownEx)
- {
- //绑定参数
- m_pBindParameter = new tagBindParameter[m_pInitParameter->m_wMaxConnect];
- ZeroMemory(m_pBindParameter, sizeof(tagBindParameter)*m_pInitParameter->m_wMaxConnect);
-
- //设置时间
- ASSERT(m_pITimerEngine != NULL);
- #ifndef _DEBUG
- m_pITimerEngine->SetTimer(IDI_COLLECT_ONLINE_INFO, m_pInitParameter->m_wCollectTime * 1000L, TIMES_INFINITY, 0);
- m_pITimerEngine->SetTimer(IDI_SERVICE, 40 * 1000L, TIMES_INFINITY, 0);
- #else
- m_pITimerEngine->SetTimer(IDI_COLLECT_ONLINE_INFO, 20 * 1000L, TIMES_INFINITY, 0);
- m_pITimerEngine->SetTimer(IDI_SERVICE, 40 * 1000L, TIMES_INFINITY, 0);
- #endif
- m_pITimerEngine->SetTimer(IDI_JULI, 60 * 1000L, TIMES_INFINITY, 0);
-
-
- //获取目录
- TCHAR szPath[MAX_PATH] = TEXT("");
- CString szFileName;
- GetModuleFileName(AfxGetInstanceHandle(), szPath, sizeof(szPath));
- szFileName = szPath;
- int nIndex = szFileName.ReverseFind(TEXT('\\'));
- szFileName = szFileName.Left(nIndex);
- szFileName += TEXT("\\PlazaOptionConfig.ini");
-
- //读取配置
- m_bShowServerStatus = (GetPrivateProfileInt(TEXT("ServerStatus"), TEXT("ShowServerStatus"), 0, szFileName) != 0);
-
- //获取目录
- TCHAR szServerAddr[LEN_SERVER] = TEXT("");
- GetCurrentDirectory(sizeof(szPath), szPath);
-
- //读取配置
- TCHAR szVideoFileName[MAX_PATH] = TEXT("");
- _sntprintf(szVideoFileName, CountArray(szVideoFileName), TEXT("%s\\VideoOption.ini"), szPath);
- m_wAVServerPort = GetPrivateProfileInt(TEXT("VideoOption"), TEXT("ServerPort"), 0, szVideoFileName);
- DWORD dwAddrLen = GetPrivateProfileString(TEXT("VideoOption"), TEXT("ServerAddr"), TEXT(""), szServerAddr, LEN_SERVER, szVideoFileName);
- if (dwAddrLen > 0)
- {
- CT2CA strServerDomain(szServerAddr);
- m_dwAVServerAddr = inet_addr(strServerDomain);
- }
- else
- {
- m_dwAVServerAddr = 0;
- }
-
- m_wServerID = CLogonServerDlg::g_StartP.wServerID; // m_pInitParameter->m_wServerID;
- TCHAR szServerID[32] = { 0 };
- _sntprintf(szServerID, CountArray(szServerID), TEXT("LogonServerID = %d"), m_wServerID);
-
- CTraceService::TraceString(szServerID, TraceLevel_Normal);
- return true;
- }
-
- //停止事件
- bool CAttemperEngineSink::OnAttemperEngineConclude(IUnknownEx * pIUnknownEx)
- {
- //状态变量
- m_bNeekCorrespond = true;
-
- //组件变量
- m_pITimerEngine = NULL;
- m_pIDataBaseEngine = NULL;
- m_pITCPNetworkEngine = NULL;
- m_pITCPSocketService = NULL;
-
- //任务参数
- m_wTaskCount = 0;
- m_wTaskCountBuffer = 0;
- ZeroMemory(&m_TaskParameter, sizeof(m_TaskParameter));
- ZeroMemory(&m_TaskParameterBuffer, sizeof(m_TaskParameterBuffer));
-
- //会员参数
- m_wMemberCount = 0;
- ZeroMemory(m_MemberParameter, sizeof(m_MemberParameter));
-
- //等级配置
- m_wLevelCount = 0;
- ZeroMemory(m_GrowLevelConfig, sizeof(m_GrowLevelConfig));
-
- //签到配置
- ZeroMemory(m_lCheckInReward, sizeof(m_lCheckInReward));
-
- //删除数据
- SafeDeleteArray(m_pBindParameter);
-
- //列表组件
- m_ServerListManager.ResetServerList();
-
- CLogonServerDlg *p = (CLogonServerDlg *)theApp.m_pMainWnd;
- if (p)
- {
- while (true)
- {
- if (p->ServiceTree.ItemHasChildren(p->hRoot))
- {
- HTREEITEM hChildItem = p->ServiceTree.GetChildItem(p->hRoot);
- p->ServiceTree.DeleteItem(hChildItem);
- }
- else
- {
- break;
- }
- }
-
- m_LoginServiceIDMap.RemoveAll();
- }
-
- return true;
- }
-
- //控制事件
- bool CAttemperEngineSink::OnEventControl(WORD wIdentifier, VOID * pData, WORD wDataSize)
- {
- switch (wIdentifier)
- {
- case CT_LOAD_DB_GAME_LIST: //加载列表
- {
- //加载列表
- m_ServerListManager.DisuseKernelItem();
-
- //清理列表
- m_ServerListManager.CleanKernelItem();
-
- //事件通知
- CP_ControlResult ControlResult;
- ControlResult.cbSuccess = ER_SUCCESS;
- SendUIControlPacket(UI_LOAD_DB_LIST_RESULT, &ControlResult, sizeof(ControlResult));
-
- //设置时间
- ASSERT(m_pITimerEngine != NULL);
- m_pITimerEngine->SetTimer(IDI_LOAD_GAME_LIST, m_pInitParameter->m_wLoadListTime * 1000L, 1, 0);
-
-
- //m_pIDataBaseEngine->PostDataBaseRequest(DBR_GP_LOAD_GAME_LIST, 0, NULL, 0);
-
- ////平台参数
- //m_pIDataBaseEngine->PostDataBaseRequest(DBR_GP_LOAD_PLATFORM_PARAMETER, 0, NULL, 0);
-
- return true;
- }
- case CT_CONNECT_CORRESPOND: //连接协调
- {
- //发起连接
- tagAddressInfo * pCorrespondAddress = &m_pInitParameter->m_CorrespondAddress;
- m_pITCPSocketService->Connect(pCorrespondAddress->szAddress, m_pInitParameter->m_wCorrespondPort);
-
- //构造提示
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("正在连接协调服务器 [ %s:%d ]"), pCorrespondAddress->szAddress, m_pInitParameter->m_wCorrespondPort);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
-
- return true;
- }
- default: break;
- }
-
- return false;
- }
-
- //调度事件
- bool CAttemperEngineSink::OnEventAttemperData(WORD wRequestID, VOID * pData, WORD wDataSize)
- {
- return false;
- }
-
-
- // 更新通道
- int CAttemperEngineSink::UpDataTongDao()
- {
- //查询所有节点服务器信息
- std::unordered_map<std::wstring, int> iptostat;
- //枚举数据
- POSITION Position = NULL;
-
-
- //枚举数据
- for (DWORD i = 0; i < m_ServerListManager.GetGameServerCount(); i++)
- {
- //获取数据
- CGameServerItem * pGameServerItem = m_ServerListManager.EmunGameServerItem(Position);
- if (pGameServerItem == NULL) continue;
-
- bool finda = false;
- std::wstring cc = pGameServerItem->m_GameServer.szServerAddr;
-
- auto iter = iptostat.find(cc);
- if (iter != std::end(iptostat))
- {
- //已经存在
- finda = true;
- }
-
- if (finda) continue;
-
- iptostat[cc] = 1;
- }
-
- IPLIST Temp;
- ZeroMemory(&Temp, sizeof(IPLIST));
-
- CList<std::wstring> aa;
- std::unordered_map<std::wstring, int>::iterator iter_ = iptostat.begin();
- for (int i = 0; i < iptostat.size(); i++)
- {
- if (iter_->first != _T(""))
- {
- aa.AddTail(iter_->first);
- }
- iter_++;
- }
- iptostat.clear();
-
- POSITION Pos = aa.GetHeadPosition();
- int i = 0;
- while (Pos)
- {
- std::wstring wRet = aa.GetNext(Pos);
-
- StringCchCat(Temp.ST_LIST[i], 64, wRet.c_str());
- i++;
-
- if (i > (64-1)) break;
- }
-
- //更新加载通道
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_GP_ONLINE_SERVICE, 0L, &Temp, sizeof(IPLIST));
-
- return 0;
- }
-
- //同步事件
- bool CAttemperEngineSink::OnTongBu(int Command, DWORD dwContextID, VOID * pData, WORD wDataSize)
- {
- switch (Command)
- {
- case DBO_GR_UPTONGDAO://更新通道
- {
- UpDataTongDao();
- return true;
- }
- case DBO_GR_UPTONGDAOACK://更新通道处理完成
- {
- ASSERT(wDataSize == sizeof(LianLuGroup));
- if (wDataSize != sizeof(LianLuGroup)) return true;
-
- LianLuGroup *pGroup = (LianLuGroup*)pData;
-
- //枚举数据
- POSITION Position = NULL;
-
- //枚举数据
- for (DWORD i = 0; i < m_ServerListManager.GetGameServerCount(); i++)
- {
- //获取数据
- CGameServerItem * pGameServerItem = m_ServerListManager.EmunGameServerItem(Position);
- if (pGameServerItem == NULL) continue;
-
- std::wstring cc = pGameServerItem->m_GameServer.szServerAddr;
- std::wstring dd = pGroup->szAdminIP;
-
- if (cc == dd)
- {
- for (int j = 0; j < MAX_TONGDAO; j++)
- {
- std::wstring ip = pGroup->Data[j].szIP;
-
- if (ip == _T("")) continue;
-
- pGameServerItem->SetLLStat(pGroup->Data[j].szIP, pGroup->Data[j].iIsOk, pGroup->Data[j].SystemTimeConclude);
-
- }
- }
- }
-
- return true;
- }
- default: break;
- }
- return true;
- }
- //时间事件
- bool CAttemperEngineSink::OnEventTimer(DWORD dwTimerID, WPARAM wBindParam)
- {
- switch (dwTimerID)
- {
- case IDI_LOAD_GAME_LIST: //加载列表
- {
- //加载列表
- m_ServerListManager.DisuseKernelItem();
- //清理列表
- m_ServerListManager.CleanKernelItem();
-
- //事件通知
- CP_ControlResult ControlResult;
- ControlResult.cbSuccess = ER_SUCCESS;
- SendUIControlPacket(UI_LOAD_DB_LIST_RESULT, &ControlResult, sizeof(ControlResult));
-
- //设置时间
- ASSERT(m_pITimerEngine != NULL);
- m_pITimerEngine->SetTimer(IDI_LOAD_GAME_LIST, m_pInitParameter->m_wLoadListTime * 1000L, 1, 0);
- //m_pIDataBaseEngine->PostDataBaseRequest(DBR_GP_LOAD_GAME_LIST, 0, NULL, 0);
-
- return true;
- }
- case IDI_SERVICE: //加载通道
- {
- m_pITCPNetworkEngine->OnTBDataEvent(DBO_GR_UPTONGDAO, 0, NULL, 0);
- //加载通道
- //m_pIDataBaseEngine->PostDataBaseRequest(DBR_GP_ONLINE_SERVICE, 0, NULL, 0);
- return true;
- }
- case IDI_JULI: //距离清空
- {
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_GP_CLEARJULI, 0, NULL, 0);
- return true;
- }
- //m_MapUserIDJuli
- case IDI_CONNECT_CORRESPOND: //连接协调
- {
- //发起连接
- tagAddressInfo * pCorrespondAddress = &m_pInitParameter->m_CorrespondAddress;
- m_pITCPSocketService->Connect(pCorrespondAddress->szAddress, m_pInitParameter->m_wCorrespondPort);
-
- //构造提示
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("正在连接协调服务器 [ %s:%d ]"), pCorrespondAddress->szAddress, m_pInitParameter->m_wCorrespondPort);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
-
- CLogonServerDlg *p = (CLogonServerDlg *)theApp.m_pMainWnd;
-
- ///---清空子节点
- if (p)
- {
- while (true)
- {
- if (p->ServiceTree.ItemHasChildren(p->hRoot))
- {
- HTREEITEM hChildItem = p->ServiceTree.GetChildItem(p->hRoot);
- p->ServiceTree.DeleteItem(hChildItem);
- }
- else
- {
- break;
- }
- }
-
- m_LoginServiceIDMap.RemoveAll();
- }
-
- return true;
- }
- case IDI_COLLECT_ONLINE_INFO: //统计在线
- {
- //变量定义
- DBR_GP_OnLineCountInfo OnLineCountInfo;
- ZeroMemory(&OnLineCountInfo, sizeof(OnLineCountInfo));
-
- //获取总数
- OnLineCountInfo.dwOnLineCountSum = m_ServerListManager.CollectOnlineInfo(false);
- OnLineCountInfo.dwAndroidCountSum = m_ServerListManager.CollectOnlineInfo(true);
-
- //获取类型
- POSITION KindPosition = NULL;
- do
- {
- //获取类型
- CGameKindItem * pGameKindItem = m_ServerListManager.EmunGameKindItem(KindPosition);
-
- //设置变量
- if (pGameKindItem != NULL)
- {
- WORD wKindIndex = OnLineCountInfo.wKindCount++;
- OnLineCountInfo.OnLineCountKind[wKindIndex].wKindID = pGameKindItem->m_GameKind.wKindID;
-
- //目录人数
- OnLineCountInfo.OnLineCountKind[wKindIndex].dwOnLineCount = pGameKindItem->m_GameKind.dwOnLineCount;
- OnLineCountInfo.OnLineCountKind[wKindIndex].wTableCount = pGameKindItem->m_GameKind.wTableCount;
- OnLineCountInfo.OnLineCountKind[wKindIndex].wFullTableCount = pGameKindItem->m_GameKind.wFullTableCount;
- }
-
- //溢出判断
- if (OnLineCountInfo.wKindCount >= CountArray(OnLineCountInfo.OnLineCountKind))
- {
- ASSERT(FALSE);
- break;
- }
-
- } while (KindPosition != NULL);
-
- //发送请求
- WORD wHeadSize = sizeof(OnLineCountInfo) - sizeof(OnLineCountInfo.OnLineCountKind);
- WORD wSendSize = wHeadSize + OnLineCountInfo.wKindCount * sizeof(OnLineCountInfo.OnLineCountKind[0]);
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_GP_ONLINE_COUNT_INFO, 0, &OnLineCountInfo, wSendSize);
-
- return true;
- }
- ///[---add by yd
- case ID_TIMER_HEARTBEAT:
- {
- if (m_pITCPSocketService != NULL)
- {
- //变量定义
- CMD_CS_C_RegisterPlaza RegisterPlaza;
- ZeroMemory(&RegisterPlaza, sizeof(RegisterPlaza));
-
- //设置变量
- lstrcpyn(RegisterPlaza.szServerName, m_pInitParameter->m_szServerName, CountArray(RegisterPlaza.szServerName));
- lstrcpyn(RegisterPlaza.szServerAddr, m_pInitParameter->m_ServiceAddress.szAddress, CountArray(RegisterPlaza.szServerAddr));
- RegisterPlaza.wServerID = m_wServerID;
-
- m_pITCPSocketService->SendData(MDM_CS_MANAGER_SERVICE, SUB_CS_C_LOGON_HEARTBEAT, &RegisterPlaza, sizeof(RegisterPlaza));
- }
-
- if (m_dwHearbeatTime > 0) //检测协调服务器有没应答
- {
- if (GetTickCount() - m_dwHearbeatTime > 6 * TIMES_LOGONSERVER_HEARTBEAT) ///---超时没有收到回包,则断开重连
- {
- m_pITCPSocketService->CloseSocket();
- m_pITimerEngine->KillTimer(ID_TIMER_HEARTBEAT);
-
- m_dwHearbeatTime = 0; //心跳时间
-
- //构造提示
- TCHAR szDescribe[128] = TEXT("");
- _sntprintf(szDescribe, CountArray(szDescribe), TEXT("没有收到协调服务器心跳回包,%ld 秒后将重新连接"), wConnectTime/*m_pInitParameter->m_wConnectTime*/);
-
- //提示消息
- CTraceService::TraceString(szDescribe, TraceLevel_Warning);
-
- //设置时间
- ASSERT(m_pITimerEngine != NULL);
- m_pITimerEngine->SetTimer(IDI_CONNECT_CORRESPOND, /*m_pInitParameter->m_wConnectTime*/wConnectTime * 1000L, 1, 0);
- }
- }
-
- return true;
- }
- default: break;
- ///---]
-
- }
-
- return false;
- }
-
- //应答事件
- bool CAttemperEngineSink::OnEventTCPNetworkBind(DWORD dwClientAddr, DWORD dwSocketID)
- {
- //获取索引
- //ASSERT(LOWORD(dwSocketID) < m_pInitParameter->m_wMaxConnect);
- //if (LOWORD(dwSocketID) >= m_pInitParameter->m_wMaxConnect) return false;
-
- //变量定义
- WORD wBindIndex = LOWORD(dwSocketID);
- tagBindParameter * pBindParameter = (m_pBindParameter + wBindIndex);
-
- //设置变量
- pBindParameter->dwSocketID = dwSocketID;
- pBindParameter->dwClientAddr = dwClientAddr;
- pBindParameter->dwActiveTime = (DWORD)time(NULL);
-
- //转化地址
- TCHAR szClientAddr[16] = TEXT("");
- BYTE * pClientAddr = (BYTE *)&dwClientAddr;
- _sntprintf(szClientAddr, CountArray(szClientAddr), TEXT("%d.%d.%d.%d"), pClientAddr[0], pClientAddr[1], pClientAddr[2], pClientAddr[3]);
- CString str;
- //str.Format(TEXT("%s 绑定成功, dwSocketID:%d / %d"), szClientAddr, LOWORD(dwSocketID), m_pInitParameter->m_wMaxConnect);
- //CTraceService::TraceString(str, TraceLevel_Normal);
-
- return true;
- }
-
- //关闭事件
- bool CAttemperEngineSink::OnEventTCPNetworkShut(DWORD dwClientAddr, DWORD dwActiveTime, DWORD dwSocketID)
- {
- //清除信息
- WORD wBindIndex = LOWORD(dwSocketID);
- ZeroMemory((m_pBindParameter + wBindIndex), sizeof(tagBindParameter));
- return false;
- }
-
- //读取事件
- bool CAttemperEngineSink::OnEventTCPNetworkRead(TCP_Command Command, VOID * pData, WORD wDataSize, DWORD dwSocketID)
- {
- switch (Command.wMainCmdID)
- {
- case MDM_MB_YANZM://获取验证码
- {
- return OnTCPNetworkMainYanZhengM(Command.wSubCmdID, pData, wDataSize, dwSocketID);
- }
- case MDM_MB_LOGON: //登录命令
- {
- return OnTCPNetworkMainMBLogon(Command.wSubCmdID, pData, wDataSize, dwSocketID);
- }
- case MDM_GR_CHECK: //通道检测
- {
- if (Command.wSubCmdID != 1) return false;
-
- //效验参数
- ASSERT(wDataSize == sizeof(CHECK));
- if (wDataSize != sizeof(CHECK)) return false;
-
- m_pITCPNetworkEngine->SendData(dwSocketID, MDM_GR_CHECK, 1, pData, wDataSize);
-
- return true;
- }
- default: break;
- }
-
- return false;
- }
-
- //数据库事件
- bool CAttemperEngineSink::OnEventDataBase(WORD wRequestID, DWORD dwContextID, VOID * pData, WORD wDataSize)
- {
- switch (wRequestID)
- {
- case DBO_GP_GAME_LIST_RESULT: //加载结果
- {
- return OnDBPCGameListResult(dwContextID, pData, wDataSize);
- }
- case DBR_MB_IPHONEYANZM://获取验证码之前,校验数据库成功
- {
- return OnDBPCYanZhengMSuccess(dwContextID, pData, wDataSize);
- }
- case DBO_MB_LOGON_SUCCESS: //登录成功
- {
- return OnDBMBLogonSuccess(dwContextID, pData, wDataSize);
- }
- case DBO_MB_LOGON_FAILURE: //登录失败
- {
- return OnDBMBLogonFailure(dwContextID, pData, wDataSize);
- }
- default: break;
- }
-
- return false;
- }
-
- //关闭事件
- bool CAttemperEngineSink::OnEventTCPSocketShut(WORD wServiceID, BYTE cbShutReason)
- {
- //协调连接
- if (wServiceID == NETWORK_CORRESPOND)
- {
- //重连判断
- if (m_bNeekCorrespond == true)
- {
- ///[---add by yd 断线后,删除心跳定时器
- m_pITimerEngine->KillTimer(ID_TIMER_HEARTBEAT);
- ///---]
-
- //构造提示
- TCHAR szDescribe[128] = TEXT("");
- _sntprintf(szDescribe, CountArray(szDescribe), TEXT("与协调服务器的连接关闭了,%ld 秒后将重新连接"), wConnectTime/*m_pInitParameter->m_wConnectTime*/);
-
- //提示消息
- CTraceService::TraceString(szDescribe, TraceLevel_Warning);
-
- //设置时间
- ASSERT(m_pITimerEngine != NULL);
- m_pITimerEngine->SetTimer(IDI_CONNECT_CORRESPOND, wConnectTime/*m_pInitParameter->m_wConnectTime*/ * 1000L, 1, 0);
-
- return true;
- }
-
- }
-
- return false;
- }
-
- //连接事件
- bool CAttemperEngineSink::OnEventTCPSocketLink(WORD wServiceID, INT nErrorCode)
- {
- //协调连接
- if (wServiceID == NETWORK_CORRESPOND)
- {
- //错误判断
- if (nErrorCode != 0)
- {
- //构造提示
- TCHAR szDescribe[128] = TEXT("");
- _sntprintf(szDescribe, CountArray(szDescribe), TEXT("协调服务器连接失败 [ %ld ],%ld 秒后将重新连接"),
- nErrorCode, m_pInitParameter->m_wConnectTime);
-
- //提示消息
- CTraceService::TraceString(szDescribe, TraceLevel_Warning);
-
- //设置时间
- ASSERT(m_pITimerEngine != NULL);
- m_pITimerEngine->SetTimer(IDI_CONNECT_CORRESPOND, m_pInitParameter->m_wConnectTime * 1000L, 1, 0);
-
- return false;
- }
-
- //提示消息
- CTraceService::TraceString(TEXT("正在注册游戏登录服务器..."), TraceLevel_Normal);
-
- //变量定义
- CMD_CS_C_RegisterPlaza RegisterPlaza;
- ZeroMemory(&RegisterPlaza, sizeof(RegisterPlaza));
-
- //设置变量
- lstrcpyn(RegisterPlaza.szServerName, m_pInitParameter->m_szServerName, CountArray(RegisterPlaza.szServerName));
- lstrcpyn(RegisterPlaza.szServerAddr, m_pInitParameter->m_ServiceAddress.szAddress, CountArray(RegisterPlaza.szServerAddr));
-
- ///[---add by yd 用当前时间作为登录服务器的ID
- RegisterPlaza.wServerID = m_wServerID;
- ///---]
-
- //发送数据
- m_pITCPSocketService->SendData(MDM_CS_REGISTER, SUB_CS_C_REGISTER_PLAZA, &RegisterPlaza, sizeof(RegisterPlaza));
-
- return true;
- }
-
- return true;
- }
-
- //读取事件
- bool CAttemperEngineSink::OnEventTCPSocketRead(WORD wServiceID, TCP_Command Command, VOID * pData, WORD wDataSize)
- {
- //协调连接
- if (wServiceID == NETWORK_CORRESPOND)
- {
- switch (Command.wMainCmdID)
- {
- case MDM_CS_REGISTER: //注册服务
- {
- return OnTCPSocketMainRegister(Command.wSubCmdID, pData, wDataSize);
- }
- case MDM_CS_SERVICE_INFO: //服务信息
- {
- return OnTCPSocketMainServiceInfo(Command.wSubCmdID, pData, wDataSize);
- }
- case MDM_CS_MANAGER_SERVICE: //管理服务
- {
- return OnTCPSocketMainManagerService(Command.wSubCmdID, pData, wDataSize);
- }
- default: break;
- }
- }
-
- //错误断言
- ASSERT(FALSE);
-
- return true;
- }
-
- //注册事件
- bool CAttemperEngineSink::OnTCPSocketMainRegister(WORD wSubCmdID, VOID * pData, WORD wDataSize)
- {
- switch (wSubCmdID)
- {
- case SUB_CS_S_REGISTER_FAILURE: //注册失败
- {
- ///[---add by yd 注册失败,删除心跳定时器
- m_pITimerEngine->KillTimer(ID_TIMER_HEARTBEAT);
- ///---]
-
- //变量定义
- CMD_CS_S_RegisterFailure * pRegisterFailure = (CMD_CS_S_RegisterFailure *)pData;
-
- //效验参数
- ASSERT(wDataSize >= (sizeof(CMD_CS_S_RegisterFailure) - sizeof(pRegisterFailure->szDescribeString)));
- if (wDataSize < (sizeof(CMD_CS_S_RegisterFailure) - sizeof(pRegisterFailure->szDescribeString))) return false;
-
- //关闭处理
- m_bNeekCorrespond = false;
- m_pITCPSocketService->CloseSocket();
-
- //显示消息
- LPCTSTR pszDescribeString = pRegisterFailure->szDescribeString;
- if (lstrlen(pszDescribeString) > 0) CTraceService::TraceString(pszDescribeString, TraceLevel_Exception);
-
- //事件通知
- CP_ControlResult ControlResult;
- ControlResult.cbSuccess = ER_FAILURE;
- SendUIControlPacket(UI_CORRESPOND_RESULT, &ControlResult, sizeof(ControlResult));
-
- return true;
- }
- default: break;
- }
-
- return true;
- }
-
- //列表事件
- bool CAttemperEngineSink::OnTCPSocketMainServiceInfo(WORD wSubCmdID, VOID * pData, WORD wDataSize)
- {
- switch (wSubCmdID)
- {
- case SUB_CS_S_SERVER_STAT:
- {
- //游戏节点状态改变
- //效验参数
- ASSERT(wDataSize == sizeof(JN_GR_SERVICESTAT));
- if (wDataSize != sizeof(JN_GR_SERVICESTAT)) return false;
-
- //变量定义
- JN_GR_SERVICESTAT * pServerModify = (JN_GR_SERVICESTAT *)pData;
-
- //查找房间
- ASSERT(m_ServerListManager.SearchGameServer(pServerModify->dwServerID));
- CGameServerItem * pGameServerItem = m_ServerListManager.SearchGameServer(pServerModify->dwServerID);
-
- //设置房间
- if (pGameServerItem != NULL)
- {
- //修改房间信息
- pGameServerItem->m_GameServer.bService = pServerModify->bService;
-
- CLogonServerDlg *p = (CLogonServerDlg *)theApp.m_pMainWnd;
- if (p)
- {
- HTREEITEM startitem = p->ServiceTree.GetChildItem(p->hRoot);
-
- while (startitem)
- {
- CString strTemp = p->ServiceTree.GetItemText(startitem);
- DWORD dData = p->ServiceTree.GetItemData(startitem);
-
- if (dData == pServerModify->dwServerID)
- {
- if (pGameServerItem->m_GameServer.bService > 0)
- {
- //正常服务状态
- p->ServiceTree.SetItemImage(startitem, 1, 1);
- break;
- }
- else if (pGameServerItem->m_GameServer.bService == 0)
- {
- //主动不提供服务状态
- p->ServiceTree.SetItemImage(startitem, 2, 2);
- break;
- }
- else
- {
- //被攻击无法服务状态
- p->ServiceTree.SetItemImage(startitem, 3, 3);
- break;
- }
- }
- startitem = p->ServiceTree.GetNextSiblingItem(startitem);
- }
- }
- }
-
- return true;
- }
- case SUB_CS_S_SERVER_INFO: //房间信息
- {
- CTraceService::TraceString(TEXT("注册成功"), TraceLevel_Normal);
- //废弃列表
- m_ServerListManager.DisuseServerItem();
-
- return true;
- }
- case SUB_CS_S_SERVER_ONLINE: //房间人数
- {
- //效验参数
- ASSERT(wDataSize == sizeof(CMD_CS_S_ServerOnLine));
- if (wDataSize != sizeof(CMD_CS_S_ServerOnLine)) return false;
-
- //变量定义
- CMD_CS_S_ServerOnLine * pServerOnLine = (CMD_CS_S_ServerOnLine *)pData;
-
- //查找房间
- CGameServerItem * pGameServerItem = m_ServerListManager.SearchGameServer(pServerOnLine->wServerID);
- if (pGameServerItem == NULL) return true;
-
- //获取对象
- tagGameServer * pGameServer = &pGameServerItem->m_GameServer;
-
- DWORD dwOldOnlineCount = pGameServer->dwOnLineCount;
- DWORD dwOldwTableCount = pGameServer->wTableOnlineCount;
-
- //房间人数
- pGameServer->wTableOnlineCount = pServerOnLine->wTableOnlineCount;
- pGameServer->dwOnLineCount = pServerOnLine->dwOnLineCount;
- pGameServer->wTableFullCount = pServerOnLine->wTableFullCount;
-
- //目录人数
- CGameKindItem * pGameKindItem = m_ServerListManager.SearchGameKind(pGameServer->wKindID);
- if (pGameKindItem != NULL)
- {
- //目录总数
- pGameKindItem->m_GameKind.dwOnLineCount -= dwOldOnlineCount;
- pGameKindItem->m_GameKind.dwOnLineCount += pGameServer->dwOnLineCount;
-
- //机器人数
- pGameKindItem->m_GameKind.wTableCount -= dwOldwTableCount;
- pGameKindItem->m_GameKind.wTableCount += pServerOnLine->wTableOnlineCount;
- }
-
- CTime time = CTime::GetCurrentTime();
- CString m_strTime = time.Format("%Y-%m-%d %H:%M:%S");
-
- DWORD dwOnLineCountSum = m_ServerListManager.CollectOnlineInfo(false);
-
- CString csTest;
- csTest.Format(L"%d -> 人数更新 %s,总人数:%d ", pServerOnLine->wServerID, m_strTime, dwOnLineCountSum);
- CLogonServerDlg::SetUpdata(csTest);
-
- //回报核查当前登录服务器数据信息
- CMD_CS_S_ServerAllOnLine ServerAllOnLineData;
-
- ZeroMemory(&ServerAllOnLineData, sizeof(CMD_CS_S_ServerAllOnLine));
- ServerAllOnLineData.dwOnLineCount = dwOnLineCountSum;
- ServerAllOnLineData.dwServerNum = m_ServerListManager.GetGameServerCount();
-
- if (m_pITCPSocketService) m_pITCPSocketService->SendData(MDM_CS_SERVICE_INFO, SUB_CS_C_SERVER_ONLINE_ACK, &ServerAllOnLineData, sizeof(CMD_CS_S_ServerAllOnLine));
- return true;
- }
- case SUB_CS_S_SERVER_INSERT: //房间插入
- {
- //效验参数
- ASSERT(wDataSize % sizeof(tagGameServer) == 0);
- if (wDataSize % sizeof(tagGameServer) != 0) return false;
-
- //变量定义
- WORD wItemCount = wDataSize / sizeof(tagGameServer);
- tagGameServer * pGameServer = (tagGameServer *)pData;
-
- //更新数据
- for (WORD i = 0; i < wItemCount; i++)
- {
- m_ServerListManager.InsertGameServer(pGameServer);
-
- CLogonServerDlg *p = (CLogonServerDlg *)theApp.m_pMainWnd;
-
- HTREEITEM hTemp;
- if (!m_LoginServiceIDMap.Lookup(pGameServer->wServerID, hTemp))
- {
- HTREEITEM aa = nullptr;
-
- if (p != NULL)
- {
- CString csIpPort;
- csIpPort.Format(L"%s:%d level->%d stat->%s:%d", pGameServer->szServerAddr, pGameServer->wServerPort, pGameServer->wServerLevel, pGameServer->bService == 1 ? _T("run") : (pGameServer->bService == 0 ? _T("stop") : _T("by ddos")), pGameServer->bService);
- aa = p->ServiceTree.InsertItem(csIpPort, 1, 1, p->hRoot, TVI_LAST);
- p->ServiceTree.SetItemData(aa, pGameServer->wServerID);
- }
-
- m_LoginServiceIDMap[pGameServer->wServerID] = aa;
- pGameServer++;
- }
-
- }
-
- //更新加载通道
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_GP_ONLINE_SERVICE, 0, NULL, 0);
-
- return true;
- }
- case SUB_CS_S_SERVER_MODIFY: //房间修改
- {
- //效验参数
- ASSERT(wDataSize == sizeof(CMD_CS_S_ServerModify));
- if (wDataSize != sizeof(CMD_CS_S_ServerModify)) return false;
-
- //变量定义
- CMD_CS_S_ServerModify * pServerModify = (CMD_CS_S_ServerModify *)pData;
-
- //查找房间
- ASSERT(m_ServerListManager.SearchGameServer(pServerModify->wServerID));
- CGameServerItem * pGameServerItem = m_ServerListManager.SearchGameServer(pServerModify->wServerID);
-
- //设置房间
- if (pGameServerItem != NULL)
- {
- //设置人数
- DWORD dwOldOnlineCount = pGameServerItem->m_GameServer.dwOnLineCount;
- DWORD dwOldFullCount = pGameServerItem->m_GameServer.dwFullCount;
-
- //修改房间信息
- pGameServerItem->m_GameServer.wKindID = pServerModify->wKindID;
- pGameServerItem->m_GameServer.wNodeID = pServerModify->wNodeID;
- pGameServerItem->m_GameServer.wSortID = pServerModify->wSortID;
- pGameServerItem->m_GameServer.wServerPort = pServerModify->wServerPort;
- pGameServerItem->m_GameServer.dwOnLineCount = pServerModify->dwOnLineCount;
- pGameServerItem->m_GameServer.dwFullCount = pServerModify->dwFullCount;
- lstrcpyn(pGameServerItem->m_GameServer.szServerName, pServerModify->szServerName, CountArray(pGameServerItem->m_GameServer.szServerName));
- lstrcpyn(pGameServerItem->m_GameServer.szServerAddr, pServerModify->szServerAddr, CountArray(pGameServerItem->m_GameServer.szServerAddr));
-
- //目录人数
- CGameKindItem * pGameKindItem = m_ServerListManager.SearchGameKind(pGameServerItem->m_GameServer.wKindID);
- if (pGameKindItem != NULL)
- {
- tagGameServer * pGameServer = &pGameServerItem->m_GameServer;
- pGameKindItem->m_GameKind.dwOnLineCount -= dwOldOnlineCount;
- pGameKindItem->m_GameKind.dwOnLineCount += pGameServer->dwOnLineCount;
-
- pGameKindItem->m_GameKind.dwFullCount -= dwOldFullCount;
- pGameKindItem->m_GameKind.dwFullCount += pGameServer->dwFullCount;
- }
- }
-
- return true;
- }
- case SUB_CS_S_SERVER_REMOVE: //房间删除
- {
- //效验参数
- ASSERT(wDataSize == sizeof(CMD_CS_S_ServerRemove));
- if (wDataSize != sizeof(CMD_CS_S_ServerRemove)) return false;
-
- //变量定义
- CMD_CS_S_ServerRemove * pServerRemove = (CMD_CS_S_ServerRemove *)pData;
-
- //变量定义
- m_ServerListManager.DeleteGameServer(pServerRemove->wServerID);
-
- CLogonServerDlg *p = (CLogonServerDlg *)theApp.m_pMainWnd;
-
- HTREEITEM hTemp;
- if (m_LoginServiceIDMap.Lookup(pServerRemove->wServerID, hTemp))
- {
- if (p)
- {
- p->ServiceTree.DeleteItem(hTemp);
- }
- ///---add by yd 2017-8-4
- m_LoginServiceIDMap.RemoveKey(pServerRemove->wServerID);
- }
- return true;
- }
- case SUB_CS_S_SERVER_FINISH: //房间完成
- {
- ///[---add by yd 开启心跳定时器
- m_pITimerEngine->SetTimer(ID_TIMER_HEARTBEAT, TIMES_LOGONSERVER_HEARTBEAT, TIMES_INFINITY, 0);
- ///---]
-
- //清理列表
- m_ServerListManager.CleanServerItem();
-
- //事件处理
- CP_ControlResult ControlResult;
- ControlResult.cbSuccess = ER_SUCCESS;
- SendUIControlPacket(UI_CORRESPOND_RESULT, &ControlResult, sizeof(ControlResult));
-
- return true;
- }
- case SUB_CS_S_SERVER_USER_INFO: //用户房间信息
- {
- //效验参数
- ASSERT(wDataSize == sizeof(CMD_CS_S_ServerUserInfo));
- if (wDataSize != sizeof(CMD_CS_S_ServerUserInfo)) return false;
-
- //变量定义
- CMD_CS_S_ServerUserInfo * pServerUserInfo = (CMD_CS_S_ServerUserInfo *)pData;
- m_MapServerUserID[pServerUserInfo->dwUserID] = pServerUserInfo->wServerID;
- return true;
- }
- case SUB_CS_C_SERVER_JULI_ACK:
- {
- ASSERT(wDataSize == sizeof(CMD_CS_C_JULI));
- if (wDataSize != sizeof(CMD_CS_C_JULI)) return false;
-
- //投递请求
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_GP_CLEARJULIADD, 0, pData, wDataSize);
- return true;
- }
- default: break;
- }
-
- return true;
- }
-
- //管理服务
- bool CAttemperEngineSink::OnTCPSocketMainManagerService(WORD wSubCmdID, VOID * pData, WORD wDataSize)
- {
- switch (wSubCmdID)
- {
- case SUB_CS_C_LOGON_HEARTBEAT: ///收到协调服务器的心跳回包
- {
- ASSERT(wDataSize == sizeof(CMD_CS_C_RegisterPlaza));
- if (wDataSize != sizeof(CMD_CS_C_RegisterPlaza))
- {
- return false;
- }
-
- CMD_CS_C_RegisterPlaza * pRegisterPlaza = (CMD_CS_C_RegisterPlaza *)pData;
- ASSERT(pRegisterPlaza->wServerID == m_wServerID);
-
-
- m_dwHearbeatTime = GetTickCount(); ///---更新时间
- CString str;
- str.Format(L"收到协调服务器的心跳回包%ld", m_dwHearbeatTime);
- //CTraceService::TraceString(str, TraceLevel_Normal);
-
- }
- break;
- default: break;
- }
-
- return true;
- }
-
- bool CAttemperEngineSink::OnTCPNetworkMainMBLogon(WORD wSubCmdID, VOID * pData, WORD wDataSize, DWORD dwSocketID)
- {
- switch (wSubCmdID)
- {
- case SUB_MB_LOGON_ACCOUNTS_IPHONE: //帐号登录,手机号码登录,闲聊登录
- {
- return OnTCPNetworkSubMBLogonAccounts(pData, wDataSize, dwSocketID);
- }
- case SUB_MB_LOGON_OTHERPLATFORM: //微信登录
- {
- return OnTCPNetworkSubMBLogonOtherPlatform(pData, wDataSize, dwSocketID);
- }
- default: break;
- }
-
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("客户端登录失败 [非法协议ID]"));
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
-
- return false;
- }
- //获取验证码回调
- bool CAttemperEngineSink::OnTCPNetworkMainMBLogonMiMa(CString strIPhone, CString VerfCode, DWORD dwSocketID)
- {
- //投递请求
- DBR_MB_VerifCodeToMiMa LogonVerfCodeToMiMa = { 0 };
- _sntprintf(LogonVerfCodeToMiMa.PhoneNum, 12, TEXT("%s"), strIPhone);
- _sntprintf(LogonVerfCodeToMiMa.VerifCode, 7, TEXT("%s"), VerfCode);
- //lstrcpyn(LogonVerfCodeToMiMa.PhoneNum , strIPhone, 12);
- //lstrcpyn(LogonVerfCodeToMiMa.VerifCode, VerfCode, 7);
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_MB_IPHONEMIMA, dwSocketID, &LogonVerfCodeToMiMa, sizeof(DBR_MB_VerifCodeToMiMa));
- return true;
- }
-
- // 回调
- bool CAttemperEngineSink::OnTCPNetworkMainHandleMBLogon(CString strIPhone, DWORD dwSocketID)
- {
- //投递请求
- DBR_MB_VerifCodeToMiMa LogonVerfCodeToMiMa = { 0 };
- _sntprintf(LogonVerfCodeToMiMa.PhoneNum, 12, TEXT("%s"), strIPhone);
-
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_MB_HANDLE_IPHONEMIMA, dwSocketID, &LogonVerfCodeToMiMa, sizeof(DBR_MB_VerifCodeToMiMa));
- return true;
- }
-
- ////I D 登录
- //bool CAttemperEngineSink::OnTCPNetworkSubMBLogonGameID(VOID * pData, WORD wDataSize, DWORD dwSocketID)
- //{
- // CTraceService::TraceString(TEXT("CAttemperEngineSink::OnTCPNetworkSubMBLogonGameID"), TraceLevel_Debug);
- // //效验参数
- // ASSERT(wDataSize >= sizeof(CMD_MB_LogonGameID));
- // if (wDataSize < sizeof(CMD_MB_LogonGameID)) return false;
- //
- // //变量定义
- // WORD wBindIndex = LOWORD(dwSocketID);
- // tagBindParameter * pBindParameter = (m_pBindParameter + wBindIndex);
- //
- // //处理消息
- // CMD_MB_LogonGameID * pLogonGameID = (CMD_MB_LogonGameID *)pData;
- // pLogonGameID->szPassword[CountArray(pLogonGameID->szPassword) - 1] = 0;
- // pLogonGameID->szMachineID[CountArray(pLogonGameID->szMachineID) - 1] = 0;
- // pLogonGameID->szMobilePhone[CountArray(pLogonGameID->szMobilePhone) - 1] = 0;
- //
- // //设置连接
- // pBindParameter->cbClientKind = CLIENT_KIND_MOBILE;
- // pBindParameter->wModuleID = pLogonGameID->wModuleID;
- // pBindParameter->dwPlazaVersion = pLogonGameID->dwPlazaVersion;
- //
- // //效验版本
- // if (CheckPlazaVersion(pLogonGameID->cbDeviceType, pLogonGameID->dwPlazaVersion, dwSocketID) == false) return true;
- //
- // //变量定义
- // DBR_MB_LogonGameID LogonGameID;
- // ZeroMemory(&LogonGameID, sizeof(LogonGameID));
- //
- // //附加信息
- // LogonGameID.pBindParameter = (m_pBindParameter + LOWORD(dwSocketID));
- //
- // //构造数据
- // LogonGameID.dwGameID = pLogonGameID->dwGameID;
- // LogonGameID.dwClientAddr = (m_pBindParameter + LOWORD(dwSocketID))->dwClientAddr;
- // lstrcpyn(LogonGameID.szPassword, pLogonGameID->szPassword, CountArray(LogonGameID.szPassword));
- // lstrcpyn(LogonGameID.szMachineID, pLogonGameID->szMachineID, CountArray(LogonGameID.szMachineID));
- // lstrcpyn(LogonGameID.szMobilePhone, pLogonGameID->szMobilePhone, CountArray(LogonGameID.szMobilePhone));
- //
- // //投递请求
- // m_pIDataBaseEngine->PostDataBaseRequest(DBR_MB_LOGON_GAMEID, dwSocketID, &LogonGameID, sizeof(LogonGameID));
- //
- // return true;
- //}
-
- //获取手机验证码验证码
- bool CAttemperEngineSink::OnTCPNetworkMainYanZhengM(WORD wSubCmdID, VOID * pData, WORD wDataSize, DWORD dwSocketID)
- {
- LogonServer::PB_CS_C_LogonCheckVerifCode VerifCode;
- VerifCode.ParseFromArray(pData, wDataSize);
-
- DBR_MB_LogonCheckVerifCode pUser;
- ZeroMemory(&pUser, sizeof(pUser));
- CString phonenum = (CA2CTEX<2048>(VerifCode.phonenum().c_str(), CP_UTF8)).m_szBuffer;
- _sntprintf(pUser.PhoneNum, CountArray(pUser.PhoneNum), TEXT("%s"), phonenum);
- pUser.PhoneNum[11] = 0;
- CString str;
- str.Format(TEXT("手机获取验证码 %s,"), pUser.PhoneNum);
- CTraceService::TraceString(str, TraceLevel_Debug);
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_MB_IPHONEYANZM, dwSocketID, &pUser, sizeof(DBR_MB_LogonCheckVerifCode));
- return true;
- }
- //帐号登录,手机登录
- bool CAttemperEngineSink::OnTCPNetworkSubMBLogonAccounts(VOID * pData, WORD wDataSize, DWORD dwSocketID)
- {
- LogonServer::PB_CS_C_LogonAccounts LogonMobile;
- LogonMobile.ParseFromArray(pData, wDataSize);
-
- //变量定义
- WORD wBindIndex = LOWORD(dwSocketID);
- tagBindParameter * pBindParameter = (m_pBindParameter + wBindIndex);
-
- //处理消息
- CMD_MB_LogonAccounts pLogonAccounts;
- ZeroMemory(&pLogonAccounts, sizeof(pLogonAccounts));
- pLogonAccounts.wModuleID = LogonMobile.wmoduleid();
- pLogonAccounts.dwPlazaVersion = LogonMobile.dwplazaversion();
- pLogonAccounts.cbDeviceType = LogonMobile.cbdevicetype();
- pLogonAccounts.bLogonType = LogonMobile.blogontype();
- CString szaccounts = (CA2CTEX<2048>(LogonMobile.szaccounts().c_str(), CP_UTF8)).m_szBuffer;
- CString szpassword = (CA2CTEX<2048>(LogonMobile.szpassword().c_str(), CP_UTF8)).m_szBuffer;
- CString szmachineid = (CA2CTEX<2048>(LogonMobile.szmachineid().c_str(), CP_UTF8)).m_szBuffer;
- _sntprintf(pLogonAccounts.szAccounts, CountArray(pLogonAccounts.szAccounts), TEXT("%s"), szaccounts);
- _sntprintf(pLogonAccounts.szPassword, CountArray(pLogonAccounts.szPassword), TEXT("%s"), szpassword);
- _sntprintf(pLogonAccounts.szMachineID, CountArray(pLogonAccounts.szMachineID), TEXT("%s"), szmachineid);
-
- pLogonAccounts.szAccounts[CountArray(pLogonAccounts.szAccounts) - 1] = 0;
- pLogonAccounts.szPassword[CountArray(pLogonAccounts.szPassword) - 1] = 0;
- pLogonAccounts.szMachineID[CountArray(pLogonAccounts.szMachineID) - 1] = 0;
-
- //设置连接
- pBindParameter->cbClientKind = CLIENT_KIND_MOBILE;
- pBindParameter->wModuleID = pLogonAccounts.wModuleID;
- pBindParameter->dwPlazaVersion = pLogonAccounts.dwPlazaVersion;
- ////版本判断
- //if (CheckPlazaVersion(pLogonAccounts.cbDeviceType, pLogonAccounts.dwPlazaVersion, dwSocketID) == false) return true;
- //变量定义
- DBR_MB_LogonAccounts LogonAccounts;
- ZeroMemory(&LogonAccounts, sizeof(LogonAccounts));
- //附加信息
- LogonAccounts.cbDeviceType = pLogonAccounts.cbDeviceType;
- LogonAccounts.pBindParameter = (m_pBindParameter + LOWORD(dwSocketID));
- lstrcpyn(LogonAccounts.szAccounts, pLogonAccounts.szAccounts, CountArray(LogonAccounts.szAccounts));
- lstrcpyn(LogonAccounts.szPassword, pLogonAccounts.szPassword, CountArray(LogonAccounts.szPassword));
- lstrcpyn(LogonAccounts.szMachineID, pLogonAccounts.szMachineID, CountArray(LogonAccounts.szMachineID));
- if (pLogonAccounts.bLogonType == 1)//手机号码登录
- {
- lstrcpyn(LogonAccounts.szMobilePhone, pLogonAccounts.szAccounts, CountArray(LogonAccounts.szMobilePhone));
- lstrcpyn(LogonAccounts.szIPhonePassword, pLogonAccounts.szPassword, CountArray(LogonAccounts.szIPhonePassword));
- }
- LogonAccounts.LogonType = pLogonAccounts.bLogonType;
- /*测试数据
- LogonAccounts.LogonType = 1;
- TCHAR str1[12] = _T("18822861951");
- lstrcpyn(LogonAccounts.szMobilePhone, str1, CountArray(str1));
- TCHAR str2[12] = _T("123456");
- lstrcpyn(LogonAccounts.szIPhonePassword, str2, CountArray(str2));
- */
-
- //投递请求
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_MB_LOGON_ACCOUNTS, dwSocketID, &LogonAccounts, sizeof(LogonAccounts));
- return true;
- }
-
-
- //其他登录
- bool CAttemperEngineSink::OnTCPNetworkSubMBLogonOtherPlatform(VOID * pData, WORD wDataSize, DWORD dwSocketID)
- {
- CTraceService::TraceString(TEXT("CAttemperEngineSink::OnTCPNetworkSubMBLogonOtherPlatform"), TraceLevel_Debug);
-
- //变量定义
- WORD wBindIndex = LOWORD(dwSocketID);
- tagBindParameter * pBindParameter = (m_pBindParameter + wBindIndex);
-
- LogonServer::PB_CS_C_LogonOtherPlatformEx PlatformEx;
- PlatformEx.ParseFromArray(pData, wDataSize);
-
- //处理消息
- CMD_MB_LogonOtherPlatformEx pLogonOtherPlatform;
- ZeroMemory(&pLogonOtherPlatform, sizeof(pLogonOtherPlatform));
- pLogonOtherPlatform.wModuleID = PlatformEx.wmoduleid();
- pLogonOtherPlatform.dwPlazaVersion = PlatformEx.dwplazaversion();
- pLogonOtherPlatform.cbDeviceType = PlatformEx.cbdevicetype();
- pLogonOtherPlatform.cbGender = PlatformEx.cbgender();
- pLogonOtherPlatform.cbPlatformID = PlatformEx.cbplatformid();
- CString szuseruin = (CA2CTEX<2048>(PlatformEx.szuseruin().c_str(), CP_UTF8)).m_szBuffer;
- CString sznickname = (CA2CTEX<2048>(PlatformEx.sznickname().c_str(), CP_UTF8)).m_szBuffer;
- CString szcompellation = (CA2CTEX<2048>(PlatformEx.szcompellation().c_str(), CP_UTF8)).m_szBuffer;
- CString szmachineid = (CA2CTEX<2048>(PlatformEx.szmachineid().c_str(), CP_UTF8)).m_szBuffer;
- CString szmobilephone = (CA2CTEX<2048>(PlatformEx.szmobilephone().c_str(), CP_UTF8)).m_szBuffer;
- CString szheadurl = (CA2CTEX<2048>(PlatformEx.szheadurl().c_str(), CP_UTF8)).m_szBuffer;
- _sntprintf(pLogonOtherPlatform.szUserUin, CountArray(pLogonOtherPlatform.szUserUin), TEXT("%s"), szuseruin);
- _sntprintf(pLogonOtherPlatform.szNickName, CountArray(pLogonOtherPlatform.szNickName), TEXT("%s"), sznickname);
- _sntprintf(pLogonOtherPlatform.szCompellation, CountArray(pLogonOtherPlatform.szCompellation), TEXT("%s"), szcompellation);
- _sntprintf(pLogonOtherPlatform.szMachineID, CountArray(pLogonOtherPlatform.szMachineID), TEXT("%s"), szmachineid);
- _sntprintf(pLogonOtherPlatform.szMobilePhone, CountArray(pLogonOtherPlatform.szMobilePhone), TEXT("%s"), szmobilephone);
- _sntprintf(pLogonOtherPlatform.szHeadUrl, CountArray(pLogonOtherPlatform.szHeadUrl), TEXT("%s"), szheadurl);
- pLogonOtherPlatform.x = PlatformEx.x();
- pLogonOtherPlatform.y = PlatformEx.y();
- pLogonOtherPlatform.isSimulator = PlatformEx.issimulator();
- pLogonOtherPlatform.networkType = PlatformEx.networktype();
- pLogonOtherPlatform.dianliang = PlatformEx.dianliang();
-
-
- pLogonOtherPlatform.szUserUin[CountArray(pLogonOtherPlatform.szUserUin) - 1] = 0;
- //过滤非法字符
- Fstring(pLogonOtherPlatform.szNickName);
- pLogonOtherPlatform.szNickName[CountArray(pLogonOtherPlatform.szNickName) - 1] = 0;
-
- pLogonOtherPlatform.szMachineID[CountArray(pLogonOtherPlatform.szMachineID) - 1] = 0;//机器标识 版本号
- pLogonOtherPlatform.szMobilePhone[CountArray(pLogonOtherPlatform.szMobilePhone) - 1] = 0;
- pLogonOtherPlatform.szCompellation[CountArray(pLogonOtherPlatform.szCompellation) - 1] = 0;//真实名字 如果等于 AutoLogin 则为自动登录
- pLogonOtherPlatform.szHeadUrl[CountArray(pLogonOtherPlatform.szHeadUrl) - 1] = 0;
-
- //平台判断
- ASSERT(pLogonOtherPlatform.cbPlatformID == ULMBySina || pLogonOtherPlatform.cbPlatformID == ULMByTencent || pLogonOtherPlatform.cbPlatformID == ULMByRenRen);
- if (pLogonOtherPlatform.cbPlatformID != ULMBySina && pLogonOtherPlatform.cbPlatformID != ULMByTencent && pLogonOtherPlatform.cbPlatformID != ULMByRenRen)
- {
- //构造提示
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("客户端[%s]登录失败 [平台编号验证失败]"), pLogonOtherPlatform.szMachineID);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
- return false;
- }
- //设置连接
- pBindParameter->cbClientKind = CLIENT_KIND_MOBILE;
- pBindParameter->wModuleID = pLogonOtherPlatform.wModuleID;
- pBindParameter->dwPlazaVersion = pLogonOtherPlatform.dwPlazaVersion;
-
- //版本判断
- //if (CheckPlazaVersion(pLogonOtherPlatform.cbDeviceType, pLogonOtherPlatform.dwPlazaVersion, dwSocketID) == false)
- //{
- // //构造提示
- // TCHAR szString[512] = TEXT("");
- // _sntprintf(szString, CountArray(szString), TEXT("客户端[%s]登录失败 [版本验证失败]"), pLogonOtherPlatform.szMachineID);
-
- // //提示消息
- // CTraceService::TraceString(szString, TraceLevel_Normal);
- // return false;
- //}
- //变量定义
- DBR_MB_LogonOtherPlatform LogonOtherPlatform;
- ZeroMemory(&LogonOtherPlatform, sizeof(LogonOtherPlatform));
-
- //附加信息
- LogonOtherPlatform.pBindParameter = (m_pBindParameter + LOWORD(dwSocketID));
-
- //构造数据
- LogonOtherPlatform.dwClientAddr = (m_pBindParameter + LOWORD(dwSocketID))->dwClientAddr;
- LogonOtherPlatform.cbGender = pLogonOtherPlatform.cbGender;
- LogonOtherPlatform.cbPlatformID = pLogonOtherPlatform.cbPlatformID;
- lstrcpyn(LogonOtherPlatform.szUserUin, pLogonOtherPlatform.szUserUin, CountArray(LogonOtherPlatform.szUserUin));
- lstrcpyn(LogonOtherPlatform.szNickName, pLogonOtherPlatform.szNickName, CountArray(LogonOtherPlatform.szNickName));
- lstrcpyn(LogonOtherPlatform.szMachineID, pLogonOtherPlatform.szMachineID, CountArray(LogonOtherPlatform.szMachineID));
- lstrcpyn(LogonOtherPlatform.szMobilePhone, pLogonOtherPlatform.szMobilePhone, CountArray(LogonOtherPlatform.szMobilePhone));
- lstrcpyn(LogonOtherPlatform.szCompellation, pLogonOtherPlatform.szCompellation, CountArray(LogonOtherPlatform.szCompellation));
-
- lstrcpyn(LogonOtherPlatform.szHeadUrl, pLogonOtherPlatform.szHeadUrl, CountArray(LogonOtherPlatform.szHeadUrl));
- LogonOtherPlatform.x = pLogonOtherPlatform.x;
- LogonOtherPlatform.y = pLogonOtherPlatform.y;
- LogonOtherPlatform.isSimulator = pLogonOtherPlatform.cbDeviceType;
- LogonOtherPlatform.networkType = pLogonOtherPlatform.networkType;
- LogonOtherPlatform.dianliang = pLogonOtherPlatform.dianliang;
-
- //投递请求
- m_pIDataBaseEngine->PostDataBaseRequest(DBR_MB_LOGON_OTHERPLATFORM, dwSocketID, &LogonOtherPlatform, sizeof(LogonOtherPlatform));
-
- return true;
- }
-
-
- //手机号码校验
- bool CAttemperEngineSink::OnDBPCYanZhengMSuccess(DWORD dwContextID, VOID * pData, WORD wDataSize)
- {
- if ((m_pBindParameter + LOWORD(dwContextID))->dwSocketID != dwContextID)
- {
- //构造提示
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("客户端登录失败 [SOCKET核查失败]"));
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
- return false;
- }
- //变量定义
- CMD_MB_LogonCheckVerifCode* pCheckVerifCode = (CMD_MB_LogonCheckVerifCode*)pData;
- if (pCheckVerifCode->bResult == 0)
- {
- GETDUILIEBASE_EX VerifCode;
- ZeroMemory(&VerifCode, sizeof(GETDUILIEBASE_EX));
- StringCchCat(VerifCode.szIphoneNum, 12, pCheckVerifCode->PhoneNum);
- VerifCode.CommendID = 1; //校验手机验证码(只作透传)
- VerifCode.dwSocketID = dwContextID;
- CHttpClient::AddLog(dwContextID, VerifCode);
- }
- LogonServer::PB_CS_C_LogonCheckVerifCode pCheckVerif;
- pCheckVerif.set_bresult(pCheckVerifCode->bResult);
- std::string PhoneNum = CW2AEX<1024>(pCheckVerifCode->PhoneNum, CP_UTF8).m_psz;
- pCheckVerif.set_phonenum(PhoneNum);
- /*std::string strErrorDescribe = CW2AEX<1024>(pCheckVerifCode->strErrorDescribe, CP_UTF8).m_psz;
- pCheckVerif.set_strerrordescribe(strErrorDescribe);*/
- //发送数据
- std::string pbdata = pCheckVerif.SerializePartialAsString();
- m_pITCPNetworkEngine->SendData(dwContextID, MDM_MB_YANZM, 1, (void*)pbdata.c_str(), pbdata.length());
- //关闭连接
- if (pCheckVerifCode->bResult != 0)
- m_pITCPNetworkEngine->ShutDownSocket(dwContextID);
- return true;
-
- }
-
- //登录成功
- bool CAttemperEngineSink::OnDBMBLogonSuccess(DWORD dwContextID, VOID * pData, WORD wDataSize)
- {
- //判断在线
- ASSERT(LOWORD(dwContextID) < m_pInitParameter->m_wMaxConnect);
- if ((m_pBindParameter + LOWORD(dwContextID))->dwSocketID != dwContextID)
- {
- //构造提示
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("客户端登录失败 [SOCKET核查失败]"));
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
- return false;
- }
-
- //变量定义
- DBO_MB_LogonSuccess * pDBOLogonSuccess = (DBO_MB_LogonSuccess *)pData;
-
- LogonServer::PB_CS_S_LogonSuccess pLogonSuccess;
- pLogonSuccess.set_wfaceid(pDBOLogonSuccess->wFaceID);
- pLogonSuccess.set_cbgender(pDBOLogonSuccess->cbGender);
- pLogonSuccess.set_dwcustomid(pDBOLogonSuccess->dwCustomID);
- pLogonSuccess.set_dwgameid(pDBOLogonSuccess->dwGameID);
- pLogonSuccess.set_dwuserid(pDBOLogonSuccess->dwUserID);
- pLogonSuccess.set_dwexperience(pDBOLogonSuccess->dwExperience);
- pLogonSuccess.set_dwloveliness(pDBOLogonSuccess->dwLoveLiness);
- std::string szNickName = CW2AEX<1024>(pDBOLogonSuccess->szNickName, CP_UTF8).m_psz;
- std::string szDynamicPass = CW2AEX<1024>(pDBOLogonSuccess->szDynamicPass, CP_UTF8).m_psz;
- pLogonSuccess.set_sznickname(szNickName);
- pLogonSuccess.set_szdynamicpass(szDynamicPass);
- pLogonSuccess.set_luserscore(pDBOLogonSuccess->lUserScore);
- pLogonSuccess.set_luseringot(pDBOLogonSuccess->lUserIngot);
- pLogonSuccess.set_luserinsure(pDBOLogonSuccess->lUserInsure);
- pLogonSuccess.set_duserbeans(pDBOLogonSuccess->dUserBeans);
- pLogonSuccess.set_cbinsureenabled(pDBOLogonSuccess->cbInsureEnabled);
- pLogonSuccess.set_bingding(pDBOLogonSuccess->BingDing);
-
- std::string pbdata = pLogonSuccess.SerializePartialAsString();
-
- m_pITCPNetworkEngine->SendData(dwContextID, MDM_MB_LOGON, SUB_MB_LOGON_SUCCESS, (void*)pbdata.c_str(), pbdata.length());
-
-
- //------发送用户服务器ID--------
- //构造结构
- CMD_GP_UserServerID UserServerID;
- ZeroMemory(&UserServerID, sizeof(UserServerID));
- UserServerID.wServerID = 0;
-
- m_MapServerUserID.Lookup(pDBOLogonSuccess->dwUserID, UserServerID.wServerID);
-
- if (UserServerID.wServerID != 0 && m_ServerListManager.SearchGameServer(UserServerID.wServerID) == NULL)
- {
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("未找到上次游戏节点ID=%d,用户ID=%d"), UserServerID.wServerID, pDBOLogonSuccess->dwUserID);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Warning);
- UserServerID.wServerID = 0;
- }
-
- LogonServer::PB_CS_S_UserServerID ServerID;
- ServerID.set_wserverid(UserServerID.wServerID);
- std::string bdata = ServerID.SerializePartialAsString();
-
- m_pITCPNetworkEngine->SendData(dwContextID, MDM_GP_USER_SERVICE, SUB_GP_USER_SERVER_ID, (void*)bdata.c_str(), bdata.length());
-
-
-
- //发送房间
- WORD wIndex = LOWORD(dwContextID);
- int iRet = SendMobileServerInfo(dwContextID, (m_pBindParameter + wIndex)->wModuleID, pDBOLogonSuccess->dwXinYong, UserServerID.wServerID, pDBOLogonSuccess->dwUserID, pDBOLogonSuccess->llJuLi);
-
- if (iRet == -1)
- {
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("客户端登录失败 [游戏服务器未开启]"));
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
-
- LogonServer::PB_CS_S_LogonFailure pLogonFailures;
- pLogonFailures.set_lresultcode(-1);
- std::string szDescribeString = CW2AEX<1024>(TEXT("出错代码:0x01,当前无可用服务器,请稍后再试."), CP_UTF8).m_psz;
- pLogonFailures.set_szdescribestring(szDescribeString);
- //发送数据
- std::string pbdata = pLogonFailures.SerializePartialAsString();
-
- m_pITCPNetworkEngine->SendData(dwContextID, MDM_MB_LOGON, SUB_MB_LOGON_SUCCESS, (void*)pbdata.c_str(), pbdata.length());
-
- //关闭连接
- m_pITCPNetworkEngine->ShutDownSocket(dwContextID);
-
- }
- else if (iRet == 0)
- {
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("客户端登录失败iRet=0 [无此账号可用游戏服务器] 此账号级别[%d]"), pDBOLogonSuccess->dwXinYong);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
-
- LogonServer::PB_CS_S_LogonFailure pLogonFailures;
- pLogonFailures.set_lresultcode(-1);
- std::string szDescribeString = CW2AEX<1024>(TEXT("出错代码:0x02,当前无可用服务器,请稍后再试."), CP_UTF8).m_psz;
- pLogonFailures.set_szdescribestring(szDescribeString);
- //发送数据
- std::string pbdata = pLogonFailures.SerializePartialAsString();
-
- m_pITCPNetworkEngine->SendData(dwContextID, MDM_MB_LOGON, SUB_MB_LOGON_SUCCESS, (void*)pbdata.c_str(), pbdata.length());
- //关闭连接
- m_pITCPNetworkEngine->ShutDownSocket(dwContextID);
- }
- else if (iRet == -2)
- {
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("客户端登录失败iRet=-2 [无此账号可用游戏服务器] 此账号级别[%d]"), pDBOLogonSuccess->dwXinYong);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
-
- LogonServer::PB_CS_S_LogonFailure pLogonFailures;
- pLogonFailures.set_lresultcode(-1);
- std::string szDescribeString = CW2AEX<1024>(TEXT("出错代码:0x03,当前无可用服务器,请稍后再试."), CP_UTF8).m_psz;
- pLogonFailures.set_szdescribestring(szDescribeString);
- //发送数据
- std::string pbdata = pLogonFailures.SerializePartialAsString();
-
- m_pITCPNetworkEngine->SendData(dwContextID, MDM_MB_LOGON, SUB_MB_LOGON_SUCCESS, (void*)pbdata.c_str(), pbdata.length());
-
- //关闭连接
- m_pITCPNetworkEngine->ShutDownSocket(dwContextID);
- }
- return true;
- }
-
- std::string CAttemperEngineSink::string_To_UTF8(LPCSTR str, DWORD dwSize)
- {
- int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
-
- wchar_t* pwBuf = new wchar_t[nwLen + 1];//一定要加1,不然会出现尾巴
- ZeroMemory(pwBuf, nwLen * 2 + 2);
-
- ::MultiByteToWideChar(CP_ACP, 0, str, dwSize, pwBuf, nwLen);
-
- int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
-
- char* pBuf = new char[nLen + 1];
- ZeroMemory(pBuf, nLen + 1);
-
- ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
-
- std::string retStr(pBuf);
-
- delete[]pwBuf;
- delete[]pBuf;
-
- pwBuf = NULL;
- pBuf = NULL;
-
- return retStr;
- }
- //登录失败
- bool CAttemperEngineSink::OnDBMBLogonFailure(DWORD dwContextID, VOID * pData, WORD wDataSize)
- {
- //判断在线
- ASSERT(LOWORD(dwContextID) < m_pInitParameter->m_wMaxConnect);
- if ((m_pBindParameter + LOWORD(dwContextID))->dwSocketID != dwContextID) return true;
-
- //变量定义
- DBO_MB_LogonFailure * pLogonFailure = (DBO_MB_LogonFailure *)pData;
- LogonServer::PB_CS_S_LogonFailure pLogonFailures;
- pLogonFailures.set_lresultcode(pLogonFailure->lResultCode);
- std::string add = CW2AEX<1024>(pLogonFailure->szDescribeString, CP_UTF8).m_psz;
- pLogonFailures.set_szdescribestring(add);
- //发送数据
- std::string pbdata = pLogonFailures.SerializePartialAsString();
-
- m_pITCPNetworkEngine->SendData(dwContextID, MDM_MB_LOGON, SUB_MB_LOGON_FAILURE, (void*)pbdata.c_str(), pbdata.length());
-
- //关闭连接
- m_pITCPNetworkEngine->ShutDownSocket(dwContextID);
-
- return true;
- }
-
- bool CAttemperEngineSink::OnDBPCGameListResult(DWORD dwContextID, VOID * pData, WORD wDataSize)
- {
- //效验参数
- ASSERT(wDataSize == sizeof(DBO_GP_GameListResult));
- if (wDataSize != sizeof(DBO_GP_GameListResult)) return false;
-
- //变量定义
- DBO_GP_GameListResult * pGameListResult = (DBO_GP_GameListResult *)pData;
-
- //消息处理
- if (pGameListResult->cbSuccess == TRUE)
- {
- //清理列表
- m_ServerListManager.CleanKernelItem();
-
- //事件通知
- CP_ControlResult ControlResult;
- ControlResult.cbSuccess = ER_SUCCESS;
- SendUIControlPacket(UI_LOAD_DB_LIST_RESULT, &ControlResult, sizeof(ControlResult));
-
- //设置时间
- ASSERT(m_pITimerEngine != NULL);
- m_pITimerEngine->SetTimer(IDI_LOAD_GAME_LIST, m_pInitParameter->m_wLoadListTime * 1000L, 1, 0);
- }
- else
- {
- //构造提示
- TCHAR szDescribe[128] = TEXT("");
- _sntprintf(szDescribe, CountArray(szDescribe), TEXT("服务器列表加载失败,%ld 秒后将重新加载"), m_pInitParameter->m_wReLoadListTime);
-
- //提示消息
- CTraceService::TraceString(szDescribe, TraceLevel_Warning);
-
- //设置时间
- ASSERT(m_pITimerEngine != NULL);
- m_pITimerEngine->SetTimer(IDI_LOAD_GAME_LIST, m_pInitParameter->m_wReLoadListTime * 1000L, 1, 0);
- }
-
- return true;
- }
-
- //版本检测
- bool CAttemperEngineSink::CheckPlazaVersion(BYTE cbDeviceType, DWORD dwPlazaVersion, DWORD dwSocketID, bool bCheckLowVer)
- {
- //变量定义
- bool bMustUpdate = false;
- bool bAdviceUpdate = false;
- DWORD dwVersion = VERSION_PLAZA;
-
- //手机版本
- if (cbDeviceType >= DEVICE_TYPE_IPAD) dwVersion = VERSION_MOBILE_IOS;
- else if (cbDeviceType >= DEVICE_TYPE_IPHONE) dwVersion = VERSION_MOBILE_IOS;
- else if (cbDeviceType >= DEVICE_TYPE_ITOUCH) dwVersion = VERSION_MOBILE_IOS;
- else if (cbDeviceType >= DEVICE_TYPE_ANDROID) dwVersion = VERSION_MOBILE_ANDROID;
- else if (cbDeviceType == DEVICE_TYPE_PC) dwVersion = VERSION_PLAZA;
-
- //版本判断
- if (bCheckLowVer && GetSubVer(dwPlazaVersion) < GetSubVer(dwVersion)) bAdviceUpdate = true;
- if (GetMainVer(dwPlazaVersion) != GetMainVer(dwVersion)) bMustUpdate = true;
- if (GetProductVer(dwPlazaVersion) != GetProductVer(dwVersion)) bMustUpdate = true;
-
- //升级判断
- if ((bMustUpdate == true) || (bAdviceUpdate == true))
- {
- ////变量定义
- //CMD_GP_UpdateNotify UpdateNotify;
- //ZeroMemory(&UpdateNotify, sizeof(UpdateNotify));
-
- ////变量定义
- //UpdateNotify.cbMustUpdate = bMustUpdate;
- //UpdateNotify.cbAdviceUpdate = bAdviceUpdate;
- //UpdateNotify.dwCurrentVersion = dwVersion;
-
- //发送消息 mod 2019-12-26
- //m_pITCPNetworkEngine->SendData(dwSocketID, MDM_GP_LOGON, SUB_GP_UPDATE_NOTIFY, &UpdateNotify, sizeof(UpdateNotify));
-
- //中断判断
- if (bMustUpdate == true)
- {
- m_pITCPNetworkEngine->ShutDownSocket(dwSocketID);
- return false;
- }
- }
-
- return true;
- }
-
- //发送请求
- bool CAttemperEngineSink::SendUIControlPacket(WORD wRequestID, VOID * pData, WORD wDataSize)
- {
- //发送数据
- CServiceUnits * pServiceUnits = CServiceUnits::g_pServiceUnits;
- pServiceUnits->PostControlRequest(wRequestID, pData, wDataSize);
-
- return true;
- }
-
- // 函数对象
- class SortByLineCountFunc
- {
- public:
- int operator()(CGameServerItem* l, CGameServerItem* r)
- {
- return l->m_GameServer.dwOnLineCount < r->m_GameServer.dwOnLineCount;
- }
- };
-
- class SortCountFunc
- {
- public:
- int operator()(LONGLONG l, LONGLONG r)
- {
- return l< r;
- }
- };
-
- //发送房间
- int CAttemperEngineSink::SendMobileServerInfo(DWORD dwSocketID, WORD wModuleID, DWORD dwXinYong, DWORD wServerID, DWORD dUserID, LONGLONG JuLi)
- {
- //CTraceService::TraceString(L"发送房间", TraceLevel_Warning);
-
- std::wstring ip;
- //网络数据
- WORD wSendSize = 0;
- BYTE cbDataBuffer[SOCKET_TCP_PACKET];
- ZeroMemory(cbDataBuffer, SOCKET_TCP_PACKET);
-
-
- //枚举数据
- POSITION Position = NULL;
- CGameServerItem* pGameServerItem = NULL;
-
- //计算距离排名
- int iPaiMing = 0; int iCountMax = 1;
- GetPaiMing(dUserID, JuLi, iPaiMing, iCountMax);
-
- if (wServerID != 0)
- {
- pGameServerItem = m_ServerListManager.SearchGameServer(wServerID);
-
- if (pGameServerItem)
- {
- ip = pGameServerItem->GetRandom(dUserID, iPaiMing, iCountMax);//获取通道
-
- if (ip == L"")
- {
- TCHAR szString[512] = TEXT("");
- _sntprintf(szString, CountArray(szString), TEXT("未找到上次游戏节点ID=%d 的可用通道,用户ID=%d"), wServerID,dUserID);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Warning);
-
- goto end1; //获取通道失败,没能力给予断线重连。分配其他服务器IP,重新进入游戏。
- }
-
- tagGameServer temp;
- ZeroMemory(&temp, sizeof(tagGameServer));
-
- CopyMemory(&temp, &(pGameServerItem->m_GameServer), sizeof(tagGameServer));
- ZeroMemory(temp.szServerAddr, sizeof(TCHAR) * 32);
- StringCbCat(temp.szServerAddr, 32, ip.c_str());
-
- LogonServer::PB_CS_S_tagGameServer tagGameServer;
- tagGameServer.set_wkindid(pGameServerItem->m_GameServer.wKindID);
- tagGameServer.set_wnodeid(pGameServerItem->m_GameServer.wNodeID);
- tagGameServer.set_wsortid(pGameServerItem->m_GameServer.wSortID);
- tagGameServer.set_wserverid(pGameServerItem->m_GameServer.wServerID);
- tagGameServer.set_wserverkind(pGameServerItem->m_GameServer.wServerKind);
- tagGameServer.set_wservertype(pGameServerItem->m_GameServer.wServerType);
- tagGameServer.set_wserverport(pGameServerItem->m_GameServer.wServerPort);
- tagGameServer.set_lcellscore(pGameServerItem->m_GameServer.lCellScore);
- tagGameServer.set_lcellscore(pGameServerItem->m_GameServer.lEnterScore);
- tagGameServer.set_dwserverrule(pGameServerItem->m_GameServer.dwServerRule);
- tagGameServer.set_dwonlinecount(pGameServerItem->m_GameServer.dwOnLineCount);
- tagGameServer.set_wtablefullcount(pGameServerItem->m_GameServer.wTableFullCount);
- tagGameServer.set_wtableonlinecount(pGameServerItem->m_GameServer.wTableOnlineCount);
- tagGameServer.set_dwfullcount(pGameServerItem->m_GameServer.dwFullCount);
- std::string szServerAddr = CW2AEX<1024>(temp.szServerAddr, CP_UTF8).m_psz;
- std::string szServerName = CW2AEX<1024>(pGameServerItem->m_GameServer.szServerName, CP_UTF8).m_psz;
- tagGameServer.set_szserveraddr(szServerAddr);
- tagGameServer.set_szservername(szServerName);
- tagGameServer.set_dwlivetime(pGameServerItem->m_GameServer.dwLiveTime);
- tagGameServer.set_wserverlevel(pGameServerItem->m_GameServer.wServerLevel);
- std::string pbdata = tagGameServer.SerializePartialAsString();
-
- m_pITCPNetworkEngine->SendData(dwSocketID, MDM_MB_SERVER_LIST, SUB_MB_LIST_SERVER, (void*)pbdata.c_str(), pbdata.length());
-
- TCHAR szString[512] = TEXT("");
- ZeroMemory(szString, sizeof(TCHAR) * 512);
- _sntprintf(szString, CountArray(szString), TEXT("发送可用服务器[%d]-> %s:%d 通道->%s level:%d UserLevel:%d UserID:%d")
- , (pGameServerItem->m_GameServer).wServerID, pGameServerItem->m_GameServer.szServerAddr, pGameServerItem->m_GameServer.wServerPort, ip.c_str(), pGameServerItem->m_GameServer.wServerLevel, dwXinYong, dUserID);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
- return 1;
- }
- }
-
- end1:
- int iNum = m_ServerListManager.GetGameServerCount();
-
- if (iNum == 0)
- {
- LogonServer::PB_CS_S_tagGameServer tagGameServer;
- std::string pbdata = tagGameServer.SerializePartialAsString();
-
- m_pITCPNetworkEngine->SendData(dwSocketID, MDM_MB_SERVER_LIST, SUB_MB_LIST_SERVER, (void*)pbdata.c_str(), pbdata.length());
- return -1;
- }
-
- CList<CGameServerItem*> List;
- for (DWORD i = 0; i < m_ServerListManager.GetGameServerCount(); i++)
- {
- //获取数据
- pGameServerItem = m_ServerListManager.EmunGameServerItem(Position);
- if (pGameServerItem == NULL) break;
-
- ///---过滤掉金币场的GameServer
- if (pGameServerItem->m_GameServer.wNodeID > 0)
- {
- CTraceService::TraceString(L"过滤掉一个金币场房间", TraceLevel_Normal);
- continue;
- }
-
- if (pGameServerItem->m_GameServer.dwOnLineCount >= pGameServerItem->m_GameServer.dwFullCount)
- {
- if (wServerID != pGameServerItem->m_GameServer.wServerID || wServerID == 0)
- {
- TCHAR szString[512] = TEXT("");
-
- ZeroMemory(szString, sizeof(TCHAR) * 512);
- _sntprintf(szString, CountArray(szString), TEXT("wServerID=%d,pGameServerItem->m_GameServer.wServerID=%d")
- , wServerID, pGameServerItem->m_GameServer.wServerID);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
- continue;
- }
- }
-
- if (pGameServerItem->m_GameServer.wServerLevel > dwXinYong)
- {
- if (wServerID != pGameServerItem->m_GameServer.wServerID || wServerID == 0)
- {
- TCHAR szString[512] = TEXT("");
-
- ZeroMemory(szString, sizeof(TCHAR) * 512);
- _sntprintf(szString, CountArray(szString), TEXT("wServerLevel=%d,dwXinYong=%d")
- , pGameServerItem->m_GameServer.wServerLevel, dwXinYong);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
- continue;
- }
- }
-
- if (pGameServerItem->m_GameServer.bService < 1)
- {
- if (wServerID != pGameServerItem->m_GameServer.wServerID || wServerID == 0)
- {
- if (pGameServerItem->m_GameServer.bService < 0 && pGameServerItem->m_GameServer.wServerLevel == 1 && dwXinYong < 2)
- {
-
- }
- else
- {
- TCHAR szString[512] = TEXT("");
-
- ZeroMemory(szString, sizeof(TCHAR) * 512);
- _sntprintf(szString, CountArray(szString), TEXT("bService=%d")
- , pGameServerItem->m_GameServer.bService);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
- continue;
- }
- }
- }
-
- List.AddTail(pGameServerItem);
- }
-
- int iCount = List.GetCount();
- if (iCount == 0)
- {
- return -2;
- }
-
- int iCheckLevel = -1;
- iCheckLevel = dwXinYong < 9 ? dwXinYong : 2;
- CGameServerItem* pRet = NULL;
- for (int i = iCheckLevel; i > 0; i--)
- {
- CGameServerItem* pwip = GetServiceLevel(i, &List, dUserID, iPaiMing, iCountMax);
- if (pwip != NULL)
- {
- pRet = pwip;
- ip = pwip->m_GameServer.szServerAddr;
- if (ip != L"")
- {
- goto end2;
- }
- }
- }
-
- if (ip == L"")
- {
- TCHAR szString[512] = TEXT("");
-
- ZeroMemory(szString, sizeof(TCHAR) * 512);
- _sntprintf(szString, CountArray(szString), TEXT("IP为空-> 数量:%d iPaiMing:%d iCountMax:%d ")
- , List.GetCount(), iPaiMing, iCountMax);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
-
- List.RemoveAll();
- TRACE("\n%s - %d : ip is empty", __FUNCTION__, __LINE__);
- return 0;
- }
- end2:
-
- List.RemoveAll();
- if (pRet)
- {
- TCHAR szString[512] = TEXT("");
-
- ZeroMemory(szString, sizeof(TCHAR)*512);
- _sntprintf(szString, CountArray(szString), TEXT("发送可用服务器[%d]-> %s:%d 通道->%s level:%d UserLevel:%d UserID:%d")
- , (pRet->m_GameServer).wServerID, pRet->m_GameServer.szServerAddr, pRet->m_GameServer.wServerPort, ip.c_str(), pRet->m_GameServer.wServerLevel, dwXinYong, dUserID);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
-
- tagGameServer temp;
- ZeroMemory(&temp, sizeof(tagGameServer));
-
- CopyMemory(&temp, &(pRet->m_GameServer), sizeof(tagGameServer));
- ZeroMemory(temp.szServerAddr, sizeof(TCHAR)*32);
- StringCbCat(temp.szServerAddr, 32, ip.c_str());
-
- LogonServer::PB_CS_S_tagGameServer tagGameServer;
- tagGameServer.set_wkindid(temp.wKindID);
- tagGameServer.set_wnodeid(temp.wNodeID);
- tagGameServer.set_wsortid(temp.wSortID);
- tagGameServer.set_wserverid(temp.wServerID);
- tagGameServer.set_wserverkind(temp.wServerKind);
- tagGameServer.set_wservertype(temp.wServerType);
- tagGameServer.set_wserverport(temp.wServerPort);
- tagGameServer.set_lcellscore(temp.lCellScore);
- tagGameServer.set_lcellscore(temp.lEnterScore);
- tagGameServer.set_dwserverrule(temp.dwServerRule);
- tagGameServer.set_dwonlinecount(temp.dwOnLineCount);
- tagGameServer.set_wtablefullcount(temp.wTableFullCount);
- tagGameServer.set_wtableonlinecount(temp.wTableOnlineCount);
- tagGameServer.set_dwfullcount(temp.dwFullCount);
- std::string szServerAddr = CW2AEX<1024>(temp.szServerAddr, CP_UTF8).m_psz;
- std::string szServerName = CW2AEX<1024>(temp.szServerName, CP_UTF8).m_psz;
- tagGameServer.set_szserveraddr(szServerAddr);
- tagGameServer.set_szservername(szServerName);
- tagGameServer.set_dwlivetime(temp.dwLiveTime);
- tagGameServer.set_wserverlevel(temp.wServerLevel);
- std::string pbdata = tagGameServer.SerializePartialAsString();
-
- m_pITCPNetworkEngine->SendData(dwSocketID, MDM_MB_SERVER_LIST, SUB_MB_LIST_SERVER, (void*)pbdata.c_str(), pbdata.length());
-
- }
- else
- {
- TCHAR szString[512] = TEXT("");
-
- ZeroMemory(szString, sizeof(TCHAR) * 512);
- _sntprintf(szString, CountArray(szString), TEXT("IP为空2-> 数量:%d iPaiMing:%d iCountMax:%d ")
- , List.GetCount(), iPaiMing, iCountMax);
-
- //提示消息
- CTraceService::TraceString(szString, TraceLevel_Normal);
- return 0;
- }
-
- return 1;
- }
-
- //获取距离排名
- bool CAttemperEngineSink::GetPaiMing(DWORD dUserID, LONGLONG JuLi, int& iPaiMing, int& iCount)
- {
- iPaiMing = 0;
- iCount = 1;
- //枚举数据
- CDataBaseEngineSink::m_MapUserIDJuli[dUserID] = JuLi;
-
- std::vector<LONGLONG> vecJuLi;
-
- DWORD dUser;
- LONGLONG llJuLi;
- POSITION pos = CDataBaseEngineSink::m_MapUserIDJuli.GetStartPosition();
- while (pos)
- {
- CDataBaseEngineSink::m_MapUserIDJuli.GetNextAssoc(pos, dUser, llJuLi);
- vecJuLi.push_back(llJuLi);
- }
-
- iCount = vecJuLi.size();
- std::sort(vecJuLi.begin(), vecJuLi.end(), SortCountFunc());
-
- int count = vecJuLi.size();
- for (int i = 0; i < count; i++)
- {
- if (vecJuLi[i] == JuLi)
- {
- iPaiMing = i;
- break;
- }
- }
-
- vecJuLi.clear();
- return true;
- }
-
- //////////////////////////////////////////////////////////////////////////////////
-
-
- void CAttemperEngineSink::Fstring(TCHAR* pCheck)
- {
- for (int i = 0; i < 32; i++)
- {
- try
- {
- WORD bb = pCheck[i];
- if ((bb > 126 && bb < 19968)
- || (bb > 40869)
- || bb < 33)
- {
- if (pCheck[i] == 0x00) break;
- pCheck[i] = L' ';
- }
- }
- catch (...)
- {
-
- }
- }
-
- }
-
-
- // 获取可用服务器
- CGameServerItem* CAttemperEngineSink::GetServiceLevel(int iLevel, CList<CGameServerItem*>* List, DWORD UserID, int iPaiMing, int iCount)
- {
- CGameServerItem* pCGameServerItem = NULL;
- std::vector<CGameServerItem*> vecServer;
- POSITION posA = List->GetHeadPosition();
- while (posA)
- {
- CGameServerItem* ptagGameServer = List->GetNext(posA);
- if (ptagGameServer
- &&ptagGameServer->m_GameServer.wServerLevel == iLevel)
- {
- vecServer.push_back(ptagGameServer);
- }
- }
- std::sort(vecServer.begin(), vecServer.end(), SortByLineCountFunc());
- for (BYTE i = 0; i < vecServer.size(); i++)
- {
- CGameServerItem* ptagGameServer = vecServer[i];
- if (ptagGameServer&&ptagGameServer->m_GameServer.dwOnLineCount < ptagGameServer->m_GameServer.dwFullCount)
- {
- if (ptagGameServer->GetRandom(UserID, iPaiMing, iCount) == L"") continue;
- pCGameServerItem = ptagGameServer;
- break;
- }
- }
- return pCGameServerItem;
- }
|