Example #1
0
        private static void UploadFailed(HighScore score, string leaderboard, HighScoreType type)
        {
#if DEBUG
            Console.WriteLine($"Uploading Failed. Adding to Scores to send");
#endif
            //make sure that we dont have the score in the list already

            NEX_Category?category = CategoryHelper.GetCategory(leaderboard);
            if (category == null)
            {
                throw new Exception("Category does not exits!");
            }

            int index = -1;
            if (type == HighScoreType.Score)
            {
                index = _scoresToSend.FindIndex(x => x.Leaderboard == leaderboard && x.Score.Principal_ID == score.Principal_ID &&
                                                x.Score.Nex_Unique_ID == score.Nex_Unique_ID && x.Score.Score == score.Score);
            }
            else
            {
                index = _scoresToSend.FindIndex(x => x.Leaderboard == leaderboard && x.Score.Principal_ID == score.Principal_ID &&
                                                x.Score.Nex_Unique_ID == score.Nex_Unique_ID); // && x.Score.CommonUserData == score.CommonUserData); <-- nonsense
            }
            if (index != -1)                                                                   //if the score already exits
            {
                return;
            }

            //here we dont have one of theses scores add it
            int scoreIndex = _scoresToSend.FindIndex(x => x.Leaderboard == leaderboard &&
                                                     x.Score.Principal_ID == score.Principal_ID && x.Score.Nex_Unique_ID == score.Nex_Unique_ID);
            if (scoreIndex == -1)
            {
                _scoresToSend.Add(new QueuededScore(score, leaderboard, type));
                _saveSoon = true;
            }
            else
            {
                bool isBetter = false;
                //check to see if score is better or not
                if (category.Value.SortBy == SortOrder.Accending)
                {
                    if (_scoresToSend[scoreIndex].Score.Score > score.Score)
                    {
                        isBetter = true;
                    }
                }
                else
                if (_scoresToSend[scoreIndex].Score.Score > score.Score)
                {
                    isBetter = true;
                }

                if (isBetter)
                {
                    QueuededScore qs = new QueuededScore(score, _scoresToSend[scoreIndex].Leaderboard, type);
                    _scoresToSend[scoreIndex] = qs;
                }
            }
        }
Example #2
0
        public static void Load()
        {
            PrintLine("Atempting Load of leadeboards");
            FileStream fs = null;

            if (!UFile.Exits(_savePath))
            {
                PrintLine("no file found");
                return;
            }
            try
            {
                fs = UFile.Open(_savePath, FileMode.Open);
                PrintLine("Loading Scores");
                CustomXmlReader reader = CustomXmlReader.Create(fs);
                _scoresToSend.Clear();
                while (reader.Read())
                {
                    if (reader.Name == "ScoresToSend")
                    {
                        if (reader.IsStartElement())
                        {
                            HighScore hs = new Networking.HighScore()
                            {
                                Principal_ID       = reader.ReadAttributeULong("Id"),
                                Nex_Unique_ID      = reader.ReadAttributeULong("Nex_Id"),
                                Misc               = reader.ReadAttributeULong("Misc"),
                                Score              = reader.ReadAttributeUInt("Score"),
                                CommonDataBinary   = reader.ReadAttributeArrayOfByte("Cud"),
                                CommonDataUserName = reader.ReadAttributeString("UserName"),
                            };

                            QueuededScore qhs = new QueuededScore(hs, reader.ReadAttributeString("Leaderboard"),
                                                                  (HighScoreType)reader.ReadAttributeInt("Type"));
                            _scoresToSend.Add(qhs);
                        }
                    }
                    string currentLeaderboard;
                    if (reader.Name == "Leaderboard")
                    {
                        if (reader.IsStartElement())
                        {
                            currentLeaderboard = reader.ReadAttributeString("Name");

                            if (!_localLeaderboards.ContainsKey(currentLeaderboard))
                            {
                                _localLeaderboards.Add(currentLeaderboard, new List <HighScore>());
                            }
                            while (reader.Read())
                            {
                                if (reader.Name == "Leaderboard")
                                {
                                    if (!reader.IsStartElement())
                                    {
                                        break;
                                    }
                                }

                                if (reader.Name == "Score")
                                {
                                    if (reader.IsStartElement())
                                    {
                                        HighScore hs = new HighScore()
                                        {
                                            Principal_ID       = reader.ReadAttributeULong("Id"),
                                            Nex_Unique_ID      = reader.ReadAttributeULong("Nex_Id"),
                                            Misc               = reader.ReadAttributeULong("Misc"),
                                            Score              = reader.ReadAttributeUInt("Score"),
                                            CommonDataUserName = reader.ReadAttributeString("UserName"),
                                            CommonDataBinary   = reader.ReadAttributeArrayOfByte("Cud"),
                                        };


                                        _localLeaderboards[currentLeaderboard].Add(hs);
                                    }
                                }
                            }
                        }
                    }
                }

                foreach (QueuededScore qs in _scoresToSend)
                {
                    PrintLine($"{qs.Leaderboard} > {qs.Score.Principal_ID}, {qs.Score.Score}");
                }
                reader.Close();
                PrintLine("Loading Compleate");
            }
            catch (System.Exception x)
            {
                PrintLine($"Error Saving: {x.Message}");
//
            }
            fs.Close();
        }