FIx: Fixed Coverage Screenshots And htmlRepot.
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html id="htmlId">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>Coverage Report > CompositeClientBroadcaster</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</a>
|
||||
</div>
|
||||
|
||||
<h1>Coverage Summary for Class: CompositeClientBroadcaster (it.polimi.ingsw.gc14.Network)</h1>
|
||||
|
||||
<table class="coverageStats">
|
||||
<tr>
|
||||
<th class="name">Class</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Class, %
|
||||
</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Method, %
|
||||
</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Line, %
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name">CompositeClientBroadcaster</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/3)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/7)
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<pre>
|
||||
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Network;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
||||
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
|
||||
|
||||
/**
|
||||
* Forwards every notification to both the RMI and the TCP transport layers.
|
||||
*
|
||||
* <p>This follows the Composite pattern: the caller interacts with a single
|
||||
* broadcaster without knowing which protocols are active underneath.
|
||||
*/
|
||||
public class CompositeClientBroadcaster {
|
||||
/** RMI transport used to reach RMI-connected clients. */
|
||||
private final RMIServer rmiServer;
|
||||
/** TCP transport used to reach TCP-connected clients. */
|
||||
private final TCPServer tcpServer;
|
||||
|
||||
/**
|
||||
* Constructs a composite broadcaster backed by the given RMI and TCP servers.
|
||||
*
|
||||
* @param rmiServer the RMI server used to reach RMI clients.
|
||||
* @param tcpServer the TCP server used to reach TCP clients.
|
||||
*/
|
||||
<b class="nc"> public CompositeClientBroadcaster(RMIServer rmiServer, TCPServer tcpServer) {</b>
|
||||
<b class="nc"> this.rmiServer = rmiServer;</b>
|
||||
<b class="nc"> this.tcpServer = tcpServer;</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards the event to both the RMI and the TCP server.
|
||||
* Each server is responsible for filtering error events to the
|
||||
* requesting player only.
|
||||
*
|
||||
* @param event the network event to broadcast.
|
||||
*/
|
||||
public void notifyAll(NetworkEvent event) {
|
||||
<b class="nc"> rmiServer.notifyAll(event);</b>
|
||||
<b class="nc"> tcpServer.notifyAll(event);</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards the model snapshot to every client on both transports.
|
||||
*
|
||||
* @param model the mini model snapshot to broadcast.
|
||||
*/
|
||||
public void notifyAll(MiniModel model) {
|
||||
<b class="nc"> rmiServer.notifyAll(model);</b>
|
||||
<b class="nc"> tcpServer.notifyAll(model);</b>
|
||||
}
|
||||
}
|
||||
</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>
|
||||
@@ -0,0 +1,181 @@
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html id="htmlId">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>Coverage Report > EventType</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</a>
|
||||
</div>
|
||||
|
||||
<h1>Coverage Summary for Class: EventType (it.polimi.ingsw.gc14.Network)</h1>
|
||||
|
||||
<table class="coverageStats">
|
||||
<tr>
|
||||
<th class="name">Class</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Class, %
|
||||
</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Method, %
|
||||
</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Line, %
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name">EventType</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/4)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/16)
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<pre>
|
||||
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Network;
|
||||
|
||||
/**
|
||||
* Represents the different types of network events that can be sent between
|
||||
* client and server.
|
||||
*/
|
||||
<b class="nc"> public enum EventType {</b>
|
||||
|
||||
/**
|
||||
* Event used to add a player to the game.
|
||||
*/
|
||||
<b class="nc"> ADD_PLAYER("Add Player Event"),</b>
|
||||
|
||||
/**
|
||||
* Event used to submit a player's totem choice.
|
||||
*/
|
||||
<b class="nc"> TOTEM_CHOICE("Totem Choice"),</b>
|
||||
|
||||
/**
|
||||
* Event used to submit a player's slot choice.
|
||||
*/
|
||||
<b class="nc"> SLOT_CHOICE("Slot Choice"),</b>
|
||||
|
||||
/**
|
||||
* Event used to draw a tribe card from the upper card list.
|
||||
*/
|
||||
<b class="nc"> DRAW_UPPER_TRIBE("Drawing Upper Tribe"),</b>
|
||||
|
||||
/**
|
||||
* Event used to draw a tribe card from the lower card list.
|
||||
*/
|
||||
<b class="nc"> DRAW_LOWER_TRIBE("Drawing Lower Tribe"),</b>
|
||||
|
||||
/**
|
||||
* Event used to draw a building card from the upper card list.
|
||||
*/
|
||||
<b class="nc"> DRAW_UPPER_BUILD("Drawing Upper Build"),</b>
|
||||
|
||||
/**
|
||||
* Event used to draw a building card from the lower card list.
|
||||
*/
|
||||
<b class="nc"> DRAW_LOWER_BUILD("Drawing Lower Build"),</b>
|
||||
|
||||
/**
|
||||
* Event used to skip the current turn or optional action.
|
||||
*/
|
||||
<b class="nc"> SKIP_TURN("Skip Turn"),</b>
|
||||
|
||||
/**
|
||||
* Event used to notify that a player has disconnected.
|
||||
*/
|
||||
<b class="nc"> DISCONNECTED_PLAYER("Disconnected Player"),</b>
|
||||
|
||||
/**
|
||||
* Event used to notify that a player has reconnected.
|
||||
*/
|
||||
<b class="nc"> RECONNECT_PLAYER("Reconnect Player"),</b>
|
||||
|
||||
/**
|
||||
* Event used to apply the transition to the next round.
|
||||
*/
|
||||
<b class="nc"> NEXT_ROUND("Next Round"),</b>
|
||||
|
||||
/**
|
||||
* Event used to notify that the game has ended.
|
||||
*/
|
||||
<b class="nc"> ENDED_GAME("Ended Game");</b>
|
||||
/** Human-readable label for this event type, returned by {@link #toString()}. */
|
||||
private final String description;
|
||||
<b class="nc"> EventType(String description) {</b>
|
||||
<b class="nc"> this.description = description;</b>
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
<b class="nc"> return description;</b>
|
||||
}
|
||||
}
|
||||
</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>
|
||||
@@ -0,0 +1,191 @@
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html id="htmlId">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>Coverage Report > InterfaceResolver</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</a>
|
||||
</div>
|
||||
|
||||
<h1>Coverage Summary for Class: InterfaceResolver (it.polimi.ingsw.gc14.Network)</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">InterfaceResolver</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/3)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/26)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/22)
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<pre>
|
||||
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Network;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/** Utility class for resolving the local network interface to use when connecting to a server. */
|
||||
public class InterfaceResolver {
|
||||
private InterfaceResolver() {}
|
||||
|
||||
/**
|
||||
* Returns the local IPv4 address that can reach the given server IP.
|
||||
*
|
||||
* <p>If the server is localhost, returns {@code "127.0.0.1"}.
|
||||
* Otherwise, iterates active non-loopback interfaces to find one on the same subnet;
|
||||
* falls back to a UDP connect trick if no matching subnet is found.
|
||||
*
|
||||
* @param serverIp the server IP address or hostname.
|
||||
* @return the local IP address string to use for outbound connections.
|
||||
* @throws Exception if no suitable interface can be determined.
|
||||
*/
|
||||
public static String resolveLocalInterface(String serverIp) throws Exception {
|
||||
<b class="nc"> if (serverIp.equalsIgnoreCase("localhost") || serverIp.startsWith("127.") || serverIp.isEmpty()) {</b>
|
||||
<b class="nc"> return "127.0.0.1";</b>
|
||||
}
|
||||
|
||||
<b class="nc"> InetAddress serverAddr = InetAddress.getByName(serverIp);</b>
|
||||
<b class="nc"> Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();</b>
|
||||
<b class="nc"> while (ifaces.hasMoreElements()) {</b>
|
||||
<b class="nc"> NetworkInterface ni = ifaces.nextElement();</b>
|
||||
<b class="nc"> if (!ni.isUp() || ni.isLoopback()) continue;</b>
|
||||
|
||||
<b class="nc"> for (InterfaceAddress ia : ni.getInterfaceAddresses()) {</b>
|
||||
<b class="nc"> InetAddress localAddr = ia.getAddress();</b>
|
||||
<b class="nc"> if (!(localAddr instanceof Inet4Address)) continue;</b>
|
||||
|
||||
<b class="nc"> int prefix = ia.getNetworkPrefixLength();</b>
|
||||
<b class="nc"> if (sameSubnet(localAddr, serverAddr, prefix)) {</b>
|
||||
<b class="nc"> return localAddr.getHostAddress();</b>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<b class="nc"> try (DatagramSocket socket = new DatagramSocket()) {</b>
|
||||
<b class="nc"> socket.connect(serverAddr, 9);</b>
|
||||
<b class="nc"> return socket.getLocalAddress().getHostAddress();</b>
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns {@code true} if {@code a} and {@code b} share the same subnet given a CIDR {@code prefix} length.
|
||||
*
|
||||
* @param a first IPv4 address.
|
||||
* @param b second IPv4 address.
|
||||
* @param prefix CIDR prefix length (0–32).
|
||||
* @return {@code true} if both addresses belong to the same subnet.
|
||||
*/
|
||||
private static boolean sameSubnet(InetAddress a, InetAddress b, int prefix) {
|
||||
<b class="nc"> if (prefix < 0 || prefix > 32) return false;</b>
|
||||
<b class="nc"> int maskBits = prefix == 0 ? 0 : (0xFFFFFFFF << (32 - prefix));</b>
|
||||
<b class="nc"> int addrA = toInt(a.getAddress()) & maskBits;</b>
|
||||
<b class="nc"> int addrB = toInt(b.getAddress()) & maskBits;</b>
|
||||
<b class="nc"> return addrA == addrB;</b>
|
||||
}
|
||||
/**
|
||||
* Converts a 4-byte big-endian IPv4 address array to a signed 32-bit integer.
|
||||
*
|
||||
* @param bytes the 4-byte address array.
|
||||
* @return the corresponding signed integer.
|
||||
*/
|
||||
private static int toInt(byte[] bytes) {
|
||||
<b class="nc"> return ((bytes[0] & 0xFF) << 24) |</b>
|
||||
((bytes[1] & 0xFF) << 16) |
|
||||
((bytes[2] & 0xFF) << 8) |
|
||||
(bytes[3] & 0xFF);
|
||||
}
|
||||
}
|
||||
</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>
|
||||
@@ -0,0 +1,317 @@
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html id="htmlId">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>Coverage Report > NetworkEvent</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</a>
|
||||
</div>
|
||||
|
||||
<h1>Coverage Summary for Class: NetworkEvent (it.polimi.ingsw.gc14.Network)</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">NetworkEvent</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/10)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/2)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/19)
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<pre>
|
||||
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Network;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Model.Slot;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents an event sent over the network.
|
||||
*
|
||||
* <p>A network event contains the information required to identify
|
||||
* the requested action, determine whether it produced an error,
|
||||
* and apply it either to the server-side {@link GameController}
|
||||
* or to the client-side {@link MiniModel}.
|
||||
*/
|
||||
public abstract class NetworkEvent implements Serializable {
|
||||
|
||||
/** The error type associated with this event; set when the event failed to apply. */
|
||||
protected ErrorType errorType;
|
||||
|
||||
/**
|
||||
* Returns the error type associated with this event.
|
||||
*
|
||||
* @return the error type, or {@code null} if no error occurred.
|
||||
*/
|
||||
public ErrorType getErrorType() {
|
||||
<b class="nc"> return errorType;</b>
|
||||
}
|
||||
/**
|
||||
* Username of the player requesting the event.
|
||||
*/
|
||||
protected final String username;
|
||||
|
||||
/**
|
||||
* Returns the username of the player requesting the event.
|
||||
*
|
||||
* @return the username associated with the event.
|
||||
*/
|
||||
public String getUsername() {
|
||||
<b class="nc"> return username;</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of the network event.
|
||||
*/
|
||||
protected final EventType eventType;
|
||||
|
||||
/**
|
||||
* Map associating each occupied slot with the corresponding player.
|
||||
*/
|
||||
protected Map<Slot, Player> slotPlayerMap;
|
||||
|
||||
/**
|
||||
* Order logic card used to manage the player turn order.
|
||||
*/
|
||||
protected OrderLogicCard orderLogicCard;
|
||||
|
||||
/**
|
||||
* Current state of the game associated with the event.
|
||||
*/
|
||||
protected CurrentState currentState;
|
||||
|
||||
/**
|
||||
* List of all players.
|
||||
*/
|
||||
protected List<Player> playerList;
|
||||
|
||||
/**
|
||||
* Usernames of players currently disconnected from the game.
|
||||
* Sent with every event so clients always have an up-to-date list.
|
||||
*/
|
||||
protected ArrayList<String> disconnectedPlayers;
|
||||
|
||||
/**
|
||||
* Populates this event with the current game state so clients can
|
||||
* update their local model after receiving it.
|
||||
* Subclasses that carry extra state (available totems, etc.) override
|
||||
* this method and call {@code super} first.
|
||||
*
|
||||
* @param game the current game model.
|
||||
* @param disconnectedUsernames usernames of currently disconnected players.
|
||||
*/
|
||||
public void enrichWithGameState(Game game, ArrayList<String> disconnectedUsernames) {
|
||||
<b class="nc"> setData(game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(), game.getPlayers());</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the game data associated with this network event.
|
||||
*
|
||||
* @param slotPlayerMap the map associating each slot with the player occupying it.
|
||||
* @param orderLogicCard the order logic card used to manage turn order.
|
||||
* @param currentState the current state of the game.
|
||||
* @param playerList the list of the actual state of the players
|
||||
*/
|
||||
public void setData(Map<Slot, Player> slotPlayerMap,
|
||||
OrderLogicCard orderLogicCard,
|
||||
CurrentState currentState,
|
||||
List<Player> playerList) {
|
||||
<b class="nc"> this.slotPlayerMap = slotPlayerMap;</b>
|
||||
<b class="nc"> this.orderLogicCard = orderLogicCard;</b>
|
||||
<b class="nc"> this.currentState = currentState;</b>
|
||||
<b class="nc"> this.playerList = playerList;</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of this event.
|
||||
*
|
||||
* @return the event type.
|
||||
*/
|
||||
public EventType getEventType() {
|
||||
<b class="nc"> return eventType;</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag indicating whether the event could not be applied successfully.
|
||||
*/
|
||||
protected boolean isError;
|
||||
|
||||
/**
|
||||
* Returns whether the event represents an error.
|
||||
*
|
||||
* @return {@code true} if the event could not be applied successfully,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public boolean isError() {
|
||||
<b class="nc"> return isError;</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the event represents an error.
|
||||
*
|
||||
* @param isError {@code true} if the event could not be applied successfully,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public void setIsError(boolean isError) {
|
||||
<b class="nc"> this.isError = isError;</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the error type for this event.
|
||||
*
|
||||
* @param errorType the error type to set.
|
||||
*/
|
||||
public void setErrorType(ErrorType errorType) {
|
||||
<b class="nc"> this.errorType = errorType;</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a network event.
|
||||
*
|
||||
* @param username the username of the player requesting the event.
|
||||
* @param eventType the type of the event.
|
||||
* @param isError {@code true} if the event represents an error,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
<b class="nc"> protected NetworkEvent(String username, EventType eventType, boolean isError, ErrorType errorType) {</b>
|
||||
<b class="nc"> this.username = username;</b>
|
||||
<b class="nc"> this.eventType = eventType;</b>
|
||||
<b class="nc"> this.isError = isError;</b>
|
||||
<b class="nc"> this.errorType = errorType;</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a textual description of the event and its outcome.
|
||||
*
|
||||
* @return a string describing the event type and whether it represents an error.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
<b class="nc"> if (isError) {</b>
|
||||
<b class="nc"> return "ERROR: " + eventType;</b>
|
||||
} else {
|
||||
<b class="nc"> return "ACTION: " + eventType;</b>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this event to the specified server-side game controller.
|
||||
*
|
||||
* @param gameController the game controller on which the event must be applied.
|
||||
* @return {@code true} if the event is applied successfully,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
public abstract boolean apply(GameController gameController);
|
||||
|
||||
/**
|
||||
* Applies this event to the specified client-side mini model.
|
||||
*
|
||||
* @param model the mini model on which the event must be applied.
|
||||
*/
|
||||
public abstract void apply(MiniModel model);
|
||||
}
|
||||
</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>
|
||||
@@ -0,0 +1,89 @@
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html id="htmlId">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>Coverage Report > NetworkConfig</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</a>
|
||||
</div>
|
||||
|
||||
<h1>Coverage Summary for Class: NetworkConfig (it.polimi.ingsw.gc14.Network)</h1>
|
||||
|
||||
<table class="coverageStats">
|
||||
<tr>
|
||||
<th class="name">Class</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name">NetworkConfig</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<pre>
|
||||
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Network;
|
||||
|
||||
/** Shared network constants used by both server and client components. */
|
||||
public final class NetworkConfig {
|
||||
/** Port on which the RMI registry listens. */
|
||||
public static final int RMI_PORT = 1099;
|
||||
/** Port on which the TCP game server listens. */
|
||||
public static final int TCP_PORT = 8080;
|
||||
/** Port on which the TCP heartbeat server listens. */
|
||||
public static final int HEARTBEAT_PORT = 8081;
|
||||
/** Milliseconds of silence before a client is considered disconnected. */
|
||||
public static final long SILENCE_THRESHOLD_MS = 5_000;
|
||||
/** Milliseconds between keep-alive pings sent by the client. */
|
||||
public static final long KEEPALIVE_INTERVAL_MS = 3_000;
|
||||
/** Minimum number of players required to start a game. */
|
||||
public static final int MIN_PLAYERS = 2;
|
||||
/** Maximum number of players allowed in a game. */
|
||||
public static final int MAX_PLAYERS = 5;
|
||||
|
||||
private NetworkConfig() {}
|
||||
}
|
||||
</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>
|
||||
@@ -0,0 +1,146 @@
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html id="htmlId">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>Coverage Report > IClient</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</a>
|
||||
</div>
|
||||
|
||||
<h1>Coverage Summary for Class: IClient (it.polimi.ingsw.gc14.Network)</h1>
|
||||
|
||||
<table class="coverageStats">
|
||||
<tr>
|
||||
<th class="name">Class</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name">IClient</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<pre>
|
||||
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Network;
|
||||
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
|
||||
/**
|
||||
* Defines the operations that a client can request during the game.
|
||||
*/
|
||||
public interface IClient {
|
||||
|
||||
/**
|
||||
* Connects the client to the server using the specified username
|
||||
* and preferred connection type.
|
||||
*
|
||||
* @param username the username chosen by the player.
|
||||
* @param proposedNPlayers the desired number of players proposed by this client.
|
||||
* @return {@code true} if the connection is established successfully,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
ErrorType connect(String username, int proposedNPlayers);
|
||||
|
||||
/**
|
||||
* Requests to draw a tribe card from the upper tribe card list.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @param pos the position of the selected card in the upper tribe card list.
|
||||
*/
|
||||
void drawUpperTribeCard(String playerUsername, int pos);
|
||||
|
||||
/**
|
||||
* Requests to draw a tribe card from the lower tribe card list.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @param pos the position of the selected card in the lower tribe card list.
|
||||
*/
|
||||
void drawLowerTribeCard(String playerUsername, int pos);
|
||||
|
||||
/**
|
||||
* Requests to draw a building card from the upper building card list.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @param pos the position of the selected card in the upper building card list.
|
||||
*/
|
||||
void drawUpperBuildingCard(String playerUsername, int pos);
|
||||
|
||||
/**
|
||||
* Requests to draw a building card from the lower building card list.
|
||||
*
|
||||
* @param playerUsername the username of the player performing the action.
|
||||
* @param pos the position of the selected card in the lower building card list.
|
||||
*/
|
||||
void drawLowerBuildingCard(String playerUsername, int pos);
|
||||
|
||||
/**
|
||||
* Requests to skip the current player's optional action.
|
||||
*
|
||||
* @param playerUsername the username of the player skipping the action.
|
||||
*/
|
||||
void skipTurn(String playerUsername);
|
||||
|
||||
/**
|
||||
* Requests to assign the specified player to a slot.
|
||||
*
|
||||
* @param playerUsername the username of the player making the slot choice.
|
||||
* @param pos the position of the selected slot.
|
||||
*/
|
||||
void slotChoice(String playerUsername, int pos);
|
||||
|
||||
/**
|
||||
* Requests to assign the selected totem to the specified player.
|
||||
*
|
||||
* @param playerUsername the username of the player making the totem choice.
|
||||
* @param totem the name of the selected totem.
|
||||
*/
|
||||
void totemChoice(String playerUsername, String totem);
|
||||
|
||||
/** Notifies the server of a voluntary disconnection and closes the connection. */
|
||||
void notifyDisconnection();
|
||||
}
|
||||
</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>
|
||||
Reference in New Issue
Block a user