123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RoomData{
- public List<SocketOnlineRoomItemData> dataList = new List<SocketOnlineRoomItemData>();
- public Dictionary<int, UserData> userList = new Dictionary<int, UserData>();//当前的房间里 听众列表
- 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<SocketOnlineRoomItemData>(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<System.Object> PublicList
- {
- get
- {
- return GetListBySubjectId(true);
- }
- }
- public List<System.Object> PrivateList
- {
- get
- {
- return GetListBySubjectId(false);
- }
- }
- private List<System.Object> GetListBySubjectId(bool id_str)
- {
- List<System.Object> t_list = new List<System.Object>();
- 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);
- }
- }
|