| 1 |
using System; |
using System; |
| 2 |
|
using System.Reflection; |
| 3 |
using System.Collections.Generic; |
using System.Collections.Generic; |
| 4 |
using System.Text; |
using System.Text; |
| 5 |
using OpenMetaverse; |
using OpenMetaverse; |
| 6 |
using OpenSim.Framework; |
using OpenSim.Framework; |
| 7 |
using OpenSim.Region.Environment.Scenes; |
using OpenSim.Region.Environment.Scenes; |
| 8 |
|
using log4net; |
| 9 |
|
|
| 10 |
namespace ModularRex.RexParts.RexPython |
namespace ModularRex.RexParts.RexPython |
| 11 |
{ |
{ |
| 13 |
class RexEventManager |
class RexEventManager |
| 14 |
{ |
{ |
| 15 |
private RexScriptEngine myScriptEngine; |
private RexScriptEngine myScriptEngine; |
| 16 |
|
private static readonly ILog m_log |
| 17 |
|
= LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
| 18 |
|
|
| 19 |
// tuco fixme, is there a better way to do this search??? |
// tuco fixme, is there a better way to do this search??? |
| 20 |
private EntityBase GetEntityBase(uint vId) |
private EntityBase GetEntityBase(uint vId) |
| 29 |
public RexEventManager(RexScriptEngine vScriptEngine) |
public RexEventManager(RexScriptEngine vScriptEngine) |
| 30 |
{ |
{ |
| 31 |
myScriptEngine = vScriptEngine; |
myScriptEngine = vScriptEngine; |
| 32 |
myScriptEngine.Log.InfoFormat("[RexScriptEngine]: Hooking up to server events"); |
m_log.InfoFormat("[RexScriptEngine]: Hooking up to server events"); |
| 33 |
myScriptEngine.World.EventManager.OnObjectGrab += touch_start; |
myScriptEngine.World.EventManager.OnObjectGrab += touch_start; |
| 34 |
// myScriptEngine.World.EventManager.OnRezScript += OnRezScript; |
// myScriptEngine.World.EventManager.OnRezScript += OnRezScript; |
| 35 |
// myScriptEngine.World.EventManager.OnRemoveScript += OnRemoveScript; |
// myScriptEngine.World.EventManager.OnRemoveScript += OnRemoveScript; |
| 42 |
///TODO: |
///TODO: |
| 43 |
///These events were added to forked version. Some of them can be handled |
///These events were added to forked version. Some of them can be handled |
| 44 |
///other way, some need changes to core and some need changes to physics engine. |
///other way, some need changes to core and some need changes to physics engine. |
| 45 |
//myScriptEngine.World.EventManager.OnAddEntity += OnAddEntity; |
//myScriptEngine.World.EventManager.OnAddEntity += OnAddEntity; //this was previously launched from Scene or InnerScene |
| 46 |
//myScriptEngine.World.EventManager.OnRemoveEntity += OnRemoveEntity; |
//myScriptEngine.World.EventManager.OnRemoveEntity += OnRemoveEntity; //this was previously launched from Scene |
| 47 |
//myScriptEngine.World.EventManager.OnPythonClassChange += OnPythonClassChange; |
//myScriptEngine.World.EventManager.OnPythonClassChange += OnPythonClassChange; //this was launched from SceneObjectPart |
| 48 |
//myScriptEngine.World.EventManager.OnPrimVolumeCollision += OnPrimVolumeCollision; |
//myScriptEngine.World.EventManager.OnPrimVolumeCollision += OnPrimVolumeCollision; //this was launched from PhysicActor |
| 49 |
//myScriptEngine.World.EventManager.OnRexScriptListen += OnRexScriptListen; |
myScriptEngine.World.EventManager.OnChatFromWorld += OnRexScriptListen; |
| 50 |
OpenSim.OpenSim.RegisterCmd("python", PythonScriptCommand, "Rex python commands. Type \"python help\" for more information."); |
myScriptEngine.World.EventManager.OnChatBroadcast += OnRexScriptListen; |
| 51 |
|
myScriptEngine.World.EventManager.OnChatFromClient += OnRexScriptListen; |
| 52 |
} |
} |
| 53 |
|
|
| 54 |
private void PythonScriptCommand(string[] cmdparams) |
private void PythonScriptCommand(string[] cmdparams) |
| 61 |
switch (command) |
switch (command) |
| 62 |
{ |
{ |
| 63 |
case "help": |
case "help": |
| 64 |
myScriptEngine.Log.Info("[RexScriptEngine]: Python commands available:"); |
m_log.Info("[RexScriptEngine]: Python commands available:"); |
| 65 |
myScriptEngine.Log.Info("[RexScriptEngine]: python restart - restarts the python engine"); |
m_log.Info("[RexScriptEngine]: python restart - restarts the python engine"); |
| 66 |
break; |
break; |
| 67 |
case "restart": |
case "restart": |
| 68 |
myScriptEngine.RestartPythonEngine(); |
myScriptEngine.RestartPythonEngine(); |
| 69 |
break; |
break; |
| 70 |
default: |
default: |
| 71 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: Unknown PythonScriptEngine command:" + cmdparams[0]); |
m_log.WarnFormat("[RexScriptEngine]: Unknown PythonScriptEngine command:" + cmdparams[0]); |
| 72 |
break; |
break; |
| 73 |
} |
} |
| 74 |
} |
} |
| 75 |
} |
} |
| 76 |
catch (Exception e) |
catch (Exception e) |
| 77 |
{ |
{ |
| 78 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnPythonScriptCommand: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnPythonScriptCommand: " + e.ToString()); |
| 79 |
} |
} |
| 80 |
} |
} |
| 81 |
|
|
| 133 |
} |
} |
| 134 |
catch (Exception e) |
catch (Exception e) |
| 135 |
{ |
{ |
| 136 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnNewPresence: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnNewPresence: " + e.ToString()); |
| 137 |
} |
} |
| 138 |
} |
} |
| 139 |
|
|
| 147 |
} |
} |
| 148 |
catch (Exception e) |
catch (Exception e) |
| 149 |
{ |
{ |
| 150 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRemovePresence: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnRemovePresence: " + e.ToString()); |
| 151 |
} |
} |
| 152 |
} |
} |
| 153 |
|
|
| 173 |
} |
} |
| 174 |
catch (Exception e) |
catch (Exception e) |
| 175 |
{ |
{ |
| 176 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnAddEntity: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnAddEntity: " + e.ToString()); |
| 177 |
} |
} |
| 178 |
} |
} |
| 179 |
|
|
| 186 |
} |
} |
| 187 |
catch (Exception e) |
catch (Exception e) |
| 188 |
{ |
{ |
| 189 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRemoveEntity: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnRemoveEntity: " + e.ToString()); |
| 190 |
} |
} |
| 191 |
} |
} |
| 192 |
|
|
| 215 |
} |
} |
| 216 |
catch (Exception e) |
catch (Exception e) |
| 217 |
{ |
{ |
| 218 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnPythonClassChange: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnPythonClassChange: " + e.ToString()); |
| 219 |
} |
} |
| 220 |
} |
} |
| 221 |
|
|
| 232 |
} |
} |
| 233 |
catch (Exception e) |
catch (Exception e) |
| 234 |
{ |
{ |
| 235 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRexClientScriptCommand: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnRexClientScriptCommand: " + e.ToString()); |
| 236 |
} |
} |
| 237 |
} |
} |
| 238 |
|
|
| 245 |
} |
} |
| 246 |
catch (Exception e) |
catch (Exception e) |
| 247 |
{ |
{ |
| 248 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnPrimVolumeCollision: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnPrimVolumeCollision: " + e.ToString()); |
| 249 |
} |
} |
| 250 |
} |
} |
| 251 |
|
|
| 252 |
public void OnRexScriptListen(uint vPrimLocalId, int vChannel, string vName, UUID vId, string vMessage) |
/// <summary> |
| 253 |
|
/// Listens to all world scripts and clients. Sends event from that to python scripts |
| 254 |
|
/// </summary> |
| 255 |
|
public void OnRexScriptListen(object sender, OSChatMessage chat)//uint vPrimLocalId, int vChannel, string vName, UUID vId, string vMessage) |
| 256 |
{ |
{ |
| 257 |
try |
try |
| 258 |
{ |
{ |
| 259 |
SceneObjectPart source = null; |
if (chat.Message != "") |
| 260 |
ScenePresence avatar = null; |
{ |
| 261 |
|
uint localId = 0; |
| 262 |
string sid = "0"; |
string sid = "0"; |
| 263 |
|
string name = chat.From; |
| 264 |
|
|
| 265 |
source = myScriptEngine.World.GetSceneObjectPart(vId); |
SceneObjectPart sop = myScriptEngine.World.GetSceneObjectPart(chat.SenderUUID); |
| 266 |
if (source != null) |
if (sop != null) |
| 267 |
{ |
{ |
| 268 |
if ((EntityBase)(source.ParentGroup) != null) |
localId = sop.LocalId; |
| 269 |
sid = ((EntityBase)source.ParentGroup).LocalId.ToString(); |
sid = sop.ParentGroup.LocalId.ToString(); |
| 270 |
} |
} |
| 271 |
else |
|
| 272 |
|
if (chat.Sender != null) |
| 273 |
|
{ |
| 274 |
|
ScenePresence sp = myScriptEngine.World.GetScenePresence(chat.Sender.AgentId); |
| 275 |
|
if (sp != null) |
| 276 |
{ |
{ |
| 277 |
avatar = myScriptEngine.World.GetScenePresence(vId); |
localId = sp.LocalId; |
| 278 |
if(avatar != null) |
sid = chat.Sender.AgentId.ToString(); |
| 279 |
sid = avatar.UUID.ToString(); |
if (name == "" || name == null) name = chat.Sender.Name; |
| 280 |
|
} |
| 281 |
} |
} |
| 282 |
|
|
| 283 |
string EventParams = "\"listen\"," + vPrimLocalId.ToString() + "," + vChannel.ToString() + "," + |
//if (chat.SenderObject != null) |
| 284 |
"\"" + vName + "\"" + "," + "\"" + sid + "\"" + "," + "\"" + vMessage.ToString() + "\""; |
//{ |
| 285 |
myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + EventParams + ")"); |
// m_log.Info("sender is an "+chat.SenderObject.GetType()); |
| 286 |
|
//} |
| 287 |
|
|
| 288 |
|
string eventParams = "\"listen\"," + localId + "," + chat.Channel.ToString() + "," + |
| 289 |
|
"\"" + name + "\"" + "," + "\"" + sid + "\"" + "," + "\"" + chat.Message + "\""; |
| 290 |
|
myScriptEngine.ExecutePythonCommand("CreateEventWithName(" + eventParams + ")"); |
| 291 |
|
//m_log.Info(eventParams); |
| 292 |
|
} |
| 293 |
} |
} |
| 294 |
catch (Exception e) |
catch (Exception e) |
| 295 |
{ |
{ |
| 296 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRexScriptListen: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnRexScriptListen: " + e.ToString()); |
| 297 |
} |
} |
| 298 |
} |
} |
| 299 |
|
|
| 306 |
} |
} |
| 307 |
catch (Exception e) |
catch (Exception e) |
| 308 |
{ |
{ |
| 309 |
myScriptEngine.Log.WarnFormat("[RexScriptEngine]: OnRexClientStartUp: " + e.ToString()); |
m_log.WarnFormat("[RexScriptEngine]: OnRexClientStartUp: " + e.ToString()); |
| 310 |
} |
} |
| 311 |
} |
} |
| 312 |
|
|