Documentation ¶
Overview ¶
./handlers/admin.go
./handlers/alliance.go (Ensure CreateAlliance uses correct models)
./handlers/faction.go (Ensure Faction references Zone correctly)
./handlers/match.go (Ensure Match does not reference undefined types)
Index ¶
- Variables
- func CreateAdmin(w http.ResponseWriter, r *http.Request)
- func CreateAlliance(w http.ResponseWriter, r *http.Request)
- func CreateFaction(w http.ResponseWriter, r *http.Request)
- func CreateMatch(w http.ResponseWriter, r *http.Request)
- func DeletePlayer(w http.ResponseWriter, r *http.Request)
- func GetLeaderboard(w http.ResponseWriter, r *http.Request)
- func InitHandlers(database *gorm.DB, natsConn *nats.Conn)
- func InitLeaderboard(database *gorm.DB, rdb *redis.Client)
- func LoginPlayer(w http.ResponseWriter, r *http.Request)
- func PlayTurn(w http.ResponseWriter, r *http.Request)
- func PublishAlert(subject, message string)
- func RegisterPlayer(w http.ResponseWriter, r *http.Request)
- func SendAlert(nc *nats.Conn, subject, message string)
- func UpdateResource(w http.ResponseWriter, r *http.Request)
- func WebSocketHandler(w http.ResponseWriter, r *http.Request)
- type Claims
- type GameState
- type PlayerConnection
- type PlayerMove
Constants ¶
This section is empty.
Variables ¶
var (
JwtKey = []byte(os.Getenv("JWT_SECRET_KEY")) // Load JWT key from env var
)
Functions ¶
func CreateAdmin ¶
func CreateAdmin(w http.ResponseWriter, r *http.Request)
CreateAdmin allows the creation of admin users. This should be restricted and possibly handled offline.
func CreateAlliance ¶
func CreateAlliance(w http.ResponseWriter, r *http.Request)
CreateAlliance allows two faction leaders to form an alliance.
func CreateFaction ¶
func CreateFaction(w http.ResponseWriter, r *http.Request)
CreateFaction allows a player to create a new faction within a game instance.
func CreateMatch ¶
func CreateMatch(w http.ResponseWriter, r *http.Request)
CreateMatch initiates a match between two players with an initial game state.
func DeletePlayer ¶
func DeletePlayer(w http.ResponseWriter, r *http.Request)
Example of a protected admin route
func GetLeaderboard ¶
func GetLeaderboard(w http.ResponseWriter, r *http.Request)
GetLeaderboard handles various types of leaderboard views
func InitHandlers ¶
InitHandlers sets up the shared database and NATS connection instances
func InitLeaderboard ¶
InitLeaderboard initializes Redis and database
func LoginPlayer ¶
func LoginPlayer(w http.ResponseWriter, r *http.Request)
LoginPlayer handles player login and JWT generation
func PlayTurn ¶
func PlayTurn(w http.ResponseWriter, r *http.Request)
PlayTurn allows a player to submit their turn, updates game state, and saves it.
func PublishAlert ¶
func PublishAlert(subject, message string)
PublishAlert sends an alert message to a specific NATS subject
func RegisterPlayer ¶
func RegisterPlayer(w http.ResponseWriter, r *http.Request)
RegisterPlayer handles player registration
func SendAlert ¶
func SendAlert(nc *nats.Conn, subject, message string)
SendAlert publishes an alert message to a NATS subject
func UpdateResource ¶
func UpdateResource(w http.ResponseWriter, r *http.Request)
UpdateResource allows updating a player's resources.
func WebSocketHandler ¶
func WebSocketHandler(w http.ResponseWriter, r *http.Request)
WebSocketHandler establishes a WebSocket connection and manages turns
Types ¶
type Claims ¶
type Claims struct { Username string `json:"username"` UserID uint `json:"id"` jwt.RegisteredClaims }
Claims structure with UserID included for authentication
type GameState ¶
type GameState struct { TurnCount int `json:"turn_count"` Moves []PlayerMove `json:"moves"` // Record of moves in the game }
GameState represents the state of the game within a match.
type PlayerConnection ¶
PlayerConnection represents an active WebSocket connection for a player
type PlayerMove ¶
PlayerMove represents a single move by a player.