Skip to content

Commit

Permalink
Updated GalaxiEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Mar 7, 2023
1 parent 618e8bd commit 8fafc04
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 170 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ME1312.net Uno
[![Build Status](https://dev.me1312.net/jenkins/job/ME1312.net%20Uno/badge/icon)](https://dev.me1312.net/jenkins/job/ME1312.net%20Uno/)<br><br>
[![Build Status](https://dev.me1312.net/jenkins/job/ME1312.net%20Uno/badge/icon)](https://dev.me1312.net/jenkins/job/ME1312.net%20Uno/)
[![Snapshot Verison](https://img.shields.io/badge/dynamic/xml.svg?label=snapshot&url=https%3A%2F%2Fdev.me1312.net%2Fjenkins%2Fjob%2FME1312.net%2520Uno%2FlastSuccessfulBuild%2Fapi%2Fxml&query=%2F%2FdisplayName&colorB=blue)](https://dev.me1312.net/jenkins/job/ME1312.net%20Uno/)<br><br>
This is the server program for a game of Uno launched through ME1312.net
> [https://www.me1312.net/uno](https://www.me1312.net/uno)<br>
Expand Down
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>19w39b</version>
<version>23w10a</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUI</artifactId>
<version>23w10a</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.42.Final</version>
<version>4.1.89.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/net/ME1312/Uno/Game/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.util.List;
import java.util.Random;

import static net.ME1312.Uno.Game.CardColor.*;
import static net.ME1312.Uno.Game.CardAction.*;
import static net.ME1312.Uno.Game.CardColor.*;

public enum Card {
// Red 0-9
Expand Down
11 changes: 6 additions & 5 deletions src/net/ME1312/Uno/Game/Game.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.ME1312.Uno.Game;

import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Log.Logger;
import net.ME1312.Uno.Network.Packet.*;
import net.ME1312.Uno.UnoServer;

import org.json.JSONObject;

import java.util.*;
Expand Down Expand Up @@ -265,7 +266,7 @@ public void play(String id) {
if (canplay) {
Player player = players.get(currentPlayer);
boolean canplay = false;
if (player.getCards().keySet().contains(id)) {
if (player.getCards().containsKey(id)) {
if (stackmode) {
if (player.getCard(id).getNumber() == 12 || player.getCard(id) == Card.WD4 || player.getCard(id) == Card.WD8)
canplay = true;
Expand Down Expand Up @@ -636,8 +637,8 @@ public void quit(Player player) {
spectators.remove(player);
}

public NamedContainer<CardColor, Integer> getCurrentCard() {
return new NamedContainer<>(lastCardColor, lastCardNumber);
public ContainedPair<CardColor, Integer> getCurrentCard() {
return new ContainedPair<>(lastCardColor, lastCardNumber);
}

public Player getCurrentPlayer() {
Expand Down
4 changes: 2 additions & 2 deletions src/net/ME1312/Uno/Game/Player.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.ME1312.Uno.Game;

import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Uno.Network.Client;
import net.ME1312.Uno.Network.ClientHandler;
import net.ME1312.Uno.Network.Packet.PacketOutAddCard;
import net.ME1312.Uno.Network.Packet.PacketOutAlert;
import net.ME1312.Uno.Network.Packet.PacketOutPlayerQuit;
import net.ME1312.Uno.UnoServer;

import org.json.JSONObject;

import java.io.*;
Expand Down Expand Up @@ -52,7 +52,7 @@ public JSONObject getProfile() {
}

public JSONObject getStats() {
UniversalFile file = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Stats:" + profile.getLong("id") + ".json");
File file = new File(GalaxiEngine.getInstance().getRuntimeDirectory(), "Stats/" + profile.getLong("id") + ".json");
JSONObject stats = new JSONObject();
if (file.exists()) {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/net/ME1312/Uno/Library/Gzip.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.ME1312.Uno.Library;

import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

/**
* Gzip Utility Class
Expand Down
66 changes: 0 additions & 66 deletions src/net/ME1312/Uno/Library/TextColor.java

This file was deleted.

11 changes: 7 additions & 4 deletions src/net/ME1312/Uno/Network/Client.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package net.ME1312.Uno.Network;

import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Uno.Library.Exception.IllegalPacketException;
import net.ME1312.Uno.Network.Packet.PacketAuthorization;
import net.ME1312.Uno.Network.Packet.PacketMessage;

import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.json.JSONException;
import org.json.JSONObject;
import org.yaml.snakeyaml.error.YAMLException;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
* Network Client Class
Expand Down
13 changes: 7 additions & 6 deletions src/net/ME1312/Uno/Network/Packet/PacketAuthorization.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package net.ME1312.Uno.Network.Packet;

import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.Galaxi.Log.Logger;
import net.ME1312.Uno.Game.Player;
import net.ME1312.Uno.Library.Gzip;
import net.ME1312.Uno.Network.Client;
import net.ME1312.Uno.Network.PacketIn;
import net.ME1312.Uno.Network.PacketOut;
import net.ME1312.Uno.Network.SubDataServer;
import net.ME1312.Uno.UnoServer;

import org.json.JSONObject;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -65,22 +66,22 @@ public ObjectMap<String> generate() {
@Override
public void execute(Client client, ObjectMap<String> data) {
try {
if (data.getRawString("password").equals(server.config.get().getMap("Settings").getMap("SubData").getRawString("Password"))) {
URLConnection request = new URL("https://www.me1312.net/account/auth.php?token=" + data.getRawString("profile")).openConnection();
if (data.getString("password").equals(server.config.get().getMap("Settings").getMap("SubData").getString("Password"))) {
URLConnection request = new URL("https://www.me1312.net/account/auth.php?token=" + data.getString("profile")).openConnection();
request.addRequestProperty("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
request.addRequestProperty("accept-encoding", "gzip, deflate, b");
request.addRequestProperty("accept-language", "en-US,en;q=0.9");
request.addRequestProperty("cache-control", "no-cache");
request.addRequestProperty("cookie", "");
request.addRequestProperty("upgrade-insecure-requests", "1");
request.addRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
request.addRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36");
request.connect();
JSONObject auth = new JSONObject(Gzip.ungzip(request.getInputStream()));
if (auth.getString("error").length() == 0) {
if (!server.players.keySet().contains(auth.getJSONObject("profile").getString("name")) || server.players.get(auth.getJSONObject("profile").getString("name")).getSubData() == null) {
if (!server.players.containsKey(auth.getJSONObject("profile").getString("name")) || server.players.get(auth.getJSONObject("profile").getString("name")).getSubData() == null) {
client.authorize(auth.getJSONObject("profile"));
Player player;
if (server.players.keySet().contains(auth.getJSONObject("profile").getString("name"))) {
if (server.players.containsKey(auth.getJSONObject("profile").getString("name"))) {
player = server.players.get(auth.getJSONObject("profile").getString("name"));
} else {
player = new Player(server, auth.getJSONObject("profile"));
Expand Down
2 changes: 1 addition & 1 deletion src/net/ME1312/Uno/Network/Packet/PacketInCallOut.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public PacketInCallOut(UnoServer server) {
@Override
public void execute(Client client, ObjectMap<String> data) throws Throwable {
if (server.game != null && client.getHandler() instanceof Player && ((Player) client.getHandler()).isPlaying()) {
server.game.callout((Player) client.getHandler(), server.players.get(data.getRawString("player")));
server.game.callout((Player) client.getHandler(), server.players.get(data.getString("player")));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/net/ME1312/Uno/Network/Packet/PacketMessage.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.ME1312.Uno.Network.Packet;

import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.Galaxi.Log.Logger;
import net.ME1312.Uno.Game.Player;
import net.ME1312.Uno.Network.Client;
import net.ME1312.Uno.Network.PacketIn;
Expand All @@ -27,9 +27,9 @@ public PacketMessage(Player player, String message) {
@Override
public void execute(Client client, ObjectMap<String> data) throws Throwable {
if (client.getHandler() instanceof Player) {
log.info.println(((Player) client.getHandler()).getProfile().getString("displayName") + " > " + data.getRawString("message"));
log.info.println(((Player) client.getHandler()).getProfile().getString("displayName") + " > " + data.getString("message"));
for (Client other : server.subdata.getClients()) {
if (other.isAuthorized()) other.sendPacket(new PacketMessage((Player) client.getHandler(), data.getRawString("message")));
if (other.isAuthorized()) other.sendPacket(new PacketMessage((Player) client.getHandler(), data.getString("message")));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/net/ME1312/Uno/Network/Packet/PacketOutPlayerJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.Uno.Game.Player;
import net.ME1312.Uno.Network.PacketOut;

import org.json.JSONObject;

public class PacketOutPlayerJoin implements PacketOut {
Expand Down
4 changes: 2 additions & 2 deletions src/net/ME1312/Uno/Network/Packet/PacketOutStartGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public ObjectMap<String> generate() throws Throwable {
info.set("cards", cardlist);
}
ObjectMap<String> cardinfo = new ObjectMap<String>();
cardinfo.set("color", game.getCurrentCard().name().toString());
cardinfo.set("number", game.getCurrentCard().get());
cardinfo.set("color", game.getCurrentCard().key.toString());
cardinfo.set("number", game.getCurrentCard().value);
info.set("houseCard", cardinfo);
return info;
}
Expand Down
3 changes: 2 additions & 1 deletion src/net/ME1312/Uno/Network/Packet/PacketPlayerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.ME1312.Uno.Network.PacketIn;
import net.ME1312.Uno.Network.PacketOut;
import net.ME1312.Uno.UnoServer;

import org.json.JSONObject;

import java.math.BigInteger;
Expand All @@ -27,7 +28,7 @@ public PacketPlayerList(UnoServer server, String id) {

@Override
public void execute(Client client, ObjectMap<String> data) throws Throwable {
client.sendPacket(new PacketPlayerList(server, (data.contains("id"))?data.getRawString("id"):null));
client.sendPacket(new PacketPlayerList(server, (data.contains("id"))?data.getString("id"):null));
}

@Override
Expand Down

0 comments on commit 8fafc04

Please sign in to comment.