Skip to content

Commit 22211da

Browse files
authored
Merge pull request #8 from LootLocker/white-label-login
Add Support for White Label Login and Guest Login
2 parents 89f4910 + d4e29b6 commit 22211da

10 files changed

+429
-28
lines changed

Runtime/Client/LootLockerBaseServerAPI.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace LootLocker.LootLockerEnums
1414
{
15-
public enum LootLockerCallerRole { User, Admin, Player };
15+
public enum LootLockerCallerRole { User, Admin, Player, Base };
1616
}
1717

1818
namespace LootLocker
@@ -47,6 +47,9 @@ public void SwitchURL(LootLocker.LootLockerEnums.LootLockerCallerRole mainCaller
4747
case LootLocker.LootLockerEnums.LootLockerCallerRole.Player:
4848
SERVER_URL = LootLockerConfig.current.playerUrl;
4949
break;
50+
case LootLocker.LootLockerEnums.LootLockerCallerRole.Base:
51+
SERVER_URL = LootLockerConfig.current.baseUrl;
52+
break;
5053
default:
5154
SERVER_URL = LootLockerConfig.current.url;
5255
break;

Runtime/Client/LootLockerConfig.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static LootLockerConfig Get()
2525
return settingsInstance;
2626
}
2727

28-
public static bool CreateNewSettings(string apiKey, string gameVersion, platformType platform, bool onDevelopmentMode, DebugLevel debugLevel = DebugLevel.Off, bool allowTokenRefresh = false)
28+
public static bool CreateNewSettings(string apiKey, string gameVersion, platformType platform, bool onDevelopmentMode, string domainKey, DebugLevel debugLevel = DebugLevel.Off, bool allowTokenRefresh = false)
2929
{
3030
settingsInstance = Resources.Load<LootLockerConfig>("Config/LootLockerConfig");
3131

@@ -38,6 +38,7 @@ public static bool CreateNewSettings(string apiKey, string gameVersion, platform
3838
settingsInstance.developmentMode = onDevelopmentMode;
3939
settingsInstance.currentDebugLevel = debugLevel;
4040
settingsInstance.allowTokenRefresh = allowTokenRefresh;
41+
settingsInstance.domainKey = domainKey;
4142

4243
return true;
4344
}
@@ -63,12 +64,14 @@ public static LootLockerConfig current
6364
[HideInInspector]
6465
public string adminToken;
6566
[HideInInspector]
67+
public string domainKey;
68+
[HideInInspector]
6669
public int gameID;
6770
public string game_version = "1.0";
6871
[HideInInspector]
6972
public string deviceID = "defaultPlayerId";
7073
public platformType platform;
71-
public enum platformType { Android, iOS, Steam, Windows, GoG, Xbox, PlayStationNetwork, EpicStore, NintendoSwitch, Web, Other }
74+
public enum platformType { Android, iOS, Steam, PlayStationNetwork }
7275
public bool developmentMode;
7376
[HideInInspector]
7477
public string url = "https://api.lootlocker.io/game/v1";
@@ -78,6 +81,8 @@ public enum platformType { Android, iOS, Steam, Windows, GoG, Xbox, PlayStationN
7881
public string playerUrl = "https://api.lootlocker.io/player";
7982
[HideInInspector]
8083
public string userUrl = "https://api.lootlocker.io/game";
84+
[HideInInspector]
85+
public string baseUrl = "https://api.lootlocker.io";
8186
public enum DebugLevel { All, ErrorOnly, NormalOnly, Off }
8287
public DebugLevel currentDebugLevel;
8388
public bool allowTokenRefresh = true;

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@ namespace LootLocker
66
{
77
public class LootLockerEndPoints
88
{
9-
//Authentication
10-
[Header("Authentication Endpoints")]
9+
// Authentication
10+
[Header("Authentication")]
1111
public static EndPointClass playerVerification = new EndPointClass("v1/player/verify", LootLockerHTTPMethod.POST);
1212
public static EndPointClass authenticationRequest = new EndPointClass("v2/session", LootLockerHTTPMethod.POST);
13+
public static EndPointClass guestSessionRequest = new EndPointClass("v2/session/guest", LootLockerHTTPMethod.POST);
14+
public static EndPointClass whiteLabelLoginSessionRequest = new EndPointClass("v2/session/white-label", LootLockerHTTPMethod.POST);
1315
public static EndPointClass endingSession = new EndPointClass("v1/session", LootLockerHTTPMethod.DELETE);
1416
public static EndPointClass initialAuthenticationRequest = new EndPointClass("v1/session", LootLockerHTTPMethod.POST);
1517
public static EndPointClass twoFactorAuthenticationCodeVerification = new EndPointClass("v1/2fa", LootLockerHTTPMethod.POST);
1618
public static EndPointClass subsequentRequests = new EndPointClass("v1/games", LootLockerHTTPMethod.GET);
1719

18-
//Player
19-
[Header("Player Endpoints")]
20+
// White Label Login
21+
[Header("White Label Login")]
22+
public static EndPointClass whiteLabelSignUp = new EndPointClass("white-label-login/sign-up", LootLockerHTTPMethod.POST);
23+
public static EndPointClass whiteLabelRequestPasswordReset = new EndPointClass("white-label-login/request-reset-password", LootLockerHTTPMethod.POST);
24+
public static EndPointClass whiteLabelRequestAccountVerification = new EndPointClass("white-label-login/request-verification", LootLockerHTTPMethod.POST);
25+
26+
// Player
27+
[Header("Player")]
2028
public static EndPointClass getPlayerInfo = new EndPointClass("v1/player/info", LootLockerHTTPMethod.GET);
2129
public static EndPointClass getInventory = new EndPointClass("v1/player/inventory/list", LootLockerHTTPMethod.GET);
2230
public static EndPointClass getCurrencyBalance = new EndPointClass("v1/player/balance", LootLockerHTTPMethod.GET);
@@ -31,8 +39,8 @@ public class LootLockerEndPoints
3139
public static EndPointClass getPlayerName = new EndPointClass("player/name", LootLockerHTTPMethod.GET);
3240
public static EndPointClass setPlayerName = new EndPointClass("player/name", LootLockerHTTPMethod.PATCH);
3341

34-
//Character
35-
[Header("Character Endpoints")]
42+
// Character
43+
[Header("Character")]
3644
public static EndPointClass characterLoadouts = new EndPointClass("v1/player/character/loadout", LootLockerHTTPMethod.GET);
3745
public static EndPointClass getOtherPlayersCharacterLoadouts = new EndPointClass("v1/player/character/loadout/{0}?platform={1}", LootLockerHTTPMethod.GET);
3846
public static EndPointClass updateCharacter = new EndPointClass("v1/player/character/{0}", LootLockerHTTPMethod.PUT);
@@ -46,20 +54,18 @@ public class LootLockerEndPoints
4654
public static EndPointClass getOtherPlayersLoadoutToDefaultCharacter = new EndPointClass("v1/player/loadout/{0}?platform={1}", LootLockerHTTPMethod.GET);
4755
public static EndPointClass getEquipableContextToDefaultCharacter = new EndPointClass("v1/player/character/contexts", LootLockerHTTPMethod.GET);
4856
public static EndPointClass getEquipableContextbyCharacter = new EndPointClass("v1/player/character/{0}/contexts", LootLockerHTTPMethod.GET);
49-
5057
public static EndPointClass createCharacter = new EndPointClass("v1/player/character", LootLockerHTTPMethod.POST);
5158
public static EndPointClass listCharacterTypes = new EndPointClass("v1/player/character/types", LootLockerHTTPMethod.GET);
5259

53-
54-
//Persistentplayer storage
60+
// Persistentplayer storage
5561
[Header("Persitent Player Storage")]
5662
public static EndPointClass getEntirePersistentStorage = new EndPointClass("v1/player/storage", LootLockerHTTPMethod.GET);
5763
public static EndPointClass getSingleKeyFromPersitenctStorage = new EndPointClass("v1/player/storage?key={0}", LootLockerHTTPMethod.GET);
5864
public static EndPointClass updateOrCreateKeyValue = new EndPointClass("v1/player/storage", LootLockerHTTPMethod.POST);
5965
public static EndPointClass deleteKeyValue = new EndPointClass("v1/player/storage?key={0}", LootLockerHTTPMethod.DELETE);
6066
public static EndPointClass getOtherPlayersPublicKeyValuePairs = new EndPointClass("v1/player/{0}/storage", LootLockerHTTPMethod.GET);
6167

62-
//Asset storage
68+
// Asset storage
6369
[Header("Assets")]
6470
public static EndPointClass gettingContexts = new EndPointClass("v1/contexts", LootLockerHTTPMethod.GET);
6571
public static EndPointClass gettingAssetListWithCount = new EndPointClass("v1/assets/list?count={0}", LootLockerHTTPMethod.GET);
@@ -71,7 +77,7 @@ public class LootLockerEndPoints
7177
public static EndPointClass addingFavouriteAssets = new EndPointClass("v1/asset/{0}/favourite", LootLockerHTTPMethod.POST);
7278
public static EndPointClass removingFavouriteAssets = new EndPointClass("v1/asset/{0}/favourite", LootLockerHTTPMethod.DELETE);
7379

74-
//Asset storage
80+
// Asset storage
7581
[Header("Asset Instances")]
7682
public static EndPointClass getAllKeyValuePairs = new EndPointClass("v1/asset/instance/storage", LootLockerHTTPMethod.GET);
7783
public static EndPointClass getAllKeyValuePairsToAnInstance = new EndPointClass("v1/asset/instance/{0}/storage", LootLockerHTTPMethod.GET);
@@ -82,7 +88,8 @@ public class LootLockerEndPoints
8288
public static EndPointClass deleteKeyValuePair = new EndPointClass("v1/asset/instance/{0}/storage/{1}", LootLockerHTTPMethod.DELETE);
8389
public static EndPointClass inspectALootBox = new EndPointClass("v1/asset/instance/{0}/inspect", LootLockerHTTPMethod.GET);
8490
public static EndPointClass openALootBox = new EndPointClass("v1/asset/instance/{0}/open", LootLockerHTTPMethod.PUT);
85-
//UGC
91+
92+
// UGC
8693
[Header("UGC")]
8794
public static EndPointClass creatingAnAssetCandidate = new EndPointClass("v1/player/assets/candidates", LootLockerHTTPMethod.POST);
8895
public static EndPointClass updatingAnAssetCandidate = new EndPointClass("v1/player/assets/candidates/{0}", LootLockerHTTPMethod.PUT);
@@ -92,25 +99,25 @@ public class LootLockerEndPoints
9299
public static EndPointClass addingFilesToAssetCandidates = new EndPointClass("v1/player/assets/candidates/{0}/file", LootLockerHTTPMethod.UPLOAD);
93100
public static EndPointClass removingFilesFromAssetCandidates = new EndPointClass("v1/player/assets/candidates/{0}/file/{1}", LootLockerHTTPMethod.DELETE);
94101

95-
//Events
102+
// Events
96103
[Header("Events")]
97104
public static EndPointClass gettingAllEvents = new EndPointClass("v1/missions", LootLockerHTTPMethod.GET);
98105
public static EndPointClass gettingASingleEvent = new EndPointClass("v1/mission/{0}", LootLockerHTTPMethod.GET);
99106
public static EndPointClass startingEvent = new EndPointClass("v1/mission/{0}/start", LootLockerHTTPMethod.POST);
100107
public static EndPointClass finishingEvent = new EndPointClass("v1/mission/{0}/end", LootLockerHTTPMethod.POST);
101108

102-
//UGC
109+
// UGC
103110
[Header("Missions")]
104111
public static EndPointClass gettingAllMissions = new EndPointClass("v1/missions", LootLockerHTTPMethod.GET);
105112
public static EndPointClass gettingASingleMission = new EndPointClass("v1/mission/{0}", LootLockerHTTPMethod.GET);
106113
public static EndPointClass startingMission = new EndPointClass("v1/mission/{0}/start", LootLockerHTTPMethod.POST);
107114
public static EndPointClass finishingMission = new EndPointClass("v1/mission/{0}/end", LootLockerHTTPMethod.POST);
108115

109-
//Maps
116+
// Maps
110117
[Header("Maps")]
111118
public static EndPointClass gettingAllMaps = new EndPointClass("v1/maps", LootLockerHTTPMethod.GET);
112119

113-
//Purchase
120+
// Purchase
114121
[Header("Purchase")]
115122
public static EndPointClass normalPurchaseCall = new EndPointClass("v1/purchase", LootLockerHTTPMethod.POST);
116123
public static EndPointClass rentalPurchaseCall = new EndPointClass("v1/purchase", LootLockerHTTPMethod.POST);
@@ -119,33 +126,33 @@ public class LootLockerEndPoints
119126
public static EndPointClass pollingOrderStatus = new EndPointClass("v1/purchase/{0}", LootLockerHTTPMethod.GET);
120127
public static EndPointClass activatingARentalAsset = new EndPointClass("v1/asset/instance/{0}/activate", LootLockerHTTPMethod.POST);
121128

122-
//EventTrigger
129+
// EventTrigger
123130
[Header("EventTrigger")]
124131
public static EndPointClass triggeringAnEvent = new EndPointClass("v1/player/trigger", LootLockerHTTPMethod.POST);
125132
public static EndPointClass listingTriggeredTriggerEvents = new EndPointClass("v1/player/triggers", LootLockerHTTPMethod.GET);
126133

127-
//Maps
134+
// Maps
128135
[Header("Collectables")]
129136
public static EndPointClass gettingCollectables = new EndPointClass("v1/collectable", LootLockerHTTPMethod.GET);
130137
public static EndPointClass collectingAnItem = new EndPointClass("v1/collectable", LootLockerHTTPMethod.POST);
131138

132-
//Messages
139+
// Messages
133140
[Header("Messages")]
134141
public static EndPointClass getMessages = new EndPointClass("v1/messages", LootLockerHTTPMethod.GET);
135142

136-
//Crashes
143+
// Crashes
137144
[Header("Crashes")]
138145
public static EndPointClass submittingACrashLog = new EndPointClass("v1/crash", LootLockerHTTPMethod.POST);
139146

140-
//Leaderboards
147+
// Leaderboards
141148
[Header("Leaderboards")]
142149
public static EndPointClass getMemberRank = new EndPointClass("leaderboards/{0}/member/{1}", LootLockerHTTPMethod.GET);
143150
public static EndPointClass getByListOfMembers = new EndPointClass("leaderboards/{0}/members", LootLockerHTTPMethod.POST);
144151
public static EndPointClass getAllMemberRanks = new EndPointClass("leaderboards/member/{0}?count={1}", LootLockerHTTPMethod.GET);
145152
public static EndPointClass getScoreList = new EndPointClass("leaderboards/{0}/list?count={1}", LootLockerHTTPMethod.GET);
146153
public static EndPointClass submitScore = new EndPointClass("leaderboards/{0}/submit", LootLockerHTTPMethod.POST);
147154

148-
//Drop Tables
155+
// Drop Tables
149156
[Header("Drop Tables")]
150157
public static EndPointClass ComputeAndLockDropTable = new EndPointClass("v1/player/droptables/{0}/compute?asset_details={1}", LootLockerHTTPMethod.POST);
151158
public static EndPointClass PickDropsFromDropTable = new EndPointClass("v1/player/droptables/{0}/pick", LootLockerHTTPMethod.POST);

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ public class LootLockerResponse
6262

6363
}
6464

65+
/// <summary>
66+
/// Convenience factory class for creating some responses that we use often.
67+
/// </summary>
68+
public class LootLockerResponseFactory
69+
{
70+
/// <summary>
71+
/// Construct an error response to send to the client.
72+
/// </summary>
73+
public static T Error<T> (string errorMessage) where T : LootLockerResponse, new()
74+
{
75+
return new T()
76+
{
77+
success = false,
78+
hasError = true,
79+
Error = errorMessage,
80+
text = errorMessage
81+
};
82+
}
83+
84+
/// <summary>
85+
/// Construct an error response specifically when the SDK has not been initialized.
86+
/// </summary>
87+
public static T SDKNotInitializedError<T>() where T : LootLockerResponse, new()
88+
{
89+
return Error<T>("SDK not initialised");
90+
}
91+
}
92+
6593
/// <summary>
6694
/// Construct a request to send to the server.
6795
/// </summary>
@@ -115,6 +143,34 @@ public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, str
115143
});
116144
}
117145

146+
public static void CallDomainAuthAPI(string endPoint, LootLockerHTTPMethod httpMethod, string body = null, Action<LootLockerResponse> onComplete = null)
147+
{
148+
if (LootLockerConfig.current.domainKey.ToString().Length == 0)
149+
{
150+
#if UNITY_EDITOR
151+
LootLockerSDKManager.DebugMessage("LootLocker domain key must be set in settings", true);
152+
#endif
153+
onComplete?.Invoke(LootLockerResponseFactory.Error<LootLockerResponse>("LootLocker domain key must be set in settings"));
154+
155+
return;
156+
}
157+
158+
Dictionary<string, string> headers = new Dictionary<string, string>();
159+
headers.Add("domain-key", LootLockerConfig.current.domainKey);
160+
161+
if (LootLockerConfig.current.developmentMode)
162+
{
163+
headers.Add("is-development", "true");
164+
}
165+
166+
LootLockerBaseServerAPI.I.SwitchURL(LootLockerCallerRole.Base);
167+
168+
new LootLockerServerRequest(endPoint, httpMethod, body, headers, callerRole: LootLockerCallerRole.Base).Send((response) =>
169+
{
170+
onComplete?.Invoke(response);
171+
});
172+
}
173+
118174
public static void UploadFile(string endPoint, LootLockerHTTPMethod httpMethod, byte[] file, string fileName = "file", string fileContentType = "text/plain", Dictionary<string, string> body = null, Action<LootLockerResponse> onComplete = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User)
119175
{
120176
Dictionary<string, string> headers = new Dictionary<string, string>();

Runtime/Editor/ProjectSettings.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,38 @@ private void DrawGameSettings()
5656
{
5757
gameSettings.apiKey = m_CustomSettings.FindProperty("apiKey").stringValue;
5858
}
59+
var content = new GUIContent();
60+
content.text = "API key can be found in `Settings > Game settings > API` in the Web Console";
61+
EditorGUILayout.HelpBox(content, false);
62+
EditorGUILayout.Space();
63+
64+
EditorGUI.BeginChangeCheck();
65+
66+
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("domainKey"));
67+
if (EditorGUI.EndChangeCheck())
68+
{
69+
gameSettings.domainKey = m_CustomSettings.FindProperty("domainKey").stringValue;
70+
}
71+
var domainContent = new GUIContent();
72+
domainContent.text = "Domain key can be found in `Settings > Game settings > API` in the Web Console";
73+
EditorGUILayout.HelpBox(domainContent, false);
74+
EditorGUILayout.Space();
5975

6076
EditorGUI.BeginChangeCheck();
6177
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("game_version"));
6278
if (EditorGUI.EndChangeCheck())
6379
{
6480
gameSettings.game_version = m_CustomSettings.FindProperty("game_version").stringValue;
6581
}
82+
EditorGUILayout.Space();
6683

6784
EditorGUI.BeginChangeCheck();
6885
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("platform"));
6986
if (EditorGUI.EndChangeCheck())
7087
{
7188
gameSettings.platform = (LootLockerConfig.platformType)m_CustomSettings.FindProperty("platform").enumValueIndex;
7289
}
90+
EditorGUILayout.Space();
7391

7492
EditorGUI.BeginChangeCheck();
7593
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("developmentMode"));
@@ -78,6 +96,7 @@ private void DrawGameSettings()
7896
{
7997
gameSettings.developmentMode = m_CustomSettings.FindProperty("developmentMode").boolValue;
8098
}
99+
EditorGUILayout.Space();
81100

82101
EditorGUI.BeginChangeCheck();
83102
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("currentDebugLevel"));
@@ -86,6 +105,7 @@ private void DrawGameSettings()
86105
{
87106
gameSettings.currentDebugLevel = (LootLockerConfig.DebugLevel)m_CustomSettings.FindProperty("currentDebugLevel").enumValueIndex;
88107
}
108+
EditorGUILayout.Space();
89109

90110
EditorGUI.BeginChangeCheck();
91111
EditorGUILayout.PropertyField(m_CustomSettings.FindProperty("allowTokenRefresh"));
@@ -94,6 +114,7 @@ private void DrawGameSettings()
94114
{
95115
gameSettings.allowTokenRefresh = m_CustomSettings.FindProperty("allowTokenRefresh").boolValue;
96116
}
117+
EditorGUILayout.Space();
97118
}
98119

99120
[SettingsProvider]

0 commit comments

Comments
 (0)