8.lua

main 71 lines · 3.3 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1function onUpdateDatabase()
2 print("> Updating database to version 9 (global inbox)")
3 db.query("CREATE TABLE IF NOT EXISTS `player_inboxitems` (`player_id` int(11) NOT NULL, `sid` int(11) NOT NULL, `pid` int(11) NOT NULL DEFAULT '0', `itemtype` smallint(6) NOT NULL, `count` smallint(5) NOT NULL DEFAULT '0', `attributes` blob NOT NULL, UNIQUE KEY `player_id_2` (`player_id`,`sid`), KEY `player_id` (`player_id`), FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1")
4
5 -- Delete "market" item
6 db.query("DELETE FROM `player_depotitems` WHERE `itemtype` = 14405")
7
8 -- Move up items in depot chests
9 local resultId = db.storeQuery("SELECT `player_id`, `pid`, (SELECT `dp2`.`sid` FROM `player_depotitems` AS `dp2` WHERE `dp2`.`player_id` = `dp1`.`player_id` AND `dp2`.`pid` = `dp1`.`sid` AND `itemtype` = 2594) AS `sid` FROM `player_depotitems` AS `dp1` WHERE `itemtype` = 2589")
10 if resultId ~= false then
11 repeat
12 db.query("UPDATE `player_depotitems` SET `pid` = " .. result.getNumber(resultId, "pid") .. " WHERE `player_id` = " .. result.getNumber(resultId, "player_id") .. " AND `pid` = " .. result.getNumber(resultId, "sid"))
13 until not result.next(resultId)
14 result.free(resultId)
15 end
16
17 -- Delete the depot lockers
18 db.query("DELETE FROM `player_depotitems` WHERE `itemtype` = 2589")
19
20 -- Delete the depot chests
21 db.query("DELETE FROM `player_depotitems` WHERE `itemtype` = 2594")
22
23 resultId = db.storeQuery("SELECT DISTINCT `player_id` FROM `player_depotitems` WHERE `itemtype` = 14404")
24 if resultId ~= false then
25 repeat
26 local playerId = result.getNumber(resultId, "player_id")
27
28 local runningId = 100
29
30 local stmt = "INSERT INTO `player_inboxitems` (`player_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES "
31
32 local resultId2 = db.storeQuery("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = " .. playerId .. " AND `itemtype` = 14404")
33 if resultId2 ~= false then
34 repeat
35 local sids = {}
36 sids[#sids + 1] = result.getNumber(resultId2, "sid")
37 while #sids > 0 do
38 local sid = sids[#sids]
39 sids[#sids] = nil
40
41 local resultId3 = db.storeQuery("SELECT * FROM `player_depotitems` WHERE `player_id` = " .. playerId .. " AND `pid` = " .. sid)
42 if resultId3 ~= false then
43 repeat
44 local attr, attrSize = result.getStream(resultId3, "attributes")
45 runningId = runningId + 1
46 stmt = stmt .. "(" .. playerId .. "," .. runningId .. ",0," .. result.getNumber(resultId3, "itemtype") .. "," .. result.getNumber(resultId3, "count") .. "," .. db.escapeBlob(attr, attrSize) .. "),"
47 sids[#sids + 1] = result.getNumber(resultId3, "sid")
48
49 db.query("DELETE FROM `player_depotitems` WHERE `player_id` = " .. result.getNumber(resultId, "player_id") .. " AND `sid` = " .. result.getNumber(resultId3, "sid"))
50 until not result.next(resultId3)
51 result.free(resultId3)
52 end
53 end
54 until not result.next(resultId2)
55 result.free(resultId2)
56 end
57
58 local stmtLen = string.len(stmt)
59 if stmtLen > 102 then
60 stmt = string.sub(stmt, 1, stmtLen - 1)
61 db.query(stmt)
62 end
63 until not result.next(resultId)
64 result.free(resultId)
65 end
66
67 -- Delete the inboxes
68 db.query("DELETE FROM `player_depotitems` WHERE `itemtype` = 14404")
69 return true
70end
71
Top