made it so already-taken login to server would reprompt for login
This commit is contained in:
parent
2ba23d1965
commit
65032fa0f5
2 changed files with 27 additions and 14 deletions
|
@ -169,20 +169,33 @@ void play_multiplayer_client(display& disp, game_data& units_data, config& cfg,
|
|||
|
||||
//if we got a direction to login
|
||||
if(data.child("mustlogin")) {
|
||||
std::string login = preferences::login();
|
||||
const int res = gui::show_dialog(disp,NULL,"",
|
||||
"You must login to this server",gui::OK_CANCEL,
|
||||
NULL,NULL,"Login: ",&login);
|
||||
if(res != 0 || login.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
config response;
|
||||
response.add_child("login")["username"] = login;
|
||||
network::send_data(response);
|
||||
config* error = NULL;
|
||||
|
||||
data_res = network::receive_data(data,0,5000);
|
||||
check_response(data_res,data);
|
||||
do {
|
||||
if(error != NULL) {
|
||||
gui::show_dialog(disp,NULL,"",(*error)["message"],gui::OK_ONLY);
|
||||
}
|
||||
|
||||
std::string login = preferences::login();
|
||||
const int res = gui::show_dialog(disp,NULL,"",
|
||||
"You must log in to this server",gui::OK_CANCEL,
|
||||
NULL,NULL,"Login: ",&login);
|
||||
if(res != 0 || login.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
config response;
|
||||
response.add_child("login")["username"] = login;
|
||||
network::send_data(response);
|
||||
|
||||
data_res = network::receive_data(data,0,5000);
|
||||
if(!data_res) {
|
||||
throw network::error(string_table["connection_timeout"]);
|
||||
}
|
||||
|
||||
error = data.child("error");
|
||||
} while(error != NULL);
|
||||
}
|
||||
|
||||
//if we got a gamelist back - otherwise we have
|
||||
|
|
|
@ -67,7 +67,7 @@ int main()
|
|||
continue;
|
||||
}
|
||||
|
||||
//check the username is valid (all alnum)
|
||||
//check the username is valid (all alpha-numeric)
|
||||
const std::string& username = (*login)["username"];
|
||||
if(std::count_if(username.begin(),username.end(),isalnum)
|
||||
!= username.size() || username.empty()) {
|
||||
|
@ -86,7 +86,7 @@ int main()
|
|||
|
||||
if(p != players.end()) {
|
||||
network::send_data(construct_error(
|
||||
"This username is already taken"));
|
||||
"This username is already taken"),sock);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue