Fixed code issues (variable renames and such)

This commit is contained in:
Robin Kanters 2015-05-08 21:56:08 +02:00
parent ff815aa2fc
commit 4206f2d005
6 changed files with 52 additions and 69 deletions

View File

@ -11,7 +11,7 @@ namespace TrueCraft.API.Server
string Name { get; }
string Description { 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);
}
}

View File

@ -1,8 +1,4 @@
using System.Collections.Generic;
using System.Text;
using TrueCraft.Core.Windows;
using TrueCraft.API;
using TrueCraft.API.Networking;
using TrueCraft.API.Networking;
using TrueCraft.Core.Networking.Packets;
namespace TrueCraft.Commands
@ -24,14 +20,14 @@ namespace TrueCraft.Commands
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)
{
Help(Client, alias, arguments);
Help(client, alias, arguments);
return;
}
Client.SendMessage(Client.Entity.Position.ToString());
client.SendMessage(client.Entity.Position.ToString());
}
public override void Help(IRemoteClient client, string alias, string[] arguments)
@ -57,14 +53,14 @@ namespace TrueCraft.Commands
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)
{
Help(Client, alias, arguments);
Help(client, alias, arguments);
return;
}
Client.EnableLogging = !Client.EnableLogging;
client.EnableLogging = !client.EnableLogging;
}
public override void Help(IRemoteClient client, string alias, string[] arguments)
@ -90,14 +86,14 @@ namespace TrueCraft.Commands
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)
{
Help(Client, alias, arguments);
Help(client, alias, arguments);
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)

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrueCraft.API.Networking;
using TrueCraft.API.Server;
@ -19,63 +16,58 @@ namespace TrueCraft.Commands
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)
{
Help(Client, alias, arguments);
Help(client, alias, arguments);
return;
}
string Identifier;
var identifier = arguments.Length >= 1 ? arguments[0] : "0";
if (arguments.Length >= 1)
Identifier = arguments[0];
else
Identifier = "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;
}
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;
}
int PageNumber = 0;
if (int.TryParse(Identifier, out PageNumber))
int pageNumber;
if (int.TryParse(identifier, out pageNumber))
{
HelpPage(Client, PageNumber);
HelpPage(client, pageNumber);
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;
int Pages = (int)Math.Floor((double)(Program.CommandManager.Commands.Count / PerPage));
if ((Program.CommandManager.Commands.Count % PerPage) > 0)
Pages++;
const int perPage = 5;
int numPages = (int)Math.Floor(((double)Program.CommandManager.Commands.Count / perPage));
if ((Program.CommandManager.Commands.Count % perPage) > 0)
numPages++;
if (Page < 1 || Page > Pages)
Page = 1;
if (page < 1 || page > numPages)
page = 1;
int StartingIndex = (Page - 1) * PerPage;
Client.SendMessage("--Help Page " + Page + " of " + Pages + "--");
for (int i = 0; i < PerPage; i++)
int startingIndex = (page - 1) * perPage;
client.SendMessage("--Help page " + page + " of " + numPages + "--");
for (int i = 0; i < perPage; i++)
{
int Index = StartingIndex + i;
if (Index > Program.CommandManager.Commands.Count - 1)
int index = startingIndex + i;
if (index > Program.CommandManager.Commands.Count - 1)
{
break;
}
ICommand C = Program.CommandManager.Commands[Index];
Client.SendMessage("/" + C.Name + " - " + C.Description);
var command = Program.CommandManager.Commands[index];
client.SendMessage("/" + command.Name + " - " + command.Description);
}
}

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrueCraft.API.Networking;
using TrueCraft.API.Networking;
namespace TrueCraft.Commands
{
@ -18,9 +14,9 @@ namespace TrueCraft.Commands
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)

View File

@ -22,32 +22,32 @@ namespace TrueCraft.Commands
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)
{
switch (arguments.Length)
{
case 0:
Client.SendMessage(Client.World.Time.ToString());
client.SendMessage(client.World.Time.ToString());
break;
case 2:
if (!arguments[0].Equals("set"))
Help(Client, alias, arguments);
Help(client, alias, arguments);
int newTime;
if(!Int32.TryParse(arguments[1], out newTime))
Help(Client, alias, arguments);
Help(client, alias, arguments);
Client.World.Time = newTime;
client.World.Time = newTime;
Client.SendMessage(string.Format("Setting time to {0}", arguments[1]));
client.SendMessage(string.Format("Setting time to {0}", arguments[1]));
foreach (var client in Client.Server.Clients.Where(c => c.World.Equals(Client.World)))
client.QueuePacket(new TimeUpdatePacket(newTime));
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);
Help(client, alias, arguments);
break;
}
}

View File

@ -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">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -44,6 +44,7 @@
<Compile Include="Commands\GiveMeCommand.cs" />
<Compile Include="Commands\HelpCommand.cs" />
<Compile Include="Commands\PingCommand.cs" />
<Compile Include="Commands\TimeCommand.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MultiplayerServer.cs" />
@ -78,9 +79,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Exceptions\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>