Пример #1
0
    // =========================================================================================================================
    // === debug ===============================================================================================================
#if UNITY_EDITOR
    void Debug_GenerateRandomFriends(bool inActive)
    {
        if (inActive == true)
        {
            m_Friends.Clear();
            for (int i = 0; i < 10; i++)
            {
                FriendInfo friend = new FriendInfo();
                friend.PrimaryKey = MFDebugUtils.GetRandomString(Random.Range(5, 12));
                //friend.m_Level        = Random.Range(1,20);
                //friend.m_Missions	= Random.Range(0,200);
                friend.LastOnlineDate = 0;                 //MiscUtils.RandomValue( new string[] {"unknown", "yesterday", "tomorrow"});
                m_Friends.Add(friend);
            }
        }
        else
        {
            m_PendingFriends.Clear();
            for (int i = 0; i < 10; i++)
            {
                PendingFriendInfo friend = new PendingFriendInfo();
                friend.PrimaryKey = MFDebugUtils.GetRandomString(Random.Range(5, 12));
                friend.AddedDate  = GuiBaseUtils.DateToEpoch(CloudDateTime.UtcNow);

                if (Random.Range(0, 2) == 0)
                {
                    // create dummy message, for testing gui behavior...
                    friend.CloudCommand = MFDebugUtils.GetRandomString(Random.Range(512, 512));
                }

                m_PendingFriends.Add(friend);
            }
        }
    }
Пример #2
0
    //..........................................................................................................................
    public void ProcessMessage(CloudMailbox.BaseMessage inMessage)
    {
        // add into pending friends..
        CloudMailbox.FriendRequest req = inMessage as CloudMailbox.FriendRequest;
        if (req != null)
        {
            FriendInfo fInfo = m_Friends.Find(f => f.PrimaryKey == inMessage.m_Sender);
            if (fInfo != null)
            {
                //Debug.Log("User with name " + inMessage.m_Sender + " is already your friend");
                return;
            }

            List <PendingFriendInfo> pfInfo = m_PendingFriends.FindAll(f => f.PrimaryKey == inMessage.m_Sender);
            if (pfInfo != null && pfInfo.Count > 0)
            {
                foreach (PendingFriendInfo p in pfInfo)
                {
                    if (p != null && p.IsItRequest == true)
                    {
                        //Debug.Log("Request from this person is already in pending list");
                        return;
                    }
                }
            }

            PendingFriendInfo friend = new PendingFriendInfo();
            friend.PrimaryKey   = req.m_Sender;
            friend.Nickname     = req.m_NickName;
            friend.Username_New = req.m_Username;
            friend.AddedDate    = GuiBaseUtils.DateToEpoch(inMessage.m_SendTime);
            friend.Message      = inMessage.m_Message;
            friend.CloudCommand = req.m_ConfirmCommand;

            m_PendingFriends.Add(friend);
            OnPendingFriendListChanged();
            Save();
            return;
        }

        CloudMailbox.FriendRequestReject reject = inMessage as CloudMailbox.FriendRequestReject;
        if (reject != null)
        {
            // remove this friend from pending list if it is still there.
            List <PendingFriendInfo> pfInfo = m_PendingFriends.FindAll(friend => friend.PrimaryKey == inMessage.m_Sender);
            if (pfInfo != null && pfInfo.Count > 0)
            {
                foreach (PendingFriendInfo p in pfInfo)
                {
                    m_PendingFriends.Remove(p);
                }
            }

            OnPendingFriendListChanged();
            Save();
            return;
        }

        Debug.LogError("Unknown message " + inMessage + " " + inMessage.msgType);
    }
Пример #3
0
    //..........................................................................................................................
    public bool AddNewFriend(string inPrimaryKey, string inUsername, string inNickName, string inMessage)
    {
        // check preconditions...
        if (CloudUser.instance.isUserAuthenticated == false)
        {
            Debug.LogError("user is not authenticated, can't fetch friends list");
            return(false);
        }

        FriendInfo fInfo = m_Friends.Find(f => f.PrimaryKey == inPrimaryKey);

        if (fInfo != null)
        {
            //Debug.Log("User with name " + inFriendName + " is already your friend");
            return(false);
        }

        PendingFriendInfo pfInfo = m_PendingFriends.Find(f => f.PrimaryKey == inPrimaryKey);

        if (pfInfo != null)
        {
            //Debug.Log("User with name " + inFriendName + " is already in pending friend list");
            return(false);
        }

        if (string.IsNullOrEmpty(inMessage) == true)
        {
            inMessage = string.Format(TextDatabase.instance[02040236], CloudUser.instance.nickName);
        }

        // create message object...
        CloudMailbox.FriendRequest msg = new CloudMailbox.FriendRequest();
        msg.m_TargetSystem = "Game.FriendList";
        msg.m_Mailbox      = CloudMailbox.E_Mailbox.Global;
        msg.m_Sender       = CloudUser.instance.primaryKey;
        msg.m_Username     = CloudUser.instance.userName_TODO;
        msg.m_NickName     = CloudUser.instance.nickName;
        msg.m_Message      = inMessage;    // this will not be shown...

        //GameCloudManager.mailbox.SendMessage(m_FriendName, msg);
        GameCloudManager.mailbox.SendMessage(inPrimaryKey, msg);

        // add into pending friends...
        PendingFriendInfo friend = new PendingFriendInfo();

        friend.PrimaryKey   = inPrimaryKey;
        friend.Username_New = inUsername;
        friend.Nickname     = inNickName;
        friend.AddedDate    = GuiBaseUtils.DateToEpoch(CloudDateTime.UtcNow);
        m_PendingFriends.Add(friend);
        OnPendingFriendListChanged();
        Save();

        return(true);
    }
Пример #4
0
    public void MarkLastFinishedGame(bool winner)
    {
        PlayerData.Stats.Today.GamesFinished += 1;
        PlayerData.Stats.Today.GamesWon      += winner ? 1 : 0;

        int gameType = (int)Game.GetMultiplayerGameType();

        PPIPlayerStats.GameData gameData = PlayerData.Stats.Games[gameType];
        gameData.LastFinishedGameDate    = GuiBaseUtils.DateToEpoch(CloudDateTime.UtcNow);
        PlayerData.Stats.Games[gameType] = gameData;
        PlayerDataChanged = true;
    }
Пример #5
0
 public static Message Create(string primaryKey, string nickname, int rank, string text)
 {
     return(new Chat.Message()
     {
         Id = System.Guid.NewGuid().ToString(),
         Date = GuiBaseUtils.DateToEpoch(CloudDateTime.UtcNow),
         PrimaryKey = primaryKey,
         Nickname = nickname,
         Rank = rank,
         Text = text
     });
 }
Пример #6
0
    void OnOnlineStatusRequest(LobbyClient.PlayerStatusMultiRequest request)
    {
        if (request.HasSucceeded == true)
        {
            foreach (var friend in m_Friends)
            {
                LobbyClient.PlayerStatus status = request.GetPlayerStatus(friend.PrimaryKey);
                if (status == null || status.IsOnline == false)
                {
                    friend.OnlineStatus = E_OnlineStatus.Offline;
                }
                else
                {
                    friend.OnlineStatus   = status.IsInGame == true ? E_OnlineStatus.InGame : E_OnlineStatus.InLobby;
                    friend.LastOnlineDate = GuiBaseUtils.DateToEpoch(CloudDateTime.UtcNow);
                }
            }

            OnFriendListChanged();
        }

        Invoke("CreateOnlineStatusRequest", ONLINE_STATUS_FREQUENCY);
    }