-
Notifications
You must be signed in to change notification settings - Fork 0
/
luserver.cpp
47 lines (36 loc) · 1.12 KB
/
luserver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "luserver.h"
LUServer::LUServer(QString pass, RakMessageHandler* handler, QTextStream *logger, QObject *parent) : QObject(parent)
{
_logger = logger;
handler->setParent(this);
_handler = handler;
_peer = new QtRakPeer(30, this);
_peer->SetIncomingPassword(pass.toLatin1().data(), pass.length());
connect(_peer, &QtRakPeer::Recieve, _handler, &RakMessageHandler::handleMessage);
connect(_handler, &RakMessageHandler::sendMessage,
[this](QByteArray data, SystemAddress address)
{
_peer->Send(data, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, address, false);
});
}
LUServer::~LUServer()
{
shutdown(300);
}
bool LUServer::startup(unsigned int port, int maxConnections, int maxIncoming)
{
SocketDescriptor sd(port, 0);
bool good = _peer->Startup(maxConnections, 30, &sd, 1);
_peer->SetMaximumIncomingConnections(maxIncoming);
if(good)
INFO(_logger, "Server started at " << _peer->GetLocalIP(0) << ":" << port);
return good;
}
void LUServer::shutdown(unsigned int block)
{
_peer->Shutdown(block);
}
bool LUServer::active()
{
return _peer->IsActive();
}