Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Add command to change handshake parameters #11

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add command to change handshake parameters
  • Loading branch information
André Hahn committed Oct 28, 2019
commit 34d7f9f28e366532824fbcaa0eb810aa5212f049
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ Pitaya REPL Client
>>> help

Commands:
clear clear the screen
connect connects to pitaya
disconnect disconnects from pitaya server
exit exit the program
help display help
notify makes a notify to pitaya server
request makes a request to pitaya server
clear clear the screen
connect connects to pitaya
disconnect disconnects from pitaya server
exit exit the program
help display help
notify makes a notify to pitaya server
push insert information of push return
request makes a request to pitaya server
sethandshake sets a handshake parameter
```

For connecting to a protobuffer server specify the documentation route with the -docs argument:
Expand All @@ -49,6 +51,17 @@ pitaya-cli -docs connector.docsHandler.docs

This example can be run with the pitaya-bot protobuffer testing example.

### Set handshake parameters

You can edit some handshake parameters before connecting to the server. The parameters are:

```
Pitaya REPL Client
>>> sethandshake platform ios
>>> sethandshake buildNumber 999
>>> sethandshake version 1.0.6
```

### Read commands from file

It's possible to add a list of sequential requests into a file and pitaya-cli will execute them in order.
Expand Down
19 changes: 19 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func connect(logger Log, addr string, onMessageCallback func([]byte)) (err error
logger.Println("Using json client")
pClient = client.New(logrus.InfoLevel)
}
pClient.SetClientHandshakeData(handshake)

if err != nil {
return err
Expand All @@ -57,6 +58,24 @@ func connect(logger Log, addr string, onMessageCallback func([]byte)) (err error
return nil
}

func setHandshake(logger Log, args []string) error {
if len(args) != 2 {
return errors.New("invalid number of arguments, expected 2")
}
if args[0] != "version" && args[0] != "platform" && args[0] != "buildNumber" {
return errors.New("invalid argument to sethandshake, expected version, platform or buildNumber")
}
switch arg := args[0]; arg {
case "version":
handshake.Sys.Version = args[1]
case "platform":
handshake.Sys.Platform = args[1]
case "buildNumber":
handshake.Sys.BuildNumber = args[1]
}
return nil
}

func push(logger Log, args []string) error {
if pClient != nil {
return errors.New("use this command before connect")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ require (
github.com/sirupsen/logrus v1.0.6
github.com/spf13/afero v1.1.1 // indirect
github.com/spf13/pflag v1.0.1 // indirect
github.com/topfreegames/pitaya v0.16.0
github.com/topfreegames/pitaya v0.16.1
gopkg.in/abiosoft/ishell.v2 v2.0.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 h1:lYIiVD
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/topfreegames/go-workers v1.0.0 h1:R53uIT6nwlT45WBm79ZDnxG8W2ec9lJk3uJhZUmd3GI=
github.com/topfreegames/go-workers v1.0.0/go.mod h1:FZ45GKJrHNIChLw008zoR8lvoMTxK9RprdE2c3uLrCQ=
github.com/topfreegames/pitaya v0.16.0 h1:A2NP1T4GajlNw7ZAn0oQTeDfQyS9b1r5Ds5y1wfEPqo=
github.com/topfreegames/pitaya v0.16.0/go.mod h1:2UaEoglDroRu3YvM4tF5PMV2UCqVyh/UTVFc6biFCDk=
github.com/topfreegames/pitaya v0.16.1 h1:RNnR3HGFm5At/pVIrjA8sGU0HgnjIn0+afeEpwJA8Lw=
github.com/topfreegames/pitaya v0.16.1/go.mod h1:2UaEoglDroRu3YvM4tF5PMV2UCqVyh/UTVFc6biFCDk=
github.com/uber-go/atomic v1.3.2 h1:Azu9lPBWRNKzYXSIwRfgRuDuS0YKsK4NFhiQv98gkxo=
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
github.com/uber/jaeger-client-go v2.13.0+incompatible h1:BQ7GxyS54wK+5kfRNoMVOhgQ7VAjhYlFq4rAhV7pnHc=
Expand Down
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sync"

"github.com/topfreegames/pitaya/client"
"github.com/topfreegames/pitaya/session"
)

var (
Expand All @@ -35,13 +36,25 @@ var (
pushInfo map[string]string
wait sync.WaitGroup
prettyJSON bool
handshake *session.HandshakeData
)

func main() {
flag.StringVar(&docsString, "docs", "", "documentation route")
flag.StringVar(&fileName, "filename", "", "file with commands")
flag.BoolVar(&prettyJSON, "pretty", false, "print pretty jsons")
flag.Parse()
handshake = &session.HandshakeData{
Sys: session.HandshakeClientData{
Platform: "mac",
LibVersion: "0.3.5-release",
BuildNumber: "20",
Version: "1.0.0",
},
User: map[string]interface{}{
"age": 30,
},
}

switch {
case fileName != "":
Expand Down
14 changes: 14 additions & 0 deletions shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func repl() {
registerRequest(shell)
registerNotify(shell)
registerPush(shell)
registerSetHandshake(shell)

pushInfo = make(map[string]string)

Expand Down Expand Up @@ -111,3 +112,16 @@ func registerDisconnect(shell *ishell.Shell) {
},
})
}

func registerSetHandshake(shell *ishell.Shell) {
shell.AddCmd(&ishell.Cmd{
Name: "sethandshake",
Help: "sets a handshake parameter",
Func: func(c *ishell.Context) {
err := setHandshake(c, c.Args)
if err != nil {
c.Err(err)
}
},
})
}