| 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 | |
| 17 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 18 | #include "output.h"cxx . . $ `<file>/src/bnetd/output.h`/ |
| 19 | |
| 20 | #include <cstdio> |
| 21 | #include <cerrno> |
| 22 | #include <cstring> |
| 23 | #include <string> |
| 24 | |
| 25 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 26 | #include "common/xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/ |
| 27 | #include "common/tag.h"cxx . . $ `<file>/src/common/tag.h`/ |
| 28 | #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/ |
| 29 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 30 | |
| 31 | #include "prefs.h"cxx . . $ `<file>/src/bnetd/prefs.h`/ |
| 32 | #include "game.h"cxx . . $ `<file>/src/bnetd/game.h`/ |
| 33 | #include "channel.h"cxx . . $ `<file>/src/bnetd/channel.h`/ |
| 34 | #include "connection.h"cxx . . $ `<file>/src/bnetd/connection.h`/ |
| 35 | #include "account.h"cxx . . $ `<file>/src/bnetd/account.h`/ |
| 36 | #include "server.h"cxx . . $ `<file>/src/bnetd/server.h`/ |
| 37 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 38 | |
| 39 | namespace pvpgncxx . . $ pvpgn/ |
| 40 | { |
| 41 | |
| 42 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 43 | { |
| 44 | |
| 45 | stdcxx . . $ std/::stringcxx . . $ std/string# status_filenamecxx . . $ pvpgn/bnetd/status_filename.; |
| 46 | |
| 47 | int output_standard_writercxx . . $ pvpgn/bnetd/output_standard_writer(89bc1efcdac0ca22).(stdcxx . . $ std/::FILEcxx . . $ std/FILE# * fp); |
| 48 | |
| 49 | /* |
| 50 | * Initialisation Output * |
| 51 | */ |
| 52 | |
| 53 | extern void output_initcxx . . $ pvpgn/bnetd/output_init(49f6e7a06ebc5aa8).() |
| 54 | { |
| 55 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "initializing output file"); |
| 56 | |
| 57 | if (prefs_get_XML_status_outputcxx . . $ pvpgn/bnetd/prefs_get_XML_status_output(b126dc7c1de90089).()) |
| 58 | status_filenamecxx . . $ pvpgn/bnetd/status_filename. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). fmtcxx . . $ fmt/::formatcxx . . $ fmt/format(9dfaebe7421e19ae).("{}/{}"cxx . . $ fmt/BasicCStringRef#BasicCStringRef(88376428bb603c08)., prefs_get_outputdircxx . . $ pvpgn/bnetd/prefs_get_outputdir(33a1f659e94feb42).(), "server.xml"); |
| 59 | else |
| 60 | status_filenamecxx . . $ pvpgn/bnetd/status_filename. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). fmtcxx . . $ fmt/::formatcxx . . $ fmt/format(9dfaebe7421e19ae).("{}/{}"cxx . . $ fmt/BasicCStringRef#BasicCStringRef(88376428bb603c08)., prefs_get_outputdircxx . . $ pvpgn/bnetd/prefs_get_outputdir(33a1f659e94feb42).(), "server.dat"); |
| 61 | |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Write Functions * |
| 67 | */ |
| 68 | |
| 69 | static int _glist_cb_xmlcxx . . $ pvpgn/bnetd/_glist_cb_xml(7b7c187348591887).(t_gamecxx . . $ pvpgn/bnetd/t_game# *game, void *data) |
| 70 | { |
| 71 | char clienttag_str[5]; |
| 72 | |
| 73 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).((stdcxx . . $ std/::FILEcxx . . $ std/FILE#*)data, "\t\t<game><id>%u</id><name>%s</name><clienttag>%s</clienttag></game>\n", game_get_idcxx . . $ pvpgn/bnetd/game_get_id(d7b85b5cd2056731).(game), game_get_namecxx . . $ pvpgn/bnetd/game_get_name(743fb6d1aa411c4e).(game), tag_uint_to_strcxx . . $ pvpgn/tag_uint_to_str(d172961b102a89a5).(clienttag_str, game_get_clienttagcxx . . $ pvpgn/bnetd/game_get_clienttag(d7b85b5cd2056731).(game))); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static int _glist_cb_simplecxx . . $ pvpgn/bnetd/_glist_cb_simple(7b7c187348591887).(t_gamecxx . . $ pvpgn/bnetd/t_game# *game, void *data) |
| 79 | { |
| 80 | static int number; |
| 81 | char clienttag_str[5]; |
| 82 | |
| 83 | if (!data) { |
| 84 | number = 1; |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).((stdcxx . . $ std/::FILEcxx . . $ std/FILE#*)data, "game%d=%s,%u,%s\n", number, tag_uint_to_strcxx . . $ pvpgn/tag_uint_to_str(d172961b102a89a5).(clienttag_str, game_get_clienttagcxx . . $ pvpgn/bnetd/game_get_clienttag(d7b85b5cd2056731).(game)), game_get_idcxx . . $ pvpgn/bnetd/game_get_id(d7b85b5cd2056731).(game), game_get_namecxx . . $ pvpgn/bnetd/game_get_name(743fb6d1aa411c4e).(game)); |
| 89 | number++; |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | int output_standard_writercxx . . $ pvpgn/bnetd/output_standard_writer(89bc1efcdac0ca22).(stdcxx . . $ std/::FILEcxx . . $ std/FILE# * fp) |
| 95 | { |
| 96 | t_elemcxx . . $ pvpgn/t_elem# const *curr; |
| 97 | t_connectioncxx . . $ pvpgn/bnetd/t_connection# *conn; |
| 98 | t_channelcxx . . $ pvpgn/bnetd/t_channel# const *channel; |
| 99 | t_gamecxx . . $ pvpgn/bnetd/t_game# *game; |
| 100 | |
| 101 | char const *channel_name; |
| 102 | int number; |
| 103 | char clienttag_str[5]; |
| 104 | int uptime = server_get_uptimecxx . . $ pvpgn/bnetd/server_get_uptime(db52760e79bf9054).(); |
| 105 | |
| 106 | |
| 107 | if (prefs_get_XML_status_outputcxx . . $ pvpgn/bnetd/prefs_get_XML_status_output(b126dc7c1de90089).()) |
| 108 | { |
| 109 | int seconds; |
| 110 | int minutes; |
| 111 | int hours; |
| 112 | int days; |
| 113 | |
| 114 | days = (uptime / (60 * 60 * 24)); |
| 115 | hours = (uptime / (60 * 60)) % 24; |
| 116 | minutes = (uptime / 60) % 60; |
| 117 | seconds = uptime % 60; |
| 118 | |
| 119 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "<?xml version=\"1.0\"?>\n<status>\n"); |
| 120 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<Version>%s</Version>\n", PVPGN_VERSIONcxx . . $ `src/common/version.h:23:9`!); |
| 121 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<Uptime>\n"); |
| 122 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t\t<Days>%d</Days>\n", days); |
| 123 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t\t<Hours>%d</Hours>\n", hours); |
| 124 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t\t<Minutes>%d</Minutes>\n", minutes); |
| 125 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t\t<Seconds>%d</Seconds>\n", seconds); |
| 126 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t</Uptime>\n"); |
| 127 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<Users>\n"); |
| 128 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<Number>%d</Number>\n", connlist_login_get_lengthcxx . . $ pvpgn/bnetd/connlist_login_get_length(db52760e79bf9054).()); |
| 129 | |
| 130 | LIST_TRAVERSE_CONSTcxx . . $ `src/common/list.h:95:9`!(connlist(), curr) |
| 131 | { |
| 132 | conn = (t_connectioncxx . . $ pvpgn/bnetd/t_connection#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr); |
| 133 | if (conn_get_accountcxx . . $ pvpgn/bnetd/conn_get_account(8df8b24b7c17a7f3).(conn)) |
| 134 | { |
| 135 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<user><name>%s</name><clienttag>%s</clienttag><version>%s</version>", conn_get_usernamecxx . . $ `src/bnetd/connection.h:361:9`!(conn), tag_uint_to_strcxx . . $ pvpgn/tag_uint_to_str(d172961b102a89a5).(clienttag_str, conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(conn)), conn_get_clientvercxx . . $ pvpgn/bnetd/conn_get_clientver(c99dbccf638f5c6).(conn)); |
| 136 | |
| 137 | const char * country = conn_get_countrycxx . . $ pvpgn/bnetd/conn_get_country(c99dbccf638f5c6).(conn); |
| 138 | if (!country) country = "-"; |
| 139 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "<country>%s</country>", country); |
| 140 | |
| 141 | if ((game = conn_get_gamecxx . . $ pvpgn/bnetd/conn_get_game(692151a8f99bc3ef).(conn))) |
| 142 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "<gameid>%u</gameid>", game_get_idcxx . . $ pvpgn/bnetd/game_get_id(d7b85b5cd2056731).(game)); |
| 143 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "</user>\n"); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t</Users>\n"); |
| 148 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<Games>\n"); |
| 149 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<Number>%d</Number>\n", gamelist_get_lengthcxx . . $ pvpgn/bnetd/gamelist_get_length(b126dc7c1de90089).()); |
| 150 | |
| 151 | gamelist_traversecxx . . $ pvpgn/bnetd/gamelist_traverse(c7b2023d64399da8).(_glist_cb_xmlcxx . . $ pvpgn/bnetd/_glist_cb_xml(7b7c187348591887)., fp, gamelist_source_nonecxx . . $ pvpgn/bnetd/gamelist_source_none.); |
| 152 | |
| 153 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t</Games>\n"); |
| 154 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<Channels>\n"); |
| 155 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<Number>%d</Number>\n", channellist_get_lengthcxx . . $ pvpgn/bnetd/channellist_get_length(b126dc7c1de90089).()); |
| 156 | |
| 157 | LIST_TRAVERSE_CONSTcxx . . $ `src/common/list.h:95:9`!(channellist(), curr) |
| 158 | { |
| 159 | channel = (t_channelcxx . . $ pvpgn/bnetd/t_channel#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr); |
| 160 | channel_name = channel_get_namecxx . . $ pvpgn/bnetd/channel_get_name(7800017c14723985).(channel); |
| 161 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t<channel>%s</channel>\n", channel_name); |
| 162 | } |
| 163 | |
| 164 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\t\t</Channels>\n"); |
| 165 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "</status>\n"); |
| 166 | return 0; |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "[STATUS]\nVersion=%s\nUptime=%s\nGames=%d\nUsers=%d\nChannels=%d\nUserAccounts=%d\n", PVPGN_VERSIONcxx . . $ `src/common/version.h:23:9`!, seconds_to_timestrcxx . . $ pvpgn/seconds_to_timestr(81a3ae90da26a711).(uptime), gamelist_get_lengthcxx . . $ pvpgn/bnetd/gamelist_get_length(b126dc7c1de90089).(), connlist_login_get_lengthcxx . . $ pvpgn/bnetd/connlist_login_get_length(db52760e79bf9054).(), channellist_get_lengthcxx . . $ pvpgn/bnetd/channellist_get_length(b126dc7c1de90089).(), accountlist_get_lengthcxx . . $ pvpgn/bnetd/accountlist_get_length(db52760e79bf9054).()); // Status |
| 171 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "[CHANNELS]\n"); |
| 172 | number = 1; |
| 173 | LIST_TRAVERSE_CONSTcxx . . $ `src/common/list.h:95:9`!(channellist(), curr) |
| 174 | { |
| 175 | channel = (t_channelcxx . . $ pvpgn/bnetd/t_channel#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr); |
| 176 | channel_name = channel_get_namecxx . . $ pvpgn/bnetd/channel_get_name(7800017c14723985).(channel); |
| 177 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "channel%d=%s\n", number, channel_name); |
| 178 | number++; |
| 179 | } |
| 180 | |
| 181 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "[GAMES]\n"); |
| 182 | _glist_cb_simplecxx . . $ pvpgn/bnetd/_glist_cb_simple(7b7c187348591887).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); /* init number */ |
| 183 | gamelist_traversecxx . . $ pvpgn/bnetd/gamelist_traverse(c7b2023d64399da8).(_glist_cb_simplecxx . . $ pvpgn/bnetd/_glist_cb_simple(7b7c187348591887)., fp, gamelist_source_nonecxx . . $ pvpgn/bnetd/gamelist_source_none.); |
| 184 | |
| 185 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "[USERS]\n"); |
| 186 | number = 1; |
| 187 | LIST_TRAVERSE_CONSTcxx . . $ `src/common/list.h:95:9`!(connlist(), curr) |
| 188 | { |
| 189 | conn = (t_connectioncxx . . $ pvpgn/bnetd/t_connection#*)elem_get_datacxx . . $ pvpgn/elem_get_data(317ff0e7f02bf2b).(curr); |
| 190 | if (conn_get_accountcxx . . $ pvpgn/bnetd/conn_get_account(8df8b24b7c17a7f3).(conn)) |
| 191 | { |
| 192 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "user%d=%s,%s,%s", number, tag_uint_to_strcxx . . $ pvpgn/tag_uint_to_str(d172961b102a89a5).(clienttag_str, conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(conn)), conn_get_usernamecxx . . $ `src/bnetd/connection.h:361:9`!(conn), conn_get_clientvercxx . . $ pvpgn/bnetd/conn_get_clientver(c99dbccf638f5c6).(conn)); |
| 193 | |
| 194 | const char * country = conn_get_countrycxx . . $ pvpgn/bnetd/conn_get_country(c99dbccf638f5c6).(conn); |
| 195 | if (!country) country = "-"; |
| 196 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, ",%s", country); |
| 197 | |
| 198 | if ((game = conn_get_gamecxx . . $ pvpgn/bnetd/conn_get_game(692151a8f99bc3ef).(conn))) |
| 199 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, ",%u", game_get_idcxx . . $ pvpgn/bnetd/game_get_id(d7b85b5cd2056731).(game)); |
| 200 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "\n"); |
| 201 | number++; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | extern int output_write_to_filecxx . . $ pvpgn/bnetd/output_write_to_file(b126dc7c1de90089).() |
| 210 | { |
| 211 | if (status_filenamecxx . . $ pvpgn/bnetd/status_filename..emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 212 | { |
| 213 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got empty filename"); |
| 214 | return -1; |
| 215 | } |
| 216 | |
| 217 | stdcxx . . $ std/::FILEcxx . . $ std/FILE#* fp = stdcxx . . $ std/::fopencxx . . $ std/fopen(82ec0787cd37e0a3).(status_filenamecxx . . $ pvpgn/bnetd/status_filename..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), "w"); |
| 218 | if (!fp) |
| 219 | { |
| 220 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not open file \"{}\" for writing (std::fopen: {})", status_filenamecxx . . $ pvpgn/bnetd/status_filename., stdcxx . . $ std/::strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 221 | return -1; |
| 222 | } |
| 223 | |
| 224 | output_standard_writercxx . . $ pvpgn/bnetd/output_standard_writer(89bc1efcdac0ca22).(fp); |
| 225 | stdcxx . . $ std/::fclosecxx . . $ std/fclose(89bc1efcdac0ca22).(fp); |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | } |
| 231 | |
| 232 | } |