NSMC Server Launcher with Remote Command Server



main.go 3.4KB

    package main import ( "path" "fmt" "os" "git.swzry.com/NSMCServerLauncher/Logger" "git.swzry.com/NSMCServerLauncher/Utils" "git.swzry.com/NSMCServerLauncher/SSHServer" "git.swzry.com/NSMCServerLauncher/Commands" ) var CurrentPath string var MainThreadBlockChan chan byte func main(){ cp,err := Utils.GetCurrentDirectory() if(err != nil){ fmt.Println("[StdOutLog][Fatal Error] Failed Get PWD: ",err) return } CurrentPath = cp if r,err := Utils.PathExists(path.Join(CurrentPath,"sysfiles")); ((!r) || (err != nil)) { fmt.Println("[StdOutLog][Fatal Error] System File Dir './sysfiles/' Not Exist! ") return } isinit := false if r,err := Utils.PathExists(path.Join(CurrentPath,"data")); ((!r) || (err != nil)) { fmt.Println("[StdOutLog][WARNING] Dir './data/' Not Exist! Will Create One.") isinit = true if err := os.MkdirAll(path.Join(CurrentPath,"data"),0777);err != nil { fmt.Println("[StdOutLog][Fatal Error] Failed Create Dir './data/' : ",err) return } } if r,err := Utils.PathExists(path.Join(CurrentPath,"data","conf")); ((!r) || (err != nil)) { fmt.Println("[StdOutLog][WARNING] Config Dir './data/conf/' Not Exist! Will Create One.") isinit = true if err := os.MkdirAll(path.Join(CurrentPath,"data","conf"),0777);err != nil { fmt.Println("[StdOutLog][Fatal Error] Failed Create Dir './data/conf/' : ",err) return } } if r,err := Utils.PathExists(path.Join(CurrentPath,"data","conf", "logger.conf")); ((!r) || (err != nil)) { fmt.Println("[StdOutLog][WARNING] Config File './data/conf/logger.conf' Not Exist! Will Create A Template Config File..") isinit = true if _,err := Utils.CopyFile(path.Join(CurrentPath,"data","conf", "logger.conf"),path.Join(CurrentPath,"sysfiles","conftpl", "logger.conf"));err != nil { fmt.Println("[StdOutLog][Fatal Error] Failed Copy Template Config File './data/conf/logger.conf' : ",err) return } } if r,err := Utils.PathExists(path.Join(CurrentPath,"data","conf", "sshd.conf")); ((!r) || (err != nil)) { fmt.Println("[StdOutLog][WARNING] Config File './data/conf/sshd.conf' Not Exist! Will Create A Template Config File..") isinit = true if _,err := Utils.CopyFile(path.Join(CurrentPath,"data","conf", "sshd.conf"),path.Join(CurrentPath,"sysfiles","conftpl", "sshd.conf"));err != nil { fmt.Println("[StdOutLog][Fatal Error] Failed Copy Template Config File './data/conf/sshd.conf' : ",err) return } } // TODO: Other Config File Process Code Here if(isinit){ fmt.Println("[StdOutLog][WARNING] At this time, we had created template config files for you, you should edit them and restart this server..") fmt.Println("[StdOutLog][INFO] Server Exit.") return } if Logger.LoadLoggerConfig(path.Join(CurrentPath,"data","conf", "logger.conf")) != nil{ return } if Logger.InitLogger() != nil { return } fmt.Fprintln(&Logger.Log.SysInfo,"NSMC Server Launcher System Start.") if err := Utils.MkDirIfNotExist(path.Join(CurrentPath,"data","keys")); err != nil { fmt.Println("[StdOutLog][Fatal Error] Failed Create Dir '",path.Join(CurrentPath,"data","keys"),"' : ",err) return } if SSHServer.LoadSSHConfig(path.Join(CurrentPath,"data","conf", "sshd.conf")) != nil{ return } fmt.Fprintln(&Logger.Log.SysInfo,"Regist Commands....") Commands.RegistAllCommands() fmt.Fprintln(&Logger.Log.SysInfo,"Start SSH Server...") go SSHServer.StartSSHServer(MainThreadBlockChan) <-MainThreadBlockChan }