From 4e89085e113c63de223cbcfe78cbff1b60f95199 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Tue, 27 Aug 2013 19:36:36 -0700 Subject: Fix bug with mapnames being falsy Fixes #7 --- src/char/char.cpp | 13 +++++++------ src/common/mmo.hpp | 2 +- src/common/strings.hpp | 4 ++++ src/login/login.cpp | 4 ++-- src/map/chrif.cpp | 2 +- src/map/mob.cpp | 2 +- src/map/pc.cpp | 2 +- 7 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/char/char.cpp b/src/char/char.cpp index fb1ca7d..ab68322 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -256,8 +256,9 @@ FString mmo_char_tostr(struct mmo_charstatus *p) 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]) + if (p->memo_point[i].map_) { str_p += STRPRINTF("%s,%d,%d ", p->memo_point[i].map_, p->memo_point[i].x, p->memo_point[i].y); @@ -312,7 +313,7 @@ FString mmo_char_tostr(struct mmo_charstatus *p) str_p += '\t'; for (int i = 0; i < p->global_reg_num; i++) - if (p->global_reg[i].str[0]) + if (p->global_reg[i].str) str_p += STRPRINTF("%s,%d ", p->global_reg[i].str, p->global_reg[i].value); @@ -1118,7 +1119,7 @@ void parse_tologin(int fd) // if no map-server already connected, display a message... int i; for (i = 0; i < MAX_MAP_SERVERS; i++) - if (server_fd[i] >= 0 && server[i].maps[0][0]) // if map-server online and at least 1 map + if (server_fd[i] >= 0 && server[i].maps[0]) // if map-server online and at least 1 map break; if (i == MAX_MAP_SERVERS) PRINTF("Awaiting maps from map-server.\n"); @@ -1603,7 +1604,7 @@ void parse_frommap(int fd) WFIFOW(fd, 8) = server[x].port; j = 0; for (int i = 0; i < MAX_MAP_PER_SERVER; i++) - if (server[x].maps[i][0]) + if (server[x].maps[i]) WFIFO_STRING(fd, 10 + (j++) * 16, server[x].maps[i], 16); if (j > 0) { @@ -2026,7 +2027,7 @@ int search_mapserver(XString map) { for (int i = 0; i < MAX_MAP_SERVERS; i++) if (server_fd[i] >= 0) - for (int j = 0; server[i].maps[j][0]; j++) + for (int j = 0; server[i].maps[j]; j++) if (server[i].maps[j] == map) return i; @@ -2089,7 +2090,7 @@ void handle_x0066(int fd, struct char_session_data *sd, uint8_t rfifob_2, uint8_ i = 0; for (j = 0; j < MAX_MAP_SERVERS; j++) if (server_fd[j] >= 0 - && server[j].maps[0][0]) + && server[j].maps[0]) { // change save point to one of map found on the server (the first) i = j; cd->last_point.map_ = server[j].maps[0]; diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp index 89ff50a..0d3403c 100644 --- a/src/common/mmo.hpp +++ b/src/common/mmo.hpp @@ -65,7 +65,7 @@ public: MapName(VString<15> v) : _impl(v.oislice_h(std::find(v.begin(), v.end(), '.'))) {} iterator begin() const { return &*_impl.begin(); } - iterator end() const { return &*_impl.begin(); } + iterator end() const { return &*_impl.end(); } const char *c_str() const { return _impl.c_str(); } operator FString() const { return _impl; } diff --git a/src/common/strings.hpp b/src/common/strings.hpp index ead3f52..0b10570 100644 --- a/src/common/strings.hpp +++ b/src/common/strings.hpp @@ -119,6 +119,10 @@ namespace strings operator bool() const { return size(); } bool operator !() const { return !size(); } + // the existence of this has led to bugs + // it's not really sane from a unicode perspective anyway ... + // prefer startswith or extract + __attribute__((deprecated)) char operator[](size_t i) const { return begin()[i]; } char front() const { return *begin(); } char back() const { return end()[-1]; } diff --git a/src/login/login.cpp b/src/login/login.cpp index e09f96b..b0b3137 100644 --- a/src/login/login.cpp +++ b/src/login/login.cpp @@ -501,7 +501,7 @@ FString mmo_auth_tostr(const AuthData *p) p->ban_until_time); for (int i = 0; i < p->account_reg2_num; i++) - if (p->account_reg2[i].str[0]) + if (p->account_reg2[i].str) str += STRPRINTF("%s,%d ", p->account_reg2[i].str, p->account_reg2[i].value); @@ -541,7 +541,7 @@ bool extract(XString line, AuthData *ad) } // 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] == '-') + if (!ad->pass.startswith('!') && ad->memo.startswith('-')) { XString pass = ad->pass; AccountPass plain = stringish(pass); diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 126235c..33a9879 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -674,7 +674,7 @@ int chrif_saveaccountreg2(dumb_ptr sd) for (j = 0; j < sd->status.account_reg2_num; j++) { struct global_reg *reg = &sd->status.account_reg2[j]; - if (reg->str[0] && reg->value != 0) + if (reg->str && reg->value != 0) { WFIFO_STRING(char_fd, p, reg->str, 32); WFIFOL(char_fd, p + 32) = reg->value; diff --git a/src/map/mob.cpp b/src/map/mob.cpp index ebd336f..cd548a4 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -76,7 +76,7 @@ int mobdb_searchname(MobName str) int mobdb_checkid(const int id) { if (id <= 0 || id >= (sizeof(mob_db) / sizeof(mob_db[0])) - || mob_db[id].name[0] == '\0') + || !mob_db[id].name) return 0; return id; diff --git a/src/map/pc.cpp b/src/map/pc.cpp index b683474..e34f765 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -2354,7 +2354,7 @@ int pc_setpos(dumb_ptr sd, while (bool(read_gatp(m, x, y) & MapCell::UNWALKABLE)); } - if (sd->mapname_[0] && sd->bl_prev != NULL) + if (sd->mapname_ && sd->bl_prev != NULL) { clif_clearchar(sd, clrtype); map_delblock(sd); -- cgit v1.2.3-60-g2f50