summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-02-15 20:18:11 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-02-15 20:18:11 +0000
commit8f4bff4143898963b1210ffa2d3300020df04c4e (patch)
tree1195d8b6ebbcf50ae90be7b61e21b6ae9f26dd9a /src
parentea2ae867ed32cdea9107b446ee7cdfe3a2be6d95 (diff)
downloadhercules-8f4bff4143898963b1210ffa2d3300020df04c4e.tar.gz
hercules-8f4bff4143898963b1210ffa2d3300020df04c4e.tar.bz2
hercules-8f4bff4143898963b1210ffa2d3300020df04c4e.tar.xz
hercules-8f4bff4143898963b1210ffa2d3300020df04c4e.zip
- Fixed the char servers to store correctly exp as uints. They are also capped to LONG_MAX before being sent to the client.
- TK_DODGE now dodges all ranged attacks, when used with SPURT, dodges everything. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@5289 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c36
-rw-r--r--src/char_sql/char.c28
-rw-r--r--src/map/battle.c2
3 files changed, 37 insertions, 29 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 3cc5fc69b..1cedc568c 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -23,6 +23,7 @@ typedef long in_addr_t;
#include <fcntl.h>
#include <string.h>
#include <stdarg.h>
+#include <limits.h>
#include "../common/strlib.h"
#include "../common/core.h"
@@ -360,7 +361,7 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p, struct global_reg *reg,
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"
+ str_p += sprintf(str_p, "%d\t%d,%d\t%s\t%d,%d,%d\t%u,%u,%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,%d,%d,%d,%d\t",
p->char_id, p->account_id, p->char_num, p->name, //
@@ -425,18 +426,19 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p, struct global_reg *reg,
int mmo_char_fromstr(char *str, struct mmo_charstatus *p, struct global_reg *reg, int *reg_num) {
char tmp_str[3][128]; //To avoid deleting chars with too long names.
int tmp_int[256];
+ unsigned int tmp_uint[2]; //To read exp....
int set, next, len, i, j;
// initilialise character
memset(p, '\0', sizeof(struct mmo_charstatus));
// If it's not char structure of version 1488 and after
- if ((set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d"
+ if ((set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%u,%u,%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%127[^,],%d,%d\t%127[^,],%d,%d,%d,%d,%d,%d,%d%n",
&tmp_int[0], &tmp_int[1], &tmp_int[2], tmp_str[0],
&tmp_int[3], &tmp_int[4], &tmp_int[5],
- &tmp_int[6], &tmp_int[7], &tmp_int[8],
+ &tmp_uint[0], &tmp_uint[1], &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],
@@ -450,12 +452,12 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p, struct global_reg *reg
{
tmp_int[43] = 0;
// If it's not char structure of version 1363 and after
- if ((set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d"
+ if ((set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%u,%u,%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%127[^,],%d,%d\t%127[^,],%d,%d,%d,%d,%d,%d%n",
&tmp_int[0], &tmp_int[1], &tmp_int[2], tmp_str[0], //
&tmp_int[3], &tmp_int[4], &tmp_int[5],
- &tmp_int[6], &tmp_int[7], &tmp_int[8],
+ &tmp_uint[0], &tmp_uint[1], &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],
@@ -471,12 +473,12 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p, struct global_reg *reg
tmp_int[41] = 0; // mother
tmp_int[42] = 0; // child
// If it's not char structure of version 1008 and before 1363
- if ((set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d"
+ if ((set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%u,%u,%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%127[^,],%d,%d\t%127[^,],%d,%d,%d%n",
&tmp_int[0], &tmp_int[1], &tmp_int[2], tmp_str[0], //
&tmp_int[3], &tmp_int[4], &tmp_int[5],
- &tmp_int[6], &tmp_int[7], &tmp_int[8],
+ &tmp_uint[0], &tmp_uint[1], &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],
@@ -489,12 +491,12 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p, struct global_reg *reg
{
tmp_int[39] = 0; // partner id
// If not char structure from version 384 to 1007
- if ((set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d"
+ if ((set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%u,%u,%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%127[^,],%d,%d\t%127[^,],%d,%d%n",
&tmp_int[0], &tmp_int[1], &tmp_int[2], tmp_str[0], //
&tmp_int[3], &tmp_int[4], &tmp_int[5],
- &tmp_int[6], &tmp_int[7], &tmp_int[8],
+ &tmp_uint[0], &tmp_uint[1], &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],
@@ -507,12 +509,12 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p, struct global_reg *reg
{
// It's char structure of a version before 384
tmp_int[26] = 0; // pet id
- set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d"
+ set = sscanf(str, "%d\t%d,%d\t%127[^\t]\t%d,%d,%d\t%u,%u,%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%127[^,],%d,%d\t%127[^,],%d,%d%n",
&tmp_int[0], &tmp_int[1], &tmp_int[2], tmp_str[0], //
&tmp_int[3], &tmp_int[4], &tmp_int[5],
- &tmp_int[6], &tmp_int[7], &tmp_int[8],
+ &tmp_uint[0], &tmp_uint[1], &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],
@@ -553,8 +555,8 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p, struct global_reg *reg
p->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->base_exp = tmp_uint[0];
+ p->job_exp = tmp_uint[1];
p->zeny = tmp_int[8];
p->hp = tmp_int[9];
p->max_hp = tmp_int[10];
@@ -1611,9 +1613,9 @@ int mmo_char_send006b(int fd, struct char_session_data *sd) {
j = offset + (i * 106); // increase speed of code
WFIFOL(fd,j) = p->char_id;
- WFIFOL(fd,j+4) = p->base_exp;
+ WFIFOL(fd,j+4) = p->base_exp>LONG_MAX?LONG_MAX:p->base_exp;
WFIFOL(fd,j+8) = p->zeny;
- WFIFOL(fd,j+12) = p->job_exp;
+ WFIFOL(fd,j+12) = p->job_exp>LONG_MAX?LONG_MAX:p->job_exp;
WFIFOL(fd,j+16) = p->job_level;
WFIFOL(fd,j+20) = 0;
@@ -3355,9 +3357,9 @@ int parse_char(int fd) {
memset(WFIFOP(fd,2), 0, 106);
WFIFOL(fd,2) = char_dat[i].status.char_id;
- WFIFOL(fd,2+4) = char_dat[i].status.base_exp;
+ WFIFOL(fd,2+4) = char_dat[i].status.base_exp>LONG_MAX?LONG_MAX:char_dat[i].status.base_exp;
WFIFOL(fd,2+8) = char_dat[i].status.zeny;
- WFIFOL(fd,2+12) = char_dat[i].status.job_exp;
+ WFIFOL(fd,2+12) = char_dat[i].status.job_exp>LONG_MAX?LONG_MAX:char_dat[i].status.job_exp;
WFIFOL(fd,2+16) = char_dat[i].status.job_level;
WFIFOL(fd,2+28) = char_dat[i].status.karma;
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index b8c467fb3..0d5f6eca8 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -27,6 +27,7 @@ typedef long in_addr_t;
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <limits.h>
#include "char.h"
#include "../common/utils.h"
@@ -463,7 +464,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){
//query
sprintf(tmp_sql ,"UPDATE `%s` SET `base_level`='%d', `job_level`='%d',"
- "`base_exp`='%d', `job_exp`='%d', `zeny`='%d',"
+ "`base_exp`='%u', `job_exp`='%u', `zeny`='%d',"
"`max_hp`='%d',`hp`='%d',`max_sp`='%d',`sp`='%d',`status_point`='%d',`skill_point`='%d',"
"`str`='%d',`agi`='%d',`vit`='%d',`int`='%d',`dex`='%d',`luk`='%d',"
"`option`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d',"
@@ -862,6 +863,7 @@ int memitemdata_to_sql(struct itemtmp mapitem[], int count, int char_id, int tab
//=====================================================================================================
int mmo_char_fromsql(int char_id, struct mmo_charstatus *p){
int i,j, n;
+ double exp;
char t_msg[128];
char *str_p = tmp_sql;
struct mmo_charstatus *cp;
@@ -905,8 +907,10 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus *p){
p->class_ = atoi(sql_row[4]);
p->base_level = atoi(sql_row[5]);
p->job_level = atoi(sql_row[6]);
- p->base_exp = atoi(sql_row[7]);
- p->job_exp = atoi(sql_row[8]);
+ exp = atof(sql_row[7]);
+ p->base_exp = exp<0?0:(exp>UINT_MAX?UINT_MAX:(unsigned int)exp);
+ exp = atof(sql_row[8]);
+ p->job_exp = exp<0?0:(exp>UINT_MAX?UINT_MAX:(unsigned int)exp);
p->zeny = atoi(sql_row[9]);
p->str = atoi(sql_row[10]);
p->agi = atoi(sql_row[11]);
@@ -1118,7 +1122,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus *p){
//
int mmo_char_fromsql_short(int char_id, struct mmo_charstatus *p){
char t_msg[128];
-
+ double exp;
memset(p, 0, sizeof(struct mmo_charstatus));
t_msg[0]= '\0';
@@ -1156,8 +1160,10 @@ int mmo_char_fromsql_short(int char_id, struct mmo_charstatus *p){
p->class_ = atoi(sql_row[4]);
p->base_level = atoi(sql_row[5]);
p->job_level = atoi(sql_row[6]);
- p->base_exp = atoi(sql_row[7]);
- p->job_exp = atoi(sql_row[8]);
+ exp = atof(sql_row[7]);
+ p->base_exp = exp<0?0:(exp>UINT_MAX?UINT_MAX:(unsigned int)exp);
+ exp = atof(sql_row[8]);
+ p->job_exp = exp<0?0:(exp>UINT_MAX?UINT_MAX:(unsigned int)exp);
p->zeny = atoi(sql_row[9]);
p->str = atoi(sql_row[10]);
p->agi = atoi(sql_row[11]);
@@ -1796,9 +1802,9 @@ int mmo_char_send006b(int fd, struct char_session_data *sd) {
j = offset + (i * 106); // increase speed of code
WFIFOL(fd,j) = p->char_id;
- WFIFOL(fd,j+4) = p->base_exp;
+ WFIFOL(fd,j+4) = p->base_exp>LONG_MAX?LONG_MAX:p->base_exp;
WFIFOL(fd,j+8) = p->zeny;
- WFIFOL(fd,j+12) = p->job_exp;
+ WFIFOL(fd,j+12) = p->job_exp>LONG_MAX?LONG_MAX:p->job_exp;
WFIFOL(fd,j+16) = p->job_level;
WFIFOL(fd,j+20) = 0;
@@ -3324,15 +3330,15 @@ int parse_char(int fd) {
//mmo_char_fromsql(i, char_dat);
i = 0;
WFIFOL(fd, 2) = char_dat[i].char_id;
- WFIFOL(fd,2+4) = char_dat[i].base_exp;
+ WFIFOL(fd,2+4) = char_dat[i].base_exp>LONG_MAX?LONG_MAX:char_dat[i].base_exp;
WFIFOL(fd,2+8) = char_dat[i].zeny;
- WFIFOL(fd,2+12) = char_dat[i].job_exp;
+ WFIFOL(fd,2+12) = char_dat[i].job_exp>LONG_MAX?LONG_MAX:char_dat[i].job_exp;
WFIFOL(fd,2+16) = char_dat[i].job_level;
WFIFOL(fd,2+28) = char_dat[i].karma;
WFIFOL(fd,2+32) = char_dat[i].manner;
- WFIFOW(fd,2+40) = 0x30;
+ WFIFOW(fd,2+40) = 0x30;
WFIFOW(fd,2+42) = (char_dat[i].hp > 0x7fff) ? 0x7fff : char_dat[i].hp;
WFIFOW(fd,2+44) = (char_dat[i].max_hp > 0x7fff) ? 0x7fff : char_dat[i].max_hp;
WFIFOW(fd,2+46) = (char_dat[i].sp > 0x7fff) ? 0x7fff : char_dat[i].sp;
diff --git a/src/map/battle.c b/src/map/battle.c
index a0a6d932d..e5f591649 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -610,7 +610,7 @@ int battle_calc_damage(struct block_list *src,struct block_list *bl,int damage,i
}
if(sc->data[SC_DODGE].timer != -1 && !sc->opt1 &&
- ((flag&BF_LONG && flag&BF_WEAPON) || sc->data[SC_SPURT].timer != -1)
+ (flag&BF_LONG || sc->data[SC_SPURT].timer != -1)
&& rand()%100 < 20) {
if (sd && pc_issit(sd)) pc_setstand(sd); //Stand it to dodge.
clif_skill_nodamage(bl,bl,TK_DODGE,1,1);