summaryrefslogtreecommitdiff
path: root/src/char
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2012-12-16 17:47:51 -0800
committerBen Longbons <b.r.longbons@gmail.com>2012-12-24 10:02:00 -0800
commitb52127bcbf817ff8285b36d22198b275327e16bb (patch)
tree7bc596289c011e719168bef846b8cf63bf5d4947 /src/char
parent4bd7eeec09629d3c0f900d42c899fe23c69e07b6 (diff)
downloadtmwa-b52127bcbf817ff8285b36d22198b275327e16bb.tar.gz
tmwa-b52127bcbf817ff8285b36d22198b275327e16bb.tar.bz2
tmwa-b52127bcbf817ff8285b36d22198b275327e16bb.tar.xz
tmwa-b52127bcbf817ff8285b36d22198b275327e16bb.zip
Cleanup headers and remove all uses of va_list except logging
Diffstat (limited to 'src/char')
-rw-r--r--src/char/char.cpp67
-rw-r--r--src/char/char.hpp5
-rw-r--r--src/char/int_party.cpp60
-rw-r--r--src/char/int_party.hpp3
-rw-r--r--src/char/int_storage.cpp25
-rw-r--r--src/char/int_storage.hpp3
-rw-r--r--src/char/inter.cpp37
-rw-r--r--src/char/inter.hpp3
8 files changed, 98 insertions, 105 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp
index 87e8901..4091b7d 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -1,39 +1,35 @@
-// $Id: char.c,v 1.3 2004/09/13 16:52:16 Yor Exp $
-// original : char2.c 2003/03/14 11:58:35 Rev.1.5
+#include "char.hpp"
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <arpa/inet.h>
#include <netinet/in.h>
-#include <sys/time.h>
-#include <time.h>
#include <sys/ioctl.h>
-#include <unistd.h>
-#include <signal.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
#include <fcntl.h>
-#include <string.h>
-#include <arpa/inet.h>
#include <netdb.h>
-#include <stdarg.h>
-#include <sys/wait.h>
+#include <unistd.h>
+
+#include <cstdarg> // exception to "no va_list" rule
+#include <cstdio>
+#include <cstdlib>
+#include <csignal>
+#include <cstring>
+#include <ctime>
#include "../common/core.hpp"
+#include "../common/lock.hpp"
+#include "../common/mmo.hpp"
#include "../common/socket.hpp"
#include "../common/timer.hpp"
-#include "../common/mmo.hpp"
#include "../common/version.hpp"
-#include "../common/lock.hpp"
-#include "char.hpp"
#include "inter.hpp"
#include "int_party.hpp"
#include "int_storage.hpp"
-#ifdef MEMWATCH
-#include "memwatch.hpp"
-#endif
-
struct mmo_map_server server[MAX_MAP_SERVERS];
int server_fd[MAX_MAP_SERVERS];
int server_freezeflag[MAX_MAP_SERVERS]; // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed
@@ -215,7 +211,6 @@ char *search_character_name(int index)
static
int mmo_char_tostr(char *str, struct mmo_charstatus *p)
{
- int i;
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.
@@ -231,7 +226,7 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p)
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);
- for (i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++)
if (p->memo_point[i].map[0])
{
str_p +=
@@ -240,7 +235,7 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p)
}
*(str_p++) = '\t';
- for (i = 0; i < MAX_INVENTORY; i++)
+ 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 ",
@@ -257,7 +252,7 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p)
}
*(str_p++) = '\t';
- for (i = 0; i < MAX_CART; i++)
+ 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 ",
@@ -280,7 +275,7 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p)
}
*(str_p++) = '\t';
- for (i = 0; i < p->global_reg_num; i++)
+ 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,
@@ -756,7 +751,7 @@ void mmo_char_sync(void)
// Function to save (in a periodic way) datas in files
//----------------------------------------------------
static
-void mmo_char_sync_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void mmo_char_sync_timer(timer_id, tick_t, custom_id_t, custom_data_t)
{
if (pid != 0)
{
@@ -786,7 +781,8 @@ void mmo_char_sync_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_
//----------------------------------------------------
// Remove trailing whitespace from a name
//----------------------------------------------------
-static void remove_trailing_blanks(char *name)
+static
+void remove_trailing_blanks(char *name)
{
char *tail = name + strlen(name) - 1;
@@ -797,7 +793,8 @@ static void remove_trailing_blanks(char *name)
//----------------------------------------------------
// Remove prefix whitespace from a name
//----------------------------------------------------
-static void remove_prefix_blanks(char *name)
+static
+void remove_prefix_blanks(char *name)
{
char *dst = name;
char *src = name;
@@ -1526,7 +1523,8 @@ int count_users(void)
//----------------------------------------
// [Fate] Find inventory item based on equipment mask, return view. ID must match view ID (!).
//----------------------------------------
-static int find_equip_view(struct mmo_charstatus *p, unsigned int equipmask)
+static
+int find_equip_view(struct mmo_charstatus *p, unsigned int equipmask)
{
int i;
for (i = 0; i < MAX_INVENTORY; i++)
@@ -1717,7 +1715,8 @@ int disconnect_player(int accound_id)
}
// キャラ削除に伴うデータ削除
-static int char_delete(struct mmo_charstatus *cs)
+static
+int char_delete(struct mmo_charstatus *cs)
{
// パーティー脱退
if (cs->party_id)
@@ -2234,7 +2233,7 @@ void parse_tologin(int fd)
// Map-server anti-freeze system
//--------------------------------
static
-void map_anti_freeze_system(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void map_anti_freeze_system(timer_id, tick_t, custom_id_t, custom_data_t)
{
int i;
@@ -3473,7 +3472,7 @@ int mapif_send(int fd, const uint8_t *buf, unsigned int len)
}
static
-void send_users_tologin(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void send_users_tologin(timer_id, tick_t, custom_id_t, custom_data_t)
{
int users = count_users();
uint8_t buf[16];
@@ -3492,7 +3491,7 @@ void send_users_tologin(timer_id tid, tick_t tick, custom_id_t id, custom_data_t
}
static
-void check_connect_login_server(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void check_connect_login_server(timer_id, tick_t, custom_id_t, custom_data_t)
{
if (login_fd <= 0 || session[login_fd] == NULL)
{
diff --git a/src/char/char.hpp b/src/char/char.hpp
index 112a5af..2389bd9 100644
--- a/src/char/char.hpp
+++ b/src/char/char.hpp
@@ -1,7 +1,8 @@
-// $Id: char.h,v 1.1.1.1 2004/09/10 17:26:50 MagicalTux Exp $
#ifndef CHAR_HPP
#define CHAR_HPP
+#include "../common/mmo.hpp"
+
#define MAX_MAP_SERVERS 30
#define CHAR_CONF_NAME "conf/char_athena.conf"
@@ -30,4 +31,4 @@ int char_log(const char *fmt, ...);
extern int autosave_interval;
-#endif
+#endif // CHAR_HPP
diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp
index 19c4fbd..4967676 100644
--- a/src/char/int_party.cpp
+++ b/src/char/int_party.cpp
@@ -1,19 +1,23 @@
-// $Id: int_party.c,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
-#include "inter.hpp"
#include "int_party.hpp"
-#include "../common/mmo.hpp"
-#include "char.hpp"
-#include "../common/socket.hpp"
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
#include "../common/db.hpp"
#include "../common/lock.hpp"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "../common/mmo.hpp"
+#include "../common/socket.hpp"
+
+#include "char.hpp"
+#include "inter.hpp"
char party_txt[1024] = "save/party.txt";
-static struct dbt *party_db;
-static int party_newid = 100;
+static
+struct dbt *party_db;
+static
+int party_newid = 100;
int mapif_party_broken(int party_id, int flag);
int party_check_empty(struct party *p);
@@ -134,13 +138,11 @@ int inter_party_init(void)
// パーティーデータのセーブ用
static
-void inter_party_save_sub(db_key_t key, db_val_t data, va_list ap)
+void inter_party_save_sub(db_key_t, db_val_t data, FILE *fp)
{
char line[8192];
- FILE *fp;
inter_party_tostr(line, (struct party *) data);
- fp = va_arg(ap, FILE *);
fprintf(fp, "%s\n", line);
}
@@ -156,7 +158,7 @@ int inter_party_save(void)
party_txt);
return 1;
}
- numdb_foreach(party_db, inter_party_save_sub, fp);
+ numdb_foreach(party_db, std::bind(inter_party_save_sub, ph::_1, ph::_2, fp));
// fprintf(fp, "%d\t%%newid%%\n", party_newid);
lock_fclose(fp, party_txt, &lock);
// printf("int_party: %s saved.\n", party_txt);
@@ -166,13 +168,10 @@ int inter_party_save(void)
// パーティ名検索用
static
-void search_partyname_sub(db_key_t key, db_val_t data, va_list ap)
+void search_partyname_sub(db_key_t, db_val_t data, const char *str, struct party **dst)
{
- struct party *p = (struct party *) data, **dst;
- char *str;
+ struct party *p = (struct party *) data;
- str = va_arg(ap, char *);
- dst = va_arg(ap, struct party **);
if (strcasecmp(p->name, str) == 0)
*dst = p;
}
@@ -182,7 +181,7 @@ static
struct party *search_partyname(const char *str)
{
struct party *p = NULL;
- numdb_foreach(party_db, search_partyname_sub, str, &p);
+ numdb_foreach(party_db, std::bind(search_partyname_sub, ph::_1, ph::_2, str, &p));
return p;
}
@@ -233,15 +232,11 @@ int party_check_empty(struct party *p)
// キャラの競合がないかチェック用
static
-void party_check_conflict_sub(db_key_t key, db_val_t data, va_list ap)
+void party_check_conflict_sub(db_key_t, db_val_t data,
+ int party_id, int account_id, const char *nick)
{
struct party *p = (struct party *) data;
- int party_id, account_id, i;
- char *nick;
-
- party_id = va_arg(ap, int);
- account_id = va_arg(ap, int);
- nick = va_arg(ap, char *);
+ int i;
if (p->party_id == party_id) // 本来の所属なので問題なし
return;
@@ -263,8 +258,9 @@ void party_check_conflict_sub(db_key_t key, db_val_t data, va_list ap)
static
int party_check_conflict(int party_id, int account_id, const char *nick)
{
- numdb_foreach(party_db, party_check_conflict_sub, party_id, account_id,
- nick);
+ numdb_foreach(party_db,
+ std::bind(party_check_conflict_sub, ph::_1, ph::_2,
+ party_id, account_id, nick));
return 0;
}
@@ -551,7 +547,7 @@ int mapif_parse_PartyChangeOption(int fd, int party_id, int account_id,
}
// パーティ脱退要求
-int mapif_parse_PartyLeave(int fd, int party_id, int account_id)
+int mapif_parse_PartyLeave(int, int party_id, int account_id)
{
struct party *p = (struct party *)numdb_search(party_db, party_id);
if (p != NULL)
@@ -623,7 +619,7 @@ int mapif_parse_BreakParty(int fd, int party_id)
// パーティメッセージ送信
static
-int mapif_parse_PartyMessage(int fd, int party_id, int account_id, const char *mes,
+int mapif_parse_PartyMessage(int, int party_id, int account_id, const char *mes,
int len)
{
return mapif_party_message(party_id, account_id, mes, len);
@@ -631,7 +627,7 @@ int mapif_parse_PartyMessage(int fd, int party_id, int account_id, const char *m
// パーティチェック要求
static
-int mapif_parse_PartyCheck(int fd, int party_id, int account_id, const char *nick)
+int mapif_parse_PartyCheck(int, int party_id, int account_id, const char *nick)
{
return party_check_conflict(party_id, account_id, nick);
}
diff --git a/src/char/int_party.hpp b/src/char/int_party.hpp
index 50e6cce..eca5893 100644
--- a/src/char/int_party.hpp
+++ b/src/char/int_party.hpp
@@ -1,4 +1,3 @@
-// $Id: int_party.h,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
#ifndef INT_PARTY_HPP
#define INT_PARTY_HPP
@@ -11,4 +10,4 @@ int inter_party_leave(int party_id, int account_id);
extern char party_txt[1024];
-#endif
+#endif // INT_PARTY_HPP
diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp
index a968c2a..cdc8d69 100644
--- a/src/char/int_storage.cpp
+++ b/src/char/int_storage.cpp
@@ -1,21 +1,22 @@
-// $Id: int_storage.c,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
-
-#include <string.h>
-#include <stdlib.h>
+#include "int_storage.hpp"
-#include "../common/mmo.hpp"
-#include "../common/socket.hpp"
#include "../common/db.hpp"
#include "../common/lock.hpp"
+#include "../common/mmo.hpp"
+#include "../common/socket.hpp"
+
#include "char.hpp"
#include "inter.hpp"
-#include "int_storage.hpp"
+
+#include <cstdlib>
+#include <cstring>
// ファイル名のデフォルト
// inter_config_read()で再設定される
char storage_txt[1024] = "save/storage.txt";
-static struct dbt *storage_db;
+static
+struct dbt *storage_db;
// 倉庫データを文字列に変換
static
@@ -171,7 +172,7 @@ int inter_storage_init(void)
}
static
-void storage_db_final(db_key_t k, db_val_t data, va_list ap)
+void storage_db_final(db_key_t, db_val_t data)
{
struct storage *p = (struct storage *) data;
if (p)
@@ -185,12 +186,10 @@ void inter_storage_final(void)
}
static
-void inter_storage_save_sub(db_key_t key, db_val_t data, va_list ap)
+void inter_storage_save_sub(db_key_t, db_val_t data, FILE *fp)
{
char line[65536];
- FILE *fp;
storage_tostr(line, (struct storage *) data);
- fp = va_arg(ap, FILE *);
if (*line)
fprintf(fp, "%s\n", line);
}
@@ -211,7 +210,7 @@ int inter_storage_save(void)
storage_txt);
return 1;
}
- numdb_foreach(storage_db, inter_storage_save_sub, fp);
+ 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);
return 0;
diff --git a/src/char/int_storage.hpp b/src/char/int_storage.hpp
index 0b22af2..a5e9e0b 100644
--- a/src/char/int_storage.hpp
+++ b/src/char/int_storage.hpp
@@ -1,4 +1,3 @@
-// $Id: int_storage.h,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
#ifndef INT_STORAGE_HPP
#define INT_STORAGE_HPP
@@ -12,4 +11,4 @@ int inter_storage_parse_frommap(int fd);
extern char storage_txt[1024];
-#endif
+#endif // INT_STORAGE_HPP
diff --git a/src/char/inter.cpp b/src/char/inter.cpp
index 14a9561..98ea03c 100644
--- a/src/char/inter.cpp
+++ b/src/char/inter.cpp
@@ -1,16 +1,18 @@
-// $Id: inter.c,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
+#include "inter.hpp"
+
+#include <cstdarg> // exception to "no va_list" rule
+#include <cstdlib>
+#include <cstring>
+
+#include "../common/db.hpp"
+#include "../common/lock.hpp"
#include "../common/mmo.hpp"
-#include "char.hpp"
#include "../common/socket.hpp"
#include "../common/timer.hpp"
-#include "../common/db.hpp"
-#include <string.h>
-#include <stdlib.h>
-#include "inter.hpp"
+#include "char.hpp"
#include "int_party.hpp"
#include "int_storage.hpp"
-#include "../common/lock.hpp"
#define WISDATA_TTL (60*1000) // Existence time of Wisp/page data (60 seconds)
// that is the waiting time of answers of all map-servers
@@ -19,7 +21,8 @@
char inter_log_filename[1024] = "log/inter.log";
char accreg_txt[1024] = "save/accreg.txt";
-static struct dbt *accreg_db = NULL;
+static
+struct dbt *accreg_db = NULL;
struct accreg
{
@@ -61,8 +64,10 @@ struct WisData
unsigned long tick;
unsigned char src[24], dst[24], msg[1024];
};
-static struct dbt *wis_db = NULL;
-static int wis_dellist[WISDELLIST_MAX], wis_delnum;
+static
+struct dbt *wis_db = NULL;
+static
+int wis_dellist[WISDELLIST_MAX], wis_delnum;
//--------------------------------------------------------
@@ -143,16 +148,14 @@ int inter_accreg_init(void)
// アカウント変数のセーブ用
static
-void inter_accreg_save_sub(db_key_t key, db_val_t data, va_list ap)
+void inter_accreg_save_sub(db_key_t, db_val_t data, FILE *fp)
{
char line[8192];
- FILE *fp;
struct accreg *reg = (struct accreg *) data;
if (reg->reg_num > 0)
{
inter_accreg_tostr(line, reg);
- fp = va_arg(ap, FILE *);
fprintf(fp, "%s\n", line);
}
}
@@ -170,7 +173,7 @@ int inter_accreg_save(void)
accreg_txt);
return 1;
}
- numdb_foreach(accreg_db, inter_accreg_save_sub, fp);
+ 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);
@@ -372,11 +375,9 @@ int mapif_account_reg_reply(int fd, int account_id)
// Existence check of WISP data
static
-void check_ttl_wisdata_sub(db_key_t key, db_val_t data, va_list ap)
+void check_ttl_wisdata_sub(db_key_t, db_val_t data, unsigned long tick)
{
- unsigned long tick;
struct WisData *wd = (struct WisData *) data;
- tick = va_arg(ap, unsigned long);
if (DIFF_TICK(tick, wd->tick) > WISDATA_TTL
&& wis_delnum < WISDELLIST_MAX)
@@ -392,7 +393,7 @@ int check_ttl_wisdata(void)
do
{
wis_delnum = 0;
- numdb_foreach(wis_db, check_ttl_wisdata_sub, tick);
+ numdb_foreach(wis_db, std::bind(check_ttl_wisdata_sub, ph::_1, ph::_2, tick));
for (i = 0; i < wis_delnum; i++)
{
struct WisData *wd = (struct WisData *)numdb_search(wis_db, wis_dellist[i]);
diff --git a/src/char/inter.hpp b/src/char/inter.hpp
index 1887ff1..f8cb3da 100644
--- a/src/char/inter.hpp
+++ b/src/char/inter.hpp
@@ -1,4 +1,3 @@
-// $Id: inter.h,v 1.1.1.1 2004/09/10 17:26:51 MagicalTux Exp $
#ifndef INTER_HPP
#define INTER_HPP
@@ -16,4 +15,4 @@ int inter_log(const char *fmt, ...);
extern int party_share_level;
extern char inter_log_filename[1024];
-#endif
+#endif // INTER_HPP