Debian Codegraph @

src/bnetd/anongame_gameresult.cpp

raw symbols SCIP
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16 #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/
17 #define ANONGAME_GAMERESULT_INTERNAL_ACCESScxx . . $ `src/bnetd/anongame_gameresult.cpp:17:9`!
18 #include "anongame_gameresult.h"cxx . . $ `<file>/src/bnetd/anongame_gameresult.h`/
19
20 #include <cassert>
21
22 #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/
23 #include "common/xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/
24 #include "common/packet.h"cxx . . $ `<file>/src/common/packet.h`/
25 #include "common/bn_type.h"cxx . . $ `<file>/src/common/bn_type.h`/
26
27
28 #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/
29
30 namespace pvpgncxx . . $ pvpgn/
31 {
32
33 namespace bnetdcxx . . $ pvpgn/bnetd/
34 {
35
36 extern int gameresult_destroycxx . . $ pvpgn/bnetd/gameresult_destroy(8722457eb06eb166).(t_anongame_gameresultcxx . . $ pvpgn/bnetd/t_anongame_gameresult# * gameresult)
37 {
38 if (!(gameresult))
39 {
40 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL gameresult");
41 return -1;
42 }
43
44 if ((gameresult->playerscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#players.)) xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)gameresult->players);
45 if ((gameresult->heroescxx . . $ pvpgn/bnetd/anongame_gameresult_struct#heroes.)) xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)gameresult->heroes);
46 xfreecxx . . $ `src/common/xalloc.h:51:9`!((void *)gameresult);
47
48 return 0;
49 }
50
51 extern t_anongame_gameresultcxx . . $ pvpgn/bnetd/t_anongame_gameresult# * anongame_gameresult_parsecxx . . $ pvpgn/bnetd/anongame_gameresult_parse(afad805d69d149a8).(t_packetcxx . . $ pvpgn/t_packet# const * const packet)
52 {
53 t_anongame_gameresultcxx . . $ pvpgn/bnetd/t_anongame_gameresult# * gameresult;
54 t_client_w3route_gameresult_playercxx . . $ pvpgn/t_client_w3route_gameresult_player# * player;
55 t_client_w3route_gameresult_part2cxx . . $ pvpgn/t_client_w3route_gameresult_part2# * part2;
56 t_client_w3route_gameresult_herocxx . . $ pvpgn/t_client_w3route_gameresult_hero# * hero;
57 t_client_w3route_gameresult_part3cxx . . $ pvpgn/t_client_w3route_gameresult_part3# * part3;
58
59 int counter, heroes_count;
60 unsigned expectedsize; //still without hero infos
61 unsigned int offset = 0;
62
63 int result_count = bn_byte_get(packet->ucxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#u..client_w3route_gameresultcxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#$anonymous_type_3#client_w3route_gameresult..number_of_resultscxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_11#number_of_results.);
64 expectedsize = sizeof(t_client_w3route_gameresultcxx . . $ pvpgn/t_client_w3route_gameresult#)+
65 sizeof(t_client_w3route_gameresult_playercxx . . $ pvpgn/t_client_w3route_gameresult_player#)* result_count +
66 sizeof(t_client_w3route_gameresult_part2cxx . . $ pvpgn/t_client_w3route_gameresult_part2#)+
67 sizeof(t_client_w3route_gameresult_part3cxx . . $ pvpgn/t_client_w3route_gameresult_part3#);
68
69 if (packet_get_sizecxx . . $ pvpgn/packet_get_size(e4ac9e2b4744cb4b).(packet) < expectedsize)
70 {
71 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "gameresult packet is smaller than expected");
72 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
73 }
74
75 gameresult = (t_anongame_gameresultcxx . . $ pvpgn/bnetd/t_anongame_gameresult#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_anongame_gameresult));
76
77 gameresult->playerscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#players. = (t_anongame_playercxx . . $ pvpgn/bnetd/t_anongame_player#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_anongame_player)*result_count);
78
79 gameresult->number_of_resultscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#number_of_results. = result_count;
80
81 offset += sizeof(t_client_w3route_gameresultcxx . . $ pvpgn/t_client_w3route_gameresult#);
82
83 for (counter = 0; counter < result_count; counter++)
84 {
85 player = (t_client_w3route_gameresult_playercxx . . $ pvpgn/t_client_w3route_gameresult_player# *)packet_get_raw_data_constcxx . . $ pvpgn/packet_get_raw_data_const(1f58ab00371793b4).(packet, offset);
86
87 gameresult->playerscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#players.[counter].numbercxx . . $ pvpgn/bnetd/$anonymous_type_4f6080add7ca2b3d_0#number. = bn_byte_get(player->numbercxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_12#number.);
88 gameresult->playerscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#players.[counter].resultcxx . . $ pvpgn/bnetd/$anonymous_type_4f6080add7ca2b3d_0#result. = bn_int_get(player->resultcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_12#result.);
89 gameresult->playerscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#players.[counter].racecxx . . $ pvpgn/bnetd/$anonymous_type_4f6080add7ca2b3d_0#race. = bn_int_get(player->racecxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_12#race.);
90
91 offset += sizeof(t_client_w3route_gameresult_playercxx . . $ pvpgn/t_client_w3route_gameresult_player#);
92 }
93
94 part2 = (t_client_w3route_gameresult_part2cxx . . $ pvpgn/t_client_w3route_gameresult_part2# *)packet_get_raw_data_constcxx . . $ pvpgn/packet_get_raw_data_const(1f58ab00371793b4).(packet, offset);
95
96 gameresult->unit_scorecxx . . $ pvpgn/bnetd/anongame_gameresult_struct#unit_score. = bn_int_get(part2->unit_scorecxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_13#unit_score.);
97 gameresult->heroes_scorecxx . . $ pvpgn/bnetd/anongame_gameresult_struct#heroes_score. = bn_int_get(part2->heroes_scorecxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_13#heroes_score.);
98 gameresult->resource_scorecxx . . $ pvpgn/bnetd/anongame_gameresult_struct#resource_score. = bn_int_get(part2->resource_scorecxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_13#resource_score.);
99 gameresult->units_producedcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#units_produced. = bn_int_get(part2->units_producedcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_13#units_produced.);
100 gameresult->units_killedcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#units_killed. = bn_int_get(part2->units_killedcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_13#units_killed.);
101 gameresult->buildings_producedcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#buildings_produced. = bn_int_get(part2->buildings_producedcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_13#buildings_produced.);
102 gameresult->buildings_razedcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#buildings_razed. = bn_int_get(part2->buildings_razedcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_13#buildings_razed.);
103 gameresult->largest_armycxx . . $ pvpgn/bnetd/anongame_gameresult_struct#largest_army. = bn_int_get(part2->largest_armycxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_13#largest_army.);
104 heroes_count = bn_int_get(part2->heroes_used_countcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_13#heroes_used_count.);
105 gameresult->heroes_used_countcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#heroes_used_count. = heroes_count;
106
107 offset += sizeof(t_client_w3route_gameresult_part2cxx . . $ pvpgn/t_client_w3route_gameresult_part2#);
108
109 if ((heroes_count))
110 {
111 gameresult->heroescxx . . $ pvpgn/bnetd/anongame_gameresult_struct#heroes. = (t_anongame_herocxx . . $ pvpgn/bnetd/t_anongame_hero#*)xmalloccxx . . $ `src/common/xalloc.h:43:9`!(sizeof(t_anongame_hero)*heroes_count);
112
113 if (packet_get_sizecxx . . $ pvpgn/packet_get_size(e4ac9e2b4744cb4b).(packet) < expectedsize + sizeof(t_client_w3route_gameresult_herocxx . . $ pvpgn/t_client_w3route_gameresult_hero#)*heroes_count)
114 {
115 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "gameresult packet is smaller than expected");
116 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
117 }
118
119 for (counter = 0; counter < heroes_count; counter++)
120 {
121 hero = (t_client_w3route_gameresult_herocxx . . $ pvpgn/t_client_w3route_gameresult_hero# *)packet_get_raw_data_constcxx . . $ pvpgn/packet_get_raw_data_const(1f58ab00371793b4).(packet, offset);
122
123 gameresult->heroescxx . . $ pvpgn/bnetd/anongame_gameresult_struct#heroes.[counter].levelcxx . . $ pvpgn/bnetd/$anonymous_type_4f6080add7ca2b3d_1#level. = bn_short_get(hero->levelcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_14#level.);
124 gameresult->heroescxx . . $ pvpgn/bnetd/anongame_gameresult_struct#heroes.[counter].race_and_namecxx . . $ pvpgn/bnetd/$anonymous_type_4f6080add7ca2b3d_1#race_and_name. = bn_int_get(hero->race_and_namecxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_14#race_and_name.);
125 gameresult->heroescxx . . $ pvpgn/bnetd/anongame_gameresult_struct#heroes.[counter].hero_xpcxx . . $ pvpgn/bnetd/$anonymous_type_4f6080add7ca2b3d_1#hero_xp. = bn_int_get(hero->hero_xpcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_14#hero_xp.);
126
127 offset += sizeof(t_client_w3route_gameresult_herocxx . . $ pvpgn/t_client_w3route_gameresult_hero#);
128 }
129 }
130 else
131 gameresult->heroescxx . . $ pvpgn/bnetd/anongame_gameresult_struct#heroes. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
132
133 part3 = (t_client_w3route_gameresult_part3cxx . . $ pvpgn/t_client_w3route_gameresult_part3# *)packet_get_raw_data_constcxx . . $ pvpgn/packet_get_raw_data_const(1f58ab00371793b4).(packet, offset);
134
135 gameresult->heroes_killedcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#heroes_killed. = bn_int_get(part3->heroes_killedcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#heroes_killed.);
136 gameresult->items_obtainedcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#items_obtained. = bn_int_get(part3->items_obtainedcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#items_obtained.);
137 gameresult->mercenaries_hiredcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#mercenaries_hired. = bn_int_get(part3->mercenaries_hiredcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#mercenaries_hired.);
138 gameresult->total_hero_xpcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#total_hero_xp. = bn_int_get(part3->total_hero_xpcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#total_hero_xp.);
139 gameresult->gold_minedcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#gold_mined. = bn_int_get(part3->gold_minedcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#gold_mined.);
140 gameresult->lumber_harvestedcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#lumber_harvested. = bn_int_get(part3->lumber_harvestedcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#lumber_harvested.);
141 gameresult->resources_traded_givencxx . . $ pvpgn/bnetd/anongame_gameresult_struct#resources_traded_given. = bn_int_get(part3->resources_traded_givencxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#resources_traded_given.);
142 gameresult->resources_traded_takencxx . . $ pvpgn/bnetd/anongame_gameresult_struct#resources_traded_taken. = bn_int_get(part3->resources_traded_takencxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#resources_traded_taken.);
143 gameresult->tech_percentagecxx . . $ pvpgn/bnetd/anongame_gameresult_struct#tech_percentage. = bn_int_get(part3->tech_percentagecxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#tech_percentage.);
144 gameresult->gold_lost_to_upkeepcxx . . $ pvpgn/bnetd/anongame_gameresult_struct#gold_lost_to_upkeep. = bn_int_get(part3->gold_lost_to_upkeepcxx . . $ pvpgn/$anonymous_type_37d0d0c67ba6cc0e_15#gold_lost_to_upkeep.);
145
146 return gameresult;
147 }
148
149 extern char gameresult_get_number_of_resultscxx . . $ pvpgn/bnetd/gameresult_get_number_of_results(dcc703a55377cfa1).(t_anongame_gameresultcxx . . $ pvpgn/bnetd/t_anongame_gameresult# * gameresult)
150 {
151 assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(gameresult);
152
153 return gameresult->number_of_resultscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#number_of_results.;
154 }
155
156 extern int gameresult_get_player_resultcxx . . $ pvpgn/bnetd/gameresult_get_player_result(4919fea90e2d0dd3).(t_anongame_gameresultcxx . . $ pvpgn/bnetd/t_anongame_gameresult# * gameresult, int player)
157 {
158 if (!(gameresult))
159 return -1;
160
161 if (player >= gameresult->number_of_resultscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#number_of_results.)
162 {
163 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "request for invalid player number");
164 return -1;
165 }
166
167 return gameresult->playerscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#players.[player].resultcxx . . $ pvpgn/bnetd/$anonymous_type_4f6080add7ca2b3d_0#result.;
168 }
169
170 extern int gameresult_get_player_numbercxx . . $ pvpgn/bnetd/gameresult_get_player_number(4919fea90e2d0dd3).(t_anongame_gameresultcxx . . $ pvpgn/bnetd/t_anongame_gameresult# * gameresult, int player)
171 {
172 if (!(gameresult))
173 return -1;
174
175 if (player >= gameresult->number_of_resultscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#number_of_results.)
176 {
177 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "request for invalid player number");
178 return -1;
179 }
180
181 return gameresult->playerscxx . . $ pvpgn/bnetd/anongame_gameresult_struct#players.[player].numbercxx . . $ pvpgn/bnetd/$anonymous_type_4f6080add7ca2b3d_0#number.;
182 }
183
184 }
185
186 }