[Server] Added parameter 'port' for init().

This commit is contained in:
Quentin Bazin 2019-01-11 23:54:33 +01:00
parent 389ee41f05
commit 7caeafb845
3 changed files with 6 additions and 5 deletions

View File

@ -22,7 +22,7 @@
class Server {
public:
void init();
void init(u16 port = 4242);
void handleKeyState();

View File

@ -20,7 +20,7 @@ ServerApplication::ServerApplication(int argc, char **argv) : gk::CoreApplicatio
void ServerApplication::init() {
gk::CoreApplication::init();
m_server.init();
m_server.init(4242);
m_server.setRunning(true);
m_server.setGameStarted(false);
@ -36,6 +36,7 @@ void ServerApplication::mainLoop() {
m_server.handleKeyState();
m_clock.updateGame([&] {
// TODO
});
m_clock.waitForNextFrame();

View File

@ -14,13 +14,13 @@
#include "Network.hpp"
#include "Server.hpp"
void Server::init() {
if (m_udpSocket.bind(4242) != sf::Socket::Done)
void Server::init(u16 port) {
if (m_udpSocket.bind(port) != sf::Socket::Done)
throw EXCEPTION("Network error: Bind failed");
m_udpSocket.setBlocking(false);
if (m_tcpListener.listen(4242) != sf::Socket::Done)
if (m_tcpListener.listen(port) != sf::Socket::Done)
throw EXCEPTION("Network error: Listen failed");
m_tcpListener.setBlocking(false);