Skip to content

Commit 9e297ee

Browse files
committed
goop: Add Goop (GO OPerator), a BNCS/Discord Channel Operator
* Supports connecting to multiple realms simulateously * Supports BNCS, Discord, stdin * Supports relaying chat between realms * Automatically reconnect on disconnect
1 parent e047b32 commit 9e297ee

File tree

30 files changed

+1483
-133
lines changed

30 files changed

+1483
-133
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bin/
2+
3+
# Config files
4+
config.toml
5+
6+
# Test binary (go test -c)
7+
*.test
8+
9+
# Output of the go coverage tool
10+
*.out

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@
2525
[submodule "vendor/github.com/fatih/color"]
2626
path = vendor/github.com/fatih/color
2727
url = https://github.com/fatih/color.git
28+
[submodule "vendor/github.com/imdario/mergo"]
29+
path = vendor/github.com/imdario/mergo
30+
url = https://github.com/imdario/mergo.git
31+
[submodule "vendor/github.com/bwmarrin/discordgo"]
32+
path = vendor/github.com/bwmarrin/discordgo
33+
url = https://github.com/bwmarrin/discordgo.git
34+
[submodule "vendor/github.com/gorilla/websocket"]
35+
path = vendor/github.com/gorilla/websocket
36+
url = https://github.com/gorilla/websocket.git

Makefile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
# Project: gowarcraft3 (https://github.com/nielsAD/gowarcraft3)
33
# License: Mozilla Public License, v2.0
44

5+
VENDOR=vendor/StormLib/build/libstorm.a vendor/bncsutil/build/libbncsutil_static.a
6+
57
GO_FLAGS=
68
GOTEST_FLAGS=-cover -cpu=1,2,4 -timeout=2m
79

810
GO=go
911
GOFMT=gofmt
10-
GOLINT=golint
12+
GOLINT=$(shell go env GOPATH)/bin/golint
1113

1214
DIR_BIN=bin
15+
DIR_PRE=github.com/nielsAD/gowarcraft3
16+
1317
PKG:=$(shell $(GO) list ./...)
14-
DIR:=$(subst github.com/nielsAD/gowarcraft3/,,$(PKG))
18+
DIR:=$(subst $(DIR_PRE)/,,$(PKG))
19+
CMD:=$(subst $(DIR_PRE)/cmd/,,$(shell $(GO) list ./cmd/...))
1520

1621
ARCH:=$(shell $(GO) env GOARCH)
1722
ifeq ($(ARCH),amd64)
@@ -22,22 +27,27 @@ ifeq ($(TEST_RACE),1)
2227
TEST_FLAGS+= -race
2328
endif
2429

25-
.PHONY: all release build test fmt lint vet list clean
30+
.PHONY: all release check test fmt lint vet list clean
31+
2632
all: test release
33+
release: $(CMD)
2734

2835
$(DIR_BIN):
2936
mkdir -p $@
3037

38+
$(PKG): $(VENDOR)
39+
$(GO) build $@
40+
41+
$(CMD): $(VENDOR) $(DIR_BIN)
42+
cd $(DIR_BIN); $(GO) build $(GO_FLAGS) $(DIR_PRE)/cmd/$@
43+
3144
vendor/%:
3245
$(MAKE) -C vendor $(subst vendor/,,$@)
3346

34-
release: build $(DIR_BIN)
35-
cd $(DIR_BIN); $(GO) list ../cmd/... | xargs -L1 go build $(GO_FLAGS)
36-
37-
build: vendor/StormLib/build/libstorm.a vendor/bncsutil/build/libbncsutil_static.a
47+
check: $(VENDOR)
3848
$(GO) build $(PKG)
3949

40-
test: build fmt lint vet
50+
test: check fmt lint vet
4151
$(GO) test $(TEST_FLAGS) $(PKG)
4252

4353
fmt:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Tools
1212

1313
| Name | Description |
1414
|------------------------------|-------------|
15+
| [goop](./cmd/goop) |Goop (GO OPerator) is a BNCS Channel Operator that can act as a bridge between Battle.net realms and Discord.|
1516
|[bncsclient](./cmd/bncsclient)|A mocked Warcraft III chat client that can be used to connect to BNCS servers.|
1617
|[w3gsclient](./cmd/w3gsclient)|A mocked Warcraft III game client that can be used to add dummy players to games.|
1718
| [bncsdump](./cmd/bncsdump) |A tool that decodes and dumps BNCS packets via pcap (on the wire or from a file).|

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ deploy:
5454
provider: GitHub
5555
auth_token:
5656
secure: wDwXLoUDnL32TSi+DpnwB4o+8LitFI6eIoyOqjm6//LiGMBMpkLiu/PaIZdCw4G/
57-
artifact: /release.*/
57+
artifact: /release_.*/
5858
on:
5959
appveyor_repo_tag: true

cmd/bncsclient/main.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,37 @@ var stdin = bufio.NewReader(os.Stdin)
4040
func main() {
4141
flag.Parse()
4242

43-
var c = bnet.NewClient(*binpath)
43+
c, err := bnet.NewClient(&bnet.Config{BinPath: *binpath})
44+
if err != nil {
45+
logErr.Fatal("NewClient error: ", err)
46+
}
4447

4548
c.ServerAddr = strings.Join(flag.Args(), " ")
4649
if c.ServerAddr == "" {
4750
c.ServerAddr = "uswest.battle.net:6112"
4851
}
4952

5053
if *gamevers != 0 {
51-
c.AuthInfo.GameVersion.Version = uint32(*gamevers)
54+
c.GameVersion.Version = uint32(*gamevers)
5255
}
5356

5457
if *keyroc != "" {
5558
if *keytft != "" {
56-
c.AuthInfo.GameVersion.Product = w3gs.ProductTFT
59+
c.GameVersion.Product = w3gs.ProductTFT
5760
c.CDKeys = []string{*keyroc, *keytft}
5861
} else {
59-
c.AuthInfo.GameVersion.Product = w3gs.ProductROC
62+
c.GameVersion.Product = w3gs.ProductROC
6063
c.CDKeys = []string{*keyroc}
6164
}
6265
}
6366

64-
c.UserName = *username
67+
c.Username = *username
6568
c.Password = *password
6669

6770
if *username == "" {
6871
fmt.Print("Enter username: ")
69-
c.UserName, _ = stdin.ReadString('\n')
70-
c.UserName = strings.TrimSpace(c.UserName)
72+
c.Username, _ = stdin.ReadString('\n')
73+
c.Username = strings.TrimSpace(c.Username)
7174
}
7275

7376
if *password == "" {
@@ -102,7 +105,7 @@ func main() {
102105
})
103106
c.On(&bnet.Whisper{}, func(ev *network.Event) {
104107
var msg = ev.Arg.(*bnet.Whisper)
105-
logOut.Println(color.GreenString("[WHISPER] %s: %s", msg.UserName, msg.Content))
108+
logOut.Println(color.GreenString("[WHISPER] %s: %s", msg.Username, msg.Content))
106109
})
107110
c.On(&bnet.Chat{}, func(ev *network.Event) {
108111
var msg = ev.Arg.(*bnet.Chat)
@@ -114,7 +117,7 @@ func main() {
114117
logOut.Printf("[CHAT] %s\n", say.Content)
115118
} else {
116119

117-
logOut.Printf("[CHAT] %s: %s\n", c.UserName, say.Content)
120+
logOut.Printf("[CHAT] %s: %s\n", c.Username, say.Content)
118121
}
119122
})
120123
c.On(&bnet.SystemMessage{}, func(ev *network.Event) {
@@ -129,15 +132,15 @@ func main() {
129132
if err := c.CreateAccount(); err != nil {
130133
logErr.Fatal("CreateAccount error: ", err)
131134
}
132-
logOut.Println(color.MagentaString("Succesfully registered new account '%s'", c.UserName))
135+
logOut.Println(color.MagentaString("Succesfully registered new account '%s'", c.Username))
133136
return
134137
}
135138

136139
if err := c.Logon(); err != nil {
137140
logErr.Fatal("Logon error: ", err)
138141
}
139142

140-
logOut.Println(color.MagentaString("Succesfully logged onto %s@%s", c.UserName, c.ServerAddr))
143+
logOut.Println(color.MagentaString("Succesfully logged onto %s@%s", c.Username, c.ServerAddr))
141144

142145
go func() {
143146
for {

cmd/bncsdump/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ func main() {
207207

208208
go func() {
209209
for packet := range packets {
210-
trans := packet.TransportLayer().(*layers.TCP)
210+
trans, ok := packet.TransportLayer().(*layers.TCP)
211+
if !ok {
212+
continue
213+
}
214+
211215
asm.Assemble(packet.NetworkLayer().NetworkFlow(), trans)
212216
}
213217
}()

cmd/goop/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
GoWarcraft3/goop
2+
===========
3+
[![Build Status](https://travis-ci.org/nielsAD/gowarcraft3.svg?branch=master)](https://travis-ci.org/nielsAD/gowarcraft3)
4+
[![Build status](https://ci.appveyor.com/api/projects/status/a5cecrpfo0pe14ux/branch/master?svg=true)](https://ci.appveyor.com/project/nielsAD/gowarcraft3)
5+
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
6+
7+
Goop (GO OPerator) is a BNCS Channel Operator.
8+
9+
Usage
10+
-----
11+
12+
`./goop [config_file]`
13+
14+
Configuration
15+
-------------
16+
See [`config.toml.example`](/cmd/goop/config.toml.example).
17+
18+
19+
Download
20+
--------
21+
22+
Official binaries for tools are [available](https://github.com/nielsAD/gowarcraft3/releases/latest). Simply download and run.
23+
24+
_Note: additional dependencies may be required (see [build instructions](/README.md#build))._

0 commit comments

Comments
 (0)