My frist cahnge, hopefully it's not my last...

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@614 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ajarn 2004-12-19 00:20:59 +00:00
parent 721cb8679d
commit c0f5237c71
3 changed files with 238 additions and 219 deletions

View File

@ -1,4 +1,7 @@
Date Added
12/18
* Fixed SQL char creation, it now follows MySQL standards and uses mysql_last_insert_id [Ajarn]
12/10
* Fixed parse's for login-server, it actually fails if packet len isn't long enough [Wizputer]
* Edit of parses in char-server, -UNTESTED- [Wizputer]

View File

@ -132,7 +132,7 @@ int auth_fifo_pos = 0;
int check_ip_flag = 1; // It's to check IP of a player between char-server and other servers (part of anti-hacking system)
int char_id_count = 150000;
//int char_id_count = 150000; // no longer needed, use of MIN_CHAR_ID instead [Ajarn]
struct mmo_charstatus *char_dat;
int char_num,char_max;
int max_connect_user = 0;
@ -943,6 +943,9 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus *p, int online){
//==========================================================================================================
int mmo_char_sql_init(void) {
int i=0;
#ifdef DEBUG
int cid=0;
#endif
// memory initialize
// no need to set twice size in this routine. but some cause segmentation error. :P
@ -965,20 +968,29 @@ int mmo_char_sql_init(void) {
mysql_free_result(sql_res);
if (i !=0) {
// Because it's no longer needed, I made it debug. Some people may still want to know the highest
// char_id. It has no functional purpose though. [Ajarn]
#ifdef DEBUG
if (i != 0) {
sprintf(tmp_sql , "SELECT max(`char_id`) FROM `%s`", char_db);
sql_query(tmp_sql,"mmo_char_sql_init");
if((sql_res = mysql_store_result(&mysql_handle)) && (sql_row = mysql_fetch_row(sql_res)))
char_id_count = atoi (sql_row[0]);
cid = atoi (sql_row[0]);
mysql_free_result(sql_res);
#ifdef DEBUG
printf("Highest Char ID [%d]\n",char_id_count);
} else {
printf("Highest Char ID [%d]\n",char_id_count);
#endif
}
printf("Highest Char ID [%d]\n",cid);
#endif
if (i == 0) {
// If there is no characters in the SQL DB, make sure the starting id will be MIN_CHAR_ID
// Remove once main.sql has this to begin with and it's a standard to have it be this way
// (thus saving a check) [Ajarn]
sprintf(tmp_sql , "ALTER TABLE `%s` AUTO_INCREMENT = %d", char_db, MIN_CHAR_ID-1);
sql_query(tmp_sql,"mmo_char_sql_init");
}
#ifdef DEBUG
printf("Init finsihed\n");
@ -992,7 +1004,7 @@ int mmo_char_sql_init(void) {
int make_new_char_sql(int fd, unsigned char *dat) {
struct char_session_data *sd;
char t_name[100];
int i;
int i, cid;
//aphostropy error check! - fixed!
jstrescapecpy(t_name, dat);
@ -1065,30 +1077,32 @@ int make_new_char_sql(int fd, unsigned char *dat) {
mysql_free_result(sql_res);
}
char_id_count++;
//char_id_count++;
// make new char.
sprintf(tmp_sql,"INSERT INTO `%s` (`char_id`,`account_id`,`char_num`,`name`,`zeny`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,"
"`max_hp`,`hp`,`max_sp`,`sp`,`hair`,`hair_color`,`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`)"
" VALUES ('%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d','%d', '%d','%d', '%d','%s','%d','%d','%s','%d','%d')",
char_db, char_id_count, sd->account_id , dat[30] , t_name, start_zeny, dat[24], dat[25], dat[26], dat[27], dat[28], dat[29],
(40 * (100 + dat[26])/100) , (40 * (100 + dat[26])/100 ), (11 * (100 + dat[27])/100), (11 * (100 + dat[27])/100), dat[33], dat[31],
// make new char.
sprintf(tmp_sql,"INSERT INTO `%s` (`account_id`,`char_num`,`name`,`zeny`,`str`,`agi`,`vit`,`int`,`dex`,`luk`,"
"`max_hp`,`hp`,`max_sp`,`sp`,`hair`,`hair_color`,`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`)"
" VALUES ('%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d','%d', '%d','%d', '%d','%s','%d','%d','%s','%d','%d')",
char_db, sd->account_id , dat[30] , t_name, start_zeny, dat[24], dat[25], dat[26], dat[27], dat[28], dat[29],
(40 * (100 + dat[26])/100) , (40 * (100 + dat[26])/100 ), (11 * (100 + dat[27])/100), (11 * (100 + dat[27])/100), dat[33], dat[31],
start_point.map,start_point.x,start_point.y, start_point.map,start_point.x,start_point.y);
if (mysql_query(&mysql_handle, tmp_sql)) {
printf("DB server Error (insert new char into `char`)- %s\n", mysql_error(&mysql_handle));
return -1;
}
cid = mysql_last_insert_id(sql_res);
//`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`)
sprintf(tmp_sql,"INSERT INTO `%s` (`char_id`,`nameid`, `amount`, `equip`, `identify`) VALUES ('%d', '%d', '%d', '%d', '%d'),('%d', '%d', '%d', '%d', '%d')",
inventory_db, char_id_count, 1201,1,0x02,1,char_id_count,2301,1,0x10,1); //add Knife and Cotton Shirt
inventory_db, cid, 1201,1,0x02,1,cid,2301,1,0x10,1); //add Knife and Cotton Shirt
sql_query(tmp_sql,"make_new_char_sql");
#ifdef DEBUG
printf("Make new char success - id:(\033[1;32m%d\033[0m\tname:\033[1;32%s\033[0m\n", char_id_count, t_name);
printf("Make new char success - id:(\033[1;32m%d\033[0m\tname:\033[1;32%s\033[0m\n", cid, t_name);
#endif
return char_id_count;
return cid;
}
int count_users(void) {

View File

@ -54,6 +54,8 @@
#define MIN_CLOTH_COLOR battle_config.min_cloth_color
#define MAX_CLOTH_COLOR battle_config.max_cloth_color
#define MIN_CHAR_ID 150000 // shouldn't ever be changed, the client requires this min value [Ajarn]
// for produce
#define MIN_ATTRIBUTE 0
#define MAX_ATTRIBUTE 4