Kick All Players on Player leave

This commit is contained in:
brausjonas
2023-01-28 11:54:18 +01:00
parent eb56ec7a4e
commit e4aa7f112a
8 changed files with 42 additions and 19 deletions
+1 -1
View File
@@ -72,7 +72,7 @@
<updated>1674839030210</updated>
<workItem from="1674839031467" duration="221000" />
<workItem from="1674839402490" duration="20380000" />
<workItem from="1674897525328" duration="3018000" />
<workItem from="1674897525328" duration="3479000" />
</task>
<servers />
</component>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+40 -18
View File
@@ -106,15 +106,6 @@ public class Room
}
break;
case 0:
try
{
for (int i = 0; i < players.length; i++)
{
players[player].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
}
} catch (IOException ex)
{
}
server.deleteRoom(roomCode);
for(int i = 0; i < threads.size(); i++)
{
@@ -125,15 +116,7 @@ public class Room
} catch (IOException e)
{
try
{
for (int i = 0; i < players.length; i++)
{
players[player].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
}
} catch (IOException ex)
{
}
for(int i = 0; i < threads.size(); i++)
{
threads.get(i).stop();
@@ -197,4 +180,43 @@ public class Room
}
}
}
public void closeRoom()
{
try
{
players[0].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
} catch (IOException ex)
{
}
try
{
players[1].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
} catch (IOException ex)
{
}
try
{
players[2].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
} catch (IOException ex)
{
}
try
{
players[3].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
} catch (IOException ex)
{
}
}
}
+1
View File
@@ -15,6 +15,7 @@ public class Server
public void deleteRoom(String code)
{
rooms.get(code).closeRoom();
rooms.remove(code);
System.out.println("Room " + code + " successfully deleted");
}