A => LICENSE +24 -0
@@ 0,0 1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
M README.md +3 -0
@@ 2,6 2,9 @@ hackurist
=========
[hackurist](https://bitbucket.com/telesto/hackurist) is made up of a client library and a client command line program to access a running [dfhack](https://github.com/DFHack/dfhack) rpc server. It is written in [Go](http://golang.org/).
+News
+----
+
client library
--------------
Installation:
M cmd/hackurist/main.go +31 -7
@@ 13,10 13,12 @@ func usage() {
flag.PrintDefaults()
}
+var address = flag.String("a", "127.0.0.1:5000", "dfhack rpc server address")
+var debug = flag.Bool("d", false, "print debug messages")
+
func main() {
- address := flag.String("a", "127.0.0.1:5000", "dfhack rpc server address")
- debug := flag.Bool("d", false, "print debug messages")
help := flag.Bool("h", false, "help")
+ lua := flag.Bool("lua", false, "run lua command")
flag.Parse()
if *help {
@@ 27,8 29,12 @@ func main() {
usage()
os.Exit(2)
}
- cmd := flag.Arg(0)
- err := run(*address, cmd, flag.Args()[1:], *debug)
+ var err error
+ if *lua {
+ err = runCommand()
+ } else {
+ err = runLuaCommand()
+ }
if err != nil {
log.Println(err)
os.Exit(1)
@@ 36,8 42,8 @@ func main() {
os.Exit(0)
}
-func run(address, cmd string, args []string, debug bool) error {
- conn, err := hackurist.Dial(address, debug)
+func runLuaCommand() error {
+ conn, err := hackurist.Dial(*address, *debug)
if err != nil {
return err
}
@@ 46,10 52,28 @@ func run(address, cmd string, args []str
if err != nil {
return err
}
- result, err := conn.RunCommand(cmd, args)
+ result, err := conn.RunLuaCommand(flag.Arg(0), flag.Arg(1), flag.Args()[2:])
fmt.Print(string(result))
if err != nil {
return err
}
return nil
}
+
+func runCommand() error {
+ conn, err := hackurist.Dial(*address, *debug)
+ if err != nil {
+ return err
+ }
+ defer conn.Close()
+ err = conn.ShakeHands()
+ if err != nil {
+ return err
+ }
+ result, err := conn.RunCommand(flag.Arg(0), flag.Args()[1:])
+ fmt.Print(string(result))
+ if err != nil {
+ return err
+ }
+ return nil
+}
M hackurist.go +20 -3
@@ 15,9 15,10 @@ import (
type headerId int16
const (
- requestBindMethod headerId = 0 // n/a
- requestRunCommand headerId = 1 // n/a
- requestQuit headerId = -4 // RPC_REQUEST_QUIT
+ requestBindMethod headerId = 0 // n/a
+ requestRunCommand headerId = 1 // n/a
+ requestRunLuaCommand headerId = 4 // added in RemoteTools.cpp by addMethod()
+ requestQuit headerId = -4 // RPC_REQUEST_QUIT
responseResult headerId = -1 // RPC_REPLY_RESULT
responseFail headerId = -2 // RPC_REPLY_FAIL
@@ 201,6 202,22 @@ func (c Conn) RunCommand(cmd string, arg
return response, nil
}
+// RunLuaCommand sends lua command to the server.
+// It reads the response, processes it and returns the output
+// ready for a text client.
+func (c Conn) RunLuaCommand(module, fn string, args []string) ([]byte, error) {
+ protoCmd, err := proto.Marshal(&dfproto.CoreRunLuaRequest{Module: &module,
+ Function: &fn, Arguments: args})
+ if err != nil {
+ return nil, fmt.Errorf("RunCommand: %s", err)
+ }
+ if err = c.write(protoCmd); err != nil {
+ return nil, fmt.Errorf("RunLuaCommand: %s", err)
+ }
+
+ return nil, nil
+}
+
// todo: timeout
func (c Conn) write(b []byte) error {
written, err := c.conn.Write(b)