 app.get '/explode/', (request, response) ->
 	throw new Error 'Emulated error.'
 
-app.get '/explode_db/', (request, response) ->
-	dbConnection.query.sync dbConnection, 'SELECT * FROM "Emulated DB error."'
+app.get '/explode_db/', openTransaction, (request, response) ->
+	request.uonline.tx.query.sync request.uonline.tx, 'SELECT * FROM "Emulated DB error."'
+, commit
 
 
 app.get '/', (request, response) ->

app.post '/action/newCharacter',
	mustBeAuthed,
	setInstance('new_character'),
	(request, response) ->
		nameIsValid = lib.validation.characterNameIsValid(request.body.character_name)
		alreadyExists = lib.character.characterExists.sync(null, dbConnection, request.body.character_name)

		if nameIsValid and not alreadyExists
			charid = lib.character.createCharacter.sync(
				null
				dbConnection
				request.uonline.user.id
				request.body.character_name
				request.body.character_race
				request.body.character_gender
			)
			response.redirect 303, '/character/'
		else
			options = request.uonline
			options.error = true
			options.invalidName = !nameIsValid
			options.nameIsBusy = alreadyExists
			options.character_name = request.body.character_name
			response.render 'new_character', options


app.get '/game/',

app.post '/action/register',
	mustNotBeAuthed,
	setInstance('register'),
	openTransaction,
	(request, response, next) ->
		usernameIsValid = lib.validation.usernameIsValid(request.body.username)
		passwordIsValid = lib.validation.passwordIsValid(request.body.password)
		userExists = lib.user.userExists.sync(null, request.uonline.tx, request.body.username)

		if usernameIsValid and passwordIsValid and !userExists
			result = lib.user.registerUser.sync(
				null
				request.uonline.tx
				request.body.username
				request.body.password
				'user'
			)
			request.uonline.userCreated = true
			response.cookie 'sessid', result.sessid
		else
			options = request.uonline
			options.error = true
