public void Store(ServerClient client) { lock (_lock) { _clients.Add(client); } }
public override void Execute(ServerClient client, string[] args) { if (args.Length != 1) { SendUsage(client); return; } string desiredChannel = args[0]; if (!desiredChannel.StartsWith("++")) { desiredChannel = "++" + desiredChannel; } if (desiredChannel.Length > 16 || desiredChannel.Substring(2).Contains("+") || desiredChannel.Contains("%") || desiredChannel.Contains("/") || desiredChannel.Contains("@") || desiredChannel.Contains("\\") || desiredChannel.Contains(";")) { client.SendMessage("§2Invalid Channel name. Channel names may not contain +, %, /, @, ; or \\. Channel names also have a maximum length of 16 characters."); return; } TalkyChannel channel = ChannelRepository.Instance.Get(desiredChannel); if (channel != null) { client.SendMessage("§2That channel already exists."); return; } ClientChannel chan = new ClientChannel(desiredChannel); ChannelRepository.Instance.Store(chan); client.SendMessage("§4Your channel has been created."); client.JoinChannel(chan); }
public override void Execute(ServerClient client, string[] args) { if (args.Length != 1) { SendUsage(client); return; } string desiredChannel = args[0]; if (!desiredChannel.StartsWith("+")) { desiredChannel = "+" + desiredChannel; } TalkyChannel channel = ChannelRepository.Instance.Get(desiredChannel); if (channel == null) { client.SendMessage("§2That channel does not exist."); client.SendMessage("§2Use /clist to see a list of channels."); client.SendMessage("§2Use /cc to create a temporary channel."); return; } if (client.Channel.Equals(channel)) { client.SendMessage("§2You are already in that channel!"); return; } client.JoinChannel(channel); }
public void Kick(ServerClient client, string reason = null) { if (!(this is LobbyChannel)) { LobbyChannel lobby = ChannelRepository.Instance.GetLobby(); if (lobby == null) { return; } if (client.Channel.Equals(lobby)) { return; } TalkyChannel oldChannel = client.Channel; client.JoinChannel(lobby, false); if (reason != null) { oldChannel.BroadcastMessage(client.Username + " was kicked from the channel (" + reason + ")."); } oldChannel.BroadcastMessage(client.Username + " was kicked from the channel."); } }
public void Remove(ServerClient client) { lock (_lock) { _clients.Remove(client); } }
public override void Execute(ServerClient client, string[] args) { IReadOnlyList<TalkyCommand> commands = CommandManager.Instance.All(); client.SendMessage("§1=COMMANDS============="); foreach (TalkyCommand command in commands) { client.SendMessage("[" + command.Usage + "] " + command.Description); } client.SendMessage("§1=COMMANDS============="); }
public override void Execute(ServerClient client, string[] args) { if (args.Length != 1) { SendUsage(client); return; } string desiredUsername = args[0]; if (desiredUsername.Length > 16 || desiredUsername.Contains("%") || desiredUsername.Contains("/") || desiredUsername.Contains("@") || desiredUsername.Contains("\\") || desiredUsername.Contains(";")) { client.SendMessage("§2Invalid username. Usernames may not contain %, /, @, ; or \\. Usernames also have a maximum length of 16 characters."); return; } if (ClientRepository.Instance.Exists(desiredUsername)) { client.SendMessage("§2That username is already in use."); return; } if (UserAccount.Find(desiredUsername) != null) { client.SendMessage("§2That username is linked to an account."); client.SendMessage("§2If you are the account holder, use /auth to login and claim the username."); return; } if (client.Account != null) { client.SendMessage("§2Authenticated clients may not change their username."); return; } string oldUsername = client.Username; client.Username = desiredUsername; client.SendMessage("§4You are now known as " + desiredUsername + "."); if (client.Channel == null) { client.JoinChannel(ChannelRepository.Instance.GetLobby()); } if (!oldUsername.Equals("%")) { client.Channel.BroadcastMessage("§1" + oldUsername + " is now known as " + desiredUsername); } }
public override void Execute(ServerClient client, string[] args) { if (ChannelRepository.Instance.Count() == 0) { client.SendMessage("A problem happened. Sorry. :'("); return; } client.SendMessage("§1=CHANNELS============="); foreach (TalkyChannel channel in ChannelRepository.Instance.All()) { client.SendMessage("[" + channel.Name + "] " + (channel.Locked ? "Locked" : "Unlocked")); } client.SendMessage("§1=CHANNELS============="); }
public override void Execute(ServerClient client, string[] args) { if (client.Account == null || !client.Account.Role.Equals("admin")) { client.SendMessage("§2That command is admin only!"); return; } if (args.Length != 2) { SendUsage(client); return; } string username = args[0]; string role = "user"; if (args[1].ToLower().Equals("admin")) { role = "admin"; } UserAccount account = UserAccount.Find(username); if (account == null) { client.SendMessage("§2User not found."); return; } if (account.SetRole(role)) { client.SendMessage("§4Account role for " + account.Username + " set to " + role + "."); ServerClient foundClient = ClientRepository.Instance.Find(account.Username); if (foundClient != null) { foundClient.Account = account; if (foundClient.Account != null) { foundClient.SendRawMessage($"S:Account:{foundClient.Account.AccountId};{foundClient.Account.Username};{foundClient.Account.Role}"); } foundClient.SendMessage("§1Your role was set to " + role + " by " + client.Username + "."); } return; } client.SendMessage("§2Failed to update account role for " + account.Username + "."); }
public override void Execute(ServerClient client, string[] args) { if (client.Account == null) { client.SendMessage("§2You must be authenticated to use this command. See /auth."); return; } if (args.Length != 3) { SendUsage(client); return; } string currentPassword = args[0]; string newPassword = args[1]; string newPasswordRepeat = args[2]; if (string.IsNullOrEmpty(newPassword) || string.IsNullOrWhiteSpace(newPassword) || newPassword.Length < 6) { client.SendMessage("§2Invalid password. Passwords must contain at least 6 characters. Passwords may not be whitespace."); return; } if (!client.Account.ComparePassword(currentPassword)) { client.SendMessage("§2Failed to authenticate. Invalid password."); return; } if (client.Account.ComparePassword(newPassword)) { client.SendMessage("§2New password is the same as your old password."); return; } if (!newPassword.Equals(newPasswordRepeat, StringComparison.Ordinal)) { client.SendMessage("§2New password and password confirmation do not match. Please try again."); return; } client.Account.SetPassword(newPassword); client.SendMessage("§4Your password has been updated."); }
public override void Execute(ServerClient client, string[] args) { if (args.Length != 2) { SendUsage(client); return; } string username = args[0]; string password = args[1]; if (client.Account != null) { client.SendMessage("You are already authenticated."); return; } if (username.Length > 16 || username.Contains("%") || username.Contains("/") || username.Contains("@") || username.Contains("\\") || username.Contains(";")) { client.SendMessage("Invalid username. Usernames may not contain %, /, @, ; or \\. Usernames also have a maximum length of 16 characters."); return; } if (string.IsNullOrEmpty(password) || string.IsNullOrWhiteSpace(password) || password.Length < 6) { client.SendMessage("Invalid password. Passwords must contain at least 6 characters. Passwords may not be whitespace."); return; } if (UserAccount.Find(username) != null) { client.SendMessage("An account with that username already exists."); return; } UserAccount account = UserAccount.Create(username, password, false); if (account == null) { client.SendMessage("There was a problem creating your account. Please try again later."); return; } client.Account = account; client.SendMessage("You are now authenticated as " + account.Username + "!"); }
public override void Execute(ServerClient client, string[] args) { if (client.Muted) { client.SendMessage("§2You are muted."); return; } if (args.Length < 2) { SendUsage(client); return; } string recipientUsername = args[0]; string message = ""; for (int i = 1; i < args.Length; i++) { if (i == args.Length - 1) { message += args[i]; } else { message += args[i] + " "; } } ServerClient recipient = ClientRepository.Instance.Find(recipientUsername); if (recipient == null) { client.SendMessage("§2No client found by that username."); return; } if (recipient.Equals(client)) { client.SendMessage("§2You cannot send messages to yourself."); return; } recipient.SendMessage("<§1" + client.Username + " -> you§0> " + message); client.SendMessage("<§1you -> " + recipient.Username + "§0> " + message); }
public override void Execute(ServerClient client, string[] args) { if (args.Length != 2) { SendUsage(client); return; } string username = args[0]; string password = args[1]; UserAccount account = UserAccount.Attempt(username, password); if (account == null) { client.SendMessage("§2Invalid username/password."); return; } ServerClient foundClient = ClientRepository.Instance.Find(account.Username); if (foundClient != null) { if (!foundClient.Equals(client)) { foundClient.Disconnect("§2This username has been reclaimed by the account owner."); } } string oldUsername = client.Username; client.Account = account; client.Username = account.Username; client.SendMessage("§4You are now authenticated as " + account.Username + "!"); if (client.Channel == null) { client.JoinChannel(ChannelRepository.Instance.GetLobby()); } if (!oldUsername.Equals("%")) { client.Channel.BroadcastMessage("§1" + oldUsername + " is now known as " + account.Username); } }
public override void Execute(ServerClient client, string[] args) { if (client.Account == null || !client.Account.Role.Equals("admin")) { client.SendMessage("§2That command is admin only!"); return; } if (args.Length != 1) { SendUsage(client); return; } string username = args[0]; if (ClientRepository.Instance.Find(username) == null) { client.SendMessage("§2No client found with that username."); return; } ClientRepository.Instance.Find(username).Disconnect("§2Kicked from server."); client.SendMessage("§4" + username + " was kicked from the server."); }
public override void Execute(ServerClient client, string[] args) { if (client.Account == null || !client.Account.Role.Equals("admin")) { client.SendMessage("§2That command is admin only!"); return; } if (args.Length != 1) { SendUsage(client); return; } string username = args[0]; ServerClient found = ClientRepository.Instance.Find(username); if (found == null) { client.SendMessage("§2No client found with that username."); return; } found.Muted = !found.Muted; client.SendMessage("§4Client mute set to: " + found.Muted + " for " + found.Username + "."); }
public abstract void Execute(ServerClient client, string[] args);
public CommandMessage(ServerClient client, string message) : base(client, message) { }
private void ListenForClients() { TcpListener listener = new TcpListener(IPAddress.Any, Port); listener.Start(); while (!PanicMode) { TcpClient tcpClient = listener.AcceptTcpClient(); ServerClient serverClient = new ServerClient(tcpClient); if (_channelRepository.GetLobby() == null) { serverClient.Disconnect("§2Server Error: No Lobby!"); continue; } Thread clientThread = new Thread(new ThreadStart(new ServerConnection(serverClient).HandleMessages)); clientThread.Start(); } }
public StatMessage(ServerClient client, string message) : base(client, message) { }
public ServerConnection(ServerClient client) { Client = client; ClientRepository.Instance.Store(client); }
protected ServerMessage(ServerClient client, string message) { _client = client; _message = message; _time = DateTime.Now; }
public void SendUsage(ServerClient client) { client.SendMessage("§1Usage: " + Usage); }