Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Scripting for games using Java  (Read 2553 times)
0 Members and 1 Guest are viewing this topic.
Offline zingbat

Senior Member




Java games rock!


« Posted 2009-09-02 00:15:29 »

Better than using some crappy scripting language for a game is to use Janino

http://www.janino.net/

an embedded java compiler and which can load java classes directly from java source.

The problem with this is nothing prevents a modder who creates some extension for a game to access the java.io.* package and do all sorts of nasty things  without any restrictions.

My question is there a simple way to restrict a modders script when using Janino or other embedded java compiler as a game scripting solution?
Offline Nate

JGO Wizard


Medals: 81
Projects: 3


Esoteric Software


« Reply #1 - Posted 2009-09-02 00:48:51 »

How is Janino better than using a different JVM language? Java syntax can be had using BeanShell (though I don't personally like BeanShell). Java-the-language is not very expressive, so I think you may be limiting yourself unnecessarily.

You should be able to use the Java Security mechanism. Methods that you don't want users to call should check a permission that users don't have. There are also ways to control permissions to file access, network access, etc.

Pnuts has some additional mechanisms:
http://pnuts.org/doc/secure.html
http://pnuts.org/doc/limitedclass.html
http://pnuts.org/doc/configuration.html
More on Pnuts:
http://pnuts.org/snapshot/latest/
http://pnuts.org/articles/pnutsHighlights.html

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #2 - Posted 2009-09-02 01:27:45 »

My question is there a simple way to restrict a modders script when using Janino or other embedded java compiler as a game scripting solution?

A crappy solution is to not directly convert the sourcecode into classes, but save the intermediate result to either a file or a byte[]. Then you can peek around the constantpool (you must write a parser...) and terminate any naughty attempt to take over your machine. That said, you can't so much about "for(;Wink;", only Thread.stop() will get you out of that.

So much for the problems of this 'ultimate runtime compiler' -- scripting languages are not that bad after all.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #3 - Posted 2009-09-02 21:02:57 »

How is Janino better than using a different JVM language?[...]

It's a very fast on-the-fly compiler. This means you get full speed. It also means you can script full classes and it also means that you can replace them with compiled versions as soon as you're done with em.

So, you can for example prototype rather complex things (even integral parts of your framework) pretty quickly. E.g. model or image loaders, collision detection, physics, etc. The console of my scripting framework was also done like that for example.

弾幕 ☆ @mahonnaiseblog
Offline Nate

JGO Wizard


Medals: 81
Projects: 3


Esoteric Software


« Reply #4 - Posted 2009-09-02 23:36:26 »

It's a very fast on-the-fly compiler. This means you get full speed.

Other JVM langauges (eg, Pnuts Grin) can compile to bytecodes on the fly. Of course, speed is going to vary depending on what the language is doing. I think you are saying that Janino compiled classes are exactly as fast as using bytecodes from javac?

Quote
It also means you can script full classes and it also means that you can replace them with compiled versions as soon as you're done with em.

I write Java classes using a standard Java IDE (Eclipse). If I change the Java source for a class and save the file, the IDE recompiles the class and (assuming my application is running) it uses Java HotSwap to patch the bytecodes for the class in the running application. I can't imagine Janino's workflow can be smoother than this?

IMO, the real benefit to use a JVM language other than Java-the-language is for added expressiveness. There is also the benefit of being able to load code at runtime, when an IDE is not present.

So far, the only argument I could accept for using Janino would be:

1) If you needed to compile Java source at runtime, with no IDE. But isn't there a JSR for this that made it into the JDK? Does Janino provide extra funcitonality?

2) If you absolutely needed the same speed as javac, and are willing to sacrifice expressiveness to get it. Then I wonder what the speed differences actually are in real world usage.

Offline zingbat

Senior Member




Java games rock!


« Reply #5 - Posted 2009-09-03 00:06:52 »

Thanks for the input. I will check pnuts. It looks a solid scripting language.

"1) If you needed to compile Java source at runtime, with no IDE. But isn't there a JSR for this that made it into the JDK? Does Janino provide extra funcitonality?"

I have two requirements for a game scripting language 1) scripts can be compiled to bytecode and 2) it can be compiled dynamically. I know that java 1.6 has some support for dynamic compilation but i have a mac with with java 1.5 and i'm not sure if it works. Anyway it looks like Pnuts can do the job. 
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #6 - Posted 2009-09-03 01:22:14 »

>I think you are saying that Janino compiled classes are exactly as fast as using bytecodes from javac?

Yes. I never noticed any speed difference. (Complete classes.)

>I can't imagine Janino's workflow can be smoother than this?

Well, it means you easily get a workflow like that (with instant turn-overs) on very dated or very weak machines.

Janino can also compile/execute statements or method bodies, which might be handy here and there.

弾幕 ☆ @mahonnaiseblog
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (94 views)
2013-05-17 21:29:12

alaslipknot (102 views)
2013-05-16 21:24:48

gouessej (132 views)
2013-05-16 00:53:38

gouessej (127 views)
2013-05-16 00:17:58

theagentd (138 views)
2013-05-15 15:01:13

theagentd (126 views)
2013-05-15 15:00:54

StreetDoggy (168 views)
2013-05-14 15:56:26

kutucuk (189 views)
2013-05-12 17:10:36

kutucuk (192 views)
2013-05-12 15:36:09

UnluckyDevil (199 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.115 seconds with 21 queries.