On a scale from 1 to 10 how bad of an idea would it be to use a JSON like format for game networking?

Started by
23 comments, last by hplus0603 11 years, 2 months ago

It's actually lua, but there's not much difference there.

So I'm making a turned based strategy game and it does a lot of work with lua scripts server side. I created a wrapper class that I really like to use. So far I've been using it to interact with objects in the lua environment and save and load data etc. Then I thought: 'why not just use lua to send data across the network too?'

I figure the biggest bottleneck would be interpreting the code at the client and that doesn't worry since each individual client won't be receiving that many messages.

I know it's more bulky than binary, but it seems pretty convenient. Do you think it'll have a big impact on how many users the server can support? Sorry if this is a dumb question.

Advertisement

1: If it's truly turn based, this should be completely fine, and will make life a lot easier I'd say. I've even considering using compressed json strings for packets on real time games just because JSON rocks.

Douglas Eugene Reisinger II
Projects/Profile Site

[quote name='BinaryStorm' timestamp='1357848257' post='5019982']

I know it's more bulky than binary
[/quote]

My friend, you've answered your own question. If you can use binary, then use binary... or maybe you should try both and do some performance testing.

This is a severely bad idea, unless you really want malicious players to have free run of your game - both client and server.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

A JSON like format - great. It will make debugging easier, that's for sure.

But Lua? Unless you have a Lua parser that will treat it purely as data and not try to execute it, it would be extremely dangerous. Anybody on the internet could craft some malicious Lua code and send it to your server to be executed.

Didn't think about security. For what it's worth, messages would probably be executed in their own lua states, and I won't even load the standard libraries into those. I use states like that to load data.

What does that gain you over just transmitting data and using a simple parser to break it back out into the objects you want at each endpoint?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Why not use google protocol buffers instead? It'll be much faster and it has inter-language communication capabilities. The only drawback is the awkward build process.

I use json all the time for turn based networking for mobile games. I only use simple dictionaries though. One thing to watchout for with LUA though is if you are targeting iPhone. I know somebody who tried sending lua scripts as part of in app purchase downloadable content and his app was rejected.

Agreed on the security angle, however you should have more robust security in place than simple obscurity. What people seem to be worried about is, whatever protection scheme you have, the consequences become really dire, really immediately, if you're sending executable instructions around.

However, if you're truly using lua as a data-passing layer only, it probably wouldn't be too difficult to write a parser for that subset of the language (which would allow you continue using it as you are), convert to JSON (at least maintain ease of debugging), or use some other compact format, even binary.

throw table_exception("(? ???)? ? ???");

This topic is closed to new replies.

Advertisement