Merge pull request #254 from RElesgoe/master
Fix memory leaks and compiler warnings
This commit is contained in:
commit
eb8a2754f8
32 changed files with 141 additions and 123 deletions
src
bnetd
account_wrap.cppanongame.cppconnection.hgame.cpphandle_bnet.cpphandle_wol.cpphandle_wol_gameres.cppi18n.cppicons.cppmessage.cppserver.cpptournament.huserlog.cppversioncheck.cppversioncheck.h
client
common
fdwatch.cppfdwatch_epoll.cppfdwatch_kqueue.cppfdwatch_poll.cppfdwatch_select.cppsetup_before.htag.cpp
compat
d2cs
d2dbs
|
@ -1685,7 +1685,7 @@ namespace pvpgn
|
|||
char tempname[32];
|
||||
int name_len;
|
||||
|
||||
for (auto i = 0; i < list_len; i++, next_char++)
|
||||
for (std::size_t i = 0; i < list_len; i++, next_char++)
|
||||
{
|
||||
if (*next_char == ',')
|
||||
{
|
||||
|
|
|
@ -914,7 +914,6 @@ namespace pvpgn
|
|||
static int _anongame_search_found(int queue)
|
||||
{
|
||||
t_packet *rpacket;
|
||||
t_anongameinfo *info;
|
||||
t_anongame *a;
|
||||
int i, j;
|
||||
t_saf_pt2 *pt2;
|
||||
|
@ -938,9 +937,9 @@ namespace pvpgn
|
|||
addr_destroy(routeraddr);
|
||||
}
|
||||
|
||||
info = anongameinfo_create(_anongame_totalplayers(queue));
|
||||
|
||||
if (!info) {
|
||||
t_anongameinfo* const info = anongameinfo_create(_anongame_totalplayers(queue));
|
||||
if (!info)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "anongameinfo_create failed");
|
||||
return -1;
|
||||
}
|
||||
|
@ -956,10 +955,13 @@ namespace pvpgn
|
|||
bn_byte_set(&pt2->unknown3, 2);
|
||||
|
||||
/* send found packet to each of the players */
|
||||
for (i = 0; i < players[queue]; i++) {
|
||||
if (!(a = conn_get_anongame(player[queue][i]))) {
|
||||
for (i = 0; i < players[queue]; i++)
|
||||
{
|
||||
if (!(a = conn_get_anongame(player[queue][i])))
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "no anongame struct for queued player");
|
||||
xfree(pt2);
|
||||
anongameinfo_destroy(info);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -973,6 +975,7 @@ namespace pvpgn
|
|||
|
||||
if (!(rpacket = packet_create(packet_class_bnet))) {
|
||||
xfree(pt2);
|
||||
anongameinfo_destroy(info);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1012,6 +1015,8 @@ namespace pvpgn
|
|||
/* clear queue */
|
||||
players[queue] = 0;
|
||||
xfree(pt2);
|
||||
anongameinfo_destroy(info);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ namespace pvpgn
|
|||
char const * apgar; /* WOL User Password (encrypted) */
|
||||
t_anongame_wol_player * anongame_player;
|
||||
} wol;
|
||||
int cr_time;
|
||||
std::time_t cr_time;
|
||||
/* Pass fail count for bruteforce protection */
|
||||
unsigned int passfail_count;
|
||||
/* connection flag substituting some other values */
|
||||
|
|
|
@ -979,7 +979,7 @@ namespace pvpgn
|
|||
|
||||
if (game->bad)
|
||||
std::fprintf(fp, "[ game results ignored due to inconsistencies ]\n\n");
|
||||
std::fprintf(fp, "name=\"%s\" id=" GAMEID_FORMAT "\n",
|
||||
std::fprintf(fp, "name=\"%s\" id=" GAMEID_FORMATF "\n",
|
||||
game_get_name(game),
|
||||
game->id);
|
||||
std::fprintf(fp, "clienttag=%4s type=\"%s\" option=\"%s\"\n",
|
||||
|
|
|
@ -1497,8 +1497,6 @@ namespace pvpgn
|
|||
|
||||
static int _client_loginreq1(t_connection * c, t_packet const *const packet)
|
||||
{
|
||||
t_packet *rpacket;
|
||||
|
||||
if (packet_get_size(packet) < sizeof(t_client_loginreq1)) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "[{}] got bad LOGINREQ1 packet (expected {} bytes, got {})", conn_get_socket(c), sizeof(t_client_loginreq1), packet_get_size(packet));
|
||||
return -1;
|
||||
|
@ -1513,16 +1511,24 @@ namespace pvpgn
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (!(rpacket = packet_create(packet_class_bnet)))
|
||||
t_packet* const rpacket = packet_create(packet_class_bnet);
|
||||
if (!rpacket)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
packet_set_size(rpacket, sizeof(t_server_loginreply1));
|
||||
packet_set_type(rpacket, SERVER_LOGINREPLY1);
|
||||
|
||||
// too many logins? [added by NonReal]
|
||||
if (prefs_get_max_concurrent_logins() > 0) {
|
||||
if (prefs_get_max_concurrent_logins() <= connlist_login_get_length()) {
|
||||
if (prefs_get_max_concurrent_logins() > 0)
|
||||
{
|
||||
if (prefs_get_max_concurrent_logins() <= connlist_login_get_length())
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "[{}] login denied, too many concurrent logins. max: {}. current: {}.", conn_get_socket(c), prefs_get_max_concurrent_logins(), connlist_login_get_length());
|
||||
bn_int_set(&rpacket->u.server_loginreply1.message, SERVER_LOGINREPLY1_MESSAGE_FAIL);
|
||||
conn_push_outqueue(c, rpacket);
|
||||
packet_del_ref(rpacket);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -2944,16 +2950,15 @@ namespace pvpgn
|
|||
packet_set_type(rpacket, SERVER_CLANINFOREPLY);
|
||||
bn_int_set(&rpacket->u.server_profilereply.count, count);
|
||||
if (clantag1 == clantag2) {
|
||||
int temp;
|
||||
t_bnettime bn_time;
|
||||
bn_long ltime;
|
||||
|
||||
bn_byte_set(&rpacket->u.server_claninforeply.fail, 0);
|
||||
|
||||
packet_append_string(rpacket, clan_get_name(clan));
|
||||
temp = clanmember_get_status(clanmember);
|
||||
packet_append_data(rpacket, &temp, 1);
|
||||
temp = clanmember_get_join_time(clanmember);
|
||||
char status = clanmember_get_status(clanmember);
|
||||
packet_append_data(rpacket, &status, 1);
|
||||
std::time_t temp = clanmember_get_join_time(clanmember);
|
||||
bn_time = time_to_bnettime(temp, 0);
|
||||
bn_time = bnettime_add_tzbias(bn_time, -conn_get_tzbias(c));
|
||||
bnettime_to_bn_long(bn_time, <ime);
|
||||
|
@ -4906,14 +4911,13 @@ namespace pvpgn
|
|||
t_connection *conn;
|
||||
t_clan *clan;
|
||||
const char *username;
|
||||
int offset;
|
||||
char status;
|
||||
|
||||
if (packet_get_size(packet) < sizeof(t_client_clan_createinvitereply)) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "[{}] got bad CLAN_CREATEINVITEREPLY packet (expected {} bytes, got {})", conn_get_socket(c), sizeof(t_client_clan_createinvitereq), packet_get_size(packet));
|
||||
return -1;
|
||||
}
|
||||
offset = sizeof(t_client_clan_createinvitereply);
|
||||
std::size_t offset = sizeof(t_client_clan_createinvitereply);
|
||||
username = packet_get_str_const(packet, offset, MAX_USERNAME_LEN);
|
||||
if (!username)
|
||||
{
|
||||
|
@ -4980,7 +4984,7 @@ namespace pvpgn
|
|||
|
||||
if ((rpacket = packet_create(packet_class_bnet)) != NULL)
|
||||
{
|
||||
int offset = sizeof(t_client_clanmember_rankupdate_req);
|
||||
std::size_t offset = sizeof(t_client_clanmember_rankupdate_req);
|
||||
char status;
|
||||
t_clan *clan;
|
||||
t_clanmember *dest_member;
|
||||
|
@ -5218,14 +5222,13 @@ namespace pvpgn
|
|||
t_account *conn_account;
|
||||
t_clan *conn_clan;
|
||||
t_clanmember *conn_member;
|
||||
int offset;
|
||||
char status;
|
||||
|
||||
if (packet_get_size(packet) < sizeof(t_client_clan_invitereply)) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "[{}] got bad CLAN_INVITEREPLY packet (expected {} bytes, got {})", conn_get_socket(c), sizeof(t_client_clan_createreq), packet_get_size(packet));
|
||||
return -1;
|
||||
}
|
||||
offset = sizeof(t_client_clan_invitereply);
|
||||
std::size_t offset = sizeof(t_client_clan_invitereply);
|
||||
if (!(username = packet_get_str_const(packet, offset, MAX_USERNAME_LEN))) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "[{}] got bad CLAN_INVITEREPLY packet (missing username)", conn_get_socket(c));
|
||||
return -1;
|
||||
|
|
|
@ -1618,23 +1618,27 @@ namespace pvpgn
|
|||
*/
|
||||
static int _ladder_send(t_connection * conn, char const * command)
|
||||
{
|
||||
t_packet * p;
|
||||
char data[MAX_IRC_MESSAGE_LEN + 1];
|
||||
unsigned len = 0;
|
||||
|
||||
p = packet_create(packet_class_raw);
|
||||
t_packet* const p = packet_create(packet_class_raw);
|
||||
if (!p)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (command)
|
||||
len = (std::strlen(command) + 6);
|
||||
|
||||
if (len > MAX_IRC_MESSAGE_LEN) {
|
||||
if (len > MAX_IRC_MESSAGE_LEN)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "message to send is too large ({} bytes)", len);
|
||||
packet_del_ref(p);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
std::sprintf(data, "\r\n\r\n\r\n%s", command);
|
||||
//std::sprintf(data,"%s",command);
|
||||
}
|
||||
|
||||
|
||||
std::sprintf(data, "\r\n\r\n\r\n%s", command);
|
||||
|
||||
packet_set_size(p, 0);
|
||||
packet_append_data(p, data, len);
|
||||
|
@ -1765,7 +1769,6 @@ namespace pvpgn
|
|||
}
|
||||
else {
|
||||
/* Standard RUNG search */
|
||||
int i;
|
||||
unsigned start = std::atoi(params[0]);
|
||||
unsigned count = std::atoi(params[1]);
|
||||
|
||||
|
@ -1774,7 +1777,7 @@ namespace pvpgn
|
|||
LadderList* ladderList = NULL;
|
||||
|
||||
ladderList = ladders.getLadderList(LadderKey(id, cl_tag, ladder_sort_default, ladder_time_default));
|
||||
for (i = start; i < start + count; i++) {
|
||||
for (unsigned int i = start; i < start + count; i++) {
|
||||
const LadderReferencedObject* referencedObject = NULL;
|
||||
cl_account = NULL;
|
||||
if (((referencedObject = ladderList->getReferencedObject(i))) && (cl_account = referencedObject->getAccount())) {
|
||||
|
|
|
@ -2398,7 +2398,6 @@ namespace pvpgn
|
|||
t_game_result result;
|
||||
t_game_result * results = game_result->results;
|
||||
int resultnum;
|
||||
int i;
|
||||
|
||||
switch (type) {
|
||||
case wol_gameres_type_int:
|
||||
|
@ -2409,7 +2408,7 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
DEBUG2("Got %u player resultnum {}", num, resultnum);
|
||||
DEBUG2("Got {} player resultnum {}", num, resultnum);
|
||||
|
||||
resultnum &= 0x0000FF00;
|
||||
resultnum = resultnum >> 8;
|
||||
|
@ -2419,7 +2418,8 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < game_get_count(game); i++) {
|
||||
unsigned int i = 0;
|
||||
for (; i < game_get_count(game); i++) {
|
||||
if (game_get_player(game, i) == other_account) break;
|
||||
}
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ namespace pvpgn
|
|||
translations[original][languages[i]] = translate;
|
||||
}
|
||||
|
||||
INFO1("localization file loaded \"%s\"", lang_filename);
|
||||
INFO1("localization file loaded \"{}\"", lang_filename);
|
||||
xfree((void*)lang_filename);
|
||||
}
|
||||
|
||||
|
|
|
@ -724,7 +724,7 @@ namespace pvpgn
|
|||
{
|
||||
size_t option_valuelen = std::strlen(option->value);
|
||||
// convert string groups from config to integer
|
||||
for (int i = 0; i < option_valuelen; i++)
|
||||
for (std::size_t i = 0; i < option_valuelen; i++)
|
||||
{
|
||||
if (option->value[i] == '1') master_commandgroups |= 1;
|
||||
else if (option->value[i] == '2') master_commandgroups |= 2;
|
||||
|
|
|
@ -195,7 +195,7 @@ namespace pvpgn
|
|||
break;
|
||||
|
||||
case 'i':
|
||||
std::sprintf(&out[outpos], UID_FORMAT, conn_get_userid(c));
|
||||
std::sprintf(&out[outpos], UID_FORMATF, conn_get_userid(c));
|
||||
outpos += std::strlen(&out[outpos]);
|
||||
break;
|
||||
|
||||
|
|
|
@ -1248,7 +1248,7 @@ namespace pvpgn
|
|||
std::time_t next_savetime, track_time;
|
||||
std::time_t war3_ladder_updatetime;
|
||||
std::time_t output_updatetime;
|
||||
unsigned int prev_time = 0;
|
||||
std::time_t prev_time = 0;
|
||||
|
||||
starttime = std::time(NULL);
|
||||
track_time = starttime - prefs_get_track();
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef INCLUDED_TOURNAMENT_TYPES
|
||||
#define INCLUDED_TOURNAMENT_TYPES
|
||||
|
||||
#include <ctime>
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
|
@ -24,14 +26,14 @@ namespace pvpgn
|
|||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int start_preliminary;
|
||||
unsigned int end_signup;
|
||||
unsigned int end_preliminary;
|
||||
unsigned int start_round_1;
|
||||
unsigned int start_round_2;
|
||||
unsigned int start_round_3;
|
||||
unsigned int start_round_4;
|
||||
unsigned int tournament_end;
|
||||
std::time_t start_preliminary;
|
||||
std::time_t end_signup;
|
||||
std::time_t end_preliminary;
|
||||
std::time_t start_round_1;
|
||||
std::time_t start_round_2;
|
||||
std::time_t start_round_3;
|
||||
std::time_t start_round_4;
|
||||
std::time_t tournament_end;
|
||||
unsigned int game_selection;
|
||||
unsigned int game_type;
|
||||
unsigned int game_client;
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace pvpgn
|
|||
size_t cglistlen = std::strlen(cglist);
|
||||
|
||||
// convert string groups from config to integer
|
||||
for (int i = 0; i < cglistlen; i++)
|
||||
for (std::size_t i = 0; i < cglistlen; i++)
|
||||
{
|
||||
if (cglist[i] == '1') groups |= 1;
|
||||
else if (cglist[i] == '2') groups |= 2;
|
||||
|
@ -320,7 +320,7 @@ namespace pvpgn
|
|||
{
|
||||
lines = userlog_read(username, startline);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
catch (...)
|
||||
{
|
||||
message_send_text(c, message_type_error, c, "Could not read user log");
|
||||
return 0;
|
||||
|
|
|
@ -258,7 +258,7 @@ namespace pvpgn
|
|||
t1.tm_year = t1.tm_year + 100;
|
||||
|
||||
if (time_invalid)
|
||||
parsed_exeinfo->time = -1;
|
||||
parsed_exeinfo->time = static_cast<std::time_t>(-1);
|
||||
else
|
||||
parsed_exeinfo->time = std::mktime(&t1);
|
||||
parsed_exeinfo->size = size;
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#ifndef INCLUDED_VERSIONCHECK_TYPES
|
||||
#define INCLUDED_VERSIONCHECK_TYPES
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "common/tag.h"
|
||||
|
||||
namespace pvpgn
|
||||
|
@ -33,7 +35,7 @@ namespace pvpgn
|
|||
typedef struct
|
||||
{
|
||||
char const * exe;
|
||||
int time;
|
||||
std::time_t time;
|
||||
int size;
|
||||
} t_parsed_exeinfo;
|
||||
#endif
|
||||
|
|
|
@ -1849,9 +1849,8 @@ extern int main(int argc, char * argv[])
|
|||
char const * clan;
|
||||
char const * inviter;
|
||||
char invited_count;
|
||||
int offset;
|
||||
std::size_t offset = sizeof(t_server_clan_createinvitereq);
|
||||
|
||||
offset = sizeof(t_server_clan_createinvitereq);
|
||||
if (!(clan = packet_get_str_const(rpacket, offset, CLAN_NAME_MAX)))
|
||||
{
|
||||
munge(&client);
|
||||
|
|
|
@ -685,7 +685,7 @@ extern int main(int argc, char * argv[])
|
|||
if (str_to_uint(temp, &uid) < 0 || uid < 1)
|
||||
std::printf(" Account: UNKNOWN\n");
|
||||
else
|
||||
std::printf(" Account: " UID_FORMAT "\n", uid);
|
||||
std::printf(" Account: " UID_FORMATF "\n", uid);
|
||||
|
||||
if (j < keys && (temp = packet_get_str_const(rpacket, strpos, 256)))
|
||||
strpos += std::strlen(temp) + 1;
|
||||
|
|
|
@ -140,7 +140,7 @@ namespace pvpgn
|
|||
extern int fdwatch_update_fd(int idx, unsigned rw)
|
||||
{
|
||||
if (idx < 0 || idx >= fdw_maxcons) {
|
||||
ERROR2("out of bounds idx [%d] (max: %d)", idx, fdw_maxcons);
|
||||
ERROR2("out of bounds idx [{}] (max: {})", idx, fdw_maxcons);
|
||||
return -1;
|
||||
}
|
||||
/* do not allow completly reset the access because then backend codes
|
||||
|
@ -164,7 +164,7 @@ namespace pvpgn
|
|||
extern int fdwatch_del_fd(int idx)
|
||||
{
|
||||
if (idx < 0 || idx >= fdw_maxcons) {
|
||||
ERROR2("out of bounds idx [%d] (max: %d)", idx, fdw_maxcons);
|
||||
ERROR2("out of bounds idx [{}] (max: {})", idx, fdw_maxcons);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace pvpgn
|
|||
|
||||
std::memset(epevents.get(), 0, sizeof(struct epoll_event) * nfds);
|
||||
|
||||
INFO1("fdwatch epoll() based layer initialized (max %d sockets)", nfds);
|
||||
INFO1("fdwatch epoll() based layer initialized (max {} sockets)", nfds);
|
||||
}
|
||||
|
||||
FDWEpollBackend::~FDWEpollBackend() throw()
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace pvpgn
|
|||
wridx[i] = -1;
|
||||
}
|
||||
|
||||
INFO1("fdwatch kqueue() based layer initialized (max %d sockets)", nfds);
|
||||
INFO1("fdwatch kqueue() based layer initialized (max {} sockets)", nfds);
|
||||
}
|
||||
|
||||
FDWKqueueBackend::~FDWKqueueBackend() throw()
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace pvpgn
|
|||
/* I would use a memset with 255 but that is dirty and doesnt gain us anything */
|
||||
for (int i = 0; i < nfds; i++) ridx[i] = -1;
|
||||
|
||||
INFO1("fdwatch poll() based layer initialized (max %d sockets)", nfds);
|
||||
INFO1("fdwatch poll() based layer initialized (max {} sockets)", nfds);
|
||||
}
|
||||
|
||||
FDWPollBackend::~FDWPollBackend() throw()
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace pvpgn
|
|||
|
||||
PSOCK_FD_ZERO(trfds.get()); PSOCK_FD_ZERO(twfds.get());
|
||||
|
||||
INFO1("fdwatch select() based layer initialized (max %d sockets)", nfds);
|
||||
INFO1("fdwatch select() based layer initialized (max {} sockets)", nfds);
|
||||
}
|
||||
|
||||
FDWSelectBackend::~FDWSelectBackend() throw()
|
||||
|
|
|
@ -80,10 +80,12 @@
|
|||
const int LISTEN_QUEUE = 10;
|
||||
|
||||
/* the format for account numbers */
|
||||
#define UID_FORMAT "{:08}"
|
||||
#define UID_FORMAT "#{:08}"
|
||||
#define UID_FORMATF "#%08u"
|
||||
|
||||
/* the format for game ids */
|
||||
#define GAMEID_FORMAT "{:06}"
|
||||
#define GAMEID_FORMAT "#{:06}"
|
||||
#define GAMEID_FORMATF "#%06u"
|
||||
|
||||
/* the format of timestamps in the userlogfile */
|
||||
#define USEREVENT_TIME_FORMAT "%b %d %H:%M"
|
||||
|
|
|
@ -642,7 +642,7 @@ namespace pvpgn
|
|||
/* case tag_wol_locale_turkey:
|
||||
return trTR*/
|
||||
default:
|
||||
WARN1("%d is not defined", locale);
|
||||
WARN1("{} is not defined", locale);
|
||||
return GAMELANG_ENGLISH_UINT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ namespace pvpgn
|
|||
const char* _ext;
|
||||
|
||||
DIR *dir;
|
||||
class dirent *ent;
|
||||
struct dirent* ent;
|
||||
|
||||
dir = opendir(directory);
|
||||
if (!dir)
|
||||
|
@ -181,7 +181,7 @@ namespace pvpgn
|
|||
{
|
||||
std::vector<std::string> subfiles = dir_getfiles(full_file_name.c_str(), ext, recursive);
|
||||
|
||||
for (int i = 0; i < subfiles.size(); ++i)
|
||||
for (std::size_t i = 0; i < subfiles.size(); ++i)
|
||||
dfiles.push_back(subfiles[i]);
|
||||
}
|
||||
continue;
|
||||
|
|
|
@ -42,11 +42,11 @@ namespace pvpgn
|
|||
|
||||
extern int bnetd_check(void)
|
||||
{
|
||||
static unsigned int prev_connecting_checktime = 0;
|
||||
static std::time_t prev_connecting_checktime = 0;
|
||||
|
||||
if (bnetd_connection) {
|
||||
if (d2cs_conn_get_state(bnetd_connection) == conn_state_connecting) {
|
||||
if (std::time(NULL) - prev_connecting_checktime > prefs_get_s2s_timeout()) {
|
||||
if (std::time(nullptr) - prev_connecting_checktime > prefs_get_s2s_timeout()) {
|
||||
eventlog(eventlog_level_warn, __FUNCTION__, "connection to bnetd s2s timeout");
|
||||
d2cs_conn_set_state(bnetd_connection, conn_state_destroy);
|
||||
return -1;
|
||||
|
@ -61,7 +61,7 @@ namespace pvpgn
|
|||
handle_bnetd_init(bnetd_connection);
|
||||
}
|
||||
else {
|
||||
prev_connecting_checktime = std::time(NULL);
|
||||
prev_connecting_checktime = std::time(nullptr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -151,7 +151,6 @@ namespace pvpgn
|
|||
unsigned char buffer[MAX_SAVEFILE_SIZE];
|
||||
unsigned int size;
|
||||
unsigned int version;
|
||||
int ladder_time, now;
|
||||
std::FILE * fp;
|
||||
|
||||
|
||||
|
@ -242,8 +241,8 @@ namespace pvpgn
|
|||
infofile = (char*)xmalloc(std::strlen(prefs_get_charinfo_dir()) + 1 + std::strlen(account) + 1 + std::strlen(charname) + 1);
|
||||
d2char_get_infofile_name(infofile, account, charname);
|
||||
|
||||
now = std::time(NULL);
|
||||
ladder_time = prefs_get_ladder_start_time();
|
||||
std::time_t now = std::time(nullptr);
|
||||
std::time_t ladder_time = prefs_get_ladder_start_time();
|
||||
if ((ladder_time > 0) && (now < ladder_time))
|
||||
charstatus_set_ladder(status, 0);
|
||||
|
||||
|
@ -492,7 +491,7 @@ namespace pvpgn
|
|||
extern int d2charinfo_load(char const * account, char const * charname, t_d2charinfo_file * data)
|
||||
{
|
||||
char * file;
|
||||
int size, ladder_time;
|
||||
int size;
|
||||
|
||||
if (d2char_check_charname(charname) < 0) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got bad character name \"{}\"", charname);
|
||||
|
@ -525,7 +524,7 @@ namespace pvpgn
|
|||
xfree(file);
|
||||
return 0;
|
||||
}
|
||||
ladder_time = prefs_get_ladder_start_time();
|
||||
unsigned int ladder_time = prefs_get_ladder_start_time();
|
||||
if ((ladder_time > 0) && bn_int_get(data->header.create_time) < ladder_time) {
|
||||
char buffer[MAX_SAVEFILE_SIZE];
|
||||
unsigned int status_offset;
|
||||
|
|
|
@ -179,7 +179,7 @@ static int on_client_createcharreq(t_connection * c, t_packet * packet)
|
|||
try {
|
||||
Directory dir(path);
|
||||
} catch (const Directory::OpenError&) {
|
||||
INFO1("(*%s) charinfo directory do not exist, building it",account);
|
||||
INFO1("(*{}) charinfo directory do not exist, building it",account);
|
||||
p_mkdir(path,S_IRWXU);
|
||||
}
|
||||
xfree(path);
|
||||
|
@ -751,7 +751,7 @@ static int on_client_motdreq(t_connection * c, t_packet * packet)
|
|||
motd = xstrdup(prefs_get_motd());
|
||||
motd_len = std::strlen(motd);
|
||||
if (motd_len > MAX_MOTD_LENGTH) {
|
||||
WARN2("motd length (%i) exceeds maximun value (%i)",motd_len,MAX_MOTD_LENGTH);
|
||||
WARN2("motd length ({}) exceeds maximun value ({})",motd_len,MAX_MOTD_LENGTH);
|
||||
motd[MAX_MOTD_LENGTH]='\0';
|
||||
}
|
||||
if ((rpacket=packet_create(packet_class_d2cs))) {
|
||||
|
@ -903,7 +903,7 @@ static int on_client_charlistreq(t_connection * c, t_packet * packet)
|
|||
}
|
||||
}
|
||||
} catch(const Directory::OpenError&) {
|
||||
INFO1("(*%s) charinfo directory do not exist, building it",account);
|
||||
INFO1("(*{}) charinfo directory do not exist, building it",account);
|
||||
p_mkdir(path,S_IRWXU);
|
||||
}
|
||||
bn_short_set(&rpacket->u.d2cs_client_charlistreply.currchar,n);
|
||||
|
@ -1014,7 +1014,7 @@ static int on_client_charlistreq_110(t_connection * c, t_packet * packet)
|
|||
}
|
||||
}
|
||||
} catch (const Directory::OpenError&) {
|
||||
INFO1("(*%s) charinfo directory do not exist, building it",account);
|
||||
INFO1("(*{}) charinfo directory do not exist, building it",account);
|
||||
p_mkdir(path,S_IRWXU);
|
||||
}
|
||||
bn_short_set(&rpacket->u.d2cs_client_charlistreply.currchar,n);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "prefs.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
|
||||
#include "common/conf.h"
|
||||
#include "common/eventlog.h"
|
||||
|
@ -1132,7 +1133,7 @@ static int conf_setdef_account_allowed_symbols(void)
|
|||
}
|
||||
|
||||
|
||||
extern unsigned int prefs_get_ladder_start_time(void)
|
||||
extern std::time_t prefs_get_ladder_start_time()
|
||||
{
|
||||
return prefs_conf.ladder_start_time;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#ifndef INCLUDED_PREFS_H
|
||||
#define INCLUDED_PREFS_H
|
||||
|
||||
#include <ctime>
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
|
@ -80,7 +82,7 @@ namespace pvpgn
|
|||
extern unsigned int prefs_get_allow_convert(void);
|
||||
extern char const * prefs_get_d2cs_account_allowed_symbols(void);
|
||||
extern unsigned int prefs_get_d2gs_restart_delay(void);
|
||||
extern unsigned int prefs_get_ladder_start_time(void);
|
||||
extern std::time_t prefs_get_ladder_start_time();
|
||||
extern unsigned int prefs_get_char_expire_time(void);
|
||||
extern char const * prefs_get_d2gsconffile(void);
|
||||
extern char const * prefs_get_charlist_sort(void);
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace pvpgn
|
|||
|
||||
static unsigned int dbs_packet_savedata_charsave(t_d2dbs_connection* conn, char * AccountName, char * CharName, char * data, unsigned int datalen);
|
||||
static unsigned int dbs_packet_savedata_charinfo(t_d2dbs_connection* conn, char * AccountName, char * CharName, char * data, unsigned int datalen);
|
||||
static unsigned int dbs_packet_getdata_charsave(t_d2dbs_connection* conn, char * AccountName, char * CharName, char * data, unsigned int bufsize);
|
||||
static unsigned int dbs_packet_getdata_charsave(t_d2dbs_connection* conn, char * AccountName, char * CharName, char * data, long bufsize);
|
||||
static unsigned int dbs_packet_getdata_charinfo(t_d2dbs_connection* conn, char * AccountName, char * CharName, char * data, unsigned int bufsize);
|
||||
static unsigned int dbs_packet_echoreply(t_d2dbs_connection* conn);
|
||||
static int dbs_packet_getdata(t_d2dbs_connection* conn);
|
||||
|
@ -76,7 +76,6 @@ namespace pvpgn
|
|||
char filename[MAX_PATH];
|
||||
char savefile[MAX_PATH];
|
||||
char bakfile[MAX_PATH];
|
||||
unsigned short curlen, readlen, leftlen, writelen;
|
||||
std::FILE * fd;
|
||||
int checksum_header;
|
||||
int checksum_calc;
|
||||
|
@ -101,12 +100,14 @@ namespace pvpgn
|
|||
eventlog(eventlog_level_error, __FUNCTION__, "open() failed : {}", filename);
|
||||
return 0;
|
||||
}
|
||||
curlen = 0;
|
||||
leftlen = datalen;
|
||||
while (curlen<datalen) {
|
||||
if (leftlen>2000) writelen = 2000;
|
||||
else writelen = leftlen;
|
||||
readlen = std::fwrite(data + curlen, 1, writelen, fd);
|
||||
|
||||
std::size_t curlen = 0;
|
||||
std::size_t leftlen = datalen;
|
||||
while (curlen<datalen)
|
||||
{
|
||||
std::size_t writelen = leftlen > 2000 ? 2000 : leftlen;
|
||||
|
||||
std::size_t readlen = std::fwrite(data + curlen, 1, writelen, fd);
|
||||
if (readlen <= 0) {
|
||||
std::fclose(fd);
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "write() failed error : {}", std::strerror(errno));
|
||||
|
@ -137,7 +138,6 @@ namespace pvpgn
|
|||
char filepath[MAX_PATH];
|
||||
char filename[MAX_PATH];
|
||||
std::FILE * fd;
|
||||
unsigned short curlen, readlen, leftlen, writelen;
|
||||
struct stat statbuf;
|
||||
|
||||
strtolower(AccountName);
|
||||
|
@ -156,12 +156,13 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
curlen = 0;
|
||||
leftlen = datalen;
|
||||
while (curlen<datalen) {
|
||||
if (leftlen>2000) writelen = 2000;
|
||||
else writelen = leftlen;
|
||||
readlen = std::fwrite(data + curlen, 1, writelen, fd);
|
||||
std::size_t curlen = 0;
|
||||
std::size_t leftlen = datalen;
|
||||
while (curlen < datalen)
|
||||
{
|
||||
std::size_t writelen = leftlen > 2000 ? 2000 : leftlen;
|
||||
|
||||
std::size_t readlen = std::fwrite(data + curlen, 1, writelen, fd);
|
||||
if (readlen <= 0) {
|
||||
std::fclose(fd);
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "write() failed error : {}", std::strerror(errno));
|
||||
|
@ -185,13 +186,11 @@ namespace pvpgn
|
|||
return datalen;
|
||||
}
|
||||
|
||||
static unsigned int dbs_packet_getdata_charsave(t_d2dbs_connection* conn, char * AccountName, char * CharName, char * data, unsigned int bufsize)
|
||||
static unsigned int dbs_packet_getdata_charsave(t_d2dbs_connection* conn, char * AccountName, char * CharName, char * data, long bufsize)
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
char filename_d2closed[MAX_PATH];
|
||||
std::FILE * fd;
|
||||
unsigned short curlen, readlen, leftlen, writelen;
|
||||
long filesize;
|
||||
|
||||
strtolower(AccountName);
|
||||
strtolower(CharName);
|
||||
|
@ -208,25 +207,28 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
std::fseek(fd, 0, SEEK_END);
|
||||
filesize = std::ftell(fd);
|
||||
std::rewind(fd);
|
||||
if (filesize == -1) {
|
||||
long filesize = std::ftell(fd);
|
||||
if (filesize == -1L)
|
||||
{
|
||||
std::fclose(fd);
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "lseek() failed");
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "ftell() failed");
|
||||
return 0;
|
||||
}
|
||||
if ((signed)bufsize < filesize) {
|
||||
std::rewind(fd);
|
||||
|
||||
if (bufsize < filesize) {
|
||||
std::fclose(fd);
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "not enough buffer");
|
||||
return 0;
|
||||
}
|
||||
|
||||
curlen = 0;
|
||||
leftlen = filesize;
|
||||
while (curlen < filesize) {
|
||||
if (leftlen>2000) writelen = 2000;
|
||||
else writelen = leftlen;
|
||||
readlen = std::fread(data + curlen, 1, writelen, fd);
|
||||
long curlen = 0;
|
||||
std::size_t leftlen = filesize;
|
||||
while (curlen < filesize)
|
||||
{
|
||||
std::size_t writelen = leftlen > 2000 ? 2000 : leftlen;
|
||||
|
||||
std::size_t readlen = std::fread(data + curlen, 1, writelen, fd);
|
||||
if (readlen <= 0) {
|
||||
std::fclose(fd);
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "read() failed error : {}", std::strerror(errno));
|
||||
|
@ -244,8 +246,6 @@ namespace pvpgn
|
|||
{
|
||||
char filename[MAX_PATH];
|
||||
std::FILE * fd;
|
||||
unsigned short curlen, readlen, leftlen, writelen;
|
||||
long filesize;
|
||||
|
||||
strtolower(AccountName);
|
||||
strtolower(CharName);
|
||||
|
@ -257,7 +257,7 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
std::fseek(fd, 0, SEEK_END);
|
||||
filesize = std::ftell(fd);
|
||||
long filesize = std::ftell(fd);
|
||||
std::rewind(fd);
|
||||
if (filesize == -1) {
|
||||
std::fclose(fd);
|
||||
|
@ -270,14 +270,13 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
curlen = 0;
|
||||
leftlen = filesize;
|
||||
while (curlen < filesize) {
|
||||
if (leftlen>2000)
|
||||
writelen = 2000;
|
||||
else
|
||||
writelen = leftlen;
|
||||
readlen = std::fread(data + curlen, 1, writelen, fd);
|
||||
std::size_t curlen = 0;
|
||||
std::size_t leftlen = filesize;
|
||||
while (curlen < filesize)
|
||||
{
|
||||
std::size_t writelen = leftlen > 2000 ? 2000 : leftlen;
|
||||
|
||||
std::size_t readlen = std::fread(data + curlen, 1, writelen, fd);
|
||||
if (readlen <= 0)
|
||||
{
|
||||
std::fclose(fd);
|
||||
|
@ -294,7 +293,6 @@ namespace pvpgn
|
|||
|
||||
static int dbs_packet_savedata(t_d2dbs_connection * conn)
|
||||
{
|
||||
unsigned short writelen;
|
||||
unsigned short datatype;
|
||||
unsigned short datalen;
|
||||
unsigned int result;
|
||||
|
@ -364,8 +362,10 @@ namespace pvpgn
|
|||
eventlog(eventlog_level_error, __FUNCTION__, "unknown data type {}", datatype);
|
||||
return -1;
|
||||
}
|
||||
writelen = sizeof(*saveret) + std::strlen(CharName) + 1;
|
||||
if (writelen > kBufferSize - conn->nCharsInWriteBuffer) return 0;
|
||||
std::size_t writelen = sizeof(*saveret) + std::strlen(CharName) + 1;
|
||||
if (writelen > kBufferSize - conn->nCharsInWriteBuffer)
|
||||
return 0;
|
||||
|
||||
writepos = (unsigned char*)(conn->WriteBuf + conn->nCharsInWriteBuffer);
|
||||
saveret = (t_d2dbs_d2gs_save_data_reply *)writepos;
|
||||
bn_short_set(&saveret->h.type, D2DBS_D2GS_SAVE_DATA_REPLY);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#define tf(a) ((a)?1:0)
|
||||
#define SELECT_TIME_OUT 20000
|
||||
#define kBufferSize (1024*20)
|
||||
constexpr long kBufferSize = 1024L * 20L;
|
||||
#define kMaxPacketLength (1024*5)
|
||||
|
||||
#define DEFAULT_LOG_FILE "/usr/local/var/d2dbs.std::log"
|
||||
|
|
Loading…
Add table
Reference in a new issue