FIx: Fixed Coverage Screenshots And htmlRepot.

This commit is contained in:
GabrieleRadice
2026-06-19 22:57:43 +02:00
parent a4dc8b2540
commit 0129efe400
316 changed files with 4566 additions and 4497 deletions
@@ -0,0 +1,265 @@
<!DOCTYPE html>
<html id="htmlId">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Coverage Report > ClientHandler</title>
<style type="text/css">
@import "../../css/coverage.css";
@import "../../css/idea.min.css";
</style>
<script type="text/javascript" src="../../js/highlight.min.js"></script>
<script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>
<body>
<div class="content">
<div class="breadCrumbs">
Current scope: <a href="../../index.html">all classes</a>
<span class="separator">|</span>
<a href="../index.html">it.polimi.ingsw.gc14.Network.TCP.Server</a>
</div>
<h1>Coverage Summary for Class: ClientHandler (it.polimi.ingsw.gc14.Network.TCP.Server)</h1>
<table class="coverageStats">
<tr>
<th class="name">Class</th>
<th class="coverageStat
">
Class, %
</th>
<th class="coverageStat
">
Method, %
</th>
<th class="coverageStat
">
Branch, %
</th>
<th class="coverageStat
">
Line, %
</th>
</tr>
<tr>
<td class="name">ClientHandler</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/1)
</span>
</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/6)
</span>
</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/14)
</span>
</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/31)
</span>
</td>
</tr>
</table>
<br/>
<br/>
<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package it.polimi.ingsw.gc14.Network.TCP.Server;
&nbsp;
&nbsp;import it.polimi.ingsw.gc14.LimitedMap;
&nbsp;import it.polimi.ingsw.gc14.Model.MiniModel;
&nbsp;import it.polimi.ingsw.gc14.Network.NetworkEvent;
&nbsp;import it.polimi.ingsw.gc14.Network.NetworkEvents.DisconnectedPlayer;
&nbsp;
&nbsp;import java.io.*;
&nbsp;import java.net.*;
&nbsp;import java.util.List;
&nbsp;import java.util.concurrent.BlockingQueue;
&nbsp;
&nbsp;/**
&nbsp; * Handles the TCP connection with a single client.
&nbsp; * Each instance runs on a dedicated thread and is responsible for receiving {@link NetworkEvent} from its client and adding them
&nbsp; * to the {@link #actionQueue}.
&nbsp; * It is also responsible to send events and game model updates back to the client.
&nbsp; */
&nbsp;public class ClientHandler implements Runnable {
&nbsp; /**
&nbsp; * The username of the connected client on this handler
&nbsp; */
&nbsp; private final String username;
&nbsp; /** {@code true} while the handler is actively reading from the socket; set to {@code false} on disconnect. */
&nbsp; private volatile boolean running;
&nbsp;
&nbsp; /**
&nbsp; * Returns the username associated with this client.
&nbsp; *
&nbsp; * @return the username associated with this client.
&nbsp; */
&nbsp; public String getUsername() {
<b class="nc">&nbsp; return username;</b>
&nbsp; }
&nbsp; /** The TCP socket */
&nbsp; private final Socket clientSocket;
&nbsp;
&nbsp; /** Input stream used to receive objects from the client */
&nbsp; private final ObjectInputStream in;
&nbsp;
&nbsp; /** Output stream used to send objects to the client */
&nbsp; private final ObjectOutputStream out;
&nbsp;
&nbsp; /**
&nbsp; * Shared list of all client handlers.
&nbsp; * This handler removes itself from the list when disconnected.
&nbsp; */
&nbsp; private final List&lt;ClientHandler&gt; clientHandlers;
&nbsp;
&nbsp; /** Maps each connected player&#39;s username to their connection state (true = connected). */
&nbsp; private final LimitedMap&lt;String, Boolean&gt; limitedMap;
&nbsp;
&nbsp; /** Queue containing the events to be applied to the game model */
&nbsp; private final BlockingQueue&lt;NetworkEvent&gt; actionQueue;
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Class constructor that initializes the attributes.
&nbsp; *
&nbsp; * @param username the username associated with the client.
&nbsp; * @param clientSocket the socket representing the client&#39;s TCP connection.
&nbsp; * @param out the output stream used to send data to the client.
&nbsp; * @param in the input stream used to receive data from the client.
&nbsp; * @param clientHandlers the shared list of all active client handlers.
&nbsp; * @param playersMap the shared map containing the connected players.
&nbsp; * @param actionQueue the queue containing incoming events.
&nbsp; */
<b class="nc">&nbsp; public ClientHandler(String username, Socket clientSocket, ObjectOutputStream out, ObjectInputStream in, List&lt;ClientHandler&gt; clientHandlers, LimitedMap&lt;String,Boolean&gt; playersMap, BlockingQueue&lt;NetworkEvent&gt; actionQueue) {</b>
<b class="nc">&nbsp; this.username=username;</b>
<b class="nc">&nbsp; this.clientSocket = clientSocket;</b>
<b class="nc">&nbsp; this.in = in;</b>
<b class="nc">&nbsp; this.out = out;</b>
<b class="nc">&nbsp; this.clientHandlers = clientHandlers;</b>
<b class="nc">&nbsp; this.actionQueue = actionQueue;</b>
<b class="nc">&nbsp; this.limitedMap = playersMap;</b>
&nbsp; }
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Listens for incoming {@link NetworkEvent}s from the client and adds them to the {@link #actionQueue}.
&nbsp; * Upon disconnection, this handler removes itself from {@link #clientHandlers}.
&nbsp; */
&nbsp; @Override
&nbsp; public void run() {
<b class="nc">&nbsp; running = true;</b>
&nbsp; try {
<b class="nc">&nbsp; while (running) {</b>
<b class="nc">&nbsp; NetworkEvent event = (NetworkEvent) in.readObject();</b>
<b class="nc">&nbsp; if (!actionQueue.offer(event)) {</b>
<b class="nc">&nbsp; System.out.println(&quot;Error inserting action into queue&quot;);</b>
&nbsp; }
&nbsp; }
&nbsp; } catch (IOException e) {
&nbsp; } catch (ClassNotFoundException e) {
<b class="nc">&nbsp; System.err.println(&quot;Class not found: &quot; + username);</b>
&nbsp; } finally {
<b class="nc">&nbsp; if (running) disconnect();</b>
&nbsp; }
&nbsp; }
&nbsp;
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Sends a {@link NetworkEvent} to the client.
&nbsp; * @param event The network event to send to the client.
&nbsp; */
&nbsp; public synchronized void notifyEvent(NetworkEvent event) {
&nbsp; try {
<b class="nc">&nbsp; out.reset();</b>
<b class="nc">&nbsp; out.writeObject(event);</b>
&nbsp; } catch (IOException e) {
<b class="nc">&nbsp; e.printStackTrace();</b>
<b class="nc">&nbsp; disconnect();</b>
&nbsp; }
&nbsp;
&nbsp; }
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Sends the current game model to this client.
&nbsp; * @param game The current state of the game to send to the client.
&nbsp; */
&nbsp; public synchronized void notifyMiniModel(MiniModel game) {
&nbsp; try {
<b class="nc">&nbsp; out.reset();</b>
<b class="nc">&nbsp; out.writeObject(game);</b>
&nbsp; } catch (IOException e) {
<b class="nc">&nbsp; e.printStackTrace();</b>
<b class="nc">&nbsp; disconnect();</b>
&nbsp; }
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Disconnects the client from the server.
&nbsp; *
&nbsp; * &lt;p&gt;The client handler is stopped and removed from the list of active handlers.
&nbsp; * The player is marked as disconnected, a {@link DisconnectedPlayer} event is
&nbsp; * added to the action queue, and the associated socket is closed.
&nbsp; */
&nbsp; public synchronized void disconnect() {
<b class="nc">&nbsp; if (!running) return;</b>
<b class="nc">&nbsp; running = false;</b>
<b class="nc">&nbsp; clientHandlers.remove(this);</b>
<b class="nc">&nbsp; limitedMap.put(username, false);</b>
<b class="nc">&nbsp; actionQueue.add(new DisconnectedPlayer(username));</b>
<b class="nc">&nbsp; System.err.println(&quot;(TCP) Disconnected player: &quot; + username);</b>
<b class="nc">&nbsp; try { clientSocket.close(); } catch (IOException ignored) {}</b>
&nbsp; }
&nbsp;}
</code>
</pre>
</div>
<script type="text/javascript">
(function() {
var msie = false, msie9 = false;
/*@cc_on
msie = true;
@if (@_jscript_version >= 9)
msie9 = true;
@end
@*/
if (!msie || msie && msie9) {
hljs.highlightAll()
hljs.initLineNumbersOnLoad();
}
})();
</script>
<div class="footer">
<div style="float:right;">generated on 2026-06-19 22:53</div>
</div>
</body>
</html>