From 18b1965ce16909613f0a53515d40553742082ce2 Mon Sep 17 00:00:00 2001
From: shennetsind <ind@henn.et>
Date: Sat, 4 May 2013 17:22:57 -0300
Subject: mapindex update

Fixed a mapindex_name2id problem that'd persistently not fix a broken mapindex data (e.g. char save/last map data being incorrect). It'll now align it to MAP_DEFAULT when such error occurs.
Also speeded up mapindex_name2id queries, replaced the loop by the red-black-tree db lookup.
Special Thanks to yommy~!

Signed-off-by: shennetsind <ind@henn.et>
---
 src/char/char.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

(limited to 'src/char')

diff --git a/src/char/char.c b/src/char/char.c
index ba3179ef9..d07995cc1 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -1170,6 +1170,18 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
 	p->last_point.map = mapindex_name2id(last_map);
 	p->save_point.map = mapindex_name2id(save_map);
 
+	if( p->last_point.map == 0 ) {
+		p->last_point.map = strdb_iget(mapindex_db, MAP_DEFAULT);
+		p->last_point.x = MAP_DEFAULT_X;
+		p->last_point.y = MAP_DEFAULT_Y;
+	}
+	
+	if( p->save_point.map == 0 ) {
+		p->save_point.map = strdb_iget(mapindex_db, MAP_DEFAULT);
+		p->save_point.x = MAP_DEFAULT_X;
+		p->save_point.y = MAP_DEFAULT_Y;
+	}
+	
 	strcat(t_msg, " status");
 
 	if (!load_everything) // For quick selection of data when displaying the char menu
@@ -1188,8 +1200,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
 	||	SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_SHORT,  &tmp_point.y, 0, NULL, NULL) )
 		SqlStmt_ShowDebug(stmt);
 
-	for( i = 0; i < MAX_MEMOPOINTS && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i )
-	{
+	for( i = 0; i < MAX_MEMOPOINTS && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i ) {
 		tmp_point.map = mapindex_name2id(point_map);
 		memcpy(&p->memo_point[i], &tmp_point, sizeof(tmp_point));
 	}
@@ -3294,7 +3305,6 @@ int parse_frommap(int fd)
 				WFIFOW(fd,0) = 0x2b24;
 				WFIFOSET(fd,2);
 				RFIFOSKIP(fd,2);
-				ShowDebug("Received 2b23, sending 2b24\n");
 			break;
 
 			case 0x2b26: // auth request from map-server
-- 
cgit v1.2.3-70-g09d2