summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-08-04 16:24:49 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-08-04 16:24:49 +0000
commita8952b3c7b1067f304e24237bd035263e6b62ed9 (patch)
tree5b9bbc59f59f38101e2bcd7a7d10cbd89a4e81ed /src
parent65ee11a599f904bdece45c55dd41eb2633da575f (diff)
downloadhercules-a8952b3c7b1067f304e24237bd035263e6b62ed9.tar.gz
hercules-a8952b3c7b1067f304e24237bd035263e6b62ed9.tar.bz2
hercules-a8952b3c7b1067f304e24237bd035263e6b62ed9.tar.xz
hercules-a8952b3c7b1067f304e24237bd035263e6b62ed9.zip
Some all-around code reformatting/cleaning
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10947 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/common/utils.c39
-rw-r--r--src/common/utils.h8
-rw-r--r--src/map/battle.c48
-rw-r--r--src/map/clif.c270
-rw-r--r--src/map/clif.h12
-rw-r--r--src/map/status.c171
-rw-r--r--src/map/unit.c28
7 files changed, 232 insertions, 344 deletions
diff --git a/src/common/utils.c b/src/common/utils.c
index 00b6dc290..15d1d2e68 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -20,41 +20,40 @@
#include <sys/stat.h>
#endif
-#ifdef UTIL_DUMP
-void dump(const unsigned char* buffer, int num)
+// generate a hex dump of the first 'length' bytes of 'buffer'
+void dump(FILE* fp, const unsigned char* buffer, int length)
{
- int icnt, jcnt;
+ int i, j;
- printf(" Hex ASCII\n");
- printf(" ----------------------------------------------- ----------------");
+ fprintf(fp, " Hex ASCII\n");
+ fprintf(fp, " ----------------------------------------------- ----------------");
- for (icnt = 0; icnt < num; icnt += 16)
+ for (i = 0; i < length; i += 16)
{
- printf("\n%p ", &buffer[icnt]);
- for (jcnt = icnt; jcnt < icnt + 16; ++jcnt)
+ fprintf(fp, "\n%p ", &buffer[i]);
+ for (j = i; j < i + 16; ++j)
{
- if (jcnt < num)
- printf("%02hX ", buffer[jcnt]);
+ if (j < length)
+ fprintf(fp, "%02hX ", buffer[j]);
else
- printf(" ");
+ fprintf(fp, " ");
}
- printf(" | ");
+ fprintf(fp, " | ");
- for (jcnt = icnt; jcnt < icnt + 16; ++jcnt)
+ for (j = i; j < i + 16; ++j)
{
- if (jcnt < num) {
- if (buffer[jcnt] > 31 && buffer[jcnt] < 127)
- printf("%c", buffer[jcnt]);
+ if (j < length) {
+ if (buffer[j] > 31 && buffer[j] < 127)
+ fprintf(fp, "%c", buffer[j]);
else
- printf(".");
+ fprintf(fp, ".");
} else
- printf(" ");
+ fprintf(fp, " ");
}
}
- printf("\n");
+ fprintf(fp, "\n");
}
-#endif
// Allocate a StringBuf [MouseJstr]
struct StringBuf * StringBuf_Malloc()
diff --git a/src/common/utils.h b/src/common/utils.h
index 66ce04c99..898a63ab4 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -4,13 +4,11 @@
#ifndef _UTILS_H_
#define _UTILS_H_
+#include <stdio.h>
#include <stdarg.h>
-// Function that dumps the hex of the first num bytes of the buffer to the screen
-//#define UTIL_DUMP
-#ifdef UTIL_DUMP
-void dump(const unsigned char* buffer, int num);
-#endif
+// generate a hex dump of the first 'length' bytes of 'buffer'
+void dump(FILE* fp, const unsigned char* buffer, int length);
struct StringBuf {
char *buf_;
diff --git a/src/map/battle.c b/src/map/battle.c
index fa197563f..2b62f23b7 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -1,11 +1,6 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
#include "../common/cbasetypes.h"
#include "../common/timer.h"
#include "../common/nullpo.h"
@@ -26,6 +21,11 @@
#include "party.h"
#include "battle.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
int attr_fix_table[4][ELE_MAX][ELE_MAX];
struct Battle_Config battle_config;
@@ -87,18 +87,14 @@ struct block_list* battle_gettargeted(struct block_list *target)
//Returns the id of the current targetted character of the passed bl. [Skotlex]
-int battle_gettarget(struct block_list *bl)
+int battle_gettarget(struct block_list* bl)
{
switch (bl->type)
{
- case BL_PC:
- return ((struct map_session_data*)bl)->ud.target;
- case BL_MOB:
- return ((struct mob_data*)bl)->target_id;
- case BL_PET:
- return ((struct pet_data*)bl)->target_id;
- case BL_HOM:
- return ((struct homun_data*)bl)->ud.target;
+ case BL_PC: return ((struct map_session_data*)bl)->ud.target;
+ case BL_MOB: return ((struct mob_data*)bl)->target_id;
+ case BL_PET: return ((struct pet_data*)bl)->target_id;
+ case BL_HOM: return ((struct homun_data*)bl)->ud.target;
}
return 0;
}
@@ -2645,16 +2641,10 @@ struct Damage battle_calc_misc_attack(
struct Damage battle_calc_attack(int attack_type,struct block_list *bl,struct block_list *target,int skill_num,int skill_lv,int flag)
{
struct Damage d;
- switch(attack_type){
- case BF_WEAPON:
- d = battle_calc_weapon_attack(bl,target,skill_num,skill_lv,flag);
- break;
- case BF_MAGIC:
- d = battle_calc_magic_attack(bl,target,skill_num,skill_lv,flag);
- break;
- case BF_MISC:
- d = battle_calc_misc_attack(bl,target,skill_num,skill_lv,flag);
- break;
+ switch(attack_type) {
+ case BF_WEAPON: d = battle_calc_weapon_attack(bl,target,skill_num,skill_lv,flag); break;
+ case BF_MAGIC: d = battle_calc_magic_attack(bl,target,skill_num,skill_lv,flag); break;
+ case BF_MISC: d = battle_calc_misc_attack(bl,target,skill_num,skill_lv,flag); break;
default:
if (battle_config.error_log)
ShowError("battle_calc_attack: unknown attack type! %d\n",attack_type);
@@ -2671,9 +2661,10 @@ struct Damage battle_calc_attack(int attack_type,struct block_list *bl,struct bl
return d;
}
-int battle_calc_return_damage(struct block_list *bl, int *damage, int flag) {
- struct map_session_data *sd=NULL;
- struct status_change *sc;
+int battle_calc_return_damage(struct block_list* bl, int* damage, int flag)
+{
+ struct map_session_data* sd = NULL;
+ struct status_change* sc;
int rdamage = 0;
BL_CAST(BL_PC, bl, sd);
@@ -2703,8 +2694,7 @@ int battle_calc_return_damage(struct block_list *bl, int *damage, int flag) {
// magic_damage_return by [AppleGirl] and [Valaris]
if(flag&BF_MAGIC)
{
- if(sd && sd->magic_damage_return &&
- rand()%100 < sd->magic_damage_return)
+ if(sd && sd->magic_damage_return && rand()%100 < sd->magic_damage_return)
{ //Bounces back full damage, you take none.
rdamage = *damage;
*damage = 0;
diff --git a/src/map/clif.c b/src/map/clif.c
index 216116bbd..54632a3b5 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -1,9 +1,6 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#define DUMP_UNKNOWN_PACKET 0
-#define DUMP_ALL_PACKETS 0
-
#include "../common/cbasetypes.h"
#include "../common/socket.h"
#include "../common/timer.h"
@@ -45,6 +42,8 @@
#include <stdarg.h>
#include <time.h>
+#define DUMP_UNKNOWN_PACKET 0
+
struct Clif_Config {
int packet_db_ver; //Preferred packet version.
int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
@@ -3805,9 +3804,20 @@ static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int da
}
/*==========================================
- * 通常攻撃エフェクト&ダメージ
- *------------------------------------------*/
-int clif_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int type,int damage2)
+ * Sends a 'damage' packet (src performs action on dst)
+ * R 008a <src ID>.l <dst ID>.l <server tick>.l <src speed>.l <dst speed>.l <param1>.w <param2>.w <type>.B <param3>.w
+ *
+ * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
+ * type=01 pick up item
+ * type=02 sit down
+ * type=03 stand up
+ * type=04 reflected/absorbed damage?
+ * type=08 double attack
+ * type=09 don't display flinch animation (endure)
+ * type=0a critical hit
+ * type=0b lucky dodge
+ *------------------------------------------*/
+int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int damage, int div, int type, int damage2)
{
unsigned char buf[256];
struct status_change *sc;
@@ -3818,13 +3828,10 @@ int clif_damage(struct block_list *src,struct block_list *dst,unsigned int tick,
type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
sc = status_get_sc(dst);
-
if(sc && sc->count) {
if(sc->data[SC_HALLUCINATION].timer != -1) {
- if(damage > 0)
- damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
- if(damage2 > 0)
- damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
+ if(damage > 0) damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
+ if(damage2 > 0) damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
}
}
@@ -3846,22 +3853,17 @@ int clif_damage(struct block_list *src,struct block_list *dst,unsigned int tick,
clif_send(buf,packet_len(0x8a),src,AREA);
if(disguised(src)) {
- WBUFL(buf,2)=-src->id;
- if(damage > 0)
- WBUFW(buf,22)=-1;
- if(damage2 > 0)
- WBUFW(buf,27)=-1;
+ WBUFL(buf,2) = -src->id;
+ if(damage > 0) WBUFW(buf,22) = -1;
+ if(damage2 > 0) WBUFW(buf,27) = -1;
clif_send(buf,packet_len(0x8a),src,SELF);
}
if (disguised(dst)) {
- WBUFL(buf,6)=-dst->id;
- if (disguised(src))
- WBUFL(buf,2)=src->id;
+ WBUFL(buf,6) = -dst->id;
+ if (disguised(src)) WBUFL(buf,2) = src->id;
else {
- if(damage > 0)
- WBUFW(buf,22)=-1;
- if(damage2 > 0)
- WBUFW(buf,27)=-1;
+ if(damage > 0) WBUFW(buf,22) = -1;
+ if(damage2 > 0) WBUFW(buf,27) = -1;
}
clif_send(buf,packet_len(0x8a),dst,SELF);
}
@@ -3870,6 +3872,65 @@ int clif_damage(struct block_list *src,struct block_list *dst,unsigned int tick,
}
/*==========================================
+ * src picks up dst
+ *------------------------------------------*/
+void clif_takeitem(struct block_list* src, struct block_list* dst)
+{
+ //clif_damage(src,dst,0,0,0,0,0,1,0);
+ unsigned char buf[32];
+
+ nullpo_retv(src);
+ nullpo_retv(dst);
+
+ WBUFW(buf, 0) = 0x8a;
+ WBUFL(buf, 2) = src->id;
+ WBUFL(buf, 6) = dst->id;
+ WBUFB(buf,26) = 1;
+ clif_send(buf, packet_len(0x8a), src, AREA);
+
+}
+
+/*==========================================
+ * inform clients in area that `sd` is sitting
+ *------------------------------------------*/
+void clif_sitting(struct map_session_data* sd)
+{
+ unsigned char buf[32];
+
+ nullpo_retv(sd);
+
+ WBUFW(buf, 0) = 0x8a;
+ WBUFL(buf, 2) = sd->bl.id;
+ WBUFB(buf,26) = 2;
+ clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
+
+ if(disguised(&sd->bl)) {
+ WBUFL(buf, 2) = -sd->bl.id;
+ clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
+ }
+}
+
+/*==========================================
+ * inform clients in area that `sd` is standing
+ *------------------------------------------*/
+void clif_standing(struct map_session_data* sd)
+{
+ unsigned char buf[32];
+
+ nullpo_retv(sd);
+
+ WBUFW(buf, 0) = 0x8a;
+ WBUFL(buf, 2) = sd->bl.id;
+ WBUFB(buf,26) = 3;
+ clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
+
+ if(disguised(&sd->bl)) {
+ WBUFL(buf, 2) = -sd->bl.id;
+ clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
+ }
+}
+
+/*==========================================
*
*------------------------------------------*/
void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
@@ -7220,46 +7281,6 @@ void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
}
/*==========================================
- * inform clients in area that `sd` is sitting
- *------------------------------------------*/
-void clif_sitting(struct map_session_data* sd)
-{
- unsigned char buf[32];
-
- nullpo_retv(sd);
-
- WBUFW(buf, 0) = 0x8a;
- WBUFL(buf, 2) = sd->bl.id;
- WBUFB(buf,26) = 2;
- clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
-
- if(disguised(&sd->bl)) {
- WBUFL(buf, 2) = -sd->bl.id;
- clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
- }
-}
-
-/*==========================================
- * inform clients in area that `sd` is standing
- *------------------------------------------*/
-void clif_standing(struct map_session_data* sd)
-{
- unsigned char buf[32];
-
- nullpo_retv(sd);
-
- WBUFW(buf, 0) = 0x8a;
- WBUFL(buf, 2) = sd->bl.id;
- WBUFB(buf,26) = 3;
- clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
-
- if(disguised(&sd->bl)) {
- WBUFL(buf, 2) = -sd->bl.id;
- clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
- }
-}
-
-/*==========================================
*
*------------------------------------------*/
int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
@@ -8702,8 +8723,9 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type,
if (sd->sc.count && (
sd->sc.data[SC_DANCING].timer != -1 ||
(sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
- )) //No sitting during these states neither.
- break;
+ )) //No sitting during these states either.
+ break;
+
pc_setsit(sd);
skill_sit(sd,1);
clif_sitting(sd);
@@ -8881,8 +8903,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd)
// if there are 'Test' player on an other map-server and 'test' player on this map-server,
// and if we ask for 'Test', we must not contact 'test' player
// so, we send information to inter-server, which is the only one which decide (and copy correct name).
- if (dstsd == NULL ||
- strcmp(dstsd->status.name, target) != 0)
+ if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
{ // send message to inter-server
intif_wis_message(sd, target, msg, len);
aFree(command);
@@ -10315,26 +10336,24 @@ void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
}
/*==========================================
- * ギルド告知変更
+ * Guild notice update request
+ * S 016E <guildID>.l <msg1>.60B <msg2>.120B
*------------------------------------------*/
-void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd)
+void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
{
+ int guild_id = RFIFOL(fd,2);
+ char* msg1 = (char*)RFIFOP(fd,6);
+ char* msg2 = (char*)RFIFOP(fd,66);
+
if(!sd->state.gmaster_flag)
return;
- // compensate for the client's double marker bug (in both strings)
- if ((RFIFOB(fd, 6) == '|') && (RFIFOB(fd, 6+3) == '|')) {
- memmove(RFIFOP(fd, 6+3), RFIFOP(fd, 6+6), 60-6); memset(RFIFOP(fd, 60-3), 0x00, 3); // drop the duplicate marker
- }
- if ((RFIFOB(fd, 66) == '|') && (RFIFOB(fd, 66+3) == '|')) {
- memmove(RFIFOP(fd, 66+3), RFIFOP(fd, 66+6), 180-6); memset(RFIFOP(fd, 180-3), 0x00, 3); // drop the duplicate marker
- }
- // compensate for the client's adding of an extra space at the end of the message
- if (RFIFOB(fd, 66) == '|') {
- memset(RFIFOP(fd, 66 + strnlen((char*)RFIFOP(fd, 66), 120)-1), 0x00, 1); // delete extra space at the end
- }
+ // compensate for some client defects when using multilanguage mode
+ if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
+ if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
+ if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
- guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
+ guild_change_notice(sd, guild_id, msg1, msg2);
}
/*==========================================
@@ -11476,13 +11495,12 @@ void clif_parse_debug(int fd,struct map_session_data *sd)
}
/*==========================================
- * クライアントからのパケット解析
- * socket.cのdo_parsepacketから呼び出される
+ * Main client packet processing function
*------------------------------------------*/
int clif_parse(int fd)
{
- int packet_len = 0, cmd, packet_ver, err, dump = 0;
- TBL_PC *sd;
+ int packet_len = 0, cmd, packet_ver, err;
+ TBL_PC* sd;
sd = (TBL_PC *)session[fd]->session_data;
if (session[fd]->eof) {
@@ -11491,17 +11509,14 @@ int clif_parse(int fd)
//Disassociate character from the socket connection.
session[fd]->session_data = NULL;
sd->fd = 0;
- ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n",
- (pc_isGM(sd))?"GM ":"",sd->status.name);
+ ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
} else
if (sd->state.auth) {
// Player logout display [Valaris]
- ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n",
- (pc_isGM(sd))?"GM ":"",sd->status.name);
+ ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
clif_quitsave(fd, sd);
} else {
- ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n",
- sd->bl.id, sd->status.char_id);
+ ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n", sd->bl.id, sd->status.char_id);
map_quit(sd);
}
} else {
@@ -11515,8 +11530,6 @@ int clif_parse(int fd)
if (RFIFOREST(fd) < 2)
return 0;
-// printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
-
cmd = RFIFOW(fd,0);
// identify client's packet version
@@ -11547,63 +11560,28 @@ int clif_parse(int fd)
}
}
- // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
- if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) { // if packet is not inside these values: session is incorrect?? or auth packet is unknown
+ // filter out invalid / unsupported packets
+ if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
set_eof(fd);
return 0;
}
- // パケット長を計算
+ // determine real packet length
packet_len = packet_db[packet_ver][cmd].len;
- if (packet_len == -1) {
+ if (packet_len == -1) { // variable-length packet
if (RFIFOREST(fd) < 4)
- return 0; // 可変長パケットで長さの所までデータが来てない
+ return 0;
packet_len = RFIFOW(fd,2);
if (packet_len < 4 || packet_len > 32768) {
- ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
+ ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
set_eof(fd);
return 0;
}
}
if ((int)RFIFOREST(fd) < packet_len)
- return 0; // まだ1パケット分データが揃ってない
-
-#if DUMP_ALL_PACKETS
- {
- int i;
- FILE *fp;
- char packet_txt[256] = "save/packet.txt";
- time_t now;
- dump = 1;
-
- if ((fp = fopen(packet_txt, "a")) == NULL) {
- ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
- return 1;
- } else {
- time(&now);
- if (sd && sd->state.auth) {
- if (sd->status.name != NULL)
- fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent packet:\n",
- asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
- else
- fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
- } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
- fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
-
- fprintf(fp, "\tsession #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
- 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\n");
- fclose(fp);
- }
- }
-#endif
+ return 0; // not enough data received to form the packet
if (sd && sd->state.waitingdisconnect == 1) {
// 切断待ちの場合パケットを処理しない
@@ -11650,6 +11628,7 @@ int clif_parse(int fd)
}
#endif
+ /* TODO: use utils.c :: dump()
if (dump) {
int i;
ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
@@ -11668,7 +11647,7 @@ int clif_parse(int fd)
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);
- }
+ }*/
RFIFOSKIP(fd, packet_len);
@@ -11890,7 +11869,7 @@ static int packetdb_readdb(void)
{NULL,NULL}
};
- // Set server packet lengths - packet_db[SERVER]
+ // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
memset(packet_db,0,sizeof(packet_db));
for( i = 0; i < sizeof(packet_len_table)/sizeof(packet_len_table[0]); ++i )
packet_len(i) = packet_len_table[i];
@@ -11947,17 +11926,11 @@ static int packetdb_readdb(void)
memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
continue;
} else if(strcmpi(w1,"packet_db_ver")==0) {
- //This is the preferred version.
- if(strcmpi(w2,"default")==0)
+ if(strcmpi(w2,"default")==0) //This is the preferred version.
clif_config.packet_db_ver = MAX_PACKET_VER;
- else {
- // to manually set the packet DB version
- clif_config.packet_db_ver = atoi(w2);
- // check for invalid version
- if (clif_config.packet_db_ver > MAX_PACKET_VER ||
- clif_config.packet_db_ver < 0)
- clif_config.packet_db_ver = MAX_PACKET_VER;
- }
+ else // to manually set the packet DB version
+ clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
+
continue;
}
}
@@ -11992,8 +11965,7 @@ static int packetdb_readdb(void)
continue;
}
for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
- if(clif_parse_func[j].name != NULL &&
- strcmp(str[2],clif_parse_func[j].name)==0)
+ if(clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0)
{
if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
{ //If we are updating a function, we need to zero up the previous one. [Skotlex]
diff --git a/src/map/clif.h b/src/map/clif.h
index 90ead35fa..a8193faaa 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -24,8 +24,8 @@ struct packet_db_t {
// packet_db[SERVER] is reserved for server use
#define SERVER 0
-#define packet_len(x) packet_db[SERVER][x].len
-extern struct packet_db_t packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
+#define packet_len(cmd) packet_db[SERVER][cmd].len
+extern struct packet_db_t packet_db[MAX_PACKET_VER+1][MAX_PACKET_DB+1];
// local define
enum send_target {
@@ -100,8 +100,10 @@ int clif_additem(struct map_session_data*,int,int,int); //self
int clif_delitem(struct map_session_data*,int,int); //self
int clif_updatestatus(struct map_session_data*,int); //self
int clif_changestatus(struct block_list*,int,int); //area
-int clif_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int type,int damage2); // area
-#define clif_takeitem(src,dst) clif_damage(src,dst,0,0,0,0,0,1,0)
+int clif_damage(struct block_list* src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int type,int damage2); // area
+void clif_takeitem(struct block_list* src,struct block_list* dst);
+void clif_sitting(struct map_session_data* sd);
+void clif_standing(struct map_session_data* sd);
int clif_changelook(struct block_list *,int,int); // area
void clif_changetraplook(struct block_list *bl,int val); // area
void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area); //area specified in 'area'
@@ -132,8 +134,6 @@ int clif_fame_blacksmith(struct map_session_data *, int);
int clif_fame_alchemist(struct map_session_data *, int);
int clif_fame_taekwon(struct map_session_data *, int);
-void clif_sitting(struct map_session_data* sd);
-void clif_standing(struct map_session_data* sd);
void clif_emotion(struct block_list *bl,int type);
void clif_talkiebox(struct block_list* bl, const char* talkie);
void clif_wedding_effect(struct block_list *bl);
diff --git a/src/map/status.c b/src/map/status.c
index 59212b1d5..890736a37 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -675,14 +675,9 @@ int status_damage(struct block_list *src,struct block_list *target,int hp, int s
switch (target->type)
{
- case BL_MOB:
- mob_damage((TBL_MOB*)target, src, hp);
- break;
- case BL_PC:
- pc_damage((TBL_PC*)target,src,hp,sp);
- break;
- case BL_HOM:
- merc_damage((TBL_HOM*)target,src,hp,sp);
+ case BL_PC: pc_damage((TBL_PC*)target,src,hp,sp); break;
+ case BL_MOB: mob_damage((TBL_MOB*)target, src, hp); break;
+ case BL_HOM: merc_damage((TBL_HOM*)target,src,hp,sp); break;
}
if (status->hp)
@@ -698,17 +693,10 @@ int status_damage(struct block_list *src,struct block_list *target,int hp, int s
//Non-zero: Standard death. Clear status, cancel move/attack, etc
//&2: Also remove object from map.
//&4: Also delete object from memory.
- switch (target->type)
- {
- case BL_MOB:
- flag = mob_dead((TBL_MOB*)target, src, flag&4?3:0);
- break;
- case BL_PC:
- flag = pc_dead((TBL_PC*)target,src);
- break;
- case BL_HOM:
- flag = merc_hom_dead((TBL_HOM*)target,src);
- break;
+ switch (target->type) {
+ case BL_PC: flag = pc_dead((TBL_PC*)target,src); break;
+ case BL_MOB: flag = mob_dead((TBL_MOB*)target, src, flag&4?3:0); break;
+ case BL_HOM: flag = merc_hom_dead((TBL_HOM*)target,src); break;
default: //Unhandled case, do nothing to object.
flag = 0;
break;
@@ -806,15 +794,9 @@ int status_heal(struct block_list *bl,int hp,int sp, int flag)
status_change_end(bl,SC_PROVOKE,-1);
switch(bl->type) {
- case BL_MOB:
- mob_heal((TBL_MOB*)bl,hp);
- break;
- case BL_PC:
- pc_heal((TBL_PC*)bl,hp,sp,flag&2?1:0);
- break;
- case BL_HOM:
- merc_hom_heal((TBL_HOM*)bl,hp,sp);
- break;
+ case BL_PC: pc_heal((TBL_PC*)bl,hp,sp,flag&2?1:0); break;
+ case BL_MOB: mob_heal((TBL_MOB*)bl,hp); break;
+ case BL_HOM: merc_hom_heal((TBL_HOM*)bl,hp,sp); break;
}
return hp+sp;
}
@@ -912,15 +894,9 @@ int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per
if (bl->prev) //Animation only if character is already on a map.
clif_resurrection(bl, 1);
switch (bl->type) {
- case BL_MOB:
- mob_revive((TBL_MOB*)bl, hp);
- break;
- case BL_PC:
- pc_revive((TBL_PC*)bl, hp, sp);
- break;
- case BL_HOM: //[orn]
- merc_hom_revive((TBL_HOM*)bl, hp, sp);
- break;
+ case BL_PC: pc_revive((TBL_PC*)bl, hp, sp); break;
+ case BL_MOB: mob_revive((TBL_MOB*)bl, hp); break;
+ case BL_HOM: merc_hom_revive((TBL_HOM*)bl, hp, sp); break;
}
return 1;
}
@@ -1920,24 +1896,12 @@ int status_calc_pc(struct map_session_data* sd,int first)
if(!job_bonus[sd->status.class_][i])
continue;
switch(job_bonus[sd->status.class_][i]) {
- case 1:
- status->str++;
- break;
- case 2:
- status->agi++;
- break;
- case 3:
- status->vit++;
- break;
- case 4:
- status->int_++;
- break;
- case 5:
- status->dex++;
- break;
- case 6:
- status->luk++;
- break;
+ case 1: status->str++; break;
+ case 2: status->agi++; break;
+ case 3: status->vit++; break;
+ case 4: status->int_++; break;
+ case 5: status->dex++; break;
+ case 6: status->luk++; break;
}
}
@@ -3947,22 +3911,15 @@ void status_freecast_switch(struct map_session_data *sd)
clif_updatestatus(sd,SP_SPEED);
}
-const char * status_get_name(struct block_list *bl)
+const char* status_get_name(struct block_list *bl)
{
nullpo_retr(0, bl);
switch (bl->type) {
- case BL_MOB:
- return ((TBL_MOB*)bl)->name;
- case BL_PC:
- if(strlen(((TBL_PC *)bl)->fakename)>0)
- return ((TBL_PC*)bl)->fakename;
- return ((TBL_PC*)bl)->status.name;
- case BL_PET:
- return ((TBL_PET*)bl)->pet.name;
- case BL_HOM:
- return ((TBL_HOM*)bl)->homunculus.name;
- case BL_NPC:
- return ((TBL_NPC*)bl)->name;
+ case BL_PC: return ((TBL_PC *)bl)->fakename[0] != '\0' ? ((TBL_PC*)bl)->fakename : ((TBL_PC*)bl)->status.name;
+ case BL_MOB: return ((TBL_MOB*)bl)->name;
+ case BL_PET: return ((TBL_PET*)bl)->pet.name;
+ case BL_HOM: return ((TBL_HOM*)bl)->homunculus.name;
+ case BL_NPC: return ((TBL_NPC*)bl)->name;
}
return "Unknown";
}
@@ -3991,14 +3948,12 @@ int status_get_class(struct block_list *bl)
int status_get_lv(struct block_list *bl)
{
nullpo_retr(0, bl);
- if(bl->type==BL_MOB)
- return ((TBL_MOB*)bl)->level;
- if(bl->type==BL_PC)
- return ((TBL_PC*)bl)->status.base_level;
- if(bl->type==BL_PET)
- return ((TBL_PET*)bl)->pet.level;
- if(bl->type==BL_HOM)
- return ((TBL_HOM*)bl)->homunculus.level;
+ switch (bl->type) {
+ case BL_PC: return ((TBL_PC*)bl)->status.base_level;
+ case BL_MOB: return ((TBL_MOB*)bl)->level;
+ case BL_PET: return ((TBL_PET*)bl)->pet.level;
+ case BL_HOM: return ((TBL_HOM*)bl)->homunculus.level;
+ }
return 1;
}
@@ -4006,10 +3961,8 @@ struct regen_data *status_get_regen_data(struct block_list *bl)
{
nullpo_retr(NULL, bl);
switch (bl->type) {
- case BL_PC:
- return &((TBL_PC*)bl)->regen;
- case BL_HOM:
- return &((TBL_HOM*)bl)->regen;
+ case BL_PC: return &((TBL_PC*)bl)->regen;
+ case BL_HOM: return &((TBL_HOM*)bl)->regen;
default:
return NULL;
}
@@ -4020,14 +3973,10 @@ struct status_data *status_get_status_data(struct block_list *bl)
nullpo_retr(&dummy_status, bl);
switch (bl->type) {
- case BL_PC:
- return &((TBL_PC*)bl)->battle_status;
- case BL_MOB:
- return &((TBL_MOB*)bl)->status;
- case BL_PET:
- return &((TBL_PET*)bl)->status;
- case BL_HOM:
- return &((TBL_HOM*)bl)->battle_status;
+ case BL_PC: return &((TBL_PC*)bl)->battle_status;
+ case BL_MOB: return &((TBL_MOB*)bl)->status;
+ case BL_PET: return &((TBL_PET*)bl)->status;
+ case BL_HOM: return &((TBL_HOM*)bl)->battle_status;
default:
return &dummy_status;
}
@@ -4037,16 +3986,10 @@ struct status_data *status_get_base_status(struct block_list *bl)
{
nullpo_retr(NULL, bl);
switch (bl->type) {
- case BL_PC:
- return &((TBL_PC*)bl)->base_status;
- case BL_MOB:
- return ((TBL_MOB*)bl)->base_status?
- ((TBL_MOB*)bl)->base_status:
- &((TBL_MOB*)bl)->db->status;
- case BL_PET:
- return &((TBL_PET*)bl)->db->status;
- case BL_HOM:
- return &((TBL_HOM*)bl)->base_status;
+ case BL_PC: return &((TBL_PC*)bl)->base_status;
+ case BL_MOB: return ((TBL_MOB*)bl)->base_status ? ((TBL_MOB*)bl)->base_status : &((TBL_MOB*)bl)->db->status;
+ case BL_PET: return &((TBL_PET*)bl)->db->status;
+ case BL_HOM: return &((TBL_HOM*)bl)->base_status;
default:
return NULL;
}
@@ -4227,21 +4170,15 @@ int status_isimmune(struct block_list *bl)
return 0;
}
-struct view_data *status_get_viewdata(struct block_list *bl)
+struct view_data* status_get_viewdata(struct block_list *bl)
{
nullpo_retr(NULL, bl);
- switch (bl->type)
- {
- case BL_PC:
- return &((TBL_PC*)bl)->vd;
- case BL_MOB:
- return ((TBL_MOB*)bl)->vd;
- case BL_PET:
- return &((TBL_PET*)bl)->vd;
- case BL_NPC:
- return ((TBL_NPC*)bl)->vd;
- case BL_HOM: //[blackhole89]
- return ((TBL_HOM*)bl)->vd;
+ switch (bl->type) {
+ case BL_PC: return &((TBL_PC*)bl)->vd;
+ case BL_MOB: return ((TBL_MOB*)bl)->vd;
+ case BL_PET: return &((TBL_PET*)bl)->vd;
+ case BL_NPC: return ((TBL_NPC*)bl)->vd;
+ case BL_HOM: return ((TBL_HOM*)bl)->vd;
}
return NULL;
}
@@ -4364,14 +4301,10 @@ struct status_change *status_get_sc(struct block_list *bl)
{
nullpo_retr(NULL, bl);
switch (bl->type) {
- case BL_MOB:
- return &((TBL_MOB*)bl)->sc;
- case BL_PC:
- return &((TBL_PC*)bl)->sc;
- case BL_NPC:
- return &((TBL_NPC*)bl)->sc;
- case BL_HOM: //[blackhole89]
- return &((TBL_HOM*)bl)->sc;
+ case BL_PC: return &((TBL_PC*)bl)->sc;
+ case BL_MOB: return &((TBL_MOB*)bl)->sc;
+ case BL_NPC: return &((TBL_NPC*)bl)->sc;
+ case BL_HOM: return &((TBL_HOM*)bl)->sc;
}
return NULL;
}
diff --git a/src/map/unit.c b/src/map/unit.c
index d3c691c92..c53a8b6c6 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -1366,21 +1366,17 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
ud->attacktimer=-1;
target=map_id2bl(ud->target);
- if(src->prev == NULL || target==NULL || target->prev == NULL)
+ if(src == NULL || src->prev == NULL || target==NULL || target->prev == NULL)
return 0;
- if(ud->skilltimer != -1 && (!sd || pc_checkskill(sd,SA_FREECAST) <= 0))
- return 0;
-
if(src->m != target->m || status_isdead(src) || status_isdead(target) || !status_check_skilluse(src, target, 0, 0))
- return 0;
-
- sstatus = status_get_status_data(src);
+ return 0; // can't attack under these conditions
- if(!battle_config.sdelay_attack_enable &&
- DIFF_TICK(ud->canact_tick,tick) > 0 &&
- (!sd || pc_checkskill(sd,SA_FREECAST) <= 0)
- ) {
+ if(ud->skilltimer != -1 && !(sd && pc_checkskill(sd,SA_FREECAST) > 0))
+ return 0; // can't attack while casting
+
+ if(!battle_config.sdelay_attack_enable && DIFF_TICK(ud->canact_tick,tick) > 0 && !(sd && pc_checkskill(sd,SA_FREECAST) > 0))
+ { // attacking when under cast delay has restrictions:
if (tid == -1) { //requested attack.
if(sd) clif_skill_fail(sd,1,4,0);
return 0;
@@ -1394,6 +1390,7 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
return 1;
}
+ sstatus = status_get_status_data(src);
range = sstatus->rhw.range;
if(!sd || sd->status.weapon != W_BOW) range++; //Dunno why everyone but bows gets this extra range...
@@ -1420,9 +1417,9 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
//Non-players use the sync packet on the walk timer. [Skotlex]
if (tid == -1 && sd) clif_fixpos(src);
- if(DIFF_TICK(ud->attackabletime,tick) <= 0) {
- if (battle_config.attack_direction_change &&
- (src->type&battle_config.attack_direction_change)) {
+ if(DIFF_TICK(ud->attackabletime,tick) <= 0)
+ {
+ if (battle_config.attack_direction_change && (src->type&battle_config.attack_direction_change)) {
ud->dir = map_calc_dir(src, target->x,target->y );
}
if(ud->walktimer != -1)
@@ -1433,8 +1430,7 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
if (sstatus->mode&MD_ASSIST && DIFF_TICK(md->last_linktime, tick) < MIN_MOBLINKTIME)
{ // Link monsters nearby [Skotlex]
md->last_linktime = tick;
- map_foreachinrange(mob_linksearch, src, md->db->range2,
- BL_MOB, md->class_, target, tick);
+ map_foreachinrange(mob_linksearch, src, md->db->range2, BL_MOB, md->class_, target, tick);
}
}
if(src->type == BL_PET && pet_attackskill((TBL_PET*)src, target->id))