mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-11-04 09:30:00 +01:00
shorter msg, serviceworker
This commit is contained in:
parent
5213c0f91d
commit
957a306d6e
@ -23,7 +23,7 @@ class ProtocolDetectionState(val future: CompletableFuture<ProtocolVersion>) : M
|
||||
JsonParser.parseString(packet.json).asJsonObject.getAsJsonObject("version").get("protocol").asInt
|
||||
)
|
||||
future.complete(ver)
|
||||
mcLogger.info("Auto-detected $ver for ${handler.remoteAddress}")
|
||||
mcLogger.info("A.D.: ${handler.remoteAddress} $ver")
|
||||
}
|
||||
|
||||
override fun disconnect(handler: MinecraftHandler, msg: String) {
|
||||
@ -34,4 +34,4 @@ class ProtocolDetectionState(val future: CompletableFuture<ProtocolVersion>) : M
|
||||
override fun onInactivated(handler: MinecraftHandler) {
|
||||
future.completeExceptionally(ClosedChannelException())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,7 @@ class ProtocolDetectorHandler(val connectionData: ConnectionData) : ChannelDuple
|
||||
if (ctx.channel().remoteAddress() is InetSocketAddress) {
|
||||
val timeoutRun = ctx.executor().schedule({
|
||||
mcLogger.warn(
|
||||
"Timeout for protocol auto-detection in "
|
||||
+ ctx.channel().remoteAddress() + " server"
|
||||
"Timeout protocol A.D. " + ctx.channel().remoteAddress()
|
||||
)
|
||||
hold = false
|
||||
drainQueue(ctx)
|
||||
@ -87,4 +86,4 @@ class ProtocolDetectorHandler(val connectionData: ConnectionData) : ChannelDuple
|
||||
drainQueue(ctx)
|
||||
super.handlerRemoved(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class HandshakeState : MinecraftConnectionState {
|
||||
|
||||
val playerAddr = handler.data.frontHandler.remoteAddress
|
||||
mcLogger.info(
|
||||
"Handshake: ${handler.data.state.state} $playerAddr (${handler.data.frontVer}," +
|
||||
"HS: $playerAddr (P: ${handler.data.frontVer}, S: ${handler.data.state.state.toString().substring(0, 1)}" +
|
||||
" O: ${
|
||||
frontOnline.toString().substring(0, 1)
|
||||
}) -> ${packet.address}:${packet.port} (${backProto ?: "AUTO"})"
|
||||
|
@ -14,10 +14,10 @@ interface MinecraftConnectionState {
|
||||
)
|
||||
|
||||
fun disconnect(handler: MinecraftHandler, msg: String) {
|
||||
mcLogger.info("Disconnected ${handler.remoteAddress}: $msg")
|
||||
mcLogger.info("DC ${handler.remoteAddress}: $msg")
|
||||
}
|
||||
|
||||
fun onInactivated(handler: MinecraftHandler) {
|
||||
mcLogger.info(handler.remoteAddress.toString() + " inactivated")
|
||||
mcLogger.info("- ${handler.remoteAddress}")
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ private fun createBackChannel(handler: MinecraftHandler, socketAddr: InetSocketA
|
||||
.connect(socketAddr)
|
||||
.addListener(ChannelFutureListener {
|
||||
if (it.isSuccess) {
|
||||
mcLogger.info("Connected ${handler.remoteAddress} -> $socketAddr")
|
||||
mcLogger.info("+ ${handler.remoteAddress} -> $socketAddr")
|
||||
handler.data.backChannel = it.channel() as SocketChannel
|
||||
|
||||
val packet = Handshake()
|
||||
@ -105,4 +105,4 @@ fun connectBack(handler: MinecraftHandler, address: String, port: Int, state: St
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class WebLogin : WebState {
|
||||
when (obj.getAsJsonPrimitive("action").asString) {
|
||||
"offline_login" -> {
|
||||
// todo add some spam check
|
||||
val username = obj.get("username").asString
|
||||
val username = obj.get("username").asString.trim()
|
||||
val uuid = generateOfflinePlayerUuid(username)
|
||||
|
||||
val token = webClient.server.generateToken(uuid)
|
||||
@ -33,7 +33,7 @@ class WebLogin : WebState {
|
||||
| "username": "$username", "uuid": "$uuid", "token": "$token"}""".trimMargin()
|
||||
)
|
||||
|
||||
webLogger.info("${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost}) generated a token for offline account $username")
|
||||
webLogger.info("Token gen: ${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost}): offline $username")
|
||||
}
|
||||
"minecraft_id_login" -> {
|
||||
val username = obj.get("username").asString
|
||||
@ -54,10 +54,10 @@ class WebLogin : WebState {
|
||||
| "username": "$mcIdUser", "uuid": "$uuid", "token": "$token"}""".trimMargin()
|
||||
)
|
||||
|
||||
webLogger.info("${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost}) generated a token for account $mcIdUser $uuid")
|
||||
webLogger.info("Token gen: ${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost}): $mcIdUser $uuid")
|
||||
} else {
|
||||
webClient.ws.send("""{"action": "login_result", "success": false}""")
|
||||
webLogger.info("${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost}) failed to generated a token for account $username")
|
||||
webLogger.info("Token gen fail: ${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost}): $username")
|
||||
}
|
||||
}
|
||||
"listen_login_requests" -> {
|
||||
@ -65,11 +65,11 @@ class WebLogin : WebState {
|
||||
val user = webClient.server.loginTokens.getIfPresent(token)
|
||||
if (user != null && webClient.listenId(user)) {
|
||||
webClient.ws.send("""{"action": "listen_login_requests_result", "token": "$token", "success": true, "user": "$user"}""")
|
||||
webLogger.info("${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost}) listening for logins for $user")
|
||||
webLogger.info("Listen: ${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost}): $user")
|
||||
} else {
|
||||
webClient.server.loginTokens.invalidate(token)
|
||||
webClient.ws.send("""{"action": "listen_login_requests_result", "token": "$token", "success": false}""")
|
||||
webLogger.info("${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost}) failed token")
|
||||
webLogger.info("Token fail: ${webClient.ws.call.request.local.remoteHost} (O: ${webClient.ws.call.request.origin.remoteHost})")
|
||||
}
|
||||
}
|
||||
"unlisten_login_requests" -> {
|
||||
@ -96,4 +96,4 @@ class WebLogin : WebState {
|
||||
|
||||
override suspend fun onException(webClient: WebClient, exception: java.lang.Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
navigator.serviceWorker.register("sw.js");
|
||||
|
||||
// Minecraft.id
|
||||
let urlParams = new URLSearchParams();
|
||||
window.location.hash.substr(1).split("?").map(it => new URLSearchParams(it).forEach((a, b) => urlParams.append(b, a)));
|
||||
@ -286,29 +288,40 @@ function listen(token) {
|
||||
function confirmJoin(hash) {
|
||||
socket.send(JSON.stringify({action: "session_hash_response", session_hash: hash}));
|
||||
}
|
||||
var notificationCallbacks = {};
|
||||
function handleSWMsg(event) {
|
||||
console.log("sw msg: " + event);
|
||||
let data = event.data;
|
||||
let callback = notificationCallbacks[data.tag];
|
||||
if (callback == null) return;
|
||||
callback(data.action);
|
||||
}
|
||||
navigator.serviceWorker.addEventListener("message", handleSWMsg);
|
||||
function authNotification(msg, yes, no) {
|
||||
if ((!pageBlur && !document.hidden) || Notification.permission != "granted") {
|
||||
if (confirm(msg)) yes(); else no();
|
||||
return;
|
||||
}
|
||||
let notification = new Notification("Click to allow auth impersionation", {
|
||||
body: msg,
|
||||
//actions: [
|
||||
// {action: "reject", title: "Reject"},
|
||||
// {action: "confirm", title: "Confirm"}
|
||||
//]
|
||||
let tag = uuid.v4();
|
||||
navigator.serviceWorker.ready.then(r => {
|
||||
r.showNotification("Click to allow auth impersionation", {
|
||||
body: msg,
|
||||
tag: tag,
|
||||
actions: [
|
||||
{action: "reject", title: "Reject"},
|
||||
{action: "confirm", title: "Confirm"}
|
||||
]
|
||||
});
|
||||
notificationCallbacks[tag] = action => {
|
||||
if (action == "reject") {
|
||||
no();
|
||||
} else if (!action || action == "confirm") {
|
||||
yes();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
};
|
||||
});
|
||||
notification.onclick = e => {
|
||||
e.preventDefault();
|
||||
if (e.action == "reject") {
|
||||
no();
|
||||
} else if (!e.action || e.action == "confirm") {
|
||||
yes();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
notification.close();
|
||||
};
|
||||
}
|
||||
function handleJoinRequest(parsed) {
|
||||
authNotification("Allow auth impersonation from VIAaaS instance?\nUsername: " + parsed.user + "\nSession Hash: " + parsed.session_hash + "\nServer Message: '" + parsed.message + "'", () => {
|
||||
@ -398,9 +411,6 @@ $(() => {
|
||||
setInterval(refreshCorsStatus, 10 * 60 * 1000);
|
||||
refreshCorsStatus();
|
||||
|
||||
if (Notification.permission == "default") {
|
||||
Notification.requestPermission();
|
||||
}
|
||||
$("#notificate").on("click", e => Notification.requestPermission());
|
||||
|
||||
connect();
|
||||
|
6
src/main/resources/web/sw.js
Normal file
6
src/main/resources/web/sw.js
Normal file
@ -0,0 +1,6 @@
|
||||
self.addEventListener("notificationclick", event => {
|
||||
console.log("On notification click: ", event);
|
||||
event.preventDefault();
|
||||
event.notification.close();
|
||||
self.clients.matchAll({type: "window"}).then(it => it.forEach(c => c.postMessage({tag: event.notification.tag, action: event.action})));
|
||||
});
|
Loading…
Reference in New Issue
Block a user