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.

Monday, August 20, 2012

i46

i45 to i46

New Features

[#1182] Several server to server communications now use SSL host checking.

This improves the security for integrations with 3rd party components, such as google G+ and facebook.

Numerous performance improvements in the core server

  • [#1185] Calls to facebook are now made by the web layer rather than the core server.
  • [#1186] Switched to using fastjson json library for all the server to web layer communications.
  • [#1187] Switched to more efficient memory allocator in server binary.
  • [#1188] Switched to single event threaded model, rather than one thread per request.

Bug Fixes

[#1167] Appstore entries with empty modifiers no-longer cause javascript errors in the editor.

i45

i44 to i45

New Features

[#????] Added admin scripts

These are callable using scripts/run_admin with the admin_token. They must be whitelisted using whitelist_admin. Note that these scripts do not receive an args.player argument, but do receive others arguments in the same manner as conventional scripts.

[#1172] Added ability for admin to create and login players

This is done though the admin/create_player and admin/login_player functions.

The create_player function requires a name and admin token. It does not set the players password, which must be set using a separate call.

The login_player function requires an admin token, and either a name or player id.

Bug Fixes

No bug fixes this release.

i44

i43 to i44

New Features

[#1155] Added basic urban airship integration

[#1172] Added experimental direct database access to lua scripting.

This is not available by default - contact us if you want access to it.

Usage looks like this:

function luadbtest(args)
  local it = lua_db:query("SELECT id, name FROM Junk")
  local retval = {}
  while not it:is_end() do
    table.insert( retval, { id=it:column_as_string(0), name=it:column_as_string(1) } )
    it:next()
  end
  return 0, retval
end

whitelist("luadbtest")

[#1173] Return player id on login or create

All create or login calls now return the player id.

[#1174] Added google/login_or_create

Since trying to log in or create a player invalidates a google oauth2 code, we have provided an alternative function that first tries to log a player in with the given code, or else creates a new player associated to the corresponding google user.

This call returns the "mode" set to "create" or "login" depending on which method occurred. It also returns the players id and auth token.

[#1175] Added google/token functions.

This call allows the client to get the current users google oauth2 token.

Bug Fixes

[#1176] Players google data is immediately stored.

Player data corresponding to their google account was only getting periodically synced to the database, this is now occurring immediately. One symptom was that in some situations players could not log in immediately after creating an account.

[#1177] Obtaining a users google id now works on tokens with a larger variety of scopes.

Originally we required the application to request the userinfo.profile scope, for the methods we used to obatin a players google id. Applications can now use the gplus.me scope now, and any scope that embeds the users id into the token info.

[#1178] Fixed some runtime warnings from some server code.