| 1 | /* |
| 2 | * Copyright (C) 2014 HarpyWar ([email protected]) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 19 | |
| 20 | #include <algorithm> |
| 21 | #include <cctype> |
| 22 | #include <cerrno> |
| 23 | #include <cmath> |
| 24 | #include <cstdlib> |
| 25 | #include <cstring> |
| 26 | #include <stdexcept> |
| 27 | #include <string> |
| 28 | |
| 29 | #include "compat/strcasecmp.h"cxx . . $ `<file>/src/compat/strcasecmp.h`/ |
| 30 | #include "compat/pdir.h"cxx . . $ `<file>/src/compat/pdir.h`/ |
| 31 | #include "compat/mkdir.h"cxx . . $ `<file>/src/compat/mkdir.h`/ |
| 32 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 33 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 34 | #include "common/xstring.h"cxx . . $ `<file>/src/common/xstring.h`/ |
| 35 | |
| 36 | #include "connection.h"cxx . . $ `<file>/src/bnetd/connection.h`/ |
| 37 | #include "message.h"cxx . . $ `<file>/src/bnetd/message.h`/ |
| 38 | #include "account.h"cxx . . $ `<file>/src/bnetd/account.h`/ |
| 39 | #include "account_wrap.h"cxx . . $ `<file>/src/bnetd/account_wrap.h`/ |
| 40 | #include "command_groups.h"cxx . . $ `<file>/src/bnetd/command_groups.h`/ |
| 41 | #include "command.h"cxx . . $ `<file>/src/bnetd/command.h`/ |
| 42 | #include "prefs.h"cxx . . $ `<file>/src/bnetd/prefs.h`/ |
| 43 | #include "helpfile.h"cxx . . $ `<file>/src/bnetd/helpfile.h`/ |
| 44 | #include "i18n.h"cxx . . $ `<file>/src/bnetd/i18n.h`/ |
| 45 | #include "userlog.h"cxx . . $ `<file>/src/bnetd/userlog.h`/ |
| 46 | |
| 47 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 48 | |
| 49 | |
| 50 | namespace pvpgncxx . . $ pvpgn/ |
| 51 | { |
| 52 | |
| 53 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 54 | { |
| 55 | // max output lines to send user from /log command result |
| 56 | static const int userlog_max_output_linescxx . . $ pvpgn/bnetd/userlog_max_output_lines. = 50; |
| 57 | |
| 58 | static stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> userlog_commandscxx . . $ pvpgn/bnetd/userlog_commands.; |
| 59 | |
| 60 | extern void userlog_initcxx . . $ pvpgn/bnetd/userlog_init(49f6e7a06ebc5aa8).() |
| 61 | { |
| 62 | char * temp; |
| 63 | char const * tok; |
| 64 | |
| 65 | userlog_commandscxx . . $ pvpgn/bnetd/userlog_commands..clearcxx . . $ std/vector#clear(ced63f7c635d850d).(); |
| 66 | |
| 67 | // fill command list that must be logged |
| 68 | if (const char * cmdlist = prefs_get_log_command_listcxx . . $ pvpgn/bnetd/prefs_get_log_command_list(33a1f659e94feb42).()) |
| 69 | { |
| 70 | temp = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(cmdlist); |
| 71 | tok = stdcxx . . $ std/::strtok(temp, ","); /* std::strtok modifies the string it is passed */ |
| 72 | while (tok) { |
| 73 | userlog_commandscxx . . $ pvpgn/bnetd/userlog_commands..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(tokcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 74 | tok = stdcxx . . $ std/::strtok(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, ","); |
| 75 | } |
| 76 | xfreecxx . . $ `src/common/xalloc.h:51:9`!(temp); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // add new line at the end of log file |
| 81 | extern void userlog_appendcxx . . $ pvpgn/bnetd/userlog_append(d148c2d7cf6cba0).(t_accountcxx . . $ pvpgn/bnetd/t_account# * account, const char * text) |
| 82 | { |
| 83 | // is logging enabled? |
| 84 | if (!prefs_get_log_commandscxx . . $ pvpgn/bnetd/prefs_get_log_commands(db52760e79bf9054).()) |
| 85 | return; |
| 86 | |
| 87 | unsigned int groups = 0; |
| 88 | const char * cglist = prefs_get_log_command_groupscxx . . $ pvpgn/bnetd/prefs_get_log_command_groups(33a1f659e94feb42).(); |
| 89 | size_t cglistlen = stdcxx . . $ std/::strlen(cglist); |
| 90 | |
| 91 | // convert string groups from config to integer |
| 92 | for (stdcxx . . $ std/::size_tcxx . . $ std/size_t# i = 0; i < cglistlen; i++) |
| 93 | { |
| 94 | if (cglist[i] == '1') groups |= 1; |
| 95 | else if (cglist[i] == '2') groups |= 2; |
| 96 | else if (cglist[i] == '3') groups |= 4; |
| 97 | else if (cglist[i] == '4') groups |= 8; |
| 98 | else if (cglist[i] == '5') groups |= 16; |
| 99 | else if (cglist[i] == '6') groups |= 32; |
| 100 | else if (cglist[i] == '7') groups |= 64; |
| 101 | else if (cglist[i] == '8') groups |= 128; |
| 102 | } |
| 103 | |
| 104 | // log only commands for admins/operators and users in "groups" defined in config |
| 105 | if (!account_is_operator_or_admincxx . . $ pvpgn/bnetd/account_is_operator_or_admin(4b12bc5edcfaeac7).(account, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) && !(account_get_command_groupscxx . . $ pvpgn/bnetd/account_get_command_groups(c7ab9369555c44b8).(account) & groups)) |
| 106 | return; |
| 107 | |
| 108 | bool is_cmd_found = false; |
| 109 | |
| 110 | // if command list empty then log all commands |
| 111 | if (userlog_commandscxx . . $ pvpgn/bnetd/userlog_commands..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() == 0) |
| 112 | is_cmd_found = true; |
| 113 | else |
| 114 | { |
| 115 | // get command name |
| 116 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> args = split_commandcxx . . $ pvpgn/bnetd/split_command(36641c1b5e9c088b).(text, 0); |
| 117 | stdcxx . . $ std/::stringcxx . . $ std/string# cmd = argscxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]; |
| 118 | |
| 119 | // find command in defined command list |
| 120 | for (stdcxx . . $ std/::vectorcxx . . $ std/vector#<std::string>::iteratorcxx . . $ std/vector#iterator# it = userlog_commandscxx . . $ pvpgn/bnetd/userlog_commands..begincxx . . $ std/vector#begin(55a6de06420d4903).(); it !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). userlog_commandscxx . . $ pvpgn/bnetd/userlog_commands..endcxx . . $ std/vector#end(55a6de06420d4903).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).it) { |
| 121 | if (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).it ==cxx . . $ std/`operator==`(5ea818b58063a774). cmd) |
| 122 | { |
| 123 | is_cmd_found = true; |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | if (!is_cmd_found) |
| 129 | return; |
| 130 | |
| 131 | // get time string |
| 132 | char time_string[USEREVENT_TIME_MAXLENcxx . . $ USEREVENT_TIME_MAXLEN.]; |
| 133 | struct stdcxx . . $ std/::tmcxx . . $ tm# * tmnow; |
| 134 | stdcxx . . $ std/::time_tcxx . . $ std/time_t# now; |
| 135 | |
| 136 | stdcxx . . $ std/::timecxx . . $ std/time(a7cd306b2d326b09).(&now); |
| 137 | if (!(tmnow = stdcxx . . $ std/::localtimecxx . . $ std/localtime(7d91c9e5f6bb884b).(&now))) |
| 138 | stdcxx . . $ std/::strcpy(time_string, "?"); |
| 139 | else |
| 140 | stdcxx . . $ std/::strftimecxx . . $ std/strftime(689617e6f2fd1a9a).(time_string, USEREVENT_TIME_MAXLENcxx . . $ USEREVENT_TIME_MAXLEN., USEREVENT_TIME_FORMATcxx . . $ `src/common/setup_before.h:91:9`!, tmnow); |
| 141 | |
| 142 | |
| 143 | stdcxx . . $ std/::stringcxx . . $ std/string# filename = userlog_filenamecxx . . $ pvpgn/bnetd/userlog_filename(85c6895acdb29f7).(account_get_namecxx . . $ `src/bnetd/account.h:115:10`!(account), true); |
| 144 | |
| 145 | if (FILEcxx . . $ FILE# *fp = fopen(filename.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), "a")) |
| 146 | { |
| 147 | // append date and text |
| 148 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(fp, "[%s] %s\n", time_string, text); |
| 149 | stdcxx . . $ std/::fclosecxx . . $ std/fclose(89bc1efcdac0ca22).(fp); |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | ERROR1cxx . . $ `src/common/eventlog.h:74:9`!("could not write into user log file \"{}\"", filename); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // read "count" lines from the end starting from "startline" |
| 158 | extern stdcxx . . $ std/::mapcxx . . $ std/map#<long, char*> userlog_readcxx . . $ pvpgn/bnetd/userlog_read(39fb986d3c10c98f).(const char* username, long startline, const char* search_substr) |
| 159 | { |
| 160 | if (!username) |
| 161 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#("username is a nullptr"); |
| 162 | |
| 163 | FILEcxx . . $ FILE#* fp = stdcxx . . $ std/::fopencxx . . $ std/fopen(82ec0787cd37e0a3).(userlog_filenamecxx . . $ pvpgn/bnetd/userlog_filename(85c6895acdb29f7).(username).c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), "r"); |
| 164 | if (!fp) |
| 165 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#("Could not open userlog"); |
| 166 | |
| 167 | // set position to the end of file |
| 168 | stdcxx . . $ std/::fseekcxx . . $ std/fseek(543fae30d249f6b1).(fp, 0, SEEK_ENDcxx . . $ `<external>/232824719582829767/stdio.h:112:9`!); |
| 169 | |
| 170 | long pos = stdcxx . . $ std/::ftellcxx . . $ std/ftell(1dcafcd8ef4c6e6c).(fp); |
| 171 | int c = {}, prev_c = {}; |
| 172 | stdcxx . . $ std/::mapcxx . . $ std/map#<long, char*> linescxx . . $ std/map#map(49f6e7a06ebc5aa8).; |
| 173 | long linecount = 0; |
| 174 | char line[MAX_MESSAGE_LENcxx . . $ MAX_MESSAGE_LEN. + 1] = {}; |
| 175 | int linepos = 0; |
| 176 | |
| 177 | // read file in reverse, byte by byte |
| 178 | do |
| 179 | { |
| 180 | pos--; |
| 181 | stdcxx . . $ std/::fseekcxx . . $ std/fseek(543fae30d249f6b1).(fp, pos, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!); |
| 182 | c = stdcxx . . $ std/::fgetccxx . . $ std/fgetc(89bc1efcdac0ca22).(fp); |
| 183 | |
| 184 | // add char into line array |
| 185 | if (c != '\n') |
| 186 | line[linepos] = c; |
| 187 | |
| 188 | // end of line (or start of file) |
| 189 | if ((c == '\n' && c != prev_c) || pos == -1) |
| 190 | { |
| 191 | // hack for large lines (instead we will receive cut line without start symbols) |
| 192 | if (linepos == MAX_MESSAGE_LENcxx . . $ MAX_MESSAGE_LEN.) |
| 193 | { |
| 194 | // return carriage to read whole line to(from) start |
| 195 | pos = pos + MAX_MESSAGE_LENcxx . . $ MAX_MESSAGE_LEN.; |
| 196 | linepos = 0; |
| 197 | } |
| 198 | |
| 199 | if (linepos > 0) |
| 200 | { |
| 201 | line[linepos] = '\0'; // set end of string |
| 202 | strreversecxx . . $ pvpgn/strreverse(7a9722d75b371431).(line); |
| 203 | |
| 204 | linepos = 0; // reset position inside line |
| 205 | |
| 206 | linecount++; |
| 207 | if (linecount >= startline) |
| 208 | { |
| 209 | if (search_substr && stdcxx . . $ std/::strlen(search_substr) > 0) |
| 210 | { |
| 211 | if (find_substrcxx . . $ pvpgn/find_substr(9efbdc942cde3d3d).(line, search_substr)) |
| 212 | lines[cxx . . $ std/map#`operator[]`(bbd415b616967878).linecount] = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(line); |
| 213 | } |
| 214 | else |
| 215 | { |
| 216 | lines[cxx . . $ std/map#`operator[]`(bbd415b616967878).linecount] = xstrdupcxx . . $ `src/common/xalloc.h:49:9`!(line); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | // limitation of results |
| 221 | if (lines.sizecxx . . $ std/map#size(a08d7b23eb6940f6).() >= userlog_max_output_linescxx . . $ pvpgn/bnetd/userlog_max_output_lines.) |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | prev_c = c; |
| 226 | if (c != '\n' && linepos < MAX_MESSAGE_LENcxx . . $ MAX_MESSAGE_LEN.) |
| 227 | linepos++; |
| 228 | |
| 229 | } while (c != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`!); |
| 230 | |
| 231 | stdcxx . . $ std/::fclosecxx . . $ std/fclose(89bc1efcdac0ca22).(fp); |
| 232 | |
| 233 | return linescxx . . $ std/map#map(3d8f9cfb6064bed1).; |
| 234 | } |
| 235 | |
| 236 | // search "substring" in user log file from the end starting from "startline" and return "count" results |
| 237 | extern stdcxx . . $ std/::mapcxx . . $ std/map#<long, char*> userlog_find_textcxx . . $ pvpgn/bnetd/userlog_find_text(f0cb34c8d8abde56).(const char * username, const char * search_substr, long startline) |
| 238 | { |
| 239 | return userlog_readcxx . . $ pvpgn/bnetd/userlog_read(39fb986d3c10c98f).(username, startline, search_substr); |
| 240 | } |
| 241 | |
| 242 | // return full path for user log filename |
| 243 | // if (force_create_path == true) then create dirs in path if not exist |
| 244 | extern stdcxx . . $ std/::stringcxx . . $ std/string# userlog_filenamecxx . . $ pvpgn/bnetd/userlog_filename(85c6895acdb29f7).(const char * username, bool force_create_path) |
| 245 | { |
| 246 | // lowercase username |
| 247 | stdcxx . . $ std/::stringcxx . . $ std/string# lusername = stdcxx . . $ std/::stringcxx . . $ std/string#(username); |
| 248 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(lusername.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), lusername.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), lusername.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), ::tolower); |
| 249 | // get first 3 symbols of account and use it in path |
| 250 | // it will improve performance with large count of files |
| 251 | stdcxx . . $ std/::stringcxx . . $ std/string# dir_prefix = lusername.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(0, 3); |
| 252 | |
| 253 | stdcxx . . $ std/::stringcxx . . $ std/string# filepath = fmtcxx . . $ fmt/::formatcxx . . $ fmt/format(9dfaebe7421e19ae).("{}/{}"cxx . . $ fmt/BasicCStringRef#BasicCStringRef(88376428bb603c08)., prefs_get_userlogdircxx . . $ pvpgn/bnetd/prefs_get_userlogdir(33a1f659e94feb42).(), dir_prefix); |
| 254 | // create directories in path |
| 255 | if (force_create_path) |
| 256 | { |
| 257 | struct stat statbuf; |
| 258 | // create inside user dir |
| 259 | if (stat(filepath.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), &statbuf) == -1) |
| 260 | { |
| 261 | p_mkdircxx . . $ `src/compat/mkdir.h:51:11`!(filepath.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), S_IRWXUcxx . . $ `<external>/531885356569766532/stat.h:172:9`! | S_IRWXGcxx . . $ `<external>/531885356569766532/stat.h:184:9`! | S_IRWXOcxx . . $ `<external>/531885356569766532/stat.h:190:9`!); |
| 262 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_infocxx . . $ pvpgn/eventlog_level_info., __FUNCTION__, "created user directory: {}", filepath); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | filepath +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). fmtcxx . . $ fmt/::formatcxx . . $ fmt/format(9dfaebe7421e19ae).("/{}.log"cxx . . $ fmt/BasicCStringRef#BasicCStringRef(88376428bb603c08)., lusername.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 267 | |
| 268 | return filepathcxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 269 | } |
| 270 | |
| 271 | // handle command |
| 272 | // /log read user startline |
| 273 | // /log find user substr startline |
| 274 | extern int handle_log_commandcxx . . $ pvpgn/bnetd/handle_log_command(2e9022cda97b266d).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# * c, char const *text) |
| 275 | { |
| 276 | const char *subcommand, *username; |
| 277 | long startline = 0; |
| 278 | stdcxx . . $ std/::mapcxx . . $ std/map#<long, char*> linescxx . . $ std/map#map(49f6e7a06ebc5aa8).; |
| 279 | |
| 280 | // split command args |
| 281 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> args = split_commandcxx . . $ pvpgn/bnetd/split_command(36641c1b5e9c088b).(text, 4); |
| 282 | if (args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1].emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).() || args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).2].emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).() |
| 283 | || (args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1].atcxx . . $ std/__cxx11/basic_string#at(7b73c3179b3cb3ad).(0) != 'r' && args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1].atcxx . . $ std/__cxx11/basic_string#at(7b73c3179b3cb3ad).(0) != 'f')) // check start symbols for subcommand |
| 284 | { |
| 285 | describe_commandcxx . . $ pvpgn/bnetd/describe_command(2e9022cda97b266d).(c, args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 286 | return -1; |
| 287 | } |
| 288 | subcommand = args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(); // sub command |
| 289 | username = args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).2].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(); // username |
| 290 | |
| 291 | if (!accountlist_find_accountcxx . . $ pvpgn/bnetd/accountlist_find_account(db6f5ebdea1fa12b).(username)) |
| 292 | { |
| 293 | message_send_textcxx . . $ pvpgn/bnetd/message_send_text(6288036871507e5c).(c, message_type_errorcxx . . $ pvpgn/bnetd/message_type_error., c, localizecxx . . $ `src/bnetd/i18n.h:73:11`!(c, "Invalid user.")); |
| 294 | return -1; |
| 295 | } |
| 296 | |
| 297 | stdcxx . . $ std/::stringcxx . . $ std/string# title = localizecxx . . $ `src/bnetd/i18n.h:73:11`!(c, "{}'s log output", username); |
| 298 | // read |
| 299 | if (subcommand[0] == 'r') |
| 300 | { |
| 301 | if (!args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).3].emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 302 | startline = atoi(args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).3].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 303 | |
| 304 | try |
| 305 | { |
| 306 | lines =cxx . . $ std/map#`operator=`(304b443dccc1907e). userlog_readcxx . . $ pvpgn/bnetd/userlog_read(39fb986d3c10c98f).(username, startline); |
| 307 | } |
| 308 | catch (...) |
| 309 | { |
| 310 | message_send_textcxx . . $ pvpgn/bnetd/message_send_text(61daf7e3ba1862c4).(c, message_type_errorcxx . . $ pvpgn/bnetd/message_type_error., c, "Could not read user log"); |
| 311 | return 0; |
| 312 | } |
| 313 | } |
| 314 | // find |
| 315 | else if (subcommand[0] == 'f') |
| 316 | { |
| 317 | if (args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).3].emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 318 | { |
| 319 | describe_commandcxx . . $ pvpgn/bnetd/describe_command(2e9022cda97b266d).(c, args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 320 | return -1; |
| 321 | } |
| 322 | const char * search = args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).3].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(); |
| 323 | title +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). localizecxx . . $ `src/bnetd/i18n.h:73:11`!(c, " by occurrence \"{}\"", search); |
| 324 | |
| 325 | if (!args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).4].emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 326 | startline = atoi(args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).4].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 327 | |
| 328 | lines =cxx . . $ std/map#`operator=`(304b443dccc1907e). userlog_find_textcxx . . $ pvpgn/bnetd/userlog_find_text(f0cb34c8d8abde56).(username, search, startline); |
| 329 | } |
| 330 | |
| 331 | title +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). ":"; |
| 332 | message_send_textcxx . . $ pvpgn/bnetd/message_send_text(6288036871507e5c).(c, message_type_infocxx . . $ pvpgn/bnetd/message_type_info., c, titlecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).); |
| 333 | |
| 334 | int linelen = 0; |
| 335 | int paddedlen = 0; |
| 336 | stdcxx . . $ std/::stringcxx . . $ std/string# linenumcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 337 | |
| 338 | // send each log line to user |
| 339 | for (stdcxx . . $ std/::mapcxx . . $ std/map#<long, char*>::reverse_iteratorcxx . . $ std/map#reverse_iterator# it = lines.rbegincxx . . $ std/map#rbegin(58dac208a2e4e5b4).(); it !=cxx . . $ std/`operator!=`(c2ad8cf295ccec45). lines.rendcxx . . $ std/map#rend(58dac208a2e4e5b4).(); ++cxx . . $ std/reverse_iterator#operator++(b4fad7494eaaab68).it) |
| 340 | { |
| 341 | int linelen = floor(log10(static_cast<double>(abs(it->cxx . . $ std/reverse_iterator#`operator->`(a68f0626e749d9f6).firstcxx . . $ std/pair#first.)))) + 1; // get length of integer (line number) |
| 342 | if (linelen > paddedlen) |
| 343 | paddedlen = linelen; |
| 344 | |
| 345 | linenum =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). std_to_stringcxx . . $ pvpgn/std_to_string(23b83986b497e4d5).(it->cxx . . $ std/reverse_iterator#`operator->`(a68f0626e749d9f6).firstcxx . . $ std/pair#first.); |
| 346 | // pad left to max line length |
| 347 | linenum.insertcxx . . $ std/__cxx11/basic_string#insert(dd298c44d615e6bc).(linenumcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), paddedlen - linenum.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).(), '0'); |
| 348 | |
| 349 | message_send_textcxx . . $ pvpgn/bnetd/message_send_text(6288036871507e5c).(c, message_type_infocxx . . $ pvpgn/bnetd/message_type_info., c, linenum +cxx . . $ std/operator+(40fc1db9226233c6). ": " +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/::stringcxx . . $ std/string#(it->cxx . . $ std/reverse_iterator#`operator->`(a68f0626e749d9f6).secondcxx . . $ std/pair#second.)); |
| 350 | } |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | |
| 356 | } |
| 357 | } |