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