db

package
Version: v0.0.0-...-715e693 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AltAcc

type AltAcc struct {
	// The person who claimed the alt
	Owner string `json:"alt_owner" gorm:"column:owner;type:text;unique;not null"`
	// The ID of the alt account (this will be used for verifying)
	PlayerID string `json:"alt_id" gorm:"column:player_id;type:text;primary_key;not null"`
	// The name of the alt, this doesn't need to be consistent since it's mostly for listing without
	// reaching out to Mojang's API
	PlayerName string `json:"alt_name" gorm:"column:player_name;type:text;unique;not null"`
}

AltAcc represents an alt account claimed by an admin.

func (AltAcc) TableName

func (AltAcc) TableName() string

TableName gives GORM the table name for account management.

type AltsTable

type AltsTable struct {
	// contains filtered or unexported fields
}

AltsTable - The Minecraft server administrators can use alt account management to claim Minecraft players as their alts. This will allow those players to join without authentication. This is super useful for mostly alts, but also any player you want to join without question. It will still check to see if the owner of the alt is authenticated which can only be done by administrators of the server.

func GetAltsTable

func GetAltsTable(gDB *gorm.DB) AltsTable

GetAltsTable will initialize the table if it doesn't exist. It will then return AltsTable where other functions can access this database table.

func (*AltsTable) AddAlt

func (at *AltsTable) AddAlt(owner string, playerID string, playerName string) error

AddAlt adds a new alt account. owner must be the owner player name. playerID must be the player's UUID. playerName must be the player's in-game name.

func (*AltsTable) GetAllAlts

func (at *AltsTable) GetAllAlts() (result []AltAcc, err error)

GetAllAlts will get all the alt accounts in the database.

func (*AltsTable) GetAlt

func (at *AltsTable) GetAlt(playerID string) (result AltAcc, err error)

GetAlt is used by bot/verify.go, it can get an alt account based on a playerID but if the alt doesn't exist all the attributes of AltAcc will be empty.

func (*AltsTable) GetAltsOf

func (at *AltsTable) GetAltsOf(owner string) (result []AltAcc, err error)

GetAltsOf will get all the alts associated with an owner (the person who claimed the alts).

func (*AltsTable) RemAlt

func (at *AltsTable) RemAlt(identifier string) error

RemAlt removes an alt account from the table identifier can be player name or player ID.

type AuthCode

type AuthCode struct {
	// Pending authentication code
	AuthCode string `gorm:"column:auth_code;type:text;unique;not null"`
	// The Minecraft player associated with the pending code
	PlayerID string `gorm:"column:player_id;type:text;unique;not null"`
}

AuthCode represents a pending authentication code stored in the database.

func (AuthCode) TableName

func (AuthCode) TableName() string

TableName gives GORM the table used for pending authentication codes.

type AuthTable

type AuthTable struct {
	// contains filtered or unexported fields
}

AuthTable - Authentication codes are generated by (at *AuthTable) NewAuthCode() when a new player joins the Minecraft server. Players can redeem their authentication code through the Discord bot using the "auth" command. This is done through (bot *Bot) cmdAuth().

func GetAuthTable

func GetAuthTable(gDB *gorm.DB) AuthTable

GetAuthTable will setup the table if it doesn't exist

func (*AuthTable) Authorize

func (at *AuthTable) Authorize(authCode string) (playerID string, isOK bool)

Authorize a given authentication code. It will return the player ID associated with the given auth code and the returned bool will be false.

func (*AuthTable) GetAllAuthCodes

func (at *AuthTable) GetAllAuthCodes() (authCodes []AuthCode, err error)

GetAllAuthCodes will get all the pending authentication codes in the table.

func (*AuthTable) GetAuthCode

func (at *AuthTable) GetAuthCode(playerID string) (authCode string, err error)

GetAuthCode will get a pending authentication code of a player UUID. If it doesn't exist than an empty string will be returned

func (*AuthTable) GetPlayerID

func (at *AuthTable) GetPlayerID(authCode string) (playerID string, err error)

GetPlayerID will the player ID associated with the given authentication code.

func (*AuthTable) NewAuthCode

func (at *AuthTable) NewAuthCode(playerID string) (authCode string, err error)

NewAuthCode will create a new authentication code for a given player UUID. If the player already has an authentication code then their pending one will be returned instead.

func (*AuthTable) RemoveCode

func (at *AuthTable) RemoveCode(authCode string) (err error)

RemoveCode will remove an authentication code given. The bool returned represents if the authentication code removed was removed.

type Config

type Config struct {
	Host               string        `yaml:"host"`
	Port               int           `yaml:"port"`
	User               string        `yaml:"username"`
	Password           string        `yaml:"password"`
	Database           string        `yaml:"database_name"`
	MaxConnections     int           `yaml:"max_connections"`
	MaxIdleConnections int           `yaml:"max_idle_connections"`
	ConnLifespan       time.Duration `yaml:"conn_lifespan"`
}

Config is a Postgres configuration.

type LinkedAcc

type LinkedAcc struct {
	// Their Discord user ID (Twitter snowflake)
	DiscordID string `gorm:"column:discord_id;type:text;unique;not null"`
	// Their Minecraft UUID (without hyphens)
	PlayerID string `gorm:"column:player_id;type:text;unique;not null"`
}

LinkedAcc represents a linked account for a Discord or Minecraft user.

func (LinkedAcc) TableName

func (LinkedAcc) TableName() string

TableName gives GORM the table that linked accounts are stored.

type LinksTable

type LinksTable struct {
	// contains filtered or unexported fields
}

LinksTable - The account links feature mcauth is where the magic happens. Here Minecraft player UUID's (without hyphens) are associated with Discord user ID's (Twitter snowflakes). Once a user has been authenticated using their authentication code (see authcodes.go) they will be stored here with their Minecraft player UUID and Discord user ID on the same row entry

func GetLinksTable

func GetLinksTable(gDB *gorm.DB) LinksTable

GetLinksTable will create the account_links table if it doesn't exist. it will return LinksTable which can be used to interface with the table.

func (lt *LinksTable) GetAllLinks() (linkedList []LinkedAcc, err error)

GetAllLinks will get all the linked accounts in the table.

func (*LinksTable) GetDiscordID

func (lt *LinksTable) GetDiscordID(playerID string) (discordID string, err error)

GetDiscordID will get a Minecraft player's associated Discord user ID.

func (*LinksTable) GetPlayerID

func (lt *LinksTable) GetPlayerID(discordID string) (playerID string, err error)

GetPlayerID will get a Discord user's associated Minecraft player UUID (without hyphens).

func (lt *LinksTable) NewLink(discordID string, playerID string) error

NewLink establishes a new account link.

func (lt *LinksTable) SetLink(discordID, playerID string) error

SetLink will set a link whether it exists or not.

func (lt *LinksTable) UnLink(identifier string) error

UnLink will remove a link based on the given identifier. The identifier can be either their Discord user ID or Minecraft player UUID (without hyphens).

type Store

type Store struct {
	Alts  AltsTable
	Auth  AuthTable
	Links LinksTable
	// contains filtered or unexported fields
}

Store is the database. For more information about each table visit their file. This is where they're all grouped together.

func GetStore

func GetStore(config Config) (c Store)

GetStore returns the database and the structures that manage each table.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL