Only allow registered users to connect when running in DEFCON 1 or 2

This commit is contained in:
Trevor Slocum 2024-11-19 02:53:20 -08:00
parent 1ea81e7242
commit bdceb06447
4 changed files with 18 additions and 23 deletions

View file

@ -145,7 +145,7 @@ must write some data to the server at least once every 40 seconds.
- This command is only available to server administrators and moderators.
- Levels:
1. Disallow new accounts from being registered.
2. Only registered users may create and join matches.
2. Only registered users may connect.
3. Only registered users may chat and set custom match titles.
4. Warning message is broadcast to all users.
5. Normal operation.

View file

@ -94,7 +94,7 @@ var HelpText = map[string]string{
CommandDisconnect: "- Disconnect from the server.",
CommandMOTD: "[message] - View (or set) message of the day. Specifying a new message of the day is only available to server administrators.",
CommandBroadcast: "<message> - Send a message to all players. This command is only available to server administrators.",
CommandDefcon: "[level] - Apply restrictions to guests to prevent abuse. Levels:\n1. Disallow new accounts from being registered.\n2. Only registered users may create and join matches.\n3. Only registered users may chat and set custom match titles.\n4. Warning message is broadcast to all users.\n5. Normal operation.",
CommandDefcon: "[level] - Apply restrictions to guests to prevent abuse. Levels:\n1. Disallow new accounts from being registered.\n2. Only registered users may connect.\n3. Only registered users may chat and set custom match titles.\n4. Warning message is broadcast to all users.\n5. Normal operation.",
CommandKick: "<username> [reason] - Kick a user from the server.",
CommandBan: "<username> [reason] - Ban a user by IP addresss and account (if logged in).",
CommandUnban: "<IP>/<username> - Unban a user by IP address or account.",

View file

@ -58,6 +58,9 @@ msgid_plural "Double offered to opponent (%d points)."
msgstr[0] ""
msgstr[1] ""
msgid "Due to ongoing abuse, only registered users may connect. Please register an account or try again later."
msgstr ""
msgid "Due to ongoing abuse, registration is disabled. Please try again later."
msgstr ""

View file

@ -177,6 +177,11 @@ func (s *server) handleFirstCommand(cmd serverCommand, keyword string, params []
cmd.client.name = username
}
if s.defcon <= 2 {
cmd.client.Terminate(gotext.GetD(cmd.client.language, "Due to ongoing abuse, only registered users may connect. Please register an account or try again later."))
return
}
banned, banReason := checkBan(cmd.client.Address(), cmd.client.accountID)
if banned {
msg := "You are banned"
@ -244,7 +249,7 @@ func (s *server) handleFirstCommand(cmd serverCommand, keyword string, params []
}
// Send DEFCON warning message.
if s.defcon != 5 {
if s.defcon < 5 {
cmd.client.sendDefconWarning(s.defcon)
}
@ -358,7 +363,7 @@ COMMANDS:
clientGame := s.gameByClient(cmd.client)
if clientGame != nil && clientGame.client1 != cmd.client && clientGame.client2 != cmd.client {
switch keyword {
case bgammon.CommandHelp, "h", bgammon.CommandJSON, bgammon.CommandList, "ls", bgammon.CommandBoard, "b", bgammon.CommandLeave, "l", bgammon.CommandReplay, bgammon.CommandSet, bgammon.CommandPassword, bgammon.CommandFollow, bgammon.CommandUnfollow, bgammon.CommandPong, bgammon.CommandDisconnect, bgammon.CommandMOTD, bgammon.CommandBroadcast, bgammon.CommandDefcon, bgammon.CommandBan, bgammon.CommandUnban, bgammon.CommandShutdown:
case bgammon.CommandHelp, "h", bgammon.CommandJSON, bgammon.CommandList, "ls", bgammon.CommandBoard, "b", bgammon.CommandLeave, "l", bgammon.CommandReplay, bgammon.CommandSet, bgammon.CommandPassword, bgammon.CommandFollow, bgammon.CommandUnfollow, bgammon.CommandPong, bgammon.CommandDisconnect, bgammon.CommandMOTD, bgammon.CommandBroadcast, bgammon.CommandDefcon, bgammon.CommandKick, bgammon.CommandBan, bgammon.CommandUnban, bgammon.CommandShutdown:
// These commands are allowed to be used by spectators.
default:
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Command ignored: You are spectating this match."))
@ -415,7 +420,7 @@ COMMANDS:
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Message not sent: There is no one else in the match."))
continue
}
if s.defcon < 4 && cmd.client.accountID == 0 {
if s.defcon <= 3 && cmd.client.accountID == 0 {
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Due to ongoing abuse, some actions are restricted to registered users only. Please log in or register to avoid interruptions."))
continue
}
@ -452,9 +457,6 @@ COMMANDS:
} else if len(params) < 2 {
sendUsage()
continue
} else if s.defcon < 3 && cmd.client.accountID == 0 {
failCreate(gotext.GetD(cmd.client.language, "Due to ongoing abuse, some actions are restricted to registered users only. Please log in or register to avoid interruptions."))
continue
}
var gamePassword []byte
@ -509,7 +511,7 @@ COMMANDS:
points = 127
}
if s.defcon < 4 && cmd.client.accountID == 0 {
if s.defcon <= 3 && cmd.client.accountID == 0 {
gameName = nil
}
@ -555,13 +557,6 @@ COMMANDS:
continue
}
if s.defcon < 3 && cmd.client.accountID == 0 {
cmd.client.sendEvent(&bgammon.EventFailedJoin{
Reason: gotext.GetD(cmd.client.language, "Due to ongoing abuse, some actions are restricted to registered users only. Please log in or register to avoid interruptions."),
})
continue
}
var joinGameID int
if onlyNumbers.Match(params[0]) {
gameID, err := strconv.Atoi(string(params[0]))
@ -1494,17 +1489,14 @@ COMMANDS:
continue
}
lastDefcon := s.defcon
s.defcon = v
cmd.client.sendNotice(fmt.Sprintf("Updated DEFCON level to %d.", v))
if lastDefcon == 5 {
s.clientsLock.Lock()
for _, sc := range s.clients {
sc.sendDefconWarning(s.defcon)
}
s.clientsLock.Unlock()
s.clientsLock.Lock()
for _, sc := range s.clients {
sc.sendDefconWarning(s.defcon)
}
s.clientsLock.Unlock()
case bgammon.CommandKick:
if len(params) == 0 {
cmd.client.sendNotice("Please specify a username.")