Start on player registration
This commit is contained in:
parent
308c343068
commit
a8a222f89b
5 changed files with 40 additions and 15 deletions
5
go.mod
5
go.mod
|
@ -2,13 +2,12 @@ module code.haedhutner.dev/mvv/LastMUD
|
|||
|
||||
go 1.24.4
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.6.0
|
||||
)
|
||||
require github.com/google/uuid v1.6.0
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/stretchr/testify v1.10.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
2
go.sum
2
go.sum
|
@ -6,6 +6,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
|||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
|
|
|
@ -8,8 +8,6 @@ type PlayerState = byte
|
|||
|
||||
const (
|
||||
PlayerStateJoining PlayerState = iota
|
||||
PlayerStateLoggingIn
|
||||
PlayerStateRegistering
|
||||
PlayerStatePlaying
|
||||
PlayerStateLeaving
|
||||
)
|
||||
|
|
|
@ -65,3 +65,21 @@ func CreateHandler(command data.Command, handler Handler) ecs.SystemExecutor {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func arg[T any](args data.ArgsMap, name data.ArgName) (val T, err error) {
|
||||
uncast, ok := args[name]
|
||||
|
||||
if !ok || uncast.Value == nil {
|
||||
err = createCommandError("No arg named '", name, "' found or value is empty")
|
||||
return
|
||||
}
|
||||
|
||||
val, ok = uncast.Value.(T)
|
||||
|
||||
if !ok {
|
||||
err = createCommandError("Arg value of '", name, "' cannot be cast")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -25,16 +25,10 @@ func HandleSay(w *ecs.World, _ time.Duration, player ecs.Entity, args data.ArgsM
|
|||
return comp.Room == playerRoom.Room
|
||||
})
|
||||
|
||||
messageArg, ok := args[data.ArgMessageContent]
|
||||
message, err := arg[string](args, data.ArgMessageContent)
|
||||
|
||||
if !ok {
|
||||
return createCommandError("No message")
|
||||
}
|
||||
|
||||
message, ok := messageArg.Value.(string)
|
||||
|
||||
if !ok {
|
||||
return createCommandError("Can't interpret message as string")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if message == "" {
|
||||
|
@ -58,6 +52,20 @@ func HandleQuit(w *ecs.World, _ time.Duration, player ecs.Entity, _ data.ArgsMap
|
|||
return
|
||||
}
|
||||
|
||||
func HandleRegister(world *ecs.World, delta time.Duration, player ecs.Entity, args map[data.ArgName]data.Arg) (err error) {
|
||||
func HandleRegister(world *ecs.World, delta time.Duration, player ecs.Entity, args data.ArgsMap) (err error) {
|
||||
accountName, err := arg[string](args, data.ArgAccountName)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
accountPassword, err := arg[string](args, data.ArgAccountPassword)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: validate username and password, encrypt password, etc.
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue