// 循环发送PushMsg 消息处理线程 DWORD CServerPointDlg::_CycleSendPushMsgThreadProc(LPVOID lParam) { CServerPointDlg *pDlg = reinterpret_cast<CServerPointDlg*>(lParam); int nCount = 0; pDlg->m_SrvPoint.SetTokenID(T2S((pDlg->m_strTokenID.GetBuffer()))); pDlg->m_strTokenID.ReleaseBuffer(); string strSendContent = T2S(pDlg->m_strContent.GetBuffer()); pDlg->m_strContent.ReleaseBuffer(); char szbuf[1024] = {0}; while (!pDlg->m_bStopCycleSend) { ZeroMemory(szbuf,sizeof(szbuf)); sprintf_s(szbuf, sizeof(szbuf), strSendContent.c_str(), nCount); pDlg->m_SrvPoint.SendPushMessage(szbuf); ++nCount; //WaitForSingleObject(pDlg->m_CycleSendInterval_event,INFINITE); DWORD dwNow = ::GetTickCount(); while (!pDlg->m_bStopCycleSend && TIME_DIFF(dwNow, ::GetTickCount()) >= (DWORD)(pDlg->m_nSend_Interval)) { Sleep(20); } } return 0; }
// 连接到PushServer DWORD CServerPointDlg::_ConnectThreadProc(LPVOID lParam) { CServerPointDlg *pDlg = reinterpret_cast<CServerPointDlg*>(lParam); // 填ServerEndPoint 相关设置 AppID, AppKey, TokenID.. pDlg->m_SrvPoint.SetAppInfo(T2S(pDlg->m_strApplID.GetBuffer()), T2S(pDlg->m_strAppKey.GetBuffer())); pDlg->m_strApplID.ReleaseBuffer(); pDlg->m_strAppKey.ReleaseBuffer(); // 连接到PushServer BOOL bResult = pDlg->m_SrvPoint.Connect2PushSRV(pDlg->dwPushSerIP, pDlg->nPort); bResult = bResult && pDlg->m_SrvPoint.GetChallenge(); bResult = bResult && pDlg->m_SrvPoint.LoginServer(); pDlg->m_SrvPoint.AddListener(pDlg); if (bResult) { pDlg->PostMessage(SUCCESS_CONNECT, 0, 0); } else { pDlg->PostMessage(ERROR_CONNECT, 0, 0); } return bResult; }
const char *ScaleModeStr(int s) { switch (s) { T2S(SCALE_MODE_NN, "Nearest neighbor"); T2S(SCALE_MODE_BILINEAR, "Bilinear"); default: return ""; } }
const char *SwitchMoveStyleStr(int s) { switch (s) { T2S(SWITCHMOVE_SLIDE, "Slide"); T2S(SWITCHMOVE_STRAFE, "Strafe"); T2S(SWITCHMOVE_NONE, "None"); default: return ""; } }
const char *LaserSightStr(int l) { switch (l) { T2S(LASER_SIGHT_NONE, "None"); T2S(LASER_SIGHT_PLAYERS, "Players only"); T2S(LASER_SIGHT_ALL, "All"); default: return ""; } }
const char *FireMoveStyleStr(int s) { switch (s) { T2S(FIREMOVE_STOP, "Stop"); T2S(FIREMOVE_NORMAL, "Normal"); T2S(FIREMOVE_STRAFE, "Strafe"); default: return ""; } }
const char *SplitscreenStyleStr(int s) { switch (s) { T2S(SPLITSCREEN_NORMAL, "Normal"); T2S(SPLITSCREEN_ALWAYS, "Always"); T2S(SPLITSCREEN_NEVER, "Never"); default: return ""; } }
const char *GoreAmountStr(int g) { switch (g) { T2S(GORE_NONE, "None"); T2S(GORE_LOW, "Trickle"); T2S(GORE_MEDIUM, "Buckets"); T2S(GORE_HIGH, "Torrents"); default: return ""; } }
const char *LogModuleName(const LogModule m) { switch (m) { T2S(LM_MAIN, "MAIN"); T2S(LM_NET, "NET"); T2S(LM_INPUT, "INPUT"); T2S(LM_ACTOR, "ACTOR"); default: return ""; } }
const char *QuickPlayQuantityStr(int q) { switch (q) { T2S(QUICKPLAY_QUANTITY_ANY, "Any"); T2S(QUICKPLAY_QUANTITY_SMALL, "Small"); T2S(QUICKPLAY_QUANTITY_MEDIUM, "Medium"); T2S(QUICKPLAY_QUANTITY_LARGE, "Large"); default: return ""; } }
const char *AIChatterStr(int c) { switch (c) { T2S(AICHATTER_NONE, "None"); T2S(AICHATTER_SELDOM, "Seldom"); T2S(AICHATTER_OFTEN, "Often"); T2S(AICHATTER_ALWAYS, "Always"); default: return ""; } }
const char *DifficultyStr(int d) { switch (d) { T2S(DIFFICULTY_VERYEASY, "Easiest"); T2S(DIFFICULTY_EASY, "Easy"); T2S(DIFFICULTY_NORMAL, "Normal"); T2S(DIFFICULTY_HARD, "Hard"); T2S(DIFFICULTY_VERYHARD, "Very hard"); default: return ""; } }
void CServerPointDlg::OnBnClickedSend() { UpdateData(TRUE); if (m_strContent.IsEmpty() || m_strTokenID.IsEmpty() ) { MessageBox(_T("TokenID和内容不能为空"), _T("注意!"), MB_ICONWARNING | MB_OK); return; } m_SrvPoint.SetTokenID(T2S((m_strTokenID.GetBuffer()))); m_strTokenID.ReleaseBuffer(); m_SrvPoint.SendPushMessage(T2S(m_strContent.GetBuffer())); m_strContent.ReleaseBuffer(); }
const char *LogLevelName(const LogLevel l) { switch (l) { T2S(LL_TRACE, "TRACE"); T2S(LL_DEBUG, "DEBUG"); T2S(LL_INFO, "INFO"); T2S(LL_WARN, "WARN"); T2S(LL_ERROR, "ERROR"); default: return ""; } }
const char *ObjectiveTypeStr(ObjectiveType t) { switch (t) { T2S(OBJECTIVE_KILL, "Kill"); T2S(OBJECTIVE_COLLECT, "Collect"); T2S(OBJECTIVE_DESTROY, "Destroy"); T2S(OBJECTIVE_RESCUE, "Rescue"); T2S(OBJECTIVE_INVESTIGATE, "Explore"); default: return ""; } }
std::string CFileLogger::GetFileAppenderName(log4cplus::Logger& logger) { std::string appedname = logger.getName() + "-f-"; appedname += T2S(__LINE__); return appedname; }
std::string Int2Str(int data, const std::string& defaultvale) { std::string ret = defaultvale; try { ret = T2S(data); } catch (...) { ; } return ret; }
void CServerPointDlg::OnBnClickedCycleSend() { UpdateData(TRUE); if (m_strContent.IsEmpty() || m_strTokenID.IsEmpty() ) { MessageBox(_T("TokenID和内容不能为空"), _T("注意!"), MB_ICONWARNING | MB_OK); return; } if (m_nSend_Interval < 0 || m_nSend_Interval >200) { MessageBox(_T("循环发送的时间间隔设置错误,请修改!(范围是0-200)"),_T("注意!"), MB_ICONWARNING | MB_OK); return; } // 判断要发送的内容中,有没有含%d // 有则开始发送,否则提示 if (m_strContent.Find(_T("%d")) == -1) { // 没有找到%d MessageBox(_T("要发送的肉容中,没有找到%d,请修改!"), _T("注意!"), MB_ICONWARNING | MB_OK); return; } // 否则就是有找到 m_btn_SendContent.EnableWindow(FALSE); m_btn_ClearText.EnableWindow(FALSE); m_btn_CycleSend.EnableWindow(FALSE); m_btn_Stop_CycleSend.EnableWindow(TRUE); m_SrvPoint.SetTokenID(T2S((m_strTokenID.GetBuffer()))); m_strTokenID.ReleaseBuffer(); m_SrvPoint.SendPushMessage(T2S(m_strContent.GetBuffer())); m_strContent.ReleaseBuffer(); // TODO: 在此添加控件通知处理程序代码 // SetTimer(IDTM_CYCLE_SEND_INTERVAL, m_nSend_Interval*1000,NULL); m_bStopCycleSend = FALSE; m_hThreadCycleSend = ::CreateThread(NULL, 0, _CycleSendPushMsgThreadProc, this, 0, &m_nCycleSendThreadID); }
void CIOCP_ClientDlg::OnBnClickedStartTest() { if (UpdateData(TRUE)) { SetDlgItemInt(IDE_SESSION_NUM, 0, FALSE); m_nTestSpendTime = 0; SetDlgItemText(IDE_SPEND_TIME,_T("00:00")); SetTimer(ID_TIMER_PER_SEC, 1000,NULL); int iRadioButton = GetCheckedRadioButton(IDRB_GETCHALLENGE , IDRB_GETPUSHMSG); switch (iRadioButton) { case IDRB_CONNET: m_testType = SocketConnect; break; case IDRB_GETCHALLENGE: m_testType = GetChallenge; break; case IDRB_REGISTER: m_testType = RegisterToken; break; case IDRB_GETPUSHMSG: m_testType = GetPushMsg; break; } GetDlgItem(IDB_START_TEST)->EnableWindow(FALSE); GetDlgItem(IDB_STOP_TEST)->EnableWindow(TRUE); TSTRING strPerTokenID = m_strPreTokenID.GetBuffer(); ClientDB::GetInstance()->ExecuteSQL(TEXT("BEGIN;")); // Sqlite 开始事务 SetTimer(ID_TIMER_FRESH_INTERVAL, 100, NULL); // 设置自动上下线的时间阀值,每个Client对象都会从中随机Random出两个时间,用于上线和下线 TIME_THRESHOLD tm_threshold; tm_threshold.nMinOfflineIntervalTime = m_nMinOfflineTime; tm_threshold.nMaxOfflineIntervalTime = m_nMaxOfflineTime; tm_threshold.nMinOnlineIntervalTime = m_nMinOnlineTime; tm_threshold.nMaxOnlineIntervalTime = m_nMaxOnlineTime; srand(GetTickCount()); m_IOCPModel.StartTest(m_dwServerIP, m_nServerPort, T2S(strPerTokenID).c_str(), m_TokenID_StartNum, m_nClientNum, m_testType, tm_threshold); m_strPreTokenID.ReleaseBuffer(); } }
const char *KeycodeStr(int k) { switch (k) { T2S(KEY_CODE_LEFT, "left"); T2S(KEY_CODE_RIGHT, "right"); T2S(KEY_CODE_UP, "up"); T2S(KEY_CODE_DOWN, "down"); T2S(KEY_CODE_BUTTON1, "button1"); T2S(KEY_CODE_BUTTON2, "button2"); T2S(KEY_CODE_MAP, "map"); default: return ""; } }
const char *PlacementFlagStr(const int i) { switch (i) { T2S(PLACEMENT_OUTSIDE, "Outside"); T2S(PLACEMENT_INSIDE, "Inside"); T2S(PLACEMENT_NO_WALLS, "NoWalls"); T2S(PLACEMENT_ONE_WALL, "OneWall"); T2S(PLACEMENT_ONE_OR_MORE_WALLS, "OneOrMoreWalls"); T2S(PLACEMENT_FREE_IN_FRONT, "FreeInFront"); T2S(PLACEMENT_ON_WALL, "OnWall"); default: return ""; } }