loginscreen.cpp
1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "loginscreen.h"
#include "ui_loginscreen.h"
LoginScreen::LoginScreen(QWidget *parent) :
QDialog(parent),
ui(new Ui::LoginScreen)
{
ui->setupUi(this);
ui->nickEdit->setPlaceholderText("Nickname");
ui->serverURLEdit->setPlaceholderText("Server hostname:port");
}
void LoginScreen::parseURL(QString host, int port, QString URL)
{
if(validateURL(URL))
{
QStringList strings = URL.split(':');
host = strings[0].toStdString();
port = strings[1].toInt();
}
}
bool LoginScreen::validateURL(QString& url)
{
}
bool LoginScreen::connect(Socket& s)
{
QString host, nick;
string response;
int port;
parseURL(host,port,ui->serverURLEdit->text());
nick = ui->nickEdit->text();
try
{
s.Create();
s.Connect(host.toStdString(),port);
s << nick.toStdString();
s >> response;
if(response == "CHATNICKINVALID")
{
cout << "Spaces not allowed in nicknames, please enter another nickname: ";
}
else if(response == "CHATNICKEXIST")
{
cout << "Nickname in use, please enter another nickname: ";
}
else if(response == "CHATFULL")
{
cout << "Chatroom is full, please wait..." << endl;
}
else if(response != "CHATOK")
{
cout << "Error: " << response << endl;
}
else
{
return true;
}
s.Close();
return false;
}
catch(SocketException& e)
{
cout << e.description() << endl;
exit(-1);
}
}
LoginScreen::~LoginScreen()
{
delete ui;
}