Skip to content

Commit

Permalink
Actual proxy relocation support
Browse files Browse the repository at this point in the history
Before this commit, the ME1312.net public server required a custom build to achieve this.

Now anyone can serve this over SSL and integrate this into their existing websites.
  • Loading branch information
ME1312 committed Mar 7, 2023
1 parent 8fafc04 commit 47bc244
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
14 changes: 7 additions & 7 deletions Artifacts/index.html
Expand Up @@ -4,7 +4,7 @@
<title>ME1312.net Uno</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="//use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet" media="screen">
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet" media="screen">
</head>
<body>
<style>
Expand Down Expand Up @@ -814,7 +814,7 @@
<div class="disconnected" style="display: none;">
<span class="response">You have been disconnected</span><br>
<br>
<button onclick="window.location.replace('https://www.me1312.net/account/setup/eauth/#return=' + encodeURIComponent('http://' + location.hostname+':'+((location.port)?location.port:'80') + '#'));">Reconnect</button>
<button onclick="window.location.replace('https://www.me1312.net/account/setup/eauth/#return=' + encodeURIComponent(location.href.split('#', 2)[0] + '#'));">Reconnect</button>
<br>
<br>
<br>
Expand Down Expand Up @@ -1018,7 +1018,7 @@ <h1>Somebody Wins!</h1>
});

if (window.location.hash.length <= 1) {
window.location.replace("https://www.me1312.net/account/setup/eauth/#return=" + encodeURIComponent("http://" + location.hostname+':'+((location.port)?location.port:'80') + '#'));
window.location.replace("https://www.me1312.net/account/setup/eauth/#return=" + encodeURIComponent(location.href.split('#', 2)[0] + '#'));
} else {
var join = function(data) {
playerJoin(data.player);
Expand Down Expand Up @@ -1392,13 +1392,13 @@ <h1>Somebody Wins!</h1>
$($("div.login div.page form.login").children("input")[0]).prop('disabled', true);
$($("div.login div.page form.login").children("button")[0]).prop('disabled', true);
header.fadeOut(50, function() {
header.html("Connecting to " + location.hostname+':'+((location.port)?location.port:'80'));
header.html("Connecting to " + location.hostname + ((location.port)?':'+location.port:''));
header.fadeIn(50);
})
$("div.login div.page form.login").fadeOut(150, function() {
$($("div.login div.page form.login").children(".response")[0]).html("");
$($($("div.login div.page form.login").parent()).children(".loading")[0]).fadeIn(150, function() {
var connection = new WebSocket("ws://" + location.hostname+':'+((location.port)?location.port:'80') + "/game");
var connection = new WebSocket(((location.protocol == "https:")? "wss://" : "ws://") + location.hostname + ((location.port)?':'+location.port:'') + location.pathname + "game");
connection.onerror = function() {
SubDataClient.sleeplock.disable();
$($($("div.login div.page form.login").parent()).children(".loading")[0]).fadeOut(150, function() {
Expand All @@ -1411,7 +1411,7 @@ <h1>Somebody Wins!</h1>
};
connection.onopen = function() {
header.fadeOut(50, function() {
header.html("Logging into " + location.hostname+':'+((location.port)?location.port:'80'));
header.html("Logging into " + location.hostname + ((location.port)?':'+location.port:''));
$("div.login div.page form.login").children("input")[0].value = "";
header.fadeIn(50, function() {
setTimeout(function() {
Expand Down Expand Up @@ -1440,7 +1440,7 @@ <h1>Somebody Wins!</h1>
});
} else if (data.r == 3) {
connection.close();
window.location.replace("https://www.me1312.net/account/setup/eauth/#return=" + encodeURIComponent("http://" + location.hostname+':'+((location.port)?location.port:'80') + '#'));
window.location.replace("https://www.me1312.net/account/setup/eauth/#return=" + encodeURIComponent(location.href.split('#', 2)[0] + '#'));
} else {
if ((data.r == 4)) {
$($('div.login div.page div.disconnected').children('.response')).html("You are already logged into this server");
Expand Down
1 change: 0 additions & 1 deletion src/net/ME1312/Uno/Network/SubDataServer.java
Expand Up @@ -81,7 +81,6 @@ public SubDataServer(UnoServer server, int port, InetAddress address) throws Exc

@Override
public void initChannel(SocketChannel ch) throws Exception {
Container<Boolean> first = new Container<Boolean>(true);
InetSocketAddress remoteAddress = ch.remoteAddress();
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/net/ME1312/Uno/Network/WebServer.java
Expand Up @@ -36,7 +36,7 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) thro
return;
}
// Send the index page
if ("/".equals(req.uri()) || "/index.html".equals(req.uri())) {
if ("/".equals(req.uri())) {
String page;
if (System.getProperty("webserver.debug", "false").equalsIgnoreCase("true")) {
if (!new File(GalaxiEngine.getInstance().getRuntimeDirectory(), "index.html").exists()) Util.copyFromJar(WebServer.class.getClassLoader(), "net/ME1312/Uno/Library/Files/index.html", new File(GalaxiEngine.getInstance().getRuntimeDirectory(), "index.html").getPath());
Expand Down
12 changes: 3 additions & 9 deletions src/net/ME1312/Uno/UnoCommand.java
Expand Up @@ -263,21 +263,15 @@ public void command(CommandSender sender, String handle, String[] args) {
player.removeCard(id);
}

boolean first = true;
for (String card : args) {
if (first) {
first = false;
continue;
}

card = card.replace(' ', '_').replaceAll("[^A-Za-z0-9_]", "").toUpperCase();
for (int i = 1; i != args.length;) {
String card = args[i++].replace(' ', '_').replaceAll("[^A-Za-z0-9_]", "").toUpperCase();
try {
player.addCard(Card.valueOf(card));
} catch (Exception e) {
server.log.error.println(new InvocationTargetException(e, "Could not find card: " + card));
}
}
if (player.getCards().size() <= 0) player.addCard(Card.YM);
if (player.getCards().size() == 0) player.addCard(Card.W);
player.setPlaying(true);
for (Player other : server.game.getAllPlayers()) {
other.getSubData().sendPacket(new PacketOutUpdateHand(server.game, other));
Expand Down

0 comments on commit 47bc244

Please sign in to comment.