From 4ac511d26075144e31258155451def6e815d9140 Mon Sep 17 00:00:00 2001 From: Sewmina Dilshan Date: Fri, 24 Feb 2023 21:09:20 +0530 Subject: [PATCH] Leaderboard --- ...oidx.lifecycle.lifecycle-process-2.4.1.aar | Bin 9993 -> 9993 bytes ...androidx.startup.startup-runtime-1.1.1.aar | Bin 20086 -> 20086 bytes .../androidx.work.work-runtime-2.7.0.aar | Bin 1530136 -> 1530136 bytes ...roid.gms.play-services-ads-lite-21.3.0.aar | Bin 717952 -> 717952 bytes ...gle.signin.google-signin-support-1.0.4.aar | Bin 198795 -> 198795 bytes Assets/Scenes/MainMenu.unity | 3162 ++++++++++++++++- Assets/Scenes/Proto.unity | 82 +- Assets/Scripts/AudioManager.cs | 2 + Assets/Scripts/DataManager.cs | 60 +- Assets/Scripts/EncryptionTester.cs | 36 + Assets/Scripts/EncryptionTester.cs.meta | 11 + Assets/Scripts/Encryptor.cs | 102 + Assets/Scripts/Encryptor.cs.meta | 11 + Assets/Scripts/GameManager.cs | 14 + Assets/Scripts/LevelGenerator.cs | 11 +- Assets/Scripts/MainMenu.cs | 42 +- Assets/Scripts/MessageBox.cs | 2 +- ProjectSettings/ProjectSettings.asset | 6 +- 18 files changed, 3504 insertions(+), 37 deletions(-) create mode 100644 Assets/Scripts/EncryptionTester.cs create mode 100644 Assets/Scripts/EncryptionTester.cs.meta create mode 100644 Assets/Scripts/Encryptor.cs create mode 100644 Assets/Scripts/Encryptor.cs.meta diff --git a/Assets/Plugins/Android/androidx.lifecycle.lifecycle-process-2.4.1.aar b/Assets/Plugins/Android/androidx.lifecycle.lifecycle-process-2.4.1.aar index 809fa80c2fe5b11d03b61391062c1a51cc4721d8..5b79ded307645a9c42574b182b8c365ad4324bfe 100644 GIT binary patch delta 112 zcmeD5>-6Id@MdNaVc_84V0gG9Vk7S?d1fFzd6m2hn7$~l0jB@R8-Qtj1v3!6IYZ$N k6Ij4qxf)C#RW-6Id@MdNaVc_84V9;v}*~mLfo*76_UL~&rrZ38CfayQ-24GrW!3;!i&QQ3+ j1Qu{tt_IUbl}*6(A7u+LZLZ<~rmIxkK=kIrDsD^wC!Hb~ diff --git a/Assets/Plugins/Android/androidx.startup.startup-runtime-1.1.1.aar b/Assets/Plugins/Android/androidx.startup.startup-runtime-1.1.1.aar index 019c4cdc8249f89ba873e4c21f7386ad97725981..95aa778b69cc66f5a39b9291472e9f51e31a3026 100644 GIT binary patch delta 114 zcmex1hw*0;V&)Ex_~=ZwD~_+}jOAZ#M98V*&uV?=6M^ delta 114 zcmex1hwjoVDI$-OdENdfay$c3oyOJ+W|~J_jUu(n+<&2m;jeMBN6}r diff --git a/Assets/Plugins/Android/androidx.work.work-runtime-2.7.0.aar b/Assets/Plugins/Android/androidx.work.work-runtime-2.7.0.aar index 9488f88a317715af64938e564aa88e3c977c80c2..e717f67b1b6e4b13cab9e1c5cc7d1322967a2201 100644 GIT binary patch delta 194 zcmW;EKMnyw9L4cvmK}c{)-JybY@t+$C=@CM$*jVNX0PA~62&`%y?{i$iR=}W&LGh_ zgf-nK-@LrM$nqk?Zmay*(^`A)`|$#zM$`#K_(X$f5&@x!7SSd;M3<;$J)%zxh>#c( z5fKw3V*G%djH=GAXCsNj&B(;zWn}80QknlzE>rpVE+u>UIz(1x4jU^A2U=MIdi1J!1d> delta 194 zcmW;EzYT&w9K~_pU5%p|LOo%BF5Hlhq zB4SP~UXYtn_1WWYBzAZjSvq`-tQ}M$+XmG>k+0`coXXE3w6bwHS=l+z%E94n<=CJK HuHvgdNcS@P diff --git a/Assets/Plugins/Android/com.google.android.gms.play-services-ads-lite-21.3.0.aar b/Assets/Plugins/Android/com.google.android.gms.play-services-ads-lite-21.3.0.aar index fc41d36a7fecc9c21b1ba6c65fdb71241bc99bb2..dbbd1c4932e9fb1dce661def64cc9ad8c41e782a 100644 GIT binary patch delta 101 zcmZp8son5Wn>WClnMH(wgM)+N(Ta#h-d0}5R$iu7UglO_mR4TYR$jJNUiMaAj#ggI st-M@(q0B&4)8#_B4xwBEbHPHvpSWIt8Frt!^uclkpSc7W0l_&Sr2qf` delta 101 zcmZp8son5Wn>WClnMH(wgM))XzcHkdx0RQ%m6xfNm${XfrInYpm6xrRm%Wvjqm`F) sD=!ycC^Jyibh%J2c@Sf}LnxQPT(D5^C$1M@hTUf_eXv}?XD$Io00ONWaR2}S diff --git a/Assets/Plugins/Android/com.google.signin.google-signin-support-1.0.4.aar b/Assets/Plugins/Android/com.google.signin.google-signin-support-1.0.4.aar index 45d7aa6ab3082764c8fd271c842a3f780b010e8b..b23f74fcad1646909389dbcd9b52c231f5ecf756 100644 GIT binary patch delta 71 zcmeC4$kRQMXTxka=Eo}{CeL$|2hq(3+_oQZW6YTZ; Leaderboard{get; private set;} public static bool isLogged{ get{return userData != null;}} public static void Signout(){ @@ -82,7 +83,7 @@ public static class DataManager{ await Task.Yield(); } Debug.Log("glogin response: " +request.downloadHandler.text); - MessageBox.ShowMessage(request.downloadHandler.text); + // MessageBox.ShowMessage(request.downloadHandler.text); if(request.downloadHandler.text.Contains("{")){ try{ @@ -160,6 +161,47 @@ public static class DataManager{ LoadingScreen.LoadLevel("MainMenu"); } + public static async Task RefreshLeaderboard(){ + WWWForm form = new WWWForm(); + + Debug.Log(userData.ToString()); + + form.AddField("username", userData.username); + + using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "get_leaderboard.php", form)) + { + var operation = request.SendWebRequest(); + while (!operation.isDone) + { + await Task.Yield(); + } + Debug.Log("add scores response: " +request.downloadHandler.text); + + if(request.downloadHandler.text.Contains("{")){ + try{ + string[] items = request.downloadHandler.text.Split(""); + Leaderboard = new List(); + foreach(string item in items){ + LeaderboardItemData newItem = JsonConvert.DeserializeObject(item); + + Leaderboard.Add(newItem); + } + + Debug.Log("Success parsing userdata"); + + + }catch(Exception e){ + Debug.Log("Error parsing leaderboard"); + } + }else{ + + MessageBox.ShowMessage("Error getting leaderboard, Server said\n" +request.downloadHandler.text); + + } + + } + } + } [System.Serializable] @@ -176,3 +218,19 @@ public class UserData{ return JsonConvert.SerializeObject(this); } } + +[System.Serializable] +public class LeaderboardItemData{ + public int position; + public string name; + public int topScore; + + public string DisplayName{get{ + string _name= name; + if(name.Contains("#0")){ + _name = _name.Substring(0,name.IndexOf("@gmail")); + } + + return _name; + }} +} diff --git a/Assets/Scripts/EncryptionTester.cs b/Assets/Scripts/EncryptionTester.cs new file mode 100644 index 0000000..0f7dca4 --- /dev/null +++ b/Assets/Scripts/EncryptionTester.cs @@ -0,0 +1,36 @@ +using System.Collections; +using System.Collections.Generic; +using System.Security.Cryptography; +using UnityEngine; + +public class EncryptionTester : MonoBehaviour +{ + public PaddingMode paddingMode; + public CipherMode cipherMode; + [Header("Encryption")] + public string textToEncrypt; + public string encryptedText; + + [Header("Decryption")] + public string textToDecrypt; + public string decryptedText; + + [Header("Numbers")] + [Header("Encryption")] + public int numberToEncrypt; + public string encryptedNumber; + [Header("Encryption")] + public string numTextToDecrypt; + public int decryptedNumber; + + void OnDrawGizmos(){ + Encryptor.cipherMode = cipherMode; + Encryptor.paddingMode = paddingMode; + + encryptedText = Encryptor.encrypt(textToEncrypt); + decryptedText = Encryptor.decrypt(textToDecrypt); + + encryptedNumber = Encryptor.intToString(numberToEncrypt); + decryptedNumber = Encryptor.stringToInt(numTextToDecrypt); + } +} diff --git a/Assets/Scripts/EncryptionTester.cs.meta b/Assets/Scripts/EncryptionTester.cs.meta new file mode 100644 index 0000000..71d0dfb --- /dev/null +++ b/Assets/Scripts/EncryptionTester.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f08b67e0ea5507a42a56c6c80c24181c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Encryptor.cs b/Assets/Scripts/Encryptor.cs new file mode 100644 index 0000000..f358700 --- /dev/null +++ b/Assets/Scripts/Encryptor.cs @@ -0,0 +1,102 @@ + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.Security.Cryptography; +using System.IO; +using System.Text; +using System; + +public static class Encryptor +{ + private static string hash = "@419$"; + public static PaddingMode paddingMode = PaddingMode.PKCS7; + public static CipherMode cipherMode = CipherMode.ECB; + + private static string charPool = "AKFLDJAHSPIWUROCNMZX"; + + public static string encrypt(string input) + { + byte[] data = UTF8Encoding.UTF8.GetBytes(input); + using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) + { + byte[] key = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash)); + using (TripleDESCryptoServiceProvider tds = new TripleDESCryptoServiceProvider() { Key=key, Mode = cipherMode, Padding = paddingMode }) + { + ICryptoTransform ict = tds.CreateEncryptor(); + byte[] results = ict.TransformFinalBlock(data, 0, data.Length); + return Convert.ToBase64String(results, 0, results.Length); + } + } + } + + public static string decrypt(string input) + { + byte[] data = Convert.FromBase64String(input); + using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) + { + byte[] key = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash)); + using (TripleDESCryptoServiceProvider tds = new TripleDESCryptoServiceProvider() { Key = key, Mode = cipherMode, Padding = paddingMode }) + { + ICryptoTransform ict = tds.CreateDecryptor(); + byte[] results = ict.TransformFinalBlock(data, 0, data.Length); + return UTF8Encoding.UTF8.GetString(results); + } + } + } + + public static string intToString(int input){ + char[] inputBytes = input.ToString().ToCharArray(); + string output = ""; + foreach(char c in inputBytes){ + output += charPool[int.Parse(c.ToString())]; + } + int luckyNumber = GetLuckyNumber(input); + + string lastLetter = charPool.ToCharArray()[luckyNumber].ToString(); + + return output+lastLetter; + } + + public static int stringToInt(string input){ + char[] inputBytes = input.Remove(input.Length-1).ToCharArray(); + string output = ""; + foreach(char c in inputBytes){ + for(int i=0; i < charPool.Length; i++){ + if(charPool.ToCharArray()[i] == c){ + output += i.ToString(); + break; + } + } + } + + char lastchar = input.ToCharArray()[input.Length-1]; + + int outputInt = int.Parse(output); + char luckyChar = charPool.ToCharArray()[GetLuckyNumber(outputInt)]; + bool validated = luckyChar == lastchar; + + + if(validated){ + return outputInt; + }else{ + return -1; + } + } + + + public static int GetLuckyNumber(int input){ + int luckyNumber=input; + while(luckyNumber >= 10){ + int val = 0; + for(int i=0; i < luckyNumber.ToString().Length; i++){ + val += int.Parse(luckyNumber.ToString().ToCharArray()[i].ToString()); + } + + luckyNumber = val; + } + + return luckyNumber; + } + +} diff --git a/Assets/Scripts/Encryptor.cs.meta b/Assets/Scripts/Encryptor.cs.meta new file mode 100644 index 0000000..55fce2c --- /dev/null +++ b/Assets/Scripts/Encryptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a8ea67314c0e25f43a9834b0be9797db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index c9cdf08..7b4779e 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -43,11 +43,14 @@ public class GameManager : MonoBehaviour public Text gameOverBestScoreTxt, gameOverTotalScoreTxt; public GameObject GameOverUI; public GameObject PauseMenuUI; + public Button muteBtn; + public Sprite muteIcon, unmuteIcon; public Animator HoleInOne; public int curHoleIndex; private static int adCounter = 0; void Start() { + muteBtn.onClick.AddListener(OnMute); strokesTxtDefaultSize = StrokesTxt.transform.localScale; scoreTxtDefaultSize = ScoreTxt.transform.localScale; camTargetPos = ball.transform.position; @@ -232,6 +235,15 @@ public class GameManager : MonoBehaviour } ScoreTxt.text = Score.ToString(); StrokesTxt.text = CurStrokes.ToString(); + + + muteBtn.transform.GetChild(0).GetComponent().sprite = AudioManager.isMute ? muteIcon : unmuteIcon; + } + + void OnMute(){ + AudioManager.ToggleMute(); + + UpdateUI(); } @@ -271,6 +283,8 @@ public class GameManager : MonoBehaviour }else{ LeanTween.scale(PauseMenuUI, Vector3.zero, 0.15f).setEaseOutCirc(); } + + UpdateUI(); } } diff --git a/Assets/Scripts/LevelGenerator.cs b/Assets/Scripts/LevelGenerator.cs index 2ff0d86..f6c621e 100644 --- a/Assets/Scripts/LevelGenerator.cs +++ b/Assets/Scripts/LevelGenerator.cs @@ -97,12 +97,19 @@ public class LevelGenerator : MonoBehaviour } + float checker = 0; void Update() { if(GameManager.instance == null){return;} + if(checker < 30){ + checker+=Time.deltaTime; + }else{ + checker =0; - if(GameManager.instance.ball.position.x > lastOffset - 100){ - GenerateBlock(); + if(GameManager.instance.ball.position.x > lastOffset - 100){ + GenerateBlock(); + } } + } } diff --git a/Assets/Scripts/MainMenu.cs b/Assets/Scripts/MainMenu.cs index 1d32e2a..962bb90 100644 --- a/Assets/Scripts/MainMenu.cs +++ b/Assets/Scripts/MainMenu.cs @@ -9,6 +9,8 @@ public class MainMenu : MonoBehaviour public GameObject MainMenuPanel; public GameObject SettingsPanel; + public GameObject LeaderboarPanel; + public Transform LeaderboardItemsParent; public float transitionTime; public LeanTweenType transitionEffect; @@ -26,12 +28,16 @@ public class MainMenu : MonoBehaviour return; } defaultCenter = MainMenuPanel.transform.position; - SettingsPanel.transform.position = MainMenuPanel.transform.position - new Vector3(3000,0); + SettingsPanel.transform.position = MainMenuPanel.transform.position - new Vector3(10000,0); SettingsPanel.SetActive(true); + LeaderboarPanel.SetActive(true); + LeaderboarPanel.transform.position = MainMenuPanel.transform.position + new Vector3(10000,0); muteBtn.onClick.AddListener(ToggleMute); copyBtn.onClick.AddListener(CopyId); signoutBtn.onClick.AddListener(SignOut); + + DataManager.RefreshLeaderboard(); } public void Leave(){ Application.Quit(); @@ -44,7 +50,7 @@ public class MainMenu : MonoBehaviour void Refresh(){ - txtUserId.text = DataManager.userData.id.ToString(); + txtUserId.text = Encryptor.intToString(DataManager.userData.id); if(AudioManager.isMute){ muteBtn.transform.GetChild(0).GetComponent().sprite = muteIcon; }else{ @@ -57,13 +63,20 @@ public class MainMenu : MonoBehaviour LeanTween.moveX(SettingsPanel, defaultCenter.x, transitionTime).setEase(transitionEffect); } + public void LeaderboarPage(){ + LeanTween.moveX(MainMenuPanel, -10000, transitionTime).setEase(transitionEffect); + LeanTween.moveX(LeaderboarPanel, defaultCenter.x, transitionTime).setEase(transitionEffect); + RefreshLeaderboard(); + } + public void MainPage(){ LeanTween.moveX(MainMenuPanel, defaultCenter.x, transitionTime).setEase(transitionEffect); LeanTween.moveX(SettingsPanel, -10000, transitionTime).setEase(transitionEffect); + LeanTween.moveX(LeaderboarPanel, 10000, transitionTime).setEase(transitionEffect); } public void CopyId(){ - GUIUtility.systemCopyBuffer = DataManager.userData.id.ToString(); + GUIUtility.systemCopyBuffer = txtUserId.text; copyBtn.transform.Find("lbl").GetComponent().text = "Copied"; } @@ -72,6 +85,29 @@ public class MainMenu : MonoBehaviour Refresh(); } + public void Info(){ + MessageBox.ShowMessage(@"This is a game where you can relax while playing, + Listen to a podcast or to music while playing this to get the best out of it! + + Any feedback or suggestion can be directed to us via this email + sewmina7@gmail.com","About"); + } + + async void RefreshLeaderboard(){ + UpdateLeaderboardUI(); + await DataManager.RefreshLeaderboard(); + UpdateLeaderboardUI(); + } + + void UpdateLeaderboardUI(){ + for(int i =0; i < DataManager.Leaderboard.Count; i++){ + LeaderboardItemsParent.GetChild(i).GetChild(0).GetComponent().text = $"{i+1}." + DataManager.Leaderboard[i].DisplayName; + // LeaderboardItemsParent.GetChild(i).GetChild(0).GetComponent().text = $"{i+1}." + DataManager.Leaderboard[i].name; + LeaderboardItemsParent.GetChild(i).GetChild(1).GetComponent().text = DataManager.Leaderboard[i].topScore.ToString(); + + LeaderboardItemsParent.GetChild(i).GetComponent().CrossFadeAlpha((DataManager.Leaderboard[i].name == DataManager.userData.username) ? 0.9f : 0,0.5f,true); + } + } void SignOut(){ diff --git a/Assets/Scripts/MessageBox.cs b/Assets/Scripts/MessageBox.cs index ad135f4..7f5ef3a 100644 --- a/Assets/Scripts/MessageBox.cs +++ b/Assets/Scripts/MessageBox.cs @@ -50,7 +50,7 @@ public class MessageBox : MonoBehaviour for(int i=0; i < message.Length; i++){ messageTxt.text += message[i]; - yield return new WaitForSeconds(0.02f); + yield return new WaitForSeconds(0.01f); } closeButton.gameObject.SetActive(true); diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 1680b98..f4af8d7 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -134,7 +134,7 @@ PlayerSettings: 16:10: 1 16:9: 1 Others: 1 - bundleVersion: 1.0 + bundleVersion: 1.2 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0 @@ -162,9 +162,9 @@ PlayerSettings: iPhone: 0 tvOS: 0 overrideDefaultApplicationIdentifier: 1 - AndroidBundleVersionCode: 1 + AndroidBundleVersionCode: 2 AndroidMinSdkVersion: 22 - AndroidTargetSdkVersion: 0 + AndroidTargetSdkVersion: 33 AndroidPreferredInstallLocation: 1 aotOptions: stripEngineCode: 1