Преглед на файлове

added debugging

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@456 54d463be-8e91-2dee-dedb-b68131a5f0ec
amber преди 20 години
родител
ревизия
3b59f9ce74
променени са 10 файла, в които са добавени 125 реда и са изтрити 7 реда
  1. 4 0
      Changelog.txt
  2. 12 5
      src/char_sql/char.c
  3. 4 0
      src/char_sql/int_guild.c
  4. 4 0
      src/char_sql/int_party.c
  5. 2 0
      src/char_sql/int_pet.c
  6. 3 0
      src/char_sql/int_storage.c
  7. 3 0
      src/char_sql/inter.c
  8. 3 0
      src/char_sql/itemdb.c
  9. 73 0
      src/common/utils.c
  10. 17 2
      src/common/utils.h

+ 4 - 0
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]

+ 12 - 5
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);
+}

+ 4 - 0
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;

+ 4 - 0
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;
 

+ 2 - 0
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) {

+ 3 - 0
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;

+ 3 - 0
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データ削除リストの要素数
 

+ 3 - 0
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 **

+ 73 - 0
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;
+}

+ 17 - 2
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