feat: upgrade to new version go-mc

This commit is contained in:
Vaala Cat
2023-12-06 21:40:12 +08:00
parent b023de86ee
commit 511c96c57e
7 changed files with 108 additions and 155 deletions

View File

@@ -1,52 +1,53 @@
package mc
import (
"sync"
"tg-mc/models"
"time"
)
// import (
// "sync"
// "tg-mc/models"
// "time"
// )
type Auth interface {
IsAuthed(u models.User, expireMode bool) bool
Auth(u models.User)
Reject(u models.User)
}
// type Auth interface {
// IsAuthed(u models.User, expireMode bool) bool
// Auth(u models.User)
// Reject(u models.User)
// }
type Authcator struct {
UserMap *sync.Map
}
// type Authcator struct {
// UserMap *sync.Map
// }
var authcator *Authcator
// var authcator *Authcator
func GetAuthcator() Auth {
if authcator == nil {
authcator = &Authcator{
UserMap: &sync.Map{},
}
}
return authcator
}
// func GetAuthcator() Auth {
// if authcator == nil {
// authcator = &Authcator{
// UserMap: &sync.Map{},
// }
// }
// return authcator
// }
func (a *Authcator) IsAuthed(u models.User, expireMode bool) bool {
// if u.MCName != "VaalaCat" {
// return true
// }
if approveTime, ok := a.UserMap.Load(u.MCName); ok {
if !expireMode {
return true
} else if time.Since(approveTime.(time.Time)) < 30*time.Second {
return true
} else {
return false
}
}
return false
}
// func (a *Authcator) IsAuthed(u models.User, expireMode bool) bool {
// return true
// // if u.MCName != "VaalaCat" {
// // return true
// // }
// if approveTime, ok := a.UserMap.Load(u.MCName); ok {
// if !expireMode {
// return true
// } else if time.Since(approveTime.(time.Time)) < 30*time.Second {
// return true
// } else {
// return false
// }
// }
// return false
// }
func (a *Authcator) Auth(u models.User) {
a.UserMap.Store(u.MCName, time.Now())
}
// func (a *Authcator) Auth(u models.User) {
// a.UserMap.Store(u.MCName, time.Now())
// }
func (a *Authcator) Reject(u models.User) {
a.UserMap.Delete(u.MCName)
}
// func (a *Authcator) Reject(u models.User) {
// a.UserMap.Delete(u.MCName)
// }