aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/world/World.cs
diff options
context:
space:
mode:
authorMW2007-03-08 13:21:24 +0000
committerMW2007-03-08 13:21:24 +0000
commitf60bc970eb925cd245cc77b1ae700b28d4589163 (patch)
treed279883582f00232bad87bf17e5727ff263027a4 /src/world/World.cs
parentBrought OGS.sql back into trunk (diff)
downloadopensim-SC_OLD-f60bc970eb925cd245cc77b1ae700b28d4589163.zip
opensim-SC_OLD-f60bc970eb925cd245cc77b1ae700b28d4589163.tar.gz
opensim-SC_OLD-f60bc970eb925cd245cc77b1ae700b28d4589163.tar.bz2
opensim-SC_OLD-f60bc970eb925cd245cc77b1ae700b28d4589163.tar.xz
Another attemp to fix the Session Logout bug
World map data is now saved in database and recovered on startup. Primitives are now backed up to a local database and reloaded on startup.
Diffstat (limited to 'src/world/World.cs')
-rw-r--r--src/world/World.cs115
1 files changed, 96 insertions, 19 deletions
diff --git a/src/world/World.cs b/src/world/World.cs
index f6f58c7..6be9dd2 100644
--- a/src/world/World.cs
+++ b/src/world/World.cs
@@ -3,12 +3,14 @@ using libsecondlife;
3using libsecondlife.Packets; 3using libsecondlife.Packets;
4using System.Collections.Generic; 4using System.Collections.Generic;
5using System.Text; 5using System.Text;
6using System.Reflection;
6using System.IO; 7using System.IO;
7using PhysicsSystem; 8using PhysicsSystem;
9using GridInterfaces;
8 10
9namespace OpenSim.world 11namespace OpenSim.world
10{ 12{
11 public class World 13 public class World : ILocalStorageReceiver
12 { 14 {
13 public Dictionary<libsecondlife.LLUUID, Entity> Entities; 15 public Dictionary<libsecondlife.LLUUID, Entity> Entities;
14 public float[] LandMap; 16 public float[] LandMap;
@@ -17,9 +19,10 @@ namespace OpenSim.world
17 private PhysicsScene phyScene; 19 private PhysicsScene phyScene;
18 private float timeStep= 0.1f; 20 private float timeStep= 0.1f;
19 private libsecondlife.TerrainManager TerrainManager; 21 private libsecondlife.TerrainManager TerrainManager;
20 22 public ILocalStorage localStorage;
21 private Random Rand = new Random(); 23 private Random Rand = new Random();
22 private uint _primCount = 702000; 24 private uint _primCount = 702000;
25 private int storageCount;
23 26
24 public World() 27 public World()
25 { 28 {
@@ -48,8 +51,7 @@ namespace OpenSim.world
48 51
49 public void Update() 52 public void Update()
50 { 53 {
51 54 if(this.phyScene.IsThreaded)
52 if(this.phyScene.IsThreaded)
53 { 55 {
54 this.phyScene.GetResults(); 56 this.phyScene.GetResults();
55 57
@@ -66,24 +68,95 @@ namespace OpenSim.world
66 { 68 {
67 Entities[UUID].update(); 69 Entities[UUID].update();
68 } 70 }
71
72 //backup world data
73 this.storageCount++;
74 if(storageCount> 1200) //set to how often you want to backup (currently set for about every 2 minutes)
75 {
76 this.Backup();
77 storageCount =0;
78 }
69 } 79 }
70 80
81 public bool LoadStorageDLL(string dllName)
82 {
83 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
84 ILocalStorage store = null;
85
86 foreach (Type pluginType in pluginAssembly.GetTypes())
87 {
88 if (pluginType.IsPublic)
89 {
90 if (!pluginType.IsAbstract)
91 {
92 Type typeInterface = pluginType.GetInterface("ILocalStorage", true);
93
94 if (typeInterface != null)
95 {
96 ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
97 store = plug;
98 break;
99 }
100
101 typeInterface = null;
102 }
103 }
104 }
105 pluginAssembly = null;
106 this.localStorage = store;
107 return(store == null);
108 }
109
110 public void LoadPrimsFromStorage()
111 {
112 ServerConsole.MainConsole.Instance.WriteLine("World.cs: LoadPrimsFromStorage() - Loading primitives");
113 this.localStorage.LoadPrimitives(this);
114 }
115
116 public void PrimFromStorage(PrimStorage prim)
117 {
118 if(prim.LocalID >= this._primCount)
119 {
120 _primCount = prim.LocalID + 1;
121 }
122 ServerConsole.MainConsole.Instance.WriteLine("World.cs: PrimFromStorage() - Reloading prim (localId "+ prim.LocalID+ " ) from storage");
123 Primitive nPrim = new Primitive();
124 nPrim.CreateFromStorage(prim);
125 this.Entities.Add(nPrim.uuid, nPrim);
126 }
127
128 public void Close()
129 {
130 this.localStorage.ShutDown();
131 }
132
71 public void SendLayerData(OpenSimClient RemoteClient) { 133 public void SendLayerData(OpenSimClient RemoteClient) {
72 int[] patches = new int[4]; 134 int[] patches = new int[4];
73 135
74 for (int y = 0; y < 16; y++) 136 for (int y = 0; y < 16; y++)
75 { 137 {
76 for (int x = 0; x < 16; x = x + 4) 138 for (int x = 0; x < 16; x = x + 4)
77 { 139 {
78 patches[0] = x + 0 + y * 16; 140 patches[0] = x + 0 + y * 16;
79 patches[1] = x + 1 + y * 16; 141 patches[1] = x + 1 + y * 16;
80 patches[2] = x + 2 + y * 16; 142 patches[2] = x + 2 + y * 16;
81 patches[3] = x + 3 + y * 16; 143 patches[3] = x + 3 + y * 16;
82 144
83 Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches); 145 Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches);
84 RemoteClient.OutPacket(layerpack); 146 RemoteClient.OutPacket(layerpack);
85 } 147 }
86 } 148 }
149 }
150
151 public void GetInitialPrims(OpenSimClient RemoteClient)
152 {
153 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
154 {
155 if(Entities[UUID].ToString()== "OpenSim.world.Primitive")
156 {
157 ((OpenSim.world.Primitive)Entities[UUID]).UpdateClient(RemoteClient);
158 }
159 }
87 } 160 }
88 161
89 public void AddViewerAgent(OpenSimClient AgentClient) { 162 public void AddViewerAgent(OpenSimClient AgentClient) {
@@ -96,7 +169,7 @@ namespace OpenSim.world
96 NewAvatar.PhysActor = this.phyScene.AddAvatar(new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z)); 169 NewAvatar.PhysActor = this.phyScene.AddAvatar(new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z));
97 //this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user 170 //this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user
98 this.Entities.Add(AgentClient.AgentID, NewAvatar); 171 this.Entities.Add(AgentClient.AgentID, NewAvatar);
99 } 172 }
100 173
101 public void AddNewPrim(ObjectAddPacket addPacket, OpenSimClient AgentClient) 174 public void AddNewPrim(ObjectAddPacket addPacket, OpenSimClient AgentClient)
102 { 175 {
@@ -109,8 +182,12 @@ namespace OpenSim.world
109 182
110 public bool Backup() { 183 public bool Backup() {
111 /* TODO: Save the current world entities state. */ 184 /* TODO: Save the current world entities state. */
112 185 ServerConsole.MainConsole.Instance.WriteLine("World.cs: Backup() - Backing up Primitives");
113 return false; 186 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
187 {
188 Entities[UUID].BackUp();
189 }
190 return true;
114 } 191 }
115 192
116 } 193 }