mirror of
https://github.com/hamburghammer/rcon.git
synced 2024-12-23 16:27:40 +01:00
Compare commits
3 commits
7830bfeaa5
...
3e2320a5f4
Author | SHA1 | Date | |
---|---|---|---|
3e2320a5f4 | |||
447d07372b | |||
9994b2e641 |
2 changed files with 23 additions and 11 deletions
12
README.md
12
README.md
|
@ -8,22 +8,24 @@ This is a fork from [james4k/rcon](https://github.com/james4k/rcon) with the sup
|
||||||
// Establish a connection.
|
// Establish a connection.
|
||||||
remoteConsole, err := rcon.Dial("127.0.0.1", "password")
|
remoteConsole, err := rcon.Dial("127.0.0.1", "password")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
// Close the connection at the end to free the used resources.
|
||||||
|
defer remoteConsole.Close()
|
||||||
|
|
||||||
// Send a command.
|
// Send a command.
|
||||||
requestID, err := remoteConsole.Write("command")
|
requestID, err := remoteConsole.Write("command")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the response
|
// Read the response.
|
||||||
response, responseID, err := remoteConsole.Read()
|
response, responseID, err := remoteConsole.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if requestID != responseID {
|
if requestID != responseID {
|
||||||
fmt.Println("response id doesn't match the request id!")
|
log.Fatal("response id doesn't match the request id!")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(response)
|
fmt.Println(response)
|
||||||
|
|
20
rcon.go
20
rcon.go
|
@ -1,3 +1,12 @@
|
||||||
|
/*
|
||||||
|
A Go written library for the RCON Protocol from Valve.
|
||||||
|
|
||||||
|
Information to the protocol can be found under:
|
||||||
|
https://developer.valvesoftware.com/wiki/Source_RCON_Protocol
|
||||||
|
|
||||||
|
This is a fork from https://github.com/james4k/rcon with the support for go
|
||||||
|
modules and with a rework of the original implementation for better readability.
|
||||||
|
*/
|
||||||
package rcon
|
package rcon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -10,8 +19,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Information to the protocol can be found under: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
typeAuth = 3
|
typeAuth = 3
|
||||||
typeExecCommand = 2
|
typeExecCommand = 2
|
||||||
|
@ -78,13 +85,16 @@ func Dial(host, password string) (*RemoteConsole, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r := &RemoteConsole{conn: conn, readBuff: make([]byte, maxPackageSize+fieldPackageSize)}
|
remoteConsole := &RemoteConsole{
|
||||||
r.auth(password, timeout)
|
conn: conn,
|
||||||
|
readBuff: make([]byte, maxPackageSize+fieldPackageSize),
|
||||||
|
}
|
||||||
|
remoteConsole.auth(password, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return r, nil
|
return remoteConsole, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalAddr returns the local network address.
|
// LocalAddr returns the local network address.
|
||||||
|
|
Loading…
Reference in a new issue