├── f2k.ico
├── f2k.png
├── ServerGUI
├── f2k.ico
├── app.config
├── Properties
│ └── AssemblyInfo.cs
├── Program.cs
├── ConsoleBox.cs
└── ServerGUI.csproj
├── fCraftGUI
├── Tileset.png
├── TilesetShadowed.png
├── IMapGeneratorGuiProvider.cs
├── IsoCatResult.cs
├── IsoCatMode.cs
├── AboutWindow.cs
├── Properties
│ ├── AssemblyInfo.cs
│ └── Resources.Designer.cs
├── DefaultMapGenGui.cs
├── DefaultMapGenGui.Designer.cs
├── FlatMapGenGui.cs
├── MapGeneratorGui.cs
└── MapGenGuiUtil.cs
├── ConfigGUI
├── Resources
│ ├── disk.png
│ ├── map--arrow.png
│ ├── maps-stack.png
│ ├── ChatBackground.png
│ └── fcraft_config.ico
├── MinecraftFont
│ ├── minecraft.ttf
│ ├── LICENSE.txt
│ └── README.txt
├── app.config
├── Program.cs
├── CustomPictureBox.cs
├── DeleteRankPopup.cs
├── ChatPreview.Designer.cs
├── Properties
│ └── AssemblyInfo.cs
├── PermissionLimitBox.cs
├── TextEditorPopup.cs
├── PermissionLimitBox.Designer.cs
├── KeywordPicker.cs
├── KeywordPicker.Designer.cs
├── UpdaterSettingsPopup.cs
└── ColorPicker.cs
├── ServerCLI
├── fcraft_console.ico
├── app.config
├── Properties
│ └── AssemblyInfo.cs
└── ServerCLI.csproj
├── UpdateInstaller
├── fcraft_updater.ico
├── app.config
├── app.manifest
└── Properties
│ ├── AssemblyInfo.cs
│ └── Resources.Designer.cs
├── fCraft
├── app.config
├── Drawing
│ ├── Axis.cs
│ ├── DrawOps
│ │ ├── QuickPasteDrawOperation.cs
│ │ ├── SphereDrawOperation.cs
│ │ ├── SphereHollowDrawOperation.cs
│ │ ├── LineDrawOperation.cs
│ │ ├── CuboidDrawOperation.cs
│ │ ├── EllipsoidDrawOperation.cs
│ │ ├── UndoDrawOperation.cs
│ │ ├── TorusDrawOperation.cs
│ │ ├── TriangleWireframeDrawOperation.cs
│ │ ├── CuboidHollowDrawOperation.cs
│ │ └── CutDrawOperation.cs
│ ├── Brushes
│ │ └── RainbowBrush.cs
│ ├── DrawOpWithBrush.cs
│ ├── UndoState.cs
│ └── CopyState.cs
├── Utils
│ ├── IClassy.cs
│ ├── YesNoAuto.cs
│ ├── EventInterfaces.cs
│ ├── RWLSExtension.cs
│ ├── FormatUtil.cs
│ └── LogRecorder.cs
├── MapGeneration
│ ├── MapGenTheme.cs
│ ├── RealisticMapGenTerrainType.cs
│ ├── EmptyMapGen.cs
│ ├── MapGenerator.cs
│ └── MapGeneratorState.cs
├── Network
│ ├── PacketReader.cs
│ ├── PacketWriter.cs
│ ├── OpCode.cs
│ └── IRCMessage.cs
├── World
│ ├── BlockDBSearchType.cs
│ ├── BlockUpdate.cs
│ ├── Block.cs
│ ├── BlockChangeContext.cs
│ ├── BlockDBEntry.cs
│ └── World.Events.cs
├── System
│ ├── ShutdownReason.cs
│ ├── ConfigSection.cs
│ ├── ArgKey.cs
│ └── ShutdownParams.cs
├── MapConversion
│ ├── MapRaw.cs
│ ├── MapFormatException.cs
│ ├── MapFormat.cs
│ ├── IMapConverter.cs
│ ├── MapIndev.cs
│ └── MyneMetaFile.cs
├── Commands
│ └── CommandCategory.cs
├── Player
│ ├── SearchOptions.cs
│ └── Position.cs
├── Properties
│ └── AssemblyInfo.cs
└── AutoRank
│ └── Criterion.cs
├── MapConverter
├── app.config
├── ReturnCode.cs
├── Properties
│ └── AssemblyInfo.cs
└── MapConverter.csproj
├── MapRenderer
├── app.config
├── ReturnCode.cs
├── RenderTask.cs
├── Properties
│ └── AssemblyInfo.cs
├── MapRendererParams.cs
├── BlockingQueue.cs
└── MapRenderer.csproj
├── HeartbeatSaver
├── app.config
├── ReturnCode.cs
├── Properties
│ └── AssemblyInfo.cs
└── HeartbeatSaver.csproj
└── UpdaterBuilder
├── app.config
├── Program.cs
└── Properties
└── AssemblyInfo.cs
/f2k.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/f2k.ico
--------------------------------------------------------------------------------
/f2k.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/f2k.png
--------------------------------------------------------------------------------
/ServerGUI/f2k.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/ServerGUI/f2k.ico
--------------------------------------------------------------------------------
/fCraftGUI/Tileset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/fCraftGUI/Tileset.png
--------------------------------------------------------------------------------
/ConfigGUI/Resources/disk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/ConfigGUI/Resources/disk.png
--------------------------------------------------------------------------------
/ServerCLI/fcraft_console.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/ServerCLI/fcraft_console.ico
--------------------------------------------------------------------------------
/fCraftGUI/TilesetShadowed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/fCraftGUI/TilesetShadowed.png
--------------------------------------------------------------------------------
/ConfigGUI/Resources/map--arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/ConfigGUI/Resources/map--arrow.png
--------------------------------------------------------------------------------
/ConfigGUI/Resources/maps-stack.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/ConfigGUI/Resources/maps-stack.png
--------------------------------------------------------------------------------
/UpdateInstaller/fcraft_updater.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/UpdateInstaller/fcraft_updater.ico
--------------------------------------------------------------------------------
/ConfigGUI/MinecraftFont/minecraft.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/ConfigGUI/MinecraftFont/minecraft.ttf
--------------------------------------------------------------------------------
/ConfigGUI/Resources/ChatBackground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/ConfigGUI/Resources/ChatBackground.png
--------------------------------------------------------------------------------
/ConfigGUI/Resources/fcraft_config.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstefarov/fCraft/HEAD/ConfigGUI/Resources/fcraft_config.ico
--------------------------------------------------------------------------------
/fCraft/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ConfigGUI/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/MapConverter/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/MapRenderer/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ServerCLI/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ServerGUI/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/HeartbeatSaver/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/UpdateInstaller/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/UpdaterBuilder/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/HeartbeatSaver/ReturnCode.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft.HeartbeatSaver {
4 | enum ReturnCode {
5 | UsageError = 1,
6 | HeartbeatDataReadingError = 2
7 | }
8 | }
--------------------------------------------------------------------------------
/ConfigGUI/MinecraftFont/LICENSE.txt:
--------------------------------------------------------------------------------
1 | This "Minecraft" font was adapted into TrueType file by me (DjDCH).
2 |
3 | This "Minecraft" font is licensed under a Creative Commons Attribution Share Alike license (http://creativecommons.org/licenses/by-sa/3.0/).
4 |
5 | The "DjDCH" name is own by me (http://djdch.com/).
6 |
7 | The "Minecraft" font style was made by Notch.
8 |
9 | The "Minecraft" game is own by Mojang Specifications.
--------------------------------------------------------------------------------
/MapRenderer/ReturnCode.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 |
3 | namespace fCraft.MapRenderer {
4 | enum ReturnCode {
5 | Success = 0,
6 | ArgumentError = 1,
7 | UnrecognizedImporter = 2,
8 | InputPathNotFound = 4,
9 | PathError = 5,
10 | UnsupportedLoadFormat = 6,
11 | UnsupportedSaveFormat = 7
12 | }
13 | }
--------------------------------------------------------------------------------
/MapConverter/ReturnCode.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 |
3 | namespace fCraft.MapConverter {
4 | enum ReturnCode {
5 | Success = 0,
6 | ArgumentError = 1,
7 | UnrecognizedImporter = 2,
8 | UnrecognizedExporter = 3,
9 | InputPathNotFound = 4,
10 | PathError = 5,
11 | UnsupportedLoadFormat = 6,
12 | UnsupportedSaveFormat = 7
13 | }
14 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/Axis.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft.Drawing {
4 | /// Axis/orientation in a 3D space.
5 | public enum Axis {
6 | /// X axis (along width).
7 | X,
8 |
9 | /// Y axis (along length). Notch's Z/height.
10 | Y,
11 |
12 | /// Z axis (along height). Notch's Y/depth.
13 | Z
14 | }
15 | }
--------------------------------------------------------------------------------
/fCraft/Utils/IClassy.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using JetBrains.Annotations;
3 |
4 | namespace fCraft {
5 | /// Provides a way for printing an object's name beautified with Minecraft color codes.
6 | /// It was "classy" in a sense that it was colored based on "class" (rank) of a player/world/zone.
7 | public interface IClassy {
8 | /// Name optionally formatted with minecraft color codes or other decorations.
9 | [NotNull]
10 | string ClassyName { get; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/fCraft/Utils/YesNoAuto.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft {
4 | /// Three state enum used for parameters which can be manually enabled/disabled (yes/no),
5 | /// or left alone (auto). Default value is "Auto".
6 | public enum YesNoAuto {
7 | /// Indicates that automatically-deduced or default value should be used.
8 | Auto,
9 |
10 | /// Indicates "true" in all cases.
11 | Yes,
12 |
13 | /// Indicates "false" in all cases.
14 | No
15 | }
16 | }
--------------------------------------------------------------------------------
/fCraft/MapGeneration/MapGenTheme.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 |
3 | namespace fCraft.MapGeneration {
4 | /// Map generator themes. A theme defines what type of blocks are used to fill the map.
5 | public enum MapGenTheme {
6 | Arctic,
7 | Desert,
8 | Forest, // just like "Grass", but with trees (when available)
9 | Grass,
10 | Hell,
11 | Swamp, // also with trees
12 | /* TODO:
13 | Winter,
14 | Tropical,
15 | Jungle,
16 | Wasteland
17 | */
18 | }
19 | }
--------------------------------------------------------------------------------
/fCraftGUI/IMapGeneratorGuiProvider.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 |
4 | namespace fCraft.GUI {
5 | /// Represents a class that provides a GUI for chosen map generation parameters.
6 | /// Creates IMapGeneratorGui on demand.
7 | /// Associated with specific MapGenerator, by name.
8 | public interface IMapGeneratorGuiProvider {
9 | string Name { get; }
10 | Version Version { get; }
11 | bool IsCompatible( string generatorName, Version generatorVersion );
12 |
13 | MapGeneratorGui CreateGui();
14 | }
15 | }
--------------------------------------------------------------------------------
/fCraft/Network/PacketReader.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System.IO;
3 | using System.Net;
4 | using System.Text;
5 | using JetBrains.Annotations;
6 |
7 | namespace fCraft {
8 | sealed class PacketReader : BinaryReader {
9 | public PacketReader( [NotNull] Stream stream ) :
10 | base( stream ) { }
11 |
12 |
13 | public override short ReadInt16() {
14 | return IPAddress.NetworkToHostOrder( base.ReadInt16() );
15 | }
16 |
17 |
18 | public override string ReadString() {
19 | return Encoding.ASCII.GetString( ReadBytes( 64 ) ).Trim();
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/fCraft/MapGeneration/RealisticMapGenTerrainType.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 |
3 | namespace fCraft.MapGeneration {
4 | /// Map generator terrain type template.
5 | /// These define landscape shapes and features.
6 | public enum RealisticMapGenTerrainType {
7 | Defaults, // Random
8 | Archipelago,
9 | Atoll,
10 | Bay,
11 | Dunes,
12 | Flat,
13 | Hills,
14 | Ice,
15 | Island,
16 | Lake,
17 | Mountains,
18 | Peninsula,
19 | River,
20 | Streams
21 | }
22 | }
--------------------------------------------------------------------------------
/fCraft/World/BlockDBSearchType.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft {
4 | /// Describes what kind of results should BlockDB.Lookup return.
5 | public enum BlockDBSearchType {
6 | /// All BlockDB Entries (even those that have been overridden) are returned,
7 | /// possibly multiple entries per coordinate.
8 | ReturnAll,
9 |
10 | /// Only one newest entry is returned for each coordinate.
11 | ReturnNewest,
12 |
13 | /// Only one oldest entry is returned for each coordinate.
14 | ReturnOldest
15 | }
16 | }
--------------------------------------------------------------------------------
/fCraftGUI/IsoCatResult.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright 2009-2013 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 |
3 | using System.Drawing;
4 | using JetBrains.Annotations;
5 |
6 | namespace fCraft.GUI {
7 | public sealed class IsoCatResult {
8 | internal IsoCatResult( bool cancelled, [CanBeNull] Bitmap bitmap, Rectangle cropRectangle ) {
9 | Cancelled = cancelled;
10 | Bitmap = bitmap;
11 | CropRectangle = cropRectangle;
12 | }
13 |
14 | public bool Cancelled { get; private set; }
15 |
16 | [CanBeNull]
17 | public Bitmap Bitmap { get; private set; }
18 |
19 | public Rectangle CropRectangle { get; private set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/fCraftGUI/IsoCatMode.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 |
3 | namespace fCraft.GUI {
4 | /// Drawing/clipping mode of IsoCat map renderer.
5 | public enum IsoCatMode {
6 | /// Normal isometric view.
7 | Normal,
8 |
9 | /// Isometric view with the outermost layer of blocks stripped (useful for boxed maps).
10 | Peeled,
11 |
12 | /// Isometric view with a front-facing quarter of the map cut out (to show map cross-section).
13 | Cut,
14 |
15 | /// Only a specified chunk of the map is drawn.
16 | Chunk
17 | }
18 | }
--------------------------------------------------------------------------------
/fCraft/Utils/EventInterfaces.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft {
5 | /// An EventArgs for an event that can be cancelled.
6 | public interface ICancelableEvent {
7 | /// Set to "true" to cancel the event.
8 | bool Cancel { get; set; }
9 | }
10 |
11 |
12 | /// Simple interface for objects to notify of changes in their serializable state.
13 | /// This event is used to trigger saving things like Zone- and MetadataCollection.
14 | /// sender should be set for EventHandler, and e should be set to EventArgs.Empty
15 | interface INotifiesOnChange {
16 | event EventHandler Changed;
17 | }
18 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/QuickPasteDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft.Drawing {
4 | /// Draw operation that handles non-aligned (single-mark) pasting for /Paste and /PasteNot.
5 | /// Preserves original orientation of the CopyState.
6 | sealed class QuickPasteDrawOperation : PasteDrawOperation {
7 | public override string Name {
8 | get {
9 | return Not ? "PasteNot" : "Paste";
10 | }
11 | }
12 |
13 | public QuickPasteDrawOperation( Player player, bool not )
14 | : base( player, not ) {
15 | }
16 |
17 | public override bool Prepare( Vector3I[] marks ) {
18 | return base.Prepare( new[] { marks[0], marks[0] } );
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/MapRenderer/RenderTask.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 |
4 | namespace fCraft.MapRenderer {
5 | /// Holds all information related to a single map-rendering task.
6 | class RenderTask {
7 | public Byte[] Result { get; set; }
8 | public Map Map { get; set; }
9 | public Exception Exception { get; set; }
10 | public string MapPath { get; private set; }
11 | public string TargetPath { get; private set; }
12 | public string RelativeName { get; private set; }
13 |
14 | public RenderTask( string mapPath, string targetPath, string relativeName ) {
15 | MapPath = mapPath;
16 | TargetPath = targetPath;
17 | RelativeName = relativeName;
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/ConfigGUI/Program.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Windows.Forms;
4 |
5 | namespace fCraft.ConfigGUI {
6 | static class Program {
7 | [STAThread]
8 | static void Main() {
9 | Application.EnableVisualStyles();
10 | Application.SetCompatibleTextRenderingDefault( false );
11 | #if DEBUG
12 | Application.Run( new MainForm() );
13 | #else
14 | try {
15 | Application.Run( new MainForm() );
16 | } catch( Exception ex ) {
17 | Logger.LogAndReportCrash( "Error in ConfigGUI", "ConfigGUI", ex, true );
18 | if( !Server.HasArg( ArgKey.ExitOnCrash ) ) {
19 | MessageBox.Show( ex.ToString(), "fCraft ConfigGUI has crashed" );
20 | }
21 | }
22 | #endif
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/fCraftGUI/AboutWindow.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Diagnostics;
4 | using System.Windows.Forms;
5 |
6 | namespace fCraft.GUI {
7 | public sealed partial class AboutWindow : Form {
8 | public AboutWindow() {
9 | InitializeComponent();
10 | lSubheader.Text = String.Format( lSubheader.Text, Updater.CurrentRelease.VersionString );
11 | tCredits.Select( 0, 0 );
12 | }
13 |
14 | private void linkLabel1_LinkClicked( object sender, LinkLabelLinkClickedEventArgs e ) {
15 | try {
16 | Process.Start( "http://www.fcraft.net" );
17 | } catch { }
18 | }
19 |
20 | private void linkLabel2_LinkClicked( object sender, LinkLabelLinkClickedEventArgs e ) {
21 | try {
22 | Process.Start( "mailto:me@matvei.org" );
23 | } catch { }
24 | }
25 |
26 | }
27 | }
--------------------------------------------------------------------------------
/fCraft/Network/PacketWriter.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.IO;
4 | using System.Net;
5 | using System.Text;
6 | using JetBrains.Annotations;
7 |
8 | namespace fCraft {
9 | sealed class PacketWriter : BinaryWriter {
10 | public PacketWriter( [NotNull] Stream stream )
11 | : base( stream ) { }
12 |
13 |
14 | public void Write( OpCode opcode ) {
15 | Write( (byte)opcode );
16 | }
17 |
18 |
19 | public override void Write( short data ) {
20 | base.Write( IPAddress.HostToNetworkOrder( data ) );
21 | }
22 |
23 |
24 | public override void Write( string str ) {
25 | if( str == null ) throw new ArgumentNullException( "str" );
26 | if( str.Length > 64 ) throw new ArgumentException( "String is too long (>64).", "str" );
27 | Write( Encoding.ASCII.GetBytes( str.PadRight( 64 ) ) );
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/ConfigGUI/CustomPictureBox.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System.Drawing.Drawing2D;
3 | using System.Windows.Forms;
4 |
5 | namespace fCraft.ConfigGUI {
6 | // Small extension of PictureBox, that switches between HighQualityBicubic and NearestNeighbor
7 | // interpolation depending on image scale, to make the map images appear as sharp as possible.
8 | // Used by AddWorldPopup.
9 | sealed class CustomPictureBox : PictureBox {
10 | protected override void OnPaint( PaintEventArgs pe ) {
11 | if( Image != null ) {
12 | pe.Graphics.SmoothingMode = SmoothingMode.HighQuality;
13 | pe.Graphics.CompositingQuality = CompositingQuality.HighQuality;
14 | if( Image.Height * 3 > Height || Image.Width * 3 > Width ) {
15 | pe.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
16 | } else {
17 | pe.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
18 | }
19 | }
20 | base.OnPaint( pe );
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/UpdateInstaller/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/fCraft/World/BlockUpdate.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using JetBrains.Annotations;
3 |
4 | namespace fCraft {
5 | /// Structure representing a pending update to the map's block array.
6 | /// Contains information about the block coordinates, type, and change's origin.
7 | public struct BlockUpdate {
8 | /// Player who initiated the block change. Can be null.
9 | [CanBeNull] public readonly Player Origin;
10 |
11 | public readonly short X, Y, Z;
12 |
13 | /// Type of block to set at the given coordinates.
14 | public readonly Block BlockType;
15 |
16 | public BlockUpdate( Player origin, short x, short y, short z, Block blockType ) {
17 | Origin = origin;
18 | X = x;
19 | Y = y;
20 | Z = z;
21 | BlockType = blockType;
22 | }
23 |
24 | public BlockUpdate( Player origin, Vector3I coord, Block blockType ) {
25 | Origin = origin;
26 | X = (short)coord.X;
27 | Y = (short)coord.Y;
28 | Z = (short)coord.Z;
29 | BlockType = blockType;
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/ConfigGUI/MinecraftFont/README.txt:
--------------------------------------------------------------------------------
1 | This font was created by "DjDCH" :
2 | http://djdch.com/
3 | The font file in this archive was created using Fontstruct the free, online
4 | font-building tool from FontShop International. Try Fontstruct at :
5 | http://fontstruct.fontshop.com
6 |
7 | LEGAL NOTICE:
8 | In using this font you must comply with the licensing terms described in the
9 | file "LICENSE.txt" included with this archive.
10 | If you redistribute the font file in this archive, it must be accompanied by
11 | all the other files from this archive, including this one.
12 |
13 | NOTE FOR FLASH USERS:
14 | Fontstruct fonts (fontstructions) are optimized for
15 | Flash. If the font in this archive is a pixel font, it is best displayed at a
16 | font-size of 8.
17 |
18 | FONTSTRUCT:
19 | Fontstruct is brought to you by FontShop.
20 | Visit us at http://www.fontshop.com
21 | FontShop is the original independent font retailer. We’ve been around since
22 | the dawn of digital type. Whether you need the right font or need to create the
23 | right font from scratch, let our 19 years of experience work for you.
24 |
25 | COPYRIGHT:
26 | Fontstruct is copyright ©2010 Fontshop FSI and Rob Meek
27 | Fontstruct was created for FontShop International by Rob Meek
28 | (http://www.robmeek.com).
--------------------------------------------------------------------------------
/ConfigGUI/DeleteRankPopup.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Windows.Forms;
4 |
5 | namespace fCraft.ConfigGUI {
6 | public sealed partial class DeleteRankPopup : Form {
7 | internal Rank SubstituteRank { get; private set; }
8 |
9 | public DeleteRankPopup( Rank deletedRank ) {
10 | InitializeComponent();
11 | foreach( Rank rank in RankManager.Ranks ) {
12 | if( rank != deletedRank ) {
13 | cSubstitute.Items.Add( MainForm.ToComboBoxOption( rank ) );
14 | }
15 | }
16 | lWarning.Text = String.Format( lWarning.Text, deletedRank.Name );
17 | cSubstitute.SelectedIndex = cSubstitute.Items.Count - 1;
18 | }
19 |
20 |
21 | private void cSubstitute_SelectedIndexChanged( object sender, EventArgs e ) {
22 | if( cSubstitute.SelectedIndex < 0 ) return;
23 | foreach( Rank rank in RankManager.Ranks ) {
24 | if( cSubstitute.SelectedItem.ToString() != MainForm.ToComboBoxOption( rank ) ) continue;
25 | SubstituteRank = rank;
26 | bDelete.Enabled = true;
27 | break;
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/fCraft/System/ShutdownReason.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft {
4 | /// Categorizes conditions that lead to server shutdowns.
5 | public enum ShutdownReason {
6 | /// Server is shutting down, because someone called /Shutdown.
7 | ShutdownCommand = 0,
8 |
9 | /// Server is restarting, because someone called /Restart.
10 | RestartCommand = 1,
11 |
12 | /// InitLibrary or InitServer failed.
13 | FailedToInitialize = 2,
14 |
15 | /// StartServer failed.
16 | FailedToStart = 3,
17 |
18 | /// Server has experienced a non-recoverable crash.
19 | Crashed = 4,
20 |
21 | /// Server process is being closed (e.g. frontend closed, Ctrl+C, etc)
22 | ProcessClosing = 5,
23 |
24 | /// AutoRestart timer triggered.
25 | RestartTimer = 6,
26 |
27 | /// Updater should be ran, then server should be restarted.
28 | RestartForUpdate = 7,
29 |
30 | /// Updater should be ran, then server should NOT be restarted.
31 | ShutdownForUpdate = 8
32 | }
33 | }
--------------------------------------------------------------------------------
/UpdaterBuilder/Program.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.IO.Compression;
3 |
4 | namespace fCraft.UpdateBuilder {
5 | static class Program {
6 |
7 | static readonly string[] FileList = {
8 | "ConfigGUI.exe",
9 | "fCraft.dll",
10 | "fCraftGUI.dll",
11 | "ServerCLI.exe",
12 | "ServerGUI.exe",
13 | "MapConverter.exe",
14 | "MapRenderer.exe",
15 | "../../CHANGELOG.txt",
16 | "../../README.txt"
17 | };
18 |
19 | const string BinariesFileName = "../../UpdateInstaller/Resources/Payload.zip";
20 |
21 |
22 | static void Main() {
23 | FileInfo binaries = new FileInfo( BinariesFileName );
24 | if( binaries.Exists ) {
25 | binaries.Delete();
26 | }
27 |
28 | using( ZipStorer zs = ZipStorer.Create( binaries.FullName, "" ) ) {
29 | foreach( string file in FileList ) {
30 | FileInfo fi = new FileInfo( file );
31 | if( !fi.Exists ) {
32 | return; // abort if any of the files do not exist
33 | }
34 | zs.AddFile( ZipStorer.Compression.Deflate, fi.FullName, fi.Name, "" );
35 | }
36 | }
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/fCraft/System/ConfigSection.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft {
4 | /// ConfigKey section/category.
5 | public enum ConfigSection {
6 |
7 | /// General server configuration (name, port, default rank, etc).
8 | General,
9 |
10 | /// Chat-related configuration (colors, whether to announce certain events, etc).
11 | Chat,
12 |
13 | /// World-related configuration (main world, default build rank, map folder, etc).
14 | Worlds,
15 |
16 | /// Security-related configuration (name verification, connection limit per IP, anti-spam, etc).
17 | Security,
18 |
19 | /// Saving- and backup-related configuration (save interval, backup intervals, etc).
20 | SavingAndBackup,
21 |
22 | /// Logging-related configuration (what events to log, how to store log files, etc).
23 | Logging,
24 |
25 | /// IRC-related configuration (network, channel list, bot nick, etc).
26 | IRC,
27 |
28 | /// Advanced configuration (performance adjustments, protocol tweaks, experimental features, etc).
29 | Advanced
30 | }
31 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/SphereDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft.Drawing {
5 | /// Draw operation that creates a solid sphere.
6 | public sealed class SphereDrawOperation : EllipsoidDrawOperation {
7 | public override string Name {
8 | get { return "Sphere"; }
9 | }
10 |
11 | public SphereDrawOperation( Player player )
12 | : base( player ) {
13 | }
14 |
15 | public override bool Prepare( Vector3I[] marks ) {
16 | double radius = Math.Sqrt( (marks[0].X - marks[1].X) * (marks[0].X - marks[1].X) +
17 | (marks[0].Y - marks[1].Y) * (marks[0].Y - marks[1].Y) +
18 | (marks[0].Z - marks[1].Z) * (marks[0].Z - marks[1].Z) );
19 |
20 | marks[1].X = (short)Math.Round( marks[0].X - radius );
21 | marks[1].Y = (short)Math.Round( marks[0].Y - radius );
22 | marks[1].Z = (short)Math.Round( marks[0].Z - radius );
23 |
24 | marks[0].X = (short)Math.Round( marks[0].X + radius );
25 | marks[0].Y = (short)Math.Round( marks[0].Y + radius );
26 | marks[0].Z = (short)Math.Round( marks[0].Z + radius );
27 |
28 | return base.Prepare( marks );
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/fCraft/MapConversion/MapRaw.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.IO;
4 |
5 | namespace fCraft.MapConversion {
6 | /// D3 map conversion implementation, for converting D3 map format into fCraft's default map format.
7 | public sealed class MapRaw : IMapExporter {
8 |
9 | public string ServerName {
10 | get { return "Raw"; }
11 | }
12 |
13 | public bool SupportsImport {
14 | get { return false; }
15 | }
16 |
17 | public bool SupportsExport {
18 | get { return true; }
19 | }
20 |
21 | public string FileExtension {
22 | get { return "raw"; }
23 | }
24 |
25 | public MapStorageType StorageType {
26 | get { return MapStorageType.SingleFile; }
27 | }
28 |
29 | public MapFormat Format {
30 | get { return MapFormat.Raw; }
31 | }
32 |
33 | public void Save( Map mapToSave, string fileName ) {
34 | if( mapToSave == null ) throw new ArgumentNullException( "mapToSave" );
35 | if( fileName == null ) throw new ArgumentNullException( "fileName" );
36 | using( FileStream mapStream = File.Create( fileName ) ) {
37 | mapStream.Write( mapToSave.Blocks, 0, mapToSave.Blocks.Length );
38 | }
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/ConfigGUI/ChatPreview.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace fCraft.ConfigGUI {
2 | sealed partial class ChatPreview {
3 | ///
4 | /// Required designer variable.
5 | ///
6 | private System.ComponentModel.IContainer components = null;
7 |
8 | ///
9 | /// Clean up any resources being used.
10 | ///
11 | /// true if managed resources should be disposed; otherwise, false.
12 | protected override void Dispose( bool disposing ) {
13 | if( disposing && (components != null) ) {
14 | components.Dispose();
15 | }
16 | base.Dispose( disposing );
17 | }
18 |
19 | #region Component Designer generated code
20 |
21 | ///
22 | /// Required method for Designer support - do not modify
23 | /// the contents of this method with the code editor.
24 | ///
25 | private void InitializeComponent() {
26 | this.SuspendLayout();
27 | //
28 | // ChatPreview
29 | //
30 | this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
31 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
32 | this.Name = "ChatPreview";
33 | this.Size = new System.Drawing.Size( 283, 92 );
34 | this.ResumeLayout( false );
35 |
36 | }
37 |
38 | #endregion
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/fCraft/Commands/CommandCategory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft {
5 | /// Command categories. A command may belong to more than one category.
6 | /// Use binary flag logic to test whether a command belongs to a particular category.
7 | [Flags]
8 | public enum CommandCategory {
9 | /// Default command category. Do not use it.
10 | None = 0,
11 |
12 | /// Building-related commands: drawing, binding, copy/paste.
13 | Building = 1,
14 |
15 | /// Chat-related commands: messaging, ignoring, muting, etc.
16 | Chat = 2,
17 |
18 | /// Information commands: server, world, zone, rank, and player infos.
19 | Info = 4,
20 |
21 | /// Moderation commands: kick, ban, rank, tp/bring, etc.
22 | Moderation = 8,
23 |
24 | /// Server maintenance commands: reloading configs, editing PlayerDB, importing data, etc.
25 | Maintenance = 16,
26 |
27 | /// World-related commands: joining, loading, renaming, etc.
28 | World = 32,
29 |
30 | /// Zone-related commands: creating, editing, testing, etc.
31 | Zone = 64,
32 |
33 | /// Commands that are only used for diagnostics and debugging.
34 | Debug = 128
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/SphereHollowDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft.Drawing {
5 | /// Draw operation that creates a hollow sphere,
6 | /// or a sphere filled differently on inside and outside.
7 | /// The "shell" of the sphere is always 1 block wide.
8 | public sealed class SphereHollowDrawOperation : EllipsoidHollowDrawOperation {
9 | public override string Name {
10 | get { return "SphereH"; }
11 | }
12 |
13 | public SphereHollowDrawOperation( Player player )
14 | : base( player ) {
15 | }
16 |
17 | public override bool Prepare( Vector3I[] marks ) {
18 | double radius = Math.Sqrt( (marks[0].X - marks[1].X) * (marks[0].X - marks[1].X) +
19 | (marks[0].Y - marks[1].Y) * (marks[0].Y - marks[1].Y) +
20 | (marks[0].Z - marks[1].Z) * (marks[0].Z - marks[1].Z) );
21 |
22 | marks[1].X = (short)Math.Round( marks[0].X - radius );
23 | marks[1].Y = (short)Math.Round( marks[0].Y - radius );
24 | marks[1].Z = (short)Math.Round( marks[0].Z - radius );
25 |
26 | marks[0].X = (short)Math.Round( marks[0].X + radius );
27 | marks[0].Y = (short)Math.Round( marks[0].Y + radius );
28 | marks[0].Z = (short)Math.Round( marks[0].Z + radius );
29 |
30 | return base.Prepare( marks );
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/fCraft/Player/SearchOptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace fCraft {
4 | /// Flags usable with Server and PlayerDB player-search methods.
5 | [Flags]
6 | public enum SearchOptions {
7 | /// Default behavior is: do not include player themself in results;
8 | /// do not consider hidden players to be "online"; do raise events if applicable;
9 | /// do print no-players-found message when applicable.
10 | Default = 0,
11 |
12 | /// Whether player themself should be considered in search.
13 | IncludeSelf = 1,
14 |
15 | /// Whether hidden players should be considered "online" for search purposes, if applicable.
16 | IncludeHidden = 2,
17 |
18 | /// Whether to raise Server.SearchingForPlayer event, if applicable.
19 | SuppressEvent = 4,
20 |
21 | /// This flag controls what search methods do when IncludeSelf flag is not set, and player's
22 | /// own info is the only result. By default, search methods print "no results" message and return null.
23 | /// This flag changes that behavior. When ReturnSelfIfOnlyMatch is set, search methods do not
24 | /// print any message, and return player's own PlayerInfo. This is useful if you want to make a custom
25 | /// "you cannot do this to yourself" message - just check if returned PlayerInfo is player's own.
26 | ReturnSelfIfOnlyMatch = 8
27 | }
28 | }
--------------------------------------------------------------------------------
/fCraft/World/Block.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | #pragma warning disable 1591
4 | namespace fCraft {
5 | /// Enumeration of all standard Minecraft Classic block types.
6 | public enum Block : byte {
7 | None = 255,
8 |
9 | Air = 0,
10 | Stone = 1,
11 | Grass = 2,
12 | Dirt = 3,
13 | Cobblestone = 4,
14 | Wood = 5,
15 | Sapling = 6,
16 | Admincrete = 7,
17 | Water = 8,
18 | StillWater = 9,
19 | Lava = 10,
20 | StillLava = 11,
21 | Sand = 12,
22 | Gravel = 13,
23 | GoldOre = 14,
24 | IronOre = 15,
25 | Coal = 16,
26 | Log = 17,
27 | Leaves = 18,
28 | Sponge = 19,
29 | Glass = 20,
30 |
31 | Red = 21,
32 | Orange = 22,
33 | Yellow = 23,
34 | Lime = 24,
35 | Green = 25,
36 | Teal = 26,
37 | Aqua = 27,
38 | Cyan = 28,
39 | Blue = 29,
40 | Indigo = 30,
41 | Violet = 31,
42 | Magenta = 32,
43 | Pink = 33,
44 | Black = 34,
45 | Gray = 35,
46 | White = 36,
47 |
48 | YellowFlower = 37,
49 | RedFlower = 38,
50 | BrownMushroom = 39,
51 | RedMushroom = 40,
52 |
53 | Gold = 41,
54 | Iron = 42,
55 | DoubleSlab = 43,
56 | Slab = 44,
57 | Bricks = 45,
58 | TNT = 46,
59 | Books = 47,
60 | MossyCobble = 48,
61 | Obsidian = 49
62 | }
63 | }
64 | #pragma warning restore 1591
--------------------------------------------------------------------------------
/UpdateInstaller/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle( "fCraft UpdateInstaller" )]
8 | [assembly: AssemblyDescription( "fCraft self-extracting updater" )]
9 | [assembly: AssemblyConfiguration( "" )]
10 | [assembly: AssemblyCompany( "fCraft.net" )]
11 | [assembly: AssemblyProduct( "fCraft UpdateInstaller" )]
12 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
13 | [assembly: AssemblyTrademark( "" )]
14 | [assembly: AssemblyCulture( "" )]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible( false )]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid( "b228bbdb-289f-49d7-934a-2701bec9e179" )]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("0.6.4.5")]
35 | [assembly: AssemblyFileVersion("0.6.4.5")]
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/LineDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace fCraft.Drawing {
6 | /// Draw operation that creates a simple line, 1 block thick.
7 | public sealed class LineDrawOperation : DrawOperation {
8 |
9 | public override string Name {
10 | get { return "Line"; }
11 | }
12 |
13 | public override int ExpectedMarks {
14 | get { return 2; }
15 | }
16 |
17 | public LineDrawOperation( Player player )
18 | : base( player ) {
19 | }
20 |
21 |
22 | public override bool Prepare( Vector3I[] marks ) {
23 | if( !base.Prepare( marks ) ) return false;
24 |
25 | BlocksTotalEstimate = Math.Max( Bounds.Width, Math.Max( Bounds.Height, Bounds.Length ) );
26 |
27 | coordEnumerator = LineEnumerator( marks[0], marks[1] ).GetEnumerator();
28 | return true;
29 | }
30 |
31 |
32 | IEnumerator coordEnumerator;
33 | public override int DrawBatch( int maxBlocksToDraw ) {
34 | int blocksDone = 0;
35 | while( coordEnumerator.MoveNext() ) {
36 | Coords = coordEnumerator.Current;
37 | if( DrawOneBlock() ) {
38 | blocksDone++;
39 | if( blocksDone >= maxBlocksToDraw ) return blocksDone;
40 | }
41 | if( TimeToEndBatch ) return blocksDone;
42 | }
43 | IsDone = true;
44 | return blocksDone;
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/MapConverter/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using System.Resources;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle( "fCraft MapConverter" )]
9 | [assembly: AssemblyDescription( "fCraft batch map converter" )]
10 | [assembly: AssemblyConfiguration( "" )]
11 | [assembly: AssemblyCompany( "fCraft.net" )]
12 | [assembly: AssemblyProduct( "fCraft MapConverter" )]
13 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
14 | [assembly: AssemblyTrademark( "" )]
15 | [assembly: AssemblyCulture( "" )]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible( false )]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid( "dc3e4b47-37bd-4a4c-a924-4d71c4544772" )]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.6.4.5")]
36 | [assembly: AssemblyFileVersion("0.6.4.5")]
37 | [assembly: NeutralResourcesLanguageAttribute( "en-US" )]
38 |
--------------------------------------------------------------------------------
/fCraftGUI/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using System.Resources;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle( "fCraftGUI" )]
9 | [assembly: AssemblyDescription( "Shared graphics-related functionality for fCraft" )]
10 | [assembly: AssemblyConfiguration( "" )]
11 | [assembly: AssemblyCompany( "fCraft.net" )]
12 | [assembly: AssemblyProduct( "fCraftGUI" )]
13 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
14 | [assembly: AssemblyTrademark( "" )]
15 | [assembly: AssemblyCulture( "" )]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible( false )]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid( "c44d6722-6673-4d5a-88f9-f6242590826c" )]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.6.4.5")]
36 | [assembly: AssemblyFileVersion("0.6.4.5")]
37 | [assembly: NeutralResourcesLanguageAttribute( "en-US" )]
38 |
--------------------------------------------------------------------------------
/MapRenderer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using System.Resources;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle( "fCraft MapRenderer" )]
9 | [assembly: AssemblyDescription( "Isometric map renderer for fCraft" )]
10 | [assembly: AssemblyConfiguration( "" )]
11 | [assembly: AssemblyCompany( "fCraft.net" )]
12 | [assembly: AssemblyProduct( "fCraft MapRenderer" )]
13 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
14 | [assembly: AssemblyTrademark( "" )]
15 | [assembly: AssemblyCulture( "" )]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible( false )]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid( "4337b67e-b27b-4950-8e07-a7889b74d11f" )]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.6.4.5")]
36 | [assembly: AssemblyFileVersion("0.6.4.5")]
37 | [assembly: NeutralResourcesLanguageAttribute( "en-US" )]
38 |
--------------------------------------------------------------------------------
/HeartbeatSaver/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using System.Resources;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle( "fCraft HeartbeatSaver" )]
9 | [assembly: AssemblyDescription( "fCraft standalone heartbeat sender" )]
10 | [assembly: AssemblyConfiguration( "" )]
11 | [assembly: AssemblyCompany( "fCraft.net" )]
12 | [assembly: AssemblyProduct( "fCraft HeartbeatSaver" )]
13 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
14 | [assembly: AssemblyTrademark( "" )]
15 | [assembly: AssemblyCulture( "" )]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible( false )]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid( "a7697c80-fc28-4c47-82fc-2b16991bb678" )]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.6.4.5")]
36 | [assembly: AssemblyFileVersion("0.6.4.5")]
37 | [assembly: NeutralResourcesLanguageAttribute( "en-US" )]
38 |
--------------------------------------------------------------------------------
/UpdaterBuilder/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using System.Resources;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle( "fCraft UpdateBuilder" )]
9 | [assembly: AssemblyDescription( "Tool for automating the process of building fCraft update binaries." )]
10 | [assembly: AssemblyConfiguration( "" )]
11 | [assembly: AssemblyCompany( "fCraft.net" )]
12 | [assembly: AssemblyProduct( "fCraft UpdateBuilder" )]
13 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
14 | [assembly: AssemblyTrademark( "" )]
15 | [assembly: AssemblyCulture( "" )]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible( false )]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid( "67e9d038-4a42-40bb-b71f-b227a80d6e17" )]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.6.4.5")]
36 | [assembly: AssemblyFileVersion("0.6.4.5")]
37 | [assembly: NeutralResourcesLanguageAttribute( "en-US" )]
38 |
--------------------------------------------------------------------------------
/ConfigGUI/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle( "fCraft ConfigGUI" )]
10 | [assembly: AssemblyDescription( "fCraft graphical configuration tool" )]
11 | [assembly: AssemblyConfiguration( "" )]
12 | [assembly: AssemblyCompany( "fCraft.net" )]
13 | [assembly: AssemblyProduct( "fCraft ConfigGUI" )]
14 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
15 | [assembly: AssemblyTrademark( "" )]
16 | [assembly: AssemblyCulture( "" )]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 | [assembly: ComVisible( false )]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 | [assembly: Guid( "061effe2-df77-48ee-8a23-8be48c5e7684" )]
25 |
26 | // Version information for an assembly consists of the following four values:
27 | //
28 | // Major Version
29 | // Minor Version
30 | // Build Number
31 | // Revision
32 | //
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 | [assembly: AssemblyVersion("0.6.4.5")]
37 | [assembly: AssemblyFileVersion("0.6.4.5")]
38 |
39 | [assembly: CLSCompliant( false )]
40 | [assembly: NeutralResourcesLanguage( "en-US" )]
--------------------------------------------------------------------------------
/ServerCLI/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle( "fCraft ServerCLI" )]
10 | [assembly: AssemblyDescription( "Command-line frontend for fCraft server" )]
11 | [assembly: AssemblyConfiguration( "" )]
12 | [assembly: AssemblyCompany( "fCraft.net" )]
13 | [assembly: AssemblyProduct( "fCraft ServerCLI" )]
14 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
15 | [assembly: AssemblyTrademark( "" )]
16 | [assembly: AssemblyCulture( "" )]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 | [assembly: ComVisible( false )]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 | [assembly: Guid( "e463a25a-d85d-4991-8df0-ed4e4cc7cd09" )]
25 |
26 | // Version information for an assembly consists of the following four values:
27 | //
28 | // Major Version
29 | // Minor Version
30 | // Build Number
31 | // Revision
32 | //
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 | [assembly: AssemblyVersion("0.6.4.5")]
37 | [assembly: AssemblyFileVersion("0.6.4.5")]
38 |
39 | [assembly: CLSCompliant( true )]
40 | [assembly: NeutralResourcesLanguage( "en-US" )]
--------------------------------------------------------------------------------
/ServerGUI/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle( "fCraft ServerGUI" )]
10 | [assembly: AssemblyDescription( "Graphical frontend for fCraft server" )]
11 | [assembly: AssemblyConfiguration( "" )]
12 | [assembly: AssemblyCompany( "fCraft.net" )]
13 | [assembly: AssemblyProduct( "fCraft ServerGUI" )]
14 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
15 | [assembly: AssemblyTrademark( "" )]
16 | [assembly: AssemblyCulture( "" )]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 | [assembly: ComVisible( false )]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 | [assembly: Guid( "3d303d04-1235-4c51-975c-b9d2d5966113" )]
25 |
26 | // Version information for an assembly consists of the following four values:
27 | //
28 | // Major Version
29 | // Minor Version
30 | // Build Number
31 | // Revision
32 | //
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 | [assembly: AssemblyVersion("0.6.4.5")]
37 | [assembly: AssemblyFileVersion("0.6.4.5")]
38 |
39 | [assembly: CLSCompliant( false )]
40 | [assembly: NeutralResourcesLanguage( "en-US" )]
--------------------------------------------------------------------------------
/fCraft/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Resources;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle( "fCraft core" )]
10 | [assembly: AssemblyDescription( "Core components of fCraft, a better Minecraft Classic server." )]
11 | [assembly: AssemblyConfiguration( "" )]
12 | [assembly: AssemblyCompany( "fCraft.net" )]
13 | [assembly: AssemblyProduct( "fCraft core" )]
14 | [assembly: AssemblyCopyright( "fCraft is Copyright © Matvei Stefarov 2009-2014 (matvei.org)" )]
15 | [assembly: AssemblyTrademark( "" )]
16 | [assembly: AssemblyCulture( "" )]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 | [assembly: ComVisible( false )]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 | [assembly: Guid( "a9789af1-183f-4d6d-aef3-8fbacdaecdf4" )]
25 |
26 | // Version information for an assembly consists of the following four values:
27 | //
28 | // Major Version
29 | // Minor Version
30 | // Build Number
31 | // Revision
32 | //
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 | [assembly: AssemblyVersion("0.6.4.5")]
37 | [assembly: AssemblyFileVersion("0.6.4.5")]
38 |
39 | [assembly: CLSCompliant( false )]
40 | [assembly: NeutralResourcesLanguage( "en-US" )]
--------------------------------------------------------------------------------
/fCraft/MapConversion/MapFormatException.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Runtime.Serialization;
4 | using JetBrains.Annotations;
5 |
6 | namespace fCraft.MapConversion {
7 | /// Exception that is thrown when problems arise during map saving or loading.
8 | /// May be caused by map file's incorrect format or structure.
9 | [Serializable]
10 | public sealed class MapFormatException : Exception {
11 | internal MapFormatException() {}
12 |
13 |
14 | internal MapFormatException( [NotNull] string message )
15 | : base( message ) {}
16 |
17 |
18 | internal MapFormatException( [NotNull] string message, Exception innerException )
19 | : base( message, innerException ) {}
20 |
21 |
22 | MapFormatException( SerializationInfo info, StreamingContext context )
23 | : base( info, context ) {}
24 | }
25 |
26 |
27 | /// Exception that is thrown when no importer or exporter could
28 | /// be found for the given map format, or a map format could not be identified at all.
29 | [Serializable]
30 | public sealed class NoMapConverterFoundException : Exception {
31 | internal NoMapConverterFoundException() {}
32 |
33 |
34 | internal NoMapConverterFoundException( [NotNull] string message )
35 | : base( message ) {}
36 |
37 |
38 | internal NoMapConverterFoundException( [NotNull] string message, Exception innerException )
39 | : base( message, innerException ) {}
40 |
41 |
42 | NoMapConverterFoundException( SerializationInfo info, StreamingContext context )
43 | : base( info, context ) {}
44 | }
45 | }
--------------------------------------------------------------------------------
/fCraft/System/ArgKey.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft {
4 | /// Enumerates the recognized command-line switches/arguments.
5 | /// Args are parsed in Server.InitLibrary
6 | public enum ArgKey {
7 | /// Working path (directory) that fCraft should use.
8 | /// If the path is relative, it's computed against the location of fCraft.dll
9 | Path,
10 |
11 | /// Path (directory) where the log files should be placed.
12 | /// If the path is relative, it's computed against the working path.
13 | LogPath,
14 |
15 | /// Path (directory) where the map files should be loaded from/saved to.
16 | /// If the path is relative, it's computed against the working path.
17 | MapPath,
18 |
19 | /// Path (file) of the configuration file.
20 | /// If the path is relative, it's computed against the working path.
21 | Config,
22 |
23 | /// If NoRestart flag is present, fCraft will shutdown instead of restarting.
24 | /// Useful if you are using an auto-restart script/process monitor of some sort.
25 | NoRestart,
26 |
27 | /// If ExitOnCrash flag is present, fCraft front-ends will exit
28 | /// at once in the event of an unrecoverable crash, instead of showing a message.
29 | ExitOnCrash,
30 |
31 | /// Disables all logging.
32 | NoLog,
33 |
34 | /// Disables colors in CLI front-ends.
35 | NoConsoleColor,
36 |
37 | /// Do not run the updater executable upon updating.
38 | NoUpdater
39 | };
40 | }
41 |
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/CuboidDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft.Drawing {
4 | /// Draw operation that creates a simple cuboid.
5 | public sealed class CuboidDrawOperation : DrawOperation {
6 | public override string Name {
7 | get { return "Cuboid"; }
8 | }
9 |
10 | public override int ExpectedMarks {
11 | get { return 2; }
12 | }
13 |
14 | public CuboidDrawOperation( Player player )
15 | : base( player ) {
16 | }
17 |
18 |
19 | public override bool Prepare( Vector3I[] marks ) {
20 | if( !base.Prepare( marks ) ) return false;
21 | BlocksTotalEstimate = Bounds.Volume;
22 | Coords = Bounds.MinVertex;
23 | return true;
24 | }
25 |
26 |
27 | public override int DrawBatch( int maxBlocksToDraw ) {
28 | int blocksDone = 0;
29 | for( ; Coords.X <= Bounds.XMax; Coords.X++ ) {
30 | for( ; Coords.Y <= Bounds.YMax; Coords.Y++ ) {
31 | for( ; Coords.Z <= Bounds.ZMax; Coords.Z++ ) {
32 | if( !DrawOneBlock() ) continue;
33 | blocksDone++;
34 | if( blocksDone >= maxBlocksToDraw ) {
35 | Coords.Z++;
36 | return blocksDone;
37 | }
38 | }
39 | Coords.Z = Bounds.ZMin;
40 | }
41 | Coords.Y = Bounds.YMin;
42 | if( TimeToEndBatch ) {
43 | Coords.X++;
44 | return blocksDone;
45 | }
46 | }
47 | IsDone = true;
48 | return blocksDone;
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/ServerGUI/Program.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009-2014 Matvei Stefarov
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | * THE SOFTWARE.
21 | *
22 | */
23 | using System;
24 | using System.Windows.Forms;
25 |
26 | namespace fCraft.ServerGUI {
27 | static class Program {
28 |
29 | [STAThread]
30 | static void Main() {
31 | Application.EnableVisualStyles();
32 | Application.SetCompatibleTextRenderingDefault( false );
33 | #if DEBUG
34 | Application.Run( new MainForm() );
35 | #else
36 | try {
37 | Application.Run( new MainForm() );
38 | } catch( Exception ex ) {
39 | Logger.LogAndReportCrash( "Unhandled exception in ServerGUI", "ServerGUI", ex, true );
40 | }
41 | #endif
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/fCraftGUI/DefaultMapGenGui.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using fCraft.MapGeneration;
4 |
5 | namespace fCraft.GUI {
6 | public partial class DefaultMapGenGui : MapGeneratorGui {
7 | MapGeneratorParameters args;
8 |
9 | public DefaultMapGenGui() {
10 | InitializeComponent();
11 | }
12 |
13 | public override void SetParameters( MapGeneratorParameters generatorParameters ) {
14 | args = generatorParameters;
15 | pgGrid.SelectedObject = args;
16 | }
17 |
18 | public override MapGeneratorParameters GetParameters() {
19 | return args;
20 | }
21 |
22 | public override void OnMapDimensionChange( int width, int length, int height ) {
23 | args.MapWidth = width;
24 | args.MapLength = length;
25 | args.MapHeight = height;
26 | }
27 | }
28 |
29 |
30 | /// Represents a class that provides a fallback GUI for any MapGenerator.
31 | /// Creates DefaultMapGenGui instances on demand.
32 | public class DefaultMapGenGuiProvider : IMapGeneratorGuiProvider {
33 | DefaultMapGenGuiProvider() { }
34 |
35 | public static readonly DefaultMapGenGuiProvider Instance = new DefaultMapGenGuiProvider();
36 |
37 | public string Name {
38 | get { return "Default"; }
39 | }
40 |
41 | static readonly Version StaticVersion = new Version( 1, 0 );
42 |
43 | public Version Version {
44 | get { return StaticVersion; }
45 | }
46 |
47 | public bool IsCompatible( string generatorName, Version generatorVersion ) {
48 | return true;
49 | }
50 |
51 | public MapGeneratorGui CreateGui() {
52 | return new DefaultMapGenGui();
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/fCraft/System/ShutdownParams.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using JetBrains.Annotations;
4 |
5 | namespace fCraft {
6 | /// Describes the circumstances of server shutdown.
7 | public sealed class ShutdownParams {
8 | /// Creates a ShutdownParams object with given reason/delay/restart flag.
9 | public ShutdownParams( ShutdownReason reason, TimeSpan delay, bool restart ) {
10 | Reason = reason;
11 | Delay = delay;
12 | Restart = restart;
13 | }
14 |
15 |
16 | /// Creates a ShutdownParams object with given parameters.
17 | /// and may be null.
18 | public ShutdownParams( ShutdownReason reason, TimeSpan delay,
19 | bool restart, [CanBeNull] string customReason,
20 | [CanBeNull] Player initiatedBy ) :
21 | this( reason, delay, restart ) {
22 | customReasonString = customReason;
23 | InitiatedBy = initiatedBy;
24 | }
25 |
26 |
27 | public ShutdownReason Reason { get; private set; }
28 |
29 | readonly string customReasonString;
30 |
31 | [NotNull]
32 | public string ReasonString {
33 | get { return customReasonString ?? Reason.ToString(); }
34 | }
35 |
36 | /// Delay before shutting down.
37 | public TimeSpan Delay { get; private set; }
38 |
39 | /// Whether the server is expected to restart itself after shutting down.
40 | public bool Restart { get; private set; }
41 |
42 | /// Player who initiated the shutdown. May be null or Console.
43 | [CanBeNull]
44 | public Player InitiatedBy { get; private set; }
45 | }
46 | }
--------------------------------------------------------------------------------
/fCraft/World/BlockChangeContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft {
5 | /// Context of the block change. Multiple flags can be combined.
6 | [Flags]
7 | public enum BlockChangeContext { // Backed by Int32.
8 | /// Default/unknown context.
9 | Unknown = 0,
10 |
11 | /// Block was manually edited, with a click. Opposite of Drawn.
12 | Manual = 1,
13 |
14 | /// Block was edited using a drawing operation. Opposite of Manual.
15 | Drawn = 2,
16 |
17 | /// Block was replaced (using /paint, /r, /rn, /rb, or replace brush variations).
18 | Replaced = 4,
19 |
20 | /// Block was pasted (using /paste, /pastenot, /px, or /pnx)
21 | Pasted = 8,
22 |
23 | /// Block was cut (using /cut).
24 | Cut = 16,
25 |
26 | /// Undone a change previously made by same player (using /undo, /ua, or /up on self).
27 | UndoneSelf = 32,
28 |
29 | /// Undone a change previously made by another player (using /ua or /up).
30 | UndoneOther = 64,
31 |
32 | /// Block was inserted from another file (using /restore).
33 | Restored = 128,
34 |
35 | /// Block was filled (using /fill2d or /fill3d).
36 | Filled = 256,
37 |
38 | /// Redone, opposite of UndoneSelf/UndoneOther
39 | Redone = 512,
40 |
41 |
42 | /// Combination of Manual and Replaced (as used by /Paint).
43 | PaintedCombo = Manual | Replaced,
44 |
45 | /// Combination of Drawn, UndoneSelf, and Redone (as used by /Redo).
46 | RedoneCombo = Drawn | UndoneSelf | Redone
47 | }
48 | }
--------------------------------------------------------------------------------
/MapRenderer/MapRendererParams.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Drawing.Imaging;
4 | using System.Text.RegularExpressions;
5 | using fCraft.GUI;
6 | using fCraft.MapConversion;
7 |
8 | namespace fCraft.MapRenderer {
9 | /// Holds all parameters for MapRenderer program, and sets some defaults.
10 | class MapRendererParams {
11 | public int Angle { get; set; }
12 | public IsoCatMode Mode { get; set; }
13 | public ImageFormat ExportFormat { get; set; }
14 | public string ImageFileExtension { get; set; }
15 | public BoundingBox Region { get; set; }
16 | public int JpegQuality { get; set; }
17 | public IMapImporter MapImporter { get; set; }
18 | public ImageCodecInfo ImageEncoder { get; set; }
19 | public bool DirectoryMode { get; set; }
20 | public int ThreadCount { get; set; }
21 | public string[] InputPathList { get; set; }
22 | public bool NoGradient { get; set; }
23 | public bool NoShadows { get; set; }
24 | public bool SeeThroughWater { get; set; }
25 | public bool SeeThroughLava { get; set; }
26 | public bool Recursive { get; set; }
27 | public bool AlwaysOverwrite { get; set; }
28 | public bool Uncropped { get; set; }
29 | public string InputFilter { get; set; }
30 | public bool OutputDirGiven { get; set; }
31 | public string OutputDirName { get; set; }
32 | public bool TryHard { get; set; }
33 | public bool UseRegex { get; set; }
34 | public Regex FilterRegex { get; set; }
35 |
36 | public MapRendererParams() {
37 | Mode = IsoCatMode.Normal;
38 | Region = BoundingBox.Empty;
39 | JpegQuality = 90;
40 | ThreadCount = Environment.ProcessorCount;
41 | ExportFormat = ImageFormat.Png;
42 | ImageFileExtension = ".png";
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/fCraft/MapConversion/MapFormat.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 |
3 | namespace fCraft.MapConversion {
4 | /// An enumeration of map formats supported by fCraft.
5 | public enum MapFormat {
6 | /// Unidentified map.
7 | Unknown,
8 |
9 | /// Obsolete map format previously used by fCraft before release 0.500
10 | FCMv2,
11 |
12 | /// Obsolete map format previously used by fCraft 0.500-0.6xx
13 | FCMv3,
14 |
15 | /// Map format used by MCSharp and its forks (MCZall/MCLawl). Initial support added by Tyler (TkTech).
16 | MCSharp,
17 |
18 | /// Map format used by MinerCPP and LuaCraft. Initial support added by Tyler (TkTech).
19 | MinerCPP,
20 |
21 | /// Map format used by Myne and its derivatives (MyneCraft/iCraft).
22 | Myne,
23 |
24 | /// Map format used by Mojang's classic and survivaltest.
25 | Classic,
26 |
27 | /// Map format used by Mojang's indev.
28 | Indev,
29 |
30 | /// Map format used by JTE's server.
31 | JTE,
32 |
33 | /// Map format used by D3 server.
34 | D3,
35 |
36 | /// Format used by Opticraft v0.2+. Support contributed by Jared Klopper (LgZ-optical).
37 | Opticraft,
38 |
39 | /// Raw byte array, with no header. For export only.
40 | Raw
41 | }
42 |
43 |
44 | /// Type of map storage (file or folder-based).
45 | public enum MapStorageType {
46 | /// Map consists of a single file.
47 | SingleFile,
48 |
49 | /// Map consists of a directory with multiple files (e.g. Myne maps).
50 | Directory
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/fCraftGUI/DefaultMapGenGui.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace fCraft.GUI {
2 | partial class DefaultMapGenGui {
3 | ///
4 | /// Required designer variable.
5 | ///
6 | private System.ComponentModel.IContainer components = null;
7 |
8 | ///
9 | /// Clean up any resources being used.
10 | ///
11 | /// true if managed resources should be disposed; otherwise, false.
12 | protected override void Dispose( bool disposing ) {
13 | if( disposing && (components != null) ) {
14 | components.Dispose();
15 | }
16 | base.Dispose( disposing );
17 | }
18 |
19 | #region Component Designer generated code
20 |
21 | ///
22 | /// Required method for Designer support - do not modify
23 | /// the contents of this method with the code editor.
24 | ///
25 | private void InitializeComponent() {
26 | this.pgGrid = new System.Windows.Forms.PropertyGrid();
27 | this.SuspendLayout();
28 | //
29 | // pgGrid
30 | //
31 | this.pgGrid.Dock = System.Windows.Forms.DockStyle.Fill;
32 | this.pgGrid.Location = new System.Drawing.Point(0, 0);
33 | this.pgGrid.Margin = new System.Windows.Forms.Padding(0);
34 | this.pgGrid.Name = "pgGrid";
35 | this.pgGrid.Size = new System.Drawing.Size(400, 262);
36 | this.pgGrid.TabIndex = 0;
37 | //
38 | // DefaultMapGenGui
39 | //
40 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
41 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
42 | this.Controls.Add(this.pgGrid);
43 | this.Name = "DefaultMapGenGui";
44 | this.Size = new System.Drawing.Size(400, 262);
45 | this.ResumeLayout(false);
46 |
47 | }
48 |
49 | #endregion
50 |
51 | private System.Windows.Forms.PropertyGrid pgGrid;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/MapRenderer/BlockingQueue.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System.Collections.Generic;
3 | using System.Threading;
4 |
5 | namespace fCraft.MapRenderer {
6 | /// Multiple-producer, single-consumer queue.
7 | /// Dequeue blocks calling thread (consumer) until it has something to return.
8 | public class BlockingQueue {
9 | readonly Queue store = new Queue();
10 | readonly AutoResetEvent signal = new AutoResetEvent( false );
11 | public int Count { get; private set; }
12 | public int QueuedCount { get; private set; }
13 |
14 | readonly object storeMutex = new object(),
15 | consumerMutex = new object();
16 |
17 |
18 | public bool TryDequeue( out T result ) {
19 | lock( consumerMutex ) {
20 | lock( storeMutex ) {
21 | if( store.Count > 0 ) {
22 | result = store.Dequeue();
23 | return true;
24 | } else {
25 | result = default(T);
26 | return false;
27 | }
28 | }
29 | }
30 | }
31 |
32 |
33 | public T WaitDequeue() {
34 | lock( consumerMutex ) {
35 | while( true ) {
36 | lock( storeMutex ) {
37 | if( store.Count > 0 ) {
38 | Count = store.Count - 1;
39 | return store.Dequeue();
40 | } // else loop around, wait again
41 | }
42 | // waits for signal from Enqueue(), resets automatically
43 | signal.WaitOne();
44 | }
45 | }
46 | }
47 |
48 | public void Enqueue( T item ) {
49 | lock( storeMutex ) {
50 | store.Enqueue( item );
51 | Count = store.Count;
52 | QueuedCount++;
53 | // signal that queue is no longer empty
54 | signal.Set();
55 | }
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/fCraft/Utils/RWLSExtension.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Threading;
4 |
5 | namespace fCraft {
6 | static class RWLSExtension {
7 | public static ReadLockHelper ReadLock( this ReaderWriterLockSlim readerWriterLock ) {
8 | return new ReadLockHelper( readerWriterLock );
9 | }
10 |
11 | public static UpgradeableReadLockHelper UpgradableReadLock( this ReaderWriterLockSlim readerWriterLock ) {
12 | return new UpgradeableReadLockHelper( readerWriterLock );
13 | }
14 |
15 | public static WriteLockHelper WriteLock( this ReaderWriterLockSlim readerWriterLock ) {
16 | return new WriteLockHelper( readerWriterLock );
17 | }
18 |
19 | public struct ReadLockHelper : IDisposable {
20 | private readonly ReaderWriterLockSlim readerWriterLock;
21 |
22 | public ReadLockHelper( ReaderWriterLockSlim readerWriterLock ) {
23 | readerWriterLock.EnterReadLock();
24 | this.readerWriterLock = readerWriterLock;
25 | }
26 |
27 | public void Dispose() {
28 | readerWriterLock.ExitReadLock();
29 | }
30 | }
31 |
32 | public struct UpgradeableReadLockHelper : IDisposable {
33 | private readonly ReaderWriterLockSlim readerWriterLock;
34 |
35 | public UpgradeableReadLockHelper( ReaderWriterLockSlim readerWriterLock ) {
36 | readerWriterLock.EnterUpgradeableReadLock();
37 | this.readerWriterLock = readerWriterLock;
38 | }
39 |
40 | public void Dispose() {
41 | readerWriterLock.ExitUpgradeableReadLock();
42 | }
43 | }
44 |
45 | public struct WriteLockHelper : IDisposable {
46 | private readonly ReaderWriterLockSlim readerWriterLock;
47 |
48 | public WriteLockHelper( ReaderWriterLockSlim readerWriterLock ) {
49 | readerWriterLock.EnterWriteLock();
50 | this.readerWriterLock = readerWriterLock;
51 | }
52 |
53 | public void Dispose() {
54 | readerWriterLock.ExitWriteLock();
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/fCraftGUI/FlatMapGenGui.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Windows.Forms;
4 | using fCraft.MapGeneration;
5 |
6 | namespace fCraft.GUI {
7 | public partial class FlatMapGenGui : MapGeneratorGui {
8 | MapGeneratorParameters genParams;
9 |
10 | public FlatMapGenGui() {
11 | InitializeComponent();
12 | }
13 |
14 | public override void SetParameters( MapGeneratorParameters generatorParameters ) {
15 | genParams = generatorParameters;
16 | pgDetails.SelectedObject = genParams;
17 | lPreset.Text = "Preset: " + genParams.ToString().Split( ' ' )[1];
18 | }
19 |
20 | public override MapGeneratorParameters GetParameters() {
21 | return genParams;
22 | }
23 |
24 | public override void OnMapDimensionChange( int width, int length, int height ) {
25 | genParams.MapWidth = width;
26 | genParams.MapLength = length;
27 | genParams.MapHeight = height;
28 | }
29 |
30 | private void xCustom_CheckedChanged( object sender, EventArgs e ) {
31 | pgDetails.Visible = xCustom.Checked;
32 | }
33 |
34 | private void pgDetails_PropertyValueChanged( object s, PropertyValueChangedEventArgs e ) {
35 | lPreset.Text = "Preset: " + genParams.ToString().Split( ' ' )[1] +" (Modified)";
36 | }
37 | }
38 |
39 |
40 | /// Represents a class that provides a fallback GUI for any MapGenerator.
41 | /// Creates DefaultMapGenGui instances on demand.
42 | public class FlatMapGenGuiProvider : IMapGeneratorGuiProvider {
43 | FlatMapGenGuiProvider() { }
44 |
45 | public static readonly FlatMapGenGuiProvider Instance = new FlatMapGenGuiProvider();
46 |
47 | public string Name {
48 | get { return "Flat"; }
49 | }
50 |
51 | static readonly Version StaticVersion = new Version( 1, 0 );
52 |
53 | public Version Version {
54 | get { return StaticVersion; }
55 | }
56 |
57 | public bool IsCompatible( string generatorName, Version generatorVersion ) {
58 | return true;
59 | }
60 |
61 | public MapGeneratorGui CreateGui() {
62 | return new FlatMapGenGui();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/fCraft/Network/OpCode.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 |
3 | namespace fCraft {
4 | /// Minecraft protocol's opcodes.
5 | /// For detailed explanation of Minecraft Classic protocol, see http://wiki.vg/Classic_Protocol
6 | public enum OpCode {
7 | /// Client/server packet. Client provides name and mppass.
8 | /// Server responds with name, MOTD, and permission byte.
9 | Handshake = 0,
10 |
11 | /// Server packet. Send periodically to test connection status.
12 | Ping = 1,
13 |
14 | /// Server packet. Notifies player of incoming level data.
15 | MapBegin = 2,
16 |
17 | /// Server packet. Contains a chunk of gzipped map.
18 | MapChunk = 3,
19 |
20 | /// Server packet. Sent after level data is complete and gives map dimensions.
21 | MapEnd = 4,
22 |
23 | /// Client packet. Sent when a user changes a block.
24 | SetBlockClient = 5,
25 |
26 | /// Server packet. Sent to indicate a block change.
27 | SetBlockServer = 6,
28 |
29 | /// Server packet. Spawns a player model. Also used to set player's respawn point.
30 | AddEntity = 7,
31 |
32 | /// Client/server packet. Used by client to update player's position.
33 | /// Used by server to teleport player or update position of other players.
34 | Teleport = 8,
35 |
36 | /// Server packet. Updates relative location and rotation of other players.
37 | MoveRotate = 9,
38 |
39 | /// Server packet. Updates relative location of other players.
40 | Move = 10,
41 |
42 | /// Server packet. Updates rotation of other players.
43 | Rotate = 11,
44 |
45 | /// Server packet. De-spawns a player model.
46 | RemoveEntity = 12,
47 |
48 | /// Client/server packet. Used to send chat messages.
49 | Message = 13,
50 |
51 | /// Server packet. Tells client that they're being kicked.
52 | Kick = 14,
53 |
54 | /// Server packet. Sent when a player is opped/deopped.
55 | SetPermission = 15
56 | }
57 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/Brushes/RainbowBrush.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft.Drawing {
5 | /// Brush that creates a diagonal rainbow pattern, using
6 | /// Red, Orange, Yellow, Green, Aqua, Blue, and Violet blocks.
7 | public sealed class RainbowBrush : IBrushFactory, IBrush, IBrushInstance {
8 | public static readonly RainbowBrush Instance = new RainbowBrush();
9 |
10 | RainbowBrush() { }
11 |
12 | public string Name {
13 | get { return "Rainbow"; }
14 | }
15 |
16 | public int AlternateBlocks {
17 | get { return 1; }
18 | }
19 |
20 | public string[] Aliases {
21 | get { return null; }
22 | }
23 |
24 | const string HelpString = "Rainbow brush: Creates a diagonal 7-color rainbow pattern.";
25 | public string Help {
26 | get { return HelpString; }
27 | }
28 |
29 |
30 | public string Description {
31 | get { return Name; }
32 | }
33 |
34 | public IBrushFactory Factory {
35 | get { return this; }
36 | }
37 |
38 |
39 | public IBrush MakeBrush( Player player, CommandReader cmd ) {
40 | return this;
41 | }
42 |
43 |
44 | public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation state ) {
45 | return this;
46 | }
47 |
48 | static readonly Block[] Rainbow = {
49 | Block.Red,
50 | Block.Orange,
51 | Block.Yellow,
52 | Block.Green,
53 | Block.Aqua,
54 | Block.Blue,
55 | Block.Violet
56 | };
57 |
58 | public string InstanceDescription {
59 | get { return "Rainbow"; }
60 | }
61 |
62 | public IBrush Brush {
63 | get { return Instance; }
64 | }
65 |
66 | public bool Begin( Player player, DrawOperation state ) {
67 | if( player == null ) throw new ArgumentNullException( "player" );
68 | if( state == null ) throw new ArgumentNullException( "state" );
69 | return true;
70 | }
71 |
72 |
73 | public Block NextBlock( DrawOperation state ) {
74 | if( state == null ) throw new ArgumentNullException( "state" );
75 | return Rainbow[(state.Coords.X + state.Coords.Y + state.Coords.Z) % 7];
76 | }
77 |
78 |
79 | public void End() { }
80 | }
81 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOpWithBrush.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft.Drawing {
5 | /// A self-contained DrawOperation that provides its own brush.
6 | /// Purpose of this class is mostly to take care of the boilerplate code.
7 | public abstract class DrawOpWithBrush : DrawOperation, IBrushFactory, IBrush, IBrushInstance {
8 |
9 | public override abstract string Description {
10 | get;
11 | }
12 |
13 | protected DrawOpWithBrush( Player player )
14 | : base( player ) {
15 | }
16 |
17 | public abstract bool ReadParams( CommandReader cmd );
18 |
19 |
20 | protected abstract Block NextBlock();
21 |
22 |
23 | #region IBrushFactory Members
24 |
25 | string IBrushFactory.Name {
26 | get { return Name; }
27 | }
28 |
29 | string IBrushFactory.Help {
30 | get { throw new NotImplementedException(); }
31 | }
32 |
33 | string[] IBrushFactory.Aliases {
34 | get { return null; }
35 | }
36 |
37 | IBrush IBrushFactory.MakeBrush( Player player, CommandReader cmd ) {
38 | return this;
39 | }
40 |
41 | #endregion
42 |
43 |
44 | #region IBrush Members
45 |
46 | IBrushFactory IBrush.Factory {
47 | get { return this; }
48 | }
49 |
50 | string IBrush.Description {
51 | get { throw new NotImplementedException(); }
52 | }
53 |
54 | IBrushInstance IBrush.MakeInstance( Player player, CommandReader cmd, DrawOperation op ) {
55 | if( ReadParams( cmd ) ) {
56 | return this;
57 | } else {
58 | return null;
59 | }
60 | }
61 |
62 | #endregion
63 |
64 |
65 | #region IBrushInstance Members
66 |
67 | IBrush IBrushInstance.Brush {
68 | get { return this; }
69 | }
70 |
71 | string IBrushInstance.InstanceDescription {
72 | get { return Description; }
73 | }
74 |
75 | int IBrushInstance.AlternateBlocks {
76 | get { return 1; }
77 | }
78 |
79 | bool IBrushInstance.Begin( Player player, DrawOperation op ) {
80 | return true;
81 | }
82 |
83 | Block IBrushInstance.NextBlock( DrawOperation op ) {
84 | return NextBlock();
85 | }
86 |
87 | void IBrushInstance.End() { }
88 |
89 | #endregion
90 | }
91 | }
--------------------------------------------------------------------------------
/fCraft/MapGeneration/EmptyMapGen.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Xml.Linq;
4 |
5 | namespace fCraft.MapGeneration {
6 | /// Basic empty map generator. Basically a fancy wrapper for Map constructor.
7 | /// This is a singleton class -- use EmptyMapGen.Instance.
8 | public sealed class EmptyMapGen : MapGenerator {
9 | public static EmptyMapGen Instance { get; private set; }
10 |
11 | static EmptyMapGen() {
12 | Instance = new EmptyMapGen {
13 | Name = "Empty",
14 | Help = "&S\"Empty\" map generator:\n" +
15 | "Creates an empty map. Does not take any parameters."
16 | };
17 | }
18 |
19 | public override MapGeneratorParameters CreateDefaultParameters() {
20 | return new EmptyMapGenParams();
21 | }
22 |
23 | public override MapGeneratorParameters CreateParameters( XElement serializedParameters ) {
24 | return CreateDefaultParameters();
25 | }
26 |
27 | public override MapGeneratorParameters CreateParameters( Player player, CommandReader cmd ) {
28 | if( cmd.HasNext ) {
29 | player.Message( "Empty map generator does not take any parameters." );
30 | }
31 | return CreateDefaultParameters();
32 | }
33 |
34 | public override MapGeneratorParameters CreateParameters( string presetName ) {
35 | if( presetName == null ) {
36 | throw new ArgumentNullException( "presetName" );
37 | } else if( presetName.Equals( Presets[0], StringComparison.OrdinalIgnoreCase ) ) {
38 | return CreateDefaultParameters();
39 | } else {
40 | return null;
41 | }
42 | }
43 | }
44 |
45 |
46 | class EmptyMapGenParams : MapGeneratorParameters {
47 | public EmptyMapGenParams() {
48 | Generator = EmptyMapGen.Instance;
49 | }
50 |
51 | public override MapGeneratorState CreateGenerator() {
52 | return new EmptyMapGenState( this );
53 | }
54 | }
55 |
56 |
57 | class EmptyMapGenState : MapGeneratorState {
58 | public EmptyMapGenState( MapGeneratorParameters genParams ) {
59 | Parameters = genParams;
60 | }
61 |
62 | public override Map Generate() {
63 | return new Map( null, Parameters.MapWidth, Parameters.MapLength, Parameters.MapHeight, true );
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/ConfigGUI/PermissionLimitBox.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Windows.Forms;
4 |
5 | namespace fCraft.ConfigGUI {
6 | public sealed partial class PermissionLimitBox : UserControl {
7 |
8 | public Permission Permission { get; private set; }
9 |
10 | public string FirstItem { get; private set; }
11 |
12 | public Rank Rank { get; private set; }
13 |
14 | public PermissionLimitBox( string labelText, Permission permission, string firstItem ) {
15 | InitializeComponent();
16 |
17 | label.Text = labelText;
18 | label.Left = (comboBox.Left - comboBox.Margin.Left) - (label.Width + label.Margin.Right);
19 |
20 | Permission = permission;
21 | FirstItem = firstItem;
22 | RebuildList();
23 |
24 | comboBox.SelectedIndexChanged += OnPermissionLimitChanged;
25 | }
26 |
27 |
28 | void OnPermissionLimitChanged( object sender, EventArgs args ) {
29 | if( Rank == null ) return;
30 | Rank rankLimit = RankManager.FindRank( comboBox.SelectedIndex - 1 );
31 | if( rankLimit == null ) {
32 | Rank.ResetLimit( Permission );
33 | } else {
34 | Rank.SetLimit( Permission, rankLimit );
35 | }
36 | }
37 |
38 |
39 | public void Reset() {
40 | comboBox.SelectedIndex = 0;
41 | }
42 |
43 |
44 | public void RebuildList() {
45 | comboBox.Items.Clear();
46 | comboBox.Items.Add( FirstItem );
47 | foreach( Rank rank in RankManager.Ranks ) {
48 | comboBox.Items.Add( MainForm.ToComboBoxOption( rank ) );
49 | }
50 | }
51 |
52 |
53 | public void SelectRank( Rank rank ) {
54 | Rank = rank;
55 | if( rank == null ) {
56 | comboBox.SelectedIndex = -1;
57 | Visible = false;
58 | } else {
59 | comboBox.SelectedIndex = GetLimitIndex( rank, Permission );
60 | Visible = rank.Can( Permission );
61 | }
62 | }
63 |
64 |
65 | static int GetLimitIndex( Rank rank, Permission permission ) {
66 | if( rank.HasLimitSet( permission ) ) {
67 | return rank.GetLimit( permission ).Index + 1;
68 | } else {
69 | return 0;
70 | }
71 | }
72 |
73 |
74 | public void PermissionToggled( bool isOn ) {
75 | Visible = isOn;
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/fCraft/MapConversion/IMapConverter.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using JetBrains.Annotations;
3 |
4 | namespace fCraft.MapConversion {
5 | /// A map converter (either importer, exporter, or both).
6 | public interface IMapConverter {
7 | /// Returns name(s) of the server(s) that uses this format.
8 | [NotNull]
9 | string ServerName { get; }
10 |
11 | /// Whether this converter supports importing/loading from the format.
12 | bool SupportsImport { get; }
13 |
14 | /// Whether this converter supports exporting/saving to the format.
15 | bool SupportsExport { get; }
16 |
17 | /// File extension associated with this file.
18 | /// Throws NotSupportedException if this is a directory-based format.
19 | string FileExtension { get; }
20 |
21 | /// Returns the map storage type (file-based or directory-based).
22 | MapStorageType StorageType { get; }
23 |
24 | /// Returns the format name.
25 | MapFormat Format { get; }
26 | }
27 |
28 |
29 | /// IMapConverter that provides functionality for identifying and saving maps from files.
30 | public interface IMapImporter : IMapConverter {
31 | /// Returns true if the file name (or directory name) matches this format's expectations.
32 | bool ClaimsName( [NotNull] string path );
33 |
34 | /// Allows validating the map format while using minimal resources.
35 | /// Returns true if specified file/directory is valid for this format.
36 | bool Claims( [NotNull] string path );
37 |
38 | /// Attempts to load map dimensions from specified location.
39 | /// Throws MapFormatException on failure.
40 | [NotNull]
41 | Map LoadHeader( [NotNull] string path );
42 |
43 | /// Fully loads map from specified location.
44 | /// Throws MapFormatException on failure.
45 | [NotNull]
46 | Map Load( [NotNull] string path );
47 | }
48 |
49 |
50 | /// IMapConverter that provides functionality for saving maps to files.
51 | public interface IMapExporter : IMapConverter {
52 | /// Saves given map at the given location.
53 | void Save( [NotNull] Map mapToSave, [NotNull] string path );
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/EllipsoidDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft.Drawing {
5 | /// Draw operation that creates a filled ellipsoid.
6 | public class EllipsoidDrawOperation : DrawOperation {
7 | Vector3F invRadius,
8 | center;
9 |
10 | public override string Name { get { return "Ellipsoid"; } }
11 |
12 | public override int ExpectedMarks { get { return 2; } }
13 |
14 | public EllipsoidDrawOperation( Player player )
15 | : base( player ) {}
16 |
17 |
18 | public override bool Prepare( Vector3I[] marks ) {
19 | if( !base.Prepare( marks ) ) return false;
20 |
21 | double rx = Bounds.Width/2d;
22 | double ry = Bounds.Length/2d;
23 | double rz = Bounds.Height/2d;
24 |
25 | invRadius.X = (float)(1/(rx*rx));
26 | invRadius.Y = (float)(1/(ry*ry));
27 | invRadius.Z = (float)(1/(rz*rz));
28 |
29 | // find center points
30 | center.X = (Bounds.XMin + Bounds.XMax)/2f;
31 | center.Y = (Bounds.YMin + Bounds.YMax)/2f;
32 | center.Z = (Bounds.ZMin + Bounds.ZMax)/2f;
33 |
34 | BlocksTotalEstimate = (int)Math.Ceiling( 4/3d*Math.PI*rx*ry*rz );
35 |
36 | Coords = Bounds.MinVertex;
37 | return true;
38 | }
39 |
40 |
41 | public override int DrawBatch( int maxBlocksToDraw ) {
42 | int blocksDone = 0;
43 | for( ; Coords.X <= Bounds.XMax; Coords.X++ ) {
44 | for( ; Coords.Y <= Bounds.YMax; Coords.Y++ ) {
45 | for( ; Coords.Z <= Bounds.ZMax; Coords.Z++ ) {
46 | double dx = (Coords.X - center.X);
47 | double dy = (Coords.Y - center.Y);
48 | double dz = (Coords.Z - center.Z);
49 |
50 | // test if it's inside ellipse
51 | if( (dx*dx)*invRadius.X + (dy*dy)*invRadius.Y + (dz*dz)*invRadius.Z <= 1 ) {
52 | if( DrawOneBlock() ) {
53 | blocksDone++;
54 | if( blocksDone >= maxBlocksToDraw ) return blocksDone;
55 | }
56 | }
57 | }
58 | if( TimeToEndBatch ) return blocksDone;
59 | Coords.Z = Bounds.ZMin;
60 | }
61 | Coords.Y = Bounds.YMin;
62 | }
63 | IsDone = true;
64 | return blocksDone;
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/ConfigGUI/TextEditorPopup.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Windows.Forms;
6 |
7 | namespace fCraft.ConfigGUI {
8 | public sealed partial class TextEditorPopup : Form {
9 | public string OriginalText { get; private set; }
10 | public string FileName { get; private set; }
11 |
12 |
13 | public TextEditorPopup( string fileName, string defaultValue ) {
14 | InitializeComponent();
15 |
16 | FileName = fileName;
17 | Text = "Editing " + FileName;
18 |
19 | if( File.Exists( fileName ) ) {
20 | OriginalText = File.ReadAllText( fileName );
21 | } else {
22 | OriginalText = defaultValue;
23 | }
24 |
25 | tText.Text = OriginalText;
26 | lWarning.Visible = ContainsLongLines();
27 | }
28 |
29 | bool ContainsLongLines() {
30 | return tText.Lines.Any( line => (line.Length > 62) );
31 | }
32 |
33 |
34 | private void tRules_KeyDown( object sender, KeyEventArgs e ) {
35 | lWarning.Visible = ContainsLongLines();
36 | }
37 |
38 | private void bOK_Click( object sender, EventArgs e ) {
39 | File.WriteAllText( FileName, tText.Text );
40 | Close();
41 | }
42 |
43 | ColorPicker colorPicker;
44 | private void bInsertColor_Click( object sender, EventArgs e ) {
45 | if( colorPicker == null ) colorPicker = new ColorPicker("Insert color",0);
46 | if( colorPicker.ShowDialog() == DialogResult.OK){
47 | string colorToInsert = MainForm.Parse( colorPicker.ColorIndex );
48 | int selectionStart = tText.SelectionStart;
49 | tText.Paste( colorToInsert );
50 | tText.Select( selectionStart, 2 );
51 | tText.Focus();
52 | }
53 | }
54 |
55 | KeywordPicker keywordPicker;
56 | private void bInsertKeyword_Click( object sender, EventArgs e ) {
57 | if( keywordPicker == null ) keywordPicker = new KeywordPicker();
58 | if( keywordPicker.ShowDialog() == DialogResult.OK ) {
59 | int selectionStart = tText.SelectionStart;
60 | tText.Paste( keywordPicker.Result );
61 | tText.Select( selectionStart, keywordPicker.Result.Length );
62 | tText.Focus();
63 | }
64 | }
65 |
66 | private void bReset_Click( object sender, EventArgs e ) {
67 | tText.Text = OriginalText;
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/ServerGUI/ConsoleBox.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 | using System;
5 |
6 | namespace fCraft.ServerGUI {
7 | sealed class ConsoleBox : TextBox {
8 | const int WM_KEYDOWN = 0x100;
9 | const int WM_SYSKEYDOWN = 0x104;
10 | public event Action OnCommand;
11 | readonly List log = new List();
12 | int logPointer;
13 |
14 | protected override bool ProcessCmdKey( ref Message msg, Keys keyData ) {
15 | if( !Enabled ) return base.ProcessCmdKey( ref msg, keyData );
16 | switch( keyData ) {
17 | case Keys.Up:
18 | if( msg.Msg == WM_SYSKEYDOWN || msg.Msg == WM_KEYDOWN ) {
19 | if( log.Count == 0 ) return true;
20 | if( logPointer == -1 ) {
21 | logPointer = log.Count - 1;
22 | } else if( logPointer > 0 ) {
23 | logPointer--;
24 | }
25 | Text = log[logPointer];
26 | SelectAll();
27 | }
28 | return true;
29 |
30 | case Keys.Down:
31 | if( msg.Msg == WM_SYSKEYDOWN || msg.Msg == WM_KEYDOWN ) {
32 | if( log.Count == 0 || logPointer == -1 ) return true;
33 | if( logPointer < log.Count - 1 ) {
34 | logPointer++;
35 | }
36 | Text = log[logPointer];
37 | SelectAll();
38 | }
39 | return true;
40 |
41 | case Keys.Enter:
42 | if( msg.Msg == WM_SYSKEYDOWN || msg.Msg == WM_KEYDOWN ) {
43 | if( Text.Trim().Length > 0 ) {
44 | log.Add( Text );
45 | if( log.Count > 100 ) log.RemoveAt( 0 );
46 | logPointer = -1;
47 | if( OnCommand != null ) OnCommand();
48 | }
49 | }
50 | return true;
51 |
52 | case Keys.Escape:
53 | if( msg.Msg == WM_SYSKEYDOWN || msg.Msg == WM_KEYDOWN ) {
54 | logPointer = log.Count;
55 | Text = "";
56 | }
57 | return base.ProcessCmdKey( ref msg, keyData );
58 |
59 | default:
60 | return base.ProcessCmdKey( ref msg, keyData );
61 | }
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/HeartbeatSaver/HeartbeatSaver.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {F289060F-A463-48B7-BDCC-1D51D89B23C9}
9 | Exe
10 | Properties
11 | fCraft.HeartbeatSaver
12 | HeartbeatSaver
13 | v3.5
14 | 512
15 | fCraft.HeartbeatSaver.HeartbeatSaver
16 | Client
17 |
18 |
19 | 3.5
20 |
21 |
22 |
23 | true
24 | full
25 | false
26 | ..\bin\Debug\
27 | DEBUG;TRACE
28 | prompt
29 | 4
30 |
31 |
32 | pdbonly
33 | true
34 | ..\bin\Release\
35 | TRACE
36 | prompt
37 | 4
38 |
39 |
40 |
41 |
42 | 3.5
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
61 |
--------------------------------------------------------------------------------
/fCraft/Network/IRCMessage.cs:
--------------------------------------------------------------------------------
1 | /* Copyright 2009-2014 Matvei Stefarov
2 | *
3 | * Based, in part, on SmartIrc4net code. Original license is reproduced below.
4 | *
5 | *
6 | *
7 | * SmartIrc4net - the IRC library for .NET/C#
8 | *
9 | * Copyright (c) 2003-2005 Mirco Bauer
10 | *
11 | * Full LGPL License:
12 | *
13 | * This library is free software; you can redistribute it and/or
14 | * modify it under the terms of the GNU Lesser General Public
15 | * License as published by the Free Software Foundation; either
16 | * version 2.1 of the License, or (at your option) any later version.
17 | *
18 | * This library is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 | * Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public
24 | * License along with this library; if not, write to the Free Software
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 | */
27 |
28 | namespace fCraft {
29 | /// Represents a parsed incoming IRC message.
30 | public sealed class IRCMessage {
31 | public string From { get; private set; }
32 | public string Nick { get; private set; }
33 | public string Ident { get; private set; }
34 | public string Host { get; private set; }
35 | public string Channel { get; private set; }
36 | public string Message { get; private set; }
37 | public string[] MessageArray { get; private set; }
38 | public string RawMessage { get; private set; }
39 | public string[] RawMessageArray { get; private set; }
40 | public IRCMessageType Type { get; private set; }
41 | public IRCReplyCode ReplyCode { get; private set; }
42 |
43 | public IRCMessage( string from, string nick, string ident, string host, string channel, string message, string rawMessage, IRCMessageType type, IRCReplyCode replyCode ) {
44 | RawMessage = rawMessage;
45 | RawMessageArray = rawMessage.Split( new[] { ' ' } );
46 | Type = type;
47 | ReplyCode = replyCode;
48 | From = from;
49 | Nick = nick;
50 | Ident = ident;
51 | Host = host;
52 | Channel = channel;
53 | if( message != null ) {
54 | // message is optional
55 | Message = message;
56 | MessageArray = message.Split( new[] { ' ' } );
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/fCraft/AutoRank/Criterion.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Linq;
4 | using System.Xml.Linq;
5 | using JetBrains.Annotations;
6 |
7 | namespace fCraft.AutoRank {
8 | sealed class Criterion : ICloneable {
9 | public Rank FromRank { get; set; }
10 | public Rank ToRank { get; set; }
11 | public ConditionSet Condition { get; set; }
12 |
13 | public Criterion( [NotNull] Criterion other ) {
14 | if( other == null ) throw new ArgumentNullException( "other" );
15 | FromRank = other.FromRank;
16 | ToRank = other.ToRank;
17 | Condition = other.Condition;
18 | }
19 |
20 | public Criterion( [NotNull] Rank fromRank, [NotNull] Rank toRank, [NotNull] ConditionSet condition ) {
21 | if( fromRank == null ) throw new ArgumentNullException( "fromRank" );
22 | if( toRank == null ) throw new ArgumentNullException( "toRank" );
23 | if( condition == null ) throw new ArgumentNullException( "condition" );
24 | FromRank = fromRank;
25 | ToRank = toRank;
26 | Condition = condition;
27 | }
28 |
29 | public Criterion( [NotNull] XElement el ) {
30 | if( el == null ) throw new ArgumentNullException( "el" );
31 |
32 | XAttribute attribute = el.Attribute( "fromRank" );
33 | if( attribute != null ) FromRank = Rank.Parse( attribute.Value );
34 | if( FromRank == null ) throw new FormatException( "Could not parse \"fromRank\"" );
35 |
36 | attribute = el.Attribute( "toRank" );
37 | if( attribute != null ) ToRank = Rank.Parse( attribute.Value );
38 | if( ToRank == null ) throw new FormatException( "Could not parse \"toRank\"" );
39 |
40 | Condition = (ConditionSet)AutoRank.Condition.Parse( el.Elements().First() );
41 | }
42 |
43 | public object Clone() {
44 | return new Criterion( this );
45 | }
46 |
47 | public override string ToString() {
48 | return String.Format( "Criteria( {0} from {1} to {2} )",
49 | (FromRank < ToRank ? "promote" : "demote"),
50 | FromRank.Name,
51 | ToRank.Name );
52 | }
53 |
54 | public XElement Serialize() {
55 | XElement el = new XElement( "Criterion" );
56 | el.Add( new XAttribute( "fromRank", FromRank.FullName ) );
57 | el.Add( new XAttribute( "toRank", ToRank.FullName ) );
58 | if( Condition != null ) {
59 | el.Add( Condition.Serialize() );
60 | }
61 | return el;
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/ConfigGUI/PermissionLimitBox.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace fCraft.ConfigGUI {
2 | partial class PermissionLimitBox {
3 | ///
4 | /// Required designer variable.
5 | ///
6 | private System.ComponentModel.IContainer components = null;
7 |
8 | ///
9 | /// Clean up any resources being used.
10 | ///
11 | /// true if managed resources should be disposed; otherwise, false.
12 | protected override void Dispose( bool disposing ) {
13 | if( disposing && (components != null) ) {
14 | components.Dispose();
15 | }
16 | base.Dispose( disposing );
17 | }
18 |
19 | #region Component Designer generated code
20 |
21 | ///
22 | /// Required method for Designer support - do not modify
23 | /// the contents of this method with the code editor.
24 | ///
25 | private void InitializeComponent() {
26 | this.comboBox = new System.Windows.Forms.ComboBox();
27 | this.label = new System.Windows.Forms.Label();
28 | this.SuspendLayout();
29 | //
30 | // comboBox
31 | //
32 | this.comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
33 | this.comboBox.FormattingEnabled = true;
34 | this.comboBox.Location = new System.Drawing.Point( 80, 0 );
35 | this.comboBox.Name = "comboBox";
36 | this.comboBox.Size = new System.Drawing.Size( 150, 21 );
37 | this.comboBox.TabIndex = 1;
38 | //
39 | // label
40 | //
41 | this.label.AutoSize = true;
42 | this.label.Location = new System.Drawing.Point( 3, 3 );
43 | this.label.Name = "label";
44 | this.label.Size = new System.Drawing.Size( 33, 13 );
45 | this.label.TabIndex = 0;
46 | this.label.Text = "Label";
47 | this.label.TextAlign = System.Drawing.ContentAlignment.TopRight;
48 | //
49 | // PermissionLimitBox
50 | //
51 | this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
52 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
53 | this.BackColor = System.Drawing.Color.Transparent;
54 | this.Controls.Add( this.comboBox );
55 | this.Controls.Add( this.label );
56 | this.Name = "PermissionLimitBox";
57 | this.Size = new System.Drawing.Size( 230, 21 );
58 | this.ResumeLayout( false );
59 | this.PerformLayout();
60 |
61 | }
62 |
63 | #endregion
64 |
65 | private System.Windows.Forms.ComboBox comboBox;
66 | private System.Windows.Forms.Label label;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/ConfigGUI/KeywordPicker.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System.Windows.Forms;
3 |
4 | namespace fCraft.ConfigGUI {
5 | public sealed partial class KeywordPicker : Form {
6 | public string Result;
7 |
8 | readonly ToolTip tips;
9 | static readonly KeywordInfo[] Keywords = {
10 | new KeywordInfo("{SERVER_NAME}", "Server name", "Name of your server, as specified in config." ),
11 | new KeywordInfo("{RANK}", "Player's rank", "Player's rank, including prefix and colors (if applicable)." ),
12 | new KeywordInfo("{PLAYER_NAME}", "Player's name", "Name of the player, including prefix and colors (if applicable)." ),
13 | new KeywordInfo("{TIME}", "Time", "Current time (server clock)."),
14 | new KeywordInfo("{WORLD}", "Main world name","Name of the main/starting world, including prefix and colors (if applicable)." ),
15 | new KeywordInfo("{PLAYERS}", "Number of players online", "Note that hidden players will not be included in this number." ),
16 | new KeywordInfo("{WORLDS}", "Number of worlds", "Number of worlds accessible by the player. Does not count hidden worlds." ),
17 | new KeywordInfo("{MOTD}", "MOTD", "Message-of-the-day (server subtitle), as specified in config." ),
18 | new KeywordInfo("{VERSION}", "fCraft version", "Version of fCraft that this server is running." ),
19 | new KeywordInfo("{PLAYER_LIST}", "Player list", "List of names of all online players that this player can see, including prefixes and colors (if applicable)." )
20 | };
21 |
22 | const int ButtonWidth = 150,
23 | ButtonHeight = 28;
24 |
25 | public KeywordPicker() {
26 | InitializeComponent();
27 | tips = new ToolTip();
28 | foreach( KeywordInfo keyword in Keywords ) {
29 | Button newButton = new Button {
30 | Text = keyword.LongName,
31 | Tag = keyword.Keyword,
32 | Width = ButtonWidth,
33 | Height = ButtonHeight
34 | };
35 | pFlow.Controls.Add( newButton );
36 | newButton.Click += delegate {
37 | Result = (string)newButton.Tag;
38 | DialogResult = DialogResult.OK;
39 | Close();
40 | };
41 | tips.SetToolTip( newButton, keyword.Description );
42 | }
43 | }
44 |
45 |
46 | struct KeywordInfo {
47 | public KeywordInfo( string keyword, string name, string description ) {
48 | Keyword = keyword;
49 | LongName = name;
50 | Description = description;
51 | }
52 | public readonly string Keyword, LongName, Description;
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/MapConverter/MapConverter.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {A5DA5B53-2047-40DE-9504-29B6EF4BE5B6}
9 | Exe
10 | Properties
11 | fCraft.MapConverter
12 | MapConverter
13 | v3.5
14 | 512
15 | fCraft.MapConverter.MapConverter
16 | Client
17 |
18 |
19 | 3.5
20 |
21 |
22 |
23 | true
24 | full
25 | false
26 | ..\bin\Debug\
27 | DEBUG;TRACE
28 | prompt
29 | 4
30 |
31 |
32 | pdbonly
33 | true
34 | ..\bin\Release\
35 | TRACE
36 | prompt
37 | 4
38 |
39 |
40 |
41 |
42 | 3.5
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | {7FBE7809-6F77-415C-ABEB-A3F627E817B0}
56 | fCraft
57 |
58 |
59 |
60 |
67 |
--------------------------------------------------------------------------------
/fCraft/MapGeneration/MapGenerator.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Xml.Linq;
4 | using JetBrains.Annotations;
5 |
6 | namespace fCraft.MapGeneration {
7 | /// Represents a type of map generator.
8 | /// Provides general information about this generator, and ways to create IMapGeneratorParameters objects.
9 | public abstract class MapGenerator {
10 | protected MapGenerator() {
11 | Version = new Version( 1, 0 );
12 | Presets = new[] {"Defaults"};
13 | }
14 |
15 | /// Name of the map generator. Uses same rules as command and world names.
16 | [NotNull]
17 | public string Name { get; protected set; }
18 | // TODO: name aliases/shortcuts
19 |
20 | /// Current version of the map generator.
21 | [NotNull]
22 | public Version Version { get; protected set; }
23 |
24 | /// Returns list of presets for this generator. Do not include default preset.
25 | /// May be blank (but not null).
26 | [NotNull]
27 | public string[] Presets { get; protected set; }
28 |
29 | /// Help string, printed when players call "/Help Gen ThisMapGensName"
30 | public string Help { get; set; }
31 |
32 | /// Creates a IMapGeneratorParameters object containing default parameters.
33 | [NotNull]
34 | public abstract MapGeneratorParameters CreateDefaultParameters();
35 |
36 | /// Parses serialized map generation parameters into a IMapGeneratorParameters object,
37 | /// (to load settings stored in template files or map metadata).
38 | /// Throw appropriate exceptions on failure (do not return null).
39 | [NotNull]
40 | public abstract MapGeneratorParameters CreateParameters( [NotNull] XElement serializedParameters );
41 |
42 | /// Parses command arguments to the generator, coming from in-game commands.
43 | /// In case of command-parsing problems, inform the player and return null.
44 | [CanBeNull]
45 | public abstract MapGeneratorParameters CreateParameters( [NotNull] Player player, [NotNull] CommandReader cmd );
46 |
47 | /// Creates parameters for a given preset name.
48 | /// Returns null if preset name was not recognized. Throws exceptions in case of other failures.
49 | /// Name of preset. May be null (meaning "return defaults").
50 | /// MapGeneratorParameters object for given preset; null if presetName was not recognized.
51 | [CanBeNull]
52 | public abstract MapGeneratorParameters CreateParameters( [NotNull] string presetName );
53 | }
54 | }
--------------------------------------------------------------------------------
/fCraft/World/BlockDBEntry.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System.IO;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace fCraft{
6 | /// Struct representing a single block change.
7 | /// You may safely cast byte* pointers directly to BlockDBEntry* and vice versa.
8 | [StructLayout( LayoutKind.Sequential, Pack = 1 )]
9 | public struct BlockDBEntry {
10 | /// UTC Unix timestamp of the change.
11 | public readonly int Timestamp;
12 |
13 | /// Numeric PlayerDB id of the player who made the change.
14 | public readonly int PlayerID;
15 |
16 | /// X coordinate (horizontal), in terms of blocks.
17 | public readonly short X;
18 |
19 | /// Y coordinate (horizontal), in terms of blocks.
20 | public readonly short Y;
21 |
22 | /// Z coordinate (vertical), in terms of blocks.
23 | public readonly short Z;
24 |
25 | /// Block that previously occupied this coordinate
26 | public readonly Block OldBlock;
27 |
28 | /// Block that now occupies this coordinate
29 | public readonly Block NewBlock;
30 |
31 | /// Change's (X,Y,Z) coordinates as a vector.
32 | public Vector3I Coord {
33 | get { return new Vector3I( X, Y, Z ); }
34 | }
35 |
36 | /// Context for this block change.
37 | public readonly BlockChangeContext Context;
38 |
39 |
40 | public BlockDBEntry( int timestamp, int playerID, short x, short y, short z,
41 | Block oldBlock, Block newBlock, BlockChangeContext flags ) {
42 | Timestamp = timestamp;
43 | PlayerID = playerID;
44 | X = x;
45 | Y = y;
46 | Z = z;
47 | OldBlock = oldBlock;
48 | NewBlock = newBlock;
49 | Context = flags;
50 | }
51 |
52 | public BlockDBEntry( int timestamp, int playerID, Vector3I coords,
53 | Block oldBlock, Block newBlock, BlockChangeContext flags ) {
54 | Timestamp = timestamp;
55 | PlayerID = playerID;
56 | X = (short)coords.X;
57 | Y = (short)coords.Y;
58 | Z = (short)coords.Z;
59 | OldBlock = oldBlock;
60 | NewBlock = newBlock;
61 | Context = flags;
62 | }
63 |
64 | public void Serialize( BinaryWriter writer ) {
65 | writer.Write( Timestamp );
66 | writer.Write( PlayerID );
67 | writer.Write( X );
68 | writer.Write( Y );
69 | writer.Write( Z );
70 | writer.Write( (byte)OldBlock );
71 | writer.Write( (byte)NewBlock );
72 | writer.Write( (int)Context );
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/ServerCLI/ServerCLI.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {315FB33C-6C57-4A89-ABFB-C083F2015880}
9 | Exe
10 | Properties
11 | fCraft.ServerCLI
12 | ServerCLI
13 | v3.5
14 | 512
15 | fCraft.ServerCLI.Program
16 | fcraft_console.ico
17 | Client
18 |
19 |
20 | 3.5
21 |
22 |
23 |
24 | true
25 | ..\bin\Debug\
26 | DEBUG;TRACE
27 | full
28 | AnyCPU
29 | Auto
30 | prompt
31 |
32 |
33 | ..\bin\Release\
34 | TRACE
35 | true
36 | pdbonly
37 | AnyCPU
38 | Off
39 | prompt
40 |
41 |
42 |
43 |
44 | 3.5
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | {7FBE7809-6F77-415C-ABEB-A3F627E817B0}
54 | fCraft
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
71 |
--------------------------------------------------------------------------------
/ConfigGUI/KeywordPicker.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace fCraft.ConfigGUI {
2 | sealed partial class KeywordPicker {
3 | ///
4 | /// Required designer variable.
5 | ///
6 | private System.ComponentModel.IContainer components = null;
7 |
8 | ///
9 | /// Clean up any resources being used.
10 | ///
11 | /// true if managed resources should be disposed; otherwise, false.
12 | protected override void Dispose( bool disposing ) {
13 | if( disposing && (components != null) ) {
14 | components.Dispose();
15 | }
16 | base.Dispose( disposing );
17 | }
18 |
19 | #region Windows Form Designer generated code
20 |
21 | ///
22 | /// Required method for Designer support - do not modify
23 | /// the contents of this method with the code editor.
24 | ///
25 | private void InitializeComponent() {
26 | this.pFlow = new System.Windows.Forms.FlowLayoutPanel();
27 | this.bCancel = new System.Windows.Forms.Button();
28 | this.SuspendLayout();
29 | //
30 | // pFlow
31 | //
32 | this.pFlow.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
33 | | System.Windows.Forms.AnchorStyles.Left)
34 | | System.Windows.Forms.AnchorStyles.Right)));
35 | this.pFlow.Location = new System.Drawing.Point( 13, 13 );
36 | this.pFlow.Name = "pFlow";
37 | this.pFlow.Size = new System.Drawing.Size( 159, 356 );
38 | this.pFlow.TabIndex = 0;
39 | //
40 | // bCancel
41 | //
42 | this.bCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
43 | this.bCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
44 | this.bCancel.Location = new System.Drawing.Point( 62, 375 );
45 | this.bCancel.Name = "bCancel";
46 | this.bCancel.Size = new System.Drawing.Size( 60, 23 );
47 | this.bCancel.TabIndex = 1;
48 | this.bCancel.Text = "Cancel";
49 | this.bCancel.UseVisualStyleBackColor = true;
50 | //
51 | // KeywordPicker
52 | //
53 | this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
54 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
55 | this.CancelButton = this.bCancel;
56 | this.ClientSize = new System.Drawing.Size( 184, 410 );
57 | this.Controls.Add( this.bCancel );
58 | this.Controls.Add( this.pFlow );
59 | this.Name = "KeywordPicker";
60 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
61 | this.Text = "KeywordPicker";
62 | this.ResumeLayout( false );
63 |
64 | }
65 |
66 | #endregion
67 |
68 | private System.Windows.Forms.FlowLayoutPanel pFlow;
69 | private System.Windows.Forms.Button bCancel;
70 | }
71 | }
--------------------------------------------------------------------------------
/UpdateInstaller/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.1
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace fCraft.UpdateInstaller.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("fCraft.UpdateInstaller.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | internal static byte[] Payload {
64 | get {
65 | object obj = ResourceManager.GetObject("Payload", resourceCulture);
66 | return ((byte[])(obj));
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/UndoDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft.Drawing {
5 | /// Draw operation that handles /Undo and /Redo commands.
6 | /// Applies changes stored in a given UndoState object.
7 | public sealed class UndoDrawOperation : DrawOpWithBrush {
8 | readonly BlockChangeContext undoContext = BlockChangeContext.Drawn | BlockChangeContext.UndoneSelf;
9 |
10 | public UndoState State { get; private set; }
11 |
12 | public bool Redo { get; private set; }
13 |
14 | public override int ExpectedMarks {
15 | get { return 0; }
16 | }
17 |
18 | public override string Description {
19 | get { return Name; }
20 | }
21 |
22 | public override string Name {
23 | get {
24 | if( Redo ) {
25 | return "Redo";
26 | } else {
27 | return "Undo";
28 | }
29 | }
30 | }
31 |
32 |
33 | public UndoDrawOperation( Player player, UndoState state, bool redo )
34 | : base( player ) {
35 | State = state;
36 | Redo = redo;
37 | if( Redo ) {
38 | undoContext |= BlockChangeContext.Redone;
39 | }
40 | }
41 |
42 |
43 | public override bool Prepare( Vector3I[] marks ) {
44 | Brush = this;
45 | if( !base.Prepare( marks ) ) return false;
46 | BlocksTotalEstimate = State.Buffer.Count;
47 | Context = undoContext;
48 | Bounds = State.CalculateBounds();
49 | return true;
50 | }
51 |
52 |
53 | public override bool Begin() {
54 | if( !RaiseBeginningEvent( this ) ) return false;
55 | if( Redo ) {
56 | UndoState = Player.RedoBegin( this );
57 | } else {
58 | UndoState = Player.UndoBegin( this );
59 | }
60 | StartTime = DateTime.UtcNow;
61 | HasBegun = true;
62 | Map.QueueDrawOp( this );
63 | RaiseBeganEvent( this );
64 | return true;
65 | }
66 |
67 |
68 | int undoBufferIndex;
69 | Block block;
70 |
71 | public override int DrawBatch( int maxBlocksToDraw ) {
72 | int blocksDone = 0;
73 | for( ; undoBufferIndex < State.Buffer.Count; undoBufferIndex++ ) {
74 | UndoBlock blockUpdate = State.Get( undoBufferIndex );
75 | Coords = new Vector3I( blockUpdate.X, blockUpdate.Y, blockUpdate.Z );
76 | block = blockUpdate.Block;
77 | if( DrawOneBlock() ) {
78 | blocksDone++;
79 | if( blocksDone >= maxBlocksToDraw || TimeToEndBatch ) {
80 | undoBufferIndex++;
81 | return blocksDone;
82 | }
83 | }
84 | }
85 | IsDone = true;
86 | return blocksDone;
87 | }
88 |
89 |
90 | protected override Block NextBlock() {
91 | return block;
92 | }
93 |
94 | public override bool ReadParams( CommandReader cmd ) {
95 | return true;
96 | }
97 | }
98 | }
--------------------------------------------------------------------------------
/fCraftGUI/MapGeneratorGui.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Windows.Forms;
4 | using JetBrains.Annotations;
5 | using fCraft.MapGeneration;
6 |
7 | namespace fCraft.GUI {
8 | /// Class that provides a GUI (UserControl) for adjusting map parameters.
9 | /// It would make sense for this class to be abstract, but VisualStudio's Designer
10 | /// does not support controls derived from abstract classes.
11 | /// See http://stackoverflow.com/questions/2764757/
12 | public class MapGeneratorGui : UserControl {
13 | Control oldParent;
14 |
15 | protected MapGeneratorGui() {
16 | Padding = new Padding( 0 );
17 | Margin = new Padding( 0 );
18 | BorderStyle = BorderStyle.None;
19 | }
20 |
21 | protected override void OnParentChanged( EventArgs e ) {
22 | if( oldParent != null ) {
23 | oldParent.SizeChanged -= Parent_SizeChanged;
24 | } else {
25 | Parent_SizeChanged( Parent, EventArgs.Empty );
26 | }
27 | if( Parent != null ) {
28 | Parent.SizeChanged += Parent_SizeChanged;
29 | }
30 | oldParent = Parent;
31 | base.OnParentChanged( e );
32 | }
33 |
34 | void Parent_SizeChanged( object sender, EventArgs e ) {
35 | if( !DesignMode ) {
36 | // auto-resize only when not in Designer mode (in VS)
37 | Size = Parent.Size;
38 | }
39 | }
40 |
41 |
42 | /// Reads given generator params, and adjusts GUI to reflect them.
43 | /// Given generation parameters.
44 | public virtual void SetParameters( [NotNull] MapGeneratorParameters generatorParameters ) {
45 | throw new NotImplementedException( "SetParameters must be overriden in MapGeneratorGui implementations." );
46 | }
47 |
48 |
49 | /// Creates mapgen parameters based on the current GUI state.
50 | /// The returned IMapGeneratorParameters must not be modified after being returned.
51 | /// IMapGeneratorParameters object representing GUI's current state.
52 | [NotNull]
53 | public virtual MapGeneratorParameters GetParameters() {
54 | throw new NotImplementedException( "GetParameters must be overriden in MapGeneratorGui implementations." );
55 | }
56 |
57 |
58 | /// Called by parent dialog when map dimension NumericUpDown controls have changed.
59 | /// Used to adjust any settings that may rely on map dimensions for scaling.
60 | /// Map width (horizontal, x dimension), in blocks.
61 | /// Map length (horizontal, y dimension), in blocks.
62 | /// Map height (vertical, z dimension), in blocks.
63 | public virtual void OnMapDimensionChange( int width, int length, int height ) {
64 | throw new NotImplementedException(
65 | "OnMapDimensionChange must be overriden in MapGeneratorGui implementations." );
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/fCraft/MapConversion/MapIndev.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.IO;
4 | using System.IO.Compression;
5 |
6 | namespace fCraft.MapConversion {
7 | /// NBT map conversion implementation, for converting NBT map format into fCraft's default map format.
8 | public sealed class MapIndev : IMapImporter {
9 | public string ServerName {
10 | get { return "Indev"; }
11 | }
12 |
13 | public string FileExtension {
14 | get { return "mclevel"; }
15 | }
16 |
17 | public bool SupportsImport {
18 | get { return true; }
19 | }
20 |
21 | public bool SupportsExport {
22 | get { return false; }
23 | }
24 |
25 |
26 | public MapStorageType StorageType {
27 | get { return MapStorageType.SingleFile; }
28 | }
29 |
30 | public MapFormat Format {
31 | get { return MapFormat.Indev; }
32 | }
33 |
34 |
35 | public bool ClaimsName( string fileName ) {
36 | if( fileName == null ) throw new ArgumentNullException( "fileName" );
37 | return fileName.EndsWith( ".mclevel", StringComparison.OrdinalIgnoreCase );
38 | }
39 |
40 |
41 | public bool Claims( string fileName ) {
42 | if( fileName == null ) throw new ArgumentNullException( "fileName" );
43 | try {
44 | using( FileStream mapStream = File.OpenRead( fileName ) ) {
45 | GZipStream gs = new GZipStream( mapStream, CompressionMode.Decompress, true );
46 | BinaryReader bs = new BinaryReader( gs );
47 | return ( bs.ReadByte() == 10 && NBTag.ReadString( bs ) == "MinecraftLevel" );
48 | }
49 | } catch( Exception ) {
50 | return false;
51 | }
52 | }
53 |
54 |
55 | public Map LoadHeader( string fileName ) {
56 | if( fileName == null ) throw new ArgumentNullException( "fileName" );
57 | Map map = Load( fileName );
58 | map.Blocks = null;
59 | return map;
60 | }
61 |
62 |
63 | public Map Load( string fileName ) {
64 | if( fileName == null ) throw new ArgumentNullException( "fileName" );
65 | using( FileStream mapStream = File.OpenRead( fileName ) ) {
66 | GZipStream gs = new GZipStream( mapStream, CompressionMode.Decompress, true );
67 | NBTag tag = NBTag.ReadStream( gs );
68 |
69 | NBTag mapTag = tag["Map"];
70 | // ReSharper disable UseObjectOrCollectionInitializer
71 | Map map = new Map( null,
72 | mapTag["Width"].GetShort(),
73 | mapTag["Length"].GetShort(),
74 | mapTag["Height"].GetShort(),
75 | false );
76 | // ReSharper restore UseObjectOrCollectionInitializer
77 | map.Spawn = new Position( mapTag["Spawn"][0].GetShort(),
78 | mapTag["Spawn"][2].GetShort(),
79 | mapTag["Spawn"][1].GetShort() );
80 |
81 | map.Blocks = mapTag["Blocks"].GetBytes();
82 | map.RemoveUnknownBlocktypes();
83 |
84 | return map;
85 | }
86 | }
87 | }
88 | }
--------------------------------------------------------------------------------
/MapRenderer/MapRenderer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {52922C22-50A7-4E5D-8020-C5B0571B0F74}
9 | Exe
10 | Properties
11 | fCraft.MapRenderer
12 | MapRenderer
13 | v3.5
14 | 512
15 | fCraft.MapRenderer.MapRenderer
16 | Client
17 |
18 |
19 | 3.5
20 |
21 |
22 |
23 | true
24 | full
25 | false
26 | ..\bin\Debug\
27 | DEBUG;TRACE
28 | prompt
29 | 4
30 | true
31 |
32 |
33 | pdbonly
34 | true
35 | ..\bin\Release\
36 | TRACE
37 | prompt
38 | 4
39 | true
40 |
41 |
42 |
43 |
44 | 3.5
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | {AFAEE6CC-8B4F-40CD-9623-7FFDC8E52222}
65 | fCraftGUI
66 |
67 |
68 | {7FBE7809-6F77-415C-ABEB-A3F627E817B0}
69 | fCraft
70 |
71 |
72 |
73 |
80 |
--------------------------------------------------------------------------------
/fCraftGUI/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.296
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace fCraft.GUI.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("fCraft.GUI.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | internal static System.Drawing.Bitmap Tileset {
64 | get {
65 | object obj = ResourceManager.GetObject("Tileset", resourceCulture);
66 | return ((System.Drawing.Bitmap)(obj));
67 | }
68 | }
69 |
70 | internal static System.Drawing.Bitmap TilesetShadowed {
71 | get {
72 | object obj = ResourceManager.GetObject("TilesetShadowed", resourceCulture);
73 | return ((System.Drawing.Bitmap)(obj));
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/fCraft/MapGeneration/MapGeneratorState.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.ComponentModel;
4 | using JetBrains.Annotations;
5 |
6 | namespace fCraft.MapGeneration {
7 | /// Represents a single-use state object for a particular set of map generator parameters (IMapGeneratorParameters).
8 | /// Provides a synchronous method to carry out generation, asynchronous method to cancel generation,
9 | /// various properties to indicate progress, and an event to report progress changes.
10 | public abstract class MapGeneratorState {
11 | /// Associated map generation parameters.
12 | [NotNull]
13 | public MapGeneratorParameters Parameters { get; protected set; }
14 |
15 | /// Flag indicating whether this generation task has been cancelled.
16 | /// Should be set by CancelAsync(), regardless of whether async cancellation is supported.
17 | public bool Canceled { get; protected set; }
18 |
19 | /// Flag indicating whether this generation task has finished.
20 | /// Expected to be set right before Generate() exits.
21 | public bool Finished { get; protected set; }
22 |
23 | /// Progress percentage -- an integer between 0 and 100.
24 | /// Should start at 0 before Generate() is called,
25 | /// get updated as Generate is working, and end up at exactly 100 by the time Generate() returns.
26 | public int Progress { get; protected set; }
27 |
28 | /// String representing the current state of the map generator.
29 | /// This information will be shown to users in ConfigGUI.
30 | public string StatusString { get; protected set; }
31 |
32 | /// Flag: whether this generation task will report progress.
33 | public bool ReportsProgress { get; protected set; }
34 |
35 | /// Flag: whether this generation task supports async cancellation.
36 | public bool SupportsCancellation { get; protected set; }
37 |
38 | /// Map that has been generated (may be null).
39 | [CanBeNull]
40 | public Map Result { get; protected set; }
41 |
42 |
43 | /// Event that is raised when progress percentage or status string change.
44 | public event ProgressChangedEventHandler ProgressChanged;
45 |
46 |
47 | /// Synchronously creates a map file. This will be invoked on a worker thread.
48 | /// Created map file, or null (if generation was aborted).
49 | [CanBeNull]
50 | public abstract Map Generate();
51 |
52 | /// Sigals this task to asynchronously finish executing.
53 | public virtual void CancelAsync() {
54 | Canceled = true;
55 | }
56 |
57 |
58 | protected virtual void ReportProgress( int progressPercent, [NotNull] string statusString ) {
59 | if( statusString == null ) {
60 | throw new ArgumentNullException( "statusString" );
61 | }
62 | Progress = progressPercent;
63 | StatusString = statusString;
64 | var handler = ProgressChanged;
65 | if( handler != null ) {
66 | ProgressChangedEventArgs args = new ProgressChangedEventArgs( progressPercent, statusString );
67 | handler( this, args );
68 | }
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/TorusDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // fCraft is Copyright 2009-2014 Matvei Stefarov
2 | // original TorusDrawOperation written and contributed by M1_Abrams
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | namespace fCraft.Drawing {
7 | /// Draw operation that creates a horizontal torus.
8 | public sealed class TorusDrawOperation : DrawOperation {
9 | const float Bias = 0.5f;
10 | Vector3I center;
11 | int tubeR;
12 | double bigR;
13 |
14 | public override string Name {
15 | get { return "Torus"; }
16 | }
17 |
18 | public override int ExpectedMarks {
19 | get { return 2; }
20 | }
21 |
22 | public TorusDrawOperation( Player player )
23 | : base( player ) {
24 | }
25 |
26 |
27 | public override bool Prepare( Vector3I[] marks ) {
28 | if( !base.Prepare( marks ) ) return false;
29 |
30 | // center of the torus
31 | center = marks[0];
32 |
33 | Vector3I radiusVector = (marks[1] - center).Abs();
34 |
35 | // tube radius is figured out from Z component of the mark vector
36 | tubeR = radiusVector.Z;
37 |
38 | // torus radius is figured out from length of vector's X-Y components
39 | bigR = Math.Sqrt( radiusVector.X * radiusVector.X +
40 | radiusVector.Y * radiusVector.Y + .5 );
41 |
42 | // tube + torus radius, rounded up. This will be the maximum extend of the torus.
43 | int combinedRadius = (int)Math.Ceiling( bigR + tubeR );
44 |
45 | // vector from center of torus to the furthest-away point of the bounding box
46 | Vector3I combinedRadiusVector = new Vector3I( combinedRadius, combinedRadius, tubeR + 1 );
47 |
48 | // adjusted bounding box
49 | Bounds = new BoundingBox( center - combinedRadiusVector, center + combinedRadiusVector );
50 |
51 | BlocksTotalEstimate = (int)(2 * Math.PI * Math.PI * bigR * (tubeR * tubeR + Bias));
52 |
53 | coordEnumerator = BlockEnumerator().GetEnumerator();
54 | return true;
55 | }
56 |
57 |
58 | IEnumerator coordEnumerator;
59 | public override int DrawBatch( int maxBlocksToDraw ) {
60 | int blocksDone = 0;
61 | while( coordEnumerator.MoveNext() ) {
62 | Coords = coordEnumerator.Current;
63 | if( DrawOneBlock() ) {
64 | blocksDone++;
65 | if( blocksDone >= maxBlocksToDraw ) return blocksDone;
66 | }
67 | if( TimeToEndBatch ) return blocksDone;
68 | }
69 | IsDone = true;
70 | return blocksDone;
71 | }
72 |
73 |
74 | IEnumerable BlockEnumerator() {
75 | for( int x = Bounds.XMin; x <= Bounds.XMax; x++ ) {
76 | for( int y = Bounds.YMin; y <= Bounds.YMax; y++ ) {
77 | for( int z = Bounds.ZMin; z <= Bounds.ZMax; z++ ) {
78 | double dx = (x - center.X);
79 | double dy = (y - center.Y);
80 | double dz = (z - center.Z);
81 |
82 | // test if it's inside the torus
83 | double r1 = bigR - Math.Sqrt( dx * dx + dy * dy );
84 | if( r1 * r1 + dz * dz <= tubeR * tubeR + Bias ) {
85 | yield return new Vector3I( x, y, z );
86 | }
87 | }
88 | }
89 | }
90 | }
91 | }
92 | }
--------------------------------------------------------------------------------
/ConfigGUI/UpdaterSettingsPopup.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Windows.Forms;
4 |
5 | namespace fCraft.ConfigGUI {
6 | public sealed partial class UpdaterSettingsPopup : Form {
7 |
8 | public string RunBeforeUpdate {
9 | get {
10 | if( xRunBeforeUpdate.Checked) return tRunBeforeUpdate.Text;
11 | else return "";
12 | }
13 | set { tRunBeforeUpdate.Text = value; }
14 | }
15 |
16 | public string RunAfterUpdate {
17 | get {
18 | if( xRunAfterUpdate.Checked ) return tRunAfterUpdate.Text;
19 | else return "";
20 | }
21 | set { tRunAfterUpdate.Text = value; }
22 | }
23 |
24 | public UpdaterMode UpdaterMode {
25 | get {
26 | if( rDisabled.Checked ) return UpdaterMode.Disabled;
27 | if( rNotify.Checked ) return UpdaterMode.Notify;
28 | if( rPrompt.Checked ) return UpdaterMode.Prompt;
29 | return UpdaterMode.Auto;
30 | }
31 | set {
32 | switch( value ) {
33 | case UpdaterMode.Disabled:
34 | rDisabled.Checked = true; break;
35 | case UpdaterMode.Notify:
36 | rNotify.Checked = true; break;
37 | case UpdaterMode.Prompt:
38 | rPrompt.Checked = true; break;
39 | case UpdaterMode.Auto:
40 | rAutomatic.Checked = true; break;
41 | }
42 | }
43 | }
44 |
45 | public bool BackupBeforeUpdate {
46 | get { return xBackupBeforeUpdating.Checked; }
47 | set { xBackupBeforeUpdating.Checked = value; }
48 | }
49 |
50 | string oldRunBeforeUpdate, oldRunAfterUpdate;
51 | UpdaterMode oldUpdaterMode;
52 | bool oldBackupBeforeUpdate;
53 |
54 | public UpdaterSettingsPopup() {
55 | InitializeComponent();
56 | Shown += delegate {
57 | oldRunBeforeUpdate = RunBeforeUpdate;
58 | oldRunAfterUpdate = RunAfterUpdate;
59 | oldUpdaterMode = UpdaterMode;
60 | oldBackupBeforeUpdate = BackupBeforeUpdate;
61 | };
62 | FormClosed += delegate {
63 | if( DialogResult != DialogResult.OK ) {
64 | RunBeforeUpdate = oldRunBeforeUpdate;
65 | RunAfterUpdate = oldRunAfterUpdate;
66 | UpdaterMode = oldUpdaterMode;
67 | BackupBeforeUpdate = oldBackupBeforeUpdate;
68 | }
69 | };
70 | }
71 |
72 | private void xRunBeforeUpdate_CheckedChanged( object sender, EventArgs e ) {
73 | tRunBeforeUpdate.Enabled = xRunBeforeUpdate.Checked;
74 | }
75 |
76 | private void xRunAfterUpdate_CheckedChanged( object sender, EventArgs e ) {
77 | tRunAfterUpdate.Enabled = xRunAfterUpdate.Checked;
78 | }
79 |
80 | private void rDisabled_CheckedChanged( object sender, EventArgs e ) {
81 | gOptions.Enabled = !rDisabled.Checked;
82 | }
83 |
84 |
85 | private void tRunBeforeUpdate_TextChanged( object sender, EventArgs e ) {
86 | if( tRunBeforeUpdate.Text.Length > 0 ) {
87 | xRunBeforeUpdate.Checked = true;
88 | }
89 | }
90 |
91 | private void tRunAfterUpdate_TextChanged( object sender, EventArgs e ) {
92 | if( tRunAfterUpdate.Text.Length > 0 ) {
93 | xRunAfterUpdate.Checked = true;
94 | }
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/fCraft/World/World.Events.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Collections.Generic;
4 | using JetBrains.Annotations;
5 |
6 | namespace fCraft.Events {
7 | /// An EventArgs for an event that directly relates to a particular world.
8 | public interface IWorldEvent {
9 | /// World affected by the event.
10 | World World { get; }
11 | }
12 |
13 |
14 | /// Provides data for WorldManager.MainWorldChanged event. Immutable.
15 | public class MainWorldChangedEventArgs : EventArgs {
16 | internal MainWorldChangedEventArgs( [CanBeNull] World oldWorld, [NotNull] World newWorld ) {
17 | if( newWorld == null ) throw new ArgumentNullException( "newWorld" );
18 | OldMainWorld = oldWorld;
19 | NewMainWorld = newWorld;
20 | }
21 |
22 |
23 | [CanBeNull]
24 | public World OldMainWorld { get; private set; }
25 |
26 | [NotNull]
27 | public World NewMainWorld { get; private set; }
28 | }
29 |
30 |
31 | /// Provides data for WorldManager.MainWorldChanging event. Cancelable.
32 | public sealed class MainWorldChangingEventArgs : MainWorldChangedEventArgs, ICancelableEvent {
33 | internal MainWorldChangingEventArgs( World oldWorld, [NotNull] World newWorld )
34 | : base( oldWorld, newWorld ) { }
35 |
36 | public bool Cancel { get; set; }
37 | }
38 |
39 |
40 | /// Provides data for WorldManager.SearchingForWorld event. Allows changing the results.
41 | public sealed class SearchingForWorldEventArgs : EventArgs, IPlayerEvent {
42 | internal SearchingForWorldEventArgs( [CanBeNull] Player player, [NotNull] string searchQuery, [NotNull] List matches ) {
43 | if( searchQuery == null ) throw new ArgumentNullException( "searchQuery" );
44 | if( matches == null ) throw new ArgumentNullException( "matches" );
45 | Player = player;
46 | SearchQuery = searchQuery;
47 | Matches = matches;
48 | }
49 |
50 | [CanBeNull]
51 | public Player Player { get; private set; }
52 |
53 | [NotNull]
54 | public string SearchQuery { get; private set; }
55 |
56 | [NotNull]
57 | public List Matches { get; set; }
58 | }
59 |
60 |
61 | /// Provides data for WorldManager.WorldCreating event. Allows renaming. Cancelable.
62 | public sealed class WorldCreatingEventArgs : EventArgs, ICancelableEvent {
63 | internal WorldCreatingEventArgs( [CanBeNull] Player player, [NotNull] string worldName, [CanBeNull] Map map ) {
64 | if( worldName == null ) throw new ArgumentNullException( "worldName" );
65 | Player = player;
66 | WorldName = worldName;
67 | Map = map;
68 | }
69 |
70 | [CanBeNull]
71 | public Player Player { get; private set; }
72 |
73 | [NotNull]
74 | public string WorldName { get; set; }
75 |
76 | [CanBeNull]
77 | public Map Map { get; private set; }
78 |
79 | public bool Cancel { get; set; }
80 | }
81 |
82 |
83 | /// Provides data for WorldManager.WorldCreated event. Immutable.
84 | public sealed class WorldCreatedEventArgs : EventArgs, IPlayerEvent, IWorldEvent {
85 | internal WorldCreatedEventArgs( [CanBeNull] Player player, [NotNull] World world ) {
86 | if( world == null ) throw new ArgumentNullException( "world" );
87 | Player = player;
88 | World = world;
89 | }
90 |
91 | [CanBeNull]
92 | public Player Player { get; private set; }
93 |
94 | [NotNull]
95 | public World World { get; private set; }
96 | }
97 | }
--------------------------------------------------------------------------------
/fCraftGUI/MapGenGuiUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using fCraft.MapGeneration;
5 | using JetBrains.Annotations;
6 |
7 | namespace fCraft.GUI {
8 | public static class MapGenGuiUtil {
9 | static readonly Dictionary Generators =
10 | new Dictionary();
11 |
12 | static MapGenGuiUtil() {
13 | RegisterGui( RealisticMapGenGuiProvider.Instance, RealisticMapGen.Instance.Name );
14 | RegisterGui( FlatMapGenGuiProvider.Instance, FlatMapGen.Instance.Name );
15 | }
16 |
17 |
18 | /// Registers a new map generator. If another GUI provider already
19 | /// exists for this generator name, this new provider will replace it.
20 | /// IMapGeneratorGuiProvider to register.
21 | /// Name of the generator for which GuiProvider is being registered.
22 | /// provider or genName is null.
23 | public static void RegisterGui( [NotNull] IMapGeneratorGuiProvider provider, [NotNull] string genName ) {
24 | if( provider == null ) {
25 | throw new ArgumentNullException( "provider" );
26 | }
27 | IMapGeneratorGuiProvider oldProvider;
28 | if( Generators.TryGetValue( genName.ToLowerInvariant(), out oldProvider ) ) {
29 | Logger.Log( LogType.Warning,
30 | "More than one GUI has been registered for \"{0}\" map generator. {1} now overrides {2}.",
31 | oldProvider.Name,
32 | provider.Name,
33 | genName );
34 | }
35 | Generators[genName.ToLowerInvariant()] = provider;
36 | }
37 |
38 |
39 | /// Finds the best GUI provider for given map generator.
40 | /// Name of the generator for which a GUI is needed.
41 | /// Either specialized IMapGeneratorGuiProvider for given generator,
42 | /// or default GUI provider as fallback.
43 | /// genName is null.
44 | [NotNull]
45 | public static IMapGeneratorGuiProvider GetGuiForGenerator( [NotNull] string genName ) {
46 | if( genName == null ) {
47 | throw new ArgumentNullException( "genName" );
48 | }
49 | IMapGeneratorGuiProvider provider;
50 | if( Generators.TryGetValue( genName.ToLowerInvariant(), out provider ) ) {
51 | return provider;
52 | } else {
53 | return DefaultMapGenGuiProvider.Instance;
54 | }
55 | }
56 |
57 |
58 | /// Finds the best GUI provider for given MapGenerator.
59 | /// Generator for which a GUI is needed.
60 | /// Either specialized IMapGeneratorGuiProvider for given generator,
61 | /// or default GUI provider as fallback.
62 | /// gen is null.
63 | [NotNull]
64 | public static IMapGeneratorGuiProvider GetGuiForGenerator( [NotNull] MapGenerator gen ) {
65 | if( gen == null ) {
66 | throw new ArgumentNullException( "gen" );
67 | }
68 | return GetGuiForGenerator( gen.Name );
69 | }
70 |
71 |
72 | /// Returns an array of all registered GUI providers.
73 | [NotNull]
74 | public static IMapGeneratorGuiProvider[] ProviderList {
75 | get { return Generators.Values.ToArray(); }
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/TriangleWireframeDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace fCraft.Drawing {
6 | /// Draw operation that creates an outline of a triangle, using three given coordinates as vertices.
7 | public sealed class TriangleWireframeDrawOperation : DrawOperation {
8 |
9 | public override int ExpectedMarks {
10 | get { return 3; }
11 | }
12 |
13 | public override string Name {
14 | get { return "TriangleW"; }
15 | }
16 |
17 | public TriangleWireframeDrawOperation( Player player )
18 | : base( player ) {
19 | }
20 |
21 |
22 | public override bool Prepare( Vector3I[] marks ) {
23 | Vector3I minVector = new Vector3I( Math.Min( marks[0].X, Math.Min( marks[1].X, marks[2].X ) ),
24 | Math.Min( marks[0].Y, Math.Min( marks[1].Y, marks[2].Y ) ),
25 | Math.Min( marks[0].Z, Math.Min( marks[1].Z, marks[2].Z ) ) );
26 | Vector3I maxVector = new Vector3I( Math.Max( marks[0].X, Math.Max( marks[1].X, marks[2].X ) ),
27 | Math.Max( marks[0].Y, Math.Max( marks[1].Y, marks[2].Y ) ),
28 | Math.Max( marks[0].Z, Math.Max( marks[1].Z, marks[2].Z ) ) );
29 | Bounds = new BoundingBox( minVector, maxVector );
30 |
31 | if( !base.Prepare( marks ) ) return false;
32 |
33 | BlocksTotalEstimate = Math.Max( Bounds.Width, Math.Max( Bounds.Height, Bounds.Length ) );
34 |
35 | coordEnumerator1 = LineEnumerator( Marks[0], Marks[1] ).GetEnumerator();
36 | coordEnumerator2 = LineEnumerator( Marks[1], Marks[2] ).GetEnumerator();
37 | coordEnumerator3 = LineEnumerator( Marks[2], Marks[0] ).GetEnumerator();
38 | return true;
39 | }
40 |
41 |
42 | IEnumerator coordEnumerator1, coordEnumerator2, coordEnumerator3;
43 | public override int DrawBatch( int maxBlocksToDraw ) {
44 | int blocksDone = 0;
45 | while( coordEnumerator1.MoveNext() ) {
46 | Coords = coordEnumerator1.Current;
47 | if( DrawOneBlockIfNotDuplicate() ) {
48 | blocksDone++;
49 | if( blocksDone >= maxBlocksToDraw ) return blocksDone;
50 | }
51 | if( TimeToEndBatch ) return blocksDone;
52 | }
53 | while( coordEnumerator2.MoveNext() ) {
54 | Coords = coordEnumerator2.Current;
55 | if( DrawOneBlockIfNotDuplicate() ) {
56 | blocksDone++;
57 | if( blocksDone >= maxBlocksToDraw ) return blocksDone;
58 | }
59 | if( TimeToEndBatch ) return blocksDone;
60 | }
61 | while( coordEnumerator3.MoveNext() ) {
62 | Coords = coordEnumerator3.Current;
63 | if( DrawOneBlockIfNotDuplicate() ) {
64 | blocksDone++;
65 | if( blocksDone >= maxBlocksToDraw ) return blocksDone;
66 | }
67 | if( TimeToEndBatch ) return blocksDone;
68 | }
69 | IsDone = true;
70 | return blocksDone;
71 | }
72 |
73 |
74 |
75 | readonly HashSet modifiedBlocks = new HashSet();
76 |
77 | bool DrawOneBlockIfNotDuplicate() {
78 | int index = Map.Index( Coords );
79 | if( modifiedBlocks.Contains( index ) ) {
80 | return false;
81 | } else {
82 | modifiedBlocks.Add( index );
83 | return DrawOneBlock();
84 | }
85 | }
86 | }
87 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/CuboidHollowDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace fCraft.Drawing {
6 | /// Draw operation that creates a hollow cuboid, optionally filling the center.
7 | public sealed class CuboidHollowDrawOperation : DrawOperation {
8 | bool fillInner;
9 |
10 | public override string Name {
11 | get { return "CuboidH"; }
12 | }
13 |
14 | public override int ExpectedMarks {
15 | get { return 2; }
16 | }
17 |
18 | public CuboidHollowDrawOperation( Player player )
19 | : base( player ) {
20 | }
21 |
22 |
23 | public override bool Prepare( Vector3I[] marks ) {
24 | if( !base.Prepare( marks ) ) return false;
25 |
26 | fillInner = ( Brush.AlternateBlocks > 1 ) && Bounds.Width > 2 && Bounds.Length > 2 && Bounds.Height > 2;
27 |
28 | BlocksTotalEstimate = Bounds.Volume;
29 | if( !fillInner ) {
30 | BlocksTotalEstimate -= Math.Max( 0, Bounds.Width - 2 ) * Math.Max( 0, Bounds.Length - 2 ) *
31 | Math.Max( 0, Bounds.Height - 2 );
32 | }
33 |
34 | coordEnumerator = BlockEnumerator().GetEnumerator();
35 | return true;
36 | }
37 |
38 |
39 | IEnumerator coordEnumerator;
40 | public override int DrawBatch( int maxBlocksToDraw ) {
41 | int blocksDone = 0;
42 | while( coordEnumerator.MoveNext() ) {
43 | Coords = coordEnumerator.Current;
44 | if( DrawOneBlock() ) {
45 | blocksDone++;
46 | if( blocksDone >= maxBlocksToDraw ) return blocksDone;
47 | }
48 | if( TimeToEndBatch ) return blocksDone;
49 | }
50 | IsDone = true;
51 | return blocksDone;
52 | }
53 |
54 |
55 | IEnumerable BlockEnumerator() {
56 | for( int x = Bounds.XMin; x <= Bounds.XMax; x++ ) {
57 | for( int y = Bounds.YMin; y <= Bounds.YMax; y++ ) {
58 | yield return new Vector3I( x, y, Bounds.ZMin );
59 | if( Bounds.ZMin != Bounds.ZMax ) {
60 | yield return new Vector3I( x, y, Bounds.ZMax );
61 | }
62 | }
63 | }
64 |
65 | if( Bounds.Height > 2 ) {
66 | for( int x = Bounds.XMin; x <= Bounds.XMax; x++ ) {
67 | for( int z = Bounds.ZMin + 1; z < Bounds.ZMax; z++ ) {
68 | yield return new Vector3I( x, Bounds.YMin, z );
69 | if( Bounds.YMin != Bounds.YMax ) {
70 | yield return new Vector3I( x, Bounds.YMax, z );
71 | }
72 | }
73 | }
74 |
75 | for( int y = Bounds.YMin + 1; y < Bounds.YMax; y++ ) {
76 | for( int z = Bounds.ZMin + 1; z < Bounds.ZMax; z++ ) {
77 | yield return new Vector3I( Bounds.XMin, y, z );
78 | if( Bounds.XMin != Bounds.XMax ) {
79 | yield return new Vector3I( Bounds.XMax, y, z );
80 | }
81 | }
82 | }
83 | }
84 |
85 | if( fillInner ) {
86 | AlternateBlockIndex = 1;
87 | for( int x = Bounds.XMin + 1; x < Bounds.XMax; x++ ) {
88 | for( int y = Bounds.YMin + 1; y < Bounds.YMax; y++ ) {
89 | for( int z = Bounds.ZMin + 1; z < Bounds.ZMax; z++ ) {
90 | yield return new Vector3I( x, y, z );
91 | }
92 | }
93 | }
94 | }
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/fCraft/MapConversion/MyneMetaFile.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using JetBrains.Annotations;
7 |
8 | namespace fCraft.MapConversion {
9 | /// INI parser used by MapMyne.
10 | sealed class MyneMetaFile {
11 | const string Separator = "=";
12 | readonly Dictionary> contents = new Dictionary>();
13 |
14 | public string this[[NotNull] string section, [NotNull] string key] {
15 | get {
16 | if( section == null ) throw new ArgumentNullException( "section" );
17 | if( key == null ) throw new ArgumentNullException( "key" );
18 | return contents[section][key];
19 | }
20 | set {
21 | if( section == null ) throw new ArgumentNullException( "section" );
22 | if( key == null ) throw new ArgumentNullException( "key" );
23 | if( value == null ) throw new ArgumentNullException( "value" );
24 | if( !contents.ContainsKey( section ) ) {
25 | contents[section] = new Dictionary();
26 | }
27 | contents[section][key] = value;
28 | }
29 | }
30 |
31 | public MyneMetaFile( [NotNull] Stream fileStream ) {
32 | if( fileStream == null ) throw new ArgumentNullException( "fileStream" );
33 | StreamReader reader = new StreamReader( fileStream );
34 | Dictionary section = null;
35 | string lastKey = null;
36 | while( true ) {
37 | string line = reader.ReadLine();
38 | if( line == null ) break;
39 |
40 | if( line.StartsWith( "#" ) ) {
41 | lastKey = null;
42 | } else if( line.StartsWith( "[" ) ) {
43 | lastKey = null;
44 | string sectionName = line.Substring( 1, line.IndexOf( ']' ) - 1 ).Trim().ToLower();
45 | section = new Dictionary();
46 | contents.Add( sectionName, section );
47 | } else if( line.StartsWith( "\t" ) ) {
48 | if( lastKey != null ) {
49 | section[lastKey] += Environment.NewLine + line.Substring( 1 );
50 | }
51 | } else if( line.Contains( Separator ) && section != null ) {
52 | string keyName = line.Substring( 0, line.IndexOf( Separator, StringComparison.Ordinal ) ).TrimEnd().ToLower();
53 | string valueName = line.Substring( line.IndexOf( Separator, StringComparison.Ordinal ) + 1 ).TrimStart();
54 | section.Add( keyName, valueName );
55 | lastKey = keyName;
56 | } else {
57 | lastKey = null;
58 | }
59 | }
60 | }
61 |
62 |
63 | public bool ContainsSection( [NotNull] string section ) {
64 | if( section == null ) throw new ArgumentNullException( "section" );
65 | return contents.ContainsKey( section.ToLower() );
66 | }
67 |
68 | public bool Contains( [NotNull] string section, [NotNull] params string[] keys ) {
69 | if( section == null ) throw new ArgumentNullException( "section" );
70 | if( keys == null ) throw new ArgumentNullException( "keys" );
71 | if( contents.ContainsKey( section.ToLower() ) ) {
72 | return keys.All( key => contents[section.ToLower()].ContainsKey( key.ToLower() ) );
73 | } else {
74 | return false;
75 | }
76 | }
77 |
78 | public bool IsEmpty {
79 | get {
80 | return ( contents.Count == 0 );
81 | }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/fCraft/Player/Position.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace fCraft {
6 | /// Struct representing a position AND orientation in 3D space.
7 | /// Used to represent players' positions in Minecraft world.
8 | /// Stores X/Y/Z as signed shorts, and R/L as unsigned bytes (8 bytes total).
9 | /// Use Vector3I if you just need X/Y/Z coordinates without orientation.
10 | /// Note that, as a struct, Positions are COPIED when assigned or passed as an argument.
11 | [StructLayout( LayoutKind.Sequential, Pack = 1 )]
12 | public struct Position : IEquatable {
13 | /// Position at (0,0,0) with R=0 and L=0.
14 | public static readonly Position Zero = new Position( 0, 0, 0 );
15 |
16 | public readonly short X, Y, Z;
17 | public readonly byte R, L;
18 |
19 |
20 | public Position( Position other, byte r, byte l ) {
21 | X = other.X;
22 | Y = other.Y;
23 | Z = other.Z;
24 | R = r;
25 | L = l;
26 | }
27 |
28 |
29 | public Position( short x, short y, short z, byte r, byte l ) {
30 | X = x;
31 | Y = y;
32 | Z = z;
33 | R = r;
34 | L = l;
35 | }
36 |
37 |
38 | public Position( int x, int y, int z ) {
39 | X = (short)x;
40 | Y = (short)y;
41 | Z = (short)z;
42 | R = 0;
43 | L = 0;
44 | }
45 |
46 |
47 | internal bool FitsIntoMoveRotatePacket {
48 | get {
49 | return X >= SByte.MinValue && X <= SByte.MaxValue &&
50 | Y >= SByte.MinValue && Y <= SByte.MaxValue &&
51 | Z >= SByte.MinValue && Z <= SByte.MaxValue;
52 | }
53 | }
54 |
55 |
56 | public bool IsZero {
57 | get { return X == 0 && Y == 0 && Z == 0 && R == 0 && L == 0; }
58 | }
59 |
60 |
61 | // adjust for bugs in position-reporting in Minecraft client
62 | public Position GetFixed() {
63 | return new Position( X, Y, (short)(Z - 22), R, L );
64 | }
65 |
66 |
67 | public int DistanceSquaredTo( Position other ) {
68 | return ( X - other.X ) * ( X - other.X ) + ( Y - other.Y ) * ( Y - other.Y ) +
69 | ( Z - other.Z ) * ( Z - other.Z );
70 | }
71 |
72 |
73 | #region Equality
74 |
75 | public static bool operator ==( Position a, Position b ) {
76 | return a.Equals( b );
77 | }
78 |
79 |
80 | public static bool operator !=( Position a, Position b ) {
81 | return !a.Equals( b );
82 | }
83 |
84 |
85 | public bool Equals( Position other ) {
86 | return ( X == other.X ) && ( Y == other.Y ) && ( Z == other.Z ) && ( R == other.R ) && ( L == other.L );
87 | }
88 |
89 |
90 | public override bool Equals( object obj ) {
91 | return ( obj is Position ) && Equals( (Position)obj );
92 | }
93 |
94 |
95 | public override int GetHashCode() {
96 | return ( X + Y * short.MaxValue ) ^ ( R + L * short.MaxValue ) + Z;
97 | }
98 |
99 | #endregion
100 |
101 |
102 | public override string ToString() {
103 | return String.Format( "Position({0},{1},{2} @{3},{4})", X, Y, Z, R, L );
104 | }
105 |
106 |
107 | public static explicit operator Vector3I( Position a ) {
108 | return new Vector3I( a.X, a.Y, a.Z );
109 | }
110 |
111 |
112 | public Vector3I ToVector3I() {
113 | return new Vector3I( X, Y, Z );
114 | }
115 |
116 |
117 | public Vector3I ToBlockCoords() {
118 | return new Vector3I( ( X - 16 ) / 32, ( Y - 16 ) / 32, ( Z - 16 ) / 32 );
119 | }
120 | }
121 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/UndoState.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using JetBrains.Annotations;
5 |
6 | namespace fCraft.Drawing {
7 | /// Object used to store
8 | public sealed class UndoState {
9 | /// Creates a new UndoState for the given DrawOperation. can be null.
10 | public UndoState( [CanBeNull] DrawOperation op ) {
11 | Op = op;
12 | }
13 |
14 |
15 | /// Associated DrawOperation. May be null.
16 | [CanBeNull]
17 | public readonly DrawOperation Op;
18 |
19 | /// List of block changes that can be undone.
20 | [NotNull]
21 | public readonly List Buffer = new List();
22 |
23 | /// Whether the operation became too large to undo (in which case Buffer will be empty).
24 | public bool IsTooLargeToUndo;
25 |
26 | /// Object used to synchronize reading/writing of blocks.
27 | /// Necessary in case drawing/undo/redo end up running concurrently.
28 | [NotNull]
29 | public readonly object SyncRoot = new object();
30 |
31 |
32 | /// Records a new block change. Synchronized.
33 | /// True if block change was recorded; otherwise false.
34 | /// Changes will not be recorded if undo is disabled, or if max undo size was exceeded.
35 | public bool Add( Vector3I coord, Block block ) {
36 | lock( SyncRoot ) {
37 | if( BuildingCommands.MaxUndoCount < 1 || Buffer.Count <= BuildingCommands.MaxUndoCount ) {
38 | Buffer.Add( new UndoBlock( coord, block ) );
39 | return true;
40 | } else if( !IsTooLargeToUndo ) {
41 | IsTooLargeToUndo = true;
42 | Buffer.Clear();
43 | Buffer.TrimExcess();
44 | }
45 | return false;
46 | }
47 | }
48 |
49 |
50 | /// Gets block change at the specified index. Synchronized.
51 | public UndoBlock Get( int index ) {
52 | lock( SyncRoot ) {
53 | return Buffer[index];
54 | }
55 | }
56 |
57 |
58 | /// Calculates the bounding box within which all recorded blocks are located.
59 | /// Quite slow, because every recorded block change needs to be checked in order.
60 | [NotNull]
61 | public BoundingBox CalculateBounds() {
62 | lock( SyncRoot ) {
63 | if( Buffer.Count == 0 ) return BoundingBox.Empty;
64 | Vector3I min = new Vector3I( int.MaxValue, int.MaxValue, int.MaxValue );
65 | Vector3I max = new Vector3I( int.MinValue, int.MinValue, int.MinValue );
66 | for( int i = 0; i < Buffer.Count; i++ ) {
67 | if( Buffer[i].X < min.X ) min.X = Buffer[i].X;
68 | if( Buffer[i].Y < min.Y ) min.Y = Buffer[i].Y;
69 | if( Buffer[i].Z < min.Z ) min.Z = Buffer[i].Z;
70 | if( Buffer[i].X > max.X ) max.X = Buffer[i].X;
71 | if( Buffer[i].Y > max.Y ) max.Y = Buffer[i].Y;
72 | if( Buffer[i].Z > max.Z ) max.Z = Buffer[i].Z;
73 | }
74 | return new BoundingBox( min, max );
75 | }
76 | }
77 | }
78 |
79 |
80 | /// Stores state of a block at a particular coordinate, used by UndoState.
81 | [StructLayout( LayoutKind.Sequential, Pack = 2 )]
82 | public struct UndoBlock {
83 | public UndoBlock( Vector3I coord, Block block ) {
84 | X = (short)coord.X;
85 | Y = (short)coord.Y;
86 | Z = (short)coord.Z;
87 | Block = block;
88 | }
89 |
90 | public readonly short X, Y, Z;
91 | public readonly Block Block;
92 | }
93 | }
--------------------------------------------------------------------------------
/fCraft/Utils/FormatUtil.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Globalization;
4 | using System.Text;
5 | using JetBrains.Annotations;
6 |
7 | namespace fCraft {
8 | // Helper methods for working with strings and for serialization/parsing
9 | static unsafe class FormatUtil {
10 | // Quicker StringBuilder.Append(int) by Sam Allen of http://www.dotnetperls.com
11 | [NotNull]
12 | public static StringBuilder Digits( [NotNull] this StringBuilder builder, int number ) {
13 | if( builder == null ) throw new ArgumentNullException( "builder" );
14 | if( number >= 100000000 || number < 0 ) {
15 | // Use system ToString.
16 | builder.Append( number );
17 | return builder;
18 | }
19 | int copy;
20 | int digit;
21 | if( number >= 10000000 ) {
22 | // 8.
23 | copy = number % 100000000;
24 | digit = copy / 10000000;
25 | builder.Append( (char)( digit + 48 ) );
26 | }
27 | if( number >= 1000000 ) {
28 | // 7.
29 | copy = number % 10000000;
30 | digit = copy / 1000000;
31 | builder.Append( (char)( digit + 48 ) );
32 | }
33 | if( number >= 100000 ) {
34 | // 6.
35 | copy = number % 1000000;
36 | digit = copy / 100000;
37 | builder.Append( (char)( digit + 48 ) );
38 | }
39 | if( number >= 10000 ) {
40 | // 5.
41 | copy = number % 100000;
42 | digit = copy / 10000;
43 | builder.Append( (char)( digit + 48 ) );
44 | }
45 | if( number >= 1000 ) {
46 | // 4.
47 | copy = number % 10000;
48 | digit = copy / 1000;
49 | builder.Append( (char)( digit + 48 ) );
50 | }
51 | if( number >= 100 ) {
52 | // 3.
53 | copy = number % 1000;
54 | digit = copy / 100;
55 | builder.Append( (char)( digit + 48 ) );
56 | }
57 | if( number >= 10 ) {
58 | // 2.
59 | copy = number % 100;
60 | digit = copy / 10;
61 | builder.Append( (char)( digit + 48 ) );
62 | }
63 | if( number >= 0 ) {
64 | // 1.
65 | copy = number % 10;
66 | builder.Append( (char)( copy + 48 ) );
67 | }
68 | return builder;
69 | }
70 |
71 |
72 | // Quicker Int32.Parse(string) by Karl Seguin
73 | public static int Parse( [NotNull] string stringToConvert ) {
74 | if( stringToConvert == null ) throw new ArgumentNullException( "stringToConvert" );
75 | int value = 0;
76 | int length = stringToConvert.Length;
77 | fixed( char* characters = stringToConvert ) {
78 | for( int i = 0; i < length; ++i ) {
79 | value = 10 * value + ( characters[i] - 48 );
80 | }
81 | }
82 | return value;
83 | }
84 |
85 |
86 | // UppercaseFirst by Sam Allen of http://www.dotnetperls.com
87 | [NotNull]
88 | public static string UppercaseFirst( this string s ) {
89 | if( string.IsNullOrEmpty( s ) ) {
90 | return string.Empty;
91 | }
92 | char[] a = s.ToCharArray();
93 | a[0] = char.ToUpper( a[0] );
94 | return new string( a );
95 | }
96 |
97 |
98 | [NotNull]
99 | public static string ToStringInvariant( this int i ) {
100 | return i.ToString( CultureInfo.InvariantCulture );
101 | }
102 |
103 |
104 | public static int IndexOfOrdinal( [NotNull] this string haystack, [NotNull] string needle ) {
105 | return haystack.IndexOf( needle, StringComparison.Ordinal );
106 | }
107 | }
108 | }
--------------------------------------------------------------------------------
/ServerGUI/ServerGUI.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {4D4EEAA2-190C-496D-B014-0EB68CA4E535}
9 | WinExe
10 | Properties
11 | fCraft.ServerGUI
12 | ServerGUI
13 | v3.5
14 | 512
15 | fCraft.ServerGUI.Program
16 | f2k.ico
17 | Client
18 |
19 |
20 | 3.5
21 |
22 |
23 |
24 | true
25 | ..\bin\Debug\
26 | DEBUG;TRACE
27 | full
28 | AnyCPU
29 | Auto
30 | prompt
31 |
32 |
33 | ..\bin\Release\
34 | TRACE
35 | true
36 | pdbonly
37 | AnyCPU
38 | Off
39 | prompt
40 |
41 |
42 |
43 |
44 | 3.5
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | Component
54 |
55 |
56 |
57 |
58 | MainForm.cs
59 |
60 |
61 | UpdateWindow.cs
62 |
63 |
64 |
65 | Form
66 |
67 |
68 | MainForm.cs
69 |
70 |
71 | Form
72 |
73 |
74 | UpdateWindow.cs
75 |
76 |
77 |
78 |
79 | {AFAEE6CC-8B4F-40CD-9623-7FFDC8E52222}
80 | fCraftGUI
81 |
82 |
83 | {7FBE7809-6F77-415C-ABEB-A3F627E817B0}
84 | fCraft
85 |
86 |
87 |
88 |
89 |
90 |
91 |
98 |
--------------------------------------------------------------------------------
/fCraft/Utils/LogRecorder.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using System.Collections.Generic;
4 | using fCraft.Events;
5 | using System.Threading;
6 | using JetBrains.Annotations;
7 |
8 | namespace fCraft {
9 | /// A simple way to temporarily hook into fCraft's Logger.
10 | /// Make sure to dispose this class when you are done recording.
11 | /// The easiest way to ensure that is with a using(){...} block.
12 | public sealed class LogRecorder : IDisposable {
13 | readonly object locker = new object();
14 | readonly List messages = new List();
15 | readonly LogType[] thingsToLog;
16 | bool disposed;
17 | readonly Thread creatingThread;
18 |
19 |
20 | /// Creates a recorder for errors and warnings.
21 | public LogRecorder()
22 | : this( true, LogType.Error, LogType.Warning ) {
23 | }
24 |
25 |
26 | /// Creates a custom recorder.
27 | /// Whether this log recorder should limit
28 | /// recording to messages emitted from the same thread that created this object.
29 | /// A list or array of LogTypes to record.
30 | public LogRecorder( bool restrictToThisThread, [NotNull] params LogType[] thingsToLog ) {
31 | if( thingsToLog == null ) throw new ArgumentNullException( "thingsToLog" );
32 | Logger.Logged += HandleLog;
33 | this.thingsToLog = thingsToLog;
34 | if( restrictToThisThread ) {
35 | creatingThread = Thread.CurrentThread;
36 | }
37 | }
38 |
39 |
40 | void HandleLog( object sender, LogEventArgs e ) {
41 | if( creatingThread != null && creatingThread != Thread.CurrentThread ) return;
42 | for( int i = 0; i < thingsToLog.Length; i++ ) {
43 | if( thingsToLog[i] != e.MessageType ) continue;
44 | switch( e.MessageType ) {
45 | case LogType.SeriousError:
46 | case LogType.Error:
47 | HasErrors = true;
48 | break;
49 | case LogType.Warning:
50 | HasWarnings = true;
51 | break;
52 | }
53 | HasMessages = true;
54 | lock( locker ) {
55 | messages.Add( e.MessageType + ": " + e.RawMessage );
56 | }
57 | }
58 | }
59 |
60 |
61 | /// Whether any messages at all have been recorded.
62 | public bool HasMessages { get; private set; }
63 |
64 | /// Whether any errors have been recorded.
65 | public bool HasErrors { get; private set; }
66 |
67 | /// Whether any warnings have been recorded.
68 | public bool HasWarnings { get; private set; }
69 |
70 |
71 | /// An array of individual recorded messages.
72 | public string[] MessageList {
73 | get {
74 | lock( locker ) {
75 | return messages.ToArray();
76 | }
77 | }
78 | }
79 |
80 |
81 | /// All messages in one block of text, separated by newlines.
82 | public string MessageString {
83 | get {
84 | lock( locker ) {
85 | return String.Join( Environment.NewLine, messages.ToArray() );
86 | }
87 | }
88 | }
89 |
90 |
91 | /// Stops recording the messages (cannot be resumed).
92 | /// This method should be called when you are done with the object.
93 | /// If LogRecorder is in a using() block, this will be done for you (recommended).
94 | public void Dispose() {
95 | lock( locker ) {
96 | if( !disposed ) {
97 | Logger.Logged -= HandleLog;
98 | disposed = true;
99 | }
100 | }
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/fCraft/Drawing/DrawOps/CutDrawOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 |
4 | namespace fCraft.Drawing {
5 | /// Draw operation that handles /Cut command.
6 | /// Copies everything into currently-selected copy slot as soon as Begin() is called,
7 | /// then gradually fills the area.
8 | public sealed class CutDrawOperation : DrawOperation {
9 | public override string Name {
10 | get { return "Cut"; }
11 | }
12 |
13 | public override int ExpectedMarks {
14 | get { return 2; }
15 | }
16 |
17 | public override string Description {
18 | get {
19 | var normalBrush = Brush as NormalBrush;
20 | if( normalBrush != null ) {
21 | if( normalBrush.AlternateBlocks > 0 && normalBrush.Blocks[0] == Block.Air ) {
22 | return Name;
23 | } else {
24 | return String.Format( "{0}/{1}", Name, normalBrush.Blocks[0] );
25 | }
26 | } else {
27 | return base.Description;
28 | }
29 | }
30 | }
31 |
32 |
33 | public CutDrawOperation( Player player )
34 | : base( player ) {
35 | }
36 |
37 |
38 | public override bool Prepare( Vector3I[] marks ) {
39 | if( Player.World == null ) PlayerOpException.ThrowNoWorld( Player );
40 | if( !base.Prepare( marks ) ) return false;
41 |
42 | BlocksTotalEstimate = Bounds.Volume;
43 | Coords = Bounds.MinVertex;
44 |
45 | Context |= BlockChangeContext.Cut;
46 | return true;
47 | }
48 |
49 |
50 | public override bool Begin() {
51 | // remember dimensions and orientation
52 | CopyState copyInfo = new CopyState( Marks[0], Marks[1] );
53 |
54 | for( int x = Bounds.XMin; x <= Bounds.XMax; x++ ) {
55 | for( int y = Bounds.YMin; y <= Bounds.YMax; y++ ) {
56 | for( int z = Bounds.ZMin; z <= Bounds.ZMax; z++ ) {
57 | copyInfo.Blocks[x - Bounds.XMin, y - Bounds.YMin, z - Bounds.ZMin] = Map.GetBlock( x, y, z );
58 | }
59 | }
60 | }
61 | // ReSharper disable PossibleNullReferenceException
62 | copyInfo.OriginWorld = Player.World.Name;
63 | // ReSharper restore PossibleNullReferenceException
64 | copyInfo.CopyTime = DateTime.UtcNow;
65 | Player.SetCopyState( copyInfo );
66 |
67 | Player.Message( "{0} blocks cut into slot #{1}. You can now &H/Paste",
68 | Bounds.Volume, Player.CopySlot + 1 );
69 | Player.Message( "Origin at {0} {1}{2} corner.",
70 | ( copyInfo.Orientation.Z == 1 ? "bottom" : "top" ),
71 | ( copyInfo.Orientation.Y == 1 ? "south" : "north" ),
72 | ( copyInfo.Orientation.X == 1 ? "east" : "west" ) );
73 |
74 | return base.Begin();
75 | }
76 |
77 |
78 | // lifted straight from CuboidDrawOp
79 | public override int DrawBatch( int maxBlocksToDraw ) {
80 | int blocksDone = 0;
81 | for( ; Coords.X <= Bounds.XMax; Coords.X++ ) {
82 | for( ; Coords.Y <= Bounds.YMax; Coords.Y++ ) {
83 | for( ; Coords.Z <= Bounds.ZMax; Coords.Z++ ) {
84 | if( DrawOneBlock() ) {
85 | blocksDone++;
86 | if( blocksDone >= maxBlocksToDraw ) {
87 | Coords.Z++;
88 | return blocksDone;
89 | }
90 | }
91 | }
92 | Coords.Z = Bounds.ZMin;
93 | }
94 | Coords.Y = Bounds.YMin;
95 | if( TimeToEndBatch ) {
96 | Coords.X++;
97 | return blocksDone;
98 | }
99 | }
100 | IsDone = true;
101 | return blocksDone;
102 | }
103 | }
104 | }
--------------------------------------------------------------------------------
/ConfigGUI/ColorPicker.cs:
--------------------------------------------------------------------------------
1 | // Part of fCraft | Copyright (c) 2009-2014 Matvei Stefarov | BSD-3 | See LICENSE.txt
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | namespace fCraft.ConfigGUI {
6 | internal sealed partial class ColorPicker : Form {
7 | public static readonly Dictionary ColorPairs = new Dictionary();
8 | public int ColorIndex;
9 |
10 |
11 | static ColorPicker() {
12 | ColorPairs.Add( 0, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.Black ) );
13 | ColorPairs.Add( 8, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.DimGray ) );
14 | ColorPairs.Add( 1, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.Navy ) );
15 | ColorPairs.Add( 9, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.RoyalBlue ) );
16 | ColorPairs.Add( 2, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.Green ) );
17 | ColorPairs.Add( 10, new ColorPair( System.Drawing.Color.Black, System.Drawing.Color.Lime ) );
18 | ColorPairs.Add( 3, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.Teal ) );
19 | ColorPairs.Add( 11, new ColorPair( System.Drawing.Color.Black, System.Drawing.Color.Aqua ) );
20 | ColorPairs.Add( 4, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.Maroon ) );
21 | ColorPairs.Add( 12, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.Red ) );
22 | ColorPairs.Add( 5, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.Purple ) );
23 | ColorPairs.Add( 13, new ColorPair( System.Drawing.Color.Black, System.Drawing.Color.Magenta ) );
24 | ColorPairs.Add( 6, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.Olive ) );
25 | ColorPairs.Add( 14, new ColorPair( System.Drawing.Color.Black, System.Drawing.Color.Yellow ) );
26 | ColorPairs.Add( 7, new ColorPair( System.Drawing.Color.Black, System.Drawing.Color.Silver ) );
27 | ColorPairs.Add( 15, new ColorPair( System.Drawing.Color.Black, System.Drawing.Color.White ) );
28 | }
29 |
30 |
31 | public ColorPicker( string title, int oldColorIndex ) {
32 | InitializeComponent();
33 | Text = title;
34 | ColorIndex = oldColorIndex;
35 | StartPosition = FormStartPosition.CenterParent;
36 |
37 | b0.Click += delegate { ColorIndex = 0; DialogResult = DialogResult.OK; Close(); };
38 | b1.Click += delegate { ColorIndex = 1; DialogResult = DialogResult.OK; Close(); };
39 | b2.Click += delegate { ColorIndex = 2; DialogResult = DialogResult.OK; Close(); };
40 | b3.Click += delegate { ColorIndex = 3; DialogResult = DialogResult.OK; Close(); };
41 | b4.Click += delegate { ColorIndex = 4; DialogResult = DialogResult.OK; Close(); };
42 | b5.Click += delegate { ColorIndex = 5; DialogResult = DialogResult.OK; Close(); };
43 | b6.Click += delegate { ColorIndex = 6; DialogResult = DialogResult.OK; Close(); };
44 | b7.Click += delegate { ColorIndex = 7; DialogResult = DialogResult.OK; Close(); };
45 | b8.Click += delegate { ColorIndex = 8; DialogResult = DialogResult.OK; Close(); };
46 | b9.Click += delegate { ColorIndex = 9; DialogResult = DialogResult.OK; Close(); };
47 | ba.Click += delegate { ColorIndex = 10; DialogResult = DialogResult.OK; Close(); };
48 | bb.Click += delegate { ColorIndex = 11; DialogResult = DialogResult.OK; Close(); };
49 | bc.Click += delegate { ColorIndex = 12; DialogResult = DialogResult.OK; Close(); };
50 | bd.Click += delegate { ColorIndex = 13; DialogResult = DialogResult.OK; Close(); };
51 | be.Click += delegate { ColorIndex = 14; DialogResult = DialogResult.OK; Close(); };
52 | bf.Click += delegate { ColorIndex = 15; DialogResult = DialogResult.OK; Close(); };
53 | }
54 |
55 |
56 | internal struct ColorPair {
57 | public ColorPair( System.Drawing.Color foreground, System.Drawing.Color background ) {
58 | Foreground = foreground;
59 | Background = background;
60 | }
61 | public System.Drawing.Color Foreground;
62 | public System.Drawing.Color Background;
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/fCraft/Drawing/CopyState.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2014 Matvei Stefarov
2 | using System;
3 | using JetBrains.Annotations;
4 |
5 | namespace fCraft.Drawing {
6 | /// Represents a set of copied blocks, including metadata.
7 | /// Created by /Copy and /Cut commands.
8 | public sealed class CopyState : ICloneable {
9 | /// Creates a new CopyState between the two given marks.
10 | /// First mark is the origin. Bounds and Orientation are set accordingly.
11 | /// Also allocates Blocks array and sets CopyTime to UtcNow.
12 | public CopyState( Vector3I mark1, Vector3I mark2 ) {
13 | Bounds = new BoundingBox( mark1, mark2 );
14 | Orientation = new Vector3I( mark1.X <= mark2.X ? 1 : -1,
15 | mark1.Y <= mark2.Y ? 1 : -1,
16 | mark1.Z <= mark2.Z ? 1 : -1 );
17 | Blocks = new Block[Bounds.Width, Bounds.Length, Bounds.Height];
18 | CopyTime = DateTime.UtcNow;
19 | }
20 |
21 |
22 | /// Duplicates the given CopyState.
23 | /// Note that this is a deep copy -- Blocks array and everything else is duplicated too.
24 | public CopyState( [NotNull] CopyState original ) {
25 | if( original == null ) throw new ArgumentNullException();
26 | Blocks = (Block[, ,])original.Blocks.Clone();
27 | Bounds = new BoundingBox( original.Bounds );
28 | Orientation = original.Orientation;
29 | Slot = original.Slot;
30 | OriginWorld = original.OriginWorld;
31 | CopyTime = original.CopyTime;
32 | }
33 |
34 |
35 |
36 | /// Duplicates the given CopyState, but does not copy the Blocks array.
37 | /// Updates Bounds to match the new buffer's size, but preserves original Orientation.
38 | public CopyState( [NotNull] CopyState original, [NotNull] Block[, ,] buffer ) {
39 | if( original == null ) throw new ArgumentNullException();
40 | Blocks = buffer;
41 | Bounds = new BoundingBox( original.Bounds.MinVertex,
42 | buffer.GetLength( 0 ),
43 | buffer.GetLength( 1 ),
44 | buffer.GetLength( 2 ) );
45 | Orientation = original.Orientation;
46 | Slot = original.Slot;
47 | OriginWorld = original.OriginWorld;
48 | CopyTime = original.CopyTime;
49 | }
50 |
51 |
52 | /// 3D array of copies blocks.
53 | public Block[, ,] Blocks { get; private set; }
54 |
55 |
56 | /// Dimensions and coordinates of the copied blocks.
57 | public BoundingBox Bounds { get; private set; }
58 |
59 |
60 | /// Orientation of copying (relation of two marks to each other).
61 | /// Each value is either 1 (forwards along the axis) or -1 (backwards along the axis).
62 | /// Orientation is used by /Paste and /PasteNot commands to determine the direction of pasting from the clicked block.
63 | public Vector3I Orientation { get; private set; }
64 |
65 |
66 | /// Index of the copyslot into which this was copied.
67 | /// Defaults to 0.
68 | public int Slot { get; set; }
69 |
70 |
71 | /// Name of the world where this was copied from.
72 | /// Defaults to null.
73 | [CanBeNull]
74 | public string OriginWorld { get; set; }
75 |
76 |
77 | /// Time (UTC) at which the blocks were copied.
78 | /// Defaults to DateTime.UtcNow.
79 | public DateTime CopyTime { get; set; }
80 |
81 |
82 | /// Description of the corner at which copying started (e.g. "bottom southeast")
83 | public string OriginCorner {
84 | get {
85 | return String.Format( "{0} {1}{2}",
86 | (Orientation.Z == 1 ? "bottom" : "top"),
87 | (Orientation.Y == 1 ? "south" : "north"),
88 | (Orientation.X == 1 ? "east" : "west") );
89 | }
90 | }
91 |
92 |
93 | public object Clone() {
94 | return new CopyState( this );
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------