1
0
forked from mirrors/0ad

Host on arbitrary UDP ports. Patch in cooperation with Imarok, fixes #3575.

This was SVN commit r18372.
This commit is contained in:
elexis
2016-06-13 16:56:14 +00:00
parent 7b655b7ea6
commit 62061557db
15 changed files with 130 additions and 50 deletions
+2 -2
View File
@@ -154,10 +154,10 @@ void CNetClient::SetUserName(const CStrW& username)
m_UserName = username;
}
bool CNetClient::SetupConnection(const CStr& server)
bool CNetClient::SetupConnection(const CStr& server, const u16 port)
{
CNetClientSession* session = new CNetClientSession(*this);
bool ok = session->Connect(PS_DEFAULT_PORT, server, m_IsLocalClient);
bool ok = session->Connect(server, port, m_IsLocalClient);
SetAndOwnSession(session);
return ok;
}
+1 -1
View File
@@ -99,7 +99,7 @@ public:
* @param server IP address or host name to connect to
* @return true on success, false on connection failure
*/
bool SetupConnection(const CStr& server);
bool SetupConnection(const CStr& server, const u16 port);
/**
* Destroy the connection to the server.
+4 -4
View File
@@ -169,7 +169,7 @@ CNetServerWorker::~CNetServerWorker()
delete m_ServerTurnManager;
}
bool CNetServerWorker::SetupConnection()
bool CNetServerWorker::SetupConnection(const u16 port)
{
ENSURE(m_State == SERVER_STATE_UNCONNECTED);
ENSURE(!m_Host);
@@ -177,7 +177,7 @@ bool CNetServerWorker::SetupConnection()
// Bind to default host
ENetAddress addr;
addr.host = ENET_HOST_ANY;
addr.port = PS_DEFAULT_PORT;
addr.port = port;
// Create ENet server
m_Host = enet_host_create(&addr, MAX_CLIENTS, CHANNEL_COUNT, 0, 0);
@@ -1427,9 +1427,9 @@ CNetServer::~CNetServer()
delete m_Worker;
}
bool CNetServer::SetupConnection()
bool CNetServer::SetupConnection(const u16 port)
{
return m_Worker->SetupConnection();
return m_Worker->SetupConnection(port);
}
void CNetServer::StartGame()
+2 -2
View File
@@ -113,7 +113,7 @@ public:
* This function is synchronous (it won't return until the connection is established).
* @return true on success, false on error (e.g. port already in use)
*/
bool SetupConnection();
bool SetupConnection(const u16 port);
/**
* Call from the GUI to asynchronously notify all clients that they should start loading the game.
@@ -184,7 +184,7 @@ private:
* Begin listening for network connections.
* @return true on success, false on error (e.g. port already in use)
*/
bool SetupConnection();
bool SetupConnection(const u16 port);
/**
* Call from the GUI to update the player assignments.
+1 -1
View File
@@ -51,7 +51,7 @@ CNetClientSession::~CNetClientSession()
}
}
bool CNetClientSession::Connect(u16 port, const CStr& server, bool isLocalClient)
bool CNetClientSession::Connect(const CStr& server, const u16 port, const bool isLocalClient)
{
ENSURE(!m_Host);
ENSURE(!m_Server);
+1 -1
View File
@@ -70,7 +70,7 @@ public:
CNetClientSession(CNetClient& client);
~CNetClientSession();
bool Connect(u16 port, const CStr& server, bool isLocalClient);
bool Connect(const CStr& server, const u16 port, const bool isLocalClient);
/**
* Process queued incoming messages.
+6 -4
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -24,6 +24,8 @@
#include "network/NetServer.h"
#include "network/NetClient.h"
#include "network/NetTurnManager.h"
#include "network/NetMessage.h"
#include "network/NetMessages.h"
#include "ps/CLogger.h"
#include "ps/Game.h"
#include "ps/Filesystem.h"
@@ -71,9 +73,9 @@ public:
void connect(CNetServer& server, const std::vector<CNetClient*>& clients)
{
TS_ASSERT(server.SetupConnection());
TS_ASSERT(server.SetupConnection(PS_DEFAULT_PORT));
for (size_t j = 0; j < clients.size(); ++j)
TS_ASSERT(clients[j]->SetupConnection("127.0.0.1"));
TS_ASSERT(clients[j]->SetupConnection("127.0.0.1", PS_DEFAULT_PORT));
for (size_t i = 0; ; ++i)
{
@@ -273,7 +275,7 @@ public:
client2B.SetUserName(L"bob");
clients.push_back(&client2B);
TS_ASSERT(client2B.SetupConnection("127.0.0.1"));
TS_ASSERT(client2B.SetupConnection("127.0.0.1", PS_DEFAULT_PORT));
for (size_t i = 0; ; ++i)
{