forked from Melledy/LunarCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add http status request and display html (Melledy#86)
* add http status request * add maxplayer value * add http status request * add http status request * maxPlayers limit * maxPlayers limit
- Loading branch information
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/emu/lunarcore/server/http/handlers/StatusServerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package emu.lunarcore.server.http.handlers; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import emu.lunarcore.GameConstants; | ||
import emu.lunarcore.LunarCore; | ||
|
||
import io.javalin.http.Context; | ||
import io.javalin.http.Handler; | ||
|
||
public class StatusServerHandler implements Handler { | ||
|
||
@Override | ||
public void handle(@NotNull Context ctx) throws Exception { | ||
int playerCount = LunarCore.getGameServer().getPlayerCount(); | ||
int maxPlayers = LunarCore.getConfig().getServerOptions().maxPlayers; | ||
String version = GameConstants.VERSION; | ||
String responseJson = String.format( | ||
"{\"retcode\":0,\"status\":{\"playerCount\":%d,\"maxPlayers\":%d,\"version\":\"%s\"}}", | ||
playerCount, maxPlayers, version | ||
); | ||
ctx.status(200); | ||
ctx.contentType("application/json"); | ||
ctx.result(responseJson); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters