1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
|
/*
* 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 copyright
* 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.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Reflection;
using log4net;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Data.MSSQL
{
/// <summary>
/// A MSSQL Interface for the Region Server.
/// </summary>
public class MSSQLSimulationData : ISimulationDataStore
{
private const string _migrationStore = "RegionStore";
// private static FileSystemDataStore Instance = new FileSystemDataStore();
private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// The database manager
/// </summary>
private MSSQLManager _Database;
private string m_connectionString;
protected virtual Assembly Assembly
{
get { return GetType().Assembly; }
}
public MSSQLSimulationData()
{
}
public MSSQLSimulationData(string connectionString)
{
Initialise(connectionString);
}
/// <summary>
/// Initialises the region datastore
/// </summary>
/// <param name="connectionString">The connection string.</param>
public void Initialise(string connectionString)
{
m_connectionString = connectionString;
_Database = new MSSQLManager(connectionString);
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
//New Migration settings
Migration m = new Migration(conn, Assembly, "RegionStore");
m.Update();
}
}
/// <summary>
/// Dispose the database
/// </summary>
public void Dispose() { }
#region SceneObjectGroup region for loading and Store of the scene.
/// <summary>
/// Loads the objects present in the region.
/// </summary>
/// <param name="regionUUID">The region UUID.</param>
/// <returns></returns>
public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
{
UUID lastGroupID = UUID.Zero;
Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>();
Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
SceneObjectGroup grp = null;
string sql = "SELECT *, " +
"sort = CASE WHEN prims.UUID = prims.SceneGroupID THEN 0 ELSE 1 END " +
"FROM prims " +
"LEFT JOIN primshapes ON prims.UUID = primshapes.UUID " +
"WHERE RegionUUID = @RegionUUID " +
"ORDER BY SceneGroupID asc, sort asc, LinkNumber asc";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand command = new SqlCommand(sql, conn))
{
command.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
conn.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
SceneObjectPart sceneObjectPart = BuildPrim(reader);
if (reader["Shape"] is DBNull)
sceneObjectPart.Shape = PrimitiveBaseShape.Default;
else
sceneObjectPart.Shape = BuildShape(reader);
prims[sceneObjectPart.UUID] = sceneObjectPart;
UUID groupID = new UUID((Guid)reader["SceneGroupID"]);
if (groupID != lastGroupID) // New SOG
{
if (grp != null)
objects[grp.UUID] = grp;
lastGroupID = groupID;
// There sometimes exist OpenSim bugs that 'orphan groups' so that none of the prims are
// recorded as the root prim (for which the UUID must equal the persisted group UUID). In
// this case, force the UUID to be the same as the group UUID so that at least these can be
// deleted (we need to change the UUID so that any other prims in the linkset can also be
// deleted).
if (sceneObjectPart.UUID != groupID && groupID != UUID.Zero)
{
_Log.WarnFormat(
"[REGION DB]: Found root prim {0} {1} at {2} where group was actually {3}. Forcing UUID to group UUID",
sceneObjectPart.Name, sceneObjectPart.UUID, sceneObjectPart.GroupPosition, groupID);
sceneObjectPart.UUID = groupID;
}
grp = new SceneObjectGroup(sceneObjectPart);
}
else
{
// Black magic to preserve link numbers
// Why is this needed, fix this in AddPart method.
int link = sceneObjectPart.LinkNum;
grp.AddPart(sceneObjectPart);
if (link != 0)
sceneObjectPart.LinkNum = link;
}
}
}
}
if (grp != null)
objects[grp.UUID] = grp;
// Instead of attempting to LoadItems on every prim,
// most of which probably have no items... get a
// list from DB of all prims which have items and
// LoadItems only on those
List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
string qry = "select distinct primID from primitems";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand command = new SqlCommand(qry, conn))
{
conn.Open();
using (SqlDataReader itemReader = command.ExecuteReader())
{
while (itemReader.Read())
{
if (!(itemReader["primID"] is DBNull))
{
UUID primID = new UUID(itemReader["primID"].ToString());
if (prims.ContainsKey(primID))
{
primsWithInventory.Add(prims[primID]);
}
}
}
}
}
LoadItems(primsWithInventory);
_Log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
return new List<SceneObjectGroup>(objects.Values);
}
/// <summary>
/// Load in the prim's persisted inventory.
/// </summary>
/// <param name="allPrims">all prims with inventory on a region</param>
private void LoadItems(List<SceneObjectPart> allPrimsWithInventory)
{
string sql = "SELECT * FROM primitems WHERE PrimID = @PrimID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand command = new SqlCommand(sql, conn))
{
conn.Open();
foreach (SceneObjectPart objectPart in allPrimsWithInventory)
{
command.Parameters.Clear();
command.Parameters.Add(_Database.CreateParameter("@PrimID", objectPart.UUID));
List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
TaskInventoryItem item = BuildItem(reader);
item.ParentID = objectPart.UUID; // Values in database are
// often wrong
inventory.Add(item);
}
}
objectPart.Inventory.RestoreInventoryItems(inventory);
}
}
}
/// <summary>
/// Stores all object's details apart from inventory
/// </summary>
/// <param name="obj"></param>
/// <param name="regionUUID"></param>
public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
{
uint flags = obj.RootPart.GetEffectiveObjectFlags();
// Eligibility check
//
if ((flags & (uint)PrimFlags.Temporary) != 0)
return;
if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
return;
_Log.DebugFormat("[MSSQL]: Adding/Changing SceneObjectGroup: {0} to region: {1}, object has {2} prims.", obj.UUID, regionUUID, obj.Parts.Length);
using (SqlConnection conn = new SqlConnection(m_connectionString))
{
conn.Open();
SqlTransaction transaction = conn.BeginTransaction();
try
{
foreach (SceneObjectPart sceneObjectPart in obj.Parts)
{
//Update prim
using (SqlCommand sqlCommand = conn.CreateCommand())
{
sqlCommand.Transaction = transaction;
try
{
StoreSceneObjectPrim(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
}
catch (SqlException sqlEx)
{
_Log.ErrorFormat("[REGION DB]: Store SceneObjectPrim SQL error: {0} at line {1}", sqlEx.Message, sqlEx.LineNumber);
throw;
}
}
//Update primshapes
using (SqlCommand sqlCommand = conn.CreateCommand())
{
sqlCommand.Transaction = transaction;
try
{
StoreSceneObjectPrimShapes(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
}
catch (SqlException sqlEx)
{
_Log.ErrorFormat("[REGION DB]: Store SceneObjectPrimShapes SQL error: {0} at line {1}", sqlEx.Message, sqlEx.LineNumber);
throw;
}
}
}
transaction.Commit();
}
catch (Exception ex)
{
_Log.ErrorFormat("[REGION DB]: Store SceneObjectGroup error: {0}, Rolling back...", ex.Message);
try
{
transaction.Rollback();
}
catch (Exception ex2)
{
//Show error
_Log.InfoFormat("[REGION DB]: Rollback of SceneObjectGroup store transaction failed with error: {0}", ex2.Message);
}
}
}
}
/// <summary>
/// Stores the prim of the sceneobjectpart.
/// </summary>
/// <param name="sceneObjectPart">The sceneobjectpart or prim.</param>
/// <param name="sqlCommand">The SQL command with the transaction.</param>
/// <param name="sceneGroupID">The scenegroup UUID.</param>
/// <param name="regionUUID">The region UUID.</param>
private void StoreSceneObjectPrim(SceneObjectPart sceneObjectPart, SqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
{
//Big query to update or insert a new prim.
//Note for SQL Server 2008 this could be simplified
string queryPrims = @"
IF EXISTS (SELECT UUID FROM prims WHERE UUID = @UUID)
BEGIN
UPDATE prims SET
CreationDate = @CreationDate, Name = @Name, Text = @Text, Description = @Description, SitName = @SitName,
TouchName = @TouchName, ObjectFlags = @ObjectFlags, OwnerMask = @OwnerMask, NextOwnerMask = @NextOwnerMask, GroupMask = @GroupMask,
EveryoneMask = @EveryoneMask, BaseMask = @BaseMask, PositionX = @PositionX, PositionY = @PositionY, PositionZ = @PositionZ,
GroupPositionX = @GroupPositionX, GroupPositionY = @GroupPositionY, GroupPositionZ = @GroupPositionZ, VelocityX = @VelocityX,
VelocityY = @VelocityY, VelocityZ = @VelocityZ, AngularVelocityX = @AngularVelocityX, AngularVelocityY = @AngularVelocityY,
AngularVelocityZ = @AngularVelocityZ, AccelerationX = @AccelerationX, AccelerationY = @AccelerationY,
AccelerationZ = @AccelerationZ, RotationX = @RotationX, RotationY = @RotationY, RotationZ = @RotationZ, RotationW = @RotationW,
SitTargetOffsetX = @SitTargetOffsetX, SitTargetOffsetY = @SitTargetOffsetY, SitTargetOffsetZ = @SitTargetOffsetZ,
SitTargetOrientW = @SitTargetOrientW, SitTargetOrientX = @SitTargetOrientX, SitTargetOrientY = @SitTargetOrientY,
SitTargetOrientZ = @SitTargetOrientZ, RegionUUID = @RegionUUID, CreatorID = @CreatorID, OwnerID = @OwnerID, GroupID = @GroupID,
LastOwnerID = @LastOwnerID, SceneGroupID = @SceneGroupID, PayPrice = @PayPrice, PayButton1 = @PayButton1, PayButton2 = @PayButton2,
PayButton3 = @PayButton3, PayButton4 = @PayButton4, LoopedSound = @LoopedSound, LoopedSoundGain = @LoopedSoundGain,
TextureAnimation = @TextureAnimation, OmegaX = @OmegaX, OmegaY = @OmegaY, OmegaZ = @OmegaZ, CameraEyeOffsetX = @CameraEyeOffsetX,
CameraEyeOffsetY = @CameraEyeOffsetY, CameraEyeOffsetZ = @CameraEyeOffsetZ, CameraAtOffsetX = @CameraAtOffsetX,
CameraAtOffsetY = @CameraAtOffsetY, CameraAtOffsetZ = @CameraAtOffsetZ, ForceMouselook = @ForceMouselook,
ScriptAccessPin = @ScriptAccessPin, AllowedDrop = @AllowedDrop, DieAtEdge = @DieAtEdge, SalePrice = @SalePrice,
SaleType = @SaleType, ColorR = @ColorR, ColorG = @ColorG, ColorB = @ColorB, ColorA = @ColorA, ParticleSystem = @ParticleSystem,
ClickAction = @ClickAction, Material = @Material, CollisionSound = @CollisionSound, CollisionSoundVolume = @CollisionSoundVolume, PassTouches = @PassTouches,
LinkNumber = @LinkNumber, MediaURL = @MediaURL
WHERE UUID = @UUID
END
ELSE
BEGIN
INSERT INTO
prims (
UUID, CreationDate, Name, Text, Description, SitName, TouchName, ObjectFlags, OwnerMask, NextOwnerMask, GroupMask,
EveryoneMask, BaseMask, PositionX, PositionY, PositionZ, GroupPositionX, GroupPositionY, GroupPositionZ, VelocityX,
VelocityY, VelocityZ, AngularVelocityX, AngularVelocityY, AngularVelocityZ, AccelerationX, AccelerationY, AccelerationZ,
RotationX, RotationY, RotationZ, RotationW, SitTargetOffsetX, SitTargetOffsetY, SitTargetOffsetZ, SitTargetOrientW,
SitTargetOrientX, SitTargetOrientY, SitTargetOrientZ, RegionUUID, CreatorID, OwnerID, GroupID, LastOwnerID, SceneGroupID,
PayPrice, PayButton1, PayButton2, PayButton3, PayButton4, LoopedSound, LoopedSoundGain, TextureAnimation, OmegaX,
OmegaY, OmegaZ, CameraEyeOffsetX, CameraEyeOffsetY, CameraEyeOffsetZ, CameraAtOffsetX, CameraAtOffsetY, CameraAtOffsetZ,
ForceMouselook, ScriptAccessPin, AllowedDrop, DieAtEdge, SalePrice, SaleType, ColorR, ColorG, ColorB, ColorA,
ParticleSystem, ClickAction, Material, CollisionSound, CollisionSoundVolume, PassTouches, LinkNumber, MediaURL
) VALUES (
@UUID, @CreationDate, @Name, @Text, @Description, @SitName, @TouchName, @ObjectFlags, @OwnerMask, @NextOwnerMask, @GroupMask,
@EveryoneMask, @BaseMask, @PositionX, @PositionY, @PositionZ, @GroupPositionX, @GroupPositionY, @GroupPositionZ, @VelocityX,
@VelocityY, @VelocityZ, @AngularVelocityX, @AngularVelocityY, @AngularVelocityZ, @AccelerationX, @AccelerationY, @AccelerationZ,
@RotationX, @RotationY, @RotationZ, @RotationW, @SitTargetOffsetX, @SitTargetOffsetY, @SitTargetOffsetZ, @SitTargetOrientW,
@SitTargetOrientX, @SitTargetOrientY, @SitTargetOrientZ, @RegionUUID, @CreatorID, @OwnerID, @GroupID, @LastOwnerID, @SceneGroupID,
@PayPrice, @PayButton1, @PayButton2, @PayButton3, @PayButton4, @LoopedSound, @LoopedSoundGain, @TextureAnimation, @OmegaX,
@OmegaY, @OmegaZ, @CameraEyeOffsetX, @CameraEyeOffsetY, @CameraEyeOffsetZ, @CameraAtOffsetX, @CameraAtOffsetY, @CameraAtOffsetZ,
@ForceMouselook, @ScriptAccessPin, @AllowedDrop, @DieAtEdge, @SalePrice, @SaleType, @ColorR, @ColorG, @ColorB, @ColorA,
@ParticleSystem, @ClickAction, @Material, @CollisionSound, @CollisionSoundVolume, @PassTouches, @LinkNumber, @MediaURL
)
END";
//Set commandtext.
sqlCommand.CommandText = queryPrims;
//Add parameters
sqlCommand.Parameters.AddRange(CreatePrimParameters(sceneObjectPart, sceneGroupID, regionUUID));
//Execute the query. If it fails then error is trapped in calling function
sqlCommand.ExecuteNonQuery();
}
/// <summary>
/// Stores the scene object prim shapes.
/// </summary>
/// <param name="sceneObjectPart">The sceneobjectpart containing prim shape.</param>
/// <param name="sqlCommand">The SQL command with the transaction.</param>
/// <param name="sceneGroupID">The scenegroup UUID.</param>
/// <param name="regionUUID">The region UUID.</param>
private void StoreSceneObjectPrimShapes(SceneObjectPart sceneObjectPart, SqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
{
//Big query to or insert or update primshapes
//Note for SQL Server 2008 this can be simplified
string queryPrimShapes = @"
IF EXISTS (SELECT UUID FROM primshapes WHERE UUID = @UUID)
BEGIN
UPDATE primshapes SET
Shape = @Shape, ScaleX = @ScaleX, ScaleY = @ScaleY, ScaleZ = @ScaleZ, PCode = @PCode, PathBegin = @PathBegin,
PathEnd = @PathEnd, PathScaleX = @PathScaleX, PathScaleY = @PathScaleY, PathShearX = @PathShearX, PathShearY = @PathShearY,
PathSkew = @PathSkew, PathCurve = @PathCurve, PathRadiusOffset = @PathRadiusOffset, PathRevolutions = @PathRevolutions,
PathTaperX = @PathTaperX, PathTaperY = @PathTaperY, PathTwist = @PathTwist, PathTwistBegin = @PathTwistBegin,
ProfileBegin = @ProfileBegin, ProfileEnd = @ProfileEnd, ProfileCurve = @ProfileCurve, ProfileHollow = @ProfileHollow,
Texture = @Texture, ExtraParams = @ExtraParams, State = @State, Media = @Media
WHERE UUID = @UUID
END
ELSE
BEGIN
INSERT INTO
primshapes (
UUID, Shape, ScaleX, ScaleY, ScaleZ, PCode, PathBegin, PathEnd, PathScaleX, PathScaleY, PathShearX, PathShearY,
PathSkew, PathCurve, PathRadiusOffset, PathRevolutions, PathTaperX, PathTaperY, PathTwist, PathTwistBegin, ProfileBegin,
ProfileEnd, ProfileCurve, ProfileHollow, Texture, ExtraParams, State, Media
) VALUES (
@UUID, @Shape, @ScaleX, @ScaleY, @ScaleZ, @PCode, @PathBegin, @PathEnd, @PathScaleX, @PathScaleY, @PathShearX, @PathShearY,
@PathSkew, @PathCurve, @PathRadiusOffset, @PathRevolutions, @PathTaperX, @PathTaperY, @PathTwist, @PathTwistBegin, @ProfileBegin,
@ProfileEnd, @ProfileCurve, @ProfileHollow, @Texture, @ExtraParams, @State, @Media
)
END";
//Set commandtext.
sqlCommand.CommandText = queryPrimShapes;
//Add parameters
sqlCommand.Parameters.AddRange(CreatePrimShapeParameters(sceneObjectPart, sceneGroupID, regionUUID));
//Execute the query. If it fails then error is trapped in calling function
sqlCommand.ExecuteNonQuery();
}
/// <summary>
/// Removes a object from the database.
/// Meaning removing it from tables Prims, PrimShapes and PrimItems
/// </summary>
/// <param name="objectID">id of scenegroup</param>
/// <param name="regionUUID">regionUUID (is this used anyway</param>
public void RemoveObject(UUID objectID, UUID regionUUID)
{
_Log.InfoFormat("[MSSQL]: Removing obj: {0} from region: {1}", objectID, regionUUID);
//Remove from prims and primsitem table
string sqlPrims = "DELETE FROM PRIMS WHERE SceneGroupID = @objectID";
string sqlPrimItems = "DELETE FROM PRIMITEMS WHERE primID in (SELECT UUID FROM PRIMS WHERE SceneGroupID = @objectID)";
string sqlPrimShapes = "DELETE FROM PRIMSHAPES WHERE uuid in (SELECT UUID FROM PRIMS WHERE SceneGroupID = @objectID)";
lock (_Database)
{
//Using the non transaction mode.
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = sqlPrimShapes;
conn.Open();
cmd.Parameters.Add(_Database.CreateParameter("objectID", objectID));
cmd.ExecuteNonQuery();
cmd.CommandText = sqlPrimItems;
cmd.ExecuteNonQuery();
cmd.CommandText = sqlPrims;
cmd.ExecuteNonQuery();
}
}
}
/// <summary>
/// Store the inventory of a prim. Warning deletes everything first and then adds all again.
/// </summary>
/// <param name="primID"></param>
/// <param name="items"></param>
public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
{
//_Log.InfoFormat("[REGION DB: Persisting Prim Inventory with prim ID {0}", primID);
//Statement from MySQL section!
// For now, we're just going to crudely remove all the previous inventory items
// no matter whether they have changed or not, and replace them with the current set.
//Delete everything from PrimID
//TODO add index on PrimID in DB, if not already exist
string sql = "DELETE PRIMITEMS WHERE primID = @primID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@primID", primID));
conn.Open();
cmd.ExecuteNonQuery();
}
sql =
@"INSERT INTO primitems (
itemID,primID,assetID,parentFolderID,invType,assetType,name,description,creationDate,creatorID,ownerID,lastOwnerID,groupID,
nextPermissions,currentPermissions,basePermissions,everyonePermissions,groupPermissions,flags)
VALUES (@itemID,@primID,@assetID,@parentFolderID,@invType,@assetType,@name,@description,@creationDate,@creatorID,@ownerID,
@lastOwnerID,@groupID,@nextPermissions,@currentPermissions,@basePermissions,@everyonePermissions,@groupPermissions,@flags)";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
conn.Open();
foreach (TaskInventoryItem taskItem in items)
{
cmd.Parameters.AddRange(CreatePrimInventoryParameters(taskItem));
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
}
}
#endregion
/// <summary>
/// Loads the terrain map.
/// </summary>
/// <param name="regionID">regionID.</param>
/// <returns></returns>
public double[,] LoadTerrain(UUID regionID)
{
double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
terrain.Initialize();
string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// MySqlParameter param = new MySqlParameter();
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
int rev;
if (reader.Read())
{
MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]);
BinaryReader br = new BinaryReader(str);
for (int x = 0; x < (int)Constants.RegionSize; x++)
{
for (int y = 0; y < (int)Constants.RegionSize; y++)
{
terrain[x, y] = br.ReadDouble();
}
}
rev = (int)reader["Revision"];
}
else
{
_Log.Info("[REGION DB]: No terrain found for region");
return null;
}
_Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
}
}
return terrain;
}
/// <summary>
/// Stores the terrain map to DB.
/// </summary>
/// <param name="terrain">terrain map data.</param>
/// <param name="regionID">regionID.</param>
public void StoreTerrain(double[,] terrain, UUID regionID)
{
int revision = Util.UnixTimeSinceEpoch();
//Delete old terrain map
string sql = "delete from terrain where RegionUUID=@RegionUUID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
conn.Open();
cmd.ExecuteNonQuery();
}
sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision));
cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain)));
conn.Open();
cmd.ExecuteNonQuery();
}
_Log.Info("[REGION DB]: Stored terrain revision r " + revision);
}
/// <summary>
/// Loads all the land objects of a region.
/// </summary>
/// <param name="regionUUID">The region UUID.</param>
/// <returns></returns>
public List<LandData> LoadLandObjects(UUID regionUUID)
{
List<LandData> LandDataForRegion = new List<LandData>();
string sql = "select * from land where RegionUUID = @RegionUUID";
//Retrieve all land data from region
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionUUID));
conn.Open();
using (SqlDataReader readerLandData = cmd.ExecuteReader())
{
while (readerLandData.Read())
{
LandDataForRegion.Add(BuildLandData(readerLandData));
}
}
}
//Retrieve all accesslist data for all landdata
foreach (LandData LandData in LandDataForRegion)
{
sql = "select * from landaccesslist where LandUUID = @LandUUID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@LandUUID", LandData.GlobalID));
conn.Open();
using (SqlDataReader readerAccessList = cmd.ExecuteReader())
{
while (readerAccessList.Read())
{
LandData.ParcelAccessList.Add(BuildLandAccessData(readerAccessList));
}
}
}
}
//Return data
return LandDataForRegion;
}
/// <summary>
/// Stores land object with landaccess list.
/// </summary>
/// <param name="parcel">parcel data.</param>
public void StoreLandObject(ILandObject parcel)
{
//As this is only one record in land table I just delete all and then add a new record.
//As the delete landaccess is already in the mysql code
//Delete old values
RemoveLandObject(parcel.LandData.GlobalID);
//Insert new values
string sql = @"INSERT INTO [land]
([UUID],[RegionUUID],[LocalLandID],[Bitmap],[Name],[Description],[OwnerUUID],[IsGroupOwned],[Area],[AuctionID],[Category],[ClaimDate],[ClaimPrice],[GroupUUID],[SalePrice],[LandStatus],[LandFlags],[LandingType],[MediaAutoScale],[MediaTextureUUID],[MediaURL],[MusicURL],[PassHours],[PassPrice],[SnapshotUUID],[UserLocationX],[UserLocationY],[UserLocationZ],[UserLookAtX],[UserLookAtY],[UserLookAtZ],[AuthbuyerID],[OtherCleanTime])
VALUES
(@UUID,@RegionUUID,@LocalLandID,@Bitmap,@Name,@Description,@OwnerUUID,@IsGroupOwned,@Area,@AuctionID,@Category,@ClaimDate,@ClaimPrice,@GroupUUID,@SalePrice,@LandStatus,@LandFlags,@LandingType,@MediaAutoScale,@MediaTextureUUID,@MediaURL,@MusicURL,@PassHours,@PassPrice,@SnapshotUUID,@UserLocationX,@UserLocationY,@UserLocationZ,@UserLookAtX,@UserLookAtY,@UserLookAtZ,@AuthbuyerID,@OtherCleanTime)";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddRange(CreateLandParameters(parcel.LandData, parcel.RegionUUID));
conn.Open();
cmd.ExecuteNonQuery();
}
sql = "INSERT INTO [landaccesslist] ([LandUUID],[AccessUUID],[Flags],[Expires]) VALUES (@LandUUID,@AccessUUID,@Flags,@Expires)";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
conn.Open();
foreach (LandAccessEntry parcelAccessEntry in parcel.LandData.ParcelAccessList)
{
cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.RegionUUID));
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
}
}
/// <summary>
/// Removes a land object from DB.
/// </summary>
/// <param name="globalID">UUID of landobject</param>
public void RemoveLandObject(UUID globalID)
{
string sql = "delete from land where UUID=@UUID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
conn.Open();
cmd.ExecuteNonQuery();
}
sql = "delete from landaccesslist where LandUUID=@UUID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
conn.Open();
cmd.ExecuteNonQuery();
}
}
public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
{
RegionLightShareData nWP = new RegionLightShareData();
nWP.OnSave += StoreRegionWindlightSettings;
string sql = "select * from [regionwindlight] where region_id = @regionID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@regionID", regionUUID));
conn.Open();
using (SqlDataReader result = cmd.ExecuteReader())
{
if (!result.Read())
{
//No result, so store our default windlight profile and return it
nWP.regionID = regionUUID;
StoreRegionWindlightSettings(nWP);
return nWP;
}
else
{
nWP.regionID = DBGuid.FromDB(result["region_id"]);
nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]);
nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]);
nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]);
nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]);
nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]);
nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]);
nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]);
nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]);
nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]);
nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]);
nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]);
nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]);
nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]);
nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]);
nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]);
nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]);
nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]);
UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture);
nWP.horizon.X = Convert.ToSingle(result["horizon_r"]);
nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]);
nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]);
nWP.horizon.W = Convert.ToSingle(result["horizon_i"]);
nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]);
nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]);
nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]);
nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]);
nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]);
nWP.hazeDensity = Convert.ToSingle(result["haze_density"]);
nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]);
nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]);
nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]);
nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]);
nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]);
nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]);
nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]);
nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]);
nWP.ambient.X = Convert.ToSingle(result["ambient_r"]);
nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]);
nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]);
nWP.ambient.W = Convert.ToSingle(result["ambient_i"]);
nWP.eastAngle = Convert.ToSingle(result["east_angle"]);
nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]);
nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]);
nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]);
nWP.starBrightness = Convert.ToSingle(result["star_brightness"]);
nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]);
nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]);
nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]);
nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]);
nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]);
nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]);
nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]);
nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]);
nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]);
nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]);
nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]);
nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]);
nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]);
nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]);
nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]);
nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]);
nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]);
nWP.valid = true;
}
}
}
return nWP;
}
public void RemoveRegionWindlightSettings(UUID regionID)
{
string sql = "delete from [regionwindlight] where region_id = @region_id";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
conn.Open();
cmd.Parameters.Add(_Database.CreateParameter("@region_id", regionID));
cmd.ExecuteNonQuery();
}
}
public void StoreRegionWindlightSettings(RegionLightShareData wl)
{
string sql = "select count (region_id) from regionwindlight where region_id = @region_id";
bool exists = false;
using (SqlConnection conn = new SqlConnection(m_connectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@region_id", wl.regionID));
exists = (int)cmd.ExecuteScalar() > 0;
}
}
if (exists)
{
RemoveRegionWindlightSettings(wl.regionID);
}
// sql insert
sql = @"INSERT INTO [regionwindlight]
([region_id]
,[water_color_r]
,[water_color_g]
,[water_color_b]
,[water_fog_density_exponent]
,[underwater_fog_modifier]
,[reflection_wavelet_scale_1]
,[reflection_wavelet_scale_2]
,[reflection_wavelet_scale_3]
,[fresnel_scale]
,[fresnel_offset]
,[refract_scale_above]
,[refract_scale_below]
,[blur_multiplier]
,[big_wave_direction_x]
,[big_wave_direction_y]
,[little_wave_direction_x]
,[little_wave_direction_y]
,[normal_map_texture]
,[horizon_r]
,[horizon_g]
,[horizon_b]
,[horizon_i]
,[haze_horizon]
,[blue_density_r]
,[blue_density_g]
,[blue_density_b]
,[blue_density_i]
,[haze_density]
,[density_multiplier]
,[distance_multiplier]
,[max_altitude]
,[sun_moon_color_r]
,[sun_moon_color_g]
,[sun_moon_color_b]
,[sun_moon_color_i]
,[sun_moon_position]
,[ambient_r]
,[ambient_g]
,[ambient_b]
,[ambient_i]
,[east_angle]
,[sun_glow_focus]
,[sun_glow_size]
,[scene_gamma]
,[star_brightness]
,[cloud_color_r]
,[cloud_color_g]
,[cloud_color_b]
,[cloud_color_i]
,[cloud_x]
,[cloud_y]
,[cloud_density]
,[cloud_coverage]
,[cloud_scale]
,[cloud_detail_x]
,[cloud_detail_y]
,[cloud_detail_density]
,[cloud_scroll_x]
,[cloud_scroll_x_lock]
,[cloud_scroll_y]
,[cloud_scroll_y_lock]
,[draw_classic_clouds])
VALUES
(@region_id
,@water_color_r
,@water_color_g
,@water_color_b
,@water_fog_density_exponent
,@underwater_fog_modifier
,@reflection_wavelet_scale_1
,@reflection_wavelet_scale_2
,@reflection_wavelet_scale_3
,@fresnel_scale
,@fresnel_offset
,@refract_scale_above
,@refract_scale_below
,@blur_multiplier
,@big_wave_direction_x
,@big_wave_direction_y
,@little_wave_direction_x
,@little_wave_direction_y
,@normal_map_texture
,@horizon_r
,@horizon_g
,@horizon_b
,@horizon_i
,@haze_horizon
,@blue_density_r
,@blue_density_g
,@blue_density_b
,@blue_density_i
,@haze_density
,@density_multiplier
,@distance_multiplier
,@max_altitude
,@sun_moon_color_r
,@sun_moon_color_g
,@sun_moon_color_b
,@sun_moon_color_i
,@sun_moon_position
,@ambient_r
,@ambient_g
,@ambient_b
,@ambient_i
,@east_angle
,@sun_glow_focus
,@sun_glow_size
,@scene_gamma
,@star_brightness
,@cloud_color_r
,@cloud_color_g
,@cloud_color_b
,@cloud_color_i
,@cloud_x
,@cloud_y
,@cloud_density
,@cloud_coverage
,@cloud_scale
,@cloud_detail_x
,@cloud_detail_y
,@cloud_detail_density
,@cloud_scroll_x
,@cloud_scroll_x_lock
,@cloud_scroll_y
,@cloud_scroll_y_lock
,@draw_classic_clouds)";
using (SqlConnection conn = new SqlConnection(m_connectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("region_id", wl.regionID));
cmd.Parameters.Add(_Database.CreateParameter("water_color_r", wl.waterColor.X));
cmd.Parameters.Add(_Database.CreateParameter("water_color_g", wl.waterColor.Y));
cmd.Parameters.Add(_Database.CreateParameter("water_color_b", wl.waterColor.Z));
cmd.Parameters.Add(_Database.CreateParameter("water_fog_density_exponent", wl.waterFogDensityExponent));
cmd.Parameters.Add(_Database.CreateParameter("underwater_fog_modifier", wl.underwaterFogModifier));
cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X));
cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y));
cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z));
cmd.Parameters.Add(_Database.CreateParameter("fresnel_scale", wl.fresnelScale));
cmd.Parameters.Add(_Database.CreateParameter("fresnel_offset", wl.fresnelOffset));
cmd.Parameters.Add(_Database.CreateParameter("refract_scale_above", wl.refractScaleAbove));
cmd.Parameters.Add(_Database.CreateParameter("refract_scale_below", wl.refractScaleBelow));
cmd.Parameters.Add(_Database.CreateParameter("blur_multiplier", wl.blurMultiplier));
cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_x", wl.bigWaveDirection.X));
cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_y", wl.bigWaveDirection.Y));
cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_x", wl.littleWaveDirection.X));
cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_y", wl.littleWaveDirection.Y));
cmd.Parameters.Add(_Database.CreateParameter("normal_map_texture", wl.normalMapTexture));
cmd.Parameters.Add(_Database.CreateParameter("horizon_r", wl.horizon.X));
cmd.Parameters.Add(_Database.CreateParameter("horizon_g", wl.horizon.Y));
cmd.Parameters.Add(_Database.CreateParameter("horizon_b", wl.horizon.Z));
cmd.Parameters.Add(_Database.CreateParameter("horizon_i", wl.horizon.W));
cmd.Parameters.Add(_Database.CreateParameter("haze_horizon", wl.hazeHorizon));
cmd.Parameters.Add(_Database.CreateParameter("blue_density_r", wl.blueDensity.X));
cmd.Parameters.Add(_Database.CreateParameter("blue_density_g", wl.blueDensity.Y));
cmd.Parameters.Add(_Database.CreateParameter("blue_density_b", wl.blueDensity.Z));
cmd.Parameters.Add(_Database.CreateParameter("blue_density_i", wl.blueDensity.W));
cmd.Parameters.Add(_Database.CreateParameter("haze_density", wl.hazeDensity));
cmd.Parameters.Add(_Database.CreateParameter("density_multiplier", wl.densityMultiplier));
cmd.Parameters.Add(_Database.CreateParameter("distance_multiplier", wl.distanceMultiplier));
cmd.Parameters.Add(_Database.CreateParameter("max_altitude", wl.maxAltitude));
cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_r", wl.sunMoonColor.X));
cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_g", wl.sunMoonColor.Y));
cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_b", wl.sunMoonColor.Z));
cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_i", wl.sunMoonColor.W));
cmd.Parameters.Add(_Database.CreateParameter("sun_moon_position", wl.sunMoonPosition));
cmd.Parameters.Add(_Database.CreateParameter("ambient_r", wl.ambient.X));
cmd.Parameters.Add(_Database.CreateParameter("ambient_g", wl.ambient.Y));
cmd.Parameters.Add(_Database.CreateParameter("ambient_b", wl.ambient.Z));
cmd.Parameters.Add(_Database.CreateParameter("ambient_i", wl.ambient.W));
cmd.Parameters.Add(_Database.CreateParameter("east_angle", wl.eastAngle));
cmd.Parameters.Add(_Database.CreateParameter("sun_glow_focus", wl.sunGlowFocus));
cmd.Parameters.Add(_Database.CreateParameter("sun_glow_size", wl.sunGlowSize));
cmd.Parameters.Add(_Database.CreateParameter("scene_gamma", wl.sceneGamma));
cmd.Parameters.Add(_Database.CreateParameter("star_brightness", wl.starBrightness));
cmd.Parameters.Add(_Database.CreateParameter("cloud_color_r", wl.cloudColor.X));
cmd.Parameters.Add(_Database.CreateParameter("cloud_color_g", wl.cloudColor.Y));
cmd.Parameters.Add(_Database.CreateParameter("cloud_color_b", wl.cloudColor.Z));
cmd.Parameters.Add(_Database.CreateParameter("cloud_color_i", wl.cloudColor.W));
cmd.Parameters.Add(_Database.CreateParameter("cloud_x", wl.cloudXYDensity.X));
cmd.Parameters.Add(_Database.CreateParameter("cloud_y", wl.cloudXYDensity.Y));
cmd.Parameters.Add(_Database.CreateParameter("cloud_density", wl.cloudXYDensity.Z));
cmd.Parameters.Add(_Database.CreateParameter("cloud_coverage", wl.cloudCoverage));
cmd.Parameters.Add(_Database.CreateParameter("cloud_scale", wl.cloudScale));
cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_x", wl.cloudDetailXYDensity.X));
cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_y", wl.cloudDetailXYDensity.Y));
cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_density", wl.cloudDetailXYDensity.Z));
cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x", wl.cloudScrollX));
cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x_lock", wl.cloudScrollXLock));
cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y", wl.cloudScrollY));
cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y_lock", wl.cloudScrollYLock));
cmd.Parameters.Add(_Database.CreateParameter("draw_classic_clouds", wl.drawClassicClouds));
cmd.ExecuteNonQuery();
}
}
#region update
// }
// else
// {
// // sql update
// sql = @"UPDATE [OpenSim].[dbo].[regionwindlight]
// SET [region_id] = @region_id
// ,[water_color_r] = @water_color_r
// ,[water_color_g] = @water_color_g
// ,[water_color_b] = @water_color_b
// ,[water_fog_density_exponent] = @water_fog_density_exponent
// ,[underwater_fog_modifier] = @underwater_fog_modifier
// ,[reflection_wavelet_scale_1] = @reflection_wavelet_scale_1
// ,[reflection_wavelet_scale_2] = @reflection_wavelet_scale_2
// ,[reflection_wavelet_scale_3] = @reflection_wavelet_scale_3
// ,[fresnel_scale] = @fresnel_scale
// ,[fresnel_offset] = @fresnel_offset
// ,[refract_scale_above] = @refract_scale_above
// ,[refract_scale_below] = @refract_scale_below
// ,[blur_multiplier] = @blur_multiplier
// ,[big_wave_direction_x] = @big_wave_direction_x
// ,[big_wave_direction_y] = @big_wave_direction_y
// ,[little_wave_direction_x] = @little_wave_direction_x
// ,[little_wave_direction_y] = @little_wave_direction_y
// ,[normal_map_texture] = @normal_map_texture
// ,[horizon_r] = @horizon_r
// ,[horizon_g] = @horizon_g
// ,[horizon_b] = @horizon_b
// ,[horizon_i] = @horizon_i
// ,[haze_horizon] = @haze_horizon
// ,[blue_density_r] = @blue_density_r
// ,[blue_density_g] = @blue_density_g
// ,[blue_density_b] = @blue_density_b
// ,[blue_density_i] = @blue_density_i
// ,[haze_density] = @haze_density
// ,[density_multiplier] = @density_multiplier
// ,[distance_multiplier] = @distance_multiplier
// ,[max_altitude] = @max_altitude
// ,[sun_moon_color_r] = @sun_moon_color_r
// ,[sun_moon_color_g] = @sun_moon_color_g
// ,[sun_moon_color_b] = @sun_moon_color_b
// ,[sun_moon_color_i] = @sun_moon_color_i
// ,[sun_moon_position] = @sun_moon_position
// ,[ambient_r] = @ambient_r
// ,[ambient_g] = @ambient_g
// ,[ambient_b] = @ambient_b
// ,[ambient_i] = @ambient_i
// ,[east_angle] = @east_angle
// ,[sun_glow_focus] = @sun_glow_focus
// ,[sun_glow_size] = @sun_glow_size
// ,[scene_gamma] = @scene_gamma
// ,[star_brightness] = @star_brightness
// ,[cloud_color_r] = @cloud_color_r
// ,[cloud_color_g] = @cloud_color_g
// ,[cloud_color_b] = @cloud_color_b
// ,[cloud_color_i] = @cloud_color_i
// ,[cloud_x] = @cloud_x
// ,[cloud_y] = @cloud_y
// ,[cloud_density] = @cloud_density
// ,[cloud_coverage] = @cloud_coverage
// ,[cloud_scale] = @cloud_scale
// ,[cloud_detail_x] = @cloud_detail_x
// ,[cloud_detail_y] = @cloud_detail_y
// ,[cloud_detail_density] = @cloud_detail_density
// ,[cloud_scroll_x] = @cloud_scroll_x
// ,[cloud_scroll_x_lock] = @cloud_scroll_x_lock
// ,[cloud_scroll_y] = @cloud_scroll_y
// ,[cloud_scroll_y_lock] = @cloud_scroll_y_lock
// ,[draw_classic_clouds] = @draw_classic_clouds
// WHERE region_id = @region_id";
// using (SqlConnection conn = new SqlConnection(m_connectionString))
// {
// conn.Open();
// using (SqlCommand cmd = new SqlCommand(sql, conn))
// {
// cmd.Parameters.AddWithValue("region_id", wl.regionID);
// cmd.Parameters.AddWithValue("water_color_r", wl.waterColor.X);
// cmd.Parameters.AddWithValue("water_color_g", wl.waterColor.Y);
// cmd.Parameters.AddWithValue("water_color_b", wl.waterColor.Z);
// cmd.Parameters.AddWithValue("water_fog_density_exponent", wl.waterFogDensityExponent);
// cmd.Parameters.AddWithValue("underwater_fog_modifier", wl.underwaterFogModifier);
// cmd.Parameters.AddWithValue("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X);
// cmd.Parameters.AddWithValue("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y);
// cmd.Parameters.AddWithValue("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z);
// cmd.Parameters.AddWithValue("fresnel_scale", wl.fresnelScale);
// cmd.Parameters.AddWithValue("fresnel_offset", wl.fresnelOffset);
// cmd.Parameters.AddWithValue("refract_scale_above", wl.refractScaleAbove);
// cmd.Parameters.AddWithValue("refract_scale_below", wl.refractScaleBelow);
// cmd.Parameters.AddWithValue("blur_multiplier", wl.blurMultiplier);
// cmd.Parameters.AddWithValue("big_wave_direction_x", wl.bigWaveDirection.X);
// cmd.Parameters.AddWithValue("big_wave_direction_y", wl.bigWaveDirection.Y);
// cmd.Parameters.AddWithValue("little_wave_direction_x", wl.littleWaveDirection.X);
// cmd.Parameters.AddWithValue("little_wave_direction_y", wl.littleWaveDirection.Y);
// cmd.Parameters.AddWithValue("normal_map_texture", wl.normalMapTexture);
// cmd.Parameters.AddWithValue("horizon_r", wl.horizon.X);
// cmd.Parameters.AddWithValue("horizon_g", wl.horizon.Y);
// cmd.Parameters.AddWithValue("horizon_b", wl.horizon.Z);
// cmd.Parameters.AddWithValue("horizon_i", wl.horizon.W);
// cmd.Parameters.AddWithValue("haze_horizon", wl.hazeHorizon);
// cmd.Parameters.AddWithValue("blue_density_r", wl.blueDensity.X);
// cmd.Parameters.AddWithValue("blue_density_g", wl.blueDensity.Y);
// cmd.Parameters.AddWithValue("blue_density_b", wl.blueDensity.Z);
// cmd.Parameters.AddWithValue("blue_density_i", wl.blueDensity.W);
// cmd.Parameters.AddWithValue("haze_density", wl.hazeDensity);
// cmd.Parameters.AddWithValue("density_multiplier", wl.densityMultiplier);
// cmd.Parameters.AddWithValue("distance_multiplier", wl.distanceMultiplier);
// cmd.Parameters.AddWithValue("max_altitude", wl.maxAltitude);
// cmd.Parameters.AddWithValue("sun_moon_color_r", wl.sunMoonColor.X);
// cmd.Parameters.AddWithValue("sun_moon_color_g", wl.sunMoonColor.Y);
// cmd.Parameters.AddWithValue("sun_moon_color_b", wl.sunMoonColor.Z);
// cmd.Parameters.AddWithValue("sun_moon_color_i", wl.sunMoonColor.W);
// cmd.Parameters.AddWithValue("sun_moon_position", wl.sunMoonPosition);
// cmd.Parameters.AddWithValue("ambient_r", wl.ambient.X);
// cmd.Parameters.AddWithValue("ambient_g", wl.ambient.Y);
// cmd.Parameters.AddWithValue("ambient_b", wl.ambient.Z);
// cmd.Parameters.AddWithValue("ambient_i", wl.ambient.W);
// cmd.Parameters.AddWithValue("east_angle", wl.eastAngle);
// cmd.Parameters.AddWithValue("sun_glow_focus", wl.sunGlowFocus);
// cmd.Parameters.AddWithValue("sun_glow_size", wl.sunGlowSize);
// cmd.Parameters.AddWithValue("scene_gamma", wl.sceneGamma);
// cmd.Parameters.AddWithValue("star_brightness", wl.starBrightness);
// cmd.Parameters.AddWithValue("cloud_color_r", wl.cloudColor.X);
// cmd.Parameters.AddWithValue("cloud_color_g", wl.cloudColor.Y);
// cmd.Parameters.AddWithValue("cloud_color_b", wl.cloudColor.Z);
// cmd.Parameters.AddWithValue("cloud_color_i", wl.cloudColor.W);
// cmd.Parameters.AddWithValue("cloud_x", wl.cloudXYDensity.X);
// cmd.Parameters.AddWithValue("cloud_y", wl.cloudXYDensity.Y);
// cmd.Parameters.AddWithValue("cloud_density", wl.cloudXYDensity.Z);
// cmd.Parameters.AddWithValue("cloud_coverage", wl.cloudCoverage);
// cmd.Parameters.AddWithValue("cloud_scale", wl.cloudScale);
// cmd.Parameters.AddWithValue("cloud_detail_x", wl.cloudDetailXYDensity.X);
// cmd.Parameters.AddWithValue("cloud_detail_y", wl.cloudDetailXYDensity.Y);
// cmd.Parameters.AddWithValue("cloud_detail_density", wl.cloudDetailXYDensity.Z);
// cmd.Parameters.AddWithValue("cloud_scroll_x", wl.cloudScrollX);
// cmd.Parameters.AddWithValue("cloud_scroll_x_lock", wl.cloudScrollXLock);
// cmd.Parameters.AddWithValue("cloud_scroll_y", wl.cloudScrollY);
// cmd.Parameters.AddWithValue("cloud_scroll_y_lock", wl.cloudScrollYLock);
// cmd.Parameters.AddWithValue("draw_classic_clouds", wl.drawClassicClouds);
// cmd.ExecuteNonQuery();
// }
// }
// }
#endregion
}
#region Environment Settings
public string LoadRegionEnvironmentSettings(UUID regionUUID)
{
string sql = "select * from [regionenvironment] where region_id = @region_id";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@region_id", regionUUID));
conn.Open();
using (SqlDataReader result = cmd.ExecuteReader())
{
if (!result.Read())
{
return String.Empty;
}
else
{
return Convert.ToString(result["llsd_settings"]);
}
}
}
}
public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
{
{
string sql = "DELETE FROM [regionenvironment] WHERE region_id = @region_id";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@region_id", regionUUID));
conn.Open();
cmd.ExecuteNonQuery();
}
sql = "INSERT INTO [regionenvironment] (region_id, llsd_settings) VALUES (@region_id, @llsd_settings)";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@region_id", regionUUID));
cmd.Parameters.Add(_Database.CreateParameter("@llsd_settings", settings));
conn.Open();
cmd.ExecuteNonQuery();
}
}
}
public void RemoveRegionEnvironmentSettings(UUID regionUUID)
{
string sql = "delete from [regionenvironment] where region_id = @region_id";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@region_id", regionUUID));
conn.Open();
cmd.ExecuteNonQuery();
}
}
#endregion
/// <summary>
/// Loads the settings of a region.
/// </summary>
/// <param name="regionUUID">The region UUID.</param>
/// <returns></returns>
public RegionSettings LoadRegionSettings(UUID regionUUID)
{
string sql = "select * from regionsettings where regionUUID = @regionUUID";
RegionSettings regionSettings;
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
regionSettings = BuildRegionSettings(reader);
regionSettings.OnSave += StoreRegionSettings;
return regionSettings;
}
}
}
//If we reach this point then there are new region settings for that region
regionSettings = new RegionSettings();
regionSettings.RegionUUID = regionUUID;
regionSettings.OnSave += StoreRegionSettings;
//Store new values
StoreNewRegionSettings(regionSettings);
LoadSpawnPoints(regionSettings);
return regionSettings;
}
/// <summary>
/// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
/// </summary>
/// <param name="regionSettings">region settings.</param>
public void StoreRegionSettings(RegionSettings regionSettings)
{
//Little check if regionUUID already exist in DB
string regionUUID;
string sql = "SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID));
conn.Open();
regionUUID = cmd.ExecuteScalar().ToString();
}
if (string.IsNullOrEmpty(regionUUID))
{
StoreNewRegionSettings(regionSettings);
}
else
{
//This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
sql =
@"UPDATE [regionsettings] SET [block_terraform] = @block_terraform ,[block_fly] = @block_fly ,[allow_damage] = @allow_damage
,[restrict_pushing] = @restrict_pushing ,[allow_land_resell] = @allow_land_resell ,[allow_land_join_divide] = @allow_land_join_divide
,[block_show_in_search] = @block_show_in_search ,[agent_limit] = @agent_limit ,[object_bonus] = @object_bonus ,[maturity] = @maturity
,[disable_scripts] = @disable_scripts ,[disable_collisions] = @disable_collisions ,[disable_physics] = @disable_physics
,[terrain_texture_1] = @terrain_texture_1 ,[terrain_texture_2] = @terrain_texture_2 ,[terrain_texture_3] = @terrain_texture_3
,[terrain_texture_4] = @terrain_texture_4 ,[elevation_1_nw] = @elevation_1_nw ,[elevation_2_nw] = @elevation_2_nw
,[elevation_1_ne] = @elevation_1_ne ,[elevation_2_ne] = @elevation_2_ne ,[elevation_1_se] = @elevation_1_se ,[elevation_2_se] = @elevation_2_se
,[elevation_1_sw] = @elevation_1_sw ,[elevation_2_sw] = @elevation_2_sw ,[water_height] = @water_height ,[terrain_raise_limit] = @terrain_raise_limit
,[terrain_lower_limit] = @terrain_lower_limit ,[use_estate_sun] = @use_estate_sun ,[fixed_sun] = @fixed_sun ,[sun_position] = @sun_position
,[covenant] = @covenant ,[covenant_datetime] = @covenant_datetime, [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz, [Sandbox] = @Sandbox, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id, [map_tile_id] = @TerrainImageID, [telehubobject] = @telehubobject, [parcel_tile_id] = @ParcelImageID
WHERE [regionUUID] = @regionUUID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
conn.Open();
cmd.ExecuteNonQuery();
}
}
SaveSpawnPoints(regionSettings);
}
public void Shutdown()
{
//Not used??
}
#region Private Methods
/// <summary>
/// Serializes the terrain data for storage in DB.
/// </summary>
/// <param name="val">terrain data</param>
/// <returns></returns>
private static Array serializeTerrain(double[,] val)
{
MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
BinaryWriter bw = new BinaryWriter(str);
// TODO: COMPATIBILITY - Add byte-order conversions
for (int x = 0; x < (int)Constants.RegionSize; x++)
for (int y = 0; y < (int)Constants.RegionSize; y++)
{
double height = val[x, y];
if (height == 0.0)
height = double.Epsilon;
bw.Write(height);
}
return str.ToArray();
}
/// <summary>
/// Stores new regionsettings.
/// </summary>
/// <param name="regionSettings">The region settings.</param>
private void StoreNewRegionSettings(RegionSettings regionSettings)
{
string sql = @"INSERT INTO [regionsettings]
([regionUUID],[block_terraform],[block_fly],[allow_damage],[restrict_pushing],[allow_land_resell],[allow_land_join_divide],
[block_show_in_search],[agent_limit],[object_bonus],[maturity],[disable_scripts],[disable_collisions],[disable_physics],
[terrain_texture_1],[terrain_texture_2],[terrain_texture_3],[terrain_texture_4],[elevation_1_nw],[elevation_2_nw],[elevation_1_ne],
[elevation_2_ne],[elevation_1_se],[elevation_2_se],[elevation_1_sw],[elevation_2_sw],[water_height],[terrain_raise_limit],
[terrain_lower_limit],[use_estate_sun],[fixed_sun],[sun_position],[covenant],[covenant_datetime],[sunvectorx], [sunvectory], [sunvectorz],[Sandbox], [loaded_creation_datetime], [loaded_creation_id]
)
VALUES
(@regionUUID,@block_terraform,@block_fly,@allow_damage,@restrict_pushing,@allow_land_resell,@allow_land_join_divide,
@block_show_in_search,@agent_limit,@object_bonus,@maturity,@disable_scripts,@disable_collisions,@disable_physics,
@terrain_texture_1,@terrain_texture_2,@terrain_texture_3,@terrain_texture_4,@elevation_1_nw,@elevation_2_nw,@elevation_1_ne,
@elevation_2_ne,@elevation_1_se,@elevation_2_se,@elevation_1_sw,@elevation_2_sw,@water_height,@terrain_raise_limit,
@terrain_lower_limit,@use_estate_sun,@fixed_sun,@sun_position,@covenant, @covenant_datetime, @sunvectorx,@sunvectory, @sunvectorz, @Sandbox, @loaded_creation_datetime, @loaded_creation_id)";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
conn.Open();
cmd.ExecuteNonQuery();
}
}
#region Private DataRecord conversion methods
/// <summary>
/// Builds the region settings from a datarecod.
/// </summary>
/// <param name="row">datarecord with regionsettings.</param>
/// <returns></returns>
private static RegionSettings BuildRegionSettings(IDataRecord row)
{
//TODO change this is some more generic code so we doesnt have to change it every time a new field is added?
RegionSettings newSettings = new RegionSettings();
newSettings.RegionUUID = new UUID((Guid)row["regionUUID"]);
newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
newSettings.Maturity = Convert.ToInt32(row["maturity"]);
newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
newSettings.TerrainTexture1 = new UUID((Guid)row["terrain_texture_1"]);
newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]);
newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]);
newSettings.TerrainTexture4 = new UUID((Guid)row["terrain_texture_4"]);
newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
newSettings.Sandbox = Convert.ToBoolean(row["Sandbox"]);
newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
newSettings.SunVector = new Vector3(
Convert.ToSingle(row["sunvectorx"]),
Convert.ToSingle(row["sunvectory"]),
Convert.ToSingle(row["sunvectorz"])
);
newSettings.Covenant = new UUID((Guid)row["covenant"]);
newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
if (row["loaded_creation_id"] is DBNull)
newSettings.LoadedCreationID = "";
else
newSettings.LoadedCreationID = (String)row["loaded_creation_id"];
newSettings.TerrainImageID = new UUID((string)row["map_tile_ID"]);
newSettings.ParcelImageID = new UUID((Guid)row["parcel_tile_ID"]);
newSettings.TelehubObject = new UUID((Guid)row["TelehubObject"]);
return newSettings;
}
/// <summary>
/// Builds the land data from a datarecord.
/// </summary>
/// <param name="row">datarecord with land data</param>
/// <returns></returns>
private static LandData BuildLandData(IDataRecord row)
{
LandData newData = new LandData();
newData.GlobalID = new UUID((Guid)row["UUID"]);
newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
// Bitmap is a byte[512]
newData.Bitmap = (Byte[])row["Bitmap"];
newData.Name = (string)row["Name"];
newData.Description = (string)row["Description"];
newData.OwnerID = new UUID((Guid)row["OwnerUUID"]);
newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
newData.Area = Convert.ToInt32(row["Area"]);
newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
//Enum libsecondlife.Parcel.ParcelCategory
newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
newData.GroupID = new UUID((Guid)row["GroupUUID"]);
newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
//Enum. libsecondlife.Parcel.ParcelStatus
newData.Flags = Convert.ToUInt32(row["LandFlags"]);
newData.LandingType = Convert.ToByte(row["LandingType"]);
newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
newData.MediaID = new UUID((Guid)row["MediaTextureUUID"]);
newData.MediaURL = (string)row["MediaURL"];
newData.MusicURL = (string)row["MusicURL"];
newData.PassHours = Convert.ToSingle(row["PassHours"]);
newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
// UUID authedbuyer;
// UUID snapshotID;
//
// if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
// newData.AuthBuyerID = authedbuyer;
//
// if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
// newData.SnapshotID = snapshotID;
newData.AuthBuyerID = new UUID((Guid)row["AuthBuyerID"]);
newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
try
{
newData.UserLocation =
new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
Convert.ToSingle(row["UserLocationZ"]));
newData.UserLookAt =
new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
Convert.ToSingle(row["UserLookAtZ"]));
}
catch (InvalidCastException)
{
newData.UserLocation = Vector3.Zero;
newData.UserLookAt = Vector3.Zero;
_Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
}
newData.ParcelAccessList = new List<LandAccessEntry>();
newData.MediaDescription = (string)row["MediaDescription"];
newData.MediaType = (string)row["MediaType"];
newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]);
newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]);
newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
return newData;
}
/// <summary>
/// Builds the landaccess data from a data record.
/// </summary>
/// <param name="row">datarecord with landaccess data</param>
/// <returns></returns>
private static LandAccessEntry BuildLandAccessData(IDataRecord row)
{
LandAccessEntry entry = new LandAccessEntry();
entry.AgentID = new UUID((Guid)row["AccessUUID"]);
entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]);
entry.Expires = Convert.ToInt32(row["Expires"]);
return entry;
}
/// <summary>
/// Builds the prim from a datarecord.
/// </summary>
/// <param name="primRow">datarecord</param>
/// <returns></returns>
private static SceneObjectPart BuildPrim(IDataRecord primRow)
{
SceneObjectPart prim = new SceneObjectPart();
prim.UUID = new UUID((Guid)primRow["UUID"]);
// explicit conversion of integers is required, which sort
// of sucks. No idea if there is a shortcut here or not.
prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]);
prim.Name = (string)primRow["Name"];
// various text fields
prim.Text = (string)primRow["Text"];
prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]),
Convert.ToInt32(primRow["ColorR"]),
Convert.ToInt32(primRow["ColorG"]),
Convert.ToInt32(primRow["ColorB"]));
prim.Description = (string)primRow["Description"];
prim.SitName = (string)primRow["SitName"];
prim.TouchName = (string)primRow["TouchName"];
// permissions
prim.Flags = (PrimFlags)Convert.ToUInt32(primRow["ObjectFlags"]);
//prim.CreatorID = new UUID((Guid)primRow["CreatorID"]);
prim.CreatorIdentification = (string)primRow["CreatorID"];
prim.OwnerID = new UUID((Guid)primRow["OwnerID"]);
prim.GroupID = new UUID((Guid)primRow["GroupID"]);
prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]);
prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]);
prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]);
prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]);
prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]);
prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]);
// vectors
prim.OffsetPosition = new Vector3(
Convert.ToSingle(primRow["PositionX"]),
Convert.ToSingle(primRow["PositionY"]),
Convert.ToSingle(primRow["PositionZ"]));
prim.GroupPosition = new Vector3(
Convert.ToSingle(primRow["GroupPositionX"]),
Convert.ToSingle(primRow["GroupPositionY"]),
Convert.ToSingle(primRow["GroupPositionZ"]));
prim.Velocity = new Vector3(
Convert.ToSingle(primRow["VelocityX"]),
Convert.ToSingle(primRow["VelocityY"]),
Convert.ToSingle(primRow["VelocityZ"]));
prim.AngularVelocity = new Vector3(
Convert.ToSingle(primRow["AngularVelocityX"]),
Convert.ToSingle(primRow["AngularVelocityY"]),
Convert.ToSingle(primRow["AngularVelocityZ"]));
prim.Acceleration = new Vector3(
Convert.ToSingle(primRow["AccelerationX"]),
Convert.ToSingle(primRow["AccelerationY"]),
Convert.ToSingle(primRow["AccelerationZ"]));
// quaternions
prim.RotationOffset = new Quaternion(
Convert.ToSingle(primRow["RotationX"]),
Convert.ToSingle(primRow["RotationY"]),
Convert.ToSingle(primRow["RotationZ"]),
Convert.ToSingle(primRow["RotationW"]));
prim.SitTargetPositionLL = new Vector3(
Convert.ToSingle(primRow["SitTargetOffsetX"]),
Convert.ToSingle(primRow["SitTargetOffsetY"]),
Convert.ToSingle(primRow["SitTargetOffsetZ"]));
prim.SitTargetOrientationLL = new Quaternion(
Convert.ToSingle(primRow["SitTargetOrientX"]),
Convert.ToSingle(primRow["SitTargetOrientY"]),
Convert.ToSingle(primRow["SitTargetOrientZ"]),
Convert.ToSingle(primRow["SitTargetOrientW"]));
prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]);
prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]);
prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]);
prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]);
prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]);
prim.Sound = new UUID((Guid)primRow["LoopedSound"]);
prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]);
prim.SoundFlags = 1; // If it's persisted at all, it's looped
if (!(primRow["TextureAnimation"] is DBNull))
prim.TextureAnimation = (Byte[])primRow["TextureAnimation"];
if (!(primRow["ParticleSystem"] is DBNull))
prim.ParticleSystem = (Byte[])primRow["ParticleSystem"];
prim.AngularVelocity = new Vector3(
Convert.ToSingle(primRow["OmegaX"]),
Convert.ToSingle(primRow["OmegaY"]),
Convert.ToSingle(primRow["OmegaZ"]));
prim.SetCameraEyeOffset(new Vector3(
Convert.ToSingle(primRow["CameraEyeOffsetX"]),
Convert.ToSingle(primRow["CameraEyeOffsetY"]),
Convert.ToSingle(primRow["CameraEyeOffsetZ"])
));
prim.SetCameraAtOffset(new Vector3(
Convert.ToSingle(primRow["CameraAtOffsetX"]),
Convert.ToSingle(primRow["CameraAtOffsetY"]),
Convert.ToSingle(primRow["CameraAtOffsetZ"])
));
if (Convert.ToInt16(primRow["ForceMouselook"]) != 0)
prim.SetForceMouselook(true);
prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]);
if (Convert.ToInt16(primRow["AllowedDrop"]) != 0)
prim.AllowedDrop = true;
if (Convert.ToInt16(primRow["DieAtEdge"]) != 0)
prim.DIE_AT_EDGE = true;
prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]);
prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]);
prim.Material = Convert.ToByte(primRow["Material"]);
if (!(primRow["ClickAction"] is DBNull))
prim.ClickAction = Convert.ToByte(primRow["ClickAction"]);
prim.CollisionSound = new UUID((Guid)primRow["CollisionSound"]);
prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]);
if (Convert.ToInt16(primRow["PassTouches"]) != 0)
prim.PassTouches = true;
prim.LinkNum = Convert.ToInt32(primRow["LinkNumber"]);
if (!(primRow["MediaURL"] is System.DBNull))
prim.MediaUrl = (string)primRow["MediaURL"];
return prim;
}
/// <summary>
/// Builds the prim shape from a datarecord.
/// </summary>
/// <param name="shapeRow">The row.</param>
/// <returns></returns>
private static PrimitiveBaseShape BuildShape(IDataRecord shapeRow)
{
PrimitiveBaseShape baseShape = new PrimitiveBaseShape();
baseShape.Scale = new Vector3(
(float)Convert.ToDouble(shapeRow["ScaleX"]),
(float)Convert.ToDouble(shapeRow["ScaleY"]),
(float)Convert.ToDouble(shapeRow["ScaleZ"]));
// paths
baseShape.PCode = Convert.ToByte(shapeRow["PCode"]);
baseShape.PathBegin = Convert.ToUInt16(shapeRow["PathBegin"]);
baseShape.PathEnd = Convert.ToUInt16(shapeRow["PathEnd"]);
baseShape.PathScaleX = Convert.ToByte(shapeRow["PathScaleX"]);
baseShape.PathScaleY = Convert.ToByte(shapeRow["PathScaleY"]);
baseShape.PathShearX = Convert.ToByte(shapeRow["PathShearX"]);
baseShape.PathShearY = Convert.ToByte(shapeRow["PathShearY"]);
baseShape.PathSkew = Convert.ToSByte(shapeRow["PathSkew"]);
baseShape.PathCurve = Convert.ToByte(shapeRow["PathCurve"]);
baseShape.PathRadiusOffset = Convert.ToSByte(shapeRow["PathRadiusOffset"]);
baseShape.PathRevolutions = Convert.ToByte(shapeRow["PathRevolutions"]);
baseShape.PathTaperX = Convert.ToSByte(shapeRow["PathTaperX"]);
baseShape.PathTaperY = Convert.ToSByte(shapeRow["PathTaperY"]);
baseShape.PathTwist = Convert.ToSByte(shapeRow["PathTwist"]);
baseShape.PathTwistBegin = Convert.ToSByte(shapeRow["PathTwistBegin"]);
// profile
baseShape.ProfileBegin = Convert.ToUInt16(shapeRow["ProfileBegin"]);
baseShape.ProfileEnd = Convert.ToUInt16(shapeRow["ProfileEnd"]);
baseShape.ProfileCurve = Convert.ToByte(shapeRow["ProfileCurve"]);
baseShape.ProfileHollow = Convert.ToUInt16(shapeRow["ProfileHollow"]);
byte[] textureEntry = (byte[])shapeRow["Texture"];
baseShape.TextureEntry = textureEntry;
baseShape.ExtraParams = (byte[])shapeRow["ExtraParams"];
try
{
baseShape.State = Convert.ToByte(shapeRow["State"]);
}
catch (InvalidCastException)
{
}
if (!(shapeRow["Media"] is System.DBNull))
{
baseShape.Media = PrimitiveBaseShape.MediaList.FromXml((string)shapeRow["Media"]);
}
return baseShape;
}
/// <summary>
/// Build a prim inventory item from the persisted data.
/// </summary>
/// <param name="inventoryRow"></param>
/// <returns></returns>
private static TaskInventoryItem BuildItem(IDataRecord inventoryRow)
{
TaskInventoryItem taskItem = new TaskInventoryItem();
taskItem.ItemID = new UUID((Guid)inventoryRow["itemID"]);
taskItem.ParentPartID = new UUID((Guid)inventoryRow["primID"]);
taskItem.AssetID = new UUID((Guid)inventoryRow["assetID"]);
taskItem.ParentID = new UUID((Guid)inventoryRow["parentFolderID"]);
taskItem.InvType = Convert.ToInt32(inventoryRow["invType"]);
taskItem.Type = Convert.ToInt32(inventoryRow["assetType"]);
taskItem.Name = (string)inventoryRow["name"];
taskItem.Description = (string)inventoryRow["description"];
taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]);
//taskItem.CreatorID = new UUID((Guid)inventoryRow["creatorID"]);
taskItem.CreatorIdentification = (string)inventoryRow["creatorID"];
taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]);
taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]);
taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]);
taskItem.NextPermissions = Convert.ToUInt32(inventoryRow["nextPermissions"]);
taskItem.CurrentPermissions = Convert.ToUInt32(inventoryRow["currentPermissions"]);
taskItem.BasePermissions = Convert.ToUInt32(inventoryRow["basePermissions"]);
taskItem.EveryonePermissions = Convert.ToUInt32(inventoryRow["everyonePermissions"]);
taskItem.GroupPermissions = Convert.ToUInt32(inventoryRow["groupPermissions"]);
taskItem.Flags = Convert.ToUInt32(inventoryRow["flags"]);
return taskItem;
}
#endregion
#region Create parameters methods
/// <summary>
/// Creates the prim inventory parameters.
/// </summary>
/// <param name="taskItem">item in inventory.</param>
/// <returns></returns>
private SqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem)
{
List<SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(_Database.CreateParameter("itemID", taskItem.ItemID));
parameters.Add(_Database.CreateParameter("primID", taskItem.ParentPartID));
parameters.Add(_Database.CreateParameter("assetID", taskItem.AssetID));
parameters.Add(_Database.CreateParameter("parentFolderID", taskItem.ParentID));
parameters.Add(_Database.CreateParameter("invType", taskItem.InvType));
parameters.Add(_Database.CreateParameter("assetType", taskItem.Type));
parameters.Add(_Database.CreateParameter("name", taskItem.Name));
parameters.Add(_Database.CreateParameter("description", taskItem.Description));
parameters.Add(_Database.CreateParameter("creationDate", taskItem.CreationDate));
parameters.Add(_Database.CreateParameter("creatorID", taskItem.CreatorID));
parameters.Add(_Database.CreateParameter("ownerID", taskItem.OwnerID));
parameters.Add(_Database.CreateParameter("lastOwnerID", taskItem.LastOwnerID));
parameters.Add(_Database.CreateParameter("groupID", taskItem.GroupID));
parameters.Add(_Database.CreateParameter("nextPermissions", taskItem.NextPermissions));
parameters.Add(_Database.CreateParameter("currentPermissions", taskItem.CurrentPermissions));
parameters.Add(_Database.CreateParameter("basePermissions", taskItem.BasePermissions));
parameters.Add(_Database.CreateParameter("everyonePermissions", taskItem.EveryonePermissions));
parameters.Add(_Database.CreateParameter("groupPermissions", taskItem.GroupPermissions));
parameters.Add(_Database.CreateParameter("flags", taskItem.Flags));
return parameters.ToArray();
}
/// <summary>
/// Creates the region setting parameters.
/// </summary>
/// <param name="settings">regionsettings.</param>
/// <returns></returns>
private SqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
{
List<SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(_Database.CreateParameter("regionUUID", settings.RegionUUID));
parameters.Add(_Database.CreateParameter("block_terraform", settings.BlockTerraform));
parameters.Add(_Database.CreateParameter("block_fly", settings.BlockFly));
parameters.Add(_Database.CreateParameter("allow_damage", settings.AllowDamage));
parameters.Add(_Database.CreateParameter("restrict_pushing", settings.RestrictPushing));
parameters.Add(_Database.CreateParameter("allow_land_resell", settings.AllowLandResell));
parameters.Add(_Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide));
parameters.Add(_Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch));
parameters.Add(_Database.CreateParameter("agent_limit", settings.AgentLimit));
parameters.Add(_Database.CreateParameter("object_bonus", settings.ObjectBonus));
parameters.Add(_Database.CreateParameter("maturity", settings.Maturity));
parameters.Add(_Database.CreateParameter("disable_scripts", settings.DisableScripts));
parameters.Add(_Database.CreateParameter("disable_collisions", settings.DisableCollisions));
parameters.Add(_Database.CreateParameter("disable_physics", settings.DisablePhysics));
parameters.Add(_Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1));
parameters.Add(_Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2));
parameters.Add(_Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3));
parameters.Add(_Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4));
parameters.Add(_Database.CreateParameter("elevation_1_nw", settings.Elevation1NW));
parameters.Add(_Database.CreateParameter("elevation_2_nw", settings.Elevation2NW));
parameters.Add(_Database.CreateParameter("elevation_1_ne", settings.Elevation1NE));
parameters.Add(_Database.CreateParameter("elevation_2_ne", settings.Elevation2NE));
parameters.Add(_Database.CreateParameter("elevation_1_se", settings.Elevation1SE));
parameters.Add(_Database.CreateParameter("elevation_2_se", settings.Elevation2SE));
parameters.Add(_Database.CreateParameter("elevation_1_sw", settings.Elevation1SW));
parameters.Add(_Database.CreateParameter("elevation_2_sw", settings.Elevation2SW));
parameters.Add(_Database.CreateParameter("water_height", settings.WaterHeight));
parameters.Add(_Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit));
parameters.Add(_Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit));
parameters.Add(_Database.CreateParameter("use_estate_sun", settings.UseEstateSun));
parameters.Add(_Database.CreateParameter("Sandbox", settings.Sandbox));
parameters.Add(_Database.CreateParameter("fixed_sun", settings.FixedSun));
parameters.Add(_Database.CreateParameter("sun_position", settings.SunPosition));
parameters.Add(_Database.CreateParameter("sunvectorx", settings.SunVector.X));
parameters.Add(_Database.CreateParameter("sunvectory", settings.SunVector.Y));
parameters.Add(_Database.CreateParameter("sunvectorz", settings.SunVector.Z));
parameters.Add(_Database.CreateParameter("covenant", settings.Covenant));
parameters.Add(_Database.CreateParameter("covenant_datetime", settings.CovenantChangedDateTime));
parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime));
parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID));
parameters.Add(_Database.CreateParameter("TerrainImageID", settings.TerrainImageID));
parameters.Add(_Database.CreateParameter("ParcelImageID", settings.ParcelImageID));
parameters.Add(_Database.CreateParameter("TelehubObject", settings.TelehubObject));
return parameters.ToArray();
}
/// <summary>
/// Creates the land parameters.
/// </summary>
/// <param name="land">land parameters.</param>
/// <param name="regionUUID">region UUID.</param>
/// <returns></returns>
private SqlParameter[] CreateLandParameters(LandData land, UUID regionUUID)
{
List<SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(_Database.CreateParameter("UUID", land.GlobalID));
parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
parameters.Add(_Database.CreateParameter("LocalLandID", land.LocalID));
// Bitmap is a byte[512]
parameters.Add(_Database.CreateParameter("Bitmap", land.Bitmap));
parameters.Add(_Database.CreateParameter("Name", land.Name));
parameters.Add(_Database.CreateParameter("Description", land.Description));
parameters.Add(_Database.CreateParameter("OwnerUUID", land.OwnerID));
parameters.Add(_Database.CreateParameter("IsGroupOwned", land.IsGroupOwned));
parameters.Add(_Database.CreateParameter("Area", land.Area));
parameters.Add(_Database.CreateParameter("AuctionID", land.AuctionID)); //Unemplemented
parameters.Add(_Database.CreateParameter("Category", (int)land.Category)); //Enum libsecondlife.Parcel.ParcelCategory
parameters.Add(_Database.CreateParameter("ClaimDate", land.ClaimDate));
parameters.Add(_Database.CreateParameter("ClaimPrice", land.ClaimPrice));
parameters.Add(_Database.CreateParameter("GroupUUID", land.GroupID));
parameters.Add(_Database.CreateParameter("SalePrice", land.SalePrice));
parameters.Add(_Database.CreateParameter("LandStatus", (int)land.Status)); //Enum. libsecondlife.Parcel.ParcelStatus
parameters.Add(_Database.CreateParameter("LandFlags", land.Flags));
parameters.Add(_Database.CreateParameter("LandingType", land.LandingType));
parameters.Add(_Database.CreateParameter("MediaAutoScale", land.MediaAutoScale));
parameters.Add(_Database.CreateParameter("MediaTextureUUID", land.MediaID));
parameters.Add(_Database.CreateParameter("MediaURL", land.MediaURL));
parameters.Add(_Database.CreateParameter("MusicURL", land.MusicURL));
parameters.Add(_Database.CreateParameter("PassHours", land.PassHours));
parameters.Add(_Database.CreateParameter("PassPrice", land.PassPrice));
parameters.Add(_Database.CreateParameter("SnapshotUUID", land.SnapshotID));
parameters.Add(_Database.CreateParameter("UserLocationX", land.UserLocation.X));
parameters.Add(_Database.CreateParameter("UserLocationY", land.UserLocation.Y));
parameters.Add(_Database.CreateParameter("UserLocationZ", land.UserLocation.Z));
parameters.Add(_Database.CreateParameter("UserLookAtX", land.UserLookAt.X));
parameters.Add(_Database.CreateParameter("UserLookAtY", land.UserLookAt.Y));
parameters.Add(_Database.CreateParameter("UserLookAtZ", land.UserLookAt.Z));
parameters.Add(_Database.CreateParameter("AuthBuyerID", land.AuthBuyerID));
parameters.Add(_Database.CreateParameter("OtherCleanTime", land.OtherCleanTime));
return parameters.ToArray();
}
/// <summary>
/// Creates the land access parameters.
/// </summary>
/// <param name="parcelAccessEntry">parcel access entry.</param>
/// <param name="parcelID">parcel ID.</param>
/// <returns></returns>
private SqlParameter[] CreateLandAccessParameters(LandAccessEntry parcelAccessEntry, UUID parcelID)
{
List<SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(_Database.CreateParameter("LandUUID", parcelID));
parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID));
parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags));
parameters.Add(_Database.CreateParameter("Expires", parcelAccessEntry.Expires));
return parameters.ToArray();
}
/// <summary>
/// Creates the prim parameters for storing in DB.
/// </summary>
/// <param name="prim">Basic data of SceneObjectpart prim.</param>
/// <param name="sceneGroupID">The scenegroup ID.</param>
/// <param name="regionUUID">The region ID.</param>
/// <returns></returns>
private SqlParameter[] CreatePrimParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
{
List<SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
parameters.Add(_Database.CreateParameter("CreationDate", prim.CreationDate));
parameters.Add(_Database.CreateParameter("Name", prim.Name));
parameters.Add(_Database.CreateParameter("SceneGroupID", sceneGroupID));
// the UUID of the root part for this SceneObjectGroup
// various text fields
parameters.Add(_Database.CreateParameter("Text", prim.Text));
parameters.Add(_Database.CreateParameter("ColorR", prim.Color.R));
parameters.Add(_Database.CreateParameter("ColorG", prim.Color.G));
parameters.Add(_Database.CreateParameter("ColorB", prim.Color.B));
parameters.Add(_Database.CreateParameter("ColorA", prim.Color.A));
parameters.Add(_Database.CreateParameter("Description", prim.Description));
parameters.Add(_Database.CreateParameter("SitName", prim.SitName));
parameters.Add(_Database.CreateParameter("TouchName", prim.TouchName));
// permissions
parameters.Add(_Database.CreateParameter("ObjectFlags", (uint)prim.Flags));
parameters.Add(_Database.CreateParameter("CreatorID", prim.CreatorID));
parameters.Add(_Database.CreateParameter("OwnerID", prim.OwnerID));
parameters.Add(_Database.CreateParameter("GroupID", prim.GroupID));
parameters.Add(_Database.CreateParameter("LastOwnerID", prim.LastOwnerID));
parameters.Add(_Database.CreateParameter("OwnerMask", prim.OwnerMask));
parameters.Add(_Database.CreateParameter("NextOwnerMask", prim.NextOwnerMask));
parameters.Add(_Database.CreateParameter("GroupMask", prim.GroupMask));
parameters.Add(_Database.CreateParameter("EveryoneMask", prim.EveryoneMask));
parameters.Add(_Database.CreateParameter("BaseMask", prim.BaseMask));
// vectors
parameters.Add(_Database.CreateParameter("PositionX", prim.OffsetPosition.X));
parameters.Add(_Database.CreateParameter("PositionY", prim.OffsetPosition.Y));
parameters.Add(_Database.CreateParameter("PositionZ", prim.OffsetPosition.Z));
parameters.Add(_Database.CreateParameter("GroupPositionX", prim.GroupPosition.X));
parameters.Add(_Database.CreateParameter("GroupPositionY", prim.GroupPosition.Y));
parameters.Add(_Database.CreateParameter("GroupPositionZ", prim.GroupPosition.Z));
parameters.Add(_Database.CreateParameter("VelocityX", prim.Velocity.X));
parameters.Add(_Database.CreateParameter("VelocityY", prim.Velocity.Y));
parameters.Add(_Database.CreateParameter("VelocityZ", prim.Velocity.Z));
parameters.Add(_Database.CreateParameter("AngularVelocityX", prim.AngularVelocity.X));
parameters.Add(_Database.CreateParameter("AngularVelocityY", prim.AngularVelocity.Y));
parameters.Add(_Database.CreateParameter("AngularVelocityZ", prim.AngularVelocity.Z));
parameters.Add(_Database.CreateParameter("AccelerationX", prim.Acceleration.X));
parameters.Add(_Database.CreateParameter("AccelerationY", prim.Acceleration.Y));
parameters.Add(_Database.CreateParameter("AccelerationZ", prim.Acceleration.Z));
// quaternions
parameters.Add(_Database.CreateParameter("RotationX", prim.RotationOffset.X));
parameters.Add(_Database.CreateParameter("RotationY", prim.RotationOffset.Y));
parameters.Add(_Database.CreateParameter("RotationZ", prim.RotationOffset.Z));
parameters.Add(_Database.CreateParameter("RotationW", prim.RotationOffset.W));
// Sit target
Vector3 sitTargetPos = prim.SitTargetPositionLL;
parameters.Add(_Database.CreateParameter("SitTargetOffsetX", sitTargetPos.X));
parameters.Add(_Database.CreateParameter("SitTargetOffsetY", sitTargetPos.Y));
parameters.Add(_Database.CreateParameter("SitTargetOffsetZ", sitTargetPos.Z));
Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
parameters.Add(_Database.CreateParameter("SitTargetOrientW", sitTargetOrient.W));
parameters.Add(_Database.CreateParameter("SitTargetOrientX", sitTargetOrient.X));
parameters.Add(_Database.CreateParameter("SitTargetOrientY", sitTargetOrient.Y));
parameters.Add(_Database.CreateParameter("SitTargetOrientZ", sitTargetOrient.Z));
parameters.Add(_Database.CreateParameter("PayPrice", prim.PayPrice[0]));
parameters.Add(_Database.CreateParameter("PayButton1", prim.PayPrice[1]));
parameters.Add(_Database.CreateParameter("PayButton2", prim.PayPrice[2]));
parameters.Add(_Database.CreateParameter("PayButton3", prim.PayPrice[3]));
parameters.Add(_Database.CreateParameter("PayButton4", prim.PayPrice[4]));
if ((prim.SoundFlags & 1) != 0) // Looped
{
parameters.Add(_Database.CreateParameter("LoopedSound", prim.Sound));
parameters.Add(_Database.CreateParameter("LoopedSoundGain", prim.SoundGain));
}
else
{
parameters.Add(_Database.CreateParameter("LoopedSound", UUID.Zero));
parameters.Add(_Database.CreateParameter("LoopedSoundGain", 0.0f));
}
parameters.Add(_Database.CreateParameter("TextureAnimation", prim.TextureAnimation));
parameters.Add(_Database.CreateParameter("ParticleSystem", prim.ParticleSystem));
parameters.Add(_Database.CreateParameter("OmegaX", prim.AngularVelocity.X));
parameters.Add(_Database.CreateParameter("OmegaY", prim.AngularVelocity.Y));
parameters.Add(_Database.CreateParameter("OmegaZ", prim.AngularVelocity.Z));
parameters.Add(_Database.CreateParameter("CameraEyeOffsetX", prim.GetCameraEyeOffset().X));
parameters.Add(_Database.CreateParameter("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y));
parameters.Add(_Database.CreateParameter("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z));
parameters.Add(_Database.CreateParameter("CameraAtOffsetX", prim.GetCameraAtOffset().X));
parameters.Add(_Database.CreateParameter("CameraAtOffsetY", prim.GetCameraAtOffset().Y));
parameters.Add(_Database.CreateParameter("CameraAtOffsetZ", prim.GetCameraAtOffset().Z));
if (prim.GetForceMouselook())
parameters.Add(_Database.CreateParameter("ForceMouselook", 1));
else
parameters.Add(_Database.CreateParameter("ForceMouselook", 0));
parameters.Add(_Database.CreateParameter("ScriptAccessPin", prim.ScriptAccessPin));
if (prim.AllowedDrop)
parameters.Add(_Database.CreateParameter("AllowedDrop", 1));
else
parameters.Add(_Database.CreateParameter("AllowedDrop", 0));
if (prim.DIE_AT_EDGE)
parameters.Add(_Database.CreateParameter("DieAtEdge", 1));
else
parameters.Add(_Database.CreateParameter("DieAtEdge", 0));
parameters.Add(_Database.CreateParameter("SalePrice", prim.SalePrice));
parameters.Add(_Database.CreateParameter("SaleType", prim.ObjectSaleType));
byte clickAction = prim.ClickAction;
parameters.Add(_Database.CreateParameter("ClickAction", clickAction));
parameters.Add(_Database.CreateParameter("Material", prim.Material));
parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound));
parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume));
if (prim.PassTouches)
parameters.Add(_Database.CreateParameter("PassTouches", 1));
else
parameters.Add(_Database.CreateParameter("PassTouches", 0));
parameters.Add(_Database.CreateParameter("LinkNumber", prim.LinkNum));
parameters.Add(_Database.CreateParameter("MediaURL", prim.MediaUrl));
return parameters.ToArray();
}
/// <summary>
/// Creates the primshape parameters for stroing in DB.
/// </summary>
/// <param name="prim">Basic data of SceneObjectpart prim.</param>
/// <param name="sceneGroupID">The scene group ID.</param>
/// <param name="regionUUID">The region UUID.</param>
/// <returns></returns>
private SqlParameter[] CreatePrimShapeParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
{
List<SqlParameter> parameters = new List<SqlParameter>();
PrimitiveBaseShape s = prim.Shape;
parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
// shape is an enum
parameters.Add(_Database.CreateParameter("Shape", 0));
// vectors
parameters.Add(_Database.CreateParameter("ScaleX", s.Scale.X));
parameters.Add(_Database.CreateParameter("ScaleY", s.Scale.Y));
parameters.Add(_Database.CreateParameter("ScaleZ", s.Scale.Z));
// paths
parameters.Add(_Database.CreateParameter("PCode", s.PCode));
parameters.Add(_Database.CreateParameter("PathBegin", s.PathBegin));
parameters.Add(_Database.CreateParameter("PathEnd", s.PathEnd));
parameters.Add(_Database.CreateParameter("PathScaleX", s.PathScaleX));
parameters.Add(_Database.CreateParameter("PathScaleY", s.PathScaleY));
parameters.Add(_Database.CreateParameter("PathShearX", s.PathShearX));
parameters.Add(_Database.CreateParameter("PathShearY", s.PathShearY));
parameters.Add(_Database.CreateParameter("PathSkew", s.PathSkew));
parameters.Add(_Database.CreateParameter("PathCurve", s.PathCurve));
parameters.Add(_Database.CreateParameter("PathRadiusOffset", s.PathRadiusOffset));
parameters.Add(_Database.CreateParameter("PathRevolutions", s.PathRevolutions));
parameters.Add(_Database.CreateParameter("PathTaperX", s.PathTaperX));
parameters.Add(_Database.CreateParameter("PathTaperY", s.PathTaperY));
parameters.Add(_Database.CreateParameter("PathTwist", s.PathTwist));
parameters.Add(_Database.CreateParameter("PathTwistBegin", s.PathTwistBegin));
// profile
parameters.Add(_Database.CreateParameter("ProfileBegin", s.ProfileBegin));
parameters.Add(_Database.CreateParameter("ProfileEnd", s.ProfileEnd));
parameters.Add(_Database.CreateParameter("ProfileCurve", s.ProfileCurve));
parameters.Add(_Database.CreateParameter("ProfileHollow", s.ProfileHollow));
parameters.Add(_Database.CreateParameter("Texture", s.TextureEntry));
parameters.Add(_Database.CreateParameter("ExtraParams", s.ExtraParams));
parameters.Add(_Database.CreateParameter("State", s.State));
if (null == s.Media)
{
parameters.Add(_Database.CreateParameter("Media", DBNull.Value));
}
else
{
parameters.Add(_Database.CreateParameter("Media", s.Media.ToXml()));
}
return parameters.ToArray();
}
#endregion
#endregion
private void LoadSpawnPoints(RegionSettings rs)
{
rs.ClearSpawnPoints();
string sql = "SELECT Yaw, Pitch, Distance FROM spawn_points WHERE RegionUUID = @RegionUUID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", rs.RegionUUID.ToString()));
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
SpawnPoint sp = new SpawnPoint();
sp.Yaw = (float)reader["Yaw"];
sp.Pitch = (float)reader["Pitch"];
sp.Distance = (float)reader["Distance"];
rs.AddSpawnPoint(sp);
}
}
}
}
private void SaveSpawnPoints(RegionSettings rs)
{
string sql = "DELETE FROM spawn_points WHERE RegionUUID = @RegionUUID";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", rs.RegionUUID));
conn.Open();
cmd.ExecuteNonQuery();
}
foreach (SpawnPoint p in rs.SpawnPoints())
{
sql = "INSERT INTO spawn_points (RegionUUID, Yaw, Pitch, Distance) VALUES (@RegionUUID, @Yaw, @Pitch, @Distance)";
using (SqlConnection conn = new SqlConnection(m_connectionString))
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", rs.RegionUUID));
cmd.Parameters.Add(_Database.CreateParameter("@Yaw", p.Yaw));
cmd.Parameters.Add(_Database.CreateParameter("@Pitch", p.Pitch));
cmd.Parameters.Add(_Database.CreateParameter("@Distance", p.Distance));
conn.Open();
cmd.ExecuteNonQuery();
}
}
}
public UUID[] GetObjectIDs(UUID regionID)
{
return new UUID[0];
}
}
}
|