Client Timeout

This commit is contained in:
brausjonas
2023-01-29 01:54:53 +01:00
parent da8ce4b425
commit 6754d710b2
21 changed files with 1057 additions and 187 deletions
+2
View File
@@ -10,6 +10,8 @@ public class Client
public String name;
public long lastTimeSendTimeOutCheck = -1;
public Client(DataOutputStream output, DataInputStream input, Socket socket, String name)
{
+30 -11
View File
@@ -46,6 +46,26 @@ public class Room
@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!");
@@ -54,7 +74,7 @@ public class Room
}
};
t.scheduleAtFixedRate(tt, 0, 60000);
t.scheduleAtFixedRate(tt, 0, 10000);
}catch(Exception e){}
}
@@ -138,20 +158,14 @@ public class Room
break;
case 0:
server.deleteRoom(roomCode);
for(int i = 0; i < threads.size(); i++)
{
threads.get(i).stop();
}
break;
case 126:
players[player].lastTimeSendTimeOutCheck = System.currentTimeMillis();
break;
}
} catch (IOException e)
{
for(int i = 0; i < threads.size(); i++)
{
threads.get(i).stop();
}
server.deleteRoom(roomCode);
}
}
@@ -236,7 +250,7 @@ public class Room
public void closeRoom()
{
t.cancel();
System.out.println(Server.getDateTime() + " A player has left!");
try
{
@@ -282,5 +296,10 @@ public class Room
} catch (Exception ex)
{
}
for(int i = 0; i < threads.size(); i++)
{
threads.get(i).interrupt();
}
}
}