diff --git a/FlufflParty/.idea/.idea.FlufflParty/.idea/workspace.xml b/FlufflParty/.idea/.idea.FlufflParty/.idea/workspace.xml index 1efed9a..6d5d029 100644 --- a/FlufflParty/.idea/.idea.FlufflParty/.idea/workspace.xml +++ b/FlufflParty/.idea/.idea.FlufflParty/.idea/workspace.xml @@ -46,7 +46,7 @@ } - diff --git a/FlufflParty/Assets/Scripts/Start/StartHandler.cs b/FlufflParty/Assets/Scripts/Start/StartHandler.cs index 796b22a..7f0f3c3 100644 --- a/FlufflParty/Assets/Scripts/Start/StartHandler.cs +++ b/FlufflParty/Assets/Scripts/Start/StartHandler.cs @@ -19,11 +19,9 @@ public class StartHandler : MonoBehaviour private void Start() { - client = new TcpClient("185.245.96.48", 8051); - layout1.SetActive(true); layout2.SetActive(false); - + client = new TcpClient("185.245.96.48", 8051); buttonJoin.SetActive(false); } @@ -31,24 +29,24 @@ public class StartHandler : MonoBehaviour { Stream stream = client.GetStream(); byte[] readMessage = new byte[10]; - + //Send message new room - stream.Write(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - + stream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); + layout1.SetActive(false); layout2.SetActive(true); - + //wait for room code int i = stream.Read(readMessage, 0, 10); - + Debug.Log(i); string code = Encoding.ASCII.GetString(readMessage); - + PlayerPrefs.SetString("roomcode", code); roomcode = code; PlayerPrefs.Save(); - + layout2.GetComponentInChildren().text = "Your room code is: \n" + code; } @@ -58,7 +56,7 @@ public class StartHandler : MonoBehaviour roomcode = code; PlayerPrefs.SetString("roomcode", code); PlayerPrefs.Save(); - + SceneManager.LoadScene(1, LoadSceneMode.Single); client.Close(); } @@ -67,15 +65,14 @@ public class StartHandler : MonoBehaviour { PlayerPrefs.SetString("roomcode", roomcode); PlayerPrefs.Save(); - + SceneManager.LoadScene(1, LoadSceneMode.Single); client.Close(); } public void ButtonBack() { - layout1.SetActive(true); - layout2.SetActive(false); + SceneManager.LoadScene(0, LoadSceneMode.Single); } public void ButtonCopy() @@ -94,4 +91,4 @@ public class StartHandler : MonoBehaviour buttonJoin.SetActive(false); } } -} +} \ No newline at end of file diff --git a/FlufflParty/UserSettings/EditorUserSettings.asset b/FlufflParty/UserSettings/EditorUserSettings.asset index 14d6805..2bb28f9 100644 --- a/FlufflParty/UserSettings/EditorUserSettings.asset +++ b/FlufflParty/UserSettings/EditorUserSettings.asset @@ -9,10 +9,10 @@ EditorUserSettings: value: 5604555501510a0955590d74437008441216412e7578276829704a6bb0b66c3a flags: 0 RecentlyUsedSceneGuid-1: - value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a + value: 0000025f04075d0f0c0a5c7149205a4417154f782e7923357e7a4560e3b4653b flags: 0 RecentlyUsedSceneGuid-2: - value: 0000025f04075d0f0c0a5c7149205a4417154f782e7923357e7a4560e3b4653b + value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a flags: 0 UnityRemoteDevice: value: 225f4d46245b0d4902070862342649191512 diff --git a/FlufflParty/UserSettings/Layouts/default-2021.dwlt b/FlufflParty/UserSettings/Layouts/default-2021.dwlt index 5cdef4a..2962fed 100644 --- a/FlufflParty/UserSettings/Layouts/default-2021.dwlt +++ b/FlufflParty/UserSettings/Layouts/default-2021.dwlt @@ -19,7 +19,7 @@ MonoBehaviour: width: 1920 height: 1117 m_ShowMode: 4 - m_Title: Game + m_Title: Inspector m_RootView: {fileID: 6} m_MinSize: {x: 875, y: 300} m_MaxSize: {x: 10000, y: 10000} @@ -48,7 +48,7 @@ MonoBehaviour: m_MinSize: {x: 300, y: 200} m_MaxSize: {x: 24288, y: 16192} vertical: 0 - controlID: 78 + controlID: 71 --- !u!114 &3 MonoBehaviour: m_ObjectHideFlags: 52 @@ -94,8 +94,8 @@ MonoBehaviour: y: 0 width: 343 height: 686 - m_MinSize: {x: 200, y: 200} - m_MaxSize: {x: 4000, y: 4000} + m_MinSize: {x: 201, y: 221} + m_MaxSize: {x: 4001, y: 4021} m_ActualView: {fileID: 17} m_Panes: - {fileID: 17} @@ -223,7 +223,7 @@ MonoBehaviour: m_MinSize: {x: 200, y: 200} m_MaxSize: {x: 16192, y: 16192} vertical: 1 - controlID: 557 + controlID: 103 --- !u!114 &10 MonoBehaviour: m_ObjectHideFlags: 52 @@ -248,7 +248,7 @@ MonoBehaviour: m_MinSize: {x: 200, y: 100} m_MaxSize: {x: 16192, y: 8096} vertical: 0 - controlID: 55 + controlID: 104 --- !u!114 &11 MonoBehaviour: m_ObjectHideFlags: 52 @@ -670,14 +670,14 @@ MonoBehaviour: m_OverrideSceneCullingMask: 6917529027641081856 m_SceneIsLit: 1 m_SceneLighting: 1 - m_2DMode: 1 + m_2DMode: 0 m_isRotationLocked: 0 m_PlayAudio: 0 m_AudioPlay: 0 m_Position: - m_Target: {x: 977.5928, y: 457.28116, z: 33874.965} + m_Target: {x: 97.37118, y: -10.844384, z: 113.38515} speed: 2 - m_Value: {x: 977.5928, y: 457.28116, z: 33874.965} + m_Value: {x: 97.37118, y: -10.844384, z: 113.38515} m_RenderMode: 0 m_CameraMode: drawMode: 0 @@ -724,17 +724,17 @@ MonoBehaviour: m_GridAxis: 1 m_gridOpacity: 0.5 m_Rotation: - m_Target: {x: 0, y: 0, z: 0, w: 1} + m_Target: {x: -0.079544604, y: -0.90466255, z: 0.37537217, w: -0.18539767} speed: 2 - m_Value: {x: 0, y: 0, z: 0, w: 1} + m_Value: {x: -0.07954388, y: -0.9046543, z: 0.37536877, w: -0.18539599} m_Size: - m_Target: 709.59906 + m_Target: 18.768896 speed: 2 - m_Value: 709.59906 + m_Value: 18.768896 m_Ortho: - m_Target: 1 + m_Target: 0 speed: 2 - m_Value: 1 + m_Value: 0 m_CameraSettings: m_Speed: 1.005 m_SpeedNormalized: 0.5 @@ -748,7 +748,7 @@ MonoBehaviour: m_FarClip: 10000 m_DynamicClip: 1 m_OcclusionCulling: 0 - m_LastSceneViewRotation: {x: -0.44589415, y: 0.51905, z: -0.27737507, w: -0.6744397} + m_LastSceneViewRotation: {x: -0.08717229, y: 0.89959055, z: -0.21045254, w: -0.3726226} m_LastSceneViewOrtho: 0 m_ReplacementShader: {fileID: 0} m_ReplacementString: @@ -796,22 +796,22 @@ MonoBehaviour: m_SkipHidden: 0 m_SearchArea: 1 m_Folders: - - Assets/Scenes + - Assets/Scripts/Start m_Globs: [] m_OriginalText: m_ViewMode: 1 m_StartGridSize: 64 m_LastFolders: - - Assets/Scenes + - Assets/Scripts/Start m_LastFoldersGridSize: -1 m_LastProjectPath: F:\Projects\Unity\flufflparty\FlufflParty m_LockTracker: m_IsLocked: 0 m_FolderTreeState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: ae5d0000 - m_LastClickedID: 23982 - m_ExpandedIDs: 00000000285d00002a5d00002c5d00009e5d000000ca9a3b + m_SelectedIDs: 985d0000 + m_LastClickedID: 23960 + m_ExpandedIDs: 000000003c5d00003e5d0000405d000000ca9a3b m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -839,7 +839,7 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: 00000000285d00002a5d00002c5d0000 + m_ExpandedIDs: 000000003c5d00003e5d0000405d0000 m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -915,8 +915,8 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 1447 - y: 73 + x: -30553 + y: -31970 width: 472 height: 1046 m_ViewDataDictionary: {fileID: 0} @@ -969,7 +969,7 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: 1831ffff6831ffff4a38ffff5a38ffff843affffd23affffb441ffffc441ffff4850ffff9650ffff7857ffff8857ffffa859fffff859ffffda60ffffea60ffff4e63ffff2868ffff8268ffff4a6fffff666fffff8080ffff2c83ffff8283ffff648affff748affff928cffffe88cffffca93ffffda93ffffe095ffff3696ffff189dffff289dfffff89effff4e9fffff30a6ffff40a6ffffe4d5ffff04fbffff345c0000605c0000965c00009c5c000058a6000036bc000048bc000064bc00007ebc0000aabc0000b4bc0000c4bc0000 + m_ExpandedIDs: 78ddffffc8ddffffaae4ffffbae4ffff82e6ffffd2e6ffffb4edffffc4edffff9aefffffeaefffffccf6ffffdcf6ffff06fbffff m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: diff --git a/Server/.idea/workspace.xml b/Server/.idea/workspace.xml index 79856f3..7fe325e 100644 --- a/Server/.idea/workspace.xml +++ b/Server/.idea/workspace.xml @@ -72,7 +72,10 @@ 1674839030210 - + + + + diff --git a/Server/out/artifacts/Server_jar/Server.jar b/Server/out/artifacts/Server_jar/Server.jar index 0e8e6dc..aaa1b77 100644 Binary files a/Server/out/artifacts/Server_jar/Server.jar and b/Server/out/artifacts/Server_jar/Server.jar differ diff --git a/Server/out/production/Server/Room$1.class b/Server/out/production/Server/Room$1.class index 766e3e8..abef716 100644 Binary files a/Server/out/production/Server/Room$1.class and b/Server/out/production/Server/Room$1.class differ diff --git a/Server/out/production/Server/Room$2.class b/Server/out/production/Server/Room$2.class new file mode 100644 index 0000000..5258dc6 Binary files /dev/null and b/Server/out/production/Server/Room$2.class differ diff --git a/Server/out/production/Server/Room.class b/Server/out/production/Server/Room.class index d81a707..41450f5 100644 Binary files a/Server/out/production/Server/Room.class and b/Server/out/production/Server/Room.class differ diff --git a/Server/out/production/Server/Server$1.class b/Server/out/production/Server/Server$1.class index a8b1a60..e4130fe 100644 Binary files a/Server/out/production/Server/Server$1.class and b/Server/out/production/Server/Server$1.class differ diff --git a/Server/out/production/Server/Server.class b/Server/out/production/Server/Server.class index 92fef50..dc766cc 100644 Binary files a/Server/out/production/Server/Server.class and b/Server/out/production/Server/Server.class differ diff --git a/Server/src/Room.java b/Server/src/Room.java index 68f38ae..c31bdc4 100644 --- a/Server/src/Room.java +++ b/Server/src/Room.java @@ -4,6 +4,8 @@ import java.io.IOException; import java.net.ServerSocket; import java.util.ArrayList; import java.util.List; +import java.util.Timer; +import java.util.TimerTask; public class Room { @@ -18,8 +20,13 @@ public class Room 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]; @@ -29,10 +36,31 @@ public class Room startPositions[3] = new Vector3(92, 1, 128); this.server = server; + + try + { + t = new Timer(); + TimerTask tt = new TimerTask() + { + @Override + public void run() + { + if(System.currentTimeMillis() - timeOut > 600000) + { + System.out.println("[" + Server.getDateTime() + "] Room " + roomCode + " closed due to timeout!"); + server.deleteRoom(roomCode); + } + } + }; + + t.scheduleAtFixedRate(tt, 0, 60000); + }catch(Exception e){} } public void addClient(Client client) { + timeOut = System.currentTimeMillis(); + for (int i = 0; i < players.length; i++) { if (players[i] == null) @@ -40,7 +68,7 @@ public class Room players[i] = client; playerCount++; - System.out.println("Client joined room " + roomCode + " successfully as player " + i); + System.out.println("[" + Server.getDateTime() + "] Client joined room " + roomCode + " successfully as player " + i); Thread t = new Thread(new Runnable() { @@ -66,6 +94,8 @@ public class Room input.read(readData); + timeOut = System.currentTimeMillis(); + switch (readData[0]) { @@ -183,39 +213,50 @@ public class Room public void closeRoom() { + t.cancel(); + try { - players[0].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + if(players[0] != null) + { + players[0].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + } - } catch (IOException ex) + } catch (Exception ex) { } try { + if(players[1] != null) + { + players[1].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + } - players[1].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - - } catch (IOException ex) + } catch (Exception ex) { } try { + if(players[2] != null) + { + players[2].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + } - players[2].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - - } catch (IOException ex) + } catch (Exception ex) { } try { + if(players[3] != null) + { + players[3].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + } - players[3].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); - - } catch (IOException ex) + } catch (Exception ex) { } } diff --git a/Server/src/Server.java b/Server/src/Server.java index 750c01d..6fc11b7 100644 --- a/Server/src/Server.java +++ b/Server/src/Server.java @@ -4,6 +4,8 @@ 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 @@ -13,26 +15,36 @@ public class Server 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("Room " + code + " successfully deleted"); + + + System.out.println("[" + getDateTime() + "] Room" + code + " successfully deleted"); } public void start() { + try { serverSocket = new ServerSocket(8051); - System.out.println("Server started! IP 185.245.96.48 PORT 8051"); + System.out.println("[" + getDateTime() + "] Server started! IP 185.245.96.48 PORT 8051"); while(true) { Socket tempClient = serverSocket.accept(); - System.out.println("Client with IP " + tempClient.getInetAddress().getHostName() + " connected!"); + System.out.println("[" + getDateTime() + "] Client with IP " + tempClient.getInetAddress().getHostName() + " connected!"); new Thread(new Runnable() { @@ -58,7 +70,7 @@ public class Server Room room = new Room(new String(code, StandardCharsets.US_ASCII), server); rooms.put(new String(code, StandardCharsets.US_ASCII), room); - System.out.println("Room " + new String(code, StandardCharsets.US_ASCII) + " successfully created!"); + System.out.println("[" + getDateTime() + "] Room " + new String(code, StandardCharsets.US_ASCII) + " successfully created!"); break; case 1: @@ -106,6 +118,14 @@ public class Server } } + String roomCode = new String(code, StandardCharsets.US_ASCII); + + //avoide double codes (just in case^^) + if(rooms.containsKey(roomCode)) + { + code = generateRoomCode(); + } + return code; } }