Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jochen Bauer
spn-relayserver
Commits
a5ce9064
Commit
a5ce9064
authored
Apr 29, 2018
by
Hubert Denkmair
Browse files
check and set viewer keys
parent
318a2880
Changes
3
Hide whitespace changes
Inline
Side-by-side
relayserver/RelayServer.cpp
View file @
a5ce9064
#include "RelayServer.h"
#include <iostream>
#include <string>
#include <TcpServer/EPoll.h>
#include <nlohmann/json.hpp>
using
nlohmann
::
json
;
RelayServer
::
RelayServer
()
{
...
...
@@ -35,11 +38,11 @@ int RelayServer::Run()
con
->
FrameComplete
(
frame_id
,
_tcpProtocol
);
auto
key
=
con
->
getViewerKey
();
//
if (key!=0)
TODO implement
if
(
key
!=
0
)
{
for
(
auto
&
item
:
logMessages
)
{
//
if (item
->
viewer_key == key)
// TODO implement
if
(
item
.
viewer_key
==
key
)
{
con
->
LogMessage
(
frame_id
,
item
.
message
);
}
...
...
@@ -68,8 +71,23 @@ int RelayServer::Run()
);
h
.
onMessage
([](
uWS
::
WebSocket
<
uWS
::
SERVER
>
*
ws
,
char
*
message
,
size_t
length
,
uWS
::
OpCode
opCode
)
{
//ws->send(message, length, opCode);
{
auto
*
con
=
static_cast
<
WebsocketConnection
*>
(
ws
->
getUserData
());
if
(
length
>
MAX_CLIENT_MESSAGE_SIZE
)
{
return
;
}
std
::
string
s
(
message
,
length
);
json
data
=
json
::
parse
(
s
,
nullptr
,
false
);
if
(
!
data
.
is_object
())
{
return
;
}
if
(
data
[
"viewer_key"
].
is_string
())
{
std
::
string
key
=
data
[
"viewer_key"
];
con
->
setViewerKey
(
static_cast
<
uint64_t
>
(
std
::
stol
(
key
)));
}
});
std
::
string
response
=
"Hello!"
;
...
...
relayserver/RelayServer.h
View file @
a5ce9064
...
...
@@ -19,6 +19,7 @@ class RelayServer
static
constexpr
const
char
*
ENV_GAMESERVER_PORT_DEFAULT
=
"9010"
;
static
constexpr
const
char
*
ENV_WEBSOCKET_PORT
=
"WEBSOCKET_PORT"
;
static
constexpr
const
char
*
ENV_WEBSOCKET_PORT_DEFAULT
=
"9009"
;
static
constexpr
const
size_t
MAX_CLIENT_MESSAGE_SIZE
=
10
*
1024
;
static
int
connectTcpSocket
(
const
char
*
hostname
,
const
char
*
port
);
static
const
char
*
getEnvOrDefault
(
const
char
*
envVar
,
const
char
*
defaultValue
);
};
relayserver/WebsocketConnection.h
View file @
a5ce9064
...
...
@@ -12,6 +12,7 @@ class WebsocketConnection
void
LogMessage
(
uint64_t
frame_id
,
const
std
::
string
&
message
);
void
sendString
(
std
::
string
data
);
uint64_t
getViewerKey
()
{
return
_viewerKey
;
}
void
setViewerKey
(
uint64_t
key
)
{
_viewerKey
=
key
;
}
private:
uWS
::
WebSocket
<
uWS
::
SERVER
>
*
_websocket
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment