Multiplayer

47 views
Skip to first unread message

Jan Novák

unread,
Apr 21, 2016, 12:09:43 AM4/21/16
to Hax Simulator
How can I start Hax Simulator server and let others connect to it? Preferably over the network.

Hax Simulator

unread,
May 13, 2016, 5:59:39 AM5/13/16
to Hax Simulator
Hello,

this is an undocumented feature of Hax, which I planned to improve further. The basic functionality is there. There is no security or authentication involved, it works on plain TCP/IP sockets. I have implemented a proof of concept for using SSL connections, but haven't released it yet as it is still a bit "rough on the edges".

The attached file contains two data centers, "europe" and "america". These are interconnected using what is called a link. Check out the dc.groovy and especially the dclink.groovy files, they contain comments describing how the link works.
Simply put the data centers into the "datacenter" directory of your Hax installation(s). If you want to run them on separate network nodes, make sure there is TCP/IP connectivity between the nodes and that incoming traffic on the listener ports is allowed on the firewall (default ports are 31001 and 31002 for america and europe, respectively). Further firewall configuration might be necessary, but I haven't tested this so I can't tell you exactly. If you figure anything else out, please post it here.

If required, perform any necessary reconfiguration of hosts and ports in the dclink.groovy files of both data centers. Be sure to keep the references to the remote data centers in sync (hosts, ports, connector names), or the link will not work.

If you have any further questions, feel free to ask.
Cheers

link.zip

Jan Novák

unread,
May 13, 2016, 11:31:03 AM5/13/16
to Hax Simulator
So, when you have network() it opens up a network IF you can access within the groovy file with it's ID, if you do network "alias" you can access it within the link and dc groovy files using alias, or only within link file?

I'm thinking of creating a server that would would be maintained and updated and would be able to serve a datacenter for multiple people, with them being able to interact with each other. Now that I'm thinking about it, this game needs a DHCP server, or daemon that would auto-config individual client's IP's so they could, in theory, connect to each other.

Hax Simulator

unread,
May 16, 2016, 6:44:19 AM5/16/16
to Hax Simulator
Actually, I used "alias" only to simplify things.
If you declare a network interface with an "alias", what it internally does is create a so-called access point bound to the network interface.
An access point is something like a named external connector within the data center, which is bound to a device (network interface).
The link uses the name of the access point to connect to the correct local network interface.

In fact, this is also how the GUI connects with the terminals of machines declared in the data center.
Every terminal() creates a pair of keyboard and display for the given machine, and creates an access point bound to these two devices with its name equal to the machine name.

For more info, see the Hax API docs here: http://hax-simulator.github.io/framework/
The doc for an access point is here: http://hax-simulator.github.io/framework/hax/sk/hax/cloud/AccessPoint.html

To answer your question, since an access point is an external entity, it is intended to be used when connecting external components to the core data center. Thus, in dc.groovy (the core data center configuration) you can't use access point names to reference stuff. You can only use access point names in dclink.groovy (the link component configuration) and dcgui.groovy (the GUI component configuration).

I hope this is somewhat understandable, although it is quite a dive in the internals of Hax.

As for network address configuration, Hax does not have a component such as DHCP, so it would have to be created. You would have to create both the server and the client part.
The server part would maintain a table of assigned and free addresses, and assign an address upon request. The client part would ask the server for a free address, then use the setNetworkAddress kernel API call to set the network address of the machine.

In reality, DHCP is really only used within LANs. On higher levels of the network, there are registrators which assign address ranges to requesting organizations (ISP, corporations etc.). If you wanted to connect more people, you would have to do the same.
You would basically set up a high level router. For every person who would like to connect, you would have to add a network interface to the router and assign it a network address range. Then, using the link functionality, the person could connect their data center to your router. The layout of his data center can be arbitrary - just a single workstation, a switch with multiple workstations, a router with even more subnets, a network hidden behind a NAT device (http://hax-simulator.github.io/framework/soft/network/sk/hax/software/network/NetworkAddressTranslator.html)... the possibilities are virtually endless.
An important thing is that you need to select your network address space wisely. I would recommend choosing a /16 range, so that other "ISPs" might connect easily to your network in the future.

What you want to do is something I wanted to try out for quite some time, but unfortunately I don't have a server for it.
If you need help with the configuration or would like to test it with someone, I am around.
We might even try out the new SSL link functionality, which is IMO quite essential with higher amounts of various people.
You can also contact me via hangouts so we can communicate more effectively. Email will also do of course.

Jan Novák

unread,
May 16, 2016, 11:58:33 AM5/16/16
to Hax Simulator
So, the traffic is transfered over HTTP/WebSocket? If so, I might be able to run a server with that cheaper and easier than I thought. Also, is it possible to integrate Python into the scripts, I never did Java, and I'm not looking to learn Java either, but I'm very profficient in Python.

Jan Novák

unread,
May 16, 2016, 12:02:15 PM5/16/16
to Hax Simulator
Also, I would probably use DHCP just to give IPs to players. Players themselves could build their own datacenters, theoretically forming corporations, and they could even ask me for assignment of IPs and Whois/Server listing entries, so people would easily find and connect to their servers, problem with that would be the player needing to run their datacenter 24/7, so ther alternative could be having the player created datacenters interlink within the server itself.

Hax Simulator

unread,
May 16, 2016, 5:09:29 PM5/16/16
to hax-si...@googlegroups.com
As for HTTP and websockets, no. The traffic is just TCP byte streams. With SSL links, it is still just streams of bytes, only that they are encrypted, and the remote side is authenticated and trusted based on its certificates.

As for the DHCP, you still need to maintain the router network interfaces configuration and link configuration, a DHCP server could not reconfigure these programatically. Using the manual assignment is the way to go IMO. Just set up some webform where people could ask for an address range. An automatic registration could of course also be made, but for now I think it is too much effort. Implementing DHCP itself is of course another story, as I encourage anyone to implement any real-life services in Hax. The users' data centers don't have to be online 24/7. If they are down, they just simply cannot be accessed. Links in Hax allow data centers to be switched off, and after switching it on again, the link automatically reconnects (just try it on the example I posted). Of course, you can also provide data center hosting, that is up to you.

As for Python, there is support of other languages via 3rd party wrappers, and I also got a proof of concept for Python. I however have no idea if the Python wrapper supports the full functionality and the performance you get with the "built-in" language, which is btw. not Java, but Groovy. Groovy is more script-like and should not be so hard to learn for someone with a background in scripting languages. On another note, there is another language which is supported without a wrapper, since it is integrated into the JVM, and that is JavaScript. Anyway, tomorrow I will post proof of concepts for using Python and JavaScript (and maybe some others, I think Lua also did quite well) to create Hax tasks. You can then explore the possibilities of the wrapped Python engine and see where its limits are.

Hax Simulator

unread,
May 18, 2016, 10:12:24 AM5/18/16
to Hax Simulator
Well, I found out this will be more difficult than I thought. To function correctly, the alternative languages proof of concept requires a maintenance release of Hax. This will also include the new SSL link functionality. I might get to this next week or so, but I will work on it for the sake of new interest in this project.

Attached (as a teaser), you can find a Hello world example Hax task implemented in Python. This is basically the same task as this one from the sample data center: https://github.com/hax-simulator/dc-sample/blob/master/src/sk/hax/software/sample/level3/Hello.groovy. The problem with using Python is that you need to write some additional "boilerplate" code (the setProperty and getProperty methods). Also, the additional java library required for this, jython (http://www.jython.org/downloads.html), requires a wider set of permissions than Hax out-of-the-box. I have not managed to discover which ones exactly. The workaround is to start the data center without a security manager. However, this can be VERY dangerous if you intend to run unverified code inside your data center, since the sandbox for Hax tasks is not present in this case.

Anyway, I will try to put together a maintenance release as soon as possible, and afterwards post more specific instructions on how to run the Python example.
test.py

Jan Novák

unread,
May 20, 2016, 5:51:02 AM5/20/16
to Hax Simulator
Nice, can't wait for something more in there. I will rarely run unverified code in the DC, I will be probably checking user-submitted python scripts, and I will set some rules to prevent unintentional damage, for example, no eval and exec statements...

Hax Simulator

unread,
Jun 8, 2016, 9:55:37 AM6/8/16
to hax-si...@googlegroups.com
Well, I finally got around to write a few words.

Basically, to be able to run the python script from the post above, you have to do the following:
1. Download the Jython library (latest version, standalone jar) from here, and copy it into the lib directory of Hax (should be a file called jython-standalone-2.7.0.jar)
2. In the bin directory of Hax, make a backup of the hax.policy file, and replace it with the attached policy file
3. Run Hax normally on a data center, make a file on the file system of your Hax machine and put the python code there (name it with an extension of .py)
4. Run the python script from the HaxOS command line using the command: "runs <filename>.py"

It should print out "hello world" into the console. Note that running it the first time might take a little longer.

Any more questions?
Just ask.
hax.policy

Jan Novák

unread,
Jun 11, 2016, 1:22:40 AM6/11/16
to Hax Simulator
It would be nice to have full docs of what you can do with the python scripts in Hax. I know what python can do, but what are the interactions with hax it is able to do?

Jan Novák

unread,
Jun 11, 2016, 1:30:02 AM6/11/16
to Hax Simulator
Also, I get this error when trying to run the test script:
java.lang.NullPointerException [Cannot invoke method eval() on null object]

Hax Simulator

unread,
Jun 13, 2016, 11:45:59 AM6/13/16
to Hax Simulator

I am not a python programmer myself, nor have I worked extensibly with the Jython library. But you should be able to do basically anything with the python scripts. What you could try is to take the Groovy scripts in the sample data center and try to translate them into python. As a reference, you can take the Hello world python example posted above and compare it with the Groovy version. The example includes a call from TERMINAL, so you should be able to use any method from here. Another important object which is set (but never used) in the example is KERNEL, so you should be able to call some of the methods from here. The sample data center scripts are very well documented, you should get the hang of what is going on in the Groovy code, and maybe be able to translate it to respective python code. I admit this is a rather lengthy trial-and-error process, but I think it's the only way right now.

 
As for the NullPointerException, it might have to do with the permissions.
Have you correctly updated the hax.policy file?
What java version are you running it on?
Are you on Windows? If so, try to edit the line
permission java.io.FilePermission "${hax.home}/lib/jython-standalone-2.7.0.jar", "read";

and replace it with
permission java.io.FilePermission "${hax.home}\lib\jython-standalone-2.7.0.jar", "read";

If that doesn't help, try to post here the full log from the console with the full stack trace.
In the worst case, pack the whole Hax directory and send it to my email so I can investigate.
Thanks
Message has been deleted

Radek Goláň

unread,
Jul 17, 2016, 2:19:25 PM7/17/16
to Hax Simulator
It didn't help, and I'm unable to get the logs out of it. It doesn't autodump them anywhere, and I can't copy them from cmdline either.

Hax Simulator

unread,
Jul 21, 2016, 8:07:55 AM7/21/16
to hax-si...@googlegroups.com
Well, you can try one more thing to test if it is the permissions causing the trouble.
Please note that this really turns off the sandbox of Hax, so you won't be protected against malicious code.

1.) Open up the file bin\hax.bat (not the one in the root Hax folder, but inside the bin directory) in a text editor
2.) Line 17 goes like "set JAVA_OPTS=...", put a "rem" at its start (so it looks like "rem set JAVA_OPTS=...")
3.) Line 16 above it goes like "rem set JAVA_OPTS=...", remove the "rem" at its start (so it looks like "set JAVA_OPTS=...")
4.) Start Hax as normal and try to run your Python script.

If it does not work, send the whole hax directory packed with zip to my email, so i can check what the problem is.
Thanks

PS: if you want to communicate faster, you can also contact me using Hangouts.
Reply all
Reply to author
Forward
0 new messages