summaryrefslogtreecommitdiff
path: root/src/map/mob.c
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-09-20 11:09:36 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-09-20 11:09:36 +0000
commit5245e666a09df5f401c1329bf5ee1fc1b09b1d16 (patch)
treedcf032743e890fddd400b268b75a0868976b0a0b /src/map/mob.c
parentd23c508bcc38520970156e5e25f14b03714878eb (diff)
downloadhercules-5245e666a09df5f401c1329bf5ee1fc1b09b1d16.tar.gz
hercules-5245e666a09df5f401c1329bf5ee1fc1b09b1d16.tar.bz2
hercules-5245e666a09df5f401c1329bf5ee1fc1b09b1d16.tar.xz
hercules-5245e666a09df5f401c1329bf5ee1fc1b09b1d16.zip
* Merged the tmpsql branch:
- Abstraction for the sql code (sql.c/h). - New configure script and makefiles. - Restored txt zeny logging code. (r10814) - Rewrote mapserver's sql code - itemdb, mobdb, mapreg, logs. (r10814) - Fixed a precedence issue (&& and ) in char_sql/char.c. (r10833) - Improved db reading code a bit for consistency. (r11077) - Added separate atcommand for mail deletion. (r11077) - Corrected a few messages that said "new" instead of "unread". (r11077) - Broadcast (*) messages now use "*" as the target's name (not ""). (r11077) - Moved StringBuf code from utils.c/h to strlib.c/h. (r11084 r11117) - Some misc login server cleanups (reformatting etc). (r11136) - Corrected/modified some header entries. (r11141 r11147 11148) - Adjusted VS project files. (r11147) - Adjusted the way the sql charserver does item saving. (r11192) - Corrected usage of reserved keyword 'friend' in mmo.h. (r11192) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11245 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/mob.c')
-rw-r--r--src/map/mob.c112
1 files changed, 73 insertions, 39 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index 86d60a152..b5c83413c 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -9,6 +9,7 @@
#include "../common/showmsg.h"
#include "../common/ers.h"
#include "../common/strlib.h"
+#include "../common/utils.h"
#include "map.h"
#include "clif.h"
@@ -3210,7 +3211,10 @@ static unsigned int mob_drop_adjust(int rate, int rate_adjust, unsigned short ra
return cap_value(rate,rate_min,rate_max);
}
-int mob_parse_dbrow(char** str)
+/*==========================================
+ * processes one mobdb entry
+ *------------------------------------------*/
+static bool mob_parse_dbrow(char** str)
{
struct mob_db *db;
struct status_data *status;
@@ -3220,15 +3224,15 @@ int mob_parse_dbrow(char** str)
class_ = str[0] ? atoi(str[0]) : 0;
if (class_ == 0)
- return 0; //Leave blank lines alone... [Skotlex]
+ return false; //Leave blank lines alone... [Skotlex]
if (class_ <= 1000 || class_ > MAX_MOB_DB) {
ShowWarning("Mob with ID: %d not loaded. ID must be in range [%d-%d]\n", class_, 1000, MAX_MOB_DB);
- return 0;
+ return false;
}
if (pcdb_checkid(class_)) {
ShowWarning("Mob with ID: %d not loaded. That ID is reserved for player classes.\n");
- return 0;
+ return false;
}
if (mob_db_data[class_] == NULL)
@@ -3432,7 +3436,7 @@ int mob_parse_dbrow(char** str)
}
}
- return 1;
+ return true;
}
/*==========================================
@@ -3440,83 +3444,113 @@ int mob_parse_dbrow(char** str)
*------------------------------------------*/
static int mob_readdb(void)
{
- FILE *fp;
- char line[1024];
- char *filename[]={ "mob_db.txt","mob_db2.txt" };
- int i, fi;
- unsigned int ln = 0;
+ char* filename[] = { "mob_db.txt", "mob_db2.txt" };
+ int fi;
- for(fi = 0; fi < 2; fi++) {
- sprintf(line, "%s/%s", db_path, filename[fi]);
- fp = fopen(line, "r");
+ for(fi = 0; fi < 2; fi++)
+ {
+ uint32 lines = 0, count = 0;
+ char line[1024];
+ char path[256];
+ FILE* fp;
+
+ sprintf(path, "%s/%s", db_path, filename[fi]);
+ fp = fopen(path, "r");
if(fp == NULL) {
if(fi > 0)
continue;
return -1;
}
+ // process rows one by one
while(fgets(line, sizeof(line), fp))
{
char *str[38+2*MAX_MOB_DROP], *p, *np;
+ int i;
+ lines++;
if(line[0] == '/' && line[1] == '/')
continue;
- for(i = 0, p = line; i < 38 + 2*MAX_MOB_DROP; i++) {
+ for(i = 0, p = line; i < 38 + 2*MAX_MOB_DROP; i++)
+ {
+ str[i] = p;
if((np = strchr(p, ',')) != NULL) {
- str[i] = p; *np = 0; p = np + 1;
- } else
- str[i] = p;
+ *np = '\0'; p = np + 1;
+ }
}
if(i < 38 + 2*MAX_MOB_DROP) {
- ShowWarning("mob_readdb: Insufficient columns for mob with ID: %d\n", str[0] ? atoi(str[0]) : 0);
+ ShowWarning("mob_readdb: Insufficient columns for mob with id: %d, skipping.\n", atoi(str[0]));
continue;
}
if (!mob_parse_dbrow(str))
continue;
- ln++; // counts the number of correctly parsed entries
+ count++;
}
+
fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, filename[fi]);
- ln = 0;
+
+ ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename[fi]);
}
+
return 0;
}
#ifndef TXT_ONLY
/*==========================================
- * SQL reading
+ * mob_db table reading
*------------------------------------------*/
static int mob_read_sqldb(void)
{
- char *mob_db_name[] = { mob_db_db, mob_db2_db };
+ char* mob_db_name[] = { mob_db_db, mob_db2_db };
int fi;
- unsigned int ln = 0;
- for (fi = 0; fi < 2; fi++) {
- sprintf (tmp_sql, "SELECT * FROM `%s`", mob_db_name[fi]);
- if (mysql_query(&mmysql_handle, tmp_sql)) {
- ShowSQL("DB error (%s) - %s\n", mob_db_name[fi], mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
+ for (fi = 0; fi < 2; fi++)
+ {
+ uint32 lines = 0, count = 0;
+
+ // retrieve all rows from the mob database
+ if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) )
+ {
+ Sql_ShowDebug(mmysql_handle);
continue;
}
- sql_res = mysql_store_result(&mmysql_handle);
- if (sql_res) {
- while((sql_row = mysql_fetch_row(sql_res))){
-
- if (!mob_parse_dbrow(sql_row))
- continue;
+
+ // process rows one by one
+ while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) )
+ {
+ // wrap the result into a TXT-compatible format
+ char line[1024];
+ char* str[38+2*MAX_MOB_DROP];
+ char* p;
+ int i;
+
+ lines++;
+ for(i = 0, p = line; i < 38 + 2*MAX_MOB_DROP; i++)
+ {
+ char* data;
+ size_t len;
+ Sql_GetData(mmysql_handle, i, &data, &len);
- ln++; // counts the number of correctly parsed entries
+ strcpy(p, data);
+ str[i] = p;
+ p+= len + 1;
}
- mysql_free_result(sql_res);
- ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, mob_db_name[fi]);
- ln = 0;
+ if (!mob_parse_dbrow(str))
+ continue;
+
+ count++;
}
+
+ // free the query result
+ Sql_FreeResult(mmysql_handle);
+
+ ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_db_name[fi]);
+ count = 0;
}
return 0;
}