public static void UploadScores(string userName, List <uint> scores, List <string> leaderboards, ulong misc = 0, byte[] commonData = null, Action <bool> onCompleate = null) { foreach (string s in leaderboards) { NEX_Category?category = CategoryHelper.GetCategory(s); if (category == null) { throw new Exception("Category does not exits!"); } } List <HighScore> hscore = new List <HighScore>(); foreach (uint u in scores) { #if DEBUG Console.WriteLine($"Uploading Score {userName}: {u}"); #endif hscore.Add(new HighScore() { Score = u, Misc = misc, CommonDataUserName = userName, CommonDataBinary = commonData, }); } if (!CanCommunicateWithRankingsServer) { PrintLine("Not Allowed to connect to rankings server"); for (int i = 0; i < leaderboards.Count; i++) { UploadFailed(hscore[i], leaderboards[i], HighScoreType.Score); //on failed to upload score PrintLine("Adding Score Localy"); AddScoreLocaly(hscore[0], leaderboards[i]); PrintLine("Done"); } return; } Thread t = new System.Threading.Thread(() => { int checkCout = 10; while (IsBussy) { System.Threading.Thread.Sleep(1000); checkCout--; if (checkCout <= 0) { PrintLine("Sending failed"); for (int i = 0; i < leaderboards.Count; i++) { UploadFailed(hscore[i], leaderboards[i], HighScoreType.Score); //on failed to upload score } return; } } IsBussy = true; //I guess you meant to upload the common data here too but never did //using hscore.CommonDataBinary.... for (int i = 0; i < leaderboards.Count; i++) { bool success = _uploadScoreToServer(hscore[i], leaderboards[i], misc); if (!success) //try to upload the scores to the server { PrintLine("************************"); UploadFailed(hscore[i], leaderboards[i], HighScoreType.Score); //on failed to upload score SendingFailed = true; // dont allow to try to connect again } if (onCompleate != null) { onCompleate(success); } } IsBussy = false; }); t.Start(); for (int i = 0; i < leaderboards.Count; i++) { PrintLine("Adding Score Localy"); AddScoreLocaly(hscore[i], leaderboards[i]); PrintLine("Done"); } }
public static void UploadScore(string userName, uint score, string leaderboard, ulong misc = 0, byte[] commonData = null, Action <bool> onCompleate = null) { NEX_Category?category = CategoryHelper.GetCategory(leaderboard); if (category == null) { throw new Exception("Category does not exits!"); } #if DEBUG Console.WriteLine($"Uploading Score {userName}: {score}"); #endif HighScore hscore = new HighScore() { Score = score, Misc = misc, CommonDataUserName = userName, CommonDataBinary = commonData, }; if (!CanCommunicateWithRankingsServer) { PrintLine("Not Allowed to connect to rankings server"); UploadFailed(hscore, leaderboard, HighScoreType.Score); //on failed to upload score PrintLine("Adding Score Localy"); AddScoreLocaly(hscore, leaderboard); PrintLine("Done"); return; } Thread t = new System.Threading.Thread(() => { int checkCout = 10; while (IsBussy) //make sure i dont send a score while we are current uploading a score { System.Threading.Thread.Sleep(1000); checkCout--; if (checkCout <= 0) { PrintLine("Sending failed"); UploadFailed(hscore, leaderboard, HighScoreType.Score); //on failed to upload score return; } } IsBussy = true; //I guess you meant to upload the common data here too but never did //using hscore.CommonDataBinary.... bool success = _uploadScoreToServer(hscore, leaderboard, misc); if (!success) //try to upload the scores to the server { PrintLine("************************"); UploadFailed(hscore, leaderboard, HighScoreType.Score); //on failed to upload score SendingFailed = true; // dont allow to try to connect again } if (onCompleate != null) { onCompleate(success); } IsBussy = false; }); t.Start(); PrintLine("Adding Score Localy"); AddScoreLocaly(hscore, leaderboard); PrintLine("Done"); }
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; } } }