Skip to content

Commit be00a2d

Browse files
committed
Add stream badge support.
1 parent 2a7b660 commit be00a2d

File tree

5 files changed

+201
-3
lines changed

5 files changed

+201
-3
lines changed

controllers/admin/templates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"html/template"
55
)
66

7-
func InitTemplates() {
7+
func InitAdminTemplates() {
88
banlogsTempl = template.Must(template.ParseFiles("views/admin/templates/ban_logs.html"))
99
chatLogsTempl = template.Must(template.ParseFiles("views/admin/templates/chatlogs.html"))
1010
lobbiesTempl = template.Must(template.ParseFiles("views/admin/templates/lobbies.html"))

controllers/twitch_badge.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package controllers
2+
3+
import (
4+
"github.com/TF2Stadium/Helen/controllers/admin"
5+
"github.com/TF2Stadium/Helen/models"
6+
"html/template"
7+
"net/http"
8+
"regexp"
9+
)
10+
11+
var (
12+
twitchBadge *template.Template
13+
reValidPath = regexp.MustCompile(`badge/(\d+)`)
14+
)
15+
16+
func TwitchBadge(w http.ResponseWriter, r *http.Request) {
17+
if !reValidPath.MatchString(r.URL.Path) {
18+
http.NotFound(w, r)
19+
return
20+
}
21+
22+
matches := reValidPath.FindStringSubmatch(r.URL.Path)
23+
steamid := matches[1]
24+
25+
player, err := models.GetPlayerBySteamID(steamid)
26+
if err != nil { //player not found
27+
http.Error(w, "Player with given SteamID not found", http.StatusNotFound)
28+
return
29+
}
30+
31+
id, err := player.GetLobbyID(false)
32+
if err != nil {
33+
//player not in lobby right now
34+
return
35+
}
36+
37+
lobby, _ := models.GetLobbyByID(id)
38+
err = twitchBadge.Execute(w, lobby)
39+
}
40+
41+
func InitTemplates() {
42+
admin.InitAdminTemplates()
43+
twitchBadge = template.Must(template.ParseFiles("views/twitchbadge.html"))
44+
}

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/DSchalla/go-pid"
1919
"github.com/Sirupsen/logrus"
2020
"github.com/TF2Stadium/Helen/config"
21-
"github.com/TF2Stadium/Helen/controllers/admin"
21+
"github.com/TF2Stadium/Helen/controllers"
2222
chelpers "github.com/TF2Stadium/Helen/controllers/controllerhelpers"
2323
"github.com/TF2Stadium/Helen/controllers/socket"
2424
"github.com/TF2Stadium/Helen/database"
@@ -58,7 +58,7 @@ func main() {
5858
os.Exit(0)
5959
}
6060

61-
admin.InitTemplates()
61+
controllers.InitTemplates()
6262
config.SetupConstants()
6363
helpers.SetServemeContext()
6464
//models.ReadServers()

routes/http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var routes = []route{
4242
{"/admin/lobbies", chelpers.FilterHTTPRequest(helpers.ActionViewLogs, admin.ViewOpenLobbies)},
4343

4444
{"/health", controllers.Health},
45+
{"/badge/", controllers.TwitchBadge},
4546
}
4647

4748
func SetupHTTP(mux *http.ServeMux) {

views/twitchbadge.html

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<meta http-equiv="refresh" content="5">
5+
</head>
6+
<body>
7+
<svg
8+
xmlns:dc="http://purl.org/dc/elements/1.1/"
9+
xmlns:cc="http://creativecommons.org/ns#"
10+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
11+
xmlns:svg="http://www.w3.org/2000/svg"
12+
xmlns="http://www.w3.org/2000/svg"
13+
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
14+
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
15+
version="1.1"
16+
x="0px"
17+
y="0px"
18+
width="486.74515"
19+
height="99.059479"
20+
viewBox="0 0 486.74514 99.059482"
21+
enable-background="new 0 0 604.265 610.381"
22+
xml:space="preserve"
23+
id="svg3418"
24+
inkscape:version="0.91 r13725"
25+
sodipodi:docname="h.svg"><metadata
26+
id="metadata3460"><rdf:RDF><cc:Work
27+
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
28+
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
29+
id="defs3458" /><sodipodi:namedview
30+
pagecolor="#ffffff"
31+
bordercolor="#666666"
32+
borderopacity="1"
33+
objecttolerance="10"
34+
gridtolerance="10"
35+
guidetolerance="10"
36+
inkscape:pageopacity="0"
37+
inkscape:pageshadow="2"
38+
inkscape:window-width="1596"
39+
inkscape:window-height="864"
40+
id="namedview3456"
41+
showgrid="false"
42+
inkscape:zoom="0.75785828"
43+
inkscape:cx="345.0537"
44+
inkscape:cy="-47.354562"
45+
inkscape:window-x="0"
46+
inkscape:window-y="16"
47+
inkscape:window-maximized="0"
48+
inkscape:current-layer="svg3418"
49+
inkscape:snap-text-baseline="false"
50+
borderlayer="true"
51+
fit-margin-top="0"
52+
fit-margin-left="0"
53+
fit-margin-right="0"
54+
fit-margin-bottom="0" /><g
55+
id="Capa_3"
56+
transform="translate(0,-0.86897899)" /><g
57+
id="Capa_4"
58+
transform="matrix(0.08980331,0,0,0.09794216,0,-0.06503359)"><g
59+
id="g3422"><path
60+
d="m 288.831,45.008 5.33,-44.344 C 156.749,4.167 42.127,100.179 9.137,229.288 l 43.904,5.19 C 82.619,129.01 176.237,50.683 288.831,45.008 Z"
61+
id="path3424"
62+
inkscape:connector-curvature="0"
63+
style="fill:#4e9cd5" /><path
64+
d="M 44.141,327.114 0,321.896 c 6.921,133.452 98.806,244.184 222.104,278.16 l 5.332,-44.354 C 127.413,525.393 52.877,435.645 44.141,327.114 Z"
65+
id="path3426"
66+
inkscape:connector-curvature="0"
67+
style="fill:#4e9cd5" /><path
68+
d="m 560.369,294.44 43.896,5.188 C 601.657,164.684 512.228,51.221 390.02,13.728 l -5.358,44.581 C 483.596,91.983 555.74,184.394 560.369,294.44 Z"
69+
id="path3428"
70+
inkscape:connector-curvature="0"
71+
style="fill:#4e9cd5" /><path
72+
d="m 323.655,565.793 -5.359,44.588 c 130.125,-6.999 238.4,-97.01 273.785,-218.505 l -44.163,-5.22 C 516.3,484.52 428.93,556.964 323.655,565.793 Z"
73+
id="path3430"
74+
inkscape:connector-curvature="0"
75+
style="fill:#4e9cd5" /><path
76+
d="m 495.139,286.729 50.718,5.996 C 540.62,190.885 474.163,105.401 382.887,73.064 l -6.226,51.786 c 64.614,27.213 111.504,88.661 118.478,161.879 z"
77+
id="path3432"
78+
inkscape:connector-curvature="0"
79+
style="fill:#97d0f2" /><path
80+
d="m 533.325,384.933 -51.298,-6.063 c -25.176,63.022 -81.852,109.818 -150.379,120.438 l -6.223,51.759 c 97.098,-9.346 177.611,-76.042 207.9,-166.134 z"
81+
id="path3434"
82+
inkscape:connector-curvature="0"
83+
style="fill:#97d0f2" /><path
84+
d="m 109.989,334.896 -51.226,-6.054 c 9.263,100.324 78.065,183.204 170.429,212.242 l 6.171,-51.326 C 169.678,465.56 120.608,406.57 109.989,334.896 Z"
85+
id="path3436"
86+
inkscape:connector-curvature="0"
87+
style="fill:#97d0f2" /><path
88+
d="m 67.519,236.189 50.739,5.997 C 142.221,171.604 205.005,119.21 280.902,110.953 l 6.167,-51.294 C 182.649,65.99 95.92,138.503 67.519,236.189 Z"
89+
id="path3438"
90+
inkscape:connector-curvature="0"
91+
style="fill:#97d0f2" /><path
92+
d="m 134.77,244.137 50.305,5.945 c 16.669,-35.58 48.814,-62.332 87.685,-71.393 l 6.139,-51.069 c -66.686,8.702 -121.755,54.671 -144.129,116.517 z"
93+
id="path3440"
94+
inkscape:connector-curvature="0"
95+
style="fill:#cde7f8" /><path
96+
d="m 237.37,473.073 6.142,-51.094 c -31.284,-16.041 -55.231,-44.542 -65.415,-79.032 l -51.4,-6.075 c 10.831,62.419 53.581,113.755 110.673,136.201 z"
97+
id="path3442"
98+
inkscape:connector-curvature="0"
99+
style="fill:#cde7f8" /><path
100+
d="m 465.336,376.896 -51.432,-6.078 c -16.163,28.227 -42.506,49.776 -73.968,59.529 l -6.259,52.074 c 59.304,-10.772 108.38,-51.207 131.659,-105.525 z"
101+
id="path3444"
102+
inkscape:connector-curvature="0"
103+
style="fill:#cde7f8" /><path
104+
d="m 374.63,141.744 -6.263,52.105 c 30.324,18.377 52.552,48.949 60.036,84.994 l 50.291,5.944 C 471.339,220.806 430.666,167.081 374.63,141.744 Z"
105+
id="path3446"
106+
inkscape:connector-curvature="0"
107+
style="fill:#cde7f8" /><g
108+
id="g3448"><path
109+
d="m 303.313,216.977 c -49.312,0 -89.288,40.339 -89.288,90.099 0,49.761 39.976,90.1 89.288,90.1 49.311,0 89.286,-40.339 89.286,-90.1 0,-49.76 -39.975,-90.099 -89.286,-90.099 z m 0,152.943 c -34.396,0 -62.28,-28.135 -62.28,-62.844 0,-34.708 27.884,-62.845 62.28,-62.845 34.395,0 62.276,28.137 62.276,62.845 0,34.709 -27.881,62.844 -62.276,62.844 z"
110+
id="path3450"
111+
inkscape:connector-curvature="0"
112+
style="fill:#4e9cd5" /></g><g
113+
id="g3452"><path
114+
d="m 303.312,251.207 c -30.577,0 -55.365,25.013 -55.365,55.869 0,30.855 24.789,55.869 55.365,55.869 30.577,0 55.363,-25.014 55.363,-55.869 0,-30.856 -24.786,-55.869 -55.363,-55.869 z m 0,81.034 c -13.772,0 -24.938,-11.267 -24.938,-25.165 0,-13.899 11.166,-25.165 24.938,-25.165 13.772,0 24.938,11.266 24.938,25.165 0,13.899 -11.166,25.165 -24.938,25.165 z"
115+
id="path3454"
116+
inkscape:connector-curvature="0"
117+
style="fill:#4e9cd5" /></g></g></g><text
118+
xml:space="preserve"
119+
style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
120+
x="55.681004"
121+
y="42.920197"
122+
id="text3661"
123+
sodipodi:linespacing="125%"><tspan
124+
sodipodi:role="line"
125+
id="tspan3663"
126+
x="55.681004"
127+
y="42.920197">/lobby/{{.ID}}</tspan></text>
128+
<flowRoot
129+
xml:space="preserve"
130+
id="flowRoot3665"
131+
style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
132+
transform="translate(0,-0.86897899)"><flowRegion
133+
id="flowRegion3667"><rect
134+
id="rect3669"
135+
width="328.55746"
136+
height="44.86327"
137+
x="56.738842"
138+
y="64.104706" /></flowRegion><flowPara
139+
id="flowPara3671">2123123123123</flowPara><flowPara
140+
id="flowPara3673" /></flowRoot><text
141+
xml:space="preserve"
142+
style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
143+
x="52.780315"
144+
y="89.625885"
145+
id="text3675"
146+
sodipodi:linespacing="125%"><tspan
147+
sodipodi:role="line"
148+
id="tspan3677"
149+
x="52.780315"
150+
y="89.625885">{{.MapName}}</tspan></text>
151+
</svg>
152+
</body>
153+
</html>

0 commit comments

Comments
 (0)