using System.Collections; using System.Collections.Generic; using UnityEngine; public class RoomData{ public List dataList = new List(); public Dictionary userList = new Dictionary();//当前的房间里 听众列表 private short cur_room_id =-1;//当前所在的房间的id号 private AudioData CurAudioData = new AudioData(); public short CurRoomId { get { return cur_room_id; } set { cur_room_id = value; } } /* public bool AudioOpenValue { get { return this.CurAudioData.isOpen; } } public bool AudioIsEmpty { get { return this.CurAudioData.roomId == null; } } private void AudioCreated(string audioId) { this.CurAudioData.roomId = audioId; this.CurAudioData.isOpen = true; MessageCenter.Instance.Broadcast(GameEnum.MESSAGE_SEND_AUDIO_SOCKET_DATA, this.CurAudioData); } public void OpenAudio() { this.CurAudioData.isOpen = true; MessageCenter.Instance.Broadcast(GameEnum.MESSAGE_SEND_AUDIO_SOCKET_DATA, this.CurAudioData); } private void CloseAudio() { this.CurAudioData.isOpen = false; MessageCenter.Instance.Broadcast(GameEnum.MESSAGE_SEND_AUDIO_SOCKET_DATA, this.CurAudioData); } */ public void SetRoomId(Engine.Net.NetMsg iMsg) { CurRoomData data = new CurRoomData(); iMsg.UnPackMsg(ref data); CurRoomId = data.room_id; CDebug.Log("重新登陆 拿到的我的 当前的房间号是" + CurRoomId); } public void InitData(Engine.Net.NetMsg iMsg) { CDebug.Log("socket房间列表信息的解析"); SocketRoomItemArrayData data = new SocketRoomItemArrayData(); iMsg.UnPackMsg(ref data); dataList.Clear(); CDebug.Log("当前有" + data.ct + "个房间"); for(int i= 0; i< data.ct; i++) { AddRoomItemData(iMsg); } //dataList = new List(data.datas);//直接覆盖 MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_ROOM_LIST_VIEW); } private void AddRoomItemData(Engine.Net.NetMsg iMsg) { SocketOnlineRoomItemData data = new SocketOnlineRoomItemData(); iMsg.UnPackMsg(ref data); dataList.Add(data); } public void AddRommData(Engine.Net.NetMsg iMsg) { SocketOnlineRoomItemData data = new SocketOnlineRoomItemData(); iMsg.UnPackMsg(ref data); dataList.Add(data); //检查下创建房间的所有者者是是不是我自己 if (data.owner_id.Equals(GamePlayerData.Instance.user_id) || data.owner_id.ToString().Equals(GamePlayerData.Instance.user_id)) { GamePlayerData.Instance.room_data.CurRoomId = data.room_id;//创建了房间 UserData myData = new UserData(); myData.user_id = GamePlayerData.Instance.user_id; myData.user_name = GamePlayerData.Instance.user_name; myData.user_type = (short)GamePlayerData.Instance.user_type; GamePlayerData.Instance.room_data.userList.Clear(); GamePlayerData.Instance.room_data.userList.Add(myData.user_id, myData); //获取课程信息 课程信息获取了才能进入房间 MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_ENTER_COURSE); //IvChatManager.Instance.CreateRoom(data.room_id.ToString()); } else { MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_ROOM_LIST_VIEW); } } public void UpdateRoomData(Engine.Net.NetMsg iMsg) { RoomOnlineData data = new RoomOnlineData(); iMsg.UnPackMsg(ref data); foreach (SocketOnlineRoomItemData r_data in dataList) { if (r_data.room_id.Equals(data.room_id)) { r_data.onlineCt = data.online_ct; break; } } MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_ROOM_LIST_VIEW); } //销毁房间的消息 public void RemoveRoomData(Engine.Net.NetMsg iMsg) { DeleteRoomData data = new DeleteRoomData(); iMsg.UnPackMsg(ref data); foreach(SocketOnlineRoomItemData r_data in dataList) { if(r_data.room_id.Equals(data.room_id)) { if(r_data.room_id == GamePlayerData.Instance.room_data.CurRoomId && !GamePlayerData.Instance.room_data.IsReconnectOwner()) { if(GamePlayerData.Instance.room_data.CurRoomId == -1) { CDebug.Log("这里有严重的逻辑错误"); return; } //当前的房间销毁了 GamePlayerData.Instance.room_data.CurRoomId = -1; MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_EXIT_COURSE); GameNetManager.Instance.mSocketMsgCenter.SendGetDatingData();//获取大厅的消息 } dataList.Remove(r_data); //这里需要更新房间列表的删除情况 MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_ROOM_LIST_VIEW); break; } } } public void TestData(Engine.Net.NetMsg iMsg) { TestData data = new TestData(); iMsg.UnPackMsg(ref data); CDebug.LogObj(data); } public List PublicList { get { return GetListBySubjectId(true); } } public List PrivateList { get { return GetListBySubjectId(false); } } private List GetListBySubjectId(bool id_str) { List t_list = new List(); foreach (SocketOnlineRoomItemData data in dataList) { if (data.is_public == id_str) { object someBoxedStruct = data; t_list.Add(data); } } return t_list; } //初始化房间里的用户列表 public void InitUserList(Engine.Net.NetMsg iMsg) { StudentListBackData data = new StudentListBackData(); iMsg.UnPackMsg(ref data); userList.Clear();//清空数据 for (int i = 0; i < data.ct; i++) { UserData student = new UserData(); iMsg.UnPackMsg(ref student); if(student.user_id.Equals(GamePlayerData.Instance.user_id)) { //continue;//排除掉自己 } userList.Add(student.user_id, student); if (student.user_type == GameEnum.STUDENT_TYPE) StudentTaskReceiveManager.Instance.AddEmptyStudentPaper(student.user_id); } MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_USER_LIST_DATA); } public void UpdateUser(Engine.Net.NetMsg iMsg) { UserEnterBackData data = new UserEnterBackData(); iMsg.UnPackMsg(ref data); if(data.is_enter && !userList.ContainsKey(iMsg.UserId)) { UserData student = new UserData(); student.user_id = iMsg.UserId; student.user_type = data.user_type; student.user_name = data.user_name; userList.Add(iMsg.UserId, student); if(student.user_type == GameEnum.STUDENT_TYPE) StudentTaskReceiveManager.Instance.AddEmptyStudentPaper(student.user_id); if(GamePlayerData.Instance.IsFangzhu()) MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SEND_MSG_TO_NEW_STUDENT, iMsg.UserId);//同步给刚进来的学生当前的操作的数据 } if(!data.is_enter && userList.ContainsKey(iMsg.UserId)) { userList.Remove(iMsg.UserId); StudentTaskReceiveManager.Instance.RemoveStudentPaper(iMsg.UserId); } CDebug.Log("当前房间的人数 "+ userList.Count); MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_USER_LIST_DATA);//更新数据 } //这个地方需要优化 public bool NeedReconnect() { foreach(SocketOnlineRoomItemData r_data in dataList) { if(r_data.room_id == CurRoomId) { CDebug.Log("找到了已经存在的房间"); if(r_data.owner_id == GamePlayerData.Instance.user_id) { CDebug.Log("是房主"); } else { CDebug.Log("是听课的"); } return true; } } return false; } public bool IsReconnectOwner() { foreach (SocketOnlineRoomItemData r_data in dataList) { if (r_data.room_id == CurRoomId) { if (r_data.owner_id == GamePlayerData.Instance.user_id) { return true; } } } return false; } public SocketOnlineRoomItemData CurOnlineData { get { foreach(SocketOnlineRoomItemData data in dataList) { if(data.room_id == CurRoomId) { return data; } } return null; } } //房间里有没有听众 public bool IsEmptyUser { get { return userList.Count <= 1;//1是老师 一定是老师在里面 所以从1开始判定 } } //切换房主 public void ChangeOwnerId(Engine.Net.NetMsg iMsg) { ChangeOwner data = new ChangeOwner(); iMsg.UnPackMsg(ref data); CDebug.Log("收到的切换房主的信息内容 新房主 " + data.owner_id + " 房间号 " + data.room_id); if(iMsg.UserId == GamePlayerData.Instance.user_id) { MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "切换成功"); //IvChatManager.Instance.SetSilentValue(true); } //更新大厅列表 foreach (SocketOnlineRoomItemData r_data in dataList) { if (r_data.room_id.Equals(data.room_id)) { r_data.owner_id = data.owner_id; if(r_data.owner_id == GamePlayerData.Instance.user_id) { MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "你是新的房主"); //IvChatManager.Instance.SetSilentValue(false); } break; } } MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_ROOM_LIST_VIEW); MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SEND_CHANGE_ROOM_OWNER_REFRESH);//有房主的变动 MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_USER_LIST_DATA); } }