svn:eol-style native for char_sql's int_mercenary code (missing in r13166).
git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@13715 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
parent
dd635a835a
commit
8e3102cfc1
@ -1,221 +1,221 @@
|
|||||||
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
|
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
|
||||||
// For more information, see LICENCE in the main folder
|
// For more information, see LICENCE in the main folder
|
||||||
|
|
||||||
#include "../common/mmo.h"
|
#include "../common/mmo.h"
|
||||||
#include "../common/malloc.h"
|
#include "../common/malloc.h"
|
||||||
#include "../common/strlib.h"
|
#include "../common/strlib.h"
|
||||||
#include "../common/showmsg.h"
|
#include "../common/showmsg.h"
|
||||||
#include "../common/socket.h"
|
#include "../common/socket.h"
|
||||||
#include "../common/utils.h"
|
#include "../common/utils.h"
|
||||||
#include "../common/sql.h"
|
#include "../common/sql.h"
|
||||||
#include "char.h"
|
#include "char.h"
|
||||||
#include "inter.h"
|
#include "inter.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
bool mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status)
|
bool mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status)
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
|
|
||||||
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `mercenary_owner` WHERE `char_id` = '%d'", char_id) )
|
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `mercenary_owner` WHERE `char_id` = '%d'", char_id) )
|
||||||
{
|
{
|
||||||
Sql_ShowDebug(sql_handle);
|
Sql_ShowDebug(sql_handle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
|
if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
|
||||||
{
|
{
|
||||||
Sql_FreeResult(sql_handle);
|
Sql_FreeResult(sql_handle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sql_GetData(sql_handle, 0, &data, NULL); status->mer_id = atoi(data);
|
Sql_GetData(sql_handle, 0, &data, NULL); status->mer_id = atoi(data);
|
||||||
Sql_GetData(sql_handle, 1, &data, NULL); status->arch_calls = atoi(data);
|
Sql_GetData(sql_handle, 1, &data, NULL); status->arch_calls = atoi(data);
|
||||||
Sql_GetData(sql_handle, 2, &data, NULL); status->arch_faith = atoi(data);
|
Sql_GetData(sql_handle, 2, &data, NULL); status->arch_faith = atoi(data);
|
||||||
Sql_GetData(sql_handle, 3, &data, NULL); status->spear_calls = atoi(data);
|
Sql_GetData(sql_handle, 3, &data, NULL); status->spear_calls = atoi(data);
|
||||||
Sql_GetData(sql_handle, 4, &data, NULL); status->spear_faith = atoi(data);
|
Sql_GetData(sql_handle, 4, &data, NULL); status->spear_faith = atoi(data);
|
||||||
Sql_GetData(sql_handle, 5, &data, NULL); status->sword_calls = atoi(data);
|
Sql_GetData(sql_handle, 5, &data, NULL); status->sword_calls = atoi(data);
|
||||||
Sql_GetData(sql_handle, 6, &data, NULL); status->sword_faith = atoi(data);
|
Sql_GetData(sql_handle, 6, &data, NULL); status->sword_faith = atoi(data);
|
||||||
Sql_FreeResult(sql_handle);
|
Sql_FreeResult(sql_handle);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mercenary_owner_tosql(int char_id, struct mmo_charstatus *status)
|
bool mercenary_owner_tosql(int char_id, struct mmo_charstatus *status)
|
||||||
{
|
{
|
||||||
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `mercenary_owner` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
|
if( SQL_ERROR == Sql_Query(sql_handle, "REPLACE INTO `mercenary_owner` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
|
||||||
char_id, status->mer_id, status->arch_calls, status->arch_faith, status->spear_calls, status->spear_faith, status->sword_calls, status->sword_faith) )
|
char_id, status->mer_id, status->arch_calls, status->arch_faith, status->spear_calls, status->spear_faith, status->sword_calls, status->sword_faith) )
|
||||||
{
|
{
|
||||||
Sql_ShowDebug(sql_handle);
|
Sql_ShowDebug(sql_handle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mercenary_owner_delete(int char_id)
|
bool mercenary_owner_delete(int char_id)
|
||||||
{
|
{
|
||||||
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `mercenary_owner` WHERE `char_id` = '%d'", char_id) )
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `mercenary_owner` WHERE `char_id` = '%d'", char_id) )
|
||||||
Sql_ShowDebug(sql_handle);
|
Sql_ShowDebug(sql_handle);
|
||||||
|
|
||||||
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `mercenary` WHERE `char_id` = '%d'", char_id) )
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `mercenary` WHERE `char_id` = '%d'", char_id) )
|
||||||
Sql_ShowDebug(sql_handle);
|
Sql_ShowDebug(sql_handle);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mapif_mercenary_save(struct s_mercenary* merc)
|
bool mapif_mercenary_save(struct s_mercenary* merc)
|
||||||
{
|
{
|
||||||
bool flag = true;
|
bool flag = true;
|
||||||
|
|
||||||
if( merc->mercenary_id == 0 )
|
if( merc->mercenary_id == 0 )
|
||||||
{ // Create new DB entry
|
{ // Create new DB entry
|
||||||
if( SQL_ERROR == Sql_Query(sql_handle,
|
if( SQL_ERROR == Sql_Query(sql_handle,
|
||||||
"INSERT INTO `mercenary` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')",
|
"INSERT INTO `mercenary` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')",
|
||||||
merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) )
|
merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) )
|
||||||
{
|
{
|
||||||
Sql_ShowDebug(sql_handle);
|
Sql_ShowDebug(sql_handle);
|
||||||
flag = false;
|
flag = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
merc->mercenary_id = (int)Sql_LastInsertId(sql_handle);
|
merc->mercenary_id = (int)Sql_LastInsertId(sql_handle);
|
||||||
}
|
}
|
||||||
else if( SQL_ERROR == Sql_Query(sql_handle,
|
else if( SQL_ERROR == Sql_Query(sql_handle,
|
||||||
"UPDATE `mercenary` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'",
|
"UPDATE `mercenary` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'",
|
||||||
merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) )
|
merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) )
|
||||||
{ // Update DB entry
|
{ // Update DB entry
|
||||||
Sql_ShowDebug(sql_handle);
|
Sql_ShowDebug(sql_handle);
|
||||||
flag = false;
|
flag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc)
|
bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc)
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
|
|
||||||
memset(merc, 0, sizeof(struct s_mercenary));
|
memset(merc, 0, sizeof(struct s_mercenary));
|
||||||
merc->mercenary_id = merc_id;
|
merc->mercenary_id = merc_id;
|
||||||
merc->char_id = char_id;
|
merc->char_id = char_id;
|
||||||
|
|
||||||
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `mercenary` WHERE `mer_id` = '%d' AND `char_id` = '%d'", merc_id, char_id) )
|
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `class`, `hp`, `sp`, `kill_counter`, `life_time` FROM `mercenary` WHERE `mer_id` = '%d' AND `char_id` = '%d'", merc_id, char_id) )
|
||||||
{
|
{
|
||||||
Sql_ShowDebug(sql_handle);
|
Sql_ShowDebug(sql_handle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
|
if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
|
||||||
{
|
{
|
||||||
Sql_FreeResult(sql_handle);
|
Sql_FreeResult(sql_handle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sql_GetData(sql_handle, 0, &data, NULL); merc->class_ = atoi(data);
|
Sql_GetData(sql_handle, 0, &data, NULL); merc->class_ = atoi(data);
|
||||||
Sql_GetData(sql_handle, 1, &data, NULL); merc->hp = atoi(data);
|
Sql_GetData(sql_handle, 1, &data, NULL); merc->hp = atoi(data);
|
||||||
Sql_GetData(sql_handle, 2, &data, NULL); merc->sp = atoi(data);
|
Sql_GetData(sql_handle, 2, &data, NULL); merc->sp = atoi(data);
|
||||||
Sql_GetData(sql_handle, 3, &data, NULL); merc->kill_count = atoi(data);
|
Sql_GetData(sql_handle, 3, &data, NULL); merc->kill_count = atoi(data);
|
||||||
Sql_GetData(sql_handle, 4, &data, NULL); merc->life_time = atoi(data);
|
Sql_GetData(sql_handle, 4, &data, NULL); merc->life_time = atoi(data);
|
||||||
Sql_FreeResult(sql_handle);
|
Sql_FreeResult(sql_handle);
|
||||||
if( save_log )
|
if( save_log )
|
||||||
ShowInfo("Mercenary loaded (%d - %d).\n", merc->mercenary_id, merc->char_id);
|
ShowInfo("Mercenary loaded (%d - %d).\n", merc->mercenary_id, merc->char_id);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mapif_mercenary_delete(int merc_id)
|
bool mapif_mercenary_delete(int merc_id)
|
||||||
{
|
{
|
||||||
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `mercenary` WHERE `mer_id` = '%d'", merc_id) )
|
if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `mercenary` WHERE `mer_id` = '%d'", merc_id) )
|
||||||
{
|
{
|
||||||
Sql_ShowDebug(sql_handle);
|
Sql_ShowDebug(sql_handle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TXT_SQL_CONVERT
|
#ifndef TXT_SQL_CONVERT
|
||||||
|
|
||||||
static void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char flag)
|
static void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char flag)
|
||||||
{
|
{
|
||||||
int size = sizeof(struct s_mercenary) + 5;
|
int size = sizeof(struct s_mercenary) + 5;
|
||||||
|
|
||||||
WFIFOHEAD(fd,size);
|
WFIFOHEAD(fd,size);
|
||||||
WFIFOW(fd,0) = 0x3870;
|
WFIFOW(fd,0) = 0x3870;
|
||||||
WFIFOW(fd,2) = size;
|
WFIFOW(fd,2) = size;
|
||||||
WFIFOB(fd,4) = flag;
|
WFIFOB(fd,4) = flag;
|
||||||
memcpy(WFIFOP(fd,5),merc,sizeof(struct s_mercenary));
|
memcpy(WFIFOP(fd,5),merc,sizeof(struct s_mercenary));
|
||||||
WFIFOSET(fd,size);
|
WFIFOSET(fd,size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mapif_parse_mercenary_create(int fd, struct s_mercenary* merc)
|
static void mapif_parse_mercenary_create(int fd, struct s_mercenary* merc)
|
||||||
{
|
{
|
||||||
bool result = mapif_mercenary_save(merc);
|
bool result = mapif_mercenary_save(merc);
|
||||||
mapif_mercenary_send(fd, merc, result);
|
mapif_mercenary_send(fd, merc, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mapif_parse_mercenary_load(int fd, int merc_id, int char_id)
|
static void mapif_parse_mercenary_load(int fd, int merc_id, int char_id)
|
||||||
{
|
{
|
||||||
struct s_mercenary merc;
|
struct s_mercenary merc;
|
||||||
bool result = mapif_mercenary_load(merc_id, char_id, &merc);
|
bool result = mapif_mercenary_load(merc_id, char_id, &merc);
|
||||||
mapif_mercenary_send(fd, &merc, result);
|
mapif_mercenary_send(fd, &merc, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mapif_mercenary_deleted(int fd, unsigned char flag)
|
static void mapif_mercenary_deleted(int fd, unsigned char flag)
|
||||||
{
|
{
|
||||||
WFIFOHEAD(fd,3);
|
WFIFOHEAD(fd,3);
|
||||||
WFIFOW(fd,0) = 0x3871;
|
WFIFOW(fd,0) = 0x3871;
|
||||||
WFIFOB(fd,2) = flag;
|
WFIFOB(fd,2) = flag;
|
||||||
WFIFOSET(fd,3);
|
WFIFOSET(fd,3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mapif_parse_mercenary_delete(int fd, int merc_id)
|
static void mapif_parse_mercenary_delete(int fd, int merc_id)
|
||||||
{
|
{
|
||||||
bool result = mapif_mercenary_delete(merc_id);
|
bool result = mapif_mercenary_delete(merc_id);
|
||||||
mapif_mercenary_deleted(fd, result);
|
mapif_mercenary_deleted(fd, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mapif_mercenary_saved(int fd, unsigned char flag)
|
static void mapif_mercenary_saved(int fd, unsigned char flag)
|
||||||
{
|
{
|
||||||
WFIFOHEAD(fd,3);
|
WFIFOHEAD(fd,3);
|
||||||
WFIFOW(fd,0) = 0x3872;
|
WFIFOW(fd,0) = 0x3872;
|
||||||
WFIFOB(fd,2) = flag;
|
WFIFOB(fd,2) = flag;
|
||||||
WFIFOSET(fd,3);
|
WFIFOSET(fd,3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mapif_parse_mercenary_save(int fd, struct s_mercenary* merc)
|
static void mapif_parse_mercenary_save(int fd, struct s_mercenary* merc)
|
||||||
{
|
{
|
||||||
bool result = mapif_mercenary_save(merc);
|
bool result = mapif_mercenary_save(merc);
|
||||||
mapif_mercenary_saved(fd, result);
|
mapif_mercenary_saved(fd, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int inter_mercenary_sql_init(void)
|
int inter_mercenary_sql_init(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void inter_mercenary_sql_final(void)
|
void inter_mercenary_sql_final(void)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* Inter Packets
|
* Inter Packets
|
||||||
*------------------------------------------*/
|
*------------------------------------------*/
|
||||||
int inter_mercenary_parse_frommap(int fd)
|
int inter_mercenary_parse_frommap(int fd)
|
||||||
{
|
{
|
||||||
unsigned short cmd = RFIFOW(fd,0);
|
unsigned short cmd = RFIFOW(fd,0);
|
||||||
|
|
||||||
switch( cmd )
|
switch( cmd )
|
||||||
{
|
{
|
||||||
case 0x3070: mapif_parse_mercenary_create(fd, (struct s_mercenary*)RFIFOP(fd,4)); break;
|
case 0x3070: mapif_parse_mercenary_create(fd, (struct s_mercenary*)RFIFOP(fd,4)); break;
|
||||||
case 0x3071: mapif_parse_mercenary_load(fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6)); break;
|
case 0x3071: mapif_parse_mercenary_load(fd, (int)RFIFOL(fd,2), (int)RFIFOL(fd,6)); break;
|
||||||
case 0x3072: mapif_parse_mercenary_delete(fd, (int)RFIFOL(fd,2)); break;
|
case 0x3072: mapif_parse_mercenary_delete(fd, (int)RFIFOL(fd,2)); break;
|
||||||
case 0x3073: mapif_parse_mercenary_save(fd, (struct s_mercenary*)RFIFOP(fd,4)); break;
|
case 0x3073: mapif_parse_mercenary_save(fd, (struct s_mercenary*)RFIFOP(fd,4)); break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif //TXT_SQL_CONVERT
|
#endif //TXT_SQL_CONVERT
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
|
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
|
||||||
// For more information, see LICENCE in the main folder
|
// For more information, see LICENCE in the main folder
|
||||||
|
|
||||||
#ifndef _INT_MERCENARY_SQL_H_
|
#ifndef _INT_MERCENARY_SQL_H_
|
||||||
#define _INT_MERCENARY_SQL_H_
|
#define _INT_MERCENARY_SQL_H_
|
||||||
|
|
||||||
struct s_mercenary;
|
struct s_mercenary;
|
||||||
|
|
||||||
int inter_mercenary_sql_init(void);
|
int inter_mercenary_sql_init(void);
|
||||||
void inter_mercenary_sql_final(void);
|
void inter_mercenary_sql_final(void);
|
||||||
int inter_mercenary_parse_frommap(int fd);
|
int inter_mercenary_parse_frommap(int fd);
|
||||||
|
|
||||||
// Mercenary Owner Database
|
// Mercenary Owner Database
|
||||||
bool mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status);
|
bool mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status);
|
||||||
bool mercenary_owner_tosql(int char_id, struct mmo_charstatus *status);
|
bool mercenary_owner_tosql(int char_id, struct mmo_charstatus *status);
|
||||||
bool mercenary_owner_delete(int char_id);
|
bool mercenary_owner_delete(int char_id);
|
||||||
|
|
||||||
bool mapif_mercenary_delete(int merc_id);
|
bool mapif_mercenary_delete(int merc_id);
|
||||||
|
|
||||||
#endif /* _INT_MERCENARY_SQL_H_ */
|
#endif /* _INT_MERCENARY_SQL_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user