2021-04-02 18:53:25 +02:00
|
|
|
package connection
|
|
|
|
|
2021-04-07 16:14:15 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"strconv"
|
2021-04-02 18:53:25 +02:00
|
|
|
|
2021-04-07 16:14:15 +02:00
|
|
|
"git.fanyx.xyz/fanyx/goufy/pkg/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GbxClient struct {
|
|
|
|
conn net.Conn
|
|
|
|
reqHandle int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *GbxClient) Connect(c config.AppConfig) {
|
|
|
|
// create connection string from config
|
|
|
|
gbxConnString := c.Trackmania.Host + strconv.FormatInt(int64(c.Trackmania.Port), 10)
|
|
|
|
|
|
|
|
var err error
|
|
|
|
//initiate GbxClient
|
|
|
|
client.conn, err = net.Dial("tcp", gbxConnString)
|
2021-04-02 18:53:25 +02:00
|
|
|
if err != nil {
|
2021-04-07 16:14:15 +02:00
|
|
|
log.Fatal(err)
|
2021-04-02 18:53:25 +02:00
|
|
|
}
|
2021-04-07 16:14:15 +02:00
|
|
|
defer client.conn.Close()
|
|
|
|
|
|
|
|
// handshake
|
|
|
|
buf := make([]byte, 4)
|
|
|
|
_, err = client.conn.Read(buf)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("read content:", buf)
|
2021-04-02 18:53:25 +02:00
|
|
|
}
|