Skip to content

Commit

Permalink
Initial support for newer packet versions (#4944)
Browse files Browse the repository at this point in the history
Basic support for packets up to April 2020
Changing the default packet version to 2020-04-01

Thanks to everyone involved!
  • Loading branch information
Lemongrass3110 committed Jun 3, 2020
1 parent 929c30c commit 45cd580
Show file tree
Hide file tree
Showing 34 changed files with 6,952 additions and 2,697 deletions.
7 changes: 7 additions & 0 deletions conf/battle/client.conf
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,10 @@ spawn_direction: no
// kRO removed the packet and this re-enables the message.
// Official: Disabled.
mvp_exp_reward_message: no

// Send ping timer
// Interval in seconds for each timer invoke.
ping_timer_inverval: 30

// Send packets timeout in seconds before ping packet can be sent.
ping_time: 20
1 change: 1 addition & 0 deletions sql-files/main.sql
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ CREATE TABLE IF NOT EXISTS `char` (
`uniqueitem_counter` int(11) unsigned NOT NULL default '0',
`sex` ENUM('M','F','U') NOT NULL default 'U',
`hotkey_rowshift` tinyint(3) unsigned NOT NULL default '0',
`hotkey_rowshift2` tinyint(3) unsigned NOT NULL default '0',
`clan_id` int(11) unsigned NOT NULL default '0',
`last_login` datetime DEFAULT NULL,
`title_id` INT(11) unsigned NOT NULL default '0',
Expand Down
1 change: 1 addition & 0 deletions sql-files/upgrades/upgrade_20200603.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `char` ADD COLUMN `hotkey_rowshift2` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `hotkey_rowshift`;
18 changes: 11 additions & 7 deletions src/char/char.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ int char_mmo_char_tosql(uint32 char_id, struct mmo_charstatus* p){
(p->rename != cp->rename) || (p->robe != cp->robe) || (p->character_moves != cp->character_moves) ||
(p->unban_time != cp->unban_time) || (p->font != cp->font) || (p->uniqueitem_counter != cp->uniqueitem_counter) ||
(p->hotkey_rowshift != cp->hotkey_rowshift) || (p->clan_id != cp->clan_id ) || (p->title_id != cp->title_id) ||
(p->show_equip != cp->show_equip)
(p->show_equip != cp->show_equip) || (p->hotkey_rowshift2 != cp->hotkey_rowshift2)
)
{ //Save status
if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `base_level`='%d', `job_level`='%d',"
Expand All @@ -310,7 +310,7 @@ int char_mmo_char_tosql(uint32 char_id, struct mmo_charstatus* p){
"`weapon`='%d',`shield`='%d',`head_top`='%d',`head_mid`='%d',`head_bottom`='%d',"
"`last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d', `rename`='%d',"
"`delete_date`='%lu',`robe`='%d',`moves`='%d',`font`='%u',`uniqueitem_counter`='%u',"
"`hotkey_rowshift`='%d', `clan_id`='%d', `title_id`='%lu', `show_equip`='%d'"
"`hotkey_rowshift`='%d', `clan_id`='%d', `title_id`='%lu', `show_equip`='%d', `hotkey_rowshift2`='%d'"
" WHERE `account_id`='%d' AND `char_id` = '%d'",
schema_config.char_db, p->base_level, p->job_level,
p->base_exp, p->job_exp, p->zeny,
Expand All @@ -322,7 +322,7 @@ int char_mmo_char_tosql(uint32 char_id, struct mmo_charstatus* p){
mapindex_id2name(p->save_point.map), p->save_point.x, p->save_point.y, p->rename,
(unsigned long)p->delete_date, // FIXME: platform-dependent size
p->robe, p->character_moves, p->font, p->uniqueitem_counter,
p->hotkey_rowshift, p->clan_id, p->title_id, p->show_equip,
p->hotkey_rowshift, p->clan_id, p->title_id, p->show_equip, p->hotkey_rowshift2,
p->account_id, p->char_id) )
{
Sql_ShowDebug(sql_handle);
Expand Down Expand Up @@ -924,7 +924,8 @@ int char_mmo_chars_fromsql(struct char_session_data* sd, uint8* buf, uint8* coun
"`str`,`agi`,`vit`,`int`,`dex`,`luk`,`max_hp`,`hp`,`max_sp`,`sp`,"
"`status_point`,`skill_point`,`option`,`karma`,`manner`,`hair`,`hair_color`,"
"`clothes_color`,`body`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`,`last_map`,`rename`,`delete_date`,"
"`robe`,`moves`,`unban_time`,`font`,`uniqueitem_counter`,`sex`,`hotkey_rowshift`,`title_id`,`show_equip`"
"`robe`,`moves`,`unban_time`,`font`,`uniqueitem_counter`,`sex`,`hotkey_rowshift`,`title_id`,`show_equip`,"
"`hotkey_rowshift2`"
" FROM `%s` WHERE `account_id`='%d' AND `char_num` < '%d'", schema_config.char_db, sd->account_id, MAX_CHARS)
|| SQL_ERROR == SqlStmt_Execute(stmt)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &p.char_id, 0, NULL, NULL)
Expand Down Expand Up @@ -972,6 +973,7 @@ int char_mmo_chars_fromsql(struct char_session_data* sd, uint8* buf, uint8* coun
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 42, SQLDT_UCHAR, &p.hotkey_rowshift, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 43, SQLDT_ULONG, &p.title_id, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 44, SQLDT_UINT16, &p.show_equip, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 45, SQLDT_UCHAR, &p.hotkey_rowshift2, 0, NULL, NULL)
)
{
SqlStmt_ShowDebug(stmt);
Expand Down Expand Up @@ -1039,7 +1041,7 @@ int char_mmo_char_fromsql(uint32 char_id, struct mmo_charstatus* p, bool load_ev
"`status_point`,`skill_point`,`option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`,`homun_id`,`elemental_id`,`hair`,"
"`hair_color`,`clothes_color`,`body`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`,`last_map`,`last_x`,`last_y`,"
"`save_map`,`save_x`,`save_y`,`partner_id`,`father`,`mother`,`child`,`fame`,`rename`,`delete_date`,`robe`, `moves`,"
"`unban_time`,`font`,`uniqueitem_counter`,`sex`,`hotkey_rowshift`,`clan_id`,`title_id`,`show_equip`"
"`unban_time`,`font`,`uniqueitem_counter`,`sex`,`hotkey_rowshift`,`clan_id`,`title_id`,`show_equip`,`hotkey_rowshift2`"
" FROM `%s` WHERE `char_id`=? LIMIT 1", schema_config.char_db)
|| SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0)
|| SQL_ERROR == SqlStmt_Execute(stmt)
Expand Down Expand Up @@ -1105,6 +1107,7 @@ int char_mmo_char_fromsql(uint32 char_id, struct mmo_charstatus* p, bool load_ev
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 59, SQLDT_INT, &p->clan_id, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 60, SQLDT_ULONG, &p->title_id, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 61, SQLDT_UINT16, &p->show_equip, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 62, SQLDT_UCHAR, &p->hotkey_rowshift2, 0, NULL, NULL)
)
{
SqlStmt_ShowDebug(stmt);
Expand Down Expand Up @@ -1211,7 +1214,7 @@ int char_mmo_char_fromsql(uint32 char_id, struct mmo_charstatus* p, bool load_ev

while( SQL_SUCCESS == SqlStmt_NextRow(stmt) )
{
if( hotkey_num >= 0 && hotkey_num < MAX_HOTKEYS )
if( hotkey_num >= 0 && hotkey_num < MAX_HOTKEYS_DB )
memcpy(&p->hotkeys[hotkey_num], &tmp_hotkey, sizeof(tmp_hotkey));
else
ShowWarning("mmo_char_fromsql: ignoring invalid hotkey (hotkey=%d,type=%u,id=%u,lv=%u) of character %s (AID=%d,CID=%d)\n", hotkey_num, tmp_hotkey.type, tmp_hotkey.id, tmp_hotkey.lv, p->name, p->account_id, p->char_id);
Expand Down Expand Up @@ -2318,7 +2321,8 @@ bool char_checkdb(void){
"`guild_id`,`pet_id`,`homun_id`,`elemental_id`,`hair`,`hair_color`,`clothes_color`,`weapon`,"
"`shield`,`head_top`,`head_mid`,`head_bottom`,`robe`,`last_map`,`last_x`,`last_y`,`save_map`,"
"`save_x`,`save_y`,`partner_id`,`online`,`father`,`mother`,`child`,`fame`,`rename`,`delete_date`,"
"`moves`,`unban_time`,`font`,`sex`,`hotkey_rowshift`,`clan_id`,`last_login`,`title_id`,`show_equip`"
"`moves`,`unban_time`,`font`,`sex`,`hotkey_rowshift`,`clan_id`,`last_login`,`title_id`,`show_equip`,"
"`hotkey_rowshift2`"
" FROM `%s` LIMIT 1;", schema_config.char_db) ){
Sql_ShowDebug(sql_handle);
return false;
Expand Down
9 changes: 8 additions & 1 deletion src/common/mmo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
#define MAX_HOTKEYS 38
#endif

#if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
#define MAX_HOTKEYS_DB ((MAX_HOTKEYS) * 2)
#else
#define MAX_HOTKEYS_DB MAX_HOTKEYS
#endif

#define MAX_MAP_PER_SERVER 1500 /// Maximum amount of maps available on a server
#define MAX_INVENTORY 100 ///Maximum items in player inventory
/** Max number of characters per account. Note that changing this setting alone is not enough if the client is not hexed to support more characters as well.
Expand Down Expand Up @@ -518,7 +524,7 @@ struct mmo_charstatus {

struct s_friend friends[MAX_FRIENDS]; //New friend system [Skotlex]
#ifdef HOTKEY_SAVING
struct hotkey hotkeys[MAX_HOTKEYS];
struct hotkey hotkeys[MAX_HOTKEYS_DB];
#endif
bool show_equip,allow_party;
short rename;
Expand All @@ -536,6 +542,7 @@ struct mmo_charstatus {
uint32 uniqueitem_counter;

unsigned char hotkey_rowshift;
unsigned char hotkey_rowshift2;
unsigned long title_id;
};

Expand Down
4 changes: 4 additions & 0 deletions src/common/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ int send_from_fifo(int fd)

if( len > 0 )
{
session[fd]->wdata_tick = last_tick;

// some data could not be transferred?
// shift unsent data to the beginning of the queue
if( (size_t)len < session[fd]->wdata_size )
Expand Down Expand Up @@ -587,6 +589,7 @@ int make_listen_bind(uint32 ip, uint16 port)
create_session(fd, connect_client, null_send, null_parse);
session[fd]->client_addr = 0; // just listens
session[fd]->rdata_tick = 0; // disable timeouts on this socket
session[fd]->wdata_tick = 0;

return fd;
}
Expand Down Expand Up @@ -727,6 +730,7 @@ static int create_session(int fd, RecvFunc func_recv, SendFunc func_send, ParseF
session[fd]->func_send = func_send;
session[fd]->func_parse = func_parse;
session[fd]->rdata_tick = last_tick;
session[fd]->wdata_tick = last_tick;
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/common/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct socket_data
size_t rdata_size, wdata_size;
size_t rdata_pos;
time_t rdata_tick; // time of last recv (for detecting timeouts); zero when timeout is disabled
time_t wdata_tick; // time of last send (for detecting timeouts);

RecvFunc func_recv;
SendFunc func_send;
Expand Down
19 changes: 18 additions & 1 deletion src/config/packets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// Do NOT edit this line! To set your client version, please do this instead:
/// In Windows: Add this line in your src\custom\defines_pre.hpp file: #define PACKETVER YYYYMMDD
/// In Linux: The same as above or run the following command: ./configure --enable-packetver=YYYYMMDD
#define PACKETVER 20180620
#define PACKETVER 20200401
#endif

#ifndef PACKETVER_RE
Expand All @@ -24,6 +24,23 @@
#endif
#endif

#ifndef PACKETVER_RE
#define PACKETVER_MAIN_NUM PACKETVER

// Undefine all sakray server definitions
#undef PACKETVER_RE
#undef PACKETVER_RE_NUM
#else
// Undefine existing definition
#undef PACKETVER_RE

#define PACKETVER_RE PACKETVER
#define PACKETVER_RE_NUM PACKETVER

// Undefine all main server definitions
#undef PACKETVER_MAIN_NUM
#endif

#if PACKETVER >= 20110817
/// Comment to disable the official packet obfuscation support.
/// This requires PACKETVER 2011-08-17 or newer.
Expand Down
18 changes: 18 additions & 0 deletions src/login/loginclif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,20 @@ static int logclif_parse_reqcharconnec(int fd, struct login_session_data *sd, ch
return 1;
}

int logclif_parse_otp_login( int fd, struct login_session_data* sd ){
RFIFOSKIP( fd, 68 );

WFIFOHEAD( fd, 34 );
WFIFOW( fd, 0 ) = 0xae3;
WFIFOW( fd, 2 ) = 34;
WFIFOL( fd, 4 ) = 0; // normal login
safestrncpy( WFIFOCP( fd, 8 ), "S1000", 6 );
safestrncpy( WFIFOCP( fd, 28 ), "token", 6 );
WFIFOSET( fd, 34 );

return 1;
}

/**
* Entry point from client to log-server.
* Function that checks incoming command, then splits it to the correct handler.
Expand Down Expand Up @@ -521,6 +535,10 @@ int logclif_parse(int fd) {
break;
// Sending request of the coding key
case 0x01db: next = logclif_parse_reqkey(fd, sd); break;
// OTP token login
case 0x0acf:
next = logclif_parse_otp_login( fd, sd );
break;
// Connection request of a char-server
case 0x2710: logclif_parse_reqcharconnec(fd,sd, ip); return 0; // processing will continue elsewhere
default:
Expand Down
2 changes: 2 additions & 0 deletions src/map/battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8954,6 +8954,8 @@ static const struct _battle_data {
{ "bgqueue_nowarp_mapflag", &battle_config.bgqueue_nowarp_mapflag, 0, 0, 1, },
{ "homunculus_exp_gain", &battle_config.homunculus_exp_gain, 10, 0, 100, },
{ "rental_item_novalue", &battle_config.rental_item_novalue, 1, 0, 1, },
{ "ping_timer_inverval", &battle_config.ping_timer_interval, 30, 0, 99999999, },
{ "ping_time", &battle_config.ping_time, 20, 0, 99999999, },

#include "../custom/battle_config_init.inc"
};
Expand Down
2 changes: 2 additions & 0 deletions src/map/battle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ struct Battle_Config
int bgqueue_nowarp_mapflag;
int homunculus_exp_gain;
int rental_item_novalue;
int ping_timer_interval;
int ping_time;

#include "../custom/battle_config_struct.inc"
};
Expand Down
Loading

3 comments on commit 45cd580

@Masao87
Copy link

@Masao87 Masao87 commented on 45cd580 Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any info on when the "new" Lvl. 185 red aura is supported?

Otherwise thanks a lot for all the hard work you guys put into this, works great <3

@Lemongrass3110
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any info on when the "new" Lvl. 185 red aura is supported?

Otherwise thanks a lot for all the hard work you guys put into this, works great <3

One step after each other. :) But you could make use of #4377 or any unofficial exp table to support it in the meantime.

@qwerty7vp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any info on when the "new" Lvl. 185 red aura is supported?

Otherwise thanks a lot for all the hard work you guys put into this, works great <3

you meant this ?

image

if yes, it was working even without this commit

Please sign in to comment.