263 lines
8.7 KiB
C#
263 lines
8.7 KiB
C#
/*
|
|
* Copyright (c) Contributors, http://opensimulator.org/
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
* * Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above copyrightD
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* * Neither the name of the OpenSimulator Project nor the
|
|
* names of its contributors may be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
using System;
|
|
using System.Text;
|
|
using System.IO;
|
|
using OpenMetaverse;
|
|
using log4net;
|
|
|
|
namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|
{
|
|
#region ActorType Enum
|
|
public enum ActorType
|
|
{
|
|
Null,
|
|
ClientManager,
|
|
ScriptEngine,
|
|
PhysicsEngine
|
|
}
|
|
#endregion
|
|
|
|
#region ActorStatus Enum
|
|
public enum ActorStatus
|
|
{
|
|
Null,
|
|
Idle,
|
|
Sync
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// A message for synchonization message between scenes
|
|
/// </summary>
|
|
public class RegionSyncMessage
|
|
{
|
|
//KittyL: added to help identify different actors
|
|
|
|
|
|
#region MsgType Enum
|
|
public enum MsgType
|
|
{
|
|
Null,
|
|
//ConnectSyncClient,
|
|
//DisconnectSyncClient,
|
|
// CM -> SIM(Scene)
|
|
ActorConnect,
|
|
AgentAdd,
|
|
AgentUpdate,
|
|
AgentSameRegionTeleport, //from CM to PSA
|
|
AgentRemove,
|
|
AgentRequestSit,
|
|
AgentSit,
|
|
GrabObject,
|
|
GrabUpdate,
|
|
DeGrabObject,
|
|
StartAnim,
|
|
StopAnim,
|
|
GetTerrain,
|
|
GetObjects,
|
|
SubscribeObjects,
|
|
GetAvatars,
|
|
SubscribeAvatars,
|
|
ChatFromClient,
|
|
AvatarTeleportOut, // An LLClientView (real client) was converted to a RegionSyncAvatar
|
|
AvatarTeleportIn, // A RegionSyncAvatar was converted to an LLClientView (real client)
|
|
AvatarTeleportSameRegion, //from PSA to PE
|
|
// SIM -> CM
|
|
//Terrain,
|
|
//NewObject, // objects
|
|
//UpdatedObject, // objects
|
|
//RemovedObject, // objects
|
|
NewAvatar, // avatars
|
|
UpdatedAvatar, // avatars
|
|
AnimateAvatar,
|
|
AvatarAppearance,
|
|
RemovedAvatar, // avatars
|
|
BalanceClientLoad, // Tells CM a client load target and a place to teleport the extras
|
|
ChatFromSim,
|
|
SitResponse,
|
|
SendAnimations,
|
|
// BIDIR
|
|
EchoRequest,
|
|
EchoResponse,
|
|
RegionName,
|
|
RegionStatus,
|
|
//Added by KittyL
|
|
// Actor -> Scene
|
|
ActorType, //to register the type (e.g. Client Manager or Script Engine) with Scene when sync channel is initialized
|
|
SetObjectProperty,
|
|
ActorStop,
|
|
ResetScene,
|
|
OnRezScript,
|
|
OnScriptReset,
|
|
OnUpdateScript,
|
|
// Scene -> Script Engine
|
|
NewObjectWithScript,
|
|
SceneLocation,
|
|
//For load balancing purpose (among script engines)
|
|
//Temorarily put here, for easier first round of implemention.
|
|
//Script engine --> Scene
|
|
ActorStatus, //if the actor is busying syncing with a Scene, or is just idle. Status: {sync, idle}
|
|
LoadBalanceRequest,
|
|
LoadMigrationListenerInitiated,
|
|
//Scene --> Script engine
|
|
LoadMigrationNotice,
|
|
LoadBalanceResponse,
|
|
LoadBalanceRejection,
|
|
// Physics Engine -> Scene
|
|
PhysTerseUpdate,
|
|
PhysOutOfBounds,
|
|
PhysCollisionUpdate,
|
|
// Scene -> Physics Engine
|
|
PhysUpdateAttributes,
|
|
}
|
|
#endregion
|
|
|
|
#region Member Data
|
|
private MsgType m_type;
|
|
private byte[] m_data;
|
|
static ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
#endregion
|
|
|
|
#region Constructors
|
|
public RegionSyncMessage(MsgType type, byte[] data)
|
|
{
|
|
m_type = type;
|
|
m_data = data;
|
|
}
|
|
|
|
public RegionSyncMessage(MsgType type, string msg)
|
|
{
|
|
m_type = type;
|
|
m_data = System.Text.Encoding.ASCII.GetBytes(msg);
|
|
}
|
|
|
|
public RegionSyncMessage(MsgType type)
|
|
{
|
|
m_type = type;
|
|
m_data = new byte[0];
|
|
}
|
|
|
|
public RegionSyncMessage(Stream stream)
|
|
{
|
|
//ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
//try
|
|
{
|
|
m_type = (MsgType)Utils.BytesToInt(GetBytesFromStream(stream, 4));
|
|
int length = Utils.BytesToInt(GetBytesFromStream(stream, 4));
|
|
m_data = GetBytesFromStream(stream, length);
|
|
//log.WarnFormat("RegionSyncMessage Constructed {0} ({1} bytes)", m_type.ToString(), length);
|
|
}
|
|
/*
|
|
catch (Exception e)
|
|
{
|
|
log.WarnFormat("[REGION SYNC MESSAGE] RegionSyncMessage Constructor encountered an exception {0}", e.Message);
|
|
}
|
|
* */
|
|
}
|
|
|
|
private byte[] GetBytesFromStream(Stream stream, int count)
|
|
{
|
|
// Loop to receive the message length
|
|
byte[] ret = new byte[count];
|
|
int i = 0;
|
|
while (i < count)
|
|
{
|
|
i += stream.Read(ret, i, count - i);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Accessors
|
|
public MsgType Type
|
|
{
|
|
get { return m_type; }
|
|
}
|
|
|
|
public int Length
|
|
{
|
|
get { return m_data.Length; }
|
|
}
|
|
|
|
public byte[] Data
|
|
{
|
|
get { return m_data; }
|
|
}
|
|
#endregion
|
|
|
|
#region Conversions
|
|
public byte[] ToBytes()
|
|
{
|
|
byte[] buf = new byte[m_data.Length + 8];
|
|
Utils.IntToBytes((int)m_type, buf, 0);
|
|
Utils.IntToBytes(m_data.Length, buf, 4);
|
|
Array.Copy(m_data, 0, buf, 8, m_data.Length);
|
|
return buf;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return String.Format("{0} ({1} bytes)", m_type.ToString(), m_data.Length.ToString());
|
|
}
|
|
public string ToStringFull()
|
|
{
|
|
return String.Format("{0}:{1})", m_type.ToString(), Encoding.ASCII.GetString(m_data));
|
|
}
|
|
#endregion
|
|
|
|
public static void HandleSuccess(string header, RegionSyncMessage msg, string message)
|
|
{
|
|
m_log.WarnFormat("{0} Handled {1}: {2}", header, msg.ToString(), message);
|
|
}
|
|
|
|
public static void HandleTrivial(string header, RegionSyncMessage msg, string message)
|
|
{
|
|
m_log.WarnFormat("{0} Issue handling {1}: {2}", header, msg.ToString(), message);
|
|
}
|
|
|
|
public static void HandleWarning(string header, RegionSyncMessage msg, string message)
|
|
{
|
|
m_log.WarnFormat("{0} Warning handling {1}: {2}", header, msg.ToString(), message);
|
|
}
|
|
|
|
public static void HandleError(string header, RegionSyncMessage msg, string message)
|
|
{
|
|
m_log.WarnFormat("{0} Error handling {1}: {2}", header, msg.ToString(), message);
|
|
}
|
|
|
|
public static bool HandlerDebug(string header, RegionSyncMessage msg, string message)
|
|
{
|
|
m_log.WarnFormat("{0} DBG ({1}): {2}", header, msg.ToString(), message);
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|