Author Topic: Mod: Error compiling scripts (Namespace is forbidden)  (Read 526 times)

Seyon

  • Newbie
  • *
  • Posts: 8
    • View Profile
Mod: Error compiling scripts (Namespace is forbidden)
« on: April 30, 2019, 03:56:53 am »
Hello, I have a quick question about server side mods. I have written a new mod that opens a socket connection so that I can query server information  for a website (and later send commands from the website to the server).
The whole thing is still pretty rude and there are still some features missing but the general socket connection works.

But unfortunately I have some errors "in the log" when starting the server. These look like this:

Code: [Select]
[ERR] Error compiling scripts:
XXXXX\Scripts\Bootstrappers\BootstrapperServerSocket.cs (line 9)
   Error: Namespace System.Net is forbidden

The error does not seem to affect the server because everything works as expected. I suspect that is because it happens in the [COMPILER CLIENT] area which is not important for the server? But it is not nice to always have errors in the log. Is there a way to tell the server that my classes are needed only in the server compile and are ignored in the client compile?

Currently I have implemented my code in a bootstrapper with "after BootstrapperServerCore". I had already tried to outsource it to a trigger (since they are called only on the server side and I was hoping that they are ignored by the client compile). Unfortunately, both cause the same error in the log.

Can someone here call me a possible solution? Or tell me where my mistake is?

Thanks in advance.

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 1488
    • View Profile
Re: Mod: Error compiling scripts (Namespace is forbidden)
« Reply #1 on: April 30, 2019, 04:14:27 am »
Hello!

The game is using our in-house made RENKEI Engine and the primary component of it is the C# scripts compiler. The game is shipped with open source code part (Core.cpk) which contains all the gameplay-related code and assets.

So, when any script is changed (or when you're starting the game for the first time) the game engine will attempt to compile the scripts assembly. If it fails, the game server will not run (not sure regarding your message "the error does not seem to affect the server because everything works as expected" because it cannot launch without the scripts compiled).

We cannot allow scripts to access everything. Our compilation approach ensures the scripts have limited access to certain .NET API (such as System.IO, System.Net, and System.Reflection) to ensure no damage could be done to the player's operating system and personal files (another thing is that we could ensure proper disposal of the objects such as network socket when the scripts are live recompiled and reloading due to the code modification). To circumvent the problem we're providing the scripting API (for example, it has some methods to access server configuration files and to access types reflection data in a safe way). We could expand it on request to allow other API like HttpClient.

Quote
Code: [Select]
Scripts\Bootstrappers\BootstrapperServerSocket.cs (line 9)
   Error: Namespace System.Net is forbidden
This error is self-explanatory—the System.Net API is restricted and you cannot access it from the scripting. Please let me know what exactly you're trying to achieve. Will be a simple async HTTP GET method sufficient to achieve this? We could add such API for the next update. A complete HTTP/binary data listening socket server is more complicated to implement but we could consider this for sure. We're not sure if we want to expose the raw .NET Socket API as it could be abused by client-side mods to perform some unexpected stuff (and overall too complicated for the most modders to use as is, it could be wrapped by us into something much more approachable as we do with everything else in the scripting API).

Quote
Is there a way to tell the server that my classes are needed only in the server compile and are ignored in the client compile?
There is no need for that—just don't place certain stuff in the client part of the code (there is a clear separation between the client and server methods, some methods are "shared"—it's all obvious by the class names or method names). Also, you could always check Api.IsServer/Api.IsClient properties to determine whether the current execution is done on the server or client. This is how we're using this and so far this approach proved to be the most powerful and simple to use (we have max code reuse between client and server and the code is easy to read and navigate (without the need to jump between different files or folders for client/server implementation), especially RPC calls).

Regards!

Seyon

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Mod: Error compiling scripts (Namespace is forbidden)
« Reply #2 on: April 30, 2019, 05:09:38 am »
First, thanks for the quick response.

My plan was to develop a web interface for my server, with which I can view server statistics (such as current players) at any time and (in the ideal case) execute certain commands in the remote to manage the server eg whitelist / blacklist etc ..

Similar to how it works in many other games via rcon. However, since I am quite new in this area (I'm from the PHP development area.), I tried to solve this for the time being over a simple socket so that the server listens to a specific IP / port.

Quote
if it fails, the game server will not run (not sure regarding your message "the error does not seem to affect the server because everything works as expected" because it cannot launch without the scripts compiled).

By that I mean that it still works!
The server starts even though the error is issued in the console and I can connect to the server as usual. Also the socket connection works.  ;D

If this is not desired by you you can check my code and see why it still works.
Of course, I have no problem if you as a developer do not want such a feature. Then I postpone the plan indefinitely until there may be an official solution.

You can find my code here: https://github.com/seyon/cryofall_mods/tree/master/SeyonWebapp
But please note that this is currently just a proof of concept and certainly elements such as security have not yet been implemented. Of course I would have planned these aspects as well. But first I wanted to test only if it would be possible in general.

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 1488
    • View Profile
Re: Mod: Error compiling scripts (Namespace is forbidden)
« Reply #3 on: May 01, 2019, 03:53:46 am »
Hello!

Regarding:
Quote
the error does not seem to affect the server because everything works as expected

You're right, I've checked this and game server making a second attempt to compile the scripts after the first failed, and the scripts compiler is using the cached parsed C# files—even though they had validation errors they were added to the cache. When taken from the cache these C# files were not validated again (as this is the point of the cache :-) to reduce overhead if files are not changed for the subsequent compilation). It's going to be fixed in the upcoming server patch. Thanks for reporting!

Regarding the socket API usage—I see, RCON is a good idea and we're going to provide official RCON support!

We're not going to allow usage of System.Net as it has a large and complex API, potentially creating issues to the game engine (especially during scripts reloading) and other issues, as I've mentioned above. But later we will provide a simple safe wrapper at least over the HttpClient as many modders want to use that to access some data in game or pull some data into the game from their websites.

Regards!

Seyon

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Mod: Error compiling scripts (Namespace is forbidden)
« Reply #4 on: May 01, 2019, 06:55:53 am »
In any case, many thanks for the information. And I can fully understand why you do not want to allow System.Net Api.

In this case, for the time being, I only build the server installation into my web application and extend the control over RCON as soon as it is officially installed.

I'm looking forward to it, it's really fun to build Mods for this great game.