- 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;
+ 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));