示例#1
0
func startGateway() {
	msgDispatch := dispatch.NewDispatch(
		dispatch.HandleFunc{
			H: transferProxy.SendToGameServer,
		},
	)

	addr := "0.0.0.0:" + gateway_port
	err := global.Listener("tcp", addr, global.PackCodecType_UnSafe,
		func(session *link.Session) {
			//将此Session记录在缓存内,消息回传时使用
			global.AddSession(session)
			//通知LoginServer用户上线
			transferProxy.SetClientSessionOnline(session)
			//添加session关闭时回调
			session.AddCloseCallback(session, func() {
				//通知LoginServer、GameServer用户下线
				transferProxy.SetClientSessionOffline(session.Id())
			})
		},
		msgDispatch,
	)

	checkError(err)
}
//初始化
func InitServer(port string) error {
	servers = make(map[uint32]*link.Session)

	//监听tcp连接
	addr := "0.0.0.0:" + port
	err := global.Listener("tcp", addr, global.PackCodecType_Safe,
		func(session *link.Session) {},
		serverMsgDispatch,
	)

	return err
}
//初始化
func InitServer(port string) error {
	servers = make(map[string][]Server)
	gameConsistent = hashs.NewConsistent()
	gameUserSessions = make(map[uint64]int)

	//监听tcp
	addr := "0.0.0.0:" + port
	err := global.Listener("tcp", addr, global.PackCodecType_Safe,
		func(session *link.Session) {},
		serverMsgDispatch,
	)

	return err
}
示例#4
0
//初始化
func InitServer(port string) error {
	servers = make(map[string]*link.Session)

	//开启DB
	db.Init()

	//开启同步写入DB
	StartSysDB()

	//监听tcp连接
	addr := "0.0.0.0:" + port
	err := global.Listener("tcp", addr, global.PackCodecType_Safe,
		func(session *link.Session) {},
		serverMsgDispatch,
	)

	return err
}
示例#5
0
func startLocalServer() {
	//连接Redis
	redisProxyErr := redisProxy.InitClient(cfg.GetValue("redis_ip"), cfg.GetValue("redis_port"), cfg.GetValue("redis_pwd"))
	checkError(redisProxyErr)

	//开启DB
	db.Init()

	//开启同步DB数据到数据库
	dbProxy.StartSysDB()

	//开启客户端监听
	addr := "0.0.0.0:" + local_port
	err := global.Listener("tcp", addr, global.PackCodecType_UnSafe,
		func(session *link.Session) {
			global.AddSession(session)
		},
		gameProxy.MsgDispatch,
	)
	checkError(err)
}