DiscoverTenerife
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
firebaseHandler Class Reference

the part of the class firebaseHandler that controls the downloading operations More...

Inheritance diagram for firebaseHandler:

Public Member Functions

void downloadFriendData (string uid)
 this method tries to download the necesary information of the given user id. If it fails on the process it adds the user id to the friendDataDownloadQueue_ list. If it success it calls the addFriendData method of UserData class creating a new FriendData object. More...
 
void readUserData ()
 This method download all the information that is releated to the user from the firebase database. More...
 
void downloadRankingPlayerData ()
 This method downloads all the data what will be shown on the players ranking and store it as a RankingPlayerData object on the rankingData_ list. It changes the downloadingRankingData_ attribute to reflect the current state of the download. More...
 
bool internetConnection ()
 
bool FirebaseDependenciesAreResolved ()
 
void CreateNewUser (string email, string password)
 
bool cooldownVisitingPlaceFinished (string type, int id)
 This method returns true if the place with the given type and id is ready for a new visit. The cooldown time is defined on the class gameRules, check that class for more information. More...
 
bool cooldownVisitingStoredPlaceFinished (StoredPlace storedPlace)
 This method returns true if the place with the given type and id is ready for a new visit. The cooldown time is defined on the class gameRules, check that class for more information. More...
 
bool cooldownVisitingPlaceByNameFinished (string name)
 This method returns true if the place with the given name is ready for a new visit. The cooldown time is defined on the class gameRules, check that class for more information. You have to be aware that its possible that two places has the same name, on that case, it will check only the first one. More...
 
void userVisitedPlace (string type, int id, long timeOfTheVisit=-1)
 This method register a new visit for the place with the given type and id and the given timestamp, if the given timestamp is negative it will use the current timestamp. It also calls the writePlaceData and the writeUserData methods to upload the new visit information to the database. More...
 
void userVisitedPlaceByName (string name, long timeOfTheVisit=-1)
 This method search on all the places the first one who match the given name, and then, it calls the userVisitedPlace method, check that method for more information. You have to be aware that if two places has the same name, the new visit will be added only to the first one. More...
 
bool hasUserVisitPlaceByName (string name)
 This method search on the places that the current user has visited and check if there is at least one place with that name, on that case it returns true, it returns false in other case. More...
 
Place askForAPlace ()
 This method calls askForAPlace method of requestHandler and returns the place that that method returns. If you want more information check the requestHandler documentation. This method also instanciate a requestHandler if it doesnt exists when its called. More...
 
bool placesAreReady ()
 
bool userDataIsReady ()
 
void sortPlaces ()
 this method calls the sortPlaces method of the requestHandler class. Check that class documentation to get more information. More...
 
Dictionary< string, string > findPlaceByName (string name)
 this method returns a dictionary that contains the id and the type of the place that has the given name. If there isn't any place with that name, it will return a dictionary that contains two entries id with the string "-1" and type with the string "noType". If there is more than one place with the given name, only the first one will be returned. More...
 
int totalOfPlaces ()
 getter of the quantity of places More...
 
int totalOfPlacesOfZone (string zone)
 this method counts all the places that have the given zone name on their zone_ property. If there is no places on the given zone, it will show a message on the console and return a 0. The valid zones are determinated on the mapRulesHandler class, check its documentation for more information. More...
 
Dictionary< string, string > getPlaceData (string type, string id)
 This method search on the property allPlaces_ if there is a place with the given type and id. If there isn't any place that match both the given id and the given type, it will return null. More...
 
void SearchOtherUserByName (string toSearch, string type, SearchBar toAdvise=null)
 This method tries to find other user on the list of users that allow be found by other users on the different types of searchs. If a SearchBar object is given it will call the resultsOfTheSearch method of that class with a dictionary version of the found user. More...
 
void sendFriendshipInvitation (string uidToInvite, SearchedPlayer searchedPlayerToAdvice)
 This method tries to send a new friendship invitation of the current user to the user that has the given id. The sending can produce three states: More...
 
void askForNewPlaces ()
 This method calls the updateStartIndex method of the requestHandler class to make the requestHandler choose new places. More...
 
void addOtherUserScoreToUpload (Dictionary< string, string > uidAndScore)
 This method adds the given dictionary to the otherUserScoresToUpload_ list. More...
 
bool isRankingDataComplete ()
 This method returns true if all the data of the users that appeard on the ranking is already downloaded, false in other case. More...
 
bool isDownloadingRankingDataNow ()
 getter of the downloadingRankingData_ property. More...
 
RankingPlayerData getRankingPlayerDataById (string uid)
 This method returns the RankingPlayerData object with the data of the player who has the given user id. It would return null if there isnt any player with that id. More...
 
List< RankingPlayerDatagetRankingPlayerData ()
 Getter of the rankingData_ propery. More...
 
void sortRankingDataList ()
 This method sorts the users that appeard on the ranking. It sorts them setting on the firsts positions users with the highers scores. It also updates the top_ property of the RankingPlayerData objects of the lists using the setTop method. More...
 
void LoginUser (string email, string password)
 
void AnonymousUser ()
 
void SignInWithGoogle ()
 This method will be called when the google signin button is pressed, it start the google authentication process calling the method OnAuthenticationFinished when it finish. More...
 
void LogOut ()
 
void writeNewPlaceOnDataBase (Place place, string type, int placeID)
 
void writePlaceData (string type, string id)
 This method uploads the data from the place that matches the given type and id. If the upload fails it adds the information of the place to placesToUploadQueue_. More...
 
void updateUserDeleteAFriend (string noFriendUid, string deletedFriendsListInJSON)
 This method must be called when there is internet connection, otherwise it wont to nothing. This method upload the deletedFriends property of the user that has the given id. More...
 
void uploadFriendChallengesOf (FriendData friendDataToUpload)
 this method upload the challengue list of the given user. More...
 
void uploadSocialPreferences ()
 this method should be called either when there is changes on the current user's social preferences or the last changes couldnt been uploaded on the past. It checks if there is any change on the three permision and upload to the firebase database the changes on the preferences. It checks if the three lists are uploaded, if one or more of them fails on the uploading, it puts the hasToUploadSocialPreferences_ property to true, so this method will be called again when the internet connection is ready. More...
 
void updateUserAddedAFriend (string friendUid, string acceptedFriendsInvitationsListInJSON)
 This method tries to upload the accepted friendships invitations list of the given user. If it complete it succesfully, it removes the friendUid of the list of the user that need to be notified with the hasBeenNotified method. It also sets the uploadingNotifications_ property as true but when the try of updating finish, in any way, it sets the uploadingNotifications_ property as false. More...
 
void writeAllFriendProperties ()
 This method calls the writeFriendProperty with each element of the otherUsersPropertiesToUpload_ list and it removes the each of those elements taking care of that each of those elements could enter again on the list. That could happen if the upload goes wrong. More...
 
void writeFriendProperty (string userId, string property, string json)
 This method downloads the current information of the given property of the given friend and then calls the correct method for taking care of differences between the cloud information and the local information. More...
 
void writeAllUserProperties ()
 This method calls writeSafeProperties with each safe property and writeUnsafeProperty with each unsafe property of the current user. It uses the getJSONof method of UserData class. More...
 
void writeQueuedUserProperties ()
 this method calls the writeSafeProperties or writeUnsafeProperty depending of the type of each element that is stored in currentUserPropertiesToUpload_ list. It removes the elements wich it calls those methods taking care of the fact that those properties could enter again on the currentUserPropertiesToUpload_ list if they fail on the upload. More...
 
void writeSafeProperties (string property, string json)
 this method writes on the given property on the database the given json value. It doesnt take care of the version that is on the database. It simply overwrite it. If something goes wrong during the upload, it adds the property to currentUserPropertiesToUpload_ again. More...
 
void writeUnsafeProperty (string property, string json)
 this method writes on the given property on the database the given json value. It takes care of the information that is currently on the database and tries to avoid incongruencies of the database. If something goes wrong during the uploading it adds again the property to the currentUserPropertiesToUpload_ list. More...
 

Public Attributes

UserData currentUser_ = null
 
requestHandler requestHandler_
 

Static Public Attributes

static firebaseHandler firebaseHandlerInstance_ = null
 

Private Member Functions

void downloadAllFriendData ()
 this method calls the downloadFriendData method with each user id that is on the friendDataDownloadQueue_. More...
 
void downloadAllNewfriendsInvitationsData ()
 This method calls downloadNewFriendInvitationData method with each of the user ids that are on the new friends invitations list of the current user. More...
 
void downloadNewFriendInvitationData (string uid)
 this method tries to download the display name and the list of newFriendsInvitations of the user that matches the given user id. If its fails it adds the user id to the newFriendDataDownloadQueue_ list and if its success, its calls the addNewFriendData method of UserData. More...
 
void downloadAllPlaces ()
 This method start as many coroutines as types of places are defined on mapRulesHandler. Each coroutine will download the information of that type of place. If you want more information check the mapRulesHandler documentation and the downloadOneTypeOfSite method of this class. More...
 
IEnumerator downloadOneTypeOfSite (string typeSite)
 This coroutine tries to download all the places of the given type. If there is no internet connection it waits until there is avaible again. When all the places of all types has already downloaded it sets ON the placesReady_ flag. More...
 
void downloadUsersPermissionsLists ()
 This method download the lists of the user social permissions. They are usersThatAllowFriendshipInvitations, usersThatAllowBeChallenged and usersThatAllowAppearedOnRanking. The downloadingAnyOfTheUsersPermissionsLists_ is set as a true. The social permissions are downloaded in a parallel way for searching more efficiency if some of them failed the downloadingAnyOfTheUsersPermissionsLists_ property will be set as false again. More...
 
void Awake ()
 
void Update ()
 
void CheckDependenciesFirebase (Task< DependencyStatus > task)
 
void OnApplicationQuit ()
 This method is called when the application is closed, it saves all the offline information and stop the firebase online services. More...
 
void OnDestroy ()
 This method is called when the firebaseHandler object is destroyed. More...
 
void OnSceneLoaded (Scene scene, LoadSceneMode mode)
 This method is called each time a scene is loaded, if placesReady_ variable is true, it calls the useStartIndex method of the requestHandler object, to allow keeping with same places. More...
 
void uploadPlacesQueue ()
 this method tries to upload all the information that is on the placesToUpdateQueue_ property. If it success, it erase the place from the list, but if its fails the writePlaceData will add again the place to the queue. More...
 
void uploadOtherUserScores ()
 This method tries to upload the information of the first element of otherUserScoresToUpload_ list, it removes the first element just before of trying to upload it. If it fails on the uploading, it adds again the dictionary with the information to the otherUserScoresToUpload_ list. The information it uploads is the the earnedScore_ to the user id. More...
 
void writeFriendChallenges (string userId, string jsonLocal, string jsonCloud)
 This method compares the challenge list of the given user to upload correctly the information taking care of the differences between the local version and the cloud version. If something goes wrong it adds again the challenge property to the otherUsersPropertiesToUpload_ list. More...
 
void writeFriendDeletedFriends (string userId, string jsonLocal, string jsonCloud)
 This method compares the deletedFriend list of the given user to upload correctly the information taking care of the differences between the local version and the cloud version. If something goes wrong it adds again the deletedFriend property to the otherUsersPropertiesToUpload_ list. More...
 
void writeFriendAcceptedFriendsInvitations (string userId, string jsonLocal, string jsonCloud)
 This method compares the friendInvitations list of the given user to upload correctly the information taking care of the differences between the local version and the cloud version. If something goes wrong it adds again the friendInvitations property to the otherUsersPropertiesToUpload_ list. More...
 

Private Attributes

FirebaseApp firebaseApp = null
 Reference to the FirebaseApp object. More...
 
GoogleSignInConfiguration configuration
 
bool firebaseDependenciesResolved = false
 
bool firebaseDependenciesRunning = false
 
bool placesReady_ = false
 
bool userDataReady_ = false
 
Dictionary< string, Dictionary< string, Dictionary< string, string > > > allPlaces_ = new Dictionary<string,Dictionary<string,Dictionary<string,string>>>()
 
List< Dictionary< string, string > > placesToUpdateQueue_
 
List< string > friendDataDownloadQueue_
 
List< string > newFriendDataDownloadQueue_
 
bool downloadingAnyOfTheUsersPermissionsLists_
 true if it is trying to download any of the user permissions lists right now. false in other case. More...
 
bool hasToUploadSocialPreferences_
 true if there is changes on the social preferences that should be uploaded. More...
 
List< Dictionary< string, string > > otherUserScoresToUpload_
 List of dictionary strings with the user id and the score of that user that needs to be uploaded. More...
 
bool uploadingNotifications_
 Boolean that is used as a flag that indicates if the uploading of the acceptedFriendsInvitations property of a friend is uploading right now. More...
 
List< RankingPlayerDatarankingData_
 List with all the data that is showed on the ranking screen. It has a RankingPlayerData object for each player that appear on the ranking. More...
 
bool allowDownloadRankingData_
 Boolean that is used as a flag that indicates if its time to download all the ranking data. More...
 
bool downloadingRankingData_
 Boolean that is used as a flag that indicates if the ranking data is downloaded right now. More...
 
List< Dictionary< string, string > > otherUsersPropertiesToUpload_
 
List< string > currentUserPropertiesToUpload_
 

Detailed Description

the part of the class firebaseHandler that controls the downloading operations

the part of the class firebaseHandler that controls the uploading operations

the part of the class firebaseHandler that controls the login user, create user, and logout operations

This class follows the Singleton patron, so it only has one instance at the same time. The instance could be found on the firebaseHandlerInstance_ public static property. This class handles all the firebase releated methods like validating user, creating new users, downloading and uploading all the data from the database. This class is a partial class it has another 3 files: downloadHandler.cs, uploadHandler.cs and loginHandler.cs.

Member Function Documentation

◆ addOtherUserScoreToUpload()

void firebaseHandler.addOtherUserScoreToUpload ( Dictionary< string, string >  uidAndScore)

This method adds the given dictionary to the otherUserScoresToUpload_ list.

Parameters
Dictionary<string,string>with the information of the score and the user id that need to be uploaded.

◆ AnonymousUser()

void firebaseHandler.AnonymousUser ( )

This method tries to starts a session as an anonymous user, if it finish successfully it calls the downloading information methods and it also calls the anonymousUserLoginSucessfully method of the anonymousButtonHandler class.

◆ askForAPlace()

Place firebaseHandler.askForAPlace ( )

This method calls askForAPlace method of requestHandler and returns the place that that method returns. If you want more information check the requestHandler documentation. This method also instanciate a requestHandler if it doesnt exists when its called.

Returns
Place place that should be used next.

◆ askForNewPlaces()

void firebaseHandler.askForNewPlaces ( )

This method calls the updateStartIndex method of the requestHandler class to make the requestHandler choose new places.

◆ Awake()

void firebaseHandler.Awake ( )
private

The awake method is called before the first frame, it checks if other firebaseHandler was instanciated before, if that is the case, it destroy this object.

◆ CheckDependenciesFirebase()

void firebaseHandler.CheckDependenciesFirebase ( Task< DependencyStatus >  task)
private
Parameters
Task<DependencyStatus>task to wait and take its results This method creates the firebase object and check if there is a previous session, it there is login that sesion. It also calls the method that download the places information and the user data.

◆ cooldownVisitingPlaceByNameFinished()

bool firebaseHandler.cooldownVisitingPlaceByNameFinished ( string  name)

This method returns true if the place with the given name is ready for a new visit. The cooldown time is defined on the class gameRules, check that class for more information. You have to be aware that its possible that two places has the same name, on that case, it will check only the first one.

Parameters
stringthat contains the name of the place that you want to check if its ready to visit it again
Returns
bool with true if the cooldown for visiting the given place is finished, in other case, false.

◆ cooldownVisitingPlaceFinished()

bool firebaseHandler.cooldownVisitingPlaceFinished ( string  type,
int  id 
)

This method returns true if the place with the given type and id is ready for a new visit. The cooldown time is defined on the class gameRules, check that class for more information.

Parameters
stringwith the type of the place we want to check
intwith the id of the place we want to check
Returns
bool with true if the cooldown for visiting the given place is finished, in other case, false.

◆ cooldownVisitingStoredPlaceFinished()

bool firebaseHandler.cooldownVisitingStoredPlaceFinished ( StoredPlace  storedPlace)

This method returns true if the place with the given type and id is ready for a new visit. The cooldown time is defined on the class gameRules, check that class for more information.

Parameters
StoredPlacethe StoredPlace object that you want to check if you can visit it again.
Returns
bool with true if the cooldown for visiting the given place is finished, in other case, false.

◆ CreateNewUser()

void firebaseHandler.CreateNewUser ( string  email,
string  password 
)
Parameters
stringthat contains the new user email.
stringthat contains the new user password. This method tries to create a new user on the firebase backend with the given email and password.

◆ downloadAllFriendData()

void firebaseHandler.downloadAllFriendData ( )
private

this method calls the downloadFriendData method with each user id that is on the friendDataDownloadQueue_.

◆ downloadAllNewfriendsInvitationsData()

void firebaseHandler.downloadAllNewfriendsInvitationsData ( )
private

This method calls downloadNewFriendInvitationData method with each of the user ids that are on the new friends invitations list of the current user.

◆ downloadAllPlaces()

void firebaseHandler.downloadAllPlaces ( )
private

This method start as many coroutines as types of places are defined on mapRulesHandler. Each coroutine will download the information of that type of place. If you want more information check the mapRulesHandler documentation and the downloadOneTypeOfSite method of this class.

◆ downloadFriendData()

void firebaseHandler.downloadFriendData ( string  uid)

this method tries to download the necesary information of the given user id. If it fails on the process it adds the user id to the friendDataDownloadQueue_ list. If it success it calls the addFriendData method of UserData class creating a new FriendData object.

Parameters
stringthat contains the user id of the friend of the current user that you want to obtain data.

◆ downloadNewFriendInvitationData()

void firebaseHandler.downloadNewFriendInvitationData ( string  uid)
private

this method tries to download the display name and the list of newFriendsInvitations of the user that matches the given user id. If its fails it adds the user id to the newFriendDataDownloadQueue_ list and if its success, its calls the addNewFriendData method of UserData.

Parameters
stringthat contains the user id that you want to download the enough information for create the newFriendInvitation object.

◆ downloadOneTypeOfSite()

IEnumerator firebaseHandler.downloadOneTypeOfSite ( string  typeSite)
private

This coroutine tries to download all the places of the given type. If there is no internet connection it waits until there is avaible again. When all the places of all types has already downloaded it sets ON the placesReady_ flag.

Parameters
stringthat contains the type of the sites you want to download the information.

◆ downloadRankingPlayerData()

void firebaseHandler.downloadRankingPlayerData ( )

This method downloads all the data what will be shown on the players ranking and store it as a RankingPlayerData object on the rankingData_ list. It changes the downloadingRankingData_ attribute to reflect the current state of the download.

◆ downloadUsersPermissionsLists()

void firebaseHandler.downloadUsersPermissionsLists ( )
private

This method download the lists of the user social permissions. They are usersThatAllowFriendshipInvitations, usersThatAllowBeChallenged and usersThatAllowAppearedOnRanking. The downloadingAnyOfTheUsersPermissionsLists_ is set as a true. The social permissions are downloaded in a parallel way for searching more efficiency if some of them failed the downloadingAnyOfTheUsersPermissionsLists_ property will be set as false again.

◆ findPlaceByName()

Dictionary< string, string > firebaseHandler.findPlaceByName ( string  name)

this method returns a dictionary that contains the id and the type of the place that has the given name. If there isn't any place with that name, it will return a dictionary that contains two entries id with the string "-1" and type with the string "noType". If there is more than one place with the given name, only the first one will be returned.

Parameters
stringthat contains the name of the searched place
Returns
Dictionary<string,string> it contains two entries, id and type, they contains the id and the type of the place that matches the given name

◆ FirebaseDependenciesAreResolved()

bool firebaseHandler.FirebaseDependenciesAreResolved ( )

Getter of the flag that indicate that firebase dependencies are resolved or not.

◆ getPlaceData()

Dictionary< string, string > firebaseHandler.getPlaceData ( string  type,
string  id 
)

This method search on the property allPlaces_ if there is a place with the given type and id. If there isn't any place that match both the given id and the given type, it will return null.

Parameters
stringthat contains the type of the searched place.
stringthat contains the id of the searched place.
Returns
Dictionary<string, string> dictionary of strings that contains a string version of all the information of the searched place.

◆ getRankingPlayerData()

List< RankingPlayerData > firebaseHandler.getRankingPlayerData ( )

Getter of the rankingData_ propery.

Returns
List<RankingPlayerData> the whole rankingData_ property.

◆ getRankingPlayerDataById()

RankingPlayerData firebaseHandler.getRankingPlayerDataById ( string  uid)

This method returns the RankingPlayerData object with the data of the player who has the given user id. It would return null if there isnt any player with that id.

Parameters
stringthe user id of the user that you want to obtain the ranking data.
Returns
RankingPlayerData object with the data of the player who has the given user id.

◆ hasUserVisitPlaceByName()

bool firebaseHandler.hasUserVisitPlaceByName ( string  name)

This method search on the places that the current user has visited and check if there is at least one place with that name, on that case it returns true, it returns false in other case.

Parameters
stringthat contains the name of the place that you want to check if current user has visit or not.
Returns
bool true if user has visit a place with that name, false in other case.

◆ internetConnection()

bool firebaseHandler.internetConnection ( )

This method returns true only if there is internet connection, otherwise it will return false.

◆ isDownloadingRankingDataNow()

bool firebaseHandler.isDownloadingRankingDataNow ( )

getter of the downloadingRankingData_ property.

Returns
bool with the value of downloadingRankingData_ property.

◆ isRankingDataComplete()

bool firebaseHandler.isRankingDataComplete ( )

This method returns true if all the data of the users that appeard on the ranking is already downloaded, false in other case.

Returns
bool true if all the data of the users that appeard on the ranking is already downloaded, false in other case.

◆ LoginUser()

void firebaseHandler.LoginUser ( string  email,
string  password 
)
Parameters
stringthat contains the user email that will try to login with.
stringthat contains the user password that will try to login with. This method tries to start a sesion with the given email and password, if it finish successfully it will call the downloading information methods and also call the emailLoginController userLogedSuccessfully method.

◆ LogOut()

void firebaseHandler.LogOut ( )

This method end the current firebase user sesion.

◆ OnApplicationQuit()

void firebaseHandler.OnApplicationQuit ( )
private

This method is called when the application is closed, it saves all the offline information and stop the firebase online services.

◆ OnDestroy()

void firebaseHandler.OnDestroy ( )
private

This method is called when the firebaseHandler object is destroyed.

◆ OnSceneLoaded()

void firebaseHandler.OnSceneLoaded ( Scene  scene,
LoadSceneMode  mode 
)
private

This method is called each time a scene is loaded, if placesReady_ variable is true, it calls the useStartIndex method of the requestHandler object, to allow keeping with same places.

Parameters
Scenethe information of the scene it just has loaded.
LoadSceneModeobject that contains the information of the way that the scene was loaded.

◆ placesAreReady()

bool firebaseHandler.placesAreReady ( )
Returns
bool true if all the places are downloaded and ready to use.

◆ readUserData()

void firebaseHandler.readUserData ( )

This method download all the information that is releated to the user from the firebase database.

◆ SearchOtherUserByName()

void firebaseHandler.SearchOtherUserByName ( string  toSearch,
string  type,
SearchBar  toAdvise = null 
)

This method tries to find other user on the list of users that allow be found by other users on the different types of searchs. If a SearchBar object is given it will call the resultsOfTheSearch method of that class with a dictionary version of the found user.

Parameters
stringthat contains the displayName that you want to search
stringthat contains the reason of the search, it could be friend, chanllege or ranking. This reasons for the search has to be differenciated because users can allow or not be found by other users.
SearchBarobject that you want to advise when the search ends. This parameter is optional.

◆ sendFriendshipInvitation()

void firebaseHandler.sendFriendshipInvitation ( string  uidToInvite,
SearchedPlayer  searchedPlayerToAdvice 
)

This method tries to send a new friendship invitation of the current user to the user that has the given id. The sending can produce three states:

Parameters
stringthat contains the user id of the player that the current user want to send a new friendship invitation.
SearchedPlayerobject that handles the result of the sending
  • sended: all was OK and the invitation was sended successfully.
  • failed: the sending failed because there is no internet connection or other error.
  • repeated: the sending failed because that user already have an invitation of the current user.

◆ SignInWithGoogle()

void firebaseHandler.SignInWithGoogle ( )

This method will be called when the google signin button is pressed, it start the google authentication process calling the method OnAuthenticationFinished when it finish.

◆ sortPlaces()

void firebaseHandler.sortPlaces ( )

this method calls the sortPlaces method of the requestHandler class. Check that class documentation to get more information.

◆ sortRankingDataList()

void firebaseHandler.sortRankingDataList ( )

This method sorts the users that appeard on the ranking. It sorts them setting on the firsts positions users with the highers scores. It also updates the top_ property of the RankingPlayerData objects of the lists using the setTop method.

◆ totalOfPlaces()

int firebaseHandler.totalOfPlaces ( )

getter of the quantity of places

Returns
int with the total of places of types

◆ totalOfPlacesOfZone()

int firebaseHandler.totalOfPlacesOfZone ( string  zone)

this method counts all the places that have the given zone name on their zone_ property. If there is no places on the given zone, it will show a message on the console and return a 0. The valid zones are determinated on the mapRulesHandler class, check its documentation for more information.

Parameters
stringthat contains the name of a zone. Valid zones are determinated on mapRulesHandler class.
Returns
int the number of places that are on the given zone.

◆ Update()

void firebaseHandler.Update ( )
private

The Update method is called every frame. On this method this class constantly check:

  • If it has to resolve the firebase dependencies, on that case try to solve them first.
  • If the firebase dependencies has already been resolved, check if it has some information waiting for being uploaded or downloaded try if there is internet connection.

◆ updateUserAddedAFriend()

void firebaseHandler.updateUserAddedAFriend ( string  friendUid,
string  acceptedFriendsInvitationsListInJSON 
)

This method tries to upload the accepted friendships invitations list of the given user. If it complete it succesfully, it removes the friendUid of the list of the user that need to be notified with the hasBeenNotified method. It also sets the uploadingNotifications_ property as true but when the try of updating finish, in any way, it sets the uploadingNotifications_ property as false.

Parameters
stringuser id of the friend that has been acepted
stringwith the conversion of the accepted friendships invitations in JSON format.

◆ updateUserDeleteAFriend()

void firebaseHandler.updateUserDeleteAFriend ( string  noFriendUid,
string  deletedFriendsListInJSON 
)

This method must be called when there is internet connection, otherwise it wont to nothing. This method upload the deletedFriends property of the user that has the given id.

Parameters
stringthat contains the user that will has erased the friendship with the current user.
stringthat contains the deleted friends list of the user that has the given id in the JSON format.

◆ uploadFriendChallengesOf()

void firebaseHandler.uploadFriendChallengesOf ( FriendData  friendDataToUpload)

this method upload the challengue list of the given user.

Parameters
FriendDataobject that contains all the information releated to the user that own the challenges we want to upload.

◆ uploadOtherUserScores()

void firebaseHandler.uploadOtherUserScores ( )
private

This method tries to upload the information of the first element of otherUserScoresToUpload_ list, it removes the first element just before of trying to upload it. If it fails on the uploading, it adds again the dictionary with the information to the otherUserScoresToUpload_ list. The information it uploads is the the earnedScore_ to the user id.

◆ uploadPlacesQueue()

void firebaseHandler.uploadPlacesQueue ( )
private

this method tries to upload all the information that is on the placesToUpdateQueue_ property. If it success, it erase the place from the list, but if its fails the writePlaceData will add again the place to the queue.

◆ uploadSocialPreferences()

void firebaseHandler.uploadSocialPreferences ( )

this method should be called either when there is changes on the current user's social preferences or the last changes couldnt been uploaded on the past. It checks if there is any change on the three permision and upload to the firebase database the changes on the preferences. It checks if the three lists are uploaded, if one or more of them fails on the uploading, it puts the hasToUploadSocialPreferences_ property to true, so this method will be called again when the internet connection is ready.

◆ userDataIsReady()

bool firebaseHandler.userDataIsReady ( )
Returns
bool true if the user data is downloaded and ready to use.

◆ userVisitedPlace()

void firebaseHandler.userVisitedPlace ( string  type,
int  id,
long  timeOfTheVisit = -1 
)

This method register a new visit for the place with the given type and id and the given timestamp, if the given timestamp is negative it will use the current timestamp. It also calls the writePlaceData and the writeUserData methods to upload the new visit information to the database.

Parameters
stringthat contains the type of the place that current user has visited and you want to register that visit.
intthat contains the id of the place that current user has visited and you want to register that visit.
longthat contains the timestamp of the visit, the default value is -1. A negative value means that you want to use the current timestamp not the given one.

◆ userVisitedPlaceByName()

void firebaseHandler.userVisitedPlaceByName ( string  name,
long  timeOfTheVisit = -1 
)

This method search on all the places the first one who match the given name, and then, it calls the userVisitedPlace method, check that method for more information. You have to be aware that if two places has the same name, the new visit will be added only to the first one.

Parameters
stringthat contains the name of the place that current user has visited and you want to register that visit.
longthat contains the timestamp of the visit, the default value is -1. A negative value means that you want to use the current timestamp not the given one.

◆ writeAllFriendProperties()

void firebaseHandler.writeAllFriendProperties ( )

This method calls the writeFriendProperty with each element of the otherUsersPropertiesToUpload_ list and it removes the each of those elements taking care of that each of those elements could enter again on the list. That could happen if the upload goes wrong.

◆ writeAllUserProperties()

void firebaseHandler.writeAllUserProperties ( )

This method calls writeSafeProperties with each safe property and writeUnsafeProperty with each unsafe property of the current user. It uses the getJSONof method of UserData class.

◆ writeFriendAcceptedFriendsInvitations()

void firebaseHandler.writeFriendAcceptedFriendsInvitations ( string  userId,
string  jsonLocal,
string  jsonCloud 
)
private

This method compares the friendInvitations list of the given user to upload correctly the information taking care of the differences between the local version and the cloud version. If something goes wrong it adds again the friendInvitations property to the otherUsersPropertiesToUpload_ list.

Parameters
stringwith the user id of the friend that will be uploaded
stringwith the json conversion of the friendInvitations list of that friend with the local information
stringwith the json conversion of the friendInvitations list of that friend with the cloud information

◆ writeFriendChallenges()

void firebaseHandler.writeFriendChallenges ( string  userId,
string  jsonLocal,
string  jsonCloud 
)
private

This method compares the challenge list of the given user to upload correctly the information taking care of the differences between the local version and the cloud version. If something goes wrong it adds again the challenge property to the otherUsersPropertiesToUpload_ list.

Parameters
stringwith the user id of the friend that will be uploaded
stringwith the json conversion of the challenges of that friend with the local information
stringwith the json conversion of the challenges of that friend with the cloud information

◆ writeFriendDeletedFriends()

void firebaseHandler.writeFriendDeletedFriends ( string  userId,
string  jsonLocal,
string  jsonCloud 
)
private

This method compares the deletedFriend list of the given user to upload correctly the information taking care of the differences between the local version and the cloud version. If something goes wrong it adds again the deletedFriend property to the otherUsersPropertiesToUpload_ list.

Parameters
stringwith the user id of the friend that will be uploaded
stringwith the json conversion of the deletedFriend list of that friend with the local information
stringwith the json conversion of the deletedFriend list of that friend with the cloud information

◆ writeFriendProperty()

void firebaseHandler.writeFriendProperty ( string  userId,
string  property,
string  json 
)

This method downloads the current information of the given property of the given friend and then calls the correct method for taking care of differences between the cloud information and the local information.

Parameters
stringwith the user id of the friend that will be uploaded
stringwith the name of the property that needs to be uploaded
stringwith the json conversion of the property that needs to be uploaded

◆ writeNewPlaceOnDataBase()

void firebaseHandler.writeNewPlaceOnDataBase ( Place  place,
string  type,
int  placeID 
)

◆ writePlaceData()

void firebaseHandler.writePlaceData ( string  type,
string  id 
)

This method uploads the data from the place that matches the given type and id. If the upload fails it adds the information of the place to placesToUploadQueue_.

Parameters
typestring that contains the type of the place that we want to upload.
idstring that contains the id of the place that we want to upload.

◆ writeQueuedUserProperties()

void firebaseHandler.writeQueuedUserProperties ( )

this method calls the writeSafeProperties or writeUnsafeProperty depending of the type of each element that is stored in currentUserPropertiesToUpload_ list. It removes the elements wich it calls those methods taking care of the fact that those properties could enter again on the currentUserPropertiesToUpload_ list if they fail on the upload.

◆ writeSafeProperties()

void firebaseHandler.writeSafeProperties ( string  property,
string  json 
)

this method writes on the given property on the database the given json value. It doesnt take care of the version that is on the database. It simply overwrite it. If something goes wrong during the upload, it adds the property to currentUserPropertiesToUpload_ again.

Parameters
stringthat contains the name of the property
stringthat contains the json conversion of that property

◆ writeUnsafeProperty()

void firebaseHandler.writeUnsafeProperty ( string  property,
string  json 
)

this method writes on the given property on the database the given json value. It takes care of the information that is currently on the database and tries to avoid incongruencies of the database. If something goes wrong during the uploading it adds again the property to the currentUserPropertiesToUpload_ list.

Parameters
stringthat contains the name of the property
stringthat contains the json conversion of that property

Member Data Documentation

◆ allowDownloadRankingData_

bool firebaseHandler.allowDownloadRankingData_
private

Boolean that is used as a flag that indicates if its time to download all the ranking data.

◆ allPlaces_

Dictionary<string,Dictionary<string,Dictionary<string,string> > > firebaseHandler.allPlaces_ = new Dictionary<string,Dictionary<string,Dictionary<string,string>>>()
private

This atribute store all the data of the places downloaded from the database. The data stored as strings on a dictionary so they cant be directly used, its necessary to use the Place class for interpreting the information that is stored on this attribute. The data is structured as following:

  • allPlaces contains an entry for each type of place, each entry is another dictionary.
  • Each of those dictionaries has an entry for each place of that type, each entry is another dictionary.
  • Each of those dictionaries are the information of each of the places but in a string form.

◆ configuration

GoogleSignInConfiguration firebaseHandler.configuration
private

This object store the configuration for accessing the Google SingIn services, it stores for example the WebClientId token.

◆ currentUser_

UserData firebaseHandler.currentUser_ = null

A instance of the class UserData, it stores the downloaded data from the database, check the documentation of that class to get more information.

◆ currentUserPropertiesToUpload_

List<string> firebaseHandler.currentUserPropertiesToUpload_
private

◆ downloadingAnyOfTheUsersPermissionsLists_

bool firebaseHandler.downloadingAnyOfTheUsersPermissionsLists_
private

true if it is trying to download any of the user permissions lists right now. false in other case.

◆ downloadingRankingData_

bool firebaseHandler.downloadingRankingData_
private

Boolean that is used as a flag that indicates if the ranking data is downloaded right now.

◆ firebaseApp

FirebaseApp firebaseHandler.firebaseApp = null
private

Reference to the FirebaseApp object.

◆ firebaseDependenciesResolved

bool firebaseHandler.firebaseDependenciesResolved = false
private

This flag is true when the firebase dependences are resolved and ready to use. If this flag is false, this class will try to resolve the firebase dependencies each frame.

◆ firebaseDependenciesRunning

bool firebaseHandler.firebaseDependenciesRunning = false
private

This flag is true when the firebase dependences are trying to be resolved right now. This flag prevent this class for making several calls to the firebase dependencies resolver method.

◆ firebaseHandlerInstance_

firebaseHandler firebaseHandler.firebaseHandlerInstance_ = null
static

This public static attribute store the unique instance of this class.

◆ friendDataDownloadQueue_

List<string> firebaseHandler.friendDataDownloadQueue_
private

It stores a list of the users ID that this class needs to download some information, because they are friends of the current user. As soon as the information is started to download, the uid is removed from the list.

◆ hasToUploadSocialPreferences_

bool firebaseHandler.hasToUploadSocialPreferences_
private

true if there is changes on the social preferences that should be uploaded.

◆ newFriendDataDownloadQueue_

List<string> firebaseHandler.newFriendDataDownloadQueue_
private

It stores a list of the users ID that this class needs to download some information because they sended a new friend invitation. As soon as the information is started to download, the uid is removed from the list.

◆ otherUserScoresToUpload_

List<Dictionary<string,string> > firebaseHandler.otherUserScoresToUpload_
private

List of dictionary strings with the user id and the score of that user that needs to be uploaded.

◆ otherUsersPropertiesToUpload_

List<Dictionary<string,string> > firebaseHandler.otherUsersPropertiesToUpload_
private

◆ placesReady_

bool firebaseHandler.placesReady_ = false
private

This flag determinate if the information of the interesting points are already downloaded from the database and its ready to use.

◆ placesToUpdateQueue_

List<Dictionary<string, string> > firebaseHandler.placesToUpdateQueue_
private

This atribute stores the list of places that have been visited but the internet conection have failed when this class tried to upload it. This class will try to upload that information since it gets internet connection again.

◆ rankingData_

List<RankingPlayerData> firebaseHandler.rankingData_
private

List with all the data that is showed on the ranking screen. It has a RankingPlayerData object for each player that appear on the ranking.

◆ requestHandler_

requestHandler firebaseHandler.requestHandler_

This atribute stores an instance of the requestHandler class, that class converts the information of allPlaces_ on instances of the class Place. Check that class documentation for more info.

◆ uploadingNotifications_

bool firebaseHandler.uploadingNotifications_
private

Boolean that is used as a flag that indicates if the uploading of the acceptedFriendsInvitations property of a friend is uploading right now.

◆ userDataReady_

bool firebaseHandler.userDataReady_ = false
private

If this flag is true, the information of the user are already downloaded from the databse and its ready to use.


The documentation for this class was generated from the following files: