Ejemplo n.º 1
0
    /// <summary>
    /// Get the display name of the region.
    /// </summary>
    /// <param name="region">The region to get the name for.</param>
    /// <returns>The name of the region.</returns>
    public string GetName(NobleConnect.GeographicRegion region)
    {
        for (int i = 0; i < regionNames.Length; i++)
        {
            if (regionNames[i].region == region)
            {
                return(regionNames[i].name);
            }
        }

        Debug.LogError("Could not find region in geographicregiondict: " + region);
        return(default);
Ejemplo n.º 2
0
    /// <summary>
    /// Inits all values.
    /// </summary>
    /// <param name="match">The match to which to be connected to.</param>
    /// <param name="serverConnect">A reference to the server connect.</param>
    /// <returns>Wheter it successeded or not.</returns>
    public bool Set(Match match, ServerConnect serverConnect)
    {
        if (match.matchData.TryGetValue("Match name", out MatchData nameData) == false ||
            match.matchData.TryGetValue("Max players", out MatchData playersData) == false ||
            match.matchData.TryGetValue("Connected players", out MatchData connectedData) == false ||
            match.matchData.TryGetValue("Region", out MatchData regionData) == false ||
            match.matchData.TryGetValue("Password protected", out MatchData passwordData) == false)
        {
            return(false);
        }

        if (nameData.valueType != MatchData.ValueType.STRING ||
            playersData.valueType != MatchData.ValueType.INT ||
            connectedData.valueType != MatchData.ValueType.INT ||
            regionData.valueType != MatchData.ValueType.INT ||
            passwordData.valueType != MatchData.ValueType.INT)
        {
            return(false);
        }

        matchName = nameData.stringValue;
        if (matchName.Length > 20)
        {
            matchName = matchName.Substring(0, 20);
        }

        connected  = connectedData.intValue;
        maxPlayers = playersData.intValue;

        if (connected < 1 || connected >= maxPlayers || maxPlayers > 4)
        {
            return(false);
        }

        isPasswordProtected = passwordData.intValue != 0;

        int regionVal = regionData.intValue;

        if (regionVal < 1 || regionVal > 7)
        {
            return(false);
        }

        NobleConnect.GeographicRegion geoRegion = (NobleConnect.GeographicRegion)regionVal;
        regionString = GeographicRegionDict.Instance.GetName(geoRegion);
        if (regionString == default)
        {
            return(false);
        }

        gameName.text = matchName;
        Color passwordColor = passwordProtected.color;

        passwordColor.a         = isPasswordProtected ? 1 : 0;
        passwordProtected.color = passwordColor;
        region.text             = regionString;
        playercount.text        = connected + "/" + maxPlayers;

        this.serverConnect = serverConnect;
        this.match         = match;

        return(true);
    }