/// <summary> /// 添加角色成功时,msgCode返回当前角色的ID /// </summary> /// <param name="classId"></param> /// <param name="nickName"></param> /// <param name="gameServerId"></param> private void AddRoleServerResp(int classId, string nickName, int gameServerId) { Account_AddRoleRespProto proto = new Account_AddRoleRespProto(); int currentAddId = RoleDBModelServer.Instance.AddRole(classId, nickName, gameServerId, 1); if (currentAddId == -1) { proto.IsSuccess = false; proto.MsgCode = Constant.ROLE_ADD_FAIL; } else { proto.IsSuccess = true; proto.MsgCode = currentAddId; } SocketManagerServer.Instance.SendMessageToClient(proto.ToArray()); }
/// <summary> /// 手动修改过,无论是否成功都读取msgCode /// </summary> /// <param name="buffer"></param> /// <returns></returns> public static Account_AddRoleRespProto GetProto(byte[] buffer) { Account_AddRoleRespProto proto = new Account_AddRoleRespProto(); using (MemoryStreamUtil ms = new MemoryStreamUtil(buffer)) { proto.IsSuccess = ms.ReadBool(); proto.MsgCode = ms.ReadInt(); /* * if (!proto.IsSuccess) * { * proto.MsgCode = ms.ReadInt(); * } */ } return(proto); }
/// <summary> /// 服务器返回创建角色的消息 /// </summary> /// <param name="p"></param> private void OnAddRoleServerResp(byte[] buffer) { Account_AddRoleRespProto proto = Account_AddRoleRespProto.GetProto(buffer); if (proto.IsSuccess) { //创建角色成功,开始登录进游戏的逻辑 Debug.Log("add role success!!!"); mCurrentSelectedRoleId = proto.MsgCode; //UIDialogController.Instance.Show("创建角色成功"); EnterGameReq(); //角色创建成功后直接发送进去游戏req } else { //创建角色失败,弹出提示框 UIDialogController.Instance.Show("创建角色失败!错误码" + proto.MsgCode); Debug.Log("创建角色失败!错误码" + proto.MsgCode); } }