Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyAction(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, ...) policy.CommandResponse
- func BytesFromGame(req *zmq4.Socket) (string, error)
- func BytesToGame(dataIn string) (string, error)
- func CanCreateGame(authID string) (bool, error)
- func ConstructNewToken(authID string) ([]byte, time.Time, error)
- func CreateAccount(username string, password string) (bool, error)
- func CreateGame(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, ...) policy.CommandResponse
- func DeleteGame(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, ...) policy.CommandResponse
- func DeleteUser(username string) (bool, error)
- func GetGameData(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, ...) policy.CommandResponse
- func GetRoomHealth(gameID string) (time.Time, error)
- func GetUser(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, ...) policy.CommandResponse
- func IncrementCounterAndGetValue(keyName string) (int64, error)
- func IncrementTokenUses(authID string, newCount int) error
- func IsUserInGame(userID string, gameID string) (bool, error)
- func IsValidLogin(username string, password string) bool
- func JoinGame(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, ...) policy.CommandResponse
- func LeaveGame(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, ...) policy.CommandResponse
- func Login(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, ...) policy.CommandResponse
- func Register(header policy.RequestHeader, bodyFactories policy.RequestBodyFactories, ...) policy.CommandResponse
- func SetGameMetadata(metadata GameMetadata) error
- func StartGameLogic() (func(), error)
- func StartRoomsSystem() (func(), error)
- func StartUsers() (func(), error)
- func StringIDFromNumbers(counter int64) string
- type AuthToken
- type GameMetadata
- type GameWelcomeData
- type GetUserCommandBody
- type LoginCommandBody
- type RegisterCommandBody
- type SelectGameArgs
- type UserInfo
Constants ¶
const AuthIDAtomicCounter string = "authIDAtomicCounter"
Redis Key for the Atomic UserID Counter
const AuthIDSetPrefix string = "authID:"
Redis HashTable Key Prefix for User IDs. Concatenated with a UserID for a HashTable they own
const AuthIDSetTokenField string = "token"
Token Key/Field for Redis UserID HashTable
const AuthIDSetTokenStaleDateTimeField string = "stale"
Token Deadline DateTime Key/Field for Redis UserID HashTable
const AuthIDSetTokenUseCounter string = "tokenUses"
Token Use Counter Key/Field for Redis UserID HashTable
const AuthIDSetUsernameField string = "username"
Username Key/Field for Redis UserID HashTable
const CommandToExec string = "node"
Shell Command to execute
const EmptyName string = "empty"
Redis Key for Empty Set useful for ease of group deletions
const GameAtomicCounter string = "gameCountInteger"
Redis Key for Game ID Counter
const GameHashSetName string = "gameHash"
Redis Key for Game Set
const GameListName string = "gameList"
Redis Key For Game List
const GamePort string = ":" + GamePortNum
Game Port Number (prefixed with colon)
const GamePortNum string = "5011"
Game Port Number
const MetadataSetCreatedAt string = "createdAt"
Redis Field/Key for Game Metadata Creation DateTime
(number of milliseconds since epoch)
const MetadataSetLastUsed string = "lastUsed"
Redis Field/Key for Game Metadata Last Used DateTime
(number of milliseconds since epoch)
const MetadataSetOwner string = "owner"
Redis Field/Key for Game Metadata Owner
const MetadataSetPrefix string = "metadataHash:"
Redis Key Prefix for Game Metadata Hashmaps
const NumberOfGames = 20
The Maximum Number of Games If ThrottleGames is true
const OwnerHashSetName string = "ownerMapGame"
Redis Key for Owner Set
const PlayerSetPrefix string = "roster:"
Redis Key Prefix for Player Roster Sets
const ThrottleGames = false
Whether to Throttle to the Maximum Number of Games or Not
const TokenLength int = 256
Length of Characters For Secret User Authentication Token
const TokenStaleTime time.Duration = time.Minute * 5
Time A Token stays good for before it is rejected and a new login is required
const UserAuthIDTable string = "userToAuthID"
Redis Key for the Username to UserID HashMap
const UserPassTable string = "userPassword"
Redis Key for the User Password HashMap
const WaitDurationForGameAction time.Duration = 3 * time.Second
Time to Wait For Game to Respond to an Action
const WaitDurationForGameStop time.Duration = 10 * time.Second
Time to wait for Game to Finish cleaning up
Variables ¶
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 ¶
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 ¶
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 ConstructNewToken ¶ added in v0.0.3
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
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
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 ¶
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 IncrementTokenUses ¶ added in v0.0.3
func IsUserInGame ¶
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
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 ¶
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 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 ¶
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
JSON Fields for the Login Endpoint/Command
type RegisterCommandBody ¶ added in v0.0.3
JSON Fields for the Register Endpoint/Command
type SelectGameArgs ¶
type SelectGameArgs struct {
GameID string
}
Unmarshal Structure for Joining/Finding Games