mirror of
https://github.com/hamburghammer/rcon.git
synced 2024-12-23 16:27:40 +01:00
Compare commits
No commits in common. "3e2320a5f4e5c11916bcd51ce057e150d00b4f5c" and "7830bfeaa5ec613e203784491b967007e6ccc550" have entirely different histories.
3e2320a5f4
...
7830bfeaa5
2 changed files with 11 additions and 23 deletions
12
README.md
12
README.md
|
@ -8,24 +8,22 @@ 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 {
|
||||||
log.Fatal(err)
|
fmt.Println(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 {
|
||||||
log.Fatal(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the response.
|
// Read the response
|
||||||
response, responseID, err := remoteConsole.Read()
|
response, responseID, err := remoteConsole.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
if requestID != responseID {
|
if requestID != responseID {
|
||||||
log.Fatal("response id doesn't match the request id!")
|
fmt.Println("response id doesn't match the request id!")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(response)
|
fmt.Println(response)
|
||||||
|
|
22
rcon.go
22
rcon.go
|
@ -1,12 +1,3 @@
|
||||||
/*
|
|
||||||
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 (
|
||||||
|
@ -19,6 +10,8 @@ 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
|
||||||
|
@ -85,16 +78,13 @@ func Dial(host, password string) (*RemoteConsole, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteConsole := &RemoteConsole{
|
r := &RemoteConsole{conn: conn, readBuff: make([]byte, maxPackageSize+fieldPackageSize)}
|
||||||
conn: conn,
|
r.auth(password, timeout)
|
||||||
readBuff: make([]byte, maxPackageSize+fieldPackageSize),
|
|
||||||
}
|
|
||||||
remoteConsole.auth(password, timeout)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return remoteConsole, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalAddr returns the local network address.
|
// LocalAddr returns the local network address.
|
||||||
|
@ -197,7 +187,7 @@ func (r *RemoteConsole) writeCmd(reqID, pkgType int32, cmd string) error {
|
||||||
|
|
||||||
// body
|
// body
|
||||||
buffer.WriteString(cmd)
|
buffer.WriteString(cmd)
|
||||||
|
|
||||||
// double null termination
|
// double null termination
|
||||||
binary.Write(buffer, binary.LittleEndian, byte(0))
|
binary.Write(buffer, binary.LittleEndian, byte(0))
|
||||||
binary.Write(buffer, binary.LittleEndian, byte(0))
|
binary.Write(buffer, binary.LittleEndian, byte(0))
|
||||||
|
|
Loading…
Reference in a new issue