Skip to content

Commit

Permalink
Merge branch 'master' into documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
OperationalDev authored Oct 11, 2020
2 parents 6064be8 + b9b8217 commit 3aebade
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 169 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# Config files
config
config.yaml
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
### New Features
- Allow passing botname, cert, key, server as parameters.


## v0.1.0
- Initial Release
6 changes: 6 additions & 0 deletions config.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cert: "certname.crt"
key: "cername.key"
listenaddress: "0.0.0.0"
listenport: "8123"
mumbleserver: "mymumbleserver.com:64738"
username: "botname"
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ go 1.13

require (
github.com/googollee/go-socket.io v1.4.4
github.com/gorilla/websocket v1.4.1
github.com/gorilla/websocket v1.4.2
github.com/spf13/viper v1.7.1
layeh.com/gumble v0.0.0-20200818122324-146f9205029b
)

Expand Down
285 changes: 285 additions & 0 deletions go.sum

Large diffs are not rendered by default.

142 changes: 23 additions & 119 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,140 +1,44 @@
package main

import (
"amongusmumble/mumble"
"amongusmumble/socket"
"crypto/tls"
"encoding/json"
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"strings"
"time"

socketio "github.com/googollee/go-socket.io"
"github.com/spf13/viper"
"layeh.com/gumble/gumble"
"layeh.com/gumble/gumbleutil"
)

var deadplayers []string
var gamestate string
var gameup bool
var gamestatetime time.Time

type Player struct {
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
})
func main() {
var tlsConfig tls.Config

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)
tlsConfig.InsecureSkipVerify = true

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)
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")

if gamestate == "LOBBY" {
mumble.Namecheck(client, strings.TrimSpace(player.Name))
if err := viper.ReadInConfig(); err != nil {
if err, ok := err.(viper.ConfigFileNotFoundError); ok {
fmt.Println("Cannot Find Config file")
os.Exit(3)
} 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")
}
}
fmt.Println("error loading config", err)
}
})

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))
}
server := viper.GetString("mumbleserver")
listenaddress := viper.GetString("listenaddress")
listenport := viper.GetString("listenport")

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"
config.Username = viper.GetString("username")
certificateFile := viper.GetString("cert")
keyFile := viper.GetString("key")

if certificateFile != "" {
if keyFile == "" {
keyFile = certificateFile
Expand All @@ -156,7 +60,7 @@ func main() {
keepAlive <- true
},
})
client, err := gumble.DialWithDialer(new(net.Dialer), *server, config, &tlsConfig)
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 {
Expand All @@ -165,7 +69,7 @@ func main() {
os.Exit(99)
}

go socketioServer(client)
go socket.SocketioServer(client, listenaddress, listenport)

<-keepAlive
os.Exit(exitStatus)
Expand Down
Loading

0 comments on commit 3aebade

Please sign in to comment.