private void MarkAsMuted(PgUser user)
 {
     if (IsMutedInThisGameRoom(user) == false)
        MutedMembersIds.Add(user.Id);
        if (user.Id == _userData.User.Id)
        IsMuted = true;
 }
 private void MarkAsUnmuted(PgUser user)
 {
     if (IsMutedInThisGameRoom(user) == true)
        MutedMembersIds.Remove(user.Id);
        if (user.Id == _userData.User.Id)
        IsMuted = false;
 }
 public void RemoveUserFromTeam(PgUser user, PgTeam team)
 {
     if ((user.Team == null) || (team == null) || (team.Temporarily == false))
         return;
     var url = _userData.PgSession.GetWebAppFunction("/api", "/users/" + user.Id + "/remove_from_team", "team_id=" + team.Id);
     var client = new RestSharp.RestClient(url);
     var request = new RestSharp.RestRequest(RestSharp.Method.GET) { RequestFormat = RestSharp.DataFormat.Json };
     RestSharp.RestResponse<PgTeam> response = (RestSharp.RestResponse<PgTeam>)client.Execute<PgTeam>(request);
     if (response.IsOk() == true)
     {
         user.Team = response.Data;
     }
 }
 private void LoadTeamBot()
 {
     var url = UserDataManager.UserData.PgSession.GetWebAppFunction("/api", "/game_rooms/" + this._session.GameRoom.Id + "/team_bot");
     var client = new RestSharp.RestClient(url);
     var request = new RestSharp.RestRequest(RestSharp.Method.GET) { RequestFormat = RestSharp.DataFormat.Json };
     RestSharp.RestResponse response = (RestSharp.RestResponse)client.Execute(request);
     var result = Newtonsoft.Json.Linq.JObject.Parse(response.Content);
     if (((Newtonsoft.Json.Linq.JProperty)result.First).Name != "errors")
     {
         var teamBot = new PgUser();
         var name = ((Newtonsoft.Json.Linq.JProperty)result.First).Value.ToString();
         var team = new PgTeam();
         team.Name = GameRoomWindowModelView.TeamBotGroupName;
         teamBot.Id = "bot_" + name;
         teamBot.Username = name;
         teamBot.Points = Convert.ToInt32(((Newtonsoft.Json.Linq.JProperty)result.First.Next).Value.ToString());
         teamBot.Team = team;
         _session.GameRoom.TeamBot = teamBot;
         _session.GameRoom.IsTeamBotPlaced = true;
     }
     else
         _session.GameRoom.IsTeamBotPlaced = false;
 }
 private void RefreshAdminsList(GameRoomAdminDialog dialog, GameRoomAdminDialogModelView modelView)
 {
     var adminsCollection = dialog.adminsListBox.Items;
     PgUser[] admins = new PgUser[adminsCollection.Count];
     for (int i = 0; i < admins.Length; i++)
         admins[i] = (PgUser)adminsCollection[i];
     modelView.Admins = admins;
 }
 public void AddFriend(PgUser friend)
 {
     friend.IsFriend = true;
     if (!_friendLookup.ContainsKey(friend.Id))
     {
         Friends.Add(friend);
         _friendLookup[friend.Id] = friend;
     }
 }
 public bool TryGetFriend(string id, out PgUser friend)
 {
     return _friendLookup.TryGetValue(id, out friend);
 }
 public void LeavePrivateChat(PgUser other)
 {
     _privateChats.Remove(other);
 }
 public ContextMenuRights(PgUser user)
 {
     User = user;
 }
 public void RemoveFriend(PgUser friend)
 {
     friend.IsFriend = false;
     if (_friendLookup.Remove(friend.Id))
         Friends.Remove(friend);
 }
        public PgUser GetPgUser(UserBase userBase)
        {
            PgUser user;
            lock (_userLookup)
            {
                if (_userLookup.TryGetValue(userBase._id, out user))
                    return user;

                user = new PgUser
                {
                    Id = userBase._id,
                    Username = userBase.username ?? "unknown",
                    Status = "unknown",
                };

                _userLookup[userBase._id] = user;
            }
            LookupUserData(userBase._id);
            return user;
        }
 public void CreateChatroomWith(PgUser a, PgUser b)
 {
     Guid g = Guid.NewGuid();
     var id = "client_" + g.ToString().Replace("-", "");
     _sessionManager.JoinChatroom(id);
     _sessionManager.SendChatroomInvite(new ChatroomInviteOut { _id = id, toUser = a.ToUserBase(), });
     _sessionManager.SendChatroomInvite(new ChatroomInviteOut { _id = id, toUser = b.ToUserBase(), });
 }
 public void ChatWith(PgUser friend)
 {
     if (friend == User)
         return;
     _sessionManager.ChatWith(friend);
 }
 private void SynchronizeMembersList()
 {
     PgUser[] newList = new PgUser[Membership.Count];
     int i = 0;
     foreach (var item in Membership)
         if (((PgUser)item).GameRoomGroupName != "Team Bot")
         {
             PgUser user = (PgUser)item;
             user = UpdateMemberInfo(user);
             newList[i++] = user;
         }
     this._session.GameRoom.Members = newList;
 }
 public bool IsMutedInThisGameRoom(PgUser user)
 {
     foreach (var item in MutedMembersIds)
        if (item == user.Id)
            return true;
        return false;
 }
        private PgUser UpdateMemberInfo(PgUser member)
        {
            var url = _userData.PgSession.GetWebAppFunction("/api", "/game_rooms/" + this._session.GameRoomId  + "/get_member_info", "user_id=" + member.Id);
            var client = new RestSharp.RestClient(url);
            var request = new RestSharp.RestRequest(RestSharp.Method.GET);
            RestSharp.RestResponse<PgUser> response = (RestSharp.RestResponse<PgUser>)client.Execute<PgUser>(request);

            member = response.Data;
            if (response.Data.IsMuted == true)
                MarkAsMuted(member);
            else
                MarkAsUnmuted(member);

            return member;
        }
 public void OnVoiceStarted(PgUser user)
 {
     user.SpeakingRoomId = AudioRoomId;
 }
        private ChatSessionBase GetOrCreatePrivateChatSession(PgUser user)
        {
            ChatSessionBase chat;
            if (_privateChats.TryGetValue(user, out chat))
                return chat;

            var session = new PrivateChatSession(this, user);
            _privateChats[user] = session;
            session.ShowControl(false);
            return session;
        }
 public void OnVoiceStopped(PgUser user)
 {
     if (user.SpeakingRoomId == AudioRoomId)
         user.SpeakingRoomId = null;
 }
 public void ChatWith(PgUser friend)
 {
     ChatSessionBase chatSession = GetOrCreatePrivateChatSession(friend);
     chatSession.ShowControl(true);
 }
        public UserDataManager(SocketSession session)
        {
            UserData = this;
            Settings = PointGaming.Settings.SettingsUser.Load(session.User.username);
            PgSession = session;
            User = GetPgUser(session.User);
            User.Status = "online";
            _sessionManager = new SessionManager();
            Friendship = new FriendshipManager(PgSession);
            Voip = new VoipSession(this);
            Voip.Enable();

            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(5);
            timer.Tick += new EventHandler(CheckIdle);
            timer.Start();
        }