/// <summary> /// 监听服务器返回的登陆消息,里面包含角色信息 /// </summary> /// <param name="buffer"></param> private void OnLoginGameServerResp(byte[] buffer) { Account_LoginGameServerRespProto proto = Account_LoginGameServerRespProto.GetProto(buffer); int roleCount = proto.RoleCount; Debug.Log("角色数量:" + roleCount); if (roleCount == 0) //没角色,进入新建角色界面 { //新建角色界面,修改开始游戏按钮标记,切换一下UI、克隆所有角色、加载角色描述、自动赋予一个随机名字 mIsCreate = true; mUISelectRoleView.SetUIObjShow(true); SetRoleSpawnPointsShow(true); CloneAllRoles(); SetCurrentClassDesc(mCurrentSelectedClassId); mUISelectRoleView.RandomNameClick(); //新建界面自动赋值一个随机名字 mUISelectRoleView.CreateRoleButton.gameObject.SetActive(false); //创建角色界面把该按钮隐藏 Debug.Log("clone done!"); } else { //选择角色界面,修改开始游戏按钮标记,切换一下UI,加载已有角色信息、克隆对应角色 mIsCreate = false; mUISelectRoleView.SetUIObjShow(false); SetRoleSpawnPointsShow(false); mUISelectRoleView.CreateRoleButton.gameObject.SetActive(false); //把创建角色按钮隐藏 if (proto.RoleList != null) { mMyRoleList = proto.RoleList; mCurrentSelectedRoleId = proto.RoleList[0].RoleId; //我的游戏只允许创建一个角色,所以固定取第一个角色的ID为当前选择的角色ID mUISelectRoleView.SetRoleList(proto.RoleList); SetMyRolePrefab(proto.RoleList[0].RoleId); } } GlobalCache.Instance.Role_CurrentRoleId = mCurrentSelectedRoleId; //把当前的roleID缓存到全局 }
/// <summary> /// 服务器操作,把客户端传来的accountID查询对应的RoleID,并把这个role对象返回给客户端 /// 20.07.10Ich新增区服判断 /// </summary> /// <param name="role"></param> /// <param name="accountId"></param> private void LoginGameServerResp(int accountId, int gameServerId) { Account_LoginGameServerRespProto proto = new Account_LoginGameServerRespProto(); //TODO 这步是调用CacheModel层去数据库查角色,返回一个角色实体列表,后续改成我自己的逻辑 (select * from Role where [AccountId]=accountId) List <RoleEntity> lst = RoleDBModelServer.Instance.GetRoles(accountId, gameServerId); int count = 0; while (count < lst.Count) { //如果角色状态是已删除,则不向客户端返回该角色 if (lst[count].Status == EnumEntityStatus.Deleted) { Debug.Log(lst[count].NickName + "是已删除的角色!"); lst.RemoveAt(count); } else { count++; } } //List<RoleEntity> lst = RoleCacheModel.Instance.GetList(condition: string.Format("[AccountId]={0}", accountId)); if (lst != null && lst.Count > 0) { proto.RoleCount = lst.Count; proto.RoleList = new List <Account_LoginGameServerRespProto.RoleItem>(); GlobalCache.Instance.Account_CurrentId = accountId; //登陆成功时记录一下当前的accountId,后面创建角色时使用 for (int i = 0; i < lst.Count; i++) { proto.RoleList.Add(new Account_LoginGameServerRespProto.RoleItem() { RoleId = lst[i].Id, RoleNickName = lst[i].NickName, RoleLevel = lst[i].Level, RoleClass = (byte)lst[i].ClassId }); } } else { proto.RoleCount = 0; } //给客户端发消息, SocketManagerServer.Instance.SendMessageToClient(proto.ToArray()); //role.Client_Socket.SendMsg(proto.ToArray()); }
public static Account_LoginGameServerRespProto GetProto(byte[] buffer) { Account_LoginGameServerRespProto proto = new Account_LoginGameServerRespProto(); using (MemoryStreamUtil ms = new MemoryStreamUtil(buffer)) { proto.RoleCount = ms.ReadInt(); proto.RoleList = new List <RoleItem>(); for (int i = 0; i < proto.RoleCount; i++) { RoleItem _Role = new RoleItem(); _Role.RoleId = ms.ReadInt(); _Role.RoleNickName = ms.ReadUTF8String(); _Role.RoleClass = (byte)ms.ReadByte(); _Role.RoleLevel = ms.ReadInt(); proto.RoleList.Add(_Role); } } return(proto); }