-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19abedb
commit 2ced635
Showing
4 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
go 1.13 | ||
|
||
require ( | ||
github.com/googollee/go-socket.io v1.4.4 | ||
github.com/gorilla/websocket v1.4.1 | ||
layeh.com/gumble v0.0.0-20200818122324-146f9205029b | ||
) | ||
|
||
module amongusmumble |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/dchote/go-openal v0.0.0-20171116030048-f4a9a141d372/go.mod h1:74z+CYu2/mx4N+mcIS/rsvfAxBPBV9uv8zRAnwyFkdI= | ||
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= | ||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||
github.com/googollee/go-socket.io v1.4.4 h1:UWOy//wzcT1ENMDeeVsrXwcCY49XOvC/YHVMZJDfy9M= | ||
github.com/googollee/go-socket.io v1.4.4/go.mod h1:2lMkHRm5GLg158lACi6Zj6535AQaXuyA+IKbfqKzTOM= | ||
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= | ||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | ||
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= | ||
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= | ||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= | ||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= | ||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= | ||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= | ||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
layeh.com/gopus v0.0.0-20161224163843-0ebf989153aa/go.mod h1:AOef7vHz0+v4sWwJnr0jSyHiX/1NgsMoaxl+rEPz/I0= | ||
layeh.com/gumble v0.0.0-20200818122324-146f9205029b h1:Kne6wkHqbqrygRsqs5XUNhSs84DFG5TYMeCkCbM56sY= | ||
layeh.com/gumble v0.0.0-20200818122324-146f9205029b/go.mod h1:tWPVA9ZAfImNwabjcd9uDE+Mtz0Hfs7a7G3vxrnrwyc= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package main | ||
|
||
import ( | ||
"amongusmumble/mumble" | ||
"crypto/tls" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
socketio "github.com/googollee/go-socket.io" | ||
"layeh.com/gumble/gumble" | ||
"layeh.com/gumble/gumbleutil" | ||
) | ||
|
||
const ( | ||
// See http://golang.org/pkg/time/#Parse | ||
timeFormat = "2006-01-02 15:04 MST" | ||
) | ||
|
||
var deadplayers []string | ||
var gamestate string | ||
var gameup bool | ||
var gamestatetime time.Time | ||
|
||
type Player struct { | ||
//Action PlayerAction `json:"Action"` | ||
Name string `json:"Name"` | ||
Color int `json:"Color"` | ||
IsDead bool `json:"IsDead"` | ||
Disconnected bool `json:"Disconnected"` | ||
} | ||
|
||
func socketioServer(client *gumble.Client) { | ||
server, err := socketio.NewServer(nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
server.OnConnect("/", func(s socketio.Conn) error { | ||
s.SetContext("") | ||
log.Println("connected:", s.ID()) | ||
return nil | ||
}) | ||
|
||
server.OnEvent("/", "connect", func(s socketio.Conn, msg string) { | ||
log.Println("set connect code:", msg) | ||
s.Emit("reply", "set guildID successfully") | ||
}) | ||
server.OnEvent("/", "state", func(s socketio.Conn, msg string) { | ||
log.Println("Phase received from capture: ", msg) | ||
|
||
switch msg { | ||
case "0": | ||
gamestate = "LOBBY" | ||
case "1": | ||
gamestate = "TASKS" | ||
case "2": | ||
gamestate = "DISCUSSION" | ||
} | ||
log.Println("Gamestate set:", gamestate) | ||
switch gamestate { | ||
case "MENU": | ||
log.Println("Gamemode: Menu") | ||
//mumble.Endgame(client) | ||
deadplayers = nil | ||
gameup = false | ||
case "LOBBY": | ||
log.Println("Gamemode: LOBBY") | ||
//mumble.Endgame(client) | ||
deadplayers = nil | ||
gameup = false | ||
case "DISCUSSION": | ||
log.Println("Gamemode: DISCUSSION") | ||
//mumble.Meeting(client, deadplayers) | ||
case "TASKS": | ||
log.Println("Gamemode: TASKS") | ||
gamestatetime = time.Now() | ||
log.Println("Game State Time:", gamestatetime) | ||
time.Sleep(5 * time.Second) | ||
if gameup == false { | ||
mumble.Startgame(client) | ||
} else { | ||
mumble.Resumegame(client, deadplayers) | ||
} | ||
gameup = true | ||
} | ||
}) | ||
server.OnEvent("/", "player", func(s socketio.Conn, msg string) { | ||
log.Println("Player received from capture: ", msg) | ||
log.Println("Gamestate: ", gamestate) | ||
player := Player{} | ||
_ = json.Unmarshal([]byte(msg), &player) | ||
|
||
if gamestate == "LOBBY" { | ||
mumble.Namecheck(client, strings.TrimSpace(player.Name)) | ||
} else { | ||
if player.IsDead == true { | ||
deadplayers = mumble.Kill(client, strings.TrimSpace(player.Name), gamestate, deadplayers) | ||
duration := time.Since(gamestatetime) | ||
if duration.Seconds() < 10 { | ||
log.Println("Move", player.Name, "to Dead now") | ||
dead := client.Channels.Find("AmongUs", "Dead") | ||
user := client.Users.Find(player.Name) | ||
user.Move(dead) | ||
user.SetMuted(false) | ||
user.SetDeafened(false) | ||
} else { | ||
log.Println("Move", player.Name, "to Dead at end of round") | ||
} | ||
} | ||
} | ||
}) | ||
|
||
server.OnError("/", func(s socketio.Conn, e error) { | ||
log.Println("meet error:", e) | ||
}) | ||
|
||
server.OnDisconnect("/", func(s socketio.Conn, reason string) { | ||
log.Println("closed", reason) | ||
}) | ||
|
||
go server.Serve() | ||
defer server.Close() | ||
|
||
http.Handle("/socket.io/", server) | ||
log.Println("Serving at localhost:8123...") | ||
log.Fatal(http.ListenAndServe("0.0.0.0:8123", nil)) | ||
} | ||
|
||
func main() { | ||
var tlsConfig tls.Config | ||
|
||
tlsConfig.InsecureSkipVerify = true | ||
server := flag.String("server", "sg.whysomadtho.com:64738", "address of the server") | ||
config := gumble.NewConfig() | ||
config.Username = "6ix9ine" | ||
certificateFile := "6ix9ine.crt" | ||
keyFile := "6ix9ine.key" | ||
if certificateFile != "" { | ||
if keyFile == "" { | ||
keyFile = certificateFile | ||
} | ||
if certificate, err := tls.LoadX509KeyPair(certificateFile, keyFile); err != nil { | ||
fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err) | ||
os.Exit(1) | ||
} else { | ||
tlsConfig.Certificates = append(tlsConfig.Certificates, certificate) | ||
} | ||
} | ||
keepAlive := make(chan bool) | ||
exitStatus := 0 | ||
config.Attach(gumbleutil.Listener{ | ||
Disconnect: func(e *gumble.DisconnectEvent) { | ||
if e.Type != gumble.DisconnectUser { | ||
exitStatus = int(e.Type) + 1 | ||
} | ||
keepAlive <- true | ||
}, | ||
}) | ||
client, err := gumble.DialWithDialer(new(net.Dialer), *server, config, &tlsConfig) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "%s\n", err) | ||
if reject, ok := err.(*gumble.RejectError); ok { | ||
os.Exit(100 + int(reject.Type)) | ||
} | ||
os.Exit(99) | ||
} | ||
|
||
go socketioServer(client) | ||
|
||
<-keepAlive | ||
os.Exit(exitStatus) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package mumble | ||
|
||
import ( | ||
"layeh.com/gumble/gumble" | ||
"log" | ||
"strings" | ||
) | ||
|
||
|
||
func Kill(c *gumble.Client,player string,gamestate string,deadplayers []string) []string { | ||
alive := c.Channels.Find("AmongUs","Alive") | ||
|
||
log.Println("In game player:", player) | ||
aliveusers := c.Channels[alive.ID].Users | ||
var player2 string | ||
for _, element := range aliveusers { | ||
if element.Comment == player { | ||
player2 = strings.TrimSpace(element.Name) | ||
log.Println("Mumble user:",player2) | ||
} | ||
} | ||
|
||
duplicateplayer := 0 | ||
|
||
for _, s := range deadplayers { | ||
if s == player2 { | ||
duplicateplayer = duplicateplayer + 1 | ||
} | ||
} | ||
if duplicateplayer == 0 { | ||
deadplayers = append(deadplayers, strings.TrimSpace(player2)) | ||
log.Println(player2,"is now dead") | ||
} else { | ||
log.Println(player2, "is already dead") | ||
} | ||
|
||
log.Println("Dead Players:", deadplayers) | ||
return deadplayers | ||
} | ||
|
||
func Startgame(c *gumble.Client) { | ||
lobby := c.Channels.Find("AmongUs","Lobby") | ||
alive := c.Channels.Find("AmongUs","Alive") | ||
lobbyusers := c.Channels[lobby.ID].Users | ||
for _, element := range lobbyusers { | ||
element.Move(alive) | ||
element.SetMuted(true) | ||
element.SetDeafened(true) | ||
log.Println("Moving",element.Name,"to #alive") | ||
} | ||
} | ||
|
||
func Meeting(c *gumble.Client,deadplayers []string) { | ||
alive := c.Channels.Find("AmongUs","Alive") | ||
aliveusers := c.Channels[alive.ID].Users | ||
|
||
for _, element := range aliveusers { | ||
log.Println("Unmute player",element.Name) | ||
element.SetMuted(false) | ||
element.SetDeafened(false) | ||
log.Println(element.Name,"is alive") | ||
} | ||
|
||
for _,deadplayer := range deadplayers { | ||
user := c.Users.Find(deadplayer) | ||
log.Println("Mute player",user.Name) | ||
user.SetMuted(true) | ||
user.SetDeafened(false) | ||
user.Move(alive) | ||
log.Println(user.Name,"is dead") | ||
} | ||
} | ||
|
||
func Resumegame(c *gumble.Client,deadplayers []string) { | ||
alive := c.Channels.Find("AmongUs","Alive") | ||
dead := c.Channels.Find("AmongUs","Dead") | ||
|
||
aliveusers := c.Channels[alive.ID].Users | ||
|
||
log.Println("Resuming game") | ||
|
||
for _, element := range aliveusers { | ||
log.Println("Mute player",element.Name) | ||
element.SetMuted(true) | ||
element.SetDeafened(true) | ||
log.Println(element.Name,"is alive") | ||
} | ||
|
||
for _,deadplayer := range deadplayers { | ||
user := c.Users.Find(deadplayer) | ||
log.Println("Unmute player",user.Name) | ||
user.SetMuted(false) | ||
user.SetDeafened(false) | ||
user.Move(dead) | ||
log.Println(user.Name,"is dead") | ||
} | ||
} | ||
|
||
func Endgame(c *gumble.Client) { | ||
lobby := c.Channels.Find("AmongUs","Lobby") | ||
alive := c.Channels.Find("AmongUs","Alive") | ||
dead := c.Channels.Find("AmongUs","Dead") | ||
|
||
aliveusers := c.Channels[alive.ID].Users | ||
deadusers := c.Channels[dead.ID].Users | ||
|
||
for _, element := range aliveusers { | ||
element.Move(lobby) | ||
element.SetMuted(false) | ||
element.SetDeafened(false) | ||
log.Println("Unmute player",element.Name) | ||
} | ||
|
||
for _, element := range deadusers { | ||
element.Move(lobby) | ||
element.SetMuted(false) | ||
element.SetDeafened(false) | ||
log.Println("Unmute player",element.Name) | ||
} | ||
} | ||
|
||
func Namecheck (c *gumble.Client, player string) { | ||
var player2 string | ||
|
||
lobby := c.Channels.Find("AmongUs","Lobby") | ||
lobbyusers := c.Channels[lobby.ID].Users | ||
|
||
log.Println("Checking if",player,"has a mumble user set") | ||
for _, element := range lobbyusers { | ||
if element.Comment == player { | ||
player2 = element.Name | ||
log.Println("User set:",player2,"==",player) | ||
return | ||
} | ||
} | ||
log.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") | ||
log.Println("Player",player,"does not have a mumble user set.") | ||
log.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") | ||
} |