feat: creation of new user
This commit is contained in:
39
internal/game/session.go
Normal file
39
internal/game/session.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
petname "github.com/dustinkirkland/golang-petname"
|
||||
)
|
||||
|
||||
var lastSessionId int = 0
|
||||
var sessionStorage []Session = []Session{}
|
||||
var nameToSession map[string]*Session = make(map[string]*Session)
|
||||
|
||||
type Session struct {
|
||||
id int
|
||||
Name string
|
||||
Users []User
|
||||
}
|
||||
|
||||
func NewSession() Session {
|
||||
sessionName := petname.Generate(3, "-")
|
||||
|
||||
s := Session{
|
||||
id: lastSessionId,
|
||||
Name: sessionName,
|
||||
Users: []User{},
|
||||
}
|
||||
|
||||
sessionStorage = append(sessionStorage, s)
|
||||
nameToSession[sessionName] = &s
|
||||
lastSessionId++
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func GetSession(name string) *Session {
|
||||
return nameToSession[name]
|
||||
}
|
||||
|
||||
func (s *Session) AddUser(user User) {
|
||||
s.Users = append(s.Users, user)
|
||||
}
|
||||
23
internal/game/user.go
Normal file
23
internal/game/user.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Name string
|
||||
PublicKey ed25519.PublicKey
|
||||
PrivateKey ed25519.PrivateKey
|
||||
}
|
||||
|
||||
func NewUser(name string) User {
|
||||
// ed25519
|
||||
|
||||
public, private, _ := ed25519.GenerateKey(rand.Reader)
|
||||
return User{
|
||||
Name: name,
|
||||
PublicKey: public,
|
||||
PrivateKey: private,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user