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.
|
||||
remoteConsole, err := rcon.Dial("127.0.0.1", "password")
|
||||
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.
|
||||
requestID, err := remoteConsole.Write("command")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
// Read the response.
|
||||
// Read the response
|
||||
response, responseID, err := remoteConsole.Read()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Println(err)
|
||||
}
|
||||
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)
|
||||
|
|
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
|
||||
|
||||
import (
|
||||
|
@ -19,6 +10,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// Information to the protocol can be found under: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol
|
||||
|
||||
const (
|
||||
typeAuth = 3
|
||||
typeExecCommand = 2
|
||||
|
@ -85,16 +78,13 @@ func Dial(host, password string) (*RemoteConsole, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
remoteConsole := &RemoteConsole{
|
||||
conn: conn,
|
||||
readBuff: make([]byte, maxPackageSize+fieldPackageSize),
|
||||
}
|
||||
remoteConsole.auth(password, timeout)
|
||||
r := &RemoteConsole{conn: conn, readBuff: make([]byte, maxPackageSize+fieldPackageSize)}
|
||||
r.auth(password, timeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return remoteConsole, nil
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// LocalAddr returns the local network address.
|
||||
|
@ -197,7 +187,7 @@ func (r *RemoteConsole) writeCmd(reqID, pkgType int32, cmd string) error {
|
|||
|
||||
// body
|
||||
buffer.WriteString(cmd)
|
||||
|
||||
|
||||
// double null termination
|
||||
binary.Write(buffer, binary.LittleEndian, byte(0))
|
||||
binary.Write(buffer, binary.LittleEndian, byte(0))
|
||||
|
|
Loading…
Reference in a new issue