Skip to content

Commit

Permalink
fasttime.bat
Browse files Browse the repository at this point in the history
  • Loading branch information
huahua132 committed Nov 20, 2024
1 parent a789b8a commit e60137d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 19 deletions.
6 changes: 4 additions & 2 deletions lualib/skynet-fly/utils/time_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ function M.date(time)
end

--string格式的时间转换成date日期table 2023:10:26 19:22:50
function M.string_to_date(str)
local datetime = string_util.split(str,' ',':')
function M.string_to_date(str, split1, split2)
split1 = split1 or " "
split2 = split2 or ":"
local datetime = string_util.split(str, split1, split2)
if #datetime ~= 2 then
return nil,"err not space"
end
Expand Down
3 changes: 2 additions & 1 deletion script/bat/make_server.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ if not exist "%lua%" (
%lua% "%script_path%\write_check_reloadsh.lua" %skynet_fly_path%
%lua% "%script_path%\write_killmodsh.lua" %skynet_fly_path%
%lua% "%script_path%\write_restartsh.lua" %skynet_fly_path%
%lua% "%script_path%\write_try_again_reloadsh.lua" %skynet_fly_path%
%lua% "%script_path%\write_try_again_reloadsh.lua" %skynet_fly_path%
%lua% "%script_path%\write_fasttimesh.lua" %skynet_fly_path%
2 changes: 1 addition & 1 deletion script/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function CMD.fasttime()
local one_add = ARGV[ARGV_HEAD + 2] --单次加速时间 1表示1秒
assert(fastdate,"not fastdate")
assert(one_add, "not one_add")
local date,err = time_util.string_to_date(fastdate)
local date,err = time_util.string_to_date(fastdate, '-', ':')
if not date then
error(err)
end
Expand Down
95 changes: 80 additions & 15 deletions script/lua/write_fasttimesh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,92 @@ local lua_path = skynet_path .. '/3rd/lua/lua'
local server_path = "./"
local script_path = file_util.path_join(skynet_fly_path, '/script/lua')

local shell_str = "#!/bin/bash\n"
if not file_util.is_window() then
local shell_str = "#!/bin/bash\n"
shell_str = shell_str .. [[
if [ "$#" -ne 3 ]; then
echo "please format make/script/fasttime.sh load_mods.lua '2023:10:26 19:22:50' 1"
echo "please format make/script/fasttime.sh load_mods.lua 2023:10:26-19:22:50 1"
exit 1
fi
]]
shell_str = shell_str .. string.format('%s %s/console.lua %s %s $1 fasttime "$2" $3 | \n',lua_path,script_path,skynet_fly_path,svr_name)
shell_str = shell_str .. string.format("xargs -t curl -s \n")
shell_str = shell_str .. string.format('%s %s/console.lua %s %s $1 fasttime "$2" $3 | \n',lua_path,script_path,skynet_fly_path,svr_name)
shell_str = shell_str .. string.format("xargs -t curl -s \n")

local shell_path = server_path .. 'make/script/'
local shell_path = server_path .. 'make/script/'

local isok, err = file_util.mkdir(shell_path)
if not isok then
error("create shell_path err " .. err)
end
local isok, err = file_util.mkdir(shell_path)
if not isok then
error("create shell_path err " .. err)
end

local file_path = shell_path .. 'fasttime.sh'
local file_path = shell_path .. 'fasttime.sh'

local file = io.open(file_path,'w+')
assert(file)
file:write(shell_str)
file:close()
print("make " .. file_path)
local file = io.open(file_path,'w+')
assert(file)
file:write(shell_str)
file:close()
print("make " .. file_path)
else
--windows
lua_path = file_util.convert_linux_to_windows_relative(lua_path) .. ".exe"
script_path = file_util.convert_linux_to_windows_relative(script_path)
skynet_fly_path = file_util.convert_linux_to_windows_relative(skynet_fly_path)
skynet_path = file_util.convert_linux_to_windows_relative(skynet_path)
--windows
local bat_str = [[
@echo off
set load_mods=%1
set data_time=%2
set once_add=%3
if "%load_mods%" == "" (
echo please format make/script/fasttime.sh load_mods.lua 2023:10:26-19:22:50 1
exit /b 1
)
if "%data_time%" == "" (
echo please format make/script/fasttime.sh load_mods.lua 2023:10:26-19:22:50 1
exit /b 1
)
if "%once_add%" == "" (
echo please format make/script/fasttime.sh load_mods.lua 2023:10:26-19:22:50 1
exit /b 1
)
set url = ""
for /f "delims=" %%i in ('{lua_path} {skynet_fly_path}\script\lua\console.lua {skynet_fly_path} {svr_name} %load_mods% fasttime "%data_time%" %once_add%') do (
set url=%%i
)
for /f "delims=" %%i in ('curl -s -X GET "%url:~1,-1%"') do (
echo %%i
)
]]
bat_str = string.gsub(bat_str, "{(.-)}", function(name)
if name == "svr_name" then
return svr_name
elseif name == "lua_path" then
return lua_path
elseif name == "skynet_path" then
return skynet_path
elseif name == "skynet_fly_path" then
return skynet_fly_path
else
error("unknown pat name:", name)
end
end)

local bat_path = server_path .. 'make\\script\\'
local isok, err = file_util.mkdir(bat_path)
if not isok then
error("create bat_path err " .. err)
end
local file_path = bat_path .. 'fasttime.bat'

local file = io.open(file_path,'w+')
assert(file)
file:write(bat_str)
file:close()
print("make " .. file_path)
end

0 comments on commit e60137d

Please sign in to comment.