 app.post '/action/switchCharacter',
 	mustBeAuthed,
 	(request, response) ->
-		lib.character.switchCharacter.sync null, dbConnection, request.uonline.user.id, request.body.id
+		lib.character.switchCharacter.sync null, request.uonline.tx, request.uonline.user.id, request.body.id
 		response.redirect 303, 'back'
 
 
 app.post '/action/deleteCharacter',
 	mustBeAuthed,
 	(request, response) ->
-		lib.character.deleteCharacter.sync null, dbConnection, request.uonline.user.id, request.body.id
+		lib.character.deleteCharacter.sync null, request.uonline.tx, request.uonline.user.id, request.body.id
 		response.redirect 303, '/account/'
 
 
 app.get '/state/',
 	(request, response, next) ->
-		players = dbConnection.query.sync dbConnection,
+		players = request.uonline.tx.query.sync request.uonline.tx,
 			"SELECT *, (sess_time > NOW() - $1 * INTERVAL '1 SECOND') AS online FROM uniusers",
 			[config.sessionExpireTime]
 		request.uonline.userstate = players.rows
 		next()
 	,
 	setInstance('state'), render('state')
+
+
+app.get '/test/', (req, res, next) ->
+	console.log('test route. it exists, but 404 will appear')
+	next()
+
+app.use (request, response, next) ->
+	console.log('after route')
+	next()
 
 
 # 404 handling

app.post '/action/go',
	mustBeAuthed,
	(request, response) ->
		result = lib.game.changeLocation.sync null, dbConnection, request.uonline.user.character_id, request.body.to
		if result.result != 'ok'
			console.error "Location change failed: #{result.reason}"
		response.redirect 303, '/game/'



fetchItems = ((request, response) ->
	items = lib.game.getCharacterItems.sync null, request.uonline.tx, request.uonline.user.character_id
	request.uonline.equipment = items.filter (x) -> x.equipped
	request.uonline.equipment.shield = request.uonline.equipment.find (x) -> x.type == 'shield'
	request.uonline.equipment.right_hand = request.uonline.equipment.find (x) -> x.type.startsWith 'weapon'
