summaryrefslogtreecommitdiff
path: root/src/map/map.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/map.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/map.c')
-rw-r--r--src/map/map.c138
1 files changed, 58 insertions, 80 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 7c1ba6c4c..2476e0e0e 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -11,6 +11,7 @@
#include "../common/version.h"
#include "../common/nullpo.h"
#include "../common/strlib.h"
+#include "../common/utils.h"
#include "map.h"
#include "chrif.h"
@@ -34,11 +35,8 @@
#include "mercenary.h" //[orn]
#include "atcommand.h"
#include "charcommand.h"
-
#include "log.h"
-
#include "irc.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -50,10 +48,20 @@
#endif
#ifndef TXT_ONLY
-
#include "mail.h"
+#endif
-char tmp_sql[65535]="";
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <math.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
+
+#ifndef TXT_ONLY
char default_codepage[32] = "";
int map_server_port = 3306;
@@ -61,9 +69,7 @@ char map_server_ip[32] = "127.0.0.1";
char map_server_id[32] = "ragnarok";
char map_server_pw[32] = "ragnarok";
char map_server_db[32] = "ragnarok";
-MYSQL mmysql_handle;
-MYSQL_RES* sql_res;
-MYSQL_ROW sql_row;
+Sql* mmysql_handle;
int db_use_sqldbs = 0;
char item_db_db[32] = "item_db";
@@ -79,9 +85,7 @@ int log_db_port = 3306;
char log_db_id[32] = "ragnarok";
char log_db_pw[32] = "ragnarok";
char log_db[32] = "log";
-MYSQL logmysql_handle;
-MYSQL_RES* logsql_res;
-MYSQL_ROW logsql_row;
+Sql* logmysql_handle;
// mail system
int mail_server_enable = 0;
@@ -91,9 +95,7 @@ char mail_server_id[32] = "ragnarok";
char mail_server_pw[32] = "ragnarok";
char mail_server_db[32] = "ragnarok";
char mail_db[32] = "mail";
-MYSQL mail_handle;
-MYSQL_RES* mail_res;
-MYSQL_ROW mail_row;
+Sql* mail_handle;
#endif /* not TXT_ONLY */
@@ -1096,7 +1098,7 @@ int map_foreachinpath(int (*func)(struct block_list*,va_list),int m,int x0,int y
if (length)
{ //Adjust final position to fit in the given area.
//TODO: Find an alternate method which does not requires a square root calculation.
- k = sqrt(magnitude2);
+ k = (int)sqrt(magnitude2);
mx1 = x0 + (x1 - x0)*length/k;
my1 = y0 + (y1 - y0)*length/k;
len_limit = MAGNITUDE2(x0,y0, mx1,my1);
@@ -2951,43 +2953,30 @@ int inter_config_read(char *cfgName)
*---------------------------------------*/
int map_sql_init(void)
{
- mysql_init(&mmysql_handle);
+ // main db connection
+ mmysql_handle = Sql_Malloc();
- //DB connection start
ShowInfo("Connecting to the Map DB Server....\n");
- if(!mysql_real_connect(&mmysql_handle, map_server_ip, map_server_id, map_server_pw,
- map_server_db ,map_server_port, (char *)NULL, 0)) {
- //pointer check
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- exit(1);
- }
- else {
- ShowStatus("connect success! (Map Server Connection)\n");
- }
+ if( SQL_ERROR == Sql_Connect(mmysql_handle, map_server_id, map_server_pw, map_server_ip, map_server_port, map_server_db) )
+ exit(1);
+ ShowStatus("connect success! (Map Server Connection)\n");
- if(mail_server_enable) { // mail system [Valaris]
- mysql_init(&mail_handle);
- ShowInfo("Connecting to the Mail DB Server....\n");
- if(!mysql_real_connect(&mail_handle, mail_server_ip, mail_server_id, mail_server_pw,
- mail_server_db ,mail_server_port, (char *)NULL, 0)) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- exit(1);
- }
- if( strlen(default_codepage) > 0 ) {
- sprintf( tmp_sql, "SET NAMES %s", default_codepage );
- if (mysql_query(&mail_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&mail_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
- }
- }
+ if( strlen(default_codepage) > 0 )
+ if ( SQL_ERROR == Sql_SetEncoding(mmysql_handle, default_codepage) )
+ Sql_ShowDebug(mmysql_handle);
- if( strlen(default_codepage) > 0 ) {
- sprintf( tmp_sql, "SET NAMES %s", default_codepage );
- if (mysql_query(&mmysql_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&mmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
+ if(mail_server_enable)
+ {
+ // mail system
+ mail_handle = Sql_Malloc();
+
+ ShowInfo("Connecting to the Mail DB Server....\n");
+ if( SQL_ERROR == Sql_Connect(mail_handle, mail_server_id, mail_server_pw, mail_server_ip, mail_server_port, mail_server_db) )
+ exit(1);
+
+ if( strlen(default_codepage) > 0 )
+ if ( SQL_ERROR == Sql_SetEncoding(mail_handle, default_codepage) )
+ Sql_ShowDebug(mail_handle);
}
return 0;
@@ -2995,13 +2984,15 @@ int map_sql_init(void)
int map_sql_close(void)
{
- mysql_close(&mmysql_handle);
ShowStatus("Close Map DB Connection....\n");
+ Sql_Free(mmysql_handle);
+ mmysql_handle = NULL;
if (log_config.sql_logs)
{
- mysql_close(&logmysql_handle);
ShowStatus("Close Log DB Connection....\n");
+ Sql_Free(logmysql_handle);
+ logmysql_handle = NULL;
}
return 0;
@@ -3009,25 +3000,18 @@ int map_sql_close(void)
int log_sql_init(void)
{
- mysql_init(&logmysql_handle);
+ // log db connection
+ logmysql_handle = Sql_Malloc();
- //DB connection start
ShowInfo(""CL_WHITE"[SQL]"CL_RESET": Connecting to the Log Database "CL_WHITE"%s"CL_RESET" At "CL_WHITE"%s"CL_RESET"...\n",log_db,log_db_ip);
- if(!mysql_real_connect(&logmysql_handle, log_db_ip, log_db_id, log_db_pw,
- log_db ,log_db_port, (char *)NULL, 0)) {
- //pointer check
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- exit(1);
- }
-
+ if ( SQL_ERROR == Sql_Connect(logmysql_handle, log_db_id, log_db_pw, log_db_ip, log_db_port, log_db) )
+ exit(1);
ShowStatus(""CL_WHITE"[SQL]"CL_RESET": Successfully '"CL_GREEN"connected"CL_RESET"' to Database '"CL_WHITE"%s"CL_RESET"'.\n", log_db);
- if( strlen(default_codepage) > 0 ) {
- sprintf( tmp_sql, "SET NAMES %s", default_codepage );
- if (mysql_query(&logmysql_handle, tmp_sql)) {
- ShowSQL("DB error - %s\n",mysql_error(&logmysql_handle));
- ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql);
- }
- }
+
+ if( strlen(default_codepage) > 0 )
+ if ( SQL_ERROR == Sql_SetEncoding(logmysql_handle, default_codepage) )
+ Sql_ShowDebug(logmysql_handle);
+
return 0;
}
@@ -3037,31 +3021,25 @@ int log_sql_init(void)
int map_sql_ping(int tid, unsigned int tick, int id, int data)
{
ShowInfo("Pinging SQL server to keep connection alive...\n");
- mysql_ping(&mmysql_handle);
+ Sql_Ping(mmysql_handle);
if (log_config.sql_logs)
- mysql_ping(&logmysql_handle);
+ Sql_Ping(logmysql_handle);
if(mail_server_enable)
- mysql_ping(&mail_handle);
+ Sql_Ping(mail_handle);
return 0;
}
int sql_ping_init(void)
{
- int connection_timeout, connection_ping_interval;
+ uint32 connection_timeout, connection_ping_interval;
- // set a default value first
+ // set a default value
connection_timeout = 28800; // 8 hours
// ask the mysql server for the timeout value
- if (!mysql_query(&mmysql_handle, "SHOW VARIABLES LIKE 'wait_timeout'")
- && (sql_res = mysql_store_result(&mmysql_handle)) != NULL) {
- sql_row = mysql_fetch_row(sql_res);
- if (sql_row)
- connection_timeout = atoi(sql_row[1]);
- if (connection_timeout < 60)
- connection_timeout = 60;
- mysql_free_result(sql_res);
- }
+ Sql_GetTimeout(mmysql_handle, &connection_timeout);
+ if (connection_timeout < 60)
+ connection_timeout = 60;
// establish keepalive
connection_ping_interval = connection_timeout - 30; // 30-second reserve