예제 #1
0
func (playerModule *PlayerModule) Relogin(clientObj *rpc.Client, id string) rpc.ResponseObject {
	responseObj := rpc.GetInitResponseObj()

	// 判断玩家是否在缓存中已经存在
	var playerObj *player.Player
	var rs rpc.ResultStatus
	playerObj, rs = GetPlayerById(clientObj, id)
	if rs != rpc.Success {
		return responseObj.SetResultStatus(rs)
	}

	// 判断是否重复登陆
	if oldClientObj, ok := rpc.GetClientByPlayerId(playerObj.Id); ok {
		// 如果不是同一个客户端,则将之前的未发送数据Clone过来
		if clientObj != oldClientObj {
			// 先将未发送的响应的推送数据Clone到新连接,再断开连接
			rpc.CloneUnsendData(oldClientObj, clientObj)
			oldClientObj.LogoutAndQuit()
		}
	}

	// 玩家上线
	clientObj.PlayerLogin(playerObj.Id)

	// 组装返回值
	responseObj.Data = assembleToClient(playerObj)

	return responseObj
}
예제 #2
0
func (playerModule *PlayerModule) Login(clientObj *rpc.Client, partnerId, serverId int, userId string) rpc.ResponseObject {
	responseObj := rpc.GetInitResponseObj()

	// 判断玩家是否在缓存中已经存在
	var playerObj *player.Player
	var rs rpc.ResultStatus
	playerObj, rs = GetPlayerByUserId(clientObj, partnerId, serverId, userId)

	if rs == rpc.Success {
		// 判断是否重复登陆
		if oldClientObj, ok := rpc.GetClientByPlayerId(playerObj.Id); ok {
			// 如果不是同一个客户端,则先发送重复登陆的信息,然后玩家登出,客户端退出
			if clientObj != oldClientObj {
				// 先发送被踢下去的信息,再断开连接
				PushDataToClient(oldClientObj, responseObj.SetResultStatus(rpc.LoginAgain))
				oldClientObj.LogoutAndQuit()
			}
		}
	} else if rs == rpc.PlayerNotFound {
		// 创建新玩家
		// playerObj = player.New(stringUtil.GetNewGUID(), name, partnerId, serverId, clientObj.Id())

		// 注册玩家名称和Id
		// playerNameBLL.RegisterNameAndId(name, playerObj.Id)
		return responseObj.SetResultStatus(rs)
	} else {
		return responseObj.SetResultStatus(rs)
	}

	// 玩家上线
	clientObj.PlayerLogin(playerObj.Id)

	// 组装返回值
	responseObj.Data = assembleToClient(playerObj)

	return responseObj
}