Advertisement
Guest User

repcheck.ps1

a guest
Mar 20th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Checks the DMP reputation files and whenever reputation decreases it resets the value to the last known higher one
  2. #
  3. #Just copy this into a textfile and call it whatever.ps1 in the DMP main directory next to the updater
  4. #Start best before the server since it needs to get a good reputation value once
  5.  
  6.  
  7. $folders = Get-ChildItem .\Universe\Scenarios | ?{ $_.PSIsContainer }
  8. $players = @{}
  9.  
  10. function getIni
  11. {
  12.     param (
  13.     [parameter(mandatory=$true,position=0)][String]$FilePath
  14.     )
  15.     $Ini = @{}
  16.  
  17.     if(Test-Path -Path $FilePath)
  18.     {
  19.         Get-Content $FilePath | foreach {
  20.             $line = $_.split("=")
  21.             $Ini.($line[0].Trim()) = $line[1].Trim()
  22.         }
  23.     }
  24.     return $Ini
  25. }
  26.  
  27. function getReputation
  28. {
  29.     param (
  30.     [parameter(mandatory=$true,position=0)]$PlayerFolder
  31.     )
  32.     [double]$rv = -99999
  33.     [string]$repFilePath = $PlayerFolder + '\Reputation.txt'
  34.     if(Test-Path -Path $repFilePath)
  35.     {
  36.         $repIni = getIni $repFilePath
  37.         [double]$rv = [convert]::ToDouble($repIni.'rep')
  38.     }
  39.     return $rv
  40.  
  41.    
  42. }
  43.  
  44. function setReputation
  45. {
  46.     param (
  47.     [parameter(mandatory=$true,position=0)]$PlayerFolder,
  48.     [parameter(mandatory=$true,position=1)][double]$newRep
  49.     )
  50.  
  51.     [string]$repFilePath = $PlayerFolder + '\Reputation.txt'
  52.     if(Test-Path -Path $repFilePath)
  53.     {
  54.         $rawS = (get-content $repFilePath) -replace "rep =.*", "rep = $newRep"
  55.         $rawS | Out-File $repFilePath
  56.     }
  57. }
  58.  
  59.  
  60. function checkReputation
  61. {
  62.  
  63.     foreach ($player in $players.Values)
  64.     {
  65.         $currentRep = getReputation $player.myFolder
  66.  
  67.         if($currentRep -lt $player.reputation)
  68.         {
  69.             setReputation $player.myFolder $lastRep
  70.         }
  71.     }
  72.    
  73. }
  74.  
  75.  
  76. $i = 0
  77. foreach ($folder in $folders)
  78. {
  79.     $rep = getReputation $folder.FullName
  80.     if($rep -ne -99999)
  81.     {
  82.         $player = [pscustomobject]@{myFolder=$folder.FullName; reputation=$rep}
  83.         #$players.Add($folder.Name [$i] = $player
  84.         $players.Add($folder.Name, $player)
  85.         $i++
  86.     }
  87.  
  88. }
  89.  
  90. While(1){
  91.  
  92. checkReputation
  93. sleep(5)
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement