This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerAPI.Script.txt
99 lines (85 loc) · 2.75 KB
/
ServerAPI.Script.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Component : ServerAPI
*/
#Const Version "2020-04-01"
#Const ScriptName "Libs/Nadeo/TMNext/TrackMania/API/ServerAPI.Script.txt"
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Libraries
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Include "Libs/Nadeo/MenuLibs/Common/Manialink/ManiaView2.Script.txt" as MV
#Include "Libs/Nadeo/CommonLibs/Common/Http.Script.txt" as Http
#Include "Libs/Nadeo/TMNext/TrackMania/Config.Script.txt" as Config
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Constants
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Const C_Name "lib-server-api" //< Component name
#Const P "LibServerAPI_" //< Prefix use to differentiate functions/variables in the script
#Const C_API_Server "/api/token/server"
#Const C_Route_GetPlayerServerAccounts "/player-server/account"
#Const C_Headers [
"Accept" => "application/json",
"Content-Type" => "application/json"
]
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Get the component
*
* @return The component id
*/
Text Component() {
return MV::Component(
C_Name,
"""
""",
"""
#Const {{{P}}}C_API_Server {{{dump(C_API_Server)}}}
#Const {{{P}}}C_Route_GetPlayerServerAccounts {{{dump(C_Route_GetPlayerServerAccounts)}}}
#Const {{{P}}}C_Headers {{{dump(C_Headers)}}}
#Struct {{{P}}}K_HttpPlayerServerAccount {
Text accountId;
Text login;
Boolean alreadyUsed;
Integer clubRoomId;
Text clubRoomName;
}
#Struct {{{P}}}K_HttpResponseGetPlayerServerAccounts {
{{{P}}}K_HttpPlayerServerAccount[] playerServerAccount;
Integer itemCount;
}
#Struct {{{P}}}K_PlayerServerAccount {
Text AccountId;
Text Login;
Boolean AlreadyUsed;
Integer ClubRoomId;
Text ClubRoomName;
}
""",
"""
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Start a request to get the server accounts of the connected player
*
* @return The request
*/
{{{Http::P}}}K_Request {{{P}}}GetPlayerServerAccounts() {
return {{{Http::P}}}CreateGet({{{Config::P}}}Get().APIBaseUrl^{{{P}}}C_API_Server^{{{P}}}C_Route_GetPlayerServerAccounts, {{{P}}}C_Headers);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
{{{P}}}K_PlayerServerAccount[] {{{P}}}GetResponseFromGetPlayerServerAccounts({{{Http::P}}}K_Request _Request) {
declare {{{P}}}K_HttpResponseGetPlayerServerAccounts HttpResponse;
HttpResponse.fromjson({{{Http::P}}}GetResult(_Request));
declare {{{P}}}K_PlayerServerAccount[] PlayerServerAccountList;
foreach (HttpServerAccount in HttpResponse.playerServerAccount) {
PlayerServerAccountList.add({{{P}}}K_PlayerServerAccount {
AccountId = HttpServerAccount.accountId,
Login = HttpServerAccount.login,
AlreadyUsed = HttpServerAccount.alreadyUsed,
ClubRoomId = HttpServerAccount.clubRoomId,
ClubRoomName = HttpServerAccount.clubRoomName
});
}
return PlayerServerAccountList;
}
""",
[Http::Component(), Config::Component()],
[]
);
}