File tree Expand file tree Collapse file tree 5 files changed +17
-21
lines changed
java/ua/mei/minekord/mixin Expand file tree Collapse file tree 5 files changed +17
-21
lines changed Original file line number Diff line number Diff line change 12
12
import ua .mei .minekord .config .MinekordConfigKt ;
13
13
import ua .mei .minekord .event .IPCheckEvent ;
14
14
15
- import java .net .InetSocketAddress ;
16
15
import java .net .SocketAddress ;
17
16
18
17
@ Mixin (PlayerManager .class )
19
18
public class PlayerManagerMixin {
20
19
@ Inject (method = "checkCanJoin" , at = @ At ("RETURN" ), cancellable = true )
21
20
private void minekord$checkRoles (SocketAddress socketAddress , GameProfile gameProfile , CallbackInfoReturnable <Text > cir ) {
22
- if (cir .getReturnValue () == null && MinekordConfigKt .getConfig ().get (ExperimentalSpec .DiscordSpec .INSTANCE .getEnabled ())) {
23
- boolean loginByIp = MinekordConfigKt .getConfig ().get (ExperimentalSpec .DiscordSpec .INSTANCE .getLoginByIp ());
24
- String playerName = gameProfile .getName ();
25
- String cachedIp = IPCache .INSTANCE .getFromCache (playerName );
26
-
27
- if (loginByIp && socketAddress instanceof InetSocketAddress inet && !cachedIp .equals (inet .getHostName ())) {
21
+ if (cir .getReturnValue () == null && MinekordConfigKt .getConfig ().get (ExperimentalSpec .DiscordSpec .INSTANCE .getEnabled ()) && MinekordConfigKt .getConfig ().get (ExperimentalSpec .DiscordSpec .INSTANCE .getLoginByIp ())) {
22
+ if (!IPCache .INSTANCE .haveInCache (gameProfile .getName (), socketAddress )) {
28
23
IPCheckEvent .Companion .getEvent ().invoker ().request (socketAddress , gameProfile );
29
24
cir .setReturnValue (Text .translatable ("multiplayer.disconnect.generic" ));
30
25
}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import kotlinx.coroutines.launch
9
9
import ua.mei.minekord.bot.extensions.IPCheckExtension
10
10
import ua.mei.minekord.bot.extensions.SetupExtension
11
11
import ua.mei.minekord.config.BotSpec
12
+ import ua.mei.minekord.config.ExperimentalSpec
12
13
import ua.mei.minekord.config.config
13
14
import kotlin.coroutines.CoroutineContext
14
15
@@ -23,15 +24,13 @@ object MinekordBot : CoroutineScope {
23
24
bot = ExtensibleBot (config[BotSpec .token]) {
24
25
extensions {
25
26
add(::SetupExtension )
26
- add(::IPCheckExtension )
27
+
28
+ if (config[ExperimentalSpec .DiscordSpec .enabled])
29
+ add(::IPCheckExtension )
27
30
}
28
31
}
29
32
30
- try {
31
- bot.start()
32
- } catch (_: Throwable ) {
33
- println (" LOX" )
34
- }
33
+ bot.start()
35
34
}
36
35
}
37
36
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ class IPCheckExtension : Extension() {
25
25
override val name: String = " IP Check Extension"
26
26
27
27
override suspend fun setup () {
28
- IPCheckEvent .event.register { address , profile ->
28
+ IPCheckEvent .event.register { socketAddress , profile ->
29
29
MinekordBot .launch {
30
30
try {
31
31
if (! config[ExperimentalSpec .DiscordSpec .enabled]) return @launch
@@ -39,7 +39,7 @@ class IPCheckExtension : Extension() {
39
39
40
40
field {
41
41
name = " > IP"
42
- value = " > ${address .address} "
42
+ value = " > ${socketAddress .address} "
43
43
inline = true
44
44
}
45
45
field {
@@ -54,7 +54,7 @@ class IPCheckExtension : Extension() {
54
54
style = ButtonStyle .Success
55
55
56
56
action {
57
- IPCache .putIntoCache(profile.name, address .address)
57
+ IPCache .putIntoCache(profile.name, socketAddress .address)
58
58
59
59
edit {
60
60
components {
Original file line number Diff line number Diff line change @@ -3,8 +3,10 @@ package ua.mei.minekord.cache
3
3
import com.google.gson.Gson
4
4
import com.google.gson.GsonBuilder
5
5
import com.google.gson.stream.JsonReader
6
+ import io.ktor.util.network.address
6
7
import net.fabricmc.loader.api.FabricLoader
7
8
import java.io.FileReader
9
+ import java.net.SocketAddress
8
10
import java.nio.file.Files
9
11
import java.nio.file.Path
10
12
@@ -37,7 +39,7 @@ object IPCache {
37
39
save()
38
40
}
39
41
40
- fun getFromCache (nickname : String ): String {
41
- return cache[nickname] ? : " "
42
+ fun haveInCache (nickname : String , socketAddress : SocketAddress ): Boolean {
43
+ return cache[nickname] == socketAddress.address
42
44
}
43
45
}
Original file line number Diff line number Diff line change @@ -6,13 +6,13 @@ import net.fabricmc.fabric.api.event.EventFactory
6
6
import java.net.SocketAddress
7
7
8
8
fun interface IPCheckEvent {
9
- fun request (address : SocketAddress , profile : GameProfile )
9
+ fun request (socketAddress : SocketAddress , profile : GameProfile )
10
10
11
11
companion object {
12
12
val event: Event <IPCheckEvent > = EventFactory .createArrayBacked(IPCheckEvent ::class .java) { listeners ->
13
- IPCheckEvent { address , profile ->
13
+ IPCheckEvent { socketAddress , profile ->
14
14
listeners.forEach { listener ->
15
- listener.request(address , profile)
15
+ listener.request(socketAddress , profile)
16
16
}
17
17
}
18
18
}
You can’t perform that action at this time.
0 commit comments