Explorar o código

-Apply Lemongrass upd for pincode wich give pincode size > 4 possibility.
-Fix bugreport:7423 where pincode return invalide number for unix sys.
-Fix chan system leaks from iterator and incorect left count.
-Fix callfunc reallocating.
-Still leaking somewhere =(

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@17240 54d463be-8e91-2dee-dedb-b68131a5f0ec

glighta %!s(int64=12) %!d(string=hai) anos
pai
achega
bda715f6fe
Modificáronse 7 ficheiros con 77 adicións e 61 borrados
  1. 51 38
      src/char/char.c
  2. 2 0
      src/common/mmo.h
  3. 1 1
      src/login/account.h
  4. 4 3
      src/login/login.c
  5. 2 2
      src/map/clif.c
  6. 13 15
      src/map/map.c
  7. 4 2
      src/map/script.c

+ 51 - 38
src/char/char.c

@@ -13,6 +13,7 @@
 #include "../common/timer.h"
 #include "../common/utils.h"
 #include "../common/cli.h"
+#include "../common/random.h"
 #include "int_guild.h"
 #include "int_homun.h"
 #include "int_mercenary.h"
@@ -29,6 +30,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <malloc.h>
 
 #define CHAR_MAX_MSG 300
 static char* msg_table[CHAR_MAX_MSG]; // Login Server messages_conf
@@ -132,8 +134,8 @@ struct char_session_data {
 	char new_name[NAME_LENGTH];
 	char birthdate[10+1];  // YYYY-MM-DD
 	// Pincode system
-	char pincode[4+1];
-	uint16 pincode_seed;
+	char pincode[PINCODE_LENGTH+1];
+	uint32 pincode_seed;
 	time_t pincode_change;
 	uint16 pincode_try;
 	// Addon system
@@ -168,7 +170,7 @@ void pincode_setnew( int fd, struct char_session_data* sd );
 void pincode_sendstate( int fd, struct char_session_data* sd, uint16 state );
 void pincode_notifyLoginPinUpdate( int account_id, char* pin );
 void pincode_notifyLoginPinError( int account_id );
-void pincode_decrypt( unsigned long userSeed, char* pin );
+void pincode_decrypt( uint32 userSeed, char* pin );
 int pincode_compare( int fd, struct char_session_data* sd, char* pin );
 
 // Addon system
@@ -4275,10 +4277,8 @@ int parse_char(int fd)
 			if( RFIFOREST(fd) < 10 )
 				return 0;
 
-			if( RFIFOL(fd,2) != sd->account_id )
-				break;
-
-			pincode_check( fd, sd );
+			if( pincode_enabled && RFIFOL(fd,2) == sd->account_id )
+				pincode_check( fd, sd );
 
 			RFIFOSKIP(fd,10);
 		break;
@@ -4288,13 +4288,12 @@ int parse_char(int fd)
 			if( RFIFOREST(fd) < 6 )
 				return 0;
 
-			if( RFIFOL(fd,2) != sd->account_id )
-				break;
-
-			if( strlen( sd->pincode ) <= 0 ){
-				pincode_sendstate( fd, sd, PINCODE_NEW );
-			}else{
-				pincode_sendstate( fd, sd, PINCODE_ASK );
+			if( pincode_enabled && RFIFOL(fd,2) == sd->account_id ){
+				if( strlen( sd->pincode ) <= 0 ){
+					pincode_sendstate( fd, sd, PINCODE_NEW );
+				}else{
+					pincode_sendstate( fd, sd, PINCODE_ASK );
+				}
 			}
 
 			RFIFOSKIP(fd,6);
@@ -4305,10 +4304,8 @@ int parse_char(int fd)
 			if( RFIFOREST(fd) < 14 )
 				return 0;
 
-			if( RFIFOL(fd,2) != sd->account_id )
-				break;
-
-			pincode_change( fd, sd );
+			if( pincode_enabled && RFIFOL(fd,2) == sd->account_id )
+				pincode_change( fd, sd );
 
 			RFIFOSKIP(fd,14);
 		break;
@@ -4318,10 +4315,8 @@ int parse_char(int fd)
 			if( RFIFOREST(fd) < 10 )
 				return 0;
 
-			if( RFIFOL(fd,2) != sd->account_id )
-				break;
-
-			pincode_setnew( fd, sd );
+			if( pincode_enabled && RFIFOL(fd,2) == sd->account_id )
+				pincode_setnew( fd, sd );
 
 			RFIFOSKIP(fd,10);
 		break;
@@ -4520,8 +4515,11 @@ int check_connect_login_server(int tid, unsigned int tick, int id, intptr_t data
 //Pincode system
 //------------------------------------------------
 void pincode_check( int fd, struct char_session_data* sd ){
-	char pin[5] = "\0\0\0\0";
-	strncpy((char*)pin, (char*)RFIFOP(fd, 6), 4+1);
+	char pin[PINCODE_LENGTH+1];
+
+	memset(pin,0,PINCODE_LENGTH+1);
+
+	strncpy((char*)pin, (char*)RFIFOP(fd, 6), PINCODE_LENGTH);
 
 	pincode_decrypt(sd->pincode_seed, pin );
 
@@ -4546,27 +4544,33 @@ int pincode_compare( int fd, struct char_session_data* sd, char* pin ){
 }
 
 void pincode_change( int fd, struct char_session_data* sd ){
-	char oldpin[5] = "\0\0\0\0";
-	char newpin[5] = "\0\0\0\0";
+	char oldpin[PINCODE_LENGTH+1];
+	char newpin[PINCODE_LENGTH+1];
 
-	strncpy(oldpin, (char*)RFIFOP(fd,6), 4+1);
+	memset(oldpin,0,PINCODE_LENGTH+1);
+	memset(newpin,0,PINCODE_LENGTH+1);
+
+	strncpy(oldpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH);
 	pincode_decrypt(sd->pincode_seed,oldpin);
 
 	if( !pincode_compare( fd, sd, oldpin ) )
 		return;
 
-	strncpy(newpin, (char*)RFIFOP(fd,10), 4+1);
+	strncpy(newpin, (char*)RFIFOP(fd,10), PINCODE_LENGTH);
 	pincode_decrypt(sd->pincode_seed,newpin);
 
 	pincode_notifyLoginPinUpdate( sd->account_id, newpin );
+	strncpy(sd->pincode, newpin, sizeof(newpin));
 
 	pincode_sendstate( fd, sd, PINCODE_PASSED );
 }
 
 void pincode_setnew( int fd, struct char_session_data* sd ){
-	char newpin[5] = "\0\0\0\0";
+	char newpin[PINCODE_LENGTH+1];
+
+	memset(newpin,0,PINCODE_LENGTH+1);
 
-	strncpy( newpin, (char*)RFIFOP(fd,6), 4+1 );
+	strncpy( newpin, (char*)RFIFOP(fd,6), PINCODE_LENGTH );
 	pincode_decrypt( sd->pincode_seed, newpin );
 
 	pincode_notifyLoginPinUpdate( sd->account_id, newpin );
@@ -4587,7 +4591,7 @@ void pincode_setnew( int fd, struct char_session_data* sd ){
 void pincode_sendstate( int fd, struct char_session_data* sd, uint16 state ){
 	WFIFOHEAD(fd, 12);
 	WFIFOW(fd, 0) = 0x8b9;
-	WFIFOL(fd, 2) = sd->pincode_seed = rand() % 0xFFFF;
+	WFIFOL(fd, 2) = sd->pincode_seed = rnd() % 0xFFFF;
 	WFIFOL(fd, 6) = sd->account_id;
 	WFIFOW(fd,10) = state;
 	WFIFOSET(fd,12);
@@ -4597,7 +4601,7 @@ void pincode_notifyLoginPinUpdate( int account_id, char* pin ){
 	WFIFOHEAD(login_fd,11);
 	WFIFOW(login_fd,0) = 0x2738;
 	WFIFOL(login_fd,2) = account_id;
-	strncpy( (char*)WFIFOP(login_fd,6), pin, 5 );
+	strncpy( (char*)WFIFOP(login_fd,6), pin, PINCODE_LENGTH+1 );
 	WFIFOSET(login_fd,11);
 }
 
@@ -4608,10 +4612,11 @@ void pincode_notifyLoginPinError( int account_id ){
 	WFIFOSET(login_fd,6);
 }
 
-void pincode_decrypt( unsigned long userSeed, char* pin ){
+void pincode_decrypt( uint32 userSeed, char* pin ){
 	int i, pos;
 	char tab[10] = {0,1,2,3,4,5,6,7,8,9};
-	unsigned long multiplier = 0x3498, baseSeed = 0x881234;
+	char *buf;
+	uint32 multiplier = 0x3498, baseSeed = 0x881234;
 
 	for( i = 1; i < 10; i++ ){
 		userSeed = baseSeed + userSeed * multiplier;
@@ -4623,11 +4628,13 @@ void pincode_decrypt( unsigned long userSeed, char* pin ){
 		}
 	}
 
-	for( i = 0; i < 4; i++ ){
-		pin[i] = tab[pin[i]- '0'];
+	buf = (char *)malloc(sizeof(pin));
+	memset(buf,0,PINCODE_LENGTH+1);
+	for( i = 0; i < PINCODE_LENGTH; i++ ){
+		sprintf(buf+i,"%d",tab[pin[i] - '0']);
 	}
-
-	sprintf(pin, "%d%d%d%d", pin[0], pin[1], pin[2], pin[3]);
+	strcpy(pin,buf);
+	free(buf);
 }
 
 //------------------------------------------------
@@ -5018,6 +5025,12 @@ int char_config_read(const char* cfgName)
 			guild_exp_rate = atoi(w2);
 		} else if (strcmpi(w1, "pincode_enabled") == 0) {
 			pincode_enabled = config_switch(w2);
+			#if PACKETVER < 20110309
+			if( pincode_enabled ) {
+				ShowWarning("pincode_enabled requires PACKETVER 20110309 or higher. Disabling...\n");
+				pincode_enabled = false;
+			}
+			#endif
 		} else if (strcmpi(w1, "pincode_changetime") == 0) {
 			pincode_changetime = atoi(w2)*60*60*24;
 		} else if (strcmpi(w1, "pincode_maxtry") == 0) {

+ 2 - 0
src/common/mmo.h

@@ -122,6 +122,8 @@
 //For Map Names, which the client considers to be 16 in length including the .gat extension
 #define MAP_NAME_LENGTH (11 + 1)
 #define MAP_NAME_LENGTH_EXT (MAP_NAME_LENGTH + 4)
+//Pincode Length
+#define PINCODE_LENGTH 4
 
 #define MAX_FRIENDS 40
 #define MAX_MEMOPOINTS 3

+ 1 - 1
src/login/account.h

@@ -50,7 +50,7 @@ struct mmo_account
 	char lastlogin[24];     // date+time of last successful login
 	char last_ip[16];       // save of last IP of connection
 	char birthdate[10+1];   // assigned birth date (format: YYYY-MM-DD, default: 0000-00-00)
-	char pincode[4+1];		// pincode system
+	char pincode[PINCODE_LENGTH+1];		// pincode system
 	time_t pincode_change;	// (timestamp): last time of pincode change
 	int account_reg2_num;
 	struct global_reg account_reg2[ACCOUNT_REG2_NUM]; // account script variables (stored on login server)

+ 4 - 3
src/login/login.c

@@ -451,7 +451,6 @@ int parse_fromchar(int fd){
 				return 0;
 			else{
 				struct auth_node* node;
-
 				int account_id = RFIFOL(fd,2);
 				uint32 login_id1 = RFIFOL(fd,6);
 				uint32 login_id2 = RFIFOL(fd,10);
@@ -552,9 +551,11 @@ int parse_fromchar(int fd){
 				uint8 char_slots = 0;
 				int group_id = 0;
 				char birthdate[10+1] = "";
-				char pincode[4+1] = "";
-
+				char pincode[PINCODE_LENGTH+1];
 				int account_id = RFIFOL(fd,2);
+				
+				memset(pincode,0,PINCODE_LENGTH+1);
+				
 				RFIFOSKIP(fd,6);
 
 				if( !accounts->load_num(accounts, &acc, account_id) )

+ 2 - 2
src/map/clif.c

@@ -5612,10 +5612,9 @@ void clif_chsys_left(struct raChSysCh *channel, struct map_session_data *sd) {
 
 void clif_chsys_delete(struct raChSysCh *channel) {
 	if( db_size(channel->users) && !raChSys.closing ) {
-		DBIterator *iter;
 		struct map_session_data *sd;
 		unsigned char i;
-		iter = db_iterator(channel->users);
+		DBIterator *iter = db_iterator(channel->users);
 		for( sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter) ) { //for all users
 			ARR_FIND(0, sd->channel_count, i, sd->channels[i] == channel); //found cur chan
 			if( i < sd->channel_count ) {
@@ -5634,6 +5633,7 @@ void clif_chsys_delete(struct raChSysCh *channel) {
 				}
 			}
 		}
+		dbi_destroy(iter);
 	}
 	db_destroy(channel->users);
 	if( channel->m ) {

+ 13 - 15
src/map/map.c

@@ -13,6 +13,7 @@
 #include "../common/strlib.h"
 #include "../common/utils.h"
 #include "../common/cli.h"
+#include "../common/ers.h"
 
 #include "map.h"
 #include "path.h"
@@ -1485,8 +1486,7 @@ void map_addnickdb(int charid, const char* nick)
 	p = idb_ensure(nick_db, charid, create_charid2nick);
 	safestrncpy(p->nick, nick, sizeof(p->nick));
 
-	while( p->requests )
-	{
+	while( p->requests ) {
 		req = p->requests;
 		p->requests = req->next;
 		sd = map_charid2sd(req->charid);
@@ -1508,8 +1508,7 @@ void map_delnickdb(int charid, const char* name)
 	if (!nick_db->remove(nick_db, db_i2key(charid), &data) || (p = db_data2ptr(&data)) == NULL)
 		return;
 
-	while( p->requests )
-	{
+	while( p->requests ) {
 		req = p->requests;
 		p->requests = req->next;
 		sd = map_charid2sd(req->charid);
@@ -1652,7 +1651,7 @@ int map_quit(struct map_session_data *sd) {
 			status_change_end(&sd->bl, SC_ENDURE, INVALID_TIMER); //No need to save infinite endure.
 		status_change_end(&sd->bl, SC_WEIGHT50, INVALID_TIMER);
 		status_change_end(&sd->bl, SC_WEIGHT90, INVALID_TIMER);
-        status_change_end(&sd->bl, SC_SATURDAYNIGHTFEVER, INVALID_TIMER);
+		status_change_end(&sd->bl, SC_SATURDAYNIGHTFEVER, INVALID_TIMER);
 		status_change_end(&sd->bl, SC_KYOUGAKU, INVALID_TIMER);
 		if (battle_config.debuff_on_logout&1) {
 			status_change_end(&sd->bl, SC_ORCISH, INVALID_TIMER);
@@ -1714,7 +1713,8 @@ int map_quit(struct map_session_data *sd) {
 	}
 
 	if( sd->channel_count ) {
-		for( i = 0; i < sd->channel_count; i++ ) {
+		uint8 ch_count = sd->channel_count;
+		for( i = 0; i < ch_count; i++ ) {
 			if( sd->channels[i] != NULL )
 				clif_chsys_left(sd->channels[i],sd);
 		}
@@ -2662,8 +2662,7 @@ bool map_iwall_set(int16 m, int16 x, int16 y, int size, int8 dir, bool shootable
 	return true;
 }
 
-void map_iwall_get(struct map_session_data *sd)
-{
+void map_iwall_get(struct map_session_data *sd) {
 	struct iwall_data *iwall;
 	DBIterator* iter;
 	int16 x1, y1;
@@ -2673,13 +2672,11 @@ void map_iwall_get(struct map_session_data *sd)
 		return;
 
 	iter = db_iterator(iwall_db);
-	for( iwall = dbi_first(iter); dbi_exists(iter); iwall = dbi_next(iter) )
-	{
+	for( iwall = dbi_first(iter); dbi_exists(iter); iwall = dbi_next(iter) ) {
 		if( iwall->m != sd->bl.m )
 			continue;
 
-		for( i = 0; i < iwall->size; i++ )
-		{
+		for( i = 0; i < iwall->size; i++ ) {
 			map_iwall_nextxy(iwall->x, iwall->y, iwall->dir, i, &x1, &y1);
 			clif_changemapcell(sd->fd, iwall->m, x1, y1, map_getcell(iwall->m, x1, y1, CELL_GETTYPE), SELF);
 		}
@@ -2695,8 +2692,7 @@ void map_iwall_remove(const char *wall_name)
 	if( (iwall = (struct iwall_data *)strdb_get(iwall_db, wall_name)) == NULL )
 		return; // Nothing to do
 
-	for( i = 0; i < iwall->size; i++ )
-	{
+	for( i = 0; i < iwall->size; i++ ) {
 		map_iwall_nextxy(iwall->x, iwall->y, iwall->dir, i, &x1, &y1);
 
 		map_setcell(iwall->m, x1, y1, CELL_SHOOTABLE, true);
@@ -3186,6 +3182,9 @@ int parse_console(const char* buf)
 			runflag = 0;
 		}
 	}
+	else if( strcmpi("ers_report", type) == 0 ){
+		ers_report();
+	}
 	else if( strcmpi("help", type) == 0 )
 	{
 		ShowInfo("To use GM commands:\n");
@@ -3751,7 +3750,6 @@ int do_init(int argc, char *argv[])
 
 	rnd_init();
 	map_config_read(MAP_CONF_NAME);
-	/* only temporary until sirius's datapack patch is complete  */
 
 	// loads npcs
 	map_reloadnpc(false);

+ 4 - 2
src/map/script.c

@@ -4790,8 +4790,10 @@ BUILDIN_FUNC(callfunc)
 		{
 			const char* name = reference_getname(data);
 			if( name[0] == '.' ) {
-				ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 1);
-				ref[0] = (name[1] == '@' ? st->stack->var_function : st->script->script_vars);
+				if(!ref){
+					ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 1);
+					ref[0] = (name[1] == '@' ? st->stack->var_function : st->script->script_vars);
+				}
 				data->ref = ref;
 			}
 		}