error handling on Registration and login

This commit is contained in:
2023-03-03 19:59:20 +01:00
parent 26a55ff5b1
commit a1e591b5f5
2 changed files with 30 additions and 13 deletions
+1 -1
View File
@@ -20,7 +20,7 @@
{ {
"Name": "Tone_ID", "Name": "Tone_ID",
"DefaultValue": "default", "DefaultValue": "default",
"Flags": 128 "Flags": "ARCHIVE"
}, },
{ {
"Name": "Tone_token", "Name": "Tone_token",
+29 -12
View File
@@ -47,8 +47,9 @@ struct {
string killstatVersion string killstatVersion
string Tone_URI string Tone_URI
string Tone_protocol string Tone_protocol
string Tone_ID int Tone_ID
string Tone_token string Tone_token
bool connected
array<Parameter> customParameters array<Parameter> customParameters
int matchId int matchId
@@ -60,8 +61,9 @@ void function killstat_Init() {
file.killstatVersion = GetConVarString("killstat_version") file.killstatVersion = GetConVarString("killstat_version")
file.Tone_URI = GetConVarString("Tone_URI") file.Tone_URI = GetConVarString("Tone_URI")
file.Tone_protocol = GetConVarString("Tone_protocol") file.Tone_protocol = GetConVarString("Tone_protocol")
file.Tone_ID = GetConVarString("Tone_ID") file.Tone_ID = GetConVarInt("Tone_ID")
file.Tone_token = GetConVarString("Tone_token") file.Tone_token = GetConVarString("Tone_token")
file.connected = false
//register to Tone API if default or invalid token //register to Tone API if default or invalid token
Tone_Test_Auth() Tone_Test_Auth()
@@ -330,9 +332,17 @@ void function Tone_Test_Auth(){
HttpRequest request HttpRequest request
request.method = HttpRequestMethod.POST request.method = HttpRequestMethod.POST
request.url = GetToneURIWithAuth() + "/servers/"+file.Tone_ID request.url = GetToneURIWithAuth() + "/servers/"+file.Tone_ID
//print(GetToneURIWithAuth())
void functionref( HttpRequestResponse ) onSuccess = void function ( HttpRequestResponse response ) void functionref( HttpRequestResponse ) onSuccess = void function ( HttpRequestResponse response )
{ {
print("[Tone API] Tone API Online !") if(response.statusCode == 200){
print("[Tone API] Tone API Online !")
file.connected = true
}else{
print("[Tone API] Tone API registration failed")
print("[Tone API] " + response.body )
thread Tone_Register_Threaded()
}
} }
void functionref( HttpRequestFailure ) onFailure = void function ( HttpRequestFailure failure ) void functionref( HttpRequestFailure ) onFailure = void function ( HttpRequestFailure failure )
@@ -360,12 +370,19 @@ void function Tone_Register_Threaded(){
int i = 0 int i = 0
void functionref( HttpRequestResponse ) onSuccess = void function ( HttpRequestResponse response ) void functionref( HttpRequestResponse ) onSuccess = void function ( HttpRequestResponse response )
{ {
table answer = DecodeJSON(response.body) //print(response.statusCode)
file.Tone_ID = expect string(answer["id"]) if(response.statusCode == 201){
file.Tone_token = expect string(answer["token"]) table answer = DecodeJSON(response.body)
SetConVarString("Tone_ID", expect string(answer["id"])) file.Tone_ID = expect int(answer["id"])
SetConVarString("Tone_token", expect string(answer["token"])) file.Tone_token = expect string(answer["token"])
i = 5 SetConVarInt("Tone_ID", (expect int(answer["id"])))
SetConVarString("Tone_token", (expect string(answer["token"])))
print("[Tone API] Tone API Online !")
file.connected = true
}else{
print("[Tone API] Tone API registration failed")
print("[Tone API] " + response.body )
}
} }
void functionref( HttpRequestFailure ) onFailure = void function ( HttpRequestFailure failure ) void functionref( HttpRequestFailure ) onFailure = void function ( HttpRequestFailure failure )
@@ -374,18 +391,18 @@ void function Tone_Register_Threaded(){
print("[Tone API] "+ failure.errorMessage ) print("[Tone API] "+ failure.errorMessage )
} }
while(i < 5 && file.connected == false){
while(i < 5){
print("[Tone API] requesting Tone API for registration... Time " + i + " out of 5" ) print("[Tone API] requesting Tone API for registration... Time " + i + " out of 5" )
NSHttpRequest( request, onSuccess, onFailure ) NSHttpRequest( request, onSuccess, onFailure )
i = i + 1 i = i + 1
wait 300 wait 300
} }
print("[Tone API] Tone API registration failed. Stopping registration requests for now. Try mentionning @Legonzaur#2100 about this issue.")
return return
} }
string function GetToneURIWithAuth(){ string function GetToneURIWithAuth(){
return file.Tone_protocol + "://" +file.Tone_ID+":"+file.Tone_protocol+"@"+ file.Tone_URI return file.Tone_protocol + "://" +file.Tone_ID+":"+file.Tone_token+"@"+ file.Tone_URI
} }