Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

Commit

Permalink
Finish ban implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vainamov committed Mar 10, 2019
1 parent cb7c3ce commit 0a3a8df
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions NeoServer.cs
Expand Up @@ -61,6 +61,12 @@ internal class NeoServer : BaseServer
return;
}

if (member.Account.Attributes.ContainsKey("neo.banned") && (bool) member.Account.Attributes["neo.banned"]) {
Logger.Instance.Log(LogLevel.Warn, $"{member.Identity.Name} tried to join (Id: {member.Identity.Id}) but is banned.");
SendPackageTo(client.ClientId, new Package(PackageType.LoginResponse, LoginResponsePackageContent.GetUnauthorized()));
return;
}

member.Client = client;
Users.Add(member);

Expand Down Expand Up @@ -226,6 +232,14 @@ internal class NeoServer : BaseServer

if (data.Action == "kick") {
user.Client.Socket.Close();
} else if (data.Action == "ban") {
user.Client.Socket.Close();

if (user is Member member) {
member.Account.Attributes["neo.banned"] = true;
DataProvider.Save();
Target.All.SendPackageTo(new Package(PackageType.AccountListUpdate, Pool.Server.Accounts));
}
}
} else if (package.Type == PackageType.CreateChannel) {
var data = package.GetContentTypesafe<CreateChannelPackageContent>();
Expand Down Expand Up @@ -268,6 +282,16 @@ internal class NeoServer : BaseServer
}

new Target(client.ClientId).SendPackageTo(new Package(PackageType.DeleteChannelResponse, channel.DeleteChannel(GetUser(client.ClientId)) ? "Success" : "NotAllowed"));
} else if (package.Type == PackageType.DeletePunishment) {
var account = Accounts.Find(a => a.InternalId.Equals(package.GetContentTypesafe<Guid>()));

if (account == null) {
return;
}

account.Attributes.Remove("neo.banned");
DataProvider.Save();
Target.All.SendPackageTo(new Package(PackageType.AccountListUpdate, Pool.Server.Accounts));
}
}

Expand Down

0 comments on commit 0a3a8df

Please sign in to comment.