aboutsummaryrefslogtreecommitdiff
path: root/backend/handlers/record.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/handlers/record.go')
-rw-r--r--backend/handlers/record.go44
1 files changed, 43 insertions, 1 deletions
diff --git a/backend/handlers/record.go b/backend/handlers/record.go
index 79e9d3b..c620430 100644
--- a/backend/handlers/record.go
+++ b/backend/handlers/record.go
@@ -3,12 +3,14 @@ package handlers
3import ( 3import (
4 "context" 4 "context"
5 "encoding/base64" 5 "encoding/base64"
6 "fmt"
6 "io" 7 "io"
7 "log" 8 "log"
8 "mime/multipart" 9 "mime/multipart"
9 "net/http" 10 "net/http"
10 "os" 11 "os"
11 "strconv" 12 "strconv"
13 "strings"
12 14
13 "github.com/gin-gonic/gin" 15 "github.com/gin-gonic/gin"
14 "github.com/google/uuid" 16 "github.com/google/uuid"
@@ -90,6 +92,7 @@ func CreateRecordWithDemo(c *gin.Context) {
90 } 92 }
91 var hostDemoUUID, hostDemoFileID, partnerDemoUUID, partnerDemoFileID string 93 var hostDemoUUID, hostDemoFileID, partnerDemoUUID, partnerDemoFileID string
92 var hostDemoScoreCount, hostDemoScoreTime int 94 var hostDemoScoreCount, hostDemoScoreTime int
95 var hostSteamID, partnerSteamID string
93 client := serviceAccount() 96 client := serviceAccount()
94 srv, err := drive.New(client) 97 srv, err := drive.New(client)
95 if err != nil { 98 if err != nil {
@@ -127,7 +130,7 @@ func CreateRecordWithDemo(c *gin.Context) {
127 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 130 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
128 return 131 return
129 } 132 }
130 hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") 133 hostDemoScoreCount, hostDemoScoreTime, hostSteamID, partnerSteamID, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem")
131 if err != nil { 134 if err != nil {
132 deleteFile(srv, file.Id) 135 deleteFile(srv, file.Id)
133 CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordProcessDemoFail, err.Error()) 136 CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionCreateRecordProcessDemoFail, err.Error())
@@ -140,6 +143,25 @@ func CreateRecordWithDemo(c *gin.Context) {
140 c.JSON(http.StatusOK, models.ErrorResponse("Processing demo went wrong. Please contact a web admin and provide the demo in question.")) 143 c.JSON(http.StatusOK, models.ErrorResponse("Processing demo went wrong. Please contact a web admin and provide the demo in question."))
141 return 144 return
142 } 145 }
146 if !isCoop {
147 hostSplit := strings.Split(hostSteamID, ":")
148 if hostSplit[len(hostSplit)-1] != user.(models.User).SteamID {
149 c.JSON(http.StatusOK, models.ErrorResponse(fmt.Sprintf("Host SteamID from demo and request does not match! Check your submission and try again.\nDemo Host SteamID: %s\nRequest Host SteamID: %s", hostSplit[len(hostSplit)-1], user.(models.User).SteamID)))
150 return
151 }
152 } else {
153 partnerSplit := strings.Split(partnerSteamID, ":")
154 if partnerSplit[len(partnerSplit)-1] != record.PartnerID {
155 c.JSON(http.StatusOK, models.ErrorResponse(fmt.Sprintf("Partner SteamID from demo and request does not match! Check your submission and try again.\nDemo Partner SteamID: %s\nRequest Partner SteamID: %s", partnerSplit[len(partnerSplit)-1], record.PartnerID)))
156 return
157 }
158 var verifyCoopSteamID string
159 database.DB.QueryRow("SELECT steam_id FROM users WHERE steam_id = $1", record.PartnerID).Scan(&verifyCoopSteamID)
160 if verifyCoopSteamID != record.PartnerID {
161 c.JSON(http.StatusOK, models.ErrorResponse("Given partner SteamID does not match an account on LPHUB."))
162 return
163 }
164 }
143 if i == 0 { 165 if i == 0 {
144 hostDemoFileID = file.Id 166 hostDemoFileID = file.Id
145 hostDemoUUID = uuid 167 hostDemoUUID = uuid
@@ -384,3 +406,23 @@ func createFile(service *drive.Service, name string, mimeType string, content io
384func deleteFile(service *drive.Service, fileId string) { 406func deleteFile(service *drive.Service, fileId string) {
385 service.Files.Delete(fileId) 407 service.Files.Delete(fileId)
386} 408}
409
410// Convert from SteamID64 to Legacy SteamID bits
411func convertSteamID(steamID64 int64) int64 {
412 return (steamID64 >> 1) & 0x7FFFFFF
413}
414
415// Convert from Legacy SteamID bits to SteamID64
416func convertSteamID64(steamID string) int64 {
417 const baseSteam64ID = 76561197960265728 // Origin of this value remains unclear
418 parts := strings.Split(steamID, ":")
419 userId, err := strconv.Atoi(parts[2])
420 if err != nil {
421 return 0
422 }
423 steam64ID := baseSteam64ID + int64(userId*2) // Reason for multiplication by 2 is unknown
424 if parts[1] == "1" {
425 steam64ID++
426 }
427 return steam64ID
428}