Exemple #1
0
        public async Task <bool> DeleteFriend(VRCUser user)
        {
            bool onSuccess = await Vrc.FriendsApi.DeleteFriend(user.Id);

            if (onSuccess)
            {
                lock (m_lockUserData)
                {
                    if (m_userIdToIndex.ContainsKey(user.Id))
                    {
                        int index = m_userIdToIndex[user.Id];

                        Users.RemoveAt(index);

                        // Update indices.
                        for (int i = index; i < Users.Count; ++i)
                        {
                            m_userIdToIndex[Users[i].Id] = i;
                        }
                    }
                }
            }


            return(onSuccess);
        }
Exemple #2
0
        private async Task ConvertLocation(VRCUser user)
        {
            string location = user.Location;
            string userId   = user.Id;

            user.InstanceOccupant = "";

            if (location == "offline")
            {
                user.StatusText = "Offline";
            }
            else if (location == "private")
            {
                user.StatusText = "Private";
            }
            else if (location.Contains(':'))
            {
                var loc = location.Split(':');

                if (loc[1] == userId)
                {
                    user.StatusText = "Private";
                }
                else
                {
                    string worldId    = loc[0];
                    string instanceId = loc[1];

                    var world = await m_worldCache.GetWorld(Vrc, worldId);

                    if (world != null)
                    {
                        var instance = await m_worldCache.GetInstance(Vrc, worldId, instanceId);

                        if (instance != null && instance.users != null)
                        {
                            user.StatusText       = world.name;
                            user.InstanceOccupant = string.Format("({0}/{1})", instance.users.Count,
                                                                  world.capacity);

                            // 같은 인스턴스에 있으면서 나랑도 친구인 사람을 목록화.
                            lock (m_lockUserData)
                            {
                                user.FriendsWith = instance.users
                                                   .Where(u => m_userIdToIndex.ContainsKey(u.id) && u.id != userId)
                                                   .Select(u => u.displayName)
                                                   .ToList();
                            }
                        }
                        else
                        {
                            user.StatusText = world.name;
                        }
                    }
                }
            }
        }
Exemple #3
0
        public ProfileWindow(VRChatApi.VRChatApi vrc, VRCUser user)
        {
            InitializeComponent();


            Vm      = (this.DataContext as ProfileVM);
            Vm.Vrc  = vrc;
            Vm.User = user;
        }
Exemple #4
0
 // 최신 정보를 담은 newData의 데이터를 적용.
 // 네트워크에서 지속적으로 받아오는 정보가 아니면 적용하지 않음.
 public void Update(VRCUser newData)
 {
     Name              = newData.Name;
     Location          = newData.Location;
     ImageUrl          = newData.ImageUrl;
     StatusText        = newData.StatusText;
     InstanceOccupant  = newData.InstanceOccupant;
     StatusDescription = newData.StatusDescription;
     FriendsWith       = newData.FriendsWith.ToList(); // Deep copy
     Permission        = newData.Permission;
 }
Exemple #5
0
        public ProfileVM()
        {
            CmdJoin      = new CommandHandler((_) => Join());
            CmdRemoveTag = new CommandHandler((param) => RemoveTag(param as string));


#if DEBUG
            User = new VRCUser()
            {
                Id         = "Test-ID",
                Name       = "TEST NameLongLongHi",
                ImageUrl   = @"http://www.personalbrandingblog.com/wp-content/uploads/2017/08/blank-profile-picture-973460_640-300x300.png",
                Star       = 2,
                Location   = "korea:12345~hidden(123ab)~nonce(123fc)",
                StatusText = "Status TEST Hi ZZfefefefefefefefFafaMamaThx",
                Permission = VRChat_Stalker.UserTags.Trust | VRChat_Stalker.UserTags.Avatar,
                Tags       = new HashSet <string> {
                    "test", "banana", "cookie", "서벌", "타노C", "파세파세호"
                },
                InstanceOccupant = "(22/20)",
            };
#endif
        }
Exemple #6
0
        public async Task <List <VRCUser> > GetFriends(bool isOffline)
        {
            var users = new List <VRCUser>();


            int offset          = 0;
            int retry           = 3;
            int maxFriendsCount = 99;

            while (true)
            {
                List <VRChatApi.Classes.UserBriefResponse> friends = null;

                try
                {
                    friends = await Vrc.FriendsApi.Get(offset, maxFriendsCount, isOffline);
                }
                catch (Exception e)
                {
                    friends = null;

                    Console.Error.WriteLine(e.Message);
                    Console.Error.WriteLine(e.StackTrace);
                }

                if (friends == null)
                {
                    if (retry > 0)
                    {
                        await Task.Delay(1000);

                        retry -= 1;

                        continue;
                    }
                    else
                    {
                        break;
                    }
                }

                foreach (var res in friends)
                {
                    var user = new VRCUser()
                    {
                        Id                = res.id,
                        Name              = res.displayName,
                        Location          = res.location,
                        ImageUrl          = res.currentAvatarThumbnailImageUrl,
                        StatusDescription = res.statusDescription,
                    };

                    foreach (string tag in res.tags)
                    {
                        if (tag.Contains("legend"))
                        {
                            user.Permission |= UserTags.Legend;
                        }
                        else if (tag.Contains("avatar"))
                        {
                            user.Permission |= UserTags.Avatar;
                        }
                        else if (tag.Contains("world"))
                        {
                            user.Permission |= UserTags.World;
                        }
                        else if (tag.Contains("trust"))
                        {
                            user.Permission |= UserTags.Trust;
                        }
                        else if (tag.Contains("troll"))
                        {
                            user.Permission |= UserTags.Troll;
                        }
                    }

                    await ConvertLocation(user);

                    users.Add(user);
                }

                if (friends.Count < maxFriendsCount)
                {
                    break;
                }

                offset += friends.Count;
            }


            return(users);
        }
Exemple #7
0
        private void UpdateUsers(List <VRCUser> onlineUsers)
        {
            var onlineIndices = new List <int>();

            foreach (var user in onlineUsers)
            {
                if (m_userIdToIndex.ContainsKey(user.Id))
                {
                    onlineIndices.Add(m_userIdToIndex[user.Id]);
                }
            }

            onlineIndices.Sort();


            int checkIndex = 0;

            // Check offline.
            for (int i = 0; i < Users.Count; ++i)
            {
                if (checkIndex < onlineIndices.Count &&
                    onlineIndices[checkIndex] == i)
                {
                    ++checkIndex;

                    continue;
                }


                var user = Users[i];

                if (user.Location != "offline")
                {
                    user.Location         = "offline";
                    user.StatusText       = "Offline";
                    user.InstanceOccupant = "";
                    user.FriendsWith.Clear();

                    // Alarm offline.
                    if (user.IsTracked)
                    {
                        OnUserChanged(user.ImageUrl, user.Name, user.StatusText);
                    }
                }
            }

            foreach (var user in onlineUsers)
            {
                VRCUser target      = null;
                int     targetIndex = -1;

                if (m_userIdToIndex.ContainsKey(user.Id))
                {
                    targetIndex = m_userIdToIndex[user.Id];
                    target      = Users[targetIndex];
                }

                if (target == null)
                {
                    m_userIdToIndex[user.Id] = Users.Count;

                    Users.Add(user);

                    // Alarm online.
                    if (user.IsTracked)
                    {
                        OnUserChanged(user.ImageUrl, user.Name, $"Online ({user.StatusText})");
                    }
                }
                else
                {
                    if (target.IsTracked)
                    {
                        if (target.Name != user.Name)
                        {
                            // Alarm name changed.
                            OnUserChanged(user.ImageUrl, user.Name, $"{target.Name} → {user.Name}");
                        }

                        if (target.Status != user.Status)
                        {
                            // Alarm status changed.
                            OnUserChanged(user.ImageUrl, user.Name, user.StatusText);
                        }
                        else if (target.Star >= 2)
                        {
                            if (target.Location != user.Location)
                            {
                                // Alarm location changed.
                                if (string.IsNullOrWhiteSpace(user.InstanceNumber))
                                {
                                    OnUserChanged(user.ImageUrl, user.Name, user.StatusText);
                                }
                                else
                                {
                                    OnUserChanged(user.ImageUrl, user.Name,
                                                  string.Format("{0} {1}", user.StatusText, user.InstanceNumber));
                                }
                            }
                            else if (target.StatusDescription != user.StatusDescription &&
                                     string.IsNullOrWhiteSpace(user.StatusDescription) == false)
                            {
                                // Alarm status description changed.
                                OnUserChanged(user.ImageUrl, user.Name, user.StatusDescription);
                            }
                        }

                        if (target.Star >= 3)
                        {
                            if (target.ImageUrl != user.ImageUrl)
                            {
                                // Alarm image changed.
                                OnUserChanged(user.ImageUrl, user.Name, "Avatar changed");
                            }

                            if (target.Permission != user.Permission)
                            {
                                // Alarm permission changed.
                                OnUserChanged(user.ImageUrl, user.Name, "Permission changed");
                            }


                            var newFriends = new List <string>();

                            foreach (string friend in user.FriendsWith)
                            {
                                if (!target.FriendsWith.Contains(friend))
                                {
                                    newFriends.Add(friend);
                                }
                            }

                            if (newFriends.Count > 0)
                            {
                                var buffer = new StringBuilder("Now with ");

                                foreach (string friend in newFriends.Skip(1))
                                {
                                    buffer.Append(friend);
                                    buffer.Append(", ");
                                }

                                buffer.Append(newFriends.First());

                                // Alarm playmate changed.
                                OnUserChanged(user.ImageUrl, user.Name, buffer.ToString());
                            }
                        }
                    }


                    target.Update(user);
                }
            }
        }