viewing paste char.c.patch | Diff

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
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);
 
Viewed 968 times, submitted by Guest.