Ruby (Client to Server talk)

i havent been diving into ruby that much but, is it possible to send client/server message through ruby through T2? or does this need to go through another port?

Comments

  • ThythThyth Apotheosis Incarnate
    Here's the de-facto documentation of the Ruby interpreter in TribesNext:

    First of all, you should probably ask yourself if you really should be using Ruby at all in a T2 script. If you can't come up with a good reason why you need it, you probably shouldn't use it.

    The reason it's there in the TN patch is because basic arithmetic and logical operators don't work entirely correctly in the built in TorqueScript interpreter, which made implementation of the RSA cryptosystem more difficult than hacking in a Ruby interpreter that has proper arbitrary precision integers (or even regular integers that work properly).

    As such, the Ruby interpreter integrated into the patch is there specifically for infrequent cryptographic operators, and is neither user nor developer friendly. Since the interpreter is running across a process boundary, inter-process-communication is used (along with a data encode/decode process). The primary game simulation loop is also locked until the Ruby interpreter process signals completion of the evaluation. Thus, you should keep the number of TorqueScript->Ruby and Ruby->TorqueScript transitions to a minimum, since they are on the order of a dozen millisecond latency, instead of microsecond latency within one of the domains. This is not significant when only a handful of calls are made, but you would not want to invoke the Ruby interpreter inside a tight loop of script code.

    In any case, from the Torque Script side, there are three native functions related to Ruby:
    • rubyEval(string) -- this evaluates a Ruby expression, and it's pretty much the only thing you're interested in
    • rubyAddConLine(string) -- this is invoked by the native code to echo regular printed output from the Ruby interpreter into the game console, but can be replaced by a script function of the same name
    • rubyAddErrorLine(string) -- same as above, except this is used for errors encountered in the interpreter, and the output is in red to the game console
    You'll be invoking the rubyEval function exclusively. I don't see much reason to replace the functions that handle text output, but they are exposed if anyone needs to. This function returns void regardless of input.

    I do include a handful of script functions that wrap around rubyEval, such as rubyExec, but these are fairly self explanatory if you read the rubyUtils.cs file within the t2csri.vl2 archive.

    On the Ruby interpreter side, there is a single non-standard static function called tsEval, which takes a Ruby string. You use tsEval if you want to invoke the in-game interpreter from Ruby. However, it is critical to note that the implementation of tsEval is asynchronous and will queue all TorqueScript evaluations for execution at the end of the in-game RubyEval invocation. In the TribesNext code base, I almost always just used the tsEval function call to send data from the Ruby interpreter into a temporary global variable in the in-game Torque Script environment.

    The Ruby environment in the interpreter side is extremely minimalistic. It includes the Ruby core library, but none of the standard library. If you want anything special on top of this, you'll need to implement it yourself.

    Finally, in answer to your question: the only communication available to/from the Ruby interpreter is rubyEval from TorqueScript and tsEval from Ruby. The way you would do communication between the client and server that involves Ruby would be to delegate the computation to Ruby, but do the communication itself via the regular TorqueScript methods.

    This is essentially what the TribesNext patch does for the authentication handshake with the game servers. You can read the scripts to see how I did it there.
  • Thank you for the very informative post. I'll look into it, and check out the scripts some more.
Sign In or Register to comment.