starting sqlite rewrite
- adding db connector - starting rewrite of commands - WIP
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"code.jakeyoungdev.com/jake/mctl/cryptography"
|
||||
"code.jakeyoungdev.com/jake/mctl/database"
|
||||
"github.com/jake-young-dev/mcr"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -23,22 +23,25 @@ type IClient interface {
|
||||
}
|
||||
|
||||
// creates a new mcr client using saved credentials and decrypted password
|
||||
func New() (*Client, error) {
|
||||
//grab saved credentials
|
||||
server := viper.Get("server").(string)
|
||||
password := viper.Get("password").(string)
|
||||
port := viper.Get("port").(int)
|
||||
fmt.Printf("Logging into %s on port %d\n", server, port)
|
||||
|
||||
//decrypt password
|
||||
pt, err := cryptography.DecryptPassword([]byte(password))
|
||||
func New(name string) (*Client, error) {
|
||||
db, err := database.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
srv, err := db.GetServer(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Printf("Logging into %s on port %d\n", srv.Server, srv.Port)
|
||||
|
||||
var p []byte
|
||||
_, err = base64.StdEncoding.Decode(p, []byte(srv.Password))
|
||||
|
||||
//connect to game server
|
||||
cli := mcr.NewClient(server, mcr.WithPort(port))
|
||||
err = cli.Connect(string(pt))
|
||||
cli := mcr.NewClient(srv.Server, mcr.WithPort(srv.Port))
|
||||
err = cli.Connect(string(p))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user