Newer
Older
#include "client.hpp"
#include "definitions.hpp"
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
#include <iostream>
#include <string>
using namespace wordle_de;
std::string getUsernameFromInput() {
std::string username;
std::getline(std::cin, username);
if (username.empty()) {
throw "empty username is not allowed";
}
if (username.length() > USERNAME_MAX_LENGTH) {
throw "username is too long";
}
return username;
}
std::string getPasswordFromInput() {
std::string password;
std::getline(std::cin, password);
if (password.empty()) {
throw "empty password is not allowed";
}
if (password.length() < 8) {
throw "password is too short";
}
return password;
}
int main() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
std::cout << "Willkommen zu Wordle auf Deutsch!" << std::endl;
std::cout << "Bitte gib deinen Benutzernamen und Passwort ein:" << std::endl;
std::string username, password;
while (true) {
try {
std::cout << "Benutzername: ";
username = getUsernameFromInput();
std::cout << "Passwort: ";
password = getPasswordFromInput();
break;
} catch (const char *error) {
std::cout << "Error: " << error << std::endl;
}
}
// try to connect to server
auto cl = Client();
std::cout << "Connected to server!" << std::endl;
std::cout << "Logging in..." << std::endl;
auto msg = Message();
auto login = new Login();
login->set_username(username);
login->set_password(password);
msg.set_allocated_login(login);
cl.sendMessage(msg.SerializeAsString().c_str());
}