Moved access control to IMultiplayerServer

This commit is contained in:
Robin Kanters 2015-05-16 12:46:17 +02:00
parent 46ae88001b
commit 1eaf36ffda
3 changed files with 22 additions and 12 deletions

View File

@ -38,5 +38,9 @@ namespace TrueCraft.API.Server
void Log(LogCategory category, string text, params object[] parameters); void Log(LogCategory category, string text, params object[] parameters);
IEntityManager GetEntityManagerForWorld(IWorld world); IEntityManager GetEntityManagerForWorld(IWorld world);
void SendMessage(string message, params object[] parameters); void SendMessage(string message, params object[] parameters);
bool PlayerIsWhitelisted(IRemoteClient client);
bool PlayerIsBlacklisted(IRemoteClient client);
bool PlayerIsOp(IRemoteClient client);
} }
} }

View File

@ -29,7 +29,7 @@ namespace TrueCraft.Handlers
remoteClient.QueuePacket(new DisconnectPacket("Server outdated! Use beta 1.7.3.")); remoteClient.QueuePacket(new DisconnectPacket("Server outdated! Use beta 1.7.3."));
else if (server.Worlds.Count == 0) else if (server.Worlds.Count == 0)
remoteClient.QueuePacket(new DisconnectPacket("Server has no worlds configured.")); remoteClient.QueuePacket(new DisconnectPacket("Server has no worlds configured."));
else if (!PlayerIsWhitelisted(remoteClient, server) && PlayerIsBlacklisted(remoteClient, server)) else if (!server.PlayerIsWhitelisted(remoteClient) && server.PlayerIsBlacklisted(remoteClient))
remoteClient.QueuePacket(new DisconnectPacket("You're banned from this server")); remoteClient.QueuePacket(new DisconnectPacket("You're banned from this server"));
else else
{ {
@ -65,15 +65,5 @@ namespace TrueCraft.Handlers
server.SendMessage(ChatColor.Yellow + "{0} joined the server.", remoteClient.Username); server.SendMessage(ChatColor.Yellow + "{0} joined the server.", remoteClient.Username);
} }
} }
private static bool PlayerIsWhitelisted(IRemoteClient client, IMultiplayerServer server)
{
return server.AccessConfiguration.Whitelist.Contains(client.Username, StringComparer.CurrentCultureIgnoreCase);
}
private static bool PlayerIsBlacklisted(IRemoteClient client, IMultiplayerServer server)
{
return server.AccessConfiguration.Blacklist.Contains(client.Username, StringComparer.CurrentCultureIgnoreCase);
}
} }
} }

View File

@ -6,6 +6,7 @@ using System.Threading;
using System.Net.Sockets; using System.Net.Sockets;
using System.Net; using System.Net;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using TrueCraft.API.World; using TrueCraft.API.World;
using TrueCraft.API.Logging; using TrueCraft.API.Logging;
using TrueCraft.Core.Networking.Packets; using TrueCraft.Core.Networking.Packets;
@ -195,7 +196,7 @@ namespace TrueCraft
public void SendMessage(string message, params object[] parameters) public void SendMessage(string message, params object[] parameters)
{ {
var compiled = string.Format(message, parameters); var compiled = String.Format(message, parameters);
var parts = compiled.Split('\n'); var parts = compiled.Split('\n');
foreach (var client in Clients) foreach (var client in Clients)
{ {
@ -363,5 +364,20 @@ namespace TrueCraft
} }
} }
} }
public bool PlayerIsWhitelisted(IRemoteClient client)
{
return AccessConfiguration.Whitelist.Contains(client.Username, StringComparer.CurrentCultureIgnoreCase);
}
public bool PlayerIsBlacklisted(IRemoteClient client)
{
return AccessConfiguration.Blacklist.Contains(client.Username, StringComparer.CurrentCultureIgnoreCase);
}
public bool PlayerIsOp(IRemoteClient client)
{
return AccessConfiguration.Oplist.Contains(client.Username, StringComparer.CurrentCultureIgnoreCase);
}
} }
} }