#include <ClientSP.h>
Collaboration diagram for ClientSP:
Public Member Functions | |
ClientSP (string adresse, unsigned int port, string login="", string mdp="") | |
Constructeur de la classe. | |
~ClientSP () | |
bool | EstPret () |
Méthode indiquant que le client a fini sont travail (il a obtenu le port TCP du serveur de jeu). | |
unsigned int | GetPort () |
Méthode permettant de récupérer le port. | |
string | GetLogin () |
Méthode permettant de récupérer le login. | |
Private Member Functions | |
void | Traitement (string login, string mdp) |
Méthode gérant le déroulement du protocole. | |
void | SendHello () |
void | SendLogin (string login, string mdp) |
void | RegLogin (string login, string mdp) |
unsigned int | ListerPartie () |
void | ListerScore () |
void | ChoisirPartie () |
int | CreationPartie () |
int | RejoindrePartie (string port) |
Private Attributes | |
Socket * | mSocket |
Pointeur sur la socket de communication. | |
bool | mPortRenseigne |
Booléen indiquant que le port est renseigné (obtenu du serveur principal). | |
unsigned int | mPort |
Port TCP du serveur de jeu. | |
string | mLogin |
Login qui a bien été identifié par le serveur principal. |
Definition at line 38 of file ClientSP.h.
ClientSP::ClientSP | ( | string | adresse, | |
unsigned int | port, | |||
string | login = "" , |
|||
string | mdp = "" | |||
) |
Constructeur de la classe.
Si le login et le mot de passe sont vides, ils seront demandés
adresse | Adresse du serveur principal | |
port | Port du serveur principal | |
login | Login de l'utilisateur | |
mdp | Mot de passe de l'utilisateur |
Definition at line 23 of file ClientSP.cpp.
References mPort, mPortRenseigne, mSocket, and Traitement().
00023 { 00024 mSocket=new SocketTCP(adresse,port); 00025 mPortRenseigne=false; 00026 mPort=0; 00027 Traitement(login, mdp); 00028 }
Here is the call graph for this function:
ClientSP::~ClientSP | ( | ) |
Definition at line 30 of file ClientSP.cpp.
References mSocket.
00030 { 00031 delete mSocket; 00032 }
bool ClientSP::EstPret | ( | ) | [inline] |
Méthode indiquant que le client a fini sont travail (il a obtenu le port TCP du serveur de jeu).
Definition at line 55 of file ClientSP.h.
References mPortRenseigne.
00055 {return mPortRenseigne;}
unsigned int ClientSP::GetPort | ( | ) | [inline] |
Méthode permettant de récupérer le port.
Definition at line 61 of file ClientSP.h.
References mPort.
00061 {return mPort;}
string ClientSP::GetLogin | ( | ) | [inline] |
Méthode permettant de récupérer le login.
Definition at line 67 of file ClientSP.h.
References mLogin.
00067 {return mLogin;}
void ClientSP::Traitement | ( | string | login, | |
string | mdp | |||
) | [private] |
Méthode gérant le déroulement du protocole.
login | ||
mdp |
Definition at line 34 of file ClientSP.cpp.
References ChoisirPartie(), ListerPartie(), ListerScore(), RegLogin(), SendHello(), and SendLogin().
Referenced by ClientSP().
00034 { 00035 SendHello(); 00036 string rep; 00037 do{ 00038 cout<<"Etes-vous déjà utilisateur? o/n "; cin>>rep; 00039 if(rep=="o"){ 00040 SendLogin(login,mdp); break; 00041 } else if(rep=="n"){ 00042 RegLogin(login,mdp); break; 00043 } 00044 } while(1); 00045 rep=""; 00046 do{ 00047 cout<<endl; 00048 cout<<"p Lister les parties"<<endl; 00049 cout<<"s Avoir les scores"<<endl; 00050 cout<<"c Choisir ou créer une partie"<<endl<<">"; cin>>rep; 00051 if(rep=="p"){ 00052 ListerPartie(); 00053 } else if(rep=="s"){ 00054 ListerScore(); 00055 } else if(rep=="c"){ 00056 ChoisirPartie(); break; 00057 } 00058 } while(1); 00059 00060 00061 }
Here is the call graph for this function:
void ClientSP::SendHello | ( | ) | [private] |
Definition at line 63 of file ClientSP.cpp.
References Socket::Ecouter(), Socket::Envoyer(), and mSocket.
Referenced by Traitement().
00063 { 00064 while(1){ 00065 cout<<"Initialisation du protocole avec le serveur"; 00066 mSocket->Envoyer("HELLO"); 00067 if(mSocket->Ecouter()!="HELLO") printf( "\e[31m [Echec]\n\e[m"); 00068 else { 00069 printf( "\e[32m [OK]\n\e[m"); 00070 break; 00071 } 00072 } 00073 }
Here is the call graph for this function:
void ClientSP::SendLogin | ( | string | login, | |
string | mdp | |||
) | [private] |
Definition at line 75 of file ClientSP.cpp.
References Socket::Ecouter(), Socket::Envoyer(), mLogin, and mSocket.
Referenced by Traitement().
00075 { 00076 string retour, reponse; 00077 while(1){ 00078 cout<<"Envoi du login au serveur"<<endl; 00079 while(login==""){ 00080 cout<<"Login: "; cin>>login; 00081 } 00082 while(mdp==""){ 00083 cout<<"Mot de passe: "; cin>>mdp; 00084 } 00085 reponse="LOGIN "; reponse+=login; reponse+=" "; reponse +=mdp; 00086 mSocket->Envoyer(reponse); 00087 if(mSocket->Ecouter()=="LOGIN OK") break; 00088 else { 00089 login=""; mdp=""; 00090 } 00091 00092 } 00093 mLogin=login; 00094 }
Here is the call graph for this function:
void ClientSP::RegLogin | ( | string | login, | |
string | mdp | |||
) | [private] |
Definition at line 96 of file ClientSP.cpp.
References Socket::Ecouter(), Socket::Envoyer(), and mSocket.
Referenced by Traitement().
00096 { 00097 string retour; 00098 while(1){ 00099 cout<<"Création d'un compte"<<endl; 00100 while(login==""){ 00101 cout<<"Login: "; cin>>login; 00102 } 00103 while(mdp==""){ 00104 cout<<"Mot de passe: "; cin>>mdp; 00105 } 00106 string reponse="REG "; reponse+=login; reponse+=" "; reponse +=mdp; 00107 mSocket->Envoyer(reponse); 00108 if(mSocket->Ecouter()=="REG OK") break; 00109 else { 00110 login=""; mdp=""; 00111 } 00112 } 00113 }
Here is the call graph for this function:
unsigned int ClientSP::ListerPartie | ( | ) | [private] |
Definition at line 115 of file ClientSP.cpp.
References Socket::Ecouter(), Socket::Envoyer(), and mSocket.
Referenced by ChoisirPartie(), and Traitement().
00115 { 00116 mSocket->Envoyer("LIST"); 00117 string line=mSocket->Ecouter(); 00118 istringstream iss(line); 00119 string cmd; 00120 getline(iss,cmd,' '); 00121 unsigned int nb=0; 00122 if(cmd=="LIST"){ 00123 cout<<endl<<"Liste des parties en cours :"<<endl; 00124 do{ 00125 string port, nbFantome; 00126 getline(iss,port,' '); getline(iss,nbFantome,' '); 00127 if(port!=""){ 00128 nb++; 00129 cout<<nb<<") sur le port "<<port<<" avec "<<nbFantome<<" automatiques"<<endl; 00130 string loginP, scoreP; 00131 getline(iss,loginP,' '); getline(iss,scoreP,' '); 00132 if(loginP=="libre") cout<<"\tPacman [libre] "<<endl; 00133 else cout<<"\tPacman [déja connecté] : "<<loginP<<" avec un score de "<<scoreP<<endl; 00134 for(int i=0; i<3; i++){ 00135 string loginF, scoreF; 00136 getline(iss,loginF,' '); getline(iss,scoreF,' '); 00137 if(loginF=="libre") cout<<"\tFantome "<<i<<" [libre] "<<endl; 00138 else cout<<"\tFantome "<<i<<" [déja connecté] : "<<loginF<<" avec un score de "<<scoreF<<endl; 00139 } 00140 } else { 00141 cout<<"\tAucune partie en cours"<<endl; 00142 break; 00143 } 00144 string continuer; 00145 getline(iss,continuer,' '); 00146 if(continuer!=":") break; 00147 } while(1); 00148 } else cout<<"pas de LIST reçu"<<endl; 00149 return nb; 00150 }
Here is the call graph for this function:
void ClientSP::ListerScore | ( | ) | [private] |
Definition at line 152 of file ClientSP.cpp.
References Socket::Ecouter(), Socket::Envoyer(), and mSocket.
Referenced by Traitement().
00152 { 00153 mSocket->Envoyer("SCORE"); 00154 string line=mSocket->Ecouter(); 00155 istringstream iss(line); 00156 string cmd; 00157 getline(iss,cmd,' '); 00158 if(cmd=="SCORE"){ 00159 cout<<endl<<"Liste des scores :"<<endl; 00160 do{ 00161 string login, score; 00162 getline(iss,login,' '); getline(iss,score,' '); 00163 if(login!=""){ 00164 cout<<login<<" avec un score de "<<score<<endl; 00165 } else { 00166 cout<<"\tAucun score enregistré"<<endl; 00167 break; 00168 } 00169 string continuer; 00170 getline(iss,continuer,' '); 00171 if(continuer!=":") break; 00172 } while(1); 00173 } cout<<"pas de SCORE reçu"<<endl; 00174 }
Here is the call graph for this function:
void ClientSP::ChoisirPartie | ( | ) | [private] |
Definition at line 176 of file ClientSP.cpp.
References CreationPartie(), Socket::Ecouter(), Socket::Envoyer(), ListerPartie(), mSocket, and RejoindrePartie().
Referenced by Traitement().
00176 { 00177 unsigned int nb=ListerPartie(); 00178 mSocket->Envoyer("SUITE"); 00179 if(mSocket->Ecouter()=="SUITE"){ 00180 while(1){ 00181 if(nb!=0){ 00182 cout<<"Pour rejoindre une partie entrez le port sinon 'c' pour en créer une"<<endl; 00183 string c; 00184 cout<<">"; cin>>c; 00185 if(c=="c"){ 00186 if(CreationPartie()!=-1) break; 00187 } else if(RejoindrePartie(c)!=-1) break; 00188 } else if(CreationPartie()!=-1) break; 00189 } 00190 } cout<<"pas de SUITE reçu"<<endl; 00191 }
Here is the call graph for this function:
int ClientSP::CreationPartie | ( | ) | [private] |
Definition at line 213 of file ClientSP.cpp.
References Socket::Ecouter(), Socket::Envoyer(), mPort, mPortRenseigne, and mSocket.
Referenced by ChoisirPartie().
00213 { 00214 string nbFantome, retour; 00215 do{ 00216 cout<<"Demande de création de la partie"<<endl; 00217 while(nbFantome==""){ 00218 cout<<"Nombre de fantomes automatiques: "; cin>>nbFantome; 00219 } 00220 string reponse="GAME "; reponse+=nbFantome; 00221 mSocket->Envoyer(reponse); 00222 retour=mSocket->Ecouter(); 00223 string cmd, port; 00224 istringstream iss(retour); 00225 getline(iss,cmd,' '); 00226 if (cmd=="GAME"){ 00227 getline(iss,port,' '); 00228 if (port!=""){ 00229 mPortRenseigne=true; 00230 istringstream iss(port); 00231 iss >> mPort; 00232 return 1; 00233 } 00234 } 00235 nbFantome=""; 00236 } while(1); 00237 }
Here is the call graph for this function:
int ClientSP::RejoindrePartie | ( | string | port | ) | [private] |
Definition at line 193 of file ClientSP.cpp.
References Socket::Ecouter(), Socket::Envoyer(), mPort, mPortRenseigne, and mSocket.
Referenced by ChoisirPartie().
00193 { 00194 string cmd="JOIN "; cmd+=port; 00195 mSocket->Envoyer(cmd); 00196 string retour=mSocket->Ecouter(); 00197 string resultat, confirmationPort; 00198 istringstream iss(retour); 00199 getline(iss,resultat,' '); 00200 if (resultat=="GAME"){ 00201 getline(iss,confirmationPort,' '); 00202 if (confirmationPort!=""){ 00203 mPortRenseigne=true; 00204 istringstream iss(confirmationPort); 00205 iss >> mPort; 00206 return 1; 00207 } 00208 } 00209 return -1; 00210 }
Here is the call graph for this function:
Socket* ClientSP::mSocket [private] |
Pointeur sur la socket de communication.
Definition at line 87 of file ClientSP.h.
Referenced by ChoisirPartie(), ClientSP(), CreationPartie(), ListerPartie(), ListerScore(), RegLogin(), RejoindrePartie(), SendHello(), SendLogin(), and ~ClientSP().
bool ClientSP::mPortRenseigne [private] |
Booléen indiquant que le port est renseigné (obtenu du serveur principal).
Definition at line 92 of file ClientSP.h.
Referenced by ClientSP(), CreationPartie(), EstPret(), and RejoindrePartie().
unsigned int ClientSP::mPort [private] |
Port TCP du serveur de jeu.
Definition at line 97 of file ClientSP.h.
Referenced by ClientSP(), CreationPartie(), GetPort(), and RejoindrePartie().
string ClientSP::mLogin [private] |
Login qui a bien été identifié par le serveur principal.
Definition at line 102 of file ClientSP.h.
Referenced by GetLogin(), and SendLogin().