Basic auth working
This commit is contained in:
@@ -9,9 +9,23 @@
|
|||||||
"Name": "killstat_version",
|
"Name": "killstat_version",
|
||||||
"DefaultValue": "ks_3.0.0"
|
"DefaultValue": "ks_3.0.0"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Name": "Tone_protocol",
|
||||||
|
"DefaultValue": "http"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Name": "Tone_URI",
|
"Name": "Tone_URI",
|
||||||
"DefaultValue": "http://127.0.0.1:3001/v1"
|
"DefaultValue": "127.0.0.1:3001/v1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "Tone_ID",
|
||||||
|
"DefaultValue": "default",
|
||||||
|
"Flags": 128
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "Tone_token",
|
||||||
|
"DefaultValue": "default",
|
||||||
|
"Flags": 4256
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name": "killstat_custom_parameters",
|
"Name": "killstat_custom_parameters",
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ array<string> HEADERS = [ //unused
|
|||||||
struct {
|
struct {
|
||||||
string killstatVersion
|
string killstatVersion
|
||||||
string Tone_URI
|
string Tone_URI
|
||||||
int serverId
|
string Tone_protocol
|
||||||
|
string Tone_ID
|
||||||
|
string Tone_token
|
||||||
array<Parameter> customParameters
|
array<Parameter> customParameters
|
||||||
|
|
||||||
int matchId
|
int matchId
|
||||||
@@ -57,8 +59,13 @@ struct {
|
|||||||
void function killstat_Init() {
|
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")
|
||||||
//TODO : request ServerID from API ------------------------------------------------------------------------------------------------
|
file.Tone_protocol = GetConVarString("Tone_protocol")
|
||||||
file.serverId = 1
|
file.Tone_ID = GetConVarString("Tone_ID")
|
||||||
|
file.Tone_token = GetConVarString("Tone_token")
|
||||||
|
|
||||||
|
//register to Tone API if default or invalid token
|
||||||
|
Tone_Test_Auth()
|
||||||
|
|
||||||
// custom parameters
|
// custom parameters
|
||||||
string customParameterString = GetConVarString("killstat_custom_parameters")
|
string customParameterString = GetConVarString("killstat_custom_parameters")
|
||||||
array<string> customParameterEntries = split(customParameterString, ",")
|
array<string> customParameterEntries = split(customParameterString, ",")
|
||||||
@@ -98,7 +105,7 @@ void function killstat_Begin() {
|
|||||||
file.map = StringReplace(GetMapName(), "mp_", "")
|
file.map = StringReplace(GetMapName(), "mp_", "")
|
||||||
|
|
||||||
Log("-----BEGIN KILLSTAT-----")
|
Log("-----BEGIN KILLSTAT-----")
|
||||||
Log("Sending kill data to " + file.Tone_URI + "/servers/"+file.serverId+"/kill")
|
Log("Sending kill data to " + file.Tone_URI + "/servers/"+file.Tone_ID+"/kill")
|
||||||
}
|
}
|
||||||
|
|
||||||
void function killstat_Record(entity victim, entity attacker, var damageInfo) {
|
void function killstat_Record(entity victim, entity attacker, var damageInfo) {
|
||||||
@@ -176,7 +183,7 @@ void function killstat_Record(entity victim, entity attacker, var damageInfo) {
|
|||||||
|
|
||||||
string json = EncodeJSON(values)
|
string json = EncodeJSON(values)
|
||||||
print("sending here... I realise")
|
print("sending here... I realise")
|
||||||
NSHttpPostBody(file.Tone_URI + "/servers/"+file.serverId+"/kill", json)
|
NSHttpPostBody(GetToneURIWithAuth()+ "/servers/"+file.Tone_ID+"/kill", json)
|
||||||
}
|
}
|
||||||
|
|
||||||
void function killstat_End() {
|
void function killstat_End() {
|
||||||
@@ -317,3 +324,68 @@ string function join(array<string> list, string separator) {
|
|||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void function Tone_Test_Auth(){
|
||||||
|
HttpRequest request
|
||||||
|
request.method = HttpRequestMethod.POST
|
||||||
|
request.url = GetToneURIWithAuth() + "/servers/"+file.Tone_ID
|
||||||
|
void functionref( HttpRequestResponse ) onSuccess = void function ( HttpRequestResponse response )
|
||||||
|
{
|
||||||
|
print("[Tone API] Tone API Online !")
|
||||||
|
}
|
||||||
|
|
||||||
|
void functionref( HttpRequestFailure ) onFailure = void function ( HttpRequestFailure failure )
|
||||||
|
{
|
||||||
|
print("[Tone API] Tone API registration failed")
|
||||||
|
print("[Tone API] " + failure.errorMessage )
|
||||||
|
thread Tone_Register_Threaded()
|
||||||
|
}
|
||||||
|
|
||||||
|
NSHttpRequest(request, onSuccess, onFailure)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void function Tone_Register_Threaded(){
|
||||||
|
table body = {}
|
||||||
|
body["name"] <- GetConVarString("ns_server_name")
|
||||||
|
body["description"] <- GetConVarString("ns_server_desc")
|
||||||
|
body["auth_port"] <- GetConVarString("ns_player_auth_port")
|
||||||
|
HttpRequest request
|
||||||
|
request.method = HttpRequestMethod.POST
|
||||||
|
request.url = file.Tone_protocol + "://" + file.Tone_URI+ "/servers/register"
|
||||||
|
|
||||||
|
string json = EncodeJSON( body )
|
||||||
|
request.body = json
|
||||||
|
int i = 0
|
||||||
|
void functionref( HttpRequestResponse ) onSuccess = void function ( HttpRequestResponse response )
|
||||||
|
{
|
||||||
|
table answer = DecodeJSON(response.body)
|
||||||
|
file.Tone_ID = expect string(answer["id"])
|
||||||
|
file.Tone_token = expect string(answer["token"])
|
||||||
|
SetConVarString("Tone_ID", expect string(answer["id"]))
|
||||||
|
SetConVarString("Tone_token", expect string(answer["token"]))
|
||||||
|
i = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
void functionref( HttpRequestFailure ) onFailure = void function ( HttpRequestFailure failure )
|
||||||
|
{
|
||||||
|
print("[Tone API] Tone API registration failed")
|
||||||
|
print("[Tone API] "+ failure.errorMessage )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
while(i < 5){
|
||||||
|
print("[Tone API] requesting Tone API for registration... Time " + i + " out of 5" )
|
||||||
|
NSHttpRequest( request, onSuccess, onFailure )
|
||||||
|
i = i + 1
|
||||||
|
wait 300
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string function GetToneURIWithAuth(){
|
||||||
|
return file.Tone_protocol + "://" +file.Tone_ID+":"+file.Tone_protocol+"@"+ file.Tone_URI
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user