Skip to content

Commit

Permalink
Hercules Renewal'd Pin Code
Browse files Browse the repository at this point in the history
Feature is not, I repeat, NOT complete. the decryption is not fully functional which leads to dial values  different from the ones the player used.
Credits:
lemongrass3110 for the base
yommy for the packets
LightFighter for the decrypt function (altho its not stable :P)

Signed-off-by: shennetsind <ind@henn.et>
  • Loading branch information
shennetsind committed Mar 9, 2013
1 parent bb0f807 commit d2d734c
Show file tree
Hide file tree
Showing 19 changed files with 456 additions and 61 deletions.
21 changes: 21 additions & 0 deletions conf/char-server.conf
Expand Up @@ -159,4 +159,25 @@ char_del_delay: 86400
// What folder the DB files are in (item_db.txt, etc.)
db_path: db

//==================================================================
// Pincode system -- INCOMPLETE / BROKEN
//==================================================================

// A window is opened before you can select your character and you will have to enter a pincode by using only your mouse
// NOTE: Requires client 2011-03-09aragexeRE or newer.
// 0: disabled
// 1: enabled
pincode_enabled: 0

// How often does a user have to change his pincode?
// Default: 0
// 0: never
// X: every X minutes
pincode_changetime: 0

// How often can a user enter the wrong password?
// Default: 3
// NOTE: The maximum on clientside is 3
pincode_maxtry: 3

import: conf/import/char_conf.txt
6 changes: 5 additions & 1 deletion sql-files/main.sql
Expand Up @@ -438,7 +438,9 @@ CREATE TABLE IF NOT EXISTS `login` (
`lastlogin` datetime NOT NULL default '0000-00-00 00:00:00',
`last_ip` varchar(100) NOT NULL default '',
`birthdate` DATE NOT NULL DEFAULT '0000-00-00',
`character_slots` TINYINT( 3 ) unsigned NOT NULL,
`character_slots` TINYINT( 3 ) unsigned NOT NULL default '0',
`pincode` varchar(4) NOT NULL default '',
`pincode_change` int(11) unsigned NOT NULL default '0',
PRIMARY KEY (`account_id`),
KEY `name` (`userid`)
) ENGINE=MyISAM AUTO_INCREMENT=2000000;
Expand Down Expand Up @@ -648,6 +650,8 @@ CREATE TABLE IF NOT EXISTS `sql_updates` (
INSERT INTO `sql_updates` (`timestamp`) VALUES (1360858500);
INSERT INTO `sql_updates` (`timestamp`) VALUES (1360951560);
INSERT INTO `sql_updates` (`timestamp`) VALUES (1362445531);
INSERT INTO `sql_updates` (`timestamp`) VALUES (1362528000);
INSERT INTO `sql_updates` (`timestamp`) VALUES (1362794218);

--
-- Table structure for table `sstatus`
Expand Down
@@ -1,7 +1,9 @@
-- This script resets all quests that were done by your users before this revision
#1362528000
-- This script resets all dewata quests that were done by your users before this revision
-- Author: Euphy
DELETE FROM `quest` WHERE `quest_id` > 5034 AND `quest_id` < 5055;
DELETE FROM `quest` WHERE `quest_id` > 9154 AND `quest_id` < 9166;
DELETE FROM `global_reg_value` WHERE `str` = 'dewata_gatti';
DELETE FROM `global_reg_value` WHERE `str` = 'dewata_legend';
DELETE FROM `global_reg_value` WHERE `str` = 'dewata_oldman';
INSERT INTO `sql_updates` (`timestamp`) VALUES (1362528000);
4 changes: 4 additions & 0 deletions sql-files/upgrades/2013-03-09--01-56.sql
@@ -0,0 +1,4 @@
#1362794218
ALTER TABLE `login` ADD COLUMN `pincode` varchar(4) NOT NULL DEFAULT '';
ALTER TABLE `login` ADD COLUMN `pincode_change` int(11) unsigned NOT NULL DEFAULT '0';
INSERT INTO `sql_updates` (`timestamp`) VALUES (1362794218);
4 changes: 3 additions & 1 deletion sql-files/upgrades/index.txt
@@ -1,3 +1,5 @@
2013-02-14--16-15.sql
2013-02-15--18-06.sql
2013-03-05--01-05.sql
2013-03-05--01-05.sql
2013-03-06--00-00.sql
2013-03-09--01-56.sql
2 changes: 2 additions & 0 deletions src/char/CMakeLists.txt
Expand Up @@ -23,6 +23,7 @@ set( SQL_CHAR_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/int_quest.h"
"${CMAKE_CURRENT_SOURCE_DIR}/int_storage.h"
"${CMAKE_CURRENT_SOURCE_DIR}/inter.h"
"${CMAKE_CURRENT_SOURCE_DIR}/pincode.h"
)
set( SQL_CHAR_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/char.c"
Expand All @@ -37,6 +38,7 @@ set( SQL_CHAR_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/int_quest.c"
"${CMAKE_CURRENT_SOURCE_DIR}/int_storage.c"
"${CMAKE_CURRENT_SOURCE_DIR}/inter.c"
"${CMAKE_CURRENT_SOURCE_DIR}/pincode.c"
)
set( DEPENDENCIES common_sql )
set( LIBRARIES ${GLOBAL_LIBRARIES} )
Expand Down
4 changes: 2 additions & 2 deletions src/char/Makefile.in
Expand Up @@ -16,8 +16,8 @@ COMMON_SQL_OBJ = ../common/obj_sql/sql.o
COMMON_H = ../common/sql.h

CHAR_OBJ = obj_sql/char.o obj_sql/inter.o obj_sql/int_party.o obj_sql/int_guild.o \
obj_sql/int_storage.o obj_sql/int_pet.o obj_sql/int_homun.o obj_sql/int_mail.o obj_sql/int_auction.o obj_sql/int_quest.o obj_sql/int_mercenary.o obj_sql/int_elemental.o
CHAR_H = char.h inter.h int_party.h int_guild.h int_storage.h int_pet.h int_homun.h int_mail.h int_auction.h int_quest.h int_mercenary.h int_elemental.h
obj_sql/int_storage.o obj_sql/int_pet.o obj_sql/int_homun.o obj_sql/int_mail.o obj_sql/int_auction.o obj_sql/int_quest.o obj_sql/int_mercenary.o obj_sql/int_elemental.o obj_sql/pincode.o
CHAR_H = char.h inter.h int_party.h int_guild.h int_storage.h int_pet.h int_homun.h int_mail.h int_auction.h int_quest.h int_mercenary.h int_elemental.h pincode.h

HAVE_MYSQL=@HAVE_MYSQL@
ifeq ($(HAVE_MYSQL),yes)
Expand Down
106 changes: 71 additions & 35 deletions src/char/char.c
Expand Up @@ -21,6 +21,7 @@
#include "int_storage.h"
#include "char.h"
#include "inter.h"
#include "pincode.h"

#include <sys/types.h>
#include <time.h>
Expand Down Expand Up @@ -83,7 +84,7 @@ struct mmo_map_server {
unsigned short map[MAX_MAP_PER_SERVER];
} server[MAX_MAP_SERVERS];

int login_fd=-1, char_fd=-1;
int char_fd=-1;
char userid[24];
char passwd[24];
char server_name[20];
Expand Down Expand Up @@ -121,20 +122,6 @@ struct s_subnet {
} subnet[16];
int subnet_count = 0;

struct char_session_data {
bool auth; // whether the session is authed or not
int account_id, login_id1, login_id2, sex;
int found_char[MAX_CHARS]; // ids of chars on this account
char email[40]; // e-mail (default: a@a.com) by [Yor]
time_t expiration_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
int group_id; // permission
uint8 char_slots;
uint32 version;
uint8 clienttype;
char new_name[NAME_LENGTH];
char birthdate[10+1]; // YYYY-MM-DD
};

int max_connect_user = -1;
int gm_allow_group = -1;
int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
Expand Down Expand Up @@ -2149,13 +2136,12 @@ int parse_fromlogin(int fd) {
break;

case 0x2717: // account data
if (RFIFOREST(fd) < 63)
if (RFIFOREST(fd) < 72)
return 0;

// find the authenticated session with this account id
ARR_FIND( 0, fd_max, i, session[i] && (sd = (struct char_session_data*)session[i]->session_data) && sd->auth && sd->account_id == RFIFOL(fd,2) );
if( i < fd_max )
{
if( i < fd_max ) {
int server_id;
memcpy(sd->email, RFIFOP(fd,6), 40);
sd->expiration_time = (time_t)RFIFOL(fd,46);
Expand All @@ -2167,6 +2153,8 @@ int parse_fromlogin(int fd) {
} else if ( !sd->char_slots )/* no value aka 0 in sql */
sd->char_slots = MAX_CHARS;/* cap to maximum */
safestrncpy(sd->birthdate, (const char*)RFIFOP(fd,52), sizeof(sd->birthdate));
safestrncpy(sd->pincode, (const char*)RFIFOP(fd,63), sizeof(sd->pincode));
sd->pincode_change = RFIFOL(fd,68);
ARR_FIND( 0, ARRAYLENGTH(server), server_id, server[server_id].fd > 0 && server[server_id].map[0] );
// continued from char_auth_ok...
if( server_id == ARRAYLENGTH(server) || //server not online, bugreport:2359
Expand All @@ -2180,19 +2168,12 @@ int parse_fromlogin(int fd) {
} else {
// send characters to player
mmo_char_send006b(i, sd);
#if PACKETVER >= 20110309
// PIN code system, disabled
WFIFOHEAD(i, 12);
WFIFOW(i, 0) = 0x08B9;
WFIFOW(i, 2) = 0;
WFIFOW(i, 4) = 0;
WFIFOL(i, 6) = sd->account_id;
WFIFOW(i, 10) = 0;
WFIFOSET(i, 12);
#if PACKETVER >= 20110309
pincode->handle(i, sd);
#endif
}
}
RFIFOSKIP(fd,63);
RFIFOSKIP(fd,72);
break;

// login-server alive packet
Expand Down Expand Up @@ -4190,6 +4171,50 @@ int parse_char(int fd)
}
return 0; // avoid processing of followup packets here

// checks the entered pin
case 0x8b8:
if( RFIFOREST(fd) < 10 )
return 0;

if( RFIFOL(fd,2) == sd->account_id )
pincode->check( fd, sd );

RFIFOSKIP(fd,10);
break;

// request for PIN window
case 0x8c5:
if( RFIFOREST(fd) < 6 )
return 0;

if( RFIFOL(fd,2) == sd->account_id )
pincode->state( fd, sd, PINCODE_NOTSET );

RFIFOSKIP(fd,6);
break;

// pincode change request
case 0x8be:
if( RFIFOREST(fd) < 14 )
return 0;

if( RFIFOL(fd,2) == sd->account_id )
pincode->change( fd, sd );

RFIFOSKIP(fd,14);
break;

// activate PIN system and set first PIN
case 0x8ba:
if( RFIFOREST(fd) < 10 )
return 0;

if( RFIFOL(fd,2) == sd->account_id )
pincode->new( fd, sd );

RFIFOSKIP(fd,10);
break;

// unknown packet received
default:
ShowError("parse_char: Received unknown packet "CL_WHITE"0x%x"CL_RESET" from ip '"CL_WHITE"%s"CL_RESET"'! Disconnecting!\n", RFIFOW(fd,0), ip2str(ipl, NULL));
Expand Down Expand Up @@ -4544,7 +4569,17 @@ void sql_config_read(const char* cfgName)
fclose(fp);
ShowInfo("Done reading %s.\n", cfgName);
}

void char_config_dispatch(char *w1, char *w2) {
bool (*dispatch_to[]) (char *w1, char *w2) = {
/* as many as it needs */
pincode->config_read
};
int i, len = ARRAYLENGTH(dispatch_to);
for(i = 0; i < len; i++) {
if( (*dispatch_to[i])(w1,w2) )
break;/* we found who this belongs to, can stop */
}
}
int char_config_read(const char* cfgName)
{
char line[1024], w1[1024], w2[1024];
Expand Down Expand Up @@ -4695,7 +4730,8 @@ int char_config_read(const char* cfgName)
guild_exp_rate = atoi(w2);
} else if (strcmpi(w1, "import") == 0) {
char_config_read(w2);
}
} else
char_config_dispatch(w1,w2);
}
fclose(fp);

Expand Down Expand Up @@ -4774,6 +4810,8 @@ int do_init(int argc, char **argv)
mapindex_init();
start_point.map = mapindex_name2id("new_zone01");

pincode_defaults();

char_config_read((argc < 2) ? CHAR_CONF_NAME : argv[1]);
char_lan_config_read((argc > 3) ? argv[3] : LAN_CONF_NAME);
sql_config_read(SQL_CONF_NAME);
Expand All @@ -4783,16 +4821,15 @@ int do_init(int argc, char **argv)
ShowNotice("Please edit your 'login' table to create a proper inter-server user/password (gender 'S')\n");
ShowNotice("And then change the user/password to use in conf/char_athena.conf (or conf/import/char_conf.txt)\n");
}

inter_init_sql((argc > 2) ? argv[2] : inter_cfgName); // inter server configuration

auth_db = idb_alloc(DB_OPT_RELEASE_DATA);
online_char_db = idb_alloc(DB_OPT_RELEASE_DATA);
mmo_char_sql_init();
char_read_fame_list(); //Read fame lists.

if ((naddr_ != 0) && (!login_ip || !char_ip))
{
if ((naddr_ != 0) && (!login_ip || !char_ip)) {
char ip_str[16];
ip2str(addr_[0], ip_str);

Expand Down Expand Up @@ -4824,8 +4861,7 @@ int do_init(int argc, char **argv)
add_timer_func_list(online_data_cleanup, "online_data_cleanup");
add_timer_interval(gettick() + 1000, online_data_cleanup, 0, 0, 600 * 1000);

if( console )
{
if( console ) {
//##TODO invoke a CONSOLE_START plugin event
}

Expand Down
23 changes: 20 additions & 3 deletions src/char/char.h
Expand Up @@ -7,15 +7,32 @@
#include "../config/core.h"
#include "../common/core.h" // CORE_ST_LAST

enum E_CHARSERVER_ST
{
enum E_CHARSERVER_ST {
CHARSERVER_ST_RUNNING = CORE_ST_LAST,
CHARSERVER_ST_SHUTDOWN,
CHARSERVER_ST_LAST
};

struct mmo_charstatus;

struct char_session_data {
bool auth; // whether the session is authed or not
int account_id, login_id1, login_id2, sex;
int found_char[MAX_CHARS]; // ids of chars on this account
char email[40]; // e-mail (default: a@a.com) by [Yor]
time_t expiration_time; // # of seconds 1/1/1970 (timestamp): Validity limit of the account (0 = unlimited)
int group_id; // permission
uint8 char_slots;
uint32 version;
uint8 clienttype;
char pincode[4+1];
uint16 pincode_seed;
uint16 pincode_try;
uint32 pincode_change;
char new_name[NAME_LENGTH];
char birthdate[10+1]; // YYYY-MM-DD
};

#define MAX_MAP_SERVERS 30

#define DEFAULT_AUTOSAVE_INTERVAL 300*1000
Expand All @@ -39,7 +56,7 @@ int char_family(int pl1,int pl2,int pl3);

int request_accreg2(int account_id, int char_id);
int save_accreg2(unsigned char* buf, int len);

int login_fd;
extern int char_name_option;
extern char char_name_letters[];
extern bool char_gm_read;
Expand Down

2 comments on commit d2d734c

@euphyy
Copy link
Contributor

@euphyy euphyy commented on d2d734c Mar 10, 2013

Choose a reason for hiding this comment

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

There's a typo in login/account_sql.c, line 618:
... sizeof(acc->pincode)
Should be:
... strlen(acc->pincode)
http://trac.rathena.org/changeset/17187/rathena/trunk/src/login/account_sql.c

@shennetsind
Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you very much. Fixed in ebc14bc

Please sign in to comment.