- case 2:
- if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout)
- {
- phase = 1;
- phaseTime = GetTickCount();
- if (pStatusChangedCb != NULL)
- pStatusChangedCb(0, statusChangedCbData);
- }
-
- if (action == IA_DISCONNECT)
- {
- action = IA_NONE;
- NetSend(DISCONN_SYN_N);
- phase = 4;
- phaseTime = GetTickCount();
- }
-
- break;
-
- case 3:
- if ((int)(GetTickCount() - phaseTime)/1000 > userTimeout)
- {
- phase = 1;
- phaseTime = GetTickCount();
- if (pStatusChangedCb != NULL)
- pStatusChangedCb(0, statusChangedCbData);
- firstConnect = false;
- }
-
- if (action == IA_DISCONNECT)
- {
- action = IA_NONE;
- NetSend(DISCONN_SYN_N);
- phase = 4;
- phaseTime = GetTickCount();
- }
-
- break;
-
- case 4:
- if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout)
- {
- phase=1;
- phaseTime = GetTickCount();
- if (pStatusChangedCb != NULL)
- pStatusChangedCb(0, statusChangedCbData);
- }
-
- if (action == IA_CONNECT)
- {
- action = IA_NONE;
- NetSend(CONN_SYN_N);
- phase = 2;
- phaseTime = GetTickCount();
- }
-
- break;
-
- case 5:
- if ((int)(GetTickCount() - phaseTime)/1000 > aliveTimeout)
- {
- phase = 1;
- phaseTime = GetTickCount();
- if (pStatusChangedCb != NULL)
- pStatusChangedCb(0, statusChangedCbData);
- }
-
- if (action == IA_CONNECT)
- {
- action = IA_NONE;
- NetSend(CONN_SYN_N);
- phase = 2;
- phaseTime = GetTickCount();
- }
-
- break;
+ switch (m_phase)
+ {
+ case 1:
+ if (m_action == IA_CONNECT)
+ {
+ m_action = IA_NONE;
+ NetSend(CONN_SYN_N);
+ m_phase = 2;
+ m_phaseTime = GetTickCount();
+ }
+ if (m_reconnect && !m_firstConnect)
+ {
+ m_action = IA_CONNECT;
+ }
+ break;
+
+ case 2:
+ if (static_cast<int>(GetTickCount() - m_phaseTime)/1000 > m_aliveTimeout)
+ {
+ m_phase = 1;
+ m_phaseTime = GetTickCount();
+ if (m_pStatusChangedCb != NULL)
+ m_pStatusChangedCb(0, m_statusChangedCbData);
+ }
+
+ if (m_action == IA_DISCONNECT)
+ {
+ m_action = IA_NONE;
+ NetSend(DISCONN_SYN_N);
+ m_phase = 4;
+ m_phaseTime = GetTickCount();
+ }
+
+ break;
+
+ case 3:
+ if (static_cast<int>(GetTickCount() - m_phaseTime)/1000 > m_userTimeout)
+ {
+ m_phase = 1;
+ m_phaseTime = GetTickCount();
+ if (m_pStatusChangedCb != NULL)
+ m_pStatusChangedCb(0, m_statusChangedCbData);
+ m_firstConnect = false;
+ }
+
+ if (m_action == IA_DISCONNECT)
+ {
+ m_action = IA_NONE;
+ NetSend(DISCONN_SYN_N);
+ m_phase = 4;
+ m_phaseTime = GetTickCount();
+ }
+
+ break;
+
+ case 4:
+ if (static_cast<int>(GetTickCount() - m_phaseTime)/1000 > m_aliveTimeout)
+ {
+ m_phase=1;
+ m_phaseTime = GetTickCount();
+ if (m_pStatusChangedCb != NULL)
+ m_pStatusChangedCb(0, m_statusChangedCbData);
+ }
+
+ if (m_action == IA_CONNECT)
+ {
+ m_action = IA_NONE;
+ NetSend(CONN_SYN_N);
+ m_phase = 2;
+ m_phaseTime = GetTickCount();
+ }
+
+ break;
+
+ case 5:
+ if (static_cast<int>(GetTickCount() - m_phaseTime)/1000 > m_aliveTimeout)
+ {
+ m_phase = 1;
+ m_phaseTime = GetTickCount();
+ if (m_pStatusChangedCb != NULL)
+ m_pStatusChangedCb(0, m_statusChangedCbData);
+ }
+
+ if (m_action == IA_CONNECT)
+ {
+ m_action = IA_NONE;
+ NetSend(CONN_SYN_N);
+ m_phase = 2;
+ m_phaseTime = GetTickCount();
+ }
+
+ break;
+ }
+ std::this_thread::sleep_for(std::chrono::milliseconds(20));