-
Notifications
You must be signed in to change notification settings - Fork 0
/
SEremoveplayers.ps1
140 lines (126 loc) · 9.31 KB
/
SEremoveplayers.ps1
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
$filePath = 'your save path here\SANDBOX_0_0_0_.sbs'
$filePath2 = 'your save path here\SANDBOX.sbc'
# ===== only change the above values
[xml]$myXML = Get-Content $filePath -Encoding UTF8
$ns = New-Object System.Xml.XmlNamespaceManager($myXML.NameTable)
$ns.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
[xml]$myXML2 = Get-Content $filePath2 -Encoding UTF8
$ns2 = New-Object System.Xml.XmlNamespaceManager($myXML2.NameTable)
$ns2.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
#wipe orphaned id's (permanent death issue) if dead player owns nothing.
[string]$compare = "Neutral NPC"
$nodePIDs = $myXML2.SelectNodes("//Identities/MyObjectBuilder_Identity" , $ns2)
Write-Host -ForegroundColor Green " checking for abandoned ID's ... "
ForEach($node in $nodePIDs){
$NPCID = [string]$node.DisplayName
$playerid = $node.IdentityId
$client = $myXML2.SelectSingleNode("//AllPlayersData/dictionary/item/Value[IdentityId='$playerid']" , $ns2)
$clientcount= $client.count
$nodeOwns = $myXML.SelectNodes("//SectorObjects/MyObjectBuilder_EntityBase[(@xsi:type='MyObjectBuilder_CubeGrid')]/CubeBlocks/MyObjectBuilder_CubeBlock[Owner='$playerid']" , $ns).count
IF($clientcount -eq 0 -and $nodeOwns -eq 0 -and $NPCID -ne $compare){
$selectdelete = $myXML2.SelectSingleNode("//Factions/Factions/MyObjectBuilder_Faction/Members/MyObjectBuilder_FactionMember[PlayerId='$playerid']" , $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)] is not a member of a faction, proceeding..."}
$selectdelete = $myXML2.SelectSingleNode("//Factions/Players/dictionary/item[Key='$playerid']", $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)]; no faction dictionary data found, proceeding..."}
$selectdelete = $myXML2.SelectSingleNode("//Factions/Factions/MyObjectBuilder_Faction/JoinRequests/MyObjectBuilder_FactionMember[PlayerId='$playerid']" , $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)] has no faction join requests, proceeding..."}
$selectdelete = $myXML2.SelectSingleNode("//Gps/dictionary/item[Key='$playerid']", $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)]; no GPS dictionary data found, proceeding..."}
$selectdelete = $myXML2.SelectSingleNode("//ChatHistory/MyObjectBuilder_ChatHistory[IdentityId='$playerid']", $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)]; no player owned chat data found, proceeding..."}
$otherchat=$null
$selectdelete = $myXML2.SelectNodes("//ChatHistory/MyObjectBuilder_ChatHistory/PlayerChatHistory/MyObjectBuilder_PlayerChatHistory[ID='$playerid']", $ns2)
ForEach($otherchat in $selectdelete){
Try{$otherchat.ParentNode.RemoveChild($otherchat)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)]; no other chat data found, proceeding..."}
}
$node.ParentNode.RemoveChild($node)
Write-Host -ForegroundColor Green " abandoned ID deleted "
}
}
#set orphaned blocks to no owner.
Write-Host -ForegroundColor Green " scanning for orphaned blocks ..."
$orphOwns = $myXML.SelectNodes("//SectorObjects/MyObjectBuilder_EntityBase[(@xsi:type='MyObjectBuilder_CubeGrid')]/CubeBlocks/MyObjectBuilder_CubeBlock/Owner" , $ns)
ForEach($node in $orphOwns){
$clients = $myXML2.SelectSingleNode("//Identities/MyObjectBuilder_Identity[IdentityId='$($node.InnerText)']" , $ns2)
If($clients.IdentityId.count -eq 0){
$node.ParentNode.RemoveChild($node)
}
}
# remove players who dont own anything
$nodePIDs = $myXML2.SelectNodes("//Identities/MyObjectBuilder_Identity" , $ns2)
ForEach($node in $nodePIDs){
$nodeClientID=$myXML2.SelectSingleNode("//AllPlayersData/dictionary/item/Value[IdentityId='$($node.IdentityId)']" , $ns2)
$nodename = $nodeClientID.ParentNode.Key.ClientId
$nodeid = $node.IdentityId
$nodeOwns = $myXML.SelectNodes("//SectorObjects/MyObjectBuilder_EntityBase[(@xsi:type='MyObjectBuilder_CubeGrid')]/CubeBlocks/MyObjectBuilder_CubeBlock[Owner='$nodeid']" , $ns).Count
If($nodeOwns -eq 0){
$selectdelete = $myXML2.SelectSingleNode("//Factions/Factions/MyObjectBuilder_Faction/Members/MyObjectBuilder_FactionMember[PlayerId='$nodeid']" , $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)] is not a member of a faction, proceeding..."}
$selectdelete = $myXML2.SelectSingleNode("//Factions/Players/dictionary/item[Key='$nodeid']", $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)]; no faction dictionary data found, proceeding..."}
$selectdelete = $myXML2.SelectSingleNode("//Factions/Factions/MyObjectBuilder_Faction/JoinRequests/MyObjectBuilder_FactionMember[PlayerId='$nodeid']" , $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)] has no faction join requests, proceeding..."}
Try{$nodeClientID.ParentNode.ParentNode.RemoveChild($nodeClientID.ParentNode)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)] has no connection status, proceeding..."}
$selectdelete = $myXML2.SelectSingleNode("//Gps/dictionary/item[Key='$nodeid']", $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)]; no GPS dictionary data found, proceeding..."}
$selectdelete = $myXML2.SelectSingleNode("//ChatHistory/MyObjectBuilder_ChatHistory[IdentityId='$nodeid']", $ns2)
Try{$selectdelete.ParentNode.RemoveChild($selectdelete)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)]; no player owned chat data found, proceeding..."}
$otherchat=$null
$selectdelete = $myXML2.SelectNodes("//ChatHistory/MyObjectBuilder_ChatHistory/PlayerChatHistory/MyObjectBuilder_PlayerChatHistory[ID='$nodeid']", $ns2)
ForEach($otherchat in $selectdelete){
Try{$otherchat.ParentNode.RemoveChild($otherchat)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)]; no other chat data found, proceeding..."}
}
$node.ParentNode.RemoveChild($node)
$deletedplayer = $deletedplayer + 1
}
}
#remove empty factions
$nodeFactions = $myXML2.SelectNodes("//Factions/Factions/MyObjectBuilder_Faction" , $ns2)
ForEach($faction in $nodeFactions){
$membercount = $faction.SelectNodes("Members/MyObjectBuilder_FactionMember" , $ns2).count
$factionid = $faction.FactionId
If($membercount -eq 0 -or $membercount -eq $null){
$selectdelete = $myXML2.SelectNodes("//Factions/Requests/MyObjectBuilder_FactionRequests[FactionId='$factionid']" , $ns2)
ForEach($selected in $selectdelete){
$selected.ParentNode.RemoveChild($selected)
}
$selectdelete = $myXML2.SelectNodes("//Factions/Relations/MyObjectBuilder_FactionRelation[FactionId1='$factionid' or FactionId2='$factionid']" , $ns2)
ForEach($selected in $selectdelete){
$selected.ParentNode.RemoveChild($selected)
}
$selectdelete = $myXML2.SelectNodes("//FactionChatHistory/MyObjectBuilder_FactionChatHistory[ID1='$factionid'] | //FactionChatHistory/MyObjectBuilder_FactionChatHistory[ID2='$factionid']" , $ns2)
ForEach($selected in $selectdelete){
Try{$selected.ParentNode.RemoveChild($selected)}
Catch{Write-Host -ForegroundColor Green "[$($node.DisplayName)]; no other faction chat data found, proceeding..."}
}
#Add-Content -Path $playerspath -Value "Deleted faction $($faction.Name) ..."
#Write-Host -ForegroundColor Green "actioned! $membercount"
$faction.ParentNode.RemoveChild($faction)
$deletefactions = $deletefactions + 1
}
#IF($membercount -ne 0 -or $membercount-ne $null){Write-Host -ForegroundColor Green "no action $membercount"}
}
#purge chats
$factionchats = $myXML2.SelectNodes("//FactionChatHistory/MyObjectBuilder_FactionChatHistory" , $ns2)
ForEach($chat in $factionchats){
$chat.ParentNode.RemoveChild($chat)
}
$chathistory = $myXML2.SelectNodes("//ChatHistory/MyObjectBuilder_ChatHistory" , $ns2)
ForEach($chathist in $chathistory){
$chathist.ParentNode.RemoveChild($chathist)
}
$myXML.Save($filePath)
$myXML2.Save($filePath2)