Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Ajout multi côté client
Browse files Browse the repository at this point in the history
  • Loading branch information
Feelzor committed Jan 25, 2019
1 parent c093db7 commit 0f6c502
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 105 deletions.
48 changes: 0 additions & 48 deletions client.adb

This file was deleted.

54 changes: 50 additions & 4 deletions p_client.adb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
with GNAT.Sockets, p_status, Text_IO, p_common;
use GNAT.Sockets, p_status, Text_IO, p_common;
with GNAT.Sockets, Ada.Strings, Ada.Strings.Fixed, p_status, Text_IO, p_common, p_vue_graph, p_jeu;
use GNAT.Sockets, Ada.Strings, Ada.Strings.Fixed, p_status, Text_IO, p_common, p_vue_graph, p_jeu;

package body p_client is

Expand All @@ -20,17 +20,63 @@ package body p_client is
end loop;
end T_Listen;

function connexion(addr: in string; port: in integer) return boolean is
-- {} => {résultat = vrai si le client se connecte au serveur}
begin
address.addr := inet_addr(addr);
address.port := Port_Type(port);

create_socket (socket);
set_socket_option (socket, socket_Level, (reuse_address, true));

connect_socket (socket, address);

channel := stream (socket);
listen.start(channel);

return true;

exception
when E : others =>
put_Line(exception_name (E) & ": " & exception_message (E));
return false;
end connexion;

procedure deconnexion is
-- {} => {Le client se déconnecte du serveur}
begin
close_socket (socket);
end deconnexion;

procedure traiterMessage(c: in stream_access; m: in string) is
-- {} => {Handles a message received by the server}
-- {} => {Gère un message reçu par le serveur}
code : integer;
msg : string(1..15);
tailleMsg : integer;
begin
code := statutMessage(m);
case code is
when AUTHENTIFICATION_NEEDED => authentification(c);
when AUTHENTIFICATION_NEEDED => envoyerMessage(c, creerMessageStatut(trim(pseudoClient, BOTH), SEND_NAME));
when AUTHENTIFICATION_REUSSIE => put_line("Connexion réussie !");
when PSEUDO_INCORRECT =>
put_line("Le pseudo est déjà utilisé, ou vide.");
authentification(c);
when SOLUTION_RESULTAT =>
decoderMessage(m, code, msg, tailleMsg);
actualisationEssai(fenetreJeu, msg(2..tailleMsg), Integer'value(msg(1..1)));
when ACTUALISATION_SCORE =>
decoderMessage(m, code, msg, tailleMsg);
changerTexte(fenetreJeu, "Score", trim(Integer'image(msg(1..tailleMsg)), BOTH) &
(if Integer'value(msg(1..tailleMsg)) >= 2 then " Points" else " Point"));
when FIN_JEU =>
chronoJeu.stop;
chrono.stop;
cacherElem(fenetreJeu, "valider");
changerEtatBouton(fenetreJeu, "valider", ARRET);
cacherElem(fenetreJeu, "abandon");
changerEtatBouton(fenetreJeu, "abandon", ARRET);
montrerElem(fenetreJeu, "finjeu");
changerEtatBouton(fenetreJeu, "finjeu", MARCHE);
when others => null;
end case;

Expand Down
14 changes: 13 additions & 1 deletion p_client.ads
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ package p_client is
entry start(c: in stream_access);
end T_Listen;

address : sock_addr_type;
socket : socket_type;
channel : stream_access;

pseudoClient : string(1..20);

function connexion(addr: in string; port: in integer) return boolean;
-- {} => {résultat = vrai si le client se connecte au serveur}

procedure deconnexion;
-- {} => {Le client se déconnecte du serveur}

procedure traiterMessage(c: in stream_access; m: in string);
-- {} => {Handles a message received by the server}
-- {} => {Gère un message reçu par le serveur}

procedure authentification(c: in stream_access);
-- {} => {Authentifie le joueur}
Expand Down
4 changes: 2 additions & 2 deletions p_server.adb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ package body p_server is
when SOLUTION_ESSAI =>
decoderMessage(m, code, solution, tailleSolution);
verifSol(solution(1..tailleSolution), resultatSolution);
envoyerMessage(c, creerMessageStatut(trim(Integer'image(resultatSolution), BOTH), SOLUTION_RESULTAT));
envoyerMessage(c, creerMessageStatut(trim(Integer'image(resultatSolution) & solution(1..tailleSolution), BOTH), SOLUTION_RESULTAT));
if resultatSolution = SOLUTION_CORRECTE then
envoyerMessageGlobal(SCORE, trim(Integer'image(compterPoints), BOTH));
envoyerMessageGlobal(ACTUALISATION_SCORE, trim(Integer'image(compterPoints), BOTH));
end if;
when others => null;
end case;
Expand Down
2 changes: 1 addition & 1 deletion p_status.ads
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package p_status is
FIN_JEU: constant integer := 5;
SOLUTION_ESSAI: constant integer := 6;
SOLUTION_RESULTAT: constant integer := 7;
SCORE: constant integer := 8;
ACTUALISATION_SCORE: constant integer := 8;

function creerMessageStatut(msg: in string; statut: in integer) return string;
-- {msg est le message à envoyer, statut le code représentant un statut}
Expand Down
Loading

0 comments on commit 0f6c502

Please sign in to comment.