Some all-around code reformatting/cleaning

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@10947 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ultramage 2007-08-04 16:24:49 +00:00
parent 66516651c3
commit 0a0782c664
7 changed files with 231 additions and 343 deletions

View File

@ -20,41 +20,40 @@
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#ifdef UTIL_DUMP // generate a hex dump of the first 'length' bytes of 'buffer'
void dump(const unsigned char* buffer, int num) void dump(FILE* fp, const unsigned char* buffer, int length)
{ {
int icnt, jcnt; int i, j;
printf(" Hex ASCII\n"); fprintf(fp, " Hex ASCII\n");
printf(" ----------------------------------------------- ----------------"); fprintf(fp, " ----------------------------------------------- ----------------");
for (icnt = 0; icnt < num; icnt += 16) for (i = 0; i < length; i += 16)
{ {
printf("\n%p ", &buffer[icnt]); fprintf(fp, "\n%p ", &buffer[i]);
for (jcnt = icnt; jcnt < icnt + 16; ++jcnt) for (j = i; j < i + 16; ++j)
{ {
if (jcnt < num) if (j < length)
printf("%02hX ", buffer[jcnt]); fprintf(fp, "%02hX ", buffer[j]);
else 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 (j < length) {
if (buffer[jcnt] > 31 && buffer[jcnt] < 127) if (buffer[j] > 31 && buffer[j] < 127)
printf("%c", buffer[jcnt]); fprintf(fp, "%c", buffer[j]);
else else
printf("."); fprintf(fp, ".");
} else } else
printf(" "); fprintf(fp, " ");
} }
} }
printf("\n"); fprintf(fp, "\n");
} }
#endif
// Allocate a StringBuf [MouseJstr] // Allocate a StringBuf [MouseJstr]
struct StringBuf * StringBuf_Malloc() struct StringBuf * StringBuf_Malloc()

View File

@ -4,13 +4,11 @@
#ifndef _UTILS_H_ #ifndef _UTILS_H_
#define _UTILS_H_ #define _UTILS_H_
#include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
// Function that dumps the hex of the first num bytes of the buffer to the screen // generate a hex dump of the first 'length' bytes of 'buffer'
//#define UTIL_DUMP void dump(FILE* fp, const unsigned char* buffer, int length);
#ifdef UTIL_DUMP
void dump(const unsigned char* buffer, int num);
#endif
struct StringBuf { struct StringBuf {
char *buf_; char *buf_;

View File

@ -1,11 +1,6 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder // 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/cbasetypes.h"
#include "../common/timer.h" #include "../common/timer.h"
#include "../common/nullpo.h" #include "../common/nullpo.h"
@ -26,6 +21,11 @@
#include "party.h" #include "party.h"
#include "battle.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]; int attr_fix_table[4][ELE_MAX][ELE_MAX];
struct Battle_Config battle_config; 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] //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) switch (bl->type)
{ {
case BL_PC: case BL_PC: return ((struct map_session_data*)bl)->ud.target;
return ((struct map_session_data*)bl)->ud.target; case BL_MOB: return ((struct mob_data*)bl)->target_id;
case BL_MOB: case BL_PET: return ((struct pet_data*)bl)->target_id;
return ((struct mob_data*)bl)->target_id; case BL_HOM: return ((struct homun_data*)bl)->ud.target;
case BL_PET:
return ((struct pet_data*)bl)->target_id;
case BL_HOM:
return ((struct homun_data*)bl)->ud.target;
} }
return 0; 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 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; struct Damage d;
switch(attack_type){ switch(attack_type) {
case BF_WEAPON: case BF_WEAPON: d = battle_calc_weapon_attack(bl,target,skill_num,skill_lv,flag); break;
d = battle_calc_weapon_attack(bl,target,skill_num,skill_lv,flag); case BF_MAGIC: d = battle_calc_magic_attack(bl,target,skill_num,skill_lv,flag); break;
break; case BF_MISC: d = battle_calc_misc_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: default:
if (battle_config.error_log) if (battle_config.error_log)
ShowError("battle_calc_attack: unknown attack type! %d\n",attack_type); 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; return d;
} }
int battle_calc_return_damage(struct block_list *bl, int *damage, int flag) { int battle_calc_return_damage(struct block_list* bl, int* damage, int flag)
struct map_session_data *sd=NULL; {
struct status_change *sc; struct map_session_data* sd = NULL;
struct status_change* sc;
int rdamage = 0; int rdamage = 0;
BL_CAST(BL_PC, bl, sd); 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] // magic_damage_return by [AppleGirl] and [Valaris]
if(flag&BF_MAGIC) if(flag&BF_MAGIC)
{ {
if(sd && sd->magic_damage_return && if(sd && sd->magic_damage_return && rand()%100 < sd->magic_damage_return)
rand()%100 < sd->magic_damage_return)
{ //Bounces back full damage, you take none. { //Bounces back full damage, you take none.
rdamage = *damage; rdamage = *damage;
*damage = 0; *damage = 0;

View File

@ -1,9 +1,6 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder // 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/cbasetypes.h"
#include "../common/socket.h" #include "../common/socket.h"
#include "../common/timer.h" #include "../common/timer.h"
@ -45,6 +42,8 @@
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
#define DUMP_UNKNOWN_PACKET 0
struct Clif_Config { struct Clif_Config {
int packet_db_ver; //Preferred packet version. int packet_db_ver; //Preferred packet version.
int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex] 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
} }
/*========================================== /*==========================================
* * 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) 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]; unsigned char buf[256];
struct status_change *sc; 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. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
sc = status_get_sc(dst); sc = status_get_sc(dst);
if(sc && sc->count) { if(sc && sc->count) {
if(sc->data[SC_HALLUCINATION].timer != -1) { if(sc->data[SC_HALLUCINATION].timer != -1) {
if(damage > 0) if(damage > 0) damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100; if(damage2 > 0) damage2 = damage2*(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); clif_send(buf,packet_len(0x8a),src,AREA);
if(disguised(src)) { if(disguised(src)) {
WBUFL(buf,2)=-src->id; WBUFL(buf,2) = -src->id;
if(damage > 0) if(damage > 0) WBUFW(buf,22) = -1;
WBUFW(buf,22)=-1; if(damage2 > 0) WBUFW(buf,27) = -1;
if(damage2 > 0)
WBUFW(buf,27)=-1;
clif_send(buf,packet_len(0x8a),src,SELF); clif_send(buf,packet_len(0x8a),src,SELF);
} }
if (disguised(dst)) { if (disguised(dst)) {
WBUFL(buf,6)=-dst->id; WBUFL(buf,6) = -dst->id;
if (disguised(src)) if (disguised(src)) WBUFL(buf,2) = src->id;
WBUFL(buf,2)=src->id;
else { else {
if(damage > 0) if(damage > 0) WBUFW(buf,22) = -1;
WBUFW(buf,22)=-1; if(damage2 > 0) WBUFW(buf,27) = -1;
if(damage2 > 0)
WBUFW(buf,27)=-1;
} }
clif_send(buf,packet_len(0x8a),dst,SELF); clif_send(buf,packet_len(0x8a),dst,SELF);
} }
@ -3869,6 +3871,65 @@ int clif_damage(struct block_list *src,struct block_list *dst,unsigned int tick,
return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div); return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
} }
/*==========================================
* 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);
}
}
/*========================================== /*==========================================
* *
*------------------------------------------*/ *------------------------------------------*/
@ -7219,46 +7280,6 @@ void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
WFIFOSET(fd, packet_len(0x1e2)); WFIFOSET(fd, packet_len(0x1e2));
} }
/*==========================================
* 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);
}
}
/*========================================== /*==========================================
* *
*------------------------------------------*/ *------------------------------------------*/
@ -8702,8 +8723,9 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type,
if (sd->sc.count && ( if (sd->sc.count && (
sd->sc.data[SC_DANCING].timer != -1 || sd->sc.data[SC_DANCING].timer != -1 ||
(sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF) (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
)) //No sitting during these states neither. )) //No sitting during these states either.
break; break;
pc_setsit(sd); pc_setsit(sd);
skill_sit(sd,1); skill_sit(sd,1);
clif_sitting(sd); 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, // 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 // 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). // so, we send information to inter-server, which is the only one which decide (and copy correct name).
if (dstsd == NULL || if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
strcmp(dstsd->status.name, target) != 0)
{ // send message to inter-server { // send message to inter-server
intif_wis_message(sd, target, msg, len); intif_wis_message(sd, target, msg, len);
aFree(command); 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) if(!sd->state.gmaster_flag)
return; return;
// compensate for the client's double marker bug (in both strings) // compensate for some client defects when using multilanguage mode
if ((RFIFOB(fd, 6) == '|') && (RFIFOB(fd, 6+3) == '|')) { if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
memmove(RFIFOP(fd, 6+3), RFIFOP(fd, 6+6), 60-6); memset(RFIFOP(fd, 60-3), 0x00, 3); // drop the 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
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
}
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)
} }
/*========================================== /*==========================================
* * Main client packet processing function
* socket.cのdo_parsepacketから呼び出される
*------------------------------------------*/ *------------------------------------------*/
int clif_parse(int fd) int clif_parse(int fd)
{ {
int packet_len = 0, cmd, packet_ver, err, dump = 0; int packet_len = 0, cmd, packet_ver, err;
TBL_PC *sd; TBL_PC* sd;
sd = (TBL_PC *)session[fd]->session_data; sd = (TBL_PC *)session[fd]->session_data;
if (session[fd]->eof) { if (session[fd]->eof) {
@ -11491,17 +11509,14 @@ int clif_parse(int fd)
//Disassociate character from the socket connection. //Disassociate character from the socket connection.
session[fd]->session_data = NULL; session[fd]->session_data = NULL;
sd->fd = 0; sd->fd = 0;
ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
(pc_isGM(sd))?"GM ":"",sd->status.name);
} else } else
if (sd->state.auth) { if (sd->state.auth) {
// Player logout display [Valaris] // Player logout display [Valaris]
ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
(pc_isGM(sd))?"GM ":"",sd->status.name);
clif_quitsave(fd, sd); clif_quitsave(fd, sd);
} else { } else {
ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n", ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n", sd->bl.id, sd->status.char_id);
sd->bl.id, sd->status.char_id);
map_quit(sd); map_quit(sd);
} }
} else { } else {
@ -11515,8 +11530,6 @@ int clif_parse(int fd)
if (RFIFOREST(fd) < 2) if (RFIFOREST(fd) < 2)
return 0; 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); cmd = RFIFOW(fd,0);
// identify client's packet version // identify client's packet version
@ -11547,63 +11560,28 @@ int clif_parse(int fd)
} }
} }
// ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する // filter out invalid / unsupported packets
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 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); ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
set_eof(fd); set_eof(fd);
return 0; return 0;
} }
// パケット長を計算 // determine real packet length
packet_len = packet_db[packet_ver][cmd].len; packet_len = packet_db[packet_ver][cmd].len;
if (packet_len == -1) { if (packet_len == -1) { // variable-length packet
if (RFIFOREST(fd) < 4) if (RFIFOREST(fd) < 4)
return 0; // 可変長パケットで長さの所までデータが来てない return 0;
packet_len = RFIFOW(fd,2); packet_len = RFIFOW(fd,2);
if (packet_len < 4 || packet_len > 32768) { 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); set_eof(fd);
return 0; return 0;
} }
} }
if ((int)RFIFOREST(fd) < packet_len) if ((int)RFIFOREST(fd) < packet_len)
return 0; // まだ1パケット分データが揃ってない return 0; // not enough data received to form the packet
#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
if (sd && sd->state.waitingdisconnect == 1) { if (sd && sd->state.waitingdisconnect == 1) {
// 切断待ちの場合パケットを処理しない // 切断待ちの場合パケットを処理しない
@ -11650,6 +11628,7 @@ int clif_parse(int fd)
} }
#endif #endif
/* TODO: use utils.c :: dump()
if (dump) { if (dump) {
int i; int i;
ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver); 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); printf("\nAccount ID %d.\n", sd->bl.id);
} else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified) } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
printf("\nAccount ID %d.\n", sd->bl.id); printf("\nAccount ID %d.\n", sd->bl.id);
} }*/
RFIFOSKIP(fd, packet_len); RFIFOSKIP(fd, packet_len);
@ -11890,7 +11869,7 @@ static int packetdb_readdb(void)
{NULL,NULL} {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)); memset(packet_db,0,sizeof(packet_db));
for( i = 0; i < sizeof(packet_len_table)/sizeof(packet_len_table[0]); ++i ) for( i = 0; i < sizeof(packet_len_table)/sizeof(packet_len_table[0]); ++i )
packet_len(i) = packet_len_table[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])); memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
continue; continue;
} else if(strcmpi(w1,"packet_db_ver")==0) { } else if(strcmpi(w1,"packet_db_ver")==0) {
//This is the preferred version. if(strcmpi(w2,"default")==0) //This is the preferred version.
if(strcmpi(w2,"default")==0)
clif_config.packet_db_ver = MAX_PACKET_VER; clif_config.packet_db_ver = MAX_PACKET_VER;
else { else // to manually set the packet DB version
// to manually set the packet DB version clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
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;
}
continue; continue;
} }
} }
@ -11992,8 +11965,7 @@ static int packetdb_readdb(void)
continue; continue;
} }
for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){ for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
if(clif_parse_func[j].name != NULL && if(clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0)
strcmp(str[2],clif_parse_func[j].name)==0)
{ {
if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func) 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] { //If we are updating a function, we need to zero up the previous one. [Skotlex]

View File

@ -24,8 +24,8 @@ struct packet_db_t {
// packet_db[SERVER] is reserved for server use // packet_db[SERVER] is reserved for server use
#define SERVER 0 #define SERVER 0
#define packet_len(x) packet_db[SERVER][x].len #define packet_len(cmd) packet_db[SERVER][cmd].len
extern struct packet_db_t packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1]; extern struct packet_db_t packet_db[MAX_PACKET_VER+1][MAX_PACKET_DB+1];
// local define // local define
enum send_target { 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_delitem(struct map_session_data*,int,int); //self
int clif_updatestatus(struct map_session_data*,int); //self int clif_updatestatus(struct map_session_data*,int); //self
int clif_changestatus(struct block_list*,int,int); //area 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 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) 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 int clif_changelook(struct block_list *,int,int); // area
void clif_changetraplook(struct block_list *bl,int val); // 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' 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_alchemist(struct map_session_data *, int);
int clif_fame_taekwon(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_emotion(struct block_list *bl,int type);
void clif_talkiebox(struct block_list* bl, const char* talkie); void clif_talkiebox(struct block_list* bl, const char* talkie);
void clif_wedding_effect(struct block_list *bl); void clif_wedding_effect(struct block_list *bl);

View File

@ -675,14 +675,9 @@ int status_damage(struct block_list *src,struct block_list *target,int hp, int s
switch (target->type) switch (target->type)
{ {
case BL_MOB: case BL_PC: pc_damage((TBL_PC*)target,src,hp,sp); break;
mob_damage((TBL_MOB*)target, src, hp); case BL_MOB: mob_damage((TBL_MOB*)target, src, hp); break;
break; case BL_HOM: merc_damage((TBL_HOM*)target,src,hp,sp); break;
case BL_PC:
pc_damage((TBL_PC*)target,src,hp,sp);
break;
case BL_HOM:
merc_damage((TBL_HOM*)target,src,hp,sp);
} }
if (status->hp) 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 //Non-zero: Standard death. Clear status, cancel move/attack, etc
//&2: Also remove object from map. //&2: Also remove object from map.
//&4: Also delete object from memory. //&4: Also delete object from memory.
switch (target->type) switch (target->type) {
{ case BL_PC: flag = pc_dead((TBL_PC*)target,src); break;
case BL_MOB: case BL_MOB: flag = mob_dead((TBL_MOB*)target, src, flag&4?3:0); break;
flag = mob_dead((TBL_MOB*)target, src, flag&4?3:0); case BL_HOM: flag = merc_hom_dead((TBL_HOM*)target,src); break;
break;
case BL_PC:
flag = pc_dead((TBL_PC*)target,src);
break;
case BL_HOM:
flag = merc_hom_dead((TBL_HOM*)target,src);
break;
default: //Unhandled case, do nothing to object. default: //Unhandled case, do nothing to object.
flag = 0; flag = 0;
break; 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); status_change_end(bl,SC_PROVOKE,-1);
switch(bl->type) { switch(bl->type) {
case BL_MOB: case BL_PC: pc_heal((TBL_PC*)bl,hp,sp,flag&2?1:0); break;
mob_heal((TBL_MOB*)bl,hp); case BL_MOB: mob_heal((TBL_MOB*)bl,hp); break;
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_HOM:
merc_hom_heal((TBL_HOM*)bl,hp,sp);
break;
} }
return hp+sp; 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. if (bl->prev) //Animation only if character is already on a map.
clif_resurrection(bl, 1); clif_resurrection(bl, 1);
switch (bl->type) { switch (bl->type) {
case BL_MOB: case BL_PC: pc_revive((TBL_PC*)bl, hp, sp); break;
mob_revive((TBL_MOB*)bl, hp); case BL_MOB: mob_revive((TBL_MOB*)bl, hp); break;
break; case BL_HOM: merc_hom_revive((TBL_HOM*)bl, hp, sp); 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;
} }
return 1; return 1;
} }
@ -1920,24 +1896,12 @@ int status_calc_pc(struct map_session_data* sd,int first)
if(!job_bonus[sd->status.class_][i]) if(!job_bonus[sd->status.class_][i])
continue; continue;
switch(job_bonus[sd->status.class_][i]) { switch(job_bonus[sd->status.class_][i]) {
case 1: case 1: status->str++; break;
status->str++; case 2: status->agi++; break;
break; case 3: status->vit++; break;
case 2: case 4: status->int_++; break;
status->agi++; case 5: status->dex++; break;
break; case 6: status->luk++; 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); 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); nullpo_retr(0, bl);
switch (bl->type) { switch (bl->type) {
case BL_MOB: case BL_PC: return ((TBL_PC *)bl)->fakename[0] != '\0' ? ((TBL_PC*)bl)->fakename : ((TBL_PC*)bl)->status.name;
return ((TBL_MOB*)bl)->name; case BL_MOB: return ((TBL_MOB*)bl)->name;
case BL_PC: case BL_PET: return ((TBL_PET*)bl)->pet.name;
if(strlen(((TBL_PC *)bl)->fakename)>0) case BL_HOM: return ((TBL_HOM*)bl)->homunculus.name;
return ((TBL_PC*)bl)->fakename; case BL_NPC: return ((TBL_NPC*)bl)->name;
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;
} }
return "Unknown"; return "Unknown";
} }
@ -3991,14 +3948,12 @@ int status_get_class(struct block_list *bl)
int status_get_lv(struct block_list *bl) int status_get_lv(struct block_list *bl)
{ {
nullpo_retr(0, bl); nullpo_retr(0, bl);
if(bl->type==BL_MOB) switch (bl->type) {
return ((TBL_MOB*)bl)->level; case BL_PC: return ((TBL_PC*)bl)->status.base_level;
if(bl->type==BL_PC) case BL_MOB: return ((TBL_MOB*)bl)->level;
return ((TBL_PC*)bl)->status.base_level; case BL_PET: return ((TBL_PET*)bl)->pet.level;
if(bl->type==BL_PET) case BL_HOM: return ((TBL_HOM*)bl)->homunculus.level;
return ((TBL_PET*)bl)->pet.level; }
if(bl->type==BL_HOM)
return ((TBL_HOM*)bl)->homunculus.level;
return 1; return 1;
} }
@ -4006,10 +3961,8 @@ struct regen_data *status_get_regen_data(struct block_list *bl)
{ {
nullpo_retr(NULL, bl); nullpo_retr(NULL, bl);
switch (bl->type) { switch (bl->type) {
case BL_PC: case BL_PC: return &((TBL_PC*)bl)->regen;
return &((TBL_PC*)bl)->regen; case BL_HOM: return &((TBL_HOM*)bl)->regen;
case BL_HOM:
return &((TBL_HOM*)bl)->regen;
default: default:
return NULL; return NULL;
} }
@ -4020,14 +3973,10 @@ struct status_data *status_get_status_data(struct block_list *bl)
nullpo_retr(&dummy_status, bl); nullpo_retr(&dummy_status, bl);
switch (bl->type) { switch (bl->type) {
case BL_PC: case BL_PC: return &((TBL_PC*)bl)->battle_status;
return &((TBL_PC*)bl)->battle_status; case BL_MOB: return &((TBL_MOB*)bl)->status;
case BL_MOB: case BL_PET: return &((TBL_PET*)bl)->status;
return &((TBL_MOB*)bl)->status; case BL_HOM: return &((TBL_HOM*)bl)->battle_status;
case BL_PET:
return &((TBL_PET*)bl)->status;
case BL_HOM:
return &((TBL_HOM*)bl)->battle_status;
default: default:
return &dummy_status; return &dummy_status;
} }
@ -4037,16 +3986,10 @@ struct status_data *status_get_base_status(struct block_list *bl)
{ {
nullpo_retr(NULL, bl); nullpo_retr(NULL, bl);
switch (bl->type) { switch (bl->type) {
case BL_PC: case BL_PC: return &((TBL_PC*)bl)->base_status;
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_MOB: case BL_PET: return &((TBL_PET*)bl)->db->status;
return ((TBL_MOB*)bl)->base_status? case BL_HOM: return &((TBL_HOM*)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: default:
return NULL; return NULL;
} }
@ -4227,21 +4170,15 @@ int status_isimmune(struct block_list *bl)
return 0; 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); nullpo_retr(NULL, bl);
switch (bl->type) switch (bl->type) {
{ case BL_PC: return &((TBL_PC*)bl)->vd;
case BL_PC: case BL_MOB: return ((TBL_MOB*)bl)->vd;
return &((TBL_PC*)bl)->vd; case BL_PET: return &((TBL_PET*)bl)->vd;
case BL_MOB: case BL_NPC: return ((TBL_NPC*)bl)->vd;
return ((TBL_MOB*)bl)->vd; case BL_HOM: return ((TBL_HOM*)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;
} }
return NULL; return NULL;
} }
@ -4364,14 +4301,10 @@ struct status_change *status_get_sc(struct block_list *bl)
{ {
nullpo_retr(NULL, bl); nullpo_retr(NULL, bl);
switch (bl->type) { switch (bl->type) {
case BL_MOB: case BL_PC: return &((TBL_PC*)bl)->sc;
return &((TBL_MOB*)bl)->sc; case BL_MOB: return &((TBL_MOB*)bl)->sc;
case BL_PC: case BL_NPC: return &((TBL_NPC*)bl)->sc;
return &((TBL_PC*)bl)->sc; case BL_HOM: return &((TBL_HOM*)bl)->sc;
case BL_NPC:
return &((TBL_NPC*)bl)->sc;
case BL_HOM: //[blackhole89]
return &((TBL_HOM*)bl)->sc;
} }
return NULL; return NULL;
} }

View File

@ -1366,21 +1366,17 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
ud->attacktimer=-1; ud->attacktimer=-1;
target=map_id2bl(ud->target); 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; return 0;
if(src->m != target->m || status_isdead(src) || status_isdead(target) || !status_check_skilluse(src, target, 0, 0)) if(src->m != target->m || status_isdead(src) || status_isdead(target) || !status_check_skilluse(src, target, 0, 0))
return 0; return 0; // can't attack under these conditions
sstatus = status_get_status_data(src); if(ud->skilltimer != -1 && !(sd && pc_checkskill(sd,SA_FREECAST) > 0))
return 0; // can't attack while casting
if(!battle_config.sdelay_attack_enable && if(!battle_config.sdelay_attack_enable && DIFF_TICK(ud->canact_tick,tick) > 0 && !(sd && pc_checkskill(sd,SA_FREECAST) > 0))
DIFF_TICK(ud->canact_tick,tick) > 0 && { // attacking when under cast delay has restrictions:
(!sd || pc_checkskill(sd,SA_FREECAST) <= 0)
) {
if (tid == -1) { //requested attack. if (tid == -1) { //requested attack.
if(sd) clif_skill_fail(sd,1,4,0); if(sd) clif_skill_fail(sd,1,4,0);
return 0; return 0;
@ -1394,6 +1390,7 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
return 1; return 1;
} }
sstatus = status_get_status_data(src);
range = sstatus->rhw.range; range = sstatus->rhw.range;
if(!sd || sd->status.weapon != W_BOW) range++; //Dunno why everyone but bows gets this extra 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] //Non-players use the sync packet on the walk timer. [Skotlex]
if (tid == -1 && sd) clif_fixpos(src); if (tid == -1 && sd) clif_fixpos(src);
if(DIFF_TICK(ud->attackabletime,tick) <= 0) { if(DIFF_TICK(ud->attackabletime,tick) <= 0)
if (battle_config.attack_direction_change && {
(src->type&battle_config.attack_direction_change)) { if (battle_config.attack_direction_change && (src->type&battle_config.attack_direction_change)) {
ud->dir = map_calc_dir(src, target->x,target->y ); ud->dir = map_calc_dir(src, target->x,target->y );
} }
if(ud->walktimer != -1) 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) if (sstatus->mode&MD_ASSIST && DIFF_TICK(md->last_linktime, tick) < MIN_MOBLINKTIME)
{ // Link monsters nearby [Skotlex] { // Link monsters nearby [Skotlex]
md->last_linktime = tick; md->last_linktime = tick;
map_foreachinrange(mob_linksearch, src, md->db->range2, map_foreachinrange(mob_linksearch, src, md->db->range2, BL_MOB, md->class_, target, tick);
BL_MOB, md->class_, target, tick);
} }
} }
if(src->type == BL_PET && pet_attackskill((TBL_PET*)src, target->id)) if(src->type == BL_PET && pet_attackskill((TBL_PET*)src, target->id))