diff --git a/init.lua b/init.lua index ce58830..9e84eb3 100644 --- a/init.lua +++ b/init.lua @@ -42,15 +42,15 @@ if Services.crash ~= nil and Services.crash:len() > 4 then local normalLog = g_logger.getLastLog() local crashed = false if crashLog:len() > 0 then - g_http.post(Services.crash .. "?txt=0", crashLog) + g_http.post(Services.crash .. "?txt=0&version=" .. g_app.getVersion(), crashLog) crashed = true end if crashLogTxt:len() > 0 then - g_http.post(Services.crash .. "?txt=1", crashLogTxt) + g_http.post(Services.crash .. "?txt=1&version=" .. g_app.getVersion(), crashLogTxt) crashed = true end if crashed and normalLog:len() > 0 then - g_http.post(Services.crash .. "?txt=2", normalLog) + g_http.post(Services.crash .. "?txt=2&version=" .. g_app.getVersion(), normalLog) end g_resources.deleteCrashLog() end diff --git a/modules/client_entergame/characterlist.lua b/modules/client_entergame/characterlist.lua index 82211d0..7561010 100644 --- a/modules/client_entergame/characterlist.lua +++ b/modules/client_entergame/characterlist.lua @@ -34,11 +34,9 @@ local function tryLogin(charInfo, tries) -- proxies for not http login users if charInfo.worldHost == "0.0.0.0" and g_proxy then g_proxy.clear() - -- g_proxy.addProxy(localPort, proxyHost, proxyPort, proxyPriority) - g_proxy.addProxy(tonumber(charInfo.worldPort), "51.158.184.57", 7162, 0) - g_proxy.addProxy(tonumber(charInfo.worldPort), "54.39.190.20", 7162, 0) - g_proxy.addProxy(tonumber(charInfo.worldPort), "51.83.226.109", 7162, 0) - g_proxy.addProxy(tonumber(charInfo.worldPort), "35.247.201.100", 443, 0) + -- g_proxy.addProxy(proxyHost, proxyPort, proxyPriority) + g_proxy.addProxy("163.172.147.135", 7162, 0) + g_proxy.addProxy("158.69.68.42", 7162, 0) end g_game.loginWorld(G.account, G.password, charInfo.worldName, charInfo.worldHost, charInfo.worldPort, charInfo.characterName, G.authenticatorToken, G.sessionKey) diff --git a/modules/client_stats/stats.lua b/modules/client_stats/stats.lua index 168395e..9bdd9f0 100644 --- a/modules/client_stats/stats.lua +++ b/modules/client_stats/stats.lua @@ -131,6 +131,7 @@ function sendStats() display_height = g_window.getDisplayHeight(), cpu = g_platform.getCPUName(), mem = g_platform.getTotalSystemMemory(), + mem_usage = g_platform.getMemoryUsage(), os_name = g_platform.getOSName() } } diff --git a/modules/game_bot/bot.lua b/modules/game_bot/bot.lua index a34f870..d523372 100644 --- a/modules/game_bot/bot.lua +++ b/modules/game_bot/bot.lua @@ -34,6 +34,7 @@ function init() onGameStart = online, onGameEnd = offline, onTalk = botOnTalk, + onTextMessage = botOnTextMessage, onUse = botOnUse, onUseWith = botOnUseWith, onChannelList = botChannelList, @@ -161,6 +162,7 @@ function terminate() onGameStart = online, onGameEnd = offline, onTalk = botOnTalk, + onTextMessage = botOnTextMessage, onUse = botOnUse, onUseWith = botOnUseWith, onChannelList = botChannelList, @@ -479,6 +481,11 @@ function botOnTalk(name, level, mode, text, channelId, pos) safeBotCall(function() compiledConfig.callbacks.onTalk(name, level, mode, text, channelId, pos) end) end +function botOnTextMessage(mode, text) + if compiledConfig == nil then return false end + safeBotCall(function() compiledConfig.callbacks.onTextMessage(mode, text) end) +end + function botAddThing(tile, thing) if compiledConfig == nil then return false end safeBotCall(function() compiledConfig.callbacks.onAddThing(tile, thing) end) diff --git a/modules/game_bot/executor.lua b/modules/game_bot/executor.lua index dac63c9..56885bf 100644 --- a/modules/game_bot/executor.lua +++ b/modules/game_bot/executor.lua @@ -19,6 +19,7 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, webs onKeyUp = {}, onKeyPress = {}, onTalk = {}, + onTextMessage = {}, onAddThing = {}, onRemoveThing = {}, onCreatureAppear = {}, @@ -169,6 +170,11 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, webs callback(name, level, mode, text, channelId, pos) end end, + onTextMessage = function(mode, text) + for i, callback in ipairs(context._callbacks.onTextMessage) do + callback(mode, text) + end + end, onAddThing = function(tile, thing) for i, callback in ipairs(context._callbacks.onAddThing) do callback(tile, thing) diff --git a/modules/game_bot/functions/callbacks.lua b/modules/game_bot/functions/callbacks.lua index 5c5f177..ab4b87d 100644 --- a/modules/game_bot/functions/callbacks.lua +++ b/modules/game_bot/functions/callbacks.lua @@ -39,6 +39,11 @@ context.onTalk = function(callback) return context.callback("onTalk", callback) end +-- onTextMessage(callback) -- callback = function(mode, text) +context.onTextMessage = function(callback) + return context.callback("onTextMessage", callback) +end + -- onAddThing(callback) -- callback = function(tile, thing) context.onAddThing = function(callback) return context.callback("onAddThing", callback) diff --git a/modules/game_bot/functions/main.lua b/modules/game_bot/functions/main.lua index f6f078e..54873e0 100644 --- a/modules/game_bot/functions/main.lua +++ b/modules/game_bot/functions/main.lua @@ -64,12 +64,10 @@ context.macro = function(timeout, name, hotkey, callback, parent) end -- hotkey(keys, callback) --- hotkey(keys, callback, parent) -- hotkey(keys, name, callback) -- hotkey(keys, name, callback, parent) context.hotkey = function(keys, name, callback, parent, single) if type(name) == 'function' then - parent = callback callback = name name = "" end @@ -110,12 +108,10 @@ context.hotkey = function(keys, name, callback, parent, single) end -- singlehotkey(keys, callback) --- singlehotkey(keys, callback, parent) -- singlehotkey(keys, name, callback) -- singlehotkey(keys, name, callback, parent) context.singlehotkey = function(keys, name, callback, parent) if type(name) == 'function' then - parent = callback callback = name name = "" end diff --git a/modules/game_shop/shop.lua b/modules/game_shop/shop.lua index be69df0..dd2589d 100644 --- a/modules/game_shop/shop.lua +++ b/modules/game_shop/shop.lua @@ -19,7 +19,7 @@ local function sendAction(action, data) data = {} end if protocolGame then - protocolGame:sendExtendedOpcode(SHOP_EXTENTED_OPCODE, json.encode({action = action, data = data})) + protocolGame:sendExtendedJSONOpcode(SHOP_EXTENTED_OPCODE, {action = action, data = data}) end end @@ -27,7 +27,7 @@ end function init() connect(g_game, { onGameStart = check, onGameEnd = hide }) - ProtocolGame.registerExtendedOpcode(SHOP_EXTENTED_OPCODE, onExtendedOpcode) + ProtocolGame.registerExtendedJSONOpcode(SHOP_EXTENTED_OPCODE, onExtendedJSONOpcode) if g_game.isOnline() then check() @@ -37,7 +37,7 @@ end function terminate() disconnect(g_game, { onGameStart = check, onGameEnd = hide }) - ProtocolGame.unregisterExtendedOpcode(SHOP_EXTENTED_OPCODE, onExtendedOpcode) + ProtocolGame.unregisterExtendedJSONOpcode(SHOP_EXTENTED_OPCODE, onExtendedJSONOpcode) if shopButton then shopButton:destroy() @@ -87,7 +87,7 @@ function toggle() check() end -function onExtendedOpcode(protocol, code, buffer) +function onExtendedJSONOpcode(protocol, code, json_data) if not shop then shop = g_ui.displayUI('shop') shop:hide() @@ -96,12 +96,6 @@ function onExtendedOpcode(protocol, code, buffer) connect(shop.categories, { onChildFocusChange = changeCategory }) end - local json_status, json_data = pcall(function() return json.decode(buffer) end) - if not json_status then - g_logger.error("SHOP json error: " .. json_data) - return false - end - local action = json_data['action'] local data = json_data['data'] local status = json_data['status'] @@ -316,6 +310,7 @@ function addOffer(category, data) offer.description:setText(data["description"]) if category ~= 0 then offer.onDoubleClick = buyOffer + offer.buyButton.onClick = function() buyOffer(offer) end end end diff --git a/modules/game_shop/shop.otui b/modules/game_shop/shop.otui index 0bea9a9..7c105be 100644 --- a/modules/game_shop/shop.otui +++ b/modules/game_shop/shop.otui @@ -80,13 +80,23 @@ ShopOffer < Panel anchors.right: parent.right anchors.bottom: parent.bottom margin-left: 55 + margin-right: 55 text-align: topleft - text: UAHSbjaS ASDJHASD ASKJD ssssUAHSbjaS ASDJHASD ASKJD ssssUAHSbjaS ASDJHASD ASKJD ssss text-auto-resize: true text-wrap: true color: white font: verdana-11px-rounded + Button + id: buyButton + text: BUY + height: 25 + anchors.verticalCenter: parent.verticalCenter + anchors.left: prev.right + anchors.right: parent.right + margin-right: 15 + text-align: center + ShopOfferItem < ShopOffer UIItem id: item diff --git a/modules/game_walking/walking.lua b/modules/game_walking/walking.lua index deae6fa..f89ddb5 100644 --- a/modules/game_walking/walking.lua +++ b/modules/game_walking/walking.lua @@ -367,7 +367,7 @@ end function turn(dir, repeated) local player = g_game.getLocalPlayer() - if player:isWalking() and player:getWalkDirection() == dir then + if player:isWalking() and player:getWalkDirection() == dir and not player:isServerWalking() then return end diff --git a/modules/gamelib/protocolgame.lua b/modules/gamelib/protocolgame.lua index a312de5..e340aaa 100644 --- a/modules/gamelib/protocolgame.lua +++ b/modules/gamelib/protocolgame.lua @@ -1,5 +1,8 @@ local opcodeCallbacks = {} local extendedCallbacks = {} +local extendedJSONCallbacks = {} +local extendedJSONData = {} +local maxPacketSize = 65000 function ProtocolGame:onOpcode(opcode, msg) for i, callback in pairs(opcodeCallbacks) do @@ -16,6 +19,29 @@ function ProtocolGame:onExtendedOpcode(opcode, buffer) if callback then callback(self, opcode, buffer) end + + callback = extendedJSONCallbacks[opcode] + if callback then + local status = buffer:sub(1,1) -- O - just one message, S - start, P - part, E - end + local data = buffer:sub(2) + if status ~= "E" and status ~= "P" then + extendedJSONData[opcode] = "" + end + if status ~= "S" and status ~= "P" and status ~= "E" then + extendedJSONData[opcode] = buffer + else + extendedJSONData[opcode] = extendedJSONData[opcode] .. data + end + if status ~= "S" and status ~= "P" then + local json_status, json_data = pcall(function() return json.decode(extendedJSONData[opcode]) end) + extendedJSONData[opcode] = nil + if not json_status then + error("Invalid data in extended JSON opcode (" .. json_status .. "): " .. json_data) + return + end + callback(self, opcode, json_data) + end + end end function ProtocolGame.registerOpcode(opcode, callback) @@ -57,3 +83,56 @@ function ProtocolGame.unregisterExtendedOpcode(opcode) extendedCallbacks[opcode] = nil end + +function ProtocolGame.registerExtendedJSONOpcode(opcode, callback) + if not callback or type(callback) ~= 'function' then + error('Invalid callback.') + end + + if opcode < 0 or opcode > 255 then + error('Invalid opcode. Range: 0-255') + end + + if extendedJSONCallbacks[opcode] then + error('Opcode is already taken.') + end + + extendedJSONCallbacks[opcode] = callback +end + +function ProtocolGame.unregisterExtendedJSONOpcode(opcode) + if opcode < 0 or opcode > 255 then + error('Invalid opcode. Range: 0-255') + end + + if not extendedJSONCallbacks[opcode] then + error('Opcode is not registered.') + end + + extendedJSONCallbacks[opcode] = nil +end + +function ProtocolGame:sendExtendedJSONOpcode(opcode, data) + if opcode < 0 or opcode > 255 then + error('Invalid opcode. Range: 0-255') + end + + if type(data) ~= "table" then + error('Invalid data type, should be table') + end + + local buffer = json.encode(data) + local s = {} + for i=1, #buffer, maxPacketSize do + s[#s+1] = buffer:sub(i,i+maxPacketSize - 1) + end + if #s == 1 then + self:sendExtendedOpcode(opcode, s[1]) + return + end + self:sendExtendedOpcode(opcode, "S" .. s[1]) + for i=2,#s - 1 do + self:sendExtendedOpcode(opcode, "P" .. s[i]) + end + self:sendExtendedOpcode(opcode, "E" .. s[#s]) +end diff --git a/otclient_dx.exe b/otclient_dx.exe index 690df09..46709a5 100644 Binary files a/otclient_dx.exe and b/otclient_dx.exe differ diff --git a/otclient_gl.exe b/otclient_gl.exe index c362f0c..485a5b4 100644 Binary files a/otclient_gl.exe and b/otclient_gl.exe differ diff --git a/otclient_linux b/otclient_linux index aef2ef1..86dda0c 100644 Binary files a/otclient_linux and b/otclient_linux differ diff --git a/pdb/otclient_dx.zip b/pdb/otclient_dx.zip index ba6de66..5c125e5 100644 Binary files a/pdb/otclient_dx.zip and b/pdb/otclient_dx.zip differ diff --git a/pdb/otclient_gl.zip b/pdb/otclient_gl.zip index bded9c9..eefbdd4 100644 Binary files a/pdb/otclient_gl.zip and b/pdb/otclient_gl.zip differ diff --git a/server/shop/shop.lua b/server/shop/shop.lua index dac8217..ebb9dfb 100644 --- a/server/shop/shop.lua +++ b/server/shop/shop.lua @@ -17,6 +17,7 @@ local SHOP_AD = { -- can be nil url = "http://otclient.ovh", text = "" } +local MAX_PACKET_SIZE = 50000 --[[ SQL TABLE @@ -217,10 +218,36 @@ function sendJSON(player, action, data, forceStatus) end player:setStorageValue(1150001, os.time()) + + local buffer = json.encode({action = action, data = data, status = status}) + local s = {} + for i=1, #buffer, MAX_PACKET_SIZE do + s[#s+1] = buffer:sub(i,i+MAX_PACKET_SIZE - 1) + end local msg = NetworkMessage() + if #s == 1 then + msg:addByte(50) + msg:addByte(SHOP_EXTENDED_OPCODE) + msg:addString(s[1]) + msg:sendToPlayer(player) + return + end + -- split message if too big msg:addByte(50) msg:addByte(SHOP_EXTENDED_OPCODE) - msg:addString(json.encode({action = action, data = data, status = status})) + msg:addString("S" .. s[1]) + msg:sendToPlayer(player) + for i=2,#s - 1 do + msg = NetworkMessage() + msg:addByte(50) + msg:addByte(SHOP_EXTENDED_OPCODE) + msg:addString("P" .. s[i]) + msg:sendToPlayer(player) + end + msg = NetworkMessage() + msg:addByte(50) + msg:addByte(SHOP_EXTENDED_OPCODE) + msg:addString("E" .. s[#s]) msg:sendToPlayer(player) end