Wednesday, October 31, 2012

i50

i49 to i50

New Features

[CHAM-17] Enabled getting of player id from player name to lua.

Usage is id = player.get_player_id_by_name("somename"). Returns null if not found.

[CHAM-16] Added lua_db function escape that makes a string mysql safe (beta).

When forming a database query in lua, using input that comes from a user you should use the new escape function to ensure that you do not open yourself up to SQL injection attacks. Typical useage looks like this

lua_db:query( string.format(
"SELECT * FROM BLAH WHERE key=%s",
lua_db:escape("This will be safe'; TRUNCATE TABLE BLAH;")
) )

[CHAM-15] Added lua to_json and from_json functions (beta).

Functions have been added to assist with working with JSON in lua.

Converting a lua table to JSON is easy.

local s
s = to_json( { a=1 } )
-- now s = '{"a":1}'
s = to_json( { "hello", "bye" } )
-- now s = '["hello","bye"]'

This handles tables, strings, numbers, explicit null values, true and false. However there are a few issues to be aware of.

  • Since lua does not differentiate between arrays and dictionaries you should not try to convert mixed dictionaries.
  • An empty table converts to {} rather than []
  • lua dictionaries support arbitrary keys. However if you convert a table with keys that are not strings you may get an error or invalid JSON.
  • setting a value to null in a table removes that entry from the table, so the following may not do what you expect.
local v = {bar=1}
v.foo = null
s = to_json(v)
-- s = '{"bar":1}' rather than '{"bar":1,"foo":null}'

Converting from JSON is easy too.

local v
v = from_json( '{"a":1}' )
-- now v = { a=1 }
v = from_json( '[1,2]' )
-- now v = {1,2}

Some of the caveats from above still apply:

  • from_json( '{"a":null}' ) will produce an empty object.

[CHAM-14] Added basic network calls functionality to lua (beta).

It is now possible to make network calls to other services from within lua. However as this is done in an asynchronous manner there are a few limitations. Starting the request is done with the lue_network:request function. This requires the url, the callback to call, and some optional extra user data to pass to the callback.

Handling the response must be done in a callback function which gets passed a data object containing:

  • data.url The request url
  • data.user_data Some extra data passed to the request
  • data.response_code The http request response code - typically 200 for success, 40x for error
  • data.response The response body

The code to make calls looks like this:

function nw_callback( data )
print( data.url )
print( data.user_data[0] )
print( data.response_code )
print( data.response )
end

--Invoking the network call
lua_network:request(
"http://api.roar.io/mafp/info/ping/",
nw_callback,
{"some user data","yep"}
)

A limitation of the current method is that it only supports GET operations, not POST or other methods.

Bug Fixes

No bug fixes in this release

i49

i48 to i49

New Features

No new user-facing features this release.

Bug Fixes

Fixed bug where player data could get lost on publish.

i48

i47 to i48

New Features

[???] Added new get_current_timestring lua function

This function returns a string representation of the time in YYYY-MM-DD HH:MM:SS format This format has the advantage that ordering by time is the same as ordering the strings lexicographically.

Example usage is:

local timestr = get_current_timestring()
if timestr < "2013-01-01 00:00:00" then 
  print("Its still 2012")
end

Bug Fixes

No bug fixes in this release.

i47

i46 to i47

New Features

[CHAM-5] Added support to getting json formatted results from scripts/run and scripts/run_auth

The scripts/run and scritps/run_auth functions can now return JSON rather than XML. To make this happen just add format=json to the POST arguments.

Bug Fixes

[CHAM-4] Fixed google friends failing due to stricter json requirements

The changes to JSON handling in the core libraries [i46 - #1186] caused calls to obtain google friends to fail. These calls are once again working correctly.

[CHAM-3] Login with google causing server slow down.

A missing index of a core table was causing searching for players by google id to be slow. This index has been added and things are once again fast.