diff --git a/.gitignore b/.gitignore index a8e7777..c690714 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ resources configs/config.toml -dynamite +/dynamite* .idea banned_ips.json banned_players.json diff --git a/core_commands/banlist.go b/core_commands/banlist.go index a6975d4..e7b5da8 100644 --- a/core_commands/banlist.go +++ b/core_commands/banlist.go @@ -13,7 +13,7 @@ func point[T any](t T) *T { } var banlist_cmd = &commands.Command{ - Name: "ban", + Name: "banlist", RequiredPermissions: []string{"server.command.banlist"}, Arguments: []commands.Argument{ commands.NewIntegerArgument("page", struct { @@ -31,7 +31,7 @@ var banlist_cmd = &commands.Command{ page = i } } - fmt.Sprint(page) // todo add paging + _ = fmt.Sprint(page) // todo add paging str := "§lBan list:\n" for i, b := range server.BannedPlayers { str += fmt.Sprintf("§l%d§r%s", i+1, b.Name) diff --git a/core_commands/commands.go b/core_commands/commands.go index 23ed0fb..4c7db61 100644 --- a/core_commands/commands.go +++ b/core_commands/commands.go @@ -15,5 +15,6 @@ var Commands = &commands.Graph{ banlist_cmd, op_cmd, deop_cmd, + unban_cmd, }, } diff --git a/core_commands/ram.go b/core_commands/ram.go index b357380..27eee59 100644 --- a/core_commands/ram.go +++ b/core_commands/ram.go @@ -10,13 +10,16 @@ import ( var ram_cmd = &commands.Command{ Name: "ram", Aliases: []string{"mem"}, + RequiredPermissions: []string{ + "server.command.ram", + }, Execute: func(ctx commands.CommandContext) { var m runtime.MemStats runtime.ReadMemStats(&m) - ctx.Reply(fmt.Sprintf("Allocated: %v MiB, Total Allocated: %v MiB, Heap in Use: %v MiB", bToMb(m.Alloc), bToMb(m.TotalAlloc), bToMb(m.HeapInuse))) + ctx.Reply(fmt.Sprintf("Allocated: %v MiB, Total Allocated: %v MiB, Heap in Use: %v MiB", bytesToMegabytes(m.Alloc), bytesToMegabytes(m.TotalAlloc), bytesToMegabytes(m.HeapInuse))) }, } -func bToMb(b uint64) uint64 { +func bytesToMegabytes(b uint64) uint64 { return b / 1024 / 1024 } diff --git a/core_commands/unban.go b/core_commands/unban.go new file mode 100644 index 0000000..22b885e --- /dev/null +++ b/core_commands/unban.go @@ -0,0 +1,25 @@ +package core_commands + +import ( + "github.com/dynamitemc/dynamite/server/commands" +) + +var unban_cmd = &commands.Command{ + Name: "unban", + Aliases: []string{"pardon"}, + RequiredPermissions: []string{"server.command.unban"}, + Arguments: []commands.Argument{ + commands.NewEntityArgument("player", commands.EntityPlayerOnly), + }, + Execute: func(ctx commands.CommandContext) { + if len(ctx.Arguments) == 0 { + ctx.Incomplete() + return + } + playerName := ctx.Arguments[0] + server := getServer(ctx.Executor) + + server.UnbanName(playerName) + ctx.Reply("Unbanned " + playerName) + }, +} diff --git a/server/access.go b/server/access.go index f442980..635287e 100644 --- a/server/access.go +++ b/server/access.go @@ -140,6 +140,15 @@ func (srv *Server) Unban(p *PlayerController) { } } +func (srv *Server) UnbanName(name string) { + for i, b := range srv.BannedPlayers { + if b.Name == name { + srv.BannedPlayers = slices.Delete(srv.BannedPlayers, i, i+1) + return + } + } +} + func (srv *Server) MakeOperator(p *PlayerController) { p.player.SetOperator(true) srv.Operators = append(srv.Operators, user{