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
ad97506f
Commit
ad97506f
authored
May 03, 2018
by
Hubert Denkmair
Browse files
prepare update refactor
parent
5e33d723
Changes
3
Hide whitespace changes
Inline
Side-by-side
relayserver/TcpProtocol.cpp
View file @
ad97506f
...
...
@@ -7,8 +7,6 @@
#include <iostream>
TcpProtocol
::
TcpProtocol
()
:
_food
(
_worldUpdate
.
food
)
,
_bots
(
_worldUpdate
.
bots
)
{
_buf
.
resize
(
BUFFER_SIZE
);
}
...
...
@@ -46,6 +44,14 @@ bool TcpProtocol::Read(int socket)
return
true
;
}
std
::
unique_ptr
<
MsgPackProtocol
::
WorldUpdateMessage
>
TcpProtocol
::
MakeWorldUpdateMessage
()
const
{
auto
result
=
std
::
make_unique
<
MsgPackProtocol
::
WorldUpdateMessage
>
();
result
->
food
=
_food
;
result
->
bots
=
_bots
;
return
result
;
}
void
TcpProtocol
::
ClearLogItems
()
{
for
(
auto
&
kvp
:
_pendingLogItems
)
...
...
@@ -121,16 +127,13 @@ void TcpProtocol::OnMessageReceived(const char* data, size_t count)
void
TcpProtocol
::
OnGameInfoReceived
(
const
MsgPackProtocol
::
GameInfoMessage
&
msg
)
{
//_segments = std::make_unique<SnakeSegmentMap>(msg.world_size_x, msg.world_size_y, 1000);
//_foodMap = std::make_unique<FoodMap>(msg.world_size_x, msg.world_size_y, 1000);
_gameInfo
=
msg
;
}
void
TcpProtocol
::
OnWorldUpdateReceived
(
const
MsgPackProtocol
::
WorldUpdateMessage
&
msg
)
{
_worldUpdate
=
msg
;
_bots
=
_worldUpdate
.
bots
;
_food
=
_worldUpdate
.
food
;
_bots
=
msg
.
bots
;
_food
=
msg
.
food
;
}
void
TcpProtocol
::
OnTickReceived
(
const
MsgPackProtocol
::
TickMessage
&
msg
)
...
...
relayserver/TcpProtocol.h
View file @
ad97506f
...
...
@@ -22,7 +22,8 @@ class TcpProtocol
bool
Read
(
int
socket
);
const
MsgPackProtocol
::
GameInfoMessage
&
GetGameInfo
()
const
{
return
_gameInfo
;
}
const
MsgPackProtocol
::
WorldUpdateMessage
&
GetWorldUpdate
()
const
{
return
_worldUpdate
;
}
std
::
unique_ptr
<
MsgPackProtocol
::
WorldUpdateMessage
>
MakeWorldUpdateMessage
()
const
;
const
std
::
vector
<
std
::
unique_ptr
<
MsgPackProtocol
::
Message
>>&
GetPendingMessages
()
const
{
return
_pendingMessages
;
}
typedef
std
::
map
<
uint64_t
,
std
::
vector
<
MsgPackProtocol
::
BotLogItem
>>
LogItemMap
;
...
...
@@ -36,9 +37,8 @@ class TcpProtocol
FrameCompleteCallback
_frameCompleteCallback
;
MsgPackProtocol
::
GameInfoMessage
_gameInfo
;
MsgPackProtocol
::
WorldUpdateMessage
_worldUpdate
;
std
::
vector
<
FoodItem
>&
_food
;
std
::
vector
<
BotItem
>&
_bots
;
std
::
vector
<
FoodItem
>
_food
;
std
::
vector
<
BotItem
>
_bots
;
std
::
vector
<
std
::
unique_ptr
<
MsgPackProtocol
::
Message
>>
_pendingMessages
;
LogItemMap
_pendingLogItems
;
...
...
relayserver/WebsocketConnection.cpp
View file @
ad97506f
...
...
@@ -27,7 +27,7 @@ void WebsocketConnection::LogMessage(uint64_t frame_id, const std::string &messa
void
WebsocketConnection
::
sendInitialData
(
const
TcpProtocol
&
proto
)
{
sendString
(
json
(
proto
.
GetGameInfo
()).
dump
());
sendString
(
json
(
proto
.
Get
WorldUpdate
()).
dump
());
sendString
(
json
(
*
proto
.
Make
WorldUpdate
Message
()).
dump
());
}
void
WebsocketConnection
::
sendString
(
std
::
string
data
)
...
...
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