Taken from http://prod.game1.ll.sdo.com/resources/maintenace/maintenance.php Signed-off-by: Yuan Si <do4suki@gmail.com>
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
"honoka-chan/config"
|
|
"honoka-chan/database"
|
|
"honoka-chan/encrypt"
|
|
"honoka-chan/resp"
|
|
"honoka-chan/utils"
|
|
"html/template"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func AnnounceIndexHandler(ctx *gin.Context) {
|
|
ctx.HTML(http.StatusOK, "announce.tmpl", gin.H{
|
|
"title": "Love Live! 学园偶像祭 非官方服务器",
|
|
"content": template.HTML("目前开发完毕的功能包括:登录、相册、Live、个人信息。<br>其他功能仍在开发中,有报错属于正常现象。"),
|
|
})
|
|
}
|
|
|
|
func AnnounceCheckStateHandler(ctx *gin.Context) {
|
|
reqTime := time.Now().Unix()
|
|
|
|
authorizeStr := ctx.Request.Header["Authorize"]
|
|
authToken, err := utils.GetAuthorizeToken(authorizeStr)
|
|
if err != nil {
|
|
ctx.String(http.StatusForbidden, "Fuck you!")
|
|
return
|
|
}
|
|
userId := ctx.Request.Header[http.CanonicalHeaderKey("User-ID")]
|
|
if len(userId) == 0 {
|
|
ctx.String(http.StatusForbidden, "Fuck you!")
|
|
return
|
|
}
|
|
|
|
if !database.MatchTokenUid(authToken, userId[0]) {
|
|
ctx.String(http.StatusForbidden, "Fuck you!")
|
|
return
|
|
}
|
|
|
|
nonce, err := utils.GetAuthorizeNonce(authorizeStr)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
ctx.String(http.StatusForbidden, "Fuck you!")
|
|
return
|
|
}
|
|
nonce++
|
|
|
|
respTime := time.Now().Unix()
|
|
newAuthorizeStr := fmt.Sprintf("consumerKey=lovelive_test&timeStamp=%d&version=1.1&token=%s&nonce=%d&user_id=%s&requestTimeStamp=%d", respTime, authToken, nonce, userId[0], reqTime)
|
|
// fmt.Println(newAuthorizeStr)
|
|
|
|
xms := encrypt.RSA_Sign_SHA1([]byte(resp.AnnounceState), "privatekey.pem")
|
|
xms64 := base64.RawStdEncoding.EncodeToString(xms)
|
|
|
|
ctx.Header("Server-Version", config.Conf.Server.VersionNumber)
|
|
ctx.Header("user_id", userId[0])
|
|
ctx.Header("authorize", newAuthorizeStr)
|
|
ctx.Header("X-Message-Sign", xms64)
|
|
ctx.String(http.StatusOK, resp.AnnounceState)
|
|
}
|