github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/main.go (about)

     1  package main
     2  
     3  import (
     4  	"conf"
     5  	"game"
     6  	"gate"
     7  	"github.com/name5566/leaf/log"
     8  	"login"
     9  	"os"
    10  	"os/signal"
    11  	"syscall"
    12  	"time"
    13  
    14  	"github.com/name5566/leaf"
    15  	lconf "github.com/name5566/leaf/conf"
    16  )
    17  
    18  func main() {
    19  	log.Debug("dididi")
    20  	lconf.LogLevel = conf.Server.LogLevel
    21  	lconf.LogPath = conf.Server.LogPath
    22  	lconf.LogFlag = conf.LogFlag
    23  	lconf.ConsolePort = conf.Server.ConsolePort
    24  	lconf.ProfilePath = conf.Server.ProfilePath
    25  	handleSignal(syscall.SIGINT, handleINT)
    26  	leaf.Run(
    27  		game.Module,
    28  		gate.Module,
    29  		login.Module,
    30  	)
    31  }
    32  
    33  //! 注册信号量
    34  func handleSignal(signalType os.Signal, handleFun func(*chan os.Signal)) {
    35  	ch := make(chan os.Signal)
    36  	signal.Notify(ch, signalType)
    37  	go handleFun(&ch)
    38  }
    39  //! ctrl+c
    40  func handleINT(ch *chan os.Signal) {
    41  	for {
    42  		c := <-*ch
    43  		//操作
    44  		//game.BrocastServerDown(&msg.S2C_ServerDown{})
    45  		time.AfterFunc(time.Second*1, func() {
    46  			leaf.C <- c
    47  		})
    48  	}
    49  }