/** * <summary> Lorsque l'on recoit une demande d'authentification. Si l'ID de connexion n'est pas déjà prise et que le type d'authentification est "Client", * alors on accepte. </summary> */ void OnAuthentificationRequestReceived(BloodAndBileEngine.Networking.NetworkMessageInfo info, AuthentificationMessage message) { BloodAndBileEngine.Debugger.Log("Demande d'authentification reçue !"); if (message.AuthType == AuthentificationType.CLIENT) { if (ConnectedPlayers.ContainsKey(info.ConnectionID)) { BloodAndBileEngine.Debugger.Log("Demande d'authentification par un ID de connexion déjà authentifié ! Refus.", Color.red); SendAuthentificationResponse(info.ConnectionID, false, "ID de connexion déjà occupée !"); } else { BloodAndBileEngine.Debugger.Log("Demande d'authentification acceptée !"); BloodAndBileEngine.Debugger.Log("Joueur connecté : " + message.Name + " à l'ID " + info.ConnectionID); SendAuthentificationResponse(info.ConnectionID, true); ConnectedPlayers.Add(info.ConnectionID, message.Name); // Ajout du joueur au dictionnaire des joueurs connectés. MatchmakingQueue.Add(info.ConnectionID); } } else { BloodAndBileEngine.Debugger.Log("Demande d'authentification autre que Client reçue ! Refus.", Color.red); SendAuthentificationResponse(info.ConnectionID, false, "Type d'authentification erroné ! Seul les clients peuvent se connecter au Match Server."); } }
// HANDLERS /** * <summary> Déclenché lorsqu'une requête d'authentification est reçue. </summary> */ void OnAuthentificationRequest(BloodAndBileEngine.Networking.NetworkMessageInfo info, AuthentificationMessage message) { if (message.AuthType != AuthentificationType.CLIENT) { return; // Si le type d'authentification n'est pas "Client", on ne fait rien. } BloodAndBileEngine.Debugger.Log("Requête d'authentification client reçue !", Color.yellow); BloodAndBileEngine.Debugger.Log("Vérification du compte...", Color.yellow); if (KnownClients.ContainsKey(message.Name)) { BloodAndBileEngine.Debugger.Log("Compte existant : " + message.Name); BloodAndBileEngine.Debugger.Log("Vérification du mot de passe..."); if (KnownClients[message.Name].GetPassword() != message.Password) { SendAuthentificationResponse(false, "Mot de passe invalide !", info.ConnectionID); } else { SendAuthentificationResponse(true, "", info.ConnectionID); LogIn(KnownClients[message.Name], info.ConnectionID); } } else // Le compte n'existe pas ! On en crée un nouveau puis on le connecte. { BloodAndBileEngine.Debugger.Log("Compte inconnu ! Création..."); KnownClients.Add(message.Name, new ClientAccountInfo(message.Name, message.Password, info.ConnectionID)); LogIn(KnownClients[message.Name], info.ConnectionID); SendAuthentificationResponse(true, "", info.ConnectionID); } }
void OnMatchServersListRequestReceived(BloodAndBileEngine.Networking.NetworkMessageInfo info, NetworkMessage msg) { BloodAndBileEngine.Debugger.Log("Demande de transfert de la liste des Match Servers reçue ! Envoie..."); List <string> IPs = new List <string>(); foreach (string IP in MatchServerIPs.Values) { IPs.Add(IP); } MessageSender.Send(new IPListMessage(IPs.ToArray()), info.ConnectionID, 0); }
// HANDLERS /** * <summary> Déclenché lorsqu'une requête d'authentification est reçue. </summary> */ void OnAuthentificationRequest(BloodAndBileEngine.Networking.NetworkMessageInfo info, AuthentificationMessage message) { if (message.AuthType != AuthentificationType.MATCH_SERVER) { return; // Si le type d'authentification n'est pas "Match_Server", on ne fait rien. } // On vérifie que cette IP ne soit pas déjà occupée. string IP; if (message.IP == "") { IP = NetworkSocket.GetConnectionInfoFromConnectionID(info.ConnectionID).IP.Split(':')[3]; } else { IP = message.IP; } BloodAndBileEngine.Debugger.Log("Tentative de connexion d'un Match Server avec l'IP " + IP); if (MatchServerIPs.ContainsKey(info.ConnectionID)) { BloodAndBileEngine.Debugger.Log("ERREUR - Cette ID de connexion est déjà occupée !", Color.red); SendAuthentificationResponse(false, "ID de connexion déjà prit !", info.ConnectionID); } else if (MatchServerIPs.ContainsValue(IP)) { BloodAndBileEngine.Debugger.Log("ERREUR - Cette IP est déjà répertoriée !", Color.red); SendAuthentificationResponse(false, "IP déjà prise !", info.ConnectionID); } else if (message.Password == MatchServerPassword) { MatchServerIPs.Add(info.ConnectionID, IP); BloodAndBileEngine.Debugger.Log("Ajout d'un Match Server : " + IP); SendAuthentificationResponse(true, "", info.ConnectionID); } }