summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec>2004-12-05 06:54:02 +0000
committeramber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec>2004-12-05 06:54:02 +0000
commitf4b3dff16a0b23c915cfae1de150b0943db83620 (patch)
tree7019bc8f7c4356410d199b0058f1e5e2b41a2089
parentcf5a6282cace4f9b4d788909a00f6c6e0057acfe (diff)
downloadhercules-f4b3dff16a0b23c915cfae1de150b0943db83620.tar.gz
hercules-f4b3dff16a0b23c915cfae1de150b0943db83620.tar.bz2
hercules-f4b3dff16a0b23c915cfae1de150b0943db83620.tar.xz
hercules-f4b3dff16a0b23c915cfae1de150b0943db83620.zip
added debugging
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@456 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--Changelog.txt4
-rw-r--r--src/char_sql/char.c17
-rw-r--r--src/char_sql/int_guild.c4
-rw-r--r--src/char_sql/int_party.c4
-rw-r--r--src/char_sql/int_pet.c2
-rw-r--r--src/char_sql/int_storage.c3
-rw-r--r--src/char_sql/inter.c3
-rw-r--r--src/char_sql/itemdb.c3
-rw-r--r--src/common/utils.c73
-rw-r--r--src/common/utils.h19
10 files changed, 125 insertions, 7 deletions
diff --git a/Changelog.txt b/Changelog.txt
index 9fa017560..403576d2a 100644
--- a/Changelog.txt
+++ b/Changelog.txt
@@ -1,4 +1,8 @@
Date Added
+12/05
+ * some cleanup of char_sql [MouseJstr]
+ * added verbose mysql debugging to char_sql [MouseJstr]
+
12/02
* Fixed int state in SQL login.c [Wizputer]
* Moved init of send_users_tologin timer to when char connects to login [Wizputer]
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index 382c654b9..364755cf1 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -190,6 +190,7 @@ void read_gm_account(void) {
sprintf(tmp_lsql, "SELECT `%s`,`%s` FROM `%s` WHERE `%s`>='%d'",login_db_account_id,login_db_level,login_db,login_db_level,lowest_gm_level);
if (mysql_query(&lmysql_handle, tmp_lsql)) {
printf("DB server Error (select %s to Memory)- %s\n",login_db,mysql_error(&lmysql_handle));
+ return;
}
lsql_res = mysql_store_result(&lmysql_handle);
if (lsql_res) {
@@ -507,7 +508,6 @@ int memitemdata_to_sql(struct itemtemp mapitem, int eqcount, int noteqcount, int
if((eqcount==1) && (dbeqcount==1)){//printf("%s Equip Empty\n",tablename);
//item empty
} else {
-
for(i=1;i<eqcount;i++){
for(j=1;j<dbeqcount;j++){
if(mapitem.equip[i].flag==1) break;
@@ -541,7 +541,7 @@ int memitemdata_to_sql(struct itemtemp mapitem, int eqcount, int noteqcount, int
for(i=1;i<dbeqcount;i++){
//printf("dbitem.equip[i].flag = %d , dbitem.equip[i].id = %d\n",dbitem.equip[i].flag,dbitem.equip[i].id);
- if (!(dbitem.equip[i].flag == 1)) {
+ if (dbitem.equip[i].flag == 0) {
sprintf(tmp_sql,"DELETE from `%s` where `id`='%d'",tablename , dbitem.equip[i].id);
//printf("%s", tmp_sql);
if(mysql_query(&mysql_handle, tmp_sql))
@@ -549,7 +549,7 @@ int memitemdata_to_sql(struct itemtemp mapitem, int eqcount, int noteqcount, int
}
}
for(i=1;i<eqcount;i++){
- if(!(mapitem.equip[i].flag==1)){
+ if(mapitem.equip[i].flag==0){
sprintf(tmp_sql,"INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`)"
" VALUES ( '%d','%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
tablename, selectoption, char_id, mapitem.equip[i].nameid, mapitem.equip[i].amount, mapitem.equip[i].equip, mapitem.equip[i].identify, mapitem.equip[i].refine,
@@ -621,7 +621,7 @@ int memitemdata_to_sql(struct itemtemp mapitem, int eqcount, int noteqcount, int
for(i=1;i<dbnoteqcount;i++){
//printf("dbitem.notequip[i].flag = %d , dbitem.notequip[i].id = %d\n",dbitem.notequip[i].flag,dbitem.notequip[i].id);
- if(!(dbitem.notequip[i].flag==1)){
+ if(dbitem.notequip[i].flag==0){
sprintf(tmp_sql,"DELETE from `%s` where `id`='%d'", tablename, dbitem.notequip[i].id);
//printf("%s", tmp_sql);
if(mysql_query(&mysql_handle, tmp_sql))
@@ -629,7 +629,7 @@ int memitemdata_to_sql(struct itemtemp mapitem, int eqcount, int noteqcount, int
}
}
for(i=1;i<noteqcount;i++){
- if(!(mapitem.notequip[i].flag==1)){
+ if(mapitem.notequip[i].flag==0) {
sprintf(tmp_sql,"INSERT INTO `%s`( `%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`)"
" VALUES ('%d','%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
tablename ,selectoption , char_id, mapitem.notequip[i].nameid, mapitem.notequip[i].amount, mapitem.notequip[i].equip, mapitem.notequip[i].identify, mapitem.notequip[i].refine,
@@ -3042,3 +3042,10 @@ int do_init(int argc, char **argv){
}
+#undef mysql_query
+int STDCALL mysql_query(MYSQL *mysql, const char *q);
+
+int debug_mysql_query(MYSQL *mysql, const char *q) {
+ printf("DEBUG_MYSQL: %s\n", q);
+ return mysql_query(mysql, q);
+}
diff --git a/src/char_sql/int_guild.c b/src/char_sql/int_guild.c
index 4f6c88a70..47343cb7b 100644
--- a/src/char_sql/int_guild.c
+++ b/src/char_sql/int_guild.c
@@ -16,6 +16,10 @@
#include <stdio.h>
#include <stdlib.h>
+
+extern int debug_mysql_query(MYSQL *mysql, const char *q);
+#define mysql_query(_x, _y) debug_mysql_query(_x, _y)
+
static struct guild *guild_pt;
static struct guild *guild_pt2;
static struct guild_castle * guildcastle_pt;
diff --git a/src/char_sql/int_party.c b/src/char_sql/int_party.c
index 84de078c9..2ac955230 100644
--- a/src/char_sql/int_party.c
+++ b/src/char_sql/int_party.c
@@ -10,6 +10,10 @@
#include <stdlib.h>
#include <string.h>
+
+extern int debug_mysql_query(MYSQL *mysql, const char *q);
+#define mysql_query(_x, _y) debug_mysql_query(_x, _y)
+
static struct party *party_pt;
static int party_newid=100;
diff --git a/src/char_sql/int_pet.c b/src/char_sql/int_pet.c
index 14d2144c7..bf42670b6 100644
--- a/src/char_sql/int_pet.c
+++ b/src/char_sql/int_pet.c
@@ -12,6 +12,8 @@
struct s_pet *pet_pt;
static int pet_newid = 100;
+extern int debug_mysql_query(MYSQL *mysql, const char *q);
+#define mysql_query(_x, _y) debug_mysql_query(_x, _y)
//---------------------------------------------------------
int inter_pet_tosql(int pet_id, struct s_pet *p) {
diff --git a/src/char_sql/int_storage.c b/src/char_sql/int_storage.c
index 7c8c8ce4a..72b8386fc 100644
--- a/src/char_sql/int_storage.c
+++ b/src/char_sql/int_storage.c
@@ -14,6 +14,9 @@ struct storage *storage_pt=NULL;
struct guild_storage *guild_storage_pt=NULL;
+extern int debug_mysql_query(MYSQL *mysql, const char *q);
+#define mysql_query(_x, _y) debug_mysql_query(_x, _y)
+
// storage data -> DB conversion
int storage_tosql(int account_id,struct storage *p){
int i;
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index 9c10cf6c5..95768b049 100644
--- a/src/char_sql/inter.c
+++ b/src/char_sql/inter.c
@@ -15,6 +15,9 @@
#include "int_pet.h"
#include "lock.h"
+extern int debug_mysql_query(MYSQL *mysql, const char *q);
+#define mysql_query(_x, _y) debug_mysql_query(_x, _y)
+
#define WISDATA_TTL (60*1000) // Wisデータの生存時間(60秒)
#define WISDELLIST_MAX 256 // Wisデータ削除リストの要素数
diff --git a/src/char_sql/itemdb.c b/src/char_sql/itemdb.c
index 0bed07c23..7a8db9e7e 100644
--- a/src/char_sql/itemdb.c
+++ b/src/char_sql/itemdb.c
@@ -13,6 +13,9 @@
#include "memwatch.h"
#endif
+extern int debug_mysql_query(MYSQL *mysql, const char *q);
+#define mysql_query(_x, _y) debug_mysql_query(_x, _y)
+
#define MAX_RANDITEM 2000
// ** ITEMDB_OVERRIDE_NAME_VERBOSE **
diff --git a/src/common/utils.c b/src/common/utils.c
index 941f2b0bd..bdbce7318 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -1,6 +1,8 @@
#include <string.h>
#include "utils.h"
#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
void dump(unsigned char *buffer, int num)
{
@@ -106,3 +108,74 @@ void str_lower(char *name)
#endif
+// Allocate a StringBuf [MouseJstr]
+struct StringBuf * StringBuf_Malloc()
+{
+ StringBuf * ret = (struct StringBuf *) malloc(sizeof(struct StringBuf));
+ StringBuf_Init(ret);
+ return ret;
+}
+
+// Initialize a previously allocated StringBuf [MouseJstr]
+void StringBuf_Init(struct StringBuf * sbuf)
+ sbuf->max_ = 1024;
+ sbuf->ptr_ = sbuf->buf_ = (char *) malloc(sbuf->max_ + 1);
+{
+}
+
+// printf into a StringBuf, moving the pointer [MouseJstr]
+int StringBuf_Printf(struct StringBuf *sbuf,const char *fmt,...)
+{
+ va_list ap;
+ int n, size, off;
+
+ while (1) {
+ /* Try to print in the allocated space. */
+ va_start(ap, fmt);
+ size = sbuf->max_ - (sbuf->ptr_ - sbuf->buf_);
+ n = vsnprintf (sbuf->ptr_, size, fmt, ap);
+ va_end(ap);
+ /* If that worked, return the length. */
+ if (n > -1 && n < size) {
+ sbuf->ptr_ += n;
+ return sbuf->ptr_ - sbuf->buf_;
+ }
+ /* Else try again with more space. */
+ sbuf->max_ *= 2; // twice the old size
+ off = sbuf->ptr_ - sbuf->buf_;
+ sbuf->buf_ = (char *) realloc(sbuf->buf_, sbuf->max_ + 1);
+ sbuf->ptr_ = sbuf->buf_ + off;
+ }
+}
+
+// Append buf2 onto the end of buf1 [MouseJstr]
+int StringBuf_Append(struct StringBuf *buf1,const struct StringBuf *buf2)
+{
+ int buf1_avail = buf1->max_ - (buf1->ptr_ - buf1->buf_);
+ int size2 = buf2->ptr_ - buf2->buf_;
+
+ if (size2 >= buf1_avail) {
+ int off = buf1->ptr_ - buf1->buf_;
+ buf1->max_ += size2;
+ buf1->buf_ = (char *) realloc(buf1->buf_, buf1->max_ + 1);
+ buf1->ptr_ = buf1->buf_ + off;
+ }
+
+ memcpy(buf1->ptr_, buf2->buf_, size2);
+ buf1->ptr_ += size2;
+ return buf1->ptr_ - buf1->buf_;
+}
+
+// Destroy a StringBuf [MouseJstr]
+void StringBuf_Destroy(struct StringBuf *sbuf)
+{
+ free(sbuf->buf_);
+ sbuf->ptr_ = sbuf->buf_ = 0;
+}
+
+// Free a StringBuf returned by StringBuf_Malloc [MouseJstr]
+void StringBuf_Free(struct StringBuf *sbuf)
+{
+ StringBuf_Destroy(sbuf);
+ free(sbuf)buf;
+}
diff --git a/src/common/utils.h b/src/common/utils.h
index c8efd525b..f6ea8e006 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -1,3 +1,5 @@
+#ifndef UTILS_H
+#define UTILS_H
#ifndef NULL
#define NULL (void *)0
@@ -18,8 +20,7 @@
#endif
- void dump(unsigned char *buffer, int num);
-
+void dump(unsigned char *buffer, int num);
#define CREATE(result, type, number) do {\
if ((number) * sizeof(type) <= 0) \
@@ -31,3 +32,17 @@
if (!((result) = (type *) realloc ((result), sizeof(type) * (number))))\
{ printf("SYSERR: realloc failure"); abort(); } } while(0)
+struct StringBuf {
+ char *buf_;
+ char *ptr_;
+ unsigned int max_;
+};
+
+extern struct StringBuf * StringBuf_Malloc();
+extern void StringBuf_Init(struct StringBuf *);
+extern int StringBuf_Printf(struct StringBuf *,const char *,...);
+extern int StringBuf_Append(struct StringBuf *,const struct StringBuf *);
+extern void StringBuf_Destroy(struct StringBuf *);
+extern void StringBuf_Free(struct StringBuf *);
+
+#endif