From 7f6b7ef774c2a8237a963b74c22556d327e8c5a5 Mon Sep 17 00:00:00 2001 From: skotlex Date: Sun, 18 Nov 2007 21:32:24 +0000 Subject: - Implemented a small change that was long overdue: Displaying the char-select screen now uses a single SQL query instead of up to 9. - Fixed a bug in the update to prevent setting cell types on unwalkable cells. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11757 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/char_sql/char.c | 100 +++++++++++++++++++++++++++++++++++++++++----------- src/map/npc.c | 3 +- 2 files changed, 81 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 04520743a..f27cee6b7 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -822,7 +822,83 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit return 0; } +int mmo_char_tobuf(uint8* buf, struct mmo_charstatus* p); + #ifndef TXT_SQL_CONVERT +//===================================================================================================== +// Loads the basic character rooster for the given account. Returns total buffer used. +int mmo_chars_fromsql(struct char_session_data* sd, uint8* buf) +{ + SqlStmt* stmt; + struct mmo_charstatus p; + int j = 0, i; + + stmt = SqlStmt_Malloc(sql_handle); + if( stmt == NULL ) + { + SqlStmt_ShowDebug(stmt); + return 0; + } + memset(&p, 0, sizeof(p)); + + // read char data + if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT " + "`char_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`," + "`str`,`agi`,`vit`,`int`,`dex`,`luk`,`max_hp`,`hp`,`max_sp`,`sp`," + "`status_point`,`skill_point`,`option`,`karma`,`manner`,`hair`,`hair_color`," + "`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`" + " FROM `%s` WHERE `account_id`='%d' AND `char_num` < '%d'", 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) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_UCHAR, &p.slot, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_STRING, &p.name, sizeof(p.name), NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 3, SQLDT_SHORT, &p.class_, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_UINT, &p.base_level, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 5, SQLDT_UINT, &p.job_level, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 6, SQLDT_UINT, &p.base_exp, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 7, SQLDT_UINT, &p.job_exp, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 8, SQLDT_INT, &p.zeny, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 9, SQLDT_SHORT, &p.str, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 10, SQLDT_SHORT, &p.agi, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 11, SQLDT_SHORT, &p.vit, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 12, SQLDT_SHORT, &p.int_, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 13, SQLDT_SHORT, &p.dex, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 14, SQLDT_SHORT, &p.luk, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 15, SQLDT_INT, &p.max_hp, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 16, SQLDT_INT, &p.hp, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 17, SQLDT_INT, &p.max_sp, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 18, SQLDT_INT, &p.sp, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 19, SQLDT_USHORT, &p.status_point, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 20, SQLDT_USHORT, &p.skill_point, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 21, SQLDT_UINT, &p.option, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 22, SQLDT_UCHAR, &p.karma, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 23, SQLDT_SHORT, &p.manner, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 24, SQLDT_SHORT, &p.hair, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 25, SQLDT_SHORT, &p.hair_color, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 26, SQLDT_SHORT, &p.clothes_color, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 27, SQLDT_SHORT, &p.weapon, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 28, SQLDT_SHORT, &p.shield, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 29, SQLDT_SHORT, &p.head_top, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 30, SQLDT_SHORT, &p.head_mid, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 31, SQLDT_SHORT, &p.head_bottom, 0, NULL, NULL) + ) + { + SqlStmt_ShowDebug(stmt); + SqlStmt_Free(stmt); + return 0; + } + for( i = 0; i < MAX_CHARS && SQL_SUCCESS == SqlStmt_NextRow(stmt); i++ ) + { + sd->found_char[i] = p.char_id; + j += mmo_char_tobuf(WBUFP(buf, j), &p); + } + for( ; i < MAX_CHARS; i++ ) + sd->found_char[i] = -1; + + SqlStmt_Free(stmt); + return j; +} + //===================================================================================================== int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything) { @@ -1411,36 +1487,18 @@ int mmo_char_tobuf(uint8* buf, struct mmo_charstatus* p) int mmo_char_send006b(int fd, struct char_session_data* sd) { - int i, j, found_num = 0; - char* data; + int j; set_char_online(-1, 99, sd->account_id); - // load the char_ids of all chars on this account - if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `char_id` FROM `%s` WHERE `account_id` = '%d' AND `char_num` < '%d'", char_db, sd->account_id, MAX_CHARS) ) - Sql_ShowDebug(sql_handle); - for( i = 0; i < MAX_CHARS && SQL_SUCCESS == Sql_NextRow(sql_handle); ++i ) - { - Sql_GetData(sql_handle, 0, &data, NULL); sd->found_char[i] = atoi(data); // char_id - } - found_num = i; - for( ; i < MAX_CHARS; ++i ) - sd->found_char[i] = -1; - if (save_log) ShowInfo("Loading Char Data ("CL_BOLD"%d"CL_RESET")\n",sd->account_id); - j = 24; // offset - WFIFOHEAD(fd,j + found_num*108); // or 106(!) + WFIFOHEAD(fd,j + MAX_CHARS*108); // or 106(!) WFIFOW(fd,0) = 0x6b; memset(WFIFOP(fd,4), 0, 20); // unknown bytes - for(i = 0; i < found_num; i++) - { - struct mmo_charstatus char_dat; - mmo_char_fromsql(sd->found_char[i], &char_dat, false); - j += mmo_char_tobuf(WFIFOP(fd,j), &char_dat); - } + j+=mmo_chars_fromsql(sd, WFIFOP(fd,j)); WFIFOW(fd,2) = j; // packet len WFIFOSET(fd,j); diff --git a/src/map/npc.c b/src/map/npc.c index 0636bc797..c65997d39 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2543,10 +2543,11 @@ static const char* npc_parse_mapcell(char* w1, char* w2, char* w3, char* w4, con swap(y0, y1); for( x = x0; x <= x1; ++x ) - for( y = y0; y <= y1; ++y ) + for( y = y0; y <= y1; ++y ) { if (map_getcell(m, x, y, CELL_CHKNOREACH)) continue; map_setcell(m, x, y, cell); + } return strchr(start,'\n');// continue } -- cgit v1.2.3-70-g09d2