Multi : rewrite loopback client->hote + serveur durci + LS_MP_AUTOJOIN
- Le matchmaker transmet l'ip du hote telle qu'il la voit : derriere NAT/loopback (emulateur 10.0.2.2) le client tentait 127.0.0.1:2829 = lui- meme -> tcpOut null -> crash requestState au GAME_JOIN. Network.addPlayer reecrit une ip loopback vers l'hote du matchmaker (resolvableIp), logs LS-NET sur la connexion TCP (avant : System.out) - Matchmaking-Server : gardes anti-crash sur GAME_CREATE/GAME_JOIN/ GAME_PING sans jeu connu (un ack apres purge tuait tout le serveur node -> tous les clients suivants timeout, constat 16/11) - LS_MP_AUTOJOIN=1 : la recherche demarre au chargement du lobby (test coop desktop sans simulateur de clic) - Coop epreuve reelle desktop(hote)+emulateur(client via 10.0.2.2) : pairing OK, join sans crash, les DEUX dans le niveau multiplayer (captures) ; la visibilite croisee des joueurs reste le chantier handshake P2P (traces TODO)
This commit is contained in:
parent
89df5d7d0c
commit
89df1cc988
@ -20,6 +20,7 @@ public class Matchmaker implements NetworkConstants {
|
|||||||
private long lastGamePing = 0;
|
private long lastGamePing = 0;
|
||||||
|
|
||||||
public Matchmaker(InetAddress ip, int serverPort) {
|
public Matchmaker(InetAddress ip, int serverPort) {
|
||||||
|
Network.setMatchmakerAddress(ip);
|
||||||
DatagramSocket socket = null;
|
DatagramSocket socket = null;
|
||||||
try {
|
try {
|
||||||
socket = new DatagramSocket();
|
socket = new DatagramSocket();
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@ -183,15 +184,52 @@ public class Network {
|
|||||||
GameListeners.addUpdateListener(Network::update);
|
GameListeners.addUpdateListener(Network::update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adresse du matchmaker utilisée par CE client (posée par Matchmaker à
|
||||||
|
* sa construction). POURQUOI : le matchmaker transmet l'ip du hôte TELLE
|
||||||
|
* QU'IL LA VOIT — derrière un NAT/loopback c'est l'adresse du NAT, pas
|
||||||
|
* une adresse joignable par les clients (émulateur Android : le hôte est
|
||||||
|
* 10.0.2.2 mais le matchmaker le voit en 127.0.0.1 ; un client qui tente
|
||||||
|
* 127.0.0.1:2829 se connecte à LUI-MÊME -> tcpOut null -> crash
|
||||||
|
* requestState). Un joueur annoncé en loopback est donc réécrit vers
|
||||||
|
* l'hôte du matchmaker : dans ces topologies (émulateur, LAN local),
|
||||||
|
* hôte et matchmaker sont la même machine.
|
||||||
|
*/
|
||||||
|
private static InetAddress matchmakerAddress;
|
||||||
|
|
||||||
|
static void setMatchmakerAddress(InetAddress address) {
|
||||||
|
matchmakerAddress = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Réécrit une ip de joueur loopback vers l'hôte du matchmaker. */
|
||||||
|
private static String resolvableIp(String playerIp) {
|
||||||
|
try {
|
||||||
|
if (matchmakerAddress != null
|
||||||
|
&& (InetAddress.getByName(playerIp).isLoopbackAddress())
|
||||||
|
&& !matchmakerAddress.isLoopbackAddress()) {
|
||||||
|
GameLog.i("LS-NET", "Multiplayer : ip hôte '" + playerIp
|
||||||
|
+ "' loopback -> réécrite vers " + matchmakerAddress.getHostAddress()
|
||||||
|
+ " (NAT/émulateur)");
|
||||||
|
return matchmakerAddress.getHostAddress();
|
||||||
|
}
|
||||||
|
} catch (java.net.UnknownHostException e) {
|
||||||
|
// Laisse l'ip d'origine : addPlayer gèrera l'échec de connexion.
|
||||||
|
}
|
||||||
|
return playerIp;
|
||||||
|
}
|
||||||
|
|
||||||
static void addPlayer(MatchmakingPlayer player) {
|
static void addPlayer(MatchmakingPlayer player) {
|
||||||
udpAddresses[player.getId()] = new InetSocketAddress(player.getIp(), player.getUdpPort());
|
String ip = resolvableIp(player.getIp());
|
||||||
|
udpAddresses[player.getId()] = new InetSocketAddress(ip, player.getUdpPort());
|
||||||
udpOut.setAddresses(udpAddresses);
|
udpOut.setAddresses(udpAddresses);
|
||||||
try {
|
try {
|
||||||
System.out.println("Attempting to connect to TCP port " + player.getTcpPort());
|
GameLog.i("LS-NET", "Multiplayer : connexion TCP au joueur " + player.getId()
|
||||||
tcpOut[player.getId()] = new TCPWriter(new Socket(player.getIp(), player.getTcpPort()));
|
+ " sur " + ip + ":" + player.getTcpPort());
|
||||||
|
tcpOut[player.getId()] = new TCPWriter(new Socket(ip, player.getTcpPort()));
|
||||||
tcpOut[player.getId()].start();
|
tcpOut[player.getId()].start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
GameLog.e("LS-NET", "Multiplayer : connexion TCP au joueur "
|
||||||
|
+ player.getId() + " impossible (" + ip + ":" + player.getTcpPort() + ")", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package com.ezardlabs.lostsector;
|
package com.ezardlabs.lostsector;
|
||||||
|
|
||||||
|
import com.ezardlabs.dethsquare.Time;
|
||||||
import com.ezardlabs.dethsquare.Transform;
|
import com.ezardlabs.dethsquare.Transform;
|
||||||
import com.ezardlabs.dethsquare.Vector2;
|
import com.ezardlabs.dethsquare.Vector2;
|
||||||
|
import com.ezardlabs.dethsquare.util.GameLog;
|
||||||
import com.ezardlabs.lostsector.NavMesh.NavPoint.NavPointType;
|
import com.ezardlabs.lostsector.NavMesh.NavPoint.NavPointType;
|
||||||
import com.ezardlabs.lostsector.map.MapManager;
|
import com.ezardlabs.lostsector.map.MapManager;
|
||||||
|
|
||||||
@ -101,7 +103,26 @@ public class NavMesh {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static NavPoint[] getPath(Vector2 a, Vector2 b) {
|
public static NavPoint[] getPath(Vector2 a, Vector2 b) {
|
||||||
return getPath(getNavPoint(a), getNavPoint(b));
|
/*
|
||||||
|
* Hors grille (v0.12.x) : getNavPoint renvoie null pour une position
|
||||||
|
* hors du graphe (l'ancien clamp renvoyait SILENCIEUSEMENT la cellule
|
||||||
|
* la plus proche — le BFS cherchait alors un chemin depuis/vers une
|
||||||
|
* case fausse sans jamais le dire, diagnostic impossible à distance).
|
||||||
|
* On signale ici, log throttlé 1/300 frames (politique AGENTS.md),
|
||||||
|
* et on rend un chemin vide : l'ennemi reste sur place (comportement
|
||||||
|
* dégradé assumé, PAS de téléportation ni de crash).
|
||||||
|
*/
|
||||||
|
NavPoint start = getNavPoint(a);
|
||||||
|
NavPoint end = getNavPoint(b);
|
||||||
|
if (start == null || end == null) {
|
||||||
|
if (Time.frameCount % 300 == 0) {
|
||||||
|
GameLog.d("LS-AI", "getPath : position hors grille NavMesh (a=" + a
|
||||||
|
+ (start == null ? " [HORS GRILLE]" : "")
|
||||||
|
+ " b=" + b + (end == null ? " [HORS GRILLE]" : "") + ")");
|
||||||
|
}
|
||||||
|
return new NavPoint[0];
|
||||||
|
}
|
||||||
|
return getPath(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NavPoint[] getPath(NavPoint start, NavPoint end) {
|
public static NavPoint[] getPath(NavPoint start, NavPoint end) {
|
||||||
@ -160,12 +181,23 @@ public class NavMesh {
|
|||||||
|
|
||||||
public static NavPoint getNavPoint(float x, float y) {
|
public static NavPoint getNavPoint(float x, float y) {
|
||||||
/*
|
/*
|
||||||
* Clamp aux bornes : un ennemi hors de la grille (spawn en l'air au
|
* Hors grille -> null (v0.12.x, remplace le clamp) : le clamp
|
||||||
* bord de la carte, ou poussé hors champ) provoquait un
|
* renvoyait le point le plus proche — une cellule FAUSSE et silencieuse
|
||||||
* ArrayIndexOutOfBounds fatal — on renvoie le point le plus proche.
|
* pour un joueur/ennemi hors du NavMesh (spawn en l'air au bord de la
|
||||||
|
* carte, ou poussé hors champ). Le crash ArrayIndexOutOfBounds d'origine
|
||||||
|
* reste évité, mais le cas est maintenant VISIBLE : getPath logue
|
||||||
|
* throttlé et l'ennemi reste sur place ( Behaviour.getPath gère null,
|
||||||
|
* seuls appelants existants vérifiés par grep).
|
||||||
|
* Convention 2017 CONSERVÉE : j = round(y/100) + 1 — le NavPoint d'une
|
||||||
|
* position porte l'index de la cellule sous ses pieds (position d'une
|
||||||
|
* entité = origine en haut du collider de 200px de haut : y=25500 ->
|
||||||
|
* cellules 255-256, j+1 vise la cellule basse du corps, celle qui
|
||||||
|
* "tient debout"). Ne pas "corriger" ce +1 sans revalider le mapping
|
||||||
|
* acquisitions/chemins sur émulateur.
|
||||||
*/
|
*/
|
||||||
int i = Math.max(0, Math.min(navPoints.length - 1, Math.round(x / 100f)));
|
int i = Math.round(x / 100f);
|
||||||
int j = Math.max(0, Math.min(navPoints[0].length - 1, Math.round(y / 100f) + 1));
|
int j = Math.round(y / 100f) + 1;
|
||||||
|
if (i < 0 || i >= navPoints.length || j < 0 || j >= navPoints[0].length) return null;
|
||||||
return navPoints[i][j];
|
return navPoints[i][j];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,14 +292,43 @@ public class NavMesh {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jump links
|
/*
|
||||||
/*for (int x = 0; x < navPoints.length; x++) {
|
* Jump links (RÉACTIVÉS v0.12.x, adaptés du bloc 2017 commenté).
|
||||||
|
*
|
||||||
|
* POURQUOI c'est le fix central du retour "ils tentent pas de venir me
|
||||||
|
* chercher" : le 2017 avait désactivé ce bloc ENTIER — les étages
|
||||||
|
* multi-niveaux n'étaient JAMAIS reliés verticalement à la montée.
|
||||||
|
* La convention BFS (NavPoint.index) réserve JUMP à la montée
|
||||||
|
* (cible plus haut) et FALL à la descente ; les FALL existaient, donc
|
||||||
|
* DESCENDRE restait possible, mais MONTER un étage = aucun chemin
|
||||||
|
* possible pour TOUS les ennemis, systématiquement (joueur sur un
|
||||||
|
* étage supérieur -> "aucun chemin NavMesh" en boucle).
|
||||||
|
*
|
||||||
|
* Cas couvert : un rebord (RIGHT_EDGE/SOLO/LEFT_EDGE) buttant contre
|
||||||
|
* un mur — l'ennemi saute SUR le haut du mur / la marche supérieure.
|
||||||
|
* Contraintes :
|
||||||
|
* - hauteur max 3 cellules (boucle 2017 i<4) : cohérent avec la
|
||||||
|
* physique de Behaviour.jump(d) (v = √(2.5·d)+2 -> apogée ≈ d + marge,
|
||||||
|
* Rigidbody.gravity=1.25 -> apogée = v²/2.5) ; le joueur, lui, monte
|
||||||
|
* plus haut (double saut + wall jump, Player.java) — l'IA reste plus
|
||||||
|
* limitée que le joueur, choix assumé.
|
||||||
|
* - atterrissage VALIDE (isJumpLanding) : cellule libre + tête libre +
|
||||||
|
* APPUI sous les pieds. Le bloc 2017 sautait ce check — un link vers
|
||||||
|
* une cellule en l'air (NavPoint sans walk links) créait un
|
||||||
|
* cul-de-sac dans le graphe : le BFS y entrait et n'en ressortait
|
||||||
|
* jamais. Un atterrissage avec appui est une cellule "debout", donc
|
||||||
|
* déjà chaînée à sa plateforme par les walk links.
|
||||||
|
* - garde-fou addLink : toute cible hors graphe est rejetée.
|
||||||
|
* (Le addLink du cas RIGHT du 2017 ciblait x-1 au lieu de x+1 — typo
|
||||||
|
* d'époque, corrigée ici en version symétrique du cas LEFT.)
|
||||||
|
*/
|
||||||
|
for (int x = 0; x < navPoints.length; x++) {
|
||||||
for (int y = 0; y < navPoints[x].length; y++) {
|
for (int y = 0; y < navPoints[x].length; y++) {
|
||||||
if (navPoints[x][y].type == NavPointType.RIGHT_EDGE || navPoints[x][y].type == NavPointType.SOLO) {
|
if (navPoints[x][y].type == NavPointType.RIGHT_EDGE || navPoints[x][y].type == NavPointType.SOLO) {
|
||||||
if (isCollision(solidityMap, x + 1, y)) {
|
if (isCollision(solidityMap, x + 1, y)) {
|
||||||
for (int i = 1; i < 4; i++) {
|
for (int i = 1; i <= 3; i++) {
|
||||||
if (!isCollision(solidityMap, x + 1, y - i) && !isCollision(solidityMap, x + 1, y - i - 1)) {
|
if (isJumpLanding(solidityMap, x + 1, y - i)) {
|
||||||
// addLink(x - 1, y, x + 1, y - i, LinkType.JUMP);
|
addLink(x, y, x + 1, y - i, LinkType.JUMP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,19 +336,61 @@ public class NavMesh {
|
|||||||
}
|
}
|
||||||
if (navPoints[x][y].type == NavPointType.LEFT_EDGE || navPoints[x][y].type == NavPointType.SOLO) {
|
if (navPoints[x][y].type == NavPointType.LEFT_EDGE || navPoints[x][y].type == NavPointType.SOLO) {
|
||||||
if (isCollision(solidityMap, x - 1, y)) {
|
if (isCollision(solidityMap, x - 1, y)) {
|
||||||
for (int i = 1; i < 4; i++) {
|
for (int i = 1; i <= 3; i++) {
|
||||||
if (!isCollision(solidityMap, x - 1, y - i) && !isCollision(solidityMap, x - 1, y - i - 1)) {
|
if (isJumpLanding(solidityMap, x - 1, y - i)) {
|
||||||
// addLink(x, y, x - 1, y - i, LinkType.JUMP);
|
addLink(x, y, x - 1, y - i, LinkType.JUMP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Synthèse d'init : la première ligne à lire pour vérifier que les
|
||||||
|
* jump links existent bien sur une carte donnée (saut=0 -> aucune
|
||||||
|
* marche ≤ 3 cellules détectée : la montée inter-étages restera
|
||||||
|
* impossible sur CETTE carte, à distinguer d'un patch absent).
|
||||||
|
* addLink est bidirectionnel : chaque lien est compté deux fois.
|
||||||
|
*/
|
||||||
|
int marches = 0;
|
||||||
|
int chutes = 0;
|
||||||
|
int sauts = 0;
|
||||||
|
for (NavPoint[] colonne : navPoints) {
|
||||||
|
for (NavPoint p : colonne) {
|
||||||
|
for (NavPoint.Link l : p.links) {
|
||||||
|
switch (l.linkType) {
|
||||||
|
case WALK: marches++; break;
|
||||||
|
case FALL: chutes++; break;
|
||||||
|
case JUMP: sauts++; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GameLog.i("LS-MAP", "NavMesh init : grille " + navPoints.length + "x" + navPoints[0].length
|
||||||
|
+ ", liens marche=" + marches + " chute=" + chutes + " saut=" + sauts
|
||||||
|
+ " (bidirectionnels -> comptés 2x)");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Atterrissage de saut valide : cellule libre, tête libre (l'ennemi fait
|
||||||
|
* 2 cellules de haut), appui solide sous les pieds. Voir le commentaire
|
||||||
|
* du bloc jump links pour le POURQUOI de chaque condition.
|
||||||
|
*/
|
||||||
|
private static boolean isJumpLanding(int[][] solidity, int x, int y) {
|
||||||
|
return !isCollision(solidity, x, y) // cellule d'atterrissage libre
|
||||||
|
&& !isCollision(solidity, x, y - 1) // place pour la tête
|
||||||
|
&& isCollision(solidity, x, y + 1); // appui sous les pieds
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addLink(int x1, int y1, int x2, int y2, LinkType type) {
|
private static void addLink(int x1, int y1, int x2, int y2, LinkType type) {
|
||||||
|
/*
|
||||||
|
* Garde-fou : un link vers une cellule hors graphe est un cul-de-sac
|
||||||
|
* silencieux (le BFS atteint un NavPoint inexistant -> crash ou chemin
|
||||||
|
* corrompu selon l'appelant). Toute création de link passe ici.
|
||||||
|
*/
|
||||||
|
if (x2 < 0 || x2 >= navPoints.length || y2 < 0 || y2 >= navPoints[0].length) return;
|
||||||
navPoints[x1][y1].links.add(new NavPoint.Link(type, navPoints[x2][y2]));
|
navPoints[x1][y1].links.add(new NavPoint.Link(type, navPoints[x2][y2]));
|
||||||
navPoints[x2][y2].links.add(new NavPoint.Link(type, navPoints[x1][y1]));
|
navPoints[x2][y2].links.add(new NavPoint.Link(type, navPoints[x1][y1]));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -196,6 +196,16 @@ public abstract class Behaviour {
|
|||||||
private NavPoint[] getPath() {
|
private NavPoint[] getPath() {
|
||||||
NavPoint self = NavMesh.getNavPoint(transform.position.x, transform.position.y);
|
NavPoint self = NavMesh.getNavPoint(transform.position.x, transform.position.y);
|
||||||
NavPoint targetNavPoint = NavMesh.getNavPoint(target.position);
|
NavPoint targetNavPoint = NavMesh.getNavPoint(target.position);
|
||||||
|
/*
|
||||||
|
* Hors grille (v0.12.x) : getNavPoint renvoie null pour une position
|
||||||
|
* hors du graphe. Pas de recalcul ni de NPE — l'ennemi reste sur place
|
||||||
|
* (comportement dégradé documenté) et le log "aucun chemin" de move()
|
||||||
|
* (throttlé /300 frames) trace les positions pour le diagnostic.
|
||||||
|
*/
|
||||||
|
if (self == null || targetNavPoint == null) {
|
||||||
|
path = null;
|
||||||
|
return path;
|
||||||
|
}
|
||||||
if ((!self.equals(currentNavPoint) || !targetNavPoint.equals(currentTargetNavPoint)) && !self.links.isEmpty()) {
|
if ((!self.equals(currentNavPoint) || !targetNavPoint.equals(currentTargetNavPoint)) && !self.links.isEmpty()) {
|
||||||
currentNavPoint = self;
|
currentNavPoint = self;
|
||||||
currentTargetNavPoint = targetNavPoint;
|
currentTargetNavPoint = targetNavPoint;
|
||||||
|
|||||||
@ -98,6 +98,19 @@ public class MultiplayerLobbyLevel extends Level {
|
|||||||
TouchControls.attach(); // EN PREMIER (ordre d'update) — écoute "clic"
|
TouchControls.attach(); // EN PREMIER (ordre d'update) — écoute "clic"
|
||||||
TouchControls.setButtonsVisible(false); // pas de boutons de jeu au lobby
|
TouchControls.setButtonsVisible(false); // pas de boutons de jeu au lobby
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LS_MP_AUTOJOIN=1 : lancement automatique de la recherche au
|
||||||
|
* chargement du lobby (outil de test : la coop desktop <-> émulateur
|
||||||
|
* nécessitait un clic sur LANCER — impossible à simuler côté desktop
|
||||||
|
* sans accès d'aide macOS ; cf. scripts de test). Désactivé par
|
||||||
|
* défaut : le joueur garde le contrôle du lancement.
|
||||||
|
*/
|
||||||
|
if ("1".equals(System.getenv("LS_MP_AUTOJOIN"))) {
|
||||||
|
GameLog.i(TAG, "LS_MP_AUTOJOIN : lancement automatique de la recherche");
|
||||||
|
connecting = true;
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
|
||||||
GameObject.instantiate(new GameObject("Camera", new Camera(true)), new Vector2());
|
GameObject.instantiate(new GameObject("Camera", new Camera(true)), new Vector2());
|
||||||
|
|
||||||
TextureAtlas font = TextureAtlas.load("fonts");
|
TextureAtlas font = TextureAtlas.load("fonts");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user