Page 1 of 1

Items extension not communicating with game.

Posted: 06 Oct 2014, 19:56
by Ninjaoninja2
Hello,
Recently me and a buddy of mine coded an extension to get items working but the xtReq sends out a request but never receives a response back. I do have the extension labeled under the extension tag correctly in the config, it's not disabled, and I am pretty sure we did it right. Just in case we missed something here is the extension code:

Code: Select all

// a global variable
var dbase

function init()
{
	dbase = _server.getDatabaseManager()
}
function destroy()
{
	delete dbase
}
function handleRequest(cmd, params, user, fromRoom)
{
	if (cmd == "getinventory")
	{
		// create a SQL statement
		var sql = "SELECT * FROM users WHERE NAME='"+user.getName()+"'"		
		
		// execute query on DB
		// queryRes is a ResultSet object
		var queryRes = dbase.executeQuery(sql)

		// prepare the response object
		var response = {}
		
		// _cmd property is the name of the response command
		// This is the only mandatory property you should always add
		// to a response object
		response._cmd = "getinventory"
		
		// Here we create an array for storing the database data
		response.db = []
		
		// queryRes is ResultSet object
		// Methods available:
		// 
		// size() 	the number of records contained
		// get(n)	get the nth record in the RecordSet
		//
		// Example:
		// var record = queryRes.get(0)
		//
		// Gets the first record in the RecordSet
		//
		if (queryRes != null)
		{
			// Cycle through all records in the ResultSet
			for (var i = 0; i < queryRes.size(); i++)
			{
				// Get a record
				var tempRow = queryRes.get(i)
				
				// This object will hold the record data that we'll send to the client
				var item = {}

				// From the record object we can get each field value
				response.itemname1	= tempRow.getItem("Beta Hat")
                              response.db.push( item )
			}
		}
		else
			trace("DB Query failed")
		
		/*
		* 
		* Send response back to client
		* 
		* sendResponse(response, fromRoom, sender, recipients, type)
		* 
		* response = an object with the _cmd property specifying the name of the response command
		* fromRoom = the id of the room where the response comes from (-1 if not needed)
		* sender   = the user sending the response (null if not needed)
		* recipients = a list of user that should receive the reponse
		* type = can be "xml" or "str". It represent the message format
		* 
		*/

		_server.sendResponse(response, -1, null, [user])
}
}
	
/*
* This method handles internal events
* Internal events are dispactched by the Zone or Room where the extension is attached to
* 
* the (evt) object
*/
function handleInternalEvent(evt)
{
	// Simply print the name of the event that was received
	//trace("Event received: " + evt.name)	
}
If you see anything wrong please let me know!
Sincerely, Ninjaoninja2