Add Command SetLevel (#8)

* Add Remote Command API (Use KEY)

* Clean up HttpServer by removing unused code

Removed commented-out code

* Add SetLevel Command (need to restart the game for it to take effect)

* Add Proto Request Change Level (Not Work)

* Update setlevel command

---------

Co-authored-by: Melledy <121644117+Melledy@users.noreply.github.com>
This commit is contained in:
RaidenShogun503
2025-11-27 10:45:45 +07:00
committed by GitHub
parent 2acd506245
commit 6d9e28963d
7 changed files with 58 additions and 10 deletions

1
.gitignore vendored
View File

@@ -47,6 +47,7 @@ tmp/
*~.nib *~.nib
.loadpath .loadpath
.recommenders .recommenders
./StellaSoraData
# VSCode # VSCode
.vscode .vscode

1
StellaSoraData Submodule

Submodule StellaSoraData added at bb5ed8a3fd

View File

@@ -0,0 +1,41 @@
package emu.nebula.command.commands;
import emu.nebula.command.Command;
import emu.nebula.command.CommandArgs;
import emu.nebula.command.CommandHandler;
import emu.nebula.data.GameData;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.NotifyGm.GmWorldClass;
import emu.nebula.util.Utils;
@Command(label = "setlevel", aliases = {"level", "l"}, permission = "player.level", requireTarget = true, desc = "/level [level]. Set player level")
public class SetLevelCommand implements CommandHandler {
@Override
public String execute(CommandArgs args) {
// Get target
var target = args.getTarget();
// Parse level
int level = Utils.parseSafeInt(args.get(0));
// Check to make sure world class data exists for this level
var data = GameData.getWorldClassDataTable().get(level);
if (data == null) {
return "The game does not support level " + level;
}
target.setLevel(level);
target.setExp(0);
// Update
target.addNextPackage(
NetMsgId.world_class_number_notify,
GmWorldClass.newInstance()
.setFinalClass(target.getLevel())
.setLastExp(target.getExp())
);
return "Level set to " + level;
}
}

View File

@@ -202,6 +202,16 @@ public class Player implements GameDatabaseObject {
return this.session != null; return this.session != null;
} }
public void setLevel(int level) {
this.level = level;
Nebula.getGameDatabase().update(this, this.getUid(), "level", this.level);
}
public void setExp(int exp) {
this.exp = exp;
Nebula.getGameDatabase().update(this, this.getUid(), "exp", this.exp);
}
public void setRemoteToken(String token) { public void setRemoteToken(String token) {
// Skip if tokens are the same // Skip if tokens are the same
if (this.remoteToken == null) { if (this.remoteToken == null) {

View File

@@ -163,14 +163,9 @@ public class HttpServer {
// https://nova-static.stellasora.global/ // https://nova-static.stellasora.global/
getApp().get("/meta/serverlist.html", new MetaServerlistHandler(this)); getApp().get("/meta/serverlist.html", new MetaServerlistHandler(this));
getApp().get("/meta/win.html", new MetaWinHandler(this)); getApp().get("/meta/win.html", new MetaWinHandler(this));
// if (!Nebula.getConfig().getRemoteCommand().useRemoteServices) {
// getApp().post("/api/command", new RemoteHandler());
// }
getApp().post("/api/command", new RemoteHandler()); getApp().post("/api/command", new RemoteHandler());
// getApp.get("/notice/noticelist.html");
getApp().get("/webchatv3/*", ctx -> {
ctx.redirect("https://google.com");
});
} }