Exemple #1
0
 public TurnBasedMatch(string kind, string matchId, string applicationId, string variant, string status,
                       string userMatchStatus, List <TurnBasedMatchParticipant> participants,
                       TurnBasedMatchModification creationDetails, TurnBasedMatchModification lastUpdateDetails,
                       TurnBasedAutoMatchingCriteria autoMatchingCriteria, TurnBasedMatchData data, ParticipantResult results,
                       string inviterId, string withParticipantId, string description, string pendingParticipantId, string matchVersion,
                       string rematchId, string matchNumber, TurnBasedMatchData previousMatchData)
 {
     Kind                 = kind;
     MatchId              = matchId;
     ApplicationId        = applicationId;
     Variant              = variant;
     Status               = status;
     UserMatchStatus      = userMatchStatus;
     Participants         = participants;
     CreationDetails      = creationDetails;
     LastUpdateDetails    = lastUpdateDetails;
     AutoMatchingCriteria = autoMatchingCriteria;
     Data                 = data;
     Results              = results;
     InviterId            = inviterId;
     WithParticipantId    = withParticipantId;
     Description          = description;
     PendingParticipantId = pendingParticipantId;
     MatchVersion         = matchVersion;
     RematchId            = rematchId;
     MatchNumber          = matchNumber;
     PreviousMatchData    = previousMatchData;
 }
Exemple #2
0
    private TurnBasedMatch ParseMatch(string results)
    {
        string matchKind       = "";
        string id              = "";
        string applicationId   = "";
        string variant         = "";
        string status          = "";
        string userMatchStatus = "";
        List <TurnBasedMatchParticipant> ppp = new List <TurnBasedMatchParticipant>();

        string creationDetailsKind                    = "";
        string creationDetailsParticipantId           = "";
        long   creationDetailsModifiedTimestampMillis = 0;
        TurnBasedMatchModification creationDetails    = new TurnBasedMatchModification(creationDetailsKind, creationDetailsParticipantId,
                                                                                       creationDetailsModifiedTimestampMillis);
        string lastUpdateDetailsKind                 = "";
        string lastUpdateParticipantId               = "";
        long   lastUpdateModifiedTimestampMillis     = 0;
        TurnBasedMatchModification lastUpdateDetails = new TurnBasedMatchModification(lastUpdateDetailsKind, lastUpdateParticipantId,
                                                                                      lastUpdateModifiedTimestampMillis);
        string autoMatchingCriteriaKind = "";
        int    autoMatchingCriteriaMinAutoMatchingPlayers  = 0;
        int    autoMatchingCriteriaMaxAutoMatchingPlayers  = 0;
        int    autoMatchingCriteriaExclusiveBitmask        = 0;
        TurnBasedAutoMatchingCriteria autoMatchingCriteria = new TurnBasedAutoMatchingCriteria(autoMatchingCriteriaKind,
                                                                                               autoMatchingCriteriaMinAutoMatchingPlayers,
                                                                                               autoMatchingCriteriaMaxAutoMatchingPlayers,
                                                                                               autoMatchingCriteriaExclusiveBitmask);
        string dataKind                      = "";
        bool   dataDataAvailable             = false;
        TurnBasedMatchDataStructure dataData = new TurnBasedMatchDataStructure(null);
        TurnBasedMatchData          data     = new TurnBasedMatchData(dataKind, dataDataAvailable, dataData);

        string            myResultsKind          = "";
        string            myResultsParticipantId = "";
        string            myResultsResult        = "";
        string            myResultsPlacing       = "";
        ParticipantResult myResults            = new ParticipantResult(myResultsKind, myResultsParticipantId, myResultsResult, myResultsPlacing);
        string            inviterId            = "";
        string            withParticipantId    = "";
        string            description          = "";
        string            pendingParticipantId = "";
        string            matchVersion         = "";
        string            rematchId            = "";
        string            matchNumber          = "";

        string previousMatchDataKind                      = "";
        bool   previousMatchDataDataAvailable             = false;
        TurnBasedMatchDataStructure previousMatchDataData = new TurnBasedMatchDataStructure(null);
        TurnBasedMatchData          previousMatchData     = new TurnBasedMatchData(previousMatchDataKind, previousMatchDataDataAvailable,
                                                                                   previousMatchDataData);

        Dictionary <string, System.Object> resp = MiniJSON.Json.Deserialize(results) as Dictionary <string, System.Object>;

        System.Object ooo;
        resp.TryGetValue("match", out ooo);
        Dictionary <string, System.Object> ddd = (Dictionary <string, System.Object>)ooo;

        Debug.Log(ddd.ToString());
        foreach (KeyValuePair <string, System.Object> matchData in ddd)
        {
            if (matchData.Key == "kind")
            {
                if (matchData.Value != null)
                {
                    matchKind = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "matchId")
            {
                if (matchData.Value != null)
                {
                    id = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "applicationId")
            {
                if (matchData.Value != null)
                {
                    applicationId = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "variant")
            {
                if (matchData.Value != null)
                {
                    variant = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "status")
            {
                if (matchData.Value != null)
                {
                    status = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "userMatchStatus")
            {
                if (matchData.Value != null)
                {
                    userMatchStatus = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "participants")
            {
                ppp = new List <TurnBasedMatchParticipant>();

                List <System.Object> participants = new List <System.Object>();              // = matchData.Value as List<System.Object>;
                if (matchData.Value != null)
                {
                    participants = matchData.Value as List <System.Object>;
                }
                foreach (System.Object o in participants)
                {
                    Dictionary <string, System.Object> participantData = (Dictionary <string, System.Object>)o;
                    System.Object v;
                    participantData.TryGetValue("id", out v);
                    string playerId = "";
                    if (v != null)
                    {
                        playerId = (string)v;
                    }

                    participantData.TryGetValue("kind", out v);
                    string k = "";
                    if (v != null)
                    {
                        k = (string)v;
                    }

                    participantData.TryGetValue("autoMatched", out v);
                    bool autoMatched = false;
                    if (v != null)
                    {
                        autoMatched = bool.Parse((string)v);
                    }

                    participantData.TryGetValue("status", out v);
                    string playerStatus = "";
                    if (v != null)
                    {
                        playerStatus = (string)v;
                    }

                    participantData.TryGetValue("player", out v);
                    Dictionary <string, System.Object> playerD = new Dictionary <string, System.Object>();                  // = (Dictionary<string, System.Object>) v;
                    if (v != null)
                    {
                        playerD = (Dictionary <string, System.Object>)v;
                    }

                    string kind           = "";
                    string participantId  = "";
                    string avatarImageUrl = "";
                    foreach (KeyValuePair <string, System.Object> playerData in playerD)
                    {
                        if (playerData.Key == "kind")
                        {
                            if (playerData.Value != null)
                            {
                                kind = (string)playerData.Value;
                            }
                        }
                        else if (playerData.Key == "participantId")
                        {
                            if (playerData.Value != null)
                            {
                                participantId = (string)playerData.Value;
                            }
                        }
                        else if (playerData.Key == "avatarImageUrl")
                        {
                            if (playerData.Value != null)
                            {
                                avatarImageUrl = (string)playerData.Value;
                            }
                        }
                    }
                    Player player = new Player("player", participantId, avatarImageUrl);
                    TurnBasedMatchParticipant p = new TurnBasedMatchParticipant(k, playerId, player, autoMatched, playerStatus);
                    ppp.Add(p);
                }
            }
            else if (matchData.Key == "creationDetails")
            {
                string kind                    = "";
                string participantId           = "";
                long   modifiedTimestampMillis = 0;

                Dictionary <string, System.Object> details = new Dictionary <string, System.Object>();              // = matchData.Value as Dictionary<string, System.Object>;

                if (matchData.Value != null)
                {
                    details = matchData.Value as Dictionary <string, System.Object>;
                }

                foreach (KeyValuePair <string, System.Object> p in details)
                {
                    if (p.Key == "kind")
                    {
                        if (p.Value != null)
                        {
                            kind = (string)p.Value;
                        }
                    }
                    else if (p.Key == "participantId")
                    {
                        if (p.Value != null)
                        {
                            participantId = (string)p.Value;
                        }
                    }
                    else if (p.Key == "modifiedTimeStampMillis")
                    {
                        if (p.Value != null)
                        {
                            modifiedTimestampMillis = (long)p.Value;
                        }
                    }
                }
                creationDetails = new TurnBasedMatchModification(kind, participantId, modifiedTimestampMillis);
            }
            else if (matchData.Key == "lastUpdateDetails")
            {
                string kind                    = "";
                string participantId           = "";
                long   modifiedTimestampMillis = 0;

                Dictionary <string, System.Object> details = new Dictionary <string, System.Object>();              // = matchData.Value as Dictionary<string, System.Object>;
                if (matchData.Value != null)
                {
                    details = matchData.Value as Dictionary <string, System.Object>;
                }

                foreach (KeyValuePair <string, System.Object> p in details)
                {
                    if (p.Key == "kind")
                    {
                        if (p.Value != null)
                        {
                            kind = (string)p.Value;
                        }
                    }
                    else if (p.Key == "participantId")
                    {
                        if (p.Value != null)
                        {
                            participantId = (string)p.Value;
                        }
                    }
                    else if (p.Key == "modifiedTimeStampMillis")
                    {
                        if (p.Value != null)
                        {
                            modifiedTimestampMillis = (long)p.Value;
                        }
                    }
                }
                lastUpdateDetails = new TurnBasedMatchModification(kind, participantId, modifiedTimestampMillis);
            }
            else if (matchData.Key == "autoMatchingCriteria")
            {
                string kind = "";
                int    minAutoMatchingPlayers = 0;
                int    maxAutoMatchingPlayers = 0;
                int    exclusiveBitmask       = 0;

                Dictionary <string, System.Object> criteria = new Dictionary <string, System.Object>();              // = matchData.Value as Dictionary<string, System.Object>;
                if (matchData.Value != null)
                {
                    criteria = matchData.Value as Dictionary <string, System.Object>;
                }
                foreach (KeyValuePair <string, System.Object> p in criteria)
                {
                    if (p.Key == "kind")
                    {
                        if (String.Compare((string)p.Value, "\"null\"") == 0)
                        {
                            kind = (string)p.Value;
                        }
                    }
                    else if (p.Key == "minAutoMatchingPlayers")
                    {
                        if (String.Compare((string)p.Value, "\"null\"") == 0)
                        {
                            minAutoMatchingPlayers = int.Parse((string)p.Value);
                        }
                    }
                    else if (p.Key == "maxAutoMatchingPlayers")
                    {
                        if (String.Compare((string)p.Value, "\"null\"") == 0)
                        {
                            maxAutoMatchingPlayers = int.Parse((string)p.Value);
                        }
                    }
                    else if (p.Key == "exclusiveBitmask")
                    {
                        if (String.Compare((string)p.Value, "\"null\"") == 0)
                        {
                            exclusiveBitmask = int.Parse((string)p.Value);
                        }
                    }
                }
                autoMatchingCriteria = new TurnBasedAutoMatchingCriteria(kind, minAutoMatchingPlayers, maxAutoMatchingPlayers,
                                                                         exclusiveBitmask);
            }
            else if (matchData.Key == "data")
            {
                string kind          = "";
                bool   dataAvailable = false;
                TurnBasedMatchDataStructure theData = new TurnBasedMatchDataStructure(null);

                if (matchData.Value != null)
                {
                    Dictionary <string, System.Object> d = matchData.Value as Dictionary <string, System.Object>;

                    foreach (KeyValuePair <string, System.Object> p in d)
                    {
                        if (p.Key == "kind")
                        {
                            if (String.Compare((string)p.Value, "\"null\"") == 0)
                            {
                                kind = (string)p.Value;
                            }
                        }
                        else if (p.Key == "dataAvailable")
                        {
                            if (String.Compare((string)p.Value, "\"null\"") == 0)
                            {
                                dataAvailable = bool.Parse((string)p.Value);
                            }
                        }
                        else if (p.Key == "data")
                        {
                            if (p.Value != null)
                            {
                                theData = new TurnBasedMatchDataStructure((Dictionary <string, System.Object>)p.Value);
                            }
                        }
                    }
                }

                data = new TurnBasedMatchData(kind, dataAvailable, theData);
            }
            else if (matchData.Key == "results")
            {
                string kind          = "";
                string participantId = "";
                string result        = "";
                string placing       = "";

                if (matchData.Value != null)
                {
                    List <System.Object> l = matchData.Value as List <System.Object>;
                    if (l != null)
                    {
                        foreach (System.Object o in l)
                        {
                            Dictionary <string, System.Object> d = o as Dictionary <string, System.Object>;
                            if (d != null)
                            {
                                foreach (KeyValuePair <string, System.Object> p in d)
                                {
                                    if (p.Key == "kind")
                                    {
                                        if (p.Value != null)
                                        {
                                            kind = (string)p.Value;
                                        }
                                    }
                                    else if (p.Key == "participantId")
                                    {
                                        if (p.Value != null)
                                        {
                                            participantId = (string)p.Value;
                                        }
                                    }
                                    else if (p.Key == "result")
                                    {
                                        if (p.Value != null)
                                        {
                                            result = (string)p.Value;
                                        }
                                    }
                                    else if (p.Key == "placing")
                                    {
                                        if (p.Value != null)
                                        {
                                            placing = (string)p.Value;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                myResults = new ParticipantResult(kind, participantId, result, placing);
            }
            else if (matchData.Key == "inviterId")
            {
                if (matchData.Value != null)
                {
                    inviterId = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "withParticipantId")
            {
                if (matchData.Value != null)
                {
                    withParticipantId = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "description")
            {
                if (matchData.Value != null)
                {
                    description = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "pendingParticipantId")
            {
                if (matchData.Value != null)
                {
                    pendingParticipantId = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "matchVersion")
            {
                if (matchData.Value != null)
                {
                    matchVersion = matchData.Value.ToString();
                }
            }
            else if (matchData.Key == "rematchId")
            {
                if (matchData.Value != null)
                {
                    rematchId = matchData.Key.ToString();
                }
            }
            else if (matchData.Key == "matchNumber")
            {
                if (matchData.Value != null)
                {
                    matchNumber = matchData.Key.ToString();
                }
            }
            else if (matchData.Key == "previousMatchData")
            {
                string kind          = "";
                bool   dataAvailable = false;
                TurnBasedMatchDataStructure theData = new TurnBasedMatchDataStructure(null);

                Dictionary <string, System.Object> d = new Dictionary <string, System.Object>();              // = matchData.Value as Dictionary<string, System.Object>;
                if (matchData.Value != null)
                {
                    d = matchData.Value as Dictionary <string, System.Object>;
                }
                foreach (KeyValuePair <string, System.Object> p in d)
                {
                    if (p.Key == "kind")
                    {
                        kind = (string)p.Value;
                    }
                    else if (p.Key == "dataAvailable")
                    {
                        dataAvailable = bool.Parse((string)p.Value);
                    }
                    else if (p.Key == "data")
                    {
                        theData = new TurnBasedMatchDataStructure((Dictionary <string, System.Object>)p.Value);
                    }
                }

                previousMatchData = new TurnBasedMatchData(kind, dataAvailable, theData);
            }
        }

        return(new TurnBasedMatch(matchKind, id, applicationId, variant, status, userMatchStatus,
                                  ppp, creationDetails, lastUpdateDetails, autoMatchingCriteria,
                                  data, myResults, inviterId, withParticipantId, description, pendingParticipantId,
                                  matchVersion, rematchId, matchNumber, previousMatchData));
    }