aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/connection.cpp2
-rw-r--r--src/network/connection.h5
-rw-r--r--src/network/connectionthreads.cpp5
3 files changed, 10 insertions, 2 deletions
diff --git a/src/network/connection.cpp b/src/network/connection.cpp
index 1875d1461..0ba8c36b2 100644
--- a/src/network/connection.cpp
+++ b/src/network/connection.cpp
@@ -1566,7 +1566,7 @@ void Connection::sendAck(session_t peer_id, u8 channelnum, u16 seqnum)
UDPPeer* Connection::createServerPeer(Address& address)
{
- if (getPeerNoEx(PEER_ID_SERVER) != 0)
+ if (ConnectedToServer())
{
throw ConnectionException("Already connected to a server");
}
diff --git a/src/network/connection.h b/src/network/connection.h
index 2dc6d4397..24cd4fe4a 100644
--- a/src/network/connection.h
+++ b/src/network/connection.h
@@ -809,6 +809,11 @@ protected:
void putEvent(ConnectionEvent &e);
void TriggerSend();
+
+ bool ConnectedToServer()
+ {
+ return getPeerNoEx(PEER_ID_SERVER) != nullptr;
+ }
private:
MutexedQueue<ConnectionEvent> m_event_queue;
diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp
index 28ed798d9..7b62bc792 100644
--- a/src/network/connectionthreads.cpp
+++ b/src/network/connectionthreads.cpp
@@ -956,8 +956,11 @@ void ConnectionReceiveThread::receive(SharedBuffer<u8> &packetdata,
// command was sent reliably.
}
- /* The peer was not found in our lists. Add it. */
if (peer_id == PEER_ID_INEXISTENT) {
+ /* Ignore it if we are a client */
+ if (m_connection->ConnectedToServer())
+ return;
+ /* The peer was not found in our lists. Add it. */
peer_id = m_connection->createPeer(sender, MTP_MINETEST_RELIABLE_UDP, 0);
}