Exemple #1
0
 void HandleRoomListMsg(Message msg)
 {
     LobbyRoomList = new List <LobbyRoom>();
     if (msg.Data.TryGetValue("list", out object roomsObj))
     {
         List <object> rooms = roomsObj as List <object>;
         foreach (Dictionary <string, object> room in rooms)
         {
             var lobbyRoom = LobbyRoom.NewFromDictionary(room);
             LobbyRoomList.Add(lobbyRoom);
         }
     }
     OnLobbyRoomListUpdated?.Invoke(LobbyRoomList);
 }
        internal static LobbyRoom NewFromDictionary(Dictionary <string, object> roomDict)
        {
            LobbyRoom lobbyRoom = new LobbyRoom {
                RoomName = roomDict["cid"] as string
            };

            if (roomDict.TryGetValue("maxMembers", out object maxPlayerCountObj) &&
                int.TryParse(maxPlayerCountObj.ToString(), out int maxPlayerCount))
            {
                lobbyRoom.MaxPlayerCount = maxPlayerCount;
            }
            if (roomDict.TryGetValue("expectMembers", out object expectedsObj))
            {
                lobbyRoom.ExpectedUserIds = (expectedsObj as List <object>).Cast <string>().ToList();
            }
            if (roomDict.TryGetValue("emptyRoomTtl", out object roomTtlObj) &&
                int.TryParse(roomTtlObj.ToString(), out int emptyRoomTtl))
            {
                lobbyRoom.EmptyRoomTtl = emptyRoomTtl;
            }
            if (roomDict.TryGetValue("playerTtl", out object playerTtlObj) &&
                int.TryParse(playerTtlObj.ToString(), out int playerTtl))
            {
                lobbyRoom.PlayerTtl = playerTtl;
            }
            if (roomDict.TryGetValue("playerCount", out object playerCountObj) &&
                int.TryParse(playerCountObj.ToString(), out int playerCount))
            {
                lobbyRoom.PlayerCount = playerCount;
            }
            if (roomDict.TryGetValue("attr", out object propsObj))
            {
                lobbyRoom.CustomRoomProperties = propsObj as Dictionary <string, object>;
            }
            if (roomDict.TryGetValue("open", out object openObj) &&
                bool.TryParse(openObj.ToString(), out bool opened))
            {
                lobbyRoom.Opened = opened;
            }
            if (roomDict.TryGetValue("visible", out object visibleObj) &&
                bool.TryParse(visibleObj.ToString(), out bool visible))
            {
                lobbyRoom.Visible = visible;
            }
            return(lobbyRoom);
        }
Exemple #3
0
        LobbyRoom ConvertToLobbyRoom(Protocol.RoomOptions options)
        {
            var lobbyRoom = new LobbyRoom {
                RoomName       = options.Cid,
                Open           = options.Open == null || options.Open.Value,
                Visible        = options.Visible == null || options.Visible.Value,
                MaxPlayerCount = options.MaxMembers,
                PlayerCount    = options.MemberCount,
                EmptyRoomTtl   = options.EmptyRoomTtl,
                PlayerTtl      = options.PlayerTtl
            };

            if (options.ExpectMembers != null)
            {
                lobbyRoom.ExpectedUserIds = options.ExpectMembers.ToList <string>();
            }
            if (options.Attr != null)
            {
                lobbyRoom.CustomRoomProperties = CodecUtils.DeserializePlayObject(options.Attr);
            }
            return(lobbyRoom);
        }