2020-03-03 21:45:30 +00:00
|
|
|
/*
|
|
|
|
Library to manage state connexion
|
|
|
|
|
|
|
|
Copyright (C) 2019 AleaJactaEst
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "check_memory.h"
|
|
|
|
#include "state_connexion.h"
|
|
|
|
#include "network_connection_core.h"
|
2020-03-31 10:31:20 +00:00
|
|
|
#include "modules/debug/debug.h"
|
2020-04-02 19:07:38 +00:00
|
|
|
#include "modules/networkconnection/network_data.h"
|
2020-03-03 21:45:30 +00:00
|
|
|
|
2020-04-02 19:07:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
inline uint32_t diff_uint32_circulate(uint32_t a, uint32_t b)
|
|
|
|
{
|
|
|
|
// We need managed when number 'uint32_t' exceed the capacity (32bits => 4294967296)
|
|
|
|
//
|
|
|
|
// So, we split in two group.
|
|
|
|
// < 0...1073741824 > < 1073741825 ... 3221225472 > < 3221225472 ... 4294967295 >
|
|
|
|
// Group 1 : < 0...1073741824 > + < 3221225472 ... 4294967295 > => number value : 2147483648
|
|
|
|
// Group 2 : < 1073741825 ... 3221225472 > => number value : 2147483648
|
|
|
|
//
|
2020-04-10 16:09:06 +00:00
|
|
|
// TODO - check how server manage cyclic uint32 (receivedPacket / receivedAck)
|
|
|
|
// if not managed, hum
|
2020-04-02 19:07:38 +00:00
|
|
|
|
|
|
|
if ( a >= 1073741825 && a <= 3221225472 )
|
|
|
|
return a - b;
|
|
|
|
a += 1073741825;
|
|
|
|
b += 1073741825;
|
|
|
|
return a - b;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void calculate_ack_bit(NetworkData * _data, bool ackBool)
|
|
|
|
{
|
2020-04-10 16:09:06 +00:00
|
|
|
// khanat-opennel-code/code/ryzom/client/src/network_connection.cpp # bool CNetworkConnection::decodeHeader(CBitMemStream &msgin, bool checkMessageNumber)
|
|
|
|
|
2020-04-02 19:07:38 +00:00
|
|
|
// bool ackBool = (!_SystemMode && (_ConnectionState == Connected || _ConnectionState == Synchronize));
|
|
|
|
uint32_t i;
|
|
|
|
uint32_t ackBit = (ackBool ? 1 : 0);
|
|
|
|
|
|
|
|
if ( _data->_current_received_number - _data->_last_received_number < 32)
|
|
|
|
{
|
|
|
|
_data->_ack_bit_mask <<= _data->_current_received_number - _data->_last_received_number;
|
|
|
|
_data->_ack_bit_mask |= _data->_last_ack_bit << (_data->_current_received_number - _data->_last_received_number - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_data->_ack_bit_mask = (_data->_current_received_number - _data->_last_received_number == 32 && _data->_last_ack_bit != 0) ? 0x80000000 : 0x00000000;
|
|
|
|
}
|
|
|
|
_data->_last_ack_bit = ackBit;
|
|
|
|
for(i=_data->_last_received_number+1;i<_data->_current_received_number;++i)
|
|
|
|
_data->_long_ack_bit_field.clear_bit(i & 511);
|
|
|
|
_data->_long_ack_bit_field.write(_data->_current_received_number & 0x1ff, ackBool);
|
2020-04-10 16:09:06 +00:00
|
|
|
|
|
|
|
//if ( diff_uint32_circulate(_data->_last_ack_in_long_ack, _data->_current_received_number) <= 512 )
|
|
|
|
if ( _data->_last_ack_in_long_ack <= _data->_current_received_number - 512 )
|
2020-04-02 19:07:38 +00:00
|
|
|
{
|
|
|
|
_data->_last_ack_in_long_ack = _data->_current_received_number - 511;
|
|
|
|
}
|
|
|
|
_data->_last_received_number = _data->_current_received_number;
|
|
|
|
}
|
2020-03-30 20:20:59 +00:00
|
|
|
|
2020-03-03 21:45:30 +00:00
|
|
|
/*
|
|
|
|
* StateConnectionBase
|
|
|
|
*/
|
|
|
|
|
|
|
|
StateConnectionBase::StateConnectionBase(NetworkConnectionCore * network)
|
|
|
|
{
|
|
|
|
this->_network = network;
|
|
|
|
this->_data = & (network->_network_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* StateConnectionNotInitialized
|
|
|
|
*/
|
|
|
|
|
|
|
|
void StateConnectionNotInitialized::connect_to_server()
|
|
|
|
{
|
|
|
|
this->_network->_queue.clear();
|
|
|
|
this->_network->open_network();
|
|
|
|
this->_network->_state_connexion = & this->_network->_state_login;
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("connect_to_server");
|
2020-03-03 21:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* StateConnectionLogin
|
|
|
|
*/
|
|
|
|
void StateConnectionLogin::send_system_quit()
|
|
|
|
{
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("send quit to server");
|
2020-03-03 21:45:30 +00:00
|
|
|
BitStream msgout;
|
|
|
|
msgout.put_uint32(this->_data->_current_received_number);
|
|
|
|
msgout.put_bool(true);
|
|
|
|
msgout.put_uint8(CLFECOMMON::SYSTEM_QUIT_CODE);
|
|
|
|
msgout.put_sint32(this->_data->_quit_id);
|
|
|
|
|
|
|
|
if ( this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK )
|
|
|
|
{
|
|
|
|
ERR_PRINT("Error to send disconnect");
|
|
|
|
}
|
|
|
|
this->_network->_state_connexion = & this->_network->_state_quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionLogin::send_message()
|
|
|
|
{
|
|
|
|
BitStream msgout;
|
|
|
|
msgout.put_uint32(this->_data->_current_received_number);
|
|
|
|
msgout.put_bool(true);
|
|
|
|
msgout.put_uint8(CLFECOMMON::SYSTEM_LOGIN_CODE);
|
|
|
|
msgout.put_string_hexa32(this->_data->_user_addr);
|
|
|
|
msgout.put_string_hexa32(this->_data->_user_key);
|
|
|
|
msgout.put_string_hexa32(this->_data->_user_id);
|
|
|
|
msgout.put_string(this->_data->_lang);
|
|
|
|
Error ret;
|
|
|
|
ret = this->_network->_socketUDP->put_packet_buffer(msgout.get_data()); // , msgout.get_data().size()
|
|
|
|
if ( ret != Error::OK)
|
|
|
|
{
|
|
|
|
this->_network->close_network();
|
|
|
|
switch(ret)
|
|
|
|
{
|
|
|
|
case Error::ERR_CANT_CONNECT:
|
|
|
|
ERR_PRINT("network connexion - Can't connect");
|
|
|
|
default:
|
|
|
|
ERR_PRINT("network connexion - Unknown error");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Connected to khganat");
|
2020-03-03 21:45:30 +00:00
|
|
|
this->_network->_state_connexion = & this->_network->_state_synchronize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* StateConnectionSynchronize
|
|
|
|
*/
|
|
|
|
|
|
|
|
void StateConnectionSynchronize::send_system_quit()
|
|
|
|
{
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Send quit to server");
|
2020-03-03 21:45:30 +00:00
|
|
|
BitStream msgout;
|
|
|
|
msgout.put_uint32(this->_data->_current_received_number);
|
|
|
|
msgout.put_bool(true);
|
|
|
|
msgout.put_uint8(CLFECOMMON::SYSTEM_QUIT_CODE);
|
|
|
|
msgout.put_sint32(this->_data->_quit_id);
|
|
|
|
|
|
|
|
if ( this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK )
|
|
|
|
{
|
|
|
|
ERR_PRINT("Error to send quit");
|
|
|
|
}
|
|
|
|
this->_network->_state_connexion = & this->_network->_state_quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionSynchronize::send_system_ack_sync()
|
|
|
|
{
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Send system ACK Sync to server");
|
2020-03-03 21:45:30 +00:00
|
|
|
Ref<BitStream> msgout;
|
|
|
|
msgout.instance();
|
|
|
|
msgout->put_uint32(this->_data->_current_received_number);
|
|
|
|
msgout->put_bool(true);
|
|
|
|
msgout->put_uint8(CLFECOMMON::SYSTEM_ACK_SYNC_CODE);
|
|
|
|
msgout->put_sint32(this->_data->_last_received_number);
|
|
|
|
msgout->put_sint32(this->_data->_last_ack_in_long_ack);
|
|
|
|
this->_data->_long_ack_bit_field.write_serial(msgout);
|
|
|
|
msgout->put_sint32(this->_data->_server_sync);
|
|
|
|
if (this->_network->_socketUDP->put_packet_buffer(msgout->get_data()) != Error::OK)
|
|
|
|
{
|
|
|
|
ERR_PRINT("Error to send ack sync");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
msgout.unref();
|
|
|
|
this->_data->_client_sync = this->_data->_server_sync;
|
|
|
|
this->_network->_state_connexion = & this->_network->_state_connected;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionSynchronize::receive_system_sync(Ref<BitStream> msgin)
|
|
|
|
{
|
|
|
|
bool valide = true;
|
|
|
|
int i;
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("SYSTEM_SYNC_CODE\n");
|
2020-03-03 21:45:30 +00:00
|
|
|
|
|
|
|
uint32_t synchronize = msgin->get_uint32();
|
|
|
|
int64_t stime = msgin->get_sint64();
|
|
|
|
uint32_t latestsync = msgin->get_uint32();
|
|
|
|
PoolByteArray msg_xml = msgin->get_array_uint8(16);
|
|
|
|
PoolByteArray database_xml = msgin->get_array_uint8(16);
|
|
|
|
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("SYSTEM_SYNC_CODE synchronize:" + uitos(synchronize) + ", stime:" + itos(stime) + ", latestsync:" + uitos(latestsync));
|
2020-03-03 21:45:30 +00:00
|
|
|
|
|
|
|
if ( msg_xml.size() != this->_data->_checksum_msg_xml.size() )
|
|
|
|
{
|
|
|
|
valide = false;
|
2020-04-10 16:09:06 +00:00
|
|
|
ERR_PRINT("MSG XML is incorrect (server:" + itos(msg_xml.size()) +", client:" + itos(this->_data->_checksum_msg_xml.size()) + ")");
|
2020-03-03 21:45:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(i=0; i<msg_xml.size(); ++i)
|
|
|
|
{
|
|
|
|
if ( (int) msg_xml[i] != (int) this->_data->_checksum_msg_xml[i] )
|
|
|
|
{
|
|
|
|
valide = false;
|
2020-04-10 16:09:06 +00:00
|
|
|
ERR_PRINT("MSG XML is incorrect (pos:" + itos(i) +")");
|
2020-03-03 21:45:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( valide == true )
|
|
|
|
{
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("MSG XML is correct");
|
2020-03-03 21:45:30 +00:00
|
|
|
this->_data->_server_sync = latestsync;
|
|
|
|
this->_data->_synchronize = synchronize;
|
|
|
|
this->_data->_current_server_tick = this->_data->_synchronize + this->_data->_current_received_number + 2;
|
|
|
|
this->_data->_current_client_tick = this->_data->_current_server_tick + (LCT + this->_data->_ms_per_tick) / this->_data->_ms_per_tick;
|
|
|
|
this->_data->_current_client_time = this->_data->_update_time - (LCT + this->_data->_ms_per_tick);
|
|
|
|
//this->_state = STATE::Synchronize;
|
|
|
|
}
|
|
|
|
else
|
2020-04-10 16:09:06 +00:00
|
|
|
ERR_PRINT("MSG.XML is wrong");
|
2020-03-03 21:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionSynchronize::receive_message(int index)
|
|
|
|
{
|
|
|
|
bool system_mode;
|
|
|
|
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("receive_message ...");
|
2020-03-03 21:45:30 +00:00
|
|
|
|
|
|
|
//this->_data->_current_received_number = current_received_number;
|
|
|
|
Ref<BitStreamField> field = this->_network->_queue.get_msg(index);
|
|
|
|
uint32_t current_received_number = field->get_id();
|
|
|
|
Ref<BitStream> msgin = field->get_msgin();
|
|
|
|
|
|
|
|
this->_data->_current_received_number = current_received_number;
|
|
|
|
|
|
|
|
//Ref<BitStreamField> msgin = this->_network->_queue.get_msg(index)->get_msgin();
|
|
|
|
system_mode = msgin->get_bool();
|
|
|
|
if ( system_mode == true )
|
|
|
|
{
|
|
|
|
int message = msgin->get_uint8();
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case CLFECOMMON::SYSTEM_LOGIN_CODE:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("SYSTEM_LOGIN_CODE\n");
|
2020-03-03 21:45:30 +00:00
|
|
|
break;
|
|
|
|
case CLFECOMMON::SYSTEM_SYNC_CODE:
|
|
|
|
this->receive_system_sync(msgin);
|
|
|
|
break;
|
|
|
|
case CLFECOMMON::SYSTEM_STALLED_CODE:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("SYSTEM_STALLED_CODE\n");
|
2020-03-03 21:45:30 +00:00
|
|
|
break;
|
|
|
|
case CLFECOMMON::SYSTEM_SERVER_DOWN_CODE:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("SYSTEM_SERVER_DOWN_CODE\n");
|
2020-03-03 21:45:30 +00:00
|
|
|
break;
|
|
|
|
case CLFECOMMON::SYSTEM_PROBE_CODE:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("SYSTEM_PROBE_CODE\n");
|
2020-03-03 21:45:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-04-10 16:09:06 +00:00
|
|
|
ERR_PRINT("Received unknown message [" + itos(message) + "]");
|
2020-03-03 21:45:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// this->_last_received_number = current_received_number;
|
|
|
|
this->_network->_queue.erase_index(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionSynchronize::send_message()
|
|
|
|
{
|
2020-03-31 10:31:20 +00:00
|
|
|
//DEBUG_PRINTS("[%s:%d] send_system %d / %d \n", __FILE__, __LINE__, this->_data->_server_sync, this->_data->_client_sync);
|
2020-03-03 21:45:30 +00:00
|
|
|
if ( this->_data->_server_sync != this->_data->_client_sync )
|
|
|
|
this->send_system_ack_sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* StateConnectionConnected
|
|
|
|
*/
|
|
|
|
|
|
|
|
void StateConnectionConnected::send_system_quit()
|
|
|
|
{
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Send quit to server");
|
2020-03-03 21:45:30 +00:00
|
|
|
BitStream msgout;
|
|
|
|
msgout.put_uint32(this->_data->_current_received_number);
|
|
|
|
msgout.put_bool(true);
|
|
|
|
msgout.put_uint8(CLFECOMMON::SYSTEM_QUIT_CODE);
|
|
|
|
msgout.put_sint32(this->_data->_quit_id);
|
|
|
|
|
|
|
|
if ( this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK )
|
|
|
|
{
|
|
|
|
ERR_PRINT("Error to send disconnect");
|
|
|
|
}
|
|
|
|
this->_network->_state_connexion = & this->_network->_state_quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionConnected::send_system_disconnect()
|
|
|
|
{
|
|
|
|
//if ( this->_state != STATE::Connected && this->_state != STATE::ForceSynchronize ) return;
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Send disconnect to server");
|
2020-03-03 21:45:30 +00:00
|
|
|
BitStream msgout;
|
|
|
|
msgout.put_uint32(this->_data->_current_received_number);
|
|
|
|
msgout.put_bool(true);
|
|
|
|
msgout.put_uint8(CLFECOMMON::SYSTEM_DISCONNECTION_CODE);
|
|
|
|
|
|
|
|
if ( this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK )
|
|
|
|
{
|
|
|
|
ERR_PRINT("Error to send disconnect");
|
|
|
|
}
|
|
|
|
this->_network->_socketUDP->close();
|
|
|
|
// this->_state = STATE::Disconnect;
|
|
|
|
this->_network->_state_connexion = & this->_network->_state_not_initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionConnected::send_system_ack_sync()
|
|
|
|
{
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Send system ACK Sync to server");
|
2020-03-03 21:45:30 +00:00
|
|
|
|
|
|
|
Ref<BitStream> msgout;
|
|
|
|
msgout.instance();
|
|
|
|
msgout->put_uint32(this->_data->_current_received_number);
|
|
|
|
msgout->put_bool(true);
|
|
|
|
msgout->put_uint8(CLFECOMMON::SYSTEM_ACK_SYNC_CODE);
|
|
|
|
msgout->put_sint32(this->_data->_last_received_number);
|
|
|
|
msgout->put_sint32(this->_data->_last_ack_in_long_ack);
|
|
|
|
this->_data->_long_ack_bit_field.write_serial(msgout);
|
|
|
|
msgout->put_sint32(this->_data->_server_sync);
|
|
|
|
if (this->_network->_socketUDP->put_packet_buffer(msgout->get_data()) != Error::OK)
|
|
|
|
{
|
|
|
|
ERR_PRINT("Error to send ack sync");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
msgout.unref();
|
|
|
|
this->_data->_client_sync = this->_data->_server_sync;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionConnected::send_system_ack_probe()
|
|
|
|
{
|
|
|
|
// khanat-opennel-code/code/ryzom/server/src/frontend_service/fe_receive_sub.cpp:1121 void CFeReceiveSub::handleReceivedMsg( CClientHost *clienthost )
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Send system ACK PROBE to server");
|
2020-03-03 21:45:30 +00:00
|
|
|
int max = this->_data->_latest_probes.size() ;
|
|
|
|
|
|
|
|
BitStream msgout;
|
|
|
|
msgout.put_uint32(this->_data->_current_received_number);
|
|
|
|
msgout.put_bool(true);
|
|
|
|
msgout.put_uint8(CLFECOMMON::SYSTEM_ACK_PROBE_CODE);
|
|
|
|
msgout.put_sint32(max);
|
|
|
|
for(int i=0; i < max ; ++i )
|
|
|
|
{
|
|
|
|
int data = this->_data->_latest_probes[i];
|
|
|
|
msgout.put_sint32(data);
|
|
|
|
}
|
|
|
|
if (this->_network->_socketUDP->put_packet_buffer(msgout.get_data()) != Error::OK)
|
|
|
|
{
|
|
|
|
ERR_PRINT("Error to send disconnect");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->_data->_latest_probes.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionConnected::receive_system_sync(Ref<BitStream> msgin)
|
|
|
|
{
|
|
|
|
bool valide = true;
|
|
|
|
int i;
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("SYSTEM_SYNC_CODE");
|
2020-03-03 21:45:30 +00:00
|
|
|
|
|
|
|
uint32_t synchronize = msgin->get_uint32();
|
|
|
|
int64_t stime = msgin->get_sint64();
|
|
|
|
uint32_t latestsync = msgin->get_uint32();
|
|
|
|
PoolByteArray msg_xml = msgin->get_array_uint8(16);
|
|
|
|
PoolByteArray database_xml = msgin->get_array_uint8(16);
|
|
|
|
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("SYSTEM_SYNC_CODE synchronize:" + uitos(synchronize) + ", stime:" + itos(stime) + ", latestsync:" + uitos(latestsync));
|
2020-03-03 21:45:30 +00:00
|
|
|
|
|
|
|
if ( msg_xml.size() != this->_data->_checksum_msg_xml.size() )
|
|
|
|
{
|
|
|
|
valide = false;
|
2020-04-10 16:09:06 +00:00
|
|
|
ERR_PRINT("MSG XML is incorrect (server:" + itos(msg_xml.size()) +", client:" + itos(this->_data->_checksum_msg_xml.size()) + ")");
|
2020-03-03 21:45:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(i=0; i<msg_xml.size(); ++i)
|
|
|
|
{
|
|
|
|
if ( (int) msg_xml[i] != (int) this->_data->_checksum_msg_xml[i] )
|
|
|
|
{
|
|
|
|
valide = false;
|
2020-04-10 16:09:06 +00:00
|
|
|
ERR_PRINT("MSG XML is incorrect (pos:" + itos(i) +")");
|
2020-03-03 21:45:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( valide == true )
|
|
|
|
{
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("MSG XML is correct");
|
2020-03-03 21:45:30 +00:00
|
|
|
this->_data->_server_sync = latestsync;
|
|
|
|
this->_data->_synchronize = synchronize;
|
|
|
|
this->_data->_current_server_tick = this->_data->_synchronize + this->_data->_current_received_number + 2;
|
|
|
|
this->_data->_current_client_tick = this->_data->_current_server_tick + (LCT + this->_data->_ms_per_tick) / this->_data->_ms_per_tick;
|
|
|
|
this->_data->_current_client_time = this->_data->_update_time - (LCT + this->_data->_ms_per_tick);
|
|
|
|
//this->_state = STATE::Synchronize;
|
|
|
|
}
|
|
|
|
else
|
2020-04-10 16:09:06 +00:00
|
|
|
ERR_PRINT("MSG.XML is wrong");
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionConnected::unpack(Ref<BitStream> msgin)
|
|
|
|
{
|
|
|
|
bool shortcode = msgin->get_bool();
|
|
|
|
uint8_t code;
|
|
|
|
DBG_PRINT("shortcode:" + itos(shortcode));
|
|
|
|
if ( shortcode == true )
|
|
|
|
code = msgin->get_serial(2);
|
|
|
|
else
|
|
|
|
code = msgin->get_uint8();
|
|
|
|
DBG_PRINT("code:" + itos(code));
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case ACTIONCODE::ACTION_POSITION_CODE:
|
|
|
|
{
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_position.cpp:34 void CActionPosition::unpack (NLMISC::CBitMemStream &message)
|
|
|
|
// px ( 16 bit unsigned )
|
|
|
|
// py ( 16 bit unsigned )
|
|
|
|
// pz ( 16 bit unsigned ) : low bit have other signification
|
|
|
|
// 0x01 : IsRelative
|
|
|
|
// 0x02 : Interior
|
|
|
|
DBG_PRINT("ACTION_GENERIC_CODE");
|
|
|
|
uint16_t px = msgin->get_uint16();
|
|
|
|
uint16_t py = msgin->get_uint16();
|
|
|
|
uint16_t pz = msgin->get_uint16();
|
|
|
|
bool IsRelative = (pz & 0x1) != 0;
|
|
|
|
bool Interior = (pz & 0x2) != 0;
|
|
|
|
DBG_PRINT("ACTION_GENERIC_CODE px:" + uitos(px) + " py:" + uitos(py) + " pz:" + uitos(pz) + " IsRelative:" + uitos(IsRelative) + " Interior:" + uitos(Interior));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIONCODE::ACTION_GENERIC_CODE:
|
|
|
|
{
|
|
|
|
DBG_PRINT("ACTION_GENERIC_CODE");
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_generic.cpp void CActionGeneric::unpack (NLMISC::CBitMemStream &message)
|
|
|
|
// size ( 32 bits unsigned ) : if size > 512 we have an error (normally reject by server)
|
|
|
|
// StreamByte ( Array : size * 8 bits unsigned )
|
|
|
|
uint32_t size = msgin->get_uint32();
|
|
|
|
DBG_PRINT("ACTION_GENERIC_CODE size:" + uitos(size));
|
|
|
|
PoolByteArray StreamByte = msgin->get_array_uint8(size);
|
|
|
|
DBG_PRINT("ACTION_GENERIC_CODE size:" + uitos(size));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIONCODE::ACTION_GENERIC_MULTI_PART_CODE:
|
|
|
|
{
|
|
|
|
DBG_PRINT("ACTION_GENERIC_MULTI_PART_CODE");
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_generic_multi_part.h:46 virtual void unpack (NLMISC::CBitMemStream &message)
|
|
|
|
// Number ( 8 bits unsigned )
|
|
|
|
// Part ( 16 bits unsigned )
|
|
|
|
// NbBlock ( 16 bits unsigned )
|
|
|
|
// size ( 32 bits unsigned )
|
|
|
|
// PartCont ( Array : size * 8 bits unsigned )
|
|
|
|
uint8_t Number = msgin->get_uint8();
|
|
|
|
uint16_t Part = msgin->get_uint16();
|
|
|
|
uint16_t NbBlock = msgin->get_uint16();
|
|
|
|
uint32_t size = msgin->get_uint32();
|
|
|
|
PoolByteArray StreamByte = msgin->get_array_uint8(size);
|
|
|
|
DBG_PRINT("ACTION_GENERIC_MULTI_PART_CODE Number:" + uitos(Number) + " Part:" + uitos(Part) + " NbBlock:" + uitos(NbBlock) + " size:" + uitos(size));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIONCODE::ACTION_SINT64:
|
|
|
|
{
|
|
|
|
DBG_PRINT("ACTION_SINT64");
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_sint64.cpp:86 void CActionSint64::unpack (NLMISC::CBitMemStream &message)
|
|
|
|
// value ( 64 bits unsigned )
|
|
|
|
uint64_t value = msgin->get_uint64();
|
|
|
|
DBG_PRINT("ACTION_SINT64 value:" + uitos(value));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIONCODE::ACTION_SYNC_CODE:
|
|
|
|
{
|
|
|
|
DBG_PRINT("ACTION_SYNC_CODE");
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_sync.h:44 virtual void unpack (NLMISC::CBitMemStream &message)
|
|
|
|
// Sync ( 32 bits unsigned )
|
|
|
|
// BKEntityId ( 64 bits unsigned ) [see definition : khanat-opennel-code/code/nel/include/nel/misc/entity_id.h:64]
|
|
|
|
uint32_t Sync = msgin->get_uint32();
|
|
|
|
uint64_t BKEntityId = msgin->get_uint64();
|
|
|
|
DBG_PRINT("ACTION_SYNC_CODE Sync:" + uitos(Sync) + " BKEntityId:" + uitos(BKEntityId));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIONCODE::ACTION_DISCONNECTION_CODE:
|
|
|
|
{
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_disconnection.h
|
|
|
|
// No data
|
|
|
|
DBG_PRINT("ACTION_DISCONNECTION_CODE");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIONCODE::ACTION_ASSOCIATION_CODE:
|
|
|
|
{
|
|
|
|
DBG_PRINT("ACTION_ASSOCIATION_CODE");
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_association.h virtual void unpack (NLMISC::CBitMemStream &message)
|
|
|
|
// IsNewAssociation ( bool / 1 bit )
|
|
|
|
// if IsNewAssociation is true:
|
|
|
|
// SheetId ( 32 bits unsigned )
|
|
|
|
// Replace ( bool / 1 bit )
|
|
|
|
uint32_t SheetId = msgin->get_uint32();
|
|
|
|
bool Replace = msgin->get_bool();
|
|
|
|
DBG_PRINT("ACTION_ASSOCIATION_CODE SheetId:" + uitos(SheetId) + " Replace:" + uitos(Replace));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIONCODE::ACTION_LOGIN_CODE:
|
|
|
|
{
|
|
|
|
DBG_PRINT("ACTION_LOGIN_CODE");
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_login.h virtual void unpack (NLMISC::CBitMemStream &message)
|
|
|
|
// ua ( 32 bits unsigned )
|
|
|
|
// uk ( 32 bits unsigned )
|
|
|
|
// ui ( 32 bits unsigned )
|
|
|
|
uint32_t ua = msgin->get_uint32();
|
|
|
|
uint32_t uk = msgin->get_uint32();
|
|
|
|
uint32_t ui = msgin->get_uint32();
|
|
|
|
DBG_PRINT("ACTION_LOGIN_CODE ua:" + uitos(ua) + " uk:" + uitos(uk)+ " ui:" + uitos(ui));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIONCODE::ACTION_TARGET_SLOT_CODE:
|
|
|
|
{
|
|
|
|
DBG_PRINT("ACTION_TARGET_SLOT_CODE");
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_target_slot.h virtual void unpack (NLMISC::CBitMemStream &message)
|
|
|
|
// Slot ( 8 bits unsigned )
|
|
|
|
// TargetOrPickup (2 bits unsigned)
|
|
|
|
uint8_t Slot = msgin->get_uint8();
|
|
|
|
uint32_t TargetOrPickup = msgin->get_serial(2);
|
|
|
|
DBG_PRINT("ACTION_TARGET_SLOT_CODE Slot:" + uitos(Slot) + " TargetOrPickup:" + uitos(TargetOrPickup));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACTIONCODE::ACTION_DUMMY_CODE:
|
|
|
|
{
|
|
|
|
DBG_PRINT("ACTION_DUMMY_CODE");
|
|
|
|
// khanat-opennel-code/code/ryzom/common/src/game_share/action_dummy.h virtual void unpack (NLMISC::CBitMemStream &message)
|
|
|
|
// Dummy1 ( 32 bits unsigned )
|
|
|
|
// Dummy2 ( 32 bits unsigned )
|
|
|
|
uint32_t Dummy1 = msgin->get_uint32();
|
|
|
|
uint32_t Dummy2 = msgin->get_uint32();
|
|
|
|
DBG_PRINT("ACTION_DUMMY_CODE Dummy1:" + uitos(Dummy1) + " Dummy2:" + uitos(Dummy2));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ERR_PRINT("Impossible to decode message received from server (code:" + uitos(code) + ")");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionConnected::decode(Ref<BitStream> msgin, uint32_t current_received_number, uint32_t received_ack, uint32_t next_sent_packet)
|
|
|
|
{
|
|
|
|
// khanat-opennel-code/code/ryzom/client/src/impulse_decoder.cpp:38 void CImpulseDecoder::decode(CBitMemStream &inbox, TPacketNumber receivedPacket, TPacketNumber receivedAck, TPacketNumber nextSentPacket, vector<CLFECOMMON::CAction *> &actions)
|
|
|
|
int keep;
|
|
|
|
bool check_once;
|
|
|
|
bool next;
|
|
|
|
uint32_t * last_ack;
|
|
|
|
int level;
|
|
|
|
int channel;
|
|
|
|
int num;
|
|
|
|
this->_data->_last_received_ack = msgin->get_uint32();
|
|
|
|
for( level=0 ; level < 3 ; ++level )
|
|
|
|
{
|
|
|
|
DBG_PRINT("level:" + itos(level));
|
|
|
|
switch(level)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
last_ack = this->_data->_last_ack_0;
|
|
|
|
channel = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
last_ack = this->_data->_last_ack_1;
|
|
|
|
channel = current_received_number & 1;
|
|
|
|
break;
|
|
|
|
default: // 2
|
|
|
|
last_ack = this->_data->_last_ack_2;
|
|
|
|
channel = current_received_number & 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBG_PRINT("channel:" + itos(channel));
|
|
|
|
keep = -1;
|
|
|
|
check_once = false;
|
|
|
|
num = 0;
|
|
|
|
next = msgin->get_bool();
|
|
|
|
DBG_PRINT("next:" + itos(next));
|
|
|
|
while(next == true)
|
|
|
|
{
|
|
|
|
if( check_once == false )
|
|
|
|
{
|
|
|
|
check_once = true;
|
|
|
|
//keep = diff_uint32_circulate(received_ack, last_ack[channel]) >= 0;
|
|
|
|
keep = received_ack >= last_ack[channel];
|
|
|
|
if(keep)
|
|
|
|
last_ack[channel] = next_sent_packet;
|
|
|
|
}
|
|
|
|
num ++;
|
|
|
|
unpack(msgin);
|
|
|
|
/*
|
|
|
|
action = self._CActionFactory.unpack(msgin)
|
|
|
|
if keep:
|
|
|
|
logging.getLogger(LOGGER).debug("keep : %s" % str(action))
|
|
|
|
actions.append(copy.copy(action))
|
|
|
|
elif action:
|
|
|
|
logging.getLogger(LOGGER).debug("append : %s" % str(action))
|
|
|
|
self.removeCAction(copy.copy(action))
|
|
|
|
*/
|
|
|
|
|
|
|
|
// read next packet
|
|
|
|
next = msgin->get_bool();
|
|
|
|
DBG_PRINT("next:" + itos(next));
|
|
|
|
}
|
|
|
|
}
|
2020-03-03 21:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionConnected::receive_message(int index)
|
|
|
|
{
|
|
|
|
// SHOW_USAGE_MEMORY
|
|
|
|
bool system_mode;
|
|
|
|
|
2020-04-02 19:07:38 +00:00
|
|
|
//INF_PRINT("Receive application message");
|
|
|
|
|
2020-03-03 21:45:30 +00:00
|
|
|
Ref<BitStreamField> field = this->_network->_queue.get_msg(index);
|
|
|
|
uint32_t current_received_number = field->get_id();
|
2020-03-30 20:20:59 +00:00
|
|
|
|
|
|
|
if (current_received_number - this->_data->_current_received_number != 1)
|
|
|
|
{
|
|
|
|
if(this->_network->_queue.length() >= MAX_SIZE_BIT_STREAM_QUEUE)
|
|
|
|
this->_network->_state_connexion = & this->_network->_state_synchronize;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-03 21:45:30 +00:00
|
|
|
this->_data->_current_received_number = current_received_number;
|
|
|
|
Ref<BitStream> msgin = field->get_msgin();
|
|
|
|
|
|
|
|
system_mode = msgin->get_bool();
|
|
|
|
if ( system_mode == true )
|
|
|
|
{
|
2020-03-31 10:31:20 +00:00
|
|
|
//DEBUG_PRINTS("[%s:%d] system message (%d) [%d]\n", __FILE__, __LINE__, (int)current_received_number, this->_network->_queue.length());
|
2020-03-03 21:45:30 +00:00
|
|
|
int message = msgin->get_uint8();
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case CLFECOMMON::SYSTEM_LOGIN_CODE:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Receive SYSTEM_LOGIN_CODE (" + itos(current_received_number) + ") [" + uitos(this->_network->_queue.length()) + "]");
|
2020-03-03 21:45:30 +00:00
|
|
|
break;
|
|
|
|
case CLFECOMMON::SYSTEM_SYNC_CODE:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Receive SYSTEM_SYNC_CODE (" + itos(current_received_number) + ") [" + uitos(this->_network->_queue.length()) + "]");
|
2020-03-03 21:45:30 +00:00
|
|
|
this->receive_system_sync(msgin);
|
|
|
|
break;
|
|
|
|
case CLFECOMMON::SYSTEM_STALLED_CODE:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Receive SYSTEM_STALLED_CODE (" + itos(current_received_number) + ") [" + uitos(this->_network->_queue.length()) + "]");
|
2020-03-03 21:45:30 +00:00
|
|
|
break;
|
|
|
|
case CLFECOMMON::SYSTEM_SERVER_DOWN_CODE:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Receive SYSTEM_SERVER_DOWN_CODE (" + itos(current_received_number) + ") [" + uitos(this->_network->_queue.length()) + "]");
|
2020-03-03 21:45:30 +00:00
|
|
|
break;
|
|
|
|
case CLFECOMMON::SYSTEM_PROBE_CODE:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Receive SYSTEM_PROBE_CODE (" + itos(current_received_number) + ") [" + uitos(this->_network->_queue.length()) + "]");
|
2020-03-03 21:45:30 +00:00
|
|
|
this->_data->_latest_probes.append(msgin->get_sint32());
|
|
|
|
break;
|
|
|
|
default:
|
2020-03-31 10:31:20 +00:00
|
|
|
DBG_PRINT("Receive UNKNOWN SYSTEM MESSAGE [id:" + itos(message) + "] (" + itos(current_received_number) + ") [" + uitos(this->_network->_queue.length()) + "]");
|
2020-03-03 21:45:30 +00:00
|
|
|
//ERR_PRINTS("Received unknown message [" + itos(message) + "]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-10 16:09:06 +00:00
|
|
|
DBG_PRINT("Receive application message (current_received_number:" + itos(current_received_number) + ") [queue length:" + uitos(this->_network->_queue.length()) + "]");
|
|
|
|
decode(msgin, current_received_number, this->_data->_last_received_ack, this->_data->_current_send_number);
|
2020-03-03 21:45:30 +00:00
|
|
|
}
|
2020-04-02 19:07:38 +00:00
|
|
|
calculate_ack_bit(this->_data, system_mode);
|
|
|
|
|
|
|
|
//DBG_PRINT("Ack:" + this->_data->_long_ack_bit_field.show());
|
|
|
|
|
2020-03-03 21:45:30 +00:00
|
|
|
this->_network->_queue.erase_index(index);
|
2020-03-30 20:20:59 +00:00
|
|
|
// Check in buffer if we have next
|
|
|
|
if ( this->_network->_queue.is_index(index + 1) )
|
|
|
|
this->receive_message(index + 1);
|
2020-03-03 21:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateConnectionConnected::send_message()
|
|
|
|
{
|
|
|
|
if ( this->_data->_server_sync != this->_data->_client_sync )
|
|
|
|
this->send_system_ack_sync();
|
|
|
|
if (this->_data->_latest_probes.size() != 0 )
|
|
|
|
this->send_system_ack_probe();
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|