diff --git a/Server/.idea/artifacts/Server_jar.xml b/Server/.idea/artifacts/Server_jar.xml deleted file mode 100644 index a469dd7..0000000 --- a/Server/.idea/artifacts/Server_jar.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - $PROJECT_DIR$/out/artifacts/Server_jar - - - - - \ No newline at end of file diff --git a/Server/.idea/misc.xml b/Server/.idea/misc.xml deleted file mode 100644 index 0e05be0..0000000 --- a/Server/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Server/.idea/modules.xml b/Server/.idea/modules.xml deleted file mode 100644 index 7ec00e1..0000000 --- a/Server/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Server/.idea/vcs.xml b/Server/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/Server/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Server/.idea/workspace.xml b/Server/.idea/workspace.xml deleted file mode 100644 index 86fa9ef..0000000 --- a/Server/.idea/workspace.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - { - "keyToString": { - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "WebServerToolWindowFactoryState": "false", - "last_opened_file_path": "C:/flufflparty/Server", - "node.js.detected.package.eslint": "true", - "node.js.detected.package.tslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "node.js.selected.package.tslint": "(autodetect)", - "project.structure.last.edited": "Artifacts", - "project.structure.proportion": "0.0", - "project.structure.side.proportion": "0.2", - "vue.rearranger.settings.migration": "true" - } -} - - - - - - - - - - - - - - 1674839030210 - - - - - - - - - \ No newline at end of file diff --git a/Server/Server.iml b/Server/Server.iml deleted file mode 100644 index c90834f..0000000 --- a/Server/Server.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/Server/out/artifacts/Server_jar/Server.jar b/Server/out/artifacts/Server_jar/Server.jar deleted file mode 100644 index 753337c..0000000 Binary files a/Server/out/artifacts/Server_jar/Server.jar and /dev/null differ diff --git a/Server/out/production/Server/Client.class b/Server/out/production/Server/Client.class deleted file mode 100644 index c4ff6b8..0000000 Binary files a/Server/out/production/Server/Client.class and /dev/null differ diff --git a/Server/out/production/Server/META-INF/MANIFEST.MF b/Server/out/production/Server/META-INF/MANIFEST.MF deleted file mode 100644 index 5ee19cb..0000000 --- a/Server/out/production/Server/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: Main - diff --git a/Server/out/production/Server/Main.class b/Server/out/production/Server/Main.class deleted file mode 100644 index 69e2ad8..0000000 Binary files a/Server/out/production/Server/Main.class and /dev/null differ diff --git a/Server/out/production/Server/Room$1.class b/Server/out/production/Server/Room$1.class deleted file mode 100644 index 45ff557..0000000 Binary files a/Server/out/production/Server/Room$1.class and /dev/null differ diff --git a/Server/out/production/Server/Room$2.class b/Server/out/production/Server/Room$2.class deleted file mode 100644 index 8ec9296..0000000 Binary files a/Server/out/production/Server/Room$2.class and /dev/null differ diff --git a/Server/out/production/Server/Room.class b/Server/out/production/Server/Room.class deleted file mode 100644 index 91a0473..0000000 Binary files a/Server/out/production/Server/Room.class and /dev/null differ diff --git a/Server/out/production/Server/Server$1.class b/Server/out/production/Server/Server$1.class deleted file mode 100644 index 3bd2f6c..0000000 Binary files a/Server/out/production/Server/Server$1.class and /dev/null differ diff --git a/Server/out/production/Server/Server.class b/Server/out/production/Server/Server.class deleted file mode 100644 index dc4654e..0000000 Binary files a/Server/out/production/Server/Server.class and /dev/null differ diff --git a/Server/out/production/Server/Vector3.class b/Server/out/production/Server/Vector3.class deleted file mode 100644 index f77b642..0000000 Binary files a/Server/out/production/Server/Vector3.class and /dev/null differ diff --git a/Server/src/Client.java b/Server/src/Client.java deleted file mode 100644 index 9aa83af..0000000 --- a/Server/src/Client.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.net.Socket; - -public class Client -{ - public DataOutputStream output; - public DataInputStream input; - public Socket socket; - - public String name; - - public long lastTimeSendTimeOutCheck = -1; - - - public Client(DataOutputStream output, DataInputStream input, Socket socket, String name) - { - this.output = output; - this.input = input; - this.socket = socket; - this.name = name; - } -} diff --git a/Server/src/META-INF/MANIFEST.MF b/Server/src/META-INF/MANIFEST.MF deleted file mode 100644 index 5ee19cb..0000000 --- a/Server/src/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: Main - diff --git a/Server/src/Main.java b/Server/src/Main.java deleted file mode 100644 index 549ed79..0000000 --- a/Server/src/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -public class Main -{ - public static void main(String[] args) - { - new Server().start(); - } -} diff --git a/Server/src/Room.java b/Server/src/Room.java deleted file mode 100644 index a9c8069..0000000 --- a/Server/src/Room.java +++ /dev/null @@ -1,368 +0,0 @@ -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.ServerSocket; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; - -public class Room -{ - private Client[] players = new Client[2]; - private Vector3[] startPositions; - private String roomCode; - private Server server; - - private List threads = new ArrayList<>(); - - private int playerCount = 0; - - private int currentPlayer = 0; - - private long timeOut = 0; - private Timer t; - - public Room(String roomCode, Server server) - { - timeOut = System.currentTimeMillis(); - - this.roomCode = roomCode; - startPositions = new Vector3[4]; - - startPositions[0] = new Vector3(96, 1, 126); - startPositions[1] = new Vector3(92, 1, 126); - startPositions[2] = new Vector3(96, 1, 128); - startPositions[3] = new Vector3(92, 1, 128); - - this.server = server; - - try - { - t = new Timer(); - TimerTask tt = new TimerTask() - { - @Override - public void run() - { - try - { - for (int p = 0; p < players.length; p++) - { - if (players[p] != null) - { - if (System.currentTimeMillis() - players[p].lastTimeSendTimeOutCheck > 30000 && players[p].lastTimeSendTimeOutCheck != -1) - { - server.deleteRoom(roomCode); - } - - players[p].output.write(new byte[]{126, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - } - } - } catch (Exception e) - { - - } - - if (System.currentTimeMillis() - timeOut > 600000) - { - System.out.println("[" + Server.getDateTime() + "] Room " + roomCode + " closed due to timeout!"); - server.deleteRoom(roomCode); - } - } - }; - - t.scheduleAtFixedRate(tt, 0, 10000); - } catch (Exception e) - { - } - } - - public void addClient(Client client) - { - timeOut = System.currentTimeMillis(); - - for (int i = 0; i < players.length; i++) - { - if (players[i] == null) - { - players[i] = client; - playerCount++; - - System.out.println("[" + Server.getDateTime() + "] " + client.name.replace(" ", "") + " joined room " + roomCode + " successfully as player " + i); - - Thread t = new Thread(new Runnable() - { - @Override - public void run() - { - int player = playerCount - 1; - - DataInputStream input = null; - try - { - input = new DataInputStream(players[player].socket.getInputStream()); - } catch (IOException e) - { - throw new RuntimeException(e); - } - - while (true) - { - try - { - byte[] readData = new byte[10]; - - input.read(readData); - - timeOut = System.currentTimeMillis(); - - - /* - ---------------------------------------- - ---------------------------------------- - ---------------------------------------- - HERE IS THE ROOM / GAME LOGIC - ---------------------------------------- - ---------------------------------------- - ---------------------------------------- - */ - switch (readData[0]) - { - - //spieler hat gewürfelt - //1 x, x = zahl - case 3: - for (int i = 0; i < players.length; i++) - { - if (i != player) - { - players[i].output.write(new byte[]{3, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); - } - } - break; - //pfeil wurde ausgewählt - //1 x, x = idx - case 4: - for (int i = 0; i < players.length; i++) - { - if (i != player) - { - players[i].output.write(new byte[]{4, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); - } - } - break; - - //Spieler ist fertig mit seinem Zug - //1 x, x = next player - case 5: - currentPlayer++; - if (currentPlayer >= players.length) - { - currentPlayer = 0; - } - for (int i = 0; i < players.length; i++) - { - players[i].output.write(new byte[]{2, (byte) currentPlayer, 0, 0, 0, 0, 0, 0, 0, 0}); - } - break; - - //Es wurde auf ein CoinField getreten (Rot oder Blau) - //1 x, x = player; 2 y, y = Loose or Get - case 6: - for (int i = 0; i < players.length; i++) - { - if (i != player) - { - players[i].output.write(new byte[]{6, (byte)player, readData[1], 0, 0, 0, 0, 0, 0, 0}); - } - } - break; - - //Eventstop (ItemShop, BuyStar, ...) ist fertig - //1 x, x = player - case 7: - for (int i = 0; i < players.length; i++) - { - players[i].output.write(new byte[]{7, (byte)player, 0, 0, 0, 0, 0, 0, 0, 0}); - } - break; - //Spieler hat einen Stern gekauft - case 8: - for (int i = 0; i < players.length; i++) - { - if (i != player) - { - players[i].output.write(new byte[]{8, (byte)player, 0, 0, 0, 0, 0, 0, 0, 0}); - } - } - break; - - //Spieler hat ein Item Gekauft - //1 x, x = player; 2 y, y = Item.Type (byte) - case 9: - for (int i = 0; i < players.length; i++) - { - if (i != player) - { - players[i].output.write(new byte[]{9, (byte)player, readData[1], 0, 0, 0, 0, 0, 0, 0}); - } - } - break; - case 126: - players[player].lastTimeSendTimeOutCheck = System.currentTimeMillis(); - break; - } - - } catch (IOException e) - { - server.deleteRoom(roomCode); - } - } - } - }); - t.setName("Thread Player: " + (playerCount - 1)); - t.start(); - threads.add(t); - break; - } - } - - //Make clients add all players to the world - if (playerCount == players.length) - { - for (int j = 0; j < players.length; j++) - { - for (int k = 0; k < players.length; k++) - { - //0 1 create new player - //1 0 no playable player - //1 1 playable character - //2-3-4 default pos - //5 player index - if (j == k) - { - try - { - players[j].output.write(new byte[]{1, 1, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, 0}); - byte[] name = players[k].name.substring(0, 8).getBytes(StandardCharsets.US_ASCII); - byte[] send = new byte[10]; - send[0] = 5; - send[1] = (byte) k; - - for (int i = 2; i < send.length; i++) - { - send[i] = name[i - 2]; - } - - players[j].output.write(send); - } catch (IOException e) - { - - } - } else - { - try - { - players[j].output.write(new byte[]{1, 0, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, 0}); - byte[] name = players[k].name.substring(0, 8).getBytes(StandardCharsets.US_ASCII); - byte[] send = new byte[10]; - send[0] = 5; - send[1] = (byte) k; - - for (int i = 2; i < send.length; i++) - { - send[i] = name[i - 2]; - } - - players[j].output.write(send); - } catch (IOException e) - { - - } - } - } - } - - //0 2, activate a player - //1 x, x = idx - try - { - for (Client c : players) - { - c.output.write(new byte[]{2, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - } - } catch (IOException e) - { - - } - } - } - - public void closeRoom() - { - try - { - - if (players[0] != null) - { - players[0].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - } - - } catch (Exception ex) - { - } - - try - { - if (players[1] != null) - { - players[1].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - } - - } catch (Exception ex) - { - } - - try - { - if (players[2] != null) - { - players[2].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - } - - } catch (Exception ex) - { - } - - try - { - if (players[3] != null) - { - players[3].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - } - - } catch (Exception ex) - { - } - - - for (int i = 0; i < threads.size(); i++) - { - try - { - threads.get(i).interrupt(); - } catch (Exception e) - { - } - } - - try - { - t.cancel(); - } catch (Exception e) - { - } - } -} diff --git a/Server/src/Server.java b/Server/src/Server.java deleted file mode 100644 index b7f7085..0000000 --- a/Server/src/Server.java +++ /dev/null @@ -1,145 +0,0 @@ -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; -import java.nio.charset.StandardCharsets; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.HashMap; - -public class Server -{ - private ServerSocket serverSocket; - private HashMap rooms = new HashMap<>(); - - //hier ArrayList für public rooms - - private final Server server = this; - - private static DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); - - public static String getDateTime() - { - return dtf.format(LocalDateTime.now()); - } - - public void deleteRoom(String code) - { - rooms.get(code).closeRoom(); - rooms.remove(code); - - - System.out.println("[" + getDateTime() + "] Room" + code + " successfully deleted"); - } - - public void start() - { - - try - { - serverSocket = new ServerSocket(8051); - - System.out.println("[" + getDateTime() + "] Server started! IP 185.245.96.48 PORT 8051"); - - while(true) - { - Socket tempClient = serverSocket.accept(); - - System.out.println("[" + getDateTime() + "] Client with IP " + tempClient.getInetAddress().getHostName() + " connected!"); - - new Thread(new Runnable() - { - @Override - public void run() - { - Socket client = tempClient; - - try - { - DataInputStream input = new DataInputStream(client.getInputStream()); - DataOutputStream output = new DataOutputStream(client.getOutputStream()); - byte[] readData = new byte[10]; - - input.read(readData); - - switch(readData[0]) - { - //hier case 3 für public match making - //dsfjlksdfjlöasdfjlsdkjflksdjflksdjflksdjflksdjflksdjflksdjflkjsdlkfjsdlkfsdjlkfsdlkfjsdlkfjsdlkfjlsdkfjlsdkjfldksjfjlk - //fsjfklsdjflksdjflsdjflksdjflksdfjlksdjflksdjflksdjflksdjflksdjflksdjflksdjflksdjflksdjflsdkjflksdjflksdjflksdjflksdjf - - //schleife um zu checken ob ein offener room existiert (Liste) - //ansonsten einen neuen room erstellen und zur liste inhzufügen - - case 2: - byte[] code = generateRoomCode(); - output.write(code); - - Room room = new Room(new String(code, StandardCharsets.US_ASCII), server); - rooms.put(new String(code, StandardCharsets.US_ASCII), room); - - System.out.println("[" + getDateTime() + "] Room " + new String(code, StandardCharsets.US_ASCII) + " successfully created!"); - break; - case 1: - - input.read(readData); - - String roomCode = new String(readData, StandardCharsets.US_ASCII); - - input.read(readData); - - String name = new String(readData, StandardCharsets.US_ASCII); - name = name.replace("?", " "); - - if(rooms.containsKey(roomCode)) - { - Client client1 = new Client(output, input, client, name); - - rooms.get(roomCode).addClient(client1); - } - else - { - output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - } - - break; - } - - } catch (Exception e){ - - } - } - }).start(); - } - } - catch(Exception e){} - } - - private byte[] generateRoomCode() - { - byte[] code = new byte[10]; - - for(int i = 0; i < code.length; i++) - { - if(i < code.length / 2) - { - code[i] = (byte)(Math.random() * 8 + 49); - } - else - { - code[i] = (byte)(Math.random() * 25 + 97); - } - } - - String roomCode = new String(code, StandardCharsets.US_ASCII); - - //avoide double codes (just in case^^) - if(rooms.containsKey(roomCode)) - { - code = generateRoomCode(); - } - - return code; - } -} diff --git a/Server/src/Vector3.java b/Server/src/Vector3.java deleted file mode 100644 index 89578f8..0000000 --- a/Server/src/Vector3.java +++ /dev/null @@ -1,16 +0,0 @@ -public class Vector3 -{ - public float x, y, z; - - public Vector3(float x, float y, float z) - { - this.x = x; - this.y = y; - this.z = z; - } - - public static Vector3 zero() - { - return new Vector3(0, 0, 0); - } -}