update network part

This commit is contained in:
AleaJactaEst 2020-04-11 13:56:47 +02:00
parent eab87e071f
commit c8edca8e6f
15 changed files with 1728 additions and 211 deletions

View file

@ -32,6 +32,8 @@ void BitStream::_bind_methods()
ClassDB::bind_method(D_METHOD("is_little_endian"), &BitStream::is_little_endian);
ClassDB::bind_method(D_METHOD("size"), &BitStream::size);
ClassDB::bind_method(D_METHOD("size_data"), &BitStream::size_data);
ClassDB::bind_method(D_METHOD("number_bit_not_read"), &BitStream::number_bit_not_read);
ClassDB::bind_method(D_METHOD("put_serial", "value", "nbits"), &BitStream::put_serial);
ClassDB::bind_method(D_METHOD("put_bool", "value"), &BitStream::put_bool);
@ -108,6 +110,11 @@ int BitStream::size_data()
return this->_pos;
}
int BitStream::number_bit_not_read()
{
return this->_pos - this->_read;
}
void BitStream::put_serial(uint32_t value, uint32_t nbits)
{
uint32_t v;
@ -468,4 +475,15 @@ PoolByteArray BitStream::get_array_uint8(uint32_t length)
--length;
}
return ret;
}
BitStream BitStream::get_bitstream(uint32_t length)
{
BitStream a;
while(length != 0)
{
a.put_uint8(this->get_serial(8));
--length;
}
return a;
}

View file

@ -42,6 +42,7 @@ public:
int size();
int size_data();
int number_bit_not_read();
void put_serial(uint32_t value, uint32_t nbits);
void put_bool(bool value);
@ -79,6 +80,7 @@ public:
int64_t get_sint64();
uint64_t get_uint64();
PoolByteArray get_array_uint8(uint32_t length);
BitStream get_bitstream(uint32_t length);
};
#endif

5
modules/command/SCsub Normal file
View file

@ -0,0 +1,5 @@
# SCsub
Import('env')
env.add_source_files(env.modules_sources, "*.cpp") # Add all cpp files to the build

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,35 @@
/*
Action Factory
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/>.
*/
#ifndef ACTION_FACTORY_H
#define ACTION_FACTORY_H
#include "core/object.h"
#include "modules/networkconnection/network_data.h"
class ActionFactory
{
public:
void decode_message(Ref<BitStream> msgin);
void unpack(Ref<BitStream> msgin);
void decode(NetworkData * data, Ref<BitStream> msgin);
};
#endif

15
modules/command/config.py Normal file
View file

@ -0,0 +1,15 @@
# config.py
def can_build(env, platform):
return True
def configure(env):
pass
def get_doc_classes():
return [
"ActionFactory",
]
def get_doc_path():
return "doc_classes"

View file

@ -0,0 +1,14 @@
/* register_types.cpp */
#include "register_types.h"
#include "core/class_db.h"
#include "action_factory.h"
void register_command_types() {
// ClassDB::register_class<ActionFactory>();
}
void unregister_command_types() {
// Nothing to do here in this example.
}

View file

@ -0,0 +1,5 @@
/* register_types.h */
void register_command_types();
void unregister_command_types();
/* yes, the word in the middle must be the same as the module folder name */

View file

@ -23,6 +23,7 @@
// #include "core/reference.h"
// #include "core/io/packet_peer_udp.h"
#include "core/reference.h"
#include "modules/bitset/bitset.h"
#include "core/ustring.h"
@ -77,7 +78,6 @@ public:
void define_lang(String lang);
void define_user(String user_addr, String user_key, String user_id);
void define_checksum_msg_xml(Array & checksum_msg_xml);
};
#endif

View file

@ -23,8 +23,7 @@
#include "network_connection_core.h"
#include "modules/debug/debug.h"
#include "modules/networkconnection/network_data.h"
#include "modules/command/action_factory.h"
inline uint32_t diff_uint32_circulate(uint32_t a, uint32_t b)
{
@ -83,6 +82,8 @@ StateConnectionBase::StateConnectionBase(NetworkConnectionCore * network)
{
this->_network = network;
this->_data = & (network->_network_data);
//this->_data = new Ref<NetworkData>(network->_network_data);
//this->_data.reference_ptr(network->_network_data);
}
/*
@ -411,211 +412,6 @@ void StateConnectionConnected::receive_system_sync(Ref<BitStream> msgin)
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));
}
}
}
void StateConnectionConnected::receive_message(int index)
{
// SHOW_USAGE_MEMORY
@ -669,7 +465,8 @@ void StateConnectionConnected::receive_message(int index)
else
{
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);
ActionFactory decoder;
decoder.decode(this->_data, msgin);
}
calculate_ack_bit(this->_data, system_mode);

View file

@ -142,9 +142,7 @@ public:
void send_system_disconnect();
void send_system_ack_sync();
void send_system_ack_probe();
void unpack(Ref<BitStream> msgin);
void receive_system_sync(Ref<BitStream> msgin);
void decode(Ref<BitStream> msgin, uint32_t current_received_number, uint32_t received_ack, uint32_t next_sent_packet);
void receive_message(int index);
void send_message();
};

View file

@ -26,6 +26,7 @@ void ReferentialMessage::_bind_methods()
{
ClassDB::bind_method(D_METHOD("read_referential", "dictionary_message"), &ReferentialMessage::read_referential);
ClassDB::bind_method(D_METHOD("show"), &ReferentialMessage::show);
ClassDB::bind_method(D_METHOD("read_command"), &ReferentialMessage::read_command);
ClassDB::bind_method(D_METHOD("clear_session"), &ReferentialMessage::clear_session);
}
@ -40,6 +41,11 @@ void ReferentialMessage::show()
ReferentialMessageCore::get_singleton()->show();
}
int ReferentialMessage::read_command(Ref<BitStream> msgin)
{
return ReferentialMessageCore::get_singleton()->read_command(msgin);
}
void ReferentialMessage::clear_session()
{
ReferentialMessageCore::clear_session();

View file

@ -38,6 +38,7 @@ public:
void _init() {};
void read_referential(Dictionary dictionary_message);
void show();
int read_command(Ref<BitStream> msgin);
void clear_session();
};

View file

@ -731,6 +731,16 @@ void ElementReferential::show(int level, int pos)
}
}
int ElementReferential::read_command(Ref<BitStream> msgin)
{
uint32_t i = msgin->get_serial(_power2);
Ref<ElementReferential> child = _children[i];
if ( child->_id != ReferentialMessageCore::Command::__LAST_ELEMENT )
return child->_id;
return child->read_command(msgin);
}
/*
* ReferentialMessageCore
*/
@ -1844,4 +1854,9 @@ void ReferentialMessageCore::clear_session()
DBG_PRINT("Clear session for Referential Message.");
delete ReferentialMessageCore::singleton;
ReferentialMessageCore::singleton = nullptr;
}
int ReferentialMessageCore::read_command(Ref<BitStream> msgin)
{
return _decoder->read_command(msgin);
}

View file

@ -26,6 +26,8 @@
#include "modules/bitstream/bitstream.h"
#include "modules/debug/debug.h"
String get_command_name(uint32_t id);
inline uint32_t getPowerOf2(uint32_t v)
{
// See code : khanat-opennel-code/code/nel/src/misc/common.cpp
@ -56,6 +58,7 @@ public:
int get_size() { return _children.size();}
Ref<ElementReferential> add_child(uint32_t id, uint32_t pos) { Ref<ElementReferential> tmp; tmp.instance(); tmp->_id = id; _children.set(pos, tmp); tmp.unref(); return _children[pos]; }
void show(int level=0, int pos=0);
int read_command(Ref<BitStream> msgin);
};
class ReferentialMessageCore : public Reference
@ -435,6 +438,7 @@ public:
void show();
static void clear_session();
int read_command(Ref<BitStream> msgin);
};
VARIANT_ENUM_CAST(ReferentialMessageCore::Command);