Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
e11ce99dd8
@ -11,7 +11,7 @@ namespace TrueCraft.API.Server
|
|||||||
string Name { get; }
|
string Name { get; }
|
||||||
string Description { get; }
|
string Description { get; }
|
||||||
string[] Aliases { get; }
|
string[] Aliases { get; }
|
||||||
void Handle(IRemoteClient Client, string Alias, string[] Arguments);
|
void Handle(IRemoteClient client, string alias, string[] arguments);
|
||||||
void Help(IRemoteClient Client, string Alias, string[] Arguments);
|
void Help(IRemoteClient client, string alias, string[] arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -73,5 +73,10 @@ namespace TrueCraft.Core.Logic.Blocks
|
|||||||
{
|
{
|
||||||
return new Tuple<int, int>(3, 4);
|
return new Tuple<int, int>(3, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override ItemStack[] GetDrop(BlockDescriptor descriptor)
|
||||||
|
{
|
||||||
|
return new[] { new ItemStack(SnowballItem.ItemID) };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -45,7 +45,7 @@ namespace TrueCraft.Core.World
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// TODO
|
BaseTime = DateTime.Now.AddSeconds(-value/20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ namespace TrueCraft.Commands
|
|||||||
|
|
||||||
public virtual string[] Aliases { get { return new string[0]; } }
|
public virtual string[] Aliases { get { return new string[0]; } }
|
||||||
|
|
||||||
public virtual void Handle(IRemoteClient Client, string Alias, string[] Arguments) { Help(Client, Alias, Arguments); }
|
public virtual void Handle(IRemoteClient Client, string alias, string[] arguments) { Help(Client, alias, arguments); }
|
||||||
|
|
||||||
public virtual void Help(IRemoteClient Client, string Alias, string[] Arguments) { Client.SendMessage("Command \"" + Alias + "\" is not functional!"); }
|
public virtual void Help(IRemoteClient client, string alias, string[] arguments) { client.SendMessage("Command \"" + alias + "\" is not functional!"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ namespace TrueCraft.Commands
|
|||||||
{
|
{
|
||||||
Commands.Add(new PingCommand());
|
Commands.Add(new PingCommand());
|
||||||
Commands.Add(new GiveCommand());
|
Commands.Add(new GiveCommand());
|
||||||
|
Commands.Add(new GiveMeCommand());
|
||||||
Commands.Add(new HelpCommand());
|
Commands.Add(new HelpCommand());
|
||||||
Commands.Add(new ResendInvCommand());
|
Commands.Add(new ResendInvCommand());
|
||||||
Commands.Add(new PositionCommand());
|
Commands.Add(new PositionCommand());
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
using TrueCraft.API.Networking;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using TrueCraft.Core.Windows;
|
|
||||||
using TrueCraft.API;
|
|
||||||
using TrueCraft.API.Networking;
|
|
||||||
using TrueCraft.Core.Networking.Packets;
|
using TrueCraft.Core.Networking.Packets;
|
||||||
|
|
||||||
namespace TrueCraft.Commands
|
namespace TrueCraft.Commands
|
||||||
@ -26,19 +20,19 @@ namespace TrueCraft.Commands
|
|||||||
get { return new string[0]; }
|
get { return new string[0]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Handle(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
if (Arguments.Length != 0)
|
if (arguments.Length != 0)
|
||||||
{
|
{
|
||||||
Help(Client, Alias, Arguments);
|
Help(client, alias, arguments);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Client.SendMessage(Client.Entity.Position.ToString());
|
client.SendMessage(client.Entity.Position.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Help(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
Client.SendMessage("/pos: Shows your position.");
|
client.SendMessage("/pos: Shows your position.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,52 +53,19 @@ namespace TrueCraft.Commands
|
|||||||
get { return new string[0]; }
|
get { return new string[0]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Handle(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
if (Arguments.Length != 0)
|
if (arguments.Length != 0)
|
||||||
{
|
{
|
||||||
Help(Client, Alias, Arguments);
|
Help(client, alias, arguments);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Client.EnableLogging = !Client.EnableLogging;
|
client.EnableLogging = !client.EnableLogging;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Help(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
Client.SendMessage("/pos: Toggles client logging.");
|
client.SendMessage("/pos: Toggles client logging.");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TimeCommand : Command
|
|
||||||
{
|
|
||||||
public override string Name
|
|
||||||
{
|
|
||||||
get { return "time"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string Description
|
|
||||||
{
|
|
||||||
get { return "Shows the current time."; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string[] Aliases
|
|
||||||
{
|
|
||||||
get { return new string[0]; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Handle(IRemoteClient Client, string Alias, string[] Arguments)
|
|
||||||
{
|
|
||||||
if (Arguments.Length != 0)
|
|
||||||
{
|
|
||||||
Help(Client, Alias, Arguments);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Client.SendMessage(Client.World.Time.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Help(IRemoteClient Client, string Alias, string[] Arguments)
|
|
||||||
{
|
|
||||||
Client.SendMessage("/time: Shows the current time.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,19 +86,19 @@ namespace TrueCraft.Commands
|
|||||||
get { return new string[0]; }
|
get { return new string[0]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Handle(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
if (Arguments.Length != 1)
|
if (arguments.Length != 0)
|
||||||
{
|
{
|
||||||
Help(Client, Alias, Arguments);
|
Help(client, alias, arguments);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Client.QueuePacket(new WindowItemsPacket(0, Client.Inventory.GetSlots()));
|
client.QueuePacket(new WindowItemsPacket(0, client.Inventory.GetSlots()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Help(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
Client.SendMessage("/reinv: Resends your inventory.");
|
client.SendMessage("/reinv: Resends your inventory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using TrueCraft.Core.Windows;
|
using TrueCraft.Core.Windows;
|
||||||
using TrueCraft.API;
|
using TrueCraft.API;
|
||||||
using TrueCraft.API.Networking;
|
using TrueCraft.API.Networking;
|
||||||
@ -25,39 +23,79 @@ namespace TrueCraft.Commands
|
|||||||
get { return new string[1]{ "i" }; }
|
get { return new string[1]{ "i" }; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Handle(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
if (Arguments.Length != 4)
|
if (arguments.Length < 2)
|
||||||
{
|
{
|
||||||
Help(Client, Alias, Arguments);
|
Help(client, alias, arguments);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var receiver = Client.Server.Clients.SingleOrDefault(c => c.Username == Arguments[1]);
|
string username = arguments[0],
|
||||||
|
itemid = arguments[1],
|
||||||
|
amount = "1";
|
||||||
|
|
||||||
|
if(arguments.Length >= 3)
|
||||||
|
amount = arguments[2];
|
||||||
|
|
||||||
|
var receivingPlayer = GetPlayerByName(client, username);
|
||||||
|
|
||||||
|
if (receivingPlayer == null)
|
||||||
|
{
|
||||||
|
client.SendMessage("No client with the username \"" + username + "\" was found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GiveItem(receivingPlayer, itemid, amount, client))
|
||||||
|
{
|
||||||
|
Help(client, alias, arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static IRemoteClient GetPlayerByName(IRemoteClient client, string username)
|
||||||
|
{
|
||||||
|
var receivingPlayer =
|
||||||
|
client.Server.Clients.FirstOrDefault(
|
||||||
|
c => String.Equals(c.Username, username, StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
return receivingPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static bool GiveItem(IRemoteClient receivingPlayer, string itemid, string amount, IRemoteClient client)
|
||||||
|
{
|
||||||
short id;
|
short id;
|
||||||
sbyte count;
|
int count;
|
||||||
if (short.TryParse(Arguments[2], out id) && sbyte.TryParse(Arguments[3], out count))
|
|
||||||
|
if (!short.TryParse(itemid, out id) || !Int32.TryParse(amount, out count)) return false;
|
||||||
|
|
||||||
|
if (client.Server.ItemRepository.GetItemProvider(id) == null)
|
||||||
{
|
{
|
||||||
if (receiver == null)
|
client.SendMessage("Invalid item id \"" + id + "\".");
|
||||||
{
|
return true;
|
||||||
Client.SendMessage("No client with the username \"" + Arguments[1] + "\" was found.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Client.Server.ItemRepository.GetItemProvider(id) == null)
|
string username = receivingPlayer.Username;
|
||||||
|
var inventory = receivingPlayer.Inventory as InventoryWindow;
|
||||||
|
if (inventory == null) return false;
|
||||||
|
|
||||||
|
while (count > 0)
|
||||||
{
|
{
|
||||||
Client.SendMessage("Invalid item id \"" + id + "\".");
|
sbyte amountToGive;
|
||||||
return;
|
if (count >= 64)
|
||||||
|
amountToGive = 64;
|
||||||
|
else
|
||||||
|
amountToGive = (sbyte) count;
|
||||||
|
|
||||||
|
count -= amountToGive;
|
||||||
|
|
||||||
|
inventory.PickUpStack(new ItemStack(id, amountToGive));
|
||||||
}
|
}
|
||||||
|
|
||||||
var inventory = receiver.Inventory as InventoryWindow;
|
return true;
|
||||||
inventory.PickUpStack(new ItemStack(id, count));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Help(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
Client.SendMessage("Correct usage is /" + Alias + " <User> <Item ID> <Amount>");
|
client.SendMessage("Correct usage is /" + alias + " <User> <Item ID> [Amount]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
TrueCraft/Commands/GiveMeCommand.cs
Normal file
49
TrueCraft/Commands/GiveMeCommand.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using TrueCraft.API.Networking;
|
||||||
|
|
||||||
|
namespace TrueCraft.Commands
|
||||||
|
{
|
||||||
|
public class GiveMeCommand : GiveCommand
|
||||||
|
{
|
||||||
|
public override string Name
|
||||||
|
{
|
||||||
|
get { return "giveme"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] Aliases
|
||||||
|
{
|
||||||
|
get { return new string[0]; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Description
|
||||||
|
{
|
||||||
|
get { return "Give yourself an amount of items."; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Handle(IRemoteClient client, string alias, string[] arguments)
|
||||||
|
{
|
||||||
|
if (arguments.Length < 1)
|
||||||
|
{
|
||||||
|
Help(client, alias, arguments);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string itemid = arguments[0],
|
||||||
|
amount = "1";
|
||||||
|
|
||||||
|
if (arguments.Length >= 2)
|
||||||
|
amount = arguments[1];
|
||||||
|
|
||||||
|
var receivingPlayer = client;
|
||||||
|
|
||||||
|
if (!GiveItem(receivingPlayer, itemid, amount, client))
|
||||||
|
{
|
||||||
|
Help(client, alias, arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Help(IRemoteClient client, string alias, string[] arguments)
|
||||||
|
{
|
||||||
|
client.SendMessage("Correct usage is /" + alias + " <Item ID> [Amount]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using TrueCraft.API.Networking;
|
using TrueCraft.API.Networking;
|
||||||
using TrueCraft.API.Server;
|
using TrueCraft.API.Server;
|
||||||
|
|
||||||
@ -19,63 +16,64 @@ namespace TrueCraft.Commands
|
|||||||
get { return "Command help menu."; }
|
get { return "Command help menu."; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Handle(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
if (Arguments.Length < 1)
|
if (arguments.Length < 1)
|
||||||
{
|
{
|
||||||
Help(Client, Alias, Arguments);
|
Help(client, alias, arguments);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Identifier = Arguments[0];
|
var identifier = arguments.Length >= 1 ? arguments[0] : "0";
|
||||||
ICommand Found = null;
|
|
||||||
if ((Found = Program.CommandManager.FindByName(Identifier)) != null)
|
ICommand found;
|
||||||
|
if ((found = Program.CommandManager.FindByName(identifier)) != null)
|
||||||
{
|
{
|
||||||
Found.Handle(Client, Identifier, new string[0]);
|
found.Handle(client, identifier, new string[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ((Found = Program.CommandManager.FindByAlias(Identifier)) != null)
|
else if ((found = Program.CommandManager.FindByAlias(identifier)) != null)
|
||||||
{
|
{
|
||||||
Found.Help(Client, Identifier, new string[0]);
|
found.Help(client, identifier, new string[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PageNumber = 0;
|
int pageNumber;
|
||||||
if (int.TryParse(Identifier, out PageNumber))
|
if (int.TryParse(identifier, out pageNumber))
|
||||||
{
|
{
|
||||||
HelpPage(Client, PageNumber);
|
HelpPage(client, pageNumber);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Help(Client, Alias, Arguments);
|
Help(client, alias, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HelpPage(IRemoteClient Client, int Page)
|
public void HelpPage(IRemoteClient client, int page)
|
||||||
{
|
{
|
||||||
int PerPage = 5;
|
const int perPage = 5;
|
||||||
int Pages = (int)Math.Floor((double)(Program.CommandManager.Commands.Count / PerPage));
|
int numPages = (int)Math.Floor(((double)Program.CommandManager.Commands.Count / perPage));
|
||||||
if ((Program.CommandManager.Commands.Count % PerPage) > 0)
|
if ((Program.CommandManager.Commands.Count % perPage) > 0)
|
||||||
Pages++;
|
numPages++;
|
||||||
|
|
||||||
if (Page < 1 || Page > Pages)
|
if (page < 1 || page > numPages)
|
||||||
Page = 1;
|
page = 1;
|
||||||
|
|
||||||
int StartingIndex = (Page - 1) * PerPage;
|
int startingIndex = (page - 1) * perPage;
|
||||||
Client.SendMessage("--Help Page " + Page + " of " + Pages + "--");
|
client.SendMessage("--Help page " + page + " of " + numPages + "--");
|
||||||
for (int i = 0; i < PerPage; i++)
|
for (int i = 0; i < perPage; i++)
|
||||||
{
|
{
|
||||||
int Index = StartingIndex + i;
|
int index = startingIndex + i;
|
||||||
if (Index > Program.CommandManager.Commands.Count - 1)
|
if (index > Program.CommandManager.Commands.Count - 1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ICommand C = Program.CommandManager.Commands[Index];
|
var command = Program.CommandManager.Commands[index];
|
||||||
Client.SendMessage("/" + C.Name + " - " + C.Description);
|
client.SendMessage("/" + command.Name + " - " + command.Description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Help(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
Client.SendMessage("Correct usage is /" + Alias + " <page#/command> [command arguments]");
|
client.SendMessage("Correct usage is /" + alias + " <page#/command> [command arguments]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,4 @@
|
|||||||
using System;
|
using TrueCraft.API.Networking;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using TrueCraft.API.Networking;
|
|
||||||
|
|
||||||
namespace TrueCraft.Commands
|
namespace TrueCraft.Commands
|
||||||
{
|
{
|
||||||
@ -18,14 +14,14 @@ namespace TrueCraft.Commands
|
|||||||
get { return "Ping pong"; }
|
get { return "Ping pong"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Handle(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Handle(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
Client.SendMessage("Pong!");
|
client.SendMessage("Pong!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(IRemoteClient Client, string Alias, string[] Arguments)
|
public override void Help(IRemoteClient client, string alias, string[] arguments)
|
||||||
{
|
{
|
||||||
Client.SendMessage("Correct usage is /" + Alias);
|
client.SendMessage("Correct usage is /" + alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
60
TrueCraft/Commands/TimeCommand.cs
Normal file
60
TrueCraft/Commands/TimeCommand.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using TrueCraft.API.Networking;
|
||||||
|
using TrueCraft.Core.Networking.Packets;
|
||||||
|
|
||||||
|
namespace TrueCraft.Commands
|
||||||
|
{
|
||||||
|
public class TimeCommand : Command
|
||||||
|
{
|
||||||
|
public override string Name
|
||||||
|
{
|
||||||
|
get { return "time"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Description
|
||||||
|
{
|
||||||
|
get { return "Shows the current time."; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] Aliases
|
||||||
|
{
|
||||||
|
get { return new string[0]; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Handle(IRemoteClient client, string alias, string[] arguments)
|
||||||
|
{
|
||||||
|
switch (arguments.Length)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
client.SendMessage(client.World.Time.ToString());
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (!arguments[0].Equals("set"))
|
||||||
|
Help(client, alias, arguments);
|
||||||
|
|
||||||
|
int newTime;
|
||||||
|
|
||||||
|
if(!Int32.TryParse(arguments[1], out newTime))
|
||||||
|
Help(client, alias, arguments);
|
||||||
|
|
||||||
|
client.World.Time = newTime;
|
||||||
|
|
||||||
|
client.SendMessage(string.Format("Setting time to {0}", arguments[1]));
|
||||||
|
|
||||||
|
foreach (var remoteClient in client.Server.Clients.Where(c => c.World.Equals(client.World)))
|
||||||
|
remoteClient.QueuePacket(new TimeUpdatePacket(newTime));
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Help(client, alias, arguments);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Help(IRemoteClient client, string alias, string[] arguments)
|
||||||
|
{
|
||||||
|
client.SendMessage("/time: Shows the current time.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
using TrueCraft.API;
|
using TrueCraft.API;
|
||||||
|
using YamlDotNet.Core;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
|
using YamlDotNet.Serialization.NodeDeserializers;
|
||||||
|
|
||||||
namespace TrueCraft
|
namespace TrueCraft
|
||||||
{
|
{
|
||||||
@ -27,6 +30,7 @@ namespace TrueCraft
|
|||||||
Debug = new DebugConfiguration();
|
Debug = new DebugConfiguration();
|
||||||
ServerPort = 25565;
|
ServerPort = 25565;
|
||||||
ServerAddress = "0.0.0.0";
|
ServerAddress = "0.0.0.0";
|
||||||
|
WorldSaveInterval = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
[YamlMember(Alias="motd")]
|
[YamlMember(Alias="motd")]
|
||||||
@ -36,9 +40,13 @@ namespace TrueCraft
|
|||||||
public int ServerPort {get; set; }
|
public int ServerPort {get; set; }
|
||||||
|
|
||||||
[YamlMember(Alias="serverAddress")]
|
[YamlMember(Alias="serverAddress")]
|
||||||
public string ServerAddress{get; set; }
|
public string ServerAddress { get; set; }
|
||||||
|
|
||||||
[YamlMember(Alias="debug")]
|
[YamlMember(Alias = "debug")]
|
||||||
public DebugConfiguration Debug { get; set; }
|
public DebugConfiguration Debug { get; set; }
|
||||||
|
|
||||||
|
[YamlMember(Alias = "worldSaveInterval")]
|
||||||
|
public int WorldSaveInterval { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -46,8 +46,6 @@ namespace TrueCraft.Handlers
|
|||||||
var server = (MultiplayerServer)_server;
|
var server = (MultiplayerServer)_server;
|
||||||
var args = new ChatMessageEventArgs(_client, packet.Message);
|
var args = new ChatMessageEventArgs(_client, packet.Message);
|
||||||
server.OnChatMessageReceived(args);
|
server.OnChatMessageReceived(args);
|
||||||
if (!args.PreventDefault)
|
|
||||||
server.SendMessage("<{0}> {1}", _client.Username, packet.Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void HandleDisconnect(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)
|
internal static void HandleDisconnect(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)
|
||||||
|
@ -9,7 +9,6 @@ using System.IO;
|
|||||||
using TrueCraft.Commands;
|
using TrueCraft.Commands;
|
||||||
using TrueCraft.API.World;
|
using TrueCraft.API.World;
|
||||||
using System;
|
using System;
|
||||||
using TrueCraft.Core;
|
|
||||||
using TrueCraft.API;
|
using TrueCraft.API;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
@ -60,7 +59,7 @@ namespace TrueCraft
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
world = new World("default", 1922464833, new StandardGenerator());
|
world = new World("default", new StandardGenerator());
|
||||||
world.BlockRepository = Server.BlockRepository;
|
world.BlockRepository = Server.BlockRepository;
|
||||||
world.Save("world");
|
world.Save("world");
|
||||||
Server.AddWorld(world);
|
Server.AddWorld(world);
|
||||||
@ -104,7 +103,7 @@ namespace TrueCraft
|
|||||||
Console.CancelKeyPress += HandleCancelKeyPress;
|
Console.CancelKeyPress += HandleCancelKeyPress;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Thread.Sleep(1000 * 30); // TODO: Allow users to customize world save interval
|
Thread.Sleep(1000 * Configuration.WorldSaveInterval);
|
||||||
foreach (var w in Server.Worlds)
|
foreach (var w in Server.Worlds)
|
||||||
{
|
{
|
||||||
w.Save();
|
w.Save();
|
||||||
@ -119,14 +118,43 @@ namespace TrueCraft
|
|||||||
|
|
||||||
static void HandleChatMessageReceived(object sender, ChatMessageEventArgs e)
|
static void HandleChatMessageReceived(object sender, ChatMessageEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Message.StartsWith("/"))
|
var message = e.Message;
|
||||||
{
|
|
||||||
e.PreventDefault = true;
|
if (!message.StartsWith("/") || message.StartsWith("//"))
|
||||||
var messageArray = e.Message.TrimStart('/')
|
SendChatMessage(e.Client.Username, message);
|
||||||
.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
|
else
|
||||||
CommandManager.HandleCommand(e.Client, messageArray[0], messageArray);
|
e.PreventDefault = ProcessChatCommand(e);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SendChatMessage(string username, string message)
|
||||||
|
{
|
||||||
|
if (message.StartsWith("//"))
|
||||||
|
message = message.Substring(1);
|
||||||
|
|
||||||
|
Server.SendMessage("<{0}> {1}", username, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parse sent message as chat command
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
/// <returns>true if the command was successfully executed</returns>
|
||||||
|
private static bool ProcessChatCommand(ChatMessageEventArgs e)
|
||||||
|
{
|
||||||
|
var commandWithoutSlash = e.Message.TrimStart('/');
|
||||||
|
var messageArray = commandWithoutSlash
|
||||||
|
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
if (messageArray.Length <= 0) return false; // command not found
|
||||||
|
|
||||||
|
var alias = messageArray[0];
|
||||||
|
var trimmedMessageArray = new string[messageArray.Length - 1];
|
||||||
|
if (trimmedMessageArray.Length != 0)
|
||||||
|
Array.Copy(messageArray, 1, trimmedMessageArray, 0, messageArray.Length - 1);
|
||||||
|
|
||||||
|
CommandManager.HandleCommand(e.Client, alias, trimmedMessageArray);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@ -41,8 +41,10 @@
|
|||||||
<Compile Include="Commands\Command.cs" />
|
<Compile Include="Commands\Command.cs" />
|
||||||
<Compile Include="Commands\CommandManager.cs" />
|
<Compile Include="Commands\CommandManager.cs" />
|
||||||
<Compile Include="Commands\GiveCommand.cs" />
|
<Compile Include="Commands\GiveCommand.cs" />
|
||||||
|
<Compile Include="Commands\GiveMeCommand.cs" />
|
||||||
<Compile Include="Commands\HelpCommand.cs" />
|
<Compile Include="Commands\HelpCommand.cs" />
|
||||||
<Compile Include="Commands\PingCommand.cs" />
|
<Compile Include="Commands\PingCommand.cs" />
|
||||||
|
<Compile Include="Commands\TimeCommand.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="MultiplayerServer.cs" />
|
<Compile Include="MultiplayerServer.cs" />
|
||||||
@ -77,9 +79,7 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup>
|
<ItemGroup />
|
||||||
<Folder Include="Exceptions\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user