Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
** EPITECH PROJECT, 2024 |
3 |
|
|
** zappy/ai |
4 |
|
|
** File description: |
5 |
|
|
** ABotPatternUtils.hpp |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#include "../ABotPattern.hpp" |
9 |
|
|
|
10 |
|
✗ |
void ABotPattern::separateServerBroadcast(const std::string &response, std::string &responseServer, std::string &responseBroadcast) |
11 |
|
|
{ |
12 |
|
✗ |
std::istringstream stream(response); |
13 |
|
|
std::string line; |
14 |
|
|
|
15 |
|
✗ |
while (std::getline(stream, line)) |
16 |
|
|
{ |
17 |
|
✗ |
if (line.find("message") != std::string::npos) |
18 |
|
|
{ |
19 |
|
✗ |
responseBroadcast += line + "\n"; |
20 |
|
|
} |
21 |
|
|
else |
22 |
|
|
{ |
23 |
|
✗ |
responseServer += line + "\n"; |
24 |
|
|
} |
25 |
|
|
} |
26 |
|
|
|
27 |
|
✗ |
responseServer = cleanCarriageReturn(responseServer); |
28 |
|
✗ |
responseBroadcast = cleanCarriageReturn(responseBroadcast); |
29 |
|
|
|
30 |
|
|
// Handle encrypted message |
31 |
|
✗ |
if (!responseBroadcast.empty()) |
32 |
|
|
{ |
33 |
|
✗ |
std::string signature = getElementAfter(responseBroadcast, ':'); |
34 |
|
|
|
35 |
|
✗ |
if (signature != _signature) |
36 |
|
|
{ |
37 |
|
✗ |
_enemyMessage.content = _message.content; |
38 |
|
✗ |
std::cout << "Enemy message: " << _enemyMessage.content << std::endl; |
39 |
|
|
return; |
40 |
|
|
} |
41 |
|
|
else |
42 |
|
|
{ |
43 |
|
✗ |
std::string temp = getElementBefore(responseBroadcast, ':'); |
44 |
|
✗ |
_allyMessage.content = getElementAfter(temp, ','); |
45 |
|
✗ |
_direction = getElementBefore(temp, ','); |
46 |
|
✗ |
_direction = getElementAfter(_direction, ' '); |
47 |
|
✗ |
_allyMessage.vigenereDecrypt(); |
48 |
|
|
responseBroadcast = _allyMessage.content; |
49 |
|
|
// printKeyValueColored("Message", _allyMessage.content); |
50 |
|
|
// printKeyValueColored("Direction", _direction); |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
✗ |
} |
54 |
|
|
|
55 |
|
|
// TODO: fix set linemate that can be on negativ, waiter incant. 1 say group 2 say joingroup, 2 say group 1 say joingroup because lvl are not updated |
56 |
|
|
// If incant == ko, go search rocks |
57 |
|
|
|