Skip to content

Commit

Permalink
improved code.... #WeAreStillCrying
Browse files Browse the repository at this point in the history
  • Loading branch information
LeBaasti committed Oct 4, 2019
1 parent bb6d0fd commit 69a6679
Show file tree
Hide file tree
Showing 14 changed files with 413 additions and 503 deletions.
6 changes: 6 additions & 0 deletions .idea/statistic.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

632 changes: 265 additions & 367 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ configurations {
dependencies {
compile fileTree(libsDirName)
compileOnly 'net.md-5:bungeecord-api:1.14-SNAPSHOT'
compile "mysql:mysql-connector-java:5.1.46"
jarLibs 'org.jetbrains.exposed:exposed:0.17.4'
/*compileOnly 'com.velocitypowered:velocity-api:1.0.0-SNAPSHOT'*/

// compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright (c) 2006 Damien Miller <[email protected]>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

package de.tutorialwork.utils;

import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -365,8 +379,8 @@ public class BCrypt {
*
* @param d the byte array to encode
* @param len the number of bytes to encode
* @return base64-encoded string
* @throws IllegalArgumentException if the length is invalid
* @return base64-encoded string
*/
private static String encode_base64(byte d[], int len)
throws IllegalArgumentException {
Expand Down Expand Up @@ -421,8 +435,8 @@ private static byte char64(char x) {
*
* @param s the string to decode
* @param maxolen the maximum number of bytes to decode
* @return an array containing the decoded bytes
* @throws IllegalArgumentException if maxolen is invalid
* @return an array containing the decoded bytes
*/
private static byte[] decode_base64(String s, int maxolen)
throws IllegalArgumentException {
Expand Down Expand Up @@ -746,4 +760,4 @@ public static String gensalt() {
public static boolean checkpw(String plaintext, String hashed) {
return (hashed.compareTo(hashpw(plaintext, hashed)) == 0);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.tutorialwork.main
package de.tutorialwork

import de.tutorialwork.commands.*
import de.tutorialwork.global.*
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/de/tutorialwork/commands/ChatLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object ChatLog : Command(simpleName<ChatLog>()) {
return
}
val executor = sender.executor
val id = Chat.createChatlog(target, executor)
val id = Chat.createChatLog(target, executor)
LogManager.createEntry(target.toString(), executor, ActionType.Chatlog("CREATE_CHATLOG", id))
sender.msg("${prefix}Der ChatLog von §e§l${target.name} §7wurde erfolgreich erstellt")
sender.msg("${prefix}Link: §e§l$chatLogUrl$id")
Expand Down
77 changes: 35 additions & 42 deletions src/main/kotlin/de/tutorialwork/commands/WebAccount.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,43 @@ object WebAccount : Command(simpleName<WebAccount>()) {

override fun execute(sender: CommandSender, args: Array<String>) = sender.hasPermission(name) {
if (sender is ProxiedPlayer) {
if (args.size <= 1) sender.msg("$prefix/webaccount <erstellen, löschen> <Spieler> [Rang]")
if (args.size <= 1) sender.msg("$prefix/webaccount <create, delete> <Player> [Rank]")
else {
if (args[0].equals("erstellen", ignoreCase = true)) {
if (args.size == 2) {
sender.msg(prefix + "Du musst noch ein Rang des Accounts angeben §4Admin§7, §cMod§7, §9Sup")
return
when (args[0].toLowerCase()) {
"create" -> {
if (args.size == 2) {
sender.msg("${prefix}Du musst noch ein Rang des Accounts angeben ${RankType.values().joinToString { "${it.color}${it.name}§7, " }}")
return
}
val uuid = UUIDFetcher.getUUID(args[1]) ?: return
if (uuid.playerExists()) {
if (!uuid.webaccountExists) {
val target = proxyServer.getPlayer(args[1])
if (target != null) {
val password = 7.randomString()
val rankType = RankType.values().find { it.name == args[2].toUpperCase() } ?: return
uuid.createWebAccount(rankType, password, sender)
sender.msg("${prefix}Ein ${rankType.color}§l${rankType.name.toLowerCase().capitalize()} §7Account für §e§l${uuid.name} §7wurde §aerstellt")
target.msg(
"${prefix}§e§l${sender.name} §7hat einen WebAccount für dich erstellt",
"${prefix}Passwort: §c§l$password"
)
} else sender.msg("$prefix§e§l${args[1]} §7ist derzeit nicht online")
} else sender.msg("${prefix}§cDieser Spieler hat bereits einen Zugang zum Webinterface")
} else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten")
}
val uuid = UUIDFetcher.getUUID(args[1]) ?: return
if (uuid.playerExists()) {
if (!uuid.webaccountExists) {
val target = proxyServer.getPlayer(args[1])
if (target != null) {
val rowPW = 7.randomString()
val hash = BCrypt.hashpw(rowPW, BCrypt.gensalt())
when (args[2].toLowerCase()) {
"admin" -> {
uuid.createWebAccount(uuid.name, 3, hash)
sender.msg(prefix + "Ein §4§lAdmin §7Account für §e§l" + uuid.name + " §7wurde §aerstellt")
}
"mod" -> {
uuid.createWebAccount(uuid.name, 2, hash)
sender.msg(prefix + "Ein §c§lMod §7Account für §e§l" + uuid.name + " §7wurde §aerstellt")
}
"sup" -> {
uuid.createWebAccount(uuid.name, 1, hash)
sender.msg(prefix + "Ein §9§lSup §7Account für §e§l" + uuid.name + " §7wurde §aerstellt")
}
}
target.msg("${prefix}§e§l${sender.name} §7hat einen Webaccount für dich erstellt")
target.msg("${prefix}Passwort: §c§l$rowPW")
LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), ActionType.Webaccount("ADD_WEBACCOUNT"))
} else sender.msg(prefix + "§e§l" + args[1] + " §7ist derzeit nicht online")
} else sender.msg("${prefix}§cDieser Spieler hat bereits einen Zugang zum Webinterface")
} else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten")
} else if (args[0].equals("löschen", ignoreCase = true)) {
val uuid = UUIDFetcher.getUUID(args[1]) ?: return
if (uuid.playerExists()) {
if (uuid.webaccountExists) {
uuid.deleteWebAccount()
sender.msg("${prefix}Der Zugang von dem Spieler §e§l${uuid.name} §7wurde erfolgreich §agelöscht")
LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), ActionType.Webaccount("DEL_WEBACCOUNT"))
} else sender.msg("${prefix}§cDieser Spieler hat keinen Zugang zum Webinterface")
} else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten")
} else sender.msg("$prefix/webaccount <erstellen, löschen> <Spieler> [Rang]")
"delete" -> {
val uuid = UUIDFetcher.getUUID(args[1]) ?: return
if (uuid.playerExists()) {
if (uuid.webaccountExists) {
uuid.deleteWebAccount()
sender.msg("${prefix}Der Zugang von dem Spieler §e§l${uuid.name} §7wurde erfolgreich §agelöscht")
LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), ActionType.WebAccount("DEL_WEBACCOUNT"))
} else sender.msg("${prefix}§cDieser Spieler hat keinen Zugang zum Webinterface")
} else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten")
}
else -> sender.msg("$prefix/webaccount <erstellen, löschen> <Spieler> [Rang]")
}
}
} else sender.msg("${prefix}Nur Spieler können §e§lWebAccounts §7erstellen/löschen")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/de/tutorialwork/global/Vars.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.tutorialwork.global

import de.tutorialwork.main.Main
import de.tutorialwork.Main
import de.tutorialwork.utils.MySQLConnect
import net.md_5.bungee.api.connection.ProxiedPlayer

Expand Down
142 changes: 58 additions & 84 deletions src/main/kotlin/de/tutorialwork/listener/Chat.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package de.tutorialwork.listener

import de.tutorialwork.global.*
import de.tutorialwork.sql.Chat
import de.tutorialwork.utils.*
import net.md_5.bungee.api.connection.ProxiedPlayer
import net.md_5.bungee.api.event.ChatEvent
import net.md_5.bungee.api.plugin.Listener
import net.md_5.bungee.event.EventHandler
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import java.util.*

object Chat : Listener {
Expand All @@ -17,113 +20,84 @@ object Chat : Listener {
if (player in activechats) {
event.isCancelled = true
val target = activechats[player] ?: return
target.msg("§9§lSUPPORT §8• §c${player.name} §8» ${event.message}")
player.msg("§9§lSUPPORT §8• §aDu §8» ${event.message}")
for (key in activechats.keys) {
//Key has started the support chat
key.msg("§9§lSUPPORT §8• §c${player.name} §8» ${event.message}")
}
val prefix = "§9§lSUPPORT §8• §c"
target.msg(
"$prefix§c${player.name} §8» ${event.message}",
"$prefix§aDu §8» ${event.message}"
)
activechats.keys.forEach { it.msg("$prefix§c${player.name} §8» ${event.message}") }
}
val uuid = player.uniqueId
if (uuid.isMuted) {
if (uuid.rawEnd == -1L) {
event.isCancelled = true
player.msg(config.getString("LAYOUT.MUTE").replace("%grund%", uuid.reasonString).translateColors())
} else {
if (System.currentTimeMillis() >= uuid.rawEnd) uuid.unMute()
else {
event.isCancelled = true
player.sendTempMute()
}
if (System.currentTimeMillis() >= uuid.rawEnd) {
uuid.unMute()
return
}

event.isCancelled = true
player.sendMute()
} else {
if (player.hasPermission("${permissionPrefix}blacklist.bypass")) insertMessage(uuid, event.message, player.server.info.name)
else {
if (config.getBoolean("AUTOMUTE.ENABLED")) {
insertMessage(uuid, event.message, player.server.info.name)
for (blacklist in blacklist) {
if (event.message.toUpperCase().contains(blacklist.toUpperCase())) {
event.isCancelled = true
uuid.mute(config.getInt("AUTOMUTE.MUTEID").reason, consoleName)
LogManager.createEntry(uuid.toString(), consoleName, ActionType.Blacklist("AUTOMUTE_BLACKLIST"))
ActionType.Mute(config.getInt("AUTOMUTE.MUTEID")).sendNotify(uuid.name, consoleName)
player.sendMute()
return
}
}
for (adblacklist in adblacklist) {
if (event.message.toUpperCase().contains(adblacklist.toUpperCase())) {
if (!adwhitelist.contains(event.message.toUpperCase())) {
event.isCancelled = true
uuid.mute(config.getInt("AUTOMUTE.ADMUTEID").reason, consoleName)
LogManager.createEntry(uuid.toString(), consoleName, ActionType.Blacklist("AUTOMUTE_ADBLACKLIST"))
ActionType.Mute(config.getInt("AUTOMUTE.ADMUTEID")).sendNotify(uuid.name, consoleName)
player.sendMute()
return
}
}
insertMessage(uuid, event.message, player.server.info.name)
if (player.hasPermission("${permissionPrefix}blacklist.bypass")) return
val predicate: (String) -> Boolean = { it.toUpperCase() in event.message.toUpperCase() }
when {
config.getBoolean("AUTOMUTE.ENABLED") -> {
val a = if (blacklist.any(predicate)) "" else {
if (adblacklist.any(predicate) && event.message.toUpperCase() !in adwhitelist) "AD" else return
}
} else {
insertMessage(uuid, event.message, player.server.info.name)
if (config.getBoolean("AUTOMUTE.AUTOREPORT")) {
for (blacklist in blacklist) {
if (event.message.toUpperCase().contains(blacklist.toUpperCase())) {
event.isCancelled = true
player.msg("${prefix}§cAchte auf deine Wortwahl")
val logId = createChatlog(uuid, consoleName)
uuid.createReport(consoleName, "VERHALTEN", logId)
ActionType.Report("VERHALTEN").sendNotify(player.name, consoleName)
return
}
}
for (adblacklist in adblacklist) {
if (event.message.toUpperCase().contains(adblacklist.toUpperCase())) {
if (!adwhitelist.contains(event.message.toUpperCase())) {
event.isCancelled = true
player.msg("${prefix}§cDu darfst keine Werbung machen")
val logId = createChatlog(uuid, consoleName)
uuid.createReport(consoleName, "WERBUNG", logId)
ActionType.Report("WERBUNG").sendNotify(player.name, consoleName)
return
}
}
}
uuid.mute(config.getInt("AUTOMUTE.${a}MUTEID").reason, consoleName)
LogManager.createEntry(uuid.toString(), consoleName, ActionType.Blacklist("AUTOMUTE_${a}BLACKLIST"))
ActionType.Mute(config.getInt("AUTOMUTE.MUTEID")).sendNotify(uuid.name, consoleName)
player.sendMute()
}
config.getBoolean("AUTOMUTE.AUTOREPORT") -> {
val reason: String = if (blacklist.any(predicate)) {
player.msg("${prefix}§cAchte auf deine Wortwahl")
"VERHALTEN"
} else {
if (adblacklist.any(predicate) && event.message.toUpperCase() !in adwhitelist) {
player.msg("${prefix}§cDu darfst keine Werbung machen")
"WERBUNG"
} else return
}
val logId = createChatLog(uuid, consoleName)
uuid.createReport(consoleName, reason, logId)
ActionType.Report(reason).sendNotify(player.name, consoleName)
}
else -> return
}


event.isCancelled = true
}
}


private fun insertMessage(uuid: UUID, Message: String, Server: String) {
mysql.update("INSERT INTO chat(UUID, SERVER, MESSAGE, SENDDATE) " +
"VALUES ('" + uuid + "', '" + Server + "', '" + Message + "', '" + System.currentTimeMillis() + "')")
private fun insertMessage(uuid: UUID, message: String, server: String) {
Chat.insert {
it[this.uuid] = uuid.toString()
it[this.server] = server
it[this.message] = message
it[this.sendDate] = System.currentTimeMillis()
}
}

fun createChatlog(uuid: UUID, createdUUID: String): String {
val rs = mysql.query("SELECT * FROM chat WHERE uuid='$uuid'") ?: return "null"
fun createChatLog(uuid: UUID, createdUUID: String): String {
val query = Chat.getByUUID(uuid)
val id = 20.randomString()
val now = System.currentTimeMillis()
while (rs.next()) {
val tenMinutes = 10 * 60 * 1000
val tenMinutes = 10 * 60 * 1000
query.forEach {
val tenAgo = System.currentTimeMillis() - tenMinutes
if (rs.getString("SENDDATE").toLong() > tenAgo) {
val sendDate = it[Chat.sendDate]
if (sendDate > tenAgo) {
mysql.update("""INSERT INTO chatlog(LOGID, uuid, CREATOR_UUID, SERVER, MESSAGE, SENDDATE, CREATED_AT) VALUES ('$id'
|,'$uuid', '$createdUUID', '${rs.getString("SERVER")}', '${rs.getString("MESSAGE")}'
|, '${rs.getString("SENDDATE")}', '$now')""".trimMargin())
|,'$uuid', '$createdUUID', '${it[Chat.server]}', '${it[Chat.message]}'
|, '${sendDate}', '$now')""".trimMargin())
}
}
return id
}

fun hasMessages(uuid: UUID): Boolean {
val rs = mysql.query("SELECT * FROM chat WHERE uuid='$uuid'") ?: return false
var i = 0
while (rs.next()) i++
return i != 0
}
fun hasMessages(uuid: UUID): Boolean = Chat.getByUUID(uuid).any()

private fun Chat.getByUUID(uuid: UUID) = select { Chat.uuid.eq(uuid.toString()) }

}
11 changes: 11 additions & 0 deletions src/main/kotlin/de/tutorialwork/sql/Chat.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tutorialwork.sql

import org.jetbrains.exposed.sql.Table

object Chat : Table() {
val id = integer("id").autoIncrement().primaryKey()
var uuid = varchar("uuid", 36)
var server = varchar("server", 64)
var message = varchar("message", 2500)
var sendDate = long("senddate")
}
2 changes: 1 addition & 1 deletion src/main/kotlin/de/tutorialwork/utils/ActionType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ sealed class ActionType {
override val message: String = "§c§l$senderName §7hat §e§l$bannedName §7wegen §a$reason §7gemeldet"
}

class Webaccount(override val reason: String) : ActionType() {
class WebAccount(override val reason: String) : ActionType() {
override val message: String = "§c§l$senderName §7hat §e§l$bannedName §7wegen §a$reason §7gemeldet"
}

Expand Down
Loading

0 comments on commit 69a6679

Please sign in to comment.