summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/char/char.cpp1255
-rw-r--r--src/char/char.hpp7
-rw-r--r--src/char/int_party.cpp103
-rw-r--r--src/char/int_storage.cpp170
-rw-r--r--src/char/inter.cpp138
-rw-r--r--src/common/const_array.hpp175
-rw-r--r--src/common/cxxstdio.hpp123
-rw-r--r--src/common/db.cpp4
-rw-r--r--src/common/extract.hpp208
-rw-r--r--src/common/grfio.cpp11
-rw-r--r--src/common/lock.cpp17
-rw-r--r--src/common/mmo.hpp15
-rw-r--r--src/common/nullpo.cpp3
-rw-r--r--src/common/nullpo.hpp1
-rw-r--r--src/common/sanity.hpp23
-rw-r--r--src/common/socket.cpp15
-rw-r--r--src/common/timer.cpp5
-rw-r--r--src/common/utils.cpp58
-rw-r--r--src/common/utils.hpp26
-rw-r--r--src/ladmin/ladmin.cpp1505
-rw-r--r--src/login/login.cpp1925
-rw-r--r--src/map/atcommand.cpp1276
-rw-r--r--src/map/atcommand.hpp9
-rw-r--r--src/map/battle.cpp671
-rw-r--r--src/map/chrif.cpp166
-rw-r--r--src/map/chrif.hpp6
-rw-r--r--src/map/clif.cpp163
-rw-r--r--src/map/clif.hpp7
-rw-r--r--src/map/intif.cpp69
-rw-r--r--src/map/intif.hpp4
-rw-r--r--src/map/itemdb.cpp147
-rw-r--r--src/map/magic-expr.cpp74
-rw-r--r--src/map/magic-interpreter-base.cpp12
-rw-r--r--src/map/magic-interpreter-lexer.lpp2
-rw-r--r--src/map/magic-interpreter-parser.ypp16
-rw-r--r--src/map/magic-stmt.cpp48
-rw-r--r--src/map/magic.cpp2
-rw-r--r--src/map/map.cpp366
-rw-r--r--src/map/map.hpp11
-rw-r--r--src/map/mob.cpp64
-rw-r--r--src/map/npc.cpp92
-rw-r--r--src/map/npc.hpp4
-rw-r--r--src/map/party.cpp12
-rw-r--r--src/map/path.cpp8
-rw-r--r--src/map/pc.cpp146
-rw-r--r--src/map/script.cpp299
-rw-r--r--src/map/script.hpp39
-rw-r--r--src/map/skill-pools.cpp2
-rw-r--r--src/map/skill.cpp74
-rw-r--r--src/map/tmw.cpp33
-rw-r--r--src/map/tmw.hpp3
-rw-r--r--src/tool/eathena-monitor.cpp24
52 files changed, 4316 insertions, 5320 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp
index 391f81f..b07baea 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -12,14 +12,18 @@
#include <netdb.h>
#include <unistd.h>
-#include <cstdarg> // exception to "no va_list" rule
#include <cstdio>
#include <cstdlib>
#include <csignal>
#include <cstring>
#include <ctime>
+#include <fstream>
+#include <algorithm>
+
#include "../common/core.hpp"
+#include "../common/cxxstdio.hpp"
+#include "../common/extract.hpp"
#include "../common/lock.hpp"
#include "../common/mmo.hpp"
#include "../common/socket.hpp"
@@ -36,6 +40,7 @@ int server_freezeflag[MAX_MAP_SERVERS]; // Map-server anti-freeze system. Cou
int anti_freeze_enable = 0;
int ANTI_FREEZE_INTERVAL = 6;
+// TODO replace all string forms of IP addresses with class instances
int login_fd, char_fd;
char userid[24];
char passwd[24];
@@ -51,8 +56,6 @@ int char_maintenance;
int char_new;
int email_creation = 0; // disabled by default
char char_txt[1024];
-char backup_txt[1024]; //By zanetheinsane
-char backup_txt_flag = 0; // The backup_txt file was created because char deletion bug existed. Now it's finish and that take a lot of time to create a second file when there are a lot of characters. => option By [Yor]
char unknown_char_name[1024] = "Unknown";
char char_log_filename[1024] = "log/char.log";
//Added for lan support
@@ -115,32 +118,13 @@ pid_t pid = 0; // For forked DB writes
//------------------------------
// Writing function of logs file
//------------------------------
-int char_log(const char *fmt, ...)
+void char_log(const_string line)
{
- FILE *logfp;
- va_list ap;
- struct timeval tv;
- char tmpstr[2048];
-
- va_start(ap, fmt);
-
- logfp = fopen_(char_log_filename, "a");
- if (logfp)
- {
- if (fmt[0] == '\0') // jump a line if no message
- fprintf(logfp, "\n");
- else
- {
- gettimeofday(&tv, NULL);
- strftime(tmpstr, 24, "%d-%m-%Y %H:%M:%S", gmtime(&(tv.tv_sec)));
- sprintf(tmpstr + 19, ".%03d: %s", (int) tv.tv_usec / 1000, fmt);
- vfprintf(logfp, tmpstr, ap);
- }
- fclose_(logfp);
- }
-
- va_end(ap);
- return 0;
+ FILE *logfp = fopen_(char_log_filename, "a");
+ if (!logfp)
+ return;
+ log_with_timestamp(logfp, line);
+ fclose_(logfp);
}
//----------------------------------------------------------------------
@@ -209,10 +193,8 @@ char *search_character_name(int index)
// Function to create the character line (for save)
//-------------------------------------------------
static
-int mmo_char_tostr(char *str, struct mmo_charstatus *p)
+std::string mmo_char_tostr(struct mmo_charstatus *p)
{
- char *str_p = str;
-
// on multi-map server, sometimes it's posssible that last_point become void. (reason???) We check that to not lost character at restart.
if (p->last_point.map[0] == '\0')
{
@@ -221,343 +203,196 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p)
p->last_point.y = 354;
}
- str_p += sprintf(str_p, "%d\t%d,%d\t%s\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%s,%d,%d\t%s,%d,%d,%d\t", p->char_id, p->account_id, p->char_num, p->name, //
- p->pc_class, p->base_level, p->job_level, p->base_exp, p->job_exp, p->zeny, p->hp, p->max_hp, p->sp, p->max_sp,
- p->attrs[ATTR::STR], p->attrs[ATTR::AGI], p->attrs[ATTR::VIT], p->attrs[ATTR::INT], p->attrs[ATTR::DEX], p->attrs[ATTR::LUK],
- p->status_point, p->skill_point, uint16_t(p->option), p->karma, p->manner, //
- p->party_id, 0/*guild_id*/, 0, p->hair, p->hair_color, p->clothes_color, p->weapon, p->shield, p->head_top, p->head_mid, p->head_bottom, p->last_point.map, p->last_point.x, p->last_point.y, //
- p->save_point.map, p->save_point.x, p->save_point.y,
- p->partner_id);
+ std::string str_p;
+ str_p += STRPRINTF(
+ "%d\t"
+ "%d,%d\t"
+ "%s\t"
+ "%d,%d,%d\t"
+ "%d,%d,%d\t"
+ "%d,%d,%d,%d\t"
+ "%d,%d,%d,%d,%d,%d\t"
+ "%d,%d\t"
+ "%d,%d,%d\t"
+ "%d,%d,%d\t"
+ "%d,%d,%d\t"
+ "%d,%d,%d,%d,%d\t"
+ "%s,%d,%d\t"
+ "%s,%d,%d,%d\t",
+ p->char_id,
+ p->account_id, p->char_num,
+ p->name,
+ p->pc_class, p->base_level, p->job_level,
+ p->base_exp, p->job_exp, p->zeny,
+ p->hp, p->max_hp, p->sp, p->max_sp,
+ p->attrs[ATTR::STR], p->attrs[ATTR::AGI], p->attrs[ATTR::VIT], p->attrs[ATTR::INT], p->attrs[ATTR::DEX], p->attrs[ATTR::LUK],
+ p->status_point, p->skill_point,
+ p->option, p->karma, p->manner,
+ p->party_id, 0/*guild_id*/, 0/*pet_id*/,
+ p->hair, p->hair_color, p->clothes_color,
+ p->weapon, p->shield, p->head_top, p->head_mid, p->head_bottom,
+ p->last_point.map, p->last_point.x, p->last_point.y,
+ p->save_point.map, p->save_point.x, p->save_point.y, p->partner_id);
for (int i = 0; i < 10; i++)
if (p->memo_point[i].map[0])
{
- str_p +=
- sprintf(str_p, "%s,%d,%d", p->memo_point[i].map,
- p->memo_point[i].x, p->memo_point[i].y);
+ str_p += STRPRINTF("%s,%d,%d ",
+ p->memo_point[i].map, p->memo_point[i].x, p->memo_point[i].y);
}
- *(str_p++) = '\t';
+ str_p += '\t';
for (int i = 0; i < MAX_INVENTORY; i++)
if (p->inventory[i].nameid)
{
- str_p += sprintf(str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->inventory[i].id,
- p->inventory[i].nameid,
- p->inventory[i].amount,
- uint16_t(p->inventory[i].equip),
- p->inventory[i].identify,
- p->inventory[i].refine,
- p->inventory[i].attribute,
- p->inventory[i].card[0],
- p->inventory[i].card[1],
- p->inventory[i].card[2],
- p->inventory[i].card[3],
- p->inventory[i].broken);
- }
- *(str_p++) = '\t';
+ str_p += STRPRINTF("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
+ p->inventory[i].id,
+ p->inventory[i].nameid,
+ p->inventory[i].amount,
+ p->inventory[i].equip,
+ p->inventory[i].identify,
+ p->inventory[i].refine,
+ p->inventory[i].attribute,
+ p->inventory[i].card[0],
+ p->inventory[i].card[1],
+ p->inventory[i].card[2],
+ p->inventory[i].card[3],
+ p->inventory[i].broken);
+ }
+ str_p += '\t';
for (int i = 0; i < MAX_CART; i++)
if (p->cart[i].nameid)
{
- str_p += sprintf(str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->cart[i].id,
- p->cart[i].nameid,
- p->cart[i].amount,
- uint16_t(p->cart[i].equip),
- p->cart[i].identify,
- p->cart[i].refine,
- p->cart[i].attribute,
- p->cart[i].card[0],
- p->cart[i].card[1],
- p->cart[i].card[2],
- p->cart[i].card[3],
- p->cart[i].broken);
- }
- *(str_p++) = '\t';
-
- for (SkillID i = SkillID(); i < MAX_SKILL;
- i = SkillID(uint16_t(i) + 1))
+ str_p += STRPRINTF("%d,%d,%d,%hhu,%d,%hd,%hhu,%d,%d,%d,%d,%d ",
+ p->cart[i].id,
+ p->cart[i].nameid,
+ p->cart[i].amount,
+ p->cart[i].equip,
+ p->cart[i].identify,
+ p->cart[i].refine,
+ p->cart[i].attribute,
+ p->cart[i].card[0],
+ p->cart[i].card[1],
+ p->cart[i].card[2],
+ p->cart[i].card[3],
+ p->cart[i].broken);
+ }
+ str_p += '\t';
+
+ for (SkillID i : erange(SkillID(), MAX_SKILL))
if (p->skill[i].id != SkillID()/*SkillID::ZERO*/)
{
- str_p +=
- sprintf(str_p, "%d,%d ", uint16_t(p->skill[i].id),
- p->skill[i].lv | (uint16_t(p->skill[i].flags) << 16));
+ str_p += STRPRINTF("%d,%d ",
+ p->skill[i].id,
+ p->skill[i].lv | (uint16_t(p->skill[i].flags) << 16));
}
- *(str_p++) = '\t';
+ str_p += '\t';
for (int i = 0; i < p->global_reg_num; i++)
if (p->global_reg[i].str[0])
- str_p +=
- sprintf(str_p, "%s,%d ", p->global_reg[i].str,
- p->global_reg[i].value);
- *(str_p++) = '\t';
+ str_p += STRPRINTF("%s,%d ",
+ p->global_reg[i].str,
+ p->global_reg[i].value);
+ str_p += '\t';
- *str_p = '\0';
- return 0;
+ return str_p;
+}
+
+static
+bool extract(const_string str, struct point *p)
+{
+ return extract(str, record<','>(&p->map, &p->x, &p->y));
+}
+
+static
+bool extract(const_string str, struct skill *s)
+{
+ uint32_t flags_and_level;
+ if (!extract(str,
+ record<','>(&s->id, &flags_and_level)))
+ return false;
+ s->lv = flags_and_level & 0xffff;
+ s->flags = SkillFlags(flags_and_level >> 16);
+ return true;
}
//-------------------------------------------------------------------------
// Function to set the character from the line (at read of characters file)
//-------------------------------------------------------------------------
static
-int mmo_char_fromstr(char *str, struct mmo_charstatus *p)
+bool extract(const_string str, struct mmo_charstatus *p)
{
- int tmp_int[256];
- int set, next, len, i;
-
// initilialise character
memset(p, '\0', sizeof(struct mmo_charstatus));
- // If it's not char structure of version 1008 and after
- if ((set = sscanf(str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, //
- &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23], //
- &tmp_int[24], &tmp_int[25], &tmp_int[26], &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], &tmp_int[34], p->last_point.map, &tmp_int[35], &tmp_int[36], //
- p->save_point.map, &tmp_int[37], &tmp_int[38],
- &tmp_int[39], &next)) != 43)
- {
- tmp_int[39] = 0; // partner id
- // If not char structure from version 384 to 1007
- if ((set = sscanf(str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, //
- &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23], //
- &tmp_int[24], &tmp_int[25], &tmp_int[26], &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], &tmp_int[34], p->last_point.map, &tmp_int[35], &tmp_int[36], //
- p->save_point.map, &tmp_int[37], &tmp_int[38],
- &next)) != 42)
- {
- // It's char structure of a version before 384
- tmp_int[26] = 0; // pet id
- set = sscanf(str, "%d\t%d,%d\t%[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%[^,],%d,%d\t%[^,],%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], p->name, //
- &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13], &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20], &tmp_int[21], &tmp_int[22], &tmp_int[23], //
- &tmp_int[24], &tmp_int[25], //
- &tmp_int[27], &tmp_int[28], &tmp_int[29], &tmp_int[30], &tmp_int[31], &tmp_int[32], &tmp_int[33], &tmp_int[34], p->last_point.map, &tmp_int[35], &tmp_int[36], //
- p->save_point.map, &tmp_int[37], &tmp_int[38],
- &next);
- set += 2;
- //printf("char: old char data ver.1\n");
- // Char structure of version 1007 or older
- }
- else
- {
- set++;
- //printf("char: old char data ver.2\n");
- }
- // Char structure of version 1008+
- }
- else
- {
- //printf("char: new char data ver.3\n");
- }
- if (set != 43)
- return 0;
-
- p->char_id = tmp_int[0];
- p->account_id = tmp_int[1];
- p->char_num = tmp_int[2];
- p->pc_class = tmp_int[3];
- p->base_level = tmp_int[4];
- p->job_level = tmp_int[5];
- p->base_exp = tmp_int[6];
- p->job_exp = tmp_int[7];
- p->zeny = tmp_int[8];
- p->hp = tmp_int[9];
- p->max_hp = tmp_int[10];
- p->sp = tmp_int[11];
- p->max_sp = tmp_int[12];
- p->attrs[ATTR::STR] = tmp_int[13];
- p->attrs[ATTR::AGI] = tmp_int[14];
- p->attrs[ATTR::VIT] = tmp_int[15];
- p->attrs[ATTR::INT] = tmp_int[16];
- p->attrs[ATTR::DEX] = tmp_int[17];
- p->attrs[ATTR::LUK] = tmp_int[18];
- p->status_point = tmp_int[19];
- p->skill_point = tmp_int[20];
- p->option = Option(tmp_int[21]);
- p->karma = tmp_int[22];
- p->manner = tmp_int[23];
- p->party_id = tmp_int[24];
- //p->guild_id = tmp_int[25];
-// p->pet_id = tmp_int[26];
- p->hair = tmp_int[27];
- p->hair_color = tmp_int[28];
- p->clothes_color = tmp_int[29];
- p->weapon = tmp_int[30];
- p->shield = tmp_int[31];
- p->head_top = tmp_int[32];
- p->head_mid = tmp_int[33];
- p->head_bottom = tmp_int[34];
- p->last_point.x = tmp_int[35];
- p->last_point.y = tmp_int[36];
- p->save_point.x = tmp_int[37];
- p->save_point.y = tmp_int[38];
- p->partner_id = tmp_int[39];
-
- // Some checks
- for (i = 0; i < char_num; i++)
+ uint32_t unused_guild_id, unused_pet_id;
+ std::vector<struct point> memos;
+ std::vector<struct item> inventory, cart;
+ std::vector<struct skill> skills;
+ std::vector<struct global_reg> vars;
+ if (!extract(str,
+ record<'\t'>(
+ &p->char_id,
+ record<','>(&p->account_id, &p->char_num),
+ &p->name,
+ record<','>(&p->pc_class, &p->base_level, &p->job_level),
+ record<','>(&p->base_exp, &p->job_exp, &p->zeny),
+ record<','>(&p->hp, &p->max_hp, &p->sp, &p->max_sp),
+ record<','>(&p->attrs[ATTR::STR], &p->attrs[ATTR::AGI], &p->attrs[ATTR::VIT], &p->attrs[ATTR::INT], &p->attrs[ATTR::DEX], &p->attrs[ATTR::LUK]),
+ record<','>(&p->status_point, &p->skill_point),
+ record<','>(&p->option, &p->karma, &p->manner),
+ record<','>(&p->party_id, &unused_guild_id, &unused_pet_id),
+ record<','>(&p->hair, &p->hair_color, &p->clothes_color),
+ record<','>(&p->weapon, &p->shield, &p->head_top, &p->head_mid, &p->head_bottom),
+ &p->last_point,
+ // somebody was silly and stuck partner id as a field
+ // of this, instead of adding a new \t
+ // or putting it elsewhere, like by pet/guild
+ record<','>(&p->save_point.map, &p->save_point.x, &p->save_point.y, &p->partner_id),
+ vrec<' '>(&memos),
+ vrec<' '>(&inventory),
+ vrec<' '>(&cart),
+ vrec<' '>(&skills),
+ vrec<' '>(&vars))))
+ return false;
+
+ if (strcmp(wisp_server_name, p->name) == 0)
+ return false;
+
+ for (int i = 0; i < char_num; i++)
{
if (char_dat[i].char_id == p->char_id)
- {
- printf("\033[1;31mmmo_auth_init: ******Error: a character has an identical id to another.\n");
- printf(" character id #%d -> new character not readed.\n",
- p->char_id);
- printf(" Character saved in log file.\033[0m\n");
- return -1;
- }
- else if (strcmp(char_dat[i].name, p->name) == 0)
- {
- printf("\033[1;31mmmo_auth_init: ******Error: character name already exists.\n");
- printf(" character name '%s' -> new character not readed.\n",
- p->name);
- printf(" Character saved in log file.\033[0m\n");
- return -2;
- }
- }
-
- if (strcasecmp(wisp_server_name, p->name) == 0)
- {
- printf("mmo_auth_init: ******WARNING: character name has wisp server name.\n");
- printf(" Character name '%s' = wisp server name '%s'.\n",
- p->name, wisp_server_name);
- printf(" Character readed. Suggestion: change the wisp server name.\n");
- char_log("mmo_auth_init: ******WARNING: character name has wisp server name: Character name '%s' = wisp server name '%s'.\n",
- p->name, wisp_server_name);
- }
-
- if (str[next] == '\n' || str[next] == '\r')
- return 1; // 新規データ
-
- next++;
-
- for (i = 0; str[next] && str[next] != '\t'; i++)
- {
- if (sscanf(str + next, "%[^,],%d,%d%n", p->memo_point[i].map, &tmp_int[0],
- &tmp_int[1], &len) != 3)
- return -3;
- p->memo_point[i].x = tmp_int[0];
- p->memo_point[i].y = tmp_int[1];
- next += len;
- if (str[next] == ' ')
- next++;
- }
-
- next++;
-
- for (i = 0; str[next] && str[next] != '\t'; i++)
- {
- if (sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
- &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
- &tmp_int[4], &tmp_int[5], &tmp_int[6],
- &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
- &tmp_int[11], &len) == 12)
- {
- // do nothing, it's ok
- }
- else if (sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
- &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
- &tmp_int[4], &tmp_int[5], &tmp_int[6],
- &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
- &len) == 11)
- {
- tmp_int[11] = 0; // broken doesn't exist in this version -> 0
- }
- else // invalid structure
- return -4;
- p->inventory[i].id = tmp_int[0];
- p->inventory[i].nameid = tmp_int[1];
- p->inventory[i].amount = tmp_int[2];
- p->inventory[i].equip = EPOS(tmp_int[3]);
- p->inventory[i].identify = tmp_int[4];
- p->inventory[i].refine = tmp_int[5];
- p->inventory[i].attribute = tmp_int[6];
- p->inventory[i].card[0] = tmp_int[7];
- p->inventory[i].card[1] = tmp_int[8];
- p->inventory[i].card[2] = tmp_int[9];
- p->inventory[i].card[3] = tmp_int[10];
- p->inventory[i].broken = tmp_int[11];
- next += len;
- if (str[next] == ' ')
- next++;
+ return false;
+ if (strcmp(char_dat[i].name, p->name) == 0)
+ return false;
}
- next++;
+ if (memos.size() > 10)
+ return false;
+ std::copy(memos.begin(), memos.end(), p->memo_point);
+ // number of memo points is not saved - it just detects map name '\0'
- for (i = 0; str[next] && str[next] != '\t'; i++)
- {
- if (sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
- &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
- &tmp_int[4], &tmp_int[5], &tmp_int[6],
- &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
- &tmp_int[11], &len) == 12)
- {
- // do nothing, it's ok
- }
- else if (sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
- &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
- &tmp_int[4], &tmp_int[5], &tmp_int[6],
- &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
- &len) == 11)
- {
- tmp_int[11] = 0; // broken doesn't exist in this version -> 0
- }
- else // invalid structure
- return -5;
- p->cart[i].id = tmp_int[0];
- p->cart[i].nameid = tmp_int[1];
- p->cart[i].amount = tmp_int[2];
- p->cart[i].equip = EPOS(tmp_int[3]);
- p->cart[i].identify = tmp_int[4];
- p->cart[i].refine = tmp_int[5];
- p->cart[i].attribute = tmp_int[6];
- p->cart[i].card[0] = tmp_int[7];
- p->cart[i].card[1] = tmp_int[8];
- p->cart[i].card[2] = tmp_int[9];
- p->cart[i].card[3] = tmp_int[10];
- p->cart[i].broken = tmp_int[11];
- next += len;
- if (str[next] == ' ')
- next++;
- }
+ if (inventory.size() > MAX_INVENTORY)
+ return false;
+ std::copy(inventory.begin(), inventory.end(), p->inventory);
+ // number of inventory items is not saved - it just detects nameid 0
- next++;
+ if (cart.size() > MAX_CART)
+ return false;
+ std::copy(cart.begin(), cart.end(), p->cart);
+ // number of cart items is not saved - it just detects nameid 0
- for (i = 0; str[next] && str[next] != '\t'; i++)
- {
- if (sscanf(str + next, "%d,%d%n", &tmp_int[0], &tmp_int[1], &len) !=
- 2)
- return -6;
- SkillID skill_id = SkillID(tmp_int[0]);
- p->skill[skill_id].id = skill_id;
- p->skill[skill_id].lv = tmp_int[1] & 0xffff;
- p->skill[skill_id].flags = SkillFlags(tmp_int[1] >> 16);
- next += len;
- if (str[next] == ' ')
- next++;
- }
+ if (skills.size() > uint16_t(MAX_SKILL))
+ return false;
+ std::copy(skills.begin(), skills.end(), &p->skill[SkillID()]);
+ // number of skills is not saved - it just detects skill.id 0
- next++;
-
- for (i = 0;
- str[next] && str[next] != '\t' && str[next] != '\n'
- && str[next] != '\r'; i++)
- { // global_reg実装以前のathena.txt互換のため一応'\n'チェック
- if (sscanf(str + next, "%[^,],%d%n", p->global_reg[i].str,
- &p->global_reg[i].value, &len) != 2)
- {
- // because some scripts are not correct, the str can be "". So, we must check that.
- // If it's, we must not refuse the character, but just this REG value.
- // Character line will have something like: nov_2nd_cos,9 ,9 nov_1_2_cos_c,1 (here, ,9 is not good)
- if (str[next] == ','
- && sscanf(str + next, ",%d%n", &p->global_reg[i].value,
- &len) == 1)
- i--;
- else
- return -7;
- }
- next += len;
- if (str[next] == ' ')
- next++;
- }
- p->global_reg_num = i;
+ if (vars.size() > GLOBAL_REG_NUM)
+ return false;
+ std::copy(vars.begin(), vars.end(), p->global_reg);
+ p->global_reg_num = vars.size();
- return 1;
+ return true;
}
//---------------------------------
@@ -566,10 +401,6 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p)
static
int mmo_char_init(void)
{
- char line[65536];
- int ret, line_count;
- FILE *fp;
-
char_max = 256;
CREATE(char_dat, struct mmo_charstatus, 256);
CREATE(online_chars, int, 256);
@@ -578,32 +409,37 @@ int mmo_char_init(void)
char_num = 0;
- fp = fopen_(char_txt, "r");
- if (fp == NULL)
+ std::ifstream in(char_txt);
+ if (!in.is_open())
{
- printf("Characters file not found: %s.\n", char_txt);
- char_log("Characters file not found: %s.\n", char_txt);
- char_log("Id for the next created character: %d.\n",
+ PRINTF("Characters file not found: %s.\n", char_txt);
+ CHAR_LOG("Characters file not found: %s.\n", char_txt);
+ CHAR_LOG("Id for the next created character: %d.\n",
char_id_count);
return 0;
}
- line_count = 0;
- while (fgets(line, sizeof(line) - 1, fp))
+ int line_count = 0;
+ std::string line;
+ while (std::getline(in, line))
{
- int i, j;
line_count++;
if (line[0] == '/' && line[1] == '/')
continue;
- line[sizeof(line) - 1] = '\0';
+ if (line.back() == '\r')
+ {
+ line.back() = 0;
+ }
- j = 0;
- if (sscanf(line, "%d\t%%newid%%%n", &i, &j) == 1 && j > 0)
{
- if (char_id_count < i)
- char_id_count = i;
- continue;
+ int i, j = 0;
+ if (SSCANF(line, "%d\t%%newid%%%n", &i, &j) == 1 && j > 0)
+ {
+ if (char_id_count < i)
+ char_id_count = i;
+ continue;
+ }
}
if (char_num >= char_max)
@@ -611,75 +447,27 @@ int mmo_char_init(void)
char_max += 256;
RECREATE(char_dat, struct mmo_charstatus, char_max);
RECREATE(online_chars, int, char_max);
- for (i = char_max - 256; i < char_max; i++)
+ for (int i = char_max - 256; i < char_max; i++)
online_chars[i] = -1;
}
- ret = mmo_char_fromstr(line, &char_dat[char_num]);
- if (ret > 0)
- { // negative value or zero for errors
- if (char_dat[char_num].char_id >= char_id_count)
- char_id_count = char_dat[char_num].char_id + 1;
- char_num++;
- }
- else
+ if (!extract(line, &char_dat[char_num]))
{
- printf("mmo_char_init: in characters file, unable to read the line #%d.\n",
- line_count);
- printf(" -> Character saved in log file.\n");
- switch (ret)
- {
- case -1:
- char_log("Duplicate character id in the next character line (character not readed):\n");
- break;
- case -2:
- char_log("Duplicate character name in the next character line (character not readed):\n");
- break;
- case -3:
- char_log("Invalid memo point structure in the next character line (character not readed):\n");
- break;
- case -4:
- char_log("Invalid inventory item structure in the next character line (character not readed):\n");
- break;
- case -5:
- char_log("Invalid cart item structure in the next character line (character not readed):\n");
- break;
- case -6:
- char_log("Invalid skill structure in the next character line (character not readed):\n");
- break;
- case -7:
- char_log("Invalid register structure in the next character line (character not readed):\n");
- break;
- default: // 0
- char_log("Unabled to get a character in the next line - Basic structure of line (before inventory) is incorrect (character not readed):\n");
- break;
- }
- char_log("%s", line);
+ CHAR_LOG("Char skipped\n%s", line);
+ continue;
}
+ if (char_dat[char_num].char_id >= char_id_count)
+ char_id_count = char_dat[char_num].char_id + 1;
+ char_num++;
}
- fclose_(fp);
- if (char_num == 0)
- {
- printf("mmo_char_init: No character found in %s.\n", char_txt);
- char_log("mmo_char_init: No character found in %s.\n",
- char_txt);
- }
- else if (char_num == 1)
- {
- printf("mmo_char_init: 1 character read in %s.\n", char_txt);
- char_log("mmo_char_init: 1 character read in %s.\n", char_txt);
- }
- else
- {
- printf("mmo_char_init: %d characters read in %s.\n", char_num,
- char_txt);
- char_log("mmo_char_init: %d characters read in %s.\n",
- char_num, char_txt);
- }
+ PRINTF("mmo_char_init: %d characters read in %s.\n",
+ char_num, char_txt);
+ CHAR_LOG("mmo_char_init: %d characters read in %s.\n",
+ char_num, char_txt);
- char_log("Id for the next created character: %d.\n",
- char_id_count);
+ CHAR_LOG("Id for the next created character: %d.\n",
+ char_id_count);
return 0;
}
@@ -690,7 +478,6 @@ int mmo_char_init(void)
static
void mmo_char_sync(void)
{
- char line[65536];
int i, j, k;
int lock;
FILE *fp;
@@ -719,42 +506,21 @@ void mmo_char_sync(void)
fp = lock_fopen(char_txt, &lock);
if (fp == NULL)
{
- printf("WARNING: Server can't not save characters.\n");
- char_log("WARNING: Server can't not save characters.\n");
+ PRINTF("WARNING: Server can't not save characters.\n");
+ CHAR_LOG("WARNING: Server can't not save characters.\n");
}
else
{
for (i = 0; i < char_num; i++)
{
- // create only once the line, and save it in the 2 files (it's speeder than repeat twice the loop and create twice the line)
- mmo_char_tostr(line, &char_dat[id[i]]); // use of sorted index
- fprintf(fp, "%s\n", line);
+ // use of sorted index
+ std::string line = mmo_char_tostr(&char_dat[id[i]]);
+ fwrite(line.data(), 1, line.size(), fp);
+ fputc('\n', fp);
}
- fprintf(fp, "%d\t%%newid%%\n", char_id_count);
+ FPRINTF(fp, "%d\t%%newid%%\n", char_id_count);
lock_fclose(fp, char_txt, &lock);
}
-
- // Data save (backup)
- if (backup_txt_flag)
- { // The backup_txt file was created because char deletion bug existed. Now it's finish and that take a lot of time to create a second file when there are a lot of characters. => option By [Yor]
- fp = lock_fopen(backup_txt, &lock);
- if (fp == NULL)
- {
- printf("WARNING: Server can't not create backup of characters file.\n");
- char_log("WARNING: Server can't not create backup of characters file.\n");
- return;
- }
- for (i = 0; i < char_num; i++)
- {
- // create only once the line, and save it in the 2 files (it's speeder than repeat twice the loop and create twice the line)
- mmo_char_tostr(line, &char_dat[id[i]]); // use of sorted index
- fprintf(fp, "%s\n", line);
- }
- fprintf(fp, "%d\t%%newid%%\n", char_id_count);
- lock_fclose(fp, backup_txt, &lock);
- }
-
- return;
}
//----------------------------------------------------
@@ -829,7 +595,7 @@ int make_new_char(int fd, unsigned char *dat)
cdat[23] = '\0';
if (remove_control_chars(cdat))
{
- char_log("Make new char error (control char received in the name): (connection #%d, account: %d).\n",
+ CHAR_LOG("Make new char error (control char received in the name): (connection #%d, account: %d).\n",
fd, sd->account_id);
return -1;
}
@@ -841,7 +607,7 @@ int make_new_char(int fd, unsigned char *dat)
// check lenght of character name
if (strlen(cdat) < 4)
{
- char_log("Make new char error (character name too small): (connection #%d, account: %d, name: '%s').\n",
+ CHAR_LOG("Make new char error (character name too small): (connection #%d, account: %d, name: '%s').\n",
fd, sd->account_id, cdat);
return -1;
}
@@ -852,7 +618,7 @@ int make_new_char(int fd, unsigned char *dat)
for (i = 0; cdat[i]; i++)
if (strchr(char_name_letters, cdat[i]) == NULL)
{
- char_log("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n",
+ CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n",
fd, sd->account_id, cdat, cdat[i]);
return -1;
}
@@ -862,7 +628,7 @@ int make_new_char(int fd, unsigned char *dat)
for (i = 0; cdat[i]; i++)
if (strchr(char_name_letters, cdat[i]) != NULL)
{
- char_log("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n",
+ CHAR_LOG("Make new char error (invalid letter in the name): (connection #%d, account: %d), name: %s, invalid letter: %c.\n",
fd, sd->account_id, cdat, cdat[i]);
return -1;
}
@@ -874,7 +640,7 @@ int make_new_char(int fd, unsigned char *dat)
dat[33] >= 20 || // hair style
dat[31] >= 12)
{ // hair color (dat[31] can not be negativ)
- char_log("Make new char error (invalid values): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n",
+ CHAR_LOG("Make new char error (invalid values): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n",
fd, sd->account_id, dat[30], dat, dat[24], dat[25],
dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -887,7 +653,7 @@ int make_new_char(int fd, unsigned char *dat)
{
if (dat[i] < 1 || dat[i] > 9)
{
- char_log("Make new char error (invalid stat value: not between 1 to 9): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n",
+ CHAR_LOG("Make new char error (invalid stat value: not between 1 to 9): (connection #%d, account: %d) slot %d, name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d\n",
fd, sd->account_id, dat[30], dat, dat[24], dat[25],
dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -902,7 +668,7 @@ int make_new_char(int fd, unsigned char *dat)
|| (name_ignoring_case == 0
&& strcasecmp(char_dat[i].name, cdat) == 0))
{
- char_log("Make new char error (name already exists): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n",
+ CHAR_LOG("Make new char error (name already exists): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n",
fd, sd->account_id, dat[30], cdat, char_dat[i].name,
dat[24], dat[25], dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -912,7 +678,7 @@ int make_new_char(int fd, unsigned char *dat)
if (char_dat[i].account_id == sd->account_id
&& char_dat[i].char_num == dat[30])
{
- char_log("Make new char error (slot already used): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n",
+ CHAR_LOG("Make new char error (slot already used): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n",
fd, sd->account_id, dat[30], cdat, char_dat[i].name,
dat[24], dat[25], dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -923,7 +689,7 @@ int make_new_char(int fd, unsigned char *dat)
if (strcmp(wisp_server_name, cdat) == 0)
{
- char_log("Make new char error (name used is wisp name for server): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n",
+ CHAR_LOG("Make new char error (name used is wisp name for server): (connection #%d, account: %d) slot %d, name: %s (actual name of other char: %s), stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d.\n",
fd, sd->account_id, dat[30], cdat, char_dat[i].name,
dat[24], dat[25], dat[26], dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29],
@@ -946,7 +712,7 @@ int make_new_char(int fd, unsigned char *dat)
sprintf(ip, "%d.%d.%d.%d", sin_addr[0], sin_addr[1], sin_addr[2],
sin_addr[3]);
- char_log("Creation of New Character: (connection #%d, account: %d) slot %d, character Name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d. [%s]\n",
+ CHAR_LOG("Creation of New Character: (connection #%d, account: %d) slot %d, character Name: %s, stats: %d+%d+%d+%d+%d+%d=%d, hair: %d, hair color: %d. [%s]\n",
fd, sd->account_id, dat[30], cdat, dat[24], dat[25], dat[26],
dat[27], dat[28], dat[29],
dat[24] + dat[25] + dat[26] + dat[27] + dat[28] + dat[29], dat[33],
@@ -1174,8 +940,6 @@ void create_online_files(void)
if (online_display_option == 0) // we display nothing, so return
return;
- //char_log("Creation of online players files.\n");
-
// Get number of online players, id of each online players
players = 0;
// sort online characters.
@@ -1287,92 +1051,92 @@ void create_online_files(void)
// get time
time(&time_server); // get time in seconds since 1/1/1970
datetime = localtime(&time_server); // convert seconds in structure
- strftime(temp, sizeof(temp), "%d %b %Y %X", datetime); // like sprintf, but only for date/time (05 dec 2003 15:12:52)
+ strftime(temp, sizeof(temp), "%d %b %Y %X", datetime); // like SPRINTF, but only for date/time (05 dec 2003 15:12:52)
// write heading
- fprintf(fp2, "<HTML>\n");
- fprintf(fp2, " <META http-equiv=\"Refresh\" content=\"%d\">\n", online_refresh_html); // update on client explorer every x seconds
- fprintf(fp2, " <HEAD>\n");
- fprintf(fp2, " <TITLE>Online Players on %s</TITLE>\n",
+ FPRINTF(fp2, "<HTML>\n");
+ FPRINTF(fp2, " <META http-equiv=\"Refresh\" content=\"%d\">\n", online_refresh_html); // update on client explorer every x seconds
+ FPRINTF(fp2, " <HEAD>\n");
+ FPRINTF(fp2, " <TITLE>Online Players on %s</TITLE>\n",
server_name);
- fprintf(fp2, " </HEAD>\n");
- fprintf(fp2, " <BODY>\n");
- fprintf(fp2, " <H3>Online Players on %s (%s):</H3>\n",
+ FPRINTF(fp2, " </HEAD>\n");
+ FPRINTF(fp2, " <BODY>\n");
+ FPRINTF(fp2, " <H3>Online Players on %s (%s):</H3>\n",
server_name, temp);
- fprintf(fp, "Online Players on %s (%s):\n", server_name, temp);
- fprintf(fp, "\n");
+ FPRINTF(fp, "Online Players on %s (%s):\n", server_name, temp);
+ FPRINTF(fp, "\n");
// If we display at least 1 player
if (players > 0)
{
j = 0; // count the number of characters for the txt version and to set the separate line
- fprintf(fp2, " <table border=\"1\" cellspacing=\"1\">\n");
- fprintf(fp2, " <tr>\n");
+ FPRINTF(fp2, " <table border=\"1\" cellspacing=\"1\">\n");
+ FPRINTF(fp2, " <tr>\n");
if ((online_display_option & 1)
|| (online_display_option & 64))
{
- fprintf(fp2, " <td><b>Name</b></td>\n");
+ FPRINTF(fp2, " <td><b>Name</b></td>\n");
if (online_display_option & 64)
{
- fprintf(fp, "Name "); // 30
+ FPRINTF(fp, "Name "); // 30
j += 30;
}
else
{
- fprintf(fp, "Name "); // 25
+ FPRINTF(fp, "Name "); // 25
j += 25;
}
}
if ((online_display_option & 6) == 6)
{
- fprintf(fp2, " <td><b>Job (levels)</b></td>\n");
- fprintf(fp, "Job Levels "); // 27
+ FPRINTF(fp2, " <td><b>Job (levels)</b></td>\n");
+ FPRINTF(fp, "Job Levels "); // 27
j += 27;
}
else if (online_display_option & 2)
{
- fprintf(fp2, " <td><b>Job</b></td>\n");
- fprintf(fp, "Job "); // 19
+ FPRINTF(fp2, " <td><b>Job</b></td>\n");
+ FPRINTF(fp, "Job "); // 19
j += 19;
}
else if (online_display_option & 4)
{
- fprintf(fp2, " <td><b>Levels</b></td>\n");
- fprintf(fp, " Levels "); // 8
+ FPRINTF(fp2, " <td><b>Levels</b></td>\n");
+ FPRINTF(fp, " Levels "); // 8
j += 8;
}
if (online_display_option & 24)
{ // 8 or 16
- fprintf(fp2, " <td><b>Location</b></td>\n");
+ FPRINTF(fp2, " <td><b>Location</b></td>\n");
if (online_display_option & 16)
{
- fprintf(fp, "Location ( x , y ) "); // 23
+ FPRINTF(fp, "Location ( x , y ) "); // 23
j += 23;
}
else
{
- fprintf(fp, "Location "); // 13
+ FPRINTF(fp, "Location "); // 13
j += 13;
}
}
if (online_display_option & 32)
{
- fprintf(fp2,
+ FPRINTF(fp2,
" <td ALIGN=CENTER><b>zenys</b></td>\n");
- fprintf(fp, " Zenys "); // 16
+ FPRINTF(fp, " Zenys "); // 16
j += 16;
}
- fprintf(fp2, " </tr>\n");
- fprintf(fp, "\n");
+ FPRINTF(fp2, " </tr>\n");
+ FPRINTF(fp, "\n");
for (k = 0; k < j; k++)
- fprintf(fp, "-");
- fprintf(fp, "\n");
+ FPRINTF(fp, "-");
+ FPRINTF(fp, "\n");
// display each player.
for (i = 0; i < players; i++)
{
// get id of the character (more speed)
j = id[i];
- fprintf(fp2, " <tr>\n");
+ FPRINTF(fp2, " <tr>\n");
// displaying the character name
if ((online_display_option & 1)
|| (online_display_option & 64))
@@ -1382,36 +1146,36 @@ void create_online_files(void)
if (online_display_option & 64)
{
if (l >= online_gm_display_min_level)
- fprintf(fp, "%-24s (GM) ", temp);
+ FPRINTF(fp, "%-24s (GM) ", temp);
else
- fprintf(fp, "%-24s ", temp);
+ FPRINTF(fp, "%-24s ", temp);
}
else
- fprintf(fp, "%-24s ", temp);
+ FPRINTF(fp, "%-24s ", temp);
// name of the character in the html (no < >, because that create problem in html code)
- fprintf(fp2, " <td>");
+ FPRINTF(fp2, " <td>");
if ((online_display_option & 64)
&& l >= online_gm_display_min_level)
- fprintf(fp2, "<b>");
+ FPRINTF(fp2, "<b>");
for (k = 0; temp[k]; k++)
{
switch (temp[k])
{
case '<': // <
- fprintf(fp2, "&lt;");
+ FPRINTF(fp2, "&lt;");
break;
case '>': // >
- fprintf(fp2, "&gt;");
+ FPRINTF(fp2, "&gt;");
break;
default:
- fprintf(fp2, "%c", temp[k]);
+ FPRINTF(fp2, "%c", temp[k]);
break;
};
}
if ((online_display_option & 64)
&& l >= online_gm_display_min_level)
- fprintf(fp2, "</b> (GM)");
- fprintf(fp2, "</td>\n");
+ FPRINTF(fp2, "</b> (GM)");
+ FPRINTF(fp2, "</td>\n");
}
// displaying of the job
if (online_display_option & 6)
@@ -1419,24 +1183,24 @@ void create_online_files(void)
const char *jobname = job_name(char_dat[j].pc_class);
if ((online_display_option & 6) == 6)
{
- fprintf(fp2, " <td>%s %d/%d</td>\n",
+ FPRINTF(fp2, " <td>%s %d/%d</td>\n",
jobname, char_dat[j].base_level,
char_dat[j].job_level);
- fprintf(fp, "%-18s %3d/%3d ", jobname,
+ FPRINTF(fp, "%-18s %3d/%3d ", jobname,
char_dat[j].base_level,
char_dat[j].job_level);
}
else if (online_display_option & 2)
{
- fprintf(fp2, " <td>%s</td>\n", jobname);
- fprintf(fp, "%-18s ", jobname);
+ FPRINTF(fp2, " <td>%s</td>\n", jobname);
+ FPRINTF(fp, "%-18s ", jobname);
}
else if (online_display_option & 4)
{
- fprintf(fp2, " <td>%d/%d</td>\n",
+ FPRINTF(fp2, " <td>%d/%d</td>\n",
char_dat[j].base_level,
char_dat[j].job_level);
- fprintf(fp, "%3d/%3d ", char_dat[j].base_level,
+ FPRINTF(fp, "%3d/%3d ", char_dat[j].base_level,
char_dat[j].job_level);
}
}
@@ -1445,23 +1209,23 @@ void create_online_files(void)
{ // 8 or 16
// prepare map name
memset(temp, 0, sizeof(temp));
- strncpy(temp, char_dat[j].last_point.map, 16);
+ strzcpy(temp, char_dat[j].last_point.map, 16);
if (strchr(temp, '.') != NULL)
temp[strchr(temp, '.') - temp] = '\0'; // suppress the '.gat'
// write map name
if (online_display_option & 16)
{ // map-name AND coordonates
- fprintf(fp2, " <td>%s (%d, %d)</td>\n",
+ FPRINTF(fp2, " <td>%s (%d, %d)</td>\n",
temp, char_dat[j].last_point.x,
char_dat[j].last_point.y);
- fprintf(fp, "%-12s (%3d,%3d) ", temp,
+ FPRINTF(fp, "%-12s (%3d,%3d) ", temp,
char_dat[j].last_point.x,
char_dat[j].last_point.y);
}
else
{
- fprintf(fp2, " <td>%s</td>\n", temp);
- fprintf(fp, "%-12s ", temp);
+ FPRINTF(fp2, " <td>%s</td>\n", temp);
+ FPRINTF(fp, "%-12s ", temp);
}
}
// displaying number of zenys
@@ -1470,30 +1234,30 @@ void create_online_files(void)
// write number of zenys
if (char_dat[j].zeny == 0)
{ // if no zeny
- fprintf(fp2,
+ FPRINTF(fp2,
" <td ALIGN=RIGHT>no zeny</td>\n");
- fprintf(fp, " no zeny ");
+ FPRINTF(fp, " no zeny ");
}
else
{
- fprintf(fp2,
+ FPRINTF(fp2,
" <td ALIGN=RIGHT>%d z</td>\n",
char_dat[j].zeny);
- fprintf(fp, "%13d z ", char_dat[j].zeny);
+ FPRINTF(fp, "%13d z ", char_dat[j].zeny);
}
}
- fprintf(fp, "\n");
- fprintf(fp2, " </tr>\n");
+ FPRINTF(fp, "\n");
+ FPRINTF(fp2, " </tr>\n");
}
- fprintf(fp2, " </table>\n");
- fprintf(fp, "\n");
+ FPRINTF(fp2, " </table>\n");
+ FPRINTF(fp, "\n");
}
// Displaying number of online players
if (players == 0)
{
- fprintf(fp2, " <p>No user is online.</p>\n");
- fprintf(fp, "No user is online.\n");
+ FPRINTF(fp2, " <p>No user is online.</p>\n");
+ FPRINTF(fp, "No user is online.\n");
// no display if only 1 player
}
else if (players == 1)
@@ -1501,11 +1265,11 @@ void create_online_files(void)
}
else
{
- fprintf(fp2, " <p>%d users are online.</p>\n", players);
- fprintf(fp, "%d users are online.\n", players);
+ FPRINTF(fp2, " <p>%d users are online.</p>\n", players);
+ FPRINTF(fp, "%d users are online.\n", players);
}
- fprintf(fp2, " </BODY>\n");
- fprintf(fp2, "</HTML>\n");
+ FPRINTF(fp2, " </BODY>\n");
+ FPRINTF(fp2, "</HTML>\n");
fclose_(fp2);
}
fclose_(fp);
@@ -1757,7 +1521,7 @@ void parse_tologin(int fd)
{
if (fd == login_fd)
{
- printf("Char-server can't connect to login-server (connection #%d).\n",
+ PRINTF("Char-server can't connect to login-server (connection #%d).\n",
fd);
login_fd = -1;
}
@@ -1770,7 +1534,7 @@ void parse_tologin(int fd)
while (RFIFOREST(fd) >= 2)
{
-// printf("parse_tologin: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
+// PRINTF("parse_tologin: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
switch (RFIFOW(fd, 0))
{
@@ -1779,16 +1543,16 @@ void parse_tologin(int fd)
return;
if (RFIFOB(fd, 2))
{
-// printf("connect login server error : %d\n", RFIFOB(fd,2));
- printf("Can not connect to login-server.\n");
- printf("The server communication passwords (default s1/p1) is probably invalid.\n");
- printf("Also, please make sure your accounts file (default: accounts.txt) has those values present.\n");
- printf("If you changed the communication passwords, change them back at map_athena.conf and char_athena.conf\n");
+// PRINTF("connect login server error : %d\n", RFIFOB(fd,2));
+ PRINTF("Can not connect to login-server.\n");
+ PRINTF("The server communication passwords (default s1/p1) is probably invalid.\n");
+ PRINTF("Also, please make sure your accounts file (default: accounts.txt) has those values present.\n");
+ PRINTF("If you changed the communication passwords, change them back at map_athena.conf and char_athena.conf\n");
exit(1);
}
else
{
- printf("Connected to login-server (connection #%d).\n",
+ PRINTF("Connected to login-server (connection #%d).\n",
fd);
// if no map-server already connected, display a message...
int i;
@@ -1796,7 +1560,7 @@ void parse_tologin(int fd)
if (server_fd[i] >= 0 && server[i].map[0][0]) // if map-server online and at least 1 map
break;
if (i == MAX_MAP_SERVERS)
- printf("Awaiting maps from map-server.\n");
+ PRINTF("Awaiting maps from map-server.\n");
}
RFIFOSKIP(fd, 3);
break;
@@ -1804,7 +1568,7 @@ void parse_tologin(int fd)
case 0x2713:
if (RFIFOREST(fd) < 51)
return;
-// printf("parse_tologin 2713 : %d\n", RFIFOB(fd,6));
+// PRINTF("parse_tologin 2713 : %d\n", RFIFOB(fd,6));
for (int i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct char_session_data*)session[i]->session_data)
@@ -1820,12 +1584,12 @@ void parse_tologin(int fd)
|| count_users() < max_connect_user)
{
// if (max_connect_user == 0)
-// printf("max_connect_user (unlimited) -> accepted.\n");
+// PRINTF("max_connect_user (unlimited) -> accepted.\n");
// else
-// printf("count_users(): %d < max_connect_user (%d) -> accepted.\n", count_users(), max_connect_user);
+// PRINTF("count_users(): %d < max_connect_user (%d) -> accepted.\n", count_users(), max_connect_user);
memcpy(sd->email, RFIFOP(fd, 7), 40);
if (e_mail_check(sd->email) == 0)
- strncpy(sd->email, "a@a.com", 40); // default e-mail
+ strzcpy(sd->email, "a@a.com", 40); // default e-mail
sd->connect_until_time = (time_t) RFIFOL(fd, 47);
// send characters to player
mmo_char_send006b(i, sd);
@@ -1833,7 +1597,7 @@ void parse_tologin(int fd)
else
{
// refuse connection: too much online players
-// printf("count_users(): %d < max_connect_use (%d) -> fail...\n", count_users(), max_connect_user);
+// PRINTF("count_users(): %d < max_connect_use (%d) -> fail...\n", count_users(), max_connect_user);
WFIFOW(i, 0) = 0x6c;
WFIFOW(i, 2) = 0;
WFIFOSET(i, 3);
@@ -1856,7 +1620,7 @@ void parse_tologin(int fd)
{
memcpy(sd->email, RFIFOP(fd, 6), 40);
if (e_mail_check(sd->email) == 0)
- strncpy(sd->email, "a@a.com", 40); // default e-mail
+ strzcpy(sd->email, "a@a.com", 40); // default e-mail
sd->connect_until_time = (time_t) RFIFOL(fd, 46);
break;
}
@@ -1874,7 +1638,7 @@ void parse_tologin(int fd)
WBUFL(buf, 2) = RFIFOL(fd, 2); // account
WBUFL(buf, 6) = RFIFOL(fd, 6); // GM level
mapif_sendall(buf, 10);
-// printf("parse_tologin: To become GM answer: char -> map.\n");
+// PRINTF("parse_tologin: To become GM answer: char -> map.\n");
}
RFIFOSKIP(fd, 10);
break;
@@ -1948,7 +1712,7 @@ void parse_tologin(int fd)
|| RFIFOREST(fd) < (8 + RFIFOL(fd, 4)))
return;
if (RFIFOL(fd, 4) < 1)
- char_log("Receiving a message for broadcast, but message is void.\n");
+ CHAR_LOG("Receiving a message for broadcast, but message is void.\n");
else
{
int i;
@@ -1957,7 +1721,7 @@ void parse_tologin(int fd)
if (server_fd[i] >= 0)
break;
if (i == MAX_MAP_SERVERS)
- char_log("'ladmin': Receiving a message for broadcast, but no map-server is online.\n");
+ CHAR_LOG("'ladmin': Receiving a message for broadcast, but no map-server is online.\n");
else
{
uint8_t buf[128];
@@ -1974,49 +1738,30 @@ void parse_tologin(int fd)
p++;
// if message is only composed of spaces
if (p[0] == '\0')
- char_log("Receiving a message for broadcast, but message is only a lot of spaces.\n");
+ CHAR_LOG("Receiving a message for broadcast, but message is only a lot of spaces.\n");
// else send message to all map-servers
else
{
if (RFIFOW(fd, 2) == 0)
{
- char_log("'ladmin': Receiving a message for broadcast (message (in yellow): %s)\n",
- message);
+ const char *message_ptr = message;
+ CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s)\n",
+ message_ptr);
lp = 4;
}
else
{
- char_log("'ladmin': Receiving a message for broadcast (message (in blue): %s)\n",
- message);
+ const char *message_ptr = message;
+ CHAR_LOG("'ladmin': Receiving a message for broadcast (message (in blue): %s)\n",
+ message_ptr);
lp = 8;
}
- // split message to max 80 char
- while (p[0] != '\0')
- { // if not finish
- if (p[0] == ' ') // jump if first char is a space
- p++;
- else
- {
- char split[80];
- char *last_space;
- sscanf(p, "%79[^\t]", split); // max 79 char, any char (\t is control char and control char was removed before)
- split[sizeof(split) - 1] = '\0'; // last char always \0
- if ((last_space =
- strrchr(split, ' ')) != NULL)
- { // searching space from end of the string
- last_space[0] = '\0'; // replace it by NULL to have correct length of split
- p++; // to jump the new NULL
- }
- p += strlen(split);
- // send broadcast to all map-servers
- WBUFW(buf, 0) = 0x3800;
- WBUFW(buf, 2) = lp + strlen(split) + 1;
- WBUFL(buf, 4) = 0x65756c62; // only write if in blue (lp = 8)
- memcpy(WBUFP(buf, lp), split,
- strlen(split) + 1);
- mapif_sendall(buf, WBUFW(buf, 2));
- }
- }
+ // send broadcast to all map-servers
+ WBUFW(buf, 0) = 0x3800;
+ WBUFW(buf, 2) = lp + sizeof(message);
+ WBUFL(buf, 4) = 0x65756c62; // only write if in blue (lp = 8)
+ memcpy(WBUFP(buf, lp), message, sizeof(message));
+ mapif_sendall(buf, WBUFW(buf, 2));
}
}
}
@@ -2045,7 +1790,7 @@ void parse_tologin(int fd)
WBUFW(buf, 0) = 0x2b11;
mapif_sendall(buf, WBUFW(buf, 2));
RFIFOSKIP(fd, RFIFOW(fd, 2));
-// printf("char: save_account_reg_reply\n");
+// PRINTF("char: save_account_reg_reply\n");
}
break;
@@ -2084,7 +1829,7 @@ void parse_tologin(int fd)
FIX(s->storage_[j].nameid);
#undef FIX
if (changes)
- char_log("itemfrob(%d -> %d): `%s'(%d, account %d): changed %d times\n",
+ CHAR_LOG("itemfrob(%d -> %d): `%s'(%d, account %d): changed %d times\n",
source_id, dest_id, c->name, c->char_id,
c->account_id, changes);
@@ -2190,12 +1935,12 @@ void parse_tologin(int fd)
{
gm_account[GM_num].account_id = RFIFOL(fd, i);
gm_account[GM_num].level = (int) RFIFOB(fd, i + 4);
- //printf("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);
+ //PRINTF("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);
GM_num++;
}
- printf("From login-server: receiving of %d GM accounts information.\n",
+ PRINTF("From login-server: receiving of %d GM accounts information.\n",
GM_num);
- char_log("From login-server: receiving of %d GM accounts information.\n",
+ CHAR_LOG("From login-server: receiving of %d GM accounts information.\n",
GM_num);
create_online_files(); // update online players files (perhaps some online players change of GM level)
// send new gm acccounts level to map-servers
@@ -2246,17 +1991,17 @@ void map_anti_freeze_system(timer_id, tick_t, custom_id_t, custom_data_t)
{
int i;
- //printf("Entering in map_anti_freeze_system function to check freeze of servers.\n");
+ //PRINTF("Entering in map_anti_freeze_system function to check freeze of servers.\n");
for (i = 0; i < MAX_MAP_SERVERS; i++)
{
if (server_fd[i] >= 0)
{ // if map-server is online
- //printf("map_anti_freeze_system: server #%d, flag: %d.\n", i, server_freezeflag[i]);
+ //PRINTF("map_anti_freeze_system: server #%d, flag: %d.\n", i, server_freezeflag[i]);
if (server_freezeflag[i]-- < 1)
{ // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed
- printf("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n",
+ PRINTF("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n",
i);
- char_log("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n",
+ CHAR_LOG("Map-server anti-freeze system: char-server #%d is freezed -> disconnection.\n",
i);
session[server_fd[i]]->eof = 1;
}
@@ -2277,7 +2022,7 @@ void parse_frommap(int fd)
{
if (id < MAX_MAP_SERVERS)
{
- printf("Map-server %d (session #%d) has disconnected.\n", id,
+ PRINTF("Map-server %d (session #%d) has disconnected.\n", id,
fd);
memset(&server[id], 0, sizeof(struct mmo_map_server));
server_fd[id] = -1;
@@ -2293,7 +2038,7 @@ void parse_frommap(int fd)
while (RFIFOREST(fd) >= 2)
{
-// printf("parse_frommap: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
+// PRINTF("parse_frommap: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
switch (RFIFOW(fd, 0))
{
@@ -2303,7 +2048,7 @@ void parse_frommap(int fd)
{ // don't send request if no login-server
WFIFOW(login_fd, 0) = 0x2709;
WFIFOSET(login_fd, 2);
-// printf("char : request from map-server to reload GM accounts -> login-server.\n");
+// PRINTF("char : request from map-server to reload GM accounts -> login-server.\n");
}
RFIFOSKIP(fd, 2);
break;
@@ -2317,15 +2062,15 @@ void parse_frommap(int fd)
for (i = 4; i < RFIFOW(fd, 2); i += 16)
{
memcpy(server[id].map[j], RFIFOP(fd, i), 16);
-// printf("set map %d.%d : %s\n", id, j, server[id].map[j]);
+// PRINTF("set map %d.%d : %s\n", id, j, server[id].map[j]);
j++;
}
{
unsigned char *p = (unsigned char *) &server[id].ip;
- printf("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n",
+ PRINTF("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n",
id, j, p[0], p[1], p[2], p[3], server[id].port);
- printf("Map-server %d loading complete.\n", id);
- char_log("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d. Map-server %d loading complete.\n",
+ PRINTF("Map-server %d loading complete.\n", id);
+ CHAR_LOG("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d. Map-server %d loading complete.\n",
id, j, p[0], p[1], p[2], p[3],
server[id].port, id);
}
@@ -2338,8 +2083,8 @@ void parse_frommap(int fd)
int x;
if (j == 0)
{
- printf("WARNING: Map-Server %d have NO map.\n", id);
- char_log("WARNING: Map-Server %d have NO map.\n",
+ PRINTF("WARNING: Map-Server %d have NO map.\n", id);
+ CHAR_LOG("WARNING: Map-Server %d have NO map.\n",
id);
// Transmitting maps information to the other map-servers
}
@@ -2380,7 +2125,7 @@ void parse_frommap(int fd)
case 0x2afc:
if (RFIFOREST(fd) < 22)
return;
- //printf("auth_fifo search: account: %d, char: %d, secure: %08x-%08x\n", RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14));
+ //PRINTF("auth_fifo search: account: %d, char: %d, secure: %08x-%08x\n", RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14));
for (i = 0; i < AUTH_FIFO_SIZE; i++)
{
if (auth_fifo[i].account_id == RFIFOL(fd, 2) &&
@@ -2403,14 +2148,14 @@ void parse_frommap(int fd)
char_dat[auth_fifo[i].char_pos].sex =
auth_fifo[i].sex;
WFIFOW(fd, 16) = auth_fifo[i].packet_tmw_version;
- fprintf(stderr,
+ FPRINTF(stderr,
"From queue index %d: recalling packet version %d\n",
i, auth_fifo[i].packet_tmw_version);
memcpy(WFIFOP(fd, 18),
&char_dat[auth_fifo[i].char_pos],
sizeof(struct mmo_charstatus));
WFIFOSET(fd, WFIFOW(fd, 2));
- //printf("auth_fifo search success (auth #%d, account %d, character: %d).\n", i, RFIFOL(fd,2), RFIFOL(fd,6));
+ //PRINTF("auth_fifo search success (auth #%d, account %d, character: %d).\n", i, RFIFOL(fd,2), RFIFOL(fd,6));
break;
}
}
@@ -2419,7 +2164,7 @@ void parse_frommap(int fd)
WFIFOW(fd, 0) = 0x2afe;
WFIFOL(fd, 2) = RFIFOL(fd, 2);
WFIFOSET(fd, 6);
- printf("auth_fifo search error! account %d not authentified.\n",
+ PRINTF("auth_fifo search error! account %d not authentified.\n",
RFIFOL(fd, 2));
}
RFIFOSKIP(fd, 22);
@@ -2444,7 +2189,7 @@ void parse_frommap(int fd)
if (char_dat[j].char_id == char_id)
{
online_chars[j] = id;
- //printf("%d\n", char_id);
+ //PRINTF("%d\n", char_id);
break;
}
}
@@ -2479,7 +2224,7 @@ void parse_frommap(int fd)
return;
if (auth_fifo_pos >= AUTH_FIFO_SIZE)
auth_fifo_pos = 0;
- //printf("auth_fifo set (auth #%d) - account: %d, secure: %08x-%08x\n", auth_fifo_pos, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10));
+ //PRINTF("auth_fifo set (auth #%d) - account: %d, secure: %08x-%08x\n", auth_fifo_pos, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10));
auth_fifo[auth_fifo_pos].account_id = RFIFOL(fd, 2);
auth_fifo[auth_fifo_pos].char_id = 0;
auth_fifo[auth_fifo_pos].login_id1 = RFIFOL(fd, 6);
@@ -2504,7 +2249,7 @@ void parse_frommap(int fd)
auth_fifo_pos = 0;
WFIFOW(fd, 0) = 0x2b06;
memcpy(WFIFOP(fd, 2), RFIFOP(fd, 2), 42);
- //printf("auth_fifo set (auth#%d) - account: %d, secure: 0x%08x-0x%08x\n", auth_fifo_pos, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10));
+ //PRINTF("auth_fifo set (auth#%d) - account: %d, secure: 0x%08x-0x%08x\n", auth_fifo_pos, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10));
auth_fifo[auth_fifo_pos].account_id = RFIFOL(fd, 2);
auth_fifo[auth_fifo_pos].char_id = RFIFOL(fd, 14);
auth_fifo[auth_fifo_pos].login_id1 = RFIFOL(fd, 6);
@@ -2551,7 +2296,7 @@ void parse_frommap(int fd)
case 0x2b0a:
if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd, 2))
return;
-// printf("parse_frommap: change gm -> login, account: %d, pass: '%s'.\n", RFIFOL(fd,4), RFIFOP(fd,8));
+// PRINTF("parse_frommap: change gm -> login, account: %d, pass: '%s'.\n", RFIFOL(fd,4), RFIFOP(fd,8));
if (login_fd > 0)
{ // don't send request if no login-server
WFIFOW(login_fd, 0) = 0x2720;
@@ -2614,7 +2359,7 @@ void parse_frommap(int fd)
WFIFOL(login_fd, 2) = char_dat[i].account_id; // account value
WFIFOL(login_fd, 6) = 5; // status of the account
WFIFOSET(login_fd, 10);
-// printf("char : status -> login: account %d, status: %d \n", char_dat[i].account_id, 5);
+// PRINTF("char : status -> login: account %d, status: %d \n", char_dat[i].account_id, 5);
}
else
WFIFOW(fd, 32) = 3; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline
@@ -2638,7 +2383,7 @@ void parse_frommap(int fd)
WFIFOW(login_fd, 14) = RFIFOW(fd, 40); // minute
WFIFOW(login_fd, 16) = RFIFOW(fd, 42); // second
WFIFOSET(login_fd, 18);
-// printf("char : status -> login: account %d, ban: %dy %dm %dd %dh %dmn %ds\n",
+// PRINTF("char : status -> login: account %d, ban: %dy %dm %dd %dh %dmn %ds\n",
// char_dat[i].account_id, (short)RFIFOW(fd,32), (short)RFIFOW(fd,34), (short)RFIFOW(fd,36), (short)RFIFOW(fd,38), (short)RFIFOW(fd,40), (short)RFIFOW(fd,42));
}
else
@@ -2658,7 +2403,7 @@ void parse_frommap(int fd)
WFIFOL(login_fd, 2) = char_dat[i].account_id; // account value
WFIFOL(login_fd, 6) = 0; // status of the account
WFIFOSET(login_fd, 10);
-// printf("char : status -> login: account %d, status: %d \n", char_dat[i].account_id, 0);
+// PRINTF("char : status -> login: account %d, status: %d \n", char_dat[i].account_id, 0);
}
else
WFIFOW(fd, 32) = 3; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline
@@ -2676,7 +2421,7 @@ void parse_frommap(int fd)
WFIFOW(login_fd, 0) = 0x272a;
WFIFOL(login_fd, 2) = char_dat[i].account_id; // account value
WFIFOSET(login_fd, 6);
-// printf("char : status -> login: account %d, unban request\n", char_dat[i].account_id);
+// PRINTF("char : status -> login: account %d, unban request\n", char_dat[i].account_id);
}
else
WFIFOW(fd, 32) = 3; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline
@@ -2694,7 +2439,7 @@ void parse_frommap(int fd)
WFIFOW(login_fd, 0) = 0x2727;
WFIFOL(login_fd, 2) = char_dat[i].account_id; // account value
WFIFOSET(login_fd, 6);
-// printf("char : status -> login: account %d, change sex request\n", char_dat[i].account_id);
+// PRINTF("char : status -> login: account %d, change sex request\n", char_dat[i].account_id);
}
else
WFIFOW(fd, 32) = 3; // answer: 0-login-server resquest done, 1-player not found, 2-gm level too low, 3-login-server offline
@@ -2750,7 +2495,7 @@ void parse_frommap(int fd)
//WBUFW(buf,0) = 0x2b11;
//mapif_sendall(buf, WBUFW(buf,2));
RFIFOSKIP(fd, RFIFOW(fd, 2));
-// printf("char: save_account_reg (from map)\n");
+// PRINTF("char: save_account_reg (from map)\n");
break;
}
@@ -2781,7 +2526,7 @@ void parse_frommap(int fd)
return;
}
// inter server処理でもない場合は切断
- printf("char: unknown packet 0x%04x (%d bytes to read in buffer)! (from map).\n",
+ PRINTF("char: unknown packet 0x%04x (%d bytes to read in buffer)! (from map).\n",
RFIFOW(fd, 0), RFIFOREST(fd));
session[fd]->eof = 1;
return;
@@ -2796,9 +2541,8 @@ int search_mapserver(const char *map)
char temp_map[16];
int temp_map_len;
-// printf("Searching the map-server for map '%s'... ", map);
- strncpy(temp_map, map, sizeof(temp_map));
- temp_map[sizeof(temp_map) - 1] = '\0';
+// PRINTF("Searching the map-server for map '%s'... ", map);
+ strzcpy(temp_map, map, sizeof(temp_map));
if (strchr(temp_map, '.') != NULL)
temp_map[strchr(temp_map, '.') - temp_map + 1] = '\0'; // suppress the '.gat', but conserve the '.' to be sure of the name of the map
@@ -2806,14 +2550,14 @@ int search_mapserver(const char *map)
for (i = 0; i < MAX_MAP_SERVERS; i++)
if (server_fd[i] >= 0)
for (j = 0; server[i].map[j][0]; j++)
- //printf("%s : %s = %d\n", server[i].map[j], map, strncmp(server[i].map[j], temp_map, temp_map_len));
+ //PRINTF("%s : %s = %d\n", server[i].map[j], map, strncmp(server[i].map[j], temp_map, temp_map_len));
if (strncmp(server[i].map[j], temp_map, temp_map_len) == 0)
{
-// printf("found -> server #%d.\n", i);
+// PRINTF("found -> server #%d.\n", i);
return i;
}
-// printf("not found.\n");
+// PRINTF("not found.\n");
return -1;
}
@@ -2826,7 +2570,7 @@ int lan_ip_check(unsigned char *p)
int i;
int lancheck = 1;
-// printf("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
+// PRINTF("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
// p[0], p[1], p[2], p[3],
// subneti[0], subneti[1], subneti[2], subneti[3],
// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
@@ -2838,7 +2582,7 @@ int lan_ip_check(unsigned char *p)
break;
}
}
- printf("LAN test (result): %s source\033[0m.\n",
+ PRINTF("LAN test (result): %s source\033[0m.\n",
(lancheck) ? "\033[1;36mLAN" : "\033[1;32mWAN");
return lancheck;
}
@@ -2865,7 +2609,7 @@ void parse_char(int fd)
while (RFIFOREST(fd) >= 2)
{
// if (RFIFOW(fd,0) < 30000)
-// printf("parse_char: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
+// PRINTF("parse_char: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
switch (RFIFOW(fd, 0))
{
@@ -2894,10 +2638,10 @@ void parse_char(int fd)
{
int GM_value;
if ((GM_value = isGM(RFIFOL(fd, 2))))
- printf("Account Logged On; Account ID: %d (GM level %d).\n",
+ PRINTF("Account Logged On; Account ID: %d (GM level %d).\n",
RFIFOL(fd, 2), GM_value);
else
- printf("Account Logged On; Account ID: %d.\n",
+ PRINTF("Account Logged On; Account ID: %d.\n",
RFIFOL(fd, 2));
if (sd == NULL)
{
@@ -3004,7 +2748,7 @@ void parse_char(int fd)
break;
if (ch != 9)
{
- char_log("Character Selected, Account ID: %d, Character Slot: %d, Character Name: %s [%s]\n",
+ CHAR_LOG("Character Selected, Account ID: %d, Character Slot: %d, Character Name: %s [%s]\n",
sd->account_id, RFIFOB(fd, 2),
char_dat[sd->found_char[ch]].name, ip);
// searching map server
@@ -3087,7 +2831,7 @@ void parse_char(int fd)
[sd->
found_char[ch]].last_point.
map, server[j].map[0], 16);
- printf("Map-server #%d found with a map: '%s'.\n",
+ PRINTF("Map-server #%d found with a map: '%s'.\n",
j, server[j].map[0]);
// coordonates are unknown
break;
@@ -3108,10 +2852,10 @@ void parse_char(int fd)
memcpy(WFIFOP(fd, 6),
char_dat[sd->found_char[ch]].last_point.map,
16);
- printf("Character selection '%s' (account: %d, slot: %d) [%s]\n",
+ PRINTF("Character selection '%s' (account: %d, slot: %d) [%s]\n",
char_dat[sd->found_char[ch]].name,
sd->account_id, ch, ip);
- printf("--Send IP of map-server. ");
+ PRINTF("--Send IP of map-server. ");
if (lan_ip_check(p))
WFIFOL(fd, 22) = inet_addr(lan_map_ip);
else
@@ -3120,7 +2864,7 @@ void parse_char(int fd)
WFIFOSET(fd, 28);
if (auth_fifo_pos >= AUTH_FIFO_SIZE)
auth_fifo_pos = 0;
- //printf("auth_fifo set #%d - account %d, char: %d, secure: %08x-%08x\n", auth_fifo_pos, sd->account_id, char_dat[sd->found_char[ch]].char_id, sd->login_id1, sd->login_id2);
+ //PRINTF("auth_fifo set #%d - account %d, char: %d, secure: %08x-%08x\n", auth_fifo_pos, sd->account_id, char_dat[sd->found_char[ch]].char_id, sd->login_id1, sd->login_id2);
auth_fifo[auth_fifo_pos].account_id = sd->account_id;
auth_fifo[auth_fifo_pos].char_id =
char_dat[sd->found_char[ch]].char_id;
@@ -3217,7 +2961,7 @@ void parse_char(int fd)
return;
memcpy(email, RFIFOP(fd, 6), 40);
if (e_mail_check(email) == 0)
- strncpy(email, "a@a.com", 40); // default e-mail
+ strzcpy(email, "a@a.com", 40); // default e-mail
// if we activated email creation and email is default email
if (email_creation != 0 && strcmp(sd->email, "a@a.com") == 0
@@ -3498,7 +3242,7 @@ void check_connect_login_server(timer_id, tick_t, custom_id_t, custom_data_t)
{
if (login_fd <= 0 || session[login_fd] == NULL)
{
- printf("Attempt to connect to login-server...\n");
+ PRINTF("Attempt to connect to login-server...\n");
if ((login_fd = make_connection(login_ip, login_port)) < 0)
return;
session[login_fd]->func_parse = parse_tologin;
@@ -3529,44 +3273,38 @@ void check_connect_login_server(timer_id, tick_t, custom_id_t, custom_data_t)
static
int lan_config_read(const char *lancfgName)
{
- int j;
struct hostent *h = NULL;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
// set default configuration
- strncpy(lan_map_ip, "127.0.0.1", sizeof(lan_map_ip));
+ strzcpy(lan_map_ip, "127.0.0.1", sizeof(lan_map_ip));
subneti[0] = 127;
subneti[1] = 0;
subneti[2] = 0;
subneti[3] = 1;
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = 255;
- fp = fopen_(lancfgName, "r");
+ std::ifstream in(lancfgName);
- if (fp == NULL)
+ if (!in.is_open())
{
- printf("LAN support configuration file not found: %s\n", lancfgName);
+ PRINTF("LAN support configuration file not found: %s\n", lancfgName);
return 1;
}
- printf("---start reading of Lan Support configuration...\n");
+ PRINTF("---start reading of Lan Support configuration...\n");
- while (fgets(line, sizeof(line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- line[sizeof(line) - 1] = '\0';
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
- continue;
-
- remove_control_chars(w1);
- remove_control_chars(w2);
- if (strcasecmp(w1, "lan_map_ip") == 0)
- { // Read map-server Lan IP Address
- h = gethostbyname(w2);
+ if (w1 == "lan_map_ip")
+ {
+ // Read map-server Lan IP Address
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
sprintf(lan_map_ip, "%d.%d.%d.%d",
@@ -3577,50 +3315,54 @@ int lan_config_read(const char *lancfgName)
}
else
{
- strncpy(lan_map_ip, w2, sizeof(lan_map_ip));
- lan_map_ip[sizeof(lan_map_ip) - 1] = 0;
+ strzcpy(lan_map_ip, w2.c_str(), sizeof(lan_map_ip));
}
- printf("LAN IP of map-server: %s.\n", lan_map_ip);
+ PRINTF("LAN IP of map-server: %s.\n", lan_map_ip);
}
- else if (strcasecmp(w1, "subnet") == 0)
- { // Read Subnetwork
- for (j = 0; j < 4; j++)
+ else if (w1 == "subnet")
+ {
+ // Read Subnetwork
+ for (int j = 0; j < 4; j++)
subneti[j] = 0;
- h = gethostbyname(w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subneti[j] = (unsigned char) h->h_addr[j];
}
else
{
- sscanf(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1],
+ SSCANF(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1],
&subneti[2], &subneti[3]);
}
- printf("Sub-network of the map-server: %d.%d.%d.%d.\n",
+ PRINTF("Sub-network of the map-server: %d.%d.%d.%d.\n",
subneti[0], subneti[1], subneti[2], subneti[3]);
}
- else if (strcasecmp(w1, "subnetmask") == 0)
- { // Read Subnetwork Mask
- for (j = 0; j < 4; j++)
+ else if (w1 == "subnetmask")
+ {
+ // Read Subnetwork Mask
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = 255;
- h = gethostbyname(w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = (unsigned char) h->h_addr[j];
}
else
{
- sscanf(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1],
+ SSCANF(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1],
&subnetmaski[2], &subnetmaski[3]);
}
- printf("Sub-network mask of the map-server: %d.%d.%d.%d.\n",
+ PRINTF("Sub-network mask of the map-server: %d.%d.%d.%d.\n",
subnetmaski[0], subnetmaski[1], subnetmaski[2],
subnetmaski[3]);
}
+ else
+ {
+ PRINTF("WARNING: unknown lan config key: %s", w1);
+ }
}
- fclose_(fp);
// sub-network check of the map-server
{
@@ -3631,14 +3373,14 @@ int lan_config_read(const char *lancfgName)
p[1] = a1;
p[2] = a2;
p[3] = a3;
- printf("LAN test of LAN IP of the map-server: ");
+ PRINTF("LAN test of LAN IP of the map-server: ");
if (lan_ip_check(p) == 0)
{
- printf("\033[1;31m***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network.\033[0m\n");
+ PRINTF("\033[1;31m***ERROR: LAN IP of the map-server doesn't belong to the specified Sub-network.\033[0m\n");
}
}
- printf("---End reading of Lan Support configuration...\n");
+ PRINTF("---End reading of Lan Support configuration...\n");
return 0;
}
@@ -3647,54 +3389,42 @@ static
int char_config_read(const char *cfgName)
{
struct hostent *h = NULL;
- char line[1024], w1[1024], w2[1024];
- FILE *fp = fopen_(cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+
+ if (!in.is_open())
{
- printf("Configuration file not found: %s.\n", cfgName);
+ PRINTF("Configuration file not found: %s.\n", cfgName);
exit(1);
}
- while (fgets(line, sizeof(line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
- continue;
-
- line[sizeof(line) - 1] = '\0';
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- remove_control_chars(w1);
- remove_control_chars(w2);
- if (strcasecmp(w1, "userid") == 0)
- {
- memcpy(userid, w2, 24);
- }
- else if (strcasecmp(w1, "passwd") == 0)
- {
- memcpy(passwd, w2, 24);
- }
- else if (strcasecmp(w1, "server_name") == 0)
+ if (w1 == "userid")
+ strzcpy(userid, w2.c_str(), 24);
+ else if (w1 == "passwd")
+ strzcpy(passwd, w2.c_str(), 24);
+ else if (w1 == "server_name")
{
- memcpy(server_name, w2, sizeof(server_name));
- server_name[sizeof(server_name) - 1] = '\0';
- printf("%s server has been intialized\n", w2);
+ strzcpy(server_name, w2.c_str(), sizeof(server_name));
+ PRINTF("%s server has been intialized\n", w2);
}
- else if (strcasecmp(w1, "wisp_server_name") == 0)
+ else if (w1 == "wisp_server_name")
{
- if (strlen(w2) >= 4)
- {
- strncpy(wisp_server_name, w2, sizeof(wisp_server_name));
- wisp_server_name[sizeof(wisp_server_name) - 1] = '\0';
- }
+ if (w2.size() >= 4)
+ strzcpy(wisp_server_name, w2.c_str(), sizeof(wisp_server_name));
}
- else if (strcasecmp(w1, "login_ip") == 0)
+ else if (w1 == "login_ip")
{
- h = gethostbyname(w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- printf("Login server IP address : %s -> %d.%d.%d.%d\n", w2,
+ PRINTF("Login server IP address : %s -> %d.%d.%d.%d\n", w2,
(unsigned char) h->h_addr[0],
(unsigned char) h->h_addr[1],
(unsigned char) h->h_addr[2],
@@ -3706,18 +3436,18 @@ int char_config_read(const char *cfgName)
(unsigned char) h->h_addr[3]);
}
else
- memcpy(login_ip_str, w2, 16);
+ strzcpy(login_ip_str, w2.c_str(), 16);
}
- else if (strcasecmp(w1, "login_port") == 0)
+ else if (w1 == "login_port")
{
- login_port = atoi(w2);
+ login_port = atoi(w2.c_str());
}
- else if (strcasecmp(w1, "char_ip") == 0)
+ else if (w1 == "char_ip")
{
- h = gethostbyname(w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- printf("Character server IP address : %s -> %d.%d.%d.%d\n",
+ PRINTF("Character server IP address : %s -> %d.%d.%d.%d\n",
w2, (unsigned char) h->h_addr[0],
(unsigned char) h->h_addr[1],
(unsigned char) h->h_addr[2],
@@ -3729,57 +3459,49 @@ int char_config_read(const char *cfgName)
(unsigned char) h->h_addr[3]);
}
else
- memcpy(char_ip_str, w2, 16);
+ strzcpy(char_ip_str, w2.c_str(), 16);
}
- else if (strcasecmp(w1, "char_port") == 0)
+ else if (w1 == "char_port")
{
- char_port = atoi(w2);
+ char_port = atoi(w2.c_str());
}
- else if (strcasecmp(w1, "char_maintenance") == 0)
+ else if (w1 == "char_maintenance")
{
- char_maintenance = atoi(w2);
+ char_maintenance = atoi(w2.c_str());
}
- else if (strcasecmp(w1, "char_new") == 0)
+ else if (w1 == "char_new")
{
- char_new = atoi(w2);
+ char_new = atoi(w2.c_str());
}
- else if (strcasecmp(w1, "email_creation") == 0)
+ else if (w1 == "email_creation")
{
- email_creation = config_switch (w2);
+ email_creation = config_switch(w2.c_str());
}
- else if (strcasecmp(w1, "char_txt") == 0)
+ else if (w1 == "char_txt")
{
- strcpy(char_txt, w2);
- }
- else if (strcasecmp(w1, "backup_txt") == 0)
- { //By zanetheinsane
- strcpy(backup_txt, w2);
+ strzcpy(char_txt, w2.c_str(), sizeof(char_txt));
}
- else if (strcasecmp(w1, "backup_txt_flag") == 0)
- { // The backup_txt file was created because char deletion bug existed. Now it's finish and that take a lot of time to create a second file when there are a lot of characters. By [Yor]
- backup_txt_flag = config_switch (w2);
- }
- else if (strcasecmp(w1, "max_connect_user") == 0)
+ else if (w1 == "max_connect_user")
{
- max_connect_user = atoi(w2);
+ max_connect_user = atoi(w2.c_str());
if (max_connect_user < 0)
max_connect_user = 0; // unlimited online players
}
- else if (strcasecmp(w1, "check_ip_flag") == 0)
+ else if (w1 == "check_ip_flag")
{
- check_ip_flag = config_switch (w2);
+ check_ip_flag = config_switch(w2.c_str());
}
- else if (strcasecmp(w1, "autosave_time") == 0)
+ else if (w1 == "autosave_time")
{
- autosave_interval = atoi(w2) * 1000;
+ autosave_interval = atoi(w2.c_str()) * 1000;
if (autosave_interval <= 0)
autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
}
- else if (strcasecmp(w1, "start_point") == 0)
+ else if (w1 == "start_point")
{
char map[32];
int x, y;
- if (sscanf(w2, "%[^,],%d,%d", map, &x, &y) < 3)
+ if (SSCANF(w2, "%[^,],%d,%d", map, &x, &y) < 3)
continue;
if (strstr(map, ".gat") != NULL)
{ // Verify at least if '.gat' is in the map name
@@ -3788,90 +3510,91 @@ int char_config_read(const char *cfgName)
start_point.y = y;
}
}
- else if (strcasecmp(w1, "start_zeny") == 0)
+ else if (w1 == "start_zeny")
{
- start_zeny = atoi(w2);
+ start_zeny = atoi(w2.c_str());
if (start_zeny < 0)
start_zeny = 0;
}
- else if (strcasecmp(w1, "start_weapon") == 0)
+ else if (w1 == "start_weapon")
{
- start_weapon = atoi(w2);
+ start_weapon = atoi(w2.c_str());
if (start_weapon < 0)
start_weapon = 0;
}
- else if (strcasecmp(w1, "start_armor") == 0)
+ else if (w1 == "start_armor")
{
- start_armor = atoi(w2);
+ start_armor = atoi(w2.c_str());
if (start_armor < 0)
start_armor = 0;
}
- else if (strcasecmp(w1, "unknown_char_name") == 0)
+ else if (w1 == "unknown_char_name")
{
- strcpy(unknown_char_name, w2);
- unknown_char_name[24] = 0;
+ strzcpy(unknown_char_name, w2.c_str(), 24);
}
- else if (strcasecmp(w1, "char_log_filename") == 0)
+ else if (w1 == "char_log_filename")
{
- strcpy(char_log_filename, w2);
+ strzcpy(char_log_filename, w2.c_str(), sizeof(char_log_filename));
}
- else if (strcasecmp(w1, "name_ignoring_case") == 0)
+ else if (w1 == "name_ignoring_case")
{
- name_ignoring_case = config_switch (w2);
+ name_ignoring_case = config_switch(w2.c_str());
}
- else if (strcasecmp(w1, "char_name_option") == 0)
+ else if (w1 == "char_name_option")
{
- char_name_option = atoi(w2);
+ char_name_option = atoi(w2.c_str());
}
- else if (strcasecmp(w1, "char_name_letters") == 0)
+ else if (w1 == "char_name_letters")
{
- strcpy(char_name_letters, w2);
-// online files options
+ strzcpy(char_name_letters, w2.c_str(), sizeof(char_name_letters));
}
- else if (strcasecmp(w1, "online_txt_filename") == 0)
+ else if (w1 == "online_txt_filename")
{
- strcpy(online_txt_filename, w2);
+ strzcpy(online_txt_filename, w2.c_str(), sizeof(online_txt_filename));
}
- else if (strcasecmp(w1, "online_html_filename") == 0)
+ else if (w1 == "online_html_filename")
{
- strcpy(online_html_filename, w2);
+ strzcpy(online_html_filename, w2.c_str(), sizeof(online_html_filename));
}
- else if (strcasecmp(w1, "online_sorting_option") == 0)
+ else if (w1 == "online_sorting_option")
{
- online_sorting_option = atoi(w2);
+ online_sorting_option = atoi(w2.c_str());
}
- else if (strcasecmp(w1, "online_display_option") == 0)
+ else if (w1 == "online_display_option")
{
- online_display_option = atoi(w2);
+ online_display_option = atoi(w2.c_str());
}
- else if (strcasecmp(w1, "online_gm_display_min_level") == 0)
+ else if (w1 == "online_gm_display_min_level")
{ // minimum GM level to display 'GM' when we want to display it
- online_gm_display_min_level = atoi(w2);
+ online_gm_display_min_level = atoi(w2.c_str());
if (online_gm_display_min_level < 5) // send online file every 5 seconds to player is enough
online_gm_display_min_level = 5;
}
- else if (strcasecmp(w1, "online_refresh_html") == 0)
+ else if (w1 == "online_refresh_html")
{
- online_refresh_html = atoi(w2);
+ online_refresh_html = atoi(w2.c_str());
if (online_refresh_html < 1)
online_refresh_html = 1;
}
- else if (strcasecmp(w1, "anti_freeze_enable") == 0)
+ else if (w1 == "anti_freeze_enable")
{
- anti_freeze_enable = config_switch (w2);
+ anti_freeze_enable = config_switch(w2.c_str());
}
- else if (strcasecmp(w1, "anti_freeze_interval") == 0)
+ else if (w1 == "anti_freeze_interval")
{
- ANTI_FREEZE_INTERVAL = atoi(w2);
+ ANTI_FREEZE_INTERVAL = atoi(w2.c_str());
if (ANTI_FREEZE_INTERVAL < 5)
ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds
}
- else if (strcasecmp(w1, "import") == 0)
+ else if (w1 == "import")
+ {
+ char_config_read(w2.c_str());
+ }
+ else
{
- char_config_read(w2);
+ PRINTF("WARNING: unknown char config key: %s", w1);
}
}
- fclose_(fp);
return 0;
}
@@ -3896,7 +3619,7 @@ void term_func(void)
delete_session(login_fd);
delete_session(char_fd);
- char_log("----End of char-server (normal end with closing of all files).\n");
+ CHAR_LOG("----End of char-server (normal end with closing of all files).\n");
}
int do_init(int argc, char **argv)
@@ -3904,8 +3627,8 @@ int do_init(int argc, char **argv)
int i;
// a newline in the log...
- char_log("");
- char_log("The char-server starting...\n");
+ CHAR_LOG("");
+ CHAR_LOG("The char-server starting...\n");
char_config_read((argc < 2) ? CHAR_CONF_NAME : argv[1]);
lan_config_read((argc > 1) ? argv[1] : LOGIN_LAN_CONF_NAME);
@@ -3948,10 +3671,10 @@ int do_init(int argc, char **argv)
i = add_timer_interval(gettick() + 1000, map_anti_freeze_system, 0, 0, ANTI_FREEZE_INTERVAL * 1000); // checks every X seconds user specifies
}
- char_log("The char-server is ready (Server is listening on the port %d).\n",
+ CHAR_LOG("The char-server is ready (Server is listening on the port %d).\n",
char_port);
- printf("The char-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
+ PRINTF("The char-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
char_port);
return 0;
diff --git a/src/char/char.hpp b/src/char/char.hpp
index 2389bd9..5c66dd4 100644
--- a/src/char/char.hpp
+++ b/src/char/char.hpp
@@ -1,6 +1,7 @@
#ifndef CHAR_HPP
#define CHAR_HPP
+#include "../common/const_array.hpp"
#include "../common/mmo.hpp"
#define MAX_MAP_SERVERS 30
@@ -26,8 +27,10 @@ int mapif_sendall(const uint8_t *buf, unsigned int len);
int mapif_sendallwos(int fd, const uint8_t *buf, unsigned int len);
int mapif_send(int fd, const uint8_t *buf, unsigned int len);
-__attribute__((format(printf, 1, 2)))
-int char_log(const char *fmt, ...);
+void char_log(const_string line);
+
+#define CHAR_LOG(fmt, args...) \
+ char_log(static_cast<const std::string&>(STRPRINTF(fmt, ## args)))
extern int autosave_interval;
diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp
index f33febd..8c3eab8 100644
--- a/src/char/int_party.cpp
+++ b/src/char/int_party.cpp
@@ -4,6 +4,7 @@
#include <cstdlib>
#include <cstring>
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
#include "../common/lock.hpp"
#include "../common/mmo.hpp"
@@ -28,19 +29,23 @@ int mapif_parse_PartyLeave(int fd, int party_id, int account_id);
// パーティデータの文字列への変換
static
-int inter_party_tostr(char *str, struct party *p)
+std::string inter_party_tostr(struct party *p)
{
- int i, len;
-
- len =
- sprintf(str, "%d\t%s\t%d,%d\t", p->party_id, p->name, p->exp,
- p->item);
- for (i = 0; i < MAX_PARTY; i++)
+ std::string str = STRPRINTF(
+ "%d\t"
+ "%s\t"
+ "%d,%d\t",
+ p->party_id,
+ p->name,
+ p->exp, p->item);
+ for (int i = 0; i < MAX_PARTY; i++)
{
struct party_member *m = &p->member[i];
- len +=
- sprintf(str + len, "%d,%d\t%s\t", m->account_id, m->leader,
- ((m->account_id > 0) ? m->name : "NoMember"));
+ str += STRPRINTF(
+ "%d,%d\t"
+ "%s\t",
+ m->account_id, m->leader,
+ (m->account_id > 0) ? m->name : "NoMember");
}
return 0;
@@ -50,43 +55,34 @@ int inter_party_tostr(char *str, struct party *p)
static
int inter_party_fromstr(char *str, struct party *p)
{
- int i, j;
- int tmp_int[16];
- char tmp_str[256];
-
memset(p, 0, sizeof(struct party));
-// printf("sscanf party main info\n");
- if (sscanf(str, "%d\t%[^\t]\t%d,%d\t", &tmp_int[0], tmp_str, &tmp_int[1],
- &tmp_int[2]) != 4)
+ if (sscanf(str,
+ "%d\t"
+ "%[^\t]\t"
+ "%d,%d\t",
+ &p->party_id,
+ p->name,
+ &p->exp, &p->item) != 4)
return 1;
- p->party_id = tmp_int[0];
- strcpy(p->name, tmp_str);
- p->exp = tmp_int[1];
- p->item = tmp_int[2];
-// printf("%d [%s] %d %d\n", tmp_int[0], tmp_str[0], tmp_int[1], tmp_int[2]);
-
- for (j = 0; j < 3 && str != NULL; j++)
+ for (int j = 0; j < 3 && str != NULL; j++)
str = strchr(str + 1, '\t');
- for (i = 0; i < MAX_PARTY; i++)
+ for (int i = 0; i < MAX_PARTY; i++)
{
struct party_member *m = &p->member[i];
if (str == NULL)
return 1;
-// printf("sscanf party member info %d\n", i);
- if (sscanf(str + 1, "%d,%d\t%[^\t]\t", &tmp_int[0], &tmp_int[1],
- tmp_str) != 3)
+ if (sscanf(str + 1,
+ "%d,%d\t"
+ "%[^\t]\t",
+ &m->account_id, &m->leader,
+ m->name) != 3)
return 1;
- m->account_id = tmp_int[0];
- m->leader = tmp_int[1];
- strncpy(m->name, tmp_str, sizeof(m->name));
-// printf(" %d %d [%s]\n", tmp_int[0], tmp_int[1], tmp_str);
-
- for (j = 0; j < 2 && str != NULL; j++)
+ for (int j = 0; j < 2 && str != NULL; j++)
str = strchr(str + 1, '\t');
}
@@ -107,6 +103,7 @@ int inter_party_init(void)
if ((fp = fopen_(party_txt, "r")) == NULL)
return 1;
+ // TODO: convert to use char_id, and change to extract()
while (fgets(line, sizeof(line) - 1, fp))
{
j = 0;
@@ -127,14 +124,14 @@ int inter_party_init(void)
}
else
{
- printf("int_party: broken data [%s] line %d\n", party_txt,
+ PRINTF("int_party: broken data [%s] line %d\n", party_txt,
c + 1);
free(p);
}
c++;
}
fclose_(fp);
-// printf("int_party: %s read done (%d parties)\n", party_txt, c);
+// PRINTF("int_party: %s read done (%d parties)\n", party_txt, c);
return 0;
}
@@ -143,10 +140,8 @@ int inter_party_init(void)
static
void inter_party_save_sub(db_key_t, db_val_t data, FILE *fp)
{
- char line[8192];
-
- inter_party_tostr(line, (struct party *) data);
- fprintf(fp, "%s\n", line);
+ std::string line = inter_party_tostr((struct party *) data);
+ FPRINTF(fp, "%s\n", line);
}
// パーティーデータのセーブ
@@ -157,14 +152,14 @@ int inter_party_save(void)
if ((fp = lock_fopen(party_txt, &lock)) == NULL)
{
- printf("int_party: cant write [%s] !!! data is lost !!!\n",
+ PRINTF("int_party: cant write [%s] !!! data is lost !!!\n",
party_txt);
return 1;
}
numdb_foreach(party_db, std::bind(inter_party_save_sub, ph::_1, ph::_2, fp));
-// fprintf(fp, "%d\t%%newid%%\n", party_newid);
+// FPRINTF(fp, "%d\t%%newid%%\n", party_newid);
lock_fclose(fp, party_txt, &lock);
-// printf("int_party: %s saved.\n", party_txt);
+// PRINTF("int_party: %s saved.\n", party_txt);
return 0;
}
@@ -216,10 +211,10 @@ int party_check_empty(struct party *p)
{
int i;
-// printf("party check empty %08X\n", (int)p);
+// PRINTF("party check empty %08X\n", (int)p);
for (i = 0; i < MAX_PARTY; i++)
{
-// printf("%d acc=%d\n", i, p->member[i].account_id);
+// PRINTF("%d acc=%d\n", i, p->member[i].account_id);
if (p->member[i].account_id > 0)
{
return 0;
@@ -250,7 +245,7 @@ void party_check_conflict_sub(db_key_t, db_val_t data,
&& strcmp(p->member[i].name, nick) == 0)
{
// 別のパーティに偽の所属データがあるので脱退
- printf("int_party: party conflict! %d %d %d\n", account_id,
+ PRINTF("int_party: party conflict! %d %d %d\n", account_id,
party_id, p->party_id);
mapif_parse_PartyLeave(-1, p->party_id, account_id);
}
@@ -282,7 +277,7 @@ int mapif_party_created(int fd, int account_id, struct party *p)
WFIFOB(fd, 6) = 0;
WFIFOL(fd, 7) = p->party_id;
memcpy(WFIFOP(fd, 11), p->name, 24);
- printf("int_party: created! %d %s\n", p->party_id, p->name);
+ PRINTF("int_party: created! %d %s\n", p->party_id, p->name);
}
else
{
@@ -303,7 +298,7 @@ int mapif_party_noinfo(int fd, int party_id)
WFIFOW(fd, 2) = 8;
WFIFOL(fd, 4) = party_id;
WFIFOSET(fd, 8);
- printf("int_party: info not found %d\n", party_id);
+ PRINTF("int_party: info not found %d\n", party_id);
return 0;
}
@@ -321,7 +316,7 @@ int mapif_party_info(int fd, struct party *p)
mapif_sendall(buf, WBUFW(buf, 2));
else
mapif_send(fd, buf, WBUFW(buf, 2));
-// printf("int_party: info %d %s\n", p->party_id, p->name);
+// PRINTF("int_party: info %d %s\n", p->party_id, p->name);
return 0;
}
@@ -356,7 +351,7 @@ int mapif_party_optionchanged(int fd, struct party *p, int account_id,
mapif_sendall(buf, 15);
else
mapif_send(fd, buf, 15);
- printf("int_party: option changed %d %d %d %d %d\n", p->party_id,
+ PRINTF("int_party: option changed %d %d %d %d %d\n", p->party_id,
account_id, p->exp, p->item, flag);
return 0;
@@ -373,7 +368,7 @@ int mapif_party_leaved(int party_id, int account_id, char *name)
WBUFL(buf, 6) = account_id;
memcpy(WBUFP(buf, 10), name, 24);
mapif_sendall(buf, 34);
- printf("int_party: party leaved %d %d %s\n", party_id, account_id, name);
+ PRINTF("int_party: party leaved %d %d %s\n", party_id, account_id, name);
return 0;
}
@@ -403,7 +398,7 @@ int mapif_party_broken(int party_id, int flag)
WBUFL(buf, 2) = party_id;
WBUFB(buf, 6) = flag;
mapif_sendall(buf, 7);
- printf("int_party: broken %d\n", party_id);
+ PRINTF("int_party: broken %d\n", party_id);
return 0;
}
@@ -439,7 +434,7 @@ int mapif_parse_CreateParty(int fd, int account_id, const char *name, const char
{
if (!(name[i] & 0xe0) || name[i] == 0x7f)
{
- printf("int_party: illegal party name [%s]\n", name);
+ PRINTF("int_party: illegal party name [%s]\n", name);
mapif_party_created(fd, account_id, NULL);
return 0;
}
@@ -447,7 +442,7 @@ int mapif_parse_CreateParty(int fd, int account_id, const char *name, const char
if ((p = search_partyname(name)) != NULL)
{
- printf("int_party: same name party exists [%s]\n", name);
+ PRINTF("int_party: same name party exists [%s]\n", name);
mapif_party_created(fd, account_id, NULL);
return 0;
}
diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp
index 05553b9..98d443f 100644
--- a/src/char/int_storage.cpp
+++ b/src/char/int_storage.cpp
@@ -1,6 +1,8 @@
#include "int_storage.hpp"
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
+#include "../common/extract.hpp"
#include "../common/lock.hpp"
#include "../common/mmo.hpp"
#include "../common/socket.hpp"
@@ -11,6 +13,8 @@
#include <cstdlib>
#include <cstring>
+#include <fstream>
+
// ファイル名のデフォルト
// inter_config_read()で再設定される
char storage_txt[1024] = "save/storage.txt";
@@ -20,106 +24,60 @@ struct dbt *storage_db;
// 倉庫データを文字列に変換
static
-int storage_tostr(char *str, struct storage *p)
+std::string storage_tostr(struct storage *p)
{
- int i, f = 0;
- char *str_p = str;
- str_p += sprintf(str_p, "%d,%d\t", p->account_id, p->storage_amount);
+ std::string str = STRPRINTF(
+ "%d,%d\t",
+ p->account_id, p->storage_amount);
- for (i = 0; i < MAX_STORAGE; i++)
- if ((p->storage_[i].nameid) && (p->storage_[i].amount))
+ int f = 0;
+ for (int i = 0; i < MAX_STORAGE; i++)
+ if (p->storage_[i].nameid && p->storage_[i].amount)
{
- str_p += sprintf(str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->storage_[i].id,
- p->storage_[i].nameid,
- p->storage_[i].amount,
- uint16_t(p->storage_[i].equip),
- p->storage_[i].identify,
- p->storage_[i].refine,
- p->storage_[i].attribute,
- p->storage_[i].card[0],
- p->storage_[i].card[1],
- p->storage_[i].card[2],
- p->storage_[i].card[3]);
+ str += STRPRINTF(
+ "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
+ p->storage_[i].id,
+ p->storage_[i].nameid,
+ p->storage_[i].amount,
+ p->storage_[i].equip,
+ p->storage_[i].identify,
+ p->storage_[i].refine,
+ p->storage_[i].attribute,
+ p->storage_[i].card[0],
+ p->storage_[i].card[1],
+ p->storage_[i].card[2],
+ p->storage_[i].card[3]);
f++;
}
- *(str_p++) = '\t';
+ str += '\t';
- *str_p = '\0';
if (!f)
- str[0] = 0;
- return 0;
+ str.clear();
+ return str;
}
// 文字列を倉庫データに変換
static
-int storage_fromstr(char *str, struct storage *p)
+bool extract(const_string str, struct storage *p)
{
- int tmp_int[256];
- int set, next, len, i;
-
- set = sscanf(str, "%d,%d%n", &tmp_int[0], &tmp_int[1], &next);
- p->storage_amount = tmp_int[1];
-
- if (set != 2)
- return 1;
- if (str[next] == '\n' || str[next] == '\r')
- return 0;
- next++;
- for (i = 0; str[next] && str[next] != '\t' && i < MAX_STORAGE; i++)
- {
- if (sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
- &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
- &tmp_int[4], &tmp_int[5], &tmp_int[6],
- &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
- &tmp_int[10], &len) == 12)
- {
- p->storage_[i].id = tmp_int[0];
- p->storage_[i].nameid = tmp_int[1];
- p->storage_[i].amount = tmp_int[2];
- p->storage_[i].equip = EPOS(tmp_int[3] );
- p->storage_[i].identify = tmp_int[4];
- p->storage_[i].refine = tmp_int[5];
- p->storage_[i].attribute = tmp_int[6];
- p->storage_[i].card[0] = tmp_int[7];
- p->storage_[i].card[1] = tmp_int[8];
- p->storage_[i].card[2] = tmp_int[9];
- p->storage_[i].card[3] = tmp_int[10];
- next += len;
- if (str[next] == ' ')
- next++;
- }
-
- else if (sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n",
- &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
- &tmp_int[4], &tmp_int[5], &tmp_int[6],
- &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10],
- &len) == 11)
- {
- p->storage_[i].id = tmp_int[0];
- p->storage_[i].nameid = tmp_int[1];
- p->storage_[i].amount = tmp_int[2];
- p->storage_[i].equip = EPOS(tmp_int[3]);
- p->storage_[i].identify = tmp_int[4];
- p->storage_[i].refine = tmp_int[5];
- p->storage_[i].attribute = tmp_int[6];
- p->storage_[i].card[0] = tmp_int[7];
- p->storage_[i].card[1] = tmp_int[8];
- p->storage_[i].card[2] = tmp_int[9];
- p->storage_[i].card[3] = tmp_int[10];
- next += len;
- if (str[next] == ' ')
- next++;
- }
-
- else
- return 1;
- }
- if (i >= MAX_STORAGE && str[next] && str[next] != '\t')
- printf("storage_fromstr: Found a storage line with more items than MAX_STORAGE (%d), remaining items have been discarded!\n",
- MAX_STORAGE);
- return 0;
+ std::vector<struct item> storage_items;
+ if (!extract(str,
+ record<'\t'>(
+ record<','>(
+ &p->account_id,
+ &p->storage_amount),
+ vrec<' '>(&storage_items))))
+ return false;
+
+ if (p->account_id <= 0)
+ return false;
+
+ if (storage_items.size() >= MAX_STORAGE)
+ return false;
+ std::copy(storage_items.begin(), storage_items.end(), p->storage_);
+
+ return true;
}
// アカウントから倉庫データインデックスを得る(新規倉庫追加可能)
@@ -141,37 +99,34 @@ struct storage *account2storage(int account_id)
// 倉庫データを読み込む
int inter_storage_init(void)
{
- char line[65536];
- int c = 0, tmp_int;
- struct storage *s;
- FILE *fp;
+ int c = 0;
storage_db = numdb_init();
- fp = fopen_(storage_txt, "r");
- if (fp == NULL)
+ std::ifstream in(storage_txt);
+ if (!in.is_open())
{
- printf("cant't read : %s\n", storage_txt);
+ PRINTF("cant't read : %s\n", storage_txt);
return 1;
}
- while (fgets(line, 65535, fp))
+
+ std::string line;
+ while (std::getline(in, line))
{
- sscanf(line, "%d", &tmp_int);
+ struct storage *s;
CREATE(s, struct storage, 1);
- s->account_id = tmp_int;
- if (s->account_id > 0 && storage_fromstr(line, s) == 0)
+ if (extract(line, s))
{
numdb_insert(storage_db, s->account_id, s);
}
else
{
- printf("int_storage: broken data [%s] line %d\n", storage_txt,
- c);
+ PRINTF("int_storage: broken data [%s] line %d\n",
+ storage_txt, c);
free(s);
}
c++;
}
- fclose_(fp);
return 0;
}
@@ -179,10 +134,9 @@ int inter_storage_init(void)
static
void inter_storage_save_sub(db_key_t, db_val_t data, FILE *fp)
{
- char line[65536];
- storage_tostr(line, (struct storage *) data);
- if (*line)
- fprintf(fp, "%s\n", line);
+ std::string line = storage_tostr((struct storage *) data);
+ if (!line.empty())
+ FPRINTF(fp, "%s\n", line);
}
//---------------------------------------------------------
@@ -197,13 +151,13 @@ int inter_storage_save(void)
if ((fp = lock_fopen(storage_txt, &lock)) == NULL)
{
- printf("int_storage: cant write [%s] !!! data is lost !!!\n",
+ PRINTF("int_storage: cant write [%s] !!! data is lost !!!\n",
storage_txt);
return 1;
}
numdb_foreach(storage_db, std::bind(inter_storage_save_sub, ph::_1, ph::_2, fp));
lock_fclose(fp, storage_txt, &lock);
-// printf("int_storage: %s saved.\n",storage_txt);
+// PRINTF("int_storage: %s saved.\n",storage_txt);
return 0;
}
@@ -267,7 +221,7 @@ int mapif_parse_SaveStorage(int fd)
int len = RFIFOW(fd, 2);
if (sizeof(struct storage) != len - 8)
{
- printf("inter storage: data size error %d %d\n",
+ PRINTF("inter storage: data size error %d %d\n",
sizeof(struct storage), len - 8);
}
else
diff --git a/src/char/inter.cpp b/src/char/inter.cpp
index 631f804..02091b9 100644
--- a/src/char/inter.cpp
+++ b/src/char/inter.cpp
@@ -3,7 +3,11 @@
#include <cstdlib>
#include <cstring>
+#include <fstream>
+
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
+#include "../common/extract.hpp"
#include "../common/lock.hpp"
#include "../common/mmo.hpp"
#include "../common/socket.hpp"
@@ -72,75 +76,62 @@ int wis_dellist[WISDELLIST_MAX], wis_delnum;
// アカウント変数を文字列へ変換
static
-int inter_accreg_tostr(char *str, struct accreg *reg)
+std::string inter_accreg_tostr(struct accreg *reg)
{
- int j;
- char *p = str;
-
- p += sprintf(p, "%d\t", reg->account_id);
- for (j = 0; j < reg->reg_num; j++)
- {
- p += sprintf(p, "%s,%d ", reg->reg[j].str, reg->reg[j].value);
- }
-
- return 0;
+ std::string str STRPRINTF("%d\t", reg->account_id);
+ for (int j = 0; j < reg->reg_num; j++)
+ str += STRPRINTF("%s,%d ", reg->reg[j].str, reg->reg[j].value);
+ return str;
}
// アカウント変数を文字列から変換
static
-int inter_accreg_fromstr(const char *str, struct accreg *reg)
+bool extract(const_string str, struct accreg *reg)
{
- int j, v, n;
- char buf[128];
- const char *p = str;
-
- if (sscanf(p, "%d\t%n", &reg->account_id, &n) != 1
- || reg->account_id <= 0)
- return 1;
-
- for (j = 0, p += n; j < ACCOUNT_REG_NUM; j++, p += n)
- {
- if (sscanf(p, "%[^,],%d %n", buf, &v, &n) != 2)
- break;
- memcpy(reg->reg[j].str, buf, 32);
- reg->reg[j].value = v;
- }
- reg->reg_num = j;
-
- return 0;
+ std::vector<struct global_reg> vars;
+ if (!extract(str,
+ record<'\t'>(
+ &reg->account_id,
+ vrec<' '>(&vars))))
+ return false;
+ if (reg->account_id <= 0)
+ return false;
+
+ if (vars.size() > ACCOUNT_REG_NUM)
+ return false;
+ std::copy(vars.begin(), vars.end(), reg->reg);
+ reg->reg_num = vars.size();
+ return true;
}
// アカウント変数の読み込み
static
int inter_accreg_init(void)
{
- char line[8192];
- FILE *fp;
int c = 0;
- struct accreg *reg;
accreg_db = numdb_init();
- if ((fp = fopen_(accreg_txt, "r")) == NULL)
+ std::ifstream in(accreg_txt);
+ if (!in.is_open())
return 1;
- while (fgets(line, sizeof(line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- line[sizeof(line) - 1] = '\0';
+ struct accreg *reg;
CREATE(reg, struct accreg, 1);
- if (inter_accreg_fromstr(line, reg) == 0 && reg->account_id > 0)
+ if (!extract(line, reg))
{
numdb_insert(accreg_db, reg->account_id, reg);
}
else
{
- printf("inter: accreg: broken data [%s] line %d\n", accreg_txt,
+ PRINTF("inter: accreg: broken data [%s] line %d\n", accreg_txt,
c);
free(reg);
}
c++;
}
- fclose_(fp);
-// printf("inter: %s read done (%d)\n", accreg_txt, c);
return 0;
}
@@ -149,13 +140,13 @@ int inter_accreg_init(void)
static
void inter_accreg_save_sub(db_key_t, db_val_t data, FILE *fp)
{
- char line[8192];
struct accreg *reg = (struct accreg *) data;
if (reg->reg_num > 0)
{
- inter_accreg_tostr(line, reg);
- fprintf(fp, "%s\n", line);
+ std::string line = inter_accreg_tostr(reg);
+ fwrite(line.data(), 1, line.size(), fp);
+ fputc('\n', fp);
}
}
@@ -168,13 +159,12 @@ int inter_accreg_save(void)
if ((fp = lock_fopen(accreg_txt, &lock)) == NULL)
{
- printf("int_accreg: cant write [%s] !!! data is lost !!!\n",
+ PRINTF("int_accreg: cant write [%s] !!! data is lost !!!\n",
accreg_txt);
return 1;
}
numdb_foreach(accreg_db, std::bind(inter_accreg_save_sub, ph::_1, ph::_2, fp));
lock_fclose(fp, accreg_txt, &lock);
-// printf("inter: %s saved.\n", accreg_txt);
return 0;
}
@@ -188,52 +178,51 @@ int inter_accreg_save(void)
static
int inter_config_read(const char *cfgName)
{
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
- fp = fopen_(cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- printf("file not found: %s\n", cfgName);
+ PRINTF("file not found: %s\n", cfgName);
return 1;
}
- while (fgets(line, sizeof(line) - 1, fp))
- {
- if (line[0] == '/' && line[1] == '/')
- continue;
- line[sizeof(line) - 1] = '\0';
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ std::string line;
+ while (std::getline(in, line))
+ {
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- if (strcasecmp(w1, "storage_txt") == 0)
+ if (w1 == "storage_txt")
{
- strncpy(storage_txt, w2, sizeof(storage_txt));
+ strzcpy(storage_txt, w2.c_str(), sizeof(storage_txt));
}
- else if (strcasecmp(w1, "party_txt") == 0)
+ else if (w1 == "party_txt")
{
- strncpy(party_txt, w2, sizeof(party_txt));
+ strzcpy(party_txt, w2.c_str(), sizeof(party_txt));
}
- else if (strcasecmp(w1, "accreg_txt") == 0)
+ else if (w1 == "accreg_txt")
{
- strncpy(accreg_txt, w2, sizeof(accreg_txt));
+ strzcpy(accreg_txt, w2.c_str(), sizeof(accreg_txt));
}
- else if (strcasecmp(w1, "party_share_level") == 0)
+ else if (w1 == "party_share_level")
{
- party_share_level = atoi(w2);
+ party_share_level = atoi(w2.c_str());
if (party_share_level < 0)
party_share_level = 0;
}
- else if (strcasecmp(w1, "inter_log_filename") == 0)
+ else if (w1 == "inter_log_filename")
{
- strncpy(inter_log_filename, w2, sizeof(inter_log_filename));
+ strzcpy(inter_log_filename, w2.c_str(), sizeof(inter_log_filename));
}
- else if (strcasecmp(w1, "import") == 0)
+ else if (w1 == "import")
+ {
+ inter_config_read(w2.c_str());
+ }
+ else
{
- inter_config_read(w2);
+ PRINTF("WARNING: unknown inter config key: %s", w1);
}
}
- fclose_(fp);
return 0;
}
@@ -275,7 +264,6 @@ int mapif_GMmessage(unsigned char *mes, int len)
WBUFW(buf, 2) = len;
memcpy(WBUFP(buf, 4), mes, len - 4);
mapif_sendall(buf, len);
-// printf("inter server: GM:%d %s\n", len, mes);
return 0;
}
@@ -307,7 +295,6 @@ int mapif_wis_end(struct WisData *wd, int flag)
memcpy(WBUFP(buf, 2), wd->src, 24);
WBUFB(buf, 26) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
mapif_send(wd->fd, buf, 27);
-// printf("inter server wis_end: flag: %d\n", flag);
return 0;
}
@@ -378,7 +365,7 @@ int check_ttl_wisdata(void)
for (i = 0; i < wis_delnum; i++)
{
struct WisData *wd = (struct WisData *)numdb_search(wis_db, wis_dellist[i]);
- printf("inter: wis data id=%d time out : from %s to %s\n",
+ PRINTF("inter: wis data id=%d time out : from %s to %s\n",
wd->id, wd->src, wd->dst);
// removed. not send information after a timeout. Just no answer for the player
//mapif_wis_end(wd, 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
@@ -413,12 +400,12 @@ int mapif_parse_WisRequest(int fd)
if (RFIFOW(fd, 2) - 52 >= sizeof(wd->msg))
{
- printf("inter: Wis message size too long.\n");
+ PRINTF("inter: Wis message size too long.\n");
return 0;
}
else if (RFIFOW(fd, 2) - 52 <= 0)
{ // normaly, impossible, but who knows...
- printf("inter: Wis message doesn't exist.\n");
+ PRINTF("inter: Wis message doesn't exist.\n");
return 0;
}
@@ -532,7 +519,6 @@ int mapif_parse_AccReg(int fd)
static
int mapif_parse_AccRegRequest(int fd)
{
-// printf("mapif: accreg request\n");
return mapif_account_reg_reply(fd, RFIFOL(fd, 2));
}
diff --git a/src/common/const_array.hpp b/src/common/const_array.hpp
new file mode 100644
index 0000000..12c5d6f
--- /dev/null
+++ b/src/common/const_array.hpp
@@ -0,0 +1,175 @@
+#ifndef CONST_ARRAY_HPP
+#define CONST_ARRAY_HPP
+// const_array.hpp - just a pointer-to-const and a length
+//
+// Copyright © 2011-2012 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "sanity.hpp"
+
+#include <cstring>
+
+#include <iterator>
+#include <ostream>
+#include <string>
+#include <vector>
+
+#ifdef ANNOYING_GCC46_WORKAROUNDS
+# warning "like this one"
+// constexpr is buggy with templates in this version
+# define constexpr /* nothing */
+#endif
+
+template<class T>
+class const_array
+{
+ const T *d;
+ size_t n;
+public:
+ typedef const T *iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+
+ constexpr
+ const_array(std::nullptr_t)
+ : d(nullptr), n(0)
+ {}
+
+ constexpr
+ const_array(const T *p, size_t z)
+ : d(p), n(z)
+ {}
+
+ constexpr
+ const_array(const T *b, const T *e)
+ : d(b), n(e - b)
+ {}
+
+ const_array(std::initializer_list<T> list)
+ : d(list.begin()), n(list.size())
+ {}
+
+ // Implicit conversion from std::vector
+ const_array(const std::vector<T>& v)
+ : d(v.data()), n(v.size())
+ {}
+
+ // but disallow conversion from a temporary
+ const_array(std::vector<T>&&) = delete;
+
+ // All methods are non-const to "encourage" you
+ // to always pass a const_array by value.
+ // After all, "const const_array" looks funny.
+ constexpr
+ const T *data() { return d; }
+ constexpr
+ size_t size() { return n; }
+ constexpr
+ bool empty() { return not n; }
+ constexpr explicit
+ operator bool() { return n; }
+
+ constexpr
+ std::pair<const_array, const_array> cut(size_t o)
+ {
+ return {const_array(d, o), const_array(d + o, n - o)};
+ }
+
+ constexpr
+ const_array first(size_t o)
+ {
+ return cut(o).first;
+ }
+
+ constexpr
+ const_array last(size_t l)
+ {
+ return cut(size() - l).second;
+ }
+
+ constexpr
+ const_array after(size_t o)
+ {
+ return cut(o).second;
+ }
+
+ constexpr
+ iterator begin() { return d; }
+ constexpr
+ iterator end() { return d + n; }
+ constexpr
+ reverse_iterator rbegin() { return reverse_iterator(end()); }
+ constexpr
+ reverse_iterator rend() { return reverse_iterator(begin()); }
+
+ constexpr
+ const T& front() { return *begin(); }
+ constexpr
+ const T& back() { return *rbegin(); }
+};
+
+// subclass just provides a simpler name and some conversions
+class const_string : public const_array<char>
+{
+public:
+ // Implicit conversion from C string.
+ constexpr
+ const_string(const char *z)
+ : const_array<char>(z, z ? strlen(z) : 0)
+ {}
+
+ // Same as parent constructor.
+ constexpr
+ const_string(const char *s, size_t l)
+ : const_array<char>(s, l)
+ {}
+
+ // Same as parent constructor.
+ constexpr
+ const_string(const char *b, const char *e)
+ : const_array<char>(b, e)
+ {}
+
+ // Same as parent constructor.
+ const_string(const std::vector<char> s)
+ : const_array<char>(s)
+ {}
+
+ // Implicit conversion from C++ string.
+ const_string(const std::string& s)
+ : const_array<char>(s.data(), s.size())
+ {}
+
+ // but disallow converion from a temporary.
+ const_string(std::string&&) = delete;
+
+ // allow being sloppy
+ constexpr
+ const_string(const_array<char> a)
+ : const_array<char>(a)
+ {}
+};
+#ifdef ANNOYING_GCC46_WORKAROUNDS
+# undef constexpr
+#endif
+
+inline
+std::ostream& operator << (std::ostream& o, const_string s)
+{
+ return o.write(s.data(), s.size());
+}
+
+#endif // CONST_ARRAY_HPP
diff --git a/src/common/cxxstdio.hpp b/src/common/cxxstdio.hpp
index 2bd4f4b..6f5072e 100644
--- a/src/common/cxxstdio.hpp
+++ b/src/common/cxxstdio.hpp
@@ -27,6 +27,8 @@
#include <string>
+#include "const_array.hpp"
+
namespace cxxstdio
{
inline __attribute__((format(printf, 2, 0)))
@@ -58,16 +60,20 @@ namespace cxxstdio
return vfscanf(in, fmt, ap);
}
+#if 0
inline __attribute__((format(scanf, 2, 0)))
int do_vscan(const char *in, const char *fmt, va_list ap)
{
return vsscanf(in, fmt, ap);
}
+#else
+ int do_vscan(const char *in, const char *fmt, va_list ap) = delete;
+#endif
inline __attribute__((format(scanf, 2, 0)))
int do_vscan(const std::string& in, const char *fmt, va_list ap)
{
- return do_vscan(in.c_str(), fmt, ap);
+ return vsscanf(in.c_str(), fmt, ap);
}
@@ -109,11 +115,63 @@ namespace cxxstdio
return v;
}
+#if 0
+ template<class E>
+ constexpr
+ E get_enum_min_value(decltype(E::min_value))
+ {
+ return E::min_value;
+ }
+ template<class E>
+ constexpr
+ E get_enum_min_value(E def)
+ {
+ return def;
+ }
+
+ template<class E>
+ constexpr
+ E get_enum_max_value(decltype(E::max_value))
+ {
+ return E::max_value;
+ }
+ template<class E>
+ constexpr
+ E get_enum_max_value(E def)
+ {
+ return def;
+ }
+#else
+ template<class E>
+ constexpr
+ E get_enum_min_value(E)
+ {
+ return E::min_value;
+ }
+ template<class E>
+ constexpr
+ E get_max_value(E)
+ {
+ return E::max_value;
+ }
+#endif
+
template<class E>
class EnumConverter
{
E& out;
typedef typename underlying_type<E>::type U;
+#if 0
+ constexpr static
+ U min_value = U(get_enum_min_value<E>(E(std::numeric_limits<U>::min())));
+ constexpr static
+ U max_value = U(get_enum_max_value<E>(E(std::numeric_limits<U>::max())));
+#else
+ constexpr static
+ U min_value = U(get_enum_min_value(E()));
+ constexpr static
+ U max_value = U(get_enum_max_value(E()));
+#endif
U mid;
public:
EnumConverter(E& e)
@@ -121,7 +179,10 @@ namespace cxxstdio
{}
~EnumConverter()
{
- if (U(E::min_value) <= mid && mid <= U(E::max_value))
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
+ if (min_value <= mid && mid <= max_value)
+#pragma GCC diagnostic pop
out = E(mid);
}
U *operator &()
@@ -201,30 +262,40 @@ namespace cxxstdio
}
};
-#define FPRINTF(file, fmt, args...) \
- ({ \
- struct format_impl \
- { \
- constexpr static \
- const char *print_format() { return fmt; } \
- }; \
- cxxstdio::PrintFormatter<format_impl>::print(file, args); \
- })
-
-#define FSCANF(file, fmt, args...) \
- ({ \
- struct format_impl \
- { \
- constexpr static \
- const char *scan_format() { return fmt; } \
- }; \
- cxxstdio::ScanFormatter<format_impl>::scan(file, args); \
- })
-
-#define PRINTF(fmt, args...) FPRINTF(stdout, fmt, args)
-#define STRPRINTF(str, fmt, args...) FPRINTF(str, fmt, args)
-#define SCANF(fmt, args...) FSCANF(stdin, fmt, args)
-#define SSCANF(str, fmt, args...) FSCANF(str, fmt, args)
+#define FPRINTF(file, fmt, args...) \
+ ([&]() -> int \
+ { \
+ struct format_impl \
+ { \
+ constexpr static \
+ const char *print_format() { return fmt; } \
+ }; \
+ return cxxstdio::PrintFormatter<format_impl>::print(file, ## args);\
+ }())
+
+#define FSCANF(file, fmt, args...) \
+ ([&]() -> int \
+ { \
+ struct format_impl \
+ { \
+ constexpr static \
+ const char *scan_format() { return fmt; } \
+ }; \
+ return cxxstdio::ScanFormatter<format_impl>::scan(file, ## args); \
+ }())
+
+#define PRINTF(fmt, args...) FPRINTF(stdout, fmt, ## args)
+#define SPRINTF(str, fmt, args...) FPRINTF(str, fmt, ## args)
+#define SCANF(fmt, args...) FSCANF(stdin, fmt, ## args)
+#define SSCANF(str, fmt, args...) FSCANF(str, fmt, ## args)
+
+#define STRPRINTF(fmt, args...) \
+ ([&]() -> std::string \
+ { \
+ std::string _out_impl; \
+ SPRINTF(_out_impl, fmt, ## args); \
+ return _out_impl; \
+ }())
} // namespace cxxstdio
diff --git a/src/common/db.cpp b/src/common/db.cpp
index 8780138..06f85bc 100644
--- a/src/common/db.cpp
+++ b/src/common/db.cpp
@@ -414,12 +414,12 @@ void db_walk_tree(bool dealloc, struct dbn* p, db_func_t func)
return;
if (!dealloc && !func)
{
- fprintf(stderr, "DEBUG: Must walk tree to either free or invoke a function.\n");
+ FPRINTF(stderr, "DEBUG: Must walk tree to either free or invoke a function.\n");
abort();
}
if (p->parent)
{
- fprintf(stderr, "DEBUG: Root nodes must not have parents\n");
+ FPRINTF(stderr, "DEBUG: Root nodes must not have parents\n");
abort();
}
while (true)
diff --git a/src/common/extract.hpp b/src/common/extract.hpp
new file mode 100644
index 0000000..52df9df
--- /dev/null
+++ b/src/common/extract.hpp
@@ -0,0 +1,208 @@
+#ifndef EXTRACT_HPP
+#define EXTRACT_HPP
+// extract.hpp - a simple, heirarchail, tokenizer
+//
+// Copyright © 2012 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <algorithm>
+
+#include "const_array.hpp"
+#include "mmo.hpp"
+
+template<class T, typename=typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value>::type>
+bool extract(const_string str, T *iv)
+{
+ if (!str || str.size() > 20)
+ return false;
+ switch (str.front())
+ {
+ case '-':
+ case '0' ... '9':
+ break;
+ default:
+ return false;
+ }
+ char buf[20 + 1];
+ std::copy(str.begin(), str.end(), buf);
+ buf[str.size()] = '\0';
+
+ char *end;
+ errno = 0;
+ if (std::is_signed<T>::value)
+ {
+ long long v = strtoll(buf, &end, 10);
+ if (errno || *end)
+ return false;
+ *iv = v;
+ return *iv == v;
+ }
+ else
+ {
+ if (str.front() == '-')
+ return false;
+ unsigned long long v = strtoull(buf, &end, 10);
+ if (errno || *end)
+ return false;
+ *iv = v;
+ return *iv == v;
+ }
+}
+
+// extra typename=void to workaround some duplicate overload rule
+template<class T, typename=typename std::enable_if<std::is_enum<T>::value>::type, typename=void>
+bool extract(const_string str, T *iv)
+{
+ typedef typename underlying_type<T>::type U;
+ U v;
+ // defer to integer version
+ if (!extract(str, &v))
+ return false;
+ // TODO check bounds ...
+ *iv = static_cast<T>(v);
+ return true;
+}
+
+inline
+bool extract(const_string str, const_string *rv)
+{
+ *rv = str;
+ return true;
+}
+
+inline
+bool extract(const_string str, std::string *rv)
+{
+ *rv = std::string(str.begin(), str.end());
+ return true;
+}
+
+template<size_t N>
+__attribute__((deprecated))
+bool extract(const_string str, char (*out)[N])
+{
+ if (str.size() >= N)
+ return false;
+ std::copy(str.begin(), str.end(), *out);
+ std::fill(*out + str.size() , *out + N, '\0');
+ return true;
+}
+
+// basically just a std::tuple
+// but it provides its data members publically
+template<char split, class... T>
+class Record;
+template<char split>
+class Record<split>
+{
+};
+template<char split, class F, class... R>
+class Record<split, F, R...>
+{
+public:
+ F frist;
+ Record<split, R...> rest;
+public:
+ Record(F f, R... r)
+ : frist(f), rest(r...)
+ {}
+};
+template<char split, class... T>
+Record<split, T...> record(T... t)
+{
+ return Record<split, T...>(t...);
+}
+
+template<char split>
+bool extract(const_string str, Record<split>)
+{
+ return !str;
+}
+template<char split, class F, class... R>
+bool extract(const_string str, Record<split, F, R...> rec)
+{
+ const char *s = std::find(str.begin(), str.end(), split);
+ if (s == str.end())
+ return sizeof...(R) == 0 && extract(str, rec.frist);
+ return extract(const_string(str.begin(), s), rec.frist)
+ && extract(const_string(s + 1, str.end()), rec.rest);
+}
+
+template<char split, class T>
+struct VRecord
+{
+ std::vector<T> *arr;
+};
+
+template<char split, class T>
+VRecord<split, T> vrec(std::vector<T> *arr)
+{
+ return {arr};
+}
+
+template<char split, class T>
+bool extract(const_string str, VRecord<split, T> rec)
+{
+ if (str.empty())
+ return true;
+ const char *s = std::find(str.begin(), str.end(), split);
+ rec.arr->emplace_back();
+ if (s == str.end())
+ return extract(str, &rec.arr->back());
+ return extract(const_string(str.begin(), s), &rec.arr->back())
+ && extract(const_string(s + 1, str.end()), rec);
+}
+
+inline
+bool extract(const_string str, struct global_reg *var)
+{
+ return extract(str,
+ record<','>(&var->str, &var->value));
+}
+
+inline
+bool extract(const_string str, struct item *it)
+{
+ return extract(str,
+ record<','>(
+ &it->id,
+ &it->nameid,
+ &it->amount,
+ &it->equip,
+ &it->identify,
+ &it->refine,
+ &it->attribute,
+ &it->card[0],
+ &it->card[1],
+ &it->card[2],
+ &it->card[3],
+ &it->broken))
+ || extract(str,
+ record<','>(
+ &it->id,
+ &it->nameid,
+ &it->amount,
+ &it->equip,
+ &it->identify,
+ &it->refine,
+ &it->attribute,
+ &it->card[0],
+ &it->card[1],
+ &it->card[2],
+ &it->card[3]));
+}
+#endif // EXTRACT_HPP
diff --git a/src/common/grfio.cpp b/src/common/grfio.cpp
index 7eb847a..93ea4ca 100644
--- a/src/common/grfio.cpp
+++ b/src/common/grfio.cpp
@@ -7,6 +7,7 @@
#include <cstdlib>
#include <cstring>
+#include "cxxstdio.hpp"
#include "mmo.hpp"
#include "socket.hpp"
#include "utils.hpp"
@@ -73,7 +74,7 @@ FILELIST *filelist_add(FILELIST * entry)
{
if (filelist_entrys >= FILELIST_LIMIT)
{
- fprintf(stderr, "filelist limit : filelist_add\n");
+ FPRINTF(stderr, "filelist limit : filelist_add\n");
exit(1);
}
@@ -118,7 +119,7 @@ void grfio_resnametable(const char *fname, char *lfname)
FILE *fp = fopen_(restable, "rb");
if (fp == NULL)
{
- fprintf(stderr, "No resnametable, can't look for %s\n", fname);
+ FPRINTF(stderr, "No resnametable, can't look for %s\n", fname);
strcpy(lfname, fname);
char* ext = lfname + strlen(lfname) - 4;
if (!strcmp(ext, ".gat"))
@@ -142,7 +143,7 @@ void grfio_resnametable(const char *fname, char *lfname)
return;
}
}
- fprintf(stderr, "Unable to find resource: %s\n", fname);
+ FPRINTF(stderr, "Unable to find resource: %s\n", fname);
fclose_(fp);
strcpy(lfname, fname);
@@ -177,7 +178,7 @@ size_t grfio_size(const char *fname)
}
else
{
- printf("%s not found\n", fname);
+ PRINTF("%s not found\n", fname);
return 0;
}
return entry->declen;
@@ -195,7 +196,7 @@ void *grfio_reads(const char *fname, size_t *size)
FILE *in = fopen_(lfname, "rb");
if (!in)
{
- fprintf(stderr, "%s not found\n", fname);
+ FPRINTF(stderr, "%s not found\n", fname);
return NULL;
}
FILELIST lentry;
diff --git a/src/common/lock.cpp b/src/common/lock.cpp
index 9075cbb..08ec2c4 100644
--- a/src/common/lock.cpp
+++ b/src/common/lock.cpp
@@ -4,6 +4,7 @@
#include <cstdio>
+#include "cxxstdio.hpp"
#include "socket.hpp"
/// Protected file writing
@@ -12,28 +13,28 @@
// Start writing a tmpfile
FILE *lock_fopen(const char *filename, int *info)
{
- char newfile[512];
FILE *fp;
int no = getpid();
// Get a filename that doesn't already exist
+ std::string newfile;
do
{
- sprintf(newfile, "%s_%d.tmp", filename, no++);
+ newfile = STRPRINTF("%s_%d.tmp", filename, no++);
+ fp = fopen_(newfile.c_str(), "wx");
}
- while ((fp = fopen_(newfile, "r")) && (fclose_(fp), 1));
+ while (!fp);
*info = --no;
- return fopen_(newfile, "w");
+ return fp;
}
// Delete the old file and rename the new file
-void lock_fclose(FILE * fp, const char *filename, int *info)
+void lock_fclose(FILE *fp, const char *filename, int *info)
{
- char newfile[512];
if (fp)
{
fclose_(fp);
- sprintf(newfile, "%s_%d.tmp", filename, *info);
- rename(newfile, filename);
+ std::string newfile = STRPRINTF("%s_%d.tmp", filename, *info);
+ rename(newfile.c_str(), filename);
}
}
diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp
index cda097a..197816f 100644
--- a/src/common/mmo.hpp
+++ b/src/common/mmo.hpp
@@ -21,6 +21,10 @@
# define MAX_CART 100
enum class SkillID : uint16_t;
constexpr SkillID MAX_SKILL = SkillID(474); // not 450
+constexpr SkillID get_enum_min_value(SkillID) { return SkillID(); }
+constexpr SkillID get_enum_max_value(SkillID) { return MAX_SKILL; }
+
+
# define GLOBAL_REG_NUM 96
# define ACCOUNT_REG_NUM 16
# define ACCOUNT_REG2_NUM 16
@@ -71,6 +75,9 @@ enum class EPOS : uint16_t
ARROW = 0x8000,
};
ENUM_BITWISE_OPERATORS(EPOS)
+
+constexpr EPOS get_enum_min_value(EPOS) { return EPOS(0x0000); }
+constexpr EPOS get_enum_max_value(EPOS) { return EPOS(0xffff); }
}
using e::EPOS;
@@ -80,9 +87,9 @@ struct item
short nameid;
short amount;
EPOS equip;
- char identify;
- char refine;
- char attribute;
+ uint8_t identify;
+ uint8_t refine;
+ uint8_t attribute;
short card[4];
short broken;
};
@@ -116,6 +123,8 @@ struct global_reg
namespace e
{
enum class Option : uint16_t;
+constexpr Option get_enum_min_value(Option) { return Option(0x0000); }
+constexpr Option get_enum_max_value(Option) { return Option(0xffff); }
}
using e::Option;
diff --git a/src/common/nullpo.cpp b/src/common/nullpo.cpp
index 8aa2e6e..f5d75cc 100644
--- a/src/common/nullpo.cpp
+++ b/src/common/nullpo.cpp
@@ -11,7 +11,8 @@ void nullpo_info(const char *file, int line, const char *func)
if (!func || !*func)
func = "unknown";
- fprintf(stderr, "%s:%d: in func `%s': NULL pointer\n", file, line, func);
+ fprintf(stderr, "%s:%d: in func `%s': NULL pointer\n",
+ file, line, func);
}
bool nullpo_chk(const char *file, int line, const char *func,
diff --git a/src/common/nullpo.hpp b/src/common/nullpo.hpp
index b729d94..7d12033 100644
--- a/src/common/nullpo.hpp
+++ b/src/common/nullpo.hpp
@@ -8,7 +8,6 @@
/// nullpo_ret(cond) - return 0 if given pointer is NULL
/// nullpo_retv(cond) - just return (function returns void)
/// nullpo_retr(rv, cond) - return given value instead
-/// the _f variants take a printf-format string and arguments
# ifdef NULLPO_CHECK
# define NLP_MARK __FILE__, __LINE__, __func__
diff --git a/src/common/sanity.hpp b/src/common/sanity.hpp
index c4f75e0..9bad464 100644
--- a/src/common/sanity.hpp
+++ b/src/common/sanity.hpp
@@ -1,20 +1,35 @@
/// return wrappers for unexpected NULL pointers
#ifndef SANITY_HPP
#define SANITY_HPP
+
# ifndef __cplusplus
# error "Please compile in C++ mode"
# endif
-# if __GNUC__ < 3
-// I don't specifically know what version this requires,
-// but GCC 3 was the beginning of modern GCC
-# error "Please upgrade your compiler to at least GCC 3"
+
+# if __GNUC__ < 4
+# error "Your compiler is absolutely ancient. You have no chance ..."
+# endif
+
+# if __GNUC__ == 4
+// clang identifies as GCC 4.2, but is mostly okay.
+// Until a bug-free release of it happens, though, I won't recommend it.
+// (patched) clang 3.1 would be the requirement
+# if __GNUC_MINOR__ < 6 && !defined(__clang__)
+# error "Please upgrade to at least GCC 4.6"
+# endif
+# if __GNUC_MINOR__ == 6
+# warning "Working around some annoying bugs in GCC 4.6 ..."
+# define ANNOYING_GCC46_WORKAROUNDS
+# endif
# endif
+
# ifndef __i386__
// Known platform dependencies:
// endianness for the [RW]FIFO.* macros
// possibly, some signal-handling
# error "Unsupported platform"
# endif
+
# ifdef __x86_64__
// I'm working on it - I know there are some pointer-size assumptions.
# error "Sorry, this code is believed not to be 64-bit safe"
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index f223b83..d3485d3 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -14,6 +14,7 @@
#include <cstdlib>
#include <cstring>
+#include "cxxstdio.hpp"
#include "mmo.hpp"
#include "utils.hpp"
@@ -86,7 +87,7 @@ void send_from_fifo(int fd)
static
void null_parse(int fd)
{
- printf("null_parse : %d\n", fd);
+ PRINTF("null_parse : %d\n", fd);
RFIFOSKIP(fd, RFIFOREST(fd));
}
@@ -109,7 +110,7 @@ void connect_client(int listen_fd)
}
if (!free_fds())
{
- fprintf(stderr, "softlimit reached, disconnecting : %d\n", fd);
+ FPRINTF(stderr, "softlimit reached, disconnecting : %d\n", fd);
delete_session(fd);
return;
}
@@ -275,7 +276,7 @@ void delete_session(int fd)
currentuse--;
if (currentuse < 0)
{
- fprintf(stderr, "delete_session: current sessions negative!\n");
+ FPRINTF(stderr, "delete_session: current sessions negative!\n");
currentuse = 0;
}
return;
@@ -302,12 +303,12 @@ void WFIFOSET(int fd, size_t len)
if (s->wdata_size + len + 16384 > s->max_wdata)
{
realloc_fifo(fd, s->max_rdata, s->max_wdata << 1);
- printf("socket: %d wdata expanded to %d bytes.\n", fd, s->max_wdata);
+ PRINTF("socket: %d wdata expanded to %d bytes.\n", fd, s->max_wdata);
}
if (s->wdata_size + len + 2048 < s->max_wdata)
s->wdata_size += len;
else
- fprintf(stderr, "socket: %d wdata lost !!\n", fd), abort();
+ FPRINTF(stderr, "socket: %d wdata lost !!\n", fd), abort();
}
void do_sendrecv(uint32_t next)
@@ -353,7 +354,7 @@ void do_parsepacket(void)
if (!session[i]->connected
&& time(NULL) - session[i]->created > CONNECT_TIMEOUT)
{
- printf("Session #%d timed out\n", i);
+ PRINTF("Session #%d timed out\n", i);
session[i]->eof = 1;
}
if (!session[i]->rdata_size && !session[i]->eof)
@@ -383,7 +384,7 @@ void RFIFOSKIP(int fd, size_t len)
if (s->rdata_size < s->rdata_pos)
{
- fprintf(stderr, "too many skip\n");
+ FPRINTF(stderr, "too many skip\n");
abort();
}
}
diff --git a/src/common/timer.cpp b/src/common/timer.cpp
index 0215b53..004771c 100644
--- a/src/common/timer.cpp
+++ b/src/common/timer.cpp
@@ -8,6 +8,7 @@
#include <cstdlib>
#include <cstring>
+#include "cxxstdio.hpp"
#include "utils.hpp"
static
@@ -183,12 +184,12 @@ void delete_timer(timer_id id, timer_func func)
{
if (id == 0 || id >= timer_data_num)
{
- fprintf(stderr, "delete_timer error : no such timer %d\n", id);
+ FPRINTF(stderr, "delete_timer error : no such timer %d\n", id);
abort();
}
if (timer_data[id].func != func)
{
- fprintf(stderr, "Timer mismatch\n");
+ FPRINTF(stderr, "Timer mismatch\n");
abort();
}
// "to let them disappear" - is this just in case?
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
index 35fdf5a..d8c0c12 100644
--- a/src/common/utils.cpp
+++ b/src/common/utils.cpp
@@ -1,11 +1,14 @@
#include "utils.hpp"
#include <netinet/in.h>
+#include <sys/time.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <algorithm>
+
//-----------------------------------------------------
// Function to suppress control characters in a string.
//-----------------------------------------------------
@@ -95,3 +98,58 @@ const char *ip2str(struct in_addr ip, bool extra_dot)
sprintf(buf, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
return buf;
}
+
+bool split_key_value(const std::string& line, std::string *w1, std::string *w2)
+{
+ std::string::const_iterator begin = line.begin(), end = line.end();
+
+ if (line[0] == '/' && line[1] == '/')
+ return false;
+ if (line.back() == '\r')
+ --end;
+ if (line.empty())
+ return false;
+
+ if (std::find_if(begin, end,
+ [](unsigned char c) { return c < ' '; }
+ ) != line.end())
+ return false;
+ std::string::const_iterator colon = std::find(begin, end, ':');
+ if (colon == end)
+ return false;
+ w1->assign(begin, colon);
+ ++colon;
+ while (std::isspace(*colon))
+ ++colon;
+ w2->assign(colon, end);
+ return true;
+}
+
+void stamp_time(timestamp_seconds_buffer& out, time_t *t)
+{
+ time_t when = t ? *t : time(NULL);
+ strftime(out, sizeof(out), "%Y-%m-%d %H:%M:%S", gmtime(&when));
+}
+void stamp_time(timestamp_milliseconds_buffer& out)
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ strftime(out, sizeof(out), "%Y-%m-%d %H:%M:%S", gmtime(&tv.tv_sec));
+ sprintf(out + 20, ".%03d", int(tv.tv_usec / 1000));
+}
+
+void log_with_timestamp(FILE *out, const_string line)
+{
+ if (!line)
+ {
+ fputc('\n', out);
+ return;
+ }
+ timestamp_milliseconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ fwrite(tmpstr, 1, sizeof(tmpstr), out);
+ fputs(": ", out);
+ fwrite(line.data(), 1, line.size(), out);
+ if (line.back() != '\n')
+ fputc('\n', out);
+}
diff --git a/src/common/utils.hpp b/src/common/utils.hpp
index 76ac626..553d34f 100644
--- a/src/common/utils.hpp
+++ b/src/common/utils.hpp
@@ -3,7 +3,12 @@
#include "sanity.hpp"
-// unguarded!
+#include <cstdio>
+#include <cstring>
+
+#include <string>
+
+#include "const_array.hpp"
#include "utils2.hpp"
/*
@@ -26,4 +31,23 @@ int e_mail_check(const char *email);
int config_switch (const char *str);
const char *ip2str(struct in_addr ip, bool extra_dot = false);
+bool split_key_value(const std::string& line, std::string *w1, std::string *w2);
+
+inline
+void strzcpy(char *dest, const char *src, size_t n)
+{
+ if (n)
+ {
+ strncpy(dest, src, n);
+ dest[n-1] = '\0';
+ }
+}
+
+typedef char timestamp_seconds_buffer[20];
+typedef char timestamp_milliseconds_buffer[24];
+void stamp_time(timestamp_seconds_buffer&, time_t *t=nullptr);
+void stamp_time(timestamp_milliseconds_buffer&);
+
+void log_with_timestamp(FILE *out, const_string line);
+
#endif //UTILS_HPP
diff --git a/src/ladmin/ladmin.cpp b/src/ladmin/ladmin.cpp
index 7b32fc3..2dc2bdb 100644
--- a/src/ladmin/ladmin.cpp
+++ b/src/ladmin/ladmin.cpp
@@ -13,12 +13,14 @@
#include <cctype>
#include <csignal>
-#include <cstdarg> // exception to "no va_list" rule
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
+#include <fstream>
+
+#include "../common/cxxstdio.hpp"
#include "../common/core.hpp"
#include "../common/md5calc.hpp"
#include "../common/mmo.hpp"
@@ -27,7 +29,7 @@
int eathena_interactive_session; // from core.c
-#define Iprintf if (eathena_interactive_session) printf
+#define Iprintf if (eathena_interactive_session) PRINTF
//-------------------------------INSTRUCTIONS------------------------------
// Set the variables below:
@@ -43,7 +45,6 @@ int loginserverport = 6900; // Port of login-server
char loginserveradminpassword[24] = "admin"; // Administration password
int passenc = 2; // Encoding type of the password
char ladmin_log_filename[1024] = "log/ladmin.log";
-char date_format[32] = "%Y-%m-%d %H:%M:%S";
//-------------------------------------------------------------------------
// LIST of COMMANDs that you can type at the prompt:
// To use these commands you can only type only the first letters.
@@ -235,35 +236,16 @@ int already_exit_function = 0; // sometimes, the exit function is called twice..
//------------------------------
// Writing function of logs file
//------------------------------
-static __attribute__((format(printf, 1, 2)))
-int ladmin_log(const char *fmt, ...);
-int ladmin_log(const char *fmt, ...)
+#define LADMIN_LOG(fmt, args...) \
+ ladmin_log(static_cast<const std::string&>(STRPRINTF(fmt, ## args)))
+static
+void ladmin_log(const_string line)
{
- FILE *logfp;
- va_list ap;
- struct timeval tv;
- char tmpstr[2048];
-
- va_start(ap, fmt);
-
- logfp = fopen_(ladmin_log_filename, "a");
- if (logfp)
- {
- if (fmt[0] == '\0') // jump a line if no message
- fprintf(logfp, "\n");
- else
- {
- gettimeofday(&tv, NULL);
- strftime(tmpstr, 24, date_format, localtime(&(tv.tv_sec)));
- sprintf(tmpstr + strlen(tmpstr), ".%03d: %s",
- (int) tv.tv_usec / 1000, fmt);
- vfprintf(logfp, tmpstr, ap);
- }
- fclose_(logfp);
- }
-
- va_end(ap);
- return 0;
+ FILE *logfp = fopen_(ladmin_log_filename, "a");
+ if (!logfp)
+ return;
+ log_with_timestamp(logfp, line);
+ fclose_(logfp);
}
//---------------------------------------------
@@ -301,9 +283,9 @@ int verify_accountname(const char *account_name)
{
if (account_name[i] < 32)
{
- printf("Illegal character found in the account name (%d%s character).\n",
+ PRINTF("Illegal character found in the account name (%d%s character).\n",
i + 1, makeordinal(i + 1));
- ladmin_log("Illegal character found in the account name (%d%s character).\n",
+ LADMIN_LOG("Illegal character found in the account name (%d%s character).\n",
i + 1, makeordinal(i + 1));
return 0;
}
@@ -311,15 +293,15 @@ int verify_accountname(const char *account_name)
if (strlen(account_name) < 4)
{
- printf("Account name is too short. Please input an account name of 4-23 bytes.\n");
- ladmin_log("Account name is too short. Please input an account name of 4-23 bytes.\n");
+ PRINTF("Account name is too short. Please input an account name of 4-23 bytes.\n");
+ LADMIN_LOG("Account name is too short. Please input an account name of 4-23 bytes.\n");
return 0;
}
if (strlen(account_name) > 23)
{
- printf("Account name is too long. Please input an account name of 4-23 bytes.\n");
- ladmin_log("Account name is too long. Please input an account name of 4-23 bytes.\n");
+ PRINTF("Account name is too long. Please input an account name of 4-23 bytes.\n");
+ LADMIN_LOG("Account name is too long. Please input an account name of 4-23 bytes.\n");
return 0;
}
@@ -336,32 +318,32 @@ int typepasswd(char *password)
int letter;
int i;
- ladmin_log("No password was given. Request to obtain a password.\n");
+ LADMIN_LOG("No password was given. Request to obtain a password.\n");
memset(password1, '\0', sizeof(password1));
memset(password2, '\0', sizeof(password2));
- printf("\033[1;36m Type the password > \033[0;32;42m");
+ PRINTF("\033[1;36m Type the password > \033[0;32;42m");
i = 0;
while ((letter = getchar()) != '\n')
password1[i++] = letter;
- printf("\033[0m\033[1;36m Verify the password > \033[0;32;42m");
+ PRINTF("\033[0m\033[1;36m Verify the password > \033[0;32;42m");
i = 0;
while ((letter = getchar()) != '\n')
password2[i++] = letter;
- printf("\033[0m");
+ PRINTF("\033[0m");
fflush(stdout);
fflush(stdin);
if (strcmp(password1, password2) != 0)
{
- printf("Password verification failed. Please input same password.\n");
- ladmin_log("Password verification failed. Please input same password.\n");
- ladmin_log(" First password: %s, second password: %s.\n",
+ PRINTF("Password verification failed. Please input same password.\n");
+ LADMIN_LOG("Password verification failed. Please input same password.\n");
+ LADMIN_LOG(" First password: %s, second password: %s.\n",
password1, password2);
return 0;
}
- ladmin_log("Typed password: %s.\n", password1);
+ LADMIN_LOG("Typed password: %s.\n", password1);
strcpy(password, password1);
return 1;
}
@@ -378,9 +360,9 @@ int verify_password(const char *password)
{
if (password[i] < 32)
{
- printf("Illegal character found in the password (%d%s character).\n",
+ PRINTF("Illegal character found in the password (%d%s character).\n",
i + 1, makeordinal(i + 1));
- ladmin_log("Illegal character found in the password (%d%s character).\n",
+ LADMIN_LOG("Illegal character found in the password (%d%s character).\n",
i + 1, makeordinal(i + 1));
return 0;
}
@@ -388,15 +370,15 @@ int verify_password(const char *password)
if (strlen(password) < 4)
{
- printf("Account name is too short. Please input an account name of 4-23 bytes.\n");
- ladmin_log("Account name is too short. Please input an account name of 4-23 bytes.\n");
+ PRINTF("Account name is too short. Please input an account name of 4-23 bytes.\n");
+ LADMIN_LOG("Account name is too short. Please input an account name of 4-23 bytes.\n");
return 0;
}
if (strlen(password) > 23)
{
- printf("Password is too long. Please input a password of 4-23 bytes.\n");
- ladmin_log("Password is too long. Please input a password of 4-23 bytes.\n");
+ PRINTF("Password is too long. Please input a password of 4-23 bytes.\n");
+ LADMIN_LOG("Password is too long. Please input a password of 4-23 bytes.\n");
return 0;
}
@@ -553,320 +535,320 @@ void display_help(const char *param)
// Analyse of the command
check_command(command); // give complete name to the command
- ladmin_log("Displaying of the commands or a command.\n");
+ LADMIN_LOG("Displaying of the commands or a command.\n");
if (strcmp(command, "help") == 0)
{
- printf("help/?\n");
- printf(" Display the description of the commands\n");
- printf("help/? [command]\n");
- printf(" Display the description of the specified command\n");
+ PRINTF("help/?\n");
+ PRINTF(" Display the description of the commands\n");
+ PRINTF("help/? [command]\n");
+ PRINTF(" Display the description of the specified command\n");
// general commands
}
else if (strcmp(command, "add") == 0)
{
- printf("add <account_name> <sex> <password>\n");
- printf(" Create an account with the default email (a@a.com).\n");
- printf(" Concerning the sex, only the first letter is used (F or M).\n");
- printf(" The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.\n");
- printf(" When the password is omitted,\n");
- printf(" the input is done without displaying of the pressed keys.\n");
- printf(" <example> add testname Male testpass\n");
+ PRINTF("add <account_name> <sex> <password>\n");
+ PRINTF(" Create an account with the default email (a@a.com).\n");
+ PRINTF(" Concerning the sex, only the first letter is used (F or M).\n");
+ PRINTF(" The e-mail is set to a@a.com (default e-mail). It's like to have no e-mail.\n");
+ PRINTF(" When the password is omitted,\n");
+ PRINTF(" the input is done without displaying of the pressed keys.\n");
+ PRINTF(" <example> add testname Male testpass\n");
}
else if (strcmp(command, "ban") == 0)
{
- printf("ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
- printf(" Changes the final date of a banishment of an account.\n");
- printf(" Like banset, but <account name> is at end.\n");
+ PRINTF("ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
+ PRINTF(" Changes the final date of a banishment of an account.\n");
+ PRINTF(" Like banset, but <account name> is at end.\n");
}
else if (strcmp(command, "banadd") == 0)
{
- printf("banadd <account_name> <modifier>\n");
- printf(" Adds or substracts time from the final date of a banishment of an account.\n");
- printf(" Modifier is done as follows:\n");
- printf(" Adjustment value (-1, 1, +1, etc...)\n");
- printf(" Modified element:\n");
- printf(" a or y: year\n");
- printf(" m: month\n");
- printf(" j or d: day\n");
- printf(" h: hour\n");
- printf(" mn: minute\n");
- printf(" s: second\n");
- printf(" <example> banadd testname +1m-2mn1s-6y\n");
- printf(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf(" and 6 years at the same time.\n");
- printf("NOTE: If you modify the final date of a non-banished account,\n");
- printf(" you fix the final date to (actual time +- adjustments)\n");
+ PRINTF("banadd <account_name> <modifier>\n");
+ PRINTF(" Adds or substracts time from the final date of a banishment of an account.\n");
+ PRINTF(" Modifier is done as follows:\n");
+ PRINTF(" Adjustment value (-1, 1, +1, etc...)\n");
+ PRINTF(" Modified element:\n");
+ PRINTF(" a or y: year\n");
+ PRINTF(" m: month\n");
+ PRINTF(" j or d: day\n");
+ PRINTF(" h: hour\n");
+ PRINTF(" mn: minute\n");
+ PRINTF(" s: second\n");
+ PRINTF(" <example> banadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ PRINTF("NOTE: If you modify the final date of a non-banished account,\n");
+ PRINTF(" you fix the final date to (actual time +- adjustments)\n");
}
else if (strcmp(command, "banset") == 0)
{
- printf("banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf(" Changes the final date of a banishment of an account.\n");
- printf(" Default time [hh:mm:ss]: 23:59:59.\n");
- printf("banset <account_name> 0\n");
- printf(" Set a non-banished account (0 = unbanished).\n");
+ PRINTF("banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" Changes the final date of a banishment of an account.\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ PRINTF("banset <account_name> 0\n");
+ PRINTF(" Set a non-banished account (0 = unbanished).\n");
}
else if (strcmp(command, "block") == 0)
{
- printf("block <account name>\n");
- printf(" Set state 5 (You have been blocked by the GM Team) to an account.\n");
- printf(" This command works like state <account_name> 5.\n");
+ PRINTF("block <account name>\n");
+ PRINTF(" Set state 5 (You have been blocked by the GM Team) to an account.\n");
+ PRINTF(" This command works like state <account_name> 5.\n");
}
else if (strcmp(command, "check") == 0)
{
- printf("check <account_name> <password>\n");
- printf(" Check the validity of a password for an account.\n");
- printf(" NOTE: Server will never sends back a password.\n");
- printf(" It's the only method you have to know if a password is correct.\n");
- printf(" The other method is to have a ('physical') access to the accounts file.\n");
+ PRINTF("check <account_name> <password>\n");
+ PRINTF(" Check the validity of a password for an account.\n");
+ PRINTF(" NOTE: Server will never sends back a password.\n");
+ PRINTF(" It's the only method you have to know if a password is correct.\n");
+ PRINTF(" The other method is to have a ('physical') access to the accounts file.\n");
}
else if (strcmp(command, "create") == 0)
{
- printf("create <account_name> <sex> <email> <password>\n");
- printf(" Like the 'add' command, but with e-mail moreover.\n");
- printf(" <example> create testname Male my@mail.com testpass\n");
+ PRINTF("create <account_name> <sex> <email> <password>\n");
+ PRINTF(" Like the 'add' command, but with e-mail moreover.\n");
+ PRINTF(" <example> create testname Male my@mail.com testpass\n");
}
else if (strcmp(command, "delete") == 0)
{
- printf("del <account name>\n");
- printf(" Remove an account.\n");
- printf(" This order requires confirmation. After confirmation, the account is deleted.\n");
+ PRINTF("del <account name>\n");
+ PRINTF(" Remove an account.\n");
+ PRINTF(" This order requires confirmation. After confirmation, the account is deleted.\n");
}
else if (strcmp(command, "email") == 0)
{
- printf("email <account_name> <email>\n");
- printf(" Modify the e-mail of an account.\n");
+ PRINTF("email <account_name> <email>\n");
+ PRINTF(" Modify the e-mail of an account.\n");
}
else if (strcmp(command, "getcount") == 0)
{
- printf("getcount\n");
- printf(" Give the number of players online on all char-servers.\n");
+ PRINTF("getcount\n");
+ PRINTF(" Give the number of players online on all char-servers.\n");
}
else if (strcmp(command, "gm") == 0)
{
- printf("gm <account_name> [GM_level]\n");
- printf(" Modify the GM level of an account.\n");
- printf(" Default value remove GM level (GM level = 0).\n");
- printf(" <example> gm testname 80\n");
+ PRINTF("gm <account_name> [GM_level]\n");
+ PRINTF(" Modify the GM level of an account.\n");
+ PRINTF(" Default value remove GM level (GM level = 0).\n");
+ PRINTF(" <example> gm testname 80\n");
}
else if (strcmp(command, "id") == 0)
{
- printf("id <account name>\n");
- printf(" Give the id of an account.\n");
+ PRINTF("id <account name>\n");
+ PRINTF(" Give the id of an account.\n");
}
else if (strcmp(command, "info") == 0)
{
- printf("info <account_id>\n");
- printf(" Display complete information of an account.\n");
+ PRINTF("info <account_id>\n");
+ PRINTF(" Display complete information of an account.\n");
}
else if (strcmp(command, "kami") == 0)
{
- printf("kami <message>\n");
- printf(" Sends a broadcast message on all map-server (in yellow).\n");
+ PRINTF("kami <message>\n");
+ PRINTF(" Sends a broadcast message on all map-server (in yellow).\n");
}
else if (strcmp(command, "kamib") == 0)
{
- printf("kamib <message>\n");
- printf(" Sends a broadcast message on all map-server (in blue).\n");
+ PRINTF("kamib <message>\n");
+ PRINTF(" Sends a broadcast message on all map-server (in blue).\n");
}
else if (strcmp(command, "list") == 0)
{
- printf("list/ls [start_id [end_id]]\n");
- printf(" Display a list of accounts.\n");
- printf(" 'start_id', 'end_id': indicate end and start identifiers.\n");
- printf(" Research by name is not possible with this command.\n");
- printf(" <example> list 10 9999999\n");
+ PRINTF("list/ls [start_id [end_id]]\n");
+ PRINTF(" Display a list of accounts.\n");
+ PRINTF(" 'start_id', 'end_id': indicate end and start identifiers.\n");
+ PRINTF(" Research by name is not possible with this command.\n");
+ PRINTF(" <example> list 10 9999999\n");
}
else if (strcmp(command, "itemfrob") == 0)
{
- printf("itemfrob <source-id> <dest-id>\n");
- printf(" Translates item IDs for all accounts.\n");
- printf(" Any items matching the source item ID will be mapped to the dest-id.\n");
- printf(" <example> itemfrob 500 700\n");
+ PRINTF("itemfrob <source-id> <dest-id>\n");
+ PRINTF(" Translates item IDs for all accounts.\n");
+ PRINTF(" Any items matching the source item ID will be mapped to the dest-id.\n");
+ PRINTF(" <example> itemfrob 500 700\n");
}
else if (strcmp(command, "listban") == 0)
{
- printf("listBan/lsBan [start_id [end_id]]\n");
- printf(" Like list/ls, but only for accounts with state or banished.\n");
+ PRINTF("listBan/lsBan [start_id [end_id]]\n");
+ PRINTF(" Like list/ls, but only for accounts with state or banished.\n");
}
else if (strcmp(command, "listgm") == 0)
{
- printf("listGM/lsGM [start_id [end_id]]\n");
- printf(" Like list/ls, but only for GM accounts.\n");
+ PRINTF("listGM/lsGM [start_id [end_id]]\n");
+ PRINTF(" Like list/ls, but only for GM accounts.\n");
}
else if (strcmp(command, "listok") == 0)
{
- printf("listOK/lsOK [start_id [end_id]]\n");
- printf(" Like list/ls, but only for accounts without state and not banished.\n");
+ PRINTF("listOK/lsOK [start_id [end_id]]\n");
+ PRINTF(" Like list/ls, but only for accounts without state and not banished.\n");
}
else if (strcmp(command, "memo") == 0)
{
- printf("memo <account_name> <memo>\n");
- printf(" Modify the memo of an account.\n");
- printf(" 'memo': it can have until 253 characters (with spaces or not).\n");
+ PRINTF("memo <account_name> <memo>\n");
+ PRINTF(" Modify the memo of an account.\n");
+ PRINTF(" 'memo': it can have until 253 characters (with spaces or not).\n");
}
else if (strcmp(command, "name") == 0)
{
- printf("name <account_id>\n");
- printf(" Give the name of an account.\n");
+ PRINTF("name <account_id>\n");
+ PRINTF(" Give the name of an account.\n");
}
else if (strcmp(command, "password") == 0)
{
- printf("passwd <account_name> <new_password>\n");
- printf(" Change the password of an account.\n");
- printf(" When new password is omitted,\n");
- printf(" the input is done without displaying of the pressed keys.\n");
+ PRINTF("passwd <account_name> <new_password>\n");
+ PRINTF(" Change the password of an account.\n");
+ PRINTF(" When new password is omitted,\n");
+ PRINTF(" the input is done without displaying of the pressed keys.\n");
}
else if (strcmp(command, "reloadgm") == 0)
{
- printf("reloadGM\n");
- printf(" Reload GM configuration file\n");
+ PRINTF("reloadGM\n");
+ PRINTF(" Reload GM configuration file\n");
}
else if (strcmp(command, "search") == 0)
{
- printf("search <expression>\n");
- printf(" Seek accounts.\n");
- printf(" Displays the accounts whose names correspond.\n");
-// printf("search -r/-e/--expr/--regex <expression>\n");
-// printf(" Seek accounts by regular expression.\n");
-// printf(" Displays the accounts whose names correspond.\n");
+ PRINTF("search <expression>\n");
+ PRINTF(" Seek accounts.\n");
+ PRINTF(" Displays the accounts whose names correspond.\n");
+// PRINTF("search -r/-e/--expr/--regex <expression>\n");
+// PRINTF(" Seek accounts by regular expression.\n");
+// PRINTF(" Displays the accounts whose names correspond.\n");
}
else if (strcmp(command, "sex") == 0)
{
- printf("sex <account_name> <sex>\n");
- printf(" Modify the sex of an account.\n");
- printf(" <example> sex testname Male\n");
+ PRINTF("sex <account_name> <sex>\n");
+ PRINTF(" Modify the sex of an account.\n");
+ PRINTF(" <example> sex testname Male\n");
}
else if (strcmp(command, "state") == 0)
{
- printf("state <account_name> <new_state> <error_message_#7>\n");
- printf(" Change the state of an account.\n");
- printf(" 'new_state': state is the state of the packet 0x006a + 1.\n");
- printf(" The possibilities are:\n");
- printf(" 0 = Account ok\n");
- printf(" 1 = Unregistered ID\n");
- printf(" 2 = Incorrect Password\n");
- printf(" 3 = This ID is expired\n");
- printf(" 4 = Rejected from Server\n");
- printf(" 5 = You have been blocked by the GM Team\n");
- printf(" 6 = Your Game's EXE file is not the latest version\n");
- printf(" 7 = You are Prohibited to log in until...\n");
- printf(" 8 = Server is jammed due to over populated\n");
- printf(" 9 = No MSG\n");
- printf(" 100 = This ID has been totally erased\n");
- printf(" all other values are 'No MSG', then use state 9 please.\n");
- printf(" 'error_message_#7': message of the code error 6\n");
- printf(" = Your are Prohibited to log in until... (packet 0x006a)\n");
+ PRINTF("state <account_name> <new_state> <error_message_#7>\n");
+ PRINTF(" Change the state of an account.\n");
+ PRINTF(" 'new_state': state is the state of the packet 0x006a + 1.\n");
+ PRINTF(" The possibilities are:\n");
+ PRINTF(" 0 = Account ok\n");
+ PRINTF(" 1 = Unregistered ID\n");
+ PRINTF(" 2 = Incorrect Password\n");
+ PRINTF(" 3 = This ID is expired\n");
+ PRINTF(" 4 = Rejected from Server\n");
+ PRINTF(" 5 = You have been blocked by the GM Team\n");
+ PRINTF(" 6 = Your Game's EXE file is not the latest version\n");
+ PRINTF(" 7 = You are Prohibited to log in until...\n");
+ PRINTF(" 8 = Server is jammed due to over populated\n");
+ PRINTF(" 9 = No MSG\n");
+ PRINTF(" 100 = This ID has been totally erased\n");
+ PRINTF(" all other values are 'No MSG', then use state 9 please.\n");
+ PRINTF(" 'error_message_#7': message of the code error 6\n");
+ PRINTF(" = Your are Prohibited to log in until... (packet 0x006a)\n");
}
else if (strcmp(command, "timeadd") == 0)
{
- printf("timeadd <account_name> <modifier>\n");
- printf(" Adds or substracts time from the validity limit of an account.\n");
- printf(" Modifier is done as follows:\n");
- printf(" Adjustment value (-1, 1, +1, etc...)\n");
- printf(" Modified element:\n");
- printf(" a or y: year\n");
- printf(" m: month\n");
- printf(" j or d: day\n");
- printf(" h: hour\n");
- printf(" mn: minute\n");
- printf(" s: second\n");
- printf(" <example> timeadd testname +1m-2mn1s-6y\n");
- printf(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf(" and 6 years at the same time.\n");
- printf("NOTE: You can not modify a unlimited validity limit.\n");
- printf(" If you want modify it, you want probably create a limited validity limit.\n");
- printf(" So, at first, you must set the validity limit to a date/time.\n");
+ PRINTF("timeadd <account_name> <modifier>\n");
+ PRINTF(" Adds or substracts time from the validity limit of an account.\n");
+ PRINTF(" Modifier is done as follows:\n");
+ PRINTF(" Adjustment value (-1, 1, +1, etc...)\n");
+ PRINTF(" Modified element:\n");
+ PRINTF(" a or y: year\n");
+ PRINTF(" m: month\n");
+ PRINTF(" j or d: day\n");
+ PRINTF(" h: hour\n");
+ PRINTF(" mn: minute\n");
+ PRINTF(" s: second\n");
+ PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ PRINTF("NOTE: You can not modify a unlimited validity limit.\n");
+ PRINTF(" If you want modify it, you want probably create a limited validity limit.\n");
+ PRINTF(" So, at first, you must set the validity limit to a date/time.\n");
}
else if (strcmp(command, "timeadd") == 0)
{
- printf("timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf(" Changes the validity limit of an account.\n");
- printf(" Default time [hh:mm:ss]: 23:59:59.\n");
- printf("timeset <account_name> 0\n");
- printf(" Gives an unlimited validity limit (0 = unlimited).\n");
+ PRINTF("timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" Changes the validity limit of an account.\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ PRINTF("timeset <account_name> 0\n");
+ PRINTF(" Gives an unlimited validity limit (0 = unlimited).\n");
}
else if (strcmp(command, "unban") == 0)
{
- printf("unban/unbanish <account name>\n");
- printf(" Remove the banishment of an account.\n");
- printf(" This command works like banset <account_name> 0.\n");
+ PRINTF("unban/unbanish <account name>\n");
+ PRINTF(" Remove the banishment of an account.\n");
+ PRINTF(" This command works like banset <account_name> 0.\n");
}
else if (strcmp(command, "unblock") == 0)
{
- printf("unblock <account name>\n");
- printf(" Set state 0 (Account ok) to an account.\n");
- printf(" This command works like state <account_name> 0.\n");
+ PRINTF("unblock <account name>\n");
+ PRINTF(" Set state 0 (Account ok) to an account.\n");
+ PRINTF(" This command works like state <account_name> 0.\n");
}
else if (strcmp(command, "version") == 0)
{
- printf("version\n");
- printf(" Display the version of the login-server.\n");
+ PRINTF("version\n");
+ PRINTF(" Display the version of the login-server.\n");
}
else if (strcmp(command, "who") == 0)
{
- printf("who <account name>\n");
- printf(" Displays complete information of an account.\n");
+ PRINTF("who <account name>\n");
+ PRINTF(" Displays complete information of an account.\n");
// quit
}
else if (strcmp(command, "quit") == 0 ||
strcmp(command, "exit") == 0 ||
strcmp(command, "end") == 0)
{
- printf("quit/end/exit\n");
- printf(" End of the program of administration.\n");
+ PRINTF("quit/end/exit\n");
+ PRINTF(" End of the program of administration.\n");
// unknown command
}
else
{
if (strlen(command) > 0)
- printf("Unknown command [%s] for help. Displaying of all commands.\n",
+ PRINTF("Unknown command [%s] for help. Displaying of all commands.\n",
command);
- printf(" help/? -- Display this help\n");
- printf(" help/? [command] -- Display the help of the command\n");
- printf(" add <account_name> <sex> <password> -- Create an account with default email\n");
- printf(" ban/banish yyyy/mm/dd hh:mm:ss <account name> -- Change final date of a ban\n");
- printf(" banadd/ba <account_name> <modifier> -- Add or substract time from the final\n");
- printf(" example: ba apple +1m-2mn1s-2y date of a banishment of an account\n");
- printf(" banset/bs <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban\n");
- printf(" banset/bs <account_name> 0 -- Un-banish an account\n");
- printf(" block <account name> -- Set state 5 (blocked by the GM Team) to an account\n");
- printf(" check <account_name> <password> -- Check the validity of a password\n");
- printf(" create <account_name> <sex> <email> <passwrd> -- Create an account with email\n");
- printf(" del <account name> -- Remove an account\n");
- printf(" email <account_name> <email> -- Modify an email of an account\n");
- printf(" getcount -- Give the number of players online\n");
- printf(" gm <account_name> [GM_level] -- Modify the GM level of an account\n");
- printf(" id <account name> -- Give the id of an account\n");
- printf(" info <account_id> -- Display all information of an account\n");
- printf(" itemfrob <source-id> <dest-id> -- Map all items from one item ID to another\n");
- printf(" kami <message> -- Sends a broadcast message (in yellow)\n");
- printf(" kamib <message> -- Sends a broadcast message (in blue)\n");
- printf(" list/ls [First_id [Last_id]] -- Display a list of accounts\n");
- printf(" listBan/lsBan [First_id [Last_id] ] -- Display a list of accounts\n");
- printf(" with state or banished\n");
- printf(" listGM/lsGM [First_id [Last_id]] -- Display a list of GM accounts\n");
- printf(" listOK/lsOK [First_id [Last_id] ] -- Display a list of accounts\n");
- printf(" without state and not banished\n");
- printf(" memo <account_name> <memo> -- Modify the memo of an account\n");
- printf(" name <account_id> -- Give the name of an account\n");
- printf(" passwd <account_name> <new_password> -- Change the password of an account\n");
- printf(" quit/end/exit -- End of the program of administation\n");
- printf(" reloadGM -- Reload GM configuration file\n");
- printf(" search <expression> -- Seek accounts\n");
-// printf(" search -e/-r/--expr/--regex <expressn> -- Seek accounts by regular-expression\n");
- printf(" sex <nomcompte> <sexe> -- Modify the sex of an account\n");
- printf(" state <account_name> <new_state> <error_message_#7> -- Change the state\n");
- printf(" timeadd/ta <account_name> <modifier> -- Add or substract time from the\n");
- printf(" example: ta apple +1m-2mn1s-2y validity limit of an account\n");
- printf(" timeset/ts <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit\n");
- printf(" timeset/ts <account_name> 0 -- Give a unlimited validity limit\n");
- printf(" unban/unbanish <account name> -- Remove the banishment of an account\n");
- printf(" unblock <account name> -- Set state 0 (Account ok) to an account\n");
- printf(" version -- Gives the version of the login-server\n");
- printf(" who <account name> -- Display all information of an account\n");
- printf(" who <account name> -- Display all information of an account\n");
- printf(" Note: To use spaces in an account name, type \"<account name>\" (or ').\n");
+ PRINTF(" help/? -- Display this help\n");
+ PRINTF(" help/? [command] -- Display the help of the command\n");
+ PRINTF(" add <account_name> <sex> <password> -- Create an account with default email\n");
+ PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name> -- Change final date of a ban\n");
+ PRINTF(" banadd/ba <account_name> <modifier> -- Add or substract time from the final\n");
+ PRINTF(" example: ba apple +1m-2mn1s-2y date of a banishment of an account\n");
+ PRINTF(" banset/bs <account_name> yyyy/mm/dd [hh:mm:ss] -- Change final date of a ban\n");
+ PRINTF(" banset/bs <account_name> 0 -- Un-banish an account\n");
+ PRINTF(" block <account name> -- Set state 5 (blocked by the GM Team) to an account\n");
+ PRINTF(" check <account_name> <password> -- Check the validity of a password\n");
+ PRINTF(" create <account_name> <sex> <email> <passwrd> -- Create an account with email\n");
+ PRINTF(" del <account name> -- Remove an account\n");
+ PRINTF(" email <account_name> <email> -- Modify an email of an account\n");
+ PRINTF(" getcount -- Give the number of players online\n");
+ PRINTF(" gm <account_name> [GM_level] -- Modify the GM level of an account\n");
+ PRINTF(" id <account name> -- Give the id of an account\n");
+ PRINTF(" info <account_id> -- Display all information of an account\n");
+ PRINTF(" itemfrob <source-id> <dest-id> -- Map all items from one item ID to another\n");
+ PRINTF(" kami <message> -- Sends a broadcast message (in yellow)\n");
+ PRINTF(" kamib <message> -- Sends a broadcast message (in blue)\n");
+ PRINTF(" list/ls [First_id [Last_id]] -- Display a list of accounts\n");
+ PRINTF(" listBan/lsBan [First_id [Last_id] ] -- Display a list of accounts\n");
+ PRINTF(" with state or banished\n");
+ PRINTF(" listGM/lsGM [First_id [Last_id]] -- Display a list of GM accounts\n");
+ PRINTF(" listOK/lsOK [First_id [Last_id] ] -- Display a list of accounts\n");
+ PRINTF(" without state and not banished\n");
+ PRINTF(" memo <account_name> <memo> -- Modify the memo of an account\n");
+ PRINTF(" name <account_id> -- Give the name of an account\n");
+ PRINTF(" passwd <account_name> <new_password> -- Change the password of an account\n");
+ PRINTF(" quit/end/exit -- End of the program of administation\n");
+ PRINTF(" reloadGM -- Reload GM configuration file\n");
+ PRINTF(" search <expression> -- Seek accounts\n");
+// PRINTF(" search -e/-r/--expr/--regex <expressn> -- Seek accounts by regular-expression\n");
+ PRINTF(" sex <nomcompte> <sexe> -- Modify the sex of an account\n");
+ PRINTF(" state <account_name> <new_state> <error_message_#7> -- Change the state\n");
+ PRINTF(" timeadd/ta <account_name> <modifier> -- Add or substract time from the\n");
+ PRINTF(" example: ta apple +1m-2mn1s-2y validity limit of an account\n");
+ PRINTF(" timeset/ts <account_name> yyyy/mm/dd [hh:mm:ss] -- Change the validify limit\n");
+ PRINTF(" timeset/ts <account_name> 0 -- Give a unlimited validity limit\n");
+ PRINTF(" unban/unbanish <account name> -- Remove the banishment of an account\n");
+ PRINTF(" unblock <account name> -- Set state 0 (Account ok) to an account\n");
+ PRINTF(" version -- Gives the version of the login-server\n");
+ PRINTF(" who <account name> -- Display all information of an account\n");
+ PRINTF(" who <account name> -- Display all information of an account\n");
+ PRINTF(" Note: To use spaces in an account name, type \"<account name>\" (or ').\n");
}
}
@@ -890,9 +872,9 @@ int addaccount(const char *param, int emailflag)
sscanf(param, "'%[^']' %s %[^\r\n]", name, sex, password) < 2 && // password can be void
sscanf(param, "%s %s %[^\r\n]", name, sex, password) < 2)
{ // password can be void
- printf("Please input an account name, a sex and a password.\n");
- printf("<example> add testname Male testpass\n");
- ladmin_log("Incomplete parameters to create an account ('add' command).\n");
+ PRINTF("Please input an account name, a sex and a password.\n");
+ PRINTF("<example> add testname Male testpass\n");
+ LADMIN_LOG("Incomplete parameters to create an account ('add' command).\n");
return 136;
}
strcpy(email, "a@a.com"); // default email
@@ -904,9 +886,9 @@ int addaccount(const char *param, int emailflag)
sscanf(param, "%s %s %s %[^\r\n]", name, sex, email,
password) < 3)
{ // password can be void
- printf("Please input an account name, a sex and a password.\n");
- printf("<example> create testname Male my@mail.com testpass\n");
- ladmin_log("Incomplete parameters to create an account ('create' command).\n");
+ PRINTF("Please input an account name, a sex and a password.\n");
+ PRINTF("<example> create testname Male my@mail.com testpass\n");
+ LADMIN_LOG("Incomplete parameters to create an account ('create' command).\n");
return 136;
}
}
@@ -918,33 +900,33 @@ int addaccount(const char *param, int emailflag)
sex[0] = toupper(sex[0]);
if (strchr("MF", sex[0]) == NULL)
{
- printf("Illegal gender [%s]. Please input M or F.\n", sex);
- ladmin_log("Illegal gender [%s]. Please input M or F.\n",
+ PRINTF("Illegal gender [%s]. Please input M or F.\n", sex);
+ LADMIN_LOG("Illegal gender [%s]. Please input M or F.\n",
sex);
return 103;
}
if (strlen(email) < 3)
{
- printf("Email is too short [%s]. Please input a valid e-mail.\n",
+ PRINTF("Email is too short [%s]. Please input a valid e-mail.\n",
email);
- ladmin_log("Email is too short [%s]. Please input a valid e-mail.\n",
+ LADMIN_LOG("Email is too short [%s]. Please input a valid e-mail.\n",
email);
return 109;
}
if (strlen(email) > 39)
{
- printf("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
+ PRINTF("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
email);
- ladmin_log("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
+ LADMIN_LOG("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
email);
return 109;
}
if (e_mail_check(email) == 0)
{
- printf("Invalid email [%s]. Please input a valid e-mail.\n",
+ PRINTF("Invalid email [%s]. Please input a valid e-mail.\n",
email);
- ladmin_log("Invalid email [%s]. Please input a valid e-mail.\n",
+ LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n",
email);
return 109;
}
@@ -957,7 +939,7 @@ int addaccount(const char *param, int emailflag)
if (verify_password(password) == 0)
return 104;
- ladmin_log("Request to login-server to create an account.\n");
+ LADMIN_LOG("Request to login-server to create an account.\n");
WFIFOW(login_fd, 0) = 0x7930;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -989,11 +971,11 @@ int banaddaccount(const char *param)
sscanf(param, "'%[^']' %[^\r\n]", name, modif) < 2 &&
sscanf(param, "%s %[^\r\n]", name, modif) < 2)
{
- printf("Please input an account name and a modifier.\n");
- printf(" <example>: banadd testname +1m-2mn1s-6y\n");
- printf(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf(" and 6 years at the same time.\n");
- ladmin_log("Incomplete parameters to modify the ban date/time of an account ('banadd' command).\n");
+ PRINTF("Please input an account name and a modifier.\n");
+ PRINTF(" <example>: banadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ LADMIN_LOG("Incomplete parameters to modify the ban date/time of an account ('banadd' command).\n");
return 136;
}
if (verify_accountname(name) == 0)
@@ -1058,69 +1040,69 @@ int banaddaccount(const char *param)
}
}
- printf(" year: %d\n", year);
- printf(" month: %d\n", month);
- printf(" day: %d\n", day);
- printf(" hour: %d\n", hour);
- printf(" minute: %d\n", minute);
- printf(" second: %d\n", second);
+ PRINTF(" year: %d\n", year);
+ PRINTF(" month: %d\n", month);
+ PRINTF(" day: %d\n", day);
+ PRINTF(" hour: %d\n", hour);
+ PRINTF(" minute: %d\n", minute);
+ PRINTF(" second: %d\n", second);
if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0
&& second == 0)
{
- printf("Please give an adjustment with this command:\n");
- printf(" Adjustment value (-1, 1, +1, etc...)\n");
- printf(" Modified element:\n");
- printf(" a or y: year\n");
- printf(" m: month\n");
- printf(" j or d: day\n");
- printf(" h: hour\n");
- printf(" mn: minute\n");
- printf(" s: second\n");
- printf(" <example> banadd testname +1m-2mn1s-6y\n");
- printf(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf(" and 6 years at the same time.\n");
- ladmin_log("No adjustment isn't an adjustment ('banadd' command).\n");
+ PRINTF("Please give an adjustment with this command:\n");
+ PRINTF(" Adjustment value (-1, 1, +1, etc...)\n");
+ PRINTF(" Modified element:\n");
+ PRINTF(" a or y: year\n");
+ PRINTF(" m: month\n");
+ PRINTF(" j or d: day\n");
+ PRINTF(" h: hour\n");
+ PRINTF(" mn: minute\n");
+ PRINTF(" s: second\n");
+ PRINTF(" <example> banadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ LADMIN_LOG("No adjustment isn't an adjustment ('banadd' command).\n");
return 137;
}
if (year > 127 || year < -127)
{
- printf("Please give a correct adjustment for the years (from -127 to 127).\n");
- ladmin_log("Abnormal adjustement for the year ('banadd' command).\n");
+ PRINTF("Please give a correct adjustment for the years (from -127 to 127).\n");
+ LADMIN_LOG("Abnormal adjustement for the year ('banadd' command).\n");
return 137;
}
if (month > 255 || month < -255)
{
- printf("Please give a correct adjustment for the months (from -255 to 255).\n");
- ladmin_log("Abnormal adjustement for the month ('banadd' command).\n");
+ PRINTF("Please give a correct adjustment for the months (from -255 to 255).\n");
+ LADMIN_LOG("Abnormal adjustement for the month ('banadd' command).\n");
return 137;
}
if (day > 32767 || day < -32767)
{
- printf("Please give a correct adjustment for the days (from -32767 to 32767).\n");
- ladmin_log("Abnormal adjustement for the days ('banadd' command).\n");
+ PRINTF("Please give a correct adjustment for the days (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the days ('banadd' command).\n");
return 137;
}
if (hour > 32767 || hour < -32767)
{
- printf("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
- ladmin_log("Abnormal adjustement for the hours ('banadd' command).\n");
+ PRINTF("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the hours ('banadd' command).\n");
return 137;
}
if (minute > 32767 || minute < -32767)
{
- printf("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
- ladmin_log("Abnormal adjustement for the minutes ('banadd' command).\n");
+ PRINTF("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the minutes ('banadd' command).\n");
return 137;
}
if (second > 32767 || second < -32767)
{
- printf("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
- ladmin_log("Abnormal adjustement for the seconds ('banadd' command).\n");
+ PRINTF("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the seconds ('banadd' command).\n");
return 137;
}
- ladmin_log("Request to login-server to modify a ban date/time.\n");
+ LADMIN_LOG("Request to login-server to modify a ban date/time.\n");
WFIFOW(login_fd, 0) = 0x794c;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1162,9 +1144,9 @@ int bansetaccountsub(const char *name, const char *date, const char *time)
sscanf(date, "%d.%d.%d", &year, &month, &day) < 3) ||
sscanf(time, "%d:%d:%d", &hour, &minute, &second) < 3))
{
- printf("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
- printf("You can imput 0 instead of if you use 'banset' command.\n");
- ladmin_log("Invalid format for the date/time ('banset' or 'ban' command).\n");
+ PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
+ PRINTF("You can imput 0 instead of if you use 'banset' command.\n");
+ LADMIN_LOG("Invalid format for the date/time ('banset' or 'ban' command).\n");
return 102;
}
@@ -1184,41 +1166,41 @@ int bansetaccountsub(const char *name, const char *date, const char *time)
}
if (month < 1 || month > 12)
{
- printf("Please give a correct value for the month (from 1 to 12).\n");
- ladmin_log("Invalid month for the date ('banset' or 'ban' command).\n");
+ PRINTF("Please give a correct value for the month (from 1 to 12).\n");
+ LADMIN_LOG("Invalid month for the date ('banset' or 'ban' command).\n");
return 102;
}
month = month - 1;
if (day < 1 || day > 31)
{
- printf("Please give a correct value for the day (from 1 to 31).\n");
- ladmin_log("Invalid day for the date ('banset' or 'ban' command).\n");
+ PRINTF("Please give a correct value for the day (from 1 to 31).\n");
+ LADMIN_LOG("Invalid day for the date ('banset' or 'ban' command).\n");
return 102;
}
if (((month == 3 || month == 5 || month == 8 || month == 10)
&& day > 30) ||(month == 1 && day > 29))
{
- printf("Please give a correct value for a day of this month (%d).\n",
+ PRINTF("Please give a correct value for a day of this month (%d).\n",
month);
- ladmin_log("Invalid day for this month ('banset' or 'ban' command).\n");
+ LADMIN_LOG("Invalid day for this month ('banset' or 'ban' command).\n");
return 102;
}
if (hour < 0 || hour > 23)
{
- printf("Please give a correct value for the hour (from 0 to 23).\n");
- ladmin_log("Invalid hour for the time ('banset' or 'ban' command).\n");
+ PRINTF("Please give a correct value for the hour (from 0 to 23).\n");
+ LADMIN_LOG("Invalid hour for the time ('banset' or 'ban' command).\n");
return 102;
}
if (minute < 0 || minute > 59)
{
- printf("Please give a correct value for the minutes (from 0 to 59).\n");
- ladmin_log("Invalid minute for the time ('banset' or 'ban' command).\n");
+ PRINTF("Please give a correct value for the minutes (from 0 to 59).\n");
+ LADMIN_LOG("Invalid minute for the time ('banset' or 'ban' command).\n");
return 102;
}
if (second < 0 || second > 59)
{
- printf("Please give a correct value for the seconds (from 0 to 59).\n");
- ladmin_log("Invalid second for the time ('banset' or 'ban' command).\n");
+ PRINTF("Please give a correct value for the seconds (from 0 to 59).\n");
+ LADMIN_LOG("Invalid second for the time ('banset' or 'ban' command).\n");
return 102;
}
tmtime->tm_year = year;
@@ -1231,15 +1213,15 @@ int bansetaccountsub(const char *name, const char *date, const char *time)
ban_until_time = timegm(tmtime);
if (ban_until_time == -1)
{
- printf("Invalid date.\n");
- printf("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
- printf("You can imput 0 instead of if you use 'banset' command.\n");
- ladmin_log("Invalid date. ('banset' or 'ban' command).\n");
+ PRINTF("Invalid date.\n");
+ PRINTF("Please input a date and a time (format: yyyy/mm/dd hh:mm:ss).\n");
+ PRINTF("You can imput 0 instead of if you use 'banset' command.\n");
+ LADMIN_LOG("Invalid date. ('banset' or 'ban' command).\n");
return 102;
}
}
- ladmin_log("Request to login-server to set a ban.\n");
+ LADMIN_LOG("Request to login-server to set a ban.\n");
WFIFOW(login_fd, 0) = 0x794a;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1266,13 +1248,13 @@ int banaccount(const char *param)
sscanf(param, "%s %s '%[^']'", date, time, name) < 3 &&
sscanf(param, "%s %s %[^\r\n]", date, time, name) < 3)
{
- printf("Please input an account name, a date and a hour.\n");
- printf("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf(" banset <account_name> 0 (0 = un-banished)\n");
- printf(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
- printf(" unban/unbanish <account name>\n");
- printf(" Default time [hh:mm:ss]: 23:59:59.\n");
- ladmin_log("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
+ PRINTF("Please input an account name, a date and a hour.\n");
+ PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" banset <account_name> 0 (0 = un-banished)\n");
+ PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
+ PRINTF(" unban/unbanish <account name>\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
return 136;
}
@@ -1295,13 +1277,13 @@ int bansetaccount(const char *param)
sscanf(param, "'%[^']' %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
sscanf(param, "%s %s %[^\r\n]", name, date, time) < 2)
{ // if date = 0, time can be void
- printf("Please input an account name, a date and a hour.\n");
- printf("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf(" banset <account_name> 0 (0 = un-banished)\n");
- printf(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
- printf(" unban/unbanish <account name>\n");
- printf(" Default time [hh:mm:ss]: 23:59:59.\n");
- ladmin_log("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
+ PRINTF("Please input an account name, a date and a hour.\n");
+ PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" banset <account_name> 0 (0 = un-banished)\n");
+ PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
+ PRINTF(" unban/unbanish <account name>\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ LADMIN_LOG("Incomplete parameters to set a ban ('banset' or 'ban' command).\n");
return 136;
}
@@ -1326,13 +1308,13 @@ int unbanaccount(const char *param)
sscanf(param, "'%[^']'", name) < 1 &&
sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- printf("Please input an account name.\n");
- printf("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf(" banset <account_name> 0 (0 = un-banished)\n");
- printf(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
- printf(" unban/unbanish <account name>\n");
- printf(" Default time [hh:mm:ss]: 23:59:59.\n");
- ladmin_log("Incomplete parameters to set a ban ('unban' command).\n");
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example>: banset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" banset <account_name> 0 (0 = un-banished)\n");
+ PRINTF(" ban/banish yyyy/mm/dd hh:mm:ss <account name>\n");
+ PRINTF(" unban/unbanish <account name>\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ LADMIN_LOG("Incomplete parameters to set a ban ('unban' command).\n");
return 136;
}
@@ -1355,9 +1337,9 @@ int checkaccount(const char *param)
sscanf(param, "'%[^']' %[^\r\n]", name, password) < 1 && // password can be void
sscanf(param, "%s %[^\r\n]", name, password) < 1)
{ // password can be void
- printf("Please input an account name.\n");
- printf("<example> check testname password\n");
- ladmin_log("Incomplete parameters to check the password of an account ('check' command).\n");
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> check testname password\n");
+ LADMIN_LOG("Incomplete parameters to check the password of an account ('check' command).\n");
return 136;
}
@@ -1374,7 +1356,7 @@ int checkaccount(const char *param)
if (verify_password(password) == 0)
return 131;
- ladmin_log("Request to login-server to check a password.\n");
+ LADMIN_LOG("Request to login-server to check a password.\n");
WFIFOW(login_fd, 0) = 0x793a;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1403,9 +1385,9 @@ int delaccount(const char *param)
sscanf(param, "'%[^']'", name) < 1 &&
sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- printf("Please input an account name.\n");
- printf("<example> del testnametodelete\n");
- ladmin_log("No name given to delete an account ('delete' command).\n");
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> del testnametodelete\n");
+ LADMIN_LOG("No name given to delete an account ('delete' command).\n");
return 136;
}
@@ -1418,7 +1400,7 @@ int delaccount(const char *param)
while (confirm[0] != 'n'
&& confirm[0] != 'y')
{
- printf("\033[1;36m ** Are you really sure to DELETE account [$userid]? (y/n) > \033[0m");
+ PRINTF("\033[1;36m ** Are you really sure to DELETE account [$userid]? (y/n) > \033[0m");
fflush(stdout);
memset(confirm, '\0', sizeof(confirm));
i = 0;
@@ -1428,12 +1410,12 @@ int delaccount(const char *param)
if (confirm[0] == 'n')
{
- printf("Deletion canceled.\n");
- ladmin_log("Deletion canceled by user ('delete' command).\n");
+ PRINTF("Deletion canceled.\n");
+ LADMIN_LOG("Deletion canceled by user ('delete' command).\n");
return 121;
}
- ladmin_log("Request to login-server to delete an acount.\n");
+ LADMIN_LOG("Request to login-server to delete an acount.\n");
WFIFOW(login_fd, 0) = 0x7932;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1458,9 +1440,9 @@ int changeemail(const char *param)
sscanf(param, "'%[^']' %[^\r\n]", name, email) < 2 &&
sscanf(param, "%s %[^\r\n]", name, email) < 2)
{
- printf("Please input an account name and an email.\n");
- printf("<example> email testname newemail\n");
- ladmin_log("Incomplete parameters to change the email of an account ('email' command).\n");
+ PRINTF("Please input an account name and an email.\n");
+ PRINTF("<example> email testname newemail\n");
+ LADMIN_LOG("Incomplete parameters to change the email of an account ('email' command).\n");
return 136;
}
@@ -1471,30 +1453,30 @@ int changeemail(const char *param)
if (strlen(email) < 3)
{
- printf("Email is too short [%s]. Please input a valid e-mail.\n",
+ PRINTF("Email is too short [%s]. Please input a valid e-mail.\n",
email);
- ladmin_log("Email is too short [%s]. Please input a valid e-mail.\n",
+ LADMIN_LOG("Email is too short [%s]. Please input a valid e-mail.\n",
email);
return 109;
}
if (strlen(email) > 39)
{
- printf("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
+ PRINTF("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
email);
- ladmin_log("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
+ LADMIN_LOG("Email is too long [%s]. Please input an e-mail with 39 bytes at the most.\n",
email);
return 109;
}
if (e_mail_check(email) == 0)
{
- printf("Invalid email [%s]. Please input a valid e-mail.\n",
+ PRINTF("Invalid email [%s]. Please input a valid e-mail.\n",
email);
- ladmin_log("Invalid email [%s]. Please input a valid e-mail.\n",
+ LADMIN_LOG("Invalid email [%s]. Please input a valid e-mail.\n",
email);
return 109;
}
- ladmin_log("Request to login-server to change an email.\n");
+ LADMIN_LOG("Request to login-server to change an email.\n");
WFIFOW(login_fd, 0) = 0x7940;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1511,7 +1493,7 @@ int changeemail(const char *param)
static
int getlogincount(void)
{
- ladmin_log("Request to login-server to obtain the # of online players.\n");
+ LADMIN_LOG("Request to login-server to obtain the # of online players.\n");
WFIFOW(login_fd, 0) = 0x7938;
WFIFOSET(login_fd, 2);
@@ -1536,9 +1518,9 @@ int changegmlevel(const char *param)
sscanf(param, "'%[^']' %d", name, &GM_level) < 1 &&
sscanf(param, "%s %d", name, &GM_level) < 1)
{
- printf("Please input an account name and a GM level.\n");
- printf("<example> gm testname 80\n");
- ladmin_log("Incomplete parameters to change the GM level of an account ('gm' command).\n");
+ PRINTF("Please input an account name and a GM level.\n");
+ PRINTF("<example> gm testname 80\n");
+ LADMIN_LOG("Incomplete parameters to change the GM level of an account ('gm' command).\n");
return 136;
}
@@ -1549,14 +1531,14 @@ int changegmlevel(const char *param)
if (GM_level < 0 || GM_level > 99)
{
- printf("Illegal GM level [%d]. Please input a value from 0 to 99.\n",
+ PRINTF("Illegal GM level [%d]. Please input a value from 0 to 99.\n",
GM_level);
- ladmin_log("Illegal GM level [%d]. The value can be from 0 to 99.\n",
+ LADMIN_LOG("Illegal GM level [%d]. The value can be from 0 to 99.\n",
GM_level);
return 103;
}
- ladmin_log("Request to login-server to change a GM level.\n");
+ LADMIN_LOG("Request to login-server to change a GM level.\n");
WFIFOW(login_fd, 0) = 0x793e;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1582,9 +1564,9 @@ int idaccount(const char *param)
sscanf(param, "'%[^']'", name) < 1 &&
sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- printf("Please input an account name.\n");
- printf("<example> id testname\n");
- ladmin_log("No name given to search an account id ('id' command).\n");
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> id testname\n");
+ LADMIN_LOG("No name given to search an account id ('id' command).\n");
return 136;
}
@@ -1593,7 +1575,7 @@ int idaccount(const char *param)
return 102;
}
- ladmin_log("Request to login-server to know an account id.\n");
+ LADMIN_LOG("Request to login-server to know an account id.\n");
WFIFOW(login_fd, 0) = 0x7944;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1611,12 +1593,12 @@ int infoaccount(int account_id)
{
if (account_id < 0)
{
- printf("Please input a positive value for the id.\n");
- ladmin_log("Negative value was given to found the account.\n");
+ PRINTF("Please input a positive value for the id.\n");
+ LADMIN_LOG("Negative value was given to found the account.\n");
return 136;
}
- ladmin_log("Request to login-server to obtain information about an account (by its id).\n");
+ LADMIN_LOG("Request to login-server to obtain information about an account (by its id).\n");
WFIFOW(login_fd, 0) = 0x7954;
WFIFOL(login_fd, 2) = account_id;
@@ -1634,16 +1616,16 @@ int sendbroadcast(short type, const char *message)
{
if (strlen(message) == 0)
{
- printf("Please input a message.\n");
+ PRINTF("Please input a message.\n");
if (type == 0)
{
- printf("<example> kami a message\n");
+ PRINTF("<example> kami a message\n");
}
else
{
- printf("<example> kamib a message\n");
+ PRINTF("<example> kamib a message\n");
}
- ladmin_log("The message is void ('kami(b)' command).\n");
+ LADMIN_LOG("The message is void ('kami(b)' command).\n");
return 136;
}
@@ -1710,7 +1692,7 @@ int listaccount(char *param, int type)
}
}
- ladmin_log("Request to login-server to obtain the list of accounts from %d to %d.\n",
+ LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d.\n",
list_first, list_last);
WFIFOW(login_fd, 0) = 0x7920;
@@ -1737,7 +1719,7 @@ int itemfrob(const char *param)
if (sscanf(param, "%d %d", &source_id, &dest_id) < 2)
{
- printf("You must provide the source and destination item IDs.\n");
+ PRINTF("You must provide the source and destination item IDs.\n");
return 1;
}
@@ -1765,9 +1747,9 @@ int changememo(const char *param)
sscanf(param, "'%[^']' %[^\r\n]", name, memo) < 1 && // memo can be void
sscanf(param, "%s %[^\r\n]", name, memo) < 1)
{ // memo can be void
- printf("Please input an account name and a memo.\n");
- printf("<example> memo testname new memo\n");
- ladmin_log("Incomplete parameters to change the memo of an account ('email' command).\n");
+ PRINTF("Please input an account name and a memo.\n");
+ PRINTF("<example> memo testname new memo\n");
+ LADMIN_LOG("Incomplete parameters to change the memo of an account ('email' command).\n");
return 136;
}
@@ -1778,14 +1760,14 @@ int changememo(const char *param)
if (strlen(memo) > 254)
{
- printf("Memo is too long (%d characters).\n", strlen(memo));
- printf("Please input a memo of 254 bytes at the maximum.\n");
- ladmin_log("Email is too long (%d characters). Please input a memo of 254 bytes at the maximum.\n",
+ PRINTF("Memo is too long (%d characters).\n", strlen(memo));
+ PRINTF("Please input a memo of 254 bytes at the maximum.\n");
+ LADMIN_LOG("Email is too long (%d characters). Please input a memo of 254 bytes at the maximum.\n",
strlen(memo));
return 102;
}
- ladmin_log("Request to login-server to change a memo.\n");
+ LADMIN_LOG("Request to login-server to change a memo.\n");
WFIFOW(login_fd, 0) = 0x7942;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1806,12 +1788,12 @@ int nameaccount(int id)
{
if (id < 0)
{
- printf("Please input a positive value for the id.\n");
- ladmin_log("Negativ id given to search an account name ('name' command).\n");
+ PRINTF("Please input a positive value for the id.\n");
+ LADMIN_LOG("Negativ id given to search an account name ('name' command).\n");
return 136;
}
- ladmin_log("Request to login-server to know an account name.\n");
+ LADMIN_LOG("Request to login-server to know an account name.\n");
WFIFOW(login_fd, 0) = 0x7946;
WFIFOL(login_fd, 2) = id;
@@ -1837,9 +1819,9 @@ int changepasswd(const char *param)
sscanf(param, "'%[^']' %[^\r\n]", name, password) < 1 &&
sscanf(param, "%s %[^\r\n]", name, password) < 1)
{
- printf("Please input an account name.\n");
- printf("<example> passwd testname newpassword\n");
- ladmin_log("Incomplete parameters to change the password of an account ('password' command).\n");
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> passwd testname newpassword\n");
+ LADMIN_LOG("Incomplete parameters to change the password of an account ('password' command).\n");
return 136;
}
@@ -1856,7 +1838,7 @@ int changepasswd(const char *param)
if (verify_password(password) == 0)
return 131;
- ladmin_log("Request to login-server to change a password.\n");
+ LADMIN_LOG("Request to login-server to change a password.\n");
WFIFOW(login_fd, 0) = 0x7934;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1878,9 +1860,9 @@ int reloadGM(char *params)
WFIFOSET(login_fd, 2);
bytes_to_read = 0;
- ladmin_log("Request to reload the GM configuration file sended.\n");
- printf("Request to reload the GM configuration file sended.\n");
- printf("Check the actual GM accounts (after reloading):\n");
+ LADMIN_LOG("Request to reload the GM configuration file sended.\n");
+ PRINTF("Request to reload the GM configuration file sended.\n");
+ PRINTF("Check the actual GM accounts (after reloading):\n");
listaccount(params, 1); // 1: to list only GM
return 180;
@@ -1901,9 +1883,9 @@ int changesex(const char *param)
sscanf(param, "'%[^']' %[^\r\n]", name, sex) < 2 &&
sscanf(param, "%s %[^\r\n]", name, sex) < 2)
{
- printf("Please input an account name and a sex.\n");
- printf("<example> sex testname Male\n");
- ladmin_log("Incomplete parameters to change the sex of an account ('sex' command).\n");
+ PRINTF("Please input an account name and a sex.\n");
+ PRINTF("<example> sex testname Male\n");
+ LADMIN_LOG("Incomplete parameters to change the sex of an account ('sex' command).\n");
return 136;
}
@@ -1915,13 +1897,13 @@ int changesex(const char *param)
sex[0] = toupper(sex[0]);
if (strchr("MF", sex[0]) == NULL)
{
- printf("Illegal gender [%s]. Please input M or F.\n", sex);
- ladmin_log("Illegal gender [%s]. Please input M or F.\n",
+ PRINTF("Illegal gender [%s]. Please input M or F.\n", sex);
+ LADMIN_LOG("Illegal gender [%s]. Please input M or F.\n",
sex);
return 103;
}
- ladmin_log("Request to login-server to change a sex.\n");
+ LADMIN_LOG("Request to login-server to change a sex.\n");
WFIFOW(login_fd, 0) = 0x793c;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -1946,18 +1928,18 @@ int changestatesub(const char *name, int state, const char *error_message7)
if ((state < 0 || state > 9) && state != 100)
{ // Valid values: 0: ok, or value of the 0x006a packet + 1
- printf("Please input one of these states:\n");
- printf(" 0 = Account ok 6 = Your Game's EXE file is not the latest version\n");
- printf(" 1 = Unregistered ID 7 = You are Prohibited to log in until + message\n");
- printf(" 2 = Incorrect Password 8 = Server is jammed due to over populated\n");
- printf(" 3 = This ID is expired 9 = No MSG\n");
- printf(" 4 = Rejected from Server 100 = This ID has been totally erased\n");
- printf(" 5 = You have been blocked by the GM Team\n");
- printf("<examples> state testname 5\n");
- printf(" state testname 7 end of your ban\n");
- printf(" block <account name>\n");
- printf(" unblock <account name>\n");
- ladmin_log("Invalid value for the state of an account ('state', 'block' or 'unblock' command).\n");
+ PRINTF("Please input one of these states:\n");
+ PRINTF(" 0 = Account ok 6 = Your Game's EXE file is not the latest version\n");
+ PRINTF(" 1 = Unregistered ID 7 = You are Prohibited to log in until + message\n");
+ PRINTF(" 2 = Incorrect Password 8 = Server is jammed due to over populated\n");
+ PRINTF(" 3 = This ID is expired 9 = No MSG\n");
+ PRINTF(" 4 = Rejected from Server 100 = This ID has been totally erased\n");
+ PRINTF(" 5 = You have been blocked by the GM Team\n");
+ PRINTF("<examples> state testname 5\n");
+ PRINTF(" state testname 7 end of your ban\n");
+ PRINTF(" block <account name>\n");
+ PRINTF(" unblock <account name>\n");
+ LADMIN_LOG("Invalid value for the state of an account ('state', 'block' or 'unblock' command).\n");
return 151;
}
@@ -1974,19 +1956,19 @@ int changestatesub(const char *name, int state, const char *error_message7)
{
if (strlen(error_message) < 1)
{
- printf("Error message is too short. Please input a message of 1-19 bytes.\n");
- ladmin_log("Error message is too short. Please input a message of 1-19 bytes.\n");
+ PRINTF("Error message is too short. Please input a message of 1-19 bytes.\n");
+ LADMIN_LOG("Error message is too short. Please input a message of 1-19 bytes.\n");
return 102;
}
if (strlen(error_message) > 19)
{
- printf("Error message is too long. Please input a message of 1-19 bytes.\n");
- ladmin_log("Error message is too long. Please input a message of 1-19 bytes.\n");
+ PRINTF("Error message is too long. Please input a message of 1-19 bytes.\n");
+ LADMIN_LOG("Error message is too long. Please input a message of 1-19 bytes.\n");
return 102;
}
}
- ladmin_log("Request to login-server to change a state.\n");
+ LADMIN_LOG("Request to login-server to change a state.\n");
WFIFOW(login_fd, 0) = 0x7936;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -2016,12 +1998,12 @@ int changestate(const char *param)
error_message) < 2
&& sscanf(param, "%s %d %[^\r\n]", name, &state, error_message) < 2)
{
- printf("Please input an account name and a state.\n");
- printf("<examples> state testname 5\n");
- printf(" state testname 7 end of your ban\n");
- printf(" block <account name>\n");
- printf(" unblock <account name>\n");
- ladmin_log("Incomplete parameters to change the state of an account ('state' command).\n");
+ PRINTF("Please input an account name and a state.\n");
+ PRINTF("<examples> state testname 5\n");
+ PRINTF(" state testname 7 end of your ban\n");
+ PRINTF(" block <account name>\n");
+ PRINTF(" unblock <account name>\n");
+ LADMIN_LOG("Incomplete parameters to change the state of an account ('state' command).\n");
return 136;
}
@@ -2043,12 +2025,12 @@ int unblockaccount(const char *param)
sscanf(param, "'%[^']'", name) < 1 &&
sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- printf("Please input an account name.\n");
- printf("<examples> state testname 5\n");
- printf(" state testname 7 end of your ban\n");
- printf(" block <account name>\n");
- printf(" unblock <account name>\n");
- ladmin_log("Incomplete parameters to change the state of an account ('unblock' command).\n");
+ PRINTF("Please input an account name.\n");
+ PRINTF("<examples> state testname 5\n");
+ PRINTF(" state testname 7 end of your ban\n");
+ PRINTF(" block <account name>\n");
+ PRINTF(" unblock <account name>\n");
+ LADMIN_LOG("Incomplete parameters to change the state of an account ('unblock' command).\n");
return 136;
}
@@ -2070,12 +2052,12 @@ int blockaccount(const char *param)
sscanf(param, "'%[^']'", name) < 1 &&
sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- printf("Please input an account name.\n");
- printf("<examples> state testname 5\n");
- printf(" state testname 7 end of your ban\n");
- printf(" block <account name>\n");
- printf(" unblock <account name>\n");
- ladmin_log("Incomplete parameters to change the state of an account ('block' command).\n");
+ PRINTF("Please input an account name.\n");
+ PRINTF("<examples> state testname 5\n");
+ PRINTF(" state testname 7 end of your ban\n");
+ PRINTF(" block <account name>\n");
+ PRINTF(" unblock <account name>\n");
+ LADMIN_LOG("Incomplete parameters to change the state of an account ('block' command).\n");
return 136;
}
@@ -2101,11 +2083,11 @@ int timeaddaccount(const char *param)
sscanf(param, "'%[^']' %[^\r\n]", name, modif) < 2 &&
sscanf(param, "%s %[^\r\n]", name, modif) < 2)
{
- printf("Please input an account name and a modifier.\n");
- printf(" <example>: timeadd testname +1m-2mn1s-6y\n");
- printf(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf(" and 6 years at the same time.\n");
- ladmin_log("Incomplete parameters to modify a limit time ('timeadd' command).\n");
+ PRINTF("Please input an account name and a modifier.\n");
+ PRINTF(" <example>: timeadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ LADMIN_LOG("Incomplete parameters to modify a limit time ('timeadd' command).\n");
return 136;
}
if (verify_accountname(name) == 0)
@@ -2170,69 +2152,69 @@ int timeaddaccount(const char *param)
}
}
- printf(" year: %d\n", year);
- printf(" month: %d\n", month);
- printf(" day: %d\n", day);
- printf(" hour: %d\n", hour);
- printf(" minute: %d\n", minute);
- printf(" second: %d\n", second);
+ PRINTF(" year: %d\n", year);
+ PRINTF(" month: %d\n", month);
+ PRINTF(" day: %d\n", day);
+ PRINTF(" hour: %d\n", hour);
+ PRINTF(" minute: %d\n", minute);
+ PRINTF(" second: %d\n", second);
if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0
&& second == 0)
{
- printf("Please give an adjustment with this command:\n");
- printf(" Adjustment value (-1, 1, +1, etc...)\n");
- printf(" Modified element:\n");
- printf(" a or y: year\n");
- printf(" m: month\n");
- printf(" j or d: day\n");
- printf(" h: hour\n");
- printf(" mn: minute\n");
- printf(" s: second\n");
- printf(" <example> timeadd testname +1m-2mn1s-6y\n");
- printf(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
- printf(" and 6 years at the same time.\n");
- ladmin_log("No adjustment isn't an adjustment ('timeadd' command).\n");
+ PRINTF("Please give an adjustment with this command:\n");
+ PRINTF(" Adjustment value (-1, 1, +1, etc...)\n");
+ PRINTF(" Modified element:\n");
+ PRINTF(" a or y: year\n");
+ PRINTF(" m: month\n");
+ PRINTF(" j or d: day\n");
+ PRINTF(" h: hour\n");
+ PRINTF(" mn: minute\n");
+ PRINTF(" s: second\n");
+ PRINTF(" <example> timeadd testname +1m-2mn1s-6y\n");
+ PRINTF(" this example adds 1 month and 1 second, and substracts 2 minutes\n");
+ PRINTF(" and 6 years at the same time.\n");
+ LADMIN_LOG("No adjustment isn't an adjustment ('timeadd' command).\n");
return 137;
}
if (year > 127 || year < -127)
{
- printf("Please give a correct adjustment for the years (from -127 to 127).\n");
- ladmin_log("Abnormal adjustement for the year ('timeadd' command).\n");
+ PRINTF("Please give a correct adjustment for the years (from -127 to 127).\n");
+ LADMIN_LOG("Abnormal adjustement for the year ('timeadd' command).\n");
return 137;
}
if (month > 255 || month < -255)
{
- printf("Please give a correct adjustment for the months (from -255 to 255).\n");
- ladmin_log("Abnormal adjustement for the month ('timeadd' command).\n");
+ PRINTF("Please give a correct adjustment for the months (from -255 to 255).\n");
+ LADMIN_LOG("Abnormal adjustement for the month ('timeadd' command).\n");
return 137;
}
if (day > 32767 || day < -32767)
{
- printf("Please give a correct adjustment for the days (from -32767 to 32767).\n");
- ladmin_log("Abnormal adjustement for the days ('timeadd' command).\n");
+ PRINTF("Please give a correct adjustment for the days (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the days ('timeadd' command).\n");
return 137;
}
if (hour > 32767 || hour < -32767)
{
- printf("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
- ladmin_log("Abnormal adjustement for the hours ('timeadd' command).\n");
+ PRINTF("Please give a correct adjustment for the hours (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the hours ('timeadd' command).\n");
return 137;
}
if (minute > 32767 || minute < -32767)
{
- printf("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
- ladmin_log("Abnormal adjustement for the minutes ('timeadd' command).\n");
+ PRINTF("Please give a correct adjustment for the minutes (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the minutes ('timeadd' command).\n");
return 137;
}
if (second > 32767 || second < -32767)
{
- printf("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
- ladmin_log("Abnormal adjustement for the seconds ('timeadd' command).\n");
+ PRINTF("Please give a correct adjustment for the seconds (from -32767 to 32767).\n");
+ LADMIN_LOG("Abnormal adjustement for the seconds ('timeadd' command).\n");
return 137;
}
- ladmin_log("Request to login-server to modify a time limit.\n");
+ LADMIN_LOG("Request to login-server to modify a time limit.\n");
WFIFOW(login_fd, 0) = 0x7950;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -2270,11 +2252,11 @@ int timesetaccount(const char *param)
sscanf(param, "'%[^']' %s %[^\r\n]", name, date, time) < 2 && // if date = 0, time can be void
sscanf(param, "%s %s %[^\r\n]", name, date, time) < 2)
{ // if date = 0, time can be void
- printf("Please input an account name, a date and a hour.\n");
- printf("<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
- printf(" timeset <account_name> 0 (0 = unlimited)\n");
- printf(" Default time [hh:mm:ss]: 23:59:59.\n");
- ladmin_log("Incomplete parameters to set a limit time ('timeset' command).\n");
+ PRINTF("Please input an account name, a date and a hour.\n");
+ PRINTF("<example>: timeset <account_name> yyyy/mm/dd [hh:mm:ss]\n");
+ PRINTF(" timeset <account_name> 0 (0 = unlimited)\n");
+ PRINTF(" Default time [hh:mm:ss]: 23:59:59.\n");
+ LADMIN_LOG("Incomplete parameters to set a limit time ('timeset' command).\n");
return 136;
}
if (verify_accountname(name) == 0)
@@ -2292,8 +2274,8 @@ int timesetaccount(const char *param)
sscanf(date, "%d'%d'%d", &year, &month, &day) < 3) ||
sscanf(time, "%d:%d:%d", &hour, &minute, &second) < 3))
{
- printf("Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
- ladmin_log("Invalid format for the date/time ('timeset' command).\n");
+ PRINTF("Please input 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
+ LADMIN_LOG("Invalid format for the date/time ('timeset' command).\n");
return 102;
}
@@ -2313,41 +2295,41 @@ int timesetaccount(const char *param)
}
if (month < 1 || month > 12)
{
- printf("Please give a correct value for the month (from 1 to 12).\n");
- ladmin_log("Invalid month for the date ('timeset' command).\n");
+ PRINTF("Please give a correct value for the month (from 1 to 12).\n");
+ LADMIN_LOG("Invalid month for the date ('timeset' command).\n");
return 102;
}
month = month - 1;
if (day < 1 || day > 31)
{
- printf("Please give a correct value for the day (from 1 to 31).\n");
- ladmin_log("Invalid day for the date ('timeset' command).\n");
+ PRINTF("Please give a correct value for the day (from 1 to 31).\n");
+ LADMIN_LOG("Invalid day for the date ('timeset' command).\n");
return 102;
}
if (((month == 3 || month == 5 || month == 8 || month == 10)
&& day > 30) ||(month == 1 && day > 29))
{
- printf("Please give a correct value for a day of this month (%d).\n",
+ PRINTF("Please give a correct value for a day of this month (%d).\n",
month);
- ladmin_log("Invalid day for this month ('timeset' command).\n");
+ LADMIN_LOG("Invalid day for this month ('timeset' command).\n");
return 102;
}
if (hour < 0 || hour > 23)
{
- printf("Please give a correct value for the hour (from 0 to 23).\n");
- ladmin_log("Invalid hour for the time ('timeset' command).\n");
+ PRINTF("Please give a correct value for the hour (from 0 to 23).\n");
+ LADMIN_LOG("Invalid hour for the time ('timeset' command).\n");
return 102;
}
if (minute < 0 || minute > 59)
{
- printf("Please give a correct value for the minutes (from 0 to 59).\n");
- ladmin_log("Invalid minute for the time ('timeset' command).\n");
+ PRINTF("Please give a correct value for the minutes (from 0 to 59).\n");
+ LADMIN_LOG("Invalid minute for the time ('timeset' command).\n");
return 102;
}
if (second < 0 || second > 59)
{
- printf("Please give a correct value for the seconds (from 0 to 59).\n");
- ladmin_log("Invalid second for the time ('timeset' command).\n");
+ PRINTF("Please give a correct value for the seconds (from 0 to 59).\n");
+ LADMIN_LOG("Invalid second for the time ('timeset' command).\n");
return 102;
}
tmtime->tm_year = year;
@@ -2360,14 +2342,14 @@ int timesetaccount(const char *param)
connect_until_time = timegm(tmtime);
if (connect_until_time == -1)
{
- printf("Invalid date.\n");
- printf("Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
- ladmin_log("Invalid date. ('timeset' command).\n");
+ PRINTF("Invalid date.\n");
+ PRINTF("Please add 0 or a date and a time (format: 0 or yyyy/mm/dd hh:mm:ss).\n");
+ LADMIN_LOG("Invalid date. ('timeset' command).\n");
return 102;
}
}
- ladmin_log("Request to login-server to set a time limit.\n");
+ LADMIN_LOG("Request to login-server to set a time limit.\n");
WFIFOW(login_fd, 0) = 0x7948;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -2393,9 +2375,9 @@ int whoaccount(const char *param)
sscanf(param, "'%[^']'", name) < 1 &&
sscanf(param, "%[^\r\n]", name) < 1) || strlen(name) == 0)
{
- printf("Please input an account name.\n");
- printf("<example> who testname\n");
- ladmin_log("No name was given to found the account.\n");
+ PRINTF("Please input an account name.\n");
+ PRINTF("<example> who testname\n");
+ LADMIN_LOG("No name was given to found the account.\n");
return 136;
}
if (verify_accountname(name) == 0)
@@ -2403,7 +2385,7 @@ int whoaccount(const char *param)
return 102;
}
- ladmin_log("Request to login-server to obtain information about an account (by its name).\n");
+ LADMIN_LOG("Request to login-server to obtain information about an account (by its name).\n");
WFIFOW(login_fd, 0) = 0x7952;
memcpy(WFIFOP(login_fd, 2), name, 24);
@@ -2419,7 +2401,7 @@ int whoaccount(const char *param)
static
int checkloginversion(void)
{
- ladmin_log("Request to login-server to obtain its version.\n");
+ LADMIN_LOG("Request to login-server to obtain its version.\n");
WFIFOW(login_fd, 0) = 0x7530;
WFIFOSET(login_fd, 2);
@@ -2444,7 +2426,7 @@ int prompt(void)
while (bytes_to_read == 0)
{
// for help with the console colors look here:
- // http://www.edoceo.com/liberum/?doc=printf-with-color
+ // http://www.edoceo.com/liberum/?doc=PRINTF-with-color
// some code explanation (used here):
// \033[2J : clear screen and go up/left (0, 0 position)
// \033[K : clear line from actual position to end of the line
@@ -2542,12 +2524,12 @@ int prompt(void)
if (strlen(parameters) == 0)
{
- ladmin_log("Command: '%s' (without parameters)\n",
+ LADMIN_LOG("Command: '%s' (without parameters)\n",
command);
}
else
{
- ladmin_log("Command: '%s', parameters: '%s'\n",
+ LADMIN_LOG("Command: '%s', parameters: '%s'\n",
command, parameters);
}
@@ -2695,14 +2677,14 @@ int prompt(void)
strcmp(command, "exit") == 0 ||
strcmp(command, "end") == 0)
{
- printf("Bye.\n");
+ PRINTF("Bye.\n");
exit(0);
// unknown command
}
else
{
- printf("Unknown command [%s].\n", buf);
- ladmin_log("Unknown command [%s].\n", buf);
+ PRINTF("Unknown command [%s].\n", buf);
+ LADMIN_LOG("Unknown command [%s].\n", buf);
}
}
@@ -2717,16 +2699,16 @@ void parse_fromlogin(int fd)
{
if (session[fd]->eof)
{
- printf("Impossible to have a connection with the login-server [%s:%d] !\n",
+ PRINTF("Impossible to have a connection with the login-server [%s:%d] !\n",
loginserverip, loginserverport);
- ladmin_log("Impossible to have a connection with the login-server [%s:%d] !\n",
+ LADMIN_LOG("Impossible to have a connection with the login-server [%s:%d] !\n",
loginserverip, loginserverport);
close(fd);
delete_session(fd);
exit(0);
}
-// printf("parse_fromlogin : %d %d %d\n", fd, RFIFOREST(fd), RFIFOW(fd,0));
+// PRINTF("parse_fromlogin : %d %d %d\n", fd, RFIFOREST(fd), RFIFOW(fd,0));
while (RFIFOREST(fd) >= 2)
{
@@ -2737,20 +2719,20 @@ void parse_fromlogin(int fd)
return;
if (RFIFOB(fd, 2) != 0)
{
- printf("Error at login:\n");
- printf(" - incorrect password,\n");
- printf(" - administration system not activated, or\n");
- printf(" - unauthorised IP.\n");
- ladmin_log("Error at login: incorrect password, administration system not activated, or unauthorised IP.\n");
+ PRINTF("Error at login:\n");
+ PRINTF(" - incorrect password,\n");
+ PRINTF(" - administration system not activated, or\n");
+ PRINTF(" - unauthorised IP.\n");
+ LADMIN_LOG("Error at login: incorrect password, administration system not activated, or unauthorised IP.\n");
session[fd]->eof = 1;
//bytes_to_read = 1; // not stop at prompt
}
else
{
Iprintf("Established connection.\n");
- ladmin_log("Established connection.\n");
+ LADMIN_LOG("Established connection.\n");
Iprintf("Reading of the version of the login-server...\n");
- ladmin_log("Reading of the version of the login-server...\n");
+ LADMIN_LOG("Reading of the version of the login-server...\n");
//bytes_to_read = 1; // unchanged
checkloginversion();
}
@@ -2782,9 +2764,9 @@ void parse_fromlogin(int fd)
memcpy(WFIFOP(login_fd, 4), md5bin, 16);
WFIFOSET(login_fd, 20);
Iprintf("Receiving of the MD5 key.\n");
- ladmin_log("Receiving of the MD5 key.\n");
+ LADMIN_LOG("Receiving of the MD5 key.\n");
Iprintf("Sending of the encrypted password...\n");
- ladmin_log("Sending of the encrypted password...\n");
+ LADMIN_LOG("Sending of the encrypted password...\n");
}
bytes_to_read = 1;
RFIFOSKIP(fd, RFIFOW(fd, 2));
@@ -2829,7 +2811,7 @@ void parse_fromlogin(int fd)
return;
if (RFIFOW(fd, 2) < 5)
{
- ladmin_log(" Receiving of a void accounts list.\n");
+ LADMIN_LOG(" Receiving of a void accounts list.\n");
if (list_count == 0)
{
Iprintf("No account found.\n");
@@ -2845,7 +2827,7 @@ void parse_fromlogin(int fd)
else
{
int i;
- ladmin_log(" Receiving of a accounts list.\n");
+ LADMIN_LOG(" Receiving of a accounts list.\n");
for (i = 4; i < RFIFOW(fd, 2); i += 38)
{
int j;
@@ -2865,63 +2847,63 @@ void parse_fromlogin(int fd)
||(list_type == 3 && RFIFOL(fd, i + 34) != 0)
||(list_type == 4 && RFIFOL(fd, i + 34) == 0))
{
- printf("%10d ", RFIFOL(fd, i));
+ PRINTF("%10d ", RFIFOL(fd, i));
if (RFIFOB(fd, i + 4) == 0)
- printf(" ");
+ PRINTF(" ");
else
- printf("%2d ", (int) RFIFOB(fd, i + 4));
- printf("%-24s", userid);
+ PRINTF("%2d ", (int) RFIFOB(fd, i + 4));
+ PRINTF("%-24s", userid);
if (RFIFOB(fd, i + 29) == 0)
- printf("%-5s ", "Femal");
+ PRINTF("%-5s ", "Femal");
else if (RFIFOB(fd, i + 29) == 1)
- printf("%-5s ", "Male");
+ PRINTF("%-5s ", "Male");
else
- printf("%-5s ", "Servr");
- printf("%6d ", RFIFOL(fd, i + 30));
+ PRINTF("%-5s ", "Servr");
+ PRINTF("%6d ", RFIFOL(fd, i + 30));
switch (RFIFOL(fd, i + 34))
{
case 0:
- printf("%-27s\n", "Account OK");
+ PRINTF("%-27s\n", "Account OK");
break;
case 1:
- printf("%-27s\n", "Unregistered ID");
+ PRINTF("%-27s\n", "Unregistered ID");
break;
case 2:
- printf("%-27s\n", "Incorrect Password");
+ PRINTF("%-27s\n", "Incorrect Password");
break;
case 3:
- printf("%-27s\n", "This ID is expired");
+ PRINTF("%-27s\n", "This ID is expired");
break;
case 4:
- printf("%-27s\n",
+ PRINTF("%-27s\n",
"Rejected from Server");
break;
case 5:
- printf("%-27s\n", "Blocked by the GM Team"); // You have been blocked by the GM Team
+ PRINTF("%-27s\n", "Blocked by the GM Team"); // You have been blocked by the GM Team
break;
case 6:
- printf("%-27s\n", "Your EXE file is too old"); // Your Game's EXE file is not the latest version
+ PRINTF("%-27s\n", "Your EXE file is too old"); // Your Game's EXE file is not the latest version
break;
case 7:
- printf("%-27s\n", "Banishement or");
- printf(" Prohibited to login until...\n"); // You are Prohibited to log in until %s
+ PRINTF("%-27s\n", "Banishement or");
+ PRINTF(" Prohibited to login until...\n"); // You are Prohibited to log in until %s
break;
case 8:
- printf("%-27s\n",
+ PRINTF("%-27s\n",
"Server is over populated");
break;
case 9:
- printf("%-27s\n", "No MSG");
+ PRINTF("%-27s\n", "No MSG");
break;
default: // 100
- printf("%-27s\n", "This ID is totally erased"); // This ID has been totally erased
+ PRINTF("%-27s\n", "This ID is totally erased"); // This ID has been totally erased
break;
}
list_count++;
}
}
// asking of the following acounts
- ladmin_log("Request to login-server to obtain the list of accounts from %d to %d (complement).\n",
+ LADMIN_LOG("Request to login-server to obtain the list of accounts from %d to %d (complement).\n",
list_first, list_last);
WFIFOW(login_fd, 0) = 0x7920;
WFIFOL(login_fd, 2) = list_first;
@@ -2937,16 +2919,16 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] creation failed. Same account already exists.\n",
+ PRINTF("Account [%s] creation failed. Same account already exists.\n",
RFIFOP(fd, 6));
- ladmin_log("Account [%s] creation failed. Same account already exists.\n",
+ LADMIN_LOG("Account [%s] creation failed. Same account already exists.\n",
RFIFOP(fd, 6));
}
else
{
- printf("Account [%s] is successfully created [id: %d].\n",
+ PRINTF("Account [%s] is successfully created [id: %d].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Account [%s] is successfully created [id: %d].\n",
+ LADMIN_LOG("Account [%s] is successfully created [id: %d].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
bytes_to_read = 0;
@@ -2958,16 +2940,16 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] deletion failed. Account doesn't exist.\n",
+ PRINTF("Account [%s] deletion failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Account [%s] deletion failed. Account doesn't exist.\n",
+ LADMIN_LOG("Account [%s] deletion failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
}
else
{
- printf("Account [%s][id: %d] is successfully DELETED.\n",
+ PRINTF("Account [%s][id: %d] is successfully DELETED.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Account [%s][id: %d] is successfully DELETED.\n",
+ LADMIN_LOG("Account [%s][id: %d] is successfully DELETED.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
bytes_to_read = 0;
@@ -2979,18 +2961,18 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] password changing failed.\n",
+ PRINTF("Account [%s] password changing failed.\n",
RFIFOP(fd, 6));
- printf("Account [%s] doesn't exist.\n",
+ PRINTF("Account [%s] doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Account password changing failed. The compte [%s] doesn't exist.\n",
+ LADMIN_LOG("Account password changing failed. The compte [%s] doesn't exist.\n",
RFIFOP(fd, 6));
}
else
{
- printf("Account [%s][id: %d] password successfully changed.\n",
+ PRINTF("Account [%s][id: %d] password successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Account [%s][id: %d] password successfully changed.\n",
+ LADMIN_LOG("Account [%s][id: %d] password successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
bytes_to_read = 0;
@@ -3002,60 +2984,55 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] state changing failed. Account doesn't exist.\n",
+ PRINTF("Account [%s] state changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Account [%s] state changing failed. Account doesn't exist.\n",
+ LADMIN_LOG("Account [%s] state changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
}
else
{
- char tmpstr[256];
- sprintf(tmpstr,
+ std::string tmpstr = STRPRINTF(
"Account [%s] state successfully changed in [",
RFIFOP(fd, 6));
switch (RFIFOL(fd, 30))
{
case 0:
- strcat(tmpstr, "0: Account OK");
+ tmpstr += "0: Account OK";
break;
case 1:
- strcat(tmpstr, "1: Unregistered ID");
+ tmpstr += "1: Unregistered ID";
break;
case 2:
- strcat(tmpstr, "2: Incorrect Password");
+ tmpstr += "2: Incorrect Password";
break;
case 3:
- strcat(tmpstr, "3: This ID is expired");
+ tmpstr += "3: This ID is expired";
break;
case 4:
- strcat(tmpstr, "4: Rejected from Server");
+ tmpstr += "4: Rejected from Server";
break;
case 5:
- strcat(tmpstr,
- "5: You have been blocked by the GM Team");
+ tmpstr += "5: You have been blocked by the GM Team";
break;
case 6:
- strcat(tmpstr,
- "6: [Your Game's EXE file is not the latest version");
+ tmpstr += "6: [Your Game's EXE file is not the latest version";
break;
case 7:
- strcat(tmpstr,
- "7: You are Prohibited to log in until...");
+ tmpstr += "7: You are Prohibited to log in until...";
break;
case 8:
- strcat(tmpstr,
- "8: Server is jammed due to over populated");
+ tmpstr += "8: Server is jammed due to over populated";
break;
case 9:
- strcat(tmpstr, "9: No MSG");
+ tmpstr += "9: No MSG";
break;
default: // 100
- strcat(tmpstr, "100: This ID is totally erased");
+ tmpstr += "100: This ID is totally erased";
break;
}
- strcat(tmpstr, "]");
- printf("%s\n", tmpstr);
- ladmin_log("%s%s", tmpstr, "\n");
+ tmpstr += ']';
+ PRINTF("%s\n", tmpstr);
+ LADMIN_LOG("%s\n", tmpstr);
}
bytes_to_read = 0;
RFIFOSKIP(fd, 34);
@@ -3068,21 +3045,21 @@ void parse_fromlogin(int fd)
// Get length of the received packet
int i;
char name[20];
- ladmin_log(" Receiving of the number of online players.\n");
+ LADMIN_LOG(" Receiving of the number of online players.\n");
// Read information of the servers
if (RFIFOW(fd, 2) < 5)
{
- printf(" No server is connected to the login-server.\n");
+ PRINTF(" No server is connected to the login-server.\n");
}
else
{
- printf(" Number of online players (server: number).\n");
+ PRINTF(" Number of online players (server: number).\n");
// Displaying of result
for (i = 4; i < RFIFOW(fd, 2); i += 32)
{
memcpy(name, RFIFOP(fd, i + 6), sizeof(name));
name[sizeof(name) - 1] = '\0';
- printf(" %-20s : %5d\n", name,
+ PRINTF(" %-20s : %5d\n", name,
RFIFOW(fd, i + 26));
}
}
@@ -3096,16 +3073,16 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("The account [%s] doesn't exist or the password is incorrect.\n",
+ PRINTF("The account [%s] doesn't exist or the password is incorrect.\n",
RFIFOP(fd, 6));
- ladmin_log("The account [%s] doesn't exist or the password is incorrect.\n",
+ LADMIN_LOG("The account [%s] doesn't exist or the password is incorrect.\n",
RFIFOP(fd, 6));
}
else
{
- printf("The proposed password is correct for the account [%s][id: %d].\n",
+ PRINTF("The proposed password is correct for the account [%s][id: %d].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("The proposed password is correct for the account [%s][id: %d].\n",
+ LADMIN_LOG("The proposed password is correct for the account [%s][id: %d].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
bytes_to_read = 0;
@@ -3117,18 +3094,18 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] sex changing failed.\n",
+ PRINTF("Account [%s] sex changing failed.\n",
RFIFOP(fd, 6));
- printf("Account [%s] doesn't exist or the sex is already the good sex.\n",
+ PRINTF("Account [%s] doesn't exist or the sex is already the good sex.\n",
RFIFOP(fd, 6));
- ladmin_log("Account sex changing failed. The compte [%s] doesn't exist or the sex is already the good sex.\n",
+ LADMIN_LOG("Account sex changing failed. The compte [%s] doesn't exist or the sex is already the good sex.\n",
RFIFOP(fd, 6));
}
else
{
- printf("Account [%s][id: %d] sex successfully changed.\n",
+ PRINTF("Account [%s][id: %d] sex successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Account [%s][id: %d] sex successfully changed.\n",
+ LADMIN_LOG("Account [%s][id: %d] sex successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
bytes_to_read = 0;
@@ -3140,19 +3117,19 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] GM level changing failed.\n",
+ PRINTF("Account [%s] GM level changing failed.\n",
RFIFOP(fd, 6));
- printf("Account [%s] doesn't exist, the GM level is already the good GM level\n",
+ PRINTF("Account [%s] doesn't exist, the GM level is already the good GM level\n",
RFIFOP(fd, 6));
- printf("or it's impossible to modify the GM accounts file.\n");
- ladmin_log("Account GM level changing failed. The compte [%s] doesn't exist, the GM level is already the good sex or it's impossible to modify the GM accounts file.\n",
+ PRINTF("or it's impossible to modify the GM accounts file.\n");
+ LADMIN_LOG("Account GM level changing failed. The compte [%s] doesn't exist, the GM level is already the good sex or it's impossible to modify the GM accounts file.\n",
RFIFOP(fd, 6));
}
else
{
- printf("Account [%s][id: %d] GM level successfully changed.\n",
+ PRINTF("Account [%s][id: %d] GM level successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Account [%s][id: %d] GM level successfully changed.\n",
+ LADMIN_LOG("Account [%s][id: %d] GM level successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
bytes_to_read = 0;
@@ -3164,18 +3141,18 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] e-mail changing failed.\n",
+ PRINTF("Account [%s] e-mail changing failed.\n",
RFIFOP(fd, 6));
- printf("Account [%s] doesn't exist.\n",
+ PRINTF("Account [%s] doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Account e-mail changing failed. The compte [%s] doesn't exist.\n",
+ LADMIN_LOG("Account e-mail changing failed. The compte [%s] doesn't exist.\n",
RFIFOP(fd, 6));
}
else
{
- printf("Account [%s][id: %d] e-mail successfully changed.\n",
+ PRINTF("Account [%s][id: %d] e-mail successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Account [%s][id: %d] e-mail successfully changed.\n",
+ LADMIN_LOG("Account [%s][id: %d] e-mail successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
bytes_to_read = 0;
@@ -3187,16 +3164,16 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] memo changing failed. Account doesn't exist.\n",
+ PRINTF("Account [%s] memo changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Account [%s] memo changing failed. Account doesn't exist.\n",
+ LADMIN_LOG("Account [%s] memo changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
}
else
{
- printf("Account [%s][id: %d] memo successfully changed.\n",
+ PRINTF("Account [%s][id: %d] memo successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Account [%s][id: %d] memo successfully changed.\n",
+ LADMIN_LOG("Account [%s][id: %d] memo successfully changed.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
bytes_to_read = 0;
@@ -3208,16 +3185,16 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Unable to find the account [%s] id. Account doesn't exist.\n",
+ PRINTF("Unable to find the account [%s] id. Account doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Unable to find the account [%s] id. Account doesn't exist.\n",
+ LADMIN_LOG("Unable to find the account [%s] id. Account doesn't exist.\n",
RFIFOP(fd, 6));
}
else
{
- printf("The account [%s] have the id: %d.\n",
+ PRINTF("The account [%s] have the id: %d.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("The account [%s] have the id: %d.\n",
+ LADMIN_LOG("The account [%s] have the id: %d.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
bytes_to_read = 0;
@@ -3229,16 +3206,16 @@ void parse_fromlogin(int fd)
return;
if (strcmp((const char *)RFIFOP(fd, 6), "") == 0)
{
- printf("Unable to find the account [%d] name. Account doesn't exist.\n",
+ PRINTF("Unable to find the account [%d] name. Account doesn't exist.\n",
RFIFOL(fd, 2));
- ladmin_log("Unable to find the account [%d] name. Account doesn't exist.\n",
+ LADMIN_LOG("Unable to find the account [%d] name. Account doesn't exist.\n",
RFIFOL(fd, 2));
}
else
{
- printf("The account [id: %d] have the name: %s.\n",
+ PRINTF("The account [id: %d] have the name: %s.\n",
RFIFOL(fd, 2), RFIFOP(fd, 6));
- ladmin_log("The account [id: %d] have the name: %s.\n",
+ LADMIN_LOG("The account [id: %d] have the name: %s.\n",
RFIFOL(fd, 2), RFIFOP(fd, 6));
}
bytes_to_read = 0;
@@ -3250,9 +3227,9 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] validity limit changing failed. Account doesn't exist.\n",
+ PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Account [%s] validity limit changing failed. Account doesn't exist.\n",
+ LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
}
else
@@ -3260,19 +3237,18 @@ void parse_fromlogin(int fd)
time_t timestamp = RFIFOL(fd, 30);
if (timestamp == 0)
{
- printf("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n",
+ PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n",
+ LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to [unlimited].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
else
{
- char tmpstr[128];
- strftime(tmpstr, 24, date_format,
- localtime(&timestamp));
- printf("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n",
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ PRINTF("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2), tmpstr);
- ladmin_log("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n",
+ LADMIN_LOG("Validity Limit of the account [%s][id: %d] successfully changed to be until %s.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2),
tmpstr);
}
@@ -3286,9 +3262,9 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
+ PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
+ LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
}
else
@@ -3296,19 +3272,18 @@ void parse_fromlogin(int fd)
time_t timestamp = RFIFOL(fd, 30);
if (timestamp == 0)
{
- printf("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
+ PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
+ LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
else
{
- char tmpstr[128];
- strftime(tmpstr, 24, date_format,
- localtime(&timestamp));
- printf("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2), tmpstr);
- ladmin_log("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
+ LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2),
tmpstr);
}
@@ -3322,9 +3297,9 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
+ PRINTF("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
+ LADMIN_LOG("Account [%s] final date of banishment changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
}
else
@@ -3332,19 +3307,18 @@ void parse_fromlogin(int fd)
time_t timestamp = RFIFOL(fd, 30);
if (timestamp == 0)
{
- printf("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
+ PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- ladmin_log("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
+ LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to [unbanished].\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
else
{
- char tmpstr[128];
- strftime(tmpstr, 24, date_format,
- localtime(&timestamp));
- printf("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ PRINTF("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2), tmpstr);
- ladmin_log("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
+ LADMIN_LOG("Final date of banishment of the account [%s][id: %d] successfully changed to be until %s.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2),
tmpstr);
}
@@ -3358,13 +3332,13 @@ void parse_fromlogin(int fd)
return;
if (RFIFOW(fd, 2) == (unsigned short) -1)
{
- printf("Message sending failed. No online char-server.\n");
- ladmin_log("Message sending failed. No online char-server.\n");
+ PRINTF("Message sending failed. No online char-server.\n");
+ LADMIN_LOG("Message sending failed. No online char-server.\n");
}
else
{
- printf("Message successfully sended to login-server.\n");
- ladmin_log("Message successfully sended to login-server.\n");
+ PRINTF("Message successfully sended to login-server.\n");
+ LADMIN_LOG("Message successfully sended to login-server.\n");
}
bytes_to_read = 0;
RFIFOSKIP(fd, 4);
@@ -3375,9 +3349,9 @@ void parse_fromlogin(int fd)
return;
if (RFIFOL(fd, 2) == -1)
{
- printf("Account [%s] validity limit changing failed. Account doesn't exist.\n",
+ PRINTF("Account [%s] validity limit changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
- ladmin_log("Account [%s] validity limit changing failed. Account doesn't exist.\n",
+ LADMIN_LOG("Account [%s] validity limit changing failed. Account doesn't exist.\n",
RFIFOP(fd, 6));
}
else
@@ -3385,21 +3359,20 @@ void parse_fromlogin(int fd)
time_t timestamp = RFIFOL(fd, 30);
if (timestamp == 0)
{
- printf("Validity limit of the account [%s][id: %d] unchanged.\n",
+ PRINTF("Validity limit of the account [%s][id: %d] unchanged.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
- printf("The account have an unlimited validity limit or\n");
- printf("the changing is impossible with the proposed adjustments.\n");
- ladmin_log("Validity limit of the account [%s][id: %d] unchanged. The account have an unlimited validity limit or the changing is impossible with the proposed adjustments.\n",
+ PRINTF("The account have an unlimited validity limit or\n");
+ PRINTF("the changing is impossible with the proposed adjustments.\n");
+ LADMIN_LOG("Validity limit of the account [%s][id: %d] unchanged. The account have an unlimited validity limit or the changing is impossible with the proposed adjustments.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2));
}
else
{
- char tmpstr[128];
- strftime(tmpstr, 24, date_format,
- localtime(&timestamp));
- printf("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n",
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ PRINTF("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2), tmpstr);
- ladmin_log("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n",
+ LADMIN_LOG("Validity limit of the account [%s][id: %d] successfully changed to be until %s.\n",
RFIFOP(fd, 6), RFIFOL(fd, 2),
tmpstr);
}
@@ -3434,109 +3407,107 @@ void parse_fromlogin(int fd)
strncpy(memo, (const char *)RFIFOP(fd, 150), RFIFOW(fd, 148));
if (RFIFOL(fd, 2) == -1)
{
- printf("Unabled to find the account [%s]. Account doesn't exist.\n",
+ PRINTF("Unabled to find the account [%s]. Account doesn't exist.\n",
parameters);
- ladmin_log("Unabled to find the account [%s]. Account doesn't exist.\n",
+ LADMIN_LOG("Unabled to find the account [%s]. Account doesn't exist.\n",
parameters);
}
else if (strlen(userid) == 0)
{
- printf("Unabled to find the account [id: %s]. Account doesn't exist.\n",
+ PRINTF("Unabled to find the account [id: %s]. Account doesn't exist.\n",
parameters);
- ladmin_log("Unabled to find the account [id: %s]. Account doesn't exist.\n",
+ LADMIN_LOG("Unabled to find the account [id: %s]. Account doesn't exist.\n",
parameters);
}
else
{
- ladmin_log("Receiving information about an account.\n");
- printf("The account is set with:\n");
+ LADMIN_LOG("Receiving information about an account.\n");
+ PRINTF("The account is set with:\n");
if (RFIFOB(fd, 6) == 0)
{
- printf(" Id: %d (non-GM)\n", RFIFOL(fd, 2));
+ PRINTF(" Id: %d (non-GM)\n", RFIFOL(fd, 2));
}
else
{
- printf(" Id: %d (GM level %d)\n",
+ PRINTF(" Id: %d (GM level %d)\n",
RFIFOL(fd, 2), (int) RFIFOB(fd, 6));
}
- printf(" Name: '%s'\n", userid);
+ PRINTF(" Name: '%s'\n", userid);
if (RFIFOB(fd, 31) == 0)
- printf(" Sex: Female\n");
+ PRINTF(" Sex: Female\n");
else if (RFIFOB(fd, 31) == 1)
- printf(" Sex: Male\n");
+ PRINTF(" Sex: Male\n");
else
- printf(" Sex: Server\n");
- printf(" E-mail: %s\n", email);
+ PRINTF(" Sex: Server\n");
+ PRINTF(" E-mail: %s\n", email);
switch (RFIFOL(fd, 36))
{
case 0:
- printf(" Statut: 0 [Account OK]\n");
+ PRINTF(" Statut: 0 [Account OK]\n");
break;
case 1:
- printf(" Statut: 1 [Unregistered ID]\n");
+ PRINTF(" Statut: 1 [Unregistered ID]\n");
break;
case 2:
- printf(" Statut: 2 [Incorrect Password]\n");
+ PRINTF(" Statut: 2 [Incorrect Password]\n");
break;
case 3:
- printf(" Statut: 3 [This ID is expired]\n");
+ PRINTF(" Statut: 3 [This ID is expired]\n");
break;
case 4:
- printf(" Statut: 4 [Rejected from Server]\n");
+ PRINTF(" Statut: 4 [Rejected from Server]\n");
break;
case 5:
- printf(" Statut: 5 [You have been blocked by the GM Team]\n");
+ PRINTF(" Statut: 5 [You have been blocked by the GM Team]\n");
break;
case 6:
- printf(" Statut: 6 [Your Game's EXE file is not the latest version]\n");
+ PRINTF(" Statut: 6 [Your Game's EXE file is not the latest version]\n");
break;
case 7:
- printf(" Statut: 7 [You are Prohibited to log in until %s]\n",
+ PRINTF(" Statut: 7 [You are Prohibited to log in until %s]\n",
error_message);
break;
case 8:
- printf(" Statut: 8 [Server is jammed due to over populated]\n");
+ PRINTF(" Statut: 8 [Server is jammed due to over populated]\n");
break;
case 9:
- printf(" Statut: 9 [No MSG]\n");
+ PRINTF(" Statut: 9 [No MSG]\n");
break;
default: // 100
- printf(" Statut: %d [This ID is totally erased]\n",
+ PRINTF(" Statut: %d [This ID is totally erased]\n",
RFIFOL(fd, 36));
break;
}
if (ban_until_time == 0)
{
- printf(" Banishment: not banished.\n");
+ PRINTF(" Banishment: not banished.\n");
}
else
{
- char tmpstr[128];
- strftime(tmpstr, 24, date_format,
- localtime(&ban_until_time));
- printf(" Banishment: until %s.\n", tmpstr);
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &ban_until_time);
+ PRINTF(" Banishment: until %s.\n", tmpstr);
}
if (RFIFOL(fd, 32) > 1)
- printf(" Count: %d connections.\n",
+ PRINTF(" Count: %d connections.\n",
RFIFOL(fd, 32));
else
- printf(" Count: %d connection.\n",
+ PRINTF(" Count: %d connection.\n",
RFIFOL(fd, 32));
- printf(" Last connection at: %s (ip: %s)\n",
+ PRINTF(" Last connection at: %s (ip: %s)\n",
lastlogin, last_ip);
if (connect_until_time == 0)
{
- printf(" Validity limit: unlimited.\n");
+ PRINTF(" Validity limit: unlimited.\n");
}
else
{
- char tmpstr[128];
- strftime(tmpstr, 24, date_format,
- localtime(&connect_until_time));
- printf(" Validity limit: until %s.\n",
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &connect_until_time);
+ PRINTF(" Validity limit: until %s.\n",
tmpstr);
}
- printf(" Memo: '%s'\n", memo);
+ PRINTF(" Memo: '%s'\n", memo);
}
}
bytes_to_read = 0;
@@ -3544,8 +3515,8 @@ void parse_fromlogin(int fd)
break;
default:
- printf("Remote administration has been disconnected (unknown packet).\n");
- ladmin_log("'End of connection, unknown packet.\n");
+ PRINTF("Remote administration has been disconnected (unknown packet).\n");
+ LADMIN_LOG("'End of connection, unknown packet.\n");
session[fd]->eof = 1;
return;
}
@@ -3562,7 +3533,7 @@ static
int Connect_login_server(void)
{
Iprintf("Attempt to connect to login-server...\n");
- ladmin_log("Attempt to connect to login-server...\n");
+ LADMIN_LOG("Attempt to connect to login-server...\n");
if ((login_fd = make_connection(login_ip, loginserverport)) < 0)
return 0;
@@ -3576,7 +3547,7 @@ int Connect_login_server(void)
bytes_to_read = 1;
Iprintf("Sending of the password...\n");
- ladmin_log("Sending of the password...\n");
+ LADMIN_LOG("Sending of the password...\n");
}
else
{
@@ -3584,7 +3555,7 @@ int Connect_login_server(void)
WFIFOSET(login_fd, 2);
bytes_to_read = 1;
Iprintf("Request about the MD5 key...\n");
- ladmin_log("Request about the MD5 key...\n");
+ LADMIN_LOG("Request about the MD5 key...\n");
}
return 0;
@@ -3596,96 +3567,68 @@ int Connect_login_server(void)
static
int ladmin_config_read(const char *cfgName)
{
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
- fp = fopen_(cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- printf("\033[0mConfiguration file (%s) not found.\n", cfgName);
+ PRINTF("\033[0mConfiguration file (%s) not found.\n", cfgName);
return 1;
}
Iprintf("\033[0m---Start reading of Ladmin configuration file (%s)\n",
cfgName);
- while (fgets(line, sizeof(line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- line[sizeof(line) - 1] = '\0';
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2)
+ if (w1 == "login_ip")
{
- remove_control_chars(w1);
- remove_control_chars(w2);
-
- if (strcasecmp(w1, "login_ip") == 0)
+ struct hostent *h = gethostbyname(w2.c_str());
+ if (h != NULL)
{
- struct hostent *h = gethostbyname(w2);
- if (h != NULL)
- {
- Iprintf("Login server IP address: %s -> %d.%d.%d.%d\n",
- w2, (unsigned char) h->h_addr[0],
+ Iprintf("Login server IP address: %s -> %d.%d.%d.%d\n",
+ w2, (unsigned char) h->h_addr[0],
+ (unsigned char) h->h_addr[1],
+ (unsigned char) h->h_addr[2],
+ (unsigned char) h->h_addr[3]);
+ sprintf(loginserverip, "%d.%d.%d.%d",
+ (unsigned char) h->h_addr[0],
(unsigned char) h->h_addr[1],
(unsigned char) h->h_addr[2],
(unsigned char) h->h_addr[3]);
- sprintf(loginserverip, "%d.%d.%d.%d",
- (unsigned char) h->h_addr[0],
- (unsigned char) h->h_addr[1],
- (unsigned char) h->h_addr[2],
- (unsigned char) h->h_addr[3]);
- }
- else
- memcpy(loginserverip, w2, 16);
- }
- else if (strcasecmp(w1, "login_port") == 0)
- {
- loginserverport = atoi(w2);
- }
- else if (strcasecmp(w1, "admin_pass") == 0)
- {
- strncpy(loginserveradminpassword, w2,
- sizeof(loginserveradminpassword));
- loginserveradminpassword[sizeof(loginserveradminpassword) -
- 1] = '\0';
- }
- else if (strcasecmp(w1, "passenc") == 0)
- {
- passenc = atoi(w2);
- if (passenc < 0 || passenc > 2)
- passenc = 0;
- }
- else if (strcasecmp(w1, "ladmin_log_filename") == 0)
- {
- strncpy(ladmin_log_filename, w2,
- sizeof(ladmin_log_filename));
- ladmin_log_filename[sizeof(ladmin_log_filename) - 1] = '\0';
- }
- else if (strcasecmp(w1, "date_format") == 0)
- { // note: never have more than 19 char for the date!
- switch (atoi(w2))
- {
- case 0:
- strcpy(date_format, "%d-%m-%Y %H:%M:%S"); // 31-12-2004 23:59:59
- break;
- case 1:
- strcpy(date_format, "%m-%d-%Y %H:%M:%S"); // 12-31-2004 23:59:59
- break;
- case 2:
- strcpy(date_format, "%Y-%d-%m %H:%M:%S"); // 2004-31-12 23:59:59
- break;
- case 3:
- strcpy(date_format, "%Y-%m-%d %H:%M:%S"); // 2004-12-31 23:59:59
- break;
- }
- }
- else if (strcasecmp(w1, "import") == 0)
- {
- ladmin_config_read(w2);
}
+ else
+ strzcpy(loginserverip, w2.c_str(), 16);
+ }
+ else if (w1 == "login_port")
+ {
+ loginserverport = atoi(w2.c_str());
+ }
+ else if (w1 == "admin_pass")
+ {
+ strzcpy(loginserveradminpassword, w2.c_str(), sizeof(loginserveradminpassword));
+ }
+ else if (w1 == "passenc")
+ {
+ passenc = atoi(w2.c_str());
+ if (passenc < 0 || passenc > 2)
+ passenc = 0;
+ }
+ else if (w1 == "ladmin_log_filename")
+ {
+ strzcpy(ladmin_log_filename, w2.c_str(), sizeof(ladmin_log_filename));
+ }
+ else if (w1 == "import")
+ {
+ ladmin_config_read(w2.c_str());
+ }
+ else
+ {
+ PRINTF("WARNING: unknown ladmin config key: %s", w1);
}
}
- fclose_(fp);
login_ip = inet_addr(loginserverip);
@@ -3705,7 +3648,7 @@ void term_func(void)
delete_session(login_fd);
Iprintf("\033[0m----End of Ladmin (normal end with closing of all files).\n");
- ladmin_log("----End of Ladmin (normal end with closing of all files).\n");
+ LADMIN_LOG("----End of Ladmin (normal end with closing of all files).\n");
already_exit_function = 1;
}
@@ -3720,8 +3663,8 @@ int do_init(int argc, char **argv)
// read ladmin configuration
ladmin_config_read((argc > 1) ? argv[1] : LADMIN_CONF_NAME);
- ladmin_log("");
- ladmin_log("Configuration file readed.\n");
+ LADMIN_LOG("");
+ LADMIN_LOG("Configuration file readed.\n");
srand(time(NULL));
@@ -3731,7 +3674,7 @@ int do_init(int argc, char **argv)
Iprintf("(for eAthena version %d.%d.%d.)\n", ATHENA_MAJOR_VERSION,
ATHENA_MINOR_VERSION, ATHENA_REVISION);
- ladmin_log("Ladmin is ready.\n");
+ LADMIN_LOG("Ladmin is ready.\n");
Iprintf("Ladmin is \033[1;32mready\033[0m.\n\n");
Connect_login_server();
diff --git a/src/login/login.cpp b/src/login/login.cpp
index 8537024..ceb216b 100644
--- a/src/login/login.cpp
+++ b/src/login/login.cpp
@@ -14,14 +14,18 @@
#include <unistd.h>
#include <csignal>
-#include <cstdarg> // exception to "no va_list" rule
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
+#include <algorithm>
+#include <fstream>
+
#include "../common/core.hpp"
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
+#include "../common/extract.hpp"
#include "../common/lock.hpp"
#include "../common/md5calc.hpp"
#include "../common/mmo.hpp"
@@ -49,7 +53,6 @@ char GM_account_filename[1024] = "conf/GM_account.txt";
char login_log_filename[1024] = "log/login.log";
char login_log_unknown_packets_filename[1024] =
"log/login_unknown_packets.log";
-char date_format[32] = "%Y-%m-%d %H:%M:%S";
int save_unknown_packets = 0;
long creation_time_GM_account_file;
int gm_account_filename_check_timer = 15; // Timer to check if GM_account file has been changed and reload GM account automaticaly (in seconds; default: 15)
@@ -136,34 +139,16 @@ pid_t pid = 0; // For forked DB writes
//------------------------------
// Writing function of logs file
//------------------------------
-static __attribute__((format(printf, 1, 2)))
-int login_log(const char *fmt, ...)
+#define LOGIN_LOG(fmt, args...) \
+ login_log(static_cast<const std::string&>(STRPRINTF(fmt, ## args)))
+static
+void login_log(const_string line)
{
- FILE *logfp;
- va_list ap;
- struct timeval tv;
- char tmpstr[2048];
-
- va_start(ap, fmt);
-
- logfp = fopen_(login_log_filename, "a");
- if (logfp)
- {
- if (fmt[0] == '\0') // jump a line if no message
- fprintf(logfp, "\n");
- else
- {
- gettimeofday(&tv, NULL);
- strftime(tmpstr, 24, date_format, gmtime(&(tv.tv_sec)));
- sprintf(tmpstr + strlen(tmpstr), ".%03d: %s",
- (int) tv.tv_usec / 1000, fmt);
- vfprintf(logfp, tmpstr, ap);
- }
- fclose_(logfp);
- }
-
- va_end(ap);
- return 0;
+ FILE *logfp = fopen_(login_log_filename, "a");
+ if (!logfp)
+ return;
+ log_with_timestamp(logfp, line);
+ fclose_(logfp);
}
//----------------------------------------------------------------------
@@ -203,12 +188,12 @@ int read_gm_account(void)
if ((fp = fopen_(GM_account_filename, "r")) == NULL)
{
- printf("read_gm_account: GM accounts file [%s] not found.\n",
+ PRINTF("read_gm_account: GM accounts file [%s] not found.\n",
GM_account_filename);
- printf(" Actually, there is no GM accounts on the server.\n");
- login_log("read_gm_account: GM accounts file [%s] not found.\n",
+ PRINTF(" Actually, there is no GM accounts on the server.\n");
+ LOGIN_LOG("read_gm_account: GM accounts file [%s] not found.\n",
GM_account_filename);
- login_log(" Actually, there is no GM accounts on the server.\n");
+ LOGIN_LOG(" Actually, there is no GM accounts on the server.\n");
return 1;
}
// limited to 4000, because we send information to char-servers (more than 4000 GM accounts???)
@@ -221,39 +206,39 @@ int read_gm_account(void)
CREATE(p, struct gm_account, 1);
if (sscanf(line, "%d %d", &p->account_id, &p->level) != 2
&& sscanf(line, "%d: %d", &p->account_id, &p->level) != 2)
- printf("read_gm_account: file [%s], invalid 'id_acount level' format.\n",
+ PRINTF("read_gm_account: file [%s], invalid 'id_acount level' format.\n",
GM_account_filename);
else if (p->level <= 0)
- printf("read_gm_account: file [%s] %dth account (invalid level [0 or negative]: %d).\n",
+ PRINTF("read_gm_account: file [%s] %dth account (invalid level [0 or negative]: %d).\n",
GM_account_filename, c + 1, p->level);
else
{
if (p->level > 99)
{
- printf("read_gm_account: file [%s] %dth account (invalid level, but corrected: %d->99).\n",
+ PRINTF("read_gm_account: file [%s] %dth account (invalid level, but corrected: %d->99).\n",
GM_account_filename, c + 1, p->level);
p->level = 99;
}
if ((GM_level = isGM(p->account_id)) > 0)
{ // if it's not a new account
if (GM_level == p->level)
- printf("read_gm_account: GM account %d defined twice (same level: %d).\n",
+ PRINTF("read_gm_account: GM account %d defined twice (same level: %d).\n",
p->account_id, p->level);
else
- printf("read_gm_account: GM account %d defined twice (levels: %d and %d).\n",
+ PRINTF("read_gm_account: GM account %d defined twice (levels: %d and %d).\n",
p->account_id, GM_level, p->level);
}
if (GM_level != p->level)
{ // if new account or new level
numdb_insert(gm_account_db, p->account_id, p);
- //printf("GM account:%d, level: %d->%d\n", p->account_id, GM_level, p->level);
+ //PRINTF("GM account:%d, level: %d->%d\n", p->account_id, GM_level, p->level);
if (GM_level == 0)
{ // if new account
c++;
if (c >= 4000)
{
- printf("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n");
- login_log("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n");
+ PRINTF("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n");
+ LOGIN_LOG("***WARNING: 4000 GM accounts found. Next GM accounts are not readed.\n");
}
}
}
@@ -261,9 +246,9 @@ int read_gm_account(void)
}
fclose_(fp);
- printf("read_gm_account: file '%s' readed (%d GM accounts found).\n",
+ PRINTF("read_gm_account: file '%s' readed (%d GM accounts found).\n",
GM_account_filename, c);
- login_log("read_gm_account: file '%s' readed (%d GM accounts found).\n",
+ LOGIN_LOG("read_gm_account: file '%s' readed (%d GM accounts found).\n",
GM_account_filename, c);
return 0;
@@ -301,11 +286,11 @@ int check_ipmask(struct in_addr ip, const char *str)
}
else
{
- printf("check_ipmask: invalid mask [%s].\n", str);
+ PRINTF("check_ipmask: invalid mask [%s].\n", str);
return 0;
}
-// printf("Tested IP: %08x, network: %08x, network mask: %08x\n",
+// PRINTF("Tested IP: %08x, network: %08x, network mask: %08x\n",
// (unsigned int)ntohl(ip), (unsigned int)ntohl(ip2), (unsigned int)mask);
return ((ntohl(ip.s_addr) & mask) == (ntohl(ip2) & mask));
}
@@ -438,27 +423,105 @@ int search_account_index(char *account_name)
// Create a string to save the account in the account file
//--------------------------------------------------------
static
-int mmo_auth_tostr(char *str, struct auth_dat *p)
+std::string mmo_auth_tostr(struct auth_dat *p)
{
- int i;
- char *str_p = str;
-
- str_p += sprintf(str_p, "%d\t%s\t%s\t%s\t%c\t%d\t%d\t"
- "%s\t%s\t%ld\t%s\t%s\t%ld\t",
- p->account_id, p->userid, p->pass, p->lastlogin,
- (p->sex == 2) ? 'S' : (p->sex ? 'M' : 'F'),
- p->logincount, p->state,
- p->email, p->error_message,
- p->connect_until_time, p->last_ip, p->memo,
- p->ban_until_time);
-
- for (i = 0; i < p->account_reg2_num; i++)
+ std::string str = STRPRINTF(
+ "%d\t"
+ "%s\t"
+ "%s\t"
+ "%s\t"
+ "%c\t"
+ "%d\t"
+ "%d\t"
+ "%s\t"
+ "%s\t"
+ "%ld\t"
+ "%s\t"
+ "%s\t"
+ "%ld\t",
+ p->account_id,
+ p->userid,
+ p->pass,
+ p->lastlogin,
+ (p->sex == 2) ? 'S' : (p->sex ? 'M' : 'F'),
+ p->logincount,
+ p->state,
+ p->email,
+ p->error_message,
+ p->connect_until_time,
+ p->last_ip,
+ p->memo,
+ p->ban_until_time);
+
+ for (int i = 0; i < p->account_reg2_num; i++)
if (p->account_reg2[i].str[0])
- str_p +=
- sprintf(str_p, "%s,%d ", p->account_reg2[i].str,
- p->account_reg2[i].value);
+ str += STRPRINTF("%s,%d ",
+ p->account_reg2[i].str, p->account_reg2[i].value);
- return 0;
+ return str;
+}
+
+static
+bool extract(const_string line, struct auth_dat *ad)
+{
+ std::vector<struct global_reg> vars;
+ const_string sex = nullptr; // really only 1 char
+ if (!extract(line,
+ record<'\t'>(
+ &ad->account_id,
+ &ad->userid,
+ &ad->pass,
+ &ad->lastlogin,
+ &sex,
+ &ad->logincount,
+ &ad->state,
+ &ad->email,
+ &ad->error_message,
+ &ad->connect_until_time,
+ &ad->last_ip,
+ &ad->memo,
+ &ad->ban_until_time,
+ vrec<' '>(&vars))))
+ return false;
+ if (ad->account_id > END_ACCOUNT_NUM)
+ return false;
+ for (int j = 0; j < auth_num; j++)
+ {
+ if (auth_dat[j].account_id == ad->account_id)
+ return false;
+ else if (strcmp(auth_dat[j].userid, ad->userid) == 0)
+ return false;
+ }
+ // If a password is not encrypted, we encrypt it now.
+ // A password beginning with ! and - in the memo field is our magic
+ if (ad->pass[0] != '!' && ad->memo[0] == '-') {
+ strcpy(ad->pass, MD5_saltcrypt(ad->pass, make_salt()));
+ ad->memo[0] = '!';
+ }
+
+ if (sex.size() != 1)
+ return false;
+ switch(sex.front())
+ {
+ case 'S': case 's': ad->sex = 2; break;
+ case 'M': case 'm': ad->sex = 1; break;
+ case 'F': case 'f': ad->sex = 0; break;
+ default: return false;
+ }
+
+ if (e_mail_check(ad->email) == 0)
+ strzcpy(ad->email, "a@a.com", 40);
+
+ if (ad->error_message[0] == '\0' || ad->state != 7)
+ // 7, because state is packet 0x006a value + 1
+ strzcpy(ad->error_message, "-", 20);
+
+ if (vars.size() > ACCOUNT_REG2_NUM)
+ return false;
+ std::copy(vars.begin(), vars.end(), ad->account_reg2);
+ ad->account_reg2_num = vars.size();
+
+ return true;
}
//---------------------------------
@@ -467,407 +530,74 @@ int mmo_auth_tostr(char *str, struct auth_dat *p)
static
int mmo_auth_init(void)
{
- FILE *fp;
- int account_id, logincount, state, n, i, j, v;
- char line[2048], *p, userid[2048], pass[2048], lastlogin[2048], sex,
- email[2048], error_message[2048], last_ip[2048], memo[2048];
- time_t ban_until_time;
- time_t connect_until_time;
- char str[2048];
int GM_count = 0;
int server_count = 0;
CREATE(auth_dat, struct auth_dat, 256);
auth_max = 256;
- fp = fopen_(account_filename, "r");
- if (fp == NULL)
+ std::ifstream in(account_filename);
+ if (!in.is_open())
{
// no account file -> no account -> no login, including char-server (ERROR)
- printf("\033[1;31mmmo_auth_init: Accounts file [%s] not found.\033[0m\n",
+ PRINTF("\033[1;31mmmo_auth_init: Accounts file [%s] not found.\033[0m\n",
account_filename);
return 0;
}
- while (fgets(line, sizeof(line) - 1, fp) != NULL)
+ std::string line;
+ while (std::getline(in, line))
{
if (line[0] == '/' && line[1] == '/')
continue;
- line[sizeof(line) - 1] = '\0';
- p = line;
-
- // database version reading (v2)
- if (((i = sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t"
- "%[^\t]\t%[^\t]\t%ld\t%[^\t]\t%[^\t]\t%ld%n",
- &account_id, userid, pass, lastlogin, &sex,
- &logincount, &state, email, error_message,
- &connect_until_time, last_ip, memo, &ban_until_time,
- &n)) == 13 && line[n] == '\t')
- ||
- ((i =
- sscanf(line,
- "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t"
- "%[^\t]\t%[^\t]\t%ld\t%[^\t]\t%[^\t]%n", &account_id,
- userid, pass, lastlogin, &sex, &logincount, &state,
- email, error_message, &connect_until_time, last_ip,
- memo, &n)) == 12 && line[n] == '\t'))
+ if (line.back() == '\r')
{
- n = n + 1;
-
- // Some checks
- if (account_id > END_ACCOUNT_NUM)
- {
- printf("\033[1;31mmmo_auth_init: ******Error: an account has an id higher than %d\n",
- END_ACCOUNT_NUM);
- printf(" account id #%d -> account not read (saved in log file).\033[0m\n",
- account_id);
- login_log("mmmo_auth_init: ******Error: an account has an id higher than %d.\n",
- END_ACCOUNT_NUM);
- login_log(" account id #%d -> account not read (saved in next line):\n",
- account_id);
- login_log("%s", line);
- continue;
- }
- userid[23] = '\0';
- remove_control_chars(userid);
- for (j = 0; j < auth_num; j++)
- {
- if (auth_dat[j].account_id == account_id)
- {
- printf("\033[1;31mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- printf(" account id #%d -> new account not read (saved in log file).\033[0m\n",
- account_id);
- login_log("mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- login_log(" account id #%d -> new account not read (saved in next line):\n",
- account_id);
- login_log("%s", line);
- break;
- }
- else if (strcmp(auth_dat[j].userid, userid) == 0)
- {
- printf("\033[1;31mmmo_auth_init: ******Error: account name already exists.\n");
- printf(" account name '%s' -> new account not read.\n", userid); // 2 lines, account name can be long.
- printf(" Account saved in log file.\033[0m\n");
- login_log("mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- login_log(" account id #%d -> new account not read (saved in next line):\n",
- account_id);
- login_log("%s", line);
- break;
- }
- }
- if (j != auth_num)
- continue;
-
- if (auth_num >= auth_max)
- {
- auth_max += 256;
- RECREATE(auth_dat, struct auth_dat, auth_max);
- }
-
- memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat));
-
- auth_dat[auth_num].account_id = account_id;
-
- strncpy(auth_dat[auth_num].userid, userid, 24);
-
- memo[254] = '\0';
- remove_control_chars(memo);
- strncpy(auth_dat[auth_num].memo, memo, 255);
-
- pass[39] = '\0';
- remove_control_chars(pass);
- // If a password is not encrypted, we encrypt it now.
- // A password beginning with ! and - in the memo field is our magic
- if (pass[0] != '!' && memo[0] == '-') {
- strcpy(auth_dat[auth_num].pass, MD5_saltcrypt(pass, make_salt()));
- auth_dat[auth_num].memo[0] = '!';
- printf("encrypting pass: %s %s\n", pass, auth_dat[auth_num].pass);
- }
- else
- strcpy(auth_dat[auth_num].pass, pass);
-
- lastlogin[23] = '\0';
- remove_control_chars(lastlogin);
- strncpy(auth_dat[auth_num].lastlogin, lastlogin, 24);
-
- auth_dat[auth_num].sex = (sex == 'S'
- || sex == 's') ? 2 : (sex == 'M'
- || sex == 'm');
-
- if (logincount >= 0)
- auth_dat[auth_num].logincount = logincount;
- else
- auth_dat[auth_num].logincount = 0;
-
- if (state > 255)
- auth_dat[auth_num].state = 100;
- else if (state < 0)
- auth_dat[auth_num].state = 0;
- else
- auth_dat[auth_num].state = state;
-
- if (e_mail_check(email) == 0)
- {
- printf("Account %s (%d): invalid e-mail (replaced par a@a.com).\n",
- auth_dat[auth_num].userid,
- auth_dat[auth_num].account_id);
- strncpy(auth_dat[auth_num].email, "a@a.com", 40);
- }
- else
- {
- remove_control_chars(email);
- strncpy(auth_dat[auth_num].email, email, 40);
- }
-
- error_message[19] = '\0';
- remove_control_chars(error_message);
- if (error_message[0] == '\0' || state != 7)
- { // 7, because state is packet 0x006a value + 1
- strncpy(auth_dat[auth_num].error_message, "-", 20);
- }
- else
- {
- strncpy(auth_dat[auth_num].error_message, error_message, 20);
- }
-
- if (i == 13)
- auth_dat[auth_num].ban_until_time = ban_until_time;
- else
- auth_dat[auth_num].ban_until_time = 0;
-
- auth_dat[auth_num].connect_until_time = connect_until_time;
-
- last_ip[15] = '\0';
- remove_control_chars(last_ip);
- strncpy(auth_dat[auth_num].last_ip, last_ip, 16);
-
- for (j = 0; j < ACCOUNT_REG2_NUM; j++)
- {
- p += n;
- if (sscanf(p, "%[^\t,],%d %n", str, &v, &n) != 2)
- {
- // We must check if a str is void. If it's, we can continue to read other REG2.
- // Account line will have something like: str2,9 ,9 str3,1 (here, ,9 is not good)
- if (p[0] == ',' && sscanf(p, ",%d %n", &v, &n) == 1)
- {
- j--;
- continue;
- }
- else
- break;
- }
- str[31] = '\0';
- remove_control_chars(str);
- strncpy(auth_dat[auth_num].account_reg2[j].str, str, 32);
- auth_dat[auth_num].account_reg2[j].value = v;
- }
- auth_dat[auth_num].account_reg2_num = j;
-
- if (isGM(account_id) > 0)
- GM_count++;
- if (auth_dat[auth_num].sex == 2)
- server_count++;
-
- auth_num++;
- if (account_id >= account_id_count)
- account_id_count = account_id + 1;
-
- // Old athena database version reading (v1)
+#ifdef ANNOYING_GCC46_WORKAROUNDS
+# warning " and this one!"
+ line.resize(line.size() - 1);
+#else
+ line.pop_back();
+#endif
}
- else if ((i =
- sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t%n",
- &account_id, userid, pass, lastlogin, &sex,
- &logincount, &state, &n)) >= 5)
- {
- if (account_id > END_ACCOUNT_NUM)
- {
- printf("\033[1;31mmmo_auth_init: ******Error: an account has an id higher than %d\n",
- END_ACCOUNT_NUM);
- printf(" account id #%d -> account not read (saved in log file).\033[0m\n",
- account_id);
- login_log("mmmo_auth_init: ******Error: an account has an id higher than %d.\n",
- END_ACCOUNT_NUM);
- login_log(" account id #%d -> account not read (saved in next line):\n",
- account_id);
- login_log("%s", line);
- continue;
- }
- userid[23] = '\0';
- remove_control_chars(userid);
- for (j = 0; j < auth_num; j++)
- {
- if (auth_dat[j].account_id == account_id)
- {
- printf("\033[1;31mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- printf(" account id #%d -> new account not read (saved in log file).\033[0m\n",
- account_id);
- login_log("mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- login_log(" account id #%d -> new account not read (saved in next line):\n",
- account_id);
- login_log("%s", line);
- break;
- }
- else if (strcmp(auth_dat[j].userid, userid) == 0)
- {
- printf("\033[1;31mmmo_auth_init: ******Error: account name already exists.\n");
- printf(" account name '%s' -> new account not read.\n", userid); // 2 lines, account name can be long.
- printf(" Account saved in log file.\033[0m\n");
- login_log("mmmo_auth_init: ******Error: an account has an identical id to another.\n");
- login_log(" account id #%d -> new account not read (saved in next line):\n",
- account_id);
- login_log("%s", line);
- break;
- }
- }
- if (j != auth_num)
- continue;
-
- if (auth_num >= auth_max)
- {
- auth_max += 256;
- RECREATE(auth_dat, struct auth_dat, auth_max);
- }
-
- memset(&auth_dat[auth_num], '\0', sizeof(struct auth_dat));
-
- auth_dat[auth_num].account_id = account_id;
-
- strncpy(auth_dat[auth_num].userid, userid, 24);
-
- lastlogin[23] = '\0';
- remove_control_chars(lastlogin);
- strncpy(auth_dat[auth_num].lastlogin, lastlogin, 24);
-
- auth_dat[auth_num].sex = (sex == 'S'
- || sex == 's') ? 2 : (sex == 'M'
- || sex == 'm');
-
- if (i >= 6)
- {
- if (logincount >= 0)
- auth_dat[auth_num].logincount = logincount;
- else
- auth_dat[auth_num].logincount = 0;
- }
- else
- auth_dat[auth_num].logincount = 0;
+ if (std::find_if(line.begin(), line.end(),
+ [](unsigned char c) { return c < ' ' && c != '\t'; }
+ ) != line.end())
+ continue;
- if (i >= 7)
- {
- if (state > 255)
- auth_dat[auth_num].state = 100;
- else if (state < 0)
- auth_dat[auth_num].state = 0;
- else
- auth_dat[auth_num].state = state;
- }
+ struct auth_dat ad {};
+ if (!extract(line, &ad))
+ {
+ int i = 0;
+ if (SSCANF(line, "%d\t%%newid%%\n%n", &ad.account_id, &i) == 1
+ && i > 0 && ad.account_id > account_id_count)
+ account_id_count = ad.account_id;
else
- auth_dat[auth_num].state = 0;
-
- // Initialization of new data
- strncpy(auth_dat[auth_num].email, "a@a.com", 40);
- strncpy(auth_dat[auth_num].error_message, "-", 20);
- auth_dat[auth_num].ban_until_time = 0;
- auth_dat[auth_num].connect_until_time = 0;
- strncpy(auth_dat[auth_num].last_ip, "-", 16);
- strncpy(auth_dat[auth_num].memo, "!", 255);
+ LOGIN_LOG("Account skipped\n%s", line);
+ continue;
+ }
- for (j = 0; j < ACCOUNT_REG2_NUM; j++)
- {
- p += n;
- if (sscanf(p, "%[^\t,],%d %n", str, &v, &n) != 2)
- {
- // We must check if a str is void. If it's, we can continue to read other REG2.
- // Account line will have something like: str2,9 ,9 str3,1 (here, ,9 is not good)
- if (p[0] == ',' && sscanf(p, ",%d %n", &v, &n) == 1)
- {
- j--;
- continue;
- }
- else
- break;
- }
- str[31] = '\0';
- remove_control_chars(str);
- strncpy(auth_dat[auth_num].account_reg2[j].str, str, 32);
- auth_dat[auth_num].account_reg2[j].value = v;
- }
- auth_dat[auth_num].account_reg2_num = j;
+ if (auth_num >= auth_max)
+ {
+ auth_max += 256;
+ RECREATE(auth_dat, struct auth_dat, auth_max);
+ }
- if (isGM(account_id) > 0)
- GM_count++;
- if (auth_dat[auth_num].sex == 2)
- server_count++;
+ auth_dat[auth_num] = ad;
- auth_num++;
- if (account_id >= account_id_count)
- account_id_count = account_id + 1;
+ if (isGM(ad.account_id) > 0)
+ GM_count++;
+ if (auth_dat[auth_num].sex == 2)
+ server_count++;
- }
- else
- {
- i = 0;
- if (sscanf(line, "%d\t%%newid%%\n%n", &account_id, &i) == 1 &&
- i > 0 && account_id > account_id_count)
- account_id_count = account_id;
- }
+ auth_num++;
+ if (ad.account_id >= account_id_count)
+ account_id_count = ad.account_id + 1;
}
- fclose_(fp);
- if (auth_num == 0)
- {
- printf("mmo_auth_init: No account found in %s.\n", account_filename);
- sprintf(line, "No account found in %s.", account_filename);
- }
- else
- {
- if (auth_num == 1)
- {
- printf("mmo_auth_init: 1 account read in %s,\n",
- account_filename);
- sprintf(line, "1 account read in %s,", account_filename);
- }
- else
- {
- printf("mmo_auth_init: %d accounts read in %s,\n", auth_num,
- account_filename);
- sprintf(line, "%d accounts read in %s,", auth_num,
- account_filename);
- }
- if (GM_count == 0)
- {
- printf(" of which is no GM account, and ");
- sprintf(str, "%s of which is no GM account and", line);
- }
- else if (GM_count == 1)
- {
- printf(" of which is 1 GM account, and ");
- sprintf(str, "%s of which is 1 GM account and", line);
- }
- else
- {
- printf(" of which is %d GM accounts, and ",
- GM_count);
- sprintf(str, "%s of which is %d GM accounts and", line,
- GM_count);
- }
- if (server_count == 0)
- {
- printf("no server account ('S').\n");
- sprintf(line, "%s no server account ('S').", str);
- }
- else if (server_count == 1)
- {
- printf("1 server account ('S').\n");
- sprintf(line, "%s 1 server account ('S').", str);
- }
- else
- {
- printf("%d server accounts ('S').\n", server_count);
- sprintf(line, "%s %d server accounts ('S').", str, server_count);
- }
- }
- login_log("%s\n", line);
+ std::string str = STRPRINTF("%s has %d accounts (%d GMs, %d servers)\n",
+ account_filename, auth_num, GM_count, server_count);
+ PRINTF("%s: %s\n", __FUNCTION__, str);
+ LOGIN_LOG("%s\n", line);
return 0;
}
@@ -882,7 +612,6 @@ void mmo_auth_sync(void)
FILE *fp;
int i, j, k, lock;
int id[auth_num];
- char line[65536];
// Sorting before save
for (i = 0; i < auth_num; i++)
@@ -904,26 +633,26 @@ void mmo_auth_sync(void)
fp = lock_fopen(account_filename, &lock);
if (fp == NULL)
return;
- fprintf(fp,
+ FPRINTF(fp,
"// Accounts file: here are saved all information about the accounts.\n");
- fprintf(fp,
+ FPRINTF(fp,
"// Structure: ID, account name, password, last login time, sex, # of logins, state, email, error message for state 7, validity time, last (accepted) login ip, memo field, ban timestamp, repeated(register text, register value)\n");
- fprintf(fp, "// Some explanations:\n");
- fprintf(fp,
+ FPRINTF(fp, "// Some explanations:\n");
+ FPRINTF(fp,
"// account name : between 4 to 23 char for a normal account (standard client can't send less than 4 char).\n");
- fprintf(fp, "// account password: between 4 to 23 char\n");
- fprintf(fp,
+ FPRINTF(fp, "// account password: between 4 to 23 char\n");
+ FPRINTF(fp,
"// sex : M or F for normal accounts, S for server accounts\n");
- fprintf(fp,
+ FPRINTF(fp,
"// state : 0: account is ok, 1 to 256: error code of packet 0x006a + 1\n");
- fprintf(fp,
+ FPRINTF(fp,
"// email : between 3 to 39 char (a@a.com is like no email)\n");
- fprintf(fp,
+ FPRINTF(fp,
"// error message : text for the state 7: 'Your are Prohibited to login until <text>'. Max 19 char\n");
- fprintf(fp,
+ FPRINTF(fp,
"// valitidy time : 0: unlimited account, <other value>: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n");
- fprintf(fp, "// memo field : max 254 char\n");
- fprintf(fp,
+ FPRINTF(fp, "// memo field : max 254 char\n");
+ FPRINTF(fp,
"// ban time : 0: no ban, <other value>: banned until the date: date calculated by addition of 1/1/1970 + value (number of seconds since the 1/1/1970)\n");
for (i = 0; i < auth_num; i++)
{
@@ -931,10 +660,10 @@ void mmo_auth_sync(void)
if (auth_dat[k].account_id < 0)
continue;
- mmo_auth_tostr(line, &auth_dat[k]);
- fprintf(fp, "%s\n", line);
+ std::string line = mmo_auth_tostr(&auth_dat[k]);
+ FPRINTF(fp, "%s\n", line);
}
- fprintf(fp, "%d\t%%newid%%\n", account_id_count);
+ FPRINTF(fp, "%d\t%%newid%%\n", account_id_count);
lock_fclose(fp, account_filename, &lock);
@@ -1127,8 +856,6 @@ static
int mmo_auth(struct mmo_account *account, int fd)
{
int i;
- struct timeval tv;
- char tmpstr[256];
int len, newaccount = 0;
#ifdef PASSWDENC
char md5str[64], md5bin[32];
@@ -1169,14 +896,14 @@ int mmo_auth(struct mmo_account *account, int fd)
int encpasswdok = 0;
if (newaccount)
{
- login_log("Attempt of creation of an already existant account (account: %s_%c, ip: %s)\n",
+ LOGIN_LOG("Attempt of creation of an already existant account (account: %s_%c, ip: %s)\n",
account->userid, account->userid[len + 1], ip);
return 9; // 9 = Account already exists
}
if ((!pass_ok(account->passwd, auth_dat[i].pass)) && !encpasswdok)
{
if (account->passwdenc == 0)
- login_log("Invalid password (account: %s, ip: %s)\n",
+ LOGIN_LOG("Invalid password (account: %s, ip: %s)\n",
account->userid, ip);
return 1; // 1 = Incorrect Password
@@ -1184,7 +911,7 @@ int mmo_auth(struct mmo_account *account, int fd)
if (auth_dat[i].state)
{
- login_log("Connection refused (account: %s, state: %d, ip: %s)\n",
+ LOGIN_LOG("Connection refused (account: %s, state: %d, ip: %s)\n",
account->userid, auth_dat[i].state,
ip);
switch (auth_dat[i].state)
@@ -1208,19 +935,21 @@ int mmo_auth(struct mmo_account *account, int fd)
}
if (auth_dat[i].ban_until_time != 0)
- { // if account is banned
- strftime(tmpstr, 20, date_format,
- gmtime(&auth_dat[i].ban_until_time));
- tmpstr[19] = '\0';
+ {
+ // if account is banned
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &auth_dat[i].ban_until_time);
if (auth_dat[i].ban_until_time > time(NULL))
- { // always banned
- login_log("Connection refused (account: %s, banned until %s, ip: %s)\n",
+ {
+ // always banned
+ LOGIN_LOG("Connection refused (account: %s, banned until %s, ip: %s)\n",
account->userid, tmpstr, ip);
return 6; // 6 = Your are Prohibited to log in until %s
}
else
- { // ban is finished
- login_log("End of ban (account: %s, previously banned until %s -> not more banned, ip: %s)\n",
+ {
+ // ban is finished
+ LOGIN_LOG("End of ban (account: %s, previously banned until %s -> not more banned, ip: %s)\n",
account->userid, tmpstr, ip);
auth_dat[i].ban_until_time = 0; // reset the ban time
}
@@ -1229,19 +958,19 @@ int mmo_auth(struct mmo_account *account, int fd)
if (auth_dat[i].connect_until_time != 0
&& auth_dat[i].connect_until_time < time(NULL))
{
- login_log("Connection refused (account: %s, expired ID, ip: %s)\n",
+ LOGIN_LOG("Connection refused (account: %s, expired ID, ip: %s)\n",
account->userid, ip);
return 2; // 2 = This ID is expired
}
- login_log("Authentification accepted (account: %s (id: %d), ip: %s)\n",
+ LOGIN_LOG("Authentification accepted (account: %s (id: %d), ip: %s)\n",
account->userid, auth_dat[i].account_id, ip);
}
else
{
if (newaccount == 0)
{
- login_log("Unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("Unknown account (account: %s, ip: %s)\n",
account->userid, ip);
return 0; // 0 = Unregistered ID
}
@@ -1249,15 +978,14 @@ int mmo_auth(struct mmo_account *account, int fd)
{
int new_id =
mmo_auth_new(account, account->userid[len + 1], "a@a.com");
- login_log("Account creation and authentification accepted (account %s (id: %d), sex: %c, connection with _F/_M, ip: %s)\n",
+ LOGIN_LOG("Account creation and authentification accepted (account %s (id: %d), sex: %c, connection with _F/_M, ip: %s)\n",
account->userid, new_id,
account->userid[len + 1], ip);
}
}
- gettimeofday(&tv, NULL);
- strftime(tmpstr, 24, date_format, gmtime(&(tv.tv_sec)));
- sprintf(tmpstr + strlen(tmpstr), ".%03d", (int) tv.tv_usec / 1000);
+ timestamp_milliseconds_buffer tmpstr;
+ stamp_time(tmpstr);
account->account_id = auth_dat[i].account_id;
account->login_id1 = mt_random();
@@ -1279,17 +1007,17 @@ void char_anti_freeze_system(timer_id, tick_t, custom_id_t, custom_data_t)
{
int i;
- //printf("Entering in char_anti_freeze_system function to check freeze of servers.\n");
+ //PRINTF("Entering in char_anti_freeze_system function to check freeze of servers.\n");
for (i = 0; i < MAX_SERVERS; i++)
{
if (server_fd[i] >= 0)
{ // if char-server is online
- //printf("char_anti_freeze_system: server #%d '%s', flag: %d.\n", i, server[i].name, server_freezeflag[i]);
+ //PRINTF("char_anti_freeze_system: server #%d '%s', flag: %d.\n", i, server[i].name, server_freezeflag[i]);
if (server_freezeflag[i]-- < 1)
{ // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed
- printf("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n",
+ PRINTF("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n",
i, server[i].name);
- login_log("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n",
+ LOGIN_LOG("Char-server anti-freeze system: char-server #%d '%s' is freezed -> disconnection.\n",
i, server[i].name);
session[server_fd[i]]->eof = 1;
}
@@ -1314,8 +1042,8 @@ void parse_fromchar(int fd)
{
if (id < MAX_SERVERS)
{
- printf("Char-server '%s' has disconnected.\n", server[id].name);
- login_log("Char-server '%s' has disconnected (ip: %s).\n",
+ PRINTF("Char-server '%s' has disconnected.\n", server[id].name);
+ LOGIN_LOG("Char-server '%s' has disconnected (ip: %s).\n",
server[id].name, ip);
server_fd[id] = -1;
memset(&server[id], 0, sizeof(struct mmo_char_server));
@@ -1328,14 +1056,14 @@ void parse_fromchar(int fd)
while (RFIFOREST(fd) >= 2)
{
if (display_parse_fromchar == 2 || (display_parse_fromchar == 1 && RFIFOW(fd, 0) != 0x2714)) // 0x2714 is done very often (number of players)
- printf("parse_fromchar: connection #%d, packet: 0x%x (with being read: %d bytes).\n",
+ PRINTF("parse_fromchar: connection #%d, packet: 0x%x (with being read: %d bytes).\n",
fd, RFIFOW(fd, 0), RFIFOREST(fd));
switch (RFIFOW(fd, 0))
{
// request from map-server via char-server to reload GM accounts (by Yor).
case 0x2709:
- login_log("Char-server '%s': Request to re-load GM configuration file (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Request to re-load GM configuration file (ip: %s).\n",
server[id].name, ip);
read_gm_account();
// send GM accounts to all char-servers
@@ -1363,9 +1091,9 @@ void parse_fromchar(int fd)
{
int p, k;
auth_fifo[i].delflag = 1;
- login_log("Char-server '%s': authentification of the account %d accepted (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': authentification of the account %d accepted (ip: %s).\n",
server[id].name, acc, ip);
-// printf("%d\n", i);
+// PRINTF("%d\n", i);
for (k = 0; k < auth_num; k++)
{
if (auth_dat[k].account_id == acc)
@@ -1384,7 +1112,7 @@ void parse_fromchar(int fd)
}
WFIFOW(fd, 2) = p;
WFIFOSET(fd, p);
-// printf("parse_fromchar: Sending of account_reg2: login->char (auth fifo)\n");
+// PRINTF("parse_fromchar: Sending of account_reg2: login->char (auth fifo)\n");
WFIFOW(fd, 0) = 0x2713;
WFIFOL(fd, 2) = acc;
WFIFOB(fd, 6) = 0;
@@ -1403,7 +1131,7 @@ void parse_fromchar(int fd)
// authentification not found
if (i == AUTH_FIFO_SIZE)
{
- login_log("Char-server '%s': authentification of the account %d REFUSED (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': authentification of the account %d REFUSED (ip: %s).\n",
server[id].name, acc, ip);
WFIFOW(fd, 0) = 0x2713;
WFIFOL(fd, 2) = acc;
@@ -1419,7 +1147,7 @@ void parse_fromchar(int fd)
case 0x2714:
if (RFIFOREST(fd) < 6)
return;
- //printf("parse_fromchar: Receiving of the users number of the server '%s': %d\n", server[id].name, RFIFOL(fd,2));
+ //PRINTF("parse_fromchar: Receiving of the users number of the server '%s': %d\n", server[id].name, RFIFOL(fd,2));
server[id].users = RFIFOL(fd, 2);
if (anti_freeze_enable)
server_freezeflag[id] = 5; // Char anti-freeze system. Counter. 5 ok, 4...0 freezed
@@ -1437,9 +1165,9 @@ void parse_fromchar(int fd)
memcpy(email, RFIFOP(fd, 6), 40);
email[39] = '\0';
remove_control_chars(email);
- //printf("parse_fromchar: an e-mail creation of an account with a default e-mail: server '%s', account: %d, e-mail: '%s'.\n", server[id].name, acc, RFIFOP(fd,6));
+ //PRINTF("parse_fromchar: an e-mail creation of an account with a default e-mail: server '%s', account: %d, e-mail: '%s'.\n", server[id].name, acc, RFIFOP(fd,6));
if (e_mail_check(email) == 0)
- login_log("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n",
+ LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - e-mail is invalid (account: %d, ip: %s)\n",
server[id].name, acc, ip);
else
{
@@ -1450,13 +1178,13 @@ void parse_fromchar(int fd)
|| auth_dat[i].email[0] == '\0'))
{
memcpy(auth_dat[i].email, email, 40);
- login_log("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Create an e-mail on an account with a default e-mail (account: %d, new e-mail: %s, ip: %s).\n",
server[id].name, acc, email, ip);
break;
}
}
if (i == auth_num)
- login_log("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Attempt to create an e-mail on an account with a default e-mail REFUSED - account doesn't exist or e-mail of account isn't default e-mail (account: %d, ip: %s).\n",
server[id].name, acc, ip);
}
RFIFOSKIP(fd, 46);
@@ -1467,12 +1195,12 @@ void parse_fromchar(int fd)
case 0x2716:
if (RFIFOREST(fd) < 6)
return;
- //printf("parse_fromchar: E-mail/limited time request from '%s' server (concerned account: %d)\n", server[id].name, RFIFOL(fd,2));
+ //PRINTF("parse_fromchar: E-mail/limited time request from '%s' server (concerned account: %d)\n", server[id].name, RFIFOL(fd,2));
for (i = 0; i < auth_num; i++)
{
if (auth_dat[i].account_id == RFIFOL(fd, 2))
{
- login_log("Char-server '%s': e-mail of the account %d found (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': e-mail of the account %d found (ip: %s).\n",
server[id].name, RFIFOL(fd, 2), ip);
WFIFOW(fd, 0) = 0x2717;
WFIFOL(fd, 2) = RFIFOL(fd, 2);
@@ -1485,7 +1213,7 @@ void parse_fromchar(int fd)
}
if (i == auth_num)
{
- login_log("Char-server '%s': e-mail of the account %d NOT found (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': e-mail of the account %d NOT found (ip: %s).\n",
server[id].name, RFIFOL(fd, 2), ip);
}
RFIFOSKIP(fd, 6);
@@ -1499,7 +1227,7 @@ void parse_fromchar(int fd)
unsigned char buf[10];
FILE *fp;
acc = RFIFOL(fd, 4);
- //printf("parse_fromchar: Request to become a GM acount from %d account.\n", acc);
+ //PRINTF("parse_fromchar: Request to become a GM acount from %d account.\n", acc);
WBUFW(buf, 0) = 0x2721;
WBUFL(buf, 2) = acc;
WBUFL(buf, 6) = 0;
@@ -1516,12 +1244,9 @@ void parse_fromchar(int fd)
fopen_(GM_account_filename,
"a")) != NULL)
{
- char tmpstr[24];
- struct timeval tv;
- gettimeofday(&tv, NULL);
- strftime(tmpstr, 23, date_format,
- gmtime(&(tv.tv_sec)));
- fprintf(fp,
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ FPRINTF(fp,
"\n// %s: @GM command on account %d\n%d %d\n",
tmpstr,
acc, acc, level_new_gm);
@@ -1529,41 +1254,41 @@ void parse_fromchar(int fd)
WBUFL(buf, 6) = level_new_gm;
read_gm_account();
send_GM_accounts();
- printf("GM Change of the account %d: level 0 -> %d.\n",
+ PRINTF("GM Change of the account %d: level 0 -> %d.\n",
acc, level_new_gm);
- login_log("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': GM Change of the account %d: level 0 -> %d (ip: %s).\n",
server[id].name, acc,
level_new_gm, ip);
}
else
{
- printf("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n",
+ PRINTF("Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file)\n",
acc);
- login_log("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, unable to add a GM account in GM accounts file, ip: %s).\n",
server[id].name, acc, ip);
}
}
else
{
- printf("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n",
+ PRINTF("Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0))\n",
acc);
- login_log("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, correct password, but GM creation is disable (level_new_gm = 0), ip: %s).\n",
server[id].name, acc, ip);
}
}
else
{
- printf("Error of GM change (suggested account: %d (already GM), correct password).\n",
+ PRINTF("Error of GM change (suggested account: %d (already GM), correct password).\n",
acc);
- login_log("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d (already GM), correct password, ip: %s).\n",
server[id].name, acc, ip);
}
}
else
{
- printf("Error of GM change (suggested account: %d, invalid password).\n",
+ PRINTF("Error of GM change (suggested account: %d, invalid password).\n",
acc);
- login_log("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of GM change (suggested account: %d, invalid password, ip: %s).\n",
server[id].name, acc, ip);
}
charif_sendallwos(-1, buf, 10);
@@ -1586,13 +1311,13 @@ void parse_fromchar(int fd)
new_email[39] = '\0';
remove_control_chars(new_email);
if (e_mail_check(actual_email) == 0)
- login_log("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n",
+ LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual email is invalid (account: %d, ip: %s)\n",
server[id].name, acc, ip);
else if (e_mail_check(new_email) == 0)
- login_log("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)\n",
+ LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a invalid new e-mail (account: %d, ip: %s)\n",
server[id].name, acc, ip);
else if (strcasecmp(new_email, "a@a.com") == 0)
- login_log("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)\n",
+ LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command) with a default e-mail (account: %d, ip: %s)\n",
server[id].name, acc, ip);
else
{
@@ -1604,12 +1329,12 @@ void parse_fromchar(int fd)
== 0)
{
memcpy(auth_dat[i].email, new_email, 40);
- login_log("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Modify an e-mail on an account (@email GM command) (account: %d (%s), new e-mail: %s, ip: %s).\n",
server[id].name, acc,
auth_dat[i].userid, new_email, ip);
}
else
- login_log("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but actual e-mail is incorrect (account: %d (%s), actual e-mail: %s, proposed e-mail: %s, ip: %s).\n",
server[id].name, acc,
auth_dat[i].userid,
auth_dat[i].email, actual_email, ip);
@@ -1617,7 +1342,7 @@ void parse_fromchar(int fd)
}
}
if (i == auth_num)
- login_log("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Attempt to modify an e-mail on an account (@email GM command), but account doesn't exist (account: %d, ip: %s).\n",
server[id].name, acc, ip);
}
}
@@ -1638,7 +1363,7 @@ void parse_fromchar(int fd)
{
if (auth_dat[i].state != statut)
{
- login_log("Char-server '%s': Status change (account: %d, new status %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Status change (account: %d, new status %d, ip: %s).\n",
server[id].name, acc, statut,
ip);
if (statut != 0)
@@ -1656,7 +1381,7 @@ void parse_fromchar(int fd)
auth_dat[i].state = statut;
}
else
- login_log("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of Status change - actual status is already the good status (account: %d, status %d, ip: %s).\n",
server[id].name, acc, statut,
ip);
break;
@@ -1664,7 +1389,7 @@ void parse_fromchar(int fd)
}
if (i == auth_num)
{
- login_log("Char-server '%s': Error of Status change (account: %d not found, suggested status %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of Status change (account: %d not found, suggested status %d, ip: %s).\n",
server[id].name, acc, statut, ip);
}
RFIFOSKIP(fd, 10);
@@ -1711,14 +1436,14 @@ void parse_fromchar(int fd)
if (timestamp != 0)
{
unsigned char buf[16];
- char tmpstr[2048];
- strftime(tmpstr, 24, date_format,
- gmtime(&timestamp));
- login_log("Char-server '%s': Ban request (account: %d, new final date of banishment: %ld (%s), ip: %s).\n",
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ LOGIN_LOG("Char-server '%s': Ban request (account: %d, new final date of banishment: %ld (%s), ip: %s).\n",
server[id].name, acc,
timestamp,
- (timestamp ==
- 0 ? "no banishment" : tmpstr),
+ timestamp
+ ? tmpstr
+ : "no banishment",
ip);
WBUFW(buf, 0) = 0x2731;
WBUFL(buf, 2) =
@@ -1733,7 +1458,7 @@ void parse_fromchar(int fd)
}
else
{
- login_log("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, new date unbans the account, ip: %s).\n",
server[id].name, acc,
ip);
}
@@ -1741,13 +1466,13 @@ void parse_fromchar(int fd)
}
else
{
- login_log("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, no change for ban date, ip: %s).\n",
server[id].name, acc, ip);
}
}
else
{
- login_log("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of ban request (account: %d, invalid date, ip: %s).\n",
server[id].name, acc, ip);
}
break;
@@ -1755,7 +1480,7 @@ void parse_fromchar(int fd)
}
if (i == auth_num)
{
- login_log("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of ban request (account: %d not found, ip: %s).\n",
server[id].name, acc, ip);
}
RFIFOSKIP(fd, 18);
@@ -1770,11 +1495,11 @@ void parse_fromchar(int fd)
acc = RFIFOL(fd, 2);
for (i = 0; i < auth_num; i++)
{
-// printf("%d,", auth_dat[i].account_id);
+// PRINTF("%d,", auth_dat[i].account_id);
if (auth_dat[i].account_id == acc)
{
if (auth_dat[i].sex == 2)
- login_log("Char-server '%s': Error of sex change - Server account (suggested account: %d, actual sex %d (Server), ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of sex change - Server account (suggested account: %d, actual sex %d (Server), ip: %s).\n",
server[id].name, acc,
auth_dat[i].sex, ip);
else
@@ -1784,7 +1509,7 @@ void parse_fromchar(int fd)
sex = 1;
else
sex = 0;
- login_log("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Sex change (account: %d, new sex %c, ip: %s).\n",
server[id].name, acc,
(sex == 2) ? 'S' : (sex ? 'M' : 'F'),
ip);
@@ -1802,7 +1527,7 @@ void parse_fromchar(int fd)
}
if (i == auth_num)
{
- login_log("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of sex change (account: %d not found, sex would be reversed, ip: %s).\n",
server[id].name, acc, ip);
}
RFIFOSKIP(fd, 6);
@@ -1820,7 +1545,7 @@ void parse_fromchar(int fd)
if (auth_dat[i].account_id == acc)
{
unsigned char buf[RFIFOW(fd, 2) + 1];
- login_log("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d, ip: %s).\n",
server[id].name, acc, ip);
for (p = 8, j = 0;
p < RFIFOW(fd, 2) && j < ACCOUNT_REG2_NUM;
@@ -1840,14 +1565,14 @@ void parse_fromchar(int fd)
RFIFOW(fd, 2));
WBUFW(buf, 0) = 0x2729;
charif_sendallwos(fd, buf, WBUFW(buf, 2));
-// printf("parse_fromchar: receiving (from the char-server) of account_reg2 (account id: %d).\n", acc);
+// PRINTF("parse_fromchar: receiving (from the char-server) of account_reg2 (account id: %d).\n", acc);
break;
}
}
if (i == auth_num)
{
-// printf("parse_fromchar: receiving (from the char-server) of account_reg2 (unknwon account id: %d).\n", acc);
- login_log("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n",
+// PRINTF("parse_fromchar: receiving (from the char-server) of account_reg2 (unknwon account id: %d).\n", acc);
+ LOGIN_LOG("Char-server '%s': receiving (from the char-server) of account_reg2 (account: %d not found, ip: %s).\n",
server[id].name, acc, ip);
}
}
@@ -1867,12 +1592,12 @@ void parse_fromchar(int fd)
if (auth_dat[i].ban_until_time != 0)
{
auth_dat[i].ban_until_time = 0;
- login_log("Char-server '%s': UnBan request (account: %d, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': UnBan request (account: %d, ip: %s).\n",
server[id].name, acc, ip);
}
else
{
- login_log("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d, no change for unban date, ip: %s).\n",
server[id].name, acc, ip);
}
break;
@@ -1880,7 +1605,7 @@ void parse_fromchar(int fd)
}
if (i == auth_num)
{
- login_log("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Error of UnBan request (account: %d not found, ip: %s).\n",
server[id].name, acc, ip);
}
RFIFOSKIP(fd, 6);
@@ -1916,7 +1641,7 @@ void parse_fromchar(int fd)
{
status = 1;
strcpy(auth_dat[i].pass, MD5_saltcrypt(new_pass, make_salt()));
- login_log("Char-server '%s': Change pass success (account: %d (%s), ip: %s.\n",
+ LOGIN_LOG("Char-server '%s': Change pass success (account: %d (%s), ip: %s.\n",
server[id].name, acc,
auth_dat[i].userid, ip);
}
@@ -1924,7 +1649,7 @@ void parse_fromchar(int fd)
else
{
status = 2;
- login_log("Char-server '%s': Attempt to modify a pass failed, wrong password. (account: %d (%s), ip: %s).\n",
+ LOGIN_LOG("Char-server '%s': Attempt to modify a pass failed, wrong password. (account: %d (%s), ip: %s).\n",
server[id].name, acc,
auth_dat[i].userid, ip);
}
@@ -1943,37 +1668,35 @@ void parse_fromchar(int fd)
default:
{
FILE *logfp;
- char tmpstr[24];
- struct timeval tv;
logfp = fopen_(login_log_unknown_packets_filename, "a");
if (logfp)
{
- gettimeofday(&tv, NULL);
- strftime(tmpstr, 23, date_format, gmtime(&(tv.tv_sec)));
- fprintf(logfp,
- "%s.%03d: receiving of an unknown packet -> disconnection\n",
- tmpstr, (int) tv.tv_usec / 1000);
- fprintf(logfp,
+ timestamp_milliseconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ FPRINTF(logfp,
+ "%s: receiving of an unknown packet -> disconnection\n",
+ tmpstr);
+ FPRINTF(logfp,
"parse_fromchar: connection #%d (ip: %s), packet: 0x%x (with being read: %d).\n",
fd, ip, RFIFOW(fd, 0), RFIFOREST(fd));
- fprintf(logfp, "Detail (in hex):\n");
- fprintf(logfp,
+ FPRINTF(logfp, "Detail (in hex):\n");
+ FPRINTF(logfp,
"---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n");
memset(tmpstr, '\0', sizeof(tmpstr));
for (i = 0; i < RFIFOREST(fd); i++)
{
if ((i & 15) == 0)
- fprintf(logfp, "%04X ", i);
- fprintf(logfp, "%02x ", RFIFOB(fd, i));
+ FPRINTF(logfp, "%04X ", i);
+ FPRINTF(logfp, "%02x ", RFIFOB(fd, i));
if (RFIFOB(fd, i) > 0x1f)
tmpstr[i % 16] = RFIFOB(fd, i);
else
tmpstr[i % 16] = '.';
if ((i - 7) % 16 == 0) // -8 + 1
- fprintf(logfp, " ");
+ FPRINTF(logfp, " ");
else if ((i + 1) % 16 == 0)
{
- fprintf(logfp, " %s\n", tmpstr);
+ FPRINTF(logfp, " %s\n", tmpstr);
memset(tmpstr, '\0', sizeof(tmpstr));
}
}
@@ -1981,20 +1704,20 @@ void parse_fromchar(int fd)
{
for (j = i; j % 16 != 0; j++)
{
- fprintf(logfp, " ");
+ FPRINTF(logfp, " ");
if ((j - 7) % 16 == 0) // -8 + 1
- fprintf(logfp, " ");
+ FPRINTF(logfp, " ");
}
- fprintf(logfp, " %s\n", tmpstr);
+ FPRINTF(logfp, " %s\n", tmpstr);
}
- fprintf(logfp, "\n");
+ FPRINTF(logfp, "\n");
fclose_(logfp);
}
}
- printf("parse_fromchar: Unknown packet 0x%x (from a char-server)! -> disconnection.\n",
+ PRINTF("parse_fromchar: Unknown packet 0x%x (from a char-server)! -> disconnection.\n",
RFIFOW(fd, 0));
session[fd]->eof = 1;
- printf("Char-server has been disconnected (unknown packet).\n");
+ PRINTF("Char-server has been disconnected (unknown packet).\n");
return;
}
}
@@ -2016,7 +1739,7 @@ void parse_admin(int fd)
{
close(fd);
delete_session(fd);
- printf("Remote administration has disconnected (session #%d).\n",
+ PRINTF("Remote administration has disconnected (session #%d).\n",
fd);
return;
}
@@ -2024,13 +1747,13 @@ void parse_admin(int fd)
while (RFIFOREST(fd) >= 2)
{
if (display_parse_admin == 1)
- printf("parse_admin: connection #%d, packet: 0x%x (with being read: %d).\n",
+ PRINTF("parse_admin: connection #%d, packet: 0x%x (with being read: %d).\n",
fd, RFIFOW(fd, 0), RFIFOREST(fd));
switch (RFIFOW(fd, 0))
{
case 0x7530: // Request of the server version
- login_log("'ladmin': Sending of the server version (ip: %s)\n",
+ LOGIN_LOG("'ladmin': Sending of the server version (ip: %s)\n",
ip);
WFIFOW(fd, 0) = 0x7531;
WFIFOB(fd, 2) = ATHENA_MAJOR_VERSION;
@@ -2045,7 +1768,7 @@ void parse_admin(int fd)
break;
case 0x7532: // Request of end of connection
- login_log("'ladmin': End of connection (ip: %s)\n",
+ LOGIN_LOG("'ladmin': End of connection (ip: %s)\n",
ip);
RFIFOSKIP(fd, 2);
session[fd]->eof = 1;
@@ -2065,7 +1788,7 @@ void parse_admin(int fd)
st = 0;
if (ed > END_ACCOUNT_NUM || ed < st || ed <= 0)
ed = END_ACCOUNT_NUM;
- login_log("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n",
st, ed, ip);
// Sort before send
for (i = 0; i < auth_num; i++)
@@ -2138,22 +1861,22 @@ void parse_admin(int fd)
memcpy(WFIFOP(fd, 6), RFIFOP(fd, 2), 24);
if (strlen(ma.userid) > 23 || strlen(ma.passwd) > 23)
{
- login_log("'ladmin': Attempt to create an invalid account (account or pass is too long, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to create an invalid account (account or pass is too long, ip: %s)\n",
ip);
}
else if (strlen(ma.userid) < 4 || strlen(ma.passwd) < 4)
{
- login_log("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to create an invalid account (account or pass is too short, ip: %s)\n",
ip);
}
else if (ma.sex != 'F' && ma.sex != 'M')
{
- login_log("'ladmin': Attempt to create an invalid account (account: %s, invalid sex, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to create an invalid account (account: %s, invalid sex, ip: %s)\n",
ma.userid, ip);
}
else if (account_id_count > END_ACCOUNT_NUM)
{
- login_log("'ladmin': Attempt to create an account, but there is no more available id number (account: %s, sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to create an account, but there is no more available id number (account: %s, sex: %c, ip: %s)\n",
ma.userid, ma.sex, ip);
}
else
@@ -2165,7 +1888,7 @@ void parse_admin(int fd)
if (strncmp(auth_dat[i].userid, ma.userid, 24) ==
0)
{
- login_log("'ladmin': Attempt to create an already existing account (account: %s ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to create an already existing account (account: %s ip: %s)\n",
auth_dat[i].userid, ip);
break;
}
@@ -2178,7 +1901,7 @@ void parse_admin(int fd)
email[39] = '\0';
remove_control_chars(email);
new_id = mmo_auth_new(&ma, ma.sex, email);
- login_log("'ladmin': Account creation (account: %s (id: %d), sex: %c, email: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Account creation (account: %s (id: %d), sex: %c, email: %s, ip: %s)\n",
ma.userid, new_id,
ma.sex, auth_dat[i].email, ip);
WFIFOL(fd, 2) = new_id;
@@ -2210,14 +1933,13 @@ void parse_admin(int fd)
memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
WFIFOL(fd, 2) = auth_dat[i].account_id;
// save deleted account in log file
- login_log("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n",
+ LOGIN_LOG("'ladmin': Account deletion (account: %s, id: %d, ip: %s) - saved in next line:\n",
auth_dat[i].userid, auth_dat[i].account_id,
ip);
}
{
- char buf[65535];
- mmo_auth_tostr(buf, &auth_dat[i]);
- login_log("%s\n", buf);
+ std::string buf = mmo_auth_tostr(&auth_dat[i]);
+ LOGIN_LOG("%s\n", buf);
}
// delete account
memset(auth_dat[i].userid, '\0',
@@ -2227,7 +1949,7 @@ void parse_admin(int fd)
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to delete an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
WFIFOSET(fd, 30);
@@ -2249,13 +1971,13 @@ void parse_admin(int fd)
strcpy(auth_dat[i].pass, MD5_saltcrypt((char *)RFIFOP(fd, 26), make_salt()));
auth_dat[i].pass[39] = '\0';
WFIFOL(fd, 2) = auth_dat[i].account_id;
- login_log("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a password (account: %s, new password: %s, ip: %s)\n",
auth_dat[i].userid, auth_dat[i].pass, ip);
}
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify the password of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
WFIFOSET(fd, 30);
@@ -2289,16 +2011,16 @@ void parse_admin(int fd)
if (auth_dat[i].state == statut
&& strcmp(auth_dat[i].error_message,
error_message) == 0)
- login_log("'ladmin': Modification of a state, but the state of the account is already the good state (account: %s, received state: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a state, but the state of the account is already the good state (account: %s, received state: %d, ip: %s)\n",
account_name, statut, ip);
else
{
if (statut == 7)
- login_log("'ladmin': Modification of a state (account: %s, new state: %d - prohibited to login until '%s', ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d - prohibited to login until '%s', ip: %s)\n",
auth_dat[i].userid, statut,
error_message, ip);
else
- login_log("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a state (account: %s, new state: %d, ip: %s)\n",
auth_dat[i].userid, statut, ip);
if (auth_dat[i].state == 0)
{
@@ -2321,7 +2043,7 @@ void parse_admin(int fd)
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify the state of an unknown account (account: %s, received state: %d, ip: %s)\n",
account_name, statut, ip);
}
WFIFOL(fd, 30) = statut;
@@ -2331,7 +2053,7 @@ void parse_admin(int fd)
break;
case 0x7938: // Request for servers list and # of online players
- login_log("'ladmin': Sending of servers list (ip: %s)\n", ip);
+ LOGIN_LOG("'ladmin': Sending of servers list (ip: %s)\n", ip);
server_num = 0;
for (i = 0; i < MAX_SERVERS; i++)
{
@@ -2370,7 +2092,7 @@ void parse_admin(int fd)
if ( pass_ok((char *)RFIFOP(fd, 26), auth_dat[i].pass) )
{
WFIFOL(fd, 2) = auth_dat[i].account_id;
- login_log("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Check of password OK (account: %s, password: %s, ip: %s)\n",
auth_dat[i].userid, auth_dat[i].pass,
ip);
}
@@ -2380,14 +2102,14 @@ void parse_admin(int fd)
memcpy(pass, RFIFOP(fd, 26), 24);
pass[23] = '\0';
remove_control_chars(pass);
- login_log("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Failure of password check (account: %s, proposed pass: %s, ip: %s)\n",
auth_dat[i].userid, pass, ip);
}
}
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to check the password of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
WFIFOSET(fd, 30);
@@ -2409,10 +2131,10 @@ void parse_admin(int fd)
if (sex != 'F' && sex != 'M')
{
if (sex > 31)
- login_log("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to give an invalid sex (account: %s, received sex: %c, ip: %s)\n",
account_name, sex, ip);
else
- login_log("'ladmin': Attempt to give an invalid sex (account: %s, received sex: 'control char', ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to give an invalid sex (account: %s, received sex: 'control char', ip: %s)\n",
account_name, ip);
}
else
@@ -2436,7 +2158,7 @@ void parse_admin(int fd)
|| sex ==
's') ? 2 : (sex == 'M'
|| sex == 'm');
- login_log("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a sex (account: %s, new sex: %c, ip: %s)\n",
auth_dat[i].userid, sex, ip);
// send to all char-server the change
WBUFW(buf, 0) = 0x2723;
@@ -2446,13 +2168,13 @@ void parse_admin(int fd)
}
else
{
- login_log("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a sex, but the sex is already the good sex (account: %s, sex: %c, ip: %s)\n",
auth_dat[i].userid, sex, ip);
}
}
else
{
- login_log("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify the sex of an unknown account (account: %s, received sex: %c, ip: %s)\n",
account_name, sex, ip);
}
}
@@ -2475,7 +2197,7 @@ void parse_admin(int fd)
new_gm_level = RFIFOB(fd, 26);
if (new_gm_level < 0 || new_gm_level > 99)
{
- login_log("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to give an invalid GM level (account: %s, received GM level: %d, ip: %s)\n",
account_name, (int) new_gm_level, ip);
}
else
@@ -2493,8 +2215,6 @@ void parse_admin(int fd)
char line[512];
int GM_account, GM_level;
int modify_flag;
- char tmpstr[24];
- struct timeval tv;
if ((fp2 =
lock_fopen(GM_account_filename,
&lock)) != NULL)
@@ -2503,9 +2223,8 @@ void parse_admin(int fd)
fopen_(GM_account_filename,
"r")) != NULL)
{
- gettimeofday(&tv, NULL);
- strftime(tmpstr, 23, date_format,
- gmtime(&(tv.tv_sec)));
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr);
modify_flag = 0;
// read/write GM file
while (fgets(line, sizeof(line) - 1, fp))
@@ -2520,7 +2239,7 @@ void parse_admin(int fd)
if ((line[0] == '/'
&& line[1] == '/')
|| line[0] == '\0')
- fprintf(fp2, "%s\n",
+ FPRINTF(fp2, "%s\n",
line);
else
{
@@ -2531,16 +2250,16 @@ void parse_admin(int fd)
&GM_account,
&GM_level) !=
2)
- fprintf(fp2,
+ FPRINTF(fp2,
"%s\n",
line);
else if (GM_account != acc)
- fprintf(fp2,
+ FPRINTF(fp2,
"%s\n",
line);
else if (new_gm_level < 1)
{
- fprintf(fp2,
+ FPRINTF(fp2,
"// %s: 'ladmin' GM level removed on account %d '%s' (previous level: %d)\n//%d %d\n",
tmpstr,
acc,
@@ -2551,7 +2270,7 @@ void parse_admin(int fd)
}
else
{
- fprintf(fp2,
+ FPRINTF(fp2,
"// %s: 'ladmin' GM level on account %d '%s' (previous level: %d)\n%d %d\n",
tmpstr,
acc,
@@ -2563,7 +2282,7 @@ void parse_admin(int fd)
}
}
if (modify_flag == 0)
- fprintf(fp2,
+ FPRINTF(fp2,
"// %s: 'ladmin' GM level on account %d '%s' (previous level: 0)\n%d %d\n",
tmpstr, acc,
auth_dat[i].userid, acc,
@@ -2572,13 +2291,13 @@ void parse_admin(int fd)
}
else
{
- login_log("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to read GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n",
auth_dat[i].userid, acc,
(int) new_gm_level, ip);
}
lock_fclose(fp2, GM_account_filename, &lock);
WFIFOL(fd, 2) = acc;
- login_log("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a GM level (account: %s (%d), new GM level: %d, ip: %s)\n",
auth_dat[i].userid, acc,
(int) new_gm_level, ip);
// read and send new GM informations
@@ -2587,21 +2306,21 @@ void parse_admin(int fd)
}
else
{
- login_log("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify of a GM level - impossible to write GM accounts file (account: %s (%d), received GM level: %d, ip: %s)\n",
auth_dat[i].userid, acc,
(int) new_gm_level, ip);
}
}
else
{
- login_log("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify of a GM level, but the GM level is already the good GM level (account: %s (%d), GM level: %d, ip: %s)\n",
auth_dat[i].userid, acc,
(int) new_gm_level, ip);
}
}
else
{
- login_log("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify the GM level of an unknown account (account: %s, received GM level: %d, ip: %s)\n",
account_name, (int) new_gm_level,
ip);
}
@@ -2625,7 +2344,7 @@ void parse_admin(int fd)
memcpy(email, RFIFOP(fd, 26), 40);
if (e_mail_check(email) == 0)
{
- login_log("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to give an invalid e-mail (account: %s, ip: %s)\n",
account_name, ip);
}
else
@@ -2637,12 +2356,12 @@ void parse_admin(int fd)
memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
memcpy(auth_dat[i].email, email, 40);
WFIFOL(fd, 2) = auth_dat[i].account_id;
- login_log("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of an email (account: %s, new e-mail: %s, ip: %s)\n",
auth_dat[i].userid, email, ip);
}
else
{
- login_log("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify the e-mail of an unknown account (account: %s, received e-mail: %s, ip: %s)\n",
account_name, email, ip);
}
}
@@ -2683,13 +2402,13 @@ void parse_admin(int fd)
auth_dat[i].memo[size_of_memo - 1] = '\0';
remove_control_chars(auth_dat[i].memo);
WFIFOL(fd, 2) = auth_dat[i].account_id;
- login_log("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Modification of a memo field (account: %s, new memo: %s, ip: %s)\n",
auth_dat[i].userid, auth_dat[i].memo, ip);
}
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to modify the memo field of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
WFIFOSET(fd, 30);
@@ -2709,14 +2428,14 @@ void parse_admin(int fd)
{
memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
WFIFOL(fd, 2) = auth_dat[i].account_id;
- login_log("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Request (by the name) of an account id (account: %s, id: %d, ip: %s)\n",
auth_dat[i].userid, auth_dat[i].account_id,
ip);
}
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': ID request (by the name) of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
}
WFIFOSET(fd, 30);
@@ -2734,14 +2453,14 @@ void parse_admin(int fd)
if (auth_dat[i].account_id == RFIFOL(fd, 2))
{
strncpy((char *)WFIFOP(fd, 6), auth_dat[i].userid, 24);
- login_log("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Request (by id) of an account name (account: %s, id: %d, ip: %s)\n",
auth_dat[i].userid, RFIFOL(fd, 2), ip);
break;
}
}
if (i == auth_num)
{
- login_log("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Name request (by id) of an unknown account (id: %d, ip: %s)\n",
RFIFOL(fd, 2), ip);
strncpy((char *)WFIFOP(fd, 6), "", 24);
}
@@ -2753,30 +2472,31 @@ void parse_admin(int fd)
if (RFIFOREST(fd) < 30)
return;
{
- time_t timestamp;
- char tmpstr[2048];
WFIFOW(fd, 0) = 0x7949;
WFIFOL(fd, 2) = -1;
account_name = (char *)RFIFOP(fd, 2);
account_name[23] = '\0';
remove_control_chars(account_name);
- timestamp = (time_t) RFIFOL(fd, 26);
- strftime(tmpstr, 24, date_format, gmtime(&timestamp));
+ time_t timestamp = static_cast<time_t>(RFIFOL(fd, 26));
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
i = search_account_index(account_name);
if (i != -1)
{
memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
- login_log("'ladmin': Change of a validity limit (account: %s, new validity: %ld (%s), ip: %s)\n",
+ LOGIN_LOG("'ladmin': Change of a validity limit (account: %s, new validity: %ld (%s), ip: %s)\n",
auth_dat[i].userid, timestamp,
- (timestamp == 0 ? "unlimited" : tmpstr), ip);
+ timestamp ? tmpstr : "unlimited",
+ ip);
auth_dat[i].connect_until_time = timestamp;
WFIFOL(fd, 2) = auth_dat[i].account_id;
}
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %ld (%s), ip: %s)\n", account_name, timestamp,
- (timestamp == 0 ? "unlimited" : tmpstr), ip);
+ LOGIN_LOG("'ladmin': Attempt to change the validity limit of an unknown account (account: %s, received validity: %ld (%s), ip: %s)\n", account_name, timestamp,
+ timestamp ? tmpstr : "unlimited",
+ ip);
}
WFIFOL(fd, 30) = timestamp;
}
@@ -2788,25 +2508,25 @@ void parse_admin(int fd)
if (RFIFOREST(fd) < 30)
return;
{
- time_t timestamp;
- char tmpstr[2048];
WFIFOW(fd, 0) = 0x794b;
WFIFOL(fd, 2) = -1;
account_name = (char *)RFIFOP(fd, 2);
account_name[23] = '\0';
remove_control_chars(account_name);
- timestamp = (time_t) RFIFOL(fd, 26);
+ time_t timestamp = static_cast<time_t>(RFIFOL(fd, 26));
if (timestamp <= time(NULL))
timestamp = 0;
- strftime(tmpstr, 24, date_format, gmtime(&timestamp));
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
i = search_account_index(account_name);
if (i != -1)
{
memcpy(WFIFOP(fd, 6), auth_dat[i].userid, 24);
WFIFOL(fd, 2) = auth_dat[i].account_id;
- login_log("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %ld (%s), ip: %s)\n",
+ LOGIN_LOG("'ladmin': Change of the final date of a banishment (account: %s, new final date of banishment: %ld (%s), ip: %s)\n",
auth_dat[i].userid, timestamp,
- (timestamp == 0 ? "no banishment" : tmpstr), ip);
+ timestamp ? tmpstr : "no banishment",
+ ip);
if (auth_dat[i].ban_until_time != timestamp)
{
if (timestamp != 0)
@@ -2828,9 +2548,10 @@ void parse_admin(int fd)
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %ld (%s), ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to change the final date of a banishment of an unknown account (account: %s, received final date of banishment: %ld (%s), ip: %s)\n",
account_name, timestamp,
- (timestamp == 0 ? "no banishment" : tmpstr), ip);
+ timestamp ? tmpstr : "no banishment",
+ ip);
}
WFIFOL(fd, 30) = timestamp;
}
@@ -2844,7 +2565,6 @@ void parse_admin(int fd)
{
time_t timestamp;
struct tm *tmtime;
- char tmpstr[2048];
WFIFOW(fd, 0) = 0x794d;
WFIFOL(fd, 2) = -1;
account_name = (char *)RFIFOP(fd, 2);
@@ -2878,9 +2598,9 @@ void parse_admin(int fd)
{
if (timestamp <= time(NULL))
timestamp = 0;
- strftime(tmpstr, 24, date_format,
- gmtime(&timestamp));
- login_log("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %ld (%s), ip: %s)\n",
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &timestamp);
+ LOGIN_LOG("'ladmin': Adjustment of a final date of a banishment (account: %s, (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %ld (%s), ip: %s)\n",
auth_dat[i].userid,
(short) RFIFOW(fd, 26), (short) RFIFOW(fd,
28),
@@ -2889,7 +2609,7 @@ void parse_admin(int fd)
(short) RFIFOW(fd, 34), (short) RFIFOW(fd,
36),
timestamp,
- (timestamp == 0 ? "no banishment" : tmpstr),
+ timestamp ? tmpstr : "no banishment",
ip);
if (auth_dat[i].ban_until_time != timestamp)
{
@@ -2911,13 +2631,14 @@ void parse_admin(int fd)
}
else
{
- strftime(tmpstr, 24, date_format,
- gmtime(&auth_dat[i].ban_until_time));
- login_log("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %ld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n",
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &auth_dat[i].ban_until_time);
+ LOGIN_LOG("'ladmin': Impossible to adjust the final date of a banishment (account: %s, %ld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n",
auth_dat[i].userid,
auth_dat[i].ban_until_time,
- (auth_dat[i].ban_until_time ==
- 0 ? "no banishment" : tmpstr),
+ auth_dat[i].ban_until_time
+ ? tmpstr
+ : "no banishment",
(short) RFIFOW(fd, 26), (short) RFIFOW(fd,
28),
(short) RFIFOW(fd, 30), (short) RFIFOW(fd,
@@ -2932,7 +2653,7 @@ void parse_admin(int fd)
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to adjust the final date of a banishment of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
WFIFOL(fd, 30) = 0;
}
@@ -2949,7 +2670,7 @@ void parse_admin(int fd)
WFIFOW(fd, 2) = -1;
if (RFIFOL(fd, 4) < 1)
{
- login_log("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n",
+ LOGIN_LOG("'ladmin': Receiving a message for broadcast, but message is void (ip: %s)\n",
ip);
}
else
@@ -2960,7 +2681,7 @@ void parse_admin(int fd)
break;
if (i == MAX_SERVERS)
{
- login_log("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n",
+ LOGIN_LOG("'ladmin': Receiving a message for broadcast, but no char-server is online (ip: %s)\n",
ip);
}
else
@@ -2973,10 +2694,10 @@ void parse_admin(int fd)
message[sizeof(message) - 1] = '\0';
remove_control_chars(message);
if (RFIFOW(fd, 2) == 0)
- login_log("'ladmin': Receiving a message for broadcast (message (in yellow): %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Receiving a message for broadcast (message (in yellow): %s, ip: %s)\n",
message, ip);
else
- login_log("'ladmin': Receiving a message for broadcast (message (in blue): %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Receiving a message for broadcast (message (in blue): %s, ip: %s)\n",
message, ip);
// send same message to all char-servers (no answer)
memcpy(WBUFP(buf, 0), RFIFOP(fd, 0),
@@ -2995,8 +2716,6 @@ void parse_admin(int fd)
{
time_t timestamp;
struct tm *tmtime;
- char tmpstr[2048];
- char tmpstr2[2048];
WFIFOW(fd, 0) = 0x7951;
WFIFOL(fd, 2) = -1;
account_name = (char *)RFIFOP(fd, 2);
@@ -3010,7 +2729,7 @@ void parse_admin(int fd)
timestamp = auth_dat[i].connect_until_time;
if (add_to_unlimited_account == 0 && timestamp == 0)
{
- login_log("'ladmin': Attempt to adjust the validity limit of an unlimited account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unlimited account (account: %s, ip: %s)\n",
auth_dat[i].userid, ip);
WFIFOL(fd, 30) = 0;
}
@@ -3034,12 +2753,11 @@ void parse_admin(int fd)
timestamp = mktime(tmtime);
if (timestamp != -1)
{
- strftime(tmpstr, 24, date_format,
- gmtime(&auth_dat
- [i].connect_until_time));
- strftime(tmpstr2, 24, date_format,
- gmtime(&timestamp));
- login_log("'ladmin': Adjustment of a validity limit (account: %s, %ld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %ld (%s), ip: %s)\n",
+ timestamp_seconds_buffer tmpstr;
+ timestamp_seconds_buffer tmpstr2;
+ stamp_time(tmpstr, &auth_dat[i].connect_until_time);
+ stamp_time(tmpstr2, &timestamp);
+ LOGIN_LOG("'ladmin': Adjustment of a validity limit (account: %s, %ld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> new validity: %ld (%s), ip: %s)\n",
auth_dat[i].userid,
auth_dat[i].connect_until_time,
(auth_dat[i].connect_until_time ==
@@ -3050,7 +2768,7 @@ void parse_admin(int fd)
(short) RFIFOW(fd, 32),
(short) RFIFOW(fd, 34),
(short) RFIFOW(fd, 36), timestamp,
- (timestamp == 0 ? "unlimited" : tmpstr2),
+ timestamp ? tmpstr2 : "unlimited",
ip);
auth_dat[i].connect_until_time = timestamp;
WFIFOL(fd, 30) =
@@ -3059,10 +2777,9 @@ void parse_admin(int fd)
}
else
{
- strftime(tmpstr, 24, date_format,
- gmtime(&auth_dat
- [i].connect_until_time));
- login_log("'ladmin': Impossible to adjust a validity limit (account: %s, %ld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n",
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &auth_dat[i].connect_until_time);
+ LOGIN_LOG("'ladmin': Impossible to adjust a validity limit (account: %s, %ld (%s) + (%+d y %+d m %+d d %+d h %+d mn %+d s) -> ???, ip: %s)\n",
auth_dat[i].userid,
auth_dat[i].connect_until_time,
(auth_dat[i].connect_until_time ==
@@ -3080,7 +2797,7 @@ void parse_admin(int fd)
else
{
memcpy(WFIFOP(fd, 6), account_name, 24);
- login_log("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to adjust the validity limit of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
WFIFOL(fd, 30) = 0;
}
@@ -3121,7 +2838,7 @@ void parse_admin(int fd)
memcpy(WFIFOP(fd, 150), auth_dat[i].memo,
strlen(auth_dat[i].memo));
}
- login_log("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Sending information of an account (request by the name; account: %s, id: %d, ip: %s)\n",
auth_dat[i].userid, auth_dat[i].account_id,
ip);
WFIFOSET(fd, 150 + strlen(auth_dat[i].memo));
@@ -3130,7 +2847,7 @@ void parse_admin(int fd)
{
memcpy(WFIFOP(fd, 7), account_name, 24);
WFIFOW(fd, 148) = 0;
- login_log("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to obtain information (by the name) of an unknown account (account: %s, ip: %s)\n",
account_name, ip);
WFIFOSET(fd, 150);
}
@@ -3147,7 +2864,7 @@ void parse_admin(int fd)
{
if (auth_dat[i].account_id == RFIFOL(fd, 2))
{
- login_log("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Sending information of an account (request by the id; account: %s, id: %d, ip: %s)\n",
auth_dat[i].userid, RFIFOL(fd, 2), ip);
WFIFOB(fd, 6) =
(unsigned char) isGM(auth_dat[i].account_id);
@@ -3176,7 +2893,7 @@ void parse_admin(int fd)
}
if (i == auth_num)
{
- login_log("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n",
+ LOGIN_LOG("'ladmin': Attempt to obtain information (by the id) of an unknown account (id: %d, ip: %s)\n",
RFIFOL(fd, 2), ip);
strncpy((char *)WFIFOP(fd, 7), "", 24);
WFIFOW(fd, 148) = 0;
@@ -3186,7 +2903,7 @@ void parse_admin(int fd)
break;
case 0x7955: // Request to reload GM file (no answer)
- login_log("'ladmin': Request to re-load GM configuration file (ip: %s).\n",
+ LOGIN_LOG("'ladmin': Request to re-load GM configuration file (ip: %s).\n",
ip);
read_gm_account();
// send GM accounts to all char-servers
@@ -3197,37 +2914,34 @@ void parse_admin(int fd)
default:
{
FILE *logfp;
- char tmpstr[24];
- struct timeval tv;
logfp = fopen_(login_log_unknown_packets_filename, "a");
if (logfp)
{
- gettimeofday(&tv, NULL);
- strftime(tmpstr, 23, date_format, gmtime(&(tv.tv_sec)));
- fprintf(logfp,
- "%s.%03d: receiving of an unknown packet -> disconnection\n",
- tmpstr, (int) tv.tv_usec / 1000);
- fprintf(logfp,
+ timestamp_milliseconds_buffer tmpstr;
+ FPRINTF(logfp,
+ "%s: receiving of an unknown packet -> disconnection\n",
+ tmpstr);
+ FPRINTF(logfp,
"parse_admin: connection #%d (ip: %s), packet: 0x%x (with being read: %d).\n",
fd, ip, RFIFOW(fd, 0), RFIFOREST(fd));
- fprintf(logfp, "Detail (in hex):\n");
- fprintf(logfp,
+ FPRINTF(logfp, "Detail (in hex):\n");
+ FPRINTF(logfp,
"---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n");
memset(tmpstr, '\0', sizeof(tmpstr));
for (i = 0; i < RFIFOREST(fd); i++)
{
if ((i & 15) == 0)
- fprintf(logfp, "%04X ", i);
- fprintf(logfp, "%02x ", RFIFOB (fd, i));
+ FPRINTF(logfp, "%04X ", i);
+ FPRINTF(logfp, "%02x ", RFIFOB (fd, i));
if (RFIFOB(fd, i) > 0x1f)
tmpstr[i % 16] = RFIFOB(fd, i);
else
tmpstr[i % 16] = '.';
if ((i - 7) % 16 == 0) // -8 + 1
- fprintf(logfp, " ");
+ FPRINTF(logfp, " ");
else if ((i + 1) % 16 == 0)
{
- fprintf(logfp, " %s\n", tmpstr);
+ FPRINTF(logfp, " %s\n", tmpstr);
memset(tmpstr, '\0', sizeof(tmpstr));
}
}
@@ -3235,20 +2949,20 @@ void parse_admin(int fd)
{
for (j = i; j % 16 != 0; j++)
{
- fprintf(logfp, " ");
+ FPRINTF(logfp, " ");
if ((j - 7) % 16 == 0) // -8 + 1
- fprintf(logfp, " ");
+ FPRINTF(logfp, " ");
}
- fprintf(logfp, " %s\n", tmpstr);
+ FPRINTF(logfp, " %s\n", tmpstr);
}
- fprintf(logfp, "\n");
+ FPRINTF(logfp, "\n");
fclose_(logfp);
}
}
- login_log("'ladmin': End of connection, unknown packet (ip: %s)\n",
+ LOGIN_LOG("'ladmin': End of connection, unknown packet (ip: %s)\n",
ip);
session[fd]->eof = 1;
- printf("Remote administration has been disconnected (unknown packet).\n");
+ PRINTF("Remote administration has been disconnected (unknown packet).\n");
return;
}
//WFIFOW(fd,0) = 0x791f;
@@ -3267,7 +2981,7 @@ int lan_ip_check(unsigned char *p)
int i;
int lancheck = 1;
-// printf("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
+// PRINTF("lan_ip_check: to compare: %d.%d.%d.%d, network: %d.%d.%d.%d/%d.%d.%d.%d\n",
// p[0], p[1], p[2], p[3],
// subneti[0], subneti[1], subneti[2], subneti[3],
// subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
@@ -3279,7 +2993,7 @@ int lan_ip_check(unsigned char *p)
break;
}
}
- printf("LAN test (result): %s source\033[0m.\n",
+ PRINTF("LAN test (result): %s source\033[0m.\n",
(lancheck) ? "\033[1;36mLAN" : "\033[1;32mWAN");
return lancheck;
}
@@ -3311,17 +3025,17 @@ void parse_login(int fd)
if (RFIFOW(fd, 0) == 0x64 || RFIFOW(fd, 0) == 0x01dd)
{
if (RFIFOREST(fd) >= ((RFIFOW(fd, 0) == 0x64) ? 55 : 47))
- printf("parse_login: connection #%d, packet: 0x%x (with being read: %d), account: %s.\n",
+ PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %d), account: %s.\n",
fd, RFIFOW(fd, 0), RFIFOREST(fd), RFIFOP(fd, 6));
}
else if (RFIFOW(fd, 0) == 0x2710)
{
if (RFIFOREST(fd) >= 86)
- printf("parse_login: connection #%d, packet: 0x%x (with being read: %d), server: %s.\n",
+ PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %d), server: %s.\n",
fd, RFIFOW(fd, 0), RFIFOREST(fd), RFIFOP(fd, 60));
}
else
- printf("parse_login: connection #%d, packet: 0x%x (with being read: %d).\n",
+ PRINTF("parse_login: connection #%d, packet: 0x%x (with being read: %d).\n",
fd, RFIFOW(fd, 0), RFIFOREST(fd));
}
@@ -3357,18 +3071,18 @@ void parse_login(int fd)
if (RFIFOW(fd, 0) == 0x64)
{
- login_log("Request for connection (non encryption mode) of %s (ip: %s).\n",
+ LOGIN_LOG("Request for connection (non encryption mode) of %s (ip: %s).\n",
account.userid, ip);
}
else
{
- login_log("Request for connection (encryption mode) of %s (ip: %s).\n",
+ LOGIN_LOG("Request for connection (encryption mode) of %s (ip: %s).\n",
account.userid, ip);
}
if (!check_ip(session[fd]->client_addr.sin_addr))
{
- login_log("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n",
+ LOGIN_LOG("Connection refused: IP isn't authorised (deny/allow, ip: %s).\n",
ip);
WFIFOW(fd, 0) = 0x6a;
WFIFOB(fd, 2) = 0x03;
@@ -3383,7 +3097,7 @@ void parse_login(int fd)
int gm_level = isGM(account.account_id);
if (min_level_to_connect > gm_level)
{
- login_log("Connection refused: the minimum GM level for connection is %d (account: %s, GM level: %d, ip: %s).\n",
+ LOGIN_LOG("Connection refused: the minimum GM level for connection is %d (account: %s, GM level: %d, ip: %s).\n",
min_level_to_connect, account.userid,
gm_level, ip);
WFIFOW(fd, 0) = 0x81;
@@ -3395,10 +3109,10 @@ void parse_login(int fd)
int version_2 = RFIFOB(fd, 54); // version 2
if (gm_level)
- printf("Connection of the GM (level:%d) account '%s' accepted.\n",
+ PRINTF("Connection of the GM (level:%d) account '%s' accepted.\n",
gm_level, account.userid);
else
- printf("Connection of the account '%s' accepted.\n",
+ PRINTF("Connection of the account '%s' accepted.\n",
account.userid);
/*
@@ -3503,7 +3217,7 @@ void parse_login(int fd)
}
else
{
- login_log("Connection refused: there is no char-server online (account: %s, ip: %s).\n",
+ LOGIN_LOG("Connection refused: there is no char-server online (account: %s, ip: %s).\n",
account.userid, ip);
WFIFOW(fd, 0) = 0x81;
WFIFOL(fd, 2) = 1; // 01 = Server closed
@@ -3517,17 +3231,16 @@ void parse_login(int fd)
WFIFOW(fd, 0) = 0x6a;
WFIFOB(fd, 2) = result;
if (result == 6)
- { // 6 = Your are Prohibited to log in until %s
+ {
+ // 6 = Your are Prohibited to log in until %s
int i = search_account_index(account.userid);
if (i != -1)
{
if (auth_dat[i].ban_until_time != 0)
- { // if account is banned, we send ban timestamp
- char tmpstr[256];
- strftime(tmpstr, 20, date_format,
- gmtime(&auth_dat
- [i].ban_until_time));
- tmpstr[19] = '\0';
+ {
+ // if account is banned, we send ban timestamp
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr, &auth_dat[i].ban_until_time);
memcpy(WFIFOP(fd, 3), tmpstr, 20);
}
else
@@ -3548,7 +3261,7 @@ void parse_login(int fd)
struct login_session_data *ld;
if (session[fd]->session_data)
{
- printf("login: abnormal request of MD5 key (already opened session).\n");
+ PRINTF("login: abnormal request of MD5 key (already opened session).\n");
session[fd]->eof = 1;
return;
}
@@ -3556,18 +3269,18 @@ void parse_login(int fd)
session[fd]->session_data = ld;
if (!ld)
{
- printf("login: Request for md5 key: memory allocation failure (malloc)!\n");
+ PRINTF("login: Request for md5 key: memory allocation failure (malloc)!\n");
session[fd]->eof = 1;
return;
}
if (RFIFOW(fd, 0) == 0x01db)
{
- login_log("Sending request of the coding key (ip: %s)\n",
+ LOGIN_LOG("Sending request of the coding key (ip: %s)\n",
ip);
}
else
{
- login_log("'ladmin': Sending request of the coding key (ip: %s)\n",
+ LOGIN_LOG("'ladmin': Sending request of the coding key (ip: %s)\n",
ip);
}
// Creation of the coding key
@@ -3600,7 +3313,7 @@ void parse_login(int fd)
server_name = (char *)RFIFOP(fd, 60);
server_name[19] = '\0';
remove_control_chars(server_name);
- login_log("Connection request of the char-server '%s' @ %d.%d.%d.%d:%d (ip: %s)\n",
+ LOGIN_LOG("Connection request of the char-server '%s' @ %d.%d.%d.%d:%d (ip: %s)\n",
server_name, RFIFOB(fd, 54), RFIFOB(fd, 55),
RFIFOB(fd, 56), RFIFOB(fd, 57), RFIFOW(fd, 58),
ip);
@@ -3632,10 +3345,10 @@ void parse_login(int fd)
&& account.account_id < MAX_SERVERS
&& server_fd[account.account_id] == -1)
{
- login_log("Connection of the char-server '%s' accepted (account: %s, pass: %s, ip: %s)\n",
+ LOGIN_LOG("Connection of the char-server '%s' accepted (account: %s, pass: %s, ip: %s)\n",
server_name, account.userid,
account.passwd, ip);
- printf("Connection of the char-server '%s' accepted.\n",
+ PRINTF("Connection of the char-server '%s' accepted.\n",
server_name);
memset(&server[account.account_id], 0,
sizeof(struct mmo_char_server));
@@ -3674,7 +3387,7 @@ void parse_login(int fd)
}
else
{
- login_log("Connexion of the char-server '%s' REFUSED (account: %s, pass: %s, ip: %s)\n",
+ LOGIN_LOG("Connexion of the char-server '%s' REFUSED (account: %s, pass: %s, ip: %s)\n",
server_name, account.userid,
account.passwd, ip);
WFIFOW(fd, 0) = 0x2711;
@@ -3686,7 +3399,7 @@ void parse_login(int fd)
return;
case 0x7530: // Request of the server version
- login_log("Sending of the server version (ip: %s)\n",
+ LOGIN_LOG("Sending of the server version (ip: %s)\n",
ip);
WFIFOW(fd, 0) = 0x7531;
WFIFOB(fd, 2) = -1;
@@ -3699,7 +3412,7 @@ void parse_login(int fd)
break;
case 0x7532: // Request to end connection
- login_log("End of connection (ip: %s)\n", ip);
+ LOGIN_LOG("End of connection (ip: %s)\n", ip);
session[fd]->eof = 1;
return;
@@ -3711,7 +3424,7 @@ void parse_login(int fd)
WFIFOB(fd, 2) = 1;
if (!check_ladminip(session[fd]->client_addr.sin_addr))
{
- login_log("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s).\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode refused: IP isn't authorised (ladmin_allow, ip: %s).\n",
ip);
}
else
@@ -3727,23 +3440,23 @@ void parse_login(int fd)
if ((admin_state == 1)
&& (strcmp(password, admin_pass) == 0))
{
- login_log("'ladmin'-login: Connection in administration mode accepted (non encrypted password: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode accepted (non encrypted password: %s, ip: %s)\n",
password, ip);
- printf("Connection of a remote administration accepted (non encrypted password).\n");
+ PRINTF("Connection of a remote administration accepted (non encrypted password).\n");
WFIFOB(fd, 2) = 0;
session[fd]->func_parse = parse_admin;
}
else if (admin_state != 1)
- login_log("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (non encrypted password: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (non encrypted password: %s, ip: %s)\n",
password, ip);
else
- login_log("'ladmin'-login: Connection in administration mode REFUSED - invalid password (non encrypted password: %s, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - invalid password (non encrypted password: %s, ip: %s)\n",
password, ip);
}
else
{ // encrypted password
if (!ld)
- printf("'ladmin'-login: error! MD5 key not created/requested for an administration login.\n");
+ PRINTF("'ladmin'-login: error! MD5 key not created/requested for an administration login.\n");
else
{
char md5str[64] = "";
@@ -3763,17 +3476,17 @@ void parse_login(int fd)
if ((admin_state == 1)
&& (memcmp(md5bin, RFIFOP(fd, 4), 16) == 0))
{
- login_log("'ladmin'-login: Connection in administration mode accepted (encrypted password, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode accepted (encrypted password, ip: %s)\n",
ip);
- printf("Connection of a remote administration accepted (encrypted password).\n");
+ PRINTF("Connection of a remote administration accepted (encrypted password).\n");
WFIFOB(fd, 2) = 0;
session[fd]->func_parse = parse_admin;
}
else if (admin_state != 1)
- login_log("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (encrypted password, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (encrypted password, ip: %s)\n",
ip);
else
- login_log("'ladmin'-login: Connection in administration mode REFUSED - invalid password (encrypted password, ip: %s)\n",
+ LOGIN_LOG("'ladmin'-login: Connection in administration mode REFUSED - invalid password (encrypted password, ip: %s)\n",
ip);
}
}
@@ -3786,23 +3499,20 @@ void parse_login(int fd)
if (save_unknown_packets)
{
FILE *logfp;
- char tmpstr[24];
- struct timeval tv;
logfp = fopen_(login_log_unknown_packets_filename, "a");
if (logfp)
{
- gettimeofday(&tv, NULL);
- strftime(tmpstr, 23, date_format,
- gmtime(&(tv.tv_sec)));
- fprintf(logfp,
- "%s.%03d: receiving of an unknown packet -> disconnection\n",
- tmpstr, (int) tv.tv_usec / 1000);
- fprintf(logfp,
+ timestamp_milliseconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ FPRINTF(logfp,
+ "%s: receiving of an unknown packet -> disconnection\n",
+ tmpstr);
+ FPRINTF(logfp,
"parse_login: connection #%d (ip: %s), packet: 0x%x (with being read: %d).\n",
fd, ip, RFIFOW(fd, 0),
RFIFOREST(fd));
- fprintf(logfp, "Detail (in hex):\n");
- fprintf(logfp,
+ FPRINTF(logfp, "Detail (in hex):\n");
+ FPRINTF(logfp,
"---- 00-01-02-03-04-05-06-07 08-09-0A-0B-0C-0D-0E-0F\n");
memset(tmpstr, '\0', sizeof(tmpstr));
@@ -3810,17 +3520,17 @@ void parse_login(int fd)
for (i = 0; i < RFIFOREST(fd); i++)
{
if ((i & 15) == 0)
- fprintf(logfp, "%04X ", i);
- fprintf(logfp, "%02x ", RFIFOB(fd, i));
+ FPRINTF(logfp, "%04X ", i);
+ FPRINTF(logfp, "%02x ", RFIFOB(fd, i));
if (RFIFOB(fd, i) > 0x1f)
tmpstr[i % 16] = RFIFOB(fd, i);
else
tmpstr[i % 16] = '.';
if ((i - 7) % 16 == 0) // -8 + 1
- fprintf(logfp, " ");
+ FPRINTF(logfp, " ");
else if ((i + 1) % 16 == 0)
{
- fprintf(logfp, " %s\n", tmpstr);
+ FPRINTF(logfp, " %s\n", tmpstr);
memset(tmpstr, '\0', sizeof(tmpstr));
}
}
@@ -3828,17 +3538,17 @@ void parse_login(int fd)
{
for (j = i; j % 16 != 0; j++)
{
- fprintf(logfp, " ");
+ FPRINTF(logfp, " ");
if ((j - 7) % 16 == 0) // -8 + 1
- fprintf(logfp, " ");
+ FPRINTF(logfp, " ");
}
- fprintf(logfp, " %s\n", tmpstr);
+ FPRINTF(logfp, " %s\n", tmpstr);
}
- fprintf(logfp, "\n");
+ FPRINTF(logfp, "\n");
fclose_(logfp);
}
}
- login_log("End of connection, unknown packet (ip: %s)\n", ip);
+ LOGIN_LOG("End of connection, unknown packet (ip: %s)\n", ip);
session[fd]->eof = 1;
return;
}
@@ -3852,10 +3562,7 @@ void parse_login(int fd)
static
int login_lan_config_read(const char *lancfgName)
{
- int j;
struct hostent *h = NULL;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
// set default configuration
strncpy(lan_char_ip, "127.0.0.1", sizeof(lan_char_ip));
@@ -3863,34 +3570,31 @@ int login_lan_config_read(const char *lancfgName)
subneti[1] = 0;
subneti[2] = 0;
subneti[3] = 1;
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = 255;
- fp = fopen_(lancfgName, "r");
+ std::ifstream in(lancfgName);
- if (fp == NULL)
+ if (!in.is_open())
{
- printf("***WARNING: LAN Support configuration file is not found: %s\n",
+ PRINTF("***WARNING: LAN Support configuration file is not found: %s\n",
lancfgName);
return 1;
}
- printf("---Start reading Lan Support configuration file\n");
+ PRINTF("---Start reading Lan Support configuration file\n");
- while (fgets(line, sizeof(line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
- continue;
-
- line[sizeof(line) - 1] = '\0';
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- remove_control_chars(w1);
- remove_control_chars(w2);
- if (strcasecmp(w1, "lan_char_ip") == 0)
- { // Read Char-Server Lan IP Address
- h = gethostbyname(w2);
+ if (w1 == "lan_char_ip")
+ {
+ // Read Char-Server Lan IP Address
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
sprintf(lan_char_ip, "%d.%d.%d.%d",
@@ -3901,55 +3605,58 @@ int login_lan_config_read(const char *lancfgName)
}
else
{
- strncpy(lan_char_ip, w2, sizeof(lan_char_ip));
- lan_char_ip[sizeof(lan_char_ip) - 1] = '\0';
+ strzcpy(lan_char_ip, w2.c_str(), sizeof(lan_char_ip));
}
- printf("LAN IP of char-server: %s.\n", lan_char_ip);
+ PRINTF("LAN IP of char-server: %s.\n", lan_char_ip);
}
- else if (strcasecmp(w1, "subnet") == 0)
- { // Read Subnetwork
- for (j = 0; j < 4; j++)
+ else if (w1 == "subnet")
+ {
+ // Read Subnetwork
+ for (int j = 0; j < 4; j++)
subneti[j] = 0;
- h = gethostbyname(w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subneti[j] = (unsigned char) h->h_addr[j];
}
else
{
- sscanf(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1],
+ SSCANF(w2, "%d.%d.%d.%d", &subneti[0], &subneti[1],
&subneti[2], &subneti[3]);
}
- printf("Sub-network of the char-server: %d.%d.%d.%d.\n",
+ PRINTF("Sub-network of the char-server: %d.%d.%d.%d.\n",
subneti[0], subneti[1], subneti[2], subneti[3]);
}
- else if (strcasecmp(w1, "subnetmask") == 0)
+ else if (w1 == "subnetmask")
{ // Read Subnetwork Mask
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = 255;
- h = gethostbyname(w2);
+ h = gethostbyname(w2.c_str());
if (h != NULL)
{
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
subnetmaski[j] = (unsigned char) h->h_addr[j];
}
else
{
- sscanf(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1],
+ SSCANF(w2, "%d.%d.%d.%d", &subnetmaski[0], &subnetmaski[1],
&subnetmaski[2], &subnetmaski[3]);
}
- printf("Sub-network mask of the char-server: %d.%d.%d.%d.\n",
+ PRINTF("Sub-network mask of the char-server: %d.%d.%d.%d.\n",
subnetmaski[0], subnetmaski[1], subnetmaski[2],
subnetmaski[3]);
}
+ else
+ {
+ PRINTF("WARNING: unknown lan-config key: %s", w1);
+ }
}
- fclose_(fp);
// log the LAN configuration
- login_log("The LAN configuration of the server is set:\n");
- login_log("- with LAN IP of char-server: %s.\n", lan_char_ip);
- login_log("- with the sub-network of the char-server: %d.%d.%d.%d/%d.%d.%d.%d.\n",
+ LOGIN_LOG("The LAN configuration of the server is set:\n");
+ LOGIN_LOG("- with LAN IP of char-server: %s.\n", lan_char_ip);
+ LOGIN_LOG("- with the sub-network of the char-server: %d.%d.%d.%d/%d.%d.%d.%d.\n",
subneti[0], subneti[1], subneti[2], subneti[3],
subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]);
@@ -3962,15 +3669,15 @@ int login_lan_config_read(const char *lancfgName)
p[1] = a1;
p[2] = a2;
p[3] = a3;
- printf("LAN test of LAN IP of the char-server: ");
+ PRINTF("LAN test of LAN IP of the char-server: ");
if (lan_ip_check(p) == 0)
{
- printf("\033[1;31m***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network\033[0m\n");
- login_log("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n");
+ PRINTF("\033[1;31m***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network\033[0m\n");
+ LOGIN_LOG("***ERROR: LAN IP of the char-server doesn't belong to the specified Sub-network.\n");
}
}
- printf("---End reading of Lan Support configuration file\n");
+ PRINTF("---End reading of Lan Support configuration file\n");
return 0;
}
@@ -3981,281 +3688,237 @@ int login_lan_config_read(const char *lancfgName)
static
int login_config_read(const char *cfgName)
{
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
- fp = fopen_(cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- printf("Configuration file (%s) not found.\n", cfgName);
+ PRINTF("Configuration file (%s) not found.\n", cfgName);
return 1;
}
- printf("---Start reading of Login Server configuration file (%s)\n",
+ PRINTF("---Start reading of Login Server configuration file (%s)\n",
cfgName);
- while (fgets(line, sizeof(line) - 1, fp))
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- line[sizeof(line) - 1] = '\0';
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2)
+ if (w1 == "admin_state")
{
- remove_control_chars(w1);
- remove_control_chars(w2);
-
- if (strcasecmp(w1, "admin_state") == 0)
- {
- admin_state = config_switch (w2);
- }
- else if (strcasecmp(w1, "admin_pass") == 0)
+ admin_state = config_switch(w2.c_str());
+ }
+ else if (w1 == "admin_pass")
+ {
+ strzcpy(admin_pass, w2.c_str(), sizeof(admin_pass));
+ }
+ else if (w1 == "ladminallowip")
+ {
+ if (w2 == "clear")
{
- strncpy(admin_pass, w2, sizeof(admin_pass));
- admin_pass[sizeof(admin_pass) - 1] = '\0';
+ if (access_ladmin_allow)
+ free(access_ladmin_allow);
+ access_ladmin_allow = NULL;
+ access_ladmin_allownum = 0;
}
- else if (strcasecmp(w1, "ladminallowip") == 0)
+ else
{
- if (strcasecmp(w2, "clear") == 0)
+ if (w2 == "all")
{
+ // reset all previous values
if (access_ladmin_allow)
free(access_ladmin_allow);
- access_ladmin_allow = NULL;
- access_ladmin_allownum = 0;
+ // set to all
+ CREATE(access_ladmin_allow, char, ACO_STRSIZE);
+ access_ladmin_allownum = 1;
}
- else
- {
- if (strcasecmp(w2, "all") == 0)
- {
- // reset all previous values
- if (access_ladmin_allow)
- free(access_ladmin_allow);
- // set to all
+ else if (w2[0]
+ && !(access_ladmin_allownum == 1
+ && access_ladmin_allow[0] == '\0'))
+ { // don't add IP if already 'all'
+ if (access_ladmin_allow)
+ RECREATE(access_ladmin_allow, char, (access_ladmin_allownum + 1) * ACO_STRSIZE);
+ else
CREATE(access_ladmin_allow, char, ACO_STRSIZE);
- access_ladmin_allownum = 1;
- }
- else if (w2[0]
- && !(access_ladmin_allownum == 1
- && access_ladmin_allow[0] == '\0'))
- { // don't add IP if already 'all'
- if (access_ladmin_allow)
- RECREATE(access_ladmin_allow, char, (access_ladmin_allownum + 1) * ACO_STRSIZE);
- else
- CREATE(access_ladmin_allow, char, ACO_STRSIZE);
- strncpy(access_ladmin_allow +
- (access_ladmin_allownum++) * ACO_STRSIZE, w2,
- ACO_STRSIZE);
- access_ladmin_allow[access_ladmin_allownum *
- ACO_STRSIZE - 1] = '\0';
- }
+ strzcpy(access_ladmin_allow + (access_ladmin_allownum++) * ACO_STRSIZE,
+ w2.c_str(), ACO_STRSIZE);
}
}
- else if (strcasecmp(w1, "gm_pass") == 0)
- {
- strncpy(gm_pass, w2, sizeof(gm_pass));
- gm_pass[sizeof(gm_pass) - 1] = '\0';
- }
- else if (strcasecmp(w1, "level_new_gm") == 0)
- {
- level_new_gm = atoi(w2);
- }
- else if (strcasecmp(w1, "new_account") == 0)
- {
- new_account_flag = config_switch (w2);
- }
- else if (strcasecmp(w1, "login_port") == 0)
- {
- login_port = atoi(w2);
- }
- else if (strcasecmp(w1, "account_filename") == 0)
- {
- strncpy(account_filename, w2, sizeof(account_filename));
- account_filename[sizeof(account_filename) - 1] = '\0';
- }
- else if (strcasecmp(w1, "gm_account_filename") == 0)
- {
- strncpy(GM_account_filename, w2,
- sizeof(GM_account_filename));
- GM_account_filename[sizeof(GM_account_filename) - 1] = '\0';
- }
- else if (strcasecmp(w1, "gm_account_filename_check_timer") == 0)
- {
- gm_account_filename_check_timer = atoi(w2);
- }
- else if (strcasecmp(w1, "login_log_filename") == 0)
- {
- strncpy(login_log_filename, w2, sizeof(login_log_filename));
- login_log_filename[sizeof(login_log_filename) - 1] = '\0';
- }
- else if (strcasecmp(w1, "login_log_unknown_packets_filename") == 0)
- {
- strncpy(login_log_unknown_packets_filename, w2,
- sizeof(login_log_unknown_packets_filename));
- login_log_unknown_packets_filename[sizeof(login_log_unknown_packets_filename)
- - 1] = '\0';
- }
- else if (strcasecmp(w1, "save_unknown_packets") == 0)
- {
- save_unknown_packets = config_switch (w2);
- }
- else if (strcasecmp(w1, "display_parse_login") == 0)
- {
- display_parse_login = config_switch (w2); // 0: no, 1: yes
- }
- else if (strcasecmp(w1, "display_parse_admin") == 0)
- {
- display_parse_admin = config_switch (w2); // 0: no, 1: yes
- }
- else if (strcasecmp(w1, "display_parse_fromchar") == 0)
- {
- display_parse_fromchar = config_switch (w2); // 0: no, 1: yes (without packet 0x2714), 2: all packets
- }
- else if (strcasecmp(w1, "date_format") == 0)
- { // note: never have more than 19 char for the date!
- switch (atoi(w2))
- {
- case 0:
- strcpy(date_format, "%d-%m-%Y %H:%M:%S"); // 31-12-2004 23:59:59
- break;
- case 1:
- strcpy(date_format, "%m-%d-%Y %H:%M:%S"); // 12-31-2004 23:59:59
- break;
- case 2:
- strcpy(date_format, "%Y-%d-%m %H:%M:%S"); // 2004-31-12 23:59:59
- break;
- case 3:
- strcpy(date_format, "%Y-%m-%d %H:%M:%S"); // 2004-12-31 23:59:59
- break;
- }
- }
- else if (strcasecmp(w1, "min_level_to_connect") == 0)
- {
- min_level_to_connect = atoi(w2);
- }
- else if (strcasecmp(w1, "add_to_unlimited_account") == 0)
- {
- add_to_unlimited_account = config_switch (w2);
- }
- else if (strcasecmp(w1, "start_limited_time") == 0)
- {
- start_limited_time = atoi(w2);
- }
- else if (strcasecmp(w1, "check_ip_flag") == 0)
- {
- check_ip_flag = config_switch (w2);
- }
- else if (strcasecmp(w1, "order") == 0)
+ }
+ else if (w1 == "gm_pass")
+ {
+ strzcpy(gm_pass, w2.c_str(), sizeof(gm_pass));
+ }
+ else if (w1 == "level_new_gm")
+ {
+ level_new_gm = atoi(w2.c_str());
+ }
+ else if (w1 == "new_account")
+ {
+ new_account_flag = config_switch(w2.c_str());
+ }
+ else if (w1 == "login_port")
+ {
+ login_port = atoi(w2.c_str());
+ }
+ else if (w1 == "account_filename")
+ {
+ strzcpy(account_filename, w2.c_str(), sizeof(account_filename));
+ }
+ else if (w1 == "gm_account_filename")
+ {
+ strzcpy(GM_account_filename, w2.c_str(), sizeof(GM_account_filename));
+ }
+ else if (w1 == "gm_account_filename_check_timer")
+ {
+ gm_account_filename_check_timer = atoi(w2.c_str());
+ }
+ else if (w1 == "login_log_filename")
+ {
+ strzcpy(login_log_filename, w2.c_str(), sizeof(login_log_filename));
+ }
+ else if (w1 == "login_log_unknown_packets_filename")
+ {
+ strzcpy(login_log_unknown_packets_filename, w2.c_str(),
+ sizeof(login_log_unknown_packets_filename));
+ }
+ else if (w1 == "save_unknown_packets")
+ {
+ save_unknown_packets = config_switch(w2.c_str());
+ }
+ else if (w1 == "display_parse_login")
+ {
+ display_parse_login = config_switch(w2.c_str()); // 0: no, 1: yes
+ }
+ else if (w1 == "display_parse_admin")
+ {
+ display_parse_admin = config_switch(w2.c_str()); // 0: no, 1: yes
+ }
+ else if (w1 == "display_parse_fromchar")
+ {
+ display_parse_fromchar = config_switch(w2.c_str()); // 0: no, 1: yes (without packet 0x2714), 2: all packets
+ }
+ else if (w1 == "min_level_to_connect")
+ {
+ min_level_to_connect = atoi(w2.c_str());
+ }
+ else if (w1 == "add_to_unlimited_account")
+ {
+ add_to_unlimited_account = config_switch(w2.c_str());
+ }
+ else if (w1 == "start_limited_time")
+ {
+ start_limited_time = atoi(w2.c_str());
+ }
+ else if (w1 == "check_ip_flag")
+ {
+ check_ip_flag = config_switch(w2.c_str());
+ }
+ else if (w1 == "order")
+ {
+ access_order = atoi(w2.c_str());
+ if (w2 == "deny,allow" || w2 == "deny, allow")
+ access_order = ACO_DENY_ALLOW;
+ if (w2 == "allow,deny" || w2 == "allow, deny")
+ access_order = ACO_ALLOW_DENY;
+ if (w2 == "mutual-failture" || w2 == "mutual-failure")
+ access_order = ACO_MUTUAL_FAILTURE;
+ }
+ else if (w1 == "allow")
+ {
+ if (w2 == "clear")
{
- access_order = atoi(w2);
- if (strcasecmp(w2, "deny,allow") == 0 ||
- strcasecmp(w2, "deny, allow") == 0)
- access_order = ACO_DENY_ALLOW;
- if (strcasecmp(w2, "allow,deny") == 0 ||
- strcasecmp(w2, "allow, deny") == 0)
- access_order = ACO_ALLOW_DENY;
- if (strcasecmp(w2, "mutual-failture") == 0 ||
- strcasecmp(w2, "mutual-failure") == 0)
- access_order = ACO_MUTUAL_FAILTURE;
+ if (access_allow)
+ free(access_allow);
+ access_allow = NULL;
+ access_allownum = 0;
}
- else if (strcasecmp(w1, "allow") == 0)
+ else
{
- if (strcasecmp(w2, "clear") == 0)
+ if (w2 == "all")
{
+ // reset all previous values
if (access_allow)
free(access_allow);
- access_allow = NULL;
- access_allownum = 0;
+ // set to all
+ CREATE(access_allow, char, ACO_STRSIZE);
+ access_allownum = 1;
}
- else
- {
- if (strcasecmp(w2, "all") == 0)
- {
- // reset all previous values
- if (access_allow)
- free(access_allow);
- // set to all
+ else if (w2[0]
+ && !(access_allownum == 1
+ && access_allow[0] == '\0'))
+ { // don't add IP if already 'all'
+ if (access_allow)
+ RECREATE(access_allow, char, (access_allownum + 1) * ACO_STRSIZE);
+ else
CREATE(access_allow, char, ACO_STRSIZE);
- access_allownum = 1;
- }
- else if (w2[0]
- && !(access_allownum == 1
- && access_allow[0] == '\0'))
- { // don't add IP if already 'all'
- if (access_allow)
- RECREATE(access_allow, char, (access_allownum + 1) * ACO_STRSIZE);
- else
- CREATE(access_allow, char, ACO_STRSIZE);
- strncpy(access_allow +
- (access_allownum++) * ACO_STRSIZE, w2,
- ACO_STRSIZE);
- access_allow[access_allownum * ACO_STRSIZE - 1] =
- '\0';
- }
+ strzcpy(access_allow + (access_allownum++) * ACO_STRSIZE,
+ w2.c_str(), ACO_STRSIZE);
}
}
- else if (strcasecmp(w1, "deny") == 0)
+ }
+ else if (w1 == "deny")
+ {
+ if (w2 == "clear")
+ {
+ if (access_deny)
+ free(access_deny);
+ access_deny = NULL;
+ access_denynum = 0;
+ }
+ else
{
- if (strcasecmp(w2, "clear") == 0)
+ if (w2 == "all")
{
+ // reset all previous values
if (access_deny)
free(access_deny);
- access_deny = NULL;
- access_denynum = 0;
+ // set to all
+ CREATE(access_deny, char, ACO_STRSIZE);
+ access_denynum = 1;
}
- else
- {
- if (strcasecmp(w2, "all") == 0)
- {
- // reset all previous values
- if (access_deny)
- free(access_deny);
- // set to all
+ else if (!w2.empty()
+ && !(access_denynum == 1
+ && access_deny[0] == '\0'))
+ { // don't add IP if already 'all'
+ if (access_deny)
+ RECREATE(access_deny, char, (access_denynum + 1) * ACO_STRSIZE);
+ else
CREATE(access_deny, char, ACO_STRSIZE);
- access_denynum = 1;
- }
- else if (w2[0]
- && !(access_denynum == 1
- && access_deny[0] == '\0'))
- { // don't add IP if already 'all'
- if (access_deny)
- RECREATE(access_deny, char, (access_denynum + 1) * ACO_STRSIZE);
- else
- CREATE(access_deny, char, ACO_STRSIZE);
- strncpy(access_deny +
- (access_denynum++) * ACO_STRSIZE, w2,
- ACO_STRSIZE);
- access_deny[access_denynum * ACO_STRSIZE - 1] = '\0';
- }
+ strzcpy(access_deny + (access_denynum++) * ACO_STRSIZE,
+ w2.c_str(), ACO_STRSIZE);
}
}
- else if (strcasecmp(w1, "anti_freeze_enable") == 0)
- {
- anti_freeze_enable = config_switch (w2);
- }
- else if (strcasecmp(w1, "anti_freeze_interval") == 0)
- {
- ANTI_FREEZE_INTERVAL = atoi(w2);
- if (ANTI_FREEZE_INTERVAL < 5)
- ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds
- }
- else if (strcasecmp(w1, "import") == 0)
- {
- login_config_read(w2);
- }
- else if (strcasecmp(w1, "update_host") == 0)
- {
- strncpy(update_host, w2, sizeof(update_host));
- update_host[sizeof(update_host) - 1] = '\0';
- }
- else if (strcasecmp(w1, "main_server") == 0)
- {
- strncpy(main_server, w2, sizeof(main_server));
- main_server[sizeof(main_server) - 1] = '\0';
- }
+ }
+ else if (w1 == "anti_freeze_enable")
+ {
+ anti_freeze_enable = config_switch(w2.c_str());
+ }
+ else if (w1 == "anti_freeze_interval")
+ {
+ ANTI_FREEZE_INTERVAL = atoi(w2.c_str());
+ if (ANTI_FREEZE_INTERVAL < 5)
+ ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds
+ }
+ else if (w1 == "import")
+ {
+ login_config_read(w2.c_str());
+ }
+ else if (w1 == "update_host")
+ {
+ strzcpy(update_host, w2.c_str(), sizeof(update_host));
+ }
+ else if (w1 == "main_server")
+ {
+ strzcpy(main_server, w2.c_str(), sizeof(main_server));
+ }
+ else
+ {
+ PRINTF("WARNING: unknown login config key: %s", w1);
}
}
- fclose_(fp);
- printf("---End reading of Login Server configuration file.\n");
+ PRINTF("---End reading of Login Server configuration file.\n");
return 0;
}
@@ -4268,7 +3931,7 @@ void display_conf_warnings(void)
{
if (admin_state != 0 && admin_state != 1)
{
- printf("***WARNING: Invalid value for admin_state parameter -> set to 0 (no remote admin).\n");
+ PRINTF("***WARNING: Invalid value for admin_state parameter -> set to 0 (no remote admin).\n");
admin_state = 0;
}
@@ -4276,117 +3939,117 @@ void display_conf_warnings(void)
{
if (admin_pass[0] == '\0')
{
- printf("***WARNING: Administrator password is void (admin_pass).\n");
+ PRINTF("***WARNING: Administrator password is void (admin_pass).\n");
}
else if (strcmp(admin_pass, "admin") == 0)
{
- printf("***WARNING: You are using the default administrator password (admin_pass).\n");
- printf(" We highly recommend that you change it.\n");
+ PRINTF("***WARNING: You are using the default administrator password (admin_pass).\n");
+ PRINTF(" We highly recommend that you change it.\n");
}
}
if (gm_pass[0] == '\0')
{
- printf("***WARNING: 'To GM become' password is void (gm_pass).\n");
- printf(" We highly recommend that you set one password.\n");
+ PRINTF("***WARNING: 'To GM become' password is void (gm_pass).\n");
+ PRINTF(" We highly recommend that you set one password.\n");
}
else if (strcmp(gm_pass, "gm") == 0)
{
- printf("***WARNING: You are using the default GM password (gm_pass).\n");
- printf(" We highly recommend that you change it.\n");
+ PRINTF("***WARNING: You are using the default GM password (gm_pass).\n");
+ PRINTF(" We highly recommend that you change it.\n");
}
if (level_new_gm < 0 || level_new_gm > 99)
{
- printf("***WARNING: Invalid value for level_new_gm parameter -> set to 60 (default).\n");
+ PRINTF("***WARNING: Invalid value for level_new_gm parameter -> set to 60 (default).\n");
level_new_gm = 60;
}
if (new_account_flag != 0 && new_account_flag != 1)
{
- printf("***WARNING: Invalid value for new_account parameter -> set to 0 (no new account).\n");
+ PRINTF("***WARNING: Invalid value for new_account parameter -> set to 0 (no new account).\n");
new_account_flag = 0;
}
if (login_port < 1024 || login_port > 65535)
{
- printf("***WARNING: Invalid value for login_port parameter -> set to 6900 (default).\n");
+ PRINTF("***WARNING: Invalid value for login_port parameter -> set to 6900 (default).\n");
login_port = 6900;
}
if (gm_account_filename_check_timer < 0)
{
- printf("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
- printf(" -> set to 15 sec (default).\n");
+ PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
+ PRINTF(" -> set to 15 sec (default).\n");
gm_account_filename_check_timer = 15;
}
else if (gm_account_filename_check_timer == 1)
{
- printf("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
- printf(" -> set to 2 sec (minimum value).\n");
+ PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
+ PRINTF(" -> set to 2 sec (minimum value).\n");
gm_account_filename_check_timer = 2;
}
if (save_unknown_packets != 0 && save_unknown_packets != 1)
{
- printf("WARNING: Invalid value for save_unknown_packets parameter -> set to 0-no save.\n");
+ PRINTF("WARNING: Invalid value for save_unknown_packets parameter -> set to 0-no save.\n");
save_unknown_packets = 0;
}
if (display_parse_login != 0 && display_parse_login != 1)
{ // 0: no, 1: yes
- printf("***WARNING: Invalid value for display_parse_login parameter\n");
- printf(" -> set to 0 (no display).\n");
+ PRINTF("***WARNING: Invalid value for display_parse_login parameter\n");
+ PRINTF(" -> set to 0 (no display).\n");
display_parse_login = 0;
}
if (display_parse_admin != 0 && display_parse_admin != 1)
{ // 0: no, 1: yes
- printf("***WARNING: Invalid value for display_parse_admin parameter\n");
- printf(" -> set to 0 (no display).\n");
+ PRINTF("***WARNING: Invalid value for display_parse_admin parameter\n");
+ PRINTF(" -> set to 0 (no display).\n");
display_parse_admin = 0;
}
if (display_parse_fromchar < 0 || display_parse_fromchar > 2)
{ // 0: no, 1: yes (without packet 0x2714), 2: all packets
- printf("***WARNING: Invalid value for display_parse_fromchar parameter\n");
- printf(" -> set to 0 (no display).\n");
+ PRINTF("***WARNING: Invalid value for display_parse_fromchar parameter\n");
+ PRINTF(" -> set to 0 (no display).\n");
display_parse_fromchar = 0;
}
if (min_level_to_connect < 0)
{ // 0: all players, 1-99 at least gm level x
- printf("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n",
+ PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n",
min_level_to_connect);
- printf(" -> set to 0 (any player).\n");
+ PRINTF(" -> set to 0 (any player).\n");
min_level_to_connect = 0;
}
else if (min_level_to_connect > 99)
{ // 0: all players, 1-99 at least gm level x
- printf("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n",
+ PRINTF("***WARNING: Invalid value for min_level_to_connect (%d) parameter\n",
min_level_to_connect);
- printf(" -> set to 99 (only GM level 99).\n");
+ PRINTF(" -> set to 99 (only GM level 99).\n");
min_level_to_connect = 99;
}
if (add_to_unlimited_account != 0 && add_to_unlimited_account != 1)
{ // 0: no, 1: yes
- printf("***WARNING: Invalid value for add_to_unlimited_account parameter\n");
- printf(" -> set to 0 (impossible to add a time to an unlimited account).\n");
+ PRINTF("***WARNING: Invalid value for add_to_unlimited_account parameter\n");
+ PRINTF(" -> set to 0 (impossible to add a time to an unlimited account).\n");
add_to_unlimited_account = 0;
}
if (start_limited_time < -1)
{ // -1: create unlimited account, 0 or more: additionnal sec from now to create limited time
- printf("***WARNING: Invalid value for start_limited_time parameter\n");
- printf(" -> set to -1 (new accounts are created with unlimited time).\n");
+ PRINTF("***WARNING: Invalid value for start_limited_time parameter\n");
+ PRINTF(" -> set to -1 (new accounts are created with unlimited time).\n");
start_limited_time = -1;
}
if (check_ip_flag != 0 && check_ip_flag != 1)
{ // 0: no, 1: yes
- printf("***WARNING: Invalid value for check_ip_flag parameter\n");
- printf(" -> set to 1 (check players ip between login-server & char-server).\n");
+ PRINTF("***WARNING: Invalid value for check_ip_flag parameter\n");
+ PRINTF(" -> set to 1 (check players ip between login-server & char-server).\n");
check_ip_flag = 1;
}
@@ -4394,31 +4057,31 @@ void display_conf_warnings(void)
{
if (access_denynum == 1 && access_deny[0] == '\0')
{
- printf("***WARNING: The IP security order is 'deny,allow' (allow if not deny).\n");
- printf(" And you refuse ALL IP.\n");
+ PRINTF("***WARNING: The IP security order is 'deny,allow' (allow if not deny).\n");
+ PRINTF(" And you refuse ALL IP.\n");
}
}
else if (access_order == ACO_ALLOW_DENY)
{
if (access_allownum == 0)
{
- printf("***WARNING: The IP security order is 'allow,deny' (deny if not allow).\n");
- printf(" But, NO IP IS AUTHORISED!\n");
+ PRINTF("***WARNING: The IP security order is 'allow,deny' (deny if not allow).\n");
+ PRINTF(" But, NO IP IS AUTHORISED!\n");
}
}
else
{ // ACO_MUTUAL_FAILTURE
if (access_allownum == 0)
{
- printf("***WARNING: The IP security order is 'mutual-failture'\n");
- printf(" (allow if in the allow list and not in the deny list).\n");
- printf(" But, NO IP IS AUTHORISED!\n");
+ PRINTF("***WARNING: The IP security order is 'mutual-failture'\n");
+ PRINTF(" (allow if in the allow list and not in the deny list).\n");
+ PRINTF(" But, NO IP IS AUTHORISED!\n");
}
else if (access_denynum == 1 && access_deny[0] == '\0')
{
- printf("***WARNING: The IP security order is mutual-failture\n");
- printf(" (allow if in the allow list and not in the deny list).\n");
- printf(" But, you refuse ALL IP!\n");
+ PRINTF("***WARNING: The IP security order is mutual-failture\n");
+ PRINTF(" (allow if in the allow list and not in the deny list).\n");
+ PRINTF(" But, you refuse ALL IP!\n");
}
}
@@ -4434,124 +4097,124 @@ void save_config_in_log(void)
int i;
// a newline in the log...
- login_log("");
- login_log("The login-server starting...\n");
+ LOGIN_LOG("");
+ LOGIN_LOG("The login-server starting...\n");
// save configuration in log file
- login_log("The configuration of the server is set:\n");
+ LOGIN_LOG("The configuration of the server is set:\n");
if (admin_state != 1)
- login_log("- with no remote administration.\n");
+ LOGIN_LOG("- with no remote administration.\n");
else if (admin_pass[0] == '\0')
- login_log("- with a remote administration with a VOID password.\n");
+ LOGIN_LOG("- with a remote administration with a VOID password.\n");
else if (strcmp(admin_pass, "admin") == 0)
- login_log("- with a remote administration with the DEFAULT password.\n");
+ LOGIN_LOG("- with a remote administration with the DEFAULT password.\n");
else
- login_log("- with a remote administration with the password of %d character(s).\n",
+ LOGIN_LOG("- with a remote administration with the password of %d character(s).\n",
strlen(admin_pass));
if (access_ladmin_allownum == 0
|| (access_ladmin_allownum == 1 && access_ladmin_allow[0] == '\0'))
{
- login_log("- to accept any IP for remote administration\n");
+ LOGIN_LOG("- to accept any IP for remote administration\n");
}
else
{
- login_log("- to accept following IP for remote administration:\n");
+ LOGIN_LOG("- to accept following IP for remote administration:\n");
for (i = 0; i < access_ladmin_allownum; i++)
- login_log(" %s\n",
+ LOGIN_LOG(" %s\n",
(char *)(access_ladmin_allow + i * ACO_STRSIZE));
}
if (gm_pass[0] == '\0')
- login_log("- with a VOID 'To GM become' password (gm_pass).\n");
+ LOGIN_LOG("- with a VOID 'To GM become' password (gm_pass).\n");
else if (strcmp(gm_pass, "gm") == 0)
- login_log("- with the DEFAULT 'To GM become' password (gm_pass).\n");
+ LOGIN_LOG("- with the DEFAULT 'To GM become' password (gm_pass).\n");
else
- login_log("- with a 'To GM become' password (gm_pass) of %d character(s).\n",
+ LOGIN_LOG("- with a 'To GM become' password (gm_pass) of %d character(s).\n",
strlen(gm_pass));
if (level_new_gm == 0)
- login_log("- to refuse any creation of GM with @gm.\n");
+ LOGIN_LOG("- to refuse any creation of GM with @gm.\n");
else
- login_log("- to create GM with level '%d' when @gm is used.\n",
+ LOGIN_LOG("- to create GM with level '%d' when @gm is used.\n",
level_new_gm);
if (new_account_flag == 1)
- login_log("- to ALLOW new users (with _F/_M).\n");
+ LOGIN_LOG("- to ALLOW new users (with _F/_M).\n");
else
- login_log("- to NOT ALLOW new users (with _F/_M).\n");
- login_log("- with port: %d.\n", login_port);
- login_log("- with the accounts file name: '%s'.\n",
+ LOGIN_LOG("- to NOT ALLOW new users (with _F/_M).\n");
+ LOGIN_LOG("- with port: %d.\n", login_port);
+ LOGIN_LOG("- with the accounts file name: '%s'.\n",
account_filename);
- login_log("- with the GM accounts file name: '%s'.\n",
+ LOGIN_LOG("- with the GM accounts file name: '%s'.\n",
GM_account_filename);
if (gm_account_filename_check_timer == 0)
- login_log("- to NOT check GM accounts file modifications.\n");
+ LOGIN_LOG("- to NOT check GM accounts file modifications.\n");
else
- login_log("- to check GM accounts file modifications every %d seconds.\n",
+ LOGIN_LOG("- to check GM accounts file modifications every %d seconds.\n",
gm_account_filename_check_timer);
// not necessary to log the 'login_log_filename', we are inside :)
- login_log("- with the unknown packets file name: '%s'.\n",
+ LOGIN_LOG("- with the unknown packets file name: '%s'.\n",
login_log_unknown_packets_filename);
if (save_unknown_packets)
- login_log("- to SAVE all unkown packets.\n");
+ LOGIN_LOG("- to SAVE all unkown packets.\n");
else
- login_log("- to SAVE only unkown packets sending by a char-server or a remote administration.\n");
+ LOGIN_LOG("- to SAVE only unkown packets sending by a char-server or a remote administration.\n");
if (display_parse_login)
- login_log("- to display normal parse packets on console.\n");
+ LOGIN_LOG("- to display normal parse packets on console.\n");
else
- login_log("- to NOT display normal parse packets on console.\n");
+ LOGIN_LOG("- to NOT display normal parse packets on console.\n");
if (display_parse_admin)
- login_log("- to display administration parse packets on console.\n");
+ LOGIN_LOG("- to display administration parse packets on console.\n");
else
- login_log("- to NOT display administration parse packets on console.\n");
+ LOGIN_LOG("- to NOT display administration parse packets on console.\n");
if (display_parse_fromchar)
- login_log("- to display char-server parse packets on console.\n");
+ LOGIN_LOG("- to display char-server parse packets on console.\n");
else
- login_log("- to NOT display char-server parse packets on console.\n");
+ LOGIN_LOG("- to NOT display char-server parse packets on console.\n");
if (min_level_to_connect == 0) // 0: all players, 1-99 at least gm level x
- login_log("- with no minimum level for connection.\n");
+ LOGIN_LOG("- with no minimum level for connection.\n");
else if (min_level_to_connect == 99)
- login_log("- to accept only GM with level 99.\n");
+ LOGIN_LOG("- to accept only GM with level 99.\n");
else
- login_log("- to accept only GM with level %d or more.\n",
+ LOGIN_LOG("- to accept only GM with level %d or more.\n",
min_level_to_connect);
if (add_to_unlimited_account)
- login_log("- to authorize adjustment (with timeadd ladmin) on an unlimited account.\n");
+ LOGIN_LOG("- to authorize adjustment (with timeadd ladmin) on an unlimited account.\n");
else
- login_log("- to refuse adjustment (with timeadd ladmin) on an unlimited account. You must use timeset (ladmin command) before.\n");
+ LOGIN_LOG("- to refuse adjustment (with timeadd ladmin) on an unlimited account. You must use timeset (ladmin command) before.\n");
if (start_limited_time < 0)
- login_log("- to create new accounts with an unlimited time.\n");
+ LOGIN_LOG("- to create new accounts with an unlimited time.\n");
else if (start_limited_time == 0)
- login_log("- to create new accounts with a limited time: time of creation.\n");
+ LOGIN_LOG("- to create new accounts with a limited time: time of creation.\n");
else
- login_log("- to create new accounts with a limited time: time of creation + %d second(s).\n",
+ LOGIN_LOG("- to create new accounts with a limited time: time of creation + %d second(s).\n",
start_limited_time);
if (check_ip_flag)
- login_log("- with control of players IP between login-server and char-server.\n");
+ LOGIN_LOG("- with control of players IP between login-server and char-server.\n");
else
- login_log("- to not check players IP between login-server and char-server.\n");
+ LOGIN_LOG("- to not check players IP between login-server and char-server.\n");
if (access_order == ACO_DENY_ALLOW)
{
if (access_denynum == 0)
{
- login_log("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP.\n");
+ LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse no IP.\n");
}
else if (access_denynum == 1 && access_deny[0] == '\0')
{
- login_log("- with the IP security order: 'deny,allow' (allow if not deny). You refuse ALL IP.\n");
+ LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). You refuse ALL IP.\n");
}
else
{
- login_log("- with the IP security order: 'deny,allow' (allow if not deny). Refused IP are:\n");
+ LOGIN_LOG("- with the IP security order: 'deny,allow' (allow if not deny). Refused IP are:\n");
for (i = 0; i < access_denynum; i++)
- login_log(" %s\n",
+ LOGIN_LOG(" %s\n",
(char *)(access_deny + i * ACO_STRSIZE));
}
}
@@ -4559,47 +4222,47 @@ void save_config_in_log(void)
{
if (access_allownum == 0)
{
- login_log("- with the IP security order: 'allow,deny' (deny if not allow). But, NO IP IS AUTHORISED!\n");
+ LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). But, NO IP IS AUTHORISED!\n");
}
else if (access_allownum == 1 && access_allow[0] == '\0')
{
- login_log("- with the IP security order: 'allow,deny' (deny if not allow). You authorise ALL IP.\n");
+ LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). You authorise ALL IP.\n");
}
else
{
- login_log("- with the IP security order: 'allow,deny' (deny if not allow). Authorised IP are:\n");
+ LOGIN_LOG("- with the IP security order: 'allow,deny' (deny if not allow). Authorised IP are:\n");
for (i = 0; i < access_allownum; i++)
- login_log(" %s\n",
+ LOGIN_LOG(" %s\n",
(char *)(access_allow + i * ACO_STRSIZE));
}
}
else
{ // ACO_MUTUAL_FAILTURE
- login_log("- with the IP security order: 'mutual-failture' (allow if in the allow list and not in the deny list).\n");
+ LOGIN_LOG("- with the IP security order: 'mutual-failture' (allow if in the allow list and not in the deny list).\n");
if (access_allownum == 0)
{
- login_log(" But, NO IP IS AUTHORISED!\n");
+ LOGIN_LOG(" But, NO IP IS AUTHORISED!\n");
}
else if (access_denynum == 1 && access_deny[0] == '\0')
{
- login_log(" But, you refuse ALL IP!\n");
+ LOGIN_LOG(" But, you refuse ALL IP!\n");
}
else
{
if (access_allownum == 1 && access_allow[0] == '\0')
{
- login_log(" You authorise ALL IP.\n");
+ LOGIN_LOG(" You authorise ALL IP.\n");
}
else
{
- login_log(" Authorised IP are:\n");
+ LOGIN_LOG(" Authorised IP are:\n");
for (i = 0; i < access_allownum; i++)
- login_log(" %s\n",
+ LOGIN_LOG(" %s\n",
(char *)(access_allow + i * ACO_STRSIZE));
}
- login_log(" Refused IP are:\n");
+ LOGIN_LOG(" Refused IP are:\n");
for (i = 0; i < access_denynum; i++)
- login_log(" %s\n",
+ LOGIN_LOG(" %s\n",
(char *)(access_deny + i * ACO_STRSIZE));
}
}
@@ -4623,7 +4286,7 @@ void term_func(void)
}
delete_session(login_fd);
- login_log("----End of login-server (normal end with closing of all files).\n");
+ LOGIN_LOG("----End of login-server (normal end with closing of all files).\n");
}
//------------------------------
@@ -4671,10 +4334,10 @@ int do_init(int argc, char **argv)
// add_timer_func_list (check_GM_file, "check_GM_file");
i = add_timer_interval(gettick() + j * 1000, check_GM_file, 0, 0, j * 1000); // every x sec we check if gm file has been changed
- login_log("The login-server is ready (Server is listening on the port %d).\n",
+ LOGIN_LOG("The login-server is ready (Server is listening on the port %d).\n",
login_port);
- printf("The login-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
+ PRINTF("The login-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
login_port);
return 0;
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp
index 853d8b4..fa3d23d 100644
--- a/src/map/atcommand.cpp
+++ b/src/map/atcommand.cpp
@@ -8,7 +8,6 @@
#include <cctype>
#include <cmath>
-#include <cstdarg> // exception to "no va_list" rule
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -17,6 +16,7 @@
#include <array>
#include "../common/core.hpp"
+#include "../common/cxxstdio.hpp"
#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
@@ -76,7 +76,6 @@ ATCOMMAND_FUNC(gm);
ATCOMMAND_FUNC(pvpoff);
ATCOMMAND_FUNC(pvpon);
ATCOMMAND_FUNC(model);
-ATCOMMAND_FUNC(go);
ATCOMMAND_FUNC(spawn);
ATCOMMAND_FUNC(killmonster);
ATCOMMAND_FUNC(killmonster2);
@@ -243,7 +242,6 @@ AtCommandInfo atcommand_info[] = {
{AtCommand_PvPOff, "@pvpoff", 40, atcommand_pvpoff},
{AtCommand_PvPOn, "@pvpon", 40, atcommand_pvpon},
{AtCommand_Model, "@model", 20, atcommand_model},
- {AtCommand_Go, "@go", 10, atcommand_go},
{AtCommand_Spawn, "@spawn", 50, atcommand_spawn},
{AtCommand_KillMonster, "@killmonster", 60, atcommand_killmonster},
{AtCommand_KillMonster2, "@killmonster2", 40, atcommand_killmonster2},
@@ -556,22 +554,24 @@ int get_atcommand_level(const AtCommandType type)
return 100; // 100: command can not be used
}
-// TODO: remove the hard limit of 512
+static
+FILE *get_gm_log();
/*========================================
* At-command logging
*/
-void log_atcommand(struct map_session_data *sd, const char *fmt, ...)
+void log_atcommand(struct map_session_data *sd, const_string cmd)
{
- char message[512];
- va_list ap;
-
- va_start(ap, fmt);
- vsnprintf(message, 511, fmt, ap);
- va_end(ap);
-
- gm_log("%s(%d,%d) %s(%d) : %s", map[sd->bl.m].name, sd->bl.x,
- sd->bl.y, sd->status.name, sd->status.account_id, message);
+ FILE *fp = get_gm_log();
+ if (!fp)
+ return;
+ timestamp_seconds_buffer tmpstr;
+ stamp_time(tmpstr);
+ fprintf(fp, "[%s] %s(%d,%d) %s(%d) : ",
+ tmpstr,
+ map[sd->bl.m].name, sd->bl.x, sd->bl.y,
+ sd->status.name, sd->status.account_id);
+ fwrite(cmd.data(), 1, cmd.size(), fp);
}
char *gm_logfile_name = NULL;
@@ -579,54 +579,38 @@ char *gm_logfile_name = NULL;
* Log a timestamped line to GM log file
*------------------------------------------
*/
-void gm_log(const char *fmt, ...)
+FILE *get_gm_log()
{
- static int last_logfile_nr = 0;
- static FILE *gm_logfile = NULL;
- time_t time_v;
- struct tm ctime;
- int month, year, logfile_nr;
- char message[512];
- va_list ap;
-
if (!gm_logfile_name)
- return;
+ return NULL;
- va_start(ap, fmt);
- vsnprintf(message, 511, fmt, ap);
- va_end(ap);
+ time_t ts = time(NULL);
+ struct tm ctime = *gmtime(&ts);
- time(&time_v);
- gmtime_r(&time_v, &ctime);
+ int year = ctime.tm_year + 1900;
+ int month = ctime.tm_mon + 1;
+ int logfile_nr = (year * 12) + month;
- year = ctime.tm_year + 1900;
- month = ctime.tm_mon + 1;
- logfile_nr = (year * 12) + month;
+ static FILE *gm_logfile = NULL;
+ static int last_logfile_nr = 0;
+ if (logfile_nr == last_logfile_nr)
+ return gm_logfile;
+ last_logfile_nr = logfile_nr;
- if (logfile_nr != last_logfile_nr)
- {
- char *fullname = (char *)malloc(strlen(gm_logfile_name) + 10);
- sprintf(fullname, "%s.%04d-%02d", gm_logfile_name, year, month);
+ std::string fullname = STRPRINTF("%s.%04d-%02d",
+ gm_logfile_name, year, month);
- if (gm_logfile)
- fclose_(gm_logfile);
+ if (gm_logfile)
+ fclose_(gm_logfile);
- gm_logfile = fopen_(fullname, "a");
- free(fullname);
+ gm_logfile = fopen_(fullname.c_str(), "a");
- if (!gm_logfile)
- {
- perror("GM log file");
- gm_logfile_name = NULL;
- }
- last_logfile_nr = logfile_nr;
+ if (!gm_logfile)
+ {
+ perror("GM log file");
+ gm_logfile_name = NULL;
}
-
- fprintf(gm_logfile, "[%04d-%02d-%02d %02d:%02d:%02d] %s\n",
- year, month, ctime.tm_mday, ctime.tm_hour,
- ctime.tm_min, ctime.tm_sec, message);
-
- fflush(gm_logfile);
+ return gm_logfile;
}
static
@@ -636,16 +620,16 @@ AtCommandType atcommand(const int level, const char *message,
*is_atcommand @コマンドに存在するかどうか確認する
*------------------------------------------
*/
-AtCommandType is_atcommand(const int fd, struct map_session_data *sd, const char *message,
- int gmlvl)
+bool is_atcommand(const int fd, struct map_session_data *sd,
+ const char *message, int gmlvl)
{
AtCommandInfo info;
AtCommandType type;
- nullpo_retr(AtCommand_None, sd);
+ nullpo_retr(false, sd);
if (!message || !*message)
- return AtCommand_None;
+ return false;
memset(&info, 0, sizeof(info));
@@ -653,22 +637,21 @@ AtCommandType is_atcommand(const int fd, struct map_session_data *sd, const char
if (type != AtCommand_None)
{
char command[100];
- char output[200];
const char *str = message;
const char *p = message;
memset(command, '\0', sizeof(command));
- memset(output, '\0', sizeof(output));
while (*p && !isspace(*p))
p++;
if (p - str >= sizeof(command)) // too long
- return AtCommand_Unknown;
+ return true;
strncpy(command, str, p - str);
while (isspace(*p))
p++;
if (type == AtCommand_Unknown || info.proc == NULL)
{
- sprintf(output, "%s is Unknown Command.", command);
+ std::string output = STRPRINTF("%s is Unknown Command.",
+ command);
clif_displaymessage(fd, output);
}
else
@@ -676,20 +659,20 @@ AtCommandType is_atcommand(const int fd, struct map_session_data *sd, const char
if (info.proc(fd, sd, command, p) != 0)
{
// Command can not be executed
- sprintf(output, "%s failed.", command);
+ std::string output = STRPRINTF("%s failed.", command);
clif_displaymessage(fd, output);
}
else
{
if (get_atcommand_level(type) != 0) // Don't log level 0 commands
- log_atcommand(sd, "%s %s", command, p);
+ log_atcommand(sd, message);
}
}
- return info.type;
+ return true;
}
- return AtCommand_None;
+ return false;
}
/*==========================================
@@ -707,7 +690,7 @@ AtCommandType atcommand(const int level, const char *message,
return AtCommand_None;
if (!p || !*p)
{
- fprintf(stderr, "at command message is empty\n");
+ FPRINTF(stderr, "at command message is empty\n");
return AtCommand_None;
}
@@ -792,7 +775,7 @@ int atcommand_config_read(const char *cfgName)
if ((fp = fopen_(cfgName, "r")) == NULL)
{
- printf("At commands configuration file not found: %s\n", cfgName);
+ PRINTF("At commands configuration file not found: %s\n", cfgName);
return 1;
}
@@ -837,7 +820,6 @@ int atcommand_config_read(const char *cfgName)
int atcommand_setup(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char buf[256];
char character[100];
int level = 1;
@@ -851,26 +833,27 @@ int atcommand_setup(const int fd, struct map_session_data *sd,
}
level--;
- snprintf(buf, 255, "-255 %s", character);
- atcommand_character_baselevel(fd, sd, "@charbaselvl", buf);
+ std::string buf;
+ buf = STRPRINTF("-255 %s", character);
+ atcommand_character_baselevel(fd, sd, "@charbaselvl", buf.c_str());
- snprintf(buf, 255, "%d %s", level, character);
- atcommand_character_baselevel(fd, sd, "@charbaselvl", buf);
+ buf = STRPRINTF("%d %s", level, character);
+ atcommand_character_baselevel(fd, sd, "@charbaselvl", buf.c_str());
// Emote skill
- snprintf(buf, 255, "1 1 %s", character);
- atcommand_skill_learn(fd, sd, "@skill-learn", buf);
+ buf = STRPRINTF("1 1 %s", character);
+ atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str());
// Trade skill
- snprintf(buf, 255, "2 1 %s", character);
- atcommand_skill_learn(fd, sd, "@skill-learn", buf);
+ buf = STRPRINTF("2 1 %s", character);
+ atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str());
// Party skill
- snprintf(buf, 255, "2 2 %s", character);
- atcommand_skill_learn(fd, sd, "@skill-learn", buf);
+ STRPRINTF("2 2 %s", character);
+ atcommand_skill_learn(fd, sd, "@skill-learn", buf.c_str());
- snprintf(buf, 255, "018-1.gat 24 98 %s", character);
- atcommand_charwarp(fd, sd, "@charwarp", buf);
+ STRPRINTF("018-1.gat 24 98 %s", character);
+ atcommand_charwarp(fd, sd, "@charwarp", buf.c_str());
return (0);
@@ -1032,11 +1015,9 @@ int atcommand_where(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (sscanf(message, "%99[^\n]", character) < 1)
strcpy(character, sd->status.name);
@@ -1046,8 +1027,9 @@ int atcommand_where(const int fd, struct map_session_data *sd,
|| bool(pl_sd->status.option & Option::HIDE))
&& (pc_isGM(pl_sd) > pc_isGM(sd))))
{ // you can look only lower or same level
- sprintf(output, "%s: %s (%d,%d)", pl_sd->status.name, pl_sd->mapname,
- pl_sd->bl.x, pl_sd->bl.y);
+ std::string output = STRPRINTF("%s: %s (%d,%d)",
+ pl_sd->status.name,
+ pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
clif_displaymessage(fd, output);
}
else
@@ -1067,11 +1049,9 @@ int atcommand_goto(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -1097,7 +1077,7 @@ int atcommand_goto(const int fd, struct map_session_data *sd,
return -1;
}
pc_setpos(sd, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y, 3);
- sprintf(output, "Jump to %s", character);
+ std::string output = STRPRINTF("Jump to %s", character);
clif_displaymessage(fd, output);
}
else
@@ -1116,11 +1096,7 @@ int atcommand_goto(const int fd, struct map_session_data *sd,
int atcommand_jump(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char output[200];
int x = 0, y = 0;
-
- memset(output, '\0', sizeof(output));
-
sscanf(message, "%d %d", &x, &y);
if (x <= 0)
@@ -1144,7 +1120,7 @@ int atcommand_jump(const int fd, struct map_session_data *sd,
return -1;
}
pc_setpos(sd, sd->mapname, x, y, 3);
- sprintf(output, "Jump to %d %d", x, y);
+ std::string output = STRPRINTF("Jump to %d %d", x, y);
clif_displaymessage(fd, output);
}
else
@@ -1163,14 +1139,12 @@ int atcommand_jump(const int fd, struct map_session_data *sd,
int atcommand_who(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char output[200];
struct map_session_data *pl_sd;
int i, j, count;
int pl_GM_level, GM_level;
char match_text[100];
char player_name[24];
- memset(output, '\0', sizeof(output));
memset(match_text, '\0', sizeof(match_text));
memset(player_name, '\0', sizeof(player_name));
@@ -1196,16 +1170,19 @@ int atcommand_who(const int fd, struct map_session_data *sd,
for (j = 0; player_name[j]; j++)
player_name[j] = tolower(player_name[j]);
if (strstr(player_name, match_text) != NULL)
- { // search with no case sensitive
+ {
+ // search with no case sensitive
+ std::string output;
if (pl_GM_level > 0)
- sprintf(output,
- "Name: %s (GM:%d) | Location: %s %d %d",
- pl_sd->status.name, pl_GM_level,
- pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
+ output = STRPRINTF(
+ "Name: %s (GM:%d) | Location: %s %d %d",
+ pl_sd->status.name, pl_GM_level,
+ pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
else
- sprintf(output, "Name: %s | Location: %s %d %d",
- pl_sd->status.name, pl_sd->mapname,
- pl_sd->bl.x, pl_sd->bl.y);
+ output = STRPRINTF(
+ "Name: %s | Location: %s %d %d",
+ pl_sd->status.name, pl_sd->mapname,
+ pl_sd->bl.x, pl_sd->bl.y);
clif_displaymessage(fd, output);
count++;
}
@@ -1219,7 +1196,7 @@ int atcommand_who(const int fd, struct map_session_data *sd,
clif_displaymessage(fd, "1 player found.");
else
{
- sprintf(output, "%d players found.", count);
+ std::string output = STRPRINTF("%d players found.", count);
clif_displaymessage(fd, output);
}
@@ -1233,9 +1210,6 @@ int atcommand_who(const int fd, struct map_session_data *sd,
int atcommand_whogroup(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char temp0[100];
- char temp1[100];
- char output[200];
struct map_session_data *pl_sd;
int i, j, count;
int pl_GM_level, GM_level;
@@ -1243,9 +1217,6 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd,
char player_name[24];
struct party *p;
- memset(temp0, '\0', sizeof(temp0));
- memset(temp1, '\0', sizeof(temp1));
- memset(output, '\0', sizeof(output));
memset(match_text, '\0', sizeof(match_text));
memset(player_name, '\0', sizeof(player_name));
@@ -1273,18 +1244,12 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd,
if (strstr(player_name, match_text) != NULL)
{ // search with no case sensitive
p = party_search(pl_sd->status.party_id);
- if (p == NULL)
- sprintf(temp0, "None");
- else
- sprintf(temp0, "%s", p->name);
+ const char *temp0 = p ? p->name : "None";
+ std::string output;
if (pl_GM_level > 0)
- sprintf(output,
- "Name: %s (GM:%d) | Party: '%s'",
- pl_sd->status.name, pl_GM_level, temp0);
- else
- sprintf(output,
- "Name: %s | Party: '%s' | Guild: '%s'",
- pl_sd->status.name, temp0, temp1);
+ output = STRPRINTF(
+ "Name: %s (GM:%d) | Party: '%s'",
+ pl_sd->status.name, pl_GM_level, temp0);
clif_displaymessage(fd, output);
count++;
}
@@ -1298,7 +1263,7 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd,
clif_displaymessage(fd, "1 player found.");
else
{
- sprintf(output, "%d players found.", count);
+ std::string output = STRPRINTF("%d players found.", count);
clif_displaymessage(fd, output);
}
@@ -1312,14 +1277,12 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd,
int atcommand_whomap(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char output[200];
struct map_session_data *pl_sd;
int i, count;
int pl_GM_level, GM_level;
int map_id;
char map_name[100];
- memset(output, '\0', sizeof(output));
memset(map_name, '\0', sizeof(map_name));
if (!message || !*message)
@@ -1348,15 +1311,17 @@ int atcommand_whomap(const int fd, struct map_session_data *sd,
{ // you can look only lower or same level
if (pl_sd->bl.m == map_id)
{
+ std::string output;
if (pl_GM_level > 0)
- sprintf(output,
- "Name: %s (GM:%d) | Location: %s %d %d",
- pl_sd->status.name, pl_GM_level,
- pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
+ output = STRPRINTF(
+ "Name: %s (GM:%d) | Location: %s %d %d",
+ pl_sd->status.name, pl_GM_level,
+ pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
else
- sprintf(output, "Name: %s | Location: %s %d %d",
- pl_sd->status.name, pl_sd->mapname,
- pl_sd->bl.x, pl_sd->bl.y);
+ output = STRPRINTF(
+ "Name: %s | Location: %s %d %d",
+ pl_sd->status.name, pl_sd->mapname,
+ pl_sd->bl.x, pl_sd->bl.y);
clif_displaymessage(fd, output);
count++;
}
@@ -1364,14 +1329,8 @@ int atcommand_whomap(const int fd, struct map_session_data *sd,
}
}
- if (count == 0)
- sprintf(output, "No player found in map '%s'.", map[map_id].name);
- else if (count == 1)
- sprintf(output, "1 player found in map '%s'.", map[map_id].name);
- else
- {
- sprintf(output, "%d players found in map '%s'.", count, map[map_id].name);
- }
+ std::string output = STRPRINTF("%d players found in map '%s'.",
+ count, map[map_id].name);
clif_displaymessage(fd, output);
return 0;
@@ -1384,8 +1343,6 @@ int atcommand_whomap(const int fd, struct map_session_data *sd,
int atcommand_whomapgroup(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char temp0[100];
- char output[200];
struct map_session_data *pl_sd;
int i, count;
int pl_GM_level, GM_level;
@@ -1393,8 +1350,6 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd,
char map_name[100];
struct party *p;
- memset(temp0, '\0', sizeof(temp0));
- memset(output, '\0', sizeof(output));
memset(map_name, '\0', sizeof(map_name));
if (!message || !*message)
@@ -1425,18 +1380,14 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd,
if (pl_sd->bl.m == map_id)
{
p = party_search(pl_sd->status.party_id);
- if (p == NULL)
- sprintf(temp0, "None");
- else
- sprintf(temp0, "%s", p->name);
+ const char *temp0 = p ? p->name : "None";
+ std::string output;
if (pl_GM_level > 0)
- sprintf(output,
- "Name: %s (GM:%d) | Party: '%s'",
- pl_sd->status.name, pl_GM_level, temp0);
+ output = STRPRINTF("Name: %s (GM:%d) | Party: '%s'",
+ pl_sd->status.name, pl_GM_level, temp0);
else
- sprintf(output,
- "Name: %s | Party: '%s'",
- pl_sd->status.name, temp0);
+ output = STRPRINTF("Name: %s | Party: '%s'",
+ pl_sd->status.name, temp0);
clif_displaymessage(fd, output);
count++;
}
@@ -1444,13 +1395,14 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd,
}
}
+ std::string output;
if (count == 0)
- sprintf(output, "No player found in map '%s'.", map[map_id].name);
+ output = STRPRINTF("No player found in map '%s'.", map[map_id].name);
else if (count == 1)
- sprintf(output, "1 player found in map '%s'.", map[map_id].name);
+ output = STRPRINTF("1 player found in map '%s'.", map[map_id].name);
else
{
- sprintf(output, "%d players found in map '%s'.", count, map[map_id].name);
+ output = STRPRINTF("%d players found in map '%s'.", count, map[map_id].name);
}
clif_displaymessage(fd, output);
@@ -1464,8 +1416,6 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd,
int atcommand_whogm(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char temp0[100];
- char output[200];
struct map_session_data *pl_sd;
int i, j, count;
int pl_GM_level, GM_level;
@@ -1473,8 +1423,6 @@ int atcommand_whogm(const int fd, struct map_session_data *sd,
char player_name[24];
struct party *p;
- memset(temp0, '\0', sizeof(temp0));
- memset(output, '\0', sizeof(output));
memset(match_text, '\0', sizeof(match_text));
memset(player_name, '\0', sizeof(player_name));
@@ -1497,30 +1445,31 @@ int atcommand_whogm(const int fd, struct map_session_data *sd,
((battle_config.hide_GM_session
|| bool(pl_sd->status.option & Option::HIDE))
&& (pl_GM_level > GM_level)))
- { // you can look only lower or same level
+ {
+ // you can look only lower or same level
memcpy(player_name, pl_sd->status.name, 24);
for (j = 0; player_name[j]; j++)
player_name[j] = tolower(player_name[j]);
if (strstr(player_name, match_text) != NULL)
- { // search with no case sensitive
- sprintf(output,
- "Name: %s (GM:%d) | Location: %s %d %d",
- pl_sd->status.name, pl_GM_level,
- pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
+ {
+ // search with no case sensitive
+ std::string output;
+ output = STRPRINTF(
+ "Name: %s (GM:%d) | Location: %s %d %d",
+ pl_sd->status.name, pl_GM_level,
+ pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
clif_displaymessage(fd, output);
- sprintf(output,
- " BLvl: %d | Job: %s (Lvl: %d)",
- pl_sd->status.base_level,
- job_name(pl_sd->status.pc_class),
- pl_sd->status.job_level);
+ output = STRPRINTF(
+ " BLvl: %d | Job: %s (Lvl: %d)",
+ pl_sd->status.base_level,
+ job_name(pl_sd->status.pc_class),
+ pl_sd->status.job_level);
clif_displaymessage(fd, output);
p = party_search(pl_sd->status.party_id);
- if (p == NULL)
- sprintf(temp0, "None");
- else
- sprintf(temp0, "%s", p->name);
- sprintf(output, " Party: '%s'",
- temp0);
+ const char *temp0 = p ? p->name : "None";
+ output = STRPRINTF(
+ " Party: '%s'",
+ temp0);
clif_displaymessage(fd, output);
count++;
}
@@ -1535,7 +1484,7 @@ int atcommand_whogm(const int fd, struct map_session_data *sd,
clif_displaymessage(fd, "1 GM found.");
else
{
- sprintf(output, "%d GMs found.", count);
+ std::string output = STRPRINTF("%d GMs found.", count);
clif_displaymessage(fd, output);
}
@@ -1598,21 +1547,16 @@ int atcommand_load(const int fd, struct map_session_data *sd,
int atcommand_speed(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char output[200];
- int speed;
-
- memset(output, '\0', sizeof(output));
-
if (!message || !*message)
{
- sprintf(output,
- "Please, enter a speed value (usage: @speed <%d-%d>).",
- MIN_WALK_SPEED, MAX_WALK_SPEED);
+ std::string output = STRPRINTF(
+ "Please, enter a speed value (usage: @speed <%d-%d>).",
+ MIN_WALK_SPEED, MAX_WALK_SPEED);
clif_displaymessage(fd, output);
return -1;
}
- speed = atoi(message);
+ int speed = atoi(message);
if (speed >= MIN_WALK_SPEED && speed <= MAX_WALK_SPEED)
{
sd->speed = speed;
@@ -1623,9 +1567,9 @@ int atcommand_speed(const int fd, struct map_session_data *sd,
}
else
{
- sprintf(output,
- "Please, enter a valid speed value (usage: @speed <%d-%d>).",
- MIN_WALK_SPEED, MAX_WALK_SPEED);
+ std::string output = STRPRINTF(
+ "Please, enter a valid speed value (usage: @speed <%d-%d>).",
+ MIN_WALK_SPEED, MAX_WALK_SPEED);
clif_displaymessage(fd, output);
return -1;
}
@@ -1837,10 +1781,6 @@ int atcommand_alive(const int fd, struct map_session_data *sd,
int atcommand_kami(const int fd, struct map_session_data *,
const char *, const char *message)
{
- char output[200];
-
- memset(output, '\0', sizeof(output));
-
if (!message || !*message)
{
clif_displaymessage(fd,
@@ -1848,8 +1788,7 @@ int atcommand_kami(const int fd, struct map_session_data *,
return -1;
}
- sscanf(message, "%199[^\n]", output);
- intif_GMmessage(output, strlen(output) + 1, 0);
+ intif_GMmessage(message, 0);
return 0;
}
@@ -2302,18 +2241,16 @@ int atcommand_model(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
int hair_style = 0, hair_color = 0, cloth_color = 0;
- char output[200];
-
- memset(output, '\0', sizeof(output));
if (!message || !*message
|| sscanf(message, "%d %d %d", &hair_style, &hair_color,
&cloth_color) < 1)
{
- sprintf(output,
- "Please, enter at least a value (usage: @model <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d>).",
- MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR,
- MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
+ std::string output = STRPRINTF(
+ "Please, enter at least a value (usage: @model <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d>).",
+ MIN_HAIR_STYLE, MAX_HAIR_STYLE,
+ MIN_HAIR_COLOR, MAX_HAIR_COLOR,
+ MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
clif_displaymessage(fd, output);
return -1;
}
@@ -2355,15 +2292,12 @@ int atcommand_dye(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
int cloth_color = 0;
- char output[200];
-
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1)
{
- sprintf(output,
- "Please, enter a clothes color (usage: @dye/@ccolor <clothes color: %d-%d>).",
- MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
+ std::string output = STRPRINTF(
+ "Please, enter a clothes color (usage: @dye/@ccolor <clothes color: %d-%d>).",
+ MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
clif_displaymessage(fd, output);
return -1;
}
@@ -2399,15 +2333,12 @@ int atcommand_hair_style(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
int hair_style = 0;
- char output[200];
-
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%d", &hair_style) < 1)
{
- sprintf(output,
- "Please, enter a hair style (usage: @hairstyle/@hstyle <hair ID: %d-%d>).",
- MIN_HAIR_STYLE, MAX_HAIR_STYLE);
+ std::string output = STRPRINTF(
+ "Please, enter a hair style (usage: @hairstyle/@hstyle <hair ID: %d-%d>).",
+ MIN_HAIR_STYLE, MAX_HAIR_STYLE);
clif_displaymessage(fd, output);
return -1;
}
@@ -2443,15 +2374,12 @@ int atcommand_hair_color(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
int hair_color = 0;
- char output[200];
-
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%d", &hair_color) < 1)
{
- sprintf(output,
- "Please, enter a hair color (usage: @haircolor/@hcolor <hair color: %d-%d>).",
- MIN_HAIR_COLOR, MAX_HAIR_COLOR);
+ std::string output = STRPRINTF(
+ "Please, enter a hair color (usage: @haircolor/@hcolor <hair color: %d-%d>).",
+ MIN_HAIR_COLOR, MAX_HAIR_COLOR);
clif_displaymessage(fd, output);
return -1;
}
@@ -2480,253 +2408,6 @@ int atcommand_hair_color(const int fd, struct map_session_data *sd,
}
/*==========================================
- * @go [city_number/city_name]: improved by [yor] to add city names and help
- *------------------------------------------
- */
-int atcommand_go(const int fd, struct map_session_data *sd,
- const char *, const char *message)
-{
- int i;
- int town;
- char map_name[100];
- char output[200];
- int m;
-
- struct
- {
- char map[16];
- int x, y;
- } data[] =
- {
- {
- "prontera.gat", 156, 191}, // 0=Prontera
- {
- "morocc.gat", 156, 93}, // 1=Morroc
- {
- "geffen.gat", 119, 59}, // 2=Geffen
- {
- "payon.gat", 162, 233}, // 3=Payon
- {
- "alberta.gat", 192, 147}, // 4=Alberta
- {
- "izlude.gat", 128, 114}, // 5=Izlude
- {
- "aldebaran.gat", 140, 131}, // 6=Al de Baran
- {
- "xmas.gat", 147, 134}, // 7=Lutie
- {
- "comodo.gat", 209, 143}, // 8=Comodo
- {
- "yuno.gat", 157, 51}, // 9=Yuno
- {
- "amatsu.gat", 198, 84}, // 10=Amatsu
- {
- "gonryun.gat", 160, 120}, // 11=Gon Ryun
- {
- "umbala.gat", 89, 157}, // 12=Umbala
- {
- "niflheim.gat", 21, 153}, // 13=Niflheim
- {
- "louyang.gat", 217, 40}, // 14=Lou Yang
- {
- "new_1-1.gat", 53, 111}, // 15=Start point
- {
- "sec_pri.gat", 23, 61}, // 16=Prison
- };
-
- memset(map_name, '\0', sizeof(map_name));
- memset(output, '\0', sizeof(output));
-
- // get the number
- town = atoi(message);
-
- // if no value, display all value
- if (!message || !*message || sscanf(message, "%99s", map_name) < 1
- || town < -3 || town >= (int)(sizeof(data) / sizeof(data[0])))
- {
- clif_displaymessage(fd, "Invalid location number or name.");
- clif_displaymessage(fd, "Please, use one of this number/name:");
- clif_displaymessage(fd,
- "-3=(Memo point 2) 4=Alberta 11=Gon Ryun");
- clif_displaymessage(fd,
- "-2=(Memo point 1) 5=Izlude 12=Umbala");
- clif_displaymessage(fd,
- "-1=(Memo point 0) 6=Al de Baran 13=Niflheim");
- clif_displaymessage(fd,
- " 0=Prontera 7=Lutie 14=Lou Yang");
- clif_displaymessage(fd,
- " 1=Morroc 8=Comodo 15=Start point");
- clif_displaymessage(fd,
- " 2=Geffen 9=Yuno 16=Prison");
- clif_displaymessage(fd, " 3=Payon 10=Amatsu");
- return -1;
- }
- else
- {
- // get possible name of the city and add .gat if not in the name
- map_name[sizeof(map_name) - 1] = '\0';
- for (i = 0; map_name[i]; i++)
- map_name[i] = tolower(map_name[i]);
- if (strstr(map_name, ".gat") == NULL && strstr(map_name, ".afm") == NULL && strlen(map_name) < 13) // 16 - 4 (.gat)
- strcat(map_name, ".gat");
- // try to see if it's a name, and not a number (try a lot of possibilities, write errors and abbreviations too)
- if (strncmp(map_name, "prontera.gat", 3) == 0)
- { // 3 first characters
- town = 0;
- }
- else if (strncmp(map_name, "morocc.gat", 3) == 0)
- { // 3 first characters
- town = 1;
- }
- else if (strncmp(map_name, "geffen.gat", 3) == 0)
- { // 3 first characters
- town = 2;
- }
- else if (strncmp(map_name, "payon.gat", 3) == 0 || // 3 first characters
- strncmp(map_name, "paion.gat", 3) == 0)
- { // writing error (3 first characters)
- town = 3;
- }
- else if (strncmp(map_name, "alberta.gat", 3) == 0)
- { // 3 first characters
- town = 4;
- }
- else if (strncmp(map_name, "izlude.gat", 3) == 0 || // 3 first characters
- strncmp(map_name, "islude.gat", 3) == 0)
- { // writing error (3 first characters)
- town = 5;
- }
- else if (strncmp(map_name, "aldebaran.gat", 3) == 0 || // 3 first characters
- strcmp(map_name, "al.gat") == 0)
- { // al (de baran)
- town = 6;
- }
- else if (strncmp(map_name, "lutie.gat", 3) == 0 || // name of the city, not name of the map (3 first characters)
- strcmp(map_name, "christmas.gat") == 0 || // name of the symbol
- strncmp(map_name, "xmas.gat", 3) == 0 || // 3 first characters
- strncmp(map_name, "x-mas.gat", 3) == 0)
- { // writing error (3 first characters)
- town = 7;
- }
- else if (strncmp(map_name, "comodo.gat", 3) == 0)
- { // 3 first characters
- town = 8;
- }
- else if (strncmp(map_name, "yuno.gat", 3) == 0)
- { // 3 first characters
- town = 9;
- }
- else if (strncmp(map_name, "amatsu.gat", 3) == 0 || // 3 first characters
- strncmp(map_name, "ammatsu.gat", 3) == 0)
- { // writing error (3 first characters)
- town = 10;
- }
- else if (strncmp(map_name, "gonryun.gat", 3) == 0)
- { // 3 first characters
- town = 11;
- }
- else if (strncmp(map_name, "umbala.gat", 3) == 0)
- { // 3 first characters
- town = 12;
- }
- else if (strncmp(map_name, "niflheim.gat", 3) == 0)
- { // 3 first characters
- town = 13;
- }
- else if (strncmp(map_name, "louyang.gat", 3) == 0)
- { // 3 first characters
- town = 14;
- }
- else if (strncmp(map_name, "new_1-1.gat", 3) == 0 || // 3 first characters (or "newbies")
- strncmp(map_name, "startpoint.gat", 3) == 0 || // name of the position (3 first characters)
- strncmp(map_name, "begining.gat", 3) == 0)
- { // name of the position (3 first characters)
- town = 15;
- }
- else if (strncmp(map_name, "sec_pri.gat", 3) == 0 || // 3 first characters
- strncmp(map_name, "prison.gat", 3) == 0 || // name of the position (3 first characters)
- strncmp(map_name, "jails.gat", 3) == 0)
- { // name of the position
- town = 16;
- }
-
- if (town >= -3 && town <= -1)
- {
- if (sd->status.memo_point[-town - 1].map[0])
- {
- m = map_mapname2mapid(sd->status.memo_point[-town - 1].map);
- if (m >= 0 && map[m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM(sd))
- {
- clif_displaymessage(fd,
- "You are not authorised to warp you to this memo map.");
- return -1;
- }
- if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM(sd))
- {
- clif_displaymessage(fd,
- "You are not authorised to warp you from your actual map.");
- return -1;
- }
- if (pc_setpos(sd, sd->status.memo_point[-town - 1].map,
- sd->status.memo_point[-town - 1].x,
- sd->status.memo_point[-town - 1].y, 3) == 0)
- {
- clif_displaymessage(fd, "Warped.");
- }
- else
- {
- clif_displaymessage(fd, "Map not found.");
- return -1;
- }
- }
- else
- {
- sprintf(output, "Your memo point #%d doesn't exist.", -town - 1);
- clif_displaymessage(fd, output);
- return -1;
- }
- }
- else if (town >= 0 && town < (int)(sizeof(data) / sizeof(data[0])))
- {
- m = map_mapname2mapid(data[town].map);
- if (m >= 0 && map[m].flag.nowarpto
- && battle_config.any_warp_GM_min_level > pc_isGM(sd))
- {
- clif_displaymessage(fd,
- "You are not authorised to warp you to this destination map.");
- return -1;
- }
- if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarp
- && battle_config.any_warp_GM_min_level > pc_isGM(sd))
- {
- clif_displaymessage(fd,
- "You are not authorised to warp you from your actual map.");
- return -1;
- }
- if (pc_setpos(sd, data[town].map, data[town].x, data[town].y, 3)
- == 0)
- {
- clif_displaymessage(fd, "Warped.");
- }
- else
- {
- clif_displaymessage(fd, "Map not found.");
- return -1;
- }
- }
- else
- { // if you arrive here, you have an error in town variable when reading of names
- clif_displaymessage(fd, "Invalid location number or name.");
- return -1;
- }
- }
-
- return 0;
-}
-
-/*==========================================
*
*------------------------------------------
*/
@@ -2734,7 +2415,6 @@ int atcommand_spawn(const int fd, struct map_session_data *sd,
const char *command, const char *message)
{
char monster[100];
- char output[200];
int mob_id;
int number = 0;
int x = 0, y = 0;
@@ -2743,7 +2423,6 @@ int atcommand_spawn(const int fd, struct map_session_data *sd,
int mx, my, range;
memset(monster, '\0', sizeof(monster));
- memset(output, '\0', sizeof(output));
if (!message || !*message
|| sscanf(message, "%99s %d %d %d", monster, &number, &x, &y) < 1)
@@ -2777,7 +2456,7 @@ int atcommand_spawn(const int fd, struct map_session_data *sd,
number = battle_config.atc_spawn_quantity_limit;
if (battle_config.etc_log)
- printf("%s monster='%s' id=%d count=%d (%d,%d)\n", command, monster,
+ PRINTF("%s monster='%s' id=%d count=%d (%d,%d)\n", command, monster,
mob_id, number, x, y);
count = 0;
@@ -2808,7 +2487,8 @@ int atcommand_spawn(const int fd, struct map_session_data *sd,
clif_displaymessage(fd, "All monster summoned!");
else
{
- sprintf(output, "%d monster(s) summoned!", count);
+ std::string output = STRPRINTF("%d monster(s) summoned!",
+ count);
clif_displaymessage(fd, output);
}
else
@@ -2870,10 +2550,10 @@ int atcommand_killmonster(const int fd, struct map_session_data *sd,
static
void atlist_nearby_sub(struct block_list *bl, int fd)
{
- char buf[32];
nullpo_retv(bl);
- sprintf(buf, " - \"%s\"", ((struct map_session_data *) bl)->status.name);
+ std::string buf = STRPRINTF(" - \"%s\"",
+ ((struct map_session_data *) bl)->status.name);
clif_displaymessage(fd, buf);
}
@@ -2915,9 +2595,7 @@ int atcommand_produce(const int fd, struct map_session_data *sd,
int item_id, attribute = 0, star = 0;
struct item_data *item_data;
struct item tmp_item;
- char output[200];
- memset(output, '\0', sizeof(output));
memset(item_name, '\0', sizeof(item_name));
if (!message || !*message
@@ -2957,11 +2635,12 @@ int atcommand_produce(const int fd, struct map_session_data *sd,
else
{
if (battle_config.error_log)
- printf("@produce NOT WEAPON [%d]\n", item_id);
+ PRINTF("@produce NOT WEAPON [%d]\n", item_id);
+ std::string output;
if (item_id != 0 && itemdb_exists(item_id))
- sprintf(output, "This item (%d: '%s') is not an equipment.", item_id, item_data->name);
+ output = STRPRINTF("This item (%d: '%s') is not an equipment.", item_id, item_data->name);
else
- sprintf(output, "%s", "This item is not an equipment.");
+ output = STRPRINTF("%s", "This item is not an equipment.");
clif_displaymessage(fd, output);
return -1;
}
@@ -2976,21 +2655,19 @@ int atcommand_produce(const int fd, struct map_session_data *sd,
static
void atcommand_memo_sub(struct map_session_data *sd)
{
- int i;
- char output[200];
-
- memset(output, '\0', sizeof(output));
-
clif_displaymessage(sd->fd,
"Your actual memo positions are (except respawn point):");
- for (i = MIN_PORTAL_MEMO; i <= MAX_PORTAL_MEMO; i++)
+ for (int i = MIN_PORTAL_MEMO; i <= MAX_PORTAL_MEMO; i++)
{
+ std::string output;
if (sd->status.memo_point[i].map[0])
- sprintf(output, "%d - %s (%d,%d)", i,
- sd->status.memo_point[i].map, sd->status.memo_point[i].x,
- sd->status.memo_point[i].y);
+ output = STRPRINTF("%d - %s (%d,%d)",
+ i,
+ sd->status.memo_point[i].map,
+ sd->status.memo_point[i].x,
+ sd->status.memo_point[i].y);
else
- sprintf(output, "%d - void", i);
+ output = STRPRINTF("%d - void", i);
clif_displaymessage(sd->fd, output);
}
@@ -3005,9 +2682,6 @@ int atcommand_memo(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
int position = 0;
- char output[200];
-
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%d", &position) < 1)
atcommand_memo_sub(sd);
@@ -3024,7 +2698,12 @@ int atcommand_memo(const int fd, struct map_session_data *sd,
}
if (sd->status.memo_point[position].map[0])
{
- sprintf(output, "You replace previous memo position %d - %s (%d,%d).", position, sd->status.memo_point[position].map, sd->status.memo_point[position].x, sd->status.memo_point[position].y);
+ std::string output = STRPRINTF(
+ "You replace previous memo position %d - %s (%d,%d).",
+ position,
+ sd->status.memo_point[position].map,
+ sd->status.memo_point[position].x,
+ sd->status.memo_point[position].y);
clif_displaymessage(fd, output);
}
memcpy(sd->status.memo_point[position].map, map[sd->bl.m].name,
@@ -3037,9 +2716,9 @@ int atcommand_memo(const int fd, struct map_session_data *sd,
}
else
{
- sprintf(output,
- "Please, enter a valid position (usage: @memo <memo_position:%d-%d>).",
- MIN_PORTAL_MEMO, MAX_PORTAL_MEMO);
+ std::string output = STRPRINTF(
+ "Please, enter a valid position (usage: @memo <memo_position:%d-%d>).",
+ MIN_PORTAL_MEMO, MAX_PORTAL_MEMO);
clif_displaymessage(fd, output);
atcommand_memo_sub(sd);
return -1;
@@ -3056,20 +2735,18 @@ int atcommand_memo(const int fd, struct map_session_data *sd,
int atcommand_gat(const int fd, struct map_session_data *sd,
const char *, const char *)
{
- char output[200];
int y;
- memset(output, '\0', sizeof(output));
-
for (y = 2; y >= -2; y--)
{
- sprintf(output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
- map[sd->bl.m].name, sd->bl.x - 2, sd->bl.y + y,
- map_getcell(sd->bl.m, sd->bl.x - 2, sd->bl.y + y),
- map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y),
- map_getcell(sd->bl.m, sd->bl.x, sd->bl.y + y),
- map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y),
- map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y));
+ std::string output = STRPRINTF(
+ "%s (x= %d, y= %d) %02X %02X %02X %02X %02X",
+ map[sd->bl.m].name, sd->bl.x - 2, sd->bl.y + y,
+ map_getcell(sd->bl.m, sd->bl.x - 2, sd->bl.y + y),
+ map_getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y),
+ map_getcell(sd->bl.m, sd->bl.x, sd->bl.y + y),
+ map_getcell(sd->bl.m, sd->bl.x + 1, sd->bl.y + y),
+ map_getcell(sd->bl.m, sd->bl.x + 2, sd->bl.y + y));
clif_displaymessage(fd, output);
}
@@ -3226,16 +2903,15 @@ int atcommand_param(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
int value = 0, new_value;
- char output[200];
-
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%d", &value) < 1
|| value == 0)
{
- sprintf(output,
- "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>).");
- clif_displaymessage(fd, output);
+
+ // there was a clang bug here
+ // fortunately, STRPRINTF was not actually needed
+ clif_displaymessage(fd,
+ "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>).");
return -1;
}
@@ -3320,11 +2996,9 @@ int atcommand_recall(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -3352,7 +3026,7 @@ int atcommand_recall(const int fd, struct map_session_data *sd,
return -1;
}
pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2);
- sprintf(output, "%s recalled!", character);
+ std::string output = STRPRINTF("%s recalled!", character);
clif_displaymessage(fd, output);
}
else
@@ -3417,11 +3091,9 @@ int atcommand_character_stats(const int fd, struct map_session_data *,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -3432,34 +3104,35 @@ int atcommand_character_stats(const int fd, struct map_session_data *,
if ((pl_sd = map_nick2sd(character)) != NULL)
{
- sprintf(output, "'%s' stats:", pl_sd->status.name);
+ std::string output;
+ output = STRPRINTF("'%s' stats:", pl_sd->status.name);
clif_displaymessage(fd, output);
- sprintf(output, "Base Level - %d", pl_sd->status.base_level),
+ output = STRPRINTF("Base Level - %d", pl_sd->status.base_level),
clif_displaymessage(fd, output);
- sprintf(output, "Job - %s (level %d)",
+ output = STRPRINTF("Job - %s (level %d)",
job_name(pl_sd->status.pc_class), pl_sd->status.job_level);
clif_displaymessage(fd, output);
- sprintf(output, "Hp - %d", pl_sd->status.hp);
+ output = STRPRINTF("Hp - %d", pl_sd->status.hp);
clif_displaymessage(fd, output);
- sprintf(output, "MaxHp - %d", pl_sd->status.max_hp);
+ output = STRPRINTF("MaxHp - %d", pl_sd->status.max_hp);
clif_displaymessage(fd, output);
- sprintf(output, "Sp - %d", pl_sd->status.sp);
+ output = STRPRINTF("Sp - %d", pl_sd->status.sp);
clif_displaymessage(fd, output);
- sprintf(output, "MaxSp - %d", pl_sd->status.max_sp);
+ output = STRPRINTF("MaxSp - %d", pl_sd->status.max_sp);
clif_displaymessage(fd, output);
- sprintf(output, "Str - %3d", pl_sd->status.attrs[ATTR::STR]);
+ output = STRPRINTF("Str - %3d", pl_sd->status.attrs[ATTR::STR]);
clif_displaymessage(fd, output);
- sprintf(output, "Agi - %3d", pl_sd->status.attrs[ATTR::AGI]);
+ output = STRPRINTF("Agi - %3d", pl_sd->status.attrs[ATTR::AGI]);
clif_displaymessage(fd, output);
- sprintf(output, "Vit - %3d", pl_sd->status.attrs[ATTR::VIT]);
+ output = STRPRINTF("Vit - %3d", pl_sd->status.attrs[ATTR::VIT]);
clif_displaymessage(fd, output);
- sprintf(output, "Int - %3d", pl_sd->status.attrs[ATTR::INT]);
+ output = STRPRINTF("Int - %3d", pl_sd->status.attrs[ATTR::INT]);
clif_displaymessage(fd, output);
- sprintf(output, "Dex - %3d", pl_sd->status.attrs[ATTR::DEX]);
+ output = STRPRINTF("Dex - %3d", pl_sd->status.attrs[ATTR::DEX]);
clif_displaymessage(fd, output);
- sprintf(output, "Luk - %3d", pl_sd->status.attrs[ATTR::LUK]);
+ output = STRPRINTF("Luk - %3d", pl_sd->status.attrs[ATTR::LUK]);
clif_displaymessage(fd, output);
- sprintf(output, "Zeny - %d", pl_sd->status.zeny);
+ output = STRPRINTF("Zeny - %d", pl_sd->status.zeny);
clif_displaymessage(fd, output);
}
else
@@ -3479,38 +3152,39 @@ int atcommand_character_stats(const int fd, struct map_session_data *,
int atcommand_character_stats_all(const int fd, struct map_session_data *,
const char *, const char *)
{
- char output[1024], gmlevel[1024];
int i;
int count;
struct map_session_data *pl_sd;
- memset(output, '\0', sizeof(output));
- memset(gmlevel, '\0', sizeof(gmlevel));
-
count = 0;
for (i = 0; i < fd_max; i++)
{
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
-
+ std::string gmlevel;
if (pc_isGM(pl_sd) > 0)
- sprintf(gmlevel, "| GM Lvl: %d", pc_isGM(pl_sd));
+ gmlevel = STRPRINTF("| GM Lvl: %d", pc_isGM(pl_sd));
else
- sprintf(gmlevel, " ");
-
- sprintf(output,
- "Name: %s | BLvl: %d | Job: %s (Lvl: %d) | HP: %d/%d | SP: %d/%d",
- pl_sd->status.name, pl_sd->status.base_level,
- job_name(pl_sd->status.pc_class), pl_sd->status.job_level,
- pl_sd->status.hp, pl_sd->status.max_hp, pl_sd->status.sp,
- pl_sd->status.max_sp);
+ gmlevel = " ";
+
+ std::string output;
+ output = STRPRINTF(
+ "Name: %s | BLvl: %d | Job: %s (Lvl: %d) | HP: %d/%d | SP: %d/%d",
+ pl_sd->status.name, pl_sd->status.base_level,
+ job_name(pl_sd->status.pc_class), pl_sd->status.job_level,
+ pl_sd->status.hp, pl_sd->status.max_hp,
+ pl_sd->status.sp, pl_sd->status.max_sp);
clif_displaymessage(fd, output);
- sprintf(output,
- "STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s",
- pl_sd->status.attrs[ATTR::STR], pl_sd->status.attrs[ATTR::AGI], pl_sd->status.attrs[ATTR::VIT],
- pl_sd->status.attrs[ATTR::INT], pl_sd->status.attrs[ATTR::DEX], pl_sd->status.attrs[ATTR::LUK],
- pl_sd->status.zeny, gmlevel);
+ output = STRPRINTF("STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s",
+ pl_sd->status.attrs[ATTR::STR],
+ pl_sd->status.attrs[ATTR::AGI],
+ pl_sd->status.attrs[ATTR::VIT],
+ pl_sd->status.attrs[ATTR::INT],
+ pl_sd->status.attrs[ATTR::DEX],
+ pl_sd->status.attrs[ATTR::LUK],
+ pl_sd->status.zeny,
+ gmlevel);
clif_displaymessage(fd, output);
clif_displaymessage(fd, "--------");
count++;
@@ -3523,7 +3197,7 @@ int atcommand_character_stats_all(const int fd, struct map_session_data *,
clif_displaymessage(fd, "1 player found.");
else
{
- sprintf(output, "%d players found.", count);
+ std::string output = STRPRINTF("%d players found.", count);
clif_displaymessage(fd, output);
}
@@ -4673,12 +4347,10 @@ int atcommand_idsearch(const int fd, struct map_session_data *,
const char *, const char *message)
{
char item_name[100];
- char output[200];
int i, match;
struct item_data *item;
memset(item_name, '\0', sizeof(item_name));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99s", item_name) < 0)
{
@@ -4687,7 +4359,7 @@ int atcommand_idsearch(const int fd, struct map_session_data *,
return -1;
}
- sprintf(output, "The reference result of '%s' (name: id):", item_name);
+ std::string output = STRPRINTF("The reference result of '%s' (name: id):", item_name);
clif_displaymessage(fd, output);
match = 0;
for (i = 0; i < 20000; i++)
@@ -4696,11 +4368,11 @@ int atcommand_idsearch(const int fd, struct map_session_data *,
&& strstr(item->jname, item_name) != NULL)
{
match++;
- sprintf(output, "%s: %d", item->jname, item->nameid);
+ output = STRPRINTF("%s: %d", item->jname, item->nameid);
clif_displaymessage(fd, output);
}
}
- sprintf(output, "It is %d affair above.", match);
+ output = STRPRINTF("It is %d affair above.", match);
clif_displaymessage(fd, output);
return 0;
@@ -4714,11 +4386,9 @@ int atcommand_charskreset(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -4732,7 +4402,8 @@ int atcommand_charskreset(const int fd, struct map_session_data *sd,
if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can reset skill points only lower or same gm level
pc_resetskill(pl_sd);
- sprintf(output, "'%s' skill points reseted!", character);
+ std::string output = STRPRINTF(
+ "'%s' skill points reseted!", character);
clif_displaymessage(fd, output);
}
else
@@ -4758,11 +4429,9 @@ int atcommand_charstreset(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -4776,7 +4445,9 @@ int atcommand_charstreset(const int fd, struct map_session_data *sd,
if (pc_isGM(sd) >= pc_isGM(pl_sd))
{ // you can reset stats points only lower or same gm level
pc_resetstate(pl_sd);
- sprintf(output, "'%s' stats points reseted!", character);
+ std::string output = STRPRINTF(
+ "'%s' stats points reseted!",
+ character);
clif_displaymessage(fd, output);
}
else
@@ -4802,11 +4473,9 @@ int atcommand_charreset(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -4823,7 +4492,8 @@ int atcommand_charreset(const int fd, struct map_session_data *sd,
pc_resetskill(pl_sd);
pc_setglobalreg(pl_sd, "MAGIC_FLAGS", 0); // [Fate] Reset magic quest variables
pc_setglobalreg(pl_sd, "MAGIC_EXP", 0); // [Fate] Reset magic experience
- sprintf(output, "'%s' skill and stats points reseted!", character);
+ std::string output = STRPRINTF(
+ "'%s' skill and stats points reseted!", character);
clif_displaymessage(fd, output);
}
else
@@ -4849,11 +4519,9 @@ int atcommand_char_wipe(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -4913,7 +4581,7 @@ int atcommand_char_wipe(const int fd, struct map_session_data *sd,
pc_setglobalreg(pl_sd, "MAGIC_FLAGS", 0); // [Fate] Reset magic quest variables
pc_setglobalreg(pl_sd, "MAGIC_EXP", 0); // [Fate] Reset magic experience
- sprintf(output, "%s: wiped.", character);
+ std::string output = STRPRINTF("%s: wiped.", character);
clif_displaymessage(fd, output);
}
else
@@ -4941,20 +4609,19 @@ int atcommand_charmodel(const int fd, struct map_session_data *,
int hair_style = 0, hair_color = 0, cloth_color = 0;
struct map_session_data *pl_sd;
char character[100];
- char output[200];
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message
|| sscanf(message, "%d %d %d %99[^\n]", &hair_style, &hair_color,
&cloth_color, character) < 4 || hair_style < 0
|| hair_color < 0 || cloth_color < 0)
{
- sprintf(output,
- "Please, enter a valid model and a player name (usage: @charmodel <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d> <name>).",
- MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR,
- MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
+ std::string output = STRPRINTF(
+ "Please, enter a valid model and a player name (usage: @charmodel <hair ID: %d-%d> <hair color: %d-%d> <clothes color: %d-%d> <name>).",
+ MIN_HAIR_STYLE, MAX_HAIR_STYLE,
+ MIN_HAIR_COLOR, MAX_HAIR_COLOR,
+ MIN_CLOTH_COLOR, MAX_CLOTH_COLOR);
clif_displaymessage(fd, output);
return -1;
}
@@ -5166,9 +4833,6 @@ int atcommand_recallall(const int fd, struct map_session_data *sd,
struct map_session_data *pl_sd;
int i;
int count;
- char output[200];
-
- memset(output, '\0', sizeof(output));
if (sd->bl.m >= 0 && map[sd->bl.m].flag.nowarpto
&& battle_config.any_warp_GM_min_level > pc_isGM(sd))
@@ -5197,9 +4861,9 @@ int atcommand_recallall(const int fd, struct map_session_data *sd,
clif_displaymessage(fd, "All characters recalled!");
if (count)
{
- sprintf(output,
- "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.",
- count);
+ std::string output = STRPRINTF(
+ "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.",
+ count);
clif_displaymessage(fd, output);
}
@@ -5216,12 +4880,10 @@ int atcommand_partyrecall(const int fd, struct map_session_data *sd,
int i;
struct map_session_data *pl_sd;
char party_name[100];
- char output[200];
struct party *p;
int count;
memset(party_name, '\0', sizeof(party_name));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", party_name) < 1)
{
@@ -5256,13 +4918,13 @@ int atcommand_partyrecall(const int fd, struct map_session_data *sd,
pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2);
}
}
- sprintf(output, "All online characters of the %s party are near you.", p->name);
+ std::string output = STRPRINTF("All online characters of the %s party are near you.", p->name);
clif_displaymessage(fd, output);
if (count)
{
- sprintf(output,
- "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.",
- count);
+ output = STRPRINTF(
+ "Because you are not authorised to warp from some maps, %d player(s) have not been recalled.",
+ count);
clif_displaymessage(fd, output);
}
}
@@ -5360,11 +5022,10 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd,
struct map_session_data *pl_sd;
struct npc_data *nd = NULL;
struct chat_data *cd = NULL;
- char output[200], map_name[100];
+ char map_name[100];
char direction[12];
int m_id, i, chat_num, list = 0;
- memset(output, '\0', sizeof(output));
memset(map_name, '\0', sizeof(map_name));
memset(direction, '\0', sizeof(direction));
@@ -5389,11 +5050,11 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd,
}
clif_displaymessage(fd, "------ Map Info ------");
- sprintf(output, "Map Name: %s", map_name);
+ std::string output = STRPRINTF("Map Name: %s", map_name);
clif_displaymessage(fd, output);
- sprintf(output, "Players In Map: %d", map[m_id].users);
+ output = STRPRINTF("Players In Map: %d", map[m_id].users);
clif_displaymessage(fd, output);
- sprintf(output, "NPCs In Map: %d", map[m_id].npc_num);
+ output = STRPRINTF("NPCs In Map: %d", map[m_id].npc_num);
clif_displaymessage(fd, output);
chat_num = 0;
for (i = 0; i < fd_max; i++)
@@ -5405,35 +5066,35 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd,
chat_num++;
}
}
- sprintf(output, "Chats In Map: %d", chat_num);
+ output = STRPRINTF("Chats In Map: %d", chat_num);
clif_displaymessage(fd, output);
clif_displaymessage(fd, "------ Map Flags ------");
- sprintf(output, "Player vs Player: %s | No Party: %s",
+ output = STRPRINTF("Player vs Player: %s | No Party: %s",
(map[m_id].flag.pvp) ? "True" : "False",
(map[m_id].flag.pvp_noparty) ? "True" : "False");
clif_displaymessage(fd, output);
- sprintf(output, "No Dead Branch: %s",
+ output = STRPRINTF("No Dead Branch: %s",
(map[m_id].flag.nobranch) ? "True" : "False");
clif_displaymessage(fd, output);
- sprintf(output, "No Memo: %s",
+ output = STRPRINTF("No Memo: %s",
(map[m_id].flag.nomemo) ? "True" : "False");
clif_displaymessage(fd, output);
- sprintf(output, "No Penalty: %s",
+ output = STRPRINTF("No Penalty: %s",
(map[m_id].flag.nopenalty) ? "True" : "False");
clif_displaymessage(fd, output);
- sprintf(output, "No Return: %s",
+ output = STRPRINTF("No Return: %s",
(map[m_id].flag.noreturn) ? "True" : "False");
clif_displaymessage(fd, output);
- sprintf(output, "No Save: %s",
+ output = STRPRINTF("No Save: %s",
(map[m_id].flag.nosave) ? "True" : "False");
clif_displaymessage(fd, output);
- sprintf(output, "No Teleport: %s",
+ output = STRPRINTF("No Teleport: %s",
(map[m_id].flag.noteleport) ? "True" : "False");
clif_displaymessage(fd, output);
- sprintf(output, "No Monster Teleport: %s",
+ output = STRPRINTF("No Monster Teleport: %s",
(map[m_id].flag.monster_noteleport) ? "True" : "False");
clif_displaymessage(fd, output);
- sprintf(output, "No Zeny Penalty: %s",
+ output = STRPRINTF("No Zeny Penalty: %s",
(map[m_id].flag.nozenypenalty) ? "True" : "False");
clif_displaymessage(fd, output);
@@ -5450,7 +5111,7 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd,
&& pl_sd->state.auth
&& strcmp(pl_sd->mapname, map_name) == 0)
{
- sprintf(output,
+ output = STRPRINTF(
"Player '%s' (session #%d) | Location: %d,%d",
pl_sd->status.name, i, pl_sd->bl.x, pl_sd->bl.y);
clif_displaymessage(fd, output);
@@ -5495,7 +5156,7 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd,
strcpy(direction, "Unknown");
break;
}
- sprintf(output,
+ output = STRPRINTF(
"NPC %d: %s | Direction: %s | Sprite: %d | Location: %d %d",
++i, nd->name, direction, nd->npc_class, nd->bl.x,
nd->bl.y);
@@ -5512,12 +5173,12 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd,
&& strcmp(pl_sd->mapname, map_name) == 0
&& cd->usersd[0] == pl_sd)
{
- sprintf(output,
+ output = STRPRINTF(
"Chat %d: %s | Player: %s | Location: %d %d", i,
cd->title, pl_sd->status.name, cd->bl.x,
cd->bl.y);
clif_displaymessage(fd, output);
- sprintf(output,
+ output = STRPRINTF(
" Users: %d/%d | Password: %s | Public: %s",
cd->users, cd->limit, cd->pass,
(cd->pub) ? "Yes" : "No");
@@ -5667,11 +5328,9 @@ int atcommand_partyspy(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char party_name[100];
- char output[200];
struct party *p;
memset(party_name, '\0', sizeof(party_name));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", party_name) < 1)
{
@@ -5686,13 +5345,13 @@ int atcommand_partyspy(const int fd, struct map_session_data *sd,
if (sd->partyspy == p->party_id)
{
sd->partyspy = 0;
- sprintf(output, "No longer spying on the %s party.", p->name);
+ std::string output = STRPRINTF("No longer spying on the %s party.", p->name);
clif_displaymessage(fd, output);
}
else
{
sd->partyspy = p->party_id;
- sprintf(output, "Spying on the %s party.", p->name);
+ std::string output = STRPRINTF("Spying on the %s party.", p->name);
clif_displaymessage(fd, output);
}
}
@@ -5774,40 +5433,17 @@ int atcommand_disablenpc(const int fd, struct map_session_data *,
*------------------------------------------
*/
static
-const char *txt_time(unsigned int duration)
+std::string txt_time(unsigned int duration)
{
- int days, hours, minutes, seconds;
- char temp[256];
- static char temp1[256];
-
- memset(temp, '\0', sizeof(temp));
- memset(temp1, '\0', sizeof(temp1));
-
- days = duration / (60 * 60 * 24);
- duration = duration - (60 * 60 * 24 * days);
- hours = duration / (60 * 60);
- duration = duration - (60 * 60 * hours);
- minutes = duration / 60;
- seconds = duration - (60 * minutes);
-
- if (days < 2)
- sprintf(temp, "%d day", days);
- else
- sprintf(temp, "%d days", days);
- if (hours < 2)
- sprintf(temp1, "%s %d hour", temp, hours);
- else
- sprintf(temp1, "%s %d hours", temp, hours);
- if (minutes < 2)
- sprintf(temp, "%s %d minute", temp1, minutes);
- else
- sprintf(temp, "%s %d minutes", temp1, minutes);
- if (seconds < 2)
- sprintf(temp1, "%s and %d second", temp, seconds);
- else
- sprintf(temp1, "%s and %d seconds", temp, seconds);
+ int days = duration / (60 * 60 * 24);
+ duration -= (60 * 60 * 24 * days);
+ int hours = duration / (60 * 60);
+ duration -= (60 * 60 * hours);
+ int minutes = duration / 60;
+ int seconds = duration - (60 * minutes);
- return temp1;
+ return STRPRINTF("%d day(s), %d hour(s), %d minute(s), %d second(s)",
+ days, hours, minutes, seconds);
}
/*==========================================
@@ -5820,16 +5456,10 @@ int atcommand_servertime(const int fd, struct map_session_data *,
{
struct TimerData *timer_data;
struct TimerData *timer_data2;
- time_t time_server; // variable for number of seconds (used with time() function)
- struct tm *datetime; // variable for time in structure ->tm_mday, ->tm_sec, ...
- char temp[256];
- memset(temp, '\0', sizeof(temp));
-
- time(&time_server); // get time in seconds since 1/1/1970
- datetime = gmtime(&time_server); // convert seconds in structure
- // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
- strftime(temp, sizeof(temp) - 1, "Server time (normal time): %A, %B %d %Y %X.", datetime);
+ timestamp_seconds_buffer tsbuf;
+ stamp_time(tsbuf);
+ std::string temp = STRPRINTF("Server time: %s", tsbuf);
clif_displaymessage(fd, temp);
if (battle_config.night_duration == 0 && battle_config.day_duration == 0)
@@ -5843,7 +5473,8 @@ int atcommand_servertime(const int fd, struct map_session_data *,
if (night_flag == 1)
{ // we start with night
timer_data = get_timer(day_timer_tid);
- sprintf(temp, "Game time: The game is actualy in night for %s.", txt_time((timer_data->tick - gettick()) / 1000));
+ temp = STRPRINTF("Game time: The game is actualy in night for %s.",
+ txt_time((timer_data->tick - gettick()) / 1000));
clif_displaymessage(fd, temp);
clif_displaymessage(fd, "Game time: After, the game will be in permanent daylight.");
}
@@ -5853,7 +5484,8 @@ int atcommand_servertime(const int fd, struct map_session_data *,
if (night_flag == 0)
{ // we start with day
timer_data = get_timer(night_timer_tid);
- sprintf(temp, "Game time: The game is actualy in daylight for %s.", txt_time((timer_data->tick - gettick()) / 1000));
+ temp = STRPRINTF("Game time: The game is actualy in daylight for %s.",
+ txt_time((timer_data->tick - gettick()) / 1000));
clif_displaymessage(fd, temp);
clif_displaymessage(fd, "Game time: After, the game will be in permanent night.");
}
@@ -5865,28 +5497,35 @@ int atcommand_servertime(const int fd, struct map_session_data *,
{
timer_data = get_timer(night_timer_tid);
timer_data2 = get_timer(day_timer_tid);
- sprintf(temp, "Game time: The game is actualy in daylight for %s.", txt_time((timer_data->tick - gettick()) / 1000));
+ temp = STRPRINTF("Game time: The game is actualy in daylight for %s.",
+ txt_time((timer_data->tick - gettick()) / 1000));
clif_displaymessage(fd, temp);
if (timer_data->tick > timer_data2->tick)
- sprintf(temp, "Game time: After, the game will be in night for %s.", txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000));
+ temp = STRPRINTF("Game time: After, the game will be in night for %s.",
+ txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000));
else
- sprintf(temp, "Game time: After, the game will be in night for %s.", txt_time(abs(timer_data->tick - timer_data2->tick) / 1000));
+ temp = STRPRINTF("Game time: After, the game will be in night for %s.",
+ txt_time(abs(timer_data->tick - timer_data2->tick) / 1000));
clif_displaymessage(fd, temp);
- sprintf(temp, "Game time: A day cycle has a normal duration of %s.", txt_time(timer_data->interval / 1000));
+ temp = STRPRINTF("Game time: A day cycle has a normal duration of %s.",
+ txt_time(timer_data->interval / 1000));
clif_displaymessage(fd, temp);
}
else
{
timer_data = get_timer(day_timer_tid);
timer_data2 = get_timer(night_timer_tid);
- sprintf(temp, "Game time: The game is actualy in night for %s.", txt_time((timer_data->tick - gettick()) / 1000));
+ temp = STRPRINTF("Game time: The game is actualy in night for %s.",
+ txt_time((timer_data->tick - gettick()) / 1000));
clif_displaymessage(fd, temp);
if (timer_data->tick > timer_data2->tick)
- sprintf(temp, "Game time: After, the game will be in daylight for %s.", txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000));
+ temp = STRPRINTF("Game time: After, the game will be in daylight for %s.",
+ txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000));
else
- sprintf(temp, "Game time: After, the game will be in daylight for %s.", txt_time(abs(timer_data->tick - timer_data2->tick) / 1000));
+ temp = STRPRINTF("Game time: After, the game will be in daylight for %s.", txt_time(abs(timer_data->tick - timer_data2->tick) / 1000));
clif_displaymessage(fd, temp);
- sprintf(temp, "Game time: A day cycle has a normal duration of %s.", txt_time(timer_data->interval / 1000));
+ temp = STRPRINTF("Game time: A day cycle has a normal duration of %s.",
+ txt_time(timer_data->interval / 1000));
clif_displaymessage(fd, temp);
}
}
@@ -5908,12 +5547,10 @@ int atcommand_chardelitem(const int fd, struct map_session_data *sd,
char character[100];
char item_name[100];
int i, number = 0, item_id, item_position, count;
- char output[200];
struct item_data *item_data;
memset(character, '\0', sizeof(character));
memset(item_name, '\0', sizeof(item_name));
- memset(output, '\0', sizeof(output));
if (!message || !*message
|| sscanf(message, "%s %d %99[^\n]", item_name, &number,
@@ -5945,12 +5582,15 @@ int atcommand_chardelitem(const int fd, struct map_session_data *sd,
count++;
item_position = pc_search_inventory(pl_sd, item_id); // for next loop
}
- sprintf(output, "%d item(s) removed by a GM.", count);
+ std::string output = STRPRINTF(
+ "%d item(s) removed by a GM.",
+ count);
clif_displaymessage(pl_sd->fd, output);
+
if (number == count)
- sprintf(output, "%d item(s) removed from the player.", count);
+ output = STRPRINTF("%d item(s) removed from the player.", count);
else
- sprintf(output, "%d item(s) removed. Player had only %d on %d items.", count, count, number);
+ output = STRPRINTF("%d item(s) removed. Player had only %d on %d items.", count, count, number);
clif_displaymessage(fd, output);
}
else
@@ -6172,10 +5812,6 @@ int atcommand_undisguise(const int fd, struct map_session_data *sd,
int atcommand_broadcast(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char output[200];
-
- memset(output, '\0', sizeof(output));
-
if (!message || !*message)
{
clif_displaymessage(fd,
@@ -6183,8 +5819,8 @@ int atcommand_broadcast(const int fd, struct map_session_data *sd,
return -1;
}
- snprintf(output, 199, "%s : %s", sd->status.name, message);
- intif_GMmessage(output, strlen(output) + 1, 0);
+ std::string output = STRPRINTF("%s : %s", sd->status.name, message);
+ intif_GMmessage(output, 0);
return 0;
}
@@ -6196,10 +5832,6 @@ int atcommand_broadcast(const int fd, struct map_session_data *sd,
int atcommand_localbroadcast(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char output[200];
-
- memset(output, '\0', sizeof(output));
-
if (!message || !*message)
{
clif_displaymessage(fd,
@@ -6207,9 +5839,9 @@ int atcommand_localbroadcast(const int fd, struct map_session_data *sd,
return -1;
}
- snprintf(output, 199, "%s : %s", sd->status.name, message);
+ std::string output = STRPRINTF("%s : %s", sd->status.name, message);
- clif_GMmessage(&sd->bl, output, strlen(output) + 1, 1); // 1: ALL_SAMEMAP
+ clif_GMmessage(&sd->bl, output, 1); // 1: ALL_SAMEMAP
return 0;
}
@@ -6221,12 +5853,9 @@ int atcommand_localbroadcast(const int fd, struct map_session_data *sd,
int atcommand_ignorelist(const int fd, struct map_session_data *sd,
const char *, const char *)
{
- char output[200];
int count;
int i;
- memset(output, '\0', sizeof(output));
-
count = 0;
for (i = 0; i < (int)(sizeof(sd->ignore) / sizeof(sd->ignore[0])); i++)
if (sd->ignore[i].name[0])
@@ -6237,14 +5866,18 @@ int atcommand_ignorelist(const int fd, struct map_session_data *sd,
clif_displaymessage(fd, "You accept any wisp (no wisper is refused).");
else
{
- sprintf(output, "You accept any wisp, except thoses from %d player (s):", count);
+ std::string output = STRPRINTF(
+ "You accept any wisp, except thoses from %d player (s):",
+ count);
clif_displaymessage(fd, output);
}
else if (count == 0)
clif_displaymessage(fd, "You refuse all wisps (no specifical wisper is refused).");
else
{
- sprintf(output, "You refuse all wisps, AND refuse wisps from %d player (s):", count);
+ std::string output = STRPRINTF(
+ "You refuse all wisps, AND refuse wisps from %d player (s):",
+ count);
clif_displaymessage(fd, output);
}
@@ -6266,17 +5899,15 @@ int atcommand_charignorelist(const int fd, struct map_session_data *,
{
char character[100];
struct map_session_data *pl_sd;
- char output[200];
int count;
int i;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
clif_displaymessage(fd,
- "Please, enter a player name (usage: @charignorelist <char name>).");
+ "Please, enter a player name (usage: @charignorelist <char name>).");
return -1;
}
@@ -6292,22 +5923,30 @@ int atcommand_charignorelist(const int fd, struct map_session_data *,
if (pl_sd->ignoreAll == 0)
if (count == 0)
{
- sprintf(output, "'%s' accept any wisp (no wisper is refused).", pl_sd->status.name);
+ std::string output = STRPRINTF(
+ "'%s' accept any wisp (no wisper is refused).",
+ pl_sd->status.name);
clif_displaymessage(fd, output);
}
else
{
- sprintf(output, "'%s' accept any wisp, except thoses from %d player(s):", pl_sd->status.name, count);
+ std::string output = STRPRINTF(
+ "'%s' accept any wisp, except thoses from %d player(s):",
+ pl_sd->status.name, count);
clif_displaymessage(fd, output);
}
else if (count == 0)
{
- sprintf(output, "'%s' refuse all wisps (no specifical wisper is refused).", pl_sd->status.name);
+ std::string output = STRPRINTF(
+ "'%s' refuse all wisps (no specifical wisper is refused).",
+ pl_sd->status.name);
clif_displaymessage(fd, output);
}
else
{
- sprintf(output, "'%s' refuse all wisps, AND refuse wisps from %d player(s):", pl_sd->status.name, count);
+ std::string output = STRPRINTF(
+ "'%s' refuse all wisps, AND refuse wisps from %d player(s):",
+ pl_sd->status.name, count);
clif_displaymessage(fd, output);
}
@@ -6337,11 +5976,9 @@ int atcommand_inall(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -6356,14 +5993,18 @@ int atcommand_inall(const int fd, struct map_session_data *sd,
{ // you can change wisp option only to lower or same level
if (pl_sd->ignoreAll == 0)
{
- sprintf(output, "'%s' already accepts all wispers.", pl_sd->status.name);
+ std::string output = STRPRINTF(
+ "'%s' already accepts all wispers.",
+ pl_sd->status.name);
clif_displaymessage(fd, output);
return -1;
}
else
{
pl_sd->ignoreAll = 0;
- sprintf(output, "'%s' now accepts all wispers.", pl_sd->status.name);
+ std::string output = STRPRINTF(
+ "'%s' now accepts all wispers.",
+ pl_sd->status.name);
clif_displaymessage(fd, output);
// message to player
clif_displaymessage(pl_sd->fd, "A GM has authorised all wispers for you.");
@@ -6396,11 +6037,9 @@ int atcommand_exall(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char character[100];
- char output[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -6415,14 +6054,18 @@ int atcommand_exall(const int fd, struct map_session_data *sd,
{ // you can change wisp option only to lower or same level
if (pl_sd->ignoreAll == 1)
{
- sprintf(output, "'%s' already blocks all wispers.", pl_sd->status.name);
+ std::string output = STRPRINTF(
+ "'%s' already blocks all wispers.",
+ pl_sd->status.name);
clif_displaymessage(fd, output);
return -1;
}
else
{
pl_sd->ignoreAll = 1;
- sprintf(output, "'%s' blocks now all wispers.", pl_sd->status.name);
+ std::string output = STRPRINTF(
+ "'%s' blocks now all wispers.",
+ pl_sd->status.name);
clif_displaymessage(fd, output);
// message to player
clif_displaymessage(pl_sd->fd, "A GM has blocked all wispers for you.");
@@ -6663,12 +6306,10 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd,
struct map_session_data *pl_sd;
struct item_data *item_data, *item_temp;
int i, j, count, counter, counter2;
- char character[100], output[200], equipstr[100], outputtmp[200];
+ char character[100], equipstr[100];
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
memset(equipstr, '\0', sizeof(equipstr));
- memset(outputtmp, '\0', sizeof(outputtmp));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -6694,8 +6335,9 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd,
count++;
if (count == 1)
{
- sprintf(output, "------ Items list of '%s' ------",
- pl_sd->status.name);
+ std::string output = STRPRINTF(
+ "------ Items list of '%s' ------",
+ pl_sd->status.name);
clif_displaymessage(fd, output);
}
EPOS equip;
@@ -6735,8 +6377,10 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd,
}
else
memset(equipstr, '\0', sizeof(equipstr));
+
+ std::string output;
if (sd->status.inventory[i].refine)
- sprintf(output, "%d %s %+d (%s %+d, id: %d) %s",
+ output = STRPRINTF("%d %s %+d (%s %+d, id: %d) %s",
pl_sd->status.inventory[i].amount,
item_data->name,
pl_sd->status.inventory[i].refine,
@@ -6744,12 +6388,13 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd,
pl_sd->status.inventory[i].refine,
pl_sd->status.inventory[i].nameid, equipstr);
else
- sprintf(output, "%d %s (%s, id: %d) %s",
+ output = STRPRINTF("%d %s (%s, id: %d) %s",
pl_sd->status.inventory[i].amount,
item_data->name, item_data->jname,
pl_sd->status.inventory[i].nameid, equipstr);
clif_displaymessage(fd, output);
- memset(output, '\0', sizeof(output));
+
+ output.clear();
counter2 = 0;
for (j = 0; j < item_data->slot; j++)
{
@@ -6760,23 +6405,31 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd,
inventory[i].card[j])) !=
NULL)
{
- if (output[0] == '\0')
- sprintf(outputtmp,
- " -> (card(s): #%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
+ if (output.empty())
+ output = STRPRINTF(
+ " -> (card(s): #%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
else
- sprintf(outputtmp, "#%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
- strcat(output, outputtmp);
+ output += STRPRINTF(
+ "#%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
}
}
}
- if (output[0] != '\0')
+ if (!output.empty())
{
- output[strlen(output) - 2] = ')';
- output[strlen(output) - 1] = '\0';
+ // replace trailing ", "
+#ifdef ANNOYING_GCC46_WORKAROUNDS
+# warning " and "
+ output.resize(output.size() - 1);
+#else
+ output.pop_back();
+#endif
+ output.back() = ')';
clif_displaymessage(fd, output);
}
}
@@ -6785,8 +6438,9 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd,
clif_displaymessage(fd, "No item found on this player.");
else
{
- sprintf(output, "%d item(s) found in %d kind(s) of items.",
- counter, count);
+ std::string output = STRPRINTF(
+ "%d item(s) found in %d kind(s) of items.",
+ counter, count);
clif_displaymessage(fd, output);
}
}
@@ -6816,11 +6470,9 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd,
struct map_session_data *pl_sd;
struct item_data *item_data, *item_temp;
int i, j, count, counter, counter2;
- char character[100], output[200], outputtmp[200];
+ char character[100];
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
- memset(outputtmp, '\0', sizeof(outputtmp));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -6847,13 +6499,14 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd,
count++;
if (count == 1)
{
- sprintf(output,
+ std::string output = STRPRINTF(
"------ Storage items list of '%s' ------",
pl_sd->status.name);
clif_displaymessage(fd, output);
}
+ std::string output;
if (stor->storage_[i].refine)
- sprintf(output, "%d %s %+d (%s %+d, id: %d)",
+ output = STRPRINTF("%d %s %+d (%s %+d, id: %d)",
stor->storage_[i].amount,
item_data->name,
stor->storage_[i].refine,
@@ -6861,12 +6514,13 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd,
stor->storage_[i].refine,
stor->storage_[i].nameid);
else
- sprintf(output, "%d %s (%s, id: %d)",
+ output = STRPRINTF("%d %s (%s, id: %d)",
stor->storage_[i].amount,
item_data->name, item_data->jname,
stor->storage_[i].nameid);
clif_displaymessage(fd, output);
- memset(output, '\0', sizeof(output));
+
+ output.clear();
counter2 = 0;
for (j = 0; j < item_data->slot; j++)
{
@@ -6877,23 +6531,31 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd,
storage_[i].card[j])) !=
NULL)
{
- if (output[0] == '\0')
- sprintf(outputtmp,
- " -> (card(s): #%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
+ if (output.empty())
+ output = STRPRINTF(
+ " -> (card(s): #%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
else
- sprintf(outputtmp, "#%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
- strcat(output, outputtmp);
+ output += STRPRINTF(
+ "#%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
}
}
}
- if (output[0] != '\0')
+ if (!output.empty())
{
- output[strlen(output) - 2] = ')';
- output[strlen(output) - 1] = '\0';
+ // replace last ", "
+#ifdef ANNOYING_GCC46_WORKAROUNDS
+# warning " all of "
+ output.resize(output.size() - 1);
+#else
+ output.pop_back();
+#endif
+ output.back() = ')';
clif_displaymessage(fd, output);
}
}
@@ -6903,7 +6565,7 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd,
"No item found in the storage of this player.");
else
{
- sprintf(output,
+ std::string output = STRPRINTF(
"%d item(s) found in %d kind(s) of items.",
counter, count);
clif_displaymessage(fd, output);
@@ -6940,11 +6602,9 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd,
struct map_session_data *pl_sd;
struct item_data *item_data, *item_temp;
int i, j, count, counter, counter2;
- char character[100], output[200], outputtmp[200];
+ char character[100];
memset(character, '\0', sizeof(character));
- memset(output, '\0', sizeof(output));
- memset(outputtmp, '\0', sizeof(outputtmp));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1)
{
@@ -6969,26 +6629,30 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd,
count++;
if (count == 1)
{
- sprintf(output,
- "------ Cart items list of '%s' ------",
- pl_sd->status.name);
+ std::string output = STRPRINTF(
+ "------ Cart items list of '%s' ------",
+ pl_sd->status.name);
clif_displaymessage(fd, output);
}
+
+ std::string output;
if (pl_sd->status.cart[i].refine)
- sprintf(output, "%d %s %+d (%s %+d, id: %d)",
- pl_sd->status.cart[i].amount,
- item_data->name,
- pl_sd->status.cart[i].refine,
- item_data->jname,
- pl_sd->status.cart[i].refine,
- pl_sd->status.cart[i].nameid);
+ output = STRPRINTF("%d %s %+d (%s %+d, id: %d)",
+ pl_sd->status.cart[i].amount,
+ item_data->name,
+ pl_sd->status.cart[i].refine,
+ item_data->jname,
+ pl_sd->status.cart[i].refine,
+ pl_sd->status.cart[i].nameid);
else
- sprintf(output, "%d %s (%s, id: %d)",
- pl_sd->status.cart[i].amount,
- item_data->name, item_data->jname,
- pl_sd->status.cart[i].nameid);
+
+ output = STRPRINTF("%d %s (%s, id: %d)",
+ pl_sd->status.cart[i].amount,
+ item_data->name, item_data->jname,
+ pl_sd->status.cart[i].nameid);
clif_displaymessage(fd, output);
- memset(output, '\0', sizeof(output));
+
+ output.clear();
counter2 = 0;
for (j = 0; j < item_data->slot; j++)
{
@@ -6998,23 +6662,30 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd,
itemdb_search(pl_sd->status.
cart[i].card[j])) != NULL)
{
- if (output[0] == '\0')
- sprintf(outputtmp,
- " -> (card(s): #%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
+ if (output.empty())
+ output = STRPRINTF(
+ " -> (card(s): #%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
else
- sprintf(outputtmp, "#%d %s (%s), ",
- ++counter2, item_temp->name,
- item_temp->jname);
- strcat(output, outputtmp);
+ output += STRPRINTF(
+ "#%d %s (%s), ",
+ ++counter2,
+ item_temp->name,
+ item_temp->jname);
}
}
}
- if (output[0] != '\0')
+ if (!output.empty())
{
- output[strlen(output) - 2] = ')';
- output[strlen(output) - 1] = '\0';
+#ifdef ANNOYING_GCC46_WORKAROUNDS
+# warning " these ... "
+ output.resize(output.size() - 1);
+#else
+ output.pop_back();
+#endif
+ output.back() = '0';
clif_displaymessage(fd, output);
}
}
@@ -7024,7 +6695,7 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd,
"No item found in the cart of this player.");
else
{
- sprintf(output, "%d item(s) found in %d kind(s) of items.",
+ std::string output = STRPRINTF("%d item(s) found in %d kind(s) of items.",
counter, count);
clif_displaymessage(fd, output);
}
@@ -7177,24 +6848,22 @@ int atcommand_npcmove(const int, struct map_session_data *sd,
int atcommand_addwarp(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- char w1[64], w3[64], w4[64];
- char mapname[30], output[200];
+ char mapname[30];
int x, y, ret;
if (!message || !*message)
return -1;
- if (sscanf(message, "%99s %d %d[^\n]", mapname, &x, &y) < 3)
+ if (sscanf(message, "%29s %d %d[^\n]", mapname, &x, &y) < 3)
return -1;
- sprintf(w1, "%s,%d,%d", sd->mapname, sd->bl.x, sd->bl.y);
- sprintf(w3, "%s%d%d%d%d", mapname, sd->bl.x, sd->bl.y, x, y);
- sprintf(w4, "1,1,%s.gat,%d,%d", mapname, x, y);
-
- ret = npc_parse_warp(w1, "warp", w3, w4);
+ std::string w1 = STRPRINTF("%s,%d,%d", sd->mapname, sd->bl.x, sd->bl.y);
+ std::string w3 = STRPRINTF("%s%d%d%d%d", mapname, sd->bl.x, sd->bl.y, x, y);
+ std::string w4 = STRPRINTF("1,1,%s.gat,%d,%d", mapname, x, y);
- sprintf(output, "New warp NPC => %s", w3);
+ ret = npc_parse_warp(w1.c_str(), "warp", w3.c_str(), w4.c_str());
+ std::string output = STRPRINTF("New warp NPC => %s", w3);
clif_displaymessage(fd, output);
return ret;
@@ -7390,9 +7059,8 @@ int atcommand_skillid(const int fd, struct map_session_data *,
if ((strncasecmp(skill_names[idx].name, message, skillen) == 0) ||
(strncasecmp(skill_names[idx].desc, message, skillen) == 0))
{
- char output[255];
- sprintf(output, "skill %d: %s",
- uint16_t(skill_names[idx].id), skill_names[idx].desc);
+ std::string output = STRPRINTF("skill %d: %s",
+ skill_names[idx].id, skill_names[idx].desc);
clif_displaymessage(fd, output);
}
idx++;
@@ -7717,7 +7385,6 @@ int atcommand_magic_info(const int fd, struct map_session_data *,
const char *, const char *message)
{
char character[100];
- char buf[200];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
@@ -7730,14 +7397,18 @@ int atcommand_magic_info(const int fd, struct map_session_data *,
if ((pl_sd = map_nick2sd(character)) != NULL)
{
- sprintf(buf, "`%s' has the following magic skills:", character);
+ std::string buf = STRPRINTF(
+ "`%s' has the following magic skills:",
+ character);
clif_displaymessage(fd, buf);
for (size_t i = 0; i < magic_skills_nr; i++)
{
SkillID sk = magic_skills[i];
- sprintf(buf, "%d in %s",
- pl_sd->status.skill[sk].lv, magic_skill_names[i]);
+ buf = STRPRINTF(
+ "%d in %s",
+ pl_sd->status.skill[sk].lv,
+ magic_skill_names[i]);
if (pl_sd->status.skill[sk].id == sk)
clif_displaymessage(fd, buf);
}
@@ -7825,7 +7496,7 @@ int atcommand_log(const int, struct map_session_data *,
int atcommand_tee(const int, struct map_session_data *sd,
const char *, const char *message)
{
- char *data = (char *)malloc(strlen(message) + 28);
+ char data[strlen(message) + 28];
strcpy(data, sd->status.name);
strcat(data, " : ");
strcat(data, message);
@@ -7853,11 +7524,8 @@ int atcommand_jump_iterate(const int fd, struct map_session_data *sd,
struct map_session_data *(*get_start)(void),
struct map_session_data *(*get_next)(struct map_session_data*))
{
- char output[200];
struct map_session_data *pl_sd;
- memset(output, '\0', sizeof(output));
-
pl_sd = (struct map_session_data *) map_id2bl(sd->followtarget);
if (pl_sd)
@@ -7888,7 +7556,7 @@ int atcommand_jump_iterate(const int fd, struct map_session_data *sd,
return -1;
}
pc_setpos(sd, map[pl_sd->bl.m].name, pl_sd->bl.x, pl_sd->bl.y, 3);
- sprintf(output, "Jump to %s", pl_sd->status.name);
+ std::string output = STRPRINTF("Jump to %s", pl_sd->status.name);
clif_displaymessage(fd, output);
sd->followtarget = pl_sd->bl.id;
@@ -7921,7 +7589,8 @@ int atcommand_wgm(const int fd, struct map_session_data *sd,
{
if (tmw_CheckChatSpam(sd, message))
return 0;
- tmw_GmHackMsg("%s: %s", sd->status.name, message);
+
+ tmw_GmHackMsg(static_cast<const std::string&>(STRPRINTF("[GM] %s: %s", sd->status.name, message)));
if (!pc_isGM(sd))
clif_displaymessage(fd, "Message sent.");
@@ -7943,25 +7612,25 @@ int atcommand_skillpool_info(const int fd, struct map_session_data *,
if ((pl_sd = map_nick2sd(character)) != NULL)
{
- char buf[200];
SkillID pool_skills[MAX_SKILL_POOL];
int pool_skills_nr = skill_pool(pl_sd, pool_skills);
int i;
- sprintf(buf, "Active skills %d out of %d for %s:", pool_skills_nr,
- skill_pool_max(pl_sd), character);
+ std::string buf = STRPRINTF(
+ "Active skills %d out of %d for %s:",
+ pool_skills_nr, skill_pool_max(pl_sd), character);
clif_displaymessage(fd, buf);
for (i = 0; i < pool_skills_nr; ++i)
{
- sprintf(buf, " - %s [%d]: power %d",
+ buf = STRPRINTF(" - %s [%d]: power %d",
skill_name(pool_skills[i]),
- uint16_t(pool_skills[i]),
+ pool_skills[i],
skill_power(pl_sd, pool_skills[i]));
clif_displaymessage(fd, buf);
}
- sprintf(buf, "Learned skills out of %d for %s:",
- skill_pool_skills_size, character);
+ buf = STRPRINTF("Learned skills out of %d for %s:",
+ skill_pool_skills_size, character);
clif_displaymessage(fd, buf);
for (i = 0; i < skill_pool_skills_size; ++i)
@@ -7971,8 +7640,8 @@ int atcommand_skillpool_info(const int fd, struct map_session_data *,
if (lvl)
{
- sprintf(buf, " - %s [%d]: lvl %d",
- name, uint16_t(skill_pool_skills[i]), lvl);
+ buf = STRPRINTF(" - %s [%d]: lvl %d",
+ name, skill_pool_skills[i], lvl);
clif_displaymessage(fd, buf);
}
}
@@ -8075,7 +7744,6 @@ int atcommand_ipcheck(const int fd, struct map_session_data *,
{
struct map_session_data *pl_sd;
struct sockaddr_in sai;
- char output[200];
char character[25];
int i;
socklen_t sa_len = sizeof(struct sockaddr);
@@ -8118,10 +7786,10 @@ int atcommand_ipcheck(const int fd, struct map_session_data *,
// Is checking GM levels really needed here?
if (ip == sai.sin_addr.s_addr)
{
- snprintf(output, sizeof(output),
- "Name: %s | Location: %s %d %d",
- pl_sd->status.name, pl_sd->mapname,
- pl_sd->bl.x, pl_sd->bl.y);
+ std::string output = STRPRINTF(
+ "Name: %s | Location: %s %d %d",
+ pl_sd->status.name, pl_sd->mapname,
+ pl_sd->bl.x, pl_sd->bl.y);
clif_displaymessage(fd, output);
}
}
diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp
index 50ad9b2..ec69cc7 100644
--- a/src/map/atcommand.hpp
+++ b/src/map/atcommand.hpp
@@ -190,16 +190,13 @@ typedef struct AtCommandInfo
const char *command, const char *message);
} AtCommandInfo;
-AtCommandType is_atcommand(const int fd, struct map_session_data *sd,
- const char *message, int gmlvl);
+bool is_atcommand(const int fd, struct map_session_data *sd,
+ const char *message, int gmlvl);
int get_atcommand_level(const AtCommandType type);
int atcommand_config_read(const char *cfgName);
-__attribute__((format(printf, 2, 3)))
-void log_atcommand(struct map_session_data *sd, const char *fmt, ...);
-__attribute__((format(printf, 1, 2)))
-void gm_log(const char *fmt, ...);
+void log_atcommand(struct map_session_data *sd, const_string cmd);
#endif // ATCOMMAND_HPP
diff --git a/src/map/battle.cpp b/src/map/battle.cpp
index 88a322b..a6aebcb 100644
--- a/src/map/battle.cpp
+++ b/src/map/battle.cpp
@@ -5,6 +5,8 @@
#include <cstdlib>
#include <cstring>
+#include <fstream>
+
#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
@@ -1316,7 +1318,7 @@ int battle_get_mexp(struct block_list *bl)
const int retval =
(mob_db[mob->mob_class].mexp *
(int)(mob->stats[MOB_XP_BONUS])) >> MOB_XP_BONUS_SHIFT;
- fprintf(stderr, "Modifier of %x: -> %d\n", mob->stats[MOB_XP_BONUS],
+ FPRINTF(stderr, "Modifier of %x: -> %d\n", mob->stats[MOB_XP_BONUS],
retval);
return retval;
}
@@ -1570,7 +1572,7 @@ int battle_attr_fix(int damage, int atk_elem, int def_elem)
def_lv < 1 || def_lv > 4)
{ // 属 性値がおかしいのでとりあえずそのまま返す
if (battle_config.error_log)
- printf("battle_attr_fix: unknown attr type: atk=%d def_type=%d def_lv=%d\n",
+ PRINTF("battle_attr_fix: unknown attr type: atk=%d def_type=%d def_lv=%d\n",
atk_elem, def_type, def_lv);
return damage;
}
@@ -4183,7 +4185,7 @@ struct Damage battle_calc_magic_attack(struct block_list *bl,
if (thres > 700)
thres = 700;
// if(battle_config.battle_log)
-// printf("ターンアンデッド! 確率%d ‰(千分率)\n", thres);
+// PRINTF("ターンアンデッド! 確率%d ‰(千分率)\n", thres);
if (MRAND(1000) < thres && !(t_mode & 0x20)) // 成功
damage = hp;
else // 失敗
@@ -4203,7 +4205,7 @@ struct Damage battle_calc_magic_attack(struct block_list *bl,
else
{
if (battle_config.error_log)
- printf("battle_calc_magic_attack(): napam enemy count=0 !\n");
+ PRINTF("battle_calc_magic_attack(): napam enemy count=0 !\n");
}
break;
case MG_FIREBALL: // ファイヤーボール
@@ -4277,7 +4279,7 @@ struct Damage battle_calc_magic_attack(struct block_list *bl,
else
{
if (battle_config.error_log)
- printf("battle_calc_magic_attack(): napalmvulcan enemy count=0 !\n");
+ PRINTF("battle_calc_magic_attack(): napalmvulcan enemy count=0 !\n");
}
break;
}
@@ -4613,8 +4615,8 @@ struct Damage battle_calc_attack(BF attack_type,
flag);
default:
if (battle_config.error_log)
- printf("battle_calc_attack: unknwon attack type ! %d\n",
- uint16_t(attack_type));
+ PRINTF("battle_calc_attack: unknwon attack type ! %d\n",
+ attack_type);
break;
}
return d;
@@ -5213,8 +5215,8 @@ int battle_check_target(struct block_list *src, struct block_list *target,
return 0;
}
-//printf("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->id,src->id,target->id,flag,src->type,target->type);
-//printf("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g);
+//PRINTF("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->id,src->id,target->id,flag,src->type,target->type);
+//PRINTF("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g);
if (ss->type == BL_PC && target->type == BL_PC)
{ // 両方PVPモードなら否定(敵)
@@ -5293,9 +5295,6 @@ int battle_check_range(struct block_list *src, struct block_list *bl,
*/
int battle_config_read(const char *cfgName)
{
- int i;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
static int count = 0;
if ((count++) == 0)
@@ -5499,451 +5498,239 @@ int battle_config_read(const char *cfgName)
battle_config.mob_splash_radius = -1;
}
- fp = fopen_(cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- printf("file not found: %s\n", cfgName);
+ PRINTF("file not found: %s\n", cfgName);
return 1;
}
- while (fgets(line, 1020, fp))
+
+ std::string line;
+ while (std::getline(in, line))
{
+ // s/{"\([a-zA-Z_0-9]*\)", &battle_config.\1}/BATTLE_CONFIG_VAR(\1)/
const struct
{
- char str[128];
+ const char *str;
int *val;
} data[] =
{
- {
- "warp_point_debug", &battle_config.warp_point_debug},
- {
- "enemy_critical", &battle_config.enemy_critical},
- {
- "enemy_critical_rate", &battle_config.enemy_critical_rate},
- {
- "enemy_str", &battle_config.enemy_str},
- {
- "enemy_perfect_flee", &battle_config.enemy_perfect_flee},
- {
- "casting_rate", &battle_config.cast_rate},
- {
- "delay_rate", &battle_config.delay_rate},
- {
- "delay_dependon_dex", &battle_config.delay_dependon_dex},
- {
- "skill_delay_attack_enable",
- &battle_config.sdelay_attack_enable},
- {
- "left_cardfix_to_right", &battle_config.left_cardfix_to_right},
- {
- "player_skill_add_range", &battle_config.pc_skill_add_range},
- {
- "skill_out_range_consume",
- &battle_config.skill_out_range_consume},
- {
- "monster_skill_add_range", &battle_config.mob_skill_add_range},
- {
- "player_damage_delay", &battle_config.pc_damage_delay},
- {
- "player_damage_delay_rate",
- &battle_config.pc_damage_delay_rate},
- {
- "defunit_not_enemy", &battle_config.defnotenemy},
- {
- "random_monster_checklv",
- &battle_config.random_monster_checklv},
- {
- "attribute_recover", &battle_config.attr_recover},
- {
- "flooritem_lifetime", &battle_config.flooritem_lifetime},
- {
- "item_auto_get", &battle_config.item_auto_get},
- {
- "drop_pickup_safety_zone",
- &battle_config.drop_pickup_safety_zone},
- {
- "item_first_get_time", &battle_config.item_first_get_time},
- {
- "item_second_get_time", &battle_config.item_second_get_time},
- {
- "item_third_get_time", &battle_config.item_third_get_time},
- {
- "mvp_item_first_get_time",
- &battle_config.mvp_item_first_get_time},
- {
- "mvp_item_second_get_time",
- &battle_config.mvp_item_second_get_time},
- {
- "mvp_item_third_get_time",
- &battle_config.mvp_item_third_get_time},
- {
- "item_rate", &battle_config.item_rate},
- {
- "drop_rate0item", &battle_config.drop_rate0item},
- {
- "base_exp_rate", &battle_config.base_exp_rate},
- {
- "job_exp_rate", &battle_config.job_exp_rate},
- {
- "pvp_exp", &battle_config.pvp_exp},
- {
- "gtb_pvp_only", &battle_config.gtb_pvp_only},
- {
- "death_penalty_type", &battle_config.death_penalty_type},
- {
- "death_penalty_base", &battle_config.death_penalty_base},
- {
- "death_penalty_job", &battle_config.death_penalty_job},
- {
- "zeny_penalty", &battle_config.zeny_penalty},
- {
- "restart_hp_rate", &battle_config.restart_hp_rate},
- {
- "restart_sp_rate", &battle_config.restart_sp_rate},
- {
- "mvp_hp_rate", &battle_config.mvp_hp_rate},
- {
- "mvp_item_rate", &battle_config.mvp_item_rate},
- {
- "mvp_exp_rate", &battle_config.mvp_exp_rate},
- {
- "monster_hp_rate", &battle_config.monster_hp_rate},
- {
- "monster_max_aspd", &battle_config.monster_max_aspd},
- {
- "atcommand_gm_only", &battle_config.atc_gmonly},
- {
- "atcommand_spawn_quantity_limit",
- &battle_config.atc_spawn_quantity_limit},
- {
- "gm_all_skill", &battle_config.gm_allskill},
- {
- "gm_all_skill_add_abra", &battle_config.gm_allskill_addabra},
- {
- "gm_all_equipment", &battle_config.gm_allequip},
- {
- "gm_skill_unconditional", &battle_config.gm_skilluncond},
- {
- "player_skillfree", &battle_config.skillfree},
- {
- "player_skillup_limit", &battle_config.skillup_limit},
- {
- "weapon_produce_rate", &battle_config.wp_rate},
- {
- "potion_produce_rate", &battle_config.pp_rate},
- {
- "monster_active_enable", &battle_config.monster_active_enable},
- {
- "monster_damage_delay_rate",
- &battle_config.monster_damage_delay_rate},
- {
- "monster_loot_type", &battle_config.monster_loot_type},
- {
- "mob_skill_use", &battle_config.mob_skill_use},
- {
- "mob_count_rate", &battle_config.mob_count_rate},
- {
- "quest_skill_learn", &battle_config.quest_skill_learn},
- {
- "quest_skill_reset", &battle_config.quest_skill_reset},
- {
- "basic_skill_check", &battle_config.basic_skill_check},
- {
- "player_invincible_time", &battle_config.pc_invincible_time},
- {
- "skill_min_damage", &battle_config.skill_min_damage},
- {
- "finger_offensive_type", &battle_config.finger_offensive_type},
- {
- "heal_exp", &battle_config.heal_exp},
- {
- "resurrection_exp", &battle_config.resurrection_exp},
- {
- "shop_exp", &battle_config.shop_exp},
- {
- "combo_delay_rate", &battle_config.combo_delay_rate},
- {
- "item_check", &battle_config.item_check},
- {
- "wedding_modifydisplay", &battle_config.wedding_modifydisplay},
- {
- "natural_healhp_interval",
- &battle_config.natural_healhp_interval},
- {
- "natural_healsp_interval",
- &battle_config.natural_healsp_interval},
- {
- "natural_heal_skill_interval",
- &battle_config.natural_heal_skill_interval},
- {
- "natural_heal_weight_rate",
- &battle_config.natural_heal_weight_rate},
- {
- "itemheal_regeneration_factor",
- &battle_config.itemheal_regeneration_factor},
- {
- "item_name_override_grffile",
- &battle_config.item_name_override_grffile},
- {
- "arrow_decrement", &battle_config.arrow_decrement},
- {
- "max_aspd", &battle_config.max_aspd},
- {
- "max_hp", &battle_config.max_hp},
- {
- "max_sp", &battle_config.max_sp},
- {
- "max_lv", &battle_config.max_lv},
- {
- "max_parameter", &battle_config.max_parameter},
- {
- "max_cart_weight", &battle_config.max_cart_weight},
- {
- "player_skill_log", &battle_config.pc_skill_log},
- {
- "monster_skill_log", &battle_config.mob_skill_log},
- {
- "battle_log", &battle_config.battle_log},
- {
- "save_log", &battle_config.save_log},
- {
- "error_log", &battle_config.error_log},
- {
- "etc_log", &battle_config.etc_log},
- {
- "save_clothcolor", &battle_config.save_clothcolor},
- {
- "undead_detect_type", &battle_config.undead_detect_type},
- {
- "player_auto_counter_type",
- &battle_config.pc_auto_counter_type},
- {
- "monster_auto_counter_type",
- &battle_config.monster_auto_counter_type},
- {
- "agi_penaly_type", &battle_config.agi_penaly_type},
- {
- "agi_penaly_count", &battle_config.agi_penaly_count},
- {
- "agi_penaly_num", &battle_config.agi_penaly_num},
- {
- "agi_penaly_count_lv", &battle_config.agi_penaly_count_lv},
- {
- "vit_penaly_type", &battle_config.vit_penaly_type},
- {
- "vit_penaly_count", &battle_config.vit_penaly_count},
- {
- "vit_penaly_num", &battle_config.vit_penaly_num},
- {
- "vit_penaly_count_lv", &battle_config.vit_penaly_count_lv},
- {
- "player_defense_type", &battle_config.player_defense_type},
- {
- "monster_defense_type", &battle_config.monster_defense_type},
- {
- "magic_defense_type", &battle_config.magic_defense_type},
- {
- "player_skill_reiteration",
- &battle_config.pc_skill_reiteration},
- {
- "monster_skill_reiteration",
- &battle_config.monster_skill_reiteration},
- {
- "player_skill_nofootset", &battle_config.pc_skill_nofootset},
- {
- "monster_skill_nofootset",
- &battle_config.monster_skill_nofootset},
- {
- "player_cloak_check_type", &battle_config.pc_cloak_check_type},
- {
- "monster_cloak_check_type",
- &battle_config.monster_cloak_check_type},
- {
- "mob_changetarget_byskill",
- &battle_config.mob_changetarget_byskill},
- {
- "player_attack_direction_change",
- &battle_config.pc_attack_direction_change},
- {
- "monster_attack_direction_change",
- &battle_config.monster_attack_direction_change},
- {
- "player_land_skill_limit", &battle_config.pc_land_skill_limit},
- {
- "monster_land_skill_limit",
- &battle_config.monster_land_skill_limit},
- {
- "party_skill_penaly", &battle_config.party_skill_penaly},
- {
- "monster_class_change_full_recover",
- &battle_config.monster_class_change_full_recover},
- {
- "produce_item_name_input",
- &battle_config.produce_item_name_input},
- {
- "produce_potion_name_input",
- &battle_config.produce_potion_name_input},
- {
- "making_arrow_name_input",
- &battle_config.making_arrow_name_input},
- {
- "holywater_name_input", &battle_config.holywater_name_input},
- {
- "display_delay_skill_fail",
- &battle_config.display_delay_skill_fail},
- {
- "chat_warpportal", &battle_config.chat_warpportal},
- {
- "mob_warpportal", &battle_config.mob_warpportal},
- {
- "dead_branch_active", &battle_config.dead_branch_active},
- {
- "show_steal_in_same_party",
- &battle_config.show_steal_in_same_party},
- {
- "enable_upper_class", &battle_config.enable_upper_class},
- {
- "mob_attack_attr_none", &battle_config.mob_attack_attr_none},
- {
- "mob_ghostring_fix", &battle_config.mob_ghostring_fix},
- {
- "pc_attack_attr_none", &battle_config.pc_attack_attr_none},
- {
- "gx_allhit", &battle_config.gx_allhit},
- {
- "gx_cardfix", &battle_config.gx_cardfix},
- {
- "gx_dupele", &battle_config.gx_dupele},
- {
- "gx_disptype", &battle_config.gx_disptype},
- {
- "player_skill_partner_check",
- &battle_config.player_skill_partner_check},
- {
- "hide_GM_session", &battle_config.hide_GM_session},
- {
- "unit_movement_type", &battle_config.unit_movement_type},
- {
- "invite_request_check", &battle_config.invite_request_check},
- {
- "skill_removetrap_type", &battle_config.skill_removetrap_type},
- {
- "disp_experience", &battle_config.disp_experience},
- {
- "riding_weight", &battle_config.riding_weight},
- {
- "item_rate_common", &battle_config.item_rate_common}, // Added by RoVeRT
- {
- "item_rate_equip", &battle_config.item_rate_equip},
- {
- "item_rate_card", &battle_config.item_rate_card}, // End Addition
- {
- "item_rate_heal", &battle_config.item_rate_heal}, // Added by Valaris
- {
- "item_rate_use", &battle_config.item_rate_use}, // End
- {
- "item_drop_common_min", &battle_config.item_drop_common_min}, // Added by TyrNemesis^
- {
- "item_drop_common_max", &battle_config.item_drop_common_max},
- {
- "item_drop_equip_min", &battle_config.item_drop_equip_min},
- {
- "item_drop_equip_max", &battle_config.item_drop_equip_max},
- {
- "item_drop_card_min", &battle_config.item_drop_card_min},
- {
- "item_drop_card_max", &battle_config.item_drop_card_max},
- {
- "item_drop_mvp_min", &battle_config.item_drop_mvp_min},
- {
- "item_drop_mvp_max", &battle_config.item_drop_mvp_max}, // End Addition
- {
- "prevent_logout", &battle_config.prevent_logout}, // Added by RoVeRT
- {
- "alchemist_summon_reward", &battle_config.alchemist_summon_reward}, // [Valaris]
- {
- "maximum_level", &battle_config.maximum_level}, // [Valaris]
- {
- "drops_by_luk", &battle_config.drops_by_luk}, // [Valaris]
- {
- "monsters_ignore_gm", &battle_config.monsters_ignore_gm}, // [Valaris]
- {
- "equipment_breaking", &battle_config.equipment_breaking}, // [Valaris]
- {
- "equipment_break_rate", &battle_config.equipment_break_rate}, // [Valaris]
- {
- "pk_mode", &battle_config.pk_mode}, // [Valaris]
- {
- "multi_level_up", &battle_config.multi_level_up}, // [Valaris]
- {
- "backstab_bow_penalty", &battle_config.backstab_bow_penalty},
- {
- "night_at_start", &battle_config.night_at_start}, // added by [Yor]
- {
- "day_duration", &battle_config.day_duration}, // added by [Yor]
- {
- "night_duration", &battle_config.night_duration}, // added by [Yor]
- {
- "show_mob_hp", &battle_config.show_mob_hp}, // [Valaris]
- {
- "hack_info_GM_level", &battle_config.hack_info_GM_level}, // added by [Yor]
- {
- "any_warp_GM_min_level", &battle_config.any_warp_GM_min_level}, // added by [Yor]
- {
- "packet_ver_flag", &battle_config.packet_ver_flag}, // added by [Yor]
- {
- "min_hair_style", &battle_config.min_hair_style}, // added by [MouseJstr]
- {
- "max_hair_style", &battle_config.max_hair_style}, // added by [MouseJstr]
- {
- "min_hair_color", &battle_config.min_hair_color}, // added by [MouseJstr]
- {
- "max_hair_color", &battle_config.max_hair_color}, // added by [MouseJstr]
- {
- "min_cloth_color", &battle_config.min_cloth_color}, // added by [MouseJstr]
- {
- "max_cloth_color", &battle_config.max_cloth_color}, // added by [MouseJstr]
- {
- "castrate_dex_scale", &battle_config.castrate_dex_scale}, // added by [MouseJstr]
- {
- "area_size", &battle_config.area_size}, // added by [MouseJstr]
- {
- "muting_players", &battle_config.muting_players}, // added by [Apple]
- {
- "chat_lame_penalty", &battle_config.chat_lame_penalty},
- {
- "chat_spam_threshold", &battle_config.chat_spam_threshold},
- {
- "chat_spam_flood", &battle_config.chat_spam_flood},
- {
- "chat_spam_ban", &battle_config.chat_spam_ban},
- {
- "chat_spam_warn", &battle_config.chat_spam_warn},
- {
- "chat_maxline", &battle_config.chat_maxline},
- {
- "packet_spam_threshold", &battle_config.packet_spam_threshold},
- {
- "packet_spam_flood", &battle_config.packet_spam_flood},
- {
- "packet_spam_kick", &battle_config.packet_spam_kick},
- {
- "mask_ip_gms", &battle_config.mask_ip_gms},
- {
- "mob_splash_radius", &battle_config.mob_splash_radius},
+ {"warp_point_debug", &battle_config.warp_point_debug},
+ {"enemy_critical", &battle_config.enemy_critical},
+ {"enemy_critical_rate", &battle_config.enemy_critical_rate},
+ {"enemy_str", &battle_config.enemy_str},
+ {"enemy_perfect_flee", &battle_config.enemy_perfect_flee},
+ {"casting_rate", &battle_config.cast_rate},
+ {"delay_rate", &battle_config.delay_rate},
+ {"delay_dependon_dex", &battle_config.delay_dependon_dex},
+ {"skill_delay_attack_enable", &battle_config.sdelay_attack_enable},
+ {"left_cardfix_to_right", &battle_config.left_cardfix_to_right},
+ {"player_skill_add_range", &battle_config.pc_skill_add_range},
+ {"skill_out_range_consume", &battle_config.skill_out_range_consume},
+ {"monster_skill_add_range", &battle_config.mob_skill_add_range},
+ {"player_damage_delay", &battle_config.pc_damage_delay},
+ {"player_damage_delay_rate", &battle_config.pc_damage_delay_rate},
+ {"defunit_not_enemy", &battle_config.defnotenemy},
+ {"random_monster_checklv", &battle_config.random_monster_checklv},
+ {"attribute_recover", &battle_config.attr_recover},
+ {"flooritem_lifetime", &battle_config.flooritem_lifetime},
+ {"item_auto_get", &battle_config.item_auto_get},
+ {"drop_pickup_safety_zone", &battle_config.drop_pickup_safety_zone},
+ {"item_first_get_time", &battle_config.item_first_get_time},
+ {"item_second_get_time", &battle_config.item_second_get_time},
+ {"item_third_get_time", &battle_config.item_third_get_time},
+ {"mvp_item_first_get_time", &battle_config.mvp_item_first_get_time},
+ {"mvp_item_second_get_time", &battle_config.mvp_item_second_get_time},
+ {"mvp_item_third_get_time", &battle_config.mvp_item_third_get_time},
+ {"item_rate", &battle_config.item_rate},
+ {"drop_rate0item", &battle_config.drop_rate0item},
+ {"base_exp_rate", &battle_config.base_exp_rate},
+ {"job_exp_rate", &battle_config.job_exp_rate},
+ {"pvp_exp", &battle_config.pvp_exp},
+ {"gtb_pvp_only", &battle_config.gtb_pvp_only},
+ {"death_penalty_type", &battle_config.death_penalty_type},
+ {"death_penalty_base", &battle_config.death_penalty_base},
+ {"death_penalty_job", &battle_config.death_penalty_job},
+ {"zeny_penalty", &battle_config.zeny_penalty},
+ {"restart_hp_rate", &battle_config.restart_hp_rate},
+ {"restart_sp_rate", &battle_config.restart_sp_rate},
+ {"mvp_hp_rate", &battle_config.mvp_hp_rate},
+ {"mvp_item_rate", &battle_config.mvp_item_rate},
+ {"mvp_exp_rate", &battle_config.mvp_exp_rate},
+ {"monster_hp_rate", &battle_config.monster_hp_rate},
+ {"monster_max_aspd", &battle_config.monster_max_aspd},
+ {"atcommand_gm_only", &battle_config.atc_gmonly},
+ {"atcommand_spawn_quantity_limit", &battle_config.atc_spawn_quantity_limit},
+ {"gm_all_skill", &battle_config.gm_allskill},
+ {"gm_all_skill_add_abra", &battle_config.gm_allskill_addabra},
+ {"gm_all_equipment", &battle_config.gm_allequip},
+ {"gm_skill_unconditional", &battle_config.gm_skilluncond},
+ {"player_skillfree", &battle_config.skillfree},
+ {"player_skillup_limit", &battle_config.skillup_limit},
+ {"weapon_produce_rate", &battle_config.wp_rate},
+ {"potion_produce_rate", &battle_config.pp_rate},
+ {"monster_active_enable", &battle_config.monster_active_enable},
+ {"monster_damage_delay_rate", &battle_config.monster_damage_delay_rate},
+ {"monster_loot_type", &battle_config.monster_loot_type},
+ {"mob_skill_use", &battle_config.mob_skill_use},
+ {"mob_count_rate", &battle_config.mob_count_rate},
+ {"quest_skill_learn", &battle_config.quest_skill_learn},
+ {"quest_skill_reset", &battle_config.quest_skill_reset},
+ {"basic_skill_check", &battle_config.basic_skill_check},
+ {"player_invincible_time", &battle_config.pc_invincible_time},
+ {"skill_min_damage", &battle_config.skill_min_damage},
+ {"finger_offensive_type", &battle_config.finger_offensive_type},
+ {"heal_exp", &battle_config.heal_exp},
+ {"resurrection_exp", &battle_config.resurrection_exp},
+ {"shop_exp", &battle_config.shop_exp},
+ {"combo_delay_rate", &battle_config.combo_delay_rate},
+ {"item_check", &battle_config.item_check},
+ {"wedding_modifydisplay", &battle_config.wedding_modifydisplay},
+ {"natural_healhp_interval", &battle_config.natural_healhp_interval},
+ {"natural_healsp_interval", &battle_config.natural_healsp_interval},
+ {"natural_heal_skill_interval", &battle_config.natural_heal_skill_interval},
+ {"natural_heal_weight_rate", &battle_config.natural_heal_weight_rate},
+ {"itemheal_regeneration_factor", &battle_config.itemheal_regeneration_factor},
+ {"item_name_override_grffile", &battle_config.item_name_override_grffile},
+ {"arrow_decrement", &battle_config.arrow_decrement},
+ {"max_aspd", &battle_config.max_aspd},
+ {"max_hp", &battle_config.max_hp},
+ {"max_sp", &battle_config.max_sp},
+ {"max_lv", &battle_config.max_lv},
+ {"max_parameter", &battle_config.max_parameter},
+ {"max_cart_weight", &battle_config.max_cart_weight},
+ {"player_skill_log", &battle_config.pc_skill_log},
+ {"monster_skill_log", &battle_config.mob_skill_log},
+ {"battle_log", &battle_config.battle_log},
+ {"save_log", &battle_config.save_log},
+ {"error_log", &battle_config.error_log},
+ {"etc_log", &battle_config.etc_log},
+ {"save_clothcolor", &battle_config.save_clothcolor},
+ {"undead_detect_type", &battle_config.undead_detect_type},
+ {"player_auto_counter_type", &battle_config.pc_auto_counter_type},
+ {"monster_auto_counter_type", &battle_config.monster_auto_counter_type},
+ {"agi_penaly_type", &battle_config.agi_penaly_type},
+ {"agi_penaly_count", &battle_config.agi_penaly_count},
+ {"agi_penaly_num", &battle_config.agi_penaly_num},
+ {"agi_penaly_count_lv", &battle_config.agi_penaly_count_lv},
+ {"vit_penaly_type", &battle_config.vit_penaly_type},
+ {"vit_penaly_count", &battle_config.vit_penaly_count},
+ {"vit_penaly_num", &battle_config.vit_penaly_num},
+ {"vit_penaly_count_lv", &battle_config.vit_penaly_count_lv},
+ {"player_defense_type", &battle_config.player_defense_type},
+ {"monster_defense_type", &battle_config.monster_defense_type},
+ {"magic_defense_type", &battle_config.magic_defense_type},
+ {"player_skill_reiteration", &battle_config.pc_skill_reiteration},
+ {"monster_skill_reiteration", &battle_config.monster_skill_reiteration},
+ {"player_skill_nofootset", &battle_config.pc_skill_nofootset},
+ {"monster_skill_nofootset", &battle_config.monster_skill_nofootset},
+ {"player_cloak_check_type", &battle_config.pc_cloak_check_type},
+ {"monster_cloak_check_type", &battle_config.monster_cloak_check_type},
+ {"mob_changetarget_byskill", &battle_config.mob_changetarget_byskill},
+ {"player_attack_direction_change", &battle_config.pc_attack_direction_change},
+ {"monster_attack_direction_change", &battle_config.monster_attack_direction_change},
+ {"player_land_skill_limit", &battle_config.pc_land_skill_limit},
+ {"monster_land_skill_limit", &battle_config.monster_land_skill_limit},
+ {"party_skill_penaly", &battle_config.party_skill_penaly},
+ {"monster_class_change_full_recover", &battle_config.monster_class_change_full_recover},
+ {"produce_item_name_input", &battle_config.produce_item_name_input},
+ {"produce_potion_name_input", &battle_config.produce_potion_name_input},
+ {"making_arrow_name_input", &battle_config.making_arrow_name_input},
+ {"holywater_name_input", &battle_config.holywater_name_input},
+ {"display_delay_skill_fail", &battle_config.display_delay_skill_fail},
+ {"chat_warpportal", &battle_config.chat_warpportal},
+ {"mob_warpportal", &battle_config.mob_warpportal},
+ {"dead_branch_active", &battle_config.dead_branch_active},
+ {"show_steal_in_same_party", &battle_config.show_steal_in_same_party},
+ {"enable_upper_class", &battle_config.enable_upper_class},
+ {"mob_attack_attr_none", &battle_config.mob_attack_attr_none},
+ {"mob_ghostring_fix", &battle_config.mob_ghostring_fix},
+ {"pc_attack_attr_none", &battle_config.pc_attack_attr_none},
+ {"gx_allhit", &battle_config.gx_allhit},
+ {"gx_cardfix", &battle_config.gx_cardfix},
+ {"gx_dupele", &battle_config.gx_dupele},
+ {"gx_disptype", &battle_config.gx_disptype},
+ {"player_skill_partner_check", &battle_config.player_skill_partner_check},
+ {"hide_GM_session", &battle_config.hide_GM_session},
+ {"unit_movement_type", &battle_config.unit_movement_type},
+ {"invite_request_check", &battle_config.invite_request_check},
+ {"skill_removetrap_type", &battle_config.skill_removetrap_type},
+ {"disp_experience", &battle_config.disp_experience},
+ {"riding_weight", &battle_config.riding_weight},
+ {"item_rate_common", &battle_config.item_rate_common}, // Added by RoVeRT
+ {"item_rate_equip", &battle_config.item_rate_equip},
+ {"item_rate_card", &battle_config.item_rate_card}, // End Addition
+ {"item_rate_heal", &battle_config.item_rate_heal}, // Added by Valaris
+ {"item_rate_use", &battle_config.item_rate_use}, // End
+ {"item_drop_common_min", &battle_config.item_drop_common_min}, // Added by TyrNemesis^
+ {"item_drop_common_max", &battle_config.item_drop_common_max},
+ {"item_drop_equip_min", &battle_config.item_drop_equip_min},
+ {"item_drop_equip_max", &battle_config.item_drop_equip_max},
+ {"item_drop_card_min", &battle_config.item_drop_card_min},
+ {"item_drop_card_max", &battle_config.item_drop_card_max},
+ {"item_drop_mvp_min", &battle_config.item_drop_mvp_min},
+ {"item_drop_mvp_max", &battle_config.item_drop_mvp_max}, // End Addition
+ {"prevent_logout", &battle_config.prevent_logout}, // Added by RoVeRT
+ {"alchemist_summon_reward", &battle_config.alchemist_summon_reward}, // [Valaris]
+ {"maximum_level", &battle_config.maximum_level}, // [Valaris]
+ {"drops_by_luk", &battle_config.drops_by_luk}, // [Valaris]
+ {"monsters_ignore_gm", &battle_config.monsters_ignore_gm}, // [Valaris]
+ {"equipment_breaking", &battle_config.equipment_breaking}, // [Valaris]
+ {"equipment_break_rate", &battle_config.equipment_break_rate}, // [Valaris]
+ {"pk_mode", &battle_config.pk_mode}, // [Valaris]
+ {"multi_level_up", &battle_config.multi_level_up}, // [Valaris]
+ {"backstab_bow_penalty", &battle_config.backstab_bow_penalty},
+ {"night_at_start", &battle_config.night_at_start}, // added by [Yor]
+ {"day_duration", &battle_config.day_duration}, // added by [Yor]
+ {"night_duration", &battle_config.night_duration}, // added by [Yor]
+ {"show_mob_hp", &battle_config.show_mob_hp}, // [Valaris]
+ {"hack_info_GM_level", &battle_config.hack_info_GM_level}, // added by [Yor]
+ {"any_warp_GM_min_level", &battle_config.any_warp_GM_min_level}, // added by [Yor]
+ {"packet_ver_flag", &battle_config.packet_ver_flag}, // added by [Yor]
+ {"min_hair_style", &battle_config.min_hair_style}, // added by [MouseJstr]
+ {"max_hair_style", &battle_config.max_hair_style}, // added by [MouseJstr]
+ {"min_hair_color", &battle_config.min_hair_color}, // added by [MouseJstr]
+ {"max_hair_color", &battle_config.max_hair_color}, // added by [MouseJstr]
+ {"min_cloth_color", &battle_config.min_cloth_color}, // added by [MouseJstr]
+ {"max_cloth_color", &battle_config.max_cloth_color}, // added by [MouseJstr]
+ {"castrate_dex_scale", &battle_config.castrate_dex_scale}, // added by [MouseJstr]
+ {"area_size", &battle_config.area_size}, // added by [MouseJstr]
+ {"muting_players", &battle_config.muting_players}, // added by [Apple]
+ {"chat_lame_penalty", &battle_config.chat_lame_penalty},
+ {"chat_spam_threshold", &battle_config.chat_spam_threshold},
+ {"chat_spam_flood", &battle_config.chat_spam_flood},
+ {"chat_spam_ban", &battle_config.chat_spam_ban},
+ {"chat_spam_warn", &battle_config.chat_spam_warn},
+ {"chat_maxline", &battle_config.chat_maxline},
+ {"packet_spam_threshold", &battle_config.packet_spam_threshold},
+ {"packet_spam_flood", &battle_config.packet_spam_flood},
+ {"packet_spam_kick", &battle_config.packet_spam_kick},
+ {"mask_ip_gms", &battle_config.mask_ip_gms},
+ {"mob_splash_radius", &battle_config.mob_splash_radius},
};
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- if (sscanf(line, "%[^:]:%s", w1, w2) != 2)
+
+ if (w1 == "import")
+ {
+ battle_config_read(w2.c_str());
continue;
- for (i = 0; i < sizeof(data) / (sizeof(data[0])); i++)
- if (strcasecmp(w1, data[i].str) == 0)
- *data[i].val = config_switch(w2);
+ }
+
+ for (auto datum : data)
+ if (w1 == datum.str)
+ {
+ *datum.val = config_switch(w2.c_str());
+ goto continue_outer;
+ }
+
+ PRINTF("WARNING: unknown battle conf key: %s", w1);
- if (strcasecmp(w1, "import") == 0)
- battle_config_read(w2);
+ continue_outer:
+ ;
}
- fclose_(fp);
if (--count == 0)
{
diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp
index c7b8554..41c1381 100644
--- a/src/map/chrif.cpp
+++ b/src/map/chrif.cpp
@@ -12,6 +12,7 @@
#include <cstring>
#include <ctime>
+#include "../common/cxxstdio.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
#include "../common/timer.hpp"
@@ -50,20 +51,18 @@ int chrif_state;
*
*------------------------------------------
*/
-void chrif_setuserid(char *id)
+void chrif_setuserid(const char *id)
{
- strncpy(userid, id, sizeof(userid)-1);
- userid[sizeof(userid)-1] = '\0';
+ strzcpy(userid, id, sizeof(userid));
}
/*==========================================
*
*------------------------------------------
*/
-void chrif_setpasswd(char *pwd)
+void chrif_setpasswd(const char *pwd)
{
- strncpy(passwd, pwd, sizeof(passwd)-1);
- passwd[sizeof(passwd)-1] = '\0';
+ strzcpy(passwd, pwd, sizeof(passwd));
}
char *chrif_getpasswd(void)
@@ -75,10 +74,9 @@ char *chrif_getpasswd(void)
*
*------------------------------------------
*/
-void chrif_setip(char *ip)
+void chrif_setip(const char *ip)
{
- strncpy(char_ip_str, ip, sizeof(char_ip_str)-1);
- char_ip_str[sizeof(char_ip_str)-1] = '\0';
+ strzcpy(char_ip_str, ip, sizeof(char_ip_str));
char_ip = inet_addr(char_ip_str);
}
@@ -185,10 +183,10 @@ int chrif_recvmap(int fd)
{
map_setipport((const char *)RFIFOP(fd, i), ip, port);
// if (battle_config.etc_log)
-// printf("recv map %d %s\n", j, RFIFOP(fd,i));
+// PRINTF("recv map %d %s\n", j, RFIFOP(fd,i));
}
if (battle_config.etc_log)
- printf("recv map on %s:%d (%d maps)\n", ip2str(ip), port, j);
+ PRINTF("recv map on %s:%d (%d maps)\n", ip2str(ip), port, j);
return 0;
}
@@ -244,7 +242,7 @@ int chrif_changemapserverack(int fd)
if (RFIFOL(fd, 6) == 1)
{
if (battle_config.error_log)
- printf("map server change failed.\n");
+ PRINTF("map server change failed.\n");
pc_authfail(sd->fd);
return 0;
}
@@ -263,21 +261,21 @@ int chrif_connectack(int fd)
{
if (RFIFOB(fd, 2))
{
- printf("Connected to char-server failed %d.\n", RFIFOB(fd, 2));
+ PRINTF("Connected to char-server failed %d.\n", RFIFOB(fd, 2));
exit(1);
}
- printf("Connected to char-server (connection #%d).\n", fd);
+ PRINTF("Connected to char-server (connection #%d).\n", fd);
chrif_state = 1;
chrif_sendmap(fd);
- printf("chrif: OnCharIfInit event done. (%d events)\n",
+ PRINTF("chrif: OnCharIfInit event done. (%d events)\n",
npc_event_doall("OnCharIfInit"));
- printf("chrif: OnInterIfInit event done. (%d events)\n",
+ PRINTF("chrif: OnInterIfInit event done. (%d events)\n",
npc_event_doall("OnInterIfInit"));
// <Agit> Run Event [AgitInit]
-// printf("NPC_Event:[OnAgitInit] do (%d) events (Agit Initialize).\n", npc_event_doall("OnAgitInit"));
+// PRINTF("NPC_Event:[OnAgitInit] do (%d) events (Agit Initialize).\n", npc_event_doall("OnAgitInit"));
return 0;
}
@@ -291,7 +289,7 @@ int chrif_sendmapack(int fd)
{
if (RFIFOB(fd, 2))
{
- printf("chrif : send map list to char server failed %d\n",
+ PRINTF("chrif : send map list to char server failed %d\n",
RFIFOB(fd, 2));
exit(1);
}
@@ -386,7 +384,7 @@ int chrif_searchcharid(int char_id)
int chrif_changegm(int id, const char *pass, int len)
{
if (battle_config.etc_log)
- printf("chrif_changegm: account: %d, password: '%s'.\n", id, pass);
+ PRINTF("chrif_changegm: account: %d, password: '%s'.\n", id, pass);
WFIFOW(char_fd, 0) = 0x2b0a;
WFIFOW(char_fd, 2) = len + 8;
@@ -405,7 +403,7 @@ int chrif_changeemail(int id, const char *actual_email,
const char *new_email)
{
if (battle_config.etc_log)
- printf("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n",
+ PRINTF("chrif_changeemail: account: %d, actual_email: '%s', new_email: '%s'.\n",
id, actual_email, new_email);
WFIFOW(char_fd, 0) = 0x2b0c;
@@ -445,7 +443,7 @@ int chrif_char_ask_name(int id, char *character_name, short operation_type,
WFIFOW(char_fd, 40) = minute;
WFIFOW(char_fd, 42) = second;
}
- printf("chrif : sended 0x2b0e\n");
+ PRINTF("chrif : sended 0x2b0e\n");
WFIFOSET(char_fd, 44);
return 0;
@@ -472,7 +470,6 @@ int chrif_char_ask_name_answer(int fd)
{
int acc;
struct map_session_data *sd;
- char output[256];
char player_name[24];
acc = RFIFOL(fd, 2); // account_id of who has asked (-1 if nobody)
@@ -482,8 +479,10 @@ int chrif_char_ask_name_answer(int fd)
sd = map_id2sd(acc);
if (acc >= 0 && sd != NULL)
{
+ std::string output;
if (RFIFOW(fd, 32) == 1) // player not found
- sprintf(output, "The player '%s' doesn't exist.", player_name);
+ output = STRPRINTF("The player '%s' doesn't exist.",
+ player_name);
else
{
switch (RFIFOW(fd, 30))
@@ -492,20 +491,20 @@ int chrif_char_ask_name_answer(int fd)
switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf(output,
- "Login-server has been asked to block the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to block the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf(output,
- "Your GM level don't authorise you to block the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to block the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf(output,
- "Login-server is offline. Impossible to block the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to block the the player '%s'.",
+ player_name);
break;
}
break;
@@ -513,20 +512,20 @@ int chrif_char_ask_name_answer(int fd)
switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf(output,
- "Login-server has been asked to ban the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to ban the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf(output,
- "Your GM level don't authorise you to ban the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to ban the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf(output,
- "Login-server is offline. Impossible to ban the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to ban the the player '%s'.",
+ player_name);
break;
}
break;
@@ -534,20 +533,20 @@ int chrif_char_ask_name_answer(int fd)
switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf(output,
- "Login-server has been asked to unblock the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to unblock the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf(output,
- "Your GM level don't authorise you to unblock the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to unblock the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf(output,
- "Login-server is offline. Impossible to unblock the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to unblock the the player '%s'.",
+ player_name);
break;
}
break;
@@ -555,20 +554,20 @@ int chrif_char_ask_name_answer(int fd)
switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf(output,
- "Login-server has been asked to unban the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to unban the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf(output,
- "Your GM level don't authorise you to unban the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to unban the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf(output,
- "Login-server is offline. Impossible to unban the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to unban the the player '%s'.",
+ player_name);
break;
}
break;
@@ -576,33 +575,30 @@ int chrif_char_ask_name_answer(int fd)
switch (RFIFOW(fd, 32))
{
case 0: // login-server resquest done
- sprintf(output,
- "Login-server has been asked to change the sex of the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server has been asked to change the sex of the player '%s'.",
+ player_name);
break;
//case 1: // player not found
case 2: // gm level too low
- sprintf(output,
- "Your GM level don't authorise you to change the sex of the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Your GM level don't authorise you to change the sex of the player '%s'.",
+ player_name);
break;
case 3: // login-server offline
- sprintf(output,
- "Login-server is offline. Impossible to change the sex of the the player '%s'.",
- player_name);
+ output = STRPRINTF(
+ "Login-server is offline. Impossible to change the sex of the the player '%s'.",
+ player_name);
break;
}
break;
}
}
- if (output[0] != '\0')
- {
- output[sizeof(output) - 1] = '\0';
+ if (!output.empty())
clif_displaymessage(sd->fd, output);
- }
}
else
- printf("chrif_char_ask_name_answer failed - player not online.\n");
+ PRINTF("chrif_char_ask_name_answer failed - player not online.\n");
return 0;
}
@@ -623,7 +619,7 @@ int chrif_changedgm(int fd)
sd = map_id2sd(acc);
if (battle_config.etc_log)
- printf("chrif_changedgm: account: %d, GM level 0 -> %d.\n", acc,
+ PRINTF("chrif_changedgm: account: %d, GM level 0 -> %d.\n", acc,
level);
if (sd != NULL)
{
@@ -650,7 +646,7 @@ int chrif_changedsex(int fd)
acc = RFIFOL(fd, 2);
sex = RFIFOL(fd, 6);
if (battle_config.etc_log)
- printf("chrif_changedsex %d.\n", acc);
+ PRINTF("chrif_changedsex %d.\n", acc);
sd = map_id2sd(acc);
if (acc > 0)
{
@@ -702,7 +698,7 @@ int chrif_changedsex(int fd)
{
if (sd != NULL)
{
- printf("chrif_changedsex failed.\n");
+ PRINTF("chrif_changedsex failed.\n");
}
}
@@ -757,7 +753,7 @@ int chrif_accountreg2(int fd)
sd->status.account_reg2[j].value = RFIFOL(fd, p + 32);
}
sd->status.account_reg2_num = j;
-// printf("chrif: accountreg2\n");
+// PRINTF("chrif: accountreg2\n");
return 0;
}
@@ -823,7 +819,7 @@ int chrif_accountdeletion(int fd)
acc = RFIFOL(fd, 2);
if (battle_config.etc_log)
- printf("chrif_accountdeletion %d.\n", acc);
+ PRINTF("chrif_accountdeletion %d.\n", acc);
sd = map_id2sd(acc);
if (acc > 0)
{
@@ -838,7 +834,7 @@ int chrif_accountdeletion(int fd)
else
{
if (sd != NULL)
- printf("chrif_accountdeletion failed - player not online.\n");
+ PRINTF("chrif_accountdeletion failed - player not online.\n");
}
return 0;
@@ -856,7 +852,7 @@ int chrif_accountban(int fd)
acc = RFIFOL(fd, 2);
if (battle_config.etc_log)
- printf("chrif_accountban %d.\n", acc);
+ PRINTF("chrif_accountban %d.\n", acc);
sd = map_id2sd(acc);
if (acc > 0)
{
@@ -929,7 +925,7 @@ int chrif_accountban(int fd)
else
{
if (sd != NULL)
- printf("chrif_accountban failed - player not online.\n");
+ PRINTF("chrif_accountban failed - player not online.\n");
}
return 0;
@@ -942,7 +938,7 @@ int chrif_accountban(int fd)
static
int chrif_recvgmaccounts(int fd)
{
- printf("From login-server: receiving of %d GM accounts information.\n",
+ PRINTF("From login-server: receiving of %d GM accounts information.\n",
pc_read_gm_account(fd));
return 0;
@@ -1081,7 +1077,7 @@ void chrif_parse(int fd)
{
if (fd == char_fd)
{
- printf("Map-server can't connect to char-server (connection #%d).\n",
+ PRINTF("Map-server can't connect to char-server (connection #%d).\n",
fd);
char_fd = -1;
}
@@ -1181,7 +1177,7 @@ void chrif_parse(int fd)
default:
if (battle_config.error_log)
- printf("chrif_parse : unknown packet %d %d\n", fd,
+ PRINTF("chrif_parse : unknown packet %d %d\n", fd,
RFIFOW(fd, 0));
session[fd]->eof = 1;
return;
@@ -1231,7 +1227,7 @@ void check_connect_char_server(timer_id, tick_t, custom_id_t, custom_data_t)
{
if (char_fd <= 0 || session[char_fd] == NULL)
{
- printf("Attempt to connect to char-server...\n");
+ PRINTF("Attempt to connect to char-server...\n");
chrif_state = 0;
if ((char_fd = make_connection(char_ip, char_port)) < 0)
return;
diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp
index b262a7f..7c4a431 100644
--- a/src/map/chrif.hpp
+++ b/src/map/chrif.hpp
@@ -1,11 +1,11 @@
#ifndef CHRIF_HPP
#define CHRIF_HPP
-void chrif_setuserid(char *);
-void chrif_setpasswd(char *);
+void chrif_setuserid(const char *);
+void chrif_setpasswd(const char *);
char *chrif_getpasswd(void);
-void chrif_setip(char *);
+void chrif_setip(const char *);
void chrif_setport(int);
int chrif_isconnect(void);
diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index cf47d2f..913a6ac 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -13,6 +13,7 @@
#include <cstring>
#include <ctime>
+#include "../common/cxxstdio.hpp"
#include "../common/md5calc.hpp"
#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
@@ -280,10 +281,10 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len,
{
if (WFIFOP(sd->fd, 0) == buf)
{
- printf("WARNING: Invalid use of clif_send function\n");
- printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n",
+ PRINTF("WARNING: Invalid use of clif_send function\n");
+ PRINTF(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n",
WBUFW(buf, 0));
- printf(" Please correct your code.\n");
+ PRINTF(" Please correct your code.\n");
// don't send to not move the pointer of the packet for next sessions in the loop
}
else
@@ -482,7 +483,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
default:
if (battle_config.error_log)
- printf("clif_send まだ作ってないよー\n");
+ PRINTF("clif_send まだ作ってないよー\n");
return -1;
}
@@ -2127,8 +2128,8 @@ int clif_updatestatus(struct map_session_data *sd, SP type)
default:
if (battle_config.error_log)
- printf("clif_updatestatus : make %d routine\n",
- uint16_t(type));
+ PRINTF("clif_updatestatus : make %d routine\n",
+ type);
return 1;
}
WFIFOSET(fd, len);
@@ -3099,8 +3100,8 @@ void clif_getareachar(struct block_list *bl, struct map_session_data *sd)
break;
default:
if (battle_config.error_log)
- printf("get area char ??? %d\n",
- uint8_t(bl->type));
+ PRINTF("get area char ??? %d\n",
+ bl->type);
break;
}
}
@@ -3432,43 +3433,39 @@ int clif_status_change(struct block_list *bl, StatusChange type, int flag)
* Send message (modified by [Yor])
*------------------------------------------
*/
-int clif_displaymessage(int fd, const char *mes)
+void clif_displaymessage(int fd, const_string mes)
{
- int len_mes = strlen(mes);
-
- if (len_mes > 0)
- { // don't send a void message (it's not displaying on the client chat). @help can send void line.
+ if (mes)
+ {
+ // don't send a void message (it's not displaying on the client chat). @help can send void line.
WFIFOW(fd, 0) = 0x8e;
- WFIFOW(fd, 2) = 5 + len_mes; // 4 + len + NULL teminate
- memcpy(WFIFOP(fd, 4), mes, len_mes + 1);
- WFIFOSET(fd, 5 + len_mes);
+ WFIFOW(fd, 2) = 5 + mes.size(); // 4 + len + NULL teminate
+ memcpy(WFIFOP(fd, 4), mes.data(), mes.size());
+ WFIFOB(fd, 4 + mes.size()) = '\0';
+ WFIFOSET(fd, 5 + mes.size());
}
-
- return 0;
}
/*==========================================
* 天の声を送信する
*------------------------------------------
*/
-int clif_GMmessage(struct block_list *bl, const char *mes, int len, int flag)
+void clif_GMmessage(struct block_list *bl, const_string mes, int flag)
{
- unsigned char lbuf[255];
- unsigned char *buf =
- ((len + 16) >= sizeof(lbuf)) ? (unsigned char*)malloc(len + 16) : lbuf;
+ unsigned char buf[mes.size() + 16];
int lp = (flag & 0x10) ? 8 : 4;
WBUFW(buf, 0) = 0x9a;
- WBUFW(buf, 2) = len + lp;
+ WBUFW(buf, 2) = mes.size() + 1 + lp;
WBUFL(buf, 4) = 0x65756c62;
- memcpy(WBUFP(buf, lp), mes, len);
+ memcpy(WBUFP(buf, lp), mes.data(), mes.size());
+ WBUFB(buf, lp + mes.size()) = '\0';
flag &= 0x07;
clif_send(buf, WBUFW(buf, 2), bl,
(flag == 1) ? ALL_SAMEMAP :
- (flag == 2) ? AREA : (flag == 3) ? SELF : ALL_CLIENT);
- if (buf != lbuf)
- free(buf);
- return 0;
+ (flag == 2) ? AREA :
+ (flag == 3) ? SELF :
+ ALL_CLIENT);
}
/*==========================================
@@ -3659,7 +3656,7 @@ int clif_party_option(struct party *p, struct map_session_data *sd, int flag)
nullpo_ret(p);
// if(battle_config.etc_log)
-// printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
+// PRINTF("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
if (sd == NULL && flag == 0)
{
int i;
@@ -3760,7 +3757,7 @@ int clif_party_xy(struct party *, struct map_session_data *sd)
WBUFW(buf, 8) = sd->bl.y;
clif_send(buf, packet_len_table[0x107], &sd->bl, PARTY_SAMEMAP_WOS);
// if(battle_config.etc_log)
-// printf("clif_party_xy %d\n",sd->status.account_id);
+// PRINTF("clif_party_xy %d\n",sd->status.account_id);
return 0;
}
@@ -3781,7 +3778,7 @@ int clif_party_hp(struct party *, struct map_session_data *sd)
(sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
clif_send(buf, packet_len_table[0x106], &sd->bl, PARTY_AREA_WOS);
// if(battle_config.etc_log)
-// printf("clif_party_hp %d\n",sd->status.account_id);
+// PRINTF("clif_party_hp %d\n",sd->status.account_id);
return 0;
}
@@ -3882,30 +3879,6 @@ void clif_sitting(int, struct map_session_data *sd)
*
*------------------------------------------
*/
-int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
-{
- unsigned char lbuf[255];
- unsigned char *buf =
- (len + 32 >= sizeof(lbuf)) ? (unsigned char *)malloc(len + 32) : lbuf;
-
- nullpo_ret(sd);
-
- WBUFW(buf, 0) = 0x17f;
- WBUFW(buf, 2) = len + 8;
- memcpy(WBUFP(buf, 4), mes, len + 4);
-
- clif_send(buf, WBUFW(buf, 2), &sd->bl, SELF);
-
- if (buf != lbuf)
- free(buf);
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
static
int clif_GM_kickack(struct map_session_data *sd, int id)
{
@@ -3988,7 +3961,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
if (sd)
{
if (battle_config.error_log)
- printf("clif_parse_WantToConnection : invalid request?\n");
+ PRINTF("clif_parse_WantToConnection : invalid request?\n");
return;
}
@@ -4007,7 +3980,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
{
clif_authfail_fd(fd, 2); // same id
clif_authfail_fd(old_sd->fd, 2); // same id
- printf("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n",
+ PRINTF("clif_parse_WantToConnection: Double connection for account %d (sessions: #%d (new) and #%d (old)).\n",
account_id, fd, old_sd->fd);
}
else
@@ -4363,8 +4336,8 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
break;
default:
if (battle_config.error_log)
- printf("clif_parse_GetCharNameRequest : bad type %d (%d)\n",
- uint8_t(bl->type), account_id);
+ PRINTF("clif_parse_GetCharNameRequest : bad type %d (%d)\n",
+ bl->type, account_id);
break;
}
}
@@ -4393,7 +4366,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd)
return;
}
- if (is_atcommand(fd, sd, message, 0) != AtCommand_None
+ if (is_atcommand(fd, sd, message, 0)
|| ((sd->sc_data[SC_BERSERK].timer != -1 //バーサーク時は会話も不可
|| sd->sc_data[SC_NOCHAT].timer != -1)))//チャット禁止
{
@@ -4659,7 +4632,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd)
return;
}
- if (is_atcommand(fd, sd, message, 0) != AtCommand_None
+ if (is_atcommand(fd, sd, message, 0)
|| ((sd->sc_data[SC_BERSERK].timer != -1
|| sd->sc_data[SC_NOCHAT].timer != -1)))
{
@@ -4734,21 +4707,21 @@ void clif_parse_Wis(int fd, struct map_session_data *sd)
static
void clif_parse_GMmessage(int fd, struct map_session_data *sd)
{
- char m[512];
- char output[200];
+ char m[(RFIFOW(fd, 2) - 4) + 1];
nullpo_retv(sd);
if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
(pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast)))
{
strncpy(m, (const char *)RFIFOP(fd, 4), RFIFOW(fd, 2) - 4);
- m[RFIFOW(fd, 2) - 4] = 0;
- log_atcommand(sd, "/announce %s", m);
+ m[RFIFOW(fd, 2) - 4] = '\0';
+ const char *m_p = m; // because VLAs can't be passed to STRPRINTF
+ std::string fake_command = STRPRINTF("/announce %s", m_p);
+ log_atcommand(sd, fake_command);
- memset(output, '\0', sizeof(output));
- snprintf(output, 199, "%s : %s", sd->status.name, m);
+ std::string output = STRPRINTF("%s : %s", sd->status.name, m_p);
- intif_GMmessage(output, strlen(output) + 1, 0);
+ intif_GMmessage(output, 0);
}
}
@@ -5345,7 +5318,7 @@ void clif_parse_NpcStringInput(int fd, struct map_session_data *sd)
if (len >= sizeof(sd->npc_str) - 1)
{
- printf("clif_parse_NpcStringInput(): Input string too long!\n");
+ PRINTF("clif_parse_NpcStringInput(): Input string too long!\n");
len = sizeof(sd->npc_str) - 1;
}
@@ -5551,7 +5524,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data *sd)
return;
}
- if (is_atcommand(fd, sd, message, 0) != AtCommand_None
+ if (is_atcommand(fd, sd, message, 0)
|| ((sd->sc_data[SC_BERSERK].timer != -1 //バーサーク時は会話も不可
|| sd->sc_data[SC_NOCHAT].timer != -1))) //チャット禁止
{
@@ -5590,7 +5563,9 @@ void clif_parse_GMKick(int fd, struct map_session_data *sd)
{
struct map_session_data *tsd =
(struct map_session_data *) target;
- log_atcommand(sd, "@kick %s", tsd->status.name);
+ std::string fake_command = STRPRINTF("kick %s",
+ tsd->status.name);
+ log_atcommand(sd, fake_command);
if (pc_isGM(sd) > pc_isGM(tsd))
clif_GM_kick(sd, tsd, 1);
else
@@ -5615,7 +5590,7 @@ void clif_parse_GMHide(int fd, struct map_session_data *sd)
{ // Modified by [Yor]
nullpo_retv(sd);
- //printf("%2x %2x %2x\n", RFIFOW(fd,0), RFIFOW(fd,2), RFIFOW(fd,4)); // R 019d <Option_value>.2B <flag>.2B
+ //PRINTF("%2x %2x %2x\n", RFIFOW(fd,0), RFIFOW(fd,2), RFIFOW(fd,4)); // R 019d <Option_value>.2B <flag>.2B
if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
(pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide)))
{
@@ -5638,7 +5613,7 @@ void clif_parse_GMHide(int fd, struct map_session_data *sd)
static
void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
{ // Rewritten by [Yor]
- //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
+ //PRINTF("Ignore all: state: %d\n", RFIFOB(fd,2));
if (RFIFOB(fd, 2) == 0)
{ // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
WFIFOW(fd, 0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
@@ -6306,7 +6281,7 @@ int clif_check_packet_flood(int fd, int cmd)
if (sd->packet_flood_in >= battle_config.packet_spam_flood)
{
- printf("packet flood detected from %s [0x%x]\n", sd->status.name, cmd);
+ PRINTF("packet flood detected from %s [0x%x]\n", sd->status.name, cmd);
if (battle_config.packet_spam_kick)
{
session[fd]->eof = 1; // Kick
@@ -6323,7 +6298,7 @@ int clif_check_packet_flood(int fd, int cmd)
}
#define WARN_MALFORMED_MSG(sd, msg) \
- printf("clif_validate_chat(): %s (ID %d) sent a malformed" \
+ PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed" \
" message: %s.\n", sd->status.name, sd->status.account_id, msg)
/**
* Validate message integrity (inspired by upstream source (eAthena)).
@@ -6482,13 +6457,13 @@ void clif_parse(int fd)
pc_logout(sd);
clif_quitsave(fd, sd);
if (sd->status.name != NULL)
- printf("Player [%s] has logged off your server.\n", sd->status.name); // Player logout display [Valaris]
+ PRINTF("Player [%s] has logged off your server.\n", sd->status.name); // Player logout display [Valaris]
else
- printf("Player with account [%d] has logged off your server.\n", sd->bl.id); // Player logout display [Yor]
+ PRINTF("Player with account [%d] has logged off your server.\n", sd->bl.id); // Player logout display [Yor]
}
else if (sd)
{ // not authentified! (refused by char-server or disconnect before to be authentified)
- printf("Player with account [%d] has logged off your server (not auth account).\n", sd->bl.id); // Player logout display [Yor]
+ PRINTF("Player with account [%d] has logged off your server (not auth account).\n", sd->bl.id); // Player logout display [Yor]
map_deliddb(&sd->bl); // account_id has been included in the DB before auth answer
}
if (fd)
@@ -6571,7 +6546,7 @@ void clif_parse(int fd)
if (battle_config.error_log)
{
if (fd)
- printf("\nclif_parse: session #%d, packet 0x%x, lenght %d\n",
+ PRINTF("\nclif_parse: session #%d, packet 0x%x, lenght %d\n",
fd, cmd, packet_len);
#ifdef DUMP_UNKNOWN_PACKET
{
@@ -6579,28 +6554,28 @@ void clif_parse(int fd)
FILE *fp;
char packet_txt[256] = "save/packet.txt";
time_t now;
- printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
+ PRINTF("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
for (i = 0; i < packet_len; i++)
{
if ((i & 15) == 0)
- printf("\n%04X ", i);
- printf("%02X ", RFIFOB(fd, i));
+ PRINTF("\n%04X ", i);
+ PRINTF("%02X ", RFIFOB(fd, i));
}
if (sd && sd->state.auth)
{
if (sd->status.name != NULL)
- printf("\nAccount ID %d, character ID %d, player name %s.\n",
+ PRINTF("\nAccount ID %d, character ID %d, player name %s.\n",
sd->status.account_id, sd->status.char_id,
sd->status.name);
else
- printf("\nAccount ID %d.\n", sd->bl.id);
+ PRINTF("\nAccount ID %d.\n", sd->bl.id);
}
else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
- printf("\nAccount ID %d.\n", sd->bl.id);
+ PRINTF("\nAccount ID %d.\n", sd->bl.id);
if ((fp = fopen_(packet_txt, "a")) == NULL)
{
- printf("clif.c: cant write [%s] !!! data is lost !!!\n",
+ PRINTF("clif.c: cant write [%s] !!! data is lost !!!\n",
packet_txt);
return;
}
@@ -6610,30 +6585,30 @@ void clif_parse(int fd)
if (sd && sd->state.auth)
{
if (sd->status.name != NULL)
- fprintf(fp,
+ FPRINTF(fp,
"%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
asctime(gmtime(&now)),
sd->status.account_id,
sd->status.char_id, sd->status.name);
else
- fprintf(fp,
+ FPRINTF(fp,
"%sPlayer with account ID %d sent wrong packet:\n",
asctime(gmtime(&now)), sd->bl.id);
}
else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
- fprintf(fp,
+ FPRINTF(fp,
"%sPlayer with account ID %d sent wrong packet:\n",
asctime(gmtime(&now)), sd->bl.id);
- fprintf(fp,
+ FPRINTF(fp,
"\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
for (i = 0; i < packet_len; i++)
{
if ((i & 15) == 0)
- fprintf(fp, "\n\t%04X ", i);
- fprintf(fp, "%02X ", RFIFOB(fd, i));
+ FPRINTF(fp, "\n\t%04X ", i);
+ FPRINTF(fp, "%02X ", RFIFOB(fd, i));
}
- fprintf(fp, "\n\n");
+ FPRINTF(fp, "\n\n");
fclose_(fp);
}
}
@@ -6664,7 +6639,7 @@ int do_init_clif (void)
}
if (i == 10)
{
- printf("cant bind game port\n");
+ PRINTF("cant bind game port\n");
exit(1);
}
diff --git a/src/map/clif.hpp b/src/map/clif.hpp
index 2158d3a..75dc73d 100644
--- a/src/map/clif.hpp
+++ b/src/map/clif.hpp
@@ -6,6 +6,8 @@
#include <sys/socket.h>
#include <sys/types.h>
+#include "../common/const_array.hpp"
+
#include "pc.t.hpp"
#include "map.hpp"
@@ -140,9 +142,8 @@ int clif_party_xy(struct party *p, struct map_session_data *sd);
int clif_party_hp(struct party *p, struct map_session_data *sd);
// atcommand
-int clif_displaymessage(int fd, const char *mes);
-int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len);
-int clif_GMmessage(struct block_list *bl, const char *mes, int len, int flag);
+void clif_displaymessage(int fd, const_string mes);
+void clif_GMmessage(struct block_list *bl, const_string mes, int flag);
int clif_resurrection(struct block_list *bl, int type);
int clif_specialeffect(struct block_list *bl, int type, int flag); // special effects [Valaris]
diff --git a/src/map/intif.cpp b/src/map/intif.cpp
index 87ea5d0..44d381b 100644
--- a/src/map/intif.cpp
+++ b/src/map/intif.cpp
@@ -47,16 +47,15 @@ extern int char_fd; // inter serverのfdはchar_fdを使う
// inter serverへの送信
// Message for all GMs on all map servers
-int intif_GMmessage(const char *mes, int len, int flag)
+void intif_GMmessage(const_string mes, int flag)
{
int lp = (flag & 0x10) ? 8 : 4;
WFIFOW(inter_fd, 0) = 0x3000;
- WFIFOW(inter_fd, 2) = lp + len;
+ WFIFOW(inter_fd, 2) = lp + mes.size() + 1;
WFIFOL(inter_fd, 4) = 0x65756c62;
- memcpy(WFIFOP(inter_fd, lp), mes, len);
+ memcpy(WFIFOP(inter_fd, lp), mes.data(), mes.size());
+ WFIFOB(inter_fd, lp + mes.size()) = '\0';
WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
-
- return 0;
}
// The transmission of Wisp/Page to inter-server (player not found on this server)
@@ -73,7 +72,7 @@ int intif_wis_message(struct map_session_data *sd, const char *nick, const char
WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
if (battle_config.etc_log)
- printf("intif_wis_message from %s to %s (message: '%s')\n",
+ PRINTF("intif_wis_message from %s to %s (message: '%s')\n",
sd->status.name, nick, mes);
return 0;
@@ -89,7 +88,7 @@ int intif_wis_replay(int id, int flag)
WFIFOSET(inter_fd, 7);
if (battle_config.etc_log)
- printf("intif_wis_replay: id: %d, flag:%d\n", id, flag);
+ PRINTF("intif_wis_replay: id: %d, flag:%d\n", id, flag);
return 0;
}
@@ -106,7 +105,7 @@ int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char
WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
if (battle_config.etc_log)
- printf("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n",
+ PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n",
Wisp_name, min_gm_level, mes);
return 0;
@@ -176,7 +175,7 @@ int intif_create_party(struct map_session_data *sd, const char *name)
WFIFOW(inter_fd, 70) = sd->status.base_level;
WFIFOSET(inter_fd, 72);
// if(battle_config.etc_log)
-// printf("intif: create party\n");
+// PRINTF("intif: create party\n");
return 0;
}
@@ -187,7 +186,7 @@ int intif_request_partyinfo(int party_id)
WFIFOL(inter_fd, 2) = party_id;
WFIFOSET(inter_fd, 6);
// if(battle_config.etc_log)
-// printf("intif: request party info\n");
+// PRINTF("intif: request party info\n");
return 0;
}
@@ -197,7 +196,7 @@ int intif_party_addmember(int party_id, int account_id)
struct map_session_data *sd;
sd = map_id2sd(account_id);
// if(battle_config.etc_log)
-// printf("intif: party add member %d %d\n",party_id,account_id);
+// PRINTF("intif: party add member %d %d\n",party_id,account_id);
if (sd != NULL)
{
WFIFOW(inter_fd, 0) = 0x3022;
@@ -227,7 +226,7 @@ int intif_party_changeoption(int party_id, int account_id, int exp, int item)
int intif_party_leave(int party_id, int account_id)
{
// if(battle_config.etc_log)
-// printf("intif: party leave %d %d\n",party_id,account_id);
+// PRINTF("intif: party leave %d %d\n",party_id,account_id);
WFIFOW(inter_fd, 0) = 0x3024;
WFIFOL(inter_fd, 2) = party_id;
WFIFOL(inter_fd, 6) = account_id;
@@ -249,7 +248,7 @@ int intif_party_changemap(struct map_session_data *sd, int online)
WFIFOSET(inter_fd, 29);
}
// if(battle_config.etc_log)
-// printf("party: change map\n");
+// PRINTF("party: change map\n");
return 0;
}
@@ -257,7 +256,7 @@ int intif_party_changemap(struct map_session_data *sd, int online)
int intif_party_message(int party_id, int account_id, const char *mes, int len)
{
// if(battle_config.etc_log)
-// printf("intif_party_message: %s\n",mes);
+// PRINTF("intif_party_message: %s\n",mes);
WFIFOW(inter_fd, 0) = 0x3027;
WFIFOW(inter_fd, 2) = len + 12;
WFIFOL(inter_fd, 4) = party_id;
@@ -289,7 +288,7 @@ int intif_parse_WisMessage(int fd)
int i;
if (battle_config.etc_log)
- printf("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n",
+ PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n",
RFIFOL(fd, 4), RFIFOP(fd, 8), RFIFOP(fd, 32), RFIFOP(fd,
56));
sd = map_nick2sd((const char *)RFIFOP(fd, 32)); // Searching destination player
@@ -330,7 +329,7 @@ int intif_parse_WisEnd(int fd)
struct map_session_data *sd;
if (battle_config.etc_log)
- printf("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd, 2), RFIFOB(fd, 26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
+ PRINTF("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd, 2), RFIFOB(fd, 26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
sd = map_nick2sd((const char *)RFIFOP(fd, 2));
if (sd != NULL)
clif_wis_end(sd->fd, RFIFOB(fd, 26));
@@ -388,7 +387,7 @@ int intif_parse_AccountReg(int fd)
sd->status.account_reg[j].value = RFIFOL(fd, p + 32);
}
sd->status.account_reg_num = j;
-// printf("intif: accountreg\n");
+// PRINTF("intif: accountreg\n");
return 0;
}
@@ -404,7 +403,7 @@ int intif_parse_LoadStorage(int fd)
if (sd == NULL)
{
if (battle_config.error_log)
- printf("intif_parse_LoadStorage: user not found %d\n",
+ PRINTF("intif_parse_LoadStorage: user not found %d\n",
RFIFOL(fd, 4));
return 1;
}
@@ -412,14 +411,14 @@ int intif_parse_LoadStorage(int fd)
if (stor->storage_status == 1)
{ // Already open.. lets ignore this update
if (battle_config.error_log)
- printf("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n",
+ PRINTF("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n",
sd->status.account_id, sd->status.char_id);
return 1;
}
if (stor->dirty)
{ // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
if (battle_config.error_log)
- printf("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n",
+ PRINTF("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n",
sd->status.account_id, sd->status.char_id);
return 1;
}
@@ -427,12 +426,12 @@ int intif_parse_LoadStorage(int fd)
if (RFIFOW(fd, 2) - 8 != sizeof(struct storage))
{
if (battle_config.error_log)
- printf("intif_parse_LoadStorage: data size error %d %d\n",
+ PRINTF("intif_parse_LoadStorage: data size error %d %d\n",
RFIFOW(fd, 2) - 8, sizeof(struct storage));
return 1;
}
if (battle_config.save_log)
- printf("intif_openstorage: %d\n", RFIFOL(fd, 4));
+ PRINTF("intif_openstorage: %d\n", RFIFOL(fd, 4));
memcpy(stor, RFIFOP(fd, 8), sizeof(struct storage));
stor->dirty = 0;
stor->storage_status = 1;
@@ -449,7 +448,7 @@ static
int intif_parse_SaveStorage(int fd)
{
if (battle_config.save_log)
- printf("intif_savestorage: done %d %d\n", RFIFOL(fd, 2),
+ PRINTF("intif_savestorage: done %d %d\n", RFIFOL(fd, 2),
RFIFOB(fd, 6));
storage_storage_saved(RFIFOL(fd, 2));
return 0;
@@ -460,7 +459,7 @@ static
int intif_parse_PartyCreated(int fd)
{
if (battle_config.etc_log)
- printf("intif: party created\n");
+ PRINTF("intif: party created\n");
party_created(RFIFOL(fd, 2), RFIFOB(fd, 6), RFIFOL(fd, 7),
(const char *)RFIFOP(fd, 11));
return 0;
@@ -473,16 +472,16 @@ int intif_parse_PartyInfo(int fd)
if (RFIFOW(fd, 2) == 8)
{
if (battle_config.error_log)
- printf("intif: party noinfo %d\n", RFIFOL(fd, 4));
+ PRINTF("intif: party noinfo %d\n", RFIFOL(fd, 4));
party_recv_noinfo(RFIFOL(fd, 4));
return 0;
}
-// printf("intif: party info %d\n",RFIFOL(fd,4));
+// PRINTF("intif: party info %d\n",RFIFOL(fd,4));
if (RFIFOW(fd, 2) != sizeof(struct party) + 4)
{
if (battle_config.error_log)
- printf("intif: party info : data size error %d %d %d\n",
+ PRINTF("intif: party info : data size error %d %d %d\n",
RFIFOL(fd, 4), RFIFOW(fd, 2),
sizeof(struct party) + 4);
}
@@ -495,7 +494,7 @@ static
int intif_parse_PartyMemberAdded(int fd)
{
if (battle_config.etc_log)
- printf("intif: party member added %d %d %d\n", RFIFOL(fd, 2),
+ PRINTF("intif: party member added %d %d %d\n", RFIFOL(fd, 2),
RFIFOL(fd, 6), RFIFOB(fd, 10));
party_member_added(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10));
return 0;
@@ -515,7 +514,7 @@ static
int intif_parse_PartyMemberLeaved(int fd)
{
if (battle_config.etc_log)
- printf("intif: party member leaved %d %d %s\n", RFIFOL(fd, 2),
+ PRINTF("intif: party member leaved %d %d %s\n", RFIFOL(fd, 2),
RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10));
party_member_leaved(RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10));
return 0;
@@ -534,7 +533,7 @@ static
int intif_parse_PartyMove(int fd)
{
// if(battle_config.etc_log)
-// printf("intif: party move %d %d %s %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOP(fd,10),RFIFOB(fd,26),RFIFOW(fd,27));
+// PRINTF("intif: party move %d %d %s %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOP(fd,10),RFIFOB(fd,26),RFIFOW(fd,27));
party_recv_movemap(RFIFOL(fd, 2), RFIFOL(fd, 6), (const char *)RFIFOP(fd, 10),
RFIFOB(fd, 26), RFIFOW(fd, 27));
return 0;
@@ -545,7 +544,7 @@ static
int intif_parse_PartyMessage(int fd)
{
// if(battle_config.etc_log)
-// printf("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12));
+// PRINTF("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12));
party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), (const char *)RFIFOP(fd, 12),
RFIFOW(fd, 2) - 12);
return 0;
@@ -576,7 +575,7 @@ int intif_parse(int fd)
packet_len = RFIFOW(fd, 2);
}
// if(battle_config.etc_log)
-// printf("intif_parse %d %x %d %d\n",fd,cmd,packet_len,RFIFOREST(fd));
+// PRINTF("intif_parse %d %x %d %d\n",fd,cmd,packet_len,RFIFOREST(fd));
if (RFIFOREST(fd) < packet_len)
{
return 2;
@@ -585,7 +584,9 @@ int intif_parse(int fd)
switch (cmd)
{
case 0x3800:
- clif_GMmessage(NULL, (const char *)RFIFOP(fd, 4), packet_len - 4, 0);
+ clif_GMmessage(NULL,
+ const_string((const char *)RFIFOP(fd, 4),
+ (packet_len - 4) - 1), 0);
break;
case 0x3801:
intif_parse_WisMessage(fd);
@@ -631,7 +632,7 @@ int intif_parse(int fd)
break;
default:
if (battle_config.error_log)
- printf("intif_parse : unknown packet %d %x\n", fd,
+ PRINTF("intif_parse : unknown packet %d %x\n", fd,
RFIFOW(fd, 0));
return 0;
}
diff --git a/src/map/intif.hpp b/src/map/intif.hpp
index 720c7cd..7a03483 100644
--- a/src/map/intif.hpp
+++ b/src/map/intif.hpp
@@ -1,9 +1,11 @@
#ifndef INTIF_HPP
#define INTIF_HPP
+#include "../common/const_array.hpp"
+
int intif_parse(int fd);
-int intif_GMmessage(const char *mes, int len, int flag);
+void intif_GMmessage(const_string mes, int flag);
int intif_wis_message(struct map_session_data *sd, const char *nick, const char *mes,
int mes_len);
diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp
index 58206ba..fc3f59e 100644
--- a/src/map/itemdb.cpp
+++ b/src/map/itemdb.cpp
@@ -46,8 +46,6 @@ int itemdb_read_randomitem(void);
static
int itemdb_read_itemavail(void);
static
-int itemdb_read_itemnametable(void);
-static
int itemdb_read_noequip(void);
/*==========================================
@@ -220,43 +218,6 @@ int itemdb_isequip3(int nameid)
|| type == ItemType::_8);
}
-//
-// 初期化
-//
-/*==========================================
- *
- *------------------------------------------
- */
-static
-int itemdb_read_itemslottable(void)
-{
- char *buf, *p;
- size_t s;
-
- buf = (char *)grfio_reads("data\\itemslottable.txt", &s);
- if (buf == NULL)
- return -1;
- buf[s] = 0;
- for (p = buf; p - buf < s;)
- {
- int nameid, equip_;
- sscanf(p, "%d#%d#", &nameid, &equip_);
- EPOS equip = EPOS(equip_);
- itemdb_search(nameid)->equip = equip;
- p = strchr(p, 10);
- if (!p)
- break;
- p++;
- p = strchr(p, 10);
- if (!p)
- break;
- p++;
- }
- free(buf);
-
- return 0;
-}
-
/*==========================================
* アイテムデータベースの読み込み
*------------------------------------------
@@ -281,7 +242,7 @@ int itemdb_readdb(void)
{
if (i > 0)
continue;
- printf("can't read %s\n", filename[i]);
+ PRINTF("can't read %s\n", filename[i]);
exit(1);
}
@@ -358,7 +319,7 @@ int itemdb_readdb(void)
id->equip_script = parse_script(p, lines);
}
fclose_(fp);
- printf("read %s done (count=%d)\n", filename[i], ln);
+ PRINTF("read %s done (count=%d)\n", filename[i], ln);
}
return 0;
}
@@ -410,7 +371,7 @@ int itemdb_read_randomitem(void)
*pdefault = 0;
if ((fp = fopen_(fn, "r")) == NULL)
{
- printf("can't read %s\n", fn);
+ PRINTF("can't read %s\n", fn);
continue;
}
@@ -451,7 +412,7 @@ int itemdb_read_randomitem(void)
ln++;
}
fclose_(fp);
- printf("read %s done (count=%d)\n", fn, *pc);
+ PRINTF("read %s done (count=%d)\n", fn, *pc);
}
return 0;
@@ -472,7 +433,7 @@ int itemdb_read_itemavail(void)
if ((fp = fopen_("db/item_avail.txt", "r")) == NULL)
{
- printf("can't read db/item_avail.txt\n");
+ PRINTF("can't read db/item_avail.txt\n");
return -1;
}
@@ -507,93 +468,7 @@ int itemdb_read_itemavail(void)
ln++;
}
fclose_(fp);
- printf("read db/item_avail.txt done (count=%d)\n", ln);
- return 0;
-}
-
-/*==========================================
- * アイテムの名前テーブルを読み込む
- *------------------------------------------
- */
-static
-int itemdb_read_itemnametable(void)
-{
- char *buf, *p;
- size_t s;
-
- buf = (char *)grfio_reads("data\\idnum2itemdisplaynametable.txt", &s);
-
- if (buf == NULL)
- return -1;
-
- buf[s] = 0;
- for (p = buf; p - buf < s;)
- {
- int nameid;
- char buf2[64];
-
- if (sscanf(p, "%d#%[^#]#", &nameid, buf2) == 2)
- {
-
-#ifdef ITEMDB_OVERRIDE_NAME_VERBOSE
- if (itemdb_exists(nameid) &&
- strncmp(itemdb_search(nameid)->jname, buf2, 24) != 0)
- {
- printf("[override] %d %s => %s\n", nameid,
- itemdb_search(nameid)->jname, buf2);
- }
-#endif
-
- memcpy(itemdb_search(nameid)->jname, buf2, 24);
- }
-
- p = strchr(p, 10);
- if (!p)
- break;
- p++;
- }
- free(buf);
- printf("read data\\idnum2itemdisplaynametable.txt done.\n");
-
- return 0;
-}
-
-/*==========================================
- * カードイラストのリソース名前テーブルを読み込む
- *------------------------------------------
- */
-static
-int itemdb_read_cardillustnametable(void)
-{
- char *buf, *p;
- size_t s;
-
- buf = (char *)grfio_reads("data\\num2cardillustnametable.txt", &s);
-
- if (buf == NULL)
- return -1;
-
- buf[s] = 0;
- for (p = buf; p - buf < s;)
- {
- int nameid;
- char buf2[64];
-
- if (sscanf(p, "%d#%[^#]#", &nameid, buf2) == 2)
- {
- strcat(buf2, ".bmp");
- memcpy(itemdb_search(nameid)->cardillustname, buf2, 64);
-// printf("%d %s\n",nameid,itemdb_search(nameid)->cardillustname);
- }
-
- p = strchr(p, 10);
- if (!p)
- break;
- p++;
- }
- free(buf);
- printf("read data\\num2cardillustnametable.txt done.\n");
-
+ PRINTF("read db/item_avail.txt done (count=%d)\n", ln);
return 0;
}
@@ -613,7 +488,7 @@ int itemdb_read_noequip(void)
if ((fp = fopen_("db/item_noequip.txt", "r")) == NULL)
{
- printf("can't read db/item_noequip.txt\n");
+ PRINTF("can't read db/item_noequip.txt\n");
return -1;
}
while (fgets(line, 1020, fp))
@@ -641,7 +516,7 @@ int itemdb_read_noequip(void)
}
fclose_(fp);
- printf("read db/item_noequip.txt done (count=%d)\n", ln);
+ PRINTF("read db/item_noequip.txt done (count=%d)\n", ln);
return 0;
}
@@ -694,7 +569,7 @@ FILE *dfp;
static
int itemdebug(void *key,void *data,_va_list ap){
// struct item_data *id=(struct item_data *)data;
- fprintf(dfp,"%6d", (int)key);
+ FPRINTF(dfp,"%6d", (int)key);
return 0;
}
void itemdebugtxt()
@@ -712,14 +587,10 @@ void itemdebugtxt()
static
void itemdb_read(void)
{
- itemdb_read_itemslottable();
itemdb_readdb();
itemdb_read_randomitem();
itemdb_read_itemavail();
itemdb_read_noequip();
- itemdb_read_cardillustnametable();
- if (!battle_config.item_name_override_grffile)
- itemdb_read_itemnametable();
}
/*==========================================
diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp
index 4a5449d..d544234 100644
--- a/src/map/magic-expr.cpp
+++ b/src/map/magic-expr.cpp
@@ -2,6 +2,7 @@
#include <cmath>
+#include "../common/cxxstdio.hpp"
#include "../common/mt_rand.hpp"
#include "itemdb.hpp"
@@ -116,63 +117,67 @@ static
void stringify(val_t *v, int within_op)
{
static const char *dirs[8] =
- { "south", "south-west", "west", "north-west", "north", "north-east",
+ {
+ "south", "south-west",
+ "west", "north-west",
+ "north", "north-east",
"east", "south-east"
};
- char *buf;
+ std::string buf;
switch (v->ty)
{
case TY_UNDEF:
- buf = strdup("UNDEF");
+ buf = "UNDEF";
break;
case TY_INT:
- buf = (char *)malloc(32);
- sprintf(buf, "%i", v->v.v_int);
+ buf = STRPRINTF("%i", v->v.v_int);
break;
case TY_STRING:
return;
case TY_DIR:
- buf = strdup(dirs[v->v.v_int]);
+ buf = dirs[v->v.v_int];
break;
case TY_ENTITY:
- buf = strdup(show_entity(v->v.v_entity));
+ buf = show_entity(v->v.v_entity);
break;
case TY_LOCATION:
- buf = (char *) malloc(128);
- sprintf(buf, "<\"%s\", %d, %d>", map[v->v.v_location.m].name,
- v->v.v_location.x, v->v.v_location.y);
+ buf = STRPRINTF("<\"%s\", %d, %d>",
+ map[v->v.v_location.m].name,
+ v->v.v_location.x,
+ v->v.v_location.y);
break;
case TY_AREA:
- buf = strdup("%area");
+ buf = "%area";
free_area(v->v.v_area);
break;
case TY_SPELL:
- buf = strdup(v->v.v_spell->name);
+ buf = v->v.v_spell->name;
break;
case TY_INVOCATION:
{
invocation_t *invocation = within_op
- ? v->v.v_invocation : (invocation_t *) map_id2bl(v->v.v_int);
- buf = strdup(invocation->spell->name);
+ ? v->v.v_invocation
+ : (invocation_t *) map_id2bl(v->v.v_int);
+ buf = invocation->spell->name;
}
break;
default:
- fprintf(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n",
- uint8_t(v->ty));
+ FPRINTF(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n",
+ v->ty);
return;
}
- v->v.v_string = buf;
+ v->v.v_string = strdup(buf.c_str());
v->ty = TY_STRING;
}
@@ -534,7 +539,7 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height,
break;
default:
- fprintf(stderr,
+ FPRINTF(stderr,
"Error: Trying to compute area of NE/SE/NW/SW-facing bar");
*x = tx;
*y = ty;
@@ -564,7 +569,7 @@ int magic_location_in_area(int m, int x, int y, area_t *area)
&& (x < ax + awidth) && (y < ay + aheight));
}
default:
- fprintf(stderr, "INTERNAL ERROR: Invalid area\n");
+ FPRINTF(stderr, "INTERNAL ERROR: Invalid area\n");
return 0;
}
}
@@ -978,8 +983,8 @@ void magic_random_location(location_t *dest, area_t *area)
}
default:
- fprintf(stderr, "Unknown area type %d\n",
- uint8_t(area->ty));
+ FPRINTF(stderr, "Unknown area type %d\n",
+ area->ty);
}
}
@@ -1472,8 +1477,8 @@ area_t *eval_area(env_t *env, e_area_t *expr)
}
default:
- fprintf(stderr, "INTERNAL ERROR: Unknown area type %d\n",
- uint8_t(area->ty));
+ FPRINTF(stderr, "INTERNAL ERROR: Unknown area type %d\n",
+ area->ty);
free(area);
return NULL;
}
@@ -1532,7 +1537,7 @@ int magic_signature_check(const char *opname, const char *funname, const char *s
if (!ty_key)
{
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic-eval]: L%d:%d: Too many arguments (%d) to %s `%s'\n",
line, column, args_nr, opname, funname);
return 1;
@@ -1546,7 +1551,7 @@ int magic_signature_check(const char *opname, const char *funname, const char *s
if (ty == TY_UNDEF)
{
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic-eval]: L%d:%d: Argument #%d to %s `%s' undefined\n",
line, column, i + 1, opname, funname);
return 1;
@@ -1578,10 +1583,10 @@ int magic_signature_check(const char *opname, const char *funname, const char *s
if (ty != desired_ty)
{ /* Coercion failed? */
if (ty != TY_FAIL)
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic-eval]: L%d:%d: Argument #%d to %s `%s' of incorrect type (%d)\n",
line, column, i + 1, opname, funname,
- uint8_t(ty));
+ ty);
return 1;
}
}
@@ -1593,9 +1598,7 @@ int magic_signature_check(const char *opname, const char *funname, const char *s
#pragma GCC diagnostic ignored "-Wshadow"
void magic_eval(env_t *env, val_t *dest, expr_t *expr)
{
-#ifdef RECENT_GCC
#pragma GCC diagnostic pop
-#endif
switch (expr->ty)
{
case EXPR_VAL:
@@ -1671,21 +1674,17 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr)
dest->ty = TY_UNDEF;
else
{
-#ifdef RECENT_GCC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
-#endif
env_t *env = t->env;
-#ifdef RECENT_GCC
#pragma GCC diagnostic pop
-#endif
val_t val = VAR(id);
magic_copy_var(dest, &val);
}
}
else
{
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] Attempt to access field %s on non-spell\n",
env->base_env->var_name[id]);
dest->ty = TY_FAIL;
@@ -1694,15 +1693,12 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr)
}
default:
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: Unknown expression type %d\n",
- uint8_t(expr->ty));
+ expr->ty);
break;
}
}
-#ifndef RECENT_GCC
-#pragma GCC diagnostic pop
-#endif
int magic_eval_int(env_t *env, expr_t *expr)
{
diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp
index ec59d38..e970eb2 100644
--- a/src/map/magic-interpreter-base.cpp
+++ b/src/map/magic-interpreter-base.cpp
@@ -207,8 +207,8 @@ env_t *spell_create_env(magic_conf_t *conf, spell_t *spell,
default:
free(param);
- fprintf(stderr, "Unexpected spellarg type %d\n",
- uint8_t(spell->spellarg_ty));
+ FPRINTF(stderr, "Unexpected spellarg type %d\n",
+ spell->spellarg_ty);
}
set_env_entity(VAR_CASTER, &caster->bl);
@@ -307,7 +307,7 @@ int spellguard_can_satisfy(spellguard_check_t *check, character_t *caster,
int retval = check_prerequisites(caster, check->catalysts);
/*
- fprintf(stderr, "MC(%d/%s)? %d%d%d%d (%u <= %u)\n",
+ FPRINTF(stderr, "MC(%d/%s)? %d%d%d%d (%u <= %u)\n",
caster->bl.id, caster->status.name,
retval,
caster->cast_tick <= tick,
@@ -401,8 +401,8 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check,
return NULL;
default:
- fprintf(stderr, "Unexpected spellguard type %d\n",
- uint8_t(guard->ty));
+ FPRINTF(stderr, "Unexpected spellguard type %d\n",
+ guard->ty);
return NULL;
}
@@ -540,7 +540,7 @@ void spell_bind(character_t *subject, invocation_t *invocation)
|| invocation->subject || invocation->next_invocation)
{
int *i = NULL;
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: Attempt to re-bind spell invocation `%s'\n",
invocation->spell->name);
*i = 1;
diff --git a/src/map/magic-interpreter-lexer.lpp b/src/map/magic-interpreter-lexer.lpp
index 0ae6494..34461f5 100644
--- a/src/map/magic-interpreter-lexer.lpp
+++ b/src/map/magic-interpreter-lexer.lpp
@@ -136,7 +136,7 @@
"#".*$ /* Ignore comments */
"//".*$ /* Ignore comments */
[ \n\t\r] /* ignore whitespace */
-. fprintf(stderr, "%s: Unexpected character in line %d\n", MAGIC_CONFIG_FILE, magic_frontend_lineno);
+. FPRINTF(stderr, "%s: Unexpected character in line %d\n", MAGIC_CONFIG_FILE, magic_frontend_lineno);
%%
diff --git a/src/map/magic-interpreter-parser.ypp b/src/map/magic-interpreter-parser.ypp
index 2b80ffb..3cabf24 100644
--- a/src/map/magic-interpreter-parser.ypp
+++ b/src/map/magic-interpreter-parser.ypp
@@ -2,10 +2,12 @@
#include "magic-expr.hpp"
}
%code{
-#include <cstdarg> // exception to "no va_list" rule
-
#include "magic-interpreter-parser.hpp"
+#include <cstdarg> // exception to "no va_list" rule, even after cxxstdio
+
+#include "../common/cxxstdio.hpp"
+
#include "magic-interpreter.hpp"
#define YYLEX_PARAM 0, 0
@@ -783,7 +785,7 @@ static __attribute__((format(printf, 3, 4)))
void fail(int line, int column, const char *fmt, ...)
{
va_list ap;
- fprintf(stderr, "[magic-init] L%d:%d: ", line, column);
+ FPRINTF(stderr, "[magic-init] L%d:%d: ", line, column);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
failed_flag = 1;
@@ -1034,7 +1036,7 @@ val_t *find_constant(char *name)
-#define INTERN_ASSERT(name, id) { int zid = intern_id(name); if (zid != id) fprintf(stderr, "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n", name, zid, id); error_flag = 1; }
+#define INTERN_ASSERT(name, id) { int zid = intern_id(name); if (zid != id) FPRINTF(stderr, "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n", name, zid, id); error_flag = 1; }
extern FILE *magic_frontend_in;
@@ -1069,7 +1071,7 @@ int magic_init(const char *conffile)
magic_frontend_in = fopen(conffile, "r");
if (!magic_frontend_in) {
- fprintf(stderr, "[magic-conf] Magic configuration file `%s' not found -> no magic.\n", conffile);
+ FPRINTF(stderr, "[magic-conf] Magic configuration file `%s' not found -> no magic.\n", conffile);
return 0;
}
magic_frontend_parse();
@@ -1080,7 +1082,7 @@ int magic_init(const char *conffile)
if (magic_conf.vars[VAR_OBSCURE_CHANCE].ty == TY_INT)
magic_conf.obscure_chance = magic_conf.vars[VAR_OBSCURE_CHANCE].v.v_int;
- printf("[magic-conf] Magic initialised; obscure at %d%%. %d spells, %d teleport anchors.\n",
+ PRINTF("[magic-conf] Magic initialised; obscure at %d%%. %d spells, %d teleport anchors.\n",
magic_conf.obscure_chance, magic_conf.spells_nr, magic_conf.anchors_nr);
if (procs)
@@ -1093,6 +1095,6 @@ extern int magic_frontend_lineno;
static
void magic_frontend_error(const char *msg)
{
- fprintf(stderr, "[magic-conf] Parse error: %s at line %d\n", msg, magic_frontend_lineno);
+ FPRINTF(stderr, "[magic-conf] Parse error: %s at line %d\n", msg, magic_frontend_lineno);
failed_flag = 1;
}
diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp
index d176dad..de4a15e 100644
--- a/src/map/magic-stmt.cpp
+++ b/src/map/magic-stmt.cpp
@@ -1,3 +1,5 @@
+#include "../common/cxxstdio.hpp"
+
#include "magic-expr.hpp"
#include "magic-expr-eval.hpp"
#include "magic-interpreter.hpp"
@@ -14,19 +16,19 @@ void print_val(val_t *v)
switch (v->ty)
{
case TY_UNDEF:
- fprintf(stderr, "UNDEF");
+ FPRINTF(stderr, "UNDEF");
break;
case TY_INT:
- fprintf(stderr, "%d", v->v.v_int);
+ FPRINTF(stderr, "%d", v->v.v_int);
break;
case TY_DIR:
- fprintf(stderr, "dir%d", v->v.v_int);
+ FPRINTF(stderr, "dir%d", v->v.v_int);
break;
case TY_STRING:
- fprintf(stderr, "`%s'", v->v.v_string);
+ FPRINTF(stderr, "`%s'", v->v.v_string);
break;
default:
- fprintf(stderr, "ty%d", v->ty);
+ FPRINTF(stderr, "ty%d", v->ty);
break;
}
}
@@ -40,11 +42,11 @@ void dump_env(env_t *env)
val_t *v = &env->vars[i];
val_t *bv = &env->base_env->vars[i];
- fprintf(stderr, "%02x %30s ", i, env->base_env->var_name[i]);
+ FPRINTF(stderr, "%02x %30s ", i, env->base_env->var_name[i]);
print_val(v);
- fprintf(stderr, "\t(");
+ FPRINTF(stderr, "\t(");
print_val(bv);
- fprintf(stderr, ")\n");
+ FPRINTF(stderr, ")\n");
}
}
#endif
@@ -950,9 +952,9 @@ void spell_effect_report_termination(int invocation_id, int bl_id,
{
entity_t *entity = map_id2bl(bl_id);
if (entity->type == BL_PC)
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n",
- bl_id, uint16_t(sc_id));
+ bl_id, sc_id);
return;
}
@@ -1041,7 +1043,7 @@ effect_t *return_to_stack(invocation_t *invocation)
return ar->c.c_for.body;
default:
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n",
invocation->spell->name);
return NULL;
@@ -1057,7 +1059,7 @@ cont_activation_record_t *add_stack_entry(invocation_t *invocation,
invocation->stack + invocation->stack_size++;
if (invocation->stack_size >= MAX_STACK_SIZE)
{
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] Execution stack size exceeded in spell `%s'; truncating effect\n",
invocation->spell->name);
invocation->stack_size--;
@@ -1181,7 +1183,7 @@ effect_t *run_foreach(invocation_t *invocation, effect_t *foreach,
if (area.ty != TY_AREA)
{
magic_clear_var(&area);
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] Error in spell `%s': FOREACH loop over non-area\n",
invocation->spell->name);
return return_location;
@@ -1252,7 +1254,7 @@ effect_t *run_for (invocation_t *invocation, effect_t *for_,
{
magic_clear_var(&start);
magic_clear_var(&stop);
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] Error in spell `%s': FOR loop start or stop point is not an integer\n",
invocation->spell->name);
return return_location;
@@ -1305,9 +1307,9 @@ void print_cfg(int i, effect_t *e)
{
int j;
for (j = 0; j < i; j++)
- printf(" ");
+ PRINTF(" ");
- printf("%p: ", e);
+ PRINTF("%p: ", e);
if (!e)
{
@@ -1340,11 +1342,11 @@ void print_cfg(int i, effect_t *e)
case EFFECT_IF:
puts("IF");
for (j = 0; j < i; j++)
- printf(" ");
+ PRINTF(" ");
puts("THEN");
print_cfg(i + 1, e->e.e_if.true_branch);
for (j = 0; j < i; j++)
- printf(" ");
+ PRINTF(" ");
puts("ELSE");
print_cfg(i + 1, e->e.e_if.false_branch);
break;
@@ -1381,7 +1383,7 @@ int spell_run(invocation_t *invocation, int allow_delete)
#define REFRESH_INVOCATION invocation = (invocation_t *) map_id2bl(invocation_id); if (!invocation) return 0;
#ifdef DEBUG
- fprintf(stderr, "Resuming execution: invocation of `%s'\n",
+ FPRINTF(stderr, "Resuming execution: invocation of `%s'\n",
invocation->spell->name);
print_cfg(1, invocation->current_effect);
#endif
@@ -1392,7 +1394,7 @@ int spell_run(invocation_t *invocation, int allow_delete)
int i;
#ifdef DEBUG
- fprintf(stderr, "Next step of type %d\n", e->ty);
+ FPRINTF(stderr, "Next step of type %d\n", e->ty);
dump_env(invocation->env);
#endif
@@ -1524,9 +1526,9 @@ int spell_run(invocation_t *invocation, int allow_delete)
break;
default:
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] INTERNAL ERROR: Unknown effect %d\n",
- uint8_t(e->ty));
+ e->ty);
}
if (!next)
@@ -1553,7 +1555,7 @@ void spell_execute_d(invocation_t *invocation, int allow_deletion)
{
if (invocation->timer)
{
- fprintf(stderr,
+ FPRINTF(stderr,
"[magic] FATAL ERROR: Trying to add multiple timers to the same spell! Already had timer: %d\n",
invocation->timer);
/* *((int *)0x0) = 0; */
diff --git a/src/map/magic.cpp b/src/map/magic.cpp
index 5c2daf3..d50d5a7 100644
--- a/src/map/magic.cpp
+++ b/src/map/magic.cpp
@@ -95,7 +95,7 @@ int magic_message(character_t *caster, char *spell_, size_t)
effects = NULL;
#ifdef DEBUG
- fprintf(stderr, "Found spell `%s', triggered = %d\n", spell_,
+ FPRINTF(stderr, "Found spell `%s', triggered = %d\n", spell_,
effects != NULL);
#endif
if (bool(caster->status.option & Option::HIDE))
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 6323a96..e1b96a8 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -2,11 +2,12 @@
#include <netdb.h>
-#include <cstdarg> // exception to "no va_list" rule
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <fstream>
+
#include "../common/core.hpp"
#include "../common/db.hpp"
#include "../common/grfio.hpp"
@@ -81,6 +82,9 @@ char help_txt[256] = "conf/help.txt";
char wisp_server_name[24] = "Server"; // can be modified in char-server configuration file
+static
+int map_delmap(const char *mapname);
+
/*==========================================
* 全map鯖総計での接続数設定
* (char鯖から送られてくる)
@@ -121,7 +125,7 @@ int map_freeblock(void *bl)
if (block_free_count >= block_free_max)
{
if (battle_config.error_log)
- printf("map_freeblock: *WARNING* too many free block! %d %d\n",
+ PRINTF("map_freeblock: *WARNING* too many free block! %d %d\n",
block_free_count, block_free_lock);
}
else
@@ -152,7 +156,7 @@ int map_freeblock_unlock(void)
int i;
// if(block_free_count>0) {
// if(battle_config.error_log)
-// printf("map_freeblock_unlock: free %d object\n",block_free_count);
+// PRINTF("map_freeblock_unlock: free %d object\n",block_free_count);
// }
for (i = 0; i < block_free_count; i++)
{
@@ -164,7 +168,7 @@ int map_freeblock_unlock(void)
else if (block_free_lock < 0)
{
if (battle_config.error_log)
- printf("map_freeblock_unlock: lock count < 0 !\n");
+ PRINTF("map_freeblock_unlock: lock count < 0 !\n");
}
return block_free_lock;
}
@@ -196,7 +200,7 @@ int map_addblock(struct block_list *bl)
if (bl->prev != NULL)
{
if (battle_config.error_log)
- printf("map_addblock error : bl->prev!=NULL\n");
+ PRINTF("map_addblock error : bl->prev!=NULL\n");
return 0;
}
@@ -251,7 +255,7 @@ int map_delblock(struct block_list *bl)
{
// prevがNULLでnextがNULLでないのは有ってはならない
if (battle_config.error_log)
- printf("map_delblock error : bl->next!=NULL\n");
+ PRINTF("map_delblock error : bl->next!=NULL\n");
}
return 0;
}
@@ -385,7 +389,7 @@ void map_foreachinarea(std::function<void(struct block_list *)> func,
if (bl_list_count >= BL_LIST_MAX)
{
if (battle_config.error_log)
- printf("map_foreachinarea: *WARNING* block count too many!\n");
+ PRINTF("map_foreachinarea: *WARNING* block count too many!\n");
}
map_freeblock_lock(); // メモリからの解放を禁止する
@@ -539,7 +543,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func,
if (bl_list_count >= BL_LIST_MAX)
{
if (battle_config.error_log)
- printf("map_foreachinarea: *WARNING* block count too many!\n");
+ PRINTF("map_foreachinarea: *WARNING* block count too many!\n");
}
map_freeblock_lock(); // メモリからの解放を禁止する
@@ -596,7 +600,7 @@ void map_foreachincell(std::function<void(struct block_list *)> func,
if (bl_list_count >= BL_LIST_MAX)
{
if (battle_config.error_log)
- printf("map_foreachincell: *WARNING* block count too many!\n");
+ PRINTF("map_foreachincell: *WARNING* block count too many!\n");
}
map_freeblock_lock(); // メモリからの解放を禁止する
@@ -622,7 +626,7 @@ int map_addobject(struct block_list *bl)
int i;
if (bl == NULL)
{
- printf("map_addobject nullpo?\n");
+ PRINTF("map_addobject nullpo?\n");
return 0;
}
if (first_free_object_id < 2 || first_free_object_id >= MAX_FLOORITEM)
@@ -633,7 +637,7 @@ int map_addobject(struct block_list *bl)
if (i >= MAX_FLOORITEM)
{
if (battle_config.error_log)
- printf("no free object id\n");
+ PRINTF("no free object id\n");
return 0;
}
first_free_object_id = i;
@@ -656,9 +660,9 @@ int map_delobjectnofree(int id, BL type)
if (object[id]->type != type)
{
- fprintf(stderr, "Incorrect type: expected %d, got %d\n",
- uint8_t(type),
- uint8_t(object[id]->type));
+ FPRINTF(stderr, "Incorrect type: expected %d, got %d\n",
+ type,
+ object[id]->type);
abort();
}
@@ -720,7 +724,7 @@ void map_foreachobject(std::function<void(struct block_list *)> func,
if (bl_list_count >= BL_LIST_MAX)
{
if (battle_config.error_log)
- printf("map_foreachobject: too many block !\n");
+ PRINTF("map_foreachobject: too many block !\n");
}
else
bl_list[bl_list_count++] = object[i];
@@ -757,7 +761,7 @@ void map_clearflooritem_timer(timer_id tid, tick_t, custom_id_t id, custom_data_
|| (!data && fitem->cleartimer != tid))
{
if (battle_config.error_log)
- printf("map_clearflooritem_timer : error\n");
+ PRINTF("map_clearflooritem_timer : error\n");
return;
}
if (data)
@@ -1305,7 +1309,7 @@ int map_addnpc(int m, struct npc_data *nd)
if (i == MAX_NPC_PER_MAP)
{
if (battle_config.error_log)
- printf("too many NPCs in one map %s\n", map[m].name);
+ PRINTF("too many NPCs in one map %s\n", map[m].name);
return -1;
}
if (i == map[m].npc_num)
@@ -1347,7 +1351,7 @@ void map_removenpc(void)
}
}
}
- printf("%d NPCs removed.\n", n);
+ PRINTF("%d NPCs removed.\n", n);
}
/*==========================================
@@ -1521,7 +1525,7 @@ int map_setipport(const char *name, struct in_addr ip, int port)
{ // local -> check data
if (ip.s_addr != clif_getip().s_addr || port != clif_getport())
{
- printf("from char server : %s -> %s:%d\n", name, ip2str(ip),
+ PRINTF("from char server : %s -> %s:%d\n", name, ip2str(ip),
port);
return 1;
}
@@ -1548,48 +1552,12 @@ struct Waterlist
int waterheight;
} *waterlist = NULL;
-static
-void map_readwater(char *watertxt)
-{
- char line[1024], w1[1024];
- FILE *fp = NULL;
- int n = 0;
-
- fp = fopen_(watertxt, "r");
- if (fp == NULL)
- {
- printf("file not found: %s\n", watertxt);
- return;
- }
- if (waterlist == NULL)
- {
- CREATE(waterlist, struct Waterlist, MAX_MAP_PER_SERVER);
- }
- while (fgets(line, 1020, fp) && n < MAX_MAP_PER_SERVER)
- {
- int wh, count;
- if (line[0] == '/' && line[1] == '/')
- continue;
- if ((count = sscanf(line, "%s%d", w1, &wh)) < 1)
- {
- continue;
- }
- strcpy(waterlist[n].mapname, w1);
- if (count >= 2)
- waterlist[n].waterheight = wh;
- else
- waterlist[n].waterheight = 3;
- n++;
- }
- fclose_(fp);
-}
-
/*==========================================
* マップ1枚読み込み
*------------------------------------------
*/
static
-int map_readmap(int m, char *fn, char *)
+int map_readmap(int m, const char *fn, char *)
{
int s;
int x, y, xs, ys;
@@ -1604,17 +1572,17 @@ int map_readmap(int m, char *fn, char *)
if (gat == NULL)
return -1;
- printf("\rLoading Maps [%d/%d]: %-50s ", m, map_num, fn);
+ PRINTF("\rLoading Maps [%d/%d]: %-50s ", m, map_num, fn);
fflush(stdout);
map[m].m = m;
xs = map[m].xs = *(short *)(gat);
ys = map[m].ys = *(short *)(gat + 2);
- printf("\n%i %i\n", xs, ys);
+ PRINTF("\n%i %i\n", xs, ys);
map[m].gat = (uint8_t *)calloc(s = map[m].xs * map[m].ys, 1);
if (map[m].gat == NULL)
{
- printf("out of memory : map_readmap gat\n");
+ PRINTF("out of memory : map_readmap gat\n");
exit(1);
}
@@ -1653,7 +1621,7 @@ int map_readmap(int m, char *fn, char *)
strdb_insert(map_db, map[m].name, &map[m]);
-// printf("%s read done\n",fn);
+// PRINTF("%s read done\n",fn);
return 0;
}
@@ -1666,16 +1634,16 @@ static
int map_readallmap(void)
{
int i, maps_removed = 0;
- char fn[256] = "";
// 先に全部のャbプの存在を確認
for (i = 0; i < map_num; i++)
{
if (strstr(map[i].name, ".gat") == NULL)
continue;
- sprintf(fn, "data\\%s", map[i].name);
+ // TODO replace this
+ std::string fn = STRPRINTF("data\\%s", map[i].name);
// TODO - remove this, it is the last call to grfio_size, which is deprecated
- if (!grfio_size(fn))
+ if (!grfio_size(fn.c_str()))
{
map_delmap(map[i].name);
maps_removed++;
@@ -1692,8 +1660,8 @@ int map_readallmap(void)
*p = '\0';
strcpy(alias, map[i].name);
strcpy(map[i].name, p + 1);
- sprintf(fn, "data\\%s", map[i].name);
- if (map_readmap(i, fn, alias) == -1)
+ std::string fn = STRPRINTF("data\\%s", map[i].name);
+ if (map_readmap(i, fn.c_str(), alias) == -1)
{
map_delmap(map[i].name);
maps_removed++;
@@ -1701,8 +1669,8 @@ int map_readallmap(void)
}
else
{
- sprintf(fn, "data\\%s", map[i].name);
- if (map_readmap(i, fn, NULL) == -1)
+ std::string fn = STRPRINTF("data\\%s", map[i].name);
+ if (map_readmap(i, fn.c_str(), NULL) == -1)
{
map_delmap(map[i].name);
maps_removed++;
@@ -1712,8 +1680,8 @@ int map_readallmap(void)
}
free(waterlist);
- printf("\rMaps Loaded: %d %60s\n", map_num, "");
- printf("\rMaps Removed: %d \n", maps_removed);
+ PRINTF("\rMaps Loaded: %d %60s\n", map_num, "");
+ PRINTF("\rMaps Removed: %d \n", maps_removed);
return 0;
}
@@ -1722,7 +1690,7 @@ int map_readallmap(void)
*------------------------------------------
*/
static
-int map_addmap(char *mapname)
+int map_addmap(const char *mapname)
{
if (strcasecmp(mapname, "clear") == 0)
{
@@ -1732,7 +1700,7 @@ int map_addmap(char *mapname)
if (map_num >= MAX_MAP_PER_SERVER - 1)
{
- printf("too many map\n");
+ PRINTF("too many map\n");
return 1;
}
memcpy(map[map_num].name, mapname, 24);
@@ -1744,7 +1712,8 @@ int map_addmap(char *mapname)
* 読み込むmapを削除する
*------------------------------------------
*/
-int map_delmap(char *mapname)
+static
+int map_delmap(const char *mapname)
{
int i;
@@ -1758,7 +1727,7 @@ int map_delmap(char *mapname)
{
if (strcmp(map[i].name, mapname) == 0)
{
- printf("Removing map [ %s ] from maplist\n", map[i].name);
+ PRINTF("Removing map [ %s ] from maplist\n", map[i].name);
memmove(map + i, map + i + 1,
sizeof(map[0]) * (map_num - i - 1));
map_num--;
@@ -1781,31 +1750,30 @@ void map_close_logfile(void)
{
if (map_logfile)
{
- char *filenameop_buf = (char*)malloc(strlen(map_logfile_name) + 50);
- sprintf(filenameop_buf, "gzip -f %s.%ld", map_logfile_name,
- map_logfile_index);
+ std::string filenameop_buf = STRPRINTF(
+ "gzip -f %s.%ld",
+ map_logfile_name,
+ map_logfile_index);
fclose(map_logfile);
- if (!system(filenameop_buf))
- perror(filenameop_buf);
-
- free(filenameop_buf);
+ if (!system(filenameop_buf.c_str()))
+ perror(filenameop_buf.c_str());
}
}
static
void map_start_logfile(long suffix)
{
- char *filename_buf = (char*)malloc(strlen(map_logfile_name) + 50);
map_logfile_index = suffix >> LOGFILE_SECONDS_PER_CHUNK_SHIFT;
- sprintf(filename_buf, "%s.%ld", map_logfile_name, map_logfile_index);
- map_logfile = fopen(filename_buf, "w+");
+ std::string filename_buf = STRPRINTF(
+ "%s.%ld",
+ map_logfile_name,
+ map_logfile_index);
+ map_logfile = fopen(filename_buf.c_str(), "w+");
if (!map_logfile)
perror(map_logfile_name);
-
- free(filename_buf);
}
static
@@ -1821,12 +1789,12 @@ void map_set_logfile(const char *filename)
MAP_LOG("log-start v3");
}
-void map_write_log(const char *format, ...)
+void map_log(const_string line)
{
- struct timeval tv;
- va_list args;
- va_start(args, format);
+ if (!map_logfile)
+ return;
+ struct timeval tv;
gettimeofday(&tv, NULL);
if ((tv.tv_sec >> LOGFILE_SECONDS_PER_CHUNK_SHIFT) != map_logfile_index)
@@ -1835,9 +1803,16 @@ void map_write_log(const char *format, ...)
map_start_logfile(tv.tv_sec);
}
- fprintf(map_logfile, "%ld.%06ld ", (long) tv.tv_sec, (long) tv.tv_usec);
- vfprintf(map_logfile, format, args);
- fputc('\n', map_logfile);
+ if (!line)
+ {
+ fputc('\n', map_logfile);
+ return;
+ }
+
+ FPRINTF(map_logfile, "%ld.%06ld ", (long) tv.tv_sec, (long) tv.tv_usec);
+ fwrite(line.data(), 1, line.size(), map_logfile);
+ if (line.back() != '\n')
+ fputc('\n', map_logfile);
}
/*==========================================
@@ -1847,126 +1822,118 @@ void map_write_log(const char *format, ...)
static
int map_config_read(const char *cfgName)
{
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
struct hostent *h = NULL;
- fp = fopen_(cfgName, "r");
- if (fp == NULL)
+ std::ifstream in(cfgName);
+ if (!in.is_open())
{
- printf("Map configuration file not found at: %s\n", cfgName);
+ PRINTF("Map configuration file not found at: %s\n", cfgName);
exit(1);
}
- while (fgets(line, sizeof(line) - 1, fp))
+
+ std::string line;
+ while (std::getline(in, line))
{
- if (line[0] == '/' && line[1] == '/')
+ std::string w1, w2;
+ if (!split_key_value(line, &w1, &w2))
continue;
- if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2)
+ if (w1 == "userid")
{
- if (strcasecmp(w1, "userid") == 0)
- {
- chrif_setuserid(w2);
- }
- else if (strcasecmp(w1, "passwd") == 0)
- {
- chrif_setpasswd(w2);
- }
- else if (strcasecmp(w1, "char_ip") == 0)
+ chrif_setuserid(w2.c_str());
+ }
+ else if (w1 == "passwd")
+ {
+ chrif_setpasswd(w2.c_str());
+ }
+ else if (w1 == "char_ip")
+ {
+ h = gethostbyname(w2.c_str());
+ if (h != NULL)
{
- h = gethostbyname(w2);
- if (h != NULL)
- {
- printf("Character server IP address : %s -> %d.%d.%d.%d\n",
- w2, (unsigned char) h->h_addr[0],
+ PRINTF("Character server IP address : %s -> %d.%d.%d.%d\n",
+ w2, (unsigned char) h->h_addr[0],
+ (unsigned char) h->h_addr[1],
+ (unsigned char) h->h_addr[2],
+ (unsigned char) h->h_addr[3]);
+ SPRINTF(w2, "%d.%d.%d.%d", (unsigned char) h->h_addr[0],
(unsigned char) h->h_addr[1],
(unsigned char) h->h_addr[2],
(unsigned char) h->h_addr[3]);
- sprintf(w2, "%d.%d.%d.%d", (unsigned char) h->h_addr[0],
- (unsigned char) h->h_addr[1],
- (unsigned char) h->h_addr[2],
- (unsigned char) h->h_addr[3]);
- }
- chrif_setip(w2);
- }
- else if (strcasecmp(w1, "char_port") == 0)
- {
- chrif_setport(atoi(w2));
- }
- else if (strcasecmp(w1, "map_ip") == 0)
- {
- h = gethostbyname(w2);
- if (h != NULL)
- {
- printf("Map server IP address : %s -> %d.%d.%d.%d\n", w2,
- (unsigned char) h->h_addr[0],
- (unsigned char) h->h_addr[1],
- (unsigned char) h->h_addr[2],
- (unsigned char) h->h_addr[3]);
- sprintf(w2, "%d.%d.%d.%d", (unsigned char) h->h_addr[0],
- (unsigned char) h->h_addr[1],
- (unsigned char) h->h_addr[2],
- (unsigned char) h->h_addr[3]);
- }
- clif_setip(w2);
- }
- else if (strcasecmp(w1, "map_port") == 0)
- {
- clif_setport(atoi(w2));
- map_port = (atoi(w2));
- }
- else if (strcasecmp(w1, "water_height") == 0)
- {
- map_readwater(w2);
}
- else if (strcasecmp(w1, "map") == 0)
- {
- map_addmap(w2);
- }
- else if (strcasecmp(w1, "delmap") == 0)
- {
- map_delmap(w2);
- }
- else if (strcasecmp(w1, "npc") == 0)
- {
- npc_addsrcfile(w2);
- }
- else if (strcasecmp(w1, "delnpc") == 0)
- {
- npc_delsrcfile(w2);
- }
- else if (strcasecmp(w1, "autosave_time") == 0)
- {
- autosave_interval = atoi(w2) * 1000;
- if (autosave_interval <= 0)
- autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
- }
- else if (strcasecmp(w1, "motd_txt") == 0)
- {
- strcpy(motd_txt, w2);
- }
- else if (strcasecmp(w1, "help_txt") == 0)
- {
- strcpy(help_txt, w2);
- }
- else if (strcasecmp(w1, "mapreg_txt") == 0)
- {
- strcpy(mapreg_txt, w2);
- }
- else if (strcasecmp(w1, "gm_log") == 0)
- {
- gm_logfile_name = strdup(w2);
- }
- else if (strcasecmp(w1, "log_file") == 0)
- {
- map_set_logfile(w2);
- }
- else if (strcasecmp(w1, "import") == 0)
+ chrif_setip(w2.c_str());
+ }
+ else if (w1 == "char_port")
+ {
+ chrif_setport(atoi(w2.c_str()));
+ }
+ else if (w1 == "map_ip")
+ {
+ h = gethostbyname(w2.c_str());
+ if (h != NULL)
{
- map_config_read(w2);
+ PRINTF("Map server IP address : %s -> %d.%d.%d.%d\n", w2,
+ (unsigned char) h->h_addr[0],
+ (unsigned char) h->h_addr[1],
+ (unsigned char) h->h_addr[2],
+ (unsigned char) h->h_addr[3]);
+ SPRINTF(w2, "%d.%d.%d.%d", (unsigned char) h->h_addr[0],
+ (unsigned char) h->h_addr[1],
+ (unsigned char) h->h_addr[2],
+ (unsigned char) h->h_addr[3]);
}
+ clif_setip(w2.c_str());
+ }
+ else if (w1 == "map_port")
+ {
+ clif_setport(atoi(w2.c_str()));
+ }
+ else if (w1 == "map")
+ {
+ map_addmap(w2.c_str());
+ }
+ else if (w1 == "delmap")
+ {
+ map_delmap(w2.c_str());
+ }
+ else if (w1 == "npc")
+ {
+ npc_addsrcfile(w2.c_str());
+ }
+ else if (w1 == "delnpc")
+ {
+ npc_delsrcfile(w2.c_str());
+ }
+ else if (w1 == "autosave_time")
+ {
+ autosave_interval = atoi(w2.c_str()) * 1000;
+ if (autosave_interval <= 0)
+ autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
+ }
+ else if (w1 == "motd_txt")
+ {
+ strzcpy(motd_txt, w2.c_str(), sizeof(motd_txt));
+ }
+ else if (w1 == "help_txt")
+ {
+ strzcpy(help_txt, w2.c_str(), sizeof(help_txt));
+ }
+ else if (w1 == "mapreg_txt")
+ {
+ strzcpy(mapreg_txt, w2.c_str(), sizeof(mapreg_txt));
+ }
+ else if (w1 == "gm_log")
+ {
+ gm_logfile_name = strdup(w2.c_str());
+ }
+ else if (w1 == "log_file")
+ {
+ map_set_logfile(w2.c_str());
+ }
+ else if (w1 == "import")
+ {
+ map_config_read(w2.c_str());
}
}
- fclose_(fp);
return 0;
}
@@ -2075,7 +2042,6 @@ int do_init(int argc, char *argv[])
const char *MAP_CONF_NAME = "conf/map_athena.conf";
const char *BATTLE_CONF_FILENAME = "conf/battle_athena.conf";
const char *ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf";
- const char *SCRIPT_CONF_NAME = "conf/script_athena.conf";
for (i = 1; i < argc; i++)
{
@@ -2089,14 +2055,12 @@ int do_init(int argc, char *argv[])
BATTLE_CONF_FILENAME = argv[i + 1];
else if (strcmp(argv[i], "--atcommand_config") == 0)
ATCOMMAND_CONF_FILENAME = argv[i + 1];
- else if (strcmp(argv[i], "--script_config") == 0)
- SCRIPT_CONF_NAME = argv[i + 1];
}
map_config_read(MAP_CONF_NAME);
battle_config_read(BATTLE_CONF_FILENAME);
atcommand_config_read(ATCOMMAND_CONF_FILENAME);
- script_config_read(SCRIPT_CONF_NAME);
+ script_config_read();
id_db = numdb_init();
map_db = strdb_init(16);
@@ -2122,9 +2086,9 @@ int do_init(int argc, char *argv[])
npc_event_do_oninit(); // npcのOnInitイベント実行
if (battle_config.pk_mode == 1)
- printf("The server is running in \033[1;31mPK Mode\033[0m.\n");
+ PRINTF("The server is running in \033[1;31mPK Mode\033[0m.\n");
- printf("The map-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
+ PRINTF("The map-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n",
map_port);
return 0;
diff --git a/src/map/map.hpp b/src/map/map.hpp
index 7f75427..3d15bb5 100644
--- a/src/map/map.hpp
+++ b/src/map/map.hpp
@@ -9,6 +9,7 @@
#include <cstdio>
#include <ctime>
+#include "../common/cxxstdio.hpp"
#include "../common/db.hpp"
#include "../common/mmo.hpp"
#include "../common/timer.hpp"
@@ -699,10 +700,9 @@ int map_quit(struct map_session_data *);
// npc
int map_addnpc(int, struct npc_data *);
-extern FILE *map_logfile;
-__attribute__((format(printf, 1, 2)))
-void map_write_log(const char *format, ...);
-#define MAP_LOG(format, args...) {if (map_logfile) map_write_log(format, ##args);}
+void map_log(const_string line);
+#define MAP_LOG(format, args...) \
+ map_log(static_cast<const std::string&>(STRPRINTF(format, ##args)));
#define MAP_LOG_PC(sd, fmt, args...) MAP_LOG("PC%d %d:%d,%d " fmt, sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## args)
@@ -754,7 +754,4 @@ int map_calc_dir(struct block_list *src, int x, int y);
int path_search(struct walkpath_data *, int, int, int, int, int, int);
int path_blownpos(int m, int x0, int y0, int dx, int dy, int count);
-
-int map_delmap(char *mapname);
-
#endif // MAP_HPP
diff --git a/src/map/mob.cpp b/src/map/mob.cpp
index abd6260..7c26ceb 100644
--- a/src/map/mob.cpp
+++ b/src/map/mob.cpp
@@ -295,7 +295,7 @@ int mob_gen_exp(struct mob_db *mob)
(double) battle_config.base_exp_rate / 100.);
if (xp < 1)
xp = 1;
- printf("Exp for mob '%s' generated: %d\n", mob->name, xp);
+ PRINTF("Exp for mob '%s' generated: %d\n", mob->name, xp);
return xp;
}
@@ -395,7 +395,7 @@ int mob_once_spawn(struct map_session_data *sd, const char *mapname,
return 0;
}
// if(battle_config.etc_log==1)
-// printf("mobmob_class=%d try=%d\n",mob_class,i);
+// PRINTF("mobmob_class=%d try=%d\n",mob_class,i);
}
if (sd)
{
@@ -406,7 +406,7 @@ int mob_once_spawn(struct map_session_data *sd, const char *mapname,
}
else if (x <= 0 || y <= 0)
{
- printf("mob_once_spawn: ??\n");
+ PRINTF("mob_once_spawn: ??\n");
}
for (count = 0; count < amount; count++)
@@ -522,7 +522,7 @@ int mob_spawn_guardian(struct map_session_data *sd, const char *mapname,
}
else if (x <= 0 || y <= 0)
- printf("mob_spawn_guardian: ??\n");
+ PRINTF("mob_spawn_guardian: ??\n");
for (count = 0; count < amount; count++)
{
@@ -1021,7 +1021,7 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
if (md->timer != tid)
{
if (battle_config.error_log == 1)
- printf("mob_timer %d != %d\n", md->timer, tid);
+ PRINTF("mob_timer %d != %d\n", md->timer, tid);
return;
}
md->timer = -1;
@@ -1043,8 +1043,8 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
break;
default:
if (battle_config.error_log == 1)
- printf("mob_timer : %d ?\n",
- uint8_t(md->state.state));
+ PRINTF("mob_timer : %d ?\n",
+ md->state.state);
break;
}
map_freeblock_unlock();
@@ -1223,7 +1223,7 @@ int mob_spawn(int id)
if (i >= 50)
{
// if(battle_config.error_log==1)
- // printf("MOB spawn error %d @ %s\n",id,map[md->bl.m].name);
+ // PRINTF("MOB spawn error %d @ %s\n",id,map[md->bl.m].name);
add_timer(tick + 5000, mob_delayspawn, id, 0);
return 1;
}
@@ -1848,7 +1848,7 @@ int mob_randomwalk(struct mob_data *md, int tick)
if (md->move_fail_count > 1000)
{
if (battle_config.error_log == 1)
- printf("MOB cant move. random spawn %d, mob_class = %d\n",
+ PRINTF("MOB cant move. random spawn %d, mob_class = %d\n",
md->bl.id, md->mob_class);
md->move_fail_count = 0;
mob_spawn(md->bl.id);
@@ -2532,11 +2532,11 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage,
}
// if(battle_config.battle_log)
-// printf("mob_damage %d %d %d\n",md->hp,max_hp,damage);
+// PRINTF("mob_damage %d %d %d\n",md->hp,max_hp,damage);
if (md->bl.prev == NULL)
{
if (battle_config.error_log == 1)
- printf("mob_damage : BlockError!!\n");
+ PRINTF("mob_damage : BlockError!!\n");
return 0;
}
@@ -3112,7 +3112,7 @@ void mob_warpslave_sub(struct block_list *bl, int id, int x, int y)
static
int mob_warpslave(struct mob_data *md, int x, int y)
{
-//printf("warp slave\n");
+//PRINTF("warp slave\n");
map_foreachinarea(std::bind(mob_warpslave_sub, ph::_1, md->bl.id, md->bl.x, md->bl.y),
md->bl.m, x - AREA_SIZE, y - AREA_SIZE,
x + AREA_SIZE, y + AREA_SIZE, BL_MOB);
@@ -3174,7 +3174,7 @@ int mob_warp(struct mob_data *md, int m, int x, int y, int type)
{
m = md->bl.m;
if (battle_config.error_log == 1)
- printf("MOB %d warp failed, mob_class = %d\n", md->bl.id, md->mob_class);
+ PRINTF("MOB %d warp failed, mob_class = %d\n", md->bl.id, md->mob_class);
}
md->target_id = 0; // タゲを解除する
@@ -3186,7 +3186,7 @@ int mob_warp(struct mob_data *md, int m, int x, int y, int type)
if (type > 0 && i == 1000)
{
if (battle_config.battle_log == 1)
- printf("MOB %d warp to (%d,%d), mob_class = %d\n", md->bl.id, x, y,
+ PRINTF("MOB %d warp to (%d,%d), mob_class = %d\n", md->bl.id, x, y,
md->mob_class);
}
@@ -3399,7 +3399,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_
return;
if ((md = (struct mob_data *) mbl) == NULL)
{
- printf("mobskill_castend_id nullpo mbl->id:%d\n", mbl->id);
+ PRINTF("mobskill_castend_id nullpo mbl->id:%d\n", mbl->id);
return;
}
if (md->bl.type != BL_MOB || md->bl.prev == NULL)
@@ -3426,7 +3426,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_
if ((bl = map_id2bl(md->skilltarget)) == NULL || bl->prev == NULL)
{ //スキルターゲットが存在しない
- //printf("mobskill_castend_id nullpo\n");//ターゲットがいないときはnullpoじゃなくて普通に終了
+ //PRINTF("mobskill_castend_id nullpo\n");//ターゲットがいないときはnullpoじゃなくて普通に終了
return;
}
if (md->bl.m != bl->m)
@@ -3462,8 +3462,8 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_
md->skilldelay[md->skillidx] = tick;
if (battle_config.mob_skill_log == 1)
- printf("MOB skill castend skill=%d, mob_class = %d\n",
- uint16_t(md->skillid), md->mob_class);
+ PRINTF("MOB skill castend skill=%d, mob_class = %d\n",
+ md->skillid, md->mob_class);
mob_stop_walking(md, 0);
switch (skill_get_nk(md->skillid))
@@ -3611,8 +3611,8 @@ void mobskill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data
md->skilldelay[md->skillidx] = tick;
if (battle_config.mob_skill_log == 1)
- printf("MOB skill castend skill=%d, mob_class = %d\n",
- uint16_t(md->skillid), md->mob_class);
+ PRINTF("MOB skill castend skill=%d, mob_class = %d\n",
+ md->skillid, md->mob_class);
mob_stop_walking(md, 0);
skill_castend_pos2(&md->bl, md->skillx, md->skilly, md->skillid,
@@ -3697,8 +3697,8 @@ int mobskill_use_id(struct mob_data *md, struct block_list *target,
}
if (battle_config.mob_skill_log == 1)
- printf("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n",
- target->id, uint16_t(skill_id), skill_lv,
+ PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n",
+ target->id, skill_id, skill_lv,
casttime, md->mob_class);
if (casttime <= 0) // 詠唱の無いものはキャンセルされない
@@ -3784,8 +3784,8 @@ int mobskill_use_pos(struct mob_data *md,
md->state.skillcastcancel = ms->cancel;
if (battle_config.mob_skill_log == 1)
- printf("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n",
- skill_x, skill_y, uint16_t(skill_id), skill_lv,
+ PRINTF("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n",
+ skill_x, skill_y, skill_id, skill_lv,
casttime, md->mob_class);
if (casttime <= 0) // A skill without a cast time wont be cancelled.
@@ -4368,7 +4368,7 @@ int mob_readdb(void)
mob_db[mob_class].base_exp = mob_gen_exp(&mob_db[mob_class]);
}
fclose_(fp);
- printf("read %s done\n", filename[j]);
+ PRINTF("read %s done\n", filename[j]);
}
return 0;
}
@@ -4388,7 +4388,7 @@ int mob_readdb_mobavail(void)
if ((fp = fopen_("db/mob_avail.txt", "r")) == NULL)
{
- printf("can't read db/mob_avail.txt\n");
+ PRINTF("can't read db/mob_avail.txt\n");
return -1;
}
@@ -4442,7 +4442,7 @@ int mob_readdb_mobavail(void)
ln++;
}
fclose_(fp);
- printf("read db/mob_avail.txt done (count=%d)\n", ln);
+ PRINTF("read db/mob_avail.txt done (count=%d)\n", ln);
return 0;
}
@@ -4470,7 +4470,7 @@ int mob_read_randommonster(void)
fp = fopen_(mobfile[i], "r");
if (fp == NULL)
{
- printf("can't read %s\n", mobfile[i]);
+ PRINTF("can't read %s\n", mobfile[i]);
return -1;
}
while (fgets(line, 1020, fp))
@@ -4496,7 +4496,7 @@ int mob_read_randommonster(void)
mob_db[mob_class].summonper[i] = per;
}
fclose_(fp);
- printf("read %s done\n", mobfile[i]);
+ PRINTF("read %s done\n", mobfile[i]);
}
return 0;
}
@@ -4599,7 +4599,7 @@ int mob_readskilldb(void)
if (fp == NULL)
{
if (x == 0)
- printf("can't read %s\n", filename[x]);
+ PRINTF("can't read %s\n", filename[x]);
continue;
}
while (fgets(line, 1020, fp))
@@ -4635,7 +4635,7 @@ int mob_readskilldb(void)
break;
if (i == MAX_MOBSKILL)
{
- printf("mob_skill: readdb: too many skill ! [%s] in %d[%s]\n",
+ PRINTF("mob_skill: readdb: too many skill ! [%s] in %d[%s]\n",
sp[1], mob_id, mob_db[mob_id].jname);
continue;
}
@@ -4687,7 +4687,7 @@ int mob_readskilldb(void)
mob_db[mob_id].maxskill = i + 1;
}
fclose_(fp);
- printf("read %s done\n", filename[x]);
+ PRINTF("read %s done\n", filename[x]);
}
return 0;
}
diff --git a/src/map/npc.cpp b/src/map/npc.cpp
index c40e946..8966d49 100644
--- a/src/map/npc.cpp
+++ b/src/map/npc.cpp
@@ -142,7 +142,7 @@ int npc_event_dequeue(struct map_session_data *sd)
{
if (!pc_addeventtimer(sd, 100, sd->eventqueue[0]))
{
- printf("npc_event_dequeue(): Event timer is full.\n");
+ PRINTF("npc_event_dequeue(): Event timer is full.\n");
return 0;
}
@@ -191,7 +191,7 @@ int npc_timer_event(const char *eventname) // Added by RoVeRT
if ((ev == NULL || (nd = ev->nd) == NULL))
{
- printf("npc_event: event not found [%s]\n", eventname);
+ PRINTF("npc_event: event not found [%s]\n", eventname);
return 0;
}
@@ -269,30 +269,28 @@ int npc_event_do_l(const char *name, int rid, int argc, argrec_t *args)
static
void npc_event_do_clock(timer_id, tick_t, custom_id_t, custom_data_t)
{
- time_t timer;
- struct tm *t;
- char buf[64];
- int c = 0;
-
- time(&timer);
- t = gmtime(&timer);
+ time_t timer = time(NULL);
+ struct tm *t = gmtime(&timer);
if (t->tm_min != ev_tm_b.tm_min)
{
- sprintf(buf, "OnMinute%02d", t->tm_min);
- c += npc_event_doall(buf);
- sprintf(buf, "OnClock%02d%02d", t->tm_hour, t->tm_min);
- c += npc_event_doall(buf);
+ std::string buf;
+ buf = STRPRINTF("OnMinute%02d", t->tm_min);
+ npc_event_doall(buf.c_str());
+ buf = STRPRINTF("OnClock%02d%02d", t->tm_hour, t->tm_min);
+ npc_event_doall(buf.c_str());
}
if (t->tm_hour != ev_tm_b.tm_hour)
{
- sprintf(buf, "OnHour%02d", t->tm_hour);
- c += npc_event_doall(buf);
+ std::string buf;
+ buf = STRPRINTF("OnHour%02d", t->tm_hour);
+ npc_event_doall(buf.c_str());
}
if (t->tm_mday != ev_tm_b.tm_mday)
{
- sprintf(buf, "OnDay%02d%02d", t->tm_mon + 1, t->tm_mday);
- c += npc_event_doall(buf);
+ std::string buf;
+ buf = STRPRINTF("OnDay%02d%02d", t->tm_mon + 1, t->tm_mday);
+ npc_event_doall(buf.c_str());
}
memcpy(&ev_tm_b, t, sizeof(ev_tm_b));
}
@@ -304,7 +302,7 @@ void npc_event_do_clock(timer_id, tick_t, custom_id_t, custom_data_t)
int npc_event_do_oninit(void)
{
int c = npc_event_doall("OnInit");
- printf("npc: OnInit Event done. (%d npc)\n", c);
+ PRINTF("npc: OnInit Event done. (%d npc)\n", c);
add_timer_interval(gettick() + 100, npc_event_do_clock, 0, 0, 1000);
@@ -332,7 +330,7 @@ int npc_addeventtimer(struct npc_data *nd, int tick, const char *name)
(int) evname);
}
else
- printf("npc_addtimer: event timer is full !\n");
+ PRINTF("npc_addtimer: event timer is full !\n");
return 0;
}
@@ -404,7 +402,7 @@ void npc_timerevent(timer_id, tick_t tick, custom_id_t id, custom_data_t data)
struct npc_timerevent_list *te;
if (nd == NULL || nd->u.scr.nexttimer < 0)
{
- printf("npc_timerevent: ??\n");
+ PRINTF("npc_timerevent: ??\n");
return;
}
nd->u.scr.timertick = tick;
@@ -522,7 +520,7 @@ int npc_event(struct map_session_data *sd, const char *eventname,
if (sd == NULL)
{
- printf("npc_event nullpo?\n");
+ PRINTF("npc_event nullpo?\n");
}
if (ev == NULL && eventname
@@ -539,14 +537,14 @@ int npc_event(struct map_session_data *sd, const char *eventname,
if (ev == NULL || (nd = ev->nd) == NULL)
{
if (strncasecmp(eventname, "GM_MONSTER", 10) != 0)
- printf("npc_event: event not found [%s]\n", mobevent);
+ PRINTF("npc_event: event not found [%s]\n", mobevent);
return 0;
}
}
else
{
if (battle_config.error_log)
- printf("npc_event: event not found [%s]\n", eventname);
+ PRINTF("npc_event: event not found [%s]\n", eventname);
return 0;
}
}
@@ -568,7 +566,7 @@ int npc_event(struct map_session_data *sd, const char *eventname,
if (sd->npc_id != 0)
{
// if (battle_config.error_log)
-// printf("npc_event: npc_id != 0\n");
+// PRINTF("npc_event: npc_id != 0\n");
int i;
for (i = 0; i < MAX_EVENTQUEUE; i++)
if (!sd->eventqueue[i][0])
@@ -576,12 +574,12 @@ int npc_event(struct map_session_data *sd, const char *eventname,
if (i == MAX_EVENTQUEUE)
{
if (battle_config.error_log)
- printf("npc_event: event queue is full !\n");
+ PRINTF("npc_event: event queue is full !\n");
}
else
{
// if (battle_config.etc_log)
-// printf("npc_event: enqueue\n");
+// PRINTF("npc_event: enqueue\n");
strncpy(sd->eventqueue[i], eventname, 50);
sd->eventqueue[i][49] = '\0';
}
@@ -670,7 +668,7 @@ int npc_touch_areanpc(struct map_session_data *sd, int m, int x, int y)
if (f)
{
if (battle_config.error_log)
- printf("npc_touch_areanpc : some bug \n");
+ PRINTF("npc_touch_areanpc : some bug \n");
}
return 1;
}
@@ -714,7 +712,7 @@ int npc_checknear(struct map_session_data *sd, int id)
if (nd == NULL || nd->bl.type != BL_NPC)
{
if (battle_config.error_log)
- printf("no such npc : %d\n", id);
+ PRINTF("no such npc : %d\n", id);
return 1;
}
@@ -745,7 +743,7 @@ int npc_click(struct map_session_data *sd, int id)
if (sd->npc_id != 0)
{
if (battle_config.error_log)
- printf("npc_click: npc_id != 0\n");
+ PRINTF("npc_click: npc_id != 0\n");
return 1;
}
@@ -829,7 +827,7 @@ int npc_buysellsel(struct map_session_data *sd, int id, int type)
if (nd->bl.subtype != SHOP)
{
if (battle_config.error_log)
- printf("no such shop npc : %d\n", id);
+ PRINTF("no such shop npc : %d\n", id);
sd->npc_id = 0;
return 1;
}
@@ -1060,7 +1058,7 @@ void npc_clearsrcfile(void)
* 読み込むnpcファイルの追加
*------------------------------------------
*/
-void npc_addsrcfile(char *name)
+void npc_addsrcfile(const char *name)
{
struct npc_src_list *new_src;
size_t len;
@@ -1087,7 +1085,7 @@ void npc_addsrcfile(char *name)
* 読み込むnpcファイルの削除
*------------------------------------------
*/
-void npc_delsrcfile(char *name)
+void npc_delsrcfile(const char *name)
{
struct npc_src_list *p = npc_src_first, *pp = NULL, **lp = &npc_src_first;
@@ -1126,7 +1124,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4)
sscanf(w4, "%d,%d,%[^,],%d,%d", &xs, &ys, to_mapname, &to_x,
&to_y) != 5)
{
- printf("bad warp line : %s\n", w3);
+ PRINTF("bad warp line : %s\n", w3);
return 1;
}
@@ -1175,7 +1173,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4)
}
}
-// printf("warp npc %s %d read done\n",mapname,nd->bl.id);
+// PRINTF("warp npc %s %d read done\n",mapname,nd->bl.id);
npc_warp++;
nd->bl.type = BL_NPC;
nd->bl.subtype = WARP;
@@ -1203,7 +1201,7 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4)
if (sscanf(w1, "%[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 ||
strchr(w4, ',') == NULL)
{
- printf("bad shop line : %s\n", w3);
+ PRINTF("bad shop line : %s\n", w3);
return 1;
}
m = map_mapname2mapid(mapname);
@@ -1274,7 +1272,7 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4)
nd = (struct npc_data *)
realloc(nd, sizeof(struct npc_data) + sizeof(nd->u.shop_item[0]) * pos);
- //printf("shop npc %s %d read done\n",mapname,nd->bl.id);
+ //PRINTF("shop npc %s %d read done\n",mapname,nd->bl.id);
npc_shop++;
nd->bl.type = BL_NPC;
nd->bl.subtype = SHOP;
@@ -1359,7 +1357,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
if (sscanf(w1, "%[^,],%d,%d,%d", mapname, &x, &y, &dir) != 4 ||
(strcmp(w2, "script") == 0 && strchr(w4, ',') == NULL))
{
- printf("bad script line : %s\n", w3);
+ PRINTF("bad script line : %s\n", w3);
return 1;
}
m = map_mapname2mapid(mapname);
@@ -1421,12 +1419,12 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
struct npc_data *nd2;
if (sscanf(w2, "duplicate (%[^)])", srcname) != 1)
{
- printf("bad duplicate name! : %s", w2);
+ PRINTF("bad duplicate name! : %s", w2);
return 0;
}
if ((nd2 = npc_name2id(srcname)) == NULL)
{
- printf("bad duplicate name! (not exist) : %s\n", srcname);
+ PRINTF("bad duplicate name! (not exist) : %s\n", srcname);
return 0;
}
script = nd2->u.scr.script;
@@ -1518,7 +1516,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
nd->opt2 = Opt2::ZERO;
nd->opt3 = Opt3::ZERO;
- //printf("script npc %s %d %d read done\n",mapname,nd->bl.id,nd->class);
+ //PRINTF("script npc %s %d %d read done\n",mapname,nd->bl.id,nd->class);
npc_script++;
nd->bl.type = BL_NPC;
nd->bl.subtype = SCRIPT;
@@ -1583,7 +1581,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
buf = (char *) calloc(50, sizeof(char));
if (strlen(lname) > 24)
{
- printf("npc_parse_script: label name error !\n");
+ PRINTF("npc_parse_script: label name error !\n");
exit(1);
}
else
@@ -1709,7 +1707,7 @@ int npc_parse_function(char *, char *, char *w3, char *,
// もう使わないのでバッファ解放
free(srcbuf);
-// printf("function %s => %p\n",p,script);
+// PRINTF("function %s => %p\n",p,script);
return 0;
}
@@ -1734,7 +1732,7 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4)
sscanf(w4, "%d,%d,%d,%d,%s", &mob_class, &num, &delay1, &delay2,
eventname) < 2)
{
- printf("bad monster line : %s\n", w3);
+ PRINTF("bad monster line : %s\n", w3);
return 1;
}
@@ -1797,7 +1795,7 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4)
npc_mob++;
}
- //printf("warp npc %s %d read done\n",mapname,nd->bl.id);
+ //PRINTF("warp npc %s %d read done\n",mapname,nd->bl.id);
return 0;
}
@@ -2088,7 +2086,7 @@ int do_init_npc(void)
fp = fopen_(nsl->name, "r");
if (fp == NULL)
{
- printf("file not found : %s\n", nsl->name);
+ PRINTF("file not found : %s\n", nsl->name);
exit(1);
}
lines = 0;
@@ -2177,11 +2175,11 @@ int do_init_npc(void)
}
}
fclose_(fp);
- printf("\rLoading NPCs [%d]: %-54s", npc_id - START_NPC_NUM,
+ PRINTF("\rLoading NPCs [%d]: %-54s", npc_id - START_NPC_NUM,
nsl->name);
fflush(stdout);
}
- printf("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d]\n",
+ PRINTF("\rNPCs Loaded: %d [Warps:%d Shops:%d Scripts:%d Mobs:%d]\n",
npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob);
return 0;
diff --git a/src/map/npc.hpp b/src/map/npc.hpp
index 0654701..fba0ec0 100644
--- a/src/map/npc.hpp
+++ b/src/map/npc.hpp
@@ -38,8 +38,8 @@ struct npc_data *npc_spawn_text(int m, int x, int y, int class_, const char *nam
*/
void npc_free(struct npc_data *npc);
-void npc_addsrcfile(char *);
-void npc_delsrcfile(char *);
+void npc_addsrcfile(const char *);
+void npc_delsrcfile(const char *);
int do_init_npc(void);
int npc_event_do_oninit(void);
int npc_do_ontimer(int, struct map_session_data *, int);
diff --git a/src/map/party.cpp b/src/map/party.cpp
index 46374d3..9b9470c 100644
--- a/src/map/party.cpp
+++ b/src/map/party.cpp
@@ -97,7 +97,7 @@ int party_created(int account_id, int fail, int party_id, const char *name)
if ((p = (struct party *)numdb_search(party_db, party_id)) != NULL)
{
- printf("party_created(): ID already exists!\n");
+ PRINTF("party_created(): ID already exists!\n");
exit(1);
}
@@ -152,7 +152,7 @@ int party_check_member(struct party *p)
{
sd->status.party_id = 0;
if (battle_config.error_log)
- printf("party: check_member %d[%s] is not member\n",
+ PRINTF("party: check_member %d[%s] is not member\n",
sd->status.account_id, sd->status.name);
}
}
@@ -327,7 +327,7 @@ int party_member_added(int party_id, int account_id, int flag)
if (flag == 0)
{
if (battle_config.error_log)
- printf("party: member added error %d is not online\n",
+ PRINTF("party: member added error %d is not online\n",
account_id);
intif_party_leave(party_id, account_id); // キャラ側に登録できなかったため脱退要求を出す
}
@@ -339,7 +339,7 @@ int party_member_added(int party_id, int account_id, int flag)
if (p == NULL)
{
- printf("party_member_added: party %d not found.\n", party_id);
+ PRINTF("party_member_added: party %d not found.\n", party_id);
intif_party_leave(party_id, account_id);
return 0;
}
@@ -509,7 +509,7 @@ int party_recv_movemap(int party_id, int account_id, const char *mapname, int on
struct party_member *m = &p->member[i];
if (m == NULL)
{
- printf("party_recv_movemap nullpo?\n");
+ PRINTF("party_recv_movemap nullpo?\n");
return 0;
}
if (m->account_id == account_id)
@@ -523,7 +523,7 @@ int party_recv_movemap(int party_id, int account_id, const char *mapname, int on
if (i == MAX_PARTY)
{
if (battle_config.error_log)
- printf("party: not found member %d on %d[%s]", account_id,
+ PRINTF("party: not found member %d on %d[%s]", account_id,
party_id, p->name);
return 0;
}
diff --git a/src/map/path.cpp b/src/map/path.cpp
index afdae03..596332c 100644
--- a/src/map/path.cpp
+++ b/src/map/path.cpp
@@ -28,7 +28,7 @@ void push_heap_path(int *heap, struct tmp_path *tp, int index)
if (heap == NULL || tp == NULL)
{
- printf("push_heap_path nullpo\n");
+ PRINTF("push_heap_path nullpo\n");
return;
}
@@ -58,7 +58,7 @@ void update_heap_path(int *heap, struct tmp_path *tp, int index)
break;
if (h == heap[0])
{
- fprintf(stderr, "update_heap_path bug\n");
+ FPRINTF(stderr, "update_heap_path bug\n");
exit(1);
}
for (i = (h - 1) / 2;
@@ -232,13 +232,13 @@ int path_blownpos(int m, int x0, int y0, int dx, int dy, int count)
if (count > 15)
{ // 最大10マスに制限
if (battle_config.error_log)
- printf("path_blownpos: count too many %d !\n", count);
+ PRINTF("path_blownpos: count too many %d !\n", count);
count = 15;
}
if (dx > 1 || dx < -1 || dy > 1 || dy < -1)
{
if (battle_config.error_log)
- printf("path_blownpos: illeagal dx=%d or dy=%d !\n", dx, dy);
+ PRINTF("path_blownpos: illeagal dx=%d or dy=%d !\n", dx, dy);
dx = (dx >= 0) ? 1 : ((dx < 0) ? -1 : 0);
dy = (dy >= 0) ? 1 : ((dy < 0) ? -1 : 0);
}
diff --git a/src/map/pc.cpp b/src/map/pc.cpp
index 8a5a587..c25f512 100644
--- a/src/map/pc.cpp
+++ b/src/map/pc.cpp
@@ -224,7 +224,7 @@ void pc_invincible_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t)
if (sd->invincible_timer != tid)
{
if (battle_config.error_log)
- printf("invincible_timer %d != %d\n", sd->invincible_timer, tid);
+ PRINTF("invincible_timer %d != %d\n", sd->invincible_timer, tid);
return;
}
sd->invincible_timer = -1;
@@ -266,7 +266,7 @@ void pc_spiritball_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t)
if (sd->spirit_timer[0] != tid)
{
if (battle_config.error_log)
- printf("spirit_timer %d != %d\n", sd->spirit_timer[0], tid);
+ PRINTF("spirit_timer %d != %d\n", sd->spirit_timer[0], tid);
return;
}
sd->spirit_timer[0] = -1;
@@ -440,7 +440,7 @@ void pc_counttargeted_sub(struct block_list *bl,
&& md->state.state == MS_ATTACK && md->target_lv >= target_lv)
(*c)++;
- //printf("md->target_lv:%d, target_lv:%d\n",((struct mob_data *)bl)->target_lv,target_lv);
+ //PRINTF("md->target_lv:%d, target_lv:%d\n",((struct mob_data *)bl)->target_lv,target_lv);
}
}
@@ -698,7 +698,6 @@ int pc_isequip(struct map_session_data *sd, int n)
int pc_breakweapon(struct map_session_data *sd)
{
struct item_data *item;
- char output[255];
int i;
if (sd == NULL)
@@ -721,7 +720,7 @@ int pc_breakweapon(struct map_session_data *sd)
&& bool(sd->status.inventory[i].equip & EPOS::WEAPON)
&& sd->status.inventory[i].broken == 1)
{
- sprintf(output, "%s has broken.", item->jname);
+ std::string output = STRPRINTF("%s has broken.", item->jname);
clif_emotion(&sd->bl, 23);
clif_displaymessage(sd->fd, output);
clif_equiplist(sd);
@@ -742,10 +741,6 @@ int pc_breakweapon(struct map_session_data *sd)
*/
int pc_breakarmor(struct map_session_data *sd)
{
- struct item_data *item;
- char output[255];
- int i;
-
if (sd == NULL)
return -1;
if (sd->unbreakable >= MRAND(100))
@@ -753,20 +748,20 @@ int pc_breakarmor(struct map_session_data *sd)
if (sd->sc_data[SC_CP_ARMOR].timer != -1)
return 0;
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (int i = 0; i < MAX_INVENTORY; i++)
{
if (bool(sd->status.inventory[i].equip)
&& bool(sd->status.inventory[i].equip & EPOS::MISC1)
&& !sd->status.inventory[i].broken)
{
- item = sd->inventory_data[i];
+ struct item_data *item = sd->inventory_data[i];
sd->status.inventory[i].broken = 1;
- //pc_unequipitem(sd,i,CalcStatus::NOW);
if (bool(sd->status.inventory[i].equip)
&& bool(sd->status.inventory[i].equip & EPOS::MISC1)
&& sd->status.inventory[i].broken == 1)
{
- sprintf(output, "%s has broken.", item->jname);
+ std::string output = STRPRINTF("%s has broken.",
+ item->jname);
clif_emotion(&sd->bl, 23);
clif_displaymessage(sd->fd, output);
clif_equiplist(sd);
@@ -949,12 +944,12 @@ int pc_authok(int id, int login_id2, time_t connect_until_time,
if (pc_isGM(sd))
{
- printf("Connection accepted: character '%s' (account: %d; GM level %d).\n",
+ PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n",
sd->status.name, sd->status.account_id, pc_isGM(sd));
clif_updatestatus(sd, SP_GM);
}
else
- printf("Connection accepted: Character '%s' (account: %d).\n",
+ PRINTF("Connection accepted: Character '%s' (account: %d).\n",
sd->status.name, sd->status.account_id);
// Message of the Dayの送信
@@ -1217,7 +1212,7 @@ int pc_calc_skilltree(struct map_session_data *sd)
while (flag);
}
// if(battle_config.etc_log)
-// printf("calc skill_tree\n");
+// PRINTF("calc skill_tree\n");
return 0;
}
@@ -1801,7 +1796,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
}
dstr = str / 10;
sd->base_atk += str + dstr * dstr + dex / 5 + sd->paramc[ATTR::LUK] / 5;
-//fprintf(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[ATTR::LUK]/5);
+//FPRINTF(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[ATTR::LUK]/5);
sd->matk1 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 5) * (sd->paramc[ATTR::INT] / 5);
sd->matk2 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 7) * (sd->paramc[ATTR::INT] / 7);
if (sd->matk1 < sd->matk2)
@@ -2889,8 +2884,8 @@ int pc_bonus(struct map_session_data *sd, SP type, int val)
break;
default:
if (battle_config.error_log)
- printf("pc_bonus: unknown type %d %d !\n",
- uint16_t(type), val);
+ PRINTF("pc_bonus: unknown type %d %d !\n",
+ type, val);
break;
}
return 0;
@@ -3113,8 +3108,8 @@ int pc_bonus2(struct map_session_data *sd, SP type, int type2, int val)
} // end addition
default:
if (battle_config.error_log)
- printf("pc_bonus2: unknown type %d %d %d!\n",
- uint16_t(type), type2, val);
+ PRINTF("pc_bonus2: unknown type %d %d %d!\n",
+ type, type2, val);
break;
}
return 0;
@@ -3162,8 +3157,8 @@ int pc_bonus3(struct map_session_data *sd, SP type, int type2, int type3,
break;
default:
if (battle_config.error_log)
- printf("pc_bonus3: unknown type %d %d %d %d!\n",
- uint16_t(type), type2, type3, val);
+ PRINTF("pc_bonus3: unknown type %d %d %d %d!\n",
+ type, type2, type3, val);
break;
}
@@ -3181,7 +3176,7 @@ int pc_skill(struct map_session_data *sd, SkillID id, int level, int flag)
if (level > MAX_SKILL_LEVEL)
{
if (battle_config.error_log)
- printf("support card skill only!\n");
+ PRINTF("support card skill only!\n");
return 0;
}
if (!flag && (sd->status.skill[id].id == id || level == 0))
@@ -3721,25 +3716,26 @@ static
void pc_show_steal(struct block_list *bl,
struct map_session_data *sd, int itemid, int type)
{
- struct item_data *item = NULL;
- char output[100];
-
nullpo_retv(bl);
nullpo_retv(sd);
+ std::string output;
if (!type)
{
- if ((item = itemdb_exists(itemid)) == NULL)
- sprintf(output, "%s stole an Unknown_Item.", sd->status.name);
+ struct item_data *item = itemdb_exists(itemid);
+ if (item == NULL)
+ output = STRPRINTF("%s stole an Unknown_Item.",
+ sd->status.name);
else
- sprintf(output, "%s stole %s.", sd->status.name, item->jname);
+ output = STRPRINTF("%s stole %s.",
+ sd->status.name, item->jname);
clif_displaymessage(((struct map_session_data *) bl)->fd, output);
}
else
{
- sprintf(output,
- "%s has not stolen the item because of being overweight.",
- sd->status.name);
+ output = STRPRINTF(
+ "%s has not stolen the item because of being overweight.",
+ sd->status.name);
clif_displaymessage(((struct map_session_data *) bl)->fd, output);
}
}
@@ -3949,7 +3945,7 @@ int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y
if (x || y)
{
if (battle_config.error_log)
- printf("stacked (%d,%d)\n", x, y);
+ PRINTF("stacked (%d,%d)\n", x, y);
}
do
{
@@ -4077,7 +4073,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
if (sd->walktimer != tid)
{
if (battle_config.error_log)
- printf("pc_walk %d != %d\n", sd->walktimer, tid);
+ PRINTF("pc_walk %d != %d\n", sd->walktimer, tid);
return;
}
sd->walktimer = -1;
@@ -4545,7 +4541,7 @@ void pc_attack_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
if (sd->attacktimer != tid)
{
if (battle_config.error_log)
- printf("pc_attack_timer %d != %d\n", sd->attacktimer, tid);
+ PRINTF("pc_attack_timer %d != %d\n", sd->attacktimer, tid);
return;
}
sd->attacktimer = -1;
@@ -4866,7 +4862,6 @@ int pc_gainexp(struct map_session_data *sd, int base_exp, int job_exp)
int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp,
PC_GAINEXP_REASON reason)
{
- char output[256];
nullpo_ret(sd);
if (sd->bl.prev == NULL || pc_isdead(sd))
@@ -4940,9 +4935,10 @@ int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp,
if (battle_config.disp_experience)
{
- sprintf(output,
- "Experienced Gained Base:%d Job:%d", base_exp, job_exp);
- clif_disp_onlyself(sd, output, strlen(output));
+ std::string output = STRPRINTF(
+ "Experienced Gained Base:%d Job:%d",
+ base_exp, job_exp);
+ clif_displaymessage(sd->fd, output);
}
return 0;
@@ -5872,7 +5868,7 @@ int pc_setparam(struct map_session_data *sd, SP type, int val)
int pc_heal(struct map_session_data *sd, int hp, int sp)
{
// if(battle_config.battle_log)
-// printf("heal %d %d\n",hp,sp);
+// PRINTF("heal %d %d\n",hp,sp);
nullpo_ret(sd);
@@ -5998,7 +5994,7 @@ int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp)
{
int bonus;
// if(battle_config.battle_log)
-// printf("heal %d %d\n",hp,sp);
+// PRINTF("heal %d %d\n",hp,sp);
nullpo_ret(sd);
@@ -6451,7 +6447,7 @@ int pc_setregstr(struct map_session_data *sd, int reg, const char *str)
if (strlen(str) + 1 > sizeof(sd->regstr[0].data))
{
- printf("pc_setregstr(): String too long!\n");
+ PRINTF("pc_setregstr(): String too long!\n");
return 0;
}
@@ -6534,7 +6530,7 @@ int pc_setglobalreg(struct map_session_data *sd, const char *reg, int val)
return 0;
}
if (battle_config.error_log)
- printf("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n",
+ PRINTF("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n",
reg, GLOBAL_REG_NUM);
return 1;
@@ -6602,7 +6598,7 @@ int pc_setaccountreg(struct map_session_data *sd, const char *reg, int val)
return 0;
}
if (battle_config.error_log)
- printf("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n",
+ PRINTF("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n",
reg, ACCOUNT_REG_NUM);
return 1;
@@ -6670,7 +6666,7 @@ int pc_setaccountreg2(struct map_session_data *sd, const char *reg, int val)
return 0;
}
if (battle_config.error_log)
- printf("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n",
+ PRINTF("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n",
reg, ACCOUNT_REG2_NUM);
return 1;
@@ -6727,7 +6723,7 @@ void pc_eventtimer(timer_id tid, tick_t, custom_id_t id, custom_data_t data)
if (i == MAX_EVENTTIMER)
{
if (battle_config.error_log)
- printf("pc_eventtimer: no such event timer\n");
+ PRINTF("pc_eventtimer: no such event timer\n");
}
}
@@ -6869,8 +6865,8 @@ int pc_equipitem(struct map_session_data *sd, int n, EPOS)
EPOS pos = pc_equippoint(sd, n);
if (battle_config.battle_log)
- printf("equip %d (%d) %x:%x\n",
- nameid, n, uint16_t(id->equip), uint16_t(pos));
+ PRINTF("equip %d (%d) %x:%x\n",
+ nameid, n, id->equip, pos);
if (!pc_isequip(sd, n) || pos == EPOS::ZERO || sd->status.inventory[n].broken == 1)
{ // [Valaris]
clif_equipitemack(sd, n, EPOS::ZERO, 0); // fail
@@ -7044,9 +7040,9 @@ int pc_unequipitem(struct map_session_data *sd, int n, CalcStatus type)
}
if (battle_config.battle_log)
- printf("unequip %d %x:%x\n",
- n, uint16_t(pc_equippoint(sd, n)),
- uint16_t(sd->status.inventory[n].equip));
+ PRINTF("unequip %d %x:%x\n",
+ n, pc_equippoint(sd, n),
+ sd->status.inventory[n].equip);
if (bool(sd->status.inventory[n].equip))
{
for (EQUIP i : EQUIPs)
@@ -7151,7 +7147,7 @@ int pc_checkitem(struct map_session_data *sd)
if (battle_config.item_check && !itemdb_available(id))
{
if (battle_config.error_log)
- printf("illeagal item id %d in %d[%s] inventory.\n", id,
+ PRINTF("illeagal item id %d in %d[%s] inventory.\n", id,
sd->bl.id, sd->status.name);
pc_delitem(sd, i, sd->status.inventory[i].amount, 3);
continue;
@@ -7178,7 +7174,7 @@ int pc_checkitem(struct map_session_data *sd)
if (battle_config.item_check && !itemdb_available(id))
{
if (battle_config.error_log)
- printf("illeagal item id %d in %d[%s] cart.\n", id,
+ PRINTF("illeagal item id %d in %d[%s] cart.\n", id,
sd->bl.id, sd->status.name);
pc_cart_delitem(sd, i, sd->status.cart[i].amount, 1);
continue;
@@ -7359,7 +7355,7 @@ int pc_divorce(struct map_session_data *sd)
if (p_sd->status.partner_id != sd->status.char_id
|| sd->status.partner_id != p_sd->status.char_id)
{
- printf("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n",
+ PRINTF("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n",
sd->status.partner_id, p_sd->status.partner_id);
return -1;
}
@@ -7935,7 +7931,7 @@ int pc_read_gm_account(int fd)
{
gm_account[GM_num].account_id = RFIFOL(fd, i);
gm_account[GM_num].level = (int) RFIFOB(fd, i + 4);
- //printf("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);
+ //PRINTF("GM account: %d -> level %d\n", gm_account[GM_num].account_id, gm_account[GM_num].level);
GM_num++;
}
return GM_num;
@@ -8043,7 +8039,7 @@ int pc_readdb(void)
fp = fopen_("db/exp.txt", "r");
if (fp == NULL)
{
- printf("can't read db/exp.txt\n");
+ PRINTF("can't read db/exp.txt\n");
return 1;
}
i = 0;
@@ -8074,13 +8070,13 @@ int pc_readdb(void)
break;
}
fclose_(fp);
- printf("read db/exp.txt done\n");
+ PRINTF("read db/exp.txt done\n");
// JOB補正数値1
fp = fopen_("db/job_db1.txt", "r");
if (fp == NULL)
{
- printf("can't read db/job_db1.txt\n");
+ PRINTF("can't read db/job_db1.txt\n");
return 1;
}
i = 0;
@@ -8112,13 +8108,13 @@ int pc_readdb(void)
break;
}
fclose_(fp);
- printf("read db/job_db1.txt done\n");
+ PRINTF("read db/job_db1.txt done\n");
// JOBボーナス
fp = fopen_("db/job_db2.txt", "r");
if (fp == NULL)
{
- printf("can't read db/job_db2.txt\n");
+ PRINTF("can't read db/job_db2.txt\n");
return 1;
}
i = 0;
@@ -8144,13 +8140,13 @@ int pc_readdb(void)
break;
}
fclose_(fp);
- printf("read db/job_db2.txt done\n");
+ PRINTF("read db/job_db2.txt done\n");
// JOBボーナス2 転生職用
fp = fopen_("db/job_db2-2.txt", "r");
if (fp == NULL)
{
- printf("can't read db/job_db2-2.txt\n");
+ PRINTF("can't read db/job_db2-2.txt\n");
return 1;
}
i = 0;
@@ -8172,14 +8168,14 @@ int pc_readdb(void)
break;
}
fclose_(fp);
- printf("read db/job_db2-2.txt done\n");
+ PRINTF("read db/job_db2-2.txt done\n");
// スキルツリー
memset(skill_tree, 0, sizeof(skill_tree));
fp = fopen_("db/skill_tree.txt", "r");
if (fp == NULL)
{
- printf("can't read db/skill_tree.txt\n");
+ PRINTF("can't read db/skill_tree.txt\n");
return 1;
}
while (fgets(line, sizeof(line) - 1, fp))
@@ -8211,7 +8207,7 @@ int pc_readdb(void)
}
}
fclose_(fp);
- printf("read db/skill_tree.txt done\n");
+ PRINTF("read db/skill_tree.txt done\n");
// 属性修正テーブル
for (i = 0; i < 4; i++)
@@ -8221,7 +8217,7 @@ int pc_readdb(void)
fp = fopen_("db/attr_fix.txt", "r");
if (fp == NULL)
{
- printf("can't read db/attr_fix.txt\n");
+ PRINTF("can't read db/attr_fix.txt\n");
return 1;
}
while (fgets(line, sizeof(line) - 1, fp))
@@ -8239,7 +8235,7 @@ int pc_readdb(void)
}
lv = atoi(split[0]);
n = atoi(split[1]);
-// printf("%d %d\n",lv,n);
+// PRINTF("%d %d\n",lv,n);
for (i = 0; i < n;)
{
@@ -8265,7 +8261,7 @@ int pc_readdb(void)
}
}
fclose_(fp);
- printf("read db/attr_fix.txt done\n");
+ PRINTF("read db/attr_fix.txt done\n");
// サイズ補正テーブル
for (i = 0; i < 3; i++)
@@ -8274,7 +8270,7 @@ int pc_readdb(void)
fp = fopen_("db/size_fix.txt", "r");
if (fp == NULL)
{
- printf("can't read db/size_fix.txt\n");
+ PRINTF("can't read db/size_fix.txt\n");
return 1;
}
i = 0;
@@ -8298,7 +8294,7 @@ int pc_readdb(void)
i++;
}
fclose_(fp);
- printf("read db/size_fix.txt done\n");
+ PRINTF("read db/size_fix.txt done\n");
// 精錬データテーブル
for (i = 0; i < 5; i++)
@@ -8312,7 +8308,7 @@ int pc_readdb(void)
fp = fopen_("db/refine_db.txt", "r");
if (fp == NULL)
{
- printf("can't read db/refine_db.txt\n");
+ PRINTF("can't read db/refine_db.txt\n");
return 1;
}
i = 0;
@@ -8339,7 +8335,7 @@ int pc_readdb(void)
i++;
}
fclose_(fp); //Lupus. close this file!!!
- printf("read db/refine_db.txt done\n");
+ PRINTF("read db/refine_db.txt done\n");
return 0;
}
@@ -8374,7 +8370,7 @@ void pc_statpointdb(void)
if (stp == NULL)
{
- printf("can't read db/statpoint.txt\n");
+ PRINTF("can't read db/statpoint.txt\n");
return;
}
@@ -8385,7 +8381,7 @@ void pc_statpointdb(void)
buf_stat = (char *) malloc(end + 1);
l = fread(buf_stat, 1, end, stp);
fclose_(stp);
- printf("read db/statpoint.txt done (size=%d)\n", l);
+ PRINTF("read db/statpoint.txt done (size=%d)\n", l);
for (i = 0; i < 255; i++)
{
diff --git a/src/map/script.cpp b/src/map/script.cpp
index cb43f64..3a75728 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -10,7 +10,10 @@
#include <cstring>
#include <ctime>
+#include <fstream>
+
#include "../common/db.hpp"
+#include "../common/extract.hpp"
#include "../common/lock.hpp"
#include "../common/mt_rand.hpp"
#include "../common/socket.hpp"
@@ -86,9 +89,19 @@ struct dbt *script_get_userfunc_db(void)
}
static
-char pos[11][100] =
- { "頭", "体", "左手", "右手", "ローブ", "靴", "アクセサリー1",
- "アクセサリー2", "頭2", "頭3", "装着していない"
+const char *pos[11] =
+{
+ "Head",
+ "Body",
+ "Left hand",
+ "Right hand",
+ "Robe",
+ "Shoes",
+ "Accessory 1",
+ "Accessory 2",
+ "Head 2",
+ "Head 3",
+ "Not Equipped",
};
static
@@ -131,7 +144,6 @@ struct BuiltinFunction
extern BuiltinFunction builtin_functions[];
-#ifdef RECENT_GCC
enum class ScriptCode : uint8_t
{
// tyoes and specials
@@ -143,7 +155,6 @@ enum class ScriptCode : uint8_t
XOR, OR, AND, ADD, SUB, MUL, DIV, MOD, NEG, LNOT,
NOT, R_SHIFT, L_SHIFT
};
-#endif
/*==========================================
* 文字列のハッシュを計算
@@ -446,17 +457,17 @@ void disp_error_message(const char *mes, const char *pos_)
}
if (lineend == NULL || pos_ < lineend)
{
- printf("%s line %d : ", mes, line);
+ PRINTF("%s line %d : ", mes, line);
for (int i = 0;
(linestart[i] != '\r') && (linestart[i] != '\n')
&& linestart[i]; i++)
{
if (linestart + i != pos_)
- printf("%c", linestart[i]);
+ PRINTF("%c", linestart[i]);
else
- printf("\'%c\'", linestart[i]);
+ PRINTF("\'%c\'", linestart[i]);
}
- printf("\a\n");
+ PRINTF("\a\n");
if (lineend)
*lineend = c;
return;
@@ -478,7 +489,7 @@ const char *parse_simpleexpr(const char *p)
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf("parse_simpleexpr %s\n", p);
+ PRINTF("parse_simpleexpr %s\n", p);
#endif
if (*p == ';' || *p == ',')
{
@@ -577,7 +588,7 @@ const char *parse_simpleexpr(const char *p)
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf("parse_simpleexpr end %s\n", p);
+ PRINTF("parse_simpleexpr end %s\n", p);
#endif
return p;
}
@@ -593,7 +604,7 @@ const char *parse_subexpr(const char *p, int limit)
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf("parse_subexpr %s\n", p);
+ PRINTF("parse_subexpr %s\n", p);
#endif
p = skip_space(p);
@@ -696,7 +707,7 @@ const char *parse_subexpr(const char *p, int limit)
}
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf("parse_subexpr end %s\n", p);
+ PRINTF("parse_subexpr end %s\n", p);
#endif
return p; /* return first untreated operator */
}
@@ -710,7 +721,7 @@ const char *parse_expr(const char *p)
{
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf("parse_expr %s\n", p);
+ PRINTF("parse_expr %s\n", p);
#endif
switch (*p)
{
@@ -726,7 +737,7 @@ const char *parse_expr(const char *p)
p = parse_subexpr(p, -1);
#ifdef DEBUG_FUNCIN
if (battle_config.etc_log)
- printf("parse_expr end %s\n", p);
+ PRINTF("parse_expr end %s\n", p);
#endif
return p;
}
@@ -827,35 +838,30 @@ void add_builtin_functions(void)
static
void read_constdb(void)
{
- FILE *fp;
- char line[1024], name[1024];
- int val, n, i, type;
-
- fp = fopen_("db/const.txt", "r");
- if (fp == NULL)
+ std::ifstream in("db/const.txt");
+ if (!in.is_open())
{
- printf("can't read db/const.txt\n");
+ PRINTF("can't read db/const.txt\n");
return;
}
- while (fgets(line, 1020, fp))
+
+ std::string line;
+ while (std::getline(in, line))
{
if (line[0] == '/' && line[1] == '/')
continue;
- type = 0;
- if (sscanf(line, "%[A-Za-z0-9_],%d,%d", name, &val, &type) >= 2 ||
- sscanf(line, "%[A-Za-z0-9_] %d %d", name, &val, &type) >= 2)
- {
- for (i = 0; name[i]; i++)
- name[i] = tolower(name[i]);
- n = add_str(name);
- if (type == 0)
- str_data[n].type = ScriptCode::INT;
- else
- str_data[n].type = ScriptCode::PARAM;
- str_data[n].val = val;
- }
+
+ std::string name;
+ int val;
+ int type = 0; // if not provided
+ if (SSCANF(line, "%m[A-Za-z0-9_] %x %x", &name, &val, &type) < 2)
+ continue;
+ for (char& c : name)
+ c = tolower(c);
+ int n = add_str(name.c_str());
+ str_data[n].type = type ? ScriptCode::PARAM : ScriptCode::INT;
+ str_data[n].val = val;
}
- fclose_(fp);
}
/*==========================================
@@ -968,12 +974,12 @@ const ScriptCode *parse_script(const char *src, int line)
for (i = 0; i < script_pos; i++)
{
if ((i & 15) == 0)
- printf("%04x : ", i);
- printf("%02x ", script_buf[i]);
+ PRINTF("%04x : ", i);
+ PRINTF("%02x ", script_buf[i]);
if ((i & 15) == 15)
- printf("\n");
+ PRINTF("\n");
}
- printf("\n");
+ PRINTF("\n");
#endif
return script_buf;
@@ -995,7 +1001,7 @@ struct map_session_data *script_rid2sd(ScriptState *st)
struct map_session_data *sd = map_id2sd(st->rid);
if (!sd)
{
- printf("script_rid2sd: fatal error ! player not attached!\n");
+ PRINTF("script_rid2sd: fatal error ! player not attached!\n");
}
return sd;
}
@@ -1017,7 +1023,7 @@ void get_val(ScriptState *st, struct script_data *data)
if (prefix != '$')
{
if ((sd = script_rid2sd(st)) == NULL)
- printf("get_val error name?:%s\n", name);
+ PRINTF("get_val error name?:%s\n", name);
}
if (postfix == '$')
{
@@ -1035,7 +1041,7 @@ void get_val(ScriptState *st, struct script_data *data)
}
else
{
- printf("script: get_val: illegal scope string variable.\n");
+ PRINTF("script: get_val: illegal scope string variable.\n");
data->u.str = "!!ERROR!!";
}
if (data->u.str == NULL)
@@ -1126,7 +1132,7 @@ void set_reg(struct map_session_data *sd, int num, const char *name, struct scri
}
else
{
- printf("script: set_reg: illegal scope string variable !");
+ PRINTF("script: set_reg: illegal scope string variable !");
}
}
else
@@ -1238,7 +1244,7 @@ void push_val(struct script_stack *stack, ScriptCode type, int val)
64 * sizeof(*(stack->stack_data)));
}
// if(battle_config.etc_log)
-// printf("push (%d,%d)-> %d\n",type,val,stack->sp);
+// PRINTF("push (%d,%d)-> %d\n",type,val,stack->sp);
stack->stack_data[stack->sp].type = type;
stack->stack_data[stack->sp].u.num = val;
stack->sp++;
@@ -1261,7 +1267,7 @@ void push_str(struct script_stack *stack, ScriptCode type, const char *str)
64 * sizeof(*(stack->stack_data)));
}
// if(battle_config.etc_log)
-// printf("push (%d,%x)-> %d\n",type,str,stack->sp);
+// PRINTF("push (%d,%x)-> %d\n",type,str,stack->sp);
stack->stack_data[stack->sp].type = type;
stack->stack_data[stack->sp].u.str = str;
stack->sp++;
@@ -1336,7 +1342,7 @@ void builtin_goto(ScriptState *st)
{
if (st->stack->stack_data[st->start + 2].type != ScriptCode::POS)
{
- printf("script: goto: not label !\n");
+ PRINTF("script: goto: not label !\n");
st->state = END;
return;
}
@@ -1375,7 +1381,7 @@ void builtin_callfunc(ScriptState *st)
}
else
{
- printf("script:callfunc: function not found! [%s]\n", str);
+ PRINTF("script:callfunc: function not found! [%s]\n", str);
st->state = END;
}
}
@@ -1734,7 +1740,7 @@ void builtin_input(ScriptState *st)
}
else
{
- printf("builtin_input: string discarded !!\n");
+ PRINTF("builtin_input: string discarded !!\n");
}
}
else
@@ -1812,7 +1818,7 @@ void builtin_set(ScriptState *st)
if (st->stack->stack_data[st->start + 2].type != ScriptCode::NAME)
{
- printf("script: builtin_set: not name\n");
+ PRINTF("script: builtin_set: not name\n");
return;
}
@@ -1850,7 +1856,7 @@ void builtin_setarray(ScriptState *st)
if (prefix != '$' && prefix != '@')
{
- printf("builtin_setarray: illegal scope !\n");
+ PRINTF("builtin_setarray: illegal scope !\n");
return;
}
if (prefix != '$')
@@ -1882,7 +1888,7 @@ void builtin_cleararray(ScriptState *st)
if (prefix != '$' && prefix != '@')
{
- printf("builtin_cleararray: illegal scope !\n");
+ PRINTF("builtin_cleararray: illegal scope !\n");
return;
}
if (prefix != '$')
@@ -1924,7 +1930,7 @@ void builtin_getarraysize(ScriptState *st)
if (prefix != '$' && prefix != '@')
{
- printf("builtin_copyarray: illegal scope !\n");
+ PRINTF("builtin_copyarray: illegal scope !\n");
return;
}
@@ -1943,7 +1949,7 @@ void builtin_getelementofarray(ScriptState *st)
int i = conv_num(st, &(st->stack->stack_data[st->start + 3]));
if (i > 127 || i < 0)
{
- printf("script: getelementofarray (operator[]): param2 illegal number %d\n",
+ PRINTF("script: getelementofarray (operator[]): param2 illegal number %d\n",
i);
push_val(st->stack, ScriptCode::INT, 0);
}
@@ -1955,7 +1961,7 @@ void builtin_getelementofarray(ScriptState *st)
}
else
{
- printf("script: getelementofarray (operator[]): param1 not name !\n");
+ PRINTF("script: getelementofarray (operator[]): param1 not name !\n");
push_val(st->stack, ScriptCode::INT, 0);
}
}
@@ -2009,7 +2015,7 @@ void builtin_countitem(ScriptState *st)
else
{
if (battle_config.error_log)
- printf("wrong item ID : countitem (%i)\n", nameid);
+ PRINTF("wrong item ID : countitem (%i)\n", nameid);
}
push_val(st->stack, ScriptCode::INT, count);
@@ -2210,7 +2216,7 @@ void builtin_delitem(ScriptState *st)
if (nameid < 500 || amount <= 0)
{ //by Lupus. Don't run FOR if u got wrong item ID or amount<=0
- //printf("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
+ //PRINTF("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount);
return;
}
sd = script_rid2sd(st);
@@ -2389,7 +2395,7 @@ void builtin_getequipid(ScriptState *st)
sd = script_rid2sd(st);
if (sd == NULL)
{
- printf("getequipid: sd == NULL\n");
+ PRINTF("getequipid: sd == NULL\n");
return;
}
num = conv_num(st, &(st->stack->stack_data[st->start + 2]));
@@ -2992,10 +2998,10 @@ void builtin_announce(ScriptState *st)
{
struct block_list *bl = (flag & 0x08) ? map_id2bl(st->oid) :
(struct block_list *) script_rid2sd(st);
- clif_GMmessage(bl, str, strlen(str) + 1, flag);
+ clif_GMmessage(bl, str, flag);
}
else
- intif_GMmessage(str, strlen(str) + 1, flag);
+ intif_GMmessage(str, flag);
}
/*==========================================
@@ -3003,9 +3009,9 @@ void builtin_announce(ScriptState *st)
*------------------------------------------
*/
static
-void builtin_mapannounce_sub(struct block_list *bl, const char *str, int len, int flag)
+void builtin_mapannounce_sub(struct block_list *bl, const char *str, int flag)
{
- clif_GMmessage(bl, str, len, flag | 3);
+ clif_GMmessage(bl, str, flag | 3);
}
static
@@ -3019,7 +3025,7 @@ void builtin_mapannounce(ScriptState *st)
if ((m = map_mapname2mapid(mapname)) < 0)
return;
- map_foreachinarea(std::bind(builtin_mapannounce_sub, ph::_1, str, strlen(str) + 1, flag & 0x10),
+ map_foreachinarea(std::bind(builtin_mapannounce_sub, ph::_1, str, flag & 0x10),
m, 0, 0, map[m].xs, map[m].ys, BL_PC);
}
@@ -3232,7 +3238,7 @@ void builtin_sc_end(ScriptState *st)
bl = map_id2bl(((struct map_session_data *) bl)->skilltarget);
skill_status_change_end(bl, type, -1);
// if(battle_config.etc_log)
-// printf("sc_end : %d %d\n",st->rid,type);
+// PRINTF("sc_end : %d %d\n",st->rid,type);
}
static
@@ -3257,7 +3263,7 @@ static
void builtin_debugmes(ScriptState *st)
{
conv_str(st, &(st->stack->stack_data[st->start + 2]));
- printf("script debug : %d %d : %s\n", st->rid, st->oid,
+ PRINTF("script debug : %d %d : %s\n", st->rid, st->oid,
st->stack->stack_data[st->start + 2].u.str);
}
@@ -4140,7 +4146,7 @@ void builtin_npctalk(ScriptState *st)
memcpy(message, nd->name, 24);
strcat(message, " : ");
strcat(message, str);
- clif_message(&(nd->bl), message);
+ clif_message(&nd->bl, message);
}
}
@@ -4454,7 +4460,7 @@ void op_2str(ScriptState *st, ScriptCode op, int sp1, int sp2)
a = (strcmp(s1, s2) <= 0);
break;
default:
- printf("illegal string operater\n");
+ PRINTF("illegal string operater\n");
break;
}
@@ -4561,7 +4567,7 @@ void op_2(ScriptState *st, ScriptCode op)
else
{
// si,is => error
- printf("script: op_2: int&str, str&int not allow.");
+ PRINTF("script: op_2: int&str, str&int not allow.");
push_val(st->stack, ScriptCode::INT, 0);
}
}
@@ -4604,7 +4610,7 @@ void run_func(ScriptState *st)
if (i == 0)
{
if (battle_config.error_log)
- printf("function not found\n");
+ PRINTF("function not found\n");
// st->stack->sp=0;
st->state = END;
return;
@@ -4617,7 +4623,7 @@ void run_func(ScriptState *st)
if (st->stack->stack_data[st->start].type != ScriptCode::NAME
|| str_data[func].type != ScriptCode::FUNC)
{
- printf("run_func: not function and command! \n");
+ PRINTF("run_func: not function and command! \n");
// st->stack->sp=0;
st->state = END;
return;
@@ -4625,33 +4631,33 @@ void run_func(ScriptState *st)
#ifdef DEBUG_RUN
if (battle_config.etc_log)
{
- printf("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str,
+ PRINTF("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str,
func, str_data[func].type);
- printf("stack dump :");
+ PRINTF("stack dump :");
for (i = 0; i < end_sp; i++)
{
switch (st->stack->stack_data[i].type)
{
case ScriptCode::INT:
- printf(" int(%d)", st->stack->stack_data[i].u.num);
+ PRINTF(" int(%d)", st->stack->stack_data[i].u.num);
break;
case ScriptCode::NAME:
- printf(" name(%s)",
+ PRINTF(" name(%s)",
str_buf +
str_data[st->stack->stack_data[i].u.num].str);
break;
case ScriptCode::ARG:
- printf(" arg");
+ PRINTF(" arg");
break;
case ScriptCode::POS:
- printf(" pos(%d)", st->stack->stack_data[i].u.num);
+ PRINTF(" pos(%d)", st->stack->stack_data[i].u.num);
break;
default:
- printf(" %d,%d", st->stack->stack_data[i].type,
+ PRINTF(" %d,%d", st->stack->stack_data[i].type,
st->stack->stack_data[i].u.num);
}
}
- printf("\n");
+ PRINTF("\n");
}
#endif
if (str_data[func].func)
@@ -4661,8 +4667,8 @@ void run_func(ScriptState *st)
else
{
if (battle_config.error_log)
- printf("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str,
- func, uint8_t(str_data[func].type));
+ PRINTF("run_func : %s? (%d(%d))\n", str_buf + str_data[func].str,
+ func, str_data[func].type);
push_val(st->stack, ScriptCode::INT, 0);
}
@@ -4677,7 +4683,7 @@ void run_func(ScriptState *st)
if (st->defsp < 4
|| st->stack->stack_data[st->defsp - 1].type != ScriptCode::RETINFO)
{
- printf("script:run_func (return) return without callfunc or callsub!\n");
+ PRINTF("script:run_func (return) return without callfunc or callsub!\n");
st->state = END;
return;
}
@@ -4717,7 +4723,7 @@ void run_script_main(const ScriptCode *script, int pos_, int, int,
if (stack->sp != st->defsp)
{
if (battle_config.error_log)
- printf("stack.sp (%d) != default (%d)\n", stack->sp,
+ PRINTF("stack.sp (%d) != default (%d)\n", stack->sp,
st->defsp);
stack->sp = st->defsp;
}
@@ -4747,7 +4753,7 @@ void run_script_main(const ScriptCode *script, int pos_, int, int,
st->state = 0;
if (gotocount > 0 && (--gotocount) <= 0)
{
- printf("run_script: infinity loop !\n");
+ PRINTF("run_script: infinity loop !\n");
st->state = END;
}
}
@@ -4789,13 +4795,13 @@ void run_script_main(const ScriptCode *script, int pos_, int, int,
default:
if (battle_config.error_log)
- printf("unknown command : %d @ %d\n", uint8_t(c), pos_);
+ PRINTF("unknown command : %d @ %d\n", c, pos_);
st->state = END;
break;
}
if (cmdcount > 0 && (--cmdcount) <= 0)
{
- printf("run_script: infinity loop !\n");
+ PRINTF("run_script: infinity loop !\n");
st->state = END;
}
}
@@ -4942,43 +4948,47 @@ void mapreg_setregstr(int num, const char *str)
static
void script_load_mapreg(void)
{
- FILE *fp;
- char line[1024];
+ std::ifstream in(mapreg_txt);
- if ((fp = fopen_(mapreg_txt, "rt")) == NULL)
+ if (!in.is_open())
return;
- while (fgets(line, sizeof(line), fp))
- {
- char buf1[256], buf2[1024], *p;
- int n, v, s, i;
- if (sscanf(line, "%255[^,],%d\t%n", buf1, &i, &n) != 2 &&
- (i = 0, sscanf(line, "%[^\t]\t%n", buf1, &n) != 1))
- continue;
- if (buf1[strlen(buf1) - 1] == '$')
+ std::string line;
+ while (std::getline(in, line))
+ {
+ std::string buf1, buf2;
+ int index = 0;
+ if (extract(line,
+ record<'\t'>(
+ record<','>(&buf1, &index),
+ &buf2))
+ || extract(line,
+ record<'\t'>(
+ record<','>(&buf1),
+ &buf2)))
{
- if (sscanf(line + n, "%[^\n\r]", buf2) != 1)
+ int s = add_str(buf1.c_str());
+ int key = (index << 24) | s;
+ if (buf1.back() == '$')
+ {
+ char *p = strdup(buf2.c_str());
+ numdb_insert(mapregstr_db, key, p);
+ }
+ else
{
- printf("%s: %s broken data !\n", mapreg_txt, buf1);
- continue;
+ int v;
+ if (!extract(buf2, &v))
+ goto borken;
+ numdb_insert(mapreg_db, key, v);
}
- p = (char *) calloc(strlen(buf2) + 1, 1);
- strcpy(p, buf2);
- s = add_str(buf1);
- numdb_insert(mapregstr_db, (i << 24) | s, p);
}
else
{
- if (sscanf(line + n, "%d", &v) != 1)
- {
- printf("%s: %s broken data !\n", mapreg_txt, buf1);
- continue;
- }
- s = add_str(buf1);
- numdb_insert(mapreg_db, (i << 24) | s, v);
+ borken:
+ PRINTF("%s: %s broken data !\n", mapreg_txt, buf1);
+ continue;
}
}
- fclose_(fp);
mapreg_dirty = 0;
}
@@ -4994,9 +5004,9 @@ void script_save_mapreg_intsub(db_key_t key, db_val_t data, FILE *fp)
if (name[1] != '@')
{
if (i == 0)
- fprintf(fp, "%s\t%d\n", name, (int) data);
+ FPRINTF(fp, "%s\t%d\n", name, (int) data);
else
- fprintf(fp, "%s,%d\t%d\n", name, i, (int) data);
+ FPRINTF(fp, "%s,%d\t%d\n", name, i, (int) data);
}
}
@@ -5008,9 +5018,9 @@ void script_save_mapreg_strsub(db_key_t key, db_val_t data, FILE *fp)
if (name[1] != '@')
{
if (i == 0)
- fprintf(fp, "%s\t%s\n", name, (char *) data);
+ FPRINTF(fp, "%s\t%s\n", name, (char *) data);
else
- fprintf(fp, "%s,%d\t%s\n", name, i, (char *) data);
+ FPRINTF(fp, "%s,%d\t%s\n", name, i, (char *) data);
}
}
@@ -5035,69 +5045,14 @@ void script_autosave_mapreg(timer_id, tick_t, custom_id_t, custom_data_t)
script_save_mapreg();
}
-/*==========================================
- *
- *------------------------------------------
- */
-static
-void set_posword(char *p)
+void script_config_read()
{
- char *np, *str[15];
- int i = 0;
- for (i = 0; i < 11; i++)
- {
- if ((np = strchr(p, ',')) != NULL)
- {
- str[i] = p;
- *np = 0;
- p = np + 1;
- }
- else
- {
- str[i] = p;
- p += strlen(p);
- }
- if (str[i])
- strcpy(pos[i], str[i]);
- }
-}
-
-void script_config_read(const char *cfgName)
-{
- int i;
- char line[1024], w1[1024], w2[1024];
- FILE *fp;
-
script_config.warn_func_no_comma = 1;
script_config.warn_cmd_no_comma = 1;
script_config.warn_func_mismatch_paramnum = 1;
script_config.warn_cmd_mismatch_paramnum = 1;
script_config.check_cmdcount = 8192;
script_config.check_gotocount = 512;
-
- fp = fopen_(cfgName, "r");
- if (fp == NULL)
- {
- printf("file not found: %s\n", cfgName);
- return;
- }
- while (fgets(line, 1020, fp))
- {
- if (line[0] == '/' && line[1] == '/')
- continue;
- i = sscanf(line, "%[^:]: %[^\r\n]", w1, w2);
- if (i != 2)
- continue;
- if (strcasecmp(w1, "refine_posword") == 0)
- {
- set_posword(w2);
- }
- if (strcasecmp(w1, "import") == 0)
- {
- script_config_read(w2);
- }
- }
- fclose_(fp);
}
/*==========================================
diff --git a/src/map/script.hpp b/src/map/script.hpp
index 03ff950..e09baf8 100644
--- a/src/map/script.hpp
+++ b/src/map/script.hpp
@@ -3,40 +3,7 @@
#include <cstdint>
-// values are private, but gcc < 4.6 doesn't
-// support forward-declared enums
-enum class ScriptCode : uint8_t
-#ifdef RECENT_GCC
-;
-#else
-{
- // types and specials
- NOP, POS, INT, PARAM, FUNC, STR, CONSTSTR, ARG,
- NAME, EOL, RETINFO,
-
- // unary and binary operators
- LOR, LAND, LE, LT, GE, GT, EQ, NE,
- XOR, OR, AND, ADD, SUB, MUL, DIV, MOD, NEG, LNOT,
- NOT, R_SHIFT, L_SHIFT,
-
- // really nasty workaround for gcc < 4.6
-
- x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x2a, x2b, x2c, x2d, x2e, x2f,
- x30, x31, x32, x33, x34, x35, x36, x37, x38, x39, x3a, x3b, x3c, x3d, x3e, x3f,
- x40, x41, x42, x43, x44, x45, x46, x47, x48, x49, x4a, x4b, x4c, x4d, x4e, x4f,
- x50, x51, x52, x53, x54, x55, x56, x57, x58, x59, x5a, x5b, x5c, x5d, x5e, x5f,
- x60, x61, x62, x63, x64, x65, x66, x67, x68, x69, x6a, x6b, x6c, x6d, x6e, x6f,
- x70, x71, x72, x73, x74, x75, x76, x77, x78, x79, x7a, x7b, x7c, x7d, x7e, x7f,
- x80, x81, x82, x83, x84, x85, x86, x87, x88, x89, x8a, x8b, x8c, x8d, x8e, x8f,
- x90, x91, x92, x93, x94, x95, x96, x97, x98, x99, x9a, x9b, x9c, x9d, x9e, x9f,
- xa0, xa1, xa2, xa3, xa4, xa5, xa6, xa7, xa8, xa9, xaa, xab, xac, xad, xae, xaf,
- xb0, xb1, xb2, xb3, xb4, xb5, xb6, xb7, xb8, xb9, xba, xbb, xbc, xbd, xbe, xbf,
- xc0, xc1, xc2, xc3, xc4, xc5, xc6, xc7, xc8, xc9, xca, xcb, xcc, xcd, xce, xcf,
- xd0, xd1, xd2, xd3, xd4, xd5, xd6, xd7, xd8, xd9, xda, xdb, xdc, xdd, xde, xdf,
- xe0, xe1, xe2, xe3, xe4, xe5, xe6, xe7, xe8, xe9, xea, xeb, xec, xed, xee, xef,
- xf0, xf1, xf2, xf3, xf4, xf5, xf6, xf7, xf8, xf9, xfa, xfb, xfc, xfd, xfe, xff,
-};
-#endif
+enum class ScriptCode : uint8_t;
struct script_data
{
@@ -86,10 +53,10 @@ int run_script(const ScriptCode *, int, int, int);
struct dbt *script_get_label_db(void);
struct dbt *script_get_userfunc_db(void);
-void script_config_read(const char *cfgName);
+void script_config_read();
void do_init_script(void);
void do_final_script(void);
-extern char mapreg_txt[];
+extern char mapreg_txt[256];
#endif // SCRIPT_HPP
diff --git a/src/map/skill-pools.cpp b/src/map/skill-pools.cpp
index c20c863..c26d9cc 100644
--- a/src/map/skill-pools.cpp
+++ b/src/map/skill-pools.cpp
@@ -28,7 +28,7 @@ void skill_pool_register(SkillID id)
{
if (skill_pool_skills_size + 1 >= MAX_POOL_SKILLS)
{
- fprintf(stderr,
+ FPRINTF(stderr,
"Too many pool skills! Increase MAX_POOL_SKILLS and recompile.");
return;
}
diff --git a/src/map/skill.cpp b/src/map/skill.cpp
index 3050012..77da219 100644
--- a/src/map/skill.cpp
+++ b/src/map/skill.cpp
@@ -1758,8 +1758,8 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl,
if (MRAND(10000) < eff1 * sc_def_card1 / 100)
{
if (battle_config.battle_log)
- printf("PC %d skill_addeff: cardによる異常発動 %d %d\n",
- sd->bl.id, uint16_t(si), eff1);
+ PRINTF("PC %d skill_addeff: cardによる異常発動 %d %d\n",
+ sd->bl.id, si, eff1);
skill_status_change_start(bl, si, 7, 0, 0, 0,
(bi == BadSC::CONFUSION)
@@ -1774,8 +1774,8 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl,
if (MRAND(10000) < eff2 * sc_def_card2 / 100)
{
if (battle_config.battle_log)
- printf("PC %d skill_addeff: cardによる異常発動 %d %d\n",
- src->id, uint16_t(si), eff2);
+ PRINTF("PC %d skill_addeff: cardによる異常発動 %d %d\n",
+ src->id, si, eff2);
skill_status_change_start(src, si, 7, 0, 0, 0,
(bi == BadSC::CONFUSION)
? 10000 + 7000
@@ -5148,7 +5148,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
}
break;
default:
- printf("Unknown skill used:%d\n", uint16_t(skillid));
+ PRINTF("Unknown skill used:%d\n", skillid);
map_freeblock_unlock();
return 1;
}
@@ -5308,8 +5308,8 @@ void skill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
}
if (battle_config.pc_skill_log)
- printf("PC %d skill castend skill=%d\n",
- sd->bl.id, uint16_t(sd->skillid));
+ PRINTF("PC %d skill castend skill=%d\n",
+ sd->bl.id, sd->skillid);
pc_stop_walking(sd, 0);
switch (skill_get_nk(sd->skillid))
@@ -5556,8 +5556,8 @@ int skill_castend_map(struct map_session_data *sd, SkillID skill_num,
pc_stopattack(sd);
if (battle_config.pc_skill_log)
- printf("PC %d skill castend skill =%d map=%s\n",
- sd->bl.id, uint16_t(skill_num), mapname);
+ PRINTF("PC %d skill castend skill =%d map=%s\n",
+ sd->bl.id, skill_num, mapname);
pc_stop_walking(sd, 0);
if (strcmp(mapname, "cancel") == 0)
@@ -6674,7 +6674,7 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl,
/* default:
if (battle_config.error_log)
- printf("skill_unit_onplace: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id);
+ PRINTF("skill_unit_onplace: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id);
break;*/
}
if (bl->type == BL_MOB && ss != bl) /* スキル使用条件のMOBスキル */
@@ -6819,7 +6819,7 @@ int skill_unit_onout(struct skill_unit *src, struct block_list *bl,
/* default:
if (battle_config.error_log)
- printf("skill_unit_onout: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id);
+ PRINTF("skill_unit_onout: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id);
break;*/
}
skill_unitgrouptickset_delete(bl, sg->group_id);
@@ -6877,7 +6877,7 @@ int skill_unit_ondelete(struct skill_unit *src, struct block_list *bl,
/* default:
if (battle_config.error_log)
- printf("skill_unit_ondelete: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id);
+ PRINTF("skill_unit_ondelete: Unknown skill unit id=%d block=%d\n",sg->unit_id,bl->id);
break;*/
}
skill_unitgrouptickset_delete(bl, sg->group_id);
@@ -7133,8 +7133,8 @@ void skill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
}
if (battle_config.pc_skill_log)
- printf("PC %d skill castend skill=%d\n",
- sd->bl.id, uint16_t(sd->skillid));
+ PRINTF("PC %d skill castend skill=%d\n",
+ sd->bl.id, sd->skillid);
pc_stop_walking(sd, 0);
skill_castend_pos2(&sd->bl, sd->skillx, sd->skilly, sd->skillid,
@@ -7898,7 +7898,7 @@ int skill_use_id(struct map_session_data *sd, int target_id,
if ((bl = map_id2bl(target_id)) == NULL)
{
/* if (battle_config.error_log)
- printf("skill target not found %d\n",target_id); */
+ PRINTF("skill target not found %d\n",target_id); */
return 0;
}
if (sd->bl.m != bl->m || pc_isdead(sd))
@@ -7976,7 +7976,7 @@ int skill_use_id(struct map_session_data *sd, int target_id,
if (sc_data && sc_data[SC_DANCING].timer != -1)
{
// if(battle_config.pc_skill_log)
-// printf("dancing! %d\n",skill_num);
+// PRINTF("dancing! %d\n",skill_num);
if (sc_data[SC_DANCING].val4 && skill_num != BD_ADAPTATION) //合奏中はアドリブ以外不可
return 0;
if (skill_num != BD_ADAPTATION && skill_num != BA_MUSICALSTRIKE
@@ -8176,8 +8176,8 @@ int skill_use_id(struct map_session_data *sd, int target_id,
}
if (battle_config.pc_skill_log)
- printf("PC %d skill use target_id=%d skill=%d lv=%d cast=%d\n",
- sd->bl.id, target_id, uint16_t(skill_num), skill_lv, casttime);
+ PRINTF("PC %d skill use target_id=%d skill=%d lv=%d cast=%d\n",
+ sd->bl.id, target_id, skill_num, skill_lv, casttime);
// if(sd->skillitem == skill_num)
// casttime = delay = 0;
@@ -8301,9 +8301,9 @@ int skill_use_pos(struct map_session_data *sd,
sd->state.skillcastcancel = skill_db[skill_num].castcancel;
if (battle_config.pc_skill_log)
- printf("PC %d skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d\n",
+ PRINTF("PC %d skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d\n",
sd->bl.id, skill_x, skill_y,
- uint16_t(skill_num), skill_lv, casttime);
+ skill_num, skill_lv, casttime);
// if(sd->skillitem == skill_num)
// casttime = delay = 0;
@@ -8962,7 +8962,7 @@ int skill_status_change_active(struct block_list *bl, StatusChange type)
if (bl->type != BL_PC && bl->type != BL_MOB)
{
if (battle_config.error_log)
- printf("skill_status_change_active: neither MOB nor PC !\n");
+ PRINTF("skill_status_change_active: neither MOB nor PC !\n");
return 0;
}
@@ -8987,7 +8987,7 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid)
if (bl->type != BL_PC && bl->type != BL_MOB)
{
if (battle_config.error_log)
- printf("skill_status_change_end: neither MOB nor PC !\n");
+ PRINTF("skill_status_change_end: neither MOB nor PC !\n");
return 0;
}
sc_data = battle_get_sc_data(bl);
@@ -9332,7 +9332,7 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
if (sc_data[type].timer != tid)
{
if (battle_config.error_log)
- printf("skill_status_change_timer %d != %d\n", tid,
+ PRINTF("skill_status_change_timer %d != %d\n", tid,
sc_data[type].timer);
}
@@ -9877,7 +9877,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
&& MRAND(10000) < sd->reseff[bsc])
{
if (battle_config.battle_log)
- printf("PC %d skill_sc_start: cardによる異常耐性発動\n",
+ PRINTF("PC %d skill_sc_start: cardによる異常耐性発動\n",
sd->bl.id);
return 0;
}
@@ -9889,7 +9889,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
else
{
if (battle_config.error_log)
- printf("skill_status_change_start: neither MOB nor PC !\n");
+ PRINTF("skill_status_change_start: neither MOB nor PC !\n");
return 0;
}
@@ -10539,7 +10539,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
break;
default:
if (battle_config.error_log)
- printf("UnknownStatusChange [%d]\n", uint16_t(type));
+ PRINTF("UnknownStatusChange [%d]\n", type);
return 0;
}
@@ -10971,7 +10971,7 @@ struct skill_unit_group *skill_initunitgroup(struct block_list *src,
if (group == NULL)
{
- printf("skill_initunitgroup: error unit group !\n");
+ PRINTF("skill_initunitgroup: error unit group !\n");
exit(1);
}
@@ -11613,7 +11613,7 @@ SP scan_stat(char *statname)
if (!strcasecmp(statname, "none"))
return SP::ZERO;
- fprintf(stderr, "Unknown stat `%s'\n", statname);
+ FPRINTF(stderr, "Unknown stat `%s'\n", statname);
return SP::ZERO;
}
@@ -11635,7 +11635,7 @@ int skill_readdb(void)
fp = fopen_("db/skill_db.txt", "r");
if (fp == NULL)
{
- printf("can't read db/skill_db.txt\n");
+ PRINTF("can't read db/skill_db.txt\n");
return 1;
}
while (fgets(line, 1020, fp))
@@ -11654,7 +11654,7 @@ int skill_readdb(void)
}
if (split[17] == NULL || j < 18)
{
- fprintf(stderr, "Incomplete skill db data online (%d entries)\n",
+ FPRINTF(stderr, "Incomplete skill db data online (%d entries)\n",
j);
continue;
}
@@ -11749,12 +11749,12 @@ int skill_readdb(void)
skill_lookup_by_id(i).desc = tmp;
}
fclose_(fp);
- printf("read db/skill_db.txt done\n");
+ PRINTF("read db/skill_db.txt done\n");
fp = fopen_("db/skill_require_db.txt", "r");
if (fp == NULL)
{
- printf("can't read db/skill_require_db.txt\n");
+ PRINTF("can't read db/skill_require_db.txt\n");
return 1;
}
while (fgets(line, 1020, fp))
@@ -11930,13 +11930,13 @@ int skill_readdb(void)
skill_db[i].amount[9] = atoi(split[29]);
}
fclose_(fp);
- printf("read db/skill_require_db.txt done\n");
+ PRINTF("read db/skill_require_db.txt done\n");
/* ? */
fp = fopen_("db/skill_cast_db.txt", "r");
if (fp == NULL)
{
- printf("can't read db/skill_cast_db.txt\n");
+ PRINTF("can't read db/skill_cast_db.txt\n");
return 1;
}
while (fgets(line, 1020, fp))
@@ -12010,12 +12010,12 @@ int skill_readdb(void)
(split2[k]) ? atoi(split2[k]) : atoi(split2[0]);
}
fclose_(fp);
- printf("read db/skill_cast_db.txt done\n");
+ PRINTF("read db/skill_cast_db.txt done\n");
fp = fopen_("db/skill_castnodex_db.txt", "r");
if (fp == NULL)
{
- printf("can't read db/skill_castnodex_db.txt\n");
+ PRINTF("can't read db/skill_castnodex_db.txt\n");
return 1;
}
while (fgets(line, 1020, fp))
@@ -12051,7 +12051,7 @@ int skill_readdb(void)
(split2[k]) ? atoi(split2[k]) : atoi(split2[0]);
}
fclose_(fp);
- printf("read db/skill_castnodex_db.txt done\n");
+ PRINTF("read db/skill_castnodex_db.txt done\n");
return 0;
}
diff --git a/src/map/tmw.cpp b/src/map/tmw.cpp
index 0ddec5b..c08c161 100644
--- a/src/map/tmw.cpp
+++ b/src/map/tmw.cpp
@@ -1,7 +1,6 @@
#include "tmw.hpp"
#include <cctype>
-#include <cstdarg> // exception to "no va_list" rule
#include <cstring>
#include "../common/nullpo.hpp"
@@ -99,21 +98,22 @@ int tmw_CheckChatSpam(struct map_session_data *sd, const char *message)
void tmw_AutoBan(struct map_session_data *sd, const char *reason, int length)
{
- char anotherbuf[512];
-
if (length == 0 || sd->auto_ban_info.in_progress)
return;
sd->auto_ban_info.in_progress = 1;
- tmw_GmHackMsg("%s has been autobanned for %s spam",
- sd->status.name, reason);
+ std::string hack_msg = STRPRINTF("[GM] %s has been autobanned for %s spam",
+ sd->status.name,
+ reason);
+ tmw_GmHackMsg(hack_msg);
- gm_log("%s (%d,%d) Server : @autoban %s %dh (%s spam)",
- map[sd->bl.m].name, sd->bl.x, sd->bl.y,
+ std::string fake_command = STRPRINTF("@autoban %s %dh (%s spam)",
sd->status.name, length, reason);
+ log_atcommand(sd, fake_command);
- snprintf(anotherbuf, 511, "You have been banned for %s spamming. Please do not spam.", reason);
+ std::string anotherbuf = STRPRINTF("You have been banned for %s spamming. Please do not spam.",
+ reason);
clif_displaymessage(sd->fd, anotherbuf);
/* type: 2 - ban(year, month, day, hour, minute, second) */
@@ -145,22 +145,11 @@ int tmw_CheckChatLameness(struct map_session_data *, const char *message)
}
// Sends a whisper to all GMs
-void tmw_GmHackMsg(const char *fmt, ...)
+void tmw_GmHackMsg(const_string line)
{
- char buf[512];
- va_list ap;
-
- va_start(ap, fmt);
- vsnprintf(buf, 511, fmt, ap);
- va_end(ap);
-
- char outbuf[512 + 5];
- strcpy(outbuf, "[GM] ");
- strcat(outbuf, buf);
-
intif_wis_message_to_gm(wisp_server_name,
- battle_config.hack_info_GM_level, outbuf,
- strlen(outbuf) + 1);
+ battle_config.hack_info_GM_level,
+ line.data(), line.size() + 1);
}
/* Remove leading and trailing spaces from a string, modifying in place. */
diff --git a/src/map/tmw.hpp b/src/map/tmw.hpp
index 879d123..a5b198c 100644
--- a/src/map/tmw.hpp
+++ b/src/map/tmw.hpp
@@ -4,8 +4,7 @@
#include "map.hpp"
int tmw_CheckChatSpam(struct map_session_data *sd, const char *message);
-__attribute__((format(printf, 1, 2)))
-void tmw_GmHackMsg(const char *fmt, ...);
+void tmw_GmHackMsg(const_string line);
void tmw_TrimStr(char *str);
#endif // TMW_HPP
diff --git a/src/tool/eathena-monitor.cpp b/src/tool/eathena-monitor.cpp
index ff064c2..b4c89cf 100644
--- a/src/tool/eathena-monitor.cpp
+++ b/src/tool/eathena-monitor.cpp
@@ -19,6 +19,8 @@
#include <cstring>
#include <ctime>
+#include "../common/cxxstdio.hpp"
+
#define HOME getenv("HOME")
#define LOGIN_SERVER "./login-server"
#define MAP_SERVER "./map-server"
@@ -102,7 +104,7 @@ void parse_option(char *name, char *value) {
} else if (!strcasecmp(name, "logfile")) {
logfile = strdup(value);
} else {
- fprintf(stderr, "WARNING: ingnoring invalid option '%s' = '%s'\n", name, value);
+ FPRINTF(stderr, "WARNING: ingnoring invalid option '%s' = '%s'\n", name, value);
}
}
@@ -150,7 +152,7 @@ pid_t start_process(const char *exec) {
const char *args[2] = {exec, NULL};
pid_t pid = fork();
if (pid == -1) {
- fprintf(stderr, "Failed to fork");
+ FPRINTF(stderr, "Failed to fork");
return 0;
}
if (pid == 0) {
@@ -186,18 +188,18 @@ int main(int argc, char *argv[]) {
if (chdir(workdir) < 0) perror("Failed to change directory"), exit(1);
- printf("Starting:\n");
- printf("* workdir: %s\n", workdir);
- printf("* login_server: %s\n", login_server);
- printf("* map_server: %s\n", map_server);
- printf("* char_server: %s\n", char_server);
+ PRINTF("Starting:\n");
+ PRINTF("* workdir: %s\n", workdir);
+ PRINTF("* login_server: %s\n", login_server);
+ PRINTF("* map_server: %s\n", map_server);
+ PRINTF("* char_server: %s\n", char_server);
{
//make sure all possible file descriptors are free for use by the servers
//if there are file descriptors higher than the max open from before the limit dropped, that's not our problem
int fd = sysconf(_SC_OPEN_MAX);
while (--fd > 2)
if (close(fd) == 0)
- fprintf(stderr, "close fd %d\n", fd);
+ FPRINTF(stderr, "close fd %d\n", fd);
fd = open("/dev/null", O_RDWR);
if (fd < 0) perror("open /dev/null"), exit(1);
dup2(fd, 0);
@@ -213,15 +215,15 @@ int main(int argc, char *argv[]) {
if (!pid_login) {
pid_login = start_process(login_server);
- fprintf(stderr, "[%s] forked login server: %lu\n", timestamp, (unsigned long)pid_login);
+ FPRINTF(stderr, "[%s] forked login server: %lu\n", timestamp, (unsigned long)pid_login);
}
if (!pid_char) {
pid_char = start_process(char_server);
- fprintf(stderr, "[%s] forked char server: %lu\n", timestamp, (unsigned long)pid_char);
+ FPRINTF(stderr, "[%s] forked char server: %lu\n", timestamp, (unsigned long)pid_char);
}
if (!pid_map) {
pid_map = start_process(map_server);
- fprintf(stderr, "[%s] forked map server: %lu\n", timestamp, (unsigned long)pid_map);
+ FPRINTF(stderr, "[%s] forked map server: %lu\n", timestamp, (unsigned long)pid_map);
}
pid_t dead = wait(NULL);
if (dead < 0) perror("Failed to wait for child"), exit(1);