Skip to content

Commit

Permalink
feat: prototype proxy manager (#2079)
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Feb 13, 2024
1 parent fbaa8f6 commit a061b4d
Show file tree
Hide file tree
Showing 5 changed files with 398 additions and 299 deletions.
1 change: 1 addition & 0 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<ID>LongMethod:FontRenderer.kt$FontRenderer$private fun drawInternal( text: String, x0: Float, y0: Float, defaultColor: Color4b, shadow: Boolean, obfuscatedSeed: Long, z: Float, scale: Float ): Float</ID>
<ID>LongMethod:ModuleManager.kt$ModuleManager$fun registerInbuilt()</ID>
<ID>LongMethod:ModuleTrajectories.kt$ModuleTrajectories$private fun drawTrajectoryForProjectile( motion: Vec3d, trajectoryInfo: TrajectoryInfo, pos: Vec3d, player: Entity, interpolatedOffset: Vec3, color: Color4b, matrixStack: MatrixStack ): HitResult?</ID>
<ID>LongMethod:ProxyRest.kt$internal fun RestNode.proxyRest()</ID>
<ID>LongMethod:SessionRest.kt$private fun RestNode.setupAccountManagerRest()</ID>
<ID>LongMethod:Value.kt$Value$open fun setByString(string: String)</ID>
<ID>LongParameterList:AimPlan.kt$AimPlan$( val rotation: Rotation, smootherMode: SmootherMode, baseTurnSpeed: ClosedFloatingPointRange&lt;Float>, val ticksUntilReset: Int, /** * The reset threshold defines the threshold at which we are going to reset the aim plan. * The threshold is being calculated by the distance between the current rotation and the rotation we want to aim. */ val resetThreshold: Float, /** * Consider if the inventory is open or not. If the inventory is open, we might not want to continue updating. */ val considerInventory: Boolean, val applyVelocityFix: Boolean, val changeLook: Boolean )</ID>
Expand Down
144 changes: 102 additions & 42 deletions src-theme/src/client/api.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -371,66 +371,126 @@
})
}
/**
* internal fun RestNode.setupProxyRestApi() {
* get("/proxy") {
* val proxyObject = JsonObject()
*
* ProxyManager.currentProxy?.let {
* proxyObject.addProperty("host", it.host)
* proxyObject.addProperty("port", it.port)
* proxyObject.addProperty("username", it.credentials?.username)
* proxyObject.addProperty("password", it.credentials?.password)
* }
*
* httpOk(proxyObject)
* }
*
* post("/proxy") {
* data class ProxyRequest(val host: String, val port: Int, val username: String, val password: String)
*
* val body = decode<ProxyRequest>(it.content)
*
* if (body.host.isBlank())
* return@post httpForbidden("No host")
*
* if (body.port <= 0)
* return@post httpForbidden("No port")
*
* ProxyManager.setProxy(body.host, body.port, body.username, body.password)
*
* httpOk(JsonObject())
* }
*
* delete("/proxy") {
* ProxyManager.unsetProxy()
* httpOk(JsonObject())
* }
* }
*/
// get("/proxy") {
// val proxyObject = JsonObject()
//
// ProxyManager.currentProxy?.let {
// proxyObject.addProperty("host", it.host)
// proxyObject.addProperty("port", it.port)
// proxyObject.addProperty("username", it.credentials?.username)
// proxyObject.addProperty("password", it.credentials?.password)
// }
//
// httpOk(proxyObject)
// }
//
// delete("/proxy") {
// ProxyManager.unsetProxy()
// httpOk(JsonObject())
// }
//
// get("/proxies") {
// val proxiesArray = JsonArray()
//
// ProxyManager.proxies.forEachIndexed { index, proxy ->
// val proxyObject = JsonObject()
// proxyObject.addProperty("id", index)
// proxyObject.addProperty("host", proxy.host)
// proxyObject.addProperty("port", proxy.port)
// proxyObject.addProperty("username", proxy.credentials?.username)
// proxyObject.addProperty("password", proxy.credentials?.password)
// proxiesArray.add(proxyObject)
// }
//
// httpOk(proxiesArray)
// }
//
// post("/proxies") {
// data class ProxyRequest(val host: String, val port: Int, val username: String, val password: String)
//
// val body = decode<ProxyRequest>(it.content)
//
// if (body.host.isBlank()) {
// return@post httpForbidden("No host")
// }
//
// if (body.port <= 0) {
// return@post httpForbidden("No port")
// }
//
// ProxyManager.addProxy(body.host, body.port, body.username, body.password)
// httpOk(JsonObject())
// }
//
// delete("/proxies") {
// data class ProxyRequest(val id: Int)
// val body = decode<ProxyRequest>(it.content)
//
// if (body.id < 0 || body.id >= ProxyManager.proxies.size) {
// return@delete httpForbidden("Invalid id")
// }
//
// ProxyManager.removeProxy(body.id)
// httpOk(JsonObject())
// }
//
// put("/proxies") {
// data class ProxyRequest(val id: Int)
// val body = decode<ProxyRequest>(it.content)
//
// if (body.id < 0 || body.id >= ProxyManager.proxies.size) {
// return@put httpForbidden("Invalid id")
// }
//
// ProxyManager.setProxy(body.id)
// httpOk(JsonObject())
// }
export function getProxy() {
return request("/proxy")
}
export function setProxy(host, port, username, password) {
export function unsetProxy() {
return request("/proxy", {
method: "DELETE",
headers: {
"Content-Type": "application/json"
}
})
}
export function getProxies() {
return request("/proxies")
}
export function addProxy(proxy) {
return request("/proxies", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ "host": host, "port": port, "username": username, "password": password })
body: JSON.stringify({ "host": proxy.host, "port": proxy.port, "username": proxy.username, "password": proxy.password })
})
}
export function unsetProxy() {
return request("/proxy", {
export function removeProxy(id) {
return request("/proxies", {
method: "DELETE",
headers: {
"Content-Type": "application/json"
}
},
body: JSON.stringify({ "id": id })
})
}
export function setProxy(id) {
return request("/proxies", {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ "id": id })
})
}
export function getPersistentStorage(key) {
const searchParams = new URLSearchParams({ key })
Expand Down

0 comments on commit a061b4d

Please sign in to comment.