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
96855a9d
Commit
96855a9d
authored
Apr 12, 2018
by
Hubert Denkmair
Browse files
cleanup
parent
882d4870
Changes
3
Hide whitespace changes
Inline
Side-by-side
relayserver/RelayServer.cpp
View file @
96855a9d
...
...
@@ -34,7 +34,7 @@ RelayServer::RelayServer()
msg
.
SetMessageReceivedCallback
(
[](
std
::
vector
<
char
>
data
)
{
std
::
cout
<<
"received "
<<
data
.
size
()
<<
" bytes."
<<
std
::
endl
;
//
std::cout << "received " << data.size() << " bytes." << std::endl;
}
);
...
...
relayserver/TcpProtocol.cpp
View file @
96855a9d
...
...
@@ -60,7 +60,6 @@ void TcpProtocol::OnMessageReceived(std::vector<char> &data)
uint64_t
version
=
arr
.
ptr
[
0
].
via
.
u64
;
uint64_t
message_type
=
arr
.
ptr
[
1
].
via
.
u64
;
std
::
cerr
<<
"version: "
<<
version
<<
" message type: "
<<
message_type
<<
std
::
endl
;
switch
(
message_type
)
{
case
MsgPackProtocol
::
MESSAGE_TYPE_GAME_INFO
:
...
...
@@ -68,70 +67,35 @@ void TcpProtocol::OnMessageReceived(std::vector<char> &data)
break
;
case
MsgPackProtocol
::
MESSAGE_TYPE_WORLD_UPDATE
:
{
auto
msg
=
obj
.
get
().
as
<
MsgPackProtocol
::
WorldUpdateMessage
>
();
for
(
auto
&
bot
:
msg
.
bots
)
{
OnBotSpawnReceived
(
bot
);
}
for
(
auto
&
food
:
msg
.
food
)
{
OnFoodSpawnReceived
(
food
);
}
OnWorldUpdateReceived
(
obj
.
get
().
as
<
MsgPackProtocol
::
WorldUpdateMessage
>
());
break
;
}
case
MsgPackProtocol
::
MESSAGE_TYPE_TICK
:
std
::
cerr
<<
"tick"
<<
std
::
endl
;
break
;
case
MsgPackProtocol
::
MESSAGE_TYPE_BOT_SPAWN
:
{
auto
msg
=
obj
.
get
().
as
<
MsgPackProtocol
::
BotSpawnMessage
>
();
OnBotSpawnReceived
(
msg
.
bot
);
OnBotSpawnReceived
(
obj
.
get
().
as
<
MsgPackProtocol
::
BotSpawnMessage
>
());
break
;
}
case
MsgPackProtocol
::
MESSAGE_TYPE_BOT_KILL
:
OnBotKillReceived
(
obj
.
get
().
as
<
MsgPackProtocol
::
BotKillMessage
>
());
break
;
case
MsgPackProtocol
::
MESSAGE_TYPE_BOT_MOVE
:
{
auto
msg
=
obj
.
get
().
as
<
MsgPackProtocol
::
BotMoveMessage
>
();
for
(
auto
&
item
:
msg
.
items
)
{
OnBotMoveReceived
(
item
);
}
OnBotMoveReceived
(
obj
.
get
().
as
<
MsgPackProtocol
::
BotMoveMessage
>
());
break
;
}
case
MsgPackProtocol
::
MESSAGE_TYPE_FOOD_SPAWN
:
{
auto
msg
=
obj
.
get
().
as
<
MsgPackProtocol
::
FoodSpawnMessage
>
();
for
(
auto
&
item
:
msg
.
new_food
)
{
OnFoodSpawnReceived
(
item
);
}
OnFoodSpawnReceived
(
obj
.
get
().
as
<
MsgPackProtocol
::
FoodSpawnMessage
>
());
break
;
}
case
MsgPackProtocol
::
MESSAGE_TYPE_FOOD_CONSUME
:
{
auto
msg
=
obj
.
get
().
as
<
MsgPackProtocol
::
FoodConsumeMessage
>
();
for
(
auto
&
item
:
msg
.
items
)
{
OnFoodConsumedReceived
(
item
);
}
OnFoodConsumedReceived
(
obj
.
get
().
as
<
MsgPackProtocol
::
FoodConsumeMessage
>
());
break
;
}
case
MsgPackProtocol
::
MESSAGE_TYPE_FOOD_DECAY
:
auto
msg
=
obj
.
get
().
as
<
MsgPackProtocol
::
FoodDecayMessage
>
();
for
(
auto
food_id
:
msg
.
food_ids
)
{
OnFoodDecayedReceived
(
food_id
);
}
OnFoodDecayedReceived
(
obj
.
get
().
as
<
MsgPackProtocol
::
FoodDecayMessage
>
());
break
;
}
}
...
...
@@ -143,27 +107,50 @@ void TcpProtocol::OnGameInfoReceived(const MsgPackProtocol::GameInfoMessage& msg
_gameInfo
=
msg
;
}
void
TcpProtocol
::
On
FoodSpawn
Received
(
const
FoodItem
&
food
)
void
TcpProtocol
::
On
WorldUpdate
Received
(
const
MsgPackProtocol
::
WorldUpdateMessage
&
msg
)
{
for
(
auto
&
bot
:
msg
.
bots
)
{
_bots
.
push_back
(
bot
);
}
if
(
_food
==
nullptr
)
{
return
;
}
_food
->
addElement
(
food
);
for
(
auto
&
food
:
msg
.
food
)
{
_food
->
addElement
(
food
);
}
}
void
TcpProtocol
::
OnFood
Consumed
Received
(
const
MsgPackProtocol
::
Food
ConsumeItem
&
item
)
void
TcpProtocol
::
OnFood
Spawn
Received
(
const
MsgPackProtocol
::
Food
SpawnMessage
&
msg
)
{
if
(
_food
==
nullptr
)
{
return
;
}
_food
->
erase_if
([
item
](
const
FoodItem
&
food
)
{
return
food
.
guid
==
item
.
food_id
;
});
for
(
auto
&
item
:
msg
.
new_food
)
{
_food
->
addElement
(
item
);
}
}
void
TcpProtocol
::
OnFood
Decay
edReceived
(
guid_t
food_id
)
void
TcpProtocol
::
OnFood
Consum
edReceived
(
const
MsgPackProtocol
::
FoodConsumeMessage
&
msg
)
{
if
(
_food
==
nullptr
)
{
return
;
}
_food
->
erase_if
([
food_id
](
const
FoodItem
&
food
)
{
return
food
.
guid
==
food_id
;
});
for
(
auto
&
item
:
msg
.
items
)
{
_food
->
erase_if
([
item
](
const
FoodItem
&
food
)
{
return
food
.
guid
==
item
.
food_id
;
});
}
}
void
TcpProtocol
::
On
BotSpawn
Received
(
const
MsgPackProtocol
::
BotItem
&
bot
)
void
TcpProtocol
::
On
FoodDecayed
Received
(
const
MsgPackProtocol
::
FoodDecayMessage
&
msg
)
{
_bots
.
push_back
(
bot
);
if
(
_food
==
nullptr
)
{
return
;
}
for
(
auto
&
item
:
msg
.
food_ids
)
{
_food
->
erase_if
([
item
](
const
FoodItem
&
food
)
{
return
food
.
guid
==
item
;
});
}
}
void
TcpProtocol
::
OnBotSpawnReceived
(
const
MsgPackProtocol
::
BotSpawnMessage
&
msg
)
{
_bots
.
push_back
(
msg
.
bot
);
}
void
TcpProtocol
::
OnBotKillReceived
(
const
MsgPackProtocol
::
BotKillMessage
&
msg
)
...
...
@@ -171,14 +158,17 @@ void TcpProtocol::OnBotKillReceived(const MsgPackProtocol::BotKillMessage& msg)
_bots
.
erase
(
std
::
remove_if
(
_bots
.
begin
(),
_bots
.
end
(),
[
msg
](
const
BotItem
&
bot
)
{
return
bot
.
guid
==
msg
.
victim_id
;
}));
}
void
TcpProtocol
::
OnBotMoveReceived
(
const
MsgPackProtocol
::
BotMove
Item
&
item
)
void
TcpProtocol
::
OnBotMoveReceived
(
const
MsgPackProtocol
::
BotMove
Message
&
msg
)
{
auto
it
=
std
::
find_if
(
_bots
.
begin
(),
_bots
.
end
(),
[
item
](
const
BotItem
&
bot
)
{
return
bot
.
guid
==
item
.
bot_id
;
});
if
(
it
==
_bots
.
end
())
{
return
;
}
auto
&
bot
=
*
it
;
for
(
auto
&
item
:
msg
.
items
)
{
auto
it
=
std
::
find_if
(
_bots
.
begin
(),
_bots
.
end
(),
[
item
](
const
BotItem
&
bot
)
{
return
bot
.
guid
==
item
.
bot_id
;
});
if
(
it
==
_bots
.
end
())
{
return
;
}
auto
&
bot
=
*
it
;
bot
.
segments
.
insert
(
bot
.
segments
.
begin
(),
item
.
new_segments
.
begin
(),
item
.
new_segments
.
end
());
bot
.
segments
.
resize
(
item
.
current_length
);
bot
.
segment_radius
=
item
.
current_segment_radius
;
bot
.
segments
.
insert
(
bot
.
segments
.
begin
(),
item
.
new_segments
.
begin
(),
item
.
new_segments
.
end
());
bot
.
segments
.
resize
(
item
.
current_length
);
bot
.
segment_radius
=
item
.
current_segment_radius
;
}
}
relayserver/TcpProtocol.h
View file @
96855a9d
...
...
@@ -42,12 +42,13 @@ class TcpProtocol
void
OnMessageReceived
(
std
::
vector
<
char
>&
data
);
void
OnGameInfoReceived
(
const
MsgPackProtocol
::
GameInfoMessage
&
msg
);
void
OnWorldUpdateReceived
(
const
MsgPackProtocol
::
WorldUpdateMessage
&
msg
);
void
OnFoodSpawnReceived
(
const
FoodItem
&
food
);
void
OnFoodConsumedReceived
(
const
MsgPackProtocol
::
FoodConsume
Item
&
item
);
void
OnFoodDecayedReceived
(
guid_t
food_id
);
void
OnFoodSpawnReceived
(
const
MsgPackProtocol
::
FoodSpawnMessage
&
msg
);
void
OnFoodConsumedReceived
(
const
MsgPackProtocol
::
FoodConsume
Message
&
msg
);
void
OnFoodDecayedReceived
(
const
MsgPackProtocol
::
FoodDecayMessage
&
msg
);
void
OnBotSpawnReceived
(
const
MsgPackProtocol
::
Bot
Item
&
bot
);
void
OnBotSpawnReceived
(
const
MsgPackProtocol
::
Bot
SpawnMessage
&
msg
);
void
OnBotKillReceived
(
const
MsgPackProtocol
::
BotKillMessage
&
msg
);
void
OnBotMoveReceived
(
const
MsgPackProtocol
::
BotMove
Item
&
item
);
void
OnBotMoveReceived
(
const
MsgPackProtocol
::
BotMove
Message
&
msg
);
};
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