Pārlūkot izejas kodu

Refactoring, google analytics Firebase, Firebase Cloud message start, MessageToken on login

Axel Nordh 5 gadi atpakaļ
vecāks
revīzija
c6b0b49b37

+ 8 - 0
Assets/Data/google-services.json

@@ -14,6 +14,14 @@
         }
       },
       "oauth_client": [
+        {
+          "client_id": "108102546370-04af3qem370e3hdp25hg070juo232d15.apps.googleusercontent.com",
+          "client_type": 1,
+          "android_info": {
+            "package_name": "se.nordh.xyz.narKampen",
+            "certificate_hash": "21e89b1f32a959ce39269c69ff4346779afca0da"
+          }
+        },
         {
           "client_id": "108102546370-2bu9lhiunhhi5v6up5dcuntnucoo5dcf.apps.googleusercontent.com",
           "client_type": 3

+ 0 - 8
Assets/Editor.meta

@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 806208e507ba9d140a717284602613a7
-folderAsset: yes
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 23 - 0
Assets/FirebaseMessenger.cs

@@ -0,0 +1,23 @@
+using System.Collections;
+using System.Collections.Generic;
+using Firebase;
+using UnityEngine;
+
+public class FirebaseMessenger : MonoBehaviour
+{
+    // Start is called before the first frame update
+    void Start()
+    {
+        Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
+        Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
+    }
+
+    public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
+        Debug.Log("Received Registration token: " + token.Token);
+    }
+
+    public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
+        Debug.Log("Received New message from: " + e.Message.From);
+    }
+
+}

+ 11 - 0
Assets/FirebaseMessenger.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6dba90c1b32c37c43b0cb61d9dd0280c
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 2
Assets/NewDropZoneScript.cs

@@ -41,7 +41,6 @@ public class NewDropZoneScript : MonoBehaviour, IDropHandler, IPointerEnterHandl
                 });
             confirmDialog.SetOnDecline(LocalizationManager.Instance.GetText("NO"), () =>
             {
-                // Flytta onEndDrag hit för att inte generera ny fråga vid NEJ
                 NewQuestionDragController.setAnswerText("???? - ????");
                 confirmDialog.Hide();
             });
@@ -82,7 +81,8 @@ public class NewDropZoneScript : MonoBehaviour, IDropHandler, IPointerEnterHandl
             Destroy(gameObject);
             GameObject.Find("GameManager").GetComponent<GameManagerScript>().StopTimer();
             draggedQuestion.GetComponentInParent<NewQuestionCardController>().GenerateNewQuestion();
-        } else {
+        } else { // Wrong answer
+            GameObject.Find("GameManager").GetComponent<GameManagerScript>().RemoveUnlockedQuestions();
             GameObject.Find("GameManager").GetComponent<GameManagerScript>().NextRound();
         }
     }

+ 43 - 0
Assets/Scenes/User.unity

@@ -344,6 +344,49 @@ CanvasRenderer:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 27433606}
   m_CullTransparentMesh: 0
+--- !u!1 &35356223
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 35356225}
+  - component: {fileID: 35356224}
+  m_Layer: 0
+  m_Name: FirebaseController
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!114 &35356224
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 35356223}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 5a9e345e01b695946aa45906dfbfaeb7, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+--- !u!4 &35356225
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 35356223}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 960, y: 540, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_RootOrder: 3
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1 &39834636
 GameObject:
   m_ObjectHideFlags: 0

+ 43 - 0
Assets/Scenes/narKampen.unity

@@ -3096,6 +3096,49 @@ MonoBehaviour:
   m_OnValueChanged:
     m_PersistentCalls:
       m_Calls: []
+--- !u!1 &1805246927
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 1805246929}
+  - component: {fileID: 1805246928}
+  m_Layer: 0
+  m_Name: FirebaseController
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!114 &1805246928
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1805246927}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 6dba90c1b32c37c43b0cb61d9dd0280c, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+--- !u!4 &1805246929
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1805246927}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 960, y: 540, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_RootOrder: 4
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1 &1810792917
 GameObject:
   m_ObjectHideFlags: 0

+ 3 - 3
Assets/Scripts/Database/Database.cs

@@ -8,8 +8,8 @@ using UnityEngine.Networking;
 using System.IO;
 
 public class Database : MonoBehaviour {
-    private const string onlineQuestionsUrl = "nordh.xyz/narKampen/dbFiles/Question.php";
-    private const string serverUrl = "nordh.xyz/narKampen/dbFiles/";
+    private const string onlineQuestionsUrl = "narkampen.nordh.xyz/narKampen/dbFiles/Question.php";
+    private const string serverUrl = "narkampen.nordh.xyz/narKampen/dbFiles/";
     string connectionType;
     string databaseUrl;
     string gameMode;
@@ -751,7 +751,7 @@ public class Database : MonoBehaviour {
     }
 
     private IEnumerator GetQuestionData(bool showAnswer) {
-        UnityWebRequest www = UnityWebRequest.Get("nordh.xyz/narKampen/dbFiles/Question.php");
+        UnityWebRequest www = UnityWebRequest.Get("narkampen.nordh.xyz/narKampen/dbFiles/Question.php");
 
         yield return www.SendWebRequest();
 

+ 3 - 3
Assets/Scripts/Database/OnlineDatabase.cs

@@ -8,8 +8,8 @@ using UnityEngine.Networking;
 using System.IO;
 
 public class OnlineDatabase : MonoBehaviour {
-    private const string onlineQuestionsUrl = "nordh.xyz/narKampen/dbFiles/Question.php";
-    private const string serverUrl = "nordh.xyz/narKampen/dbFiles/";
+    private const string onlineQuestionsUrl = "narkampen.nordh.xyz/narKampen/dbFiles/Question.php";
+    private const string serverUrl = "narkampen.nordh.xyz/narKampen/dbFiles/";
     string gameMode;
     int winAmount = -1;
 
@@ -557,7 +557,7 @@ public class OnlineDatabase : MonoBehaviour {
     }
 
     public List<UserName> GetUsersToInvite(string searchString) {
-        string postUrl = "nordh.xyz/narKampen/dbFiles/PlayerSearch.php?";
+        string postUrl = "narkampen.nordh.xyz/narKampen/dbFiles/PlayerSearch.php?";
         postUrl += "search=" + UnityWebRequest.EscapeURL(searchString);
 
 

+ 27 - 0
Assets/Scripts/GameManagerScript.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using Firebase;
 using UnityEngine;
 using UnityEngine.UI;
 
@@ -32,8 +33,25 @@ public class GameManagerScript : MonoBehaviour {
     [SerializeField] float movementSpeed = 1.0f;
 
     List<KeyValuePair<string, int>> players;
+    private FirebaseApp app;
+
     // Start is called before the first frame update
     void Start() {
+        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
+        var dependencyStatus = task.Result;
+        if (dependencyStatus == Firebase.DependencyStatus.Available) {
+            // Create and hold a reference to your FirebaseApp,
+            // where app is a Firebase.FirebaseApp property of your application class.
+            app = Firebase.FirebaseApp.DefaultInstance;
+
+            // Set a flag here to indicate whether Firebase is ready to use by your app.
+        } else {
+            UnityEngine.Debug.LogError(System.String.Format(
+            "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
+            // Firebase Unity SDK is not safe to use here.
+        }
+        });
+        
         GameId = PlayerPrefs.GetInt("GameId");
         GameMode = PlayerPrefs.GetString("GameMode");
         QuestionTimer = PlayerPrefs.GetInt("QuestionTimer");
@@ -108,6 +126,15 @@ public class GameManagerScript : MonoBehaviour {
 
         NewQuestionCard.GetComponent<NewQuestionCardController>().GenerateNewQuestion();
         // Destroy(NewQuestionCard.gameObject);
+        StopTimer();
+    }
+
+    internal void RemoveUnlockedQuestions()
+    {
+        if (scrollViewScript == null) {
+            scrollViewScript = GameObject.FindGameObjectWithTag("AnswerLine").transform.parent.parent.GetComponent<ScrollViewScript>();
+        }
+        scrollViewScript.RemoveUnlockedQuestions();
     }
 
     private void CreateLeftSpacer()

+ 7 - 1
Assets/Scripts/Login/Login.cs

@@ -25,7 +25,7 @@ public class Login : MonoBehaviour {
 
     private string Username;
     private string Password;
-    private string loginUrl = "http://nordh.xyz/narKampen/dbFiles/Login.php?";
+    private string loginUrl = "http://narkampen.nordh.xyz/narKampen/dbFiles/Login.php?";
     private Color errorColor;
     private EventSystem system;
 
@@ -110,6 +110,12 @@ public class Login : MonoBehaviour {
     IEnumerator loginCall() {
         string postUrl = loginUrl + "name=" + UnityWebRequest.EscapeURL(Username);
 
+        string token = FirebaseStart.MyToken;
+        if (token.Length > 0) {
+            StringBuilder sb = new StringBuilder(loginUrl);
+            sb.Append("&t=" + token);
+            postUrl = sb.ToString();
+        }
         UnityWebRequest www = UnityWebRequest.Get(postUrl);
         yield return www.SendWebRequest();
 

+ 12 - 5
Assets/Scripts/NewGameScene/FirebaseStart.cs

@@ -6,6 +6,8 @@ using UnityEngine;
 
 public class FirebaseStart : MonoBehaviour
 {
+
+    public static string MyToken;
     private FirebaseApp app;
 
     // Start is called before the first frame update
@@ -26,12 +28,17 @@ public class FirebaseStart : MonoBehaviour
             // Firebase Unity SDK is not safe to use here.
         }
         });
-                
+        Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
+        Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived; 
     }
 
-    // Update is called once per frame
-    void Update()
-    {
-        
+    public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
+        MyToken = token.Token;
+        Debug.Log("Received Registration token: " + token.Token);
     }
+
+    public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
+        Debug.Log("Received New message from: " + e.Message.From);
+    }
+
 }

+ 1 - 1
Assets/Scripts/PrivacyPolicy.cs

@@ -7,7 +7,7 @@ using UnityEngine.UI;
 public class PrivacyPolicy : MonoBehaviour
 {
     Button pp;
-    private string privacyPolicyLink = "http://nordh.xyz/narKampen/PrivacyPolicy/privacy_policy.html";
+    private string privacyPolicyLink = "http://narkampen.nordh.xyz/narKampen/PrivacyPolicy/privacy_policy.html";
 
     // Start is called before the first frame update
     void Start()

+ 8 - 0
Assets/StreamingAssets/google-services-desktop.json

@@ -14,6 +14,14 @@
         }
       },
       "oauth_client": [
+        {
+          "client_id": "108102546370-04af3qem370e3hdp25hg070juo232d15.apps.googleusercontent.com",
+          "client_type": 1,
+          "android_info": {
+            "package_name": "se.nordh.xyz.narKampen",
+            "certificate_hash": "21e89b1f32a959ce39269c69ff4346779afca0da"
+          }
+        },
         {
           "client_id": "108102546370-2bu9lhiunhhi5v6up5dcuntnucoo5dcf.apps.googleusercontent.com",
           "client_type": 3

+ 1 - 1
Assets/StreamingAssets/google-services-desktop.json.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: fd73d4648d897484b8d097d7312e4992
+guid: 3120c7189ae7c4b49a8dbb694b912f6f
 TextScriptImporter:
   externalObjects: {}
   userData: 

BIN
Assets/narKampenLocal.db


+ 7 - 3
ProjectSettings/ProjectSettings.asset

@@ -742,7 +742,11 @@ PlayerSettings:
       daydreamIconForeground: {fileID: 0}
       daydreamIconBackground: {fileID: 0}
   cloudServicesEnabled:
-    Collab: 1
+    Build: 0
+    Collab: 0
+    ErrorHub: 0
+    Hub: 0
+    UNet: 1
   luminIcon:
     m_Name: 
     m_ModelFolderPath: 
@@ -755,9 +759,9 @@ PlayerSettings:
     m_VersionCode: 1
     m_VersionName: 
   apiCompatibilityLevel: 6
-  cloudProjectId: 30feeaa3-f24a-494f-b331-082b64359a05
+  cloudProjectId: 742a50d3-da1b-40e8-a05d-592971db0453
   framebufferDepthMemorylessMode: 0
-  projectName: "N\xE4r Kampen"
+  projectName: NarKampenV3
   organizationId: axelnordh
   cloudEnabled: 0
   enableNativePlatformBackendsForNewInputSystem: 0

+ 5 - 2
ProjectSettings/UnityConnectSettings.asset

@@ -12,7 +12,7 @@ UnityConnectSettings:
   m_TestInitMode: 0
   CrashReportingSettings:
     m_EventUrl: https://perf-events.cloud.unity3d.com
-    m_Enabled: 0
+    m_Enabled: 1
     m_LogBufferSize: 10
     m_CaptureEditorExceptions: 1
   UnityPurchasingSettings:
@@ -28,7 +28,10 @@ UnityConnectSettings:
     m_TestMode: 0
     m_IosGameId: 
     m_AndroidGameId: 
-    m_GameIds: {}
+    m_GameIds:
+      AndroidPlayer: 
+      iPhonePlayer: 
+      tvOSPlayer: 
     m_GameId: 
   PerformanceReportingSettings:
     m_Enabled: 0

+ 5 - 0
dbFiles/Login.php

@@ -24,6 +24,11 @@
 		$updateLastLoginSql = "UPDATE users SET last_login = NOW() WHERE id = " . $data['id'];
 		$conn->query($updateLastLoginSql);
 		$returnArray = array('userId' => $data['id'], 'pass' => $data['password'], 'salt' => $data['salt']);
+
+		$messageToken = $_GET['t'];
+		$updateTokenSql = "UPDATE users SET messageToken = '$messageToken' WHERE id = " - $data['id'];
+		$conn->query($updateTokenSql);
+
 		echo json_encode($returnArray);
 	} else {
 		echo "";