Skip to content

Commit c169756

Browse files
Merge pull request #27 from minecraft8997/main
Some fixes
2 parents 55bbf04 + 4d57284 commit c169756

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

.github/workflows/d.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
dub build
3333
3434
- name: Upload
35-
uses: actions/upload-artifact@v3
35+
uses: actions/upload-artifact@v4
3636
with:
3737
name: build-${{matrix.os}}
3838
path: ${{github.workspace}}/mcyeti*

source/client.d

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ class Client : Player {
208208
outBuffer ~= identification.CreateData();
209209
}
210210

211+
private bool ValidateUsername(string username) {
212+
if (username.length < 2 || username.length > 16) return false;
213+
214+
for (int i = 0; i < username.length; i++) {
215+
char current = username[i];
216+
if (current == '_' || current == '.') continue;
217+
if (current >= '0' && current <= '9') continue;
218+
if ((current >= 'a' && current <= 'z') || (current >= 'A' && current <= 'Z')) continue;
219+
return false;
220+
}
221+
222+
return true;
223+
}
224+
211225
void Update(Server server) {
212226
auto time = Clock.currTime().toUnixTime();
213227

@@ -234,6 +248,11 @@ class Client : Player {
234248
packet.FromData(inBuffer);
235249
inBuffer = inBuffer[packet.GetSize() .. $];
236250

251+
if (!ValidateUsername(packet.username)) {
252+
server.Kick(this, "Bad username");
253+
return;
254+
}
255+
237256
auto correctMppass = md5Of(
238257
server.salt ~ packet.username
239258
).BytesToString();
@@ -306,7 +325,6 @@ class Client : Player {
306325

307326
if (muted) {
308327
SendMessage("&eYou are muted");
309-
return;
310328
}
311329

312330
server.SendGlobalMessage(

0 commit comments

Comments
 (0)