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

Commit

Permalink
Correction bugs multi
Browse files Browse the repository at this point in the history
  • Loading branch information
Feelzor committed Jan 26, 2019
1 parent 0f6c502 commit de7a922
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 64 deletions.
7 changes: 4 additions & 3 deletions gaudigraph.adb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
with p_combinaisons, p_fenbase, p_vue_graph;
use p_combinaisons, p_fenbase, p_vue_graph;
with p_combinaisons, p_fenbase, p_vue_graph, p_client;
use p_combinaisons, p_fenbase, p_vue_graph, p_client;

procedure gaudigraph is
V: TV_Gaudi(1..16);
begin
fichiersInit(V);
initialiserFenetres;
fenetreaccueil;
initialiserSocket;
fenetreAccueil;
end gaudigraph;
76 changes: 52 additions & 24 deletions p_client.adb
Original file line number Diff line number Diff line change
@@ -1,50 +1,69 @@
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;
with GNAT.Sockets, Ada.Exceptions, Ada.Strings, Ada.Strings.Fixed, p_status, Text_IO, p_common, p_vue_graph, p_jeu, p_fenbase;
use GNAT.Sockets, Ada.Exceptions, Ada.Strings, Ada.Strings.Fixed, p_status, Text_IO, p_common, p_vue_graph, p_jeu, p_fenbase;

package body p_client is

task body T_Listen is
channel: stream_access;
begin
accept start(c: in stream_access) do
channel := c;
end start;

loop
declare
message : string := String'input (channel);
begin
put_line(message);
traiterMessage(channel, message);
end;
if not est_connecte then
select
accept start(c: in stream_access) do
channel := c;
end start;
or
terminate;
end select;
else
while est_connecte loop
declare
message : string := String'input (channel);
begin
if message'length > 0 then
traiterMessage(channel, message);
end if;
end;
end loop;
end if;
end loop;
end T_Listen;

procedure initialiserSocket is
-- {} => {Un socket de connexion a été créé}
begin
--create_socket (socket);
--set_socket_option (socket, SOCKET_LEVEL, (REUSE_ADDRESS, true));
null;
end initialiserSocket;

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));
set_socket_option (socket, SOCKET_LEVEL, (REUSE_ADDRESS, true));

connect_socket (socket, address);

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

return true;

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

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

Expand All @@ -63,20 +82,29 @@ package body p_client is
authentification(c);
when SOLUTION_RESULTAT =>
decoderMessage(m, code, msg, tailleMsg);
actualisationEssai(fenetreJeu, msg(2..tailleMsg), Integer'value(msg(1..1)));
effacerGrille(fenetreDeJeu);
actualisationEssai(fenetreDeJeu, 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) &
changerTexte(fenetreDeJeu, "Score", trim(msg(1..tailleMsg), BOTH) &
(if Integer'value(msg(1..tailleMsg)) >= 2 then " Points" else " Point"));
when DEBUT_JEU =>
decoderMessage(m, code, msg, tailleMsg);

while not jeuOuvert loop
delay 0.1;
end loop;

chrono.start(Duration'value(msg(1..tailleMsg)));
jeuEnCours := true;
chronoJeu.start(fenetreDeJeu);
tailleSolution := 0;
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);
jeuEnCours := false;
cacherElem(fenetreDeJeu, "valider");
cacherElem(fenetreDeJeu, "abandon");
montrerElem(fenetreDeJeu, "finjeu");
deconnexion;
when others => null;
end case;

Expand Down
13 changes: 11 additions & 2 deletions p_client.ads
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
with GNAT.Sockets ;
use GNAT.Sockets ;
with GNAT.Sockets, p_fenbase;
use GNAT.Sockets, p_fenbase;

package p_client is
task type T_Listen is
Expand All @@ -9,9 +9,18 @@ package p_client is
address : sock_addr_type;
socket : socket_type;
channel : stream_access;
est_connecte : boolean := false;

listen : T_Listen;

pseudoClient : string(1..20);

fenetreDeJeu: TR_Fenetre;
jeuOuvert: boolean := false;

procedure initialiserSocket;
-- {} => {Un socket de connexion a été créé}

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

Expand Down
2 changes: 1 addition & 1 deletion p_jeu.adb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ package body p_jeu is
if datefin < Ada.Calendar.Clock then
actif := false;
tempsRestant := 0.0;
finJeu(false); -- fin du jeu sans abandon
if not enLigne then finJeu(false); end if; -- fin du jeu sans abandon
else
tempsRestant := datefin - Ada.Calendar.Clock;
prochaine_maj := prochaine_maj + FREQUENCE_MAJ;
Expand Down
2 changes: 1 addition & 1 deletion p_jeu.ads
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ package p_jeu is
pseudo: string(1..20);

tempsRestant : duration := 0.0;
jeuEnCours, coteServeur : boolean := false;
jeuEnCours, coteServeur, enLigne : boolean := false;
chrono : T_Chrono;

procedure debutJeu(contigue: in boolean; temps: in duration);
Expand Down
22 changes: 15 additions & 7 deletions p_server.adb
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,32 @@ package body p_server is
-- {} => {Gère un message reçu par le serveur}
code : integer;

pseudo : string(1..20);
taillePseudo : integer;

solution : string(1..14);
tailleSolution : integer;
resultatSolution : integer;
begin
code := statutMessage(m);
case code is
when SEND_NAME =>
decoderMessage(m, code, joueurs(pid).name, joueurs(pid).nameLen);
if verificationPseudo(pid) then
decoderMessage(m, code, pseudo, taillePseudo);
if verificationPseudo(pid, pseudo) then
joueurs(pid).name := pseudo;
joueurs(pid).nameLen := taillePseudo;
put_line("Le joueur " & joueurs(pid).name(1..joueurs(pid).nameLen) & " vient de se connecter.");
envoyerMessage(c, creerMessageStatut("", AUTHENTIFICATION_REUSSIE));
else
envoyerMessage(c, creerMessageStatut("", PSEUDO_INCORRECT));
end if;
when SOLUTION_ESSAI =>
decoderMessage(m, code, solution, tailleSolution);
verifSol(solution(1..tailleSolution), resultatSolution);
if tailleSolution >= 6 then
verifSol(solution(1..tailleSolution), resultatSolution);
else
resultatSolution := SOLUTION_INVALIDE;
end if;
envoyerMessage(c, creerMessageStatut(trim(Integer'image(resultatSolution) & solution(1..tailleSolution), BOTH), SOLUTION_RESULTAT));
if resultatSolution = SOLUTION_CORRECTE then
envoyerMessageGlobal(ACTUALISATION_SCORE, trim(Integer'image(compterPoints), BOTH));
Expand All @@ -51,13 +60,12 @@ package body p_server is

end traiterMessage;

function verificationPseudo(pid: in integer) return boolean is
function verificationPseudo(pid: in integer; pseudo: in string) return boolean is
-- {} => {Vérifie que le joueur à l'id pid a un pseudo correct (non vide et pas de doublon)}
i : integer := joueurs'first;
begin
if joueurs(pid).name = EMPTY_NAME then return false; end if;
while i = pid or (i <= joueurs'last and then
joueurs(i).name(joueurs(i).nameLen) /= joueurs(pid).name(joueurs(pid).nameLen)) loop
if pseudo = EMPTY_NAME then return false; end if;
while i = pid or else (i <= joueurs'last and then pseudo /= joueurs(i).name) loop
i := i + 1;
end loop;
return i > joueurs'last;
Expand Down
2 changes: 1 addition & 1 deletion p_server.ads
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package p_server is
procedure traiterMessage(c: in stream_access; m: in string; pid: in integer);
-- {} => {Gère un message reçu par le serveur}

function verificationPseudo(pid: in integer) return boolean;
function verificationPseudo(pid: in integer; pseudo : in string) return boolean;
-- {} => {Vérifie que le joueur à l'id pid a un pseudo correct}

procedure envoyerMessageGlobal(code: in integer; m: in string);
Expand Down
Loading

0 comments on commit de7a922

Please sign in to comment.