mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] RemoteControlModule
This commit is contained in:
parent
6127e92ce5
commit
afc84ebae8
7 changed files with 71 additions and 14 deletions
|
@ -1,4 +1,5 @@
|
|||
# GravitLauncher GitConvention #
|
||||
|
||||
Цель конвенции — внедрить простые, прозрачные и эффективные правила работы с Git.
|
||||
|
||||
Разработка GravitLauncher идёт на базе [Git Flow](https://leanpub.com/git-flow/read). Подробности ниже.
|
||||
|
@ -14,12 +15,15 @@
|
|||
| **bugfix-*** | Исправляет баг нового функционала | **release** | *bugfix-auth* |
|
||||
| **feature-*** | Добавляет новую возможность | **develop** | *feature-auth* |
|
||||
| **hotfix-*** | Вносит срочное исправление для production-а | **master** | *hotfix-auth* |
|
||||
|
||||
-----
|
||||
![Image of GitFlow](https://i.ytimg.com/vi/w2r0oLFtXAw/maxresdefault.jpg)
|
||||
-----
|
||||
|
||||
## Коммиты ##
|
||||
|
||||
**Основные правила:**
|
||||
|
||||
1. Все коммиты должны быть на русском языке.
|
||||
2. Запрещено использовать прошедшее время.
|
||||
3. Обязательно должен быть использован префикс.
|
||||
|
@ -27,6 +31,7 @@
|
|||
5. Длина любой части не должна превышать 100 символов.
|
||||
|
||||
**Структура:**
|
||||
|
||||
```
|
||||
[Префикс] <Сообщение>
|
||||
```
|
||||
|
|
|
@ -11,6 +11,7 @@ public class PingServerManager {
|
|||
public static final long REPORT_EXPIRED_TIME = 20 * 1000;
|
||||
public final Map<String, ServerInfoEntry> map = new HashMap<>();
|
||||
private final LaunchServer server;
|
||||
|
||||
public PingServerManager(LaunchServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
package pro.gravit.launchserver.socket.handlers;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launchserver.socket.NettyConnectContext;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
|
||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||
|
||||
public class NettyWebAPIHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
|
||||
private static final TreeSet<SeverletPathPair> severletList = new TreeSet<>(Comparator.comparingInt((e) -> -e.key.length()));
|
||||
private final NettyConnectContext context;
|
||||
|
@ -38,7 +51,12 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) thro
|
|||
boolean isNext = true;
|
||||
for (SeverletPathPair pair : severletList) {
|
||||
if (msg.uri().startsWith(pair.key)) {
|
||||
try {
|
||||
pair.callback.handle(ctx, msg, context);
|
||||
} catch (Throwable e) {
|
||||
LogHelper.error(e);
|
||||
ctx.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer("Internal Server Error 500".getBytes())), ctx.voidPromise());
|
||||
}
|
||||
isNext = false;
|
||||
break;
|
||||
}
|
||||
|
@ -52,6 +70,39 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) thro
|
|||
@FunctionalInterface
|
||||
public interface SimpleSeverletHandler {
|
||||
void handle(ChannelHandlerContext ctx, FullHttpRequest msg, NettyConnectContext context) throws Exception;
|
||||
|
||||
default Map<String, String> getParamsFromUri(String uri) {
|
||||
int ind = uri.indexOf("?");
|
||||
if (ind <= 0) {
|
||||
return Map.of();
|
||||
}
|
||||
String sub = uri.substring(ind + 1);
|
||||
String[] result = sub.split("&");
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (int i = 0; i < result.length; ++i) {
|
||||
String c = URLDecoder.decode(result[i], Charset.defaultCharset());
|
||||
int index = c.indexOf("=");
|
||||
if (index <= 0) {
|
||||
continue;
|
||||
}
|
||||
String key = c.substring(0, index);
|
||||
String value = c.substring(index);
|
||||
map.put(key, value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
default FullHttpResponse simpleResponse(HttpResponseStatus status, String body) {
|
||||
return new DefaultFullHttpResponse(HTTP_1_1, status, body != null ? Unpooled.wrappedBuffer(body.getBytes()) : Unpooled.buffer());
|
||||
}
|
||||
|
||||
default FullHttpResponse simpleJsonResponse(HttpResponseStatus status, Object body) {
|
||||
return new DefaultFullHttpResponse(HTTP_1_1, status, body != null ? Unpooled.wrappedBuffer(Launcher.gsonManager.gson.toJson(body).getBytes()) : Unpooled.buffer());
|
||||
}
|
||||
|
||||
default void sendHttpResponse(ChannelHandlerContext ctx, FullHttpResponse response) {
|
||||
ctx.writeAndFlush(response, ctx.voidPromise());
|
||||
}
|
||||
}
|
||||
|
||||
public static class SeverletPathPair {
|
||||
|
|
|
@ -26,6 +26,7 @@ public static class PingServerReport {
|
|||
//Server addional info
|
||||
public double tps; //Server tps
|
||||
public List<UsernameInfo> users;
|
||||
|
||||
public PingServerReport(String name, int maxPlayers, int playersOnline) {
|
||||
this.name = name;
|
||||
this.maxPlayers = maxPlayers;
|
||||
|
|
|
@ -81,8 +81,7 @@ public boolean auth() {
|
|||
for (ClientProfile p : result.profiles) {
|
||||
LogHelper.debug("Get profile: %s", p.getTitle());
|
||||
boolean isFound = false;
|
||||
for(ClientProfile.ServerProfile srv : p.getServers())
|
||||
{
|
||||
for (ClientProfile.ServerProfile srv : p.getServers()) {
|
||||
if (srv != null && srv.name.equals(config.serverName)) {
|
||||
this.serverProfile = srv;
|
||||
this.profile = p;
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit a246b4a966c428e626258b1e295a6c83673ab5a2
|
||||
Subproject commit 8fd133947a9316de7b0abb7980ed0d8cb310e246
|
Loading…
Reference in a new issue