data

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: MIT Imports: 19 Imported by: 0

README

Data

The Data module represents all of the data driven manipulations for the application. This includes the majority of the redis transactions. Especially for Creating, Reading, Updating, and Deleting "rooms"

Rooms

Rooms are instances of joinable "sessions" that users can add themselves to (kind of like a roster). All joined players may send "actions" to the game. These "actions" represent the transactions from frame to frame for third party applications.

Documentation

Index

Constants

View Source
const AuthIDAtomicCounter string = "authIDAtomicCounter"

Redis Key for the Atomic UserID Counter

View Source
const AuthIDSetPrefix string = "authID:"

Redis HashTable Key Prefix for User IDs. Concatenated with a UserID for a HashTable they own

View Source
const AuthIDSetTokenField string = "token"

Token Key/Field for Redis UserID HashTable

View Source
const AuthIDSetTokenStaleDateTimeField string = "stale"

Token Deadline DateTime Key/Field for Redis UserID HashTable

View Source
const AuthIDSetTokenUseCounter string = "tokenUses"

Token Use Counter Key/Field for Redis UserID HashTable

View Source
const AuthIDSetUsernameField string = "username"

Username Key/Field for Redis UserID HashTable

View Source
const CommandToExec string = "node"

Shell Command to execute

View Source
const EmptyName string = "empty"

Redis Key for Empty Set useful for ease of group deletions

View Source
const GameAtomicCounter string = "gameCountInteger"

Redis Key for Game ID Counter

View Source
const GameHashSetName string = "gameHash"

Redis Key for Game Set

View Source
const GameListName string = "gameList"

Redis Key For Game List

View Source
const GamePort string = ":" + GamePortNum

Game Port Number (prefixed with colon)

View Source
const GamePortNum string = "5011"

Game Port Number

View Source
const MetadataSetCreatedAt string = "createdAt"

Redis Field/Key for Game Metadata Creation DateTime

(number of milliseconds since epoch)
View Source
const MetadataSetLastUsed string = "lastUsed"

Redis Field/Key for Game Metadata Last Used DateTime

(number of milliseconds since epoch)
View Source
const MetadataSetOwner string = "owner"

Redis Field/Key for Game Metadata Owner

View Source
const MetadataSetPrefix string = "metadataHash:"

Redis Key Prefix for Game Metadata Hashmaps

View Source
const NumberOfGames = 20

The Maximum Number of Games If ThrottleGames is true

View Source
const OwnerHashSetName string = "ownerMapGame"

Redis Key for Owner Set

View Source
const PlayerSetPrefix string = "roster:"

Redis Key Prefix for Player Roster Sets

View Source
const ThrottleGames = false

Whether to Throttle to the Maximum Number of Games or Not

View Source
const TokenLength int = 256

Length of Characters For Secret User Authentication Token

View Source
const TokenStaleTime time.Duration = time.Minute * 5

Time A Token stays good for before it is rejected and a new login is required

View Source
const UserAuthIDTable string = "userToAuthID"

Redis Key for the Username to UserID HashMap

View Source
const UserPassTable string = "userPassword"

Redis Key for the User Password HashMap

View Source
const WaitDurationForGameAction time.Duration = 3 * time.Second

Time to Wait For Game to Respond to an Action

View Source
const WaitDurationForGameStop time.Duration = 10 * time.Second

Time to wait for Game to Finish cleaning up

Variables

View Source
var CommandArgs []string = []string{"./node-layer/index.js", "--binding=" + GamePortNum}

Shell Command Args This value should not change at runtime

Functions

func ApplyAction

func ApplyAction(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, isSecureConnection bool) policy.CommandResponse

The Apply Action Endpoint sends the payload to the game. This will be the most highly used endpoint as this represents the main transport method to games. The Game actually runs the code, but the application loads the data for the game from the database.

func BytesFromGame

func BytesFromGame(req *zmq4.Socket) (string, error)

Receive a string of bytes from the game.(This is used with BytesToGame and there should not be a need to call this function)

req :: ZeroMQ Request Socket

returns -> string :: response from third-party game

-> error :: non-nil if it couldn't receive
       data from game

func BytesToGame

func BytesToGame(dataIn string) (string, error)

Send a string of bytes to the third party application using ZeroMQ (The Game SDK will take care of setting up the "server" part of communication. We just connect and send a string, waiting for a a response). Thread Safe with ZeroMQ!

dataIn :: string to sent to game (usually a JSON.)

returns -> string :: response from third-party game

-> error :: non-nil if it couldn't send data
       to the game.

func CanCreateGame

func CanCreateGame(authID string) (bool, error)

func ConstructNewToken added in v0.0.3

func ConstructNewToken(authID string) ([]byte, time.Time, error)

Constructs a new token and deadline for the token going stale for a user. Usually occurs on a successful login. Token can be refreshed any number of times. It is then used for identity authentication in future requests.

func CreateAccount added in v0.0.3

func CreateAccount(username string, password string) (bool, error)

Adds an account to the database, hashing the password and associating starting values in all typical fields in redis

returns bool :: true/false if the user can be added to the database

error :: if writing to the database failed it will be non-nil

func CreateGame

func CreateGame(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, isSecureConnection bool) policy.CommandResponse

Create Game Endpoint to add a Game and new Game Data to the the database. Each player can only own/create one game. They may delete and create games freely.

func DeleteGame

func DeleteGame(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, isSecureConnection bool) policy.CommandResponse

An Owner may delete their game at any time. This means the game metadata and state will be removed from the database.

func DeleteUser added in v0.0.3

func DeleteUser(username string) (bool, error)

Deletes an account from the database, not that it would be particularly needed outside of unit testing

returns bool :: true/false if the user can be deleted from the database

error :: if writing to the database failed it will be non-nil

func GetGameData

func GetGameData(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, isSecureConnection bool) policy.CommandResponse

The Get Game Data Endpoint gathers all the data in the database for a game. The Games are public by default so anyone should be able to observe

However, observers cannot change the game in any way. You have to be on the roster to apply an action

func GetRoomHealth

func GetRoomHealth(gameID string) (time.Time, error)

Returns the time in which the last recorded action was taken for a game. This loads the value from the Redis database.

gameID :: Unique Identifier for game in string form

returns -> time.Time :: time last action was made

-> error     :: non-nil if unable to read game metadata

func GetUser added in v0.0.3

func GetUser(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, isSecureConnection bool) policy.CommandResponse

Endpoint Returns the User ID associated with the supplied username. Useful for finding friends and connecting other information.

func IncrementCounterAndGetValue added in v0.0.3

func IncrementCounterAndGetValue(keyName string) (int64, error)

func IncrementTokenUses added in v0.0.3

func IncrementTokenUses(authID string, newCount int) error

func IsUserInGame

func IsUserInGame(userID string, gameID string) (bool, error)

Returns whether a user is in a game's roster (see JoinGame and leaveGame).

userID :: Unique Identifier for a user gameID :: Unique Identifier for game in string form

returns -> bool :: true if the user is in the roster, false otherwise

-> error :: non-nil if unable to read game metadata

func IsValidLogin added in v0.0.3

func IsValidLogin(username string, password string) bool

Returns if the given login is valid or invalid based on username and hashed password. If it exists in the UserPass hashMap then it is a valid Username + Password Combination.

func JoinGame

func JoinGame(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, isSecureConnection bool) policy.CommandResponse

Join Game Endpoint adds the player to the roster of an existing game. This means they can "applyActions" to the game (see game.go)

func LeaveGame

func LeaveGame(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, isSecureConnection bool) policy.CommandResponse

Leave Game Endpoint removes the player from the roster of an existing game. This means they can no longer "applyActions" to the game (see game.go)

func Login added in v0.0.3

func Login(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, isSecureConnection bool) policy.CommandResponse

Login a user to receive a valid token to continue making requests under. The connection must be secure and correctly formatted otherwise an error will be returned.

func Register added in v0.0.3

func Register(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, isSecureConnection bool) policy.CommandResponse

Register Endpoint. Registers a user to the database. It requires a unique username/identifier and a relatively strong password

TODO(TFlexSoom): Add rate Limiting

func SetGameMetadata

func SetGameMetadata(metadata GameMetadata) error

Utility Function for changing Game Metadata with Redis

metadata :: New Metadata Value

(overwrites the id at metadata.id)

func StartGameLogic

func StartGameLogic() (func(), error)

ServerTask Startup Function for the third-party Game application. Takes care of initialization. returns an error if the game can't be started (i.e. prerequisites are not met)

func StartRoomsSystem

func StartRoomsSystem() (func(), error)

ServerTask Startup Function for Game Rooms. Takes care of initialization. Sets Atomic Counter for GameIDs. Error is returned if the Database can't be reached.

func StartUsers added in v0.0.3

func StartUsers() (func(), error)

ServerTask Startup Function for Users. Takes care of initialization. Loads The Password Salt from the Hash if it does not already exist

func StringIDFromNumbers

func StringIDFromNumbers(counter int64) string

Provides a 12 character string ID from any given 64 bit Integer The ID uses the characters 0-9 and a-z This is used for GameIDs

Types

type AuthToken added in v0.0.3

type AuthToken struct {
	Token string
	Stale time.Time
	Uses  int
}

func GetToken added in v0.0.3

func GetToken(authID string) (AuthToken, error)

type GameMetadata

type GameMetadata struct {
	Id        string
	Owner     string
	CreatedAt int64 `json:",string"`
	LastUsed  int64 `json:",string"`
}

JSON Fields for the Create Game Command For Static game details

func GetGameMetadata

func GetGameMetadata(gameID string) (GameMetadata, error)

Utility Function for selecting the game Metadata from redis

gameID :: string unique identifier for game.

type GameWelcomeData

type GameWelcomeData struct {
	Id         string
	NumPlayers uint16
	Data       string
}

JSON Fields for the Join Game Command

type GetUserCommandBody added in v0.0.3

type GetUserCommandBody struct {
	Username string
}

JSON Fields for the User Lookup Endpoint/Command

type LoginCommandBody added in v0.0.3

type LoginCommandBody struct {
	Username string
	Password string
}

JSON Fields for the Login Endpoint/Command

type RegisterCommandBody added in v0.0.3

type RegisterCommandBody struct {
	Username string
	Password string
}

JSON Fields for the Register Endpoint/Command

type SelectGameArgs

type SelectGameArgs struct {
	GameID string
}

Unmarshal Structure for Joining/Finding Games

type UserInfo added in v0.0.3

type UserInfo struct {
	AuthID   string
	Username string
}

struct for ease of use when marshalling to JSON. Carries the fields used when a user is gathered from cmdGetUser

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL