服务器中控台 - 整合多组服务器程序实现一键启动/停止,并保存服务器日志
By
jerryxjr1220
at 2023-01-18 • 0人收藏 • 735人看过
贴一下最主要的部分,用process.popen管道实现服务器程序整合,并且不会出现原本的黑窗口。
import fonts.fontAwesome; import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=899;bottom=599;bgcolor=16777215;border="none";mode="popup";sysmenu=false;title=false) winform.add( edit={cls="edit";left=14;top=72;right=885;bottom=540;db=1;dl=1;dr=1;dt=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=1}; plsActive={cls="plus";text="注册服务器";left=9;top=9;right=135;bottom=72;bkBottom=3;bkLeft=7;bkRight=8;bkTop=2;border={color=-65536};dl=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');iconStyle={font=LOGFONT(h=-27;name='FontAwesome');padding={bottom=20}};iconText='\uF109';notify=1;textPadding={bottom=10};valign="bottom";x=0.5;y=0.2;z=2}; plsAdjustable={cls="plus";text="可调弯服务器";left=261;top=9;right=387;bottom=72;bkBottom=3;bkLeft=7;bkRight=8;bkTop=2;border={color=-65536};dl=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');iconStyle={font=LOGFONT(h=-27;name='FontAwesome');padding={bottom=20}};iconText='\uF109';notify=1;textPadding={bottom=10};valign="bottom";x=0.5;y=0.2;z=6}; plsEle={cls="plus";text="电极间距服务器";left=513;top=9;right=639;bottom=72;bkBottom=3;bkLeft=7;bkRight=8;bkTop=2;border={color=-65536};dr=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');iconStyle={font=LOGFONT(h=-27;name='FontAwesome');padding={bottom=20}};iconText='\uF109';notify=1;textPadding={bottom=10};valign="bottom";x=0.5;y=0.2;z=8}; plsHemo={cls="plus";text="止血阀服务器";left=135;top=9;right=261;bottom=72;bkBottom=3;bkLeft=7;bkRight=8;bkTop=2;border={color=-65536};dl=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');iconStyle={font=LOGFONT(h=-27;name='FontAwesome');padding={bottom=20}};iconText='\uF109';notify=1;textPadding={bottom=10};valign="bottom";x=0.5;y=0.2;z=5}; plsPFA={cls="plus";text="五爪脉冲服务器";left=387;top=9;right=513;bottom=72;bkBottom=3;bkLeft=7;bkRight=8;bkTop=2;border={color=-65536};dl=1;dr=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');iconStyle={font=LOGFONT(h=-27;name='FontAwesome');padding={bottom=20}};iconText='\uF109';notify=1;textPadding={bottom=10};valign="bottom";x=0.5;y=0.2;z=7}; plsShutdown={cls="plus";text="关闭服务器";left=193;top=548;right=351;bottom=577;db=1;dl=1;font=LOGFONT(h=-16;name='微软雅黑';weight=700);z=4}; plsStart={cls="plus";text="启动服务器";left=18;top=548;right=176;bottom=577;db=1;dl=1;font=LOGFONT(h=-16;name='微软雅黑';weight=700);notify=1;z=3}; plsVisualization={cls="plus";text="可视化服务器";left=639;top=9;right=765;bottom=72;bkBottom=3;bkLeft=7;bkRight=8;bkTop=2;border={color=-65536};dr=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');iconStyle={font=LOGFONT(h=-27;name='FontAwesome');padding={bottom=20}};iconText='\uF109';notify=1;textPadding={bottom=10};valign="bottom";x=0.5;y=0.2;z=9}; plsVisualization2={cls="plus";text="可视化服务器2";left=765;top=9;right=891;bottom=72;bkBottom=3;bkLeft=7;bkRight=8;bkTop=2;border={color=-65536};dr=1;dt=1;font=LOGFONT(h=-16;name='微软雅黑');iconStyle={font=LOGFONT(h=-27;name='FontAwesome');padding={bottom=20}};iconText='\uF109';notify=1;textPadding={bottom=10};valign="bottom";x=0.5;y=0.2;z=10} ) /*}}*/ import style; winform.plsActive.skin(style.subtabs); winform.plsHemo.skin(style.subtabs); winform.plsAdjustable.skin(style.subtabs); winform.plsPFA.skin(style.subtabs); winform.plsEle.skin(style.subtabs); winform.plsVisualization.skin(style.subtabs); winform.plsVisualization2.skin(style.subtabs); winform.plsStart.skin(style.primaryButton); winform.plsShutdown.skin(style.primaryButton); import process; import process.popen; import fsys.ini; ini = fsys.ini("\res\setting.ini"); winform.plsStart.oncommand = function(id,event){ if winform.plsActive.checked { var path = ini.read("setting","Active"); var interval = ini.read("setting","Interval"); if !path return; winform.prcsActive, err = process.popen(string.format("%s",path)); if !winform.prcsActive { winform.msgbox( err ); } else { winform.prcsActive.codepage = 65001; winform.prcsActive.logResponse(winform.edit, tonumber(interval)); winform.plsActive.background = 0xFF00DD22; } sleep(1000); } if winform.plsHemo.checked { var path = ini.read("setting","Hemo"); var interval = ini.read("setting","Interval"); if !path return; winform.prcsHemo, err = process.popen(string.format("%s",path)); if !winform.prcsHemo { winform.msgbox( err ); } else { winform.prcsHemo.codepage = 65001; winform.prcsHemo.logResponse(winform.edit, tonumber(interval)); winform.plsHemo.background = 0xFF00DD22; } } if winform.plsAdjustable.checked { var path = ini.read("setting","Adj"); var interval = ini.read("setting","Interval"); if !path return; winform.prcsAdj, err = process.popen(string.format("%s",path)); if !winform.prcsAdj { winform.msgbox( err ); } else { winform.prcsAdj.codepage = 65001; winform.prcsAdj.logResponse(winform.edit, tonumber(interval)); winform.plsAdjustable.background = 0xFF00DD22; } } if winform.plsPFA.checked { var path = ini.read("setting","PFA"); var interval = ini.read("setting","Interval"); if !path return; winform.prcsPFA, err = process.popen(string.format("%s",path)); if !winform.prcsPFA { winform.msgbox( err ); } else { winform.prcsPFA.codepage = 65001; winform.prcsPFA.logResponse(winform.edit, tonumber(interval)); winform.plsPFA.background = 0xFF00DD22; } } if winform.plsEle.checked { var path = ini.read("setting","Ele"); var interval = ini.read("setting","Interval"); if !path return; winform.prcsEle, err = process.popen(string.format("%s",path)); if !winform.prcsEle { winform.msgbox( err ); } else { winform.prcsEle.codepage = 65001; winform.prcsEle.logResponse(winform.edit, tonumber(interval)); winform.plsEle.background = 0xFF00DD22; } } if winform.plsVisualization.checked { var path = ini.read("setting","Visual1"); var interval = ini.read("setting","Interval"); if !path return; winform.prcsVisual1, err = process.popen(string.format("%s",path)); if !winform.prcsVisual1 { winform.msgbox( err ); } else { winform.prcsVisual1.codepage = 65001; winform.prcsVisual1.logResponse(winform.edit, tonumber(interval)); winform.plsVisualization.background = 0xFF00DD22; } } if winform.plsVisualization2.checked { var path = ini.read("setting","Visual2"); var interval = ini.read("setting","Interval"); if !path return; winform.prcsVisual2, err = process.popen(string.format("%s",path)); if !winform.prcsVisual2 { winform.msgbox( err ); } else { winform.prcsVisual2.codepage = 65001; winform.prcsVisual2.logResponse(winform.edit, tonumber(interval)); winform.plsVisualization2.background = 0xFF00DD22; } } } winform.plsShutdown.oncommand = function(id,event){ if winform.plsActive.checked { try { winform.prcsActive.terminate(); }catch(e){}; winform.edit.print( "注册服务器已关闭"); winform.plsActive.background = 0xFF00579b; winform.plsActive.checked=false; } if winform.plsHemo.checked { try { winform.prcsHemo.terminate(); }catch(e){}; winform.edit.print( "止血阀服务器已关闭"); winform.plsHemo.background = 0xFF00579b; winform.plsHemo.checked=false; } if winform.plsAdjustable.checked { try { winform.prcsAdj.terminate(); }catch(e){}; winform.edit.print( "可调弯服务器已关闭"); winform.plsAdjustable.background = 0xFF00579b; winform.plsAdjustable.checked=false; } if winform.plsPFA.checked { try { winform.prcsPFA.terminate(); }catch(e){}; winform.edit.print( "五爪脉冲服务器已关闭"); winform.plsPFA.background = 0xFF00579b; winform.plsPFA.checked=false; } if winform.plsEle.checked { try { winform.prcsEle.terminate(); }catch(e){}; winform.edit.print( "电极间距服务器已关闭"); winform.plsEle.background = 0xFF00579b; winform.plsEle.checked=false; } if winform.plsVisualization.checked { try { winform.prcsVisual1.terminate(); }catch(e){}; winform.edit.print( "可视化服务器1已关闭"); winform.plsVisualization.background = 0xFF00579b; winform.plsVisualization.checked=false; } if winform.plsVisualization2.checked { try { winform.prcsVisual2.terminate(); }catch(e){}; winform.edit.print( "可视化服务器2已关闭"); winform.plsVisualization2.background = 0xFF00579b; winform.plsVisualization2.checked=false; } } winform.show(); win.loopMessage(); return winform;
4 个回复 | 最后更新于 2023-01-21
登录后方可回帖
其中“注册服务器”会先启动,然后延时1秒,再启动其他服务器,因为其他服务器启动时会先去注册服务器对比版本信息并获取授权。