* Some more updates to Quest Log

- Implemented a new saving mechanism. Now they can be saved every 'autosave_time' in case the char-server is not online when you get a quest.
- Improved 'changequest' code.
- Increase MAX_QUEST_DB to 1200.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@13973 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
Inkfish
2009-07-28 04:04:50 +00:00
parent 9cc789d234
commit b753cba749
12 changed files with 209 additions and 255 deletions

View File

@@ -2,6 +2,7 @@
// For more information, see LICENCE in the main folder
#include "../common/mmo.h"
#include "../common/db.h"
#include "../common/malloc.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
@@ -57,41 +58,73 @@ int mapif_quests_fromsql(int char_id, struct quest questlog[])
return i;
}
//Delete a quest
int mapif_parse_quest_delete(int fd)
//Save quests
int mapif_parse_quest_save(int fd)
{
int i, j, num2, num1 = (RFIFOW(fd,2)-8)/sizeof(struct quest);
int char_id = RFIFOL(fd,4);
struct quest qd1[MAX_QUEST_DB],qd2[MAX_QUEST_DB];
uint8 buf[MAX_QUEST_DB];
int count = 0;
bool success = true;
int char_id = RFIFOL(fd,2);
int quest_id = RFIFOL(fd,6);
memset(qd1, 0, sizeof(qd1));
memset(qd2, 0, sizeof(qd2));
memcpy(&qd1, RFIFOP(fd,8), RFIFOW(fd,2)-8);
num2 = mapif_quests_fromsql(char_id, qd2);
for( i = 0; i < num1; i++ )
{
ARR_FIND( 0, num2, j, qd1[i].quest_id == qd2[j].quest_id );
if( j < num2 ) // Update existed quests
{ // Only states and counts are changable.
if( qd1[i].state != qd2[j].state || qd1[i].count[0] != qd2[j].count[0] || qd1[i].count[1] != qd2[j].count[1] || qd1[i].count[2] != qd2[j].count[2] )
mapif_quest_update(char_id, qd1[i]);
if( j < (--num2) )
{
memmove(&qd2[j],&qd2[j+1],sizeof(struct quest)*(num2-j));
memset(&qd2[num2], 0, sizeof(struct quest));
}
}
else // Add new quests
{
mapif_quest_add(char_id, qd1[i]);
WBUFL(buf,count*4) = qd1[i].quest_id;
count++;
}
}
for( i = 0; i < num2; i++ ) // Quests not in qd1 but in qd2 are to be erased.
mapif_quest_delete(char_id, qd2[i].quest_id);
WFIFOHEAD(fd,8+4*count);
WFIFOW(fd,0) = 0x3861;
WFIFOW(fd,2) = 8+4*count;
WFIFOL(fd,4) = char_id;
memcpy(WFIFOP(fd,8), buf, count*4);
WFIFOSET(fd,WFIFOW(fd,2));
return 0;
}
//Delete a quest
int mapif_quest_delete(int char_id, int quest_id)
{
if ( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, quest_id, char_id) )
{
Sql_ShowDebug(sql_handle);
success = false;
return -1;
}
WFIFOHEAD(fd,11);
WFIFOW(fd,0) = 0x3862;
WFIFOL(fd,2) = char_id;
WFIFOL(fd,6) = quest_id;
WFIFOB(fd,10) = success?1:0;
WFIFOSET(fd,11);
return 0;
return 1;
}
//Add a quest to a questlog
int mapif_parse_quest_add(int fd)
int mapif_quest_add(int char_id, struct quest qd)
{
StringBuf buf;
bool success = true;
int char_id = RFIFOL(fd,4);
struct quest qd;
memcpy(&qd, RFIFOP(fd,8), RFIFOW(fd,2)-8);
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`, `mob1`, `count1`, `mob2`, `count2`, `mob3`, `count3`) VALUES ('%d', '%d', '%d','%d', '%d', '%d', '%d', '%d', '%d', '%d')", quest_db, qd.quest_id, char_id, qd.state, qd.time, qd.mob[0], qd.count[0], qd.mob[1], qd.count[1], qd.mob[2], qd.count[2]);
@@ -99,32 +132,18 @@ int mapif_parse_quest_add(int fd)
if ( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
{
Sql_ShowDebug(sql_handle);
success = false;
return -1;
}
WFIFOHEAD(fd,11);
WFIFOW(fd,0) = 0x3861;
WFIFOL(fd,2) = char_id;
WFIFOL(fd,6) = qd.quest_id;
WFIFOB(fd,10) = success?1:0;
WFIFOSET(fd,11);
StringBuf_Destroy(&buf);
return 0;
return 1;
}
//Update a questlog
int mapif_parse_quest_update(int fd)
int mapif_quest_update(int char_id, struct quest qd)
{
StringBuf buf;
bool success = true;
int char_id = RFIFOL(fd,4);
struct quest qd;
memcpy(&qd, RFIFOP(fd,8), RFIFOW(fd,2)-8);
StringBuf_Init(&buf);
StringBuf_Printf(&buf, "UPDATE `%s` SET `state`='%d', `count1`='%d', `count2`='%d', `count3`='%d' WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id);
@@ -132,25 +151,18 @@ int mapif_parse_quest_update(int fd)
if ( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
{
Sql_ShowDebug(sql_handle);
success = false;
return -1;
}
WFIFOHEAD(fd,11);
WFIFOW(fd,0) = 0x3863;
WFIFOL(fd,2) = char_id;
WFIFOL(fd,6) = qd.quest_id;
WFIFOB(fd,10) = success?1:0;
WFIFOSET(fd,11);
StringBuf_Destroy(&buf);
return 0;
return 1;
}
//Send questlog to map server
int mapif_send_quests(int fd, int char_id)
int mapif_parse_quest_load(int fd)
{
int char_id = RFIFOL(fd,2);
struct quest tmp_questlog[MAX_QUEST_DB];
int num_quests, i, num_complete = 0;
int complete[MAX_QUEST_DB];
@@ -185,25 +197,14 @@ int mapif_send_quests(int fd, int char_id)
return 0;
}
//Map server requesting a character's quest log
int mapif_parse_loadquestrequest(int fd)
{
mapif_send_quests(fd, RFIFOL(fd,2));
return 0;
}
int inter_quest_parse_frommap(int fd)
{
switch(RFIFOW(fd,0))
{
case 0x3060: mapif_parse_loadquestrequest(fd); break;
case 0x3061: mapif_parse_quest_add(fd); break;
case 0x3062: mapif_parse_quest_delete(fd); break;
case 0x3063: mapif_parse_quest_update(fd); break;
case 0x3060: mapif_parse_quest_load(fd); break;
case 0x3061: mapif_parse_quest_save(fd); break;
default:
return 0;
}
return 1;
}

View File

@@ -8,6 +8,9 @@
struct quest;
int inter_quest_parse_frommap(int fd);
int mapif_quest_delete(int char_id, int quest_id);
int mapif_quest_add(int char_id, struct quest qd);
int mapif_quest_update(int char_id, struct quest qd);
#endif

View File

@@ -51,7 +51,7 @@ int inter_recv_packet_length[] = {
-1, 6,-1,-1, 55,19, 6,-1, 14,-1,-1,-1, 18,19,186,-1, // 3030-
5, 9, 0, 0, 0, 0, 0, 0, 7, 6,10,10, 10,-1, 0, 0, // 3040-
-1,-1,10,10, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050- Auction System [Zephyrus]
6,-1,10,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin] [Inkfish]
6,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin] [Inkfish]
-1,10, 6,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3070- Mercenary packets [Zephyrus]
48,14,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3080-
-1,10,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3090- Homunculus packets [albator]