/
acceptduo.go
84 lines (71 loc) · 3.24 KB
/
acceptduo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package api
import (
"github.com/gin-gonic/gin"
"../players/auth"
"../players"
"../queue"
"../smurf"
"../bans"
"fmt"
"time"
"encoding/base64"
)
func HttpAcceptDuo(c *gin.Context) {
mapResponse := make(map[string]interface{});
sCookieSessID, errCookieSessID := c.Cookie("session_id");
sInviteCode := c.Query("invite_code");
mapResponse["success"] = false;
if (sInviteCode != "") {
if (errCookieSessID == nil && sCookieSessID != "") {
oSession, bAuthorized := auth.GetSession(sCookieSessID, c.Query("csrf"));
if (bAuthorized) {
players.MuPlayers.Lock();
i64CurTime := time.Now().UnixMilli();
pPlayer := players.MapPlayers[oSession.SteamID64];
iMmrGrade := players.GetMmrGrade(pPlayer);
if (pPlayer.IsInQueue) {
mapResponse["error"] = "You are already in queue";
} else if (pPlayer.IsInGame) {
mapResponse["error"] = "You cant join queue, finish your game first";
} else if (queue.NewGamesBlocked) {
mapResponse["error"] = "The site is going to be restarted soon, new games are not allowed";
} else if (pPlayer.NextQueueingAllowed > i64CurTime) {
mapResponse["error"] = fmt.Sprintf("You are temporarily blocked from joining games. Please wait %d seconds.", (pPlayer.NextQueueingAllowed - i64CurTime) / 1000);
} else if (!pPlayer.IsOnline) {
mapResponse["error"] = "Somehow you are not Online, try to refresh the page";
} else if (!pPlayer.ProfValidated) {
mapResponse["error"] = "Please validate your profile first";
} else if (!pPlayer.RulesAccepted) {
mapResponse["error"] = "Please accept our rules first";
} else if (pPlayer.Access <= -2) {
mapResponse["error"] = "Sorry, you are banned, you gotta wait until it expires";
} else if (iMmrGrade == 0) {
mapResponse["error"] = "You need to gain a rank before queueing up with your friend";
} else if (iMmrGrade >= 6 && players.CustomMapsConfirmState(pPlayer) != 3) {
mapResponse["error"] = "🇬🇧 Before joining game, please confirm download/installation of custom/addon maps<br><br>🇪🇸 Antes de buscar una partida, debes confirmar que has descargado e instalado los mapas custom<br><br>🇷🇺 Перед входом в игру, пожалуйста подтвердите что вы установили кастомные/аддоновые карты";
} else {
errAcceptDuo := queue.AcceptDuo(pPlayer, sInviteCode);
if (errAcceptDuo != nil) {
mapResponse["error"] = errAcceptDuo.Error();
} else {
mapResponse["success"] = true;
sCookieUniqueKey, _ := c.Cookie("auth2");
byNickname, _ := base64.StdEncoding.DecodeString(pPlayer.NicknameBase64);
go smurf.AnnounceIPAndKey(pPlayer.SteamID64, c.ClientIP(), string(byNickname), sCookieUniqueKey);
go func(sSteamID64 string)() {bans.ChanAutoBanSmurfs <- smurf.GetKnownAccounts(sSteamID64);}(oSession.SteamID64);
}
}
players.MuPlayers.Unlock();
} else {
mapResponse["error"] = "Please authorize first";
}
} else {
mapResponse["error"] = "Please authorize first";
}
} else {
mapResponse["error"] = "No Invite Code present";
}
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("origin"));
c.Header("Access-Control-Allow-Credentials", "true");
c.JSON(200, mapResponse);
}