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
239e1a59
Commit
239e1a59
authored
May 02, 2018
by
Hubert Denkmair
Browse files
use a std::map for log messages
parent
f55221a9
Changes
3
Hide whitespace changes
Inline
Side-by-side
relayserver/RelayServer.cpp
View file @
239e1a59
...
...
@@ -38,20 +38,18 @@ int RelayServer::Run()
con
->
FrameComplete
(
frame_id
,
_tcpProtocol
);
auto
key
=
con
->
getViewerKey
();
if
(
key
!=
0
)
if
(
logMessages
.
find
(
key
)
==
logMessages
.
end
()
)
{
for
(
auto
&
item
:
logMessages
)
{
if
(
item
.
viewer_key
==
key
)
{
con
->
LogMessage
(
frame_id
,
item
.
message
);
}
}
return
;
}
for
(
auto
&
item
:
logMessages
.
at
(
key
))
{
con
->
LogMessage
(
frame_id
,
item
.
message
);
}
}
);
_tcpProtocol
.
ClearLogItems
();
//std::cout << "frame " << frame_id << " complete." << std::endl;
}
);
epoll
.
AddFileDescriptor
(
_clientSocket
,
EPOLLIN
|
EPOLLPRI
|
EPOLLERR
);
...
...
relayserver/TcpProtocol.cpp
View file @
239e1a59
...
...
@@ -46,6 +46,14 @@ bool TcpProtocol::Read(int socket)
return
true
;
}
void
TcpProtocol
::
ClearLogItems
()
{
for
(
auto
&
kvp
:
_pendingLogItems
)
{
_pendingLogItems
[
kvp
.
first
].
clear
();
}
}
void
TcpProtocol
::
OnMessageReceived
(
const
char
*
data
,
size_t
count
)
{
msgpack
::
object_handle
obj
;
...
...
@@ -192,7 +200,6 @@ void TcpProtocol::OnBotLogReceived(std::unique_ptr<MsgPackProtocol::BotLogMessag
{
for
(
auto
&
item
:
msg
->
items
)
{
_pendingLogItems
.
push
_back
(
item
);
_pendingLogItems
[
item
.
viewer_key
].
emplace
_back
(
item
);
}
}
relayserver/TcpProtocol.h
View file @
239e1a59
...
...
@@ -4,6 +4,7 @@
#include <functional>
#include <vector>
#include <memory>
#include <map>
#include "SpatialMap.h"
#include "MsgPackProtocol.h"
...
...
@@ -25,8 +26,9 @@ class TcpProtocol
const
MsgPackProtocol
::
WorldUpdateMessage
&
GetWorldUpdate
()
const
{
return
_worldUpdate
;
}
const
std
::
vector
<
std
::
unique_ptr
<
MsgPackProtocol
::
Message
>>&
GetPendingMessages
()
const
{
return
_pendingMessages
;
}
const
std
::
vector
<
MsgPackProtocol
::
BotLogItem
>&
GetPendingLogItems
()
const
{
return
_pendingLogItems
;
}
void
ClearLogItems
()
{
_pendingLogItems
.
clear
();
}
typedef
std
::
map
<
uint64_t
,
std
::
vector
<
MsgPackProtocol
::
BotLogItem
>>
LogItemMap
;
const
LogItemMap
&
GetPendingLogItems
()
const
{
return
_pendingLogItems
;
}
void
ClearLogItems
();
private:
static
constexpr
const
size_t
SPATIAL_MAP_TILES_X
=
128
;
...
...
@@ -34,7 +36,6 @@ class TcpProtocol
static
constexpr
const
size_t
SPATIAL_MAP_RESERVE_COUNT
=
10
;
typedef
SpatialMap
<
FoodItem
,
SPATIAL_MAP_TILES_X
,
SPATIAL_MAP_TILES_Y
>
FoodMap
;
typedef
SpatialMap
<
SnakeSegmentItem
,
SPATIAL_MAP_TILES_X
,
SPATIAL_MAP_TILES_Y
>
SnakeSegmentMap
;
std
::
vector
<
char
>
_buf
;
...
...
@@ -47,7 +48,8 @@ class TcpProtocol
std
::
vector
<
FoodItem
>&
_food
;
std
::
vector
<
BotItem
>&
_bots
;
std
::
vector
<
std
::
unique_ptr
<
MsgPackProtocol
::
Message
>>
_pendingMessages
;
std
::
vector
<
MsgPackProtocol
::
BotLogItem
>
_pendingLogItems
;
LogItemMap
_pendingLogItems
;
void
OnMessageReceived
(
const
char
*
data
,
size_t
count
);
...
...
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