Jump to content

DarkTwister

Member
  • Posts

    4
  • Joined

  • Last visited

DarkTwister's Achievements

Junior Member

Junior Member (1/8)

0

Reputation

  1. So I took it another step forward and now I got lua implemented instead using nlua: http://nlua.org/ Same principles again but with the following code: import clr; from System.Net import WebClient; from System.IO import File, Path; from System import Array; dll1Url = "http://example.com/KeraLua.dll"; dll2Url = "http://example.com/NLua.dll"; dll1Path = Path.Combine(TCAdminFolder, "Monitor\Shared\KeraLua.dll"); dll2Path = Path.Combine(TCAdminFolder, "Monitor\Shared\NLua.dll"); dll3Url = "http://example.com/lua52.dll"; #64-bit dll3Path = Path.Combine(TCAdminFolder, "Monitor\Shared\lua52.dll"); #64-bit if File.Exists(dll1Path) == False: client = WebClient(); client.DownloadFile(dll1Url, dll1Path); Script.WriteToConsole("KeraLua downloaded..."); if File.Exists(dll2Path) == False: client = WebClient(); client.DownloadFile(dll2Url, dll2Path); Script.WriteToConsole("NLua downloaded..."); if File.Exists(dll2Path) == False: client = WebClient(); client.DownloadFile(dll3Url, dll3Path); Script.WriteToConsole("lua52 downloaded..."); clr.AddReference("KeraLua"); clr.AddReference("NLua"); from NLua import Lua; state = Lua() state.LoadCLRPackage() state['script'] = Script; state['thisService'] = ThisService; state['thisServer'] = ThisServer; state.DoFile(Path.Combine(ThisService.RootDirectory, "myscript.lua")); Put the following into myscript.lua: script:WriteToConsole("Hello World " .. thisService.GameName) Result: So all you have to do is upload KeraLua.dll, NLua.dll, and lua52.dll to a host to ensure they get installed on the remote. Note: Make sure that the lua52.dll has the same architecture as your server (32bit or 64bit).
  2. So I've looked into it further and as I thought you will still have to compile a .jar file that will then be run with JVM and executed by your .net application. As such it will definitely take quite a performance hit, although we could probably make it work one way or another we can't be sure how well or fast it will work. C# has a similar syntax that I would suggest learning in favor of Java in this case. I might still make an attempt at implementing this though.
  3. I'm not sure about Java, but you can definitely run Javascript by essentially doing the same thing with Javascript.Net: https://github.com/JavascriptNet/Javascript.Net. I know they are vastly different but just to mention it's possible, just like it would be possible to get LUA or any other language you prefer in there. E#1: It should be possible to utilize this http://jni4net.com/ and make it work after enough work, might give it a go just for fun.
  4. Throughout my time at Fragnet Networks I have experimented a lot with the quite powerful scripting engine in TCAv2 that is done with IronPython. It has come in very handy and proved to work extremely well with what we have done, however I have also felt the need to extend functionalites. So what did I do? Well I took it upon myself to extend TCAdmin seeing as IronPython is CLR based. During my first test I decided to create a very simple C# Library DLL using .Net 3.5 (as I assume this is what TCAv2 is based on). For Lua look here: http://clientforums.tcadmin.com/showpost.php?p=75318&postcount=6 namespace TestLibrary{ public class MyClass{ public string HelloWorld = "HelloWorld"; } } I then compiled this into TestLibrary.dll and then put it in C:/Program Files/TCAdmin2/Monitor/Shared. After having added it into the folder it was time to play. I created a new script with the following content in TCAdmin: import clr; clr.AddReference("TestLibrary"); from TestLibrary import MyClass; myClass = MyClass(); Script.WriteToConsole(myClass.HelloWorld); So what was the result when ran? I got a nice and shiny "Hello World" in the script console! HURRAH! We found our way in! Now how do we make this work on all remotes? Well we let the script download the file of course using the WebClient class function "DownloadFile" of course into the shared folder. So let's change the code: import clr; from System.Net import WebClient; from System.IO import File, Path; from System import Activator; from System import Array; dllUrl = "http://example.com/TestLibrary.dll"; dllPath = Path.Combine(TCAdminFolder, "Monitor\Shared\TestLibrary.dll"); #Check if the dll file doesn't exist on the remote, and download it if File.Exists(dllPath) == False: client = WebClient(); client.DownloadFile(dllUrl, dllPath); Script.WriteToConsole("DLL downloaded..."); #Load assembly into memory clr.AddReference("TestLibrary"); from TestLibrary import MyClass; myClass = MyClass(); Script.WriteToConsole(myClass.HelloWorld); HUZZAH! More success! But being crazy as I am I wouldn't stop at that, I continued my experimentation and thought... What if I can load C# right into IronPython instead and skip the library? Well I have the pleasure of saying, yes, yes we can. This was done using the CSScriptLibrary] as it has proven to be very powerful in the past. Let's get to it below: import clr; from System.Net import WebClient; from System.IO import File, Path; from System import Activator; from System import Array; dllUrl = "http://example.com/CSScriptLibrary.v3.5.dll"; dllPath = Path.Combine(TCAdminFolder, "Monitor\Shared\CSScriptLibrary.v3.5.dll"); if File.Exists(dllPath) == False: client = WebClient(); client.DownloadFile(dllUrl, dllPath); Script.WriteToConsole("DLL downloaded..."); clr.AddReference("CSScriptLibrary.v3.5"); from CSScriptLibrary import CSScript; parameters = Array[str]([Path.Combine(TCAdminFolder, "Monitor\Shared\TCAdmin.SDK.dll"), Path.Combine(TCAdminFolder, "Monitor\Shared\TCAdmin.GameHosting.SDK.dll")]) result = CSScript.LoadCodeFrom(Path.Combine(ThisService.RootDirectory, "myscript.cs")); script = result.GetType("MyScript"); mainMethod = script.GetMethod("MainHook"); activateMe = Activator.CreateInstance(script); mainMethod.Invoke(activateMe, Array[object]([script, ThisServer, ThisService])); This will compile our fiel myscript.cs with the TCAdmin.SDK and TCAdmin.GameHosting.SDK which will allow us access to the script window and service/server settings. Here is the source of myscript.cs as I put in the game folder: using System; using TCAdmin.SDK.Scripting.Engines; using TCAdmin.GameHosting.SDK.Objects; public class MyScript { IronPythonEngine Script; Server ThisServer; Service ThisService; public void MainHook(IronPythonEngine script, Server server, Service service) { Script = script; ThisServer = server; ThisService = service; Script.WriteToConsole("Hello World " + ThisService.GameName); } } So then I run the script and what output do we get? Hello World RUST Experimental The script has executed successfully. You may close this window. Ta-da! We can now write pure C# for TCAdmin instead of IronPython (I do prefer it). Although it may definitely not be very efficient it does work and suffice for all tasks as you need them. Now feel free to do what you want and just have fun with your new knowledge of what can be done in IronPython and just how powerful it all is.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use