Beispiel #1
0
        // called when web request fails
        public void UpdateNameOnFail(ulong steamId)
        {
            // we still want to update the players name even if it fails.
            var networkUser = Util.Networking.GetNetworkUserFromSteamId(steamId);

            if (networkUser != null)
            {
                SyncNetworkUserVarTest(networkUser, _addConnectionIdToName.Value);

                OnUsernameUpdated?.Invoke();
            }
        }
Beispiel #2
0
        public void UpdateName(string name, ulong steamId)
        {
            var networkUser = Util.Networking.GetNetworkUserFromSteamId(steamId);

            if (networkUser != null)
            {
                Logger.LogInfo($"New player : {name} connected. (STEAM:{steamId})");
                networkUser.userName = name;

                // Sync with other players by forcing dirty syncVar ?
                SyncNetworkUserVarTest(networkUser, _addConnectionIdToName.Value);

                OnUsernameUpdated?.Invoke();
            }
        }
Beispiel #3
0
 /// <summary>
 /// Constructs a game user
 /// </summary>
 /// <param name="serverUser">Server user</param>
 public AGameUser(IServerUser serverUser)
 {
     if (serverUser == null)
     {
         throw new ArgumentNullException(nameof(serverUser));
     }
     if (!serverUser.IsValid)
     {
         throw new ArgumentException("Server user is not valid.", nameof(serverUser));
     }
     ServerUser = serverUser;
     serverUser.OnUsernameUpdated       += () => OnUsernameUpdated?.Invoke();
     serverUser.OnUserLobbyColorUpdated += () => OnUserLobbyColorUpdated?.Invoke();
     serverUser.OnGameLoadingFinished   += () => OnGameLoadingFinished?.Invoke();
     serverUser.OnClientTicked          += (entityDeltas, hits) => OnClientTicked?.Invoke(entityDeltas, hits);
     serverUser.OnServerTicked          += (time, entityDeltas, hits) => OnServerTicked?.Invoke(time, entityDeltas, hits);
 }
Beispiel #4
0
 /// <summary>
 /// Updates username
 /// </summary>
 /// <param name="name">Username</param>
 public void UpdateUsername(string name)
 {
     SetNameInternally(name);
     OnUsernameUpdated?.Invoke();
     ServerLobby.SendUsernameChangedMessage(this);
 }
Beispiel #5
0
        private IEnumerator WebRequestCoroutine(ulong steamId)
        {
            const string regexForLookUp      = "<dd class=\"value\"><a href=\"(.*?)\"";
            const string regexForPersonaName = "\"personaname\":\"(.*?)\"";

            var ioUrlRequest = "https://steamid.io/lookup/" + steamId;

            var webRequest = UnityWebRequest.Get(ioUrlRequest);

            yield return(webRequest.SendWebRequest());

            if (!webRequest.isNetworkError)
            {
                var rx = new Regex(regexForLookUp,
                                   RegexOptions.Compiled | RegexOptions.IgnoreCase);

                var steamProfileUrl = rx.Match(webRequest.downloadHandler.text).Groups[1].ToString();

                webRequest = UnityWebRequest.Get(steamProfileUrl);

                yield return(webRequest.SendWebRequest());

                if (!webRequest.isNetworkError)
                {
                    rx = new Regex(regexForPersonaName,
                                   RegexOptions.Compiled | RegexOptions.IgnoreCase);

                    var nameFromRegex = rx.Match(webRequest.downloadHandler.text).Groups[1].ToString();

                    if (!nameFromRegex.Equals(""))
                    {
                        var gotBlackListed = false;

                        if (_enableBlackListRichNames.Value)
                        {
                            var blackList = _blackListRichNames.Value.Split(',');

                            foreach (var tag in blackList)
                            {
                                var bannedTag = "&lt;" + tag + "=";
                                if (nameFromRegex.Contains(bannedTag))
                                {
                                    var userToKick = Util.Networking.GetNetworkUserFromSteamId(steamId);
                                    var playerId   = Util.Networking.GetPlayerIndexFromNetworkUser(userToKick);

                                    Console.instance.SubmitCmd(null, $"kick {playerId}");
                                    gotBlackListed = true;
                                }
                            }
                        }

                        if (!UsernamesCache.ContainsKey(steamId) && !gotBlackListed)
                        {
                            UsernamesCache.Add(steamId, nameFromRegex);

                            var networkUser = Util.Networking.GetNetworkUserFromSteamId(steamId);
                            if (networkUser != null)
                            {
                                Logger.LogInfo($"New player : {nameFromRegex} connected. (STEAM:{steamId})");
                                networkUser.userName = nameFromRegex;

                                // Sync with other players by forcing dirty syncVar ?
                                SyncNetworkUserVarTest(networkUser);

                                OnUsernameUpdated?.Invoke();
                            }
                        }
                    }
                }
            }

            webRequest.Dispose();
        }
 /// <summary>
 /// Invokes the username updated event
 /// </summary>
 public void InvokeUsernameUpdatedEvent() => OnUsernameUpdated?.Invoke();