Index: char.c
===================================================================
--- char.c (revision 14608)
+++ char.c (working copy)
@@ -78,6 +78,7 @@
char acc_reg_str_db[32] = "acc_reg_str_db";
char char_reg_str_db[32] = "char_reg_str_db";
char char_reg_num_db[32] = "char_reg_num_db";
+char bonus_script_db[256] = "bonus_script"; // cydh bonus_script
// show loading/saving messages
int save_log = 1;
@@ -156,6 +157,11 @@
struct fame_list chemist_fame_list[MAX_FAME_LIST];
struct fame_list taekwon_fame_list[MAX_FAME_LIST];
+// cydh bonus_script Start
+void bonus_script_get(int fd);///Get bonus_script data
+void bonus_script_save(int fd); ///Save bonus_script data
+// cydh bonus_script End
+
// check for exit signal
// 0 is saving complete
// other is char_id
@@ -1847,6 +1853,18 @@
Sql_ShowDebug(sql_handle);
#endif
+ // cydh bonus_script Start
+ /* bonus_scripts */
+ if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id` = '%d'", bonus_script_db, char_id) )
+ Sql_ShowDebug(sql_handle);
+
+ if (log_char) {
+ if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`time`, `account_id`,`char_num`,`char_msg`,`name`) VALUES (NOW(), '%d', '%d', 'Deleted char (CID %d)', '%s')",
+ charlog_db, account_id, 0, char_id, esc_name) )
+ Sql_ShowDebug(sql_handle);
+ }
+ // cydh bonus_script End
+
/* delete character */
if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `char_id`='%d'", char_db, char_id) )
Sql_ShowDebug(sql_handle);
@@ -3802,6 +3820,10 @@
}
break;
+ // cydh bonus_script Start
+ case 0x2b2d: bonus_script_get(fd); break; //Load data
+ case 0x2b2e: bonus_script_save(fd); break;//Save data
+ // cydh bonus_script end
default:
{
@@ -4967,6 +4989,97 @@
return 1;
}
+// cydh bonus_script Start
+/** [Cydh]
+* Get bonus_script data(s) from table to load
+* @param fd
+*/
+void bonus_script_get(int fd) {
+ if (RFIFOREST(fd) < 6)
+ return;
+ else {
+ int cid;
+ cid = RFIFOL(fd,2);
+ RFIFOSKIP(fd,6);
+
+ if (SQL_ERROR == SQL->Query(sql_handle,"SELECT `script`, `tick`, `flag`, `type`, `icon` FROM `%s` WHERE `char_id`='%d'",
+ bonus_script_db,cid))
+ {
+ Sql_ShowDebug(sql_handle);
+ return;
+ }
+ if (SQL->NumRows(sql_handle) > 0) {
+ struct bonus_script_data bsdata;
+ int count;
+ char *data;
+
+ WFIFOHEAD(fd,10+50*sizeof(struct bonus_script_data));
+ WFIFOW(fd,0) = 0x2b2f;
+ WFIFOL(fd,4) = cid;
+ for (count = 0; count < 20 && SQL_SUCCESS == SQL->NextRow(sql_handle); ++count) {
+ SQL->GetData(sql_handle,0,&data,NULL); memcpy(bsdata.script,data,strlen(data)+1);
+ SQL->GetData(sql_handle,1,&data,NULL); bsdata.tick = atoi(data);
+ SQL->GetData(sql_handle,2,&data,NULL); bsdata.flag = atoi(data);
+ SQL->GetData(sql_handle,3,&data,NULL); bsdata.type = atoi(data);
+ SQL->GetData(sql_handle,4,&data,NULL); bsdata.icon = atoi(data);
+ memcpy(WFIFOP(fd,10+count*sizeof(struct bonus_script_data)),&bsdata,sizeof(struct bonus_script_data));
+ }
+ if (count >= MAX_PC_BONUS_SCRIPT)
+ ShowWarning("Too many bonus_script for %d, some of them were not loaded.\n",cid);
+ if (count > 0) {
+ WFIFOW(fd,2) = 10 + count*sizeof(struct bonus_script_data);
+ WFIFOW(fd,8) = count;
+ WFIFOSET(fd,WFIFOW(fd,2));
+
+ //Clear the data once loaded.
+ if (SQL_ERROR == SQL->Query(sql_handle,"DELETE FROM `%s` WHERE `char_id`='%d'",bonus_script_db,cid))
+ Sql_ShowDebug(sql_handle);
+ ShowInfo("Loaded %d bonus_script for char_id: %d\n",count,cid);
+ }
+ }
+ SQL->FreeResult(sql_handle);
+ }
+}
+
+/** [Cydh]
+* Save bonus_script data(s) to the table
+* @param fd
+*/
+void bonus_script_save(int fd) {
+ if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
+ return;
+ else {
+ int count, cid;
+
+ cid = RFIFOL(fd,4);
+ count = RFIFOW(fd,8);
+
+ if (count > 0) {
+ struct bonus_script_data bs;
+ StringBuf buf;
+ int i;
+ char esc_script[MAX_BONUS_SCRIPT_LENGTH] = "";
+
+ StrBuf->Init(&buf);
+ StrBuf->Printf(&buf,"INSERT INTO `%s` (`char_id`, `script`, `tick`, `flag`, `type`, `icon`) VALUES ",bonus_script_db);
+ for (i = 0; i < count; ++i) {
+ memcpy(&bs,RFIFOP(fd,10+i*sizeof(struct bonus_script_data)),sizeof(struct bonus_script_data));
+ SQL->EscapeString(sql_handle,esc_script,bs.script);
+ if (i > 0)
+ StrBuf->AppendStr(&buf,", ");
+ StrBuf->Printf(&buf,"('%d','%s','%d','%d','%d',",cid,esc_script,bs.tick,bs.flag,bs.type);
+ StrBuf->Printf(&buf, "'%d')", bs.icon);
+ }
+ if (SQL_ERROR == SQL->QueryStr(sql_handle,StrBuf->Value(&buf)))
+ Sql_ShowDebug(sql_handle);
+ StrBuf->Destroy(&buf);
+ ShowInfo("Saved %d bonus_script for char_id: %d\n",count,cid,bs.icon);
+ }
+ RFIFOSKIP(fd,RFIFOW(fd,2));
+ }
+}
+// cydh bonus_script end
+
//------------------------------------------------
//Invoked 15 seconds after mapif_disconnectplayer in case the map server doesn't
//replies/disconnect the player we tried to kick. [Skotlex]
@@ -5146,7 +5259,10 @@
safestrncpy(acc_reg_str_db, w2, sizeof(acc_reg_str_db));
else if(!strcmpi(w1,"acc_reg_num_db"))
safestrncpy(acc_reg_num_db, w2, sizeof(acc_reg_num_db));
-
+ // cydh bonus_script Start
+ else if(!strcmpi(w1,"bonus_script_db"))
+ safestrncpy(bonus_script_db, w2, sizeof(bonus_script_db));
+ // cydh bonus_script End
//support the import command, just like any other config
else if(!strcmpi(w1,"import"))
sql_config_read(w2);