mirror of
https://github.com/PretendoNetwork/splatoon.git
synced 2026-04-26 07:47:57 -05:00
Some checks failed
Build and Publish Docker Image / build-publish (push) Has been cancelled
* chore: update grpc bits and add local auth mode * chore: library updates and token validation * fix: small things * feat: use secret unreleased protocols * chore: update go modules * chore: bump golang version
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package globals
|
|
|
|
import (
|
|
"github.com/PretendoNetwork/nex-go/v2"
|
|
"github.com/PretendoNetwork/nex-go/v2/types"
|
|
"strconv"
|
|
)
|
|
|
|
var AuthenticationServerAccount *nex.Account
|
|
|
|
var SecureServerAccount *nex.Account
|
|
|
|
func InitAccounts() {
|
|
AuthenticationServerAccount = nex.NewAccount(types.NewPID(1), "Quazal Authentication", KerberosPassword)
|
|
SecureServerAccount = nex.NewAccount(types.NewPID(2), "Quazal Rendez-Vous", KerberosPassword)
|
|
}
|
|
|
|
func AccountDetailsByPID(pid types.PID) (*nex.Account, *nex.Error) {
|
|
if pid.Equals(AuthenticationServerAccount.PID) {
|
|
return AuthenticationServerAccount, nil
|
|
}
|
|
|
|
if pid.Equals(SecureServerAccount.PID) {
|
|
return SecureServerAccount, nil
|
|
}
|
|
|
|
password, errorCode := PasswordFromPID(pid)
|
|
if errorCode != 0 && LocalAuthMode {
|
|
Logger.Errorf("Password err: %v", errorCode)
|
|
password, errorCode = PasswordFromPIDLocal(pid)
|
|
}
|
|
if errorCode != 0 {
|
|
return nil, nex.NewError(errorCode, "Failed to get password from PID")
|
|
}
|
|
|
|
account := nex.NewAccount(pid, strconv.Itoa(int(pid)), password)
|
|
|
|
return account, nil
|
|
}
|
|
|
|
func AccountDetailsByUsername(username string) (*nex.Account, *nex.Error) {
|
|
if username == AuthenticationServerAccount.Username {
|
|
return AuthenticationServerAccount, nil
|
|
}
|
|
|
|
if username == SecureServerAccount.Username {
|
|
return SecureServerAccount, nil
|
|
}
|
|
|
|
pidInt, err := strconv.Atoi(username)
|
|
if err != nil {
|
|
Logger.Error(err.Error())
|
|
return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidUsername, "Invalid username")
|
|
}
|
|
|
|
pid := types.NewPID(uint64(pidInt))
|
|
|
|
password, errorCode := PasswordFromPID(pid)
|
|
if errorCode != 0 && LocalAuthMode {
|
|
Logger.Errorf("Password err: %v", errorCode)
|
|
password, errorCode = PasswordFromPIDLocal(pid)
|
|
}
|
|
if errorCode != 0 {
|
|
Logger.Errorf("Password err: %v", errorCode)
|
|
return nil, nex.NewError(errorCode, "Failed to get password from PID")
|
|
}
|
|
|
|
account := nex.NewAccount(pid, username, password)
|
|
|
|
return account, nil
|
|
}
|