make server list little better and add passworded joins

This commit is contained in:
RandomityGuy 2024-07-01 00:59:05 +05:30
parent 0c9db3ea58
commit 1706c16540
3 changed files with 113 additions and 16 deletions

View file

@ -64,17 +64,91 @@ class JoinServerGui extends GuiImage {
this.position = new Vector(); this.position = new Vector();
this.extent = new Vector(640, 480); this.extent = new Vector(640, 480);
var passwordPopup = new GuiControl();
passwordPopup.position = new Vector(0, 0);
passwordPopup.extent = new Vector(640, 480);
passwordPopup.horizSizing = Width;
passwordPopup.vertSizing = Height;
var passwordWindow = new GuiImage(ResourceLoader.getResource("data/ui/mp/join/window2.png", ResourceLoader.getImage, this.imageResources).toTile());
passwordWindow.horizSizing = Center;
passwordWindow.vertSizing = Center;
passwordWindow.position = new Vector(144, 199);
passwordWindow.extent = new Vector(508, 202);
passwordPopup.addChild(passwordWindow);
var passwordTitle = new GuiText(markerFelt32);
passwordTitle.position = new Vector(22, 28);
passwordTitle.extent = new Vector(463, 14);
passwordTitle.text.textColor = 0xFFFFFF;
passwordTitle.horizSizing = Center;
passwordTitle.justify = Center;
passwordTitle.text.text = "Password Required";
passwordTitle.text.dropShadow = {
dx: 1,
dy: 1,
alpha: 0.5,
color: 0
};
passwordWindow.addChild(passwordTitle);
var passwordBar = new GuiImage(ResourceLoader.getResource("data/ui/mp/join/textbar.png", ResourceLoader.getImage, this.imageResources).toTile());
passwordBar.position = new Vector(22, 73);
passwordBar.extent = new Vector(463, 47);
passwordWindow.addChild(passwordBar);
var passwordInput = new GuiTextInput(markerFelt24);
passwordInput.position = new Vector(30, 79);
passwordInput.extent = new Vector(447, 38);
passwordInput.horizSizing = Center;
passwordInput.text.textColor = 0;
passwordWindow.addChild(passwordInput);
var passwordCancel = new GuiButton(loadButtonImages("data/ui/mp/join/cancel"));
passwordCancel.position = new Vector(29, 126);
passwordCancel.extent = new Vector(94, 45);
passwordCancel.pressedAction = (e) -> {
passwordInput.text.text = "";
MarbleGame.canvas.popDialog(passwordPopup, false);
}
passwordWindow.addChild(passwordCancel);
var passwordJoin = new GuiButton(loadButtonImages("data/ui/mp/join/join"));
passwordJoin.position = new Vector(385, 126);
passwordJoin.extent = new Vector(94, 45);
passwordWindow.addChild(passwordJoin);
var window = new GuiImage(ResourceLoader.getResource("data/ui/mp/join/window.png", ResourceLoader.getImage, this.imageResources).toTile()); var window = new GuiImage(ResourceLoader.getResource("data/ui/mp/join/window.png", ResourceLoader.getImage, this.imageResources).toTile());
window.horizSizing = Center; window.horizSizing = Center;
window.vertSizing = Center; window.vertSizing = Center;
window.position = new Vector(-60, 5); window.position = new Vector(-60, 5);
window.extent = new Vector(759, 469); window.extent = new Vector(759, 469);
var serverInfoContainer = new GuiControl();
serverInfoContainer.position = new Vector(520, 58);
serverInfoContainer.extent = new Vector(210, 166);
window.addChild(serverInfoContainer);
var serverInfo = new GuiMLText(markerFelt24, mlFontLoader);
serverInfo.position = new Vector(0, 0);
serverInfo.extent = new Vector(210, 166);
serverInfo.text.text = '<p align="center">Select a Server</p>';
serverInfo.text.dropShadow = {
dx: 1,
dy: 1,
alpha: 0.5,
color: 0
};
serverInfo.text.textColor = 0xFFFFFF;
serverInfoContainer.addChild(serverInfo);
var serverListContainer = new GuiControl(); var serverListContainer = new GuiControl();
serverListContainer.position = new Vector(30, 80); serverListContainer.position = new Vector(30, 80);
serverListContainer.extent = new Vector(475, 290); serverListContainer.extent = new Vector(475, 290);
window.addChild(serverListContainer); window.addChild(serverListContainer);
var ourServerList:Array<RemoteServerInfo> = [];
var curSelection = -1; var curSelection = -1;
var serverList = new GuiTextListCtrl(markerFelt18, [], 0xFFFFFF); var serverList = new GuiTextListCtrl(markerFelt18, [], 0xFFFFFF);
serverList.position = new Vector(0, 0); serverList.position = new Vector(0, 0);
@ -83,12 +157,18 @@ class JoinServerGui extends GuiImage {
serverList.textYOffset = -6; serverList.textYOffset = -6;
serverList.onSelectedFunc = (sel) -> { serverList.onSelectedFunc = (sel) -> {
curSelection = sel; curSelection = sel;
if (curSelection == -1) {
serverInfo.text.text = '<p align="center">Select a Server</p><p align="center">or Host your own</p>';
} else {
var server = ourServerList[curSelection];
serverInfo.text.text = '<p align="center">${server.name}</p><p align="center"><font face="MarkerFelt18" color="#DDDDEE">Hosted by ${server.host}</font></p><p align="left">${server.description}</p>';
}
} }
serverListContainer.addChild(serverList); serverListContainer.addChild(serverList);
var serverDisplays = []; var serverDisplays = [];
var ourServerList:Array<RemoteServerInfo> = [];
var platformToString = ["unknown", "pc", "mac", "web", "android"]; var platformToString = ["unknown", "pc", "mac", "web", "android"];
function updateServerListDisplay() { function updateServerListDisplay() {
@ -113,10 +193,7 @@ class JoinServerGui extends GuiImage {
} }
window.addChild(hostBtn); window.addChild(hostBtn);
var joinBtn = new GuiButton(loadButtonImages("data/ui/mp/join/join")); var joinFunc = (password:String) -> {
joinBtn.position = new Vector(628, 379);
joinBtn.extent = new Vector(93, 45);
joinBtn.pressedAction = (e) -> {
if (curSelection != -1) { if (curSelection != -1) {
var selectedServerVersion = ourServerList[curSelection].version; var selectedServerVersion = ourServerList[curSelection].version;
// if (selectedServerVersion != MarbleGame.currentVersion) { // if (selectedServerVersion != MarbleGame.currentVersion) {
@ -135,14 +212,31 @@ class JoinServerGui extends GuiImage {
} }
} }
}, 15000); }, 15000);
Net.joinServer(ourServerList[curSelection].name, "", () -> { Net.joinServer(ourServerList[curSelection].name, password, () -> {
failed = false; failed = false;
Net.remoteServerInfo = ourServerList[curSelection]; Net.remoteServerInfo = ourServerList[curSelection];
}); });
} }
} }
var joinBtn = new GuiButton(loadButtonImages("data/ui/mp/join/join"));
joinBtn.position = new Vector(628, 379);
joinBtn.extent = new Vector(93, 45);
joinBtn.pressedAction = (e) -> {
if (curSelection != -1) {
if (ourServerList[curSelection].passworded) {
MarbleGame.canvas.pushDialog(passwordPopup);
} else {
joinFunc("");
}
}
}
window.addChild(joinBtn); window.addChild(joinBtn);
passwordJoin.pressedAction = (e) -> {
joinFunc(passwordInput.text.text);
}
var refreshing = false; var refreshing = false;
var refreshBtn = new GuiButton(loadButtonImagesExt("data/ui/mp/join/refresh/refresh-1")); var refreshBtn = new GuiButton(loadButtonImagesExt("data/ui/mp/join/refresh/refresh-1"));
refreshBtn.position = new Vector(126, 379); refreshBtn.position = new Vector(126, 379);
@ -196,19 +290,18 @@ class JoinServerGui extends GuiImage {
titleText.text.textColor = 0xFFFFFF; titleText.text.textColor = 0xFFFFFF;
window.addChild(titleText); window.addChild(titleText);
var serverInfoHeader = new GuiText(markerFelt24); var listTitle = new GuiText(markerFelt24);
serverInfoHeader.position = new Vector(520, 58); listTitle.position = new Vector(30, 48);
serverInfoHeader.extent = new Vector(210, 166); listTitle.extent = new Vector(480, 22);
serverInfoHeader.justify = Center; listTitle.text.textColor = 0xDDDDEE;
serverInfoHeader.text.text = "Select a Server"; listTitle.text.dropShadow = {
serverInfoHeader.text.dropShadow = {
dx: 1, dx: 1,
dy: 1, dy: 1,
alpha: 0.5, alpha: 0.5,
color: 0 color: 0
}; };
serverInfoHeader.text.textColor = 0xFFFFFF; listTitle.text.text = " Server Name";
window.addChild(serverInfoHeader); window.addChild(listTitle);
this.addChild(window); this.addChild(window);
} }

View file

@ -11,6 +11,7 @@ import src.Console;
typedef RemoteServerInfo = { typedef RemoteServerInfo = {
name:String, name:String,
host:String,
description:String, description:String,
players:Int, players:Int,
maxPlayers:Int, maxPlayers:Int,
@ -212,6 +213,7 @@ class MasterServerClient {
queueMessage(Json.stringify({ queueMessage(Json.stringify({
type: "serverInfo", type: "serverInfo",
name: serverInfo.name, name: serverInfo.name,
host: serverInfo.hostname,
description: serverInfo.description, description: serverInfo.description,
players: serverInfo.players, players: serverInfo.players,
maxPlayers: serverInfo.maxPlayers, maxPlayers: serverInfo.maxPlayers,

View file

@ -46,6 +46,7 @@ enum abstract NetPacketType(Int) from Int to Int {
@:publicFields @:publicFields
class ServerInfo { class ServerInfo {
var name:String; var name:String;
var hostname:String;
var description:String; var description:String;
var players:Int; var players:Int;
var maxPlayers:Int; var maxPlayers:Int;
@ -53,8 +54,9 @@ class ServerInfo {
var state:String; var state:String;
var platform:NetPlatform; var platform:NetPlatform;
public function new(name:String, description:String, players:Int, maxPlayers:Int, password:String, state:String, platform:NetPlatform) { public function new(name:String, hostname:String, description:String, players:Int, maxPlayers:Int, password:String, state:String, platform:NetPlatform) {
this.name = name; this.name = name;
this.hostname = hostname;
this.description = description; this.description = description;
this.players = players; this.players = players;
this.maxPlayers = maxPlayers; this.maxPlayers = maxPlayers;
@ -103,7 +105,7 @@ class Net {
public static var turnServer:String = ""; public static var turnServer:String = "";
public static function hostServer(name:String, description:String, maxPlayers:Int, password:String, onHosted:() -> Void) { public static function hostServer(name:String, description:String, maxPlayers:Int, password:String, onHosted:() -> Void) {
serverInfo = new ServerInfo(name, description, 1, maxPlayers, password, "LOBBY", getPlatform()); serverInfo = new ServerInfo(name, Settings.highscoreName, description, 1, maxPlayers, password, "LOBBY", getPlatform());
MasterServerClient.connectToMasterServer(() -> { MasterServerClient.connectToMasterServer(() -> {
isHost = true; isHost = true;
isClient = false; isClient = false;