static void TrollHandler(Player player, Command cmd) { string Name = cmd.Next(); if (Name == null) { player.Message("Player not found. Please specify valid name."); return; } if (!Player.IsValidName(Name)) return; Player target = Server.FindPlayerOrPrintMatches(player, Name, true, true); if (target == null) return; string options = cmd.Next(); if (options == null) { CdTroll.PrintUsage(player); return; } string Message = cmd.NextAll(); if (Message.Length < 1 && options.ToLower() != "leave") { player.Message("&WError: Please enter a message for {0}.", target.ClassyName); return; } switch (options.ToLower()) { case "pm": if (player.Can(Permission.UseColorCodes) && Message.Contains("%")) { Message = Color.ReplacePercentCodes(Message); } Server.Players.Message("&Pfrom {0}: {1}", target.Name, Message); break; case "ac": Chat.SendAdmin(target, Message); break; case "st": case "staff": Chat.SendStaff(target, Message); break; case "i": case "impersonate": case "msg": case "message": case "m": Server.Message("{0}&S&F: {1}", target.ClassyName, Message); break; case "leave": case "disconnect": case "gtfo": Server.Players.Message("&SPlayer {0}&S left the server.", target.ClassyName); break; default: player.Message("Invalid option. Please choose st, ac, pm, message or leave"); break; } }
protected FuncDrawOperation(Player player, Command cmd) : base(player) { string strFunc = cmd.Next(); if (string.IsNullOrWhiteSpace(strFunc)) { player.Message("&WEmpty function expression"); return; } if (strFunc.Length < 3) { player.Message("&WExpression is too short (should be like z=f(x,y))"); return; } strFunc = strFunc.ToLower(); _vaxis = GetAxis(SimpleParser.PreparseAssignment(ref strFunc)); _expression = SimpleParser.Parse(strFunc, GetVarArray(_vaxis)); Player.Message("Expression parsed as "+_expression.Print()); string scalingStr=cmd.Next(); _scaler = new Scaler(scalingStr); }
void DoZone( Player player, Command cmd ) { if( !player.Can( Permissions.SetSpawn ) ) { world.NoAccessMessage( player ); return; } string name = cmd.Next(); if( name == null ) { player.Message( "No zone name specified. See " + Color.Help + "/help zone" ); return; } if( !Player.IsValidName( name ) ) { player.Message( "\"" + name + "\" is not a valid zone name" ); return; } Zone zone = new Zone(); zone.name = name; string property = cmd.Next(); if( property == null ) { player.Message( "No zone rank/whitelist/blacklist specified. See " + Color.Help + "/help zone" ); return; } PlayerClass minRank = world.classes.ParseClass( property ); if( minRank != null ) { zone.buildRank = minRank.rank; player.tag = zone; player.marksExpected = 2; player.marks.Clear(); player.markCount = 0; player.selectionCallback = MakeZone; } }
internal static void BRB(Player player, Command cmd) { StreamReader streamReader = new StreamReader("plugins/brbMessage.txt"); string message = streamReader.ReadToEnd(); streamReader.Close(); string msg = cmd.NextAll().Trim(); if (player.Info.IsMuted) { player.MessageMuted(); return; } if (msg.Length > 0) { Server.Message("{0}&S &EWill Brb &9({1})", player.ClassyName, msg); player.IsAway = true; return; } else { Server.Players.Message("&S{0} &EWill Brb &9(" + message + ")", player.ClassyName); player.IsAway = true; } }
static void PayHandler(Player player, Command cmd) { string targetName = cmd.Next(); string money = cmd.Next(); int amount; if (money == null) { player.Message("&ePlease select the amount of bits you wish to send."); return; } Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true); if (target == null) { player.Message("&ePlease select a player to pay bits towards."); return; } if (!int.TryParse(money, out amount)) { player.Message("&ePlease select from a whole number."); return; } PayHandler(player, new Command("/economy pay " + target + " " + money)); }
public static void SetParametrization(Player p, Command cmd) { string strFunc = cmd.Next(); if (string.IsNullOrWhiteSpace(strFunc)) { p.Message("Error: empty parametrization expression"); return; } if (strFunc.Length < 3) { p.Message("Error: expression is too short (should be like x=f(t,u,v))"); return; } strFunc = strFunc.ToLower(); try { string coordVar = SimpleParser.PreparseAssignment(ref strFunc); CheckCoordVar(coordVar); Expression expression = SimpleParser.Parse(strFunc, new string[] { "t", "u", "v" }); p.Message("Expression parsed as " + coordVar + "=" + expression.Print()); GetPlayerParametrizationCoordsStorage(p)[VarNameToIdx(coordVar[0])] = expression; } catch (Exception e) { p.Message("Error: "+e.Message); } }
internal static void StaffChat( Player player, Command cmd ) { if( player.Info.IsMuted ) { player.MutedMessage(); return; } if( DateTime.UtcNow < player.Info.MutedUntil ) { player.Message( "You are muted for another {0:0} seconds.", player.Info.MutedUntil.Subtract( DateTime.UtcNow ).TotalSeconds ); return; } Player[] plist = Server.PlayerList; if( plist.Length > 0 ) player.Info.LinesWritten++; string message = cmd.NextAll(); if( message != null && message.Trim().Length > 0 ) { message = message.Trim(); if( player.Can( Permission.UseColorCodes ) && message.Contains( "%" ) ) { message = Color.ReplacePercentCodes( message ); } for( int i = 0; i < plist.Length; i++ ) { if( (plist[i].Can( Permission.ReadStaffChat ) || plist[i] == player) && !plist[i].IsIgnoring( player.Info ) ) { plist[i].Message( "{0}(staff){1}{0}: {2}", Color.PM, player.GetClassyName(), message ); } } } }
internal static void CModeWater(Player player, Command cmd) { if (!player.Can(Permissions.ControlPhysics)) { player.NoAccessMessage(Permissions.ControlPhysics); return; } string blockpar = cmd.Next(); string wmt = ""; int BlockAddr = -1; try { BlockAddr = Convert.ToInt32(blockpar); } catch { player.Message("Incorrect parameter!"); return; } if (BlockAddr < 3 && BlockAddr >= 0) { player.world.map.modeWater = BlockAddr; switch (BlockAddr) { case 0: wmt = "'none'"; break; case 1: wmt = "'infinite'"; break; case 2: wmt = "'finite'"; break; } player.Message("Water mode set to " + wmt + "."); } }
internal static void CancelDraw( Player player, Command command ) { if( player.marksExpected > 0 ) { player.marksExpected = 0; } else { player.Message( "There is currently nothing to cancel." ); } }
public bool Call( Player player, Command cmd, bool raiseEvent ) { if( player == null ) throw new ArgumentNullException( "player" ); if( cmd == null ) throw new ArgumentNullException( "cmd" ); if( raiseEvent && CommandManager.RaiseCommandCallingEvent( cmd, this, player ) ) return false; Handler( player, cmd ); if( raiseEvent ) CommandManager.RaiseCommandCalledEvent( cmd, this, player ); return true; }
void Paint( Player player, Command cmd ) { player.replaceMode = !player.replaceMode; if( player.replaceMode ){ player.Message( "Replacement mode: ON" ); } else { player.Message( "Replacement mode: OFF" ); } }
void Compass( Player player, Command cmd ) { int offset = (int)(player.pos.r / 255f * 64f) + 32; string name = cmd.Next(); if( name != null ) { Player target = world.FindPlayer( name ); if( target != null ) { player.Message( "Coordinates of player \"" + target.name + "\":" ); offset = (int)(target.pos.r / 255f * 64f) + 32; } else { world.NoPlayerMessage( player, name ); return; } } player.Message( Color.Silver, String.Format( "({0},{1},{2}) - {3}[{4}{5}{6}{3}{7}]", player.pos.x / 32, player.pos.y / 32, player.pos.h / 32, Color.White, compass.Substring( offset - 12, 11 ), Color.Red, compass.Substring( offset - 1, 3 ), compass.Substring( offset + 2, 11 ) ) ); }
public bool IsConfirmed; // whether this command has been confirmed by the user (with /ok) public Command( Command other ) { if( other == null ) throw new ArgumentNullException( "other" ); offset = other.offset; Message = other.Message; Name = other.Name; IsConfirmed = other.IsConfirmed; }
internal static void DumpStats( Player player, Command cmd ) { string fileName = cmd.Next(); if( fileName == null ) { cdDumpStats.PrintUsage( player ); return; } if( !Paths.Contains( Paths.WorkingPath, fileName ) ) { player.UnsafePathMessage(); return; } if( Paths.IsProtectedFileName( Path.GetFileName( fileName ) ) ) { player.Message( "You may not use this file." ); return; } if( Path.HasExtension( fileName ) && !Path.GetExtension( fileName ).Equals( ".txt", StringComparison.OrdinalIgnoreCase ) ) { player.Message( "Stats filename must end with .txt" ); return; } if( File.Exists( fileName ) && !cmd.IsConfirmed ) { player.AskForConfirmation( cmd, "File \"{0}\" already exists. Overwrite?", Path.GetFileName( fileName ) ); return; } if( !Paths.TestFile( "dumpstats file", fileName, false, true, false ) ) { player.Message( "Cannot create specified file. See log for details." ); return; } PlayerInfo[] infos; using( FileStream fs = File.Create( fileName ) ) { using( StreamWriter writer = new StreamWriter( fs ) ) { infos = PlayerDB.GetPlayerListCopy(); if( infos.Length == 0 ) { writer.WriteLine( "{0} (0 players)", "(TOTAL)" ); writer.WriteLine(); } else { DumpPlayerGroupStats( writer, infos, "(TOTAL)" ); } foreach( Rank rank in RankManager.Ranks ) { infos = PlayerDB.GetPlayerListCopy( rank ); if( infos.Length == 0 ) { writer.WriteLine( "{0} (0 players)", rank.Name ); writer.WriteLine(); } else { DumpPlayerGroupStats( writer, infos, rank.Name ); } } } } player.Message( "Stats saved to \"{0}\"", Path.GetFileName( fileName ) ); }
internal static void Colors( Player player, Command cmd ) { StringBuilder sb = new StringBuilder( "List of colors: " ); foreach( var color in Color.ColorNames ) { sb.AppendFormat( "&{0}%{0} {1} ", color.Key, color.Value ); } player.Message( sb.ToString() ); }
void Load( Player player, Command cmd ) { lock( loadLock ) { if( world.loadInProgress || world.loadSendingInProgress ) { player.Message( "Loading already in progress, please wait." ); return; } world.loadInProgress = true; } if( !player.Can( Permissions.SaveAndLoad ) ) { world.NoAccessMessage( player ); world.loadInProgress = false; return; } string mapName = cmd.Next(); if( mapName == null ) { player.Message( "Syntax: " + Color.Help + "/load mapName" ); world.loadInProgress = false; return; } string mapFileName = mapName + ".fcm"; if( !File.Exists( mapFileName ) ) { player.Message( "No backup file \"" + mapName + "\" found." ); world.loadInProgress = false; return; } Map newMap = Map.Load( world, mapFileName ); if( newMap == null ) { player.Message( "Could not load \"" + mapFileName + "\". Check logfile for details." ); world.loadInProgress = false; return; } if( newMap.widthX != world.map.widthX || newMap.widthY != world.map.widthY || newMap.height != world.map.height ) { player.Message( "Map sizes of \"" + mapName + "\" and the current map do not match." ); world.loadInProgress = false; return; } world.log.Log( "{0} is loading the map \"{1}\".", LogType.UserActivity, player.name, mapName ); player.Message( "Loading map \"" + mapName + "\"..." ); world.BeginLockDown(); MapSenderParams param = new MapSenderParams() { map = newMap, player = player, world = world }; world.tasks.Add( MapSender.StreamLoad, param, true ); }
void Lava( Player player, Command cmd ) { if( player.mode == BlockPlacementMode.Lava ) { player.mode = BlockPlacementMode.Normal; player.Message( "Lava: OFF." ); } else if( player.Can( Permissions.PlaceWater ) ) { player.mode = BlockPlacementMode.Lava; player.Message( "Lava: ON. Red blocks are replaced with lava." ); } else { world.NoAccessMessage( player ); } }
void Solid( Player player, Command cmd ) { if( player.mode == BlockPlacementMode.Solid ){ player.mode = BlockPlacementMode.Normal; player.Message( "Solid: OFF" ); } else if( player.Can( Permissions.PlaceAdmincrete ) ) { player.mode = BlockPlacementMode.Solid; player.Message( "Solid: ON" ); } else { world.NoAccessMessage( player ); } }
void Water( Player player, Command cmd ) { if( player.mode == BlockPlacementMode.Water ) { player.mode = BlockPlacementMode.Normal; player.Message( "Water: OFF" ); } else if( player.Can( Permissions.PlaceWater ) ) { player.mode = BlockPlacementMode.Water; player.Message( "Water: ON. Blue blocks are replaced with water." ); } else { world.NoAccessMessage( player ); } }
void Grass( Player player, Command cmd ) { if( player.mode == BlockPlacementMode.Grass ) { player.mode = BlockPlacementMode.Normal; player.Message( "Grass: OFF" ); } else if( player.Can( Permissions.PlaceGrass ) ) { player.mode = BlockPlacementMode.Grass; player.Message( "Grass: ON. Dirt blocks are replaced with grass." ); } else { world.NoAccessMessage( player ); } }
internal static void Hardened(Player player, Command cmd) { if (player.hardenedMode == BlockPlacementMode.Hardened) { player.hardenedMode = BlockPlacementMode.Normal; player.Message("Hardened blocks: OFF"); } else if (player.Can(Permissions.PlaceHardenedBlocks)) { player.hardenedMode = BlockPlacementMode.Hardened; player.Message("Hardened blocks: ON"); } else { player.NoAccessMessage( Permissions.PlaceHardenedBlocks ); } }
public RandomMazeDrawOperation(Player player, Command cmd) : base(player) { int xSize = CommandOrDefault(cmd, DefaultXSize); int ySize = CommandOrDefault(cmd, DefaultYSize); int zSize = CommandOrDefault(cmd, DefaultZSize); ReadFlags(cmd); _cellSize = DefaultCellSize; _playersBrush = player.Brush.MakeInstance(player, cmd, this); _maze = new Maze(xSize, ySize, zSize); }
internal static void WorldInfo( Player player, Command cmd ) { string worldName = cmd.Next(); if( worldName == null ) { if( player.World == null ) { player.Message( "Please specify a world name when calling /winfo form console." ); return; } else { worldName = player.World.Name; } } World world = WorldManager.FindWorldOrPrintMatches( player, worldName ); if( world == null ) return; player.Message( "World {0}&S has {1} player(s) on.", world.GetClassyName(), world.CountVisiblePlayers(player) ); Map map = world.Map; // If map is not currently loaded, grab its header from disk if( map == null ) { try { map = MapUtility.LoadHeader( Path.Combine( Paths.MapPath, world.GetMapName() ) ); } catch( Exception ex ) { player.Message( "Map information could not be loaded: {0}: {1}", ex.GetType().Name, ex.Message ); } } if( map != null ) { player.Message( "Map dimensions are {0} x {1} x {2}", map.WidthX, map.WidthY, map.Height ); } // Print access/build limits world.AccessSecurity.PrintDescription( player, world, "world", "accessed" ); world.BuildSecurity.PrintDescription( player, world, "world", "modified" ); // Print lock/unlock information if( world.IsLocked ) { player.Message( "{0}&S was locked {1} ago by {2}", world.GetClassyName(), DateTime.UtcNow.Subtract( world.LockedDate ).ToMiniString(), world.LockedBy ); } else if( world.UnlockedBy != null ) { player.Message( "{0}&S was unlocked {1} ago by {2}", world.GetClassyName(), DateTime.UtcNow.Subtract( world.UnlockedDate ).ToMiniString(), world.UnlockedBy ); } }
void Draw( Player player, Command command, DrawMode mode ) { if( !player.Can( Permissions.Draw ) ) { world.NoAccessMessage( player ); return; } if( player.drawingInProgress ) { player.Message( "Another draw command is already in progress. Please wait." ); return; } string blockName = command.Next(); Block block; if( blockName == null || blockName == "" ) { if( mode == DrawMode.Cuboid ) { player.Message( "Usage: " + Color.Help + "/cuboid blockName" + Color.Sys + " or " + Color.Help + "/cub blockName" ); } else { player.Message( "Usage: " + Color.Help + "/ellipsoid blockName" + Color.Sys + " or " + Color.Help + "/ell blockName" ); } return; } try { block = Map.GetBlockByName( blockName ); } catch( Exception ) { player.Message( "Unknown block name: " + blockName ); return; } player.tag = block; Permissions permission = Permissions.Build; switch( block ) { case Block.Admincrete: permission = Permissions.PlaceAdmincrete; break; case Block.Air: permission = Permissions.Delete; break; case Block.Water: case Block.StillWater: permission = Permissions.PlaceWater; break; case Block.Lava: case Block.StillLava: permission = Permissions.PlaceLava; break; } if( !player.Can( permission ) ) { player.Message( "You are not allowed to draw with this block." ); return; } player.marksExpected = 2; player.markCount = 0; player.marks.Clear(); player.Message( mode.ToString() + ": Place a block or type /mark to use your location." ); if( mode == DrawMode.Cuboid ) { player.selectionCallback = DrawCuboid; } else { player.selectionCallback = DrawEllipsoid; } }
static void StaffHandler( Player player, Command cmd ) { if( player.Info.IsMuted ) { player.MessageMuted(); return; } if( player.DetectChatSpam() ) return; string message = cmd.NextAll().Trim(); if( message.Length > 0 ) { Chat.SendStaff( player, message ); } }
internal void ParseCommand( Player player, string message, bool fromConsole ) { Command cmd = new Command( message ); if( consoleSafeHandlers.ContainsKey( cmd.name ) ) { consoleSafeHandlers[cmd.name]( player, cmd ); } else if( handlers.ContainsKey( cmd.name ) ) { if( fromConsole ) { player.Message( "You cannot use this command from console." ); } else { handlers[cmd.name]( player, cmd ); } } else { player.Message( "Unrecognized command: " + cmd.name ); } }
public static void ProcessCommand( Player p, Command cmd ) { string command = cmd.Next(); if ( String.IsNullOrWhiteSpace( command ) ) { p.Message( "&WLife command is missing or empty" ); return; } LifeCommand c; if ( !Commands.TryGetValue( command.ToLower(), out c ) ) { p.Message( "&WUnknown life command " + command + ". &hType '/life help' for the list of commands." ); return; } c.F( p, cmd ); }
private static void GuildChatHandler( Player player, Command cmd ) { Guild guild = GuildManager.PlayersGuild( player.Info ); if ( guild == null ) { player.Message( "You do not have a guild" ); return; } string msg = cmd.NextAll(); if ( string.IsNullOrEmpty( msg ) ) { player.Message( "&WMessage cannot be null: /Gc [message to send]" ); return; } guild.SendGuildMessage( player, msg ); return; }
static void QuitHandler(Player player, Command cmd) { string Msg = cmd.NextAll(); if (Msg.Length < 1) { CdQuit.PrintUsage(player); return; } else { player.Info.LeaveMsg = "left the server: &C" + Msg; player.Message("Your quit message is now set to: {0}", Msg); } }
static void StaffHandler( Player player, Command cmd ) { if( player.Info.IsMuted ) { player.MessageMuted(); return; } if( player.DetectChatSpam() ) return; string message = cmd.NextAll().Trim(); if( message.Length > 0 ) { if( player.Can( Permission.UseColorCodes ) && message.Contains( "%" ) ) { message = Color.ReplacePercentCodes( message ); } Chat.SendStaff( player, message ); } }
public static void VoteHandler(Player player, Command cmd) { fCraft.VoteHandler.VoteParams(player, cmd); }
static void TimerHandler(Player player, Command cmd) { string param = cmd.Next(); // List timers if (param == null) { ChatTimer[] list = ChatTimer.TimerList.OrderBy(timer => timer.TimeLeft).ToArray(); if (list.Length == 0) { player.Message("No timers running."); } else { player.Message("There are {0} timers running:", list.Length); foreach (ChatTimer timer in list) { player.Message(" #{0} \"{1}&S\" (started by {2}, {3} left)", timer.Id, timer.Message, timer.StartedBy, timer.TimeLeft.ToMiniString()); } } return; } // Abort a timer if (param.Equals("abort", StringComparison.OrdinalIgnoreCase)) { int timerId; if (cmd.NextInt(out timerId)) { ChatTimer timer = ChatTimer.FindTimerById(timerId); if (timer == null || !timer.IsRunning) { player.Message("Given timer (#{0}) does not exist.", timerId); } else { timer.Stop(); string abortMsg = String.Format("&Y(Timer) {0}&Y aborted a timer with {1} left: {2}", player.ClassyName, timer.TimeLeft.ToMiniString(), timer.Message); Chat.SendSay(player, abortMsg); } } else { CdTimer.PrintUsage(player); } return; } // Start a timer if (player.Info.IsMuted) { player.MessageMuted(); return; } if (player.DetectChatSpam()) { return; } TimeSpan duration; if (!param.TryParseMiniTimespan(out duration)) { CdTimer.PrintUsage(player); return; } if (duration > DateTimeUtil.MaxTimeSpan) { player.MessageMaxTimeSpan(); return; } if (duration < ChatTimer.MinDuration) { player.Message("Timer: Must be at least 1 second."); return; } string sayMessage; string message = cmd.NextAll(); if (String.IsNullOrEmpty(message)) { sayMessage = String.Format("&Y(Timer) {0}&Y started a {1} timer", player.ClassyName, duration.ToMiniString()); } else { sayMessage = String.Format("&Y(Timer) {0}&Y started a {1} timer: {2}", player.ClassyName, duration.ToMiniString(), message); } Chat.SendSay(player, sayMessage); ChatTimer.Start(duration, message, player.Name); }
public static void RealmCreate(Player player, Command cmd, string themeName, string templateName) { MapGenTemplate template; MapGenTheme theme; int wx, wy, height = 128; if (!(cmd.NextInt(out wx) && cmd.NextInt(out wy) && cmd.NextInt(out height))) { if (player.World != null) { wx = 128; wy = 128; height = 128; } else { player.Message("When used from console, /gen requires map dimensions."); return; } cmd.Rewind(); cmd.Next(); cmd.Next(); } if (!Map.IsValidDimension(wx)) { player.Message("Cannot make map with width {0}: dimensions must be multiples of 16.", wx); return; } else if (!Map.IsValidDimension(wy)) { player.Message("Cannot make map with length {0}: dimensions must be multiples of 16.", wy); return; } else if (!Map.IsValidDimension(height)) { player.Message("Cannot make map with height {0}: dimensions must be multiples of 16.", height); return; } string fileName = player.Name; if (player.Name.Contains('.')) { fileName = player.Name.Replace(".", "-"); //support for email names } string fullFileName = null; if (fileName == null) { if (player.World == null) { player.Message("When used from console, /gen requires FileName."); return; } if (!cmd.IsConfirmed) { player.Confirm(cmd, "Replace this realm's map with a generated one?"); return; } } else { fileName = fileName.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); if (!fileName.EndsWith(".fcm", StringComparison.OrdinalIgnoreCase)) { fileName += ".fcm"; } fullFileName = Path.Combine(Paths.MapPath, fileName); if (!Paths.IsValidPath(fullFileName)) { player.Message("Invalid filename."); return; } if (!Paths.Contains(Paths.MapPath, fullFileName)) { player.MessageUnsafePath(); return; } string dirName = fullFileName.Substring(0, fullFileName.LastIndexOf(Path.DirectorySeparatorChar)); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } if (!cmd.IsConfirmed && File.Exists(fullFileName)) { player.Confirm(cmd, "The mapfile \"{0}\" already exists. Overwrite?", fileName); return; } } bool noTrees; if (themeName.Equals("grass", StringComparison.OrdinalIgnoreCase)) { theme = MapGenTheme.Forest; noTrees = true; } else { try { theme = (MapGenTheme)Enum.Parse(typeof(MapGenTheme), themeName, true); noTrees = (theme != MapGenTheme.Forest); } catch (Exception) { player.MessageNow("Unrecognized theme \"{0}\". Available themes are: Grass, {1}", themeName, String.Join(", ", Enum.GetNames(typeof(MapGenTheme)))); return; } } try { template = (MapGenTemplate)Enum.Parse(typeof(MapGenTemplate), templateName, true); } catch (Exception) { player.Message("Unrecognized template \"{0}\". Available templates are: {1}", templateName, String.Join(", ", Enum.GetNames(typeof(MapGenTemplate)))); return; } if (!Enum.IsDefined(typeof(MapGenTheme), theme) || !Enum.IsDefined(typeof(MapGenTemplate), template)) { return; } MapGeneratorArgs args = MapGenerator.MakeTemplate(template); args.MapWidth = wx; args.MapLength = wy; args.MapHeight = height; args.MaxHeight = (int)(args.MaxHeight / 80d * height); args.MaxDepth = (int)(args.MaxDepth / 80d * height); args.Theme = theme; args.AddTrees = !noTrees; Map map; try { if (theme == MapGenTheme.Forest && noTrees) { player.MessageNow("Generating Grass {0}...", template); } else { player.MessageNow("Generating {0} {1}...", theme, template); } if (theme == MapGenTheme.Forest && noTrees && template == MapGenTemplate.Flat) { map = MapGenerator.GenerateFlatgrass(args.MapWidth, args.MapLength, args.MapHeight); } else { MapGenerator generator = new MapGenerator(args); map = generator.Generate(); } } catch (Exception ex) { Logger.Log(LogType.Error, "MapGenerator: Generation failed: {0}", ex); player.MessageNow("&WAn error occured while generating the map."); return; } if (fileName != null) { if (map.Save(fullFileName)) { player.MessageNow("Generation done. Saved to {0}", fileName); } else { player.Message("&WAn error occured while saving generated map to {0}", fileName); } } else { player.MessageNow("Generation done. Changing map..."); player.World.ChangeMap(map); } }
public static void RealmLoad(Player player, Command cmd, string fileName, string worldName) { if (worldName == null && player.World == null) { player.Message("When using /realm from console, you must specify the realm name."); return; } if (fileName == null) { // No params given at all return; } string fullFileName = WorldManager.FindMapFile(player, fileName); if (fullFileName == null) return; // Loading map into current realm if (worldName == null) { if (!cmd.IsConfirmed) { player.Confirm(cmd, "About to replace THIS REALM with \"{0}\".", fileName); return; } Map map; try { map = MapUtility.Load(fullFileName); } catch (Exception ex) { player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message); return; } World realm = player.World; // Loading to current realm realm.MapChangedBy = player.Name; realm.ChangeMap(map); realm.Players.Message(player, "{0}&S loaded a new map for this realm.", player.ClassyName); player.MessageNow("New map loaded for the realm {0}", realm.ClassyName); Logger.Log(LogType.UserActivity, "{0} loaded new map for realm \"{1}\" from {2}", player.Name, realm.Name, fileName); realm.IsHidden = false; realm.IsRealm = true; WorldManager.SaveWorldList(); } else { // Loading to some other (or new) realm if (!World.IsValidName(worldName)) { player.MessageInvalidWorldName(worldName); return; } string buildRankName = cmd.Next(); string accessRankName = cmd.Next(); Rank buildRank = RankManager.DefaultBuildRank; Rank accessRank = null; if (buildRankName != null) { buildRank = RankManager.FindRank(buildRankName); if (buildRank == null) { player.MessageNoRank(buildRankName); return; } if (accessRankName != null) { accessRank = RankManager.FindRank(accessRankName); if (accessRank == null) { player.MessageNoRank(accessRankName); return; } } } // Retype realm name, if needed if (worldName == "-") { if (player.LastUsedWorldName != null) { worldName = player.LastUsedWorldName; } else { player.Message("Cannot repeat realm name: you haven't used any names yet."); return; } } lock (WorldManager.SyncRoot) { World realm = WorldManager.FindWorldExact(worldName); if (realm != null) { player.LastUsedWorldName = realm.Name; // Replacing existing realm's map if (!cmd.IsConfirmed) { player.Confirm(cmd, "About to replace realm map for {0}&S with \"{1}\".", realm.ClassyName, fileName); return; } Map map; try { map = MapUtility.Load(fullFileName); realm.IsHidden = false; realm.IsRealm = true; WorldManager.SaveWorldList(); } catch (Exception ex) { player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message); return; } try { realm.MapChangedBy = player.Name; realm.ChangeMap(map); realm.IsHidden = false; realm.IsRealm = true; WorldManager.SaveWorldList(); } catch (WorldOpException ex) { Logger.Log(LogType.Error, "Could not complete RealmLoad operation: {0}", ex.Message); player.Message("&WRealmLoad: {0}", ex.Message); return; } realm.Players.Message(player, "{0}&S loaded a new map for the realm {1}", player.ClassyName, realm.ClassyName); player.MessageNow("New map for the realm {0}&S has been loaded.", realm.ClassyName); Logger.Log(LogType.UserActivity, "{0} loaded new map for realm \"{1}\" from {2}", player.Name, realm.Name, fullFileName); } else { // Adding a new realm string targetFullFileName = Path.Combine(Paths.MapPath, worldName + ".fcm"); if (!cmd.IsConfirmed && File.Exists(targetFullFileName) && // target file already exists !Paths.Compare(targetFullFileName, fullFileName)) { // and is different from sourceFile player.Confirm(cmd, "A map named \"{0}\" already exists, and will be overwritten with \"{1}\".", Path.GetFileName(targetFullFileName), Path.GetFileName(fullFileName)); return; } Map map; try { map = MapUtility.Load(fullFileName); //realm.IsHidden = false; //realm.IsRealm = true; //WorldManager.SaveWorldList(); } catch (Exception ex) { player.MessageNow("Could not load \"{0}\": {1}: {2}", fileName, ex.GetType().Name, ex.Message); return; } World newWorld; try { newWorld = WorldManager.AddWorld(player, worldName, map, false); } catch (WorldOpException ex) { player.Message("RealmLoad: {0}", ex.Message); return; } player.LastUsedWorldName = worldName; newWorld.BuildSecurity.MinRank = buildRank; if (accessRank == null) { newWorld.AccessSecurity.ResetMinRank(); } else { newWorld.AccessSecurity.MinRank = accessRank; } newWorld.BlockDB.AutoToggleIfNeeded(); if (BlockDB.IsEnabledGlobally && newWorld.BlockDB.IsEnabled) { player.Message("BlockDB is now auto-enabled on realm {0}", newWorld.ClassyName); } newWorld.LoadedBy = player.Name; newWorld.LoadedOn = DateTime.UtcNow; Server.Message("{0}&S created a new realm named {1}", player.ClassyName, newWorld.ClassyName); Logger.Log(LogType.UserActivity, "{0} created a new realm named \"{1}\" (loaded from \"{2}\")", player.Name, worldName, fileName); newWorld.IsHidden = false; newWorld.IsRealm = true; WorldManager.SaveWorldList(); player.MessageNow("Access permission is {0}+&S, and build permission is {1}+", newWorld.AccessSecurity.MinRank.ClassyName, newWorld.BuildSecurity.MinRank.ClassyName); } } } Server.RequestGC(); }
internal static void RealmAccess(Player player, Command cmd, string worldName, string name) { // Print information about the current realm if (worldName == null) { if (player.World == null) { player.Message("Error."); } else { player.Message(player.World.AccessSecurity.GetDescription(player.World, "realm", "accessed")); } return; } // Find a realm by name World realm = WorldManager.FindWorldOrPrintMatches(player, worldName); if (realm == null) return; if (name == null) { player.Message(realm.AccessSecurity.GetDescription(realm, "realm", "accessed")); return; } if (realm == WorldManager.MainWorld) { player.Message("The main realm cannot have access restrictions."); 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.MessageNoPlayer(name.Substring(1)); continue; } // prevent players from whitelisting themselves to bypass protection if (realm.AccessSecurity.CheckDetailed(info) == SecurityCheckResult.Allowed) { player.Message("{0}&S is already allowed to access {1}&S (by rank)", info.ClassyName, realm.ClassyName); continue; } Player target = info.PlayerObject; if (target == player) target = null; // to avoid duplicate messages switch (realm.AccessSecurity.Include(info)) { case PermissionOverride.Deny: if (realm.AccessSecurity.Check(info)) { player.Message("{0}&S is unbanned from Realm {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You are now unbanned from Realm {0}&S (removed from blacklist by {1}&S).", realm.ClassyName, player.ClassyName); } } else { player.Message("{0}&S was unbanned from Realm {1}&S. " + "Player is still NOT allowed to join (by rank).", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You were Unbanned from Realm {0}&S by {1}&S. " + "You are still NOT allowed to join (by rank).", player.ClassyName, realm.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the access blacklist of {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.None: player.Message("{0}&S is now allowed to access {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You can now access realm {0}&S (whitelisted by {1}&S).", realm.ClassyName, player.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the access whitelist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.Allow: player.Message("{0}&S is already on the access whitelist of {1}", info.ClassyName, realm.ClassyName); 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.MessageNoPlayer(name.Substring(1)); continue; } if (realm.AccessSecurity.CheckDetailed(info) == SecurityCheckResult.RankTooHigh || realm.AccessSecurity.CheckDetailed(info) == SecurityCheckResult.RankTooLow) { player.Message("{0}&S is already barred from accessing {1}&S (by rank)", info.ClassyName, realm.ClassyName); continue; } Player target = info.PlayerObject; if (target == player) target = null; // to avoid duplicate messages switch (realm.AccessSecurity.Exclude(info)) { case PermissionOverride.Deny: player.Message("{0}&S is already banned from Realm {1}", info.ClassyName, realm.ClassyName); break; case PermissionOverride.None: player.Message("{0}&S is now banned from accessing {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("&WYou were banned by {0}&W from accessing realm {1}", player.ClassyName, realm.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the access blacklist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.Allow: if (realm.AccessSecurity.Check(info)) { player.Message("{0}&S is no longer on the access whitelist of {1}&S. " + "Player is still allowed to join (by rank).", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You were banned from Realm {0}&S by {1}&S. " + "You are still allowed to join (by rank).", player.ClassyName, realm.ClassyName); } } else { player.Message("{0}&S is no longer allowed to access {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("&WYou were banned from Realm {0}&W (Banned by {1}&W).", realm.ClassyName, player.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the access whitelist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; } // Setting minimum rank } else { Rank rank = RankManager.FindRank(name); if (rank == null) { player.MessageNoRank(name); } else { // list players who are redundantly blacklisted var exceptionList = realm.AccessSecurity.ExceptionList; PlayerInfo[] noLongerExcluded = exceptionList.Excluded.Where(excludedPlayer => excludedPlayer.Rank < rank).ToArray(); if (noLongerExcluded.Length > 0) { player.Message("Following players no longer need to be blacklisted to be barred from {0}&S: {1}", realm.ClassyName, noLongerExcluded.JoinToClassyString()); } // list players who are redundantly whitelisted PlayerInfo[] noLongerIncluded = exceptionList.Included.Where(includedPlayer => includedPlayer.Rank >= rank).ToArray(); if (noLongerIncluded.Length > 0) { player.Message("Following players no longer need to be whitelisted to access {0}&S: {1}", realm.ClassyName, noLongerIncluded.JoinToClassyString()); } // apply changes realm.AccessSecurity.MinRank = rank; changesWereMade = true; if (realm.AccessSecurity.MinRank == RankManager.LowestRank) { Server.Message("{0}&S made the realm {1}&S accessible to everyone.", player.ClassyName, realm.ClassyName); } else { Server.Message("{0}&S made the realm {1}&S accessible only by {2}+", player.ClassyName, realm.ClassyName, realm.AccessSecurity.MinRank.ClassyName); } Logger.Log(LogType.UserActivity, "{0} set access rank for realm {1} to {2}+", player.Name, realm.Name, realm.AccessSecurity.MinRank.Name); } } } while ((name = cmd.Next()) != null); if (changesWereMade) { var playersWhoCantStay = realm.Players.Where(p => !p.CanJoin(realm)); foreach (Player p in playersWhoCantStay) { p.Message("&WYou are no longer allowed to join realm {0}", realm.ClassyName); p.JoinWorld(WorldManager.MainWorld, WorldChangeReason.PermissionChanged); } WorldManager.SaveWorldList(); } }
internal static void RealmBuild(Player player, Command cmd, string worldName, string name, string NameIfRankIsName) { // Print information about the current realm if (worldName == null) { if (player.World == null) { player.Message("When calling /wbuild from console, you must specify a realm name."); } else { player.Message(player.World.BuildSecurity.GetDescription(player.World, "realm", "modified")); } return; } // Find a realm by name World realm = WorldManager.FindWorldOrPrintMatches(player, worldName); if (realm == null) return; if (name == null) { player.Message(realm.BuildSecurity.GetDescription(realm, "realm", "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.MessageNoPlayer(name.Substring(1)); continue; } if (realm.BuildSecurity.CheckDetailed(info) == SecurityCheckResult.Allowed) { player.Message("{0}&S is already allowed to build in {1}&S (by rank)", info.ClassyName, realm.ClassyName); continue; } Player target = info.PlayerObject; if (target == player) target = null; // to avoid duplicate messages switch (realm.BuildSecurity.Include(info)) { case PermissionOverride.Deny: if (realm.BuildSecurity.Check(info)) { player.Message("{0}&S is no longer barred from building in {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You can now build in realm {0}&S (removed from blacklist by {1}&S).", realm.ClassyName, player.ClassyName); } } else { player.Message("{0}&S was removed from the build blacklist of {1}&S. " + "Player is still NOT allowed to build (by rank).", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You were removed from the build blacklist of realm {0}&S by {1}&S. " + "You are still NOT allowed to build (by rank).", player.ClassyName, realm.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the build blacklist of {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.None: player.Message("{0}&S is now allowed to build in {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("You can now build in realm {0}&S (whitelisted by {1}&S).", realm.ClassyName, player.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the build whitelist on realm {2}", player.Name, info.Name, realm.Name); break; case PermissionOverride.Allow: player.Message("{0}&S is already on the build whitelist of {1}", info.ClassyName, realm.ClassyName); 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.MessageNoPlayer(name.Substring(1)); continue; } if (realm.BuildSecurity.CheckDetailed(info) == SecurityCheckResult.RankTooHigh || realm.BuildSecurity.CheckDetailed(info) == SecurityCheckResult.RankTooLow) { player.Message("{0}&S is already barred from building in {1}&S (by rank)", info.ClassyName, realm.ClassyName); continue; } Player target = info.PlayerObject; if (target == player) target = null; // to avoid duplicate messages switch (realm.BuildSecurity.Exclude(info)) { case PermissionOverride.Deny: player.Message("{0}&S is already on build blacklist of {1}", info.ClassyName, realm.ClassyName); break; case PermissionOverride.None: player.Message("{0}&S is now barred from building in {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("&WYou were barred by {0}&W from building in realm {1}", player.ClassyName, realm.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the build blacklist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; case PermissionOverride.Allow: if (realm.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.ClassyName, realm.ClassyName); if (target != null) { target.Message("You were removed from the build whitelist of realm {0}&S by {1}&S. " + "You are still allowed to build (by rank).", player.ClassyName, realm.ClassyName); } } else { player.Message("{0}&S is no longer allowed to build in {1}", info.ClassyName, realm.ClassyName); if (target != null) { target.Message("&WYou can no longer build in realm {0}&W (removed from whitelist by {1}&W).", realm.ClassyName, player.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the build whitelist on realm {2}", player.Name, info.Name, realm.Name); changesWereMade = true; break; } // Setting minimum rank } else { Rank rank = RankManager.FindRank(name); if (rank == null) { player.MessageNoRank(name); } else if (!player.Info.Rank.AllowSecurityCircumvention && realm.BuildSecurity.MinRank > rank && realm.BuildSecurity.MinRank > player.Info.Rank) { player.Message("&WYou must be ranked {0}&W+ to lower build restrictions for realm {1}", realm.BuildSecurity.MinRank.ClassyName, realm.ClassyName); } else { // list players who are redundantly blacklisted var exceptionList = realm.BuildSecurity.ExceptionList; PlayerInfo[] noLongerExcluded = exceptionList.Excluded.Where(excludedPlayer => excludedPlayer.Rank < rank).ToArray(); if (noLongerExcluded.Length > 0) { player.Message("Following players no longer need to be blacklisted on realm {0}&S: {1}", realm.ClassyName, noLongerExcluded.JoinToClassyString()); } // list players who are redundantly whitelisted PlayerInfo[] noLongerIncluded = exceptionList.Included.Where(includedPlayer => includedPlayer.Rank >= rank).ToArray(); if (noLongerIncluded.Length > 0) { player.Message("Following players no longer need to be whitelisted on realm {0}&S: {1}", realm.ClassyName, noLongerIncluded.JoinToClassyString()); } // apply changes realm.BuildSecurity.MinRank = rank; changesWereMade = true; if (realm.BuildSecurity.MinRank == RankManager.LowestRank) { Server.Message("{0}&S allowed anyone to build on realm {1}", player.ClassyName, realm.ClassyName); } else { Server.Message("{0}&S allowed only {1}+&S to build in realm {2}", player.ClassyName, realm.BuildSecurity.MinRank.ClassyName, realm.ClassyName); } Logger.Log(LogType.UserActivity, "{0} set build rank for realm {1} to {2}+", player.Name, realm.Name, realm.BuildSecurity.MinRank.Name); } } } while ((name = cmd.Next()) != null); if (changesWereMade) { WorldManager.SaveWorldList(); } }