示例#1
0
        /// <summary>
        /// 房间信息回调
        /// </summary>
        /// <param name="obj_arr"></param>
        void GetRoomMsgCallBack(params object[] obj_arr)
        {
            NetworkMessage message = (NetworkMessage)obj_arr[0];

            rooms.AddMessage(RoomMessage.GetMessage(message.message));

            NetworkManager._Instance.AddMessage(101, rooms);
        }
示例#2
0
 public void RemoveMessage(RoomMessage message)
 {
     lock (roomDic)
     {
         if (roomDic.ContainsKey(message.ip))
         {
             roomDic.Remove(message.ip);
         }
     }
 }
示例#3
0
        /// <summary>
        /// 向客户端发送房间信息
        /// </summary>
        /// <param name="obj_arr"></param>
        void SendRoomMsg(params object[] obj_arr)
        {
            NetworkMessage m   = (NetworkMessage)obj_arr[0];
            NetworkMessage rom = new NetworkMessage(1, room.ip,
                                                    RoomMessage.GetBytes(room));

            message = NetworkMessage.GetBytes(rom);
            string ip = Encoding.UTF8.GetString(m.message);

            //NetworkTools.PrintMessage("发送房间信息" + ip);
            SendMsg(ip, NetworkConstent.UDPClientPort, message);
        }
示例#4
0
 public void AddMessage(RoomMessage message)
 {
     lock (roomDic)
     {
         if (!roomDic.ContainsKey(message.ip))
         {
             roomDic.Add(message.ip, message);
             roomTime.Add(message.ip, DateTime.Now);
         }
         else
         {
             UpdateMessage(message);
         }
     }
 }
示例#5
0
        void CreateRoom(string roomName)
        {
            room = new RoomMessage(roomName, NetworkTools.GetLocalIP());

            NetworkManager._Instance.AddCallBack(2, SendRoomMsg);
            NetworkManager._Instance.AddCallBack(7, AddRoomMsgCallBack);
            NetworkManager._Instance.AddCallBack(9, QuitRoomMsgCallBack);
            NetworkManager._Instance.AddCallBack(10, UpdateRoomPlayerMsgCallBack);
            NetworkManager._Instance.AddCallBack(14, ReciveGetPlayerInfos);

            StartServer();
            playerData = new RoomPlayerData();
            playerData.AddPlayerInfo(NetworkTools.GetLocalIP(), new RoomPlayerInfoMessage("", true, NetworkTools.GetLocalIP()));
            playerInfo = new PlayerInfoMessage(1, 101, 102, "房主", NetworkTools.GetLocalIP());
            //RoomSingle.AddPlayer(new PlayerInfoMessage(2,104,105,"房主",NetworkTools.GetLocalIP()));
            NetworkManager._Instance.AddMessage(102, playerData);
            EventCenterManager._Instance.AddListener(EventType.GetPlayerInfo, GetPlayerInfoCallBack);
            EventCenterManager._Instance.AddListener(EventType.SetPlayerInfo, SetPlayerInfoCallBack);
        }
示例#6
0
 public void UpdateMessage(RoomMessage message)
 {
     roomDic[message.ip]  = message;
     roomTime[message.ip] = DateTime.Now;
 }
示例#7
0
 public static byte[] GetBytes(RoomMessage r)
 {
     return(Encoding.UTF8.GetBytes(r.name + "*" + r.ip));
 }