Example #1
0
func main() {
	logger.Info("start fight server")

	var cfg config.SvrConfig
	if err := config.ReadConfig(*svrConfigFile, &cfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
		return
	}

	fightserver.StartServices(&cfg, fightServerId)

	handler := func(s os.Signal, arg interface{}) {
		logger.Info("handle signal: %v\n", s)
		logger.Info("stop game server")
		os.Exit(0)
	}

	handlerArray := []os.Signal{syscall.SIGINT,
		syscall.SIGILL,
		syscall.SIGFPE,
		syscall.SIGSEGV,
		syscall.SIGTERM,
		syscall.SIGABRT}

	common.WatchSystemSignal(&handlerArray, handler)

	logger.Info("stop fight server")
}
Example #2
0
func CreateServices(authcfg config.AuthConfig) *AuthServer {

	//初始化db
	logger.Info("Init DB")
	db.Init()

	//初始化cache
	var cacheCfg config.CacheConfig
	if err := config.ReadConfig("etc/maincache.json", &cacheCfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
	}
	logger.Info("Init Cache %v", cacheCfg)

	pAuthServices = &AuthServer{
		maincache: db.NewCachePool(cacheCfg),
		rpcServer: rpc.NewServer(),
		exit:      make(chan bool),
	}

	pAuthServices.rpcServer.Register(pAuthServices)

	pAuthServices.rpcServer.ListenAndServe(authcfg.AuthHost, nil)

	return pAuthServices
}
func Register_lua_db_CachePool_newClass(L *lua.LState) int {
	cfg := L.CheckString(2)
	var cacheCfg config.CacheConfig
	if err := config.ReadConfig(cfg, &cacheCfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
	}
	logger.Info("Init Cache %v", cacheCfg)
	cache := db.NewCachePool(cacheCfg)
	ud := L.NewUserData()
	ud.Value = cache
	L.SetMetatable(ud, L.GetTypeMetatable(luaCachePoolTypeName))
	L.Push(ud)
	return 1
}
Example #4
0
func main() {
	logger.Info("start auth server")

	var authcfg config.AuthConfig
	if err := config.ReadConfig(*authConfigFile, &authcfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
		return
	}

	server.CreateServices(authcfg)

	common.WatchSystemSignal()

	logger.Info("stop auth server")
}
Example #5
0
func main() {
	logger.Info("start db server")

	var dbcfg config.DBConfig
	if err := config.ReadConfig(*dbConfigFile, &dbcfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
		return
	}

	server.CreateServices(dbcfg)

	common.WatchSystemSignal()

	logger.Info("stop db server")
}
Example #6
0
func Init() {
	//base
	var dbCfg config.DBConfig
	if err := config.ReadConfig("etc/dbBase.json", &dbCfg); err != nil {
		logger.Fatal("%v", err)
	}

	aHosts := make([]string, 0)
	aHosts = append(aHosts, dbCfg.DBHost)
	pPollBase = rpc.CreateClientPool(aHosts)
	if pPollBase == nil {
		logger.Fatal("create failed")
	}

	logger.Debug("Init DBClient : %v ", dbCfg.DBHost)
}
Example #7
0
func main() {
	logger.Info("start game server")

	var cfg config.SvrConfig
	if err := config.ReadConfig(*svrConfigFile, &cfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
		return
	}

	server.CreateConnectorServerForClient(cfg)

	common.WatchSystemSignal()
	//script.DefaultLuaScript().ExecuteScriptFile("script/runtime/gameserver/main.lua")

	logger.Info("stop game server")
}
Example #8
0
func CreateConnectorServerForClient(cfg config.SvrConfig) *Connector {

	db.Init()

	var authCfg config.AuthConfig
	if err := config.ReadConfig("etc/authserver.json", &authCfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
	}
	authConn, err := net.Dial("tcp", authCfg.AuthHost)
	if err != nil {
		logger.Fatal("connect logserver failed %s", err.Error())
	}

	var gsCfg config.LoginConfig
	if err = config.ReadConfig("etc/loginserver.json", &gsCfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
	}
	gsConn, err := net.Dial("tcp", gsCfg.LoginHost)
	if err != nil {
		logger.Fatal("%s", err.Error())
	}

	pConnector = &Connector{
		m:           make(map[uint32]serverInfo),
		authserver:  rpc.NewClient(authConn),
		loginserver: rpc.NewClient(gsConn),
		rpcServer:   server.NewServer(),
		players:     make(map[uint64]*Player),
		playersbyid: make(map[string]*Player),
	}

	//初始化cache
	logger.Info("Init Cache %v", authCfg.MainCacheProfile)
	pConnector.maincache = db.NewCachePool(authCfg.MainCacheProfile)

	pConnector.rpcServer.ApplyProtocol(protobuf.CS_Protocol_value)
	pConnector.rpcServer.Register(pConnector)

	pConnector.rpcServer.RegCallBackOnConn(
		func(conn server.RpcConn) {
			pConnector.onConn(conn)
		},
	)

	pConnector.rpcServer.RegCallBackOnDisConn(
		func(conn server.RpcConn) {
			pConnector.onDisConn(conn)
		},
	)

	pConnector.rpcServer.RegCallBackOnCallBefore(
		func(conn server.RpcConn) {
			conn.Lock()
		},
	)

	pConnector.rpcServer.RegCallBackOnCallAfter(
		func(conn server.RpcConn) {
			conn.Unlock()
		},
	)

	//开始对fightserver的RPC服务
	pConnector.FsMgr.Init(pConnector.rpcServer, cfg)

	listener, err := net.Listen("tcp", cfg.TcpHost)
	if err != nil {
		logger.Fatal("net.Listen: %s", err.Error())
	}

	pConnector.id = cfg.ServerID
	pConnector.listenTcpIp = cfg.TcpHost
	pConnector.listenHttpIp = cfg.HttpHost

	pConnector.sendPlayerCountToGateServer()

	go func() {
		for {
			//For Client/////////////////////////////
			time.Sleep(time.Millisecond * 5)
			conn, err := listener.Accept()

			if err != nil {
				logger.Error("cns StartServices %s", err.Error())
				break
			}

			go func() {
				rpcConn := server.NewTCPSocketConn(pConnector.rpcServer, conn, 128, 45, 1)
				defer func() {
					if r := recover(); r != nil {
						logger.Error("player rpc runtime error begin:", r)
						debug.PrintStack()
						rpcConn.Close()

						logger.Error("player rpc runtime error end ")
					}
				}()

				pConnector.rpcServer.ServeConn(rpcConn)
			}()
		}
	}()

	http.HandleFunc("/", wsServeConnHandler)
	http.ListenAndServe(cfg.HttpHost, nil)

	return pConnector
}
Example #9
0
func testLogin() {

	var cfg config.LoginConfig
	if err := config.ReadConfig(*gateConfigFile, &cfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
		return
	}

	conn, err := net.Dial("tcp", cfg.TcpHostForClient)
	if err != nil {
		logger.Fatal("%s", err.Error())
	}

	rpcConn := server.NewTCPSocketConn(nil, conn, 4, 0, 1)

	login := &protobuf.CL_CheckAccount{}
	login.SetAccount("account")
	login.SetPassword("password")
	rpcConn.Call("LoginServer.CL_CheckAccount", login)

	rst := new(server.RequestWrap)
	err = rpcConn.ReadRequest(&rst.Request)

	// argv guaranteed to be a pointer now.
	argv := reflect.New(reflect.TypeOf(protobuf.LC_CheckAccountResult{}))
	rpcConn.GetRequestBody(&rst.Request, argv.Interface())

	info := argv.Interface().(*protobuf.LC_CheckAccountResult)

	logger.Info("LoginServer Info : %v", argv.Interface())
	logger.Info("                 %v", &rst.Request)
	logger.Info("                 %v", info.GetSessionKey())

	rpcConn.Close()

	time.Sleep(time.Millisecond * 1000)

	conn, err = net.Dial("tcp", info.GetGameServerIp())
	if err != nil {
		logger.Fatal("%s", err.Error())
	}

	rpcConn = server.NewTCPSocketConn(nil, conn, 4, 0, 1)

	check := &protobuf.CS_CheckSession{}
	check.SetUid(info.GetUid())
	check.SetSessionKey(info.GetSessionKey())
	check.SetTimestamp(uint32(time.Now().Unix()))
	rpcConn.Call("GameServer.CS_CheckSession", check)

	rst = new(server.RequestWrap)
	err = rpcConn.ReadRequest(&rst.Request)

	// argv guaranteed to be a pointer now.
	argv = reflect.New(reflect.TypeOf(protobuf.SC_CheckSessionResult{}))
	rpcConn.GetRequestBody(&rst.Request, argv.Interface())
	logger.Info("GameServer.CS_CheckSession : %v", argv.Interface())
	logger.Info("                 %v", &rst.Request)

	for i := 0; i < 100; i++ {
		time.Sleep(time.Millisecond * 1000)
		req := &protobuf.CS_Ping{}
		rpcConn.Call("GameServer.CS_Ping", req)

		rst = new(server.RequestWrap)
		err = rpcConn.ReadRequest(&rst.Request)

		// argv guaranteed to be a pointer now.
		argv = reflect.New(reflect.TypeOf(protobuf.SC_PingResult{}))
		rpcConn.GetRequestBody(&rst.Request, argv.Interface())
		logger.Info("GameServer.CS_Ping : %v", argv.Interface())
		logger.Info("                 %v", &rst.Request)
	}

	rpcConn.Close()
}