diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/connection.cpp | 36 | ||||
-rw-r--r-- | src/network/connection.h | 61 | ||||
-rw-r--r-- | src/network/connectionthreads.cpp | 64 | ||||
-rw-r--r-- | src/network/connectionthreads.h | 14 | ||||
-rw-r--r-- | src/network/networkpacket.cpp | 5 | ||||
-rw-r--r-- | src/network/networkpacket.h | 11 | ||||
-rw-r--r-- | src/network/networkprotocol.h | 2 | ||||
-rw-r--r-- | src/network/peerhandler.h | 9 | ||||
-rw-r--r-- | src/network/serverpackethandler.cpp | 2 |
9 files changed, 100 insertions, 104 deletions
diff --git a/src/network/connection.cpp b/src/network/connection.cpp index b2e443901..69dc0cdff 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -56,7 +56,7 @@ std::mutex log_message_mutex; #define PING_TIMEOUT 5.0 BufferedPacket makePacket(Address &address, SharedBuffer<u8> data, - u32 protocol_id, u16 sender_peer_id, u8 channel) + u32 protocol_id, session_t sender_peer_id, u8 channel) { u32 packet_size = data.getSize() + BASE_HEADER_SIZE; BufferedPacket p(packet_size); @@ -501,7 +501,7 @@ void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout) ConnectionCommand */ -void ConnectionCommand::send(u16 peer_id_, u8 channelnum_, NetworkPacket *pkt, +void ConnectionCommand::send(session_t peer_id_, u8 channelnum_, NetworkPacket *pkt, bool reliable_) { type = CONNCMD_SEND; @@ -1198,10 +1198,10 @@ void Connection::TriggerSend() m_sendThread->Trigger(); } -PeerHelper Connection::getPeerNoEx(u16 peer_id) +PeerHelper Connection::getPeerNoEx(session_t peer_id) { MutexAutoLock peerlock(m_peers_mutex); - std::map<u16, Peer*>::iterator node = m_peers.find(peer_id); + std::map<session_t, Peer *>::iterator node = m_peers.find(peer_id); if (node == m_peers.end()) { return PeerHelper(NULL); @@ -1237,17 +1237,7 @@ u16 Connection::lookupPeer(Address& sender) return PEER_ID_INEXISTENT; } -std::list<Peer*> Connection::getPeers() -{ - std::list<Peer*> list; - for (auto &p : m_peers) { - Peer *peer = p.second; - list.push_back(peer); - } - return list; -} - -bool Connection::deletePeer(u16 peer_id, bool timeout) +bool Connection::deletePeer(session_t peer_id, bool timeout) { Peer *peer = 0; @@ -1316,7 +1306,7 @@ bool Connection::Connected() if (m_peers.size() != 1) return false; - std::map<u16, Peer*>::iterator node = m_peers.find(PEER_ID_SERVER); + std::map<session_t, Peer *>::iterator node = m_peers.find(PEER_ID_SERVER); if (node == m_peers.end()) return false; @@ -1371,8 +1361,8 @@ void Connection::Receive(NetworkPacket* pkt) throw NoIncomingDataException("No incoming data"); } -void Connection::Send(u16 peer_id, u8 channelnum, - NetworkPacket* pkt, bool reliable) +void Connection::Send(session_t peer_id, u8 channelnum, + NetworkPacket *pkt, bool reliable) { assert(channelnum < CHANNEL_COUNT); // Pre-condition @@ -1382,7 +1372,7 @@ void Connection::Send(u16 peer_id, u8 channelnum, putCommand(c); } -Address Connection::GetPeerAddress(u16 peer_id) +Address Connection::GetPeerAddress(session_t peer_id) { PeerHelper peer = getPeerNoEx(peer_id); @@ -1393,7 +1383,7 @@ Address Connection::GetPeerAddress(u16 peer_id) return peer_address; } -float Connection::getPeerStat(u16 peer_id, rtt_stat_type type) +float Connection::getPeerStat(session_t peer_id, rtt_stat_type type) { PeerHelper peer = getPeerNoEx(peer_id); if (!peer) return -1; @@ -1440,7 +1430,7 @@ u16 Connection::createPeer(Address& sender, MTProtocols protocol, int fd) // Somebody wants to make a new connection // Get a unique peer id (2 or higher) - u16 peer_id_new = m_next_remote_peer_id; + session_t peer_id_new = m_next_remote_peer_id; u16 overflow = MAX_UDP_PEERS; /* @@ -1508,14 +1498,14 @@ const std::string Connection::getDesc() itos(m_udpSocket.GetHandle())+"/"+itos(m_peer_id)+")"; } -void Connection::DisconnectPeer(u16 peer_id) +void Connection::DisconnectPeer(session_t peer_id) { ConnectionCommand discon; discon.disconnect_peer(peer_id); putCommand(discon); } -void Connection::sendAck(u16 peer_id, u8 channelnum, u16 seqnum) +void Connection::sendAck(session_t peer_id, u8 channelnum, u16 seqnum) { assert(channelnum < CHANNEL_COUNT); // Pre-condition diff --git a/src/network/connection.h b/src/network/connection.h index 5062b73d0..2fc344169 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/container.h" #include "util/thread.h" #include "util/numeric.h" +#include "networkprotocol.h" #include <iostream> #include <fstream> #include <list> @@ -103,7 +104,7 @@ struct BufferedPacket // This adds the base headers to the data and makes a packet out of it BufferedPacket makePacket(Address &address, SharedBuffer<u8> data, - u32 protocol_id, u16 sender_peer_id, u8 channel); + u32 protocol_id, session_t sender_peer_id, u8 channel); // Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet // Increments split_seqnum if a split packet is made @@ -139,7 +140,7 @@ A packet is sent through a channel to a peer with a basic header: TODO: Should we have a receiver_peer_id also? Header (7 bytes): [0] u32 protocol_id - [4] u16 sender_peer_id + [4] session_t sender_peer_id [6] u8 channel sender_peer_id: Unique to each peer. @@ -164,7 +165,7 @@ controltype and data description: CONTROLTYPE_ACK [2] u16 seqnum CONTROLTYPE_SET_PEER_ID - [2] u16 peer_id_new + [2] session_t peer_id_new CONTROLTYPE_PING - There is no actual reply, but this can be sent in a reliable packet to get a reply @@ -289,13 +290,13 @@ private: struct OutgoingPacket { - u16 peer_id; + session_t peer_id; u8 channelnum; SharedBuffer<u8> data; bool reliable; bool ack; - OutgoingPacket(u16 peer_id_, u8 channelnum_, const SharedBuffer<u8> &data_, + OutgoingPacket(session_t peer_id_, u8 channelnum_, const SharedBuffer<u8> &data_, bool reliable_,bool ack_=false): peer_id(peer_id_), channelnum(channelnum_), @@ -323,7 +324,7 @@ struct ConnectionCommand { enum ConnectionCommandType type = CONNCMD_NONE; Address address; - u16 peer_id = PEER_ID_INEXISTENT; + session_t peer_id = PEER_ID_INEXISTENT; u8 channelnum = 0; Buffer<u8> data; bool reliable = false; @@ -357,15 +358,15 @@ struct ConnectionCommand { type = CONNCMD_DISCONNECT; } - void disconnect_peer(u16 peer_id_) + void disconnect_peer(session_t peer_id_) { type = CONNCMD_DISCONNECT_PEER; peer_id = peer_id_; } - void send(u16 peer_id_, u8 channelnum_, NetworkPacket* pkt, bool reliable_); + void send(session_t peer_id_, u8 channelnum_, NetworkPacket *pkt, bool reliable_); - void ack(u16 peer_id_, u8 channelnum_, const SharedBuffer<u8> &data_) + void ack(session_t peer_id_, u8 channelnum_, const SharedBuffer<u8> &data_) { type = CONCMD_ACK; peer_id = peer_id_; @@ -374,7 +375,7 @@ struct ConnectionCommand reliable = false; } - void createPeer(u16 peer_id_, const SharedBuffer<u8> &data_) + void createPeer(session_t peer_id_, const SharedBuffer<u8> &data_) { type = CONCMD_CREATE_PEER; peer_id = peer_id_; @@ -384,7 +385,7 @@ struct ConnectionCommand raw = true; } - void disableLegacy(u16 peer_id_, const SharedBuffer<u8> &data_) + void disableLegacy(session_t peer_id_, const SharedBuffer<u8> &data_) { type = CONCMD_DISABLE_LEGACY; peer_id = peer_id_; @@ -716,7 +717,7 @@ enum ConnectionEventType{ struct ConnectionEvent { enum ConnectionEventType type = CONNEVENT_NONE; - u16 peer_id = 0; + session_t peer_id = 0; Buffer<u8> data; bool timeout = false; Address address; @@ -740,19 +741,19 @@ struct ConnectionEvent return "Invalid ConnectionEvent"; } - void dataReceived(u16 peer_id_, const SharedBuffer<u8> &data_) + void dataReceived(session_t peer_id_, const SharedBuffer<u8> &data_) { type = CONNEVENT_DATA_RECEIVED; peer_id = peer_id_; data = data_; } - void peerAdded(u16 peer_id_, Address address_) + void peerAdded(session_t peer_id_, Address address_) { type = CONNEVENT_PEER_ADDED; peer_id = peer_id_; address = address_; } - void peerRemoved(u16 peer_id_, bool timeout_, Address address_) + void peerRemoved(session_t peer_id_, bool timeout_, Address address_) { type = CONNEVENT_PEER_REMOVED; peer_id = peer_id_; @@ -787,30 +788,30 @@ public: bool Connected(); void Disconnect(); void Receive(NetworkPacket* pkt); - void Send(u16 peer_id, u8 channelnum, NetworkPacket* pkt, bool reliable); - u16 GetPeerID() { return m_peer_id; } - Address GetPeerAddress(u16 peer_id); - float getPeerStat(u16 peer_id, rtt_stat_type type); + void Send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable); + session_t GetPeerID() const { return m_peer_id; } + Address GetPeerAddress(session_t peer_id); + float getPeerStat(session_t peer_id, rtt_stat_type type); float getLocalStat(rate_stat_type type); const u32 GetProtocolID() const { return m_protocol_id; }; const std::string getDesc(); - void DisconnectPeer(u16 peer_id); + void DisconnectPeer(session_t peer_id); protected: - PeerHelper getPeerNoEx(u16 peer_id); + PeerHelper getPeerNoEx(session_t peer_id); u16 lookupPeer(Address& sender); u16 createPeer(Address& sender, MTProtocols protocol, int fd); UDPPeer* createServerPeer(Address& sender); - bool deletePeer(u16 peer_id, bool timeout); + bool deletePeer(session_t peer_id, bool timeout); - void SetPeerID(u16 id) { m_peer_id = id; } + void SetPeerID(session_t id) { m_peer_id = id; } - void sendAck(u16 peer_id, u8 channelnum, u16 seqnum); + void sendAck(session_t peer_id, u8 channelnum, u16 seqnum); void PrintInfo(std::ostream &out); - std::list<u16> getPeerIDs() + std::list<session_t> getPeerIDs() { MutexAutoLock peerlock(m_peers_mutex); return m_peer_ids; @@ -823,15 +824,13 @@ protected: void TriggerSend(); private: - std::list<Peer*> getPeers(); - MutexedQueue<ConnectionEvent> m_event_queue; - u16 m_peer_id = 0; + session_t m_peer_id = 0; u32 m_protocol_id; - std::map<u16, Peer*> m_peers; - std::list<u16> m_peer_ids; + std::map<session_t, Peer *> m_peers; + std::list<session_t> m_peer_ids; std::mutex m_peers_mutex; std::unique_ptr<ConnectionSendThread> m_sendThread; @@ -845,7 +844,7 @@ private: bool m_shutting_down = false; - u16 m_next_remote_peer_id = 2; + session_t m_next_remote_peer_id = 2; }; } // namespace diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp index ec09e9d3e..71407bf03 100644 --- a/src/network/connectionthreads.cpp +++ b/src/network/connectionthreads.cpp @@ -53,7 +53,7 @@ std::mutex log_conthread_mutex; #define WINDOW_SIZE 5 -static u16 readPeerId(u8 *packetdata) +static session_t readPeerId(u8 *packetdata) { return readU16(&packetdata[4]); } @@ -138,12 +138,12 @@ void ConnectionSendThread::Trigger() bool ConnectionSendThread::packetsQueued() { - std::list<u16> peerIds = m_connection->getPeerIDs(); + std::list<session_t> peerIds = m_connection->getPeerIDs(); if (!m_outgoing_queue.empty() && !peerIds.empty()) return true; - for (u16 peerId : peerIds) { + for (session_t peerId : peerIds) { PeerHelper peer = m_connection->getPeerNoEx(peerId); if (!peer) @@ -165,10 +165,10 @@ bool ConnectionSendThread::packetsQueued() void ConnectionSendThread::runTimeouts(float dtime) { - std::list<u16> timeouted_peers; - std::list<u16> peerIds = m_connection->getPeerIDs(); + std::list<session_t> timeouted_peers; + std::list<session_t> peerIds = m_connection->getPeerIDs(); - for (u16 &peerId : peerIds) { + for (session_t &peerId : peerIds) { PeerHelper peer = m_connection->getPeerNoEx(peerId); if (!peer) @@ -231,7 +231,7 @@ void ConnectionSendThread::runTimeouts(float dtime) for (std::list<BufferedPacket>::iterator k = timed_outs.begin(); k != timed_outs.end(); ++k) { - u16 peer_id = readPeerId(*(k->data)); + session_t peer_id = readPeerId(*(k->data)); u8 channelnum = readChannel(*(k->data)); u16 seqnum = readU16(&(k->data[BASE_HEADER_SIZE + 1])); @@ -329,7 +329,7 @@ void ConnectionSendThread::sendAsPacketReliable(BufferedPacket &p, Channel *chan rawSend(p); } -bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum, +bool ConnectionSendThread::rawSendAsPacket(session_t peer_id, u8 channelnum, SharedBuffer<u8> data, bool reliable) { PeerHelper peer = m_connection->getPeerNoEx(peer_id); @@ -557,14 +557,14 @@ void ConnectionSendThread::disconnect() // Send to all - std::list<u16> peerids = m_connection->getPeerIDs(); + std::list<session_t> peerids = m_connection->getPeerIDs(); - for (u16 peerid : peerids) { + for (session_t peerid : peerids) { sendAsPacket(peerid, 0, data, false); } } -void ConnectionSendThread::disconnect_peer(u16 peer_id) +void ConnectionSendThread::disconnect_peer(session_t peer_id) { LOG(dout_con << m_connection->getDesc() << " disconnecting peer" << std::endl); @@ -586,7 +586,7 @@ void ConnectionSendThread::disconnect_peer(u16 peer_id) dynamic_cast<UDPPeer *>(&peer)->m_pending_disconnect = true; } -void ConnectionSendThread::send(u16 peer_id, u8 channelnum, +void ConnectionSendThread::send(session_t peer_id, u8 channelnum, SharedBuffer<u8> data) { assert(channelnum < CHANNEL_COUNT); // Pre-condition @@ -629,18 +629,18 @@ void ConnectionSendThread::sendReliable(ConnectionCommand &c) void ConnectionSendThread::sendToAll(u8 channelnum, SharedBuffer<u8> data) { - std::list<u16> peerids = m_connection->getPeerIDs(); + std::list<session_t> peerids = m_connection->getPeerIDs(); - for (u16 peerid : peerids) { + for (session_t peerid : peerids) { send(peerid, channelnum, data); } } void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c) { - std::list<u16> peerids = m_connection->getPeerIDs(); + std::list<session_t> peerids = m_connection->getPeerIDs(); - for (u16 peerid : peerids) { + for (session_t peerid : peerids) { PeerHelper peer = m_connection->getPeerNoEx(peerid); if (!peer) @@ -652,11 +652,11 @@ void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c) void ConnectionSendThread::sendPackets(float dtime) { - std::list<u16> peerIds = m_connection->getPeerIDs(); - std::list<u16> pendingDisconnect; - std::map<u16, bool> pending_unreliable; + std::list<session_t> peerIds = m_connection->getPeerIDs(); + std::list<session_t> pendingDisconnect; + std::map<session_t, bool> pending_unreliable; - for (u16 peerId : peerIds) { + for (session_t peerId : peerIds) { PeerHelper peer = m_connection->getPeerNoEx(peerId); //peer may have been removed if (!peer) { @@ -780,14 +780,14 @@ void ConnectionSendThread::sendPackets(float dtime) } } - for (u16 peerId : pendingDisconnect) { + for (session_t peerId : pendingDisconnect) { if (!pending_unreliable[peerId]) { m_connection->deletePeer(peerId, false); } } } -void ConnectionSendThread::sendAsPacket(u16 peer_id, u8 channelnum, +void ConnectionSendThread::sendAsPacket(session_t peer_id, u8 channelnum, SharedBuffer<u8> data, bool ack) { OutgoingPacket packet(peer_id, channelnum, data, false, ack); @@ -835,9 +835,9 @@ void *ConnectionReceiveThread::run() if (debug_print_timer > 20.0) { debug_print_timer -= 20.0; - std::list<u16> peerids = m_connection->getPeerIDs(); + std::list<session_t> peerids = m_connection->getPeerIDs(); - for (std::list<u16>::iterator i = peerids.begin(); + for (std::list<session_t>::iterator i = peerids.begin(); i != peerids.end(); i++) { @@ -910,7 +910,7 @@ void ConnectionReceiveThread::receive() try { if (packet_queued) { bool data_left = true; - u16 peer_id; + session_t peer_id; SharedBuffer<u8> resultdata; while (data_left) { try { @@ -943,7 +943,7 @@ void ConnectionReceiveThread::receive() continue; } - u16 peer_id = readPeerId(*packetdata); + session_t peer_id = readPeerId(*packetdata); u8 channelnum = readChannel(*packetdata); if (channelnum > CHANNEL_COUNT - 1) { @@ -1044,11 +1044,11 @@ void ConnectionReceiveThread::receive() } } -bool ConnectionReceiveThread::getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst) +bool ConnectionReceiveThread::getFromBuffers(session_t &peer_id, SharedBuffer<u8> &dst) { - std::list<u16> peerids = m_connection->getPeerIDs(); + std::list<session_t> peerids = m_connection->getPeerIDs(); - for (u16 peerid : peerids) { + for (session_t peerid : peerids) { PeerHelper peer = m_connection->getPeerNoEx(peerid); if (!peer) continue; @@ -1066,7 +1066,7 @@ bool ConnectionReceiveThread::getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst } bool ConnectionReceiveThread::checkIncomingBuffers(Channel *channel, - u16 &peer_id, SharedBuffer<u8> &dst) + session_t &peer_id, SharedBuffer<u8> &dst) { u16 firstseqnum = 0; if (channel->incoming_reliables.getFirstSeqnum(firstseqnum)) { @@ -1098,7 +1098,7 @@ bool ConnectionReceiveThread::checkIncomingBuffers(Channel *channel, } SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel, - SharedBuffer<u8> packetdata, u16 peer_id, u8 channelnum, bool reliable) + SharedBuffer<u8> packetdata, session_t peer_id, u8 channelnum, bool reliable) { PeerHelper peer = m_connection->getPeerNoEx(peer_id); @@ -1197,7 +1197,7 @@ SharedBuffer<u8> ConnectionReceiveThread::handlePacketType_Control(Channel *chan if (packetdata.getSize() < 4) throw InvalidIncomingDataException ("packetdata.getSize() < 4 (SET_PEER_ID header size)"); - u16 peer_id_new = readU16(&packetdata[2]); + session_t peer_id_new = readU16(&packetdata[2]); LOG(dout_con << m_connection->getDesc() << "Got new peer id: " << peer_id_new << "... " << std::endl); diff --git a/src/network/connectionthreads.h b/src/network/connectionthreads.h index 82a08d36c..57825e1a1 100644 --- a/src/network/connectionthreads.h +++ b/src/network/connectionthreads.h @@ -53,22 +53,22 @@ private: void runTimeouts(float dtime); void rawSend(const BufferedPacket &packet); bool rawSendAsPacket( - u16 peer_id, u8 channelnum, SharedBuffer<u8> data, bool reliable); + session_t peer_id, u8 channelnum, SharedBuffer<u8> data, bool reliable); void processReliableCommand(ConnectionCommand &c); void processNonReliableCommand(ConnectionCommand &c); void serve(Address bind_address); void connect(Address address); void disconnect(); - void disconnect_peer(u16 peer_id); - void send(u16 peer_id, u8 channelnum, SharedBuffer<u8> data); + void disconnect_peer(session_t peer_id); + void send(session_t peer_id, u8 channelnum, SharedBuffer<u8> data); void sendReliable(ConnectionCommand &c); void sendToAll(u8 channelnum, SharedBuffer<u8> data); void sendToAllReliable(ConnectionCommand &c); void sendPackets(float dtime); - void sendAsPacket(u16 peer_id, u8 channelnum, SharedBuffer<u8> data, + void sendAsPacket(session_t peer_id, u8 channelnum, SharedBuffer<u8> data, bool ack = false); void sendAsPacketReliable(BufferedPacket &p, Channel *channel); @@ -106,9 +106,9 @@ private: // Returns next data from a buffer if possible // If found, returns true; if not, false. // If found, sets peer_id and dst - bool getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst); + bool getFromBuffers(session_t &peer_id, SharedBuffer<u8> &dst); - bool checkIncomingBuffers(Channel *channel, u16 &peer_id, SharedBuffer<u8> &dst); + bool checkIncomingBuffers(Channel *channel, session_t &peer_id, SharedBuffer<u8> &dst); /* Processes a packet with the basic header stripped out. @@ -119,7 +119,7 @@ private: reliable: true if recursing into a reliable packet */ SharedBuffer<u8> processPacket(Channel *channel, SharedBuffer<u8> packetdata, - u16 peer_id, u8 channelnum, bool reliable); + session_t peer_id, u8 channelnum, bool reliable); SharedBuffer<u8> handlePacketType_Control(Channel *channel, SharedBuffer<u8> packetdata, Peer *peer, u8 channelnum, diff --git a/src/network/networkpacket.cpp b/src/network/networkpacket.cpp index c91100945..a35db9574 100644 --- a/src/network/networkpacket.cpp +++ b/src/network/networkpacket.cpp @@ -21,8 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <sstream> #include "networkexceptions.h" #include "util/serialize.h" +#include "networkprotocol.h" -NetworkPacket::NetworkPacket(u16 command, u32 datasize, u16 peer_id): +NetworkPacket::NetworkPacket(u16 command, u32 datasize, session_t peer_id): m_datasize(datasize), m_command(command), m_peer_id(peer_id) { m_data.resize(m_datasize); @@ -49,7 +50,7 @@ void NetworkPacket::checkReadOffset(u32 from_offset, u32 field_size) } } -void NetworkPacket::putRawPacket(u8 *data, u32 datasize, u16 peer_id) +void NetworkPacket::putRawPacket(u8 *data, u32 datasize, session_t peer_id) { // If a m_command is already set, we are rewriting on same packet // This is not permitted diff --git a/src/network/networkpacket.h b/src/network/networkpacket.h index 008271fab..760b51f7a 100644 --- a/src/network/networkpacket.h +++ b/src/network/networkpacket.h @@ -22,23 +22,24 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <ctime> #include "util/pointer.h" #include "util/numeric.h" +#include "networkprotocol.h" #include <SColor.h> class NetworkPacket { public: - NetworkPacket(u16 command, u32 datasize, u16 peer_id); + NetworkPacket(u16 command, u32 datasize, session_t peer_id); NetworkPacket(u16 command, u32 datasize); NetworkPacket() = default; ~NetworkPacket(); - void putRawPacket(u8 *data, u32 datasize, u16 peer_id); + void putRawPacket(u8 *data, u32 datasize, session_t peer_id); // Getters - u32 getSize() { return m_datasize; } - u16 getPeerId() { return m_peer_id; } + u32 getSize() const { return m_datasize; } + session_t getPeerId() const { return m_peer_id; } u16 getCommand() { return m_command; } const u32 getRemainingBytes() const { return m_datasize - m_read_offset; } const char *getRemainingString() { return getString(m_read_offset); } @@ -135,5 +136,5 @@ private: u32 m_datasize = 0; u32 m_read_offset = 0; u16 m_command = 0; - u16 m_peer_id = 0; + session_t m_peer_id = 0; }; diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 28132396b..76e90b560 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -206,6 +206,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-" +typedef u16 session_t; + enum ToClientCommand { TOCLIENT_HELLO = 0x02, diff --git a/src/network/peerhandler.h b/src/network/peerhandler.h index b7ac9d64d..70e416e90 100644 --- a/src/network/peerhandler.h +++ b/src/network/peerhandler.h @@ -19,6 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "networkprotocol.h" + namespace con { @@ -53,21 +55,22 @@ public: virtual void deletingPeer(Peer *peer, bool timeout) = 0; }; -enum PeerChangeType +enum PeerChangeType : u8 { PEER_ADDED, PEER_REMOVED }; + struct PeerChange { - PeerChange(PeerChangeType t, u16 _peer_id, bool _timeout) + PeerChange(PeerChangeType t, session_t _peer_id, bool _timeout) : type(t), peer_id(_peer_id), timeout(_timeout) { } PeerChange() = delete; PeerChangeType type; - u16 peer_id; + session_t peer_id; bool timeout; }; } diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 7d2f6009f..69c25b468 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -356,7 +356,7 @@ void Server::handleCommand_RequestMedia(NetworkPacket* pkt) void Server::handleCommand_ClientReady(NetworkPacket* pkt) { - u16 peer_id = pkt->getPeerId(); + session_t peer_id = pkt->getPeerId(); PlayerSAO* playersao = StageTwoClientInit(peer_id); |