@@ -4,10 +4,18 @@ import com.fasterxml.jackson.databind.ObjectMapper
44import com.github.kittinunf.fuel.Fuel
55import net.zomis.core.events.EventSystem
66import org.slf4j.LoggerFactory
7+ import java.net.URL
78import java.util.UUID
89
910data class ClientLoginEvent (val client : Client , val providerId : String , val loginName : String , val provider : String , val token : String )
1011
12+ fun URL.lines (): List <String > {
13+ return this .readText(Charsets .UTF_8 ).split(" \n " )
14+ .map { it.trim() }
15+ .filter { it.isNotEmpty() }.distinct()
16+ .map { it[0 ].toUpperCase() + it.substring(1 ) }
17+ }
18+
1119class AuthorizationSystem (private val events : EventSystem ) {
1220 val router = MessageRouter (this )
1321 .handler(" guest" , this ::handleGuest)
@@ -18,9 +26,15 @@ class AuthorizationSystem(private val events: EventSystem) {
1826 private val mapper = ObjectMapper ()
1927
2028 private val guestRandom = kotlin.random.Random .Default
29+ private val guestAdjectives = this .javaClass.classLoader.getResource(" lists/adjectives.txt" )?.lines()
30+ private val guestAnimals = this .javaClass.classLoader.getResource(" lists/animals.txt" )?.lines()
31+
2132 private fun handleGuest (message : ClientJsonMessage ) {
2233 val client = message.client
23- val token: String = guestRandom.nextInt(100000 ).toString()
34+ val token: String = guestAdjectives?.random()
35+ ?.plus(guestAnimals?.random()? : " " )
36+ ?.plus(guestRandom.nextInt(10 , 99 ))
37+ ? : guestRandom.nextInt(100000 ).toString()
2438 this .handleGuest(client, token, UUID .randomUUID())
2539 }
2640 fun handleGuest (client : Client , token : String , uuid : UUID ) {
0 commit comments