Para la actualización de los sitios de microblogging basados en status.net desde los mundos virtuales basados en OpenSimulator y Second Life, se creara un HUD (Heads-Up Display), objeto que puede ser pegado directamente colocado dentro de la pantalla y no dentro del mundo como un objeto o un accesorio del avatar, de esta forma solo es visible dentro de la interface del usuario que lo esta utilizando.
El objeto contiene un script desarrollado en LSL (Linden Script Language) que escucha los mensajes enviados por el avatar dueño del objeto a traves del canal 5, de esta forma si el usuario quiere enviar un mensaje debe colocar en la ventana de chat /5 seguido por el mensaje a enviar.
// Listen all the messages and post to the microblogging site
listen(integer channel, string name, key id, string message) {
// Update the status using the message give by the user
PSNH_updateStatus(message);
}
El script toma el mensaje y lo envia a traves de una peticion HTTP al servidor, adicionando informacion de autenticacion y el nuevo estado.
// Update the estatus of the user in the microblogging site // @param message The message to use like status PSNH_updateStatus(string message) { // Construct the url to send the message // Something like this // http://username:password@server.com/api/statuses/update.xml string url = "http://" + psnh_username + ":" + psnh_password + "@" + psnh_serverName + psnh_serverPath + psnh_restPath; // Prepare request values, using post and send the message encoded string body = "status=" + message; list parameters = [ HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded; charset=UTF-8" ]; // Sen the request psnh_requestID = llHTTPRequest(url, parameters, body); }
La respuesta del servidor es capturada por el script y se visualiza un mensaje de error si el código retornado por el servidor es 200 (OK), si es otro código se escribe en la pantalla de chat simplemente el error y el contenido de la respuesta devuelta por el servidor.
// Check the reponse send by the server // @param request_id The identifier of the request // @param status The http reponse code send by the server // @param metadata Metadata associated with the request // @param body The response information send by the server PSNH_checkResponse(key request_id, integer status, list metadata, string body) { // If any problem with the server, show the page that send // The server response 200 if not problem if(status != 200) llOwnerSay(body); // Show a info message else llOwnerSay("Status Update!!!"); }
El script completo es colocado dentro del objeto, acompañado de otros archivos de documentación.
Enlaces :
Entradas Relacionadas: