Offline Messaging

From OpenSimulator

Revision as of 14:02, 13 January 2013 by Allen Kerensky (Talk | contribs)

Jump to: navigation, search

Offline Messaging makes it possible to send IM's to people who are not online.

Instead, the messages are saved to a database and delivered the next time the recipient logs in.

Please note that these are third party modules which you use at your own risk!
OpenSimulator takes no responsibility for these modules.

OfflineMessagingModule Configuration Steps

The OfflineMessagingModule is already compiled and ready for use in current versions of OpenSimulator.

However, you will need to setup the "back-end" database and PHP connector scripts to support the OfflineMessagingModule.

  1. Configure the Offline_IM database table in your MySQL using commands in Offline_IM.sql (below)
  2. Upload the mysql.php (below) into your web server
  3. Upload the offline.php (below) into your web server
  4. Enable the OfflineMessagingModule in your OpenSim.ini file

STEP 1: Offline_IM.sql

Save these SQL commands to an Offline_IM.sql file on your MySQL server.

CREATE TABLE IF NOT EXISTS `Offline_IM` (
 `uuid` varchar(36) NOT NULL,
 `message` text NOT NULL,
  KEY `uuid` (`uuid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Connect to your MySQL (Linux commands shown):

$ mysql --user=$mysqluser --password=$mysqlpassword $databasename

Replace $mysqluser, $mysqlpassword, and $databasename with your specific configuration.

At the mysql prompt, source the Offline_IM.sql file to configure your database to hold offline IMs:

mysql> source Offline_IM.sql
... ensure no error messages appear here ...
mysql> quit

STEP 2: mysql.php

Copy this PHP script to a file called mysql.php and upload the script file to your web server.

No edits of the script should be necessary.

<?php
/*
 * Copyright (c) 2007, 2008 Contributors, http://opensimulator.org/
 * See CONTRIBUTORS for a full list of copyright holders.
 *
 * See LICENSE for the full licensing terms of this file.
 *
*/
 
// This looks like its lifted from http://www.weberdev.com/get_example-4372.html
// I'd contact the original developer for licensing info, but his website is broken.
 
class DB
{
	var $Host = C_DB_HOST;				// Hostname of our MySQL server
	var $Database = C_DB_NAME;			// Logical database name on that server
	var $User = C_DB_USER;				// Database user
	var $Password = C_DB_PASS;			// Database user's password
	var $Link_ID = 0;				// Result of mysql_connect()
	var $Query_ID = 0;				// Result of most recent mysql_query()
	var $Record	= array();			// Current mysql_fetch_array()-result
	var $Row;					// Current row number
	var $Errno = 0;					// Error state of query
	var $Error = "";
 
	function halt($msg)
	{
		echo("</TD></TR></TABLE><B>Database error:</B> $msg<BR>\n");
		echo("<B>MySQL error</B>: $this->Errno ($this->Error)<BR>\n");
		die("Session halted.");
	}
 
	function connect()
	{
		if($this->Link_ID == 0)
		{
			$this->Link_ID = mysql_connect($this->Host, $this->User, $this->Password);
			if (!$this->Link_ID)
			{
				$this->halt("Link_ID == false, connect failed");
			}
			$SelectResult = mysql_select_db($this->Database, $this->Link_ID);
			if(!$SelectResult)
			{
				$this->Errno = mysql_errno($this->Link_ID);
				$this->Error = mysql_error($this->Link_ID);
				$this->halt("cannot select database <I>".$this->Database."</I>");
			}
		}
	}
 
 	function escape($String)
 	{
 		return mysql_escape_string($String);
 	}
 
	function query($Query_String)
	{
		$this->connect();
		$this->Query_ID = mysql_query($Query_String,$this->Link_ID);
		$this->Row = 0;
		$this->Errno = mysql_errno();
		$this->Error = mysql_error();
		if (!$this->Query_ID)
		{
			$this->halt("Invalid SQL: ".$Query_String);
		}
		return $this->Query_ID;
	}
 
	function next_record()
	{
		$this->Record = @mysql_fetch_array($this->Query_ID);
		$this->Row += 1;
		$this->Errno = mysql_errno();
		$this->Error = mysql_error();
		$stat = is_array($this->Record);
		if (!$stat)
		{
			@mysql_free_result($this->Query_ID);
			$this->Query_ID = 0;
		}
		return $this->Record;
	}
 
	function num_rows()
	{
		return mysql_num_rows($this->Query_ID);
	}
 
	function affected_rows()
	{
		return mysql_affected_rows($this->Link_ID);
	}
 
	function optimize($tbl_name)
	{
		$this->connect();
		$this->Query_ID = @mysql_query("OPTIMIZE TABLE $tbl_name",$this->Link_ID);
	}
 
	function clean_results()
	{
		if($this->Query_ID != 0) mysql_freeresult($this->Query_ID);
	}
 
	function close()
	{
		if($this->Link_ID != 0) mysql_close($this->Link_ID);
	}
}
?>

STEP 3: offline.php

Copy this PHP script to a file called offline.php and upload the script file to your web server.

Edit the $dbName, $dbHost, $dbUser, and $dbPassword lines at the top of the script to match your database and server information.

<?php
$dbName = "comunity";
$dbHost = "localhost";
$dbUser = "root";
$dbPassword ="";
 
define("C_DB_TYPE","mysql");
define("C_DB_HOST",$dbHost);
define("C_DB_NAME",$dbName);
define("C_DB_USER",$dbUser);
define("C_DB_PASS",$dbPassword);
define("C_OFFLINE_IM_TBL", "Offline_IM");
include("mysql.php");
$DbLink = new DB;
$method = $_SERVER["PATH_INFO"];
if ($method == "/SaveMessage/")
{
$msg = $HTTP_RAW_POST_DATA;
$start = strpos($msg, "?>");
if ($start != -1)
{
$start+=2;
$msg = substr($msg, $start);
$parts = split("[<>]", $msg);
$to_agent = $parts[12];
$DbLink->query("insert into ".C_OFFLINE_IM_TBL." (uuid, message) values ('" .
mysql_escape_string($to_agent) . "', '" .
mysql_escape_string($msg) . "')");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><boolean>true</boolean>";
}
else
{
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><boolean>false</boolean>";
}
exit;
}
if ($method == "/RetrieveMessages/")
{
$parms = $HTTP_RAW_POST_DATA;
$parts = split("[<>]", $parms);
$agent_id = $parts[6];
$DbLink->query("select message from ".C_OFFLINE_IM_TBL." where uuid='" .
mysql_escape_string($agent_id) . "'");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><ArrayOfGridInstantMessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
while(list($message) = $DbLink->next_record())
{
echo $message;
}
echo "</ArrayOfGridInstantMessage>";
$DbLink->query("delete from ".C_OFFLINE_IM_TBL." where uuid='" .
mysql_escape_string($agent_id) . "'");
exit;
}
?>

STEP 4: OfflineMessageModule

Shutdown your simulator.

Edit the OpenSim.ini [Messaging] block.

An example configuration is shown below:

[Messaging]
; Control which region module is used for instant messaging.
; Default is InstantMessageModule (this is the name of the core IM module as well as the setting)
InstantMessageModule = InstantMessageModule
; MessageTransferModule = MessageTransferModule
OfflineMessageModule = OfflineMessageModule
OfflineMessageURL = http://yourserver/offline.php
MuteListModule = MuteListModule
MuteListURL = http://yourserver/mute.php
ForwardOfflineGroupMessages = true

P.D: The MuteListModule and URL must be uncommented in order for the offline module to work, even if there is no mute.php file in the web folder.

Once the edits are made, save your OpenSim.ini and restart your simulator.

Using the OfflineMessageModule

Login and try to send a message to an offline person. You should see the message: "System: User is not logged in. Message saved."

If you see "Message not saved." check your web server error log.

Check the database Offline_IM table to verify whether or not offline.php has written a record there.

Next time the person you messaged logs in, they will get the message and the database will be updated.

Personal tools
General
About This Wiki