hermeticum/client/cmd/main.go

93 lines
2.3 KiB
Go
Raw Normal View History

2022-07-07 22:12:22 +00:00
package main
import (
2022-07-08 04:07:34 +00:00
"context"
"errors"
"flag"
2022-07-07 22:12:22 +00:00
"fmt"
"log"
2022-07-08 04:07:34 +00:00
"time"
2022-07-08 05:18:52 +00:00
"github.com/rivo/tview"
2022-07-08 04:07:34 +00:00
"github.com/vilmibm/hermeticum/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
var (
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
caFile = flag.String("ca_file", "", "The file containing the CA root cert file")
serverAddr = flag.String("addr", "localhost:6666", "The server address in the format of host:port")
serverHostOverride = flag.String("server_host_override", "x.test.example.com", "The server name used to verify the hostname returned by the TLS handshake")
2022-07-07 22:12:22 +00:00
)
func _main() error {
2022-07-08 04:07:34 +00:00
var opts []grpc.DialOption
if *tls {
return errors.New("TODO tls unsupported")
/*
if *caFile == "" {
*caFile = data.Path("x509/ca_cert.pem")
}
creds, err := credentials.NewClientTLSFromFile(*caFile, *serverHostOverride)
if err != nil {
log.Fatalf("Failed to create TLS credentials %v", err)
}
opts = append(opts, grpc.WithTransportCredentials(creds))
*/
} else {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
conn, err := grpc.Dial(*serverAddr, opts...)
if err != nil {
return fmt.Errorf("fail to dial: %w", err)
}
defer conn.Close()
client := proto.NewGameWorldClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
pong, err := client.Ping(ctx, &proto.SessionInfo{})
if err != nil {
log.Fatalf("%v.Ping -> %v", client, err)
}
2022-07-07 22:12:22 +00:00
2022-07-08 04:07:34 +00:00
log.Printf("%#v", pong)
2022-07-07 22:12:22 +00:00
2022-07-08 05:18:52 +00:00
app := tview.NewApplication()
pages := tview.NewPages()
pages.AddPage("splash",
tview.NewModal().
AddButtons([]string{"hey. let's go"}).
SetDoneFunc(func(_ int, _ string) {
pages.SwitchToPage("main")
}).SetText("h e r m e t i c u m"),
false,
true)
mainPage := tview.NewList().
AddItem("jack in", "connect using an existing account", '1', nil).
AddItem("rez a toon", "create a new account", '2', nil).
AddItem("open the hood", "client configuration", '3', nil).
AddItem("get outta here", "quit the client", '4', func() {
app.Stop()
})
mainPage.SetRect(0, 0, 100, 100)
pages.AddPage("main", mainPage, false, false)
return app.SetRoot(pages, true).SetFocus(pages).Run()
2022-07-07 22:12:22 +00:00
}
func main() {
err := _main()
if err != nil {
log.Fatal(err.Error())
}
}