private void SyncUserFriends(Account account)
        {
            string[] friendIds = account.FriendIdentities.ToArray();

            for (int i = friendIds.Length - 1; i >= 0; i--)
            {
                Account friendAccount = new Account
                                            (AccountDatabaseHandler.GetAccountNameFromId(friendIds[i]));

                ClientManager.SendMessageToClientByAccount
                    (account, GetFriendSyncCommand(friendAccount));
            }
        }
        private void HandleFriendRequest_One(string clientId, string[] segments)
        {
            //protocol#|frndrq#|id
            ClientState client = ClientManager.GetClientById(clientId);
            string      idTo   = segments[2];

            string cmd = string.Format("{0}{1}{2}{1}{3}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.FriendRequest),
                                       client.AccountRelative.AccountId);

            if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idTo)))
            {
                ClientManager.SendMessageToClientByAccount
                    (AccountHandler.GetAccountById(idTo), cmd);
            }
        }
        private void HandleFriendAddition_One(string clientId, string[] segments)
        {
            try //protocol#|adfrnd#|id
            {
                string idFrom = ClientManager.GetClientById(clientId).AccountRelative.AccountId;
                string idTo   = segments[2];

                AccountDatabaseHandler.AddFriendRelationship(idFrom, idTo);
                AccountDatabaseHandler.AddFriendRelationship(idTo, idFrom);

                if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idFrom)))
                {
                    AccountHandler.GetAccountById(idFrom).AddFriend(idTo);
                }

                if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idTo)))
                {
                    AccountHandler.GetAccountById(idTo).AddFriend(idFrom);
                }

                string cmd = string.Format("{0}{1}{2}{1}{3}",
                                           (int)ReadProtocol.GetVersion(),
                                           m_SegmentTerminator,
                                           NetworkCommand.GetCommand(NetworkCommandType.AddFriend),
                                           idTo);

                ClientManager.SendMessageToClientByAccount
                    (AccountHandler.GetAccountById(idFrom), cmd);

                cmd = string.Format("{0}{1}{2}{1}{3}",
                                    (int)ReadProtocol.GetVersion(),
                                    m_SegmentTerminator,
                                    NetworkCommand.GetCommand(NetworkCommandType.AddFriend),
                                    idFrom);

                ClientManager.SendMessageToClientByAccount
                    (AccountHandler.GetAccountById(idTo), cmd);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        private void HandleFriendRemoval_One(string clientId, string[] segments)
        {
            //protocol#|rmfrnd#|id
            string idTo   = segments[2];
            string idFrom = ClientManager.GetClientById(clientId).AccountRelative.AccountId;

            AccountDatabaseHandler.RemoveUserRelationships(idFrom, idTo);
            AccountDatabaseHandler.RemoveUserRelationships(idTo, idFrom);

            string cmd = string.Format("{0}{1}{2}{1}{3}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.RemoveFriend),
                                       idFrom);

            if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idTo)))
            {
                ClientManager.SendMessageToClientByAccount(AccountHandler.GetAccountById(idTo), cmd);
            }
        }