summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/map/atcommand.c8
-rw-r--r--src/map/atcommand.h2
-rw-r--r--src/map/clif.c5
-rw-r--r--src/map/map.c26
-rw-r--r--src/map/map.h3
-rw-r--r--src/map/pc.c52
-rw-r--r--src/map/pc.h2
-rw-r--r--src/map/script.c2
8 files changed, 82 insertions, 18 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 80f0c84f3..459a6a734 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -89,7 +89,7 @@ int lowtohigh_compare (const void * a, const void * b)
//-----------------------------------------------------------
// Return the message string of the specified number by [Yor]
//-----------------------------------------------------------
-char* msg_txt(int msg_number)
+const char* msg_txt(int msg_number)
{
if (msg_number >= 0 && msg_number < MAX_MSG &&
msg_table[msg_number] != NULL && msg_table[msg_number][0] != '\0')
@@ -5753,7 +5753,7 @@ ACMD_FUNC(skilltree)
struct map_session_data *pl_sd = NULL;
int skillnum;
int meets, j, c=0;
- char target[NAME_LENGTH], *tbl;
+ char target[NAME_LENGTH];
struct skill_tree_entry *ent;
nullpo_retr(-1, sd);
@@ -5771,9 +5771,7 @@ ACMD_FUNC(skilltree)
c = pc_calc_skilltree_normalize_job(pl_sd);
c = pc_mapid2jobid(c, pl_sd->status.sex);
- tbl = job_name(c);
-
- sprintf(atcmd_output, "Player is using %s skill tree (%d basic points)", tbl, pc_checkskill(pl_sd, 1));
+ sprintf(atcmd_output, "Player is using %s skill tree (%d basic points)", job_name(c), pc_checkskill(pl_sd, 1));
clif_displaymessage(fd, atcmd_output);
ARR_FIND( 0, MAX_SKILL_TREE, j, skill_tree[c][j].id == 0 || skill_tree[c][j].id == skillnum );
diff --git a/src/map/atcommand.h b/src/map/atcommand.h
index 37ce87ca3..5456bc348 100644
--- a/src/map/atcommand.h
+++ b/src/map/atcommand.h
@@ -41,7 +41,7 @@ int atcommand_killmonster(const int fd, struct map_session_data* sd, const char*
#define MAX_MSG 1000
extern char* msg_table[MAX_MSG];
-char* msg_txt(int msg_number);
+const char* msg_txt(int msg_number);
int msg_config_read(const char* cfgName);
void do_final_msg(void);
diff --git a/src/map/clif.c b/src/map/clif.c
index a1b617b83..eeb9f7532 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -9692,7 +9692,8 @@ void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
//0:
static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
{
- char *msg, output[256];
+ const char* msg;
+ char output[256];
// Your request has been rejected by autoreject option.
msg = msg_txt(392);
clif_disp_onlyself(src, msg, strlen(msg));
@@ -15029,7 +15030,7 @@ static int packetdb_readdb(void)
0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
//#0x0840
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
diff --git a/src/map/map.c b/src/map/map.c
index 12c805ef3..762cf1446 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1659,8 +1659,30 @@ struct mob_data * map_id2md(int id)
struct npc_data * map_id2nd(int id)
{// just a id2bl lookup because there's no npc_db
- if (id <= 0) return NULL;
- return (struct npc_data*)map_id2bl(id);
+ struct block_list* bl = map_id2bl(id);
+
+ return BL_CAST(BL_NPC, bl);
+}
+
+struct homun_data* map_id2hd(int id)
+{
+ struct block_list* bl = map_id2bl(id);
+
+ return BL_CAST(BL_HOM, bl);
+}
+
+struct mercenary_data* map_id2mc(int id)
+{
+ struct block_list* bl = map_id2bl(id);
+
+ return BL_CAST(BL_MER, bl);
+}
+
+struct chat_data* map_id2cd(int id)
+{
+ struct block_list* bl = map_id2bl(id);
+
+ return BL_CAST(BL_CHAT, bl);
}
/// Returns the nick of the target charid or NULL if unknown (requests the nick to the char server).
diff --git a/src/map/map.h b/src/map/map.h
index 8e0c11a03..456384360 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -584,6 +584,9 @@ struct map_session_data* map_charid2sd(int charid);
struct map_session_data * map_id2sd(int id);
struct mob_data * map_id2md(int id);
struct npc_data * map_id2nd(int id);
+struct homun_data* map_id2hd(int id);
+struct mercenary_data* map_id2mc(int id);
+struct chat_data* map_id2cd(int id);
struct block_list * map_id2bl(int id);
#define map_id2index(id) map[(id)].index
diff --git a/src/map/pc.c b/src/map/pc.c
index db42fdeca..4371b1276 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -3263,11 +3263,31 @@ int pc_payzeny(struct map_session_data *sd,int zeny)
void pc_paycash(struct map_session_data *sd, int price, int points)
{
char output[128];
- int cash = price - points;
+ int cash;
nullpo_retv(sd);
- pc_setaccountreg(sd,"#CASHPOINTS",sd->cashPoints - cash);
- pc_setaccountreg(sd,"#KAFRAPOINTS",sd->kafraPoints - points);
+ if( price < 0 || points < 0 )
+ {
+ ShowError("pc_paycash: Paying negative points (price=%d, points=%d, account_id=%d, char_id=%d).\n", price, points, sd->status.account_id, sd->status.char_id);
+ return;
+ }
+
+ if( points > price )
+ {
+ ShowWarning("pc_paycash: More kafra points provided than needed (price=%d, points=%d, account_id=%d, char_id=%d).\n", price, points, sd->status.account_id, sd->status.char_id);
+ points = price;
+ }
+
+ cash = price-points;
+
+ if( sd->cashPoints < cash || sd->kafraPoints < points )
+ {
+ ShowError("pc_paycash: Not enough points (cash=%d, kafra=%d) to cover the price (cash=%d, kafra=%d) (account_id=%d, char_id=%d).\n", sd->cashPoints, sd->kafraPoints, cash, points, sd->status.account_id, sd->status.char_id);
+ return;
+ }
+
+ pc_setaccountreg(sd, "#CASHPOINTS", sd->cashPoints-cash);
+ pc_setaccountreg(sd, "#KAFRAPOINTS", sd->kafraPoints-points);
if( battle_config.cashshop_show_points )
{
@@ -3283,7 +3303,13 @@ void pc_getcash(struct map_session_data *sd, int cash, int points)
if( cash > 0 )
{
- pc_setaccountreg(sd,"#CASHPOINTS",sd->cashPoints + cash);
+ if( cash > MAX_ZENY-sd->cashPoints )
+ {
+ ShowWarning("pc_getcash: Cash point overflow (cash=%d, have cash=%d, account_id=%d, char_id=%d).\n", cash, sd->cashPoints, sd->status.account_id, sd->status.char_id);
+ cash = MAX_ZENY-sd->cashPoints;
+ }
+
+ pc_setaccountreg(sd, "#CASHPOINTS", sd->cashPoints+cash);
if( battle_config.cashshop_show_points )
{
@@ -3291,10 +3317,20 @@ void pc_getcash(struct map_session_data *sd, int cash, int points)
clif_disp_onlyself(sd, output, strlen(output));
}
}
+ else if( cash < 0 )
+ {
+ ShowError("pc_getcash: Obtaining negative cash points (cash=%d, account_id=%d, char_id=%d).\n", cash, sd->status.account_id, sd->status.char_id);
+ }
if( points > 0 )
{
- pc_setaccountreg(sd,"#KAFRAPOINTS",sd->kafraPoints + points);
+ if( points > MAX_ZENY-sd->kafraPoints )
+ {
+ ShowWarning("pc_getcash: Kafra point overflow (points=%d, have points=%d, account_id=%d, char_id=%d).\n", points, sd->kafraPoints, sd->status.account_id, sd->status.char_id);
+ points = MAX_ZENY-sd->kafraPoints;
+ }
+
+ pc_setaccountreg(sd, "#KAFRAPOINTS", sd->kafraPoints+points);
if( battle_config.cashshop_show_points )
{
@@ -3302,6 +3338,10 @@ void pc_getcash(struct map_session_data *sd, int cash, int points)
clif_disp_onlyself(sd, output, strlen(output));
}
}
+ else if( points < 0 )
+ {
+ ShowError("pc_getcash: Obtaining negative kafra points (points=%d, account_id=%d, char_id=%d).\n", points, sd->status.account_id, sd->status.char_id);
+ }
}
/*==========================================
@@ -4608,7 +4648,7 @@ int pc_mapid2jobid(unsigned short class_, int sex)
/*====================================================
* This function return the name of the job (by [Yor])
*----------------------------------------------------*/
-char* job_name(int class_)
+const char* job_name(int class_)
{
switch (class_) {
case JOB_NOVICE:
diff --git a/src/map/pc.h b/src/map/pc.h
index 0473df3a9..beae8a0a3 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -727,7 +727,7 @@ int pc_candrop(struct map_session_data *sd,struct item *item);
int pc_jobid2mapid(unsigned short b_class); // Skotlex
int pc_mapid2jobid(unsigned short class_, int sex); // Skotlex
-char * job_name(int class_);
+const char * job_name(int class_);
struct skill_tree_entry {
short id;
diff --git a/src/map/script.c b/src/map/script.c
index 6b1366f07..39daede0e 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -4780,7 +4780,7 @@ BUILDIN_FUNC(jobchange)
BUILDIN_FUNC(jobname)
{
int class_=script_getnum(st,2);
- script_pushconststr(st,job_name(class_));
+ script_pushconststr(st, (char*)job_name(class_));
return 0;
}