mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 00:59:44 +03:00
[FEATURE] AddLogListener
This commit is contained in:
parent
dd586f23eb
commit
0fcb3fd5e4
4 changed files with 68 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
import ru.gravit.launcher.ClientPermissions;
|
||||
import ru.gravit.launcher.profiles.ClientProfile;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class Client {
|
||||
public long session;
|
||||
|
@ -13,6 +14,7 @@ public class Client {
|
|||
public boolean checkSign;
|
||||
public ClientPermissions permissions;
|
||||
public String username;
|
||||
public LogHelper.Output logOutput;
|
||||
|
||||
public Client(long session) {
|
||||
this.session = session;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
import ru.gravit.launchserver.socket.websocket.json.EchoResponse;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseAdapter;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
import ru.gravit.launchserver.socket.websocket.json.admin.AddLogListenerResponse;
|
||||
import ru.gravit.launchserver.socket.websocket.json.auth.*;
|
||||
import ru.gravit.launchserver.socket.websocket.json.update.LauncherResponse;
|
||||
import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse;
|
||||
|
@ -76,6 +77,7 @@ public void registerResponses() {
|
|||
registerResponse("updateList", UpdateListResponse.class);
|
||||
registerResponse("cmdExec", UpdateListResponse.class);
|
||||
registerResponse("setProfile", SetProfileResponse.class);
|
||||
registerResponse("addLogListener", AddLogListenerResponse.class);
|
||||
}
|
||||
|
||||
public void sendObject(ChannelHandlerContext ctx, Object obj) {
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package ru.gravit.launchserver.socket.websocket.json.admin;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import ru.gravit.launcher.events.request.ErrorRequestEvent;
|
||||
import ru.gravit.launcher.events.request.LogEvent;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class AddLogListenerResponse implements JsonResponseInterface {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "addLogListener";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||
if (!client.isAuth) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent("Access denied"));
|
||||
return;
|
||||
}
|
||||
if (!client.permissions.canAdmin) {
|
||||
service.sendObject(ctx, new ErrorRequestEvent("Access denied"));
|
||||
return;
|
||||
}
|
||||
if(client.logOutput != null)
|
||||
{
|
||||
LogHelper.info("Client %s remove log listener", client.username);
|
||||
LogHelper.removeOutput(client.logOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.info("Client %s add log listener", client.username);
|
||||
LogHelper.Output output = (str) -> {
|
||||
if(!ctx.isRemoved())
|
||||
{
|
||||
service.sendObject(ctx,new LogEvent(str));
|
||||
}
|
||||
else {
|
||||
LogHelper.info("Client %s remove log listener", client.username);
|
||||
LogHelper.removeOutput(client.logOutput);
|
||||
}
|
||||
};
|
||||
client.logOutput = output;
|
||||
LogHelper.addOutput(output);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package ru.gravit.launcher.events.request;
|
||||
|
||||
import ru.gravit.launcher.request.ResultInterface;
|
||||
|
||||
public class LogEvent implements ResultInterface {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "log";
|
||||
}
|
||||
public String string;
|
||||
|
||||
public LogEvent(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue