diff options
Merge branch 'careminster' into tests
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 220 |
1 files changed, 204 insertions, 16 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index a60c0ba..2fc2ea1 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -30,6 +30,7 @@ using System.IO; | |||
30 | using System.Threading; | 30 | using System.Threading; |
31 | using System.Collections; | 31 | using System.Collections; |
32 | using System.Collections.Generic; | 32 | using System.Collections.Generic; |
33 | using System.Diagnostics; //for [DebuggerNonUserCode] | ||
33 | using System.Security; | 34 | using System.Security; |
34 | using System.Security.Policy; | 35 | using System.Security.Policy; |
35 | using System.Reflection; | 36 | using System.Reflection; |
@@ -1119,6 +1120,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1119 | return false; | 1120 | return false; |
1120 | } | 1121 | } |
1121 | 1122 | ||
1123 | [DebuggerNonUserCode] | ||
1122 | public void ApiResetScript(UUID itemID) | 1124 | public void ApiResetScript(UUID itemID) |
1123 | { | 1125 | { |
1124 | IScriptInstance instance = GetInstance(itemID); | 1126 | IScriptInstance instance = GetInstance(itemID); |
@@ -1170,6 +1172,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1170 | return UUID.Zero; | 1172 | return UUID.Zero; |
1171 | } | 1173 | } |
1172 | 1174 | ||
1175 | [DebuggerNonUserCode] | ||
1173 | public void SetState(UUID itemID, string newState) | 1176 | public void SetState(UUID itemID, string newState) |
1174 | { | 1177 | { |
1175 | IScriptInstance instance = GetInstance(itemID); | 1178 | IScriptInstance instance = GetInstance(itemID); |
@@ -1245,34 +1248,219 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1245 | } | 1248 | } |
1246 | } | 1249 | } |
1247 | 1250 | ||
1248 | public string GetAssemblyName(UUID itemID) | ||
1249 | { | ||
1250 | IScriptInstance instance = GetInstance(itemID); | ||
1251 | if (instance == null) | ||
1252 | return ""; | ||
1253 | return instance.GetAssemblyName(); | ||
1254 | } | ||
1255 | |||
1256 | public string GetXMLState(UUID itemID) | 1251 | public string GetXMLState(UUID itemID) |
1257 | { | 1252 | { |
1258 | IScriptInstance instance = GetInstance(itemID); | 1253 | IScriptInstance instance = GetInstance(itemID); |
1259 | if (instance == null) | 1254 | if (instance == null) |
1260 | return ""; | 1255 | return ""; |
1261 | return instance.GetXMLState(); | 1256 | string xml = instance.GetXMLState(); |
1262 | } | ||
1263 | 1257 | ||
1264 | public bool CanBeDeleted(UUID itemID) | 1258 | XmlDocument sdoc = new XmlDocument(); |
1265 | { | 1259 | sdoc.LoadXml(xml); |
1266 | IScriptInstance instance = GetInstance(itemID); | 1260 | XmlNodeList rootL = sdoc.GetElementsByTagName("ScriptState"); |
1267 | if (instance == null) | 1261 | XmlNode rootNode = rootL[0]; |
1268 | return true; | 1262 | |
1263 | // Create <State UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"> | ||
1264 | XmlDocument doc = new XmlDocument(); | ||
1265 | XmlElement stateData = doc.CreateElement("", "State", ""); | ||
1266 | XmlAttribute stateID = doc.CreateAttribute("", "UUID", ""); | ||
1267 | stateID.Value = itemID.ToString(); | ||
1268 | stateData.Attributes.Append(stateID); | ||
1269 | XmlAttribute assetID = doc.CreateAttribute("", "Asset", ""); | ||
1270 | assetID.Value = instance.AssetID.ToString(); | ||
1271 | stateData.Attributes.Append(assetID); | ||
1272 | doc.AppendChild(stateData); | ||
1273 | |||
1274 | // Add <ScriptState>...</ScriptState> | ||
1275 | XmlNode xmlstate = doc.ImportNode(rootNode, true); | ||
1276 | stateData.AppendChild(xmlstate); | ||
1277 | |||
1278 | string assemName = instance.GetAssemblyName(); | ||
1279 | |||
1280 | string fn = Path.GetFileName(assemName); | ||
1281 | |||
1282 | string assem = String.Empty; | ||
1283 | |||
1284 | if (File.Exists(assemName + ".text")) | ||
1285 | { | ||
1286 | FileInfo tfi = new FileInfo(assemName + ".text"); | ||
1287 | |||
1288 | if (tfi != null) | ||
1289 | { | ||
1290 | Byte[] tdata = new Byte[tfi.Length]; | ||
1291 | |||
1292 | try | ||
1293 | { | ||
1294 | FileStream tfs = File.Open(assemName + ".text", | ||
1295 | FileMode.Open, FileAccess.Read); | ||
1296 | tfs.Read(tdata, 0, tdata.Length); | ||
1297 | tfs.Close(); | ||
1298 | |||
1299 | assem = new System.Text.ASCIIEncoding().GetString(tdata); | ||
1300 | } | ||
1301 | catch (Exception e) | ||
1302 | { | ||
1303 | m_log.DebugFormat("[XEngine]: Unable to open script textfile {0}, reason: {1}", assemName+".text", e.Message); | ||
1304 | } | ||
1305 | } | ||
1306 | } | ||
1307 | else | ||
1308 | { | ||
1309 | FileInfo fi = new FileInfo(assemName); | ||
1310 | |||
1311 | if (fi != null) | ||
1312 | { | ||
1313 | Byte[] data = new Byte[fi.Length]; | ||
1314 | |||
1315 | try | ||
1316 | { | ||
1317 | FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read); | ||
1318 | fs.Read(data, 0, data.Length); | ||
1319 | fs.Close(); | ||
1320 | |||
1321 | assem = System.Convert.ToBase64String(data); | ||
1322 | } | ||
1323 | catch (Exception e) | ||
1324 | { | ||
1325 | m_log.DebugFormat("[XEngine]: Unable to open script assembly {0}, reason: {1}", assemName, e.Message); | ||
1326 | } | ||
1327 | |||
1328 | } | ||
1329 | } | ||
1330 | |||
1331 | string map = String.Empty; | ||
1332 | |||
1333 | if (File.Exists(fn + ".map")) | ||
1334 | { | ||
1335 | FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read); | ||
1336 | StreamReader msr = new StreamReader(mfs); | ||
1337 | |||
1338 | map = msr.ReadToEnd(); | ||
1339 | |||
1340 | msr.Close(); | ||
1341 | mfs.Close(); | ||
1342 | } | ||
1343 | |||
1344 | XmlElement assemblyData = doc.CreateElement("", "Assembly", ""); | ||
1345 | XmlAttribute assemblyName = doc.CreateAttribute("", "Filename", ""); | ||
1346 | |||
1347 | assemblyName.Value = fn; | ||
1348 | assemblyData.Attributes.Append(assemblyName); | ||
1349 | |||
1350 | assemblyData.InnerText = assem; | ||
1351 | |||
1352 | stateData.AppendChild(assemblyData); | ||
1269 | 1353 | ||
1270 | return instance.CanBeDeleted(); | 1354 | XmlElement mapData = doc.CreateElement("", "LineMap", ""); |
1355 | XmlAttribute mapName = doc.CreateAttribute("", "Filename", ""); | ||
1356 | |||
1357 | mapName.Value = fn + ".map"; | ||
1358 | mapData.Attributes.Append(mapName); | ||
1359 | |||
1360 | mapData.InnerText = map; | ||
1361 | |||
1362 | stateData.AppendChild(mapData); | ||
1363 | return doc.InnerXml; | ||
1271 | } | 1364 | } |
1272 | 1365 | ||
1273 | private bool ShowScriptSaveResponse(UUID ownerID, UUID assetID, string text, bool compiled) | 1366 | private bool ShowScriptSaveResponse(UUID ownerID, UUID assetID, string text, bool compiled) |
1274 | { | 1367 | { |
1275 | return false; | 1368 | return false; |
1276 | } | 1369 | } |
1370 | |||
1371 | public void SetXMLState(UUID itemID, string xml) | ||
1372 | { | ||
1373 | if (xml == String.Empty) | ||
1374 | return; | ||
1375 | |||
1376 | XmlDocument doc = new XmlDocument(); | ||
1377 | |||
1378 | try | ||
1379 | { | ||
1380 | doc.LoadXml(xml); | ||
1381 | } | ||
1382 | catch (Exception) | ||
1383 | { | ||
1384 | m_log.Error("[XEngine]: Exception decoding XML data from region transfer"); | ||
1385 | return; | ||
1386 | } | ||
1387 | |||
1388 | XmlNodeList rootL = doc.GetElementsByTagName("State"); | ||
1389 | if (rootL.Count < 1) | ||
1390 | return; | ||
1391 | |||
1392 | XmlElement rootE = (XmlElement)rootL[0]; | ||
1393 | |||
1394 | if (rootE.GetAttribute("UUID") != itemID.ToString()) | ||
1395 | return; | ||
1396 | |||
1397 | string assetID = rootE.GetAttribute("Asset"); | ||
1398 | |||
1399 | XmlNodeList stateL = rootE.GetElementsByTagName("ScriptState"); | ||
1400 | |||
1401 | if (stateL.Count != 1) | ||
1402 | return; | ||
1403 | |||
1404 | XmlElement stateE = (XmlElement)stateL[0]; | ||
1405 | |||
1406 | if (World.m_trustBinaries) | ||
1407 | { | ||
1408 | XmlNodeList assemL = rootE.GetElementsByTagName("Assembly"); | ||
1409 | |||
1410 | if (assemL.Count != 1) | ||
1411 | return; | ||
1412 | |||
1413 | XmlElement assemE = (XmlElement)assemL[0]; | ||
1414 | |||
1415 | string fn = assemE.GetAttribute("Filename"); | ||
1416 | string base64 = assemE.InnerText; | ||
1417 | |||
1418 | string path = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); | ||
1419 | path = Path.Combine(path, fn); | ||
1420 | |||
1421 | if (!File.Exists(path)) | ||
1422 | { | ||
1423 | Byte[] filedata = Convert.FromBase64String(base64); | ||
1424 | |||
1425 | FileStream fs = File.Create(path); | ||
1426 | fs.Write(filedata, 0, filedata.Length); | ||
1427 | fs.Close(); | ||
1428 | |||
1429 | fs = File.Create(path + ".text"); | ||
1430 | StreamWriter sw = new StreamWriter(fs); | ||
1431 | |||
1432 | sw.Write(base64); | ||
1433 | |||
1434 | sw.Close(); | ||
1435 | fs.Close(); | ||
1436 | } | ||
1437 | } | ||
1438 | |||
1439 | string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); | ||
1440 | statepath = Path.Combine(statepath, itemID.ToString() + ".state"); | ||
1441 | |||
1442 | FileStream sfs = File.Create(statepath); | ||
1443 | StreamWriter ssw = new StreamWriter(sfs); | ||
1444 | |||
1445 | ssw.Write(stateE.OuterXml); | ||
1446 | |||
1447 | ssw.Close(); | ||
1448 | sfs.Close(); | ||
1449 | |||
1450 | XmlNodeList mapL = rootE.GetElementsByTagName("LineMap"); | ||
1451 | |||
1452 | XmlElement mapE = (XmlElement)mapL[0]; | ||
1453 | |||
1454 | string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); | ||
1455 | mappath = Path.Combine(mappath, mapE.GetAttribute("Filename")); | ||
1456 | |||
1457 | FileStream mfs = File.Create(mappath); | ||
1458 | StreamWriter msw = new StreamWriter(mfs); | ||
1459 | |||
1460 | msw.Write(mapE.InnerText); | ||
1461 | |||
1462 | msw.Close(); | ||
1463 | mfs.Close(); | ||
1464 | } | ||
1277 | } | 1465 | } |
1278 | } | 1466 | } |