mush自动更新机器人插件
很多软件都实现软件自动更新。我在想mush 机器人是否也能实现这个功能呢?可以利用mush luasocket 的 ftp.lua功能。
首先需要建立一个ftp 服务器,将最新的机器人放在ftp服务器上,提供自动下载。
当插件检查到服务器上 AutoUpdate_config.txt 中文件更新内容 和本地需要更新的文件md5不一致 就会开始自动下载覆盖更新。
--插件源代码
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on 星期三, 一月 27, 2016, 6:23 下午 -->
<!-- MuClient version 4.73 -->
<!-- Plugin "rbt_update" generated by Plugin Wizard -->
<muclient>
<plugin
name="rbt_update"
author="叶知秋"
id="5c589f1ca4fd208978a46254"
language="Lua"
purpose="书剑机器人自动更新"
date_written="2016-01-27 18:22:02"
requires="4.73"
version="1.0"
>
</plugin>
<!--Get our standard constants -->
<include name="constants.lua"/>
<!--Script-->
<script>
<![CDATA[
local function serialize(obj)
local lua = ""
local t = type(obj)
if t == "number" then
lua = lua .. obj
elseif t == "boolean" then
lua = lua .. tostring(obj)
elseif t == "string" then
lua = lua .. string.format("%q", obj)
elseif t == "table" then
lua = lua .. "{\n"
for k, v in pairs(obj) do
lua = lua .. "[" .. serialize(k) .. "]=" .. serialize(v) .. ",\n"
end
local metatable = getmetatable(obj)
if metatable ~= nil and type(metatable.__index) == "table" then
for k, v in pairs(metatable.__index) do
lua = lua .. "[" .. serialize(k) .. "]=" .. serialize(v) .. ",\n"
end
end
lua = lua .. "}"
elseif t == "nil" then
return nil
else
error("can not serialize a " .. t .. " type.")
end
return lua
end
local function unserialize(lua)
local t = type(lua)
if t == "nil" or lua == "" then
return nil
elseif t == "number" or t == "string" or t == "boolean" then
lua = tostring(lua)
else
error("can not unserialize a " .. t .. " type.")
end
lua = "return " .. lua
local func = loadstring(lua)
if func == nil then
return nil
end
return func()
end
local ftp = require("socket.ftp")
-- Log as user "anonymous" on server "ftp.tecgraf.puc-rio.br",
-- and get file "lua.tar.gz" from directory "pub/lua" as binary.
ftp.USER = ""--ftp 用户名
ftp.PASSWORD = ""--ftp 密码
local local_config={}
if t~=nil then
local_config=unserialize(t)
end
--创建需要更新的配置文件
function create()
local config_txt=io.open("update_log.txt","r")
local _config=config_txt:read("*a")
--print(_config)
config_txt:close()
local b=unserialize(_config)
for k,c in pairs(b) do
local output=c.path..c.filename
--print(output)
f = io.open (output, "rb")
if f then
local md5=utils.tohex (utils.md5 (f:read ("*a")))
print(c.filename.." md5:"..md5)
f:close ()
b.md5=md5
end -- if
end
local f=serialize(b)
local output="AutoUpdate_Config.txt"
local file = io.open(output,"wb")
file:write(f)
file:flush()
file:close()
print("配置文件生成结束!")
end
function check()
local co=coroutine.create(function()
--下载服务器上的配置文件进行比对从服务器上下载配置文件
local f, e = ftp.get("ftp://112.65.143.120//mushclient//AutoUpdate_Config.txt")
local remote_config={}
remote_config=unserialize(f)
local is_updated=false
local log=""
for k,c in pairs(remote_config) do
local output=c.path..c.filename
--print(output)
local md5=""
f = io.open (output, "rb")
if f then
md5=utils.tohex (utils.md5 (f:read ("*a")))
-- print(md5)
f:close ()
end -- if
if md5=="" or md5~=c.md5 then--不同服务器上版本
local yesno=utils.msgbox ("发现文件有更新是否更新文件"..c.filename.." "..c.description.."?", "更新", "yesno", "?")
if yesno=="no" then
else
is_updated=true
print("更新模块:"..c.description.." 文件:"..c.filename)
--print(c.ftp," 下载中!")
local f1,e1=ftp.get(c.ftp)
--print(f1)
local file1 = io.open(output,"wb")
file1:write(f1)
file1:flush()
file1:close()
log=log..c.log.."\n"
end
else
-- print("模块"..k.."已经是最新的了!")
end
end
print("更新完毕!")
if is_updated then
print("更新内容")
print("-------------------------")
print(log)
print("-------------------------")
print("请重新加载脚本和数据库!")
else
print("未发现更新!")
end
end)
coroutine.resume(co)
end
local function _init()
world.ColourNote("salmon", "", "up:check - 检查版本更新")
world.ColourNote("salmon", "", "up:create - 创建更新文件")
world.AddAlias("up_check", "up:check", "check()", alias_flag.Enabled, "")
world.SetAliasOption ("up_check", "send_to", 12) --向脚本发送
world.AddAlias("up_create", "up:create", "create()", alias_flag.Enabled, "")
world.SetAliasOption ("up_create", "send_to", 12) --向脚本发送
end
function OnPluginClose()
end
function OnPluginConnect()
end
function OnPluginDisable()
end
function OnPluginDisconnect()
end
function OnPluginEnable()
end
function mousedown()
return function (flags, hotspot_id)
--print(flags)
if flags==16 then
check()
end
end
end
function OnPluginInstall()
ColourNote("white", "red", "叶知秋版_for_书剑_检查更新插件0.1版")
_init()
win="auto_update_btn"
WindowCreate(win,0,0,15,15,miniwin.pos_center_right,0,0x909090)
local _mousedown=mousedown()
_G["at_mousedown"]=_mousedown
WindowAddHotspot(win, "auto_update_hotspot",
0,0, 15, 15, -- rectangle
"", -- MouseOver
"", -- CancelMouseOver
"at_mousedown",-- MouseDown
"", -- CancelMouseDown
"", -- MouseUp
"检查机器人更新",-- tooltip text
cursor or 1, -- cursor
0)-- flags
button()
end
function OnPluginSend(sText)
end
function button()
win="auto_update_btn"
--text add
WindowFont (win, "f", "宋体", 9, true, false, false, false)
switch_name="︾"
ColourNote("red", "black", "检查版本更新")
WindowRectOp (win, miniwin.rect_fill, 0,0,15,15,0x000010)-- raised, filled, softer, flat
WindowCircleOp (win, miniwin.circle_round_rectangle, 0, 0, 15, 15, 0xc0c0c0, 0, 1,0, 0, 9, 9)
WindowText (win, "f", switch_name,2,2,130,30,ColourNameToRGB ("red"), false) -- not Unicode
WindowShow (win,true)-- show it
--check()
end
]]>
</script>
</muclient>
---利用 插件up:create命令 来创建AutoUpdate_config.txt 文件
--update_log.txt 文件 的内容
{
map={
path="",
ftp="ftp://112.65.143.178//mushclient//map.lua",
md5="",
filename="map.lua",
description="地图引擎",
log="地图累积更新,塔林bug修正",
},
alias={
path="",
ftp="ftp://112.65.143.178//mushclient//alias.lua",
md5="",
filename="alias.lua",
description="迷宫处理",
log="地图累积更新,塔林bug修正",
},
database={
path="",
ftp="ftp://112.65.143.178//mushclient//sjcentury.db",
md5="",
filename="sjcentury.db",
description="地图数据库",
log="地图累积更新",
},
mapper={
path="lua\\",
ftp="ftp://112.65.143.178//mushclient//lua/mapper.lua",
md5="",
filename="mapper.lua",
description="地图显示",
log="地图累积更新",
},
movewindow2={
path="lua\\",
ftp="ftp://112.65.143.178//mushclient//movewindow2.lua",
md5="",
filename="movewindow2.lua",
description="窗体模块",
log="",
},
songshan={
path="",
ftp="ftp://112.65.143.178//mushclient//songshan.lua",
md5="",
filename="songshan.lua",
description="嵩山任务",
log="",
},
wudang={
path="",
ftp="ftp://112.65.143.178//mushclient//wudang.lua",
md5="",
filename="wudang.lua",
description="武当任务",
log="",
},
huashan={
path="",
ftp="ftp://112.65.143.178//mushclient//huashan.lua",
md5="",
filename="huashan.lua",
description="华山任务",
log="",
},
xueshan={
path="",
ftp="ftp://112.65.143.178//mushclient//xueshan.lua",
md5="",
filename="xueshan.lua",
description="雪山任务",
log="",
},
teachmonk={
path="",
ftp="ftp://112.65.143.178//mushclient//teachmonk.lua",
md5="",
filename="teachmonk.lua",
description="少林教和尚任务",
log="",
},
tiaoshui={
path="",
ftp="ftp://112.65.143.178//mushclient//tiaoshui.lua",
md5="",
filename="tiaoshui.lua",
description="挑水任务",
log="",
},
huxi={
path="",
ftp="ftp://112.65.143.178//mushclient//huxi.lua",
md5="",
filename="huxi.lua",
description="呼吸",
log="",
},
learn={
path="",
ftp="ftp://112.65.143.178//mushclient//learn.lua",
md5="",
filename="learn.lua",
description="学习模块",
log="",
},
wuguan={
path="",
ftp="ftp://112.65.143.178//mushclient//wuguan.lua",
md5="",
filename="wuguan.lua",
description="武馆模块",
log="更新自动问答",
},
rest={
path="",
ftp="ftp://112.65.143.178//mushclient//rest.lua",
md5="",
filename="rest.lua",
description="休息模块",
log="",
},
hp={
path="",
ftp="ftp://112.65.143.178//mushclient//hp.lua",
md5="",
filename="hp.lua",
description="气血显示模块",
log="",
},
xiulian={
path="",
ftp="ftp://112.65.143.178//mushclient//xiulian.lua",
md5="",
filename="xiulian.lua",
description="打坐吐纳模块",
log="新增吸星大法描述",
},
xuncheng={
path="",
ftp="ftp://112.65.143.178//mushclient//xuncheng.lua",
md5="",
filename="xuncheng.lua",
description="巡城模块",
log="",
},
changle={
path="",
ftp="ftp://112.65.143.178//mushclient//changle.lua",
md5="",
filename="changle.lua",
description="长乐帮模块",
log="",
},
songxin={
path="",
ftp="ftp://112.65.143.178//mushclient//songxin.lua",
md5="",
filename="songxin.lua",
description="送信模块",
},
tiandi={
path="",
ftp="ftp://112.65.143.178//mushclient//tiandi.lua",
md5="",
filename="tiandi.lua",
description="天地会模块",
log="",
},
sj_mini_win={
path="",
ftp="ftp://112.65.143.178//mushclient//sj_mini_win.lua",
md5="",
filename="sj_mini_win.lua",
description="书剑迷你窗体",
log="",
},
wait={
path="lua\\",
ftp="ftp://112.65.143.178//mushclient//lua//wait.lua",
md5="",
filename="wait.lua",
description="wait模块",
log="",
},
jiaohua={
path="",
ftp="ftp://112.65.143.178//mushclient//jiaohua.lua",
md5="",
filename="jiaohua.lua",
description="浇花模块",
log="",
},
hqg={
path="",
ftp="ftp://112.65.143.178//mushclient//hqg.lua",
md5="",
filename="hqg.lua",
description="洪七公做菜模块",
log="",
},
cond={
path="",
ftp="ftp://112.65.143.178//mushclient//cond.lua",
md5="",
filename="cond.lua",
description="状态模块",
log="",
},
special_item={
path="",
ftp="ftp://112.65.143.178//mushclient//special_item.lua",
md5="",
filename="special_item.lua",
description="特殊物品模块",
log="",
},
touxue={
path="",
ftp="ftp://112.65.143.178//mushclient//touxue.lua",
md5="",
filename="touxue.lua",
description="慕容偷学模块",
log="",
},
gaibang={
path="",
ftp="ftp://112.65.143.178//mushclient//gaibang.lua",
md5="",
filename="gaibang.lua",
description="丐帮任务模块",
log="",
},
fish={
path="",
ftp="ftp://112.65.143.178//mushclient//fish.lua",
md5="",
filename="fish.lua",
description="钓鱼模块",
log="",
},
lingwu={
path="",
ftp="ftp://112.65.143.178//mushclient//lingwu.lua",
md5="",
filename="lingwu.lua",
description="领悟模块",
log="",
},
exps={
path="",
ftp="ftp://112.65.143.178//mushclient//exps.lua",
md5="",
filename="exps.lua",
description="经验奖励模块",
log="",
},
gold={
path="",
ftp="ftp://112.65.143.178//mushclient//gold.lua",
md5="",
filename="gold.lua",
description="杀金模块",
log="",
},
fight={
path="",
ftp="ftp://112.65.143.178//mushclient//fight.lua",
md5="",
filename="fight.lua",
description="战斗模块",
log="增加金刀黑剑的提示",
},
sj={
path="",
ftp="ftp://112.65.143.178//mushclient//sj.lua",
md5="",
filename="sj.lua",
description="书剑全局模块",
log="",
},
wizard={
path="",
ftp="ftp://112.65.143.178//mushclient//wizard.lua",
md5="",
filename="wizard.lua",
description="设置向导模块",
log="新增若干job的设置向导",
},
equipments={
path="",
ftp="ftp://112.65.143.178//mushclient//equipments.lua",
md5="",
filename="equipments.lua",
description="装备检查模块",
log="新增对【+1】武器支持",
},
jobtimes={
path="",
ftp="ftp://112.65.143.178//mushclient//jobtimes.lua",
md5="",
filename="jobtimes.lua",
description="工作状态模块",
log="",
},
suoming={
path="",
ftp="ftp://112.65.143.178//mushclient//suoming.lua",
md5="",
filename="suoming.lua",
description="神龙岛索命模块",
log="",
}, --神龙岛索命
zhuashe={
path="",
ftp="ftp://112.65.143.178//mushclient//zhuashe.lua",
md5="",
filename="zhuashe.lua",
description="抓蛇模块",
log="",
},
aozhou={
path="",
ftp="ftp://112.65.143.178//mushclient//aozhou.lua",
md5="",
filename="aozhou.lua",
description="熬粥模块",
log="",
},
caikuang={
path="",
ftp="ftp://112.65.143.178//mushclient//caikuang.lua",
md5="",
filename="caikuang.lua",
description="采矿模块",
log="",
},
xunluo={
path="",
ftp="ftp://112.65.143.178//mushclient//xunluo.lua",
md5="",
filename="xunluo.lua",
description="明教巡逻模块",
log="",
},
shoumu={
path="",
ftp="ftp://112.65.143.178//mushclient//shoumu.lua",
md5="",
filename="shoumu.lua",
description="桃花守墓模块",
log="",
},
duicao={
path="",
ftp="ftp://112.65.143.178//mushclient//duicao.lua",
md5="",
filename="duicao.lua",
description="堆草模块",
log="",
},
jiuyuan={
path="",
ftp="ftp://112.65.143.178//mushclient//jiuyuan.lua",
md5="",
filename="jiuyuan.lua",
description="少林救援模块",
log="对若干大师follow 更新",
},
taishan={
path="",
ftp="ftp://112.65.143.178//mushclient//taishan.lua",
md5="",
filename="taishan.lua",
description="泰山任务模块",
log="",
},
wdj={
path="",
ftp="ftp://112.65.143.178//mushclient//wdj.lua",
md5="",
filename="wdj.lua",
description="五毒教模块",
log="杀蜘蛛自动jifa none",
},
zhuachong={
path="",
ftp="ftp://112.65.143.178//mushclient//zhuachong.lua",
md5="",
filename="zhuachong.lua",
description="抓虫模块",
log="自动炼毒",
},
qiangjie={
path="",
ftp="ftp://112.65.143.178//mushclient//qiangjie.lua",
md5="",
filename="qiangjie.lua",
description="抢劫模块",
log="",
},
liandu={
path="",
ftp="ftp://112.65.143.178//mushclient//liandu.lua",
md5="",
filename="liandu.lua",
description="炼毒模块",
log="增加对炼毒内力不足的触发",
},
ouyangke={
path="",
ftp="ftp://112.65.143.178//mushclient//ouyangke.lua",
md5="",
filename="ouyangke.lua",
description="欧阳克模块",
log="",
},
lian={
path="",
ftp="ftp://112.65.143.178//mushclient//lian.lua",
md5="",
filename="lian.lua",
description="练技能模块",
},
fb={
path="",
ftp="ftp://112.65.143.178//mushclient//fb.lua",
md5="",
filename="fb.lua",
description="副本模块",
log="",
},
hubiao={
path="",
ftp="ftp://112.65.143.178//mushclient//hubiao.lua",
md5="",
filename="hubiao.lua",
description="护镖模块",
log="未完善",
},
ckns2={
path="",
ftp="ftp://112.65.143.178//mushclient//ckns2.lua",
md5="",
filename="ckns2.lua",
description="采矿任务模块",
log="",
},
}
北大侠客行MUD,中国最好的MUD 回复 1# ptouch
大神又出新作啦~顶
还有,你那个地图插件后来如何了。。? 这是玩的什么mud 书剑mud 机器人可以自动更新 ttk_18
页:
[1]