Skip to content

Commit 68f2aa5

Browse files
committed
Added support for get name and set name for players
1 parent 9b1301b commit 68f2aa5

File tree

5 files changed

+100
-5
lines changed

5 files changed

+100
-5
lines changed

Runtime/Client/LootLockerConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static LootLockerConfig current
5656
return _current;
5757
}
5858
}
59-
59+
public (string key, string value) dateVersion = ( "LL-Version", "2021-03-01");
6060
public string apiKey;
6161
[HideInInspector]
6262
public string token;

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class LootLockerEndPoints
2828
public static EndPointClass getDlcMigration = new EndPointClass("v1/player/dlcs", LootLockerHTTPMethod.GET);
2929
public static EndPointClass setProfilePrivate = new EndPointClass("v1/player/profile/public", LootLockerHTTPMethod.DELETE);
3030
public static EndPointClass setProfilePublic = new EndPointClass("v1/player/profile/public", LootLockerHTTPMethod.POST);
31+
public static EndPointClass getPlayerName = new EndPointClass("player/name", LootLockerHTTPMethod.GET);
32+
public static EndPointClass setPlayerName = new EndPointClass("player/name", LootLockerHTTPMethod.PATCH);
3133

3234
//Character
3335
[Header("Character Endpoints")]

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class LootLockerResponse
3636
/// <summary>
3737
/// TRUE if http error OR server returns an error status
3838
/// </summary>
39-
public bool hasError ;
39+
public bool hasError;
4040
/// <summary>
4141
/// HTTP Status Code
4242
/// </summary>
@@ -103,6 +103,9 @@ public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, str
103103
headers.Add(callerRole == LootLocker.LootLockerEnums.LootLockerCallerRole.Admin ? "x-auth-token" : "x-session-token", callerRole == LootLocker.LootLockerEnums.LootLockerCallerRole.Admin ? LootLockerConfig.current.adminToken : LootLockerConfig.current.token);
104104
}
105105

106+
if (LootLockerConfig.current != null)
107+
headers.Add(LootLockerConfig.current.dateVersion.key, LootLockerConfig.current.dateVersion.value);
108+
106109
LootLockerBaseServerAPI.I.SwitchURL(callerRole);
107110

108111
new LootLockerServerRequest(endPoint, httpMethod, body, headers, callerRole: callerRole).Send((response) =>
@@ -130,9 +133,9 @@ public static void UploadFile(string endPoint, LootLockerHTTPMethod httpMethod,
130133
onComplete?.Invoke(response);
131134
});
132135
}
133-
#endregion
136+
#endregion
134137

135-
#region ServerRequest constructor
138+
#region ServerRequest constructor
136139
public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod = LootLockerHTTPMethod.GET, byte[] upload = null, string uploadName = null, string uploadType = null, Dictionary<string, string> body = null, Dictionary<string, string> extraHeaders = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User, bool isFileUpload = true)
137140
{
138141
this.retryCount = 0;
@@ -203,7 +206,7 @@ public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod
203206
LootLockerSDKManager.DebugMessage("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
204207
}
205208
}
206-
#endregion
209+
#endregion
207210

208211
/// <summary>
209212
/// just debug and call ServerAPI.SendRequest which takes the current ServerRequest and pass this response

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,40 @@ public static void SetProfilePublic(Action<LootLockerStandardResponse> onComplet
366366
}
367367
LootLockerAPIManager.SetProfilePublic(onComplete);
368368
}
369+
370+
public static void GetPlayerName(Action<PlayerNameResponse> onComplete)
371+
{
372+
if (!CheckInitialized())
373+
{
374+
PlayerNameResponse response = new PlayerNameResponse();
375+
response.status = false;
376+
response.hasError = true;
377+
response.Error = "SDk not initialised";
378+
response.text = "SDk not initialised";
379+
onComplete?.Invoke(response);
380+
return;
381+
}
382+
LootLockerAPIManager.GetPlayerName(onComplete);
383+
}
384+
385+
public static void SetPlayerName(string name, Action<PlayerNameResponse> onComplete)
386+
{
387+
if (!CheckInitialized())
388+
{
389+
PlayerNameResponse response = new PlayerNameResponse();
390+
response.status = false;
391+
response.hasError = true;
392+
response.Error = "SDk not initialised";
393+
response.text = "SDk not initialised";
394+
onComplete?.Invoke(response);
395+
return;
396+
}
397+
398+
PlayerNameRequest data = new PlayerNameRequest();
399+
data.name = name;
400+
401+
LootLockerAPIManager.SetPlayerName(data, onComplete);
402+
}
369403
#endregion
370404

371405
#region Character

Runtime/Game/Requests/PlayerRequest.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ public class LootLockerStandardResponse : LootLockerResponse
2424
public bool success { get; set; }
2525
}
2626

27+
[System.Serializable]
28+
public class PlayerNameRequest
29+
{
30+
public string name { get; set; }
31+
}
32+
33+
[System.Serializable]
34+
public class PlayerNameResponse : LootLockerResponse
35+
{
36+
public bool success => status;
37+
public string name { get; set; }
38+
}
2739
[System.Serializable]
2840
public class LootLockerDlcResponse : LootLockerResponse
2941
{
@@ -372,6 +384,50 @@ public static void SetProfilePublic(Action<LootLockerStandardResponse> onComplet
372384
}, true);
373385
}
374386

387+
public static void GetPlayerName(Action<PlayerNameResponse> onComplete)
388+
{
389+
EndPointClass endPoint = LootLockerEndPoints.getPlayerName;
390+
391+
string getVariable = endPoint.endPoint;
392+
393+
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, null, (serverResponse) =>
394+
{
395+
PlayerNameResponse response = new PlayerNameResponse();
396+
if (string.IsNullOrEmpty(serverResponse.Error))
397+
response = JsonConvert.DeserializeObject<PlayerNameResponse>(serverResponse.text);
398+
399+
//LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
400+
response.text = serverResponse.text;
401+
response.status = serverResponse.status;
402+
response.Error = serverResponse.Error;
403+
response.statusCode = serverResponse.statusCode;
404+
onComplete?.Invoke(response);
405+
}, true);
406+
}
407+
408+
public static void SetPlayerName(PlayerNameRequest data, Action<PlayerNameResponse> onComplete)
409+
{
410+
EndPointClass endPoint = LootLockerEndPoints.setPlayerName;
411+
string json = "";
412+
if (data == null) return;
413+
else json = JsonConvert.SerializeObject(data);
414+
415+
string getVariable = endPoint.endPoint;
416+
417+
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, json, (serverResponse) =>
418+
{
419+
PlayerNameResponse response = new PlayerNameResponse();
420+
if (string.IsNullOrEmpty(serverResponse.Error))
421+
response = JsonConvert.DeserializeObject<PlayerNameResponse>(serverResponse.text);
422+
423+
//LootLockerSDKManager.DebugMessage(serverResponse.text, !string.IsNullOrEmpty(serverResponse.Error));
424+
response.text = serverResponse.text;
425+
response.status = serverResponse.status;
426+
response.Error = serverResponse.Error;
427+
response.statusCode = serverResponse.statusCode;
428+
onComplete?.Invoke(response);
429+
}, true);
430+
}
375431
}
376432

377433
}

0 commit comments

Comments
 (0)