internal static void WorldBuild( Player player, Command cmd ) {
string worldName = cmd.Next();
// Print information about the current world
if( worldName == null ) {
if( player == Player.Console ) {
player.Message( "When calling /wbuild from console, you must specify a world name." );
} else {
player.World.BuildSecurity.PrintDescription( player, player.World, "world", "modified" );
}
return;
}
// Find a world by name
World world = WorldManager.FindWorldOrPrintMatches( player, worldName );
if( world == null ) return;
string name = cmd.Next();
if( name == null ) {
world.BuildSecurity.PrintDescription( player, world, "world", "modified" );
return;
}
bool changesWereMade = false;
do {
if( name.Length < 2 ) continue;
// Whitelisting individuals
if( name.StartsWith( "+" ) ) {
PlayerInfo info;
if( !PlayerDB.FindPlayerInfo( name.Substring( 1 ), out info ) ) {
player.Message( "More than one player found matching \"{0}\"", name.Substring( 1 ) );
continue;
} else if( info == null ) {
player.NoPlayerMessage( name.Substring( 1 ) );
continue;
}
// prevent players from whitelisting themselves to bypass protection
if( player.Info == info && !player.Info.Rank.AllowSecurityCircumvention ) {
switch( world.BuildSecurity.CheckDetailed( player.Info ) ) {
case SecurityCheckResult.RankTooLow:
player.Message( "&WYou must be {0}&W+ to add yourself to the build whitelist of {0}",
world.BuildSecurity.MinRank.GetClassyName(),
world.GetClassyName() );
continue;
// TODO: RankTooHigh
case SecurityCheckResult.BlackListed:
player.Message( "&WYou cannot remove yourself from the build blacklist of {0}",
world.GetClassyName() );
continue;
}
}
if( world.BuildSecurity.CheckDetailed( info ) == SecurityCheckResult.Allowed ) {
player.Message( "{0}&S is already allowed to build in {1}&S (by rank)",
info.GetClassyName(), world.GetClassyName() );
continue;
}
Player target = Server.FindPlayerExact( info );
if( target == player ) target = null; // to avoid duplicate messages
switch( world.BuildSecurity.Include( info ) ) {
case PermissionOverride.Deny:
if( world.BuildSecurity.Check( info ) ) {
player.Message( "{0}&S is no longer barred from building in {1}",
info.GetClassyName(), world.GetClassyName() );
if( target != null ) {
target.Message( "You can now build in world {0}&S (removed from blacklist by {1}&S).",
world.GetClassyName(), player.GetClassyName() );
}
} else {
player.Message( "{0}&S was removed from the build blacklist of {1}&S. " +
"Player is still NOT allowed to build (by rank).",
info.GetClassyName(), world.GetClassyName() );
if( target != null ) {
target.Message( "You were removed from the build blacklist of world {0}&S by {1}&S. " +
"You are still NOT allowed to build (by rank).",
player.GetClassyName(), world.GetClassyName() );
}
}
Logger.Log( "{0} removed {1} from the build blacklist of {2}", LogType.UserActivity,
player.Name, info.Name, world.Name );
changesWereMade = true;
break;
case PermissionOverride.None:
player.Message( "{0}&S is now allowed to build in {1}",
info.GetClassyName(), world.GetClassyName() );
if( target != null ) {
target.Message( "You can now build in world {0}&S (whitelisted by {1}&S).",
world.GetClassyName(), player.GetClassyName() );
}
Logger.Log( "{0} added {1} to the build whitelist on world {2}", LogType.UserActivity,
player.Name, info.Name, world.Name );
changesWereMade = true;
break;
case PermissionOverride.Allow:
player.Message( "{0}&S is already on the build whitelist of {1}",
info.GetClassyName(), world.GetClassyName() );
break;
}
// Blacklisting individuals
} else if( name.StartsWith( "-" ) ) {
PlayerInfo info;
if( !PlayerDB.FindPlayerInfo( name.Substring( 1 ), out info ) ) {
player.Message( "More than one player found matching \"{0}\"", name.Substring( 1 ) );
continue;
} else if( info == null ) {
player.NoPlayerMessage( name.Substring( 1 ) );
continue;
}
if( world.BuildSecurity.CheckDetailed( info ) == SecurityCheckResult.RankTooHigh ||
world.BuildSecurity.CheckDetailed( info ) == SecurityCheckResult.RankTooLow ) {
player.Message( "{0}&S is already barred from building in {1}&S (by rank)",
info.GetClassyName(), world.GetClassyName() );
continue;
}
Player target = Server.FindPlayerExact( info );
if( target == player ) target = null; // to avoid duplicate messages
switch( world.BuildSecurity.Exclude( info ) ) {
case PermissionOverride.Deny:
player.Message( "{0}&S is already on build blacklist of {1}",
info.GetClassyName(), world.GetClassyName() );
break;
case PermissionOverride.None:
player.Message( "{0}&S is now barred from building in {1}",
info.GetClassyName(), world.GetClassyName() );
if( target != null ) {
target.Message( "&WYou were barred by {0}&W from building in world {1}",
player.GetClassyName(), world.GetClassyName() );
}
Logger.Log( "{0} added {1} to the build blacklist on world {2}", LogType.UserActivity,
player.Name, info.Name, world.Name );
changesWereMade = true;
break;
case PermissionOverride.Allow:
if( world.BuildSecurity.Check( info ) ) {
player.Message( "{0}&S is no longer on the build whitelist of {1}&S. " +
"Player is still allowed to build (by rank).",
info.GetClassyName(), world.GetClassyName() );
if( target != null ) {
target.Message( "You were removed from the build whitelist of world {0}&S by {1}&S. " +
"You are still allowed to build (by rank).",
player.GetClassyName(), world.GetClassyName() );
}
} else {
player.Message( "{0}&S is no longer allowed to build in {1}",
info.GetClassyName(), world.GetClassyName() );
if( target != null ) {
target.Message( "&WYou can no longer build in world {0}&W (removed from whitelist by {1}&W).",
world.GetClassyName(), player.GetClassyName() );
}
}
Logger.Log( "{0} removed {1} from the build whitelist on world {2}", LogType.UserActivity,
player.Name, info.Name, world.Name );
changesWereMade = true;
break;
}
// Setting minimum rank
} else {
Rank rank = RankManager.FindRank( name );
if( rank == null ) {
player.NoRankMessage( name );
} else if( !player.Info.Rank.AllowSecurityCircumvention &&
world.BuildSecurity.MinRank > rank &&
world.BuildSecurity.MinRank > player.Info.Rank ) {
player.Message( "&WYou must be ranked {0}&W+ to lower build restrictions for world {1}",
world.BuildSecurity.MinRank.GetClassyName(), world.GetClassyName() );
} else {
// list players who are redundantly blacklisted
SecurityController.PlayerListCollection lists = world.BuildSecurity.ExceptionList;
PlayerInfo[] noLongerExcluded = lists.Excluded.Where( excludedPlayer => excludedPlayer.Rank < rank ).ToArray();
if( noLongerExcluded.Length > 0 ) {
player.Message( "Following players no longer need to be blacklisted on world {0}&S: {1}",
world.GetClassyName(),
noLongerExcluded.JoinToClassyString() );
}
// list players who are redundantly whitelisted
PlayerInfo[] noLongerIncluded = lists.Included.Where( includedPlayer => includedPlayer.Rank >= rank ).ToArray();
if( noLongerIncluded.Length > 0 ) {
player.Message( "Following players no longer need to be whitelisted on world {0}&S: {1}",
world.GetClassyName(),
noLongerIncluded.JoinToClassyString() );
}
// apply changes
world.BuildSecurity.MinRank = rank;
changesWereMade = true;
if( world.BuildSecurity.MinRank == RankManager.LowestRank ) {
Server.SendToAll( "{0}&S allowed anyone to build on world {1}",
player.GetClassyName(), world.GetClassyName() );
} else {
Server.SendToAll( "{0}&S allowed only {1}+&S to build in world {2}",
player.GetClassyName(), world.BuildSecurity.MinRank.GetClassyName(), world.GetClassyName() );
}
Logger.Log( "{0} set build rank for world {1} to {2}+", LogType.UserActivity,
player.Name, world.Name, world.BuildSecurity.MinRank.Name );
}
}
} while( (name = cmd.Next()) != null );
if( changesWereMade ) {
WorldManager.SaveWorldList();
}
}