awwwwww, when i click buttons create and login i have the same error
http://s1.pokazywarka.pl/bigImages/1910820/6810469.jpgi hate work on pointers xD
#include "include/Client.h"
#include <TGUI/TGUI.hpp>
int main()
{
Client client;
sf::RenderWindow window(sf::VideoMode(800, 600), "Client");
sf::Clock Framerate;
float acu = 0;
float frametime = 0.01;
tgui::Form Wnd( window );
tgui::Panel::Ptr Menu(Wnd);
tgui::Panel::Ptr Create(Wnd);
tgui::Panel::Ptr Login(Wnd);
Login->load( 800, 600);
Create->load(800,600);
Menu->load(800,600);
Menu->setGlobalFont( "Font/djvs.ttf");
Create->setGlobalFont( "Font/djvs.ttf");
Login->setGlobalFont( "Font/djvs.ttf");
tgui::Button::Ptr connect(*Menu);
tgui::Button::Ptr disconnect(*Menu);
tgui::Button::Ptr createaccount(*Menu);
tgui::Button::Ptr create(*Create);
tgui::Button::Ptr login(*Login);
tgui::Label::Ptr labelUsername(*Create);
labelUsername->setText("Username:");
labelUsername->setPosition(200, 70);
labelUsername->setTextSize(10);
Create->add(labelUsername);
tgui::Label::Ptr labelPassword(*Create);
labelPassword->setText("Password:");
labelPassword->setPosition(200, 230);
labelPassword->setTextSize(10);
Create->add(labelPassword);
tgui::Label::Ptr labelMail(*Create);
labelMail->setText("E-Mail:");
labelMail->setPosition(200, 370);
labelMail->setTextSize(10);
Create->add(labelMail);
tgui::EditBox::Ptr editBoxUsername(*Create, "Username");
editBoxUsername->load("gui/EditBox/Black");
editBoxUsername->setSize(100, 40);
editBoxUsername->setPosition(200, 90);
editBoxUsername->setMaximumCharacters( 15 );
editBoxUsername->setTextSize(10);
Create->add(editBoxUsername, "Username" );
tgui::EditBox::Ptr editBoxPassword(*Create, "Password");
editBoxPassword->load("gui/EditBox/Black");
editBoxPassword->setPosition(200, 250);
editBoxPassword->setSize(100, 40);
editBoxPassword->setPasswordChar('*');
editBoxPassword->setMaximumCharacters( 15 );
editBoxPassword->setTextSize(10);
Create->add(editBoxPassword, "Password");
tgui::EditBox::Ptr editBoxMail(*Create, "E-Mail");
editBoxMail->load("gui/Editbox/Black");
editBoxMail->setSize(100,40);
editBoxMail->setPosition(200, 390);
editBoxMail->setTextSize(10);
Create->add(editBoxMail, "E-Mail");
tgui::EditBox::Ptr editBoxLogin( *Login, "Username" );
editBoxLogin->load("gui/Editbox/Black");
editBoxLogin->setSize(100, 40);
editBoxLogin->setPosition(100,100);
editBoxLogin->setMaximumCharacters( 15 );
editBoxLogin->setTextSize(10);
Login->add(editBoxLogin, "Username");
tgui::EditBox::Ptr editBoxPass( *Login, "Password" );
editBoxPass->load("gui/Editbox/Black");
editBoxPass->setSize(100, 40);
editBoxPass->setPosition(220,200);
editBoxPass->setMaximumCharacters( 15 );
editBoxPass->setTextSize(10);
Login->add(editBoxPass, "Password");
createaccount->load("gui/Button/Black");
createaccount->setSize(100, 50);
createaccount->setPosition(270, 280);
createaccount->setText("Create Account");
createaccount->bindCallback(tgui::Button::LeftMouseClicked);
createaccount->setCallbackId(1);
createaccount->setTextSize(10);
connect->load("gui/Button/Black");
connect->setSize(100, 50);
connect->setPosition(270, 340);
connect->setText("Connect");
connect->bindCallback(tgui::Button::LeftMouseClicked);
connect->setCallbackId(2);
connect->setTextSize(10);
disconnect->load("gui/Button/Black");
disconnect->setSize(100, 50);
disconnect->setPosition(270, 400);
disconnect->setText("Disconnect");
disconnect->bindCallback(tgui::Button::LeftMouseClicked);
disconnect->setCallbackId(3);
disconnect->setTextSize(10);
create->load("gui/Button/Black");
create->setSize(100, 50);
create->setPosition(400, 100);
create->setText("Register");
create->bindCallback(tgui::Button::LeftMouseClicked);
create->setCallbackId(4);
create->setTextSize(10);
login->load("gui/Button/Black");
login->setText("Login");
login->setSize(100,50);
login->setPosition(400,400);
login->bindCallback(tgui::Button::LeftMouseClicked);
login->setCallbackId(5);
login->setTextSize(10);
Menu->add(createaccount);
Menu->add(disconnect);
Menu->add(connect);
Login->add(login);
Create->add(create);
int menu = 1;
while (window.isOpen())
{
acu += Framerate.restart().asSeconds();
sf::Event event;
/// input
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
Wnd.handleEvent(event);
} /// end of input
/// logic
if( acu > frametime)
{
tgui::Callback callback;
while (Wnd.pollCallback(callback))
{
switch( callback.callbackId)
{
case 1:
{
if( client.init( "127.0.0.1", 6667 ))
{
menu = 2;
}
else menu=1;
break;
}
case 2:
{
if( client.init( "127.0.0.1", 6667 ) )
{
menu = 3;
}
else menu=1;
break;
}
case 3:
{
client.Disconnect();
menu = 1;
break;
}
case 4:
{
editBoxUsername = Wnd.get("Username");
editBoxPassword = Wnd.get("Password");
editBoxMail = Wnd.get("E-Mail");
sf::String username = editBoxUsername->getText();
sf::String password = editBoxPassword->getText();
sf::String email = editBoxMail->getText();
editBoxUsername->setText("");
editBoxPassword->setText("");
editBoxMail->setText("");
std::string user = username.toAnsiString();
std::string pass = password.toAnsiString();
std::string mail = email.toAnsiString();
if( user.size() >= 4 && pass.size() >= 6 && mail.find("@") && mail.size() >=8 )
{
int data;
client.Send << Packet::PACKET_ACCOUNT << Packet::PACKET_REQUEST << user; /// pytanie czy konto o danej nazwie juz istnieje
client.ServerSock.send( client.Send );
client.ServerSock.receive(client.Recv);
client.Recv >> client.family >> client.action >> data;
client.Send.clear();
client.Recv.clear();
if( client.family == 2 && client.action == 2)
{
if( data == 0 ) /// jesli istnieje przerywa polaczenie
{
std::cout<<"Konto o tym loginie juz istnieje"<<std::endl;
editBoxUsername->setText(user);
editBoxPassword->setText(pass);
editBoxMail->setText(mail);
client.Disconnect();
menu=1;
}
else if( data == 1 ) /// jesli nie wysyla haslo i maila potrzebne przy tworzeniu konta
{
client.Send << Packet::PACKET_ACCOUNT << Packet::PACKET_CREATE << pass << mail;
client.ServerSock.send(client.Send);
client.Send.clear();
client.ServerSock.receive(client.Recv);
client.Recv >> client.family >> client.action >> data;
if( client.family == 2 && client.action==1 )
{
if( data == 1 ) /// konto utworzono
{
std::cout<<"utworzono konto: "<< user << " " << pass << " " << mail << std::endl;
client.Disconnect();
menu=1;
}
/// blad przy tworzeniu
else if(data==0)
{
std::cout<<"Nie moge stworzyc konta" <<std::endl;
client.Disconnect();
menu=1;
}
else
{
std::cout<<"Nieznany problem przy tworzeniu konta" <<std::endl;
client.Disconnect();
menu=1;
}
}
else
{
client.Disconnect();
std::cout<<"nieznany error: " << data<<std::endl;
menu=1;
}
}
}
else
{
client.Disconnect();
menu=1;
}
break;
}
}
case 5:
{
editBoxLogin = Wnd.get("Username");
editBoxPass = Wnd.get("Password");
sf::String username = editBoxLogin->getText();
sf::String password = editBoxPass->getText();
editBoxLogin->setText("");
editBoxPass->setText("");
std::string user = username.toAnsiString();
std::string pass = password.toAnsiString();
if( user.size() >=4 && pass.size() >= 6 )
{
int data;
client.Send << Packet::PACKET_LOGIN << Packet::PACKET_REQUEST << user;
client.ServerSock.send(client.Send);
client.ServerSock.receive(client.Recv);
client.Recv >> client.family >> client.action >> data;
if(client.family==3 && client.action==2)
{
if( data == 1)
{
client.Send.clear();
client.Recv.clear();
client.Send << Packet::PACKET_LOGIN << Packet::PACKET_REPLY << pass;
client.ServerSock.send(client.Send);
client.ServerSock.receive(client.Recv);
client.Recv >> client.family >> client.action >> data;
client.Send.clear();
client.Recv.clear();
if( client.family==3 && client.action==1)
{
if(data==0)
{
std::cout << "Podano zle haslo" << std::endl;
client.Disconnect();
menu=1;
}
else if(data==1)
{
std::cout << "Zalogowano"<<std::endl;
menu=1;
break;
}
else if(data==2)
{
std::cout << "Konto w uzyciu" << std::endl;
client.Disconnect();
menu=1;
}
else
{
std::cout << "Nieznany blad: " << data << std::endl;
client.Disconnect();
menu=1;
}
}
else std::cout<<"problemy z pakietem 2"<<std::endl; client.Disconnect(); menu=1;
}
else
{
std::cout<< "Nie ma takiego konta"<<std::endl;
client.Disconnect();
menu=1;
}
}
else std::cout<<"problemy z pakietem 1"<<std::endl; client.Disconnect(); menu=1;
}
break;
}
}
}
}
/// end of logic
/// drawing
window.clear();
switch(menu)
{
case 1:
{
Login->hide();
Create->hide();
Menu->enable();
Login->enable();
Create->enable();
Menu->show();
Wnd.draw();
break;
}
case 2:
{
Create->show();
Login->hide();
Menu->hide();
Wnd.draw();
break;
}
case 3:
{
Login->show();
Create->hide();
Menu->hide();
Wnd.draw();
break;
}
}
window.display(); /// end of drawing
}
}