Skip to content

Commit

Permalink
Merge pull request #1 from SsNiPeR1/1.20.1
Browse files Browse the repository at this point in the history
some useful shit that you may review before merging
  • Loading branch information
oq-x authored Oct 14, 2023
2 parents dff56b2 + 9728922 commit 3c2405a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resources
configs/config.toml
dynamite
/dynamite*
.idea
banned_ips.json
banned_players.json
Expand Down
4 changes: 2 additions & 2 deletions core_commands/banlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions core_commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ var Commands = &commands.Graph{
banlist_cmd,
op_cmd,
deop_cmd,
unban_cmd,
},
}
7 changes: 5 additions & 2 deletions core_commands/ram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
25 changes: 25 additions & 0 deletions core_commands/unban.go
Original file line number Diff line number Diff line change
@@ -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)
},
}
9 changes: 9 additions & 0 deletions server/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 3c2405a

Please sign in to comment.