Sync #202

Merged
RElesgoe merged 4 commits from master into master 2016-05-23 14:46:03 -06:00
17 changed files with 441 additions and 422 deletions

View file

@ -1105,7 +1105,7 @@ namespace pvpgn
return 0; return 0;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\wins"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\wins");
return account_get_numattr(account, key.c_str()); return account_get_numattr(account, key.c_str());
} }
@ -1119,7 +1119,7 @@ namespace pvpgn
return -1; return -1;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\wins"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\wins");
return account_set_numattr(account, key.c_str(), account_get_ladder_wins(account, clienttag, id) + 1); return account_set_numattr(account, key.c_str(), account_get_ladder_wins(account, clienttag, id) + 1);
} }
@ -1133,7 +1133,7 @@ namespace pvpgn
return -1; return -1;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\wins"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\wins");
return account_set_numattr(account, key.c_str(), wins); return account_set_numattr(account, key.c_str(), wins);
} }
@ -1147,7 +1147,7 @@ namespace pvpgn
return 0; return 0;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\losses"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\losses");
return account_get_numattr(account, key.c_str()); return account_get_numattr(account, key.c_str());
} }
@ -1161,7 +1161,7 @@ namespace pvpgn
return -1; return -1;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\losses"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\losses");
return account_set_numattr(account, key.c_str(), account_get_ladder_losses(account, clienttag, id) + 1); return account_set_numattr(account, key.c_str(), account_get_ladder_losses(account, clienttag, id) + 1);
} }
@ -1175,7 +1175,7 @@ namespace pvpgn
return -1; return -1;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\losses"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\losses");
return account_set_numattr(account, key.c_str(), losses); return account_set_numattr(account, key.c_str(), losses);
} }
@ -1189,7 +1189,7 @@ namespace pvpgn
return 0; return 0;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\draws"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\draws");
return account_get_numattr(account, key.c_str()); return account_get_numattr(account, key.c_str());
} }
@ -1203,7 +1203,7 @@ namespace pvpgn
return -1; return -1;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\draws"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\draws");
return account_set_numattr(account, key.c_str(), account_get_ladder_draws(account, clienttag, id) + 1); return account_set_numattr(account, key.c_str(), account_get_ladder_draws(account, clienttag, id) + 1);
} }
@ -1217,7 +1217,7 @@ namespace pvpgn
return -1; return -1;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\draws"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\draws");
return account_set_numattr(account, key.c_str(), draws); return account_set_numattr(account, key.c_str(), draws);
} }
@ -1231,7 +1231,7 @@ namespace pvpgn
return 0; return 0;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\disconnects"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\disconnects");
return account_get_numattr(account, key.c_str()); return account_get_numattr(account, key.c_str());
} }
@ -1245,7 +1245,7 @@ namespace pvpgn
return -1; return -1;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\disconnects"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\disconnects");
return account_set_numattr(account, key.c_str(), account_get_ladder_disconnects(account, clienttag, id) + 1); return account_set_numattr(account, key.c_str(), account_get_ladder_disconnects(account, clienttag, id) + 1);
} }
@ -1259,7 +1259,7 @@ namespace pvpgn
return -1; return -1;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\disconnects"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\disconnects");
return account_set_numattr(account, key.c_str(), discs); return account_set_numattr(account, key.c_str(), discs);
} }
@ -1336,7 +1336,7 @@ namespace pvpgn
return 0; return 0;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\rank"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\rank");
return account_get_numattr(account, key.c_str()); return account_get_numattr(account, key.c_str());
} }
@ -1350,7 +1350,7 @@ namespace pvpgn
return -1; return -1;
} }
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\rank"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\rank");
int retval = 0; int retval = 0;
if (account_set_numattr(account, key.c_str(), rank) < 0) if (account_set_numattr(account, key.c_str(), rank) < 0)
@ -1359,7 +1359,7 @@ namespace pvpgn
unsigned int oldrank = account_get_ladder_high_rank(account, clienttag, id); unsigned int oldrank = account_get_ladder_high_rank(account, clienttag, id);
if (oldrank == 0 || rank < oldrank) if (oldrank == 0 || rank < oldrank)
{ {
key = "Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\high rank"; key = "Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\high rank";
if (account_set_numattr(account, key.c_str(), rank) < 0) if (account_set_numattr(account, key.c_str(), rank) < 0)
retval = -1; retval = -1;
@ -2026,9 +2026,10 @@ namespace pvpgn
// WAR3 Play Game & Profile Funcs // WAR3 Play Game & Profile Funcs
extern char const * race_get_str(unsigned int race) extern std::string race_get_str(unsigned int race)
{ {
switch (race) { switch (race)
{
case W3_RACE_ORCS: case W3_RACE_ORCS:
return "orcs"; return "orcs";
case W3_RACE_HUMANS: case W3_RACE_HUMANS:
@ -2046,17 +2047,17 @@ namespace pvpgn
return "demons"; return "demons";
default: default:
eventlog(eventlog_level_warn, __FUNCTION__, "unknown race: %x", race); eventlog(eventlog_level_warn, __FUNCTION__, "unknown race: %x", race);
return nullptr; return std::string();
} }
} }
extern int account_inc_racewins(t_account * account, unsigned int intrace, t_clienttag clienttag) extern int account_inc_racewins(t_account * account, unsigned int intrace, t_clienttag clienttag)
{ {
char const * race = race_get_str(intrace); std::string race = race_get_str(intrace);
if (race == nullptr) if (race.empty())
return -1; return -1;
std::string table("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(race) + "\\wins"); std::string table("Record\\" + tag_uint_to_str2(clienttag) + "\\" + race + "\\wins");
unsigned int wins = account_get_numattr(account, table.c_str()); wins++; unsigned int wins = account_get_numattr(account, table.c_str()); wins++;
return account_set_numattr(account, table.c_str(), wins); return account_set_numattr(account, table.c_str(), wins);
@ -2064,22 +2065,22 @@ namespace pvpgn
extern int account_get_racewins(t_account * account, unsigned int intrace, t_clienttag clienttag) extern int account_get_racewins(t_account * account, unsigned int intrace, t_clienttag clienttag)
{ {
char const *race = race_get_str(intrace); std::string race = race_get_str(intrace);
if (race == nullptr) if (race.empty())
return 0; return 0;
std::string table("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(race) + "\\wins"); std::string table("Record\\" + tag_uint_to_str2(clienttag) + "\\" + race + "\\wins");
return account_get_numattr(account, table.c_str()); return account_get_numattr(account, table.c_str());
} }
extern int account_inc_racelosses(t_account * account, unsigned int intrace, t_clienttag clienttag) extern int account_inc_racelosses(t_account * account, unsigned int intrace, t_clienttag clienttag)
{ {
char const *race = race_get_str(intrace); std::string race = race_get_str(intrace);
if (race == nullptr) if (race.empty())
return -1; return -1;
std::string table("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(race) + "\\losses"); std::string table("Record\\" + tag_uint_to_str2(clienttag) + "\\" + race + "\\losses");
unsigned int losses = account_get_numattr(account, table.c_str()); losses++; unsigned int losses = account_get_numattr(account, table.c_str()); losses++;
@ -2089,11 +2090,11 @@ namespace pvpgn
extern int account_get_racelosses(t_account * account, unsigned int intrace, t_clienttag clienttag) extern int account_get_racelosses(t_account * account, unsigned int intrace, t_clienttag clienttag)
{ {
char const *race = race_get_str(intrace); std::string race = race_get_str(intrace);
if (race == nullptr) if (race.empty())
return 0; return 0;
std::string table("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(race) + "\\losses"); std::string table("Record\\" + tag_uint_to_str2(clienttag) + "\\" + race + "\\losses");
return account_get_numattr(account, table.c_str()); return account_get_numattr(account, table.c_str());
@ -2142,28 +2143,28 @@ namespace pvpgn
extern int account_get_ladder_xp(t_account * account, t_clienttag clienttag, t_ladder_id id) extern int account_get_ladder_xp(t_account * account, t_clienttag clienttag, t_ladder_id id)
{ {
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\xp"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\xp");
return account_get_numattr(account, key.c_str()); return account_get_numattr(account, key.c_str());
} }
extern int account_set_ladder_xp(t_account * account, t_clienttag clienttag, t_ladder_id id, unsigned int xp) extern int account_set_ladder_xp(t_account * account, t_clienttag clienttag, t_ladder_id id, unsigned int xp)
{ {
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\xp"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\xp");
return account_set_numattr(account, key.c_str(), xp); return account_set_numattr(account, key.c_str(), xp);
} }
extern int account_get_ladder_level(t_account * account, t_clienttag clienttag, t_ladder_id id) extern int account_get_ladder_level(t_account * account, t_clienttag clienttag, t_ladder_id id)
{ {
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\level"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\level");
return account_get_numattr(account, key.c_str()); return account_get_numattr(account, key.c_str());
} }
extern int account_set_ladder_level(t_account * account, t_clienttag clienttag, t_ladder_id id, unsigned int level) extern int account_set_ladder_level(t_account * account, t_clienttag clienttag, t_ladder_id id, unsigned int level)
{ {
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\level"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\level");
return account_set_numattr(account, key.c_str(), level); return account_set_numattr(account, key.c_str(), level);
} }
@ -2737,14 +2738,14 @@ namespace pvpgn
extern int account_get_ladder_points(t_account * account, t_clienttag clienttag, t_ladder_id id) extern int account_get_ladder_points(t_account * account, t_clienttag clienttag, t_ladder_id id)
{ {
std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\points"); std::string key("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\points");
return account_get_numattr(account, key.c_str()); return account_get_numattr(account, key.c_str());
} }
extern int account_set_ladder_points(t_account * account, t_clienttag clienttag, t_ladder_id id, unsigned int points) extern int account_set_ladder_points(t_account * account, t_clienttag clienttag, t_ladder_id id, unsigned int points)
{ {
std::string key ("Record\\" + tag_uint_to_str2(clienttag) + "\\" + std::string(ladder_id_str[static_cast<int>(id)]) + "\\points"); std::string key ("Record\\" + tag_uint_to_str2(clienttag) + "\\" + ladder_id_str.at(static_cast<size_t>(id)) + "\\points");
return account_set_numattr(account, key.c_str(), points); return account_set_numattr(account, key.c_str(), points);
} }

View file

@ -216,7 +216,7 @@ namespace pvpgn
extern int account_remove_friend(t_account * account, int friendnum); extern int account_remove_friend(t_account * account, int friendnum);
extern int account_remove_friend2(t_account * account, const char * friendname); extern int account_remove_friend2(t_account * account, const char * friendname);
extern char const * race_get_str(unsigned int race); extern std::string race_get_str(unsigned int race);
extern int account_set_admin(t_account * account); extern int account_set_admin(t_account * account);
extern int account_set_demoteadmin(t_account * account); extern int account_set_demoteadmin(t_account * account);

View file

@ -253,7 +253,7 @@ namespace pvpgn
return; return;
} }
// check if where allready knows about ctag // check if where already knows about ctag
AdCtagRefMap::iterator cit2(where.find(adKey)); AdCtagRefMap::iterator cit2(where.find(adKey));
// if not register ctag // if not register ctag
if (cit2 == where.end()) if (cit2 == where.end())

View file

@ -1234,7 +1234,7 @@ namespace pvpgn
*/ */
/* opponent level calculation has to be done here, because later on, the level of other players /* opponent level calculation has to be done here, because later on, the level of other players
* may allready be modified * may already be modified
*/ */
for (i = 0; i < tp; i++) { for (i = 0; i < tp; i++) {
int j, k, l; int j, k, l;

View file

@ -289,37 +289,40 @@ namespace pvpgn
static int _send_msg(t_connection * conn, char const * command, char const * text) static int _send_msg(t_connection * conn, char const * command, char const * text)
{ {
t_packet * p; if (!conn)
char data[MAX_IRC_MESSAGE_LEN + 1]; {
char const * nick;
if (!conn) {
eventlog(eventlog_level_error, __FUNCTION__, "got NULL connection"); eventlog(eventlog_level_error, __FUNCTION__, "got NULL connection");
return -1; return -1;
} }
if (!command) { if (!command)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL command"); eventlog(eventlog_level_error, __FUNCTION__, "got NULL command");
return -1; return -1;
} }
if (!text) { if (!text)
{
eventlog(eventlog_level_error, __FUNCTION__, "got NULL text"); eventlog(eventlog_level_error, __FUNCTION__, "got NULL text");
return -1; return -1;
} }
if (!(p = packet_create(packet_class_raw))) {
t_packet * p = packet_create(packet_class_raw);
if (!p)
{
eventlog(eventlog_level_error, __FUNCTION__, "could not create packet"); eventlog(eventlog_level_error, __FUNCTION__, "could not create packet");
return -1; return -1;
} }
nick = conn_get_loggeduser(conn); const char *nick = conn_get_loggeduser(conn);
if (!nick) if (!nick)
nick = "UserName"; nick = "UserName";
std::snprintf(data, sizeof(data), ":matchbot!u@h %s %s %s", command, nick, text); std::string data(":matchbot!u@h " + std::string(command) + " " + std::string(nick) + " " + std::string(text));
data.erase(MAX_IRC_MESSAGE_LEN, std::string::npos);
DEBUG2("[%d] sent \"%s\"", conn_get_socket(conn), data); DEBUG2("[%d] sent \"%s\"", conn_get_socket(conn), data.c_str());
std::strcat(data, "\r\n"); data.append("\r\n");
packet_set_size(p, 0); packet_set_size(p, 0);
packet_append_data(p, data, std::strlen(data)); packet_append_data(p, data.c_str(), data.length());
conn_push_outqueue(conn, p); conn_push_outqueue(conn, p);
packet_del_ref(p); packet_del_ref(p);
return 0; return 0;
@ -391,37 +394,37 @@ namespace pvpgn
if ((player1 != player2) && ((conn_get_channel(conn_pl1)) == (conn_get_channel(conn_pl2)))) { if ((player1 != player2) && ((conn_get_channel(conn_pl1)) == (conn_get_channel(conn_pl2)))) {
switch (ctag) { switch (ctag) {
case CLIENTTAG_REDALERT2_UINT: { case CLIENTTAG_REDALERT2_UINT: {
random = rand(); random = rand();
if (std::strcmp(channelname, RAL2_CHANNEL_FFA) == 0) { if (std::strcmp(channelname, RAL2_CHANNEL_FFA) == 0) {
int pl1_colour = anongame_wol_player_get_colour(player1); int pl1_colour = anongame_wol_player_get_colour(player1);
int pl1_country = anongame_wol_player_get_country(player1); int pl1_country = anongame_wol_player_get_country(player1);
int pl2_colour = anongame_wol_player_get_colour(player2); int pl2_colour = anongame_wol_player_get_colour(player2);
int pl2_country = anongame_wol_player_get_country(player2); int pl2_country = anongame_wol_player_get_country(player2);
DEBUG0("Generating SOLO game for Red Alert 2"); DEBUG0("Generating SOLO game for Red Alert 2");
_get_pair(&pl1_colour, &pl2_colour, 7, true); _get_pair(&pl1_colour, &pl2_colour, 7, true);
_get_pair(&pl1_country, &pl2_country, 8, false); _get_pair(&pl1_country, &pl2_country, 8, false);
mapname = anongame_get_map_from_prefs(ANONGAME_TYPE_1V1, ctag); mapname = anongame_get_map_from_prefs(ANONGAME_TYPE_1V1, ctag);
/* We have madatory of game */ /* We have madatory of game */
std::snprintf(_temp, sizeof(_temp), ":Start %d,0,0,10000,0,1,0,1,1,0,1,x,2,1,165368,%s,1:", random, mapname); std::snprintf(_temp, sizeof(_temp), ":Start %d,0,0,10000,0,1,0,1,1,0,1,x,2,1,165368,%s,1:", random, mapname);
std::strcat(temp, _temp); std::strcat(temp, _temp);
/* GameHost informations */ /* GameHost informations */
std::snprintf(_temp, sizeof(_temp), "%s,%d,%d,%x,1,%x,", conn_get_chatname(conn_pl1), pl1_country, pl1_colour, anongame_wol_player_get_address(player1), anongame_wol_player_get_port(player1)); std::snprintf(_temp, sizeof(_temp), "%s,%d,%d,%x,1,%x,", conn_get_chatname(conn_pl1), pl1_country, pl1_colour, anongame_wol_player_get_address(player1), anongame_wol_player_get_port(player1));
std::strcat(temp, _temp); std::strcat(temp, _temp);
/* GameJoinie informations */ /* GameJoinie informations */
std::snprintf(_temp, sizeof(_temp), "%s,%d,%d,%x,1,%x", conn_get_chatname(conn_pl2), pl2_country, pl2_colour, anongame_wol_player_get_address(player2), anongame_wol_player_get_port(player2)); std::snprintf(_temp, sizeof(_temp), "%s,%d,%d,%x,1,%x", conn_get_chatname(conn_pl2), pl2_country, pl2_colour, anongame_wol_player_get_address(player2), anongame_wol_player_get_port(player2));
std::strcat(temp, _temp); std::strcat(temp, _temp);
_send_msg(conn_pl1, "PRIVMSG", temp); _send_msg(conn_pl1, "PRIVMSG", temp);
_send_msg(conn_pl2, "PRIVMSG", temp); _send_msg(conn_pl2, "PRIVMSG", temp);
} }
else else
ERROR1("undefined channel type for %s channel", channelname); ERROR1("undefined channel type for %s channel", channelname);
} }
return 0; return 0;
case CLIENTTAG_YURISREV_UINT: { case CLIENTTAG_YURISREV_UINT: {

View file

@ -181,7 +181,7 @@ namespace pvpgn
if (now == (std::time_t)0) /* zero means user logged out before expiration */ if (now == (std::time_t)0) /* zero means user logged out before expiration */
{ {
eventlog(eventlog_level_trace, __FUNCTION__, "[%d] connection allready closed", conn_get_socket(c)); eventlog(eventlog_level_trace, __FUNCTION__, "[%d] connection already closed", conn_get_socket(c));
return; return;
} }
@ -699,7 +699,7 @@ namespace pvpgn
lua_handle_user(c, NULL, NULL, luaevent_user_disconnect); lua_handle_user(c, NULL, NULL, luaevent_user_disconnect);
#endif #endif
if (account_get_conn(c->protocol.account) == c) /* make sure you don't set this when allready on new conn (relogin with same account) */ if (account_get_conn(c->protocol.account) == c) /* make sure you don't set this when already on new conn (relogin with same account) */
account_set_conn(c->protocol.account, NULL); account_set_conn(c->protocol.account, NULL);
c->protocol.account = NULL; /* the account code will free the memory later */ c->protocol.account = NULL; /* the account code will free the memory later */
} }
@ -1535,18 +1535,18 @@ namespace pvpgn
else { else {
unsigned int userid = 0; unsigned int userid = 0;
str_to_uint(&username[1], &userid); str_to_uint(&username[1], &userid);
if (userid != 0){ if (userid != 0)
if (prefs_get_account_force_username()){ {
if (prefs_get_account_force_username())
{
t_account* account = accountlist_find_account_by_uid(userid); t_account* account = accountlist_find_account_by_uid(userid);
temp = xstrdup(account_get_name(account)); temp = xstrdup(account_get_name(account));
} }
else{ else
char uid_string[MAX_USERNAME_LEN] = {}; temp = xstrdup(std::string("#" + userid).c_str());
std::snprintf(uid_string, sizeof(uid_string), "#%u", userid);
temp = xstrdup(uid_string);
}
} }
else{ //theoretically this should never happen... else
{ //theoretically this should never happen...
eventlog(eventlog_level_error, __FUNCTION__, "got invalid numeric uid \"%s\"", username); eventlog(eventlog_level_error, __FUNCTION__, "got invalid numeric uid \"%s\"", username);
// set value that would have been set prior to this bugfix... // set value that would have been set prior to this bugfix...
temp = xstrdup(username); temp = xstrdup(username);
@ -1922,15 +1922,13 @@ namespace pvpgn
if ((!clan) || (clan_get_clantag(clan) != clantag)) { if ((!clan) || (clan_get_clantag(clan) != clantag)) {
if (!channel) if (!channel)
{ {
char msgtemp[MAX_MESSAGE_LEN]; message_send_text(c, message_type_error, c, std::string("Unable to join channel " + std::string(channelname) + ", there is no member of that clan in the channel!").c_str());
std::snprintf(msgtemp, sizeof(msgtemp), "Unable to join channel %s, there is no member of that clan in the channel!", channelname);
message_send_text(c, message_type_error, c, msgtemp);
if (conn_get_game(c) || c->protocol.chat.channel == NULL) { if (conn_get_game(c) || c->protocol.chat.channel == NULL)
{
// FIXME: This is not tested to be according to battle.net!! // FIXME: This is not tested to be according to battle.net!!
// This is fix for empty clan channels with preventing to join CHANNEL_NAME_BANNED when is used _handle_join_command // This is fix for empty clan channels with preventing to join CHANNEL_NAME_BANNED when is used _handle_join_command
std::snprintf(msgtemp, sizeof(msgtemp), "You have been redirected to %s.", CHANNEL_NAME_BANNED); message_send_text(c, message_type_error, c, std::string("You have been redirected to " + std::string(CHANNEL_NAME_BANNED)).c_str());
message_send_text(c, message_type_error, c, msgtemp);
channel = channellist_find_channel_by_name(CHANNEL_NAME_BANNED, conn_get_country(c), realm_get_name(conn_get_realm(c))); channel = channellist_find_channel_by_name(CHANNEL_NAME_BANNED, conn_get_country(c), realm_get_name(conn_get_realm(c)));
} }
else else

View file

@ -1885,7 +1885,7 @@ namespace pvpgn
if (game->reported_results[i]) if (game->reported_results[i])
{ {
eventlog(eventlog_level_error, __FUNCTION__, "player \"%s\" allready reported results - skipping this report", account_get_name(account)); eventlog(eventlog_level_error, __FUNCTION__, "player \"%s\" already reported results - skipping this report", account_get_name(account));
return -1; return -1;
} }

View file

@ -1677,7 +1677,7 @@ namespace pvpgn
eventlog(eventlog_level_info, __FUNCTION__, "[%d] login for \"%s\" refused (already logged in)", conn_get_socket(c), username); eventlog(eventlog_level_info, __FUNCTION__, "[%d] login for \"%s\" refused (already logged in)", conn_get_socket(c), username);
if (supports_locked_reply) { if (supports_locked_reply) {
bn_int_set(&rpacket->u.server_loginreply1.message, SERVER_LOGINREPLY2_MESSAGE_LOCKED); bn_int_set(&rpacket->u.server_loginreply1.message, SERVER_LOGINREPLY2_MESSAGE_LOCKED);
packet_append_string(rpacket, "This account is allready logged in."); packet_append_string(rpacket, "This account is already logged in.");
} }
else { else {
bn_int_set(&rpacket->u.server_loginreply1.message, SERVER_LOGINREPLY2_MESSAGE_BADPASS); bn_int_set(&rpacket->u.server_loginreply1.message, SERVER_LOGINREPLY2_MESSAGE_BADPASS);
@ -2131,7 +2131,7 @@ namespace pvpgn
int i; int i;
const char * client_password_proof; const char * client_password_proof;
/* PELISH: This can not occur - We allready tested packet size which must be wrong firstly. /* PELISH: This can not occur - We already tested packet size which must be wrong firstly.
Also pvpgn will crash when will dereferencing NULL pointer (so we cant got this errorlog message) Also pvpgn will crash when will dereferencing NULL pointer (so we cant got this errorlog message)
I vote for deleting this "if" */ I vote for deleting this "if" */
if (!(client_password_proof = (const char*)packet_get_data_const(packet, offsetof(t_client_logonproofreq, client_password_proof), 20))) { if (!(client_password_proof = (const char*)packet_get_data_const(packet, offsetof(t_client_logonproofreq, client_password_proof), 20))) {
@ -2557,12 +2557,12 @@ namespace pvpgn
if (!(team = account_find_team_by_accounts(members[0], members, ctag))) { if (!(team = account_find_team_by_accounts(members[0], members, ctag))) {
team = create_team(members, ctag); //no need to free on return -1 because it's allready in teamlist team = create_team(members, ctag); //no need to free on return -1 because it's already in teamlist
eventlog(eventlog_level_trace, __FUNCTION__, "this team has never played before, creating new team"); eventlog(eventlog_level_trace, __FUNCTION__, "this team has never played before, creating new team");
} }
else { else {
eventlog(eventlog_level_trace, __FUNCTION__, "this team has allready played before"); eventlog(eventlog_level_trace, __FUNCTION__, "this team has already played before");
} }
teamid = team_get_teamid(team); teamid = team_get_teamid(team);
@ -3502,7 +3502,7 @@ namespace pvpgn
} }
if ((channel = conn_get_channel(c)) && (strcasecmp(channel_get_name(channel), cname) == 0)) if ((channel = conn_get_channel(c)) && (strcasecmp(channel_get_name(channel), cname) == 0))
return 0; //we are allready in this channel return 0; //we are already in this channel
std::string tmpstr; std::string tmpstr;
clienttag = conn_get_clienttag(c); clienttag = conn_get_clienttag(c);
@ -5125,12 +5125,12 @@ namespace pvpgn
(conn_account = conn_get_account(conn)))) { (conn_account = conn_get_account(conn)))) {
response_code = CLAN_RESPONSE_NOT_FOUND; response_code = CLAN_RESPONSE_NOT_FOUND;
// target user allready in a clan or creating a clan // target user already in a clan or creating a clan
} }
else if (account_get_clanmember_forced(conn_get_account(conn))) { else if (account_get_clanmember_forced(conn_get_account(conn))) {
response_code = CLAN_RESPONSE_NOT_FOUND; response_code = CLAN_RESPONSE_NOT_FOUND;
// clan allready full // clan allready ful
} }
else if (clan_get_member_count(clan) >= prefs_get_clan_max_members()) { else if (clan_get_member_count(clan) >= prefs_get_clan_max_members()) {
response_code = CLAN_RESPONSE_CLAN_FULL; response_code = CLAN_RESPONSE_CLAN_FULL;
@ -5232,14 +5232,17 @@ namespace pvpgn
clan_remove_member(clan, member); clan_remove_member(clan, member);
bn_byte_set(&rpacket->u.server_clan_invitereply.result, CLAN_RESPONSE_CLAN_FULL); bn_byte_set(&rpacket->u.server_clan_invitereply.result, CLAN_RESPONSE_CLAN_FULL);
} }
else { else
char channelname[10]; {
clanmember_set_fullmember(member, 1); clanmember_set_fullmember(member, 1);
std::snprintf(channelname, sizeof(channelname), "Clan %s", clantag_to_str(clan_get_clantag(clan))); if (conn_get_channel(c))
if (conn_get_channel(c)) { {
conn_update_w3_playerinfo(c); conn_update_w3_playerinfo(c);
channel_set_userflags(c); channel_set_userflags(c);
if (conn_set_channel(c, channelname) < 0) {
std::string channelname("Clan " + std::string(clantag_to_str(clan_get_clantag(clan))));
if (conn_set_channel(c, channelname.c_str()) < 0)
{
conn_set_channel(c, CHANNEL_NAME_BANNED); /* should not fail */ conn_set_channel(c, CHANNEL_NAME_BANNED); /* should not fail */
} }
clanmember_set_online(c); clanmember_set_online(c);

View file

@ -325,8 +325,7 @@ namespace pvpgn
bnet_hash(&passhash, std::strlen(pass), pass); bnet_hash(&passhash, std::strlen(pass), pass);
std::snprintf(msgtemp, sizeof(msgtemp), "Trying to create account \"%s\" with password \"%s\"", username, pass); message_send_text(conn, message_type_info, conn, std::string("Trying to create account \"" + std::string(username) + "\" with password \"" + std::string(pass) + "\"").c_str());
message_send_text(conn, message_type_info, conn, msgtemp);
temp = accountlist_create_account(username, hash_get_str(passhash)); temp = accountlist_create_account(username, hash_get_str(passhash));
if (!temp) { if (!temp) {
@ -336,16 +335,13 @@ namespace pvpgn
break; break;
} }
std::snprintf(msgtemp, sizeof(msgtemp), "Account " UID_FORMAT " created.", account_get_uid(temp)); message_send_text(conn, message_type_info, conn, std::string("Account #" + std::to_string(account_get_uid(temp)) + " created."));
message_send_text(conn, message_type_info, conn, msgtemp);
eventlog(eventlog_level_debug, __FUNCTION__, "[%d] account \"%s\" created", conn_get_socket(conn), username); eventlog(eventlog_level_debug, __FUNCTION__, "[%d] account \"%s\" created", conn_get_socket(conn), username);
conn_unget_chatname(conn, username); conn_unget_chatname(conn, username);
} }
else { else {
char tmp[MAX_IRC_MESSAGE_LEN + 1]; message_send_text(conn, message_type_notice, nullptr, "Invalid arguments for NICKSERV");
message_send_text(conn, message_type_notice, NULL, "Invalid arguments for NICKSERV"); message_send_text(conn, message_type_notice, nullptr, std::string(":Unrecognized command \"" + std::string(text) + "\"").c_str());
std::snprintf(tmp, sizeof(tmp), ":Unrecognized command \"%s\"", text);
message_send_text(conn, message_type_notice, NULL, tmp);
} }
} }
else if (conn_get_state(conn) == conn_state_loggedin) { else if (conn_get_state(conn) == conn_state_loggedin) {
@ -443,38 +439,30 @@ namespace pvpgn
static int _handle_list_command(t_connection * conn, int numparams, char ** params, char * text) static int _handle_list_command(t_connection * conn, int numparams, char ** params, char * text)
{ {
char temp[MAX_IRC_MESSAGE_LEN]; std::string tmp;
irc_send(conn, RPL_LISTSTART, "Channel :Users Names"); /* backward compatibility */ irc_send(conn, RPL_LISTSTART, "Channel :Users Names"); /* backward compatibility */
if (numparams == 0) { if (numparams == 0)
{
t_elem const * curr; t_elem const * curr;
class_topic Topic; class_topic Topic;
LIST_TRAVERSE_CONST(channellist(), curr) LIST_TRAVERSE_CONST(channellist(), curr)
{ {
t_channel const * channel = (const t_channel*)elem_get_data(curr); t_channel const * channel = (const t_channel*)elem_get_data(curr);
char const * tempname; char const * tempname = irc_convert_channel(channel, conn);
std::string topicstr = Topic.get(channel_get_name(channel)); std::string topicstr = Topic.get(channel_get_name(channel));
tempname = irc_convert_channel(channel, conn);
/* FIXME: AARON: only list channels like in /channels command */ /* FIXME: AARON: only list channels like in /channels command */
if (topicstr.empty() == false) { tmp = std::string(tempname) + " " + std::to_string(channel_get_length(channel)) + " :" + topicstr;
if (std::strlen(tempname) + 1 + 20 + 1 + 1 + std::strlen(topicstr.c_str()) < MAX_IRC_MESSAGE_LEN)
std::snprintf(temp, sizeof(temp), "%s %u :%s", tempname, channel_get_length(channel), topicstr.c_str()); if (tmp.length() > MAX_IRC_MESSAGE_LEN)
else eventlog(eventlog_level_warn, __FUNCTION__, "LISTREPLY length exceeded");
eventlog(eventlog_level_warn, __FUNCTION__, "LISTREPLY length exceeded");
} irc_send(conn, RPL_LIST, tmp.c_str());
else {
if (std::strlen(tempname) + 1 + 20 + 1 + 1 < MAX_IRC_MESSAGE_LEN)
std::snprintf(temp, sizeof(temp), "%s %u :", tempname, channel_get_length(channel));
else
eventlog(eventlog_level_warn, __FUNCTION__, "LISTREPLY length exceeded");
}
irc_send(conn, RPL_LIST, temp);
} }
} }
else if (numparams >= 1) { else if (numparams >= 1)
{
int i; int i;
char ** e; char ** e;
class_topic Topic; class_topic Topic;
@ -482,40 +470,33 @@ namespace pvpgn
e = irc_get_listelems(params[0]); e = irc_get_listelems(params[0]);
/* FIXME: support wildcards! */ /* FIXME: support wildcards! */
for (i = 0; ((e) && (e[i])); i++) { for (i = 0; ((e) && (e[i])); i++)
t_channel const * channel; {
char const * verytemp; /* another good example for creative naming conventions :) */ char const * verytemp = irc_convert_ircname(e[i]);
char const * tempname;
std::string topicstr;
verytemp = irc_convert_ircname(e[i]);
if (!verytemp) if (!verytemp)
continue; /* something is wrong with the name ... */ continue; /* something is wrong with the name ... */
channel = channellist_find_channel_by_name(verytemp, NULL, NULL);
t_channel const * channel = channellist_find_channel_by_name(verytemp, NULL, NULL);
if (!channel) if (!channel)
continue; /* channel doesn't exist */ continue; /* channel doesn't exist */
topicstr = Topic.get(channel_get_name(channel)); std::string topicstr = Topic.get(channel_get_name(channel));
tempname = irc_convert_channel(channel, conn); char const * tempname = irc_convert_channel(channel, conn);
if (topicstr.c_str()) { tmp = std::string(tempname) + " " + std::to_string(channel_get_length(channel)) + " :" + topicstr;
if (std::strlen(tempname) + 1 + 20 + 1 + 1 + std::strlen(topicstr.c_str()) < MAX_IRC_MESSAGE_LEN)
std::snprintf(temp, sizeof(temp), "%s %u :%s", tempname, channel_get_length(channel), topicstr.c_str()); if (tmp.length() > MAX_IRC_MESSAGE_LEN)
else eventlog(eventlog_level_warn, __FUNCTION__, "LISTREPLY length exceeded");
eventlog(eventlog_level_warn, __FUNCTION__, "LISTREPLY length exceeded");
} irc_send(conn, RPL_LIST, tmp.c_str());
else {
if (std::strlen(tempname) + 1 + 20 + 1 + 1 < MAX_IRC_MESSAGE_LEN)
std::snprintf(temp, sizeof(temp), "%s %u :", tempname, channel_get_length(channel));
else
eventlog(eventlog_level_warn, __FUNCTION__, "LISTREPLY length exceeded");
}
irc_send(conn, RPL_LIST, temp);
} }
if (e) if (e)
irc_unget_listelems(e); irc_unget_listelems(e);
} }
irc_send(conn, RPL_LISTEND, ":End of LIST command"); irc_send(conn, RPL_LISTEND, ":End of LIST command");
return 0; return 0;
} }
@ -589,30 +570,29 @@ namespace pvpgn
static int _handle_whois_command(t_connection * conn, int numparams, char ** params, char * text) static int _handle_whois_command(t_connection * conn, int numparams, char ** params, char * text)
{ {
char temp[MAX_IRC_MESSAGE_LEN]; std::string tmp;
char temp2[MAX_IRC_MESSAGE_LEN];
if (numparams >= 1) { if (numparams >= 1)
{
int i; int i;
char ** e; char ** e = irc_get_listelems(params[0]);
t_connection * c; t_connection * c;
t_channel * chan; t_channel * chan;
temp[0] = '\0'; for (i = 0; ((e) && (e[i])); i++)
temp2[0] = '\0'; {
e = irc_get_listelems(params[0]); if ((c = connlist_find_connection_by_accountname(e[i])))
for (i = 0; ((e) && (e[i])); i++) { {
if ((c = connlist_find_connection_by_accountname(e[i]))) {
if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(conn)) & command_get_group("/admin-addr"))) if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(conn)) & command_get_group("/admin-addr")))
std::snprintf(temp, sizeof(temp), "%s %s hidden * :%s", e[i], clienttag_uint_to_str(conn_get_clienttag(c)), "PvPGN user"); tmp = std::string(e[i]) + " " + std::string(clienttag_uint_to_str(conn_get_clienttag(c))) + " hidden * :PvPGN user";
else else
std::snprintf(temp, sizeof(temp), "%s %s %s * :%s", e[i], clienttag_uint_to_str(conn_get_clienttag(c)), addr_num_to_ip_str(conn_get_addr(c)), "PvPGN user"); tmp = std::string(e[i]) + " " + std::string(clienttag_uint_to_str(conn_get_clienttag(c))) + " " + std::string(addr_num_to_ip_str(conn_get_addr(c))) + " * :PvPGN user";
irc_send(conn, RPL_WHOISUSER, temp); irc_send(conn, RPL_WHOISUSER, tmp.c_str());
if ((chan = conn_get_channel(conn))) { if ((chan = conn_get_channel(conn)))
char flg; {
unsigned int flags; std::string flg;
auto flags = conn_get_flags(c);
flags = conn_get_flags(c);
if (flags & MF_BLIZZARD) if (flags & MF_BLIZZARD)
flg = '@'; flg = '@';
@ -620,9 +600,11 @@ namespace pvpgn
flg = '%'; flg = '%';
else if (flags & MF_VOICE) else if (flags & MF_VOICE)
flg = '+'; flg = '+';
else flg = ' '; else
std::snprintf(temp2, sizeof(temp2), "%s :%c%s", e[i], flg, irc_convert_channel(chan, conn)); flg = ' ';
irc_send(conn, RPL_WHOISCHANNELS, temp2);
tmp = std::string(e[i]) + " :" + flg + std::string(irc_convert_channel(chan, conn));
irc_send(conn, RPL_WHOISCHANNELS, tmp.c_str());
} }
} }

View file

@ -258,18 +258,16 @@ namespace pvpgn
} }
if (handle_irc_common_con_command(conn, command, numparams, params, text) != -1) {} if (handle_irc_common_con_command(conn, command, numparams, params, text) != -1) {}
else if (conn_get_state(conn) != conn_state_loggedin) { else if (conn_get_state(conn) != conn_state_loggedin)
char temp[MAX_IRC_MESSAGE_LEN + 1]; {
std::string tmp(":Unrecognized command \"" + std::string(command) + "\" (before login)");
if ((38 + std::strlen(command) + 16 + 1) < sizeof(temp)) { if (tmp.length() > MAX_IRC_MESSAGE_LEN)
std::snprintf(temp, sizeof(temp), ":Unrecognized command \"%s\" (before login)", command); irc_send(conn, ERR_UNKNOWNCOMMAND, tmp.c_str());
irc_send(conn, ERR_UNKNOWNCOMMAND, temp); else
}
else {
irc_send(conn, ERR_UNKNOWNCOMMAND, ":Unrecognized command (before login)"); irc_send(conn, ERR_UNKNOWNCOMMAND, ":Unrecognized command (before login)");
}
} }
else { else
{
/* command is handled later */ /* command is handled later */
unrecognized_before = 1; unrecognized_before = 1;
} }

View file

@ -233,11 +233,12 @@ namespace pvpgn
tempapgar = conn_wol_get_apgar(conn); tempapgar = conn_wol_get_apgar(conn);
temphash = account_get_wol_apgar(a); temphash = account_get_wol_apgar(a);
if (connlist_find_connection_by_account(a) && prefs_get_kick_old_login() == 0) { if (connlist_find_connection_by_account(a) && prefs_get_kick_old_login() == 0)
std::snprintf(temp, sizeof(temp), "%s :Account is already in use!", conn_get_loggeduser(conn)); {
irc_send(conn, ERR_NICKNAMEINUSE, temp); irc_send(conn, ERR_NICKNAMEINUSE, std::string(std::string(conn_get_loggeduser(conn)) + " :Account is already in use!").c_str());
} }
else if (account_get_auth_lock(a) == 1) { else if (account_get_auth_lock(a) == 1)
{
/* FIXME: Send real error code */ /* FIXME: Send real error code */
message_send_text(conn, message_type_notice, NULL, "Authentication rejected (account is locked) "); message_send_text(conn, message_type_notice, NULL, "Authentication rejected (account is locked) ");
} }
@ -280,29 +281,28 @@ namespace pvpgn
static int handle_wol_send_claninfo(t_connection * conn, t_clan * clan) static int handle_wol_send_claninfo(t_connection * conn, t_clan * clan)
{ {
char _temp[MAX_IRC_MESSAGE_LEN];
unsigned int clanid; unsigned int clanid;
const char * clantag; const char * clantag;
const char * clanname; const char * clanname;
std::memset(_temp, 0, sizeof(_temp)); if (!conn)
{
if (!conn) {
ERROR0("got NULL connection"); ERROR0("got NULL connection");
return -1; return -1;
} }
if (clan) { if (clan)
{
clanid = clan_get_clanid(clan); clanid = clan_get_clanid(clan);
clantag = clantag_to_str(clan_get_clantag(clan)); clantag = clantag_to_str(clan_get_clantag(clan));
clanname = clan_get_name(clan); clanname = clan_get_name(clan);
std::snprintf(_temp, sizeof(_temp), "%u`%s`%s`0`0`1`0`0`0`0`0`0`0`x`x`x", clanid, clanname, clantag); irc_send(conn, RPL_BATTLECLAN, std::string(std::to_string(clanid) + "`" + std::string(clanname) + "`" + std::string(clantag) + "`0`0`1`0`0`0`0`0`0`0`x`x`x").c_str());
irc_send(conn, RPL_BATTLECLAN, _temp);
} }
else { else
std::snprintf(_temp, sizeof(_temp), ":ID does not exist"); {
irc_send(conn, ERR_IDNOEXIST, _temp); irc_send(conn, ERR_IDNOEXIST, ":ID does not exist");
} }
return 0; return 0;
} }
@ -420,8 +420,7 @@ namespace pvpgn
} }
} }
else { else {
std::snprintf(msgtemp, sizeof(msgtemp), "%s :No such channel", e[0]); irc_send(conn, ERR_NOSUCHCHANNEL, std::string(std::string(e[0]) + " :No such channel").c_str());
irc_send(conn, ERR_NOSUCHCHANNEL, msgtemp);
} }
} }
else { else {
@ -717,17 +716,19 @@ namespace pvpgn
* :[servername] 379 [username] :none none none [oldversnum] [SKU] REQ * :[servername] 379 [username] :none none none [oldversnum] [SKU] REQ
*/ */
if (numparams == 2) { if (numparams == 2)
{
clienttag = tag_sku_to_uint(std::atoi(params[0])); clienttag = tag_sku_to_uint(std::atoi(params[0]));
if (clienttag != CLIENTTAG_WWOL_UINT) if (clienttag != CLIENTTAG_WWOL_UINT)
conn_set_clienttag(conn, clienttag); conn_set_clienttag(conn, clienttag);
std::snprintf(temp, sizeof(temp), ":none none none 1 %s NONREQ", params[0]); std::string tmp(":none none none 1 " + std::string(params[0]) + " NONREQ");
eventlog(eventlog_level_debug, __FUNCTION__, "[** WOL **] VERCHK %s", temp); eventlog(eventlog_level_debug, __FUNCTION__, "[** WOL **] VERCHK %s", tmp.c_str());
irc_send(conn, RPL_VERCHK_NONREQ, temp); irc_send(conn, RPL_VERCHK_NONREQ, tmp.c_str());
} }
else else
irc_send(conn, ERR_NEEDMOREPARAMS, "VERCHK :Not enough parameters"); irc_send(conn, ERR_NEEDMOREPARAMS, "VERCHK :Not enough parameters");
return 0; return 0;
} }
@ -829,28 +830,24 @@ namespace pvpgn
static int _handle_getcodepage_command(t_connection * conn, int numparams, char ** params, char * text) static int _handle_getcodepage_command(t_connection * conn, int numparams, char ** params, char * text)
{ {
char temp[MAX_IRC_MESSAGE_LEN]; std::string temp;
char _temp[MAX_IRC_MESSAGE_LEN];
std::memset(temp, 0, sizeof(temp)); if ((numparams >= 1) && (params[0]))
std::memset(_temp, 0, sizeof(_temp)); {
for (auto i = 0; i < numparams; i++)
if ((numparams >= 1) && (params[0])) { {
int i;
for (i = 0; i < numparams; i++) {
t_connection * user;
int codepage = 0; int codepage = 0;
t_connection * user = connlist_find_connection_by_accountname(params[i]);
if (user = connlist_find_connection_by_accountname(params[i])) if (user)
codepage = conn_wol_get_codepage(user); codepage = conn_wol_get_codepage(user);
std::snprintf(_temp, sizeof(_temp), "%s`%u", params[i], codepage); temp.append(std::string(params[i]) + "`" + std::to_string(codepage));
std::strcat(temp, _temp);
if (i < numparams - 1) if (i < numparams - 1)
std::strcat(temp, "`"); temp.append("`");
} }
irc_send(conn, RPL_GET_CODEPAGE, temp);
irc_send(conn, RPL_GET_CODEPAGE, temp.c_str());
} }
else else
irc_send(conn, ERR_NEEDMOREPARAMS, "GETCODEPAGE :Not enough parameters"); irc_send(conn, ERR_NEEDMOREPARAMS, "GETCODEPAGE :Not enough parameters");
@ -874,27 +871,22 @@ namespace pvpgn
static int _handle_getlocale_command(t_connection * conn, int numparams, char ** params, char * text) static int _handle_getlocale_command(t_connection * conn, int numparams, char ** params, char * text)
{ {
char temp[MAX_IRC_MESSAGE_LEN]; std::string temp;
char _temp[MAX_IRC_MESSAGE_LEN];
std::memset(temp, 0, sizeof(temp)); if ((numparams >= 1) && (params[0]))
std::memset(_temp, 0, sizeof(_temp)); {
for (auto i = 0; i < numparams; i++)
if ((numparams >= 1) && (params[0])) { {
int i;
for (i = 0; i < numparams; i++) {
t_account * account;
int locale = 0; int locale = 0;
t_account * account = accountlist_find_account(params[i]);
if (account = accountlist_find_account(params[i])) if (account)
locale = account_get_locale(account); locale = account_get_locale(account);
std::snprintf(_temp, sizeof(_temp), "%s`%u", params[i], locale); temp.append(std::string(params[i]) + "`" + std::to_string(locale));
std::strcat(temp, _temp);
if (i < numparams - 1) if (i < numparams - 1)
std::strcat(temp, "`"); temp.append("`");
} }
irc_send(conn, RPL_GET_LOCALE, temp); irc_send(conn, RPL_GET_LOCALE, temp.c_str());
} }
else else
irc_send(conn, ERR_NEEDMOREPARAMS, "GETLOCALE :Not enough parameters"); irc_send(conn, ERR_NEEDMOREPARAMS, "GETLOCALE :Not enough parameters");
@ -903,8 +895,6 @@ namespace pvpgn
static int _handle_getinsider_command(t_connection * conn, int numparams, char ** params, char * text) static int _handle_getinsider_command(t_connection * conn, int numparams, char ** params, char * text)
{ {
char _temp[MAX_IRC_MESSAGE_LEN];
/** /**
* Here is imput expected: * Here is imput expected:
* GETINSIDER [nickname] * GETINSIDER [nickname]
@ -912,14 +902,11 @@ namespace pvpgn
* :[servername] 399 [nick] [nickname]`0 * :[servername] 399 [nick] [nickname]`0
*/ */
std::memset(_temp, 0, sizeof(_temp)); if ((numparams >= 1) && (params[0]))
irc_send(conn, RPL_GET_INSIDER, std::string(std::string(params[0]) + "`0").c_str());
if ((numparams >= 1) && (params[0])) {
std::snprintf(_temp, sizeof(_temp), "%s`%u", params[0], 0);
irc_send(conn, RPL_GET_INSIDER, _temp);
}
else else
irc_send(conn, ERR_NEEDMOREPARAMS, "GETINSIDER :Not enough parameters"); irc_send(conn, ERR_NEEDMOREPARAMS, "GETINSIDER :Not enough parameters");
return 0; return 0;
} }
@ -970,52 +957,63 @@ namespace pvpgn
return 0; return 0;
} }
if (!(gamename) || !(game = gamelist_find_game_available(gamename, conn_get_clienttag(conn), game_type_all))) { if (!(gamename) || !(game = gamelist_find_game_available(gamename, conn_get_clienttag(conn), game_type_all)))
std::snprintf(_temp, sizeof(_temp), "%s :Game channel has closed", e[0]); {
irc_send(conn, ERR_GAMEHASCLOSED, _temp); irc_send(conn, ERR_GAMEHASCLOSED, std::string(std::string(e[0]) + " :Game channel has closed").c_str());
if (e) if (e)
irc_unget_listelems(e); irc_unget_listelems(e);
return 0; return 0;
} }
channel = game_get_channel(game); channel = game_get_channel(game);
if (game_get_ref(game) == game_get_maxplayers(game)) { if (game_get_ref(game) == game_get_maxplayers(game))
std::snprintf(_temp, sizeof(_temp), "%s :Channel is full", e[0]); {
irc_send(conn, ERR_CHANNELISFULL, _temp); irc_send(conn, ERR_CHANNELISFULL, std::string(std::string(e[0]) + " :Channel is full.").c_str());
if (e) if (e)
irc_unget_listelems(e); irc_unget_listelems(e);
return 0; return 0;
} }
if (channel_check_banning(channel, conn)) { if (channel_check_banning(channel, conn))
std::snprintf(_temp, sizeof(_temp), "%s :You are banned from that channel.", e[0]); {
irc_send(conn, ERR_BANNEDFROMCHAN, _temp); irc_send(conn, ERR_BANNEDFROMCHAN, std::string(std::string(e[0]) + " :You are banned from that channel.").c_str());
if (e) if (e)
irc_unget_listelems(e); irc_unget_listelems(e);
return 0; return 0;
} }
if (std::strcmp(game_get_pass(game), "") != 0) { if (std::strcmp(game_get_pass(game), "") != 0)
if ((numparams == 3) && (params[2]) && (std::strcmp(params[2], game_get_pass(game)) == 0)) { {
strcpy(gamepass, params[2]); if ((numparams == 3) && (params[2]) && (std::strcmp(params[2], game_get_pass(game)) == 0))
{
std::strcpy(gamepass, params[2]);
} }
else { else
std::snprintf(_temp, sizeof(_temp), "%s :Bad password", e[0]); {
irc_send(conn, ERR_BADCHANNELKEY, _temp); irc_send(conn, ERR_BADCHANNELKEY, std::string(std::string(e[0]) + ":Bad password").c_str());
if (e) if (e)
irc_unget_listelems(e); irc_unget_listelems(e);
return 0; return 0;
} }
} }
gametype = game_get_type(game); gametype = game_get_type(game);
if ((conn_set_game(conn, gamename, gamepass, "", gametype, 0)) < 0) { if ((conn_set_game(conn, gamename, gamepass, "", gametype, 0)) < 0)
std::snprintf(_temp, sizeof(_temp), "%s :JOINGAME failed", e[0]); {
irc_send(conn, ERR_GAMEHASCLOSED, _temp); irc_send(conn, ERR_GAMEHASCLOSED, std::string(std::string(e[0]) + " :JOINGAME failed").c_str());
} }
else { else
{
/*conn_set_channel()*/ /*conn_set_channel()*/
channel = game_get_channel(game); channel = game_get_channel(game);
conn_set_channel_var(conn, channel); conn_set_channel_var(conn, channel);
@ -1048,9 +1046,9 @@ namespace pvpgn
irc_send_rpl_namreply(conn, channel); irc_send_rpl_namreply(conn, channel);
} }
else { else
std::snprintf(_temp, sizeof(_temp), "%s :JOINGAME failed", e[0]); {
irc_send(conn, ERR_GAMEHASCLOSED, _temp); irc_send(conn, ERR_GAMEHASCLOSED, std::string(std::string(e[0]) + " :JOINGAME failed").c_str());
} }
} }
} }

View file

@ -32,6 +32,7 @@
#include <map> #include <map>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include <vector>
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
# include <sys/stat.h> # include <sys/stat.h>
@ -65,10 +66,10 @@ namespace pvpgn
static t_xplevel_entry * xplevels; static t_xplevel_entry * xplevels;
int w3_xpcalc_maxleveldiff; int w3_xpcalc_maxleveldiff;
const char * ladder_id_str[] = { "0", "1", "", "3", "", "solo", "team", "ffa" }; const std::vector<std::string> ladder_id_str = { "0", "1", "", "3", "", "solo", "team", "ffa" };
const char * bin_ladder_id_str[] = { "", "", "", "I", "", "SOLO", "TEAM", "FFA", "AT" }; const std::vector<std::string> bin_ladder_id_str = { "", "", "", "I", "", "SOLO", "TEAM", "FFA", "AT" };
const char * bin_ladder_sort_str[] = { "R", "W", "G", "" }; const std::vector<std::string> bin_ladder_sort_str = { "R", "W", "G", "" };
const char * bin_ladder_time_str[] = { "A", "C", "" }; const std::vector<std::string> bin_ladder_time_str = { "A", "C", "" };
Ladders ladders; Ladders ladders;
@ -955,9 +956,9 @@ namespace pvpgn
{ {
ladderFilename = clienttag_uint_to_str(ladderKey_.getClienttag()); ladderFilename = clienttag_uint_to_str(ladderKey_.getClienttag());
ladderFilename += "_"; ladderFilename += "_";
ladderFilename += bin_ladder_time_str[ladderKey_.getLadderTime()]; ladderFilename += bin_ladder_time_str.at(static_cast<size_t>(ladderKey_.getLadderTime()));
ladderFilename += bin_ladder_sort_str[ladderKey_.getLadderSort()]; ladderFilename += bin_ladder_sort_str.at(static_cast<size_t>(ladderKey_.getLadderSort()));
ladderFilename += bin_ladder_id_str[ladderKey_.getLadderId()]; ladderFilename += bin_ladder_id_str.at(static_cast<size_t>(ladderKey_.getLadderId()));
ladderFilename += "_LADDER"; ladderFilename += "_LADDER";
} }

View file

@ -44,7 +44,7 @@ namespace pvpgn
ladder_sort_default ladder_sort_default
} t_ladder_sort; } t_ladder_sort;
extern const char * bin_ladder_sort_str[]; extern const std::vector<std::string> bin_ladder_sort_str;
typedef enum typedef enum
{ {
@ -53,7 +53,7 @@ namespace pvpgn
ladder_time_default ladder_time_default
} t_ladder_time; } t_ladder_time;
extern const char * bin_ladder_time_str[]; extern const std::vector<std::string> bin_ladder_time_str;
typedef enum typedef enum
{ {
@ -66,8 +66,8 @@ namespace pvpgn
ladder_id_ateam = 8 ladder_id_ateam = 8
} t_ladder_id; } t_ladder_id;
const extern char * ladder_id_str[]; const extern std::vector<std::string> ladder_id_str;
const extern char * bin_ladder_id_str[]; const extern std::vector<std::string> bin_ladder_id_str;
typedef enum typedef enum
{ {

View file

@ -154,7 +154,7 @@ static void oom_free(void)
FILE *hexstrm = NULL; FILE *hexstrm = NULL;
char serviceLongName[] = "PvPGN service"; char serviceLongName[] = PVPGN_SOFTWARE " service";
char serviceName[] = "pvpgn"; char serviceName[] = "pvpgn";
char serviceDescription[] = "Player vs. Player Gaming Network - Server"; char serviceDescription[] = "Player vs. Player Gaming Network - Server";

View file

@ -21,6 +21,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <string>
#include "common/eventlog.h" #include "common/eventlog.h"
#include "common/xalloc.h" #include "common/xalloc.h"
@ -88,9 +89,7 @@ namespace pvpgn
extern const char* conf_get_int(unsigned ival) extern const char* conf_get_int(unsigned ival)
{ {
static char tmpbuf[128]; return std::to_string(ival).c_str();
std::snprintf(tmpbuf, sizeof(tmpbuf), "%u", ival);
return tmpbuf;
} }
extern const char* conf_get_bool(unsigned ival) extern const char* conf_get_bool(unsigned ival)

View file

@ -201,10 +201,10 @@ const char * const BNETD_SERV_ADDRS = ""; /* this means none */
const int BNETD_SERV_PORT = 6112; const int BNETD_SERV_PORT = 6112;
const char * const BNETD_W3ROUTE_ADDR = "0.0.0.0"; const char * const BNETD_W3ROUTE_ADDR = "0.0.0.0";
const int BNETD_W3ROUTE_PORT = 6200; const int BNETD_W3ROUTE_PORT = 6200;
const char * const BNETD_SERVERNAME = "PvPGN Realm"; const char * const BNETD_SERVERNAME = PVPGN_SOFTWARE " Realm";
const char * const BNETD_IRC_ADDRS = ""; /* this means none */ const char * const BNETD_IRC_ADDRS = ""; /* this means none */
const int BNETD_IRC_PORT = 6667; /* used if port not specified */ const int BNETD_IRC_PORT = 6667; /* used if port not specified */
const char * const BNETD_IRC_NETWORK_NAME = "PvPGN"; const char * const BNETD_IRC_NETWORK_NAME = PVPGN_SOFTWARE;
const char * const BNETD_TRACK_ADDRS = "track.pvpgn.org"; const char * const BNETD_TRACK_ADDRS = "track.pvpgn.org";
const int BNETD_TRACK_PORT = 6114; /* use this port if not specified */ const int BNETD_TRACK_PORT = 6114; /* use this port if not specified */
const int BNETD_DEF_TEST_PORT = 6112; /* default guess for UDP test port */ const int BNETD_DEF_TEST_PORT = 6112; /* default guess for UDP test port */

View file

@ -24,6 +24,8 @@
#include "winmain.h" #include "winmain.h"
#include <cstdio> #include <cstdio>
#include <cstring>
#include <string>
#include <windows.h> #include <windows.h>
#if _DEBUG #if _DEBUG
#include <dbghelp.h> #include <dbghelp.h>
@ -32,7 +34,6 @@
#include <winuser.h> #include <winuser.h>
#include <process.h> #include <process.h>
#include <richedit.h> #include <richedit.h>
#include <cstring>
#include <commctrl.h> #include <commctrl.h>
#include <time.h> #include <time.h>
@ -71,7 +72,8 @@ namespace pvpgn
static void guiThread(void*); static void guiThread(void*);
static void guiAddText(const char *, COLORREF); static void guiAddText(const char *, COLORREF);
static void guiAddText_user(const char *, COLORREF); static void guiAddText_user(const char *, COLORREF);
static void guiDEAD(char*); static void guiDEAD(std::string msg);
static void guiDEAD(char* msg);
static void guiMoveWindow(HWND, RECT*); static void guiMoveWindow(HWND, RECT*);
static void guiClearLogWindow(void); static void guiClearLogWindow(void);
static void guiKillTrayIcon(void); static void guiKillTrayIcon(void);
@ -159,7 +161,8 @@ namespace pvpgn
wc.lpszClassName = "BnetdWndClass"; wc.lpszClassName = "BnetdWndClass";
wc.hIconSm = NULL; wc.hIconSm = NULL;
if (!RegisterClassEx(&wc)) guiDEAD("cant register WNDCLASS"); if (!RegisterClassEx(&wc))
guiDEAD("cant register WNDCLASS");
gui.hwnd = CreateWindowEx( gui.hwnd = CreateWindowEx(
0, 0,
@ -175,7 +178,8 @@ namespace pvpgn
(HINSTANCE)param, (HINSTANCE)param,
NULL); NULL);
if (!gui.hwnd) guiDEAD("cant create window"); if (!gui.hwnd)
guiDEAD("cant create window");
ShowWindow(gui.hwnd, SW_SHOW); ShowWindow(gui.hwnd, SW_SHOW);
SetEvent(gui.event_ready); SetEvent(gui.event_ready);
@ -228,7 +232,8 @@ namespace pvpgn
0, 0,
NULL); NULL);
if (!ghwndConsole) return FALSE; if (!ghwndConsole)
return FALSE;
gui.hwndUsers = CreateWindowEx( gui.hwndUsers = CreateWindowEx(
WS_EX_CLIENTEDGE, WS_EX_CLIENTEDGE,
@ -242,7 +247,8 @@ namespace pvpgn
0, 0,
NULL); NULL);
if (!gui.hwndUsers) return FALSE; if (!gui.hwndUsers)
return FALSE;
//amadeo: temp. button for useredit until rightcklick is working.... //amadeo: temp. button for useredit until rightcklick is working....
gui.hwndUserEditButton = CreateWindow( gui.hwndUserEditButton = CreateWindow(
@ -256,7 +262,8 @@ namespace pvpgn
0, 0,
NULL); NULL);
if (!gui.hwndUserEditButton) return FALSE; if (!gui.hwndUserEditButton)
return FALSE;
gui.hwndUserCount = CreateWindowEx( gui.hwndUserCount = CreateWindowEx(
WS_EX_CLIENTEDGE, WS_EX_CLIENTEDGE,
@ -270,13 +277,14 @@ namespace pvpgn
0, 0,
NULL); NULL);
if (!gui.hwndUserCount) return FALSE; if (!gui.hwndUserCount)
return FALSE;
SendMessage(gui.hwndUserCount, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0); SendMessage(gui.hwndUserCount, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
SendMessage(gui.hwndUsers, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0); SendMessage(gui.hwndUsers, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
SendMessage(gui.hwndUserEditButton, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0); SendMessage(gui.hwndUserEditButton, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
BringWindowToTop(gui.hwndUsers); BringWindowToTop(gui.hwndUsers);
strcpy(gui.szDefaultStatus, "Void"); std::strcpy(gui.szDefaultStatus, "Void");
gui.y_ratio = (100 << 10) / 100; gui.y_ratio = (100 << 10) / 100;
gui.x_ratio = (0 << 10) / 100; gui.x_ratio = (0 << 10) / 100;
@ -346,20 +354,24 @@ namespace pvpgn
static int guiOnShellNotify(int uID, int uMessage) static int guiOnShellNotify(int uID, int uMessage)
{ {
if (uID == IDI_TRAY) { if (uID == IDI_TRAY)
if (uMessage == WM_LBUTTONDBLCLK) { {
if (uMessage == WM_LBUTTONDBLCLK)
{
if (!IsWindowVisible(gui.hwnd)) if (!IsWindowVisible(gui.hwnd))
ShowWindow(gui.hwnd, SW_RESTORE); ShowWindow(gui.hwnd, SW_RESTORE);
SetForegroundWindow(gui.hwnd); SetForegroundWindow(gui.hwnd);
} }
else if (uMessage == WM_RBUTTONDOWN) { else if (uMessage == WM_RBUTTONDOWN)
{
POINT cp; POINT cp;
GetCursorPos(&cp); GetCursorPos(&cp);
SetForegroundWindow(gui.hwnd); SetForegroundWindow(gui.hwnd);
TrackPopupMenu(gui.hmenuTray, TPM_LEFTALIGN | TPM_LEFTBUTTON, cp.x, cp.y, 0, gui.hwnd, NULL); TrackPopupMenu(gui.hmenuTray, TPM_LEFTALIGN | TPM_LEFTBUTTON, cp.x, cp.y, 0, gui.hwnd, NULL);
} }
} }
return 0; return 0;
} }
@ -385,11 +397,13 @@ namespace pvpgn
static void guiOnClose(HWND hwnd) static void guiOnClose(HWND hwnd)
{ {
guiKillTrayIcon(); guiKillTrayIcon();
if (!gui.main_finished) { if (!gui.main_finished)
{
eventlog(eventlog_level_debug, __FUNCTION__, "GUI wants server dead..."); eventlog(eventlog_level_debug, __FUNCTION__, "GUI wants server dead...");
exit(0); std::exit(0);
} }
else { else
{
eventlog(eventlog_level_debug, __FUNCTION__, "GUI wants to exit..."); eventlog(eventlog_level_debug, __FUNCTION__, "GUI wants to exit...");
eventlog_close(); eventlog_close();
SetEvent(gui.event_ready); SetEvent(gui.event_ready);
@ -400,7 +414,8 @@ namespace pvpgn
{ {
int cy_console, cy_edge, cx_edge, cy_frame, cy_status; int cy_console, cy_edge, cx_edge, cy_frame, cy_status;
if (state == SIZE_MINIMIZED) { if (state == SIZE_MINIMIZED)
{
NOTIFYICONDATA dta; NOTIFYICONDATA dta;
dta.cbSize = sizeof(NOTIFYICONDATA); dta.cbSize = sizeof(NOTIFYICONDATA);
@ -409,15 +424,14 @@ namespace pvpgn
dta.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; dta.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
dta.uCallbackMessage = WM_SHELLNOTIFY; dta.uCallbackMessage = WM_SHELLNOTIFY;
dta.hIcon = LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(IDI_ICON1)); dta.hIcon = LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(IDI_ICON1));
strcpy(dta.szTip, "PvPGN"); std::strcpy(dta.szTip, std::string(std::string(PVPGN_SOFTWARE) + " " + std::string(PVPGN_VERSION)).c_str());
strcat(dta.szTip, " ");
strcat(dta.szTip, PVPGN_VERSION);
Shell_NotifyIcon(NIM_ADD, &dta); Shell_NotifyIcon(NIM_ADD, &dta);
ShowWindow(hwnd, SW_HIDE); ShowWindow(hwnd, SW_HIDE);
return; return;
} }
if (state == SIZE_RESTORED) { if (state == SIZE_RESTORED)
{
NOTIFYICONDATA dta; NOTIFYICONDATA dta;
dta.hWnd = hwnd; dta.hWnd = hwnd;
@ -456,7 +470,8 @@ namespace pvpgn
{ {
POINT p; POINT p;
if (hwnd == hwndCursor && codeHitTest == HTCLIENT) { if (hwnd == hwndCursor && codeHitTest == HTCLIENT)
{
GetCursorPos(&p); GetCursorPos(&p);
ScreenToClient(hwnd, &p); ScreenToClient(hwnd, &p);
if (PtInRect(&gui.rectHDivider, p)) if (PtInRect(&gui.rectHDivider, p))
@ -475,7 +490,8 @@ namespace pvpgn
p.x = x; p.x = x;
p.y = y; p.y = y;
if (PtInRect(&gui.rectHDivider, p)) { if (PtInRect(&gui.rectHDivider, p))
{
SetCapture(hwnd); SetCapture(hwnd);
gui.mode |= MODE_HDIVIDE; gui.mode |= MODE_HDIVIDE;
} }
@ -497,7 +513,8 @@ namespace pvpgn
int offset, cy_console, cy_users; int offset, cy_console, cy_users;
RECT r; RECT r;
if (gui.mode & MODE_HDIVIDE) { if (gui.mode & MODE_HDIVIDE)
{
offset = y - gui.rectHDivider.top; offset = y - gui.rectHDivider.top;
if (!offset) return; if (!offset) return;
cy_console = gui.rectConsole.bottom - gui.rectConsole.top; cy_console = gui.rectConsole.bottom - gui.rectConsole.top;
@ -552,7 +569,6 @@ namespace pvpgn
t_connection * c; t_connection * c;
t_elem const * curr; t_elem const * curr;
t_account * acc; t_account * acc;
char UserCount[80];
SendMessage(gui.hwndUsers, LB_RESETCONTENT, 0, 0); SendMessage(gui.hwndUsers, LB_RESETCONTENT, 0, 0);
@ -564,9 +580,8 @@ namespace pvpgn
SendMessage(gui.hwndUsers, LB_ADDSTRING, 0, (LPARAM)account_get_name(acc)); SendMessage(gui.hwndUsers, LB_ADDSTRING, 0, (LPARAM)account_get_name(acc));
} }
sprintf(UserCount, "%d", connlist_login_get_length()); std::string UserCount(std::to_string(connlist_login_get_length()) + " user(s) online:");
strcat(UserCount, " user(s) online:"); SendMessage(gui.hwndUserCount, WM_SETTEXT, 0, (LPARAM)UserCount.c_str());
SendMessage(gui.hwndUserCount, WM_SETTEXT, 0, (LPARAM)UserCount);
} }
static void guiAddText(const char *str, COLORREF clr) static void guiAddText(const char *str, COLORREF clr)
@ -577,7 +592,8 @@ namespace pvpgn
CHARFORMAT fmt; CHARFORMAT fmt;
text_length = SendMessage(ghwndConsole, WM_GETTEXTLENGTH, 0, 0); text_length = SendMessage(ghwndConsole, WM_GETTEXTLENGTH, 0, 0);
if (text_length > 30000) { if (text_length > 30000)
{
ds.cpMin = 0; ds.cpMin = 0;
ds.cpMax = text_length - 30000; ds.cpMax = text_length - 30000;
SendMessage(ghwndConsole, EM_EXSETSEL, 0, (LPARAM)&ds); SendMessage(ghwndConsole, EM_EXSETSEL, 0, (LPARAM)&ds);
@ -594,17 +610,15 @@ namespace pvpgn
fmt.yHeight = 160; fmt.yHeight = 160;
fmt.dwEffects = 0; fmt.dwEffects = 0;
fmt.crTextColor = clr; fmt.crTextColor = clr;
strcpy(fmt.szFaceName, "Courier New"); std::strcpy(fmt.szFaceName, "Courier New");
SendMessage(ghwndConsole, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt); SendMessage(ghwndConsole, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
SendMessage(ghwndConsole, EM_REPLACESEL, FALSE, (LPARAM)str); SendMessage(ghwndConsole, EM_REPLACESEL, FALSE, (LPARAM)str);
} }
static void guiDEAD(char *message) static void guiDEAD(std::string message)
{ {
char *nl; char *msgLastError = nullptr;
char errorStr[4096];
char *msgLastError;
FormatMessage( FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
@ -615,14 +629,21 @@ namespace pvpgn
0, 0,
NULL); NULL);
nl = strchr(msgLastError, '\r'); char *nl = std::strchr(msgLastError, '\r');
if (nl) *nl = 0; if (nl)
*nl = 0;
sprintf(errorStr, "%s\nGetLastError() = '%s'\n", message, msgLastError); std::string errorStr(message + "\nGetLastError() = '" + std::string(msgLastError) + "'\n");
LocalFree(msgLastError); LocalFree(msgLastError);
MessageBox(0, errorStr, "guiDEAD", MB_ICONSTOP | MB_OK);
exit(1); MessageBox(0, errorStr.c_str(), "guiDEAD", MB_ICONSTOP | MB_OK);
std::exit(1);
}
static void guiDEAD(char *message)
{
guiDEAD(std::string(message));
} }
static void guiMoveWindow(HWND hwnd, RECT* r) static void guiMoveWindow(HWND hwnd, RECT* r)
@ -648,11 +669,13 @@ namespace pvpgn
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{ {
switch (Message) { switch (Message)
{
case WM_INITDIALOG: case WM_INITDIALOG:
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
switch (LOWORD(wParam)) { switch (LOWORD(wParam))
{
case IDOK: case IDOK:
EndDialog(hwnd, IDOK); EndDialog(hwnd, IDOK);
break; break;
@ -667,34 +690,38 @@ namespace pvpgn
BOOL CALLBACK AnnDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) BOOL CALLBACK AnnDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{ {
t_message *message;
switch (Message) { switch (Message)
{
case WM_INITDIALOG: case WM_INITDIALOG:
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
switch (LOWORD(wParam)) { switch (LOWORD(wParam))
{
case IDOK: case IDOK:
{ {
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT1)); int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT1));
if (len > 0) { if (len > 0)
char* buf; {
buf = (char*)GlobalAlloc(GPTR, len + 1); char* buf = static_cast<char*>(GlobalAlloc(GPTR, len + 1));
GetDlgItemText(hwnd, IDC_EDIT1, buf, len + 1); GetDlgItemText(hwnd, IDC_EDIT1, buf, len + 1);
if ((message = message_create(message_type_error, NULL, buf))) { t_message *message = message_create(message_type_error, nullptr, buf);
message_send_all(message); if (message)
message_destroy(message); {
} message_send_all(message);
message_destroy(message);
}
GlobalFree((HANDLE)buf); GlobalFree((HGLOBAL)buf);
SetDlgItemText(hwnd, IDC_EDIT1, ""); SetDlgItemText(hwnd, IDC_EDIT1, "");
} }
else { else
MessageBox(hwnd, "You didn't enter anything!", "Warning", MB_OK); {
} MessageBox(hwnd, "You didn't enter anything!", "Warning", MB_OK);
break; }
break;
} }
} }
break; break;
@ -709,9 +736,11 @@ namespace pvpgn
BOOL CALLBACK KickDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) BOOL CALLBACK KickDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{ {
switch (Message) { switch (Message)
{
case WM_INITDIALOG: case WM_INITDIALOG:
if (selected_item[0] != 0) { if (selected_item[0] != 0)
{
SetDlgItemText(hwnd, IDC_EDITKICK, selected_item); SetDlgItemText(hwnd, IDC_EDITKICK, selected_item);
} }
@ -720,99 +749,104 @@ namespace pvpgn
switch (LOWORD(wParam)) { switch (LOWORD(wParam)) {
case IDC_KICK_EXECUTE: case IDC_KICK_EXECUTE:
{ {
t_connection * conngui; GetDlgItemText(hwnd, IDC_EDITKICK, selected_item, 32);
t_account * accountgui;
BOOL messageq;
BOOL kickq;
char temp[60];
char ipadr[110];
messageq = FALSE; t_connection * conngui = connlist_find_connection_by_accountname(selected_item);
kickq = FALSE; t_account * accountgui = accountlist_find_account(selected_item);
GetDlgItemText(hwnd, IDC_EDITKICK, selected_item, 32); if (conngui == nullptr)
{
std::strcat(selected_item, " could not be found in Userlist!");
MessageBox(hwnd, selected_item, "Error", MB_OK);
}
else
{
HWND hButton = GetDlgItem(hwnd, IDC_CHECKBAN);
HWND hButton1 = GetDlgItem(hwnd, IDC_CHECKKICK);
HWND hButton2 = GetDlgItem(hwnd, IDC_CHECKADMIN);
HWND hButton3 = GetDlgItem(hwnd, IDC_CHECKMOD);
HWND hButton4 = GetDlgItem(hwnd, IDC_CHECKANN);
conngui = connlist_find_connection_by_accountname(selected_item); BOOL messageq = FALSE;
accountgui = accountlist_find_account(selected_item); BOOL kickq = FALSE;
if (conngui == NULL) { if (SendMessage(hButton2, BM_GETCHECK, 0, 0) == BST_CHECKED)
strcat(selected_item, " could not be found in Userlist!"); {
MessageBox(hwnd, selected_item, "ERROR", MB_OK); account_set_admin(accountgui);
} account_set_command_groups(accountgui, 255);
else { messageq = TRUE;
}
HWND hButton = GetDlgItem(hwnd, IDC_CHECKBAN); if (SendMessage(hButton3, BM_GETCHECK, 0, 0) == BST_CHECKED)
HWND hButton1 = GetDlgItem(hwnd, IDC_CHECKKICK); {
HWND hButton2 = GetDlgItem(hwnd, IDC_CHECKADMIN); account_set_auth_operator(accountgui, nullptr, 1);
HWND hButton3 = GetDlgItem(hwnd, IDC_CHECKMOD); messageq = TRUE;
HWND hButton4 = GetDlgItem(hwnd, IDC_CHECKANN); }
if (SendMessage(hButton2, BM_GETCHECK, 0, 0) == BST_CHECKED) { if (SendMessage(hButton4, BM_GETCHECK, 0, 0) == BST_CHECKED)
account_set_admin(accountgui); {
account_set_command_groups(accountgui, 255); account_set_strattr(accountgui, "BNET\\auth\\announce", "true");
messageq = TRUE; messageq = TRUE;
} }
if (SendMessage(hButton3, BM_GETCHECK, 0, 0) == BST_CHECKED) { if (SendMessage(hButton, BM_GETCHECK, 0, 0) == BST_CHECKED)
account_set_auth_operator(accountgui, NULL, 1); {
messageq = TRUE; char temp[60];
} char ipadr[110];
unsigned int i_GUI;
if (SendMessage(hButton4, BM_GETCHECK, 0, 0) == BST_CHECKED) { std::strcpy(temp, addr_num_to_addr_str(conn_get_addr(conngui), 0));
account_set_strattr(accountgui, "BNET\\auth\\announce", "true");
messageq = TRUE;
}
if (SendMessage(hButton, BM_GETCHECK, 0, 0) == BST_CHECKED) { for (i_GUI = 0; temp[i_GUI] != ':'; i_GUI++)
unsigned int i_GUI; ipadr[i_GUI] = temp[i_GUI];
strcpy(temp, addr_num_to_addr_str(conn_get_addr(conngui), 0)); ipadr[i_GUI] = 0;
for (i_GUI = 0; temp[i_GUI] != ':'; i_GUI++) std::strcpy(temp, " a ");
ipadr[i_GUI] = temp[i_GUI]; std::strcat(temp, ipadr);
handle_ipban_command(NULL, temp);
ipadr[i_GUI] = 0; temp[0] = 0;
std::strcpy(temp, " has been added to IpBanList");
std::strcat(ipadr, temp);
if (messageq == TRUE)
{
std::strcat(ipadr, " and UserStatus changed");
MessageBox(hwnd, ipadr, "ipBan & StatusChange", MB_OK);
messageq = FALSE;
kickq = FALSE;
}
else
MessageBox(hwnd, ipadr, "ipBan", MB_OK);
}
strcpy(temp, " a "); if (SendMessage(hButton1, BM_GETCHECK, 0, 0) == BST_CHECKED)
strcat(temp, ipadr); {
handle_ipban_command(NULL, temp); conn_set_state(conngui, conn_state_destroy);
kickq = TRUE;
}
temp[0] = 0; if ((messageq == TRUE) && (kickq == TRUE))
strcpy(temp, " has been added to IpBanList"); {
strcat(ipadr, temp); std::strcat(selected_item, "has been kicked and Status has changed");
if (messageq == TRUE) { MessageBox(hwnd, selected_item, "UserKick & StatusChange", MB_OK);
strcat(ipadr, " and UserStatus changed"); }
MessageBox(hwnd, ipadr, "ipBan & StatusChange", MB_OK);
messageq = FALSE;
kickq = FALSE;
}
else
MessageBox(hwnd, ipadr, "ipBan", MB_OK);
}
if (SendMessage(hButton1, BM_GETCHECK, 0, 0) == BST_CHECKED) { if ((kickq == TRUE) && (messageq == FALSE))
conn_set_state(conngui, conn_state_destroy); {
kickq = TRUE; std::strcat(selected_item, " has been kicked from the server");
} MessageBox(hwnd, selected_item, "UserKick", MB_OK);
}
if ((messageq == TRUE) && (kickq == TRUE)) { if ((kickq == FALSE) && (messageq == TRUE))
strcat(selected_item, "has been kicked and Status has changed"); {
MessageBox(hwnd, selected_item, "UserKick & StatusChange", MB_OK); std::strcat(selected_item, "'s Status has been changed");
} MessageBox(hwnd, selected_item, "StatusChange", MB_OK);
}
if ((kickq == TRUE) && (messageq == FALSE)) { selected_item[0] = 0;
strcat(selected_item, " has been kicked from the server"); }
MessageBox(hwnd, selected_item, "UserKick", MB_OK); break;
}
if ((kickq == FALSE) && (messageq == TRUE)) {
strcat(selected_item, "'s Status has been changed");
MessageBox(hwnd, selected_item, "StatusChange", MB_OK);
}
selected_item[0] = 0;
}
break;
} }
} }
break; break;
@ -890,11 +924,13 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE reserved, LPSTR lpCmdLine, i
#endif #endif
Console console; Console console;
if (cmdline_load(__argc, __argv) != 1) { if (cmdline_load(__argc, __argv) != 1)
{
return -1; return -1;
} }
if (cmdline_get_console()){ if (cmdline_get_console())
{
console.RedirectIOToConsole(); console.RedirectIOToConsole();
return app_main(__argc, __argv); return app_main(__argc, __argv);
} }