mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Add --no-register flag and register-account CLI
Build and Push Docker images to Docker Hub / build-and-push (push) Has been cancelled
Build and Push Docker images to Docker Hub / build-and-push (push) Has been cancelled
Author: https://github.com/REUSS-dev
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/peer"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
@@ -23,19 +24,30 @@ import (
|
||||
|
||||
type UserServiceServer struct {
|
||||
pb.UnimplementedUserServiceServer
|
||||
users store.UserRepository
|
||||
sessions store.SessionRepository
|
||||
authURL string
|
||||
users store.UserRepository
|
||||
sessions store.SessionRepository
|
||||
authURL string
|
||||
noRegister bool
|
||||
}
|
||||
|
||||
func NewUserServiceServer(users store.UserRepository, sessions store.SessionRepository, authURL string) *UserServiceServer {
|
||||
func NewUserServiceServer(users store.UserRepository, sessions store.SessionRepository, authURL string, noRegister bool) *UserServiceServer {
|
||||
if authURL != "" && !strings.Contains(authURL, "://") {
|
||||
authURL = "http://" + authURL
|
||||
}
|
||||
return &UserServiceServer{users: users, sessions: sessions, authURL: authURL}
|
||||
return &UserServiceServer{users: users, sessions: sessions, authURL: authURL, noRegister: noRegister}
|
||||
}
|
||||
|
||||
func (s *UserServiceServer) RegisterUser(ctx context.Context, req *pb.RegisterUserRequest) (*pb.RegisterUserResponse, error) {
|
||||
if s.noRegister {
|
||||
ip := "invalid"
|
||||
|
||||
if p, ok := peer.FromContext(ctx); ok {
|
||||
ip = p.Addr.String()
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("Denied user registration: ip=%s uuid=%s", ip, req.Uuid)
|
||||
}
|
||||
|
||||
platform := model.ClientPlatformFromContext(ctx)
|
||||
userId, err := s.users.CreateUser(req.Uuid, platform)
|
||||
if err != nil {
|
||||
@@ -89,11 +101,14 @@ func (s *UserServiceServer) GameStart(ctx context.Context, _ *emptypb.Empty) (*p
|
||||
|
||||
func (s *UserServiceServer) TransferUser(ctx context.Context, req *pb.TransferUserRequest) (*pb.TransferUserResponse, error) {
|
||||
platform := model.ClientPlatformFromContext(ctx)
|
||||
|
||||
log.Printf("[UserService] TransferUser: platform=%s", platform)
|
||||
userId, err := s.users.CreateUser(req.Uuid, platform)
|
||||
|
||||
userId, err := s.users.GetUserByUUID(req.Uuid)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create user: %w", err)
|
||||
}
|
||||
|
||||
return &pb.TransferUserResponse{
|
||||
UserId: userId,
|
||||
Signature: "transferred-sig",
|
||||
|
||||
Reference in New Issue
Block a user