Update KillTrackR_MainScript.ps1

forgot to finish implement "function Send-ApiData"
This commit is contained in:
Koda-Dog 2025-01-31 15:33:26 +01:00
parent abec2205e3
commit a92dbdfef1

View file

@ -13,7 +13,6 @@ $script:AppName = "AutoTrackR2"
$script:ScriptFolder = Join-Path -Path $env:LOCALAPPDATA -ChildPath $AppName $script:ScriptFolder = Join-Path -Path $env:LOCALAPPDATA -ChildPath $AppName
$script:ConfigFileName= "config.ini" $script:ConfigFileName= "config.ini"
$script:ConfigFile = "$script:ScriptFolder\$script:ConfigFileName" $script:ConfigFile = "$script:ScriptFolder\$script:ConfigFileName"
# File Data # File Data
$script:CSVFileName = "Kill-log.csv" $script:CSVFileName = "Kill-log.csv"
$script:CSVFile = "$script:ScriptFolder\$script:CSVFileName" $script:CSVFile = "$script:ScriptFolder\$script:CSVFileName"
@ -307,7 +306,7 @@ function Read-LogEntry {
# Apply the regex pattern to the line # Apply the regex pattern to the line
if (-not $initialised -and $line -match $script:KillPattern) { if (-not $initialised -and $line -match $script:KillPattern) {
Write-OutputData "LogInfo=KillPattern detected!" Write-OutputData "LogInfo=KillPattern detected"
$eventData = New-KillEvent -data $matches -location $location -vehicle_id $vehicle_id $eventData = New-KillEvent -data $matches -location $location -vehicle_id $vehicle_id
$type = New-EventType -eventData $eventData -userName $script:UserName -killLog $config.KillLog -deathLog $config.DeathLog -otherLog $config.OtherLog $type = New-EventType -eventData $eventData -userName $script:UserName -killLog $config.KillLog -deathLog $config.DeathLog -otherLog $config.OtherLog
@ -319,13 +318,11 @@ function Read-LogEntry {
$eventData.victimShip = Format-ShipName $eventData.victimShip $eventData.victimShip = Format-ShipName $eventData.victimShip
$eventData.playerShip = Format-ShipName $script:Loadout $eventData.playerShip = Format-ShipName $script:Loadout
$csvData = New-CsvData $type $eventData $playerInfo $csvData = New-CsvData -type $type -eventData $eventData -playerInfo $playerInfo
if ($type -eq "Kill" -and $null -ne $config.ApiUrl -and -not $config.OfflineMode) {
if ($type -eq "Kill" -and $null -ne $apiUrl -and -not $config.OfflineMode) {
Write-OutputData "LogInfo=Send $type data to server" Write-OutputData "LogInfo=Send $type data to server"
Send-ApiData $csvData Send-ApiData -csvData $csvData -location $location -apiUrl $config.ApiUrl -apiKey $config.ApiKey
} }
Write-CSVData -csvData $csvData -csvFile $script:CSVFile Write-CSVData -csvData $csvData -csvFile $script:CSVFile
Update-Tally $type Update-Tally $type
@ -429,16 +426,36 @@ function New-EventType {
[bool]$deathLog = $false, [bool]$deathLog = $false,
[bool]$otherLog = $false [bool]$otherLog = $false
) )
# Other way's to die
$otherWay = @(
"Crash",
"Suicide"
)
# Kill
if ($eventData.AgressorPilot -eq $userName -and $eventData.VictimPilot -ne $userName) { if ($eventData.AgressorPilot -eq $userName -and $eventData.VictimPilot -ne $userName) {
if($killLog){return "Kill"}else{return "none"} if($killLog){return "Kill"}else{return "none"}
# Death and Others
} elseif ($eventData.AgressorPilot -ne $userName -and $eventData.VictimPilot -eq $userName) { } elseif ($eventData.AgressorPilot -ne $userName -and $eventData.VictimPilot -eq $userName) {
# Others
foreach ($way in $otherWay) {
if ($eventData.DamageType -contains $way) {
if($otherLog){return "Other"}else{return "none"}
}
}
if ($eventData.AgressorPilot -eq "unknown" -and $eventData.Weapon -eq "unknown") { if ($eventData.AgressorPilot -eq "unknown" -and $eventData.Weapon -eq "unknown") {
if($otherLog){return "Other"}else{return "none"} if($otherLog){return "Other"}else{return "none"}
} }
# Death
if($deathLog){return "Death"}else{return "none"} if($deathLog){return "Death"}else{return "none"}
#Suicide
} elseif ($eventData.AgressorPilot -eq $userName -or $eventData.VictimPilot -eq $userName) { } elseif ($eventData.AgressorPilot -eq $userName -or $eventData.VictimPilot -eq $userName) {
return "Other" if($otherLog){return "Other"}else{return "none"}
} }
return "none" return "none"
} }
@ -522,7 +539,8 @@ function Format-ShipName {
function Send-ApiData { function Send-ApiData {
param ( param (
[hashtable]$data, [PSCustomObject]$csvData,
[string] $location,
[string]$apiUrl, [string]$apiUrl,
[string]$apiKey [string]$apiKey
) )
@ -533,8 +551,34 @@ function Send-ApiData {
"User-Agent" = "AutoTrackR2" "User-Agent" = "AutoTrackR2"
} }
$sendData = @{
victim_ship = $csvData.EnemyShip
victim = $csvData.EnemyPilot
enlisted = $csvData.Enlisted
rsi = $csvData.RecordNumber
weapon = $csvData.Weapon
method = $csvData.Method
loadout_ship = $csvData.Ship
game_version = $csvData.GameVersion
gamemode = $csvData.Mode
trackr_version = $csvData.TrackRver
location = $location
}
If ($null -ne $apiUrl){
if ($apiUrl -notlike "*/register-kill") {
if ($apiUrl -like "*/"){
$apiUrl = $apiUrl + "register-kill"
}
if ($apiUrl -notlike "*/"){
$apiUrl = $apiUrl + "/register-kill"
}
}
Write-OutputData "LogInfo=ApiURL: $apiURL"
}
try { try {
$null = Invoke-RestMethod -Uri $apiUrl -Method Post -Body ($data | ConvertTo-Json -Depth 5) -Headers $headers $null = Invoke-RestMethod -Uri $apiUrl -Method Post -Body ($sendData | ConvertTo-Json -Depth 5) -Headers $headers
return "API" return "API"
} catch { } catch {
Write-Warning "LogInfo=API-Error: $_" Write-Warning "LogInfo=API-Error: $_"