-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
74 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/dev/andante/audience/resource/ResourcePackHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package dev.andante.audience.resource | ||
|
||
import io.netty.channel.ChannelHandlerContext | ||
import net.mcbrawls.inject.InjectorContext | ||
import net.mcbrawls.inject.http.HttpByteBuf | ||
import net.mcbrawls.inject.http.HttpRequest | ||
import net.mcbrawls.inject.http.HttpInjector | ||
import net.mcbrawls.inject.http.httpBuffer | ||
|
||
object ResourcePackHandler : HttpInjector() { | ||
private val resourcePacks: MutableMap<String, ByteArray> = mutableMapOf() | ||
|
||
private val SHA1_REGEX = Regex("^[a-fA-F0-9]{40}$") | ||
|
||
override fun isRelevant(ctx: InjectorContext, request: HttpRequest): Boolean = true | ||
|
||
override fun intercept(ctx: ChannelHandlerContext, request: HttpRequest): HttpByteBuf { | ||
val response = ctx.httpBuffer() | ||
|
||
val path = request.requestURI.removePrefix("/") | ||
if (!path.matches(SHA1_REGEX)) { | ||
return response | ||
} | ||
|
||
val pack = resourcePacks[path] ?: return response | ||
response.writeStatusLine("1.1", 200, "OK") | ||
|
||
response.writeHeader("Content-Type", "application/zip") | ||
response.writeBytes(pack) | ||
|
||
return response | ||
} | ||
|
||
/** | ||
* Adds a resource pack to be served. | ||
*/ | ||
fun add(pack: ByteResourcePack) { | ||
resourcePacks[pack.hash] = pack.bytes | ||
} | ||
|
||
/** | ||
* Removes a resource pack from service. | ||
* @return whether a pack was removed | ||
*/ | ||
fun remove(pack: ByteResourcePack): Boolean { | ||
return remove(pack.hash) | ||
} | ||
|
||
/** | ||
* Removes a resource pack from service. | ||
* @return whether a pack was removed | ||
*/ | ||
fun remove(hash: String): Boolean { | ||
return resourcePacks.remove(hash) != null | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
src/main/kotlin/dev/andante/audience/resource/ResourcePackRequestHandler.kt
This file was deleted.
Oops, something went wrong.
86 changes: 0 additions & 86 deletions
86
src/main/kotlin/dev/andante/audience/resource/ResourcePackServer.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters