Version 1.5 - bug fixes and small improvements

This commit is contained in:
OTCv8 2019-12-23 20:19:46 +01:00
parent cf8b21263d
commit d15cc347dc
17 changed files with 149 additions and 25 deletions

View File

@ -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

View File

@ -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)

View File

@ -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()
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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