--- /dev/null
+/*
+ * Copyright (c) 2021, Dwarf <dwarf@rizon.net>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package net.rizon.acid.plugins.vizon.commands;
+
+import net.rizon.acid.core.*;
+import net.rizon.acid.plugins.vizon.Vizon;
+import net.rizon.acid.plugins.vizon.db.VizonDatabase;
+
+import java.util.Arrays;
+
+/**
+ *
+ * @author Dwarf <dwarf@rizon.net>
+ */
+public class BanCommand extends Command
+{
+ public BanCommand()
+ {
+ super(1, 1);
+ }
+
+ @Override
+ public void Run(User source, AcidUser to, Channel c, String[] args)
+ {
+ String[] parts = args[0].split(" ");
+ String nick = parts[0];
+ String reason = String.join(" ", Arrays.copyOfRange(parts, 1, parts.length));
+
+ VizonDatabase database = Vizon.getVizonDatabase();
+ if (database.findBanByNick(nick) != null)
+ {
+ Acidictive.reply(source, to, c, "Nickname is already banned.");
+ return;
+ }
+
+ if (database.insertBan(nick, source.getNick(), reason))
+ {
+ Acidictive.reply(source, to, c, "Nickname banned from playing.");
+ }
+ else
+ {
+ Acidictive.reply(source, to, c, "Couldn't create a ban, contact a dev.");
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.rizon.acid.plugins.vizon.commands;
+
+import net.rizon.acid.core.*;
+import net.rizon.acid.plugins.vizon.Vizon;
+import net.rizon.acid.plugins.vizon.db.VizonBan;
+import net.rizon.acid.plugins.vizon.db.VizonDatabase;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class BanlistCommand extends Command
+{
+ public BanlistCommand()
+ {
+ super(0, 0);
+ }
+
+ @Override
+ public void Run(User source, AcidUser to, Channel c, String[] args)
+ {
+ VizonDatabase database = Vizon.getVizonDatabase();
+ List<VizonBan> bans = new ArrayList<>(database.getBans());
+
+
+ Acidictive.reply(source, to, c, "VIzon bans:");
+ for (int i = 0; i <= bans.size(); i++)
+ {
+ VizonBan ban = bans.get(i);
+ Acidictive.reply(source, to, c, (i+1) + ". Nick " + ban.getNick() + " :: Banned by " + ban.getOper() + " :: Reason " + ban.getReason());
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2021, Dwarf <dwarf@rizon.net>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package net.rizon.acid.plugins.vizon.db;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ *
+ * @author Dwarf <dwarf@rizon.net>
+ */
+public class VizonBan {
+ private static final Logger logger = LoggerFactory.getLogger(VizonBan.class);
+
+ private final int id;
+ private final String nick;
+ private final String oper;
+ private final String reason;
+
+ public static VizonBan fromResultSet(ResultSet rs)
+ {
+ try
+ {
+ int id = rs.getInt("id");
+ String nick = rs.getString("nick");
+ String oper = rs.getString("oper");
+ String reason = rs.getString("reason");
+ return new VizonBan(id, nick, oper, reason);
+ }
+ catch (SQLException ex)
+ {
+ logger.warn("Unable to construct VizonBan from ResultSet", ex);
+ return null;
+ }
+ }
+
+ private VizonBan(
+ int id,
+ String nick,
+ String oper,
+ String reason)
+ {
+ this.id = id;
+ this.nick = nick;
+ this.oper = oper;
+ this.reason = reason;
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public String getNick()
+ {
+ return nick;
+ }
+
+ public String getOper()
+ {
+ return oper;
+ }
+
+ public String getReason()
+ {
+ return reason;
+ }
+}
return drawings;
}
+
+ /**
+ * Try and find a ban matching {@code nick}.
+ * @param nick Nickname to find a ban for.
+ * @return A {@link VizonBan} or null if the user is not banned.
+ */
+ public VizonBan findBanByNick(String nick)
+ {
+ if (nick == null)
+ {
+ return null;
+ }
+
+ try
+ {
+ PreparedStatement statement = vizonSql.prepare("SELECT * FROM vizon_bans WHERE nick = ?");
+ statement.setString(1, nick);
+
+ ResultSet rs = vizonSql.executeQuery(statement);
+
+ if (rs.next())
+ {
+ return VizonBan.fromResultSet(rs);
+ }
+
+ return null;
+ }
+ catch (SQLException ex)
+ {
+ logger.warn("Unable to select or create ban in Vizon Database", ex);
+ return null;
+ }
+ }
+
+ public Collection<VizonBan> getBans()
+ {
+ try
+ {
+ PreparedStatement statement = vizonSql.prepare("SELECT * FROM vizon_bans");
+
+ ResultSet rs = vizonSql.executeQuery(statement);
+
+ List<VizonBan> bans = new ArrayList<>();
+
+ while (rs.next())
+ {
+ VizonBan ban = VizonBan.fromResultSet(rs);
+
+ if (ban != null)
+ {
+ bans.add(ban);
+ }
+ }
+
+ return bans;
+ }
+ catch (SQLException ex)
+ {
+ logger.warn("Unable to select bans from Vizon Database", ex);
+ return null;
+ }
+ }
+
+ /**
+ * Ban a nickname from playing.
+ * @param nick The nickname to ban.
+ * @param oper The oper who banned this nickname.
+ * @param reason The reason to ban for.
+ * @return True on success, otherwise false.
+ */
+ public boolean insertBan(String nick, String oper, String reason)
+ {
+ if (nick.isEmpty() || reason.isEmpty())
+ {
+ return false;
+ }
+
+ try
+ {
+ PreparedStatement statement = vizonSql.prepare("INSERT INTO vizon_bans "
+ + "(nick, oper, reason) "
+ + "VALUES (?, ?, ?)");
+ statement.setString(1, nick);
+ statement.setString(2, oper);
+ statement.setString(3, reason);
+
+ int result = vizonSql.executeUpdateBlocking(statement);
+
+ return result > 0;
+ }
+ catch (SQLException ex)
+ {
+ logger.warn("Unable to insert vhost ban", ex);
+ return false;
+ }
+ }
}
name: vhost
privilege: none
clazz: net.rizon.acid.plugins.vizon.commands.ModifyVhostCommand
+ - name: ban
+ channels: [ vhost ]
+ privilege: none
+ clazz: net.rizon.acid.plugins.vizon.commands.BanCommand
+ - name: b
+ channels: [ vhost ]
+ privilege: none
+ clazz: net.rizon.acid.plugins.vizon.commands.BanCommand
vizonChannel: "#opers"
vizonDebugChannel: "#opers"
ON UPDATE CASCADE)
ENGINE = InnoDB;
+-- -----------------------------------------------------
+-- Table `vizon`.`vizon_bans`
+-- -----------------------------------------------------
+CREATE TABLE IF NOT EXISTS `vizon`.`vizon_bans` (
+`id` INT AUTO_INCREMENT,
+`nick` VARCHAR(64) not null,
+`oper` VARCHAR(64) not null,
+`reason` VARCHAR(128),
+PRIMARY KEY (id),
+UNIQUE INDEX `nick_UNIQUE` (`nick` ASC));
+
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;