示例#1
0
文件: onlinec.go 项目: lijie/siriusdb
func main() {
	flag.StringVar(&onlineAddr, "online", "127.0.0.1:30800", "online server addr")
	flag.StringVar(&gsAddr, "gs", "127.0.0.1:30500", "game server addr")
	flag.Parse()

	var err error

	accountName = fmt.Sprintf("%s%d", "TestOnline", time.Now().UnixNano())
	roleName = fmt.Sprintf("%s%d", "TestRole", time.Now().UnixNano())
	roleName2 = fmt.Sprintf("%s%d", "TestRole2", time.Now().UnixNano())

	onlineServer.Conn, err = connect(onlineAddr)
	assert(err == nil)
	onlineServer.Client = sirius_rpc.NewClient(onlineServer.Conn)

	gsServer1.Conn, err = connect(gsAddr)
	assert(err == nil)
	gsServer1.Client = sirius_rpc.NewClient(gsServer1.Conn)

	gsServer2.Conn, err = connect(gsAddr)
	assert(err == nil)
	gsServer2.Client = sirius_rpc.NewClient(gsServer2.Conn)

	TestFunc1()
	TestFunc2()
	TestFunc3()
}
示例#2
0
func connectOnline(t *testing.T) {
	var err error
	onlineAddr = "127.0.0.1:30800"
	onlineServer.Conn, err = connect(onlineAddr)
	if err != nil {
		t.Fatal("connect online", err)
	}
	onlineServer.Client = sirius_rpc.NewClient(onlineServer.Conn)
}
示例#3
0
文件: onlinec.go 项目: lijie/siriusdb
func TestFunc1() {
	fmt.Printf("start TestFunc1...")
	// 获取账户信息
	fmt.Printf("Fetch user account info\n")
	var roleid uint64
	var errcode int
	accountInfo, err := getAccountInfo()
	if err == ErrNoAccount {
		roleid, err = createRole(roleName)
		fmt.Printf("create role %s\n", roleName)
		checkError(err)
		accountInfo, err = getAccountInfo()
		checkError(err)
	}

	if len(accountInfo.Accounts) == 0 {
		roleid, err = createRole(roleName)
		fmt.Printf("create role %s\n", roleName)
		checkError(err)
	} else {
		// find role
		for i := range accountInfo.Accounts {
			ac := accountInfo.Accounts[i]
			if ac.GetName() == roleName {
				roleid = ac.GetRoleid()
			}
		}
		// not found
		if roleid == 0 {
			roleid, err = createRole(roleName)
			fmt.Printf("create role %s\n", roleName)
			checkError(err)
		}
	}
	fmt.Println(accountInfo)
	fmt.Println(roleid)

	// 设置roleid在线
	fmt.Printf("try set %d online...\n", roleid)
	err = setRoleOnline(roleid)
	assert(err == nil)
	fmt.Printf("set online done\n")

	// login to gs
	fmt.Printf("try login %d to gs...\n", roleid)
	err = loginGS1(roleid)
	fmt.Printf("errcode %d, err %v\n", errcode, err)
	assert(err == nil)
	fmt.Printf("login ok\n")

	// 重复登录
	fmt.Printf("try login %d repeat...\n", roleid)
	err = loginGS1(roleid)
	assert(err.Error() == "server error 10503")
	fmt.Printf("login repeat done\n")

	// 重复设置roleid在线
	// 之前登录GS的role应该被踢下线
	err = setRoleOnline(roleid)
	assert(err == nil)
	fmt.Printf("set online again done\n")

	// 再次发登录信息
	// 应该发送失败, 连接已经被GS断开
	err = loginGS1(roleid)
	assert(err != nil)
	fmt.Println("loginGS1 should failed, err:", err)

	// 重新连接gs
	// gsConn.Close()
	// gsConn, _ = connect(gsAddr)
	gsServer1.Client.Close()
	gsServer1.Conn, _ = connect(gsAddr)
	gsServer1.Client = sirius_rpc.NewClient(gsServer1.Conn)

	// login to gs
	err = loginGS1(roleid)
	assert(err == nil)
	fmt.Printf("login ok\n")
}