@@ -91,6 +91,14 @@ public void PurgeIdentities(int days)
9191 Context . Respond ( $ "Removed { count } old identities and { count2 } grids owned by them.") ;
9292 }
9393
94+ [ Command ( "rep wipe" , "Resets the reputation on the server" ) ]
95+ public void WipeReputation ( bool removePlayerToFaction = true , bool removeFactionToFaction = true )
96+ {
97+ var count = WipeRep ( removePlayerToFaction , removeFactionToFaction ) ;
98+ Context . Respond ( $ "Wiped { count } reputations") ;
99+ }
100+
101+
94102 [ Command ( "faction clean" , "Removes factions with fewer than the given number of players." ) ]
95103 public void CleanFactions ( int memberCount = 1 )
96104 {
@@ -316,6 +324,11 @@ public void CleanSandbox()
316324 //clean up empty factions
317325 count += CleanFaction_Internal ( ) ;
318326
327+ //cleanup reputations
328+
329+ count += CleanupReputations ( ) ;
330+
331+
319332 //Keen, for the love of god why is everything about GPS internal.
320333 var playerGpss = GpsDicField . GetValue ( MySession . Static . Gpss ) as Dictionary < long , Dictionary < int , MyGps > > ;
321334 foreach ( var id in playerGpss . Keys )
@@ -368,5 +381,98 @@ public void CleanSandbox()
368381
369382 Context . Respond ( $ "Removed { count } unnecessary elements.") ;
370383 }
384+
385+ [ ReflectedGetter ( Name = "m_relationsBetweenFactions" , Type = typeof ( MyFactionCollection ) ) ]
386+ private static Func < MyFactionCollection , Dictionary < MyFactionCollection . MyRelatablePair , Tuple < MyRelationsBetweenFactions , int > > > _relationsGet ;
387+ [ ReflectedGetter ( Name = "m_relationsBetweenPlayersAndFactions" , Type = typeof ( MyFactionCollection ) ) ]
388+ private static Func < MyFactionCollection , Dictionary < MyFactionCollection . MyRelatablePair , Tuple < MyRelationsBetweenFactions , int > > > _playerRelationsGet ;
389+
390+ private static int WipeRep ( bool removePlayerToFaction , bool removeFactionToFaction )
391+ {
392+ var result = 0 ;
393+ var collection0 = _relationsGet ( MySession . Static . Factions ) ;
394+ var collection1 = _playerRelationsGet ( MySession . Static . Factions ) ;
395+
396+ if ( removeFactionToFaction )
397+ {
398+ foreach ( var pair in collection0 . Keys . ToList ( ) )
399+ {
400+ collection0 . Remove ( pair ) ;
401+ result ++ ;
402+ }
403+ }
404+
405+ if ( removePlayerToFaction )
406+ {
407+ foreach ( var pair in collection1 . Keys . ToList ( ) )
408+ {
409+ collection1 . Remove ( pair ) ;
410+ result ++ ;
411+ }
412+ }
413+
414+ return result ;
415+
416+ }
417+ private static int CleanupReputations ( )
418+ {
419+ var collection = _relationsGet ( MySession . Static . Factions ) ;
420+ var collection2 = _playerRelationsGet ( MySession . Static . Factions ) ;
421+
422+
423+ var validIdentities = new HashSet < long > ( ) ;
424+
425+ //find all identities owning a block
426+ foreach ( var entity in MyEntities . GetEntities ( ) )
427+ {
428+ var grid = entity as MyCubeGrid ;
429+ if ( grid == null )
430+ continue ;
431+ validIdentities . UnionWith ( grid . SmallOwners ) ;
432+ }
433+
434+
435+ //find online identities
436+ foreach ( var online in MySession . Static . Players . GetOnlinePlayers ( ) )
437+ {
438+ validIdentities . Add ( online . Identity . IdentityId ) ;
439+ }
440+
441+ foreach ( var identity in MySession . Static . Players . GetAllIdentities ( ) . ToList ( ) )
442+ {
443+ if ( MySession . Static . Players . IdentityIsNpc ( identity . IdentityId ) )
444+ {
445+ validIdentities . Add ( identity . IdentityId ) ;
446+ }
447+ }
448+
449+
450+ //might not be necessary, but just in case
451+ validIdentities . Remove ( 0 ) ;
452+ var result = 0 ;
453+
454+ var collection0List = collection . Keys . ToList ( ) ;
455+ var collection1List = collection2 . Keys . ToList ( ) ;
456+
457+ foreach ( var pair in collection0List )
458+ {
459+ if ( validIdentities . Contains ( pair . RelateeId1 ) && validIdentities . Contains ( pair . RelateeId2 ) )
460+ continue ;
461+ collection . Remove ( pair ) ;
462+ }
463+
464+ foreach ( var pair in collection1List )
465+ {
466+ if ( validIdentities . Contains ( pair . RelateeId1 ) && validIdentities . Contains ( pair . RelateeId2 ) )
467+ continue ;
468+ collection2 . Remove ( pair ) ;
469+ }
470+
471+
472+ //_relationsSet.Invoke(MySession.Static.Factions,collection);
473+ //_playerRelationsSet.Invoke(MySession.Static.Factions,collection2);
474+ return result ;
475+ }
476+
371477 }
372478}
0 commit comments