Exemplo n.º 1
0
func main() {

	cfg := NewWsConfig(cfgFile)
	cfg.LoadConfig()
	curDir, err := os.Getwd()
	if err != nil {
		panic(err)
	}
	logFile = fileLogger.NewDefaultLogger(curDir+"/log", cfg.LogFile)
	logFile.SetPrefix("[ERROR] ")

	ws = NewWorldServer(cfg)
	err = ws.NewServer()
	if err != nil {
		println("World Server Error: 启动 WS 服务器 失败. ", err.Error())
		logFile.Printf("World Server Error: 启动 WS 服务器 失败. ", err.Error())
		return
	}
	println("World Key Server start:", ws.keyserver.GetListener().Addr().String())

	println("World Server start:", ws.server.GetListener().Addr().String())
	usermap = safemap.NewSafeMap()
	waitgroup = new(sync.WaitGroup)

	waitgroup.Add(2)
	go ws.KeyServe()
	go ws.Serve()

	//go ws.CheckUserState()
	waitgroup.Wait()
	ws.Stop()
}
Exemplo n.º 2
0
func NewMsgServer(cfg *MSConfig) *MsgServer {
	return &MsgServer{
		cfg:             cfg,
		customCodec:     new(codec.CustomCodec),
		keyCodec:        new(codec.KeyCodec),
		userlist:        safemap.NewSafeMap(),
		isSentHeartBeat: false,
	}
}
Exemplo n.º 3
0
func NewClient(cfg *ClientConfig) *Client {
	return &Client{
		cfg:             cfg,
		customcodec:     new(codec.CustomCodec),
		keycodec:        new(codec.KeyCodec),
		MsgChan:         make(chan *msgcmd.Cmd, 1024),
		isSentHeartBeat: false,
		onLineUsers:     safemap.NewSafeMap(),
	}
}
Exemplo n.º 4
0
/*
* 描  述:	NewServer -- 创建一个Server结构实例
* 参  数:	listener -- 监听套接字
			codetype -- 指定一个编解码对象,该对象实现了CodecTypeer接口
* 返回值:	一个Server对象的指针
*/
func NewServer(listener net.Listener, codetype CodecTypeer) *Server {
	ret := &Server{
		listener:  listener,
		codectype: codetype,
	}
	for i := 0; i < sessionMapNum; i++ {
		// ret.sessionMaps[i].sessions = make(map[uint64]*Session)
		ret.sessionMaps[i] = safemap.NewSafeMap()
	}
	return ret
}