int_auction.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "int_auction.hpp"
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include "../common/malloc.hpp"
  8. #include "../common/mmo.hpp"
  9. #include "../common/showmsg.hpp"
  10. #include "../common/socket.hpp"
  11. #include "../common/sql.hpp"
  12. #include "../common/strlib.hpp"
  13. #include "../common/timer.hpp"
  14. #include "char.hpp"
  15. #include "char_mapif.hpp"
  16. #include "inter.hpp"
  17. #include "int_mail.hpp"
  18. static DBMap* auction_db_ = NULL; // int auction_id -> struct auction_data*
  19. void auction_delete(struct auction_data *auction);
  20. TIMER_FUNC(auction_end_timer);
  21. int auction_count(uint32 char_id, bool buy)
  22. {
  23. int i = 0;
  24. struct auction_data *auction;
  25. DBIterator *iter = db_iterator(auction_db_);
  26. for( auction = (struct auction_data *)dbi_first(iter); dbi_exists(iter); auction = (struct auction_data *)dbi_next(iter) )
  27. {
  28. if( (buy && auction->buyer_id == char_id) || (!buy && auction->seller_id == char_id) )
  29. i++;
  30. }
  31. dbi_destroy(iter);
  32. return i;
  33. }
  34. void auction_save(struct auction_data *auction)
  35. {
  36. int j;
  37. StringBuf buf;
  38. SqlStmt* stmt;
  39. if( !auction )
  40. return;
  41. StringBuf_Init(&buf);
  42. StringBuf_Printf(&buf, "UPDATE `%s` SET `seller_id` = '%d', `seller_name` = ?, `buyer_id` = '%d', `buyer_name` = ?, `price` = '%d', `buynow` = '%d', `hours` = '%d', `timestamp` = '%lu', `nameid` = '%u', `item_name` = ?, `type` = '%d', `refine` = '%d', `attribute` = '%d', `enchantgrade`",
  43. schema_config.auction_db, auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute, auction->item.enchantgrade);
  44. for( j = 0; j < MAX_SLOTS; j++ )
  45. StringBuf_Printf(&buf, ", `card%d` = '%u'", j, auction->item.card[j]);
  46. for (j = 0; j < MAX_ITEM_RDM_OPT; j++) {
  47. StringBuf_Printf(&buf, ", `option_id%d` = '%d'", j, auction->item.option[j].id);
  48. StringBuf_Printf(&buf, ", `option_val%d` = '%d'", j, auction->item.option[j].value);
  49. StringBuf_Printf(&buf, ", `option_parm%d` = '%d'", j, auction->item.option[j].param);
  50. }
  51. StringBuf_Printf(&buf, " WHERE `auction_id` = '%d'", auction->auction_id);
  52. stmt = SqlStmt_Malloc(sql_handle);
  53. if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
  54. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
  55. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH))
  56. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH))
  57. || SQL_SUCCESS != SqlStmt_Execute(stmt) )
  58. {
  59. SqlStmt_ShowDebug(stmt);
  60. }
  61. SqlStmt_Free(stmt);
  62. StringBuf_Destroy(&buf);
  63. }
  64. unsigned int auction_create(struct auction_data *auction)
  65. {
  66. int j;
  67. StringBuf buf;
  68. SqlStmt* stmt;
  69. if( !auction )
  70. return false;
  71. auction->timestamp = time(NULL) + (auction->hours * 3600);
  72. StringBuf_Init(&buf);
  73. StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`,`enchantgrade`", schema_config.auction_db);
  74. for( j = 0; j < MAX_SLOTS; j++ )
  75. StringBuf_Printf(&buf, ",`card%d`", j);
  76. for (j = 0; j < MAX_ITEM_RDM_OPT; ++j) {
  77. StringBuf_Printf(&buf, ", `option_id%d`", j);
  78. StringBuf_Printf(&buf, ", `option_val%d`", j);
  79. StringBuf_Printf(&buf, ", `option_parm%d`", j);
  80. }
  81. StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%u',?,'%d','%d','%d','%" PRIu64 "','%d'",
  82. auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute, auction->item.unique_id, auction->item.enchantgrade);
  83. for( j = 0; j < MAX_SLOTS; j++ )
  84. StringBuf_Printf(&buf, ",'%u'", auction->item.card[j]);
  85. for (j = 0; j < MAX_ITEM_RDM_OPT; ++j) {
  86. StringBuf_Printf(&buf, ", '%d'", auction->item.option[j].id);
  87. StringBuf_Printf(&buf, ", '%d'", auction->item.option[j].value);
  88. StringBuf_Printf(&buf, ", '%d'", auction->item.option[j].param);
  89. }
  90. StringBuf_AppendStr(&buf, ")");
  91. stmt = SqlStmt_Malloc(sql_handle);
  92. if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
  93. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
  94. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH))
  95. || SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH))
  96. || SQL_SUCCESS != SqlStmt_Execute(stmt) )
  97. {
  98. SqlStmt_ShowDebug(stmt);
  99. auction->auction_id = 0;
  100. }
  101. else
  102. {
  103. struct auction_data *auction_;
  104. t_tick tick = auction->hours * 3600000;
  105. auction->item.amount = 1;
  106. auction->item.identify = 1;
  107. auction->item.expire_time = 0;
  108. auction->auction_id = (unsigned int)SqlStmt_LastInsertId(stmt);
  109. auction->auction_end_timer = add_timer( gettick() + tick , auction_end_timer, auction->auction_id, 0);
  110. ShowInfo("New Auction %u | time left %" PRtf " ms | By %s.\n", auction->auction_id, tick, auction->seller_name);
  111. CREATE(auction_, struct auction_data, 1);
  112. memcpy(auction_, auction, sizeof(struct auction_data));
  113. idb_put(auction_db_, auction_->auction_id, auction_);
  114. }
  115. SqlStmt_Free(stmt);
  116. StringBuf_Destroy(&buf);
  117. return auction->auction_id;
  118. }
  119. void mapif_Auction_message(uint32 char_id, unsigned char result)
  120. {
  121. unsigned char buf[74];
  122. WBUFW(buf,0) = 0x3854;
  123. WBUFL(buf,2) = char_id;
  124. WBUFL(buf,6) = result;
  125. chmapif_sendall(buf,7);
  126. }
  127. TIMER_FUNC(auction_end_timer){
  128. struct auction_data *auction;
  129. if( (auction = (struct auction_data *)idb_get(auction_db_, id)) != NULL )
  130. {
  131. if( auction->buyer_id )
  132. {
  133. mail_sendmail(0, msg_txt(200), auction->buyer_id, auction->buyer_name, msg_txt(201), msg_txt(202), 0, &auction->item, 1);
  134. mapif_Auction_message(auction->buyer_id, 6); // You have won the auction
  135. mail_sendmail(0, msg_txt(200), auction->seller_id, auction->seller_name, msg_txt(201), msg_txt(203), auction->price, NULL, 0);
  136. }
  137. else
  138. mail_sendmail(0, msg_txt(200), auction->seller_id, auction->seller_name, msg_txt(201), msg_txt(204), 0, &auction->item, 1);
  139. ShowInfo("Auction End: id %u.\n", auction->auction_id);
  140. auction->auction_end_timer = INVALID_TIMER;
  141. auction_delete(auction);
  142. }
  143. return 0;
  144. }
  145. void auction_delete(struct auction_data *auction)
  146. {
  147. unsigned int auction_id = auction->auction_id;
  148. if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%d'", schema_config.auction_db, auction_id) )
  149. Sql_ShowDebug(sql_handle);
  150. if( auction->auction_end_timer != INVALID_TIMER )
  151. delete_timer(auction->auction_end_timer, auction_end_timer);
  152. idb_remove(auction_db_, auction_id);
  153. }
  154. void inter_auctions_fromsql(void)
  155. {
  156. int i;
  157. char *data;
  158. StringBuf buf;
  159. t_tick tick = gettick(), endtick;
  160. time_t now = time(NULL);
  161. StringBuf_Init(&buf);
  162. StringBuf_AppendStr(&buf, "SELECT `auction_id`,`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,"
  163. "`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`,`enchantgrade`");
  164. for( i = 0; i < MAX_SLOTS; i++ )
  165. StringBuf_Printf(&buf, ",`card%d`", i);
  166. for (i = 0; i < MAX_ITEM_RDM_OPT; ++i) {
  167. StringBuf_Printf(&buf, ", `option_id%d`", i);
  168. StringBuf_Printf(&buf, ", `option_val%d`", i);
  169. StringBuf_Printf(&buf, ", `option_parm%d`", i);
  170. }
  171. StringBuf_Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", schema_config.auction_db);
  172. if( SQL_ERROR == Sql_Query(sql_handle, StringBuf_Value(&buf)) )
  173. Sql_ShowDebug(sql_handle);
  174. StringBuf_Destroy(&buf);
  175. while( SQL_SUCCESS == Sql_NextRow(sql_handle) )
  176. {
  177. struct item *item;
  178. struct auction_data *auction;
  179. CREATE(auction, struct auction_data, 1);
  180. Sql_GetData(sql_handle, 0, &data, NULL); auction->auction_id = atoi(data);
  181. Sql_GetData(sql_handle, 1, &data, NULL); auction->seller_id = atoi(data);
  182. Sql_GetData(sql_handle, 2, &data, NULL); safestrncpy(auction->seller_name, data, NAME_LENGTH);
  183. Sql_GetData(sql_handle, 3, &data, NULL); auction->buyer_id = atoi(data);
  184. Sql_GetData(sql_handle, 4, &data, NULL); safestrncpy(auction->buyer_name, data, NAME_LENGTH);
  185. Sql_GetData(sql_handle, 5, &data, NULL); auction->price = atoi(data);
  186. Sql_GetData(sql_handle, 6, &data, NULL); auction->buynow = atoi(data);
  187. Sql_GetData(sql_handle, 7, &data, NULL); auction->hours = atoi(data);
  188. Sql_GetData(sql_handle, 8, &data, NULL); auction->timestamp = atoi(data);
  189. item = &auction->item;
  190. Sql_GetData(sql_handle, 9, &data, NULL); item->nameid = strtoul(data, nullptr, 10);
  191. Sql_GetData(sql_handle,10, &data, NULL); safestrncpy(auction->item_name, data, ITEM_NAME_LENGTH);
  192. Sql_GetData(sql_handle,11, &data, NULL); auction->type = atoi(data);
  193. Sql_GetData(sql_handle,12, &data, NULL); item->refine = atoi(data);
  194. Sql_GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data);
  195. Sql_GetData(sql_handle,14, &data, NULL); item->unique_id = strtoull(data, NULL, 10);
  196. Sql_GetData(sql_handle,15, &data, NULL); item->enchantgrade = atoi(data);
  197. item->identify = 1;
  198. item->amount = 1;
  199. item->expire_time = 0;
  200. for( i = 0; i < MAX_SLOTS; i++ )
  201. {
  202. Sql_GetData(sql_handle, 16 + i, &data, NULL);
  203. item->card[i] = strtoul(data, nullptr, 10);
  204. }
  205. for (i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  206. Sql_GetData(sql_handle, 16 + MAX_SLOTS + i*3, &data, NULL);
  207. item->option[i].id = atoi(data);
  208. Sql_GetData(sql_handle, 17 + MAX_SLOTS + i*3, &data, NULL);
  209. item->option[i].value = atoi(data);
  210. Sql_GetData(sql_handle, 18 + MAX_SLOTS + i*3, &data, NULL);
  211. item->option[i].param = atoi(data);
  212. }
  213. if( auction->timestamp > now )
  214. endtick = ((unsigned int)(auction->timestamp - now) * 1000) + tick;
  215. else
  216. endtick = tick + 10000; // 10 Second's to process ended auctions
  217. auction->auction_end_timer = add_timer(endtick, auction_end_timer, auction->auction_id, 0);
  218. idb_put(auction_db_, auction->auction_id, auction);
  219. }
  220. Sql_FreeResult(sql_handle);
  221. }
  222. void mapif_Auction_sendlist(int fd, uint32 char_id, short count, short pages, unsigned char *buf)
  223. {
  224. int len = (sizeof(struct auction_data) * count) + 12;
  225. WFIFOHEAD(fd, len);
  226. WFIFOW(fd,0) = 0x3850;
  227. WFIFOW(fd,2) = len;
  228. WFIFOL(fd,4) = char_id;
  229. WFIFOW(fd,8) = count;
  230. WFIFOW(fd,10) = pages;
  231. memcpy(WFIFOP(fd,12), buf, len - 12);
  232. WFIFOSET(fd,len);
  233. }
  234. void mapif_parse_Auction_requestlist(int fd)
  235. {
  236. char searchtext[NAME_LENGTH];
  237. uint32 char_id = RFIFOL(fd,4), len = sizeof(struct auction_data);
  238. int price = RFIFOL(fd,10);
  239. short type = RFIFOW(fd,8), page = max(1,RFIFOW(fd,14));
  240. unsigned char buf[5 * sizeof(struct auction_data)];
  241. DBIterator *iter = db_iterator(auction_db_);
  242. struct auction_data *auction;
  243. short i = 0, j = 0, pages = 1;
  244. memcpy(searchtext, RFIFOP(fd,16), NAME_LENGTH);
  245. for( auction = static_cast<auction_data *>(dbi_first(iter)); dbi_exists(iter); auction = static_cast<auction_data *>(dbi_next(iter)) )
  246. {
  247. if( (type == 0 && auction->type != IT_ARMOR && auction->type != IT_PETARMOR) ||
  248. (type == 1 && auction->type != IT_WEAPON) ||
  249. (type == 2 && auction->type != IT_CARD) ||
  250. (type == 3 && auction->type != IT_ETC) ||
  251. (type == 4 && !strstr(auction->item_name, searchtext)) ||
  252. (type == 5 && auction->price > price) ||
  253. (type == 6 && auction->seller_id != char_id) ||
  254. (type == 7 && auction->buyer_id != char_id) )
  255. continue;
  256. i++;
  257. if( i > 5 )
  258. { // Counting Pages of Total Results (5 Results per Page)
  259. pages++;
  260. i = 1; // First Result of This Page
  261. }
  262. if( page != pages )
  263. continue; // This is not the requested Page
  264. memcpy(WBUFP(buf, j * len), auction, len);
  265. j++; // Found Results
  266. }
  267. dbi_destroy(iter);
  268. mapif_Auction_sendlist(fd, char_id, j, pages, buf);
  269. }
  270. void mapif_Auction_register(int fd, struct auction_data *auction)
  271. {
  272. int len = sizeof(struct auction_data) + 4;
  273. WFIFOHEAD(fd,len);
  274. WFIFOW(fd,0) = 0x3851;
  275. WFIFOW(fd,2) = len;
  276. memcpy(WFIFOP(fd,4), auction, sizeof(struct auction_data));
  277. WFIFOSET(fd,len);
  278. }
  279. void mapif_parse_Auction_register(int fd)
  280. {
  281. struct auction_data auction;
  282. if( RFIFOW(fd,2) != sizeof(struct auction_data) + 4 )
  283. return;
  284. memcpy(&auction, RFIFOP(fd,4), sizeof(struct auction_data));
  285. if( auction_count(auction.seller_id, false) < 5 )
  286. auction.auction_id = auction_create(&auction);
  287. mapif_Auction_register(fd, &auction);
  288. }
  289. void mapif_Auction_cancel(int fd, uint32 char_id, unsigned char result)
  290. {
  291. WFIFOHEAD(fd,7);
  292. WFIFOW(fd,0) = 0x3852;
  293. WFIFOL(fd,2) = char_id;
  294. WFIFOB(fd,6) = result;
  295. WFIFOSET(fd,7);
  296. }
  297. void mapif_parse_Auction_cancel(int fd)
  298. {
  299. uint32 char_id = RFIFOL(fd,2), auction_id = RFIFOL(fd,6);
  300. struct auction_data *auction;
  301. if( (auction = (struct auction_data *)idb_get(auction_db_, auction_id)) == NULL )
  302. {
  303. mapif_Auction_cancel(fd, char_id, 1); // Bid Number is Incorrect
  304. return;
  305. }
  306. if( auction->seller_id != char_id )
  307. {
  308. mapif_Auction_cancel(fd, char_id, 2); // You cannot end the auction
  309. return;
  310. }
  311. if( auction->buyer_id > 0 )
  312. {
  313. mapif_Auction_cancel(fd, char_id, 3); // An auction with at least one bidder cannot be canceled
  314. return;
  315. }
  316. mail_sendmail(0, msg_txt(200), auction->seller_id, auction->seller_name, msg_txt(201), msg_txt(205), 0, &auction->item, 1);
  317. auction_delete(auction);
  318. mapif_Auction_cancel(fd, char_id, 0); // The auction has been canceled
  319. }
  320. void mapif_Auction_close(int fd, uint32 char_id, unsigned char result)
  321. {
  322. WFIFOHEAD(fd,7);
  323. WFIFOW(fd,0) = 0x3853;
  324. WFIFOL(fd,2) = char_id;
  325. WFIFOB(fd,6) = result;
  326. WFIFOSET(fd,7);
  327. }
  328. void mapif_parse_Auction_close(int fd)
  329. {
  330. uint32 char_id = RFIFOL(fd,2), auction_id = RFIFOL(fd,6);
  331. struct auction_data *auction;
  332. if( (auction = (struct auction_data *)idb_get(auction_db_, auction_id)) == NULL )
  333. {
  334. mapif_Auction_close(fd, char_id, 2); // Bid Number is Incorrect
  335. return;
  336. }
  337. if( auction->seller_id != char_id )
  338. {
  339. mapif_Auction_close(fd, char_id, 1); // You cannot end the auction
  340. return;
  341. }
  342. if( auction->buyer_id == 0 )
  343. {
  344. mapif_Auction_close(fd, char_id, 1); // You cannot end the auction
  345. return;
  346. }
  347. // Send Money to Seller
  348. mail_sendmail(0, msg_txt(200), auction->seller_id, auction->seller_name, msg_txt(201), msg_txt(206), auction->price, NULL, 0);
  349. // Send Item to Buyer
  350. mail_sendmail(0, msg_txt(200), auction->buyer_id, auction->buyer_name, msg_txt(201), msg_txt(207), 0, &auction->item, 1);
  351. mapif_Auction_message(auction->buyer_id, 6); // You have won the auction
  352. auction_delete(auction);
  353. mapif_Auction_close(fd, char_id, 0); // You have ended the auction
  354. }
  355. void mapif_Auction_bid(int fd, uint32 char_id, int bid, unsigned char result)
  356. {
  357. WFIFOHEAD(fd,11);
  358. WFIFOW(fd,0) = 0x3855;
  359. WFIFOL(fd,2) = char_id;
  360. WFIFOL(fd,6) = bid; // To Return Zeny
  361. WFIFOB(fd,10) = result;
  362. WFIFOSET(fd,11);
  363. }
  364. void mapif_parse_Auction_bid(int fd)
  365. {
  366. uint32 char_id = RFIFOL(fd,4), auction_id = RFIFOL(fd,8);
  367. int bid = RFIFOL(fd,12);
  368. struct auction_data *auction;
  369. if( (auction = (struct auction_data *)idb_get(auction_db_, auction_id)) == NULL || auction->price >= bid || auction->seller_id == char_id )
  370. {
  371. mapif_Auction_bid(fd, char_id, bid, 0); // You have failed to bid in the auction
  372. return;
  373. }
  374. if( auction_count(char_id, true) > 4 && bid < auction->buynow && auction->buyer_id != char_id )
  375. {
  376. mapif_Auction_bid(fd, char_id, bid, 9); // You cannot place more than 5 bids at a time
  377. return;
  378. }
  379. if( auction->buyer_id > 0 )
  380. { // Send Money back to the previous Buyer
  381. if( auction->buyer_id != char_id )
  382. {
  383. mail_sendmail(0, msg_txt(200), auction->buyer_id, auction->buyer_name, msg_txt(201), msg_txt(208), auction->price, NULL, 0);
  384. mapif_Auction_message(auction->buyer_id, 7); // You have failed to win the auction
  385. }
  386. else
  387. mail_sendmail(0, msg_txt(200), auction->buyer_id, auction->buyer_name, msg_txt(201), msg_txt(209), auction->price, NULL, 0);
  388. }
  389. auction->buyer_id = char_id;
  390. safestrncpy(auction->buyer_name, RFIFOCP(fd,16), NAME_LENGTH);
  391. auction->price = bid;
  392. if( bid >= auction->buynow )
  393. { // Automatic won the auction
  394. mapif_Auction_bid(fd, char_id, bid - auction->buynow, 1); // You have successfully bid in the auction
  395. mail_sendmail(0, msg_txt(200), auction->buyer_id, auction->buyer_name, msg_txt(201), msg_txt(210), 0, &auction->item, 1);
  396. mapif_Auction_message(char_id, 6); // You have won the auction
  397. mail_sendmail(0, msg_txt(200), auction->seller_id, auction->seller_name, msg_txt(201), msg_txt(211), auction->buynow, NULL, 0);
  398. auction_delete(auction);
  399. return;
  400. }
  401. auction_save(auction);
  402. mapif_Auction_bid(fd, char_id, 0, 1); // You have successfully bid in the auction
  403. }
  404. /*==========================================
  405. * Packets From Map Server
  406. *------------------------------------------*/
  407. int inter_auction_parse_frommap(int fd)
  408. {
  409. switch(RFIFOW(fd,0))
  410. {
  411. case 0x3050: mapif_parse_Auction_requestlist(fd); break;
  412. case 0x3051: mapif_parse_Auction_register(fd); break;
  413. case 0x3052: mapif_parse_Auction_cancel(fd); break;
  414. case 0x3053: mapif_parse_Auction_close(fd); break;
  415. case 0x3055: mapif_parse_Auction_bid(fd); break;
  416. default:
  417. return 0;
  418. }
  419. return 1;
  420. }
  421. int inter_auction_sql_init(void)
  422. {
  423. auction_db_ = idb_alloc(DB_OPT_RELEASE_DATA);
  424. inter_auctions_fromsql();
  425. return 0;
  426. }
  427. void inter_auction_sql_final(void)
  428. {
  429. auction_db_->destroy(auction_db_,NULL);
  430. return;
  431. }