Skip to content

Commit 4c4ed2f

Browse files
committed
user.d: move ban check to authenticate()
1 parent d7c71b5 commit 4c4ed2f

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/server/msghandler.d

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ final class MessageHandler
4444
break;
4545

4646
user.username = msg.username;
47-
const banned_until = server.db.user_banned_until(msg.username);
48-
49-
if (banned_until > Clock.currTime)
50-
// The official server doesn't send a response when a user
51-
// is banned. We also ban users temporarily when kicking
52-
// them, and simply closing the connection after some time
53-
// allows the client to automatically reconnect to the
54-
// server.
55-
break;
56-
57-
if (banned_until > SysTime()) server.db.unban_user(msg.username);
5847
user.client_version = text(
5948
msg.major_version, ".", msg.minor_version
6049
);

src/server/user.d

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,6 @@ final class User
103103

104104
void authenticate(string username, string password)
105105
{
106-
const user_exists = server.db.user_exists(username);
107-
108-
if (!user_exists && server.db.server_private_mode) {
109-
reject_login(LoginRejectionReason.server_private);
110-
return;
111-
}
112-
113-
if (server.num_connected_users >= server.db.server_max_users) {
114-
reject_login(LoginRejectionReason.server_full);
115-
return;
116-
}
117-
118106
const invalid_name_reason = check_username(username);
119107
if (invalid_name_reason !is null) {
120108
reject_login(
@@ -129,6 +117,28 @@ final class User
129117
return;
130118
}
131119

120+
const banned_until = server.db.user_banned_until(username);
121+
if (banned_until > Clock.currTime)
122+
// The official server doesn't send a response when a user
123+
// is banned. We also ban users temporarily when kicking
124+
// them, and simply closing the connection after some time
125+
// allows the client to automatically reconnect to the
126+
// server.
127+
return;
128+
129+
if (banned_until > SysTime()) server.db.unban_user(username);
130+
131+
const user_exists = server.db.user_exists(username);
132+
if (!user_exists && server.db.server_private_mode) {
133+
reject_login(LoginRejectionReason.server_private);
134+
return;
135+
}
136+
137+
if (server.num_connected_users >= server.db.server_max_users) {
138+
reject_login(LoginRejectionReason.server_full);
139+
return;
140+
}
141+
132142
if (!user_exists) {
133143
hashing_password = true;
134144
const salt = create_salt();

0 commit comments

Comments
 (0)