-
-
Save NomadWithoutAHome/172a29e506a50c1f80fc5848ac186bf9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Threading.Tasks; | |
| using DeviceConnection; | |
| using Firebase; | |
| using Firebase.Firestore; | |
| using UnityEngine; | |
| using UnityEngine.Events; | |
| namespace SailApi | |
| { | |
| // Token: 0x020001BC RID: 444 | |
| public class Api | |
| { | |
| // Token: 0x06000A69 RID: 2665 RVA: 0x0000EAD1 File Offset: 0x0000CCD1 | |
| private Api() | |
| { | |
| } | |
| // Token: 0x170000AE RID: 174 | |
| // (get) Token: 0x06000A6A RID: 2666 RVA: 0x00016666 File Offset: 0x00014866 | |
| public static Api Instance | |
| { | |
| get | |
| { | |
| Api.instance.Initialize(); | |
| return Api.instance; | |
| } | |
| } | |
| // Token: 0x06000A6B RID: 2667 RVA: 0x00045E38 File Offset: 0x00044038 | |
| public void Initialize() | |
| { | |
| FirebaseApp.Create(new AppOptions | |
| { | |
| ApiKey = Api.FB_API_KEY, | |
| AppId = Api.FB_APP_ID, | |
| ProjectId = Api.FB_PROJECT_ID, | |
| StorageBucket = Api.FB_STORAGE_BUCKET, | |
| MessageSenderId = Api.FB_MESSAGE_SENDER_ID | |
| }); | |
| this.db = FirebaseFirestore.DefaultInstance; | |
| } | |
| // Token: 0x06000A6C RID: 2668 RVA: 0x00016677 File Offset: 0x00014877 | |
| public void SetPlayer(PlayerInfo player) | |
| { | |
| this.SetDocument(PlayerInfo.COLLECTION_KEY, player.GetPlayerId(), player.GetData()); | |
| } | |
| // Token: 0x06000A6D RID: 2669 RVA: 0x00016690 File Offset: 0x00014890 | |
| public void UpdatePlayer(PlayerInfo player) | |
| { | |
| this.UpdateDocument(PlayerInfo.COLLECTION_KEY, player.GetPlayerId(), player.GetData()); | |
| } | |
| // Token: 0x06000A6E RID: 2670 RVA: 0x00045E94 File Offset: 0x00044094 | |
| public async void GetPlayer(string playerId, UnityAction<PlayerInfo> action) | |
| { | |
| UnityAction<PlayerInfo> unityAction = action; | |
| Dictionary<string, object> dictionary = await this.GetDocumentDictionary(PlayerInfo.COLLECTION_KEY, playerId); | |
| unityAction(new PlayerInfo(dictionary)); | |
| unityAction = null; | |
| } | |
| // Token: 0x06000A6F RID: 2671 RVA: 0x00045EDC File Offset: 0x000440DC | |
| public async void GetPlayersByName(string name, UnityAction<List<PlayerInfo>> action) | |
| { | |
| UnityAction<List<PlayerInfo>> unityAction = action; | |
| List<PlayerInfo> list = await this.GetPlayersByProperty(PlayerInfo.NAME, name, 100, null); | |
| unityAction(list); | |
| unityAction = null; | |
| } | |
| // Token: 0x06000A70 RID: 2672 RVA: 0x00045F24 File Offset: 0x00044124 | |
| public async void GetPlayersByName(string name, PlayerInfo startAfter, UnityAction<List<PlayerInfo>> action) | |
| { | |
| UnityAction<List<PlayerInfo>> unityAction = action; | |
| List<PlayerInfo> list = await this.GetPlayersByProperty(PlayerInfo.NAME, name, 100, startAfter.GetData()); | |
| unityAction(list); | |
| unityAction = null; | |
| } | |
| // Token: 0x06000A71 RID: 2673 RVA: 0x000166A9 File Offset: 0x000148A9 | |
| public void GetPlayerByDeviceUserId(string deviceUserId, DeviceModel model, UnityAction<PlayerInfo> action) | |
| { | |
| if (model == DeviceModel.OCULUS) | |
| { | |
| this.GetPlayerByOculusId(deviceUserId, action); | |
| return; | |
| } | |
| if (model == DeviceModel.STEAM) | |
| { | |
| this.GetPlayerBySteamId(deviceUserId, action); | |
| return; | |
| } | |
| if (model == DeviceModel.PICO) | |
| { | |
| this.GetPlayerByPicoId(deviceUserId, action); | |
| return; | |
| } | |
| if (model == DeviceModel.EDITOR) | |
| { | |
| this.GetPlayerByEditorId(deviceUserId, action); | |
| } | |
| } | |
| // Token: 0x06000A72 RID: 2674 RVA: 0x00045F74 File Offset: 0x00044174 | |
| public async void GetPlayerByOculusId(string oculusId, UnityAction<PlayerInfo> action) | |
| { | |
| UnityAction<PlayerInfo> unityAction = action; | |
| PlayerInfo playerInfo = await this.GetPlayerByProperty(PlayerInfo.OCULUS_ID, oculusId); | |
| unityAction(playerInfo); | |
| unityAction = null; | |
| } | |
| // Token: 0x06000A73 RID: 2675 RVA: 0x00045FBC File Offset: 0x000441BC | |
| public async void GetPlayerBySteamId(string steamId, UnityAction<PlayerInfo> action) | |
| { | |
| UnityAction<PlayerInfo> unityAction = action; | |
| PlayerInfo playerInfo = await this.GetPlayerByProperty(PlayerInfo.STEAM_ID, steamId); | |
| unityAction(playerInfo); | |
| unityAction = null; | |
| } | |
| // Token: 0x06000A74 RID: 2676 RVA: 0x00046004 File Offset: 0x00044204 | |
| public async void GetPlayerByPicoId(string picoId, UnityAction<PlayerInfo> action) | |
| { | |
| UnityAction<PlayerInfo> unityAction = action; | |
| PlayerInfo playerInfo = await this.GetPlayerByProperty(PlayerInfo.PICO_ID, picoId); | |
| unityAction(playerInfo); | |
| unityAction = null; | |
| } | |
| // Token: 0x06000A75 RID: 2677 RVA: 0x0004604C File Offset: 0x0004424C | |
| public async void GetPlayerByEditorId(string editorId, UnityAction<PlayerInfo> action) | |
| { | |
| UnityAction<PlayerInfo> unityAction = action; | |
| PlayerInfo playerInfo = await this.GetPlayerByProperty(PlayerInfo.EDITOR_ID, editorId); | |
| unityAction(playerInfo); | |
| unityAction = null; | |
| } | |
| // Token: 0x06000A76 RID: 2678 RVA: 0x00046094 File Offset: 0x00044294 | |
| public async void GetPlayerByFirst8DigitsOfPlayerId(string first8digitsPlayerId, UnityAction<PlayerInfo> action) | |
| { | |
| IEnumerator<DocumentSnapshot> enumerator = (await this.db.Collection(PlayerInfo.COLLECTION_KEY).WhereGreaterThanOrEqualTo(PlayerInfo.PLAYER_ID, first8digitsPlayerId).Limit(1) | |
| .GetSnapshotAsync(Source.Default)).Documents.GetEnumerator(); | |
| if (enumerator.MoveNext()) | |
| { | |
| action(new PlayerInfo(enumerator.Current.ToDictionary(ServerTimestampBehavior.None))); | |
| } | |
| else | |
| { | |
| action(null); | |
| } | |
| } | |
| // Token: 0x06000A77 RID: 2679 RVA: 0x000460DC File Offset: 0x000442DC | |
| public async Task<PlayerInfo> GetPlayerByProperty(string property, string matchTarget) | |
| { | |
| PlayerInfo playerInfo; | |
| try | |
| { | |
| IEnumerator<DocumentSnapshot> enumerator = (await this.db.Collection(PlayerInfo.COLLECTION_KEY).WhereEqualTo(property, matchTarget).Limit(1) | |
| .GetSnapshotAsync(Source.Default)).Documents.GetEnumerator(); | |
| if (enumerator.MoveNext()) | |
| { | |
| playerInfo = new PlayerInfo(enumerator.Current.ToDictionary(ServerTimestampBehavior.None)); | |
| } | |
| else | |
| { | |
| playerInfo = null; | |
| } | |
| } | |
| catch (Exception ex) | |
| { | |
| this.LogError(ex.Message); | |
| playerInfo = null; | |
| } | |
| return playerInfo; | |
| } | |
| // Token: 0x06000A78 RID: 2680 RVA: 0x00046130 File Offset: 0x00044330 | |
| public async Task<List<PlayerInfo>> GetPlayersByProperty(string property, string matchTarget, int limit, Dictionary<string, object> startAfterData = null) | |
| { | |
| QuerySnapshot querySnapshot = await this.db.Collection(PlayerInfo.COLLECTION_KEY).WhereEqualTo(property, matchTarget).Limit(limit) | |
| .OrderBy(property) | |
| .StartAfter(new object[] { startAfterData }) | |
| .GetSnapshotAsync(Source.Default); | |
| List<PlayerInfo> list = new List<PlayerInfo>(); | |
| foreach (DocumentSnapshot documentSnapshot in querySnapshot.Documents) | |
| { | |
| list.Add(new PlayerInfo(documentSnapshot.ToDictionary(ServerTimestampBehavior.None))); | |
| } | |
| return list; | |
| } | |
| // Token: 0x06000A79 RID: 2681 RVA: 0x00046194 File Offset: 0x00044394 | |
| public async Task<List<PlayerInfo>> GetNewPlayersByProperty(string property, string matchTarget, int limit, Dictionary<string, object> startAfterData = null) | |
| { | |
| QuerySnapshot querySnapshot = await this.db.Collection(PlayerInfo.COLLECTION_KEY).WhereEqualTo(property, matchTarget).Limit(limit) | |
| .OrderBy(property) | |
| .StartAfter(new object[] { startAfterData }) | |
| .GetSnapshotAsync(Source.Default); | |
| List<PlayerInfo> list = new List<PlayerInfo>(); | |
| foreach (DocumentSnapshot documentSnapshot in querySnapshot.Documents) | |
| { | |
| list.Add(new PlayerInfo(documentSnapshot.ToDictionary(ServerTimestampBehavior.None))); | |
| } | |
| return list; | |
| } | |
| // Token: 0x06000A7A RID: 2682 RVA: 0x000461F8 File Offset: 0x000443F8 | |
| public async Task<List<PlayerInfo>> GetAllPlayers(string property, int limit, Dictionary<string, object> startAfterData = null) | |
| { | |
| QuerySnapshot querySnapshot = await this.db.Collection(PlayerInfo.COLLECTION_KEY).Limit(limit).OrderBy(property) | |
| .StartAfter(new object[] { startAfterData }) | |
| .GetSnapshotAsync(Source.Default); | |
| List<PlayerInfo> list = new List<PlayerInfo>(); | |
| foreach (DocumentSnapshot documentSnapshot in querySnapshot.Documents) | |
| { | |
| list.Add(new PlayerInfo(documentSnapshot.ToDictionary(ServerTimestampBehavior.None))); | |
| } | |
| return list; | |
| } | |
| // Token: 0x06000A7B RID: 2683 RVA: 0x00046254 File Offset: 0x00044454 | |
| public async void GetTotalPlayerCount(UnityAction<long> action) | |
| { | |
| AggregateQuerySnapshot aggregateQuerySnapshot = await this.db.Collection(PlayerInfo.COLLECTION_KEY).Count.GetSnapshotAsync(AggregateSource.Server); | |
| action(aggregateQuerySnapshot.Count); | |
| } | |
| // Token: 0x06000A7C RID: 2684 RVA: 0x00046294 File Offset: 0x00044494 | |
| public async void GetServerInfo(UnityAction<ServerInfo> onServerInfoUpdate) | |
| { | |
| DocumentSnapshot documentSnapshot = await this.db.Collection(ServerInfo.COLLECTION_KEY).Document(ServerInfo.DOCUMENT_KEY).GetSnapshotAsync(Source.Default); | |
| onServerInfoUpdate(new ServerInfo(documentSnapshot.ToDictionary(ServerTimestampBehavior.None))); | |
| } | |
| // Token: 0x06000A7D RID: 2685 RVA: 0x000462D4 File Offset: 0x000444D4 | |
| public async void GetPrivateServerInfo(UnityAction<ServerInfo> onServerInfoUpdate) | |
| { | |
| DocumentSnapshot documentSnapshot = await this.db.Collection(ServerInfo.COLLECTION_KEY).Document(ServerInfo.PRIVATE_ROOM_DOCUMENT_KEY).GetSnapshotAsync(Source.Default); | |
| onServerInfoUpdate(new ServerInfo(documentSnapshot.ToDictionary(ServerTimestampBehavior.None))); | |
| } | |
| // Token: 0x06000A7E RID: 2686 RVA: 0x00046314 File Offset: 0x00044514 | |
| public async Task<Dictionary<string, object>> GetAllPrivateServers() | |
| { | |
| return (await this.db.Collection(ServerInfo.COLLECTION_KEY).Document(ServerInfo.PRIVATE_ROOM_DOCUMENT_KEY).GetSnapshotAsync(Source.Default)).ToDictionary(ServerTimestampBehavior.None); | |
| } | |
| // Token: 0x06000A7F RID: 2687 RVA: 0x000166DD File Offset: 0x000148DD | |
| public void UpdateServerInfo(ServerInfo serverInfo) | |
| { | |
| this.UpdateDocument(ServerInfo.COLLECTION_KEY, ServerInfo.DOCUMENT_KEY, serverInfo.GetData()); | |
| } | |
| // Token: 0x06000A80 RID: 2688 RVA: 0x000166F5 File Offset: 0x000148F5 | |
| public void UpdatePrivateServerInfo(ServerInfo serverInfo) | |
| { | |
| this.UpdateDocument(ServerInfo.COLLECTION_KEY, ServerInfo.PRIVATE_ROOM_DOCUMENT_KEY, serverInfo.GetData()); | |
| } | |
| // Token: 0x06000A81 RID: 2689 RVA: 0x00046358 File Offset: 0x00044558 | |
| public async void GetCrew(string crewId, UnityAction<CrewInfo> action) | |
| { | |
| UnityAction<CrewInfo> unityAction = action; | |
| Dictionary<string, object> dictionary = await this.GetDocumentDictionary(CrewInfo.COLLECTION_ID, CrewInfo.CREW_ID); | |
| unityAction(new CrewInfo(dictionary)); | |
| unityAction = null; | |
| } | |
| // Token: 0x06000A82 RID: 2690 RVA: 0x0001670D File Offset: 0x0001490D | |
| public void UpdateCrew(CrewInfo crewInfo) | |
| { | |
| this.UpdateDocument(CrewInfo.COLLECTION_ID, crewInfo.GetCrewId(), crewInfo.GetData()); | |
| } | |
| // Token: 0x06000A83 RID: 2691 RVA: 0x00016726 File Offset: 0x00014926 | |
| public void SetCrew(CrewInfo crewInfo) | |
| { | |
| this.SetDocument(CrewInfo.COLLECTION_ID, crewInfo.GetCrewId(), crewInfo.GetData()); | |
| } | |
| // Token: 0x06000A84 RID: 2692 RVA: 0x00046398 File Offset: 0x00044598 | |
| public async void GetAppInfo(UnityAction<AppInfo> action) | |
| { | |
| if (this.cachedAppInfo == null) | |
| { | |
| Dictionary<string, object> dictionary = await this.GetDocumentDictionary(AppInfo.COLLECTION_ID, AppInfo.DOCUMENT_ID); | |
| this.cachedAppInfo = new AppInfo(dictionary); | |
| action(this.cachedAppInfo); | |
| } | |
| else | |
| { | |
| action(this.cachedAppInfo); | |
| } | |
| } | |
| // Token: 0x06000A85 RID: 2693 RVA: 0x000463D8 File Offset: 0x000445D8 | |
| public void SetDocument(string collectionID, string documentID, Dictionary<string, object> document) | |
| { | |
| this.db.Collection(collectionID).Document(documentID).SetAsync(document, null) | |
| .ContinueWith(delegate(Task task) | |
| { | |
| this.LogRequest("Set", collectionID, documentID); | |
| }); | |
| } | |
| // Token: 0x06000A86 RID: 2694 RVA: 0x00046438 File Offset: 0x00044638 | |
| public async void UpdateDocument(string collectionID, string documentID, Dictionary<string, object> document) | |
| { | |
| await this.db.Collection(collectionID).Document(documentID).UpdateAsync(document) | |
| .ContinueWith(delegate(Task task) | |
| { | |
| this.LogRequest("Update", collectionID, documentID); | |
| if (task.IsFaulted) | |
| { | |
| this.LogRequestError("Update FAILED", collectionID, documentID); | |
| } | |
| }); | |
| } | |
| // Token: 0x06000A87 RID: 2695 RVA: 0x00046488 File Offset: 0x00044688 | |
| public void DeleteDocumentField(string collectionId, string documentID, string fieldName) | |
| { | |
| DocumentReference documentReference = this.db.Collection(collectionId).Document(documentID); | |
| Dictionary<string, object> dictionary = new Dictionary<string, object> { | |
| { | |
| fieldName, | |
| FieldValue.Delete | |
| } }; | |
| documentReference.UpdateAsync(dictionary).ContinueWith(delegate(Task contAction) | |
| { | |
| this.LogRequest(string.Format("Delete Field - {0}", contAction), collectionId, documentID); | |
| }); | |
| } | |
| // Token: 0x06000A88 RID: 2696 RVA: 0x000464F8 File Offset: 0x000446F8 | |
| public void DeleteDocumentFields(string collectionId, string documentID, string[] fieldNames) | |
| { | |
| if (fieldNames.Length == 0) | |
| { | |
| return; | |
| } | |
| DocumentReference documentReference = this.db.Collection(collectionId).Document(documentID); | |
| Dictionary<string, object> dictionary = new Dictionary<string, object>(); | |
| foreach (string text in fieldNames) | |
| { | |
| dictionary.Add(text, FieldValue.Delete); | |
| } | |
| documentReference.UpdateAsync(dictionary).ContinueWith(delegate(Task contAction) | |
| { | |
| this.LogRequest(string.Format("Delete Field - {0}", contAction), collectionId, documentID); | |
| }); | |
| } | |
| // Token: 0x06000A89 RID: 2697 RVA: 0x00046588 File Offset: 0x00044788 | |
| public void DeleteDocument(string collectionID, string documentID) | |
| { | |
| this.db.Collection(collectionID).Document(documentID).DeleteAsync() | |
| .ContinueWith(delegate(Task task) | |
| { | |
| this.LogRequest("Delete", collectionID, documentID); | |
| }); | |
| } | |
| // Token: 0x06000A8A RID: 2698 RVA: 0x0001673F File Offset: 0x0001493F | |
| public DocumentReference GetDocumentRef(string collectionID, string documentID) | |
| { | |
| return this.db.Collection(collectionID).Document(documentID); | |
| } | |
| // Token: 0x06000A8B RID: 2699 RVA: 0x000465E4 File Offset: 0x000447E4 | |
| public async Task<DocumentSnapshot> GetDocumentSnapshot(string collectionID, string documentID) | |
| { | |
| return await this.db.Collection(collectionID).Document(documentID).GetSnapshotAsync(Source.Default); | |
| } | |
| // Token: 0x06000A8C RID: 2700 RVA: 0x00046638 File Offset: 0x00044838 | |
| public async Task<Dictionary<string, object>> GetDocumentDictionary(string collectionID, string documentID) | |
| { | |
| return (await this.db.Collection(collectionID).Document(documentID).GetSnapshotAsync(Source.Default)).ToDictionary(ServerTimestampBehavior.None); | |
| } | |
| // Token: 0x06000A8D RID: 2701 RVA: 0x0004668C File Offset: 0x0004488C | |
| private void LogRequest(string action, string collectionID, string documentID) | |
| { | |
| if (this.DEBUG) | |
| { | |
| Debug.Log(string.Concat(new string[] { "[API] (", action, ") ", documentID, " document, ", collectionID, " collection." })); | |
| } | |
| } | |
| // Token: 0x06000A8E RID: 2702 RVA: 0x000466E0 File Offset: 0x000448E0 | |
| private void LogRequestError(string action, string collectionID, string documentID) | |
| { | |
| if (this.DEBUG) | |
| { | |
| Debug.LogError(string.Concat(new string[] { "[API] (", action, ") ", documentID, " document, ", collectionID, " collection." })); | |
| } | |
| } | |
| // Token: 0x06000A8F RID: 2703 RVA: 0x00016753 File Offset: 0x00014953 | |
| private void Log(string msg) | |
| { | |
| Debug.Log("[API] " + msg); | |
| } | |
| // Token: 0x06000A90 RID: 2704 RVA: 0x00016765 File Offset: 0x00014965 | |
| private void LogError(string msg) | |
| { | |
| Debug.LogError("[API] " + msg); | |
| } | |
| // Token: 0x04000BA7 RID: 2983 | |
| private static readonly string FB_API_KEY = "AIzaSyAD8HlftiTdxGbiraldZx0RS2Qn8vMiKOA"; | |
| // Token: 0x04000BA8 RID: 2984 | |
| private static readonly string FB_APP_ID = "1:198422519604:android:76db2b4504aabeec554f61"; | |
| // Token: 0x04000BA9 RID: 2985 | |
| private static readonly string FB_MESSAGE_SENDER_ID = "mystical-mote-389916"; | |
| // Token: 0x04000BAA RID: 2986 | |
| private static readonly string FB_PROJECT_ID = "mystical-mote-389916"; | |
| // Token: 0x04000BAB RID: 2987 | |
| private static readonly string FB_STORAGE_BUCKET = "mystical-mote-389916.appspot.com"; | |
| // Token: 0x04000BAC RID: 2988 | |
| private static readonly Api instance = new Api(); | |
| // Token: 0x04000BAD RID: 2989 | |
| private FirebaseFirestore db; | |
| // Token: 0x04000BAE RID: 2990 | |
| public bool DEBUG; | |
| // Token: 0x04000BAF RID: 2991 | |
| private AppInfo cachedAppInfo; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment