mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-10-01 05:08:08 +02: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
|
JsonParser.parseString(packet.json).asJsonObject.getAsJsonObject("version").get("protocol").asInt
|
||||||
)
|
)
|
||||||
future.complete(ver)
|
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) {
|
override fun disconnect(handler: MinecraftHandler, msg: String) {
|
||||||
|
@ -22,8 +22,7 @@ class ProtocolDetectorHandler(val connectionData: ConnectionData) : ChannelDuple
|
|||||||
if (ctx.channel().remoteAddress() is InetSocketAddress) {
|
if (ctx.channel().remoteAddress() is InetSocketAddress) {
|
||||||
val timeoutRun = ctx.executor().schedule({
|
val timeoutRun = ctx.executor().schedule({
|
||||||
mcLogger.warn(
|
mcLogger.warn(
|
||||||
"Timeout for protocol auto-detection in "
|
"Timeout protocol A.D. " + ctx.channel().remoteAddress()
|
||||||
+ ctx.channel().remoteAddress() + " server"
|
|
||||||
)
|
)
|
||||||
hold = false
|
hold = false
|
||||||
drainQueue(ctx)
|
drainQueue(ctx)
|
||||||
|
@ -63,7 +63,7 @@ class HandshakeState : MinecraftConnectionState {
|
|||||||
|
|
||||||
val playerAddr = handler.data.frontHandler.remoteAddress
|
val playerAddr = handler.data.frontHandler.remoteAddress
|
||||||
mcLogger.info(
|
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: ${
|
" O: ${
|
||||||
frontOnline.toString().substring(0, 1)
|
frontOnline.toString().substring(0, 1)
|
||||||
}) -> ${packet.address}:${packet.port} (${backProto ?: "AUTO"})"
|
}) -> ${packet.address}:${packet.port} (${backProto ?: "AUTO"})"
|
||||||
|
@ -14,10 +14,10 @@ interface MinecraftConnectionState {
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun disconnect(handler: MinecraftHandler, msg: String) {
|
fun disconnect(handler: MinecraftHandler, msg: String) {
|
||||||
mcLogger.info("Disconnected ${handler.remoteAddress}: $msg")
|
mcLogger.info("DC ${handler.remoteAddress}: $msg")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onInactivated(handler: MinecraftHandler) {
|
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)
|
.connect(socketAddr)
|
||||||
.addListener(ChannelFutureListener {
|
.addListener(ChannelFutureListener {
|
||||||
if (it.isSuccess) {
|
if (it.isSuccess) {
|
||||||
mcLogger.info("Connected ${handler.remoteAddress} -> $socketAddr")
|
mcLogger.info("+ ${handler.remoteAddress} -> $socketAddr")
|
||||||
handler.data.backChannel = it.channel() as SocketChannel
|
handler.data.backChannel = it.channel() as SocketChannel
|
||||||
|
|
||||||
val packet = Handshake()
|
val packet = Handshake()
|
||||||
|
@ -24,7 +24,7 @@ class WebLogin : WebState {
|
|||||||
when (obj.getAsJsonPrimitive("action").asString) {
|
when (obj.getAsJsonPrimitive("action").asString) {
|
||||||
"offline_login" -> {
|
"offline_login" -> {
|
||||||
// todo add some spam check
|
// todo add some spam check
|
||||||
val username = obj.get("username").asString
|
val username = obj.get("username").asString.trim()
|
||||||
val uuid = generateOfflinePlayerUuid(username)
|
val uuid = generateOfflinePlayerUuid(username)
|
||||||
|
|
||||||
val token = webClient.server.generateToken(uuid)
|
val token = webClient.server.generateToken(uuid)
|
||||||
@ -33,7 +33,7 @@ class WebLogin : WebState {
|
|||||||
| "username": "$username", "uuid": "$uuid", "token": "$token"}""".trimMargin()
|
| "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" -> {
|
"minecraft_id_login" -> {
|
||||||
val username = obj.get("username").asString
|
val username = obj.get("username").asString
|
||||||
@ -54,10 +54,10 @@ class WebLogin : WebState {
|
|||||||
| "username": "$mcIdUser", "uuid": "$uuid", "token": "$token"}""".trimMargin()
|
| "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 {
|
} else {
|
||||||
webClient.ws.send("""{"action": "login_result", "success": false}""")
|
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" -> {
|
"listen_login_requests" -> {
|
||||||
@ -65,11 +65,11 @@ class WebLogin : WebState {
|
|||||||
val user = webClient.server.loginTokens.getIfPresent(token)
|
val user = webClient.server.loginTokens.getIfPresent(token)
|
||||||
if (user != null && webClient.listenId(user)) {
|
if (user != null && webClient.listenId(user)) {
|
||||||
webClient.ws.send("""{"action": "listen_login_requests_result", "token": "$token", "success": true, "user": "$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 {
|
} else {
|
||||||
webClient.server.loginTokens.invalidate(token)
|
webClient.server.loginTokens.invalidate(token)
|
||||||
webClient.ws.send("""{"action": "listen_login_requests_result", "token": "$token", "success": false}""")
|
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" -> {
|
"unlisten_login_requests" -> {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
navigator.serviceWorker.register("sw.js");
|
||||||
|
|
||||||
// Minecraft.id
|
// Minecraft.id
|
||||||
let urlParams = new URLSearchParams();
|
let urlParams = new URLSearchParams();
|
||||||
window.location.hash.substr(1).split("?").map(it => new URLSearchParams(it).forEach((a, b) => urlParams.append(b, a)));
|
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) {
|
function confirmJoin(hash) {
|
||||||
socket.send(JSON.stringify({action: "session_hash_response", session_hash: 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) {
|
function authNotification(msg, yes, no) {
|
||||||
if ((!pageBlur && !document.hidden) || Notification.permission != "granted") {
|
if ((!pageBlur && !document.hidden) || Notification.permission != "granted") {
|
||||||
if (confirm(msg)) yes(); else no();
|
if (confirm(msg)) yes(); else no();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let notification = new Notification("Click to allow auth impersionation", {
|
let tag = uuid.v4();
|
||||||
|
navigator.serviceWorker.ready.then(r => {
|
||||||
|
r.showNotification("Click to allow auth impersionation", {
|
||||||
body: msg,
|
body: msg,
|
||||||
//actions: [
|
tag: tag,
|
||||||
// {action: "reject", title: "Reject"},
|
actions: [
|
||||||
// {action: "confirm", title: "Confirm"}
|
{action: "reject", title: "Reject"},
|
||||||
//]
|
{action: "confirm", title: "Confirm"}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
notification.onclick = e => {
|
notificationCallbacks[tag] = action => {
|
||||||
e.preventDefault();
|
if (action == "reject") {
|
||||||
if (e.action == "reject") {
|
|
||||||
no();
|
no();
|
||||||
} else if (!e.action || e.action == "confirm") {
|
} else if (!action || action == "confirm") {
|
||||||
yes();
|
yes();
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
notification.close();
|
|
||||||
};
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function handleJoinRequest(parsed) {
|
function handleJoinRequest(parsed) {
|
||||||
authNotification("Allow auth impersonation from VIAaaS instance?\nUsername: " + parsed.user + "\nSession Hash: " + parsed.session_hash + "\nServer Message: '" + parsed.message + "'", () => {
|
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);
|
setInterval(refreshCorsStatus, 10 * 60 * 1000);
|
||||||
refreshCorsStatus();
|
refreshCorsStatus();
|
||||||
|
|
||||||
if (Notification.permission == "default") {
|
|
||||||
Notification.requestPermission();
|
|
||||||
}
|
|
||||||
$("#notificate").on("click", e => Notification.requestPermission());
|
$("#notificate").on("click", e => Notification.requestPermission());
|
||||||
|
|
||||||
connect();
|
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