Skip to content

Commit

Permalink
Move network protocol implementation behind an interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Aug 21, 2024
1 parent c6ef5ab commit 7968ab6
Show file tree
Hide file tree
Showing 18 changed files with 2,103 additions and 2,048 deletions.
7 changes: 3 additions & 4 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ void Client::connect(const Address &address, const std::string &address_name,
}

m_address_name = address_name;
m_con.reset(new con::Connection(PROTOCOL_ID, 512, CONNECTION_TIMEOUT,
address.isIPv6(), this));
m_con.reset(con::createMTP(CONNECTION_TIMEOUT, address.isIPv6(), this));

infostream << "Connecting to server at ";
address.print(infostream);
Expand Down Expand Up @@ -866,13 +865,13 @@ bool Client::loadMedia(const std::string &data, const std::string &filename,
}

// Virtual methods from con::PeerHandler
void Client::peerAdded(con::Peer *peer)
void Client::peerAdded(con::IPeer *peer)
{
infostream << "Client::peerAdded(): peer->id="
<< peer->id << std::endl;
}

void Client::deletingPeer(con::Peer *peer, bool timeout)
void Client::deletingPeer(con::IPeer *peer, bool timeout)
{
infostream << "Client::deletingPeer(): "
"Server Peer is getting deleted "
Expand Down
8 changes: 4 additions & 4 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Camera;
struct PlayerControl;
class NetworkPacket;
namespace con {
class Connection;
class IConnection;
}
using sound_handle_t = int;

Expand Down Expand Up @@ -452,8 +452,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void loadMods();

// Virtual methods from con::PeerHandler
void peerAdded(con::Peer *peer) override;
void deletingPeer(con::Peer *peer, bool timeout) override;
void peerAdded(con::IPeer *peer) override;
void deletingPeer(con::IPeer *peer, bool timeout) override;

void initLocalMapSaving(const Address &address,
const std::string &hostname,
Expand Down Expand Up @@ -493,7 +493,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
std::unique_ptr<MeshUpdateManager> m_mesh_update_manager;
ClientEnvironment m_env;
std::unique_ptr<ParticleManager> m_particle_manager;
std::unique_ptr<con::Connection> m_con;
std::unique_ptr<con::IConnection> m_con;
std::string m_address_name;
ELoginRegister m_allow_login_or_register = ELoginRegister::Any;
Camera *m_camera = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions src/network/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
set(common_network_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/address.cpp
${CMAKE_CURRENT_SOURCE_DIR}/connection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/connectionthreads.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mtp/impl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mtp/threads.cpp
${CMAKE_CURRENT_SOURCE_DIR}/networkpacket.cpp
${CMAKE_CURRENT_SOURCE_DIR}/serverpackethandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/serveropcodes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/serverpackethandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/socket.cpp
PARENT_SCOPE
)
Expand Down
Loading

0 comments on commit 7968ab6

Please sign in to comment.