Skip to content
Snippets Groups Projects
Verified Commit 9746d04b authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

it works when Impostor works, i guess

parent 11fc28a9
Branches master
No related tags found
No related merge requests found
.idea
app
FROM archlinux:latest
WORKDIR /app
ADD . /app
RUN pacman -Syu go dotnet-sdk make base-devel --needed --noconfirm && make
EXPOSE 8080
ENTRYPOINT ["/app/app"]
\ No newline at end of file
all:
echo Hi
all: impostor golang
echo Done.
impostor:
bash -c "cd Impostor/client; dotnet build"
golang:
go build -o app
\ No newline at end of file
go.mod 0 → 100644
package main
import (
"git.sch.bme.hu/mikewashere/sus/mattermost"
"net/http"
)
// 3ugf3tmipjdj7g34yg1owqkaea
func main() {
//http.ListenAndServe(":8080", )
e := http.ListenAndServe(":8080", http.HandlerFunc(mattermost.Handler))
if e != nil {
panic(e)
}
}
package mattermost
import "net/http"
import (
"encoding/json"
"fmt"
"git.sch.bme.hu/mikewashere/sus/wrapper"
"net/http"
"strings"
"time"
)
type respType string
const (
InChannel respType = "in_channel"
Ephemeral respType = "ephemeral"
)
type resp struct {
ResponseType respType `json:"response_type"`
Text string `json:"text"`
}
func syntaxError(w http.ResponseWriter) {
w.Header().Add("Content-Type", "application/json")
by, _ := json.Marshal(resp{
ResponseType: InChannel,
Text: "syntax error",
})
_, _ = w.Write(by)
}
func Handler(w http.ResponseWriter, r *http.Request) {
e := r.ParseForm()
if e != nil {
syntaxError(w)
return
}
txt := r.Form.Get("text")
if txt == "" {
syntaxError(w)
}
s := strings.Split(txt, " ")
room := s[0]
region := "EU"
if len(s) >= 2 && s[1] != "" {
region = s[1]
}
room = strings.ToUpper(room)
region = strings.ToUpper(region)
if wrapper.ExistsRoom(room) {
go wrapper.CheckRoom(room, wrapper.GetRegion(region))
}
time.Sleep(5 * time.Second)
w.Header().Add("Content-Type", "application/json")
_, _ = w.Write([]byte(`{
"response_type": "in_channel",
"text": "i'm alive"
}`))
state := wrapper.GetLastRoomState(room)
response := ""
if state.Data != nil {
response = fmt.Sprintf(`Csatlakozz ide: %s (%s)
jelenleg játszik:
'`, room, region)
for _, b := range state.Data {
response += fmt.Sprintf("* %s (%s)\n", b.Name, b.Color.Emoji())
}
} else {
response = "error"
}
by, _ := json.Marshal(resp{
ResponseType: Ephemeral,
Text: response,
})
_, _ = w.Write(by)
}
package wrapper
import (
"bufio"
"encoding/json"
"fmt"
"os/exec"
"time"
)
var rooms = make(map[string]Data)
func CheckRoom(room string, region Region) {
if len(room) != 6 {
return
}
cmd := exec.Command("./Impostor/client/bin/Debug/netcoreapp3.1/client", string(region), room)
out, e := cmd.StdoutPipe()
if e != nil {
fmt.Println(e)
return
}
scan := bufio.NewScanner(out)
go func() {
for scan.Scan() {
d := Data{}
by := scan.Bytes()
fmt.Println(string(by))
e = json.Unmarshal(by, &d)
if e != nil {
fmt.Println(e)
continue
}
rooms[room] = d
}
}()
time.Sleep(time.Second)
if err := cmd.Start(); err != nil {
fmt.Println(err)
}
time.Sleep(time.Second)
if err := cmd.Wait(); err != nil {
fmt.Println(err)
}
delete(rooms, room)
}
func ExistsRoom(room string) bool {
_, ok := rooms[room]
return ok
}
func GetLastRoomState(room string) Data {
return rooms[room]
}
package wrapper
type Type string
const (
GameData Type = "gameData"
Connect Type = "connect"
Disconnect Type = "disconnect"
Error Type = "error"
)
type Color int
const (
Red Color = iota
Blue
Green
Pink
Orange
Yellow
Black
White
Purple
Brown
Cyan
Lime
)
func (c *Color) Emoji() string {
switch *c {
case Red:
return "\U0001F7E5"
case Blue:
return "\U0001F7E6"
case Green:
return "\U0001F7E9"
case Pink:
return "\U0001F9A9"
case Orange:
return "\U0001F7E7"
case Yellow:
return "\U0001F7E8"
case Black:
return "⬛"
case White:
return "⬜"
case Purple:
return "\U0001F7EA"
case Brown:
return "\U0001F7EB"
case Cyan:
return "🐦"
case Lime:
return "🍐"
}
return ""
}
type Boi struct {
Name string
Color Color
}
type Data struct {
Type Type
Data []Boi
Message string
}
package wrapper
type Region string
const EU Region = "172.105.251.170"
const US Region = "198.58.99.71"
const ASIA Region = "139.162.111.196"
func GetRegion(region string) Region {
switch region {
case "US":
return US
case "ASIA":
return ASIA
default:
return EU
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment