修复服务器加入
This commit is contained in:
parent
ffc9370ca4
commit
4ca9b70e4a
20
db/cache/fastcache_test.go
vendored
Normal file
20
db/cache/fastcache_test.go
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/samber/lo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFastCache(t *testing.T) {
|
||||||
|
f := NewFastCache(100000)
|
||||||
|
c := CacheHelp[string]{
|
||||||
|
Cache: f,
|
||||||
|
}
|
||||||
|
c.Put([]byte("123"), "123", time.Now().Add(10*time.Second))
|
||||||
|
|
||||||
|
if lo.Must(c.Get([]byte("123"))) != "123" {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
package yggdrasil
|
package yggdrasil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
|
"github.com/samber/lo"
|
||||||
"github.com/xmdhs/authlib-skin/model/yggdrasil"
|
"github.com/xmdhs/authlib-skin/model/yggdrasil"
|
||||||
sutils "github.com/xmdhs/authlib-skin/service/utils"
|
sutils "github.com/xmdhs/authlib-skin/service/utils"
|
||||||
"github.com/xmdhs/authlib-skin/utils"
|
"github.com/xmdhs/authlib-skin/utils"
|
||||||
@ -47,6 +49,11 @@ func (y *Yggdrasil) HasJoined() httprouter.Handle {
|
|||||||
w.WriteHeader(204)
|
w.WriteHeader(204)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
y.yggdrasilService.HasJoined(ctx, name, serverId, ip, r.Host)
|
u, err := y.yggdrasilService.HasJoined(ctx, name, serverId, ip, r.Host)
|
||||||
|
if err != nil {
|
||||||
|
y.logger.WarnContext(ctx, err.Error())
|
||||||
|
w.WriteHeader(204)
|
||||||
|
}
|
||||||
|
w.Write(lo.Must(json.Marshal(u)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ type UserProperties struct {
|
|||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
AccessToken string `json:"accessToken" validate:"required,jwt"`
|
AccessToken string `json:"accessToken" validate:"required,jwt"`
|
||||||
SelectedProfile string `json:"selectedProfile" validate:"required,uuid"`
|
SelectedProfile string `json:"selectedProfile" validate:"required"`
|
||||||
ServerID string `json:"serverId"`
|
ServerID string `json:"serverId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func newYggdrasil(r *httprouter.Router, handelY yggdrasil.Yggdrasil) error {
|
|||||||
r.POST("/api/yggdrasil/api/profiles/minecraft", warpHJSON(handelY.BatchProfile()))
|
r.POST("/api/yggdrasil/api/profiles/minecraft", warpHJSON(handelY.BatchProfile()))
|
||||||
|
|
||||||
r.POST("/api/yggdrasil/sessionserver/session/minecraft/join", warpHJSON(handelY.SessionJoin()))
|
r.POST("/api/yggdrasil/sessionserver/session/minecraft/join", warpHJSON(handelY.SessionJoin()))
|
||||||
r.GET("/api/yggdrasil/sessionserver/session/minecraft/hasJoined", warpHJSON(handelY.SessionJoin()))
|
r.GET("/api/yggdrasil/sessionserver/session/minecraft/hasJoined", warpHJSON(handelY.HasJoined()))
|
||||||
|
|
||||||
r.POST("/api/yggdrasil/minecraftservices/player/certificates", warpHJSON(handelY.PlayerCertificates()))
|
r.POST("/api/yggdrasil/minecraftservices/player/certificates", warpHJSON(handelY.PlayerCertificates()))
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type sessionWithIP struct {
|
type sessionWithIP struct {
|
||||||
user model.TokenClaims
|
User model.TokenClaims
|
||||||
IP string
|
IP string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ func (y *Yggdrasil) SessionJoin(ctx context.Context, s yggdrasil.Session, ip str
|
|||||||
return fmt.Errorf("SessionJoin: %w", sutils.ErrTokenInvalid)
|
return fmt.Errorf("SessionJoin: %w", sutils.ErrTokenInvalid)
|
||||||
}
|
}
|
||||||
err = cache.CacheHelp[sessionWithIP]{Cache: y.cache}.Put([]byte("session"+s.ServerID), sessionWithIP{
|
err = cache.CacheHelp[sessionWithIP]{Cache: y.cache}.Put([]byte("session"+s.ServerID), sessionWithIP{
|
||||||
user: *t,
|
User: *t,
|
||||||
IP: ip,
|
IP: ip,
|
||||||
}, time.Now().Add(30*time.Second))
|
}, time.Now().Add(30*time.Second))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -51,7 +51,7 @@ func (y *Yggdrasil) HasJoined(ctx context.Context, username, serverId string, ip
|
|||||||
return yggdrasil.UserInfo{}, fmt.Errorf("HasJoined: %w", err)
|
return yggdrasil.UserInfo{}, fmt.Errorf("HasJoined: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if up.UUID != sIP.user.Subject {
|
if up.UUID != sIP.User.Subject {
|
||||||
return yggdrasil.UserInfo{}, fmt.Errorf("uuid 不相同")
|
return yggdrasil.UserInfo{}, fmt.Errorf("uuid 不相同")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user