SCTP support.
This commit is contained in:
@@ -758,6 +758,7 @@ void mainWindowImpl::callJoinNetworkGameDialog() {
|
||||
myJoinNetworkGameDialog->lineEdit_ipAddress->text().toUtf8().constData(),
|
||||
myJoinNetworkGameDialog->spinBox_port->value(),
|
||||
myJoinNetworkGameDialog->checkBox_ipv6->isChecked(),
|
||||
myJoinNetworkGameDialog->checkBox_sctp->isChecked(),
|
||||
myJoinNetworkGameDialog->lineEdit_password->text().toUtf8().constData());
|
||||
|
||||
//Dialog mit Statusbalken
|
||||
|
||||
@@ -35,6 +35,10 @@ public:
|
||||
|
||||
void SetSocket(SOCKET sockfd);
|
||||
|
||||
int GetProtocol() const
|
||||
{return m_protocol;}
|
||||
void SetProtocol(int protocol)
|
||||
{m_protocol = protocol;}
|
||||
int GetAddrFamily() const
|
||||
{return m_addrFamily;}
|
||||
void SetAddrFamily(int addrFamily)
|
||||
@@ -65,6 +69,7 @@ public:
|
||||
|
||||
private:
|
||||
SOCKET m_sockfd;
|
||||
int m_protocol;
|
||||
int m_addrFamily;
|
||||
std::string m_serverAddr;
|
||||
unsigned m_serverPort;
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
const std::string &serverAddress,
|
||||
unsigned serverPort,
|
||||
bool ipv6,
|
||||
bool sctp,
|
||||
const std::string &pwd,
|
||||
const std::string &playerName);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <net/clientcontext.h>
|
||||
|
||||
ClientContext::ClientContext()
|
||||
: m_sockfd(INVALID_SOCKET), m_addrFamily(AF_INET), m_serverPort(0)
|
||||
: m_sockfd(INVALID_SOCKET), m_protocol(0), m_addrFamily(AF_INET), m_serverPort(0)
|
||||
{
|
||||
bzero(&m_clientSockaddr, sizeof(m_clientSockaddr));
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ ClientStateInit::Process(ClientThread &client)
|
||||
// if (context.GetServerPort() < 1024)
|
||||
// throw ClientException(ERR_SOCK_INVALID_PORT, 0);
|
||||
|
||||
context.SetSocket(socket(context.GetAddrFamily(), SOCK_STREAM, 0));
|
||||
context.SetSocket(socket(context.GetAddrFamily(), SOCK_STREAM, context.GetProtocol()));
|
||||
if (!IS_VALID_SOCKET(context.GetSocket()))
|
||||
throw ClientException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO());
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ ClientThread::~ClientThread()
|
||||
|
||||
void
|
||||
ClientThread::Init(
|
||||
const string &serverAddress, unsigned serverPort, bool ipv6, const string &pwd, const string &playerName)
|
||||
const string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const string &pwd, const string &playerName)
|
||||
{
|
||||
if (IsRunning())
|
||||
{
|
||||
@@ -77,6 +77,7 @@ ClientThread::Init(
|
||||
|
||||
ClientContext &context = GetContext();
|
||||
|
||||
context.SetProtocol(sctp ? SOCKET_IPPROTO_SCTP : 0);
|
||||
context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET);
|
||||
context.SetServerAddr(serverAddress);
|
||||
context.SetServerPort(serverPort);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <net/servercontext.h>
|
||||
|
||||
ServerContext::ServerContext()
|
||||
: m_sockfd(INVALID_SOCKET), m_addrFamily(AF_INET), m_serverPort(0)
|
||||
: m_sockfd(INVALID_SOCKET), m_protocol(0), m_addrFamily(AF_INET), m_serverPort(0)
|
||||
{
|
||||
bzero(&m_serverSockaddr, sizeof(m_serverSockaddr));
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ ServerThread::~ServerThread()
|
||||
}
|
||||
|
||||
void
|
||||
ServerThread::Init(unsigned serverPort, bool ipv6, const std::string &pwd,
|
||||
ServerThread::Init(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd,
|
||||
const GameData &gameData)
|
||||
{
|
||||
if (IsRunning())
|
||||
@@ -49,6 +49,7 @@ ServerThread::Init(unsigned serverPort, bool ipv6, const std::string &pwd,
|
||||
|
||||
ServerContext &context = GetContext();
|
||||
|
||||
context.SetProtocol(sctp ? SOCKET_IPPROTO_SCTP : 0);
|
||||
context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET);
|
||||
context.SetServerPort(serverPort);
|
||||
|
||||
@@ -106,7 +107,7 @@ ServerThread::Listen()
|
||||
// if (context.GetServerPort() < 1024)
|
||||
// throw ServerException(ERR_SOCK_INVALID_PORT, 0);
|
||||
|
||||
context.SetSocket(socket(context.GetAddrFamily(), SOCK_STREAM, 0));
|
||||
context.SetSocket(socket(context.GetAddrFamily(), SOCK_STREAM, context.GetProtocol()));
|
||||
if (!IS_VALID_SOCKET(context.GetSocket()))
|
||||
throw ServerException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO());
|
||||
|
||||
|
||||
@@ -35,6 +35,10 @@ public:
|
||||
|
||||
void SetSocket(SOCKET sockfd);
|
||||
|
||||
int GetProtocol() const
|
||||
{return m_protocol;}
|
||||
void SetProtocol(int protocol)
|
||||
{m_protocol = protocol;}
|
||||
int GetAddrFamily() const
|
||||
{return m_addrFamily;}
|
||||
void SetAddrFamily(int addrFamily)
|
||||
@@ -53,6 +57,7 @@ public:
|
||||
|
||||
private:
|
||||
SOCKET m_sockfd;
|
||||
int m_protocol;
|
||||
int m_addrFamily;
|
||||
unsigned m_serverPort;
|
||||
sockaddr_storage m_serverSockaddr;
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
virtual ~ServerThread();
|
||||
|
||||
// Set the parameters.
|
||||
void Init(unsigned serverPort, bool ipv6, const std::string &pwd,
|
||||
void Init(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd,
|
||||
const GameData &gameData);
|
||||
void StartGame();
|
||||
|
||||
|
||||
@@ -58,6 +58,12 @@ typedef unsigned char u_char;
|
||||
#define IS_VALID_SEND(_s) ((_s) != SOCKET_ERROR)
|
||||
#define IS_VALID_SELECT(_s) ((_s) != SOCKET_ERROR)
|
||||
|
||||
#ifdef IPPROTO_SCTP
|
||||
#define SOCKET_IPPROTO_SCTP IPPROTO_SCTP
|
||||
#else
|
||||
#define SOCKET_IPPROTO_SCTP 0
|
||||
#endif
|
||||
|
||||
// All char *s are assumed to be UTF-8.
|
||||
|
||||
/**
|
||||
|
||||
+4
-1
@@ -103,7 +103,7 @@ GuiInterface *Session::getGui()
|
||||
return myGui;
|
||||
}
|
||||
|
||||
void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, const string &pwd)
|
||||
void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const string &pwd)
|
||||
{
|
||||
if (myNetClient || !myGui)
|
||||
{
|
||||
@@ -115,6 +115,7 @@ void Session::startNetworkClient(const string &serverAddress, unsigned serverPor
|
||||
serverAddress,
|
||||
serverPort,
|
||||
ipv6,
|
||||
sctp,
|
||||
pwd,
|
||||
myConfig->readConfigString("MyName"));
|
||||
myNetClient->Run();
|
||||
@@ -132,6 +133,7 @@ void Session::startNetworkClientForLocalServer()
|
||||
"localhost",
|
||||
myConfig->readConfigInt("ServerPort"),
|
||||
myConfig->readConfigInt("ServerUseIpv6") == 1,
|
||||
myConfig->readConfigInt("ServerUseSctp") == 1,
|
||||
myConfig->readConfigString("ServerPassword"),
|
||||
myConfig->readConfigString("MyName"));
|
||||
myNetClient->Run();
|
||||
@@ -162,6 +164,7 @@ void Session::startNetworkServer(const GameData &gameData)
|
||||
myNetServer->Init(
|
||||
myConfig->readConfigInt("ServerPort"),
|
||||
myConfig->readConfigInt("ServerUseIpv6") == 1,
|
||||
myConfig->readConfigInt("ServerUseSCTP") == 1,
|
||||
myConfig->readConfigString("ServerPassword"),
|
||||
gameData);
|
||||
myNetServer->Run();
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
GuiInterface *getGui();
|
||||
|
||||
void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, const std::string &pwd);
|
||||
void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd);
|
||||
void startNetworkClientForLocalServer();
|
||||
void terminateNetworkClient();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user