feat: gateway
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing

This commit is contained in:
vaalacat
2024-04-23 11:18:16 +00:00
parent a42fecfc63
commit 75944abbc2
13 changed files with 404 additions and 87 deletions

View File

@@ -1,53 +0,0 @@
package mc
// 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 Authcator struct {
// UserMap *sync.Map
// }
// var authcator *Authcator
// func GetAuthcator() Auth {
// if authcator == nil {
// authcator = &Authcator{
// UserMap: &sync.Map{},
// }
// }
// return authcator
// }
// 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) Reject(u models.User) {
// a.UserMap.Delete(u.MCName)
// }

View File

@@ -5,6 +5,7 @@ import (
"log"
"strings"
"tg-mc/conf"
"tg-mc/services/utils"
"time"
"github.com/Tnze/go-mc/bot"
@@ -17,6 +18,15 @@ import (
"github.com/sirupsen/logrus"
)
func StartBridgeClient() {
for {
if err := Run(); err != nil {
utils.SendMsg("致命错误:" + err.Error())
}
time.Sleep(time.Second * 5)
}
}
func Run() error {
conf.Client = bot.NewClient()
conf.Client.Auth.Name = conf.GetBotSettings().MCBotName
@@ -44,7 +54,8 @@ func Run() error {
)
if err != nil {
log.Fatal(err)
log.Printf("joinserver error: %v", err)
return err
}
log.Println("Login success")