已测试并修正了新bug,择日再改
This commit is contained in:
parent
084f3644ff
commit
b5c2402fa5
@ -6,9 +6,10 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Timeout int `yaml:"timeout"` // minutes
|
||||
StartCommand string `yaml:"start_command"`
|
||||
Port string `yaml:"port"`
|
||||
Timeout int `yaml:"timeout"` // minutes
|
||||
StartCommand string `yaml:"start_command"`
|
||||
Port string `yaml:"port"`
|
||||
ConnectTimeout int `yaml:"connect_timeout"` //seconds
|
||||
}
|
||||
|
||||
// this is a global constant since it's shared
|
||||
|
||||
6
conn.go
6
conn.go
@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
//"time"
|
||||
)
|
||||
|
||||
func handle(client net.Conn) {
|
||||
@ -12,11 +13,12 @@ func handle(client net.Conn) {
|
||||
ChanChan <- queryChan
|
||||
proceed := func() {
|
||||
server, err := net.Dial("tcp", "127.0.0.1:25565")
|
||||
defer server.Close()
|
||||
if err != nil {
|
||||
GetLogger().Errorf("Failed to connect to MC server: %v", err)
|
||||
return
|
||||
}
|
||||
// TODO:better way of setting connection timeout
|
||||
defer server.Close()
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
@ -64,7 +66,7 @@ func Listen() {
|
||||
GetLogger().Errorf("ection error: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
//conn.SetReadDeadline(time.Now().Add(time.Duration(config.ConnectTimeout) * time.Second))
|
||||
GetLogger().Infof("New connection from %s", conn.RemoteAddr())
|
||||
go handle(conn)
|
||||
}
|
||||
|
||||
6
fsm.go
6
fsm.go
@ -60,6 +60,7 @@ var waitChan chan struct{}
|
||||
|
||||
// no we don't need cmdChan, we just make it work immediately
|
||||
func handleWaitingToRunning() {
|
||||
GetLogger().Infof("Server is currently at %s state", stateToStr[RUNNING])
|
||||
waitChan <- struct{}{}
|
||||
_, ok := <-waitChan
|
||||
if ok {
|
||||
@ -67,6 +68,7 @@ func handleWaitingToRunning() {
|
||||
} //else it's too late
|
||||
}
|
||||
func handleRunningToWaiting() {
|
||||
GetLogger().Infof("Server is currently at %s state", stateToStr[WAITING])
|
||||
waitChan = make(chan struct{})
|
||||
go waitingThread()
|
||||
state = WAITING
|
||||
@ -74,6 +76,7 @@ func handleRunningToWaiting() {
|
||||
|
||||
// TODO: work with daemon
|
||||
func handleWaitingToStopping() {
|
||||
GetLogger().Infof("Server is currently at %s state", stateToStr[STOPPED])
|
||||
go stoppingThread()
|
||||
state = STOPPING
|
||||
}
|
||||
@ -83,6 +86,7 @@ func stoppingThread() {
|
||||
handleStoppingToStopped()
|
||||
}
|
||||
func handleStoppingToStopped() {
|
||||
GetLogger().Infof("Server is currently at %s state", stateToStr[STOPPED])
|
||||
state = STOPPED
|
||||
}
|
||||
func bootingThread() {
|
||||
@ -94,10 +98,12 @@ func bootingThread() {
|
||||
var RunningChan = make(chan struct{})
|
||||
|
||||
func handleBootingToRunning() {
|
||||
GetLogger().Infof("Server is currently at %s state", stateToStr[RUNNING])
|
||||
state = RUNNING
|
||||
RunningChan <- struct{}{}
|
||||
}
|
||||
func handleStoppedToBooting() {
|
||||
GetLogger().Infof("Server is currently at %s state", stateToStr[BOOTING])
|
||||
go bootingThread()
|
||||
state = BOOTING
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user