Post your custom code here
Posted: August 21st, 2011, 6:58 am
---
Official fCraft server software forums
https://forum.fcraft.net/
Code: Select all
var values = Tuple.Create(DL, player);
Code: Select all
using System;
using System.Collections.Generic;
using fCraft.Events;
namespace fCraft
{
public static class Doors
{
static readonly TimeSpan DoorCloseTimer = TimeSpan.FromMilliseconds(1500); // time that door will stay open
public static Dictionary<string, string[]> DoorLookUp = new Dictionary<string, string[]>();
// DoorLookUp to store currently open doors
public static void Init()
{
CommandManager.RegisterCommand(cdDoor);
CommandManager.RegisterCommand(cdDoorRemove);
Server.PlayerClicked += PlayerClickedDoor;
}
static readonly CommandDescriptor cdDoorRemove = new CommandDescriptor
{
Name = "removedoor",
Aliases = new[] { "rd" },
Category = CommandCategory.Zone,
Permissions = new[] { Permission.Chat },
Help = "Removes door.",
Handler = DoorRemove
};
static void DoorRemove(Player player, Command cmd)
{
if (player.World.Map.Zones.Find(player.Info.Name + "door") != null)
{
player.World.Map.Zones.Remove(player.Info.Name + "door");
DoorLookUp.Remove(player.Info.Name + "door");
player.Message("Door removed.");
}
}
static readonly CommandDescriptor cdDoor = new CommandDescriptor
{
Name = "door",
Category = CommandCategory.Zone,
Permissions = new[] { Permission.Chat },
Help = "Creates door zone. Left click to open doors.",
Handler = Door
};
static void Door(Player player, Command cmd)
{
if (player.World.Map.Zones.Find(player.Info.Name + "door") != null)
{
player.Message("One door per person.");
return;
}
Zone door = new Zone();
door.Name = player.Info.Name + "door";
player.SelectionStart(2, DoorAdd, door, cdDoor.Permissions);
player.Message("Door: Place a block or type /mark to use your location.");
}
static void DoorAdd(Player player, Position[] marks, object tag)
{
int maxBlocks = 12; //max door size, change as needed... should add config key
int sx = Math.Min(marks[0].X, marks[1].X);
int ex = Math.Max(marks[0].X, marks[1].X);
int sy = Math.Min(marks[0].Y, marks[1].Y);
int ey = Math.Max(marks[0].Y, marks[1].Y);
int sh = Math.Min(marks[0].Z, marks[1].Z);
int eh = Math.Max(marks[0].Z, marks[1].Z);
int volume = (ex - sx + 1) * (ey - sy + 1) * (eh - sh + 1);
if (volume > maxBlocks)
{
player.Message("Doors are only allowed to be {0} blocks", maxBlocks);
return;
}
ZoneCommands.ZoneAddCallback(player, marks, tag);
player.Message("Door successfully created");
Logger.Log("{0} created door {1} (on world {2})", LogType.UserActivity, player.Name, player.Name + "door", player.World.Name);
}
static void DoorTimer_Elapsed(SchedulerTask task)
{
string door = (string)task.UserState;
string[] doorVars = DoorLookUp[door];
string x, y, z, b;
Player player = Server.FindPlayerExact(doorVars[4]);
//parse values from DoorLookUp
x = doorVars[0].TrimEnd(' '); y = doorVars[1].TrimEnd(' '); z = doorVars[2].TrimEnd(' '); b = doorVars[3].TrimEnd(' ');
string[] xs = x.Split(' '), ys = y.Split(' '), zs = z.Split(' '), bs = b.Split(' ');
int i = 0;
foreach (string arg in xs)
{
player.World.Map.QueueUpdate(new BlockUpdate(null, Int32.Parse(xs[i]), Int32.Parse(ys[i]), Int32.Parse(zs[i]), Byte.Parse(bs[i])));
i++;
}
}
public static void PlayerClickedDoor(object sender, PlayerClickedEventArgs e)
{
Zone[] allowed, denied;
if (e.Player.World.Map.Zones.CheckDetailed(e.X, e.Y, e.Z, e.Player, out allowed, out denied))
{
foreach (Zone zone in allowed)
{
if (zone.Name.Contains("door"))
{
CutDoor(zone, e.Player);
}
}
}
}
public static void CutDoor(Zone zone, Player player)
{
int sx = zone.Bounds.XMin;
int ex = zone.Bounds.XMax;
int sy = zone.Bounds.YMin;
int ey = zone.Bounds.YMax;
int sh = zone.Bounds.ZMin;
int eh = zone.Bounds.ZMax;
string[] DL = new string[5];
DL[0] = ""; DL[1] = ""; DL[2] = ""; DL[3] = ""; DL[4] = player.Name;
//for each block in selection, add x, y, z coords and block type to string array
for (int i = sx; i <= ex; i++)
{
for (int j = sy; j <= ey; j++)
{
for (int k = sh; k <= eh; k++)
{
DL[0] += i.ToString() + " "; //x
DL[1] += j.ToString() + " "; //y
DL[2] += k.ToString() + " "; //z
DL[3] += player.World.Map.GetBlockByte(i, j, k) + " "; //block
//clear the door
player.World.Map.QueueUpdate(new BlockUpdate(null, i, j, k, Block.Air));
}
}
}
Logger.Log("{0} opened door {1} (on world {2})", LogType.UserActivity, player.Name, zone.Name, player.World.Name);
if (!DoorLookUp.ContainsKey(zone.Name))
{
DoorLookUp.Add(zone.Name, DL);
}
else
{
DoorLookUp[zone.Name] = DL;
}
Scheduler.NewTask(DoorTimer_Elapsed).RunOnce(zone.Name, DoorCloseTimer); //timer to re-close door
}
}
}
There is a command for that its /hideJonty800 wrote:Hey, I thought it would be nice to share our custom code with each other (if people want to lol)
I have a few bits that I'm willing to share, although I wouldn't consider them to be amazing. But I was mainly trying to concentrate on the functionality and atmosphere of the server.
Chat commands
/away
Code: Select all
static readonly CommandDescriptor cdAway = new CommandDescriptor { Name = "away", Category = CommandCategory.Chat, IsConsoleSafe = true, Usage = "/away [optional message]", Help = "Request an Op to review your build.", Handler = Away }; internal static void Away(Player player, Command cmd) { if (player.Info.IsMuted) { player.MessageMuted(); return; } if (player.Can(Permission.Chat)) { string msg = cmd.NextAll().Trim(); if (msg.Length > 0) { Server.Players.Message("&S{0} &cis Away &9({1})", player.ClassyName, msg); } else { Server.Players.Message("&S{0} &cis Away &9(Away From Keyboard)", player.ClassyName); } } }
Code: Select all
static void BlockDBHandler( Player player, Command cmd ) {
string worldName = cmd.Next();
if( worldName == null ) {
World[] trackedWorlds = WorldManager.WorldList.Where( w => w.BlockDB.Enabled ).ToArray();
if( trackedWorlds.Length > 0 ) {
player.Message( "BlockDB is enabled on: {0}",
trackedWorlds.JoinToClassyString() );
Code: Select all
if( !BlockDB.IsEnabled ) {
player.Message( "&WBlockDB is disabled on this server." );
return;
}
dont work for my have you teamviewer?Jonty800 wrote:Try getting the HEAD revision, then move ipbans.txt, playerdb.txt, config.xml and worlds.xml and folder 'maps' from your server backup (old server) into the new folder where you put the head revision. Then open and check configGUI.
If you have a config.xml problem:
If you delete your config.xml, then run ConfigGUI and click "OK" without changing anything, you will get the very same default config.xml
Code: Select all
static readonly CommandDescriptor CdGuestwipe = new CommandDescriptor
{
Name = "guestwipe",
Category = CommandCategory.World,
Permissions = new[] { Permission.Guestwipe },
IsConsoleSafe = true,
Usage = "/guestwipe",
Help = "Wipes a map with the name 'Guest'.",
Handler = Guestwipe
};
internal static void Guestwipe(Player player, Command cmd)
{
string guestwipe = cmd.Next();
if (guestwipe == null)
{
Scheduler.NewTask(t => Server.Players.Message("&9Warning! The Guest world will be wiped in 30 seconds.")).RunOnce(TimeSpan.FromSeconds(1));
Scheduler.NewTask(t => Server.Players.Message("&9Warning! The Guest world will be wiped in 15 seconds.")).RunOnce(TimeSpan.FromSeconds(16));
Scheduler.NewTask(t => player.Message("&4Prepare to use /ok when notified.")).RunOnce(TimeSpan.FromSeconds(25));
Scheduler.NewTask(t => WorldLoadHandler(player, new Command("/wload2 guestwipe guest"))).RunOnce(TimeSpan.FromSeconds(30));
}
}
Code: Select all
#region wload2
static readonly CommandDescriptor CdWorldLoad2 = new CommandDescriptor
{
Name = "wload2",
Aliases = new[] { "wadd2" },
Category = CommandCategory.World,
IsConsoleSafe = true,
IsHidden = true,
Permissions = new[] { Permission.ThemedRealms },
Usage = "/wload FileName [WorldName]",
Help = "Using this command could get you banned",
Handler = WorldLoad2
};
internal static void WorldLoad2(Player player, Command cmd)
{
string fileName = cmd.Next();
string worldName = cmd.Next();
if (worldName == null && player.World == null)
{
player.Message("When using /wload from console, you must specify the world name.");
return;
}
if (fileName == null)
{
// No params given at all
CdWorldLoad.PrintUsage(player);
return;
}
string fullFileName = WorldManager.FindMapFile(player, fileName);
if (fullFileName == null) return;
// Loading map into current world
if (worldName == null)
{
if (!cmd.IsConfirmed)
{
player.Confirm(cmd, "About to replace THIS MAP with \"{0}\".", fileName);
return;
}
Map map;
try
{
map = MapUtility.Load(fullFileName);
}
catch (Exception ex)
{
player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
return;
}
// Loading to current world
player.World.ChangeMap(map);
player.World.Players.Message(player, "{0}&S loaded a new map for this world.",
player.ClassyName);
player.MessageNow("New map loaded for the world {0}", player.World.ClassyName);
Logger.Log("{0} loaded new map for world \"{1}\" from {2}", LogType.UserActivity,
player.Name, player.World.Name, fileName);
}
else
{
// Loading to some other (or new) world
if (!World.IsValidName(worldName))
{
player.MessageNow("Invalid world name: \"{0}\".", worldName);
return;
}
lock (WorldManager.WorldListLock)
{
World world = WorldManager.FindWorldExact(worldName);
if (world != null)
{
// Replacing existing world's map
if (!cmd.IsConfirmed)
{
player.Confirm(cmd, "About to replace map for {0}&S with \"{1}\".",
world.ClassyName, fileName);
return;
}
Map map;
try
{
map = MapUtility.Load(fullFileName);
}
catch (Exception ex)
{
player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
return;
}
try
{
world.ChangeMap(map);
}
catch (WorldOpException ex)
{
Logger.Log("Could not complete WorldLoad operation: {0}", LogType.Error, ex.Message);
player.Message("&WWLoad: {0}", ex.Message);
return;
}
world.Players.Message(player, "{0}&S loaded a new map for the world {1}",
player.ClassyName, world.ClassyName);
player.MessageNow("New map for the world {0}&S has been loaded.", world.ClassyName);
Logger.Log("{0} loaded new map for world \"{1}\" from {2}", LogType.UserActivity,
player.Name, world.Name, fullFileName);
}
else
{
// Adding a new world
string targetFullFileName = Path.Combine(Paths.MapPath, worldName + ".fcm");
if (!cmd.IsConfirmed &&
File.Exists(targetFullFileName) && // target file already exists
!Paths.Compare(targetFullFileName, fullFileName))
{ // and is different from sourceFile
player.Confirm(cmd, "A map named \"{0}\" already exists, and will be overwritten with \"{1}\".",
Path.GetFileName(targetFullFileName), Path.GetFileName(fullFileName));
return;
}
try
{
MapUtility.Load(fullFileName);
}
catch (Exception ex)
{
player.MessageNow("Could not load \"{0}\": {1}: {2}",
fileName, ex.GetType().Name, ex.Message);
return;
}
World newWorld;
try
{
newWorld = WorldManager.AddWorld(player, worldName, null, false);
}
catch (WorldOpException ex)
{
player.Message("WLoad: {0}", ex.Message);
return;
}
if (newWorld != null)
{
newWorld.BuildSecurity.MinRank = Rank.Parse(ConfigKey.DefaultBuildRank.GetString());
Server.Message("{0}&S created a new world named {1}",
player.ClassyName, newWorld.ClassyName);
Logger.Log("{0} created a new world named \"{1}\" (loaded from \"{2}\")", LogType.UserActivity,
player.Name, worldName, fileName);
WorldManager.SaveWorldList();
player.MessageNow("Reminder: New world's access permission is {0}+&S, and build permission is {1}+",
newWorld.AccessSecurity.MinRank.ClassyName,
newWorld.BuildSecurity.MinRank.ClassyName);
}
else
{
player.MessageNow("Failed to create a new world.");
}
}
}
}
Server.RequestGC();
}
#endregion
Code: Select all
/// <summary> Ability to wipe the guest world </summary>
Guestwipe,
TVStar wrote:dont work for my have you teamviewer?Jonty800 wrote:Try getting the HEAD revision, then move ipbans.txt, playerdb.txt, config.xml and worlds.xml and folder 'maps' from your server backup (old server) into the new folder where you put the head revision. Then open and check configGUI.
If you have a config.xml problem:
If you delete your config.xml, then run ConfigGUI and click "OK" without changing anything, you will get the very same default config.xml