Line |
Branch |
Exec |
Source |
1 |
|
|
#include "Parser.hpp" |
2 |
|
|
#include "Player.hpp" |
3 |
|
|
#include "Egg.hpp" |
4 |
|
|
#include "Incantation.hpp" |
5 |
|
|
#include "../utils/GuiException.hpp" |
6 |
|
|
|
7 |
|
|
#include <cstddef> |
8 |
|
|
#include <sstream> |
9 |
|
|
#include <string> |
10 |
|
|
#include <vector> |
11 |
|
|
#include <iostream> |
12 |
|
|
|
13 |
|
|
#include <boost/filesystem.hpp> |
14 |
|
|
#include <boost/tokenizer.hpp> |
15 |
|
|
|
16 |
|
|
#include "../utils/Debug.hpp" |
17 |
|
|
|
18 |
|
|
// ---------------------------------------------------------------- // |
19 |
|
|
// --------------------------- HANDLERS --------------------------- // |
20 |
|
|
// ---------------------------------------------------------------- // |
21 |
|
|
|
22 |
|
6 |
void Parser::msz (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
23 |
3/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 3 times.
|
12 |
checkType(tokens, std::vector<Type>(2, Parser::Type::INT), __func__); |
24 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
|
6 |
auto lambda = [tokens, &gameData]() { |
25 |
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 |
if (gameData.getMap().getMap().size() > 0) |
26 |
|
|
return; |
27 |
|
3 |
int x = std::get<int>(tokens.at(1)); |
28 |
|
3 |
int y = std::get<int>(tokens.at(2)); |
29 |
|
|
debug_print << "msz X:" << x << " Y:" << y << std::endl; |
30 |
|
3 |
gameData.getMap().fillMap(x, y); |
31 |
|
3 |
}; |
32 |
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 |
_queue.push(lambda); |
33 |
|
3 |
}; |
34 |
|
|
|
35 |
|
3 |
void Parser::bct (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
36 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(9, Parser::Type::INT), __func__); |
37 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
38 |
|
1 |
int x = std::get<int>(tokens.at(1)); |
39 |
|
1 |
int y = std::get<int>(tokens.at(2)); |
40 |
|
|
// debug_print << "bct X:" << x << " Y:" << y << std::endl; |
41 |
|
1 |
std::vector<int> values; |
42 |
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 |
for (int i = 3; i < 10; i++) |
43 |
2/4
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 |
values.push_back(std::get<int>(tokens.at(i))); |
44 |
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 |
gameData.getMap().updateTile(x, y, values); |
45 |
|
2 |
}; |
46 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
47 |
|
1 |
}; |
48 |
|
|
|
49 |
|
3 |
void Parser::tna (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
50 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::STRING), __func__); |
51 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
52 |
|
2 |
std::string teamName = std::get<std::string>(tokens.at(1)); |
53 |
|
|
debug_print << "tna " << teamName << std::endl; |
54 |
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
if (!gameData.doesTeamExist(teamName)) |
55 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
gameData.addTeam(teamName); |
56 |
|
2 |
}; |
57 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
58 |
|
1 |
}; |
59 |
|
|
|
60 |
|
17 |
void Parser::pnw (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
61 |
3/4
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 15 times.
✓ Branch 6 taken 2 times.
|
34 |
checkType(tokens, std::vector<Type>({Parser::Type::INT, Parser::Type::INT, Parser::Type::INT, Parser::Type::INT, Parser::Type::INT, Parser::Type::STRING}), __func__); |
62 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
|
30 |
auto lambda = [tokens, &gameData]() { |
63 |
|
15 |
std::vector<int> values; |
64 |
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 15 times.
|
90 |
for (int i = 1; i < 6; i++) |
65 |
2/4
✓ Branch 1 taken 75 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 75 times.
✗ Branch 5 not taken.
|
150 |
values.push_back(std::get<int>(tokens.at(i))); |
66 |
2/4
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
|
30 |
std::string teamName = std::get<std::string>(tokens.at(6)); |
67 |
|
|
debug_print << "pnw inv:" << values.at(0) << " " << values.at(1) << " " << values.at(2) << " " << values.at(3) << " " << values.at(4) << " TeamName" << teamName << std::endl; |
68 |
3/6
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 15 times.
✗ Branch 8 not taken.
|
30 |
gameData.addPlayer(values, teamName); |
69 |
|
30 |
}; |
70 |
1/2
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
|
30 |
_queue.push(lambda); |
71 |
|
15 |
}; |
72 |
|
|
|
73 |
|
3 |
void Parser::ppo (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
74 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(4, Parser::Type::INT), __func__); |
75 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
76 |
|
2 |
std::shared_ptr<Player> player = gameData.getPlayerById(std::get<int>(tokens.at(1))); |
77 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
int x = std::get<int>(tokens.at(2)); |
78 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
int y = std::get<int>(tokens.at(3)); |
79 |
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 |
int orientation = std::get<int>(tokens.at(4)); |
80 |
|
|
debug_print << "ppo X:" << x << " Y:" << y << " O:" << orientation << std::endl; |
81 |
3/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
2 |
player->setPosition(std::vector<int>({x, y})); |
82 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
player->setOrientation(orientation); |
83 |
|
2 |
}; |
84 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
85 |
|
1 |
}; |
86 |
|
|
|
87 |
|
3 |
void Parser::plv (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
88 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(2, Parser::Type::INT), __func__); |
89 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
90 |
|
2 |
std::shared_ptr<Player> player = gameData.getPlayerById(std::get<int>(tokens.at(1))); |
91 |
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 |
int lvl = std::get<int>(tokens.at(2)); |
92 |
|
|
debug_print << "plv lvl:" << lvl << std::endl; |
93 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
player->setLvl(lvl); |
94 |
|
2 |
}; |
95 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
96 |
|
1 |
}; |
97 |
|
|
|
98 |
|
3 |
void Parser::pin (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
99 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(10, Parser::Type::INT), __func__); |
100 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
101 |
|
2 |
std::shared_ptr<Player> player = gameData.getPlayerById(std::get<int>(tokens.at(1))); |
102 |
|
1 |
std::vector<int> inventory; |
103 |
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 |
for (int i = 4; i < 11; i++) |
104 |
2/4
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 |
inventory.push_back(std::get<int>(tokens.at(i))); |
105 |
|
|
debug_print << "pin inv:" << inventory.at(0) << " " << inventory.at(1) << " " << inventory.at(2) << " " << inventory.at(3) << " " << inventory.at(4) << " " << inventory.at(5) << " " << inventory.at(6) << std::endl; |
106 |
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 |
player->setInventory(inventory); |
107 |
|
2 |
}; |
108 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
109 |
|
1 |
}; |
110 |
|
|
|
111 |
|
3 |
void Parser::pex (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
112 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::INT), __func__); |
113 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData, &server]() { |
114 |
|
1 |
int playerNb = std::get<int>(tokens.at(1)); |
115 |
|
|
debug_print << "pex " << playerNb << std::endl; |
116 |
|
1 |
std::shared_ptr<Player> player = gameData.getPlayerById(playerNb); |
117 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
player->setPushed(); |
118 |
3/8
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
3 |
server.sendToServer("ppo Pid:" + std::to_string(playerNb) + "\n"); |
119 |
|
1 |
}; |
120 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
121 |
|
1 |
}; |
122 |
|
|
|
123 |
|
3 |
void Parser::pbc (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
124 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>({Parser::Type::INT, Parser::Type::STRING}), __func__); |
125 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
126 |
|
1 |
int playerNb = std::get<int>(tokens.at(1)); |
127 |
|
1 |
std::shared_ptr<Player> player = gameData.getPlayerById(playerNb); |
128 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
std::vector<int> pos = player->getPosition(); |
129 |
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 |
std::string msg = std::get<std::string>(tokens.at(2)); |
130 |
|
|
debug_print << "pbc Pid:" << playerNb << " X:" << pos.at(0) << " Y:" << pos.at(1) << " MSG:" << msg << std::endl; |
131 |
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
2 |
gameData.addBroadcast(playerNb, pos, msg); |
132 |
|
2 |
}; |
133 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
134 |
|
1 |
}; |
135 |
|
|
|
136 |
|
2 |
void Parser::pic (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
137 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
4 |
auto lambda = [tokens, &gameData]() { |
138 |
|
2 |
int x = std::get<int>(tokens.at(1)); |
139 |
|
2 |
int y = std::get<int>(tokens.at(2)); |
140 |
|
2 |
std::vector<int> pos = std::vector<int>({x, y}); |
141 |
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 |
int lvl = std::get<int>(tokens.at(3)); |
142 |
|
2 |
std::vector<int> playersId; |
143 |
|
|
debug_print << "pic X:" << x << " Y:" << y << " lvl:" << lvl << " Pid1:" << std::get<int>(tokens.at(4)) << std::endl; |
144 |
|
|
|
145 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 |
for (size_t i = 4; i < tokens.size(); i++) { |
146 |
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 |
int playerNb = std::get<int>(tokens.at(i)); |
147 |
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 |
std::shared_ptr<Player> player = gameData.getPlayerById(playerNb); |
148 |
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 |
player->setIncanting(); |
149 |
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 |
playersId.push_back(playerNb); |
150 |
|
|
} |
151 |
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
4 |
gameData.addIncantation(pos, lvl, playersId); |
152 |
|
4 |
}; |
153 |
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 |
_queue.push(lambda); |
154 |
|
2 |
}; |
155 |
|
|
|
156 |
|
3 |
void Parser::pie (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
157 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(3, Parser::Type::INT), __func__); |
158 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
159 |
|
1 |
int x = std::get<int>(tokens.at(1)); |
160 |
|
1 |
int y = std::get<int>(tokens.at(2)); |
161 |
|
1 |
int result = std::get<int>(tokens.at(3)); |
162 |
|
1 |
std::vector<int> pos = std::vector<int>({x, y}); |
163 |
|
|
|
164 |
|
|
debug_print << "pie result:" << result << " X:" << x << " Y:" << y << std::endl; |
165 |
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
std::shared_ptr<Incantation> incantation = gameData.getIncantationByPos(pos); |
166 |
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 |
incantation->setStatus(result == 0 ? FAILURE : SUCCESS); |
167 |
|
2 |
}; |
168 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
169 |
|
1 |
}; |
170 |
|
|
|
171 |
|
3 |
void Parser::pfk (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
172 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::INT), __func__); |
173 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
174 |
|
1 |
int playerNb = std::get<int>(tokens.at(1)); |
175 |
|
|
debug_print << "pfk Pid:" << playerNb << std::endl; |
176 |
|
1 |
std::shared_ptr<Player> player = gameData.getPlayerById(playerNb); |
177 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
player->setEgging(); |
178 |
|
2 |
}; |
179 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
180 |
|
1 |
}; |
181 |
|
|
|
182 |
|
3 |
void Parser::pdr (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
183 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(2, Parser::Type::INT), __func__); |
184 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData, &server]() { |
185 |
|
1 |
int playerNb = std::get<int>(tokens.at(1)); |
186 |
|
1 |
int resource = std::get<int>(tokens.at(2)); |
187 |
|
|
debug_print << "pdr (drop) Pid:" << playerNb << " Res:" << resource << std::endl; |
188 |
|
1 |
std::shared_ptr<Player> player = gameData.getPlayerById(playerNb); |
189 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
player->setDrop(resource); |
190 |
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
|
2 |
server.sendToServer("pin " + std::to_string(playerNb) + "\n"); |
191 |
1/8
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 |
server.sendToServer("ppo " + std::to_string(playerNb) + "\n"); |
192 |
|
1 |
}; |
193 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
194 |
|
1 |
}; |
195 |
|
|
|
196 |
|
3 |
void Parser::pgt (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
197 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(2, Parser::Type::INT), __func__); |
198 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData, &server]() { |
199 |
|
1 |
int playerNb = std::get<int>(tokens.at(1)); |
200 |
|
1 |
int resource = std::get<int>(tokens.at(2)); |
201 |
|
|
debug_print << "pgt (take) Pid:" << playerNb << " Res:" << resource << std::endl; |
202 |
|
1 |
std::shared_ptr<Player> player = gameData.getPlayerById(playerNb); |
203 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
player->setPickup(resource); |
204 |
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
|
2 |
server.sendToServer("pin " + std::to_string(playerNb) + "\n"); |
205 |
1/8
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 |
server.sendToServer("ppo " + std::to_string(playerNb) + "\n"); |
206 |
|
1 |
}; |
207 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
208 |
|
1 |
}; |
209 |
|
|
|
210 |
|
3 |
void Parser::pdi (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
211 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::INT), __func__); |
212 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
213 |
|
1 |
int playerNb = std::get<int>(tokens.at(1)); |
214 |
|
|
debug_print << "pdi (die) Pid:" << playerNb << std::endl; |
215 |
|
1 |
std::shared_ptr<Player> player = gameData.getPlayerById(playerNb); |
216 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
player->setAlive(false); |
217 |
|
2 |
}; |
218 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
219 |
|
1 |
}; |
220 |
|
|
|
221 |
|
5 |
void Parser::enw (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
222 |
3/4
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 2 times.
|
10 |
checkType(tokens, std::vector<Type>(4, Parser::Type::INT), __func__); |
223 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
|
6 |
auto lambda = [tokens, &gameData]() { |
224 |
|
3 |
int eggNb = std::get<int>(tokens.at(1)); |
225 |
|
3 |
int playerNb = std::get<int>(tokens.at(2)); |
226 |
|
3 |
int x = std::get<int>(tokens.at(3)); |
227 |
|
3 |
int y = std::get<int>(tokens.at(4)); |
228 |
|
|
debug_print << "enw Eid:" << eggNb << " Pid:" << playerNb << " X:" << x << " Y:" << y << std::endl; |
229 |
|
3 |
std::vector<int> pos = std::vector<int>({x, y}); |
230 |
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
6 |
gameData.addEgg(pos, eggNb, playerNb, INCUBATING); |
231 |
|
6 |
}; |
232 |
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 |
_queue.push(lambda); |
233 |
|
3 |
}; |
234 |
|
|
|
235 |
|
3 |
void Parser::ebo (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
236 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::INT), __func__); |
237 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
238 |
|
1 |
int eggNb = std::get<int>(tokens.at(1)); |
239 |
|
|
debug_print << "ebo Eid:" << eggNb << std::endl; |
240 |
|
1 |
gameData.getEggById(eggNb).setState(HATCHED); |
241 |
|
1 |
}; |
242 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
243 |
|
1 |
}; |
244 |
|
|
|
245 |
|
3 |
void Parser::edi (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
246 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::INT), __func__); |
247 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
248 |
|
1 |
int eggNb = std::get<int>(tokens.at(1)); |
249 |
|
|
debug_print << "edi Eid:" << eggNb << std::endl; |
250 |
|
1 |
gameData.getEggById(eggNb).setState(DEAD); |
251 |
|
1 |
}; |
252 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
253 |
|
1 |
}; |
254 |
|
|
|
255 |
|
3 |
void Parser::sst(const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
256 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::INT), __func__); |
257 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
258 |
|
1 |
int tickRate = std::get<int>(tokens.at(1)); |
259 |
|
|
debug_print << "sst Tick rate:" << tickRate << std::endl; |
260 |
|
1 |
gameData.setTickRate(tickRate); |
261 |
|
1 |
}; |
262 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
263 |
|
1 |
}; |
264 |
|
|
|
265 |
|
3 |
void Parser::sgt(const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
266 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::INT), __func__); |
267 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
268 |
|
1 |
int tickRate = std::get<int>(tokens.at(1)); |
269 |
|
|
debug_print << "sgt Tick rate:" << tickRate << std::endl; |
270 |
|
1 |
gameData.setTickRate(tickRate); |
271 |
|
1 |
}; |
272 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
273 |
|
1 |
}; |
274 |
|
|
|
275 |
|
3 |
void Parser::seg (const std::vector<TokenType>& tokens, Data& gameData, [[maybe_unused]] ServerConnect &server) { |
276 |
|
|
|
277 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::STRING), __func__); |
278 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens, &gameData]() { |
279 |
|
2 |
std::string teamName = std::get<std::string>(tokens.at(1)); |
280 |
|
|
debug_print << "seg TeamName:" << teamName << std::endl; |
281 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
gameData.setWinner(teamName); |
282 |
|
2 |
}; |
283 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
284 |
|
1 |
}; |
285 |
|
|
|
286 |
|
3 |
void Parser::smg (const std::vector<TokenType>& tokens, [[maybe_unused]] Data& gameData, [[maybe_unused]] ServerConnect &server) { |
287 |
|
|
|
288 |
3/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
|
6 |
checkType(tokens, std::vector<Type>(1, Parser::Type::STRING), __func__); |
289 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens]() { |
290 |
|
2 |
std::string msg = std::get<std::string>(tokens.at(1)); |
291 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 |
std::cout << "server sent: " << msg << std::endl; |
292 |
|
2 |
}; |
293 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
294 |
|
1 |
}; |
295 |
|
|
|
296 |
|
1 |
void Parser::suc (const std::vector<TokenType>& tokens, [[maybe_unused]] Data& gameData, [[maybe_unused]] ServerConnect &server) { |
297 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens]() { |
298 |
|
1 |
std::cout << "Unknown command response from the server" << std::endl; |
299 |
|
1 |
}; |
300 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
301 |
|
1 |
}; |
302 |
|
|
|
303 |
|
1 |
void Parser::sbp (const std::vector<TokenType>& tokens, [[maybe_unused]] Data& gameData, [[maybe_unused]] ServerConnect &server) { |
304 |
1/4
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 |
auto lambda = [tokens]() { |
305 |
|
1 |
std::cout << "server sent sbp. what for ?" << std::endl; |
306 |
|
1 |
}; |
307 |
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 |
_queue.push(lambda); |
308 |
|
1 |
}; |
309 |
|
|
|
310 |
|
|
|
311 |
|
|
// ---------------------------------------------------------------- // |
312 |
|
|
// -------------------------- EXECUTION --------------------------- // |
313 |
|
|
// ---------------------------------------------------------------- // |
314 |
|
|
|
315 |
|
|
|
316 |
|
24 |
void Parser::execute() { |
317 |
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 24 times.
|
67 |
while (!_queue.empty()) { |
318 |
|
|
try { |
319 |
2/2
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 3 times.
|
43 |
_queue.front()(); |
320 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 |
} catch (const guiException& e) { |
321 |
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 |
std::cerr << "error in data update:\n" << e.what() << std::endl; |
322 |
|
3 |
} |
323 |
|
43 |
_queue.pop(); |
324 |
|
|
} |
325 |
|
24 |
}; |
326 |
|
|
|
327 |
|
✗ |
void Parser::updateData(Data &gameData, ServerConnect &server) |
328 |
|
|
{ |
329 |
|
|
std::string data; |
330 |
|
|
try { |
331 |
|
✗ |
data = server.readFromServer(); |
332 |
|
✗ |
} catch (const guiException& e) { |
333 |
|
✗ |
std::cerr << e.what() << std::endl; |
334 |
|
✗ |
} |
335 |
|
|
|
336 |
|
✗ |
if (data.compare(std::string("WELCOME\n")) == 0) { |
337 |
|
✗ |
server.sendToServer("GRAPHIC\n"); |
338 |
|
✗ |
server.sendToServer("msz\n"); |
339 |
|
✗ |
server.sendToServer("mct\n"); |
340 |
|
✗ |
server.sendToServer("tna\n"); |
341 |
|
|
return; |
342 |
|
|
} |
343 |
|
|
|
344 |
|
✗ |
std::istringstream dataStream(data); |
345 |
|
|
std::string line; |
346 |
|
|
|
347 |
|
✗ |
while (std::getline(dataStream, line)) { |
348 |
|
✗ |
boost::tokenizer<> tok(line); |
349 |
|
✗ |
std::vector<std::string> tokens(tok.begin(), tok.end()); |
350 |
|
✗ |
std::vector<std::variant<std::string, int>> vals; |
351 |
|
|
|
352 |
|
✗ |
for (auto& token : tokens) { |
353 |
|
|
try { |
354 |
|
|
int numVal = std::stoi(token); |
355 |
|
✗ |
vals.push_back(numVal); |
356 |
|
✗ |
} catch (const std::exception& e) { |
357 |
|
✗ |
vals.push_back(token); |
358 |
|
✗ |
} |
359 |
|
|
} |
360 |
|
|
try { |
361 |
|
✗ |
parse(vals, gameData, server); |
362 |
|
✗ |
} catch (const ParserException& e) { |
363 |
|
✗ |
std::cerr << "error in parsing:\n" << e.what() << std::endl; |
364 |
|
✗ |
} |
365 |
|
✗ |
} |
366 |
|
✗ |
execute(); |
367 |
|
✗ |
} |
368 |
|
|
|
369 |
1/2
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
|
88 |
void Parser::parse(std::vector<TokenType> values, Data& gameData, ServerConnect &server) |
370 |
|
|
{ |
371 |
3/4
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 87 times.
|
88 |
if (values.empty() || !std::holds_alternative<std::string>(values.at(0))) { |
372 |
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 |
throw ParserException("Invalid command format"); |
373 |
|
|
} |
374 |
|
|
|
375 |
|
87 |
const std::string& command = std::get<std::string>(values.at(0)); |
376 |
|
|
auto it = handlers.find(command); |
377 |
|
|
|
378 |
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 1 times.
|
87 |
if (it != handlers.end()) { |
379 |
|
86 |
it->second(values, gameData, server); |
380 |
|
|
} else { |
381 |
|
|
// std::cerr << "Command not found: " << command << std::endl; |
382 |
|
|
} |
383 |
|
44 |
}; |
384 |
|
|
|
385 |
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 30 times.
|
82 |
void Parser::checkType(const std::vector<TokenType>& tokens, const std::vector<Type>& expectedTypes, const std::string &name) { |
386 |
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 30 times.
|
82 |
if (tokens.size() != (expectedTypes.size() + 1)) |
387 |
2/4
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 30 times.
✗ Branch 6 not taken.
|
60 |
throw ParserException("Invalid number of arguments for command " + name); |
388 |
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 39 times.
|
204 |
for (size_t i = 1; i < tokens.size(); i++) { |
389 |
4/4
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 21 times.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 133 times.
|
165 |
if (expectedTypes.at(i - 1) == Parser::Type::INT && !std::holds_alternative<int>(tokens.at(i))) |
390 |
4/8
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 11 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 11 times.
✗ Branch 12 not taken.
|
33 |
throw ParserException("Invalid type for argument " + std::to_string(i) + " in command " + name); |
391 |
4/4
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 133 times.
✓ Branch 4 taken 19 times.
✓ Branch 5 taken 2 times.
|
154 |
if (expectedTypes.at(i - 1) == Parser::Type::STRING && !std::holds_alternative<std::string>(tokens.at(i))) |
392 |
4/8
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
|
6 |
throw ParserException("Invalid type for argument " + std::to_string(i) + " in command " + name); |
393 |
|
|
} |
394 |
|
39 |
}; |
395 |
|
|
|