Skip to content

Commit

Permalink
feat(b): kick/ban will try uid&steam64
Browse files Browse the repository at this point in the history
  • Loading branch information
zaigie committed Feb 27, 2024
1 parent 53d6212 commit 7d95b6c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
47 changes: 44 additions & 3 deletions api/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,35 @@ func getPlayer(c *gin.Context) {
// @Success 200 {object} SuccessResponse
// @Failure 400 {object} ErrorResponse
// @Failure 401 {object} ErrorResponse
// @Failure 404 {object} ErrorResponse
// @Router /api/player/{player_uid}/kick [post]
func kickPlayer(c *gin.Context) {
playerUid := c.Param("player_uid")
if err := tool.KickPlayer(playerUid); err != nil {
player, err := service.GetPlayer(database.GetDB(), playerUid)
if err != nil {
if err == service.ErrNoRecord {
c.JSON(http.StatusNotFound, gin.H{"error": "Player not found"})
return
}
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err = tool.KickPlayer(playerUid)
if err != nil {
if player.SteamId == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err = tool.KickPlayer(player.SteamId)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
} else {
c.JSON(http.StatusOK, gin.H{"success": true})
return
}
}
c.JSON(http.StatusOK, gin.H{"success": true})

}

// banPlayer godoc
Expand All @@ -151,13 +171,34 @@ func kickPlayer(c *gin.Context) {
// @Success 200 {object} SuccessResponse
// @Failure 400 {object} ErrorResponse
// @Failure 401 {object} ErrorResponse
// @Failure 404 {object} ErrorResponse
// @Router /api/player/{player_uid}/ban [post]
func banPlayer(c *gin.Context) {
playerUid := c.Param("player_uid")
if err := tool.BanPlayer(playerUid); err != nil {
player, err := service.GetPlayer(database.GetDB(), playerUid)
if err != nil {
if err == service.ErrNoRecord {
c.JSON(http.StatusNotFound, gin.H{"error": "Player not found"})
return
}
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err = tool.BanPlayer(playerUid)
if err != nil {
if player.SteamId == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err = tool.BanPlayer(player.SteamId)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
} else {
c.JSON(http.StatusOK, gin.H{"success": true})
return
}
}
c.JSON(http.StatusOK, gin.H{"success": true})
}

Expand Down
12 changes: 12 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ const docTemplate = `{
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
Expand Down Expand Up @@ -433,6 +439,12 @@ const docTemplate = `{
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
Expand Down Expand Up @@ -422,6 +428,12 @@
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ paths:
description: Unauthorized
schema:
$ref: '#/definitions/api.ErrorResponse'
"404":
description: Not Found
schema:
$ref: '#/definitions/api.ErrorResponse'
security:
- ApiKeyAuth: []
summary: Ban Player
Expand Down Expand Up @@ -472,6 +476,10 @@ paths:
description: Unauthorized
schema:
$ref: '#/definitions/api.ErrorResponse'
"404":
description: Not Found
schema:
$ref: '#/definitions/api.ErrorResponse'
security:
- ApiKeyAuth: []
summary: Kick Player
Expand Down

0 comments on commit 7d95b6c

Please sign in to comment.