aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorcw2007-01-31 22:09:20 +0000
committercw2007-01-31 22:09:20 +0000
commita82950672860eedeaa23da75421c74e094b5c0a4 (patch)
tree6901851f8e1de03d5eadfbe05e03563126b879a2
downloadopensim-SC-a82950672860eedeaa23da75421c74e094b5c0a4.zip
opensim-SC-a82950672860eedeaa23da75421c74e094b5c0a4.tar.gz
opensim-SC-a82950672860eedeaa23da75421c74e094b5c0a4.tar.bz2
opensim-SC-a82950672860eedeaa23da75421c74e094b5c0a4.tar.xz
Making trunk; applying appropriate license to each file
-rw-r--r--Agent_Manager.cs618
-rw-r--r--AssemblyInfo.cs59
-rw-r--r--Asset_manager.cs167
-rw-r--r--Class1.cs23
-rw-r--r--Login_manager.cs163
-rw-r--r--Main-sever.Designer.cs80
-rw-r--r--Main-sever.cs270
-rw-r--r--Main-sever.resx123
-rw-r--r--Physics_manager.cs43
-rw-r--r--Prim_manager.cs310
-rw-r--r--Script_manager.cs89
-rw-r--r--Second-server.csproj62
-rw-r--r--Second-server.sln17
-rw-r--r--Server.cs756
-rw-r--r--Texture_manager.cs219
15 files changed, 2999 insertions, 0 deletions
diff --git a/Agent_Manager.cs b/Agent_Manager.cs
new file mode 100644
index 0000000..934fb57
--- /dev/null
+++ b/Agent_Manager.cs
@@ -0,0 +1,618 @@
1/*
2Copyright (c) 2007 Michael Wright
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*/
26
27using System;
28using System.Collections.Generic;
29using libsecondlife;
30using libsecondlife.Packets;
31using libsecondlife.AssetSystem;
32using System.IO;
33using Axiom.MathLib;
34
35namespace Second_server
36{
37 /// <summary>
38 /// Description of Agent_Manager.
39 /// </summary>
40 public class Agent_Manager
41 {
42 public Dictionary<libsecondlife.LLUUID,Avatar_data> Agent_list;
43 //public uint number_agents=0;
44 private uint local_numer=0;
45 private Server server;
46 public Prim_manager prim_man;
47 private byte [] data1;
48
49 private libsecondlife.Packets.RegionHandshakePacket reg;
50 private System.Text.Encoding enc = System.Text.Encoding.ASCII;
51 public libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock avatar_template;
52 //private int appc=0;
53
54 public Agent_Manager(Server serve)
55 {
56 Agent_list=new Dictionary<libsecondlife.LLUUID,Avatar_data>();
57 server=serve;
58 this.initialise();
59 }
60 //***************************************************
61 public Avatar_data Get_Agent(LLUUID id)
62 {
63
64
65 if(!this.Agent_list.ContainsKey(id))
66 {
67 return null;
68 }
69 else
70 {
71 Avatar_data ad=this.Agent_list[id];
72 return ad;
73 }
74 }
75
76 public void Add_Agent(Avatar_data agent)
77 {
78 this.Agent_list.Add(agent.Full_ID,agent);
79 }
80
81 public bool New_Agent(User_Agent_info User_info)
82 {
83 Avatar_data ad=new Avatar_data();
84 ad.Full_ID=User_info.AgentID;
85 ad.Net_info=User_info;
86 ad.pos=new LLVector3(100,100,22);
87 this.Agent_list.Add(ad.Full_ID,ad);
88 return(true);
89 }
90
91 public void Agent_join(User_Agent_info User_info)
92 {
93 //send region data
94 server.SendPacket(reg,true,User_info);
95
96 //inform client of join comlete
97 libsecondlife.Packets.AgentMovementCompletePacket mov=new AgentMovementCompletePacket();
98 mov.AgentData.SessionID=User_info.SessionID;
99 mov.AgentData.AgentID=User_info.AgentID;
100 mov.Data.RegionHandle=1096213093147648;
101 mov.Data.Timestamp=1169838966;
102 mov.Data.Position=new LLVector3(100f,100f,22f);
103 mov.Data.LookAt=new LLVector3(0.99f,0.042f,0);
104 server.SendPacket(mov,true,User_info);
105 }
106 public void tick()
107 {
108 //update positions
109 foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list)
110 {
111
112 kp.Value.pos.X+=(kp.Value.vel.X*0.2f);
113 kp.Value.pos.Y+=(kp.Value.vel.Y*0.2f);
114 kp.Value.pos.Z+=(kp.Value.vel.Z*0.2f);
115 }
116 }
117 //**************************************************************
118 private void initialise()
119 {
120 //Region data
121 reg=new RegionHandshakePacket();
122 reg.RegionInfo.BillableFactor=0;
123 reg.RegionInfo.IsEstateManager=false;
124 reg.RegionInfo.TerrainHeightRange00=60;
125 reg.RegionInfo.TerrainHeightRange01=60;
126 reg.RegionInfo.TerrainHeightRange10=60;
127 reg.RegionInfo.TerrainHeightRange11=60;
128 reg.RegionInfo.TerrainStartHeight00=20;
129 reg.RegionInfo.TerrainStartHeight01=20;
130 reg.RegionInfo.TerrainStartHeight10=20;
131 reg.RegionInfo.TerrainStartHeight11=20;
132 reg.RegionInfo.SimAccess=13;
133 reg.RegionInfo.WaterHeight=5;
134 reg.RegionInfo.RegionFlags=72458694;
135 reg.RegionInfo.SimName=enc.GetBytes( "Test Sandbox\0");
136 reg.RegionInfo.SimOwner=new LLUUID("00000000-0000-0000-0000-000000000000");
137 reg.RegionInfo.TerrainBase0=new LLUUID("b8d3965a-ad78-bf43-699b-bff8eca6c975");
138 reg.RegionInfo.TerrainBase1=new LLUUID("abb783e6-3e93-26c0-248a-247666855da3");
139 reg.RegionInfo.TerrainBase2=new LLUUID("179cdabd-398a-9b6b-1391-4dc333ba321f");
140 reg.RegionInfo.TerrainBase3=new LLUUID("beb169c7-11ea-fff2-efe5-0f24dc881df2");
141 reg.RegionInfo.TerrainDetail0=new LLUUID("00000000-0000-0000-0000-000000000000");
142 reg.RegionInfo.TerrainDetail1=new LLUUID("00000000-0000-0000-0000-000000000000");
143 reg.RegionInfo.TerrainDetail2=new LLUUID("00000000-0000-0000-0000-000000000000");
144 reg.RegionInfo.TerrainDetail3=new LLUUID("00000000-0000-0000-0000-000000000000");
145 reg.RegionInfo.CacheID=new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab33");
146
147 this.setuptemplate("objectupate168.dat");
148 }
149
150 public void setuptemplate(string name)
151 {
152 /*ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
153 objupdate.RegionData.RegionHandle=1096213093147648;
154 objupdate.RegionData.TimeDilation=64096;
155 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
156 */
157 int i=0;
158 FileInfo fInfo = new FileInfo(name);
159
160 long numBytes = fInfo.Length;
161
162 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
163
164 BinaryReader br = new BinaryReader(fStream);
165
166 byte [] data1 = br.ReadBytes((int)numBytes);
167
168 br.Close();
169
170 fStream.Close();
171
172 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1,ref i);
173
174 //objupdate.ObjectData[0]=objdata;
175
176 System.Text.Encoding enc = System.Text.Encoding.ASCII;
177 libsecondlife.LLVector3 pos=new LLVector3(objdata.ObjectData, 16);
178 pos.X=100f;
179 objdata.ID=8880000;
180 objdata.NameValue=enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
181 libsecondlife.LLVector3 pos2=new LLVector3(13.981f,100.0f,20.0f);
182 //objdata.FullID=user.AgentID;
183 byte[] pb=pos.GetBytes();
184
185 Array.Copy(pb,0,objdata.ObjectData,16,pb.Length);
186
187 avatar_template=objdata;
188
189 }
190 //**********************************************************
191 public void send_intial_data(User_Agent_info User_info)
192 {
193
194 //shouldn't really have to read all this in from disk for every new client?
195 string data_path=System.Windows.Forms.Application.StartupPath + @"\layer_data\";
196
197 //send layerdata
198 LayerDataPacket layerpack=new LayerDataPacket();
199 layerpack.LayerID.Type=76;
200 //layerpack.LayerData.ReadfromFile(data_path+@"layerdata0.dat");
201 this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata0.dat");
202
203 //server.SendPacket(layerpack,true,User_info);
204
205 LayerDataPacket layerpack1=new LayerDataPacket();
206 layerpack1.LayerID.Type=76;
207 //layerpack1.LayerData.ReadfromFile(data_path+@"layerdata1.dat");
208 this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata1.dat");
209 //server.SendPacket(layerpack1,true,User_info);
210
211 LayerDataPacket layerpack2=new LayerDataPacket();
212 layerpack2.LayerID.Type=56;
213 //layerpack2.LayerData.ReadfromFile(data_path+@"layerdata2.dat");
214 this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata2.dat");
215 //server.SendPacket(layerpack2,true,User_info);
216
217 LayerDataPacket layerpack3=new LayerDataPacket();
218 layerpack3.LayerID.Type=55;
219 //layerpack3.LayerData.ReadfromFile(data_path+@"layerdata3.dat");
220 this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata3.dat");
221 //server.SendPacket(layerpack3,true,User_info);
222
223 LayerDataPacket layerpack4=new LayerDataPacket();
224 layerpack4.LayerID.Type=56;
225 //layerpack4.LayerData.ReadfromFile(data_path+@"layerdata4.dat");
226 this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata4.dat");
227 //server.SendPacket(layerpack4,true,User_info);
228
229 LayerDataPacket layerpack5=new LayerDataPacket();
230 layerpack5.LayerID.Type=55;
231 //layerpack5.LayerData.ReadfromFile(data_path+@"layerdata5.dat");
232 this.read_layerdata(User_info,ref layerpack,data_path+@"layerdata5.dat");
233 //server.SendPacket(layerpack5,true,User_info);
234
235
236 //send intial set of captured prims data?
237 this.prim_man.Read_Prim_database( "objectdatabase.ini",User_info);
238
239 //send prims that have been created by users
240 //prim_man.send_existing_prims(User_info);
241
242 //send update about clients avatar
243 this.send_intial_avatar_position(User_info);
244
245 //send updates about all other users
246 //this.send_test_avatar_position(User_info);
247 foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list)
248 {
249 if(kp.Value.Net_info.AgentID!=User_info.AgentID)
250 {
251 this.send_other_avatar_position(User_info,kp.Value);
252 }
253 }
254
255
256 }
257 public void send_intial_avatar_position(User_Agent_info User_info)
258 {
259 //send a objectupdate packet with information about the clients avatar
260 ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
261 objupdate.RegionData.RegionHandle=1096213093147648;
262 objupdate.RegionData.TimeDilation=64096;
263 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
264
265 objupdate.ObjectData[0]=avatar_template;
266 //give this avatar object a local id and assign the user a name
267 objupdate.ObjectData[0].ID=8880000+this.local_numer;
268 User_info.localID=objupdate.ObjectData[0].ID;
269 //User_info.name="Test"+this.local_numer+" User";
270 this.Get_Agent(User_info.AgentID).started=true;
271 objupdate.ObjectData[0].FullID=User_info.AgentID;
272 objupdate.ObjectData[0].NameValue=enc.GetBytes("FirstName STRING RW SV Test"+ this.local_numer+"\nLastName STRING RW SV User \0");
273 User_info.name="FirstName STRING RW SV Test"+ this.local_numer+"\nLastName STRING RW SV User \0";
274 User_info.last_name="User";
275 User_info.first_name="Test"+this.local_numer;
276 libsecondlife.LLVector3 pos2=new LLVector3(100f,100.0f,22.0f);
277
278 byte[] pb=pos2.GetBytes();
279
280 Array.Copy(pb,0,objupdate.ObjectData[0].ObjectData,16,pb.Length);
281 this.local_numer++;
282
283 server.SendPacket(objupdate,true,User_info);
284
285 //send this info to other existing clients
286 foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list)
287 {
288 if(kp.Value.Net_info.AgentID!=User_info.AgentID)
289 {
290 server.SendPacket(objupdate,true,kp.Value.Net_info);
291 this.send_other_apper(kp.Value.Net_info,objupdate.ObjectData[0].FullID);
292 }
293 }
294
295 }
296 public void send_intial_avatar_apper(User_Agent_info user)
297 {
298
299 //seems that we don't send a avatarapperance for ourself.
300 /*AvatarAppearancePacket avp=new AvatarAppearancePacket();
301
302 avp.VisualParam=new AvatarAppearancePacket.VisualParamBlock[218];
303 avp.ObjectData.TextureEntry=this.avatar_template.TextureEntry;// br.ReadBytes((int)numBytes);
304
305 AvatarAppearancePacket.VisualParamBlock avblock=null;
306 for(int i=0; i<218; i++)
307 {
308 avblock=new AvatarAppearancePacket.VisualParamBlock();
309 avblock.ParamValue=(byte)100;
310 avp.VisualParam[i]=avblock;
311 }
312
313 avp.Sender.IsTrial=false;
314 avp.Sender.ID=user.AgentID;
315 */
316
317 AgentWearablesUpdatePacket aw=new AgentWearablesUpdatePacket();
318 aw.AgentData.AgentID=user.AgentID;
319 aw.AgentData.SerialNum=0;//(uint)appc;
320 //appc++;
321 aw.AgentData.SessionID=user.SessionID;//new LLUUID("00000000-0000-0000-0000-000000000000");//user.SessionID;
322
323 aw.WearableData= new AgentWearablesUpdatePacket.WearableDataBlock[13];
324 AgentWearablesUpdatePacket.WearableDataBlock awb=null;
325 awb=new AgentWearablesUpdatePacket.WearableDataBlock();
326 awb.WearableType=(byte)0;
327 awb.AssetID=new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
328 //awb.ItemID=new LLUUID("b7878000-0000-0000-0000-000000000000");
329 awb.ItemID=new LLUUID("b7878441893b094917f791174bc8401c");
330 //awb.ItemID=new LLUUID("00000000-0000-0000-0000-000000000000");
331 aw.WearableData[0]=awb;
332
333
334 /*awb=new AgentWearablesUpdatePacket.WearableDataBlock();
335 awb.WearableType=(byte)1;
336 awb.AssetID=new LLUUID("e0ee49b5a4184df8d3c9a65361fe7f49");
337 awb.ItemID=new LLUUID("193f0876fc11d143797454352f9c9c26");
338 //awb.ItemID=new LLUUID("00000000-0000-0000-0000-000000000000");
339 aw.WearableData[1]=awb;*/
340
341
342 for(int i=1; i<13; i++)
343 {
344 awb=new AgentWearablesUpdatePacket.WearableDataBlock();
345 awb.WearableType=(byte)i;
346 awb.AssetID=new LLUUID("00000000-0000-0000-0000-000000000000");
347 awb.ItemID=new LLUUID("00000000-0000-0000-0000-000000000000");
348 aw.WearableData[i]=awb;
349 }
350
351 //server.SendPacket(avp,true,user);
352 server.SendPacket(aw,true,user);
353 //System.Console.WriteLine(avp);
354
355
356 }
357 public void send_other_apper(User_Agent_info user,LLUUID id)
358 {
359 AvatarAppearancePacket avp=new AvatarAppearancePacket();
360
361
362 avp.VisualParam=new AvatarAppearancePacket.VisualParamBlock[218];
363 //avp.ObjectData.TextureEntry=this.avatar_template.TextureEntry;// br.ReadBytes((int)numBytes);
364
365 FileInfo fInfo = new FileInfo("Avatar_texture3.dat");
366
367 long numBytes = fInfo.Length;
368 FileStream fStream = new FileStream("Avatar_texture3.dat", FileMode.Open, FileAccess.Read);
369 BinaryReader br = new BinaryReader(fStream);
370 avp.ObjectData.TextureEntry= br.ReadBytes((int)numBytes);
371 br.Close();
372 fStream.Close();
373
374 AvatarAppearancePacket.VisualParamBlock avblock=null;
375 for(int i=0; i<218; i++)
376 {
377 avblock=new AvatarAppearancePacket.VisualParamBlock();
378 avblock.ParamValue=(byte)100;
379 avp.VisualParam[i]=avblock;
380 }
381
382 avp.Sender.IsTrial=false;
383 avp.Sender.ID=id;
384 server.SendPacket(avp,true,user);
385
386 }
387
388 public void send_test_avatar_position(User_Agent_info User_info)
389 {
390 //send a objectupdate packet with information about the clients avatar
391 ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
392 objupdate.RegionData.RegionHandle=1096213093147648;
393 objupdate.RegionData.TimeDilation=64500;
394 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
395
396 objupdate.ObjectData[0]=avatar_template;
397 //give this avatar object a local id and assign the user a name
398 objupdate.ObjectData[0].ID=8880000+this.local_numer;
399 objupdate.ObjectData[0].FullID=new LLUUID("00000000-0000-0000-5665-000000000034");
400 objupdate.ObjectData[0].NameValue=enc.GetBytes("FirstName STRING RW SV Test"+ this.local_numer+"\nLastName STRING RW SV User \0");
401 libsecondlife.LLVector3 pos2=new LLVector3(120f,120.0f,22.0f);
402
403 byte[] pb=pos2.GetBytes();
404
405 Array.Copy(pb,0,objupdate.ObjectData[0].ObjectData,16,pb.Length);
406 this.local_numer++;
407
408 server.SendPacket(objupdate,true,User_info);
409
410 this.send_other_apper(User_info,new LLUUID("00000000-0000-0000-5665-000000000034"));
411
412 }
413
414 public void send_other_avatar_position(User_Agent_info User_info, Avatar_data avd)
415 {
416 //send a objectupdate packet with information about the clients avatar
417 ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
418 objupdate.RegionData.RegionHandle=1096213093147648;
419 objupdate.RegionData.TimeDilation=64500;
420 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
421
422 objupdate.ObjectData[0]=avatar_template;
423 //give this avatar object a local id and assign the user a name
424 objupdate.ObjectData[0].ID=avd.Net_info.localID;
425 objupdate.ObjectData[0].FullID=avd.Net_info.AgentID;//new LLUUID("00000000-0000-0000-5665-000000000034");
426 objupdate.ObjectData[0].NameValue=enc.GetBytes(avd.Net_info.name);//enc.GetBytes("FirstName STRING RW SV Test"+ this.local_numer+"\nLastName STRING RW SV User \0");
427 libsecondlife.LLVector3 pos2=new LLVector3(avd.pos.X,avd.pos.Y,avd.pos.Z);
428
429 byte[] pb=pos2.GetBytes();
430
431 Array.Copy(pb,0,objupdate.ObjectData[0].ObjectData,16,pb.Length);
432 this.local_numer++;
433
434 server.SendPacket(objupdate,true,User_info);
435
436 this.send_other_apper(User_info,avd.Net_info.AgentID);//new LLUUID("00000000-0000-0000-5665-000000000034"));
437
438 }
439 //*************************************************************
440 public void send_chat_message(User_Agent_info User_info, string line)
441 {
442 libsecondlife.Packets.ChatFromSimulatorPacket reply=new ChatFromSimulatorPacket();
443 reply.ChatData.Audible=1;
444 reply.ChatData.Message=enc.GetBytes(line);
445 reply.ChatData.ChatType=1;
446 reply.ChatData.SourceType=1;
447 reply.ChatData.Position=new LLVector3(120,100,21); //should set to actual position
448 reply.ChatData.FromName=enc.GetBytes(User_info.first_name +" "+User_info.last_name +"\0"); //enc.GetBytes("Echo: \0"); //and actual name
449 reply.ChatData.OwnerID=User_info.AgentID;
450 reply.ChatData.SourceID=User_info.AgentID;
451 //echo to sender
452 server.SendPacket(reply,true,User_info);
453
454 //send to all users
455 foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list)
456 {
457 if(kp.Value.Net_info.AgentID!=User_info.AgentID)
458 {
459 server.SendPacket(reply,true,kp.Value.Net_info);
460 }
461 }
462 }
463 //*************************************************************
464 public void send_move_command(User_Agent_info user, bool stop,float x, float y, float z, uint av_id, libsecondlife.LLQuaternion body)
465 {
466 uint ID=user.localID;
467 //ID=av_id;
468 byte[] bytes=new byte[60];
469
470 ImprovedTerseObjectUpdatePacket im=new ImprovedTerseObjectUpdatePacket();
471 im.RegionData.RegionHandle=1096213093147648;
472 im.RegionData.TimeDilation=64096;
473
474 im.ObjectData=new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
475 int i=0;
476 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat=new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
477
478 im.ObjectData[0]=dat;
479
480 dat.TextureEntry=avatar_template.TextureEntry;
481 libsecondlife.LLVector3 pos2=new LLVector3(x,y,z);
482
483 bytes[i++] = (byte)(ID % 256);
484 bytes[i++] = (byte)((ID >> 8) % 256);
485 bytes[i++] = (byte)((ID >> 16) % 256);
486 bytes[i++] = (byte)((ID >> 24) % 256);
487
488 bytes[i++]=0;
489 bytes[i++]=1;
490
491 i+=14;
492 bytes[i++]=128;
493 bytes[i++]=63;
494 byte[] pb=pos2.GetBytes();
495
496 Array.Copy(pb,0,bytes,i,pb.Length);
497 i+=12;
498 ushort ac=32767;
499 Axiom.MathLib.Vector3 v3=new Axiom.MathLib.Vector3(1,0,0);
500 Axiom.MathLib.Quaternion q=new Axiom.MathLib.Quaternion(body.W,body.X,body.Y,body.Z);
501 Axiom.MathLib.Vector3 direc=q*v3;
502 direc.Normalize();
503
504 direc=direc*(0.03f);
505 direc.x+=1;
506 direc.y+=1;
507 direc.z+=1;
508 ushort dx,dy,dz;
509 dx=(ushort)(32768*direc.x);
510 dy=(ushort)(32768*direc.y);
511 dz=(ushort)(32768*direc.z);
512
513 //vel
514 if(!stop)
515 {
516 bytes[i++] = (byte)(dx % 256);
517 bytes[i++] = (byte)((dx >> 8) % 256);
518
519 bytes[i++] = (byte)(dy % 256);
520 bytes[i++] = (byte)((dy >> 8) % 256);
521
522 bytes[i++] = (byte)(dz % 256);
523 bytes[i++] = (byte)((dz >> 8) % 256);
524 }
525 else
526 {
527 bytes[i++] = (byte)(ac % 256);
528 bytes[i++] = (byte)((ac >> 8) % 256);
529
530 bytes[i++] = (byte)(ac % 256);
531 bytes[i++] = (byte)((ac >> 8) % 256);
532
533 bytes[i++] = (byte)(ac % 256);
534 bytes[i++] = (byte)((ac >> 8) % 256);
535 }
536 //accel
537 bytes[i++] = (byte)(ac % 256);
538 bytes[i++] = (byte)((ac >> 8) % 256);
539
540 bytes[i++] = (byte)(ac % 256);
541 bytes[i++] = (byte)((ac >> 8) % 256);
542
543 bytes[i++] = (byte)(ac % 256);
544 bytes[i++] = (byte)((ac >> 8) % 256);
545
546 //rot
547 bytes[i++] = (byte)(ac % 256);
548 bytes[i++] = (byte)((ac >> 8) % 256);
549
550 bytes[i++] = (byte)(ac % 256);
551 bytes[i++] = (byte)((ac >> 8) % 256);
552
553 bytes[i++] = (byte)(ac % 256);
554 bytes[i++] = (byte)((ac >> 8) % 256);
555
556 bytes[i++] = (byte)(ac % 256);
557 bytes[i++] = (byte)((ac >> 8) % 256);
558
559 //rotation vel
560 bytes[i++] = (byte)(ac % 256);
561 bytes[i++] = (byte)((ac >> 8) % 256);
562
563 bytes[i++] = (byte)(ac % 256);
564 bytes[i++] = (byte)((ac >> 8) % 256);
565
566 bytes[i++] = (byte)(ac % 256);
567 bytes[i++] = (byte)((ac >> 8) % 256);
568
569 dat.Data=bytes;
570
571 server.SendPacket(im,true,user);
572
573 //should send to all users.
574 foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in this.Agent_list)
575 {
576 if(kp.Value.Net_info.AgentID!=user.AgentID)
577 {
578 server.SendPacket(im,true,kp.Value.Net_info);
579 }
580 }
581 }
582 //*************************************************************
583 public void read_layerdata(User_Agent_info User_info,ref LayerDataPacket lay,string name)
584 {
585 FileInfo fInfo = new FileInfo(name);
586
587 long numBytes = fInfo.Length;
588
589 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
590
591 BinaryReader br = new BinaryReader(fStream);
592
593 data1 = br.ReadBytes((int)numBytes);
594
595 br.Close();
596
597 fStream.Close();
598 lay.LayerData.Data=data1;
599 server.SendPacket(lay,true,User_info);
600 //System.Console.WriteLine("sent");
601 }
602 }
603
604 public class Avatar_data
605 {
606 public User_Agent_info Net_info;
607 public LLUUID Full_ID;
608 public LLVector3 pos;
609 public LLVector3 vel=new LLVector3(0,0,0);
610 public bool walk=false;
611 public bool started=false;
612
613 public Avatar_data()
614 {
615
616 }
617 }
618}
diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs
new file mode 100644
index 0000000..2738c92
--- /dev/null
+++ b/AssemblyInfo.cs
@@ -0,0 +1,59 @@
1/*
2* Copyright (c) <year>, <copyright holder>
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the <organization> nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27*/
28
29using System.Reflection;
30using System.Runtime.CompilerServices;
31using System.Runtime.InteropServices;
32
33// Information about this assembly is defined by the following
34// attributes.
35//
36// change them to the information which is associated with the assembly
37// you compile.
38
39[assembly: AssemblyTitle("Second-server")]
40[assembly: AssemblyDescription("")]
41[assembly: AssemblyConfiguration("")]
42[assembly: AssemblyCompany("")]
43[assembly: AssemblyProduct("Second-server")]
44[assembly: AssemblyCopyright("")]
45[assembly: AssemblyTrademark("")]
46[assembly: AssemblyCulture("")]
47
48// This sets the default COM visibility of types in the assembly to invisible.
49// If you need to expose a type to COM, use [ComVisible(true)] on that type.
50[assembly: ComVisible(false)]
51
52// The assembly version has following format :
53//
54// Major.Minor.Build.Revision
55//
56// You can specify all values by your own or you can build default build and revision
57// numbers with the '*' character (the default):
58
59[assembly: AssemblyVersion("1.0.*")]
diff --git a/Asset_manager.cs b/Asset_manager.cs
new file mode 100644
index 0000000..194d28f
--- /dev/null
+++ b/Asset_manager.cs
@@ -0,0 +1,167 @@
1/*
2Copyright (c) 2007 Michael Wright
3
4* Copyright (c) <year>, <copyright holder>
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28
29using System;
30using System.Collections.Generic;
31using libsecondlife;
32using System.Collections;
33using libsecondlife.Packets;
34using libsecondlife.AssetSystem;
35using System.IO;
36
37namespace Second_server
38{
39 /// <summary>
40 /// Description of Asset_manager.
41 /// </summary>
42 public class Asset_manager
43 {
44 public Dictionary<libsecondlife.LLUUID,Asset_info> Assets;
45 public ArrayList requests=new ArrayList(); //should change to a generic
46 // public ArrayList uploads=new ArrayList();
47 private Server server;
48
49 public Asset_manager(Server serve)
50 {
51 server=serve;
52 Assets=new Dictionary<libsecondlife.LLUUID,Asset_info> ();
53 this.initialise();
54 }
55
56 public void add_request(User_Agent_info user, LLUUID asset_id, TransferRequestPacket tran_req)
57 {
58
59 if(!this.Assets.ContainsKey(asset_id))
60 {
61 //not found asset
62 return;
63 }
64 Asset_info info=this.Assets[asset_id];
65 System.Console.WriteLine("send asset : "+asset_id);
66 //for now as it will be only skin or shape request just send back the asset
67 TransferInfoPacket tran_i=new TransferInfoPacket();
68 tran_i.TransferInfo.ChannelType=2;
69 tran_i.TransferInfo.Status=0;
70 tran_i.TransferInfo.TargetType=0;
71 tran_i.TransferInfo.Params=tran_req.TransferInfo.Params;
72 tran_i.TransferInfo.Size=info.data.Length;
73 tran_i.TransferInfo.TransferID=tran_req.TransferInfo.TransferID;
74
75 server.SendPacket(tran_i,true,user);
76
77 TransferPacketPacket tran_p=new TransferPacketPacket();
78 tran_p.TransferData.Packet=0;
79 tran_p.TransferData.ChannelType=2;
80 tran_p.TransferData.TransferID=tran_req.TransferInfo.TransferID;
81 if(info.data.Length>1000) //but needs to be less than 2000 at the moment
82 {
83 byte[] chunk=new byte[1000];
84 Array.Copy(info.data,chunk,1000);
85 tran_p.TransferData.Data=chunk;
86 tran_p.TransferData.Status=0;
87 server.SendPacket(tran_p,true,user);
88
89 tran_p=new TransferPacketPacket();
90 tran_p.TransferData.Packet=1;
91 tran_p.TransferData.ChannelType=2;
92 tran_p.TransferData.TransferID=tran_req.TransferInfo.TransferID;
93 byte[] chunk1=new byte[(info.data.Length-1000)];
94 Array.Copy(info.data,1000,chunk1,0,chunk1.Length);
95 tran_p.TransferData.Data=chunk1;
96 tran_p.TransferData.Status=1;
97 server.SendPacket(tran_p,true,user);
98 }
99 else
100 {
101 tran_p.TransferData.Status=1; //last packet? so set to 1
102 tran_p.TransferData.Data=info.data;
103 server.SendPacket(tran_p,true,user);
104 }
105
106
107
108 }
109
110 private void initialise()
111 {
112 //for now read in our test image
113 Asset_info im=new Asset_info();
114 im.filename="base_shape.dat";
115 im.Full_ID=new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
116 this.load_asset(im);
117 this.Assets.Add(im.Full_ID,im);
118 }
119 private void load_asset(Asset_info info)
120 {
121 string data_path=System.Windows.Forms.Application.StartupPath + @"\assets\";
122 string filename=data_path+@info.filename;
123 FileInfo fInfo = new FileInfo(filename);
124
125 long numBytes = fInfo.Length;
126
127 FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
128 byte[] idata=new byte[numBytes];
129 BinaryReader br = new BinaryReader(fStream);
130 idata= br.ReadBytes((int)numBytes);
131 br.Close();
132 fStream.Close();
133 info.data=idata;
134 info.loaded=true;
135 }
136 }
137
138 public class Asset_request
139 {
140 public User_Agent_info req_user;
141 public LLUUID req_image;
142 public Asset_info asset_inf;
143 public long data_pointer=0;
144 public int num_packets=0;
145 public int packet_counter=0;
146
147 public Asset_request()
148 {
149
150 }
151 }
152 public class Asset_info
153 {
154 public byte[] data;
155 public LLUUID Full_ID;
156 public string name;
157 public string filename;
158 public bool loaded;
159 public ulong last_used; //need to add a tick/time counter and keep record
160 // of how often images are requested to unload unused ones.
161
162 public Asset_info()
163 {
164
165 }
166 }
167}
diff --git a/Class1.cs b/Class1.cs
new file mode 100644
index 0000000..761a7eb
--- /dev/null
+++ b/Class1.cs
@@ -0,0 +1,23 @@
1/*
2 * Created by SharpDevelop.
3 * User: Ma
4 * Date: 29/01/2007
5 * Time: 18:02
6 *
7 * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 */
9
10using System;
11
12namespace Second_server
13{
14 /// <summary>
15 /// Description of Class1.
16 /// </summary>
17 public class Class1
18 {
19 public Class1()
20 {
21 }
22 }
23}
diff --git a/Login_manager.cs b/Login_manager.cs
new file mode 100644
index 0000000..84f475d
--- /dev/null
+++ b/Login_manager.cs
@@ -0,0 +1,163 @@
1/*Copyright (c) 2007 Michael Wright
2
3* Copyright (c) <year>, <copyright holder>
4* All rights reserved.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* * Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of the <organization> nor the
14* names of its contributors may be used to endorse or promote products
15* derived from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
18* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29using System;
30using System.IO;
31using System.Net;
32using System.Net.Sockets;
33using System.Text;
34using System.Text.RegularExpressions;
35using System.Threading;
36
37namespace Second_server
38{
39 /// <summary>
40 /// Description of Login_manager.
41 /// </summary>
42 public class Login_manager
43 {
44 public Login_manager()
45 {
46
47 }
48
49 public ushort loginPort = 8080;
50 public IPAddress clientAddress = IPAddress.Loopback;
51 public IPAddress remoteAddress = IPAddress.Any;
52 private Socket loginServer;
53 private Random RandomClass = new Random();
54
55 // InitializeLoginProxy: initialize the login proxy
56 private void InitializeLoginProxy() {
57 loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
58 loginServer.Bind(new IPEndPoint(remoteAddress, loginPort));
59 loginServer.Listen(1);
60 }
61
62 public void startup()
63 {
64 this.InitializeLoginProxy();
65 Thread runLoginProxy = new Thread(new ThreadStart(RunLoginProxy));
66 runLoginProxy.IsBackground = true;
67 runLoginProxy.Start();
68 }
69
70 private void RunLoginProxy() {
71 try {
72 for (;;) {
73 Socket client = loginServer.Accept();
74 IPEndPoint clientEndPoint = (IPEndPoint)client.RemoteEndPoint;
75
76
77 NetworkStream networkStream = new NetworkStream(client);
78 StreamReader networkReader = new StreamReader(networkStream);
79 StreamWriter networkWriter = new StreamWriter(networkStream);
80
81 try
82 {
83 ProxyLogin(networkReader, networkWriter);
84 }
85 catch (Exception e)
86 {
87 Console.WriteLine(e.Message);
88 }
89
90 networkWriter.Close();
91 networkReader.Close();
92 networkStream.Close();
93
94 client.Close();
95
96 // send any packets queued for injection
97
98 }
99 } catch (Exception e) {
100 Console.WriteLine(e.Message);
101 Console.WriteLine(e.StackTrace);
102 }
103 }
104
105 // ProxyLogin: proxy a login request
106 private void ProxyLogin(StreamReader reader, StreamWriter writer) { lock(this) {
107 string line;
108 int contentLength = 0;
109
110 // read HTTP header
111 do {
112 // read one line of the header
113 line = reader.ReadLine();
114
115 // check for premature EOF
116 if (line == null)
117 throw new Exception("EOF in client HTTP header");
118
119 // look for Content-Length
120 Match match = (new Regex(@"Content-Length: (\d+)$")).Match(line);
121 if (match.Success)
122 contentLength = Convert.ToInt32(match.Groups[1].Captures[0].ToString());
123 } while (line != "");
124 System.Console.WriteLine(line);
125 // read the HTTP body into a buffer
126 char[] content = new char[contentLength];
127 reader.Read(content, 0, contentLength);
128
129
130 // forward the XML-RPC response to the client
131 writer.WriteLine("HTTP/1.0 200 OK");
132 writer.WriteLine("Content-type: text/xml");
133 writer.WriteLine();
134
135
136 StreamReader SR;
137 string lines;
138 SR=File.OpenText("login.dat");
139 lines=SR.ReadLine();
140 writer.WriteLine(lines);
141 lines=SR.ReadLine();
142 int ran=this.RandomClass.Next(1,9999);
143
144 lines="<member><name>session_id</name><value><string>99998888-"+ran.ToString("0000")+"-4f52-8ec1-0b1d5cd6aead</string></value></member>";
145 writer.WriteLine(lines);
146 lines=SR.ReadLine();
147 writer.WriteLine(lines);
148 lines=SR.ReadLine();
149 ran=this.RandomClass.Next(1,9999);
150 lines="<member><name>agent_id</name><value><string>aaaabbbb-8932-"+ran.ToString("0000")+"-8664-58f53e442797</string></value></member>";
151 writer.WriteLine(lines);
152 lines=SR.ReadLine();
153
154 while(lines!="end-mfile")
155 {
156 writer.WriteLine(lines);
157 lines=SR.ReadLine();
158 }
159 SR.Close();
160 }
161 }
162 }
163}
diff --git a/Main-sever.Designer.cs b/Main-sever.Designer.cs
new file mode 100644
index 0000000..af8cfe8
--- /dev/null
+++ b/Main-sever.Designer.cs
@@ -0,0 +1,80 @@
1/*
2Copyright (c) 2007 Michael Wright
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18namespace Second_server
19{
20 partial class Main_server : System.Windows.Forms.Form
21 {
22 /// <summary>
23 /// Designer variable used to keep track of non-visual components.
24 /// </summary>
25 private System.ComponentModel.IContainer components = null;
26
27 /// <summary>
28 /// Disposes resources used by the form.
29 /// </summary>
30 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
31 protected override void Dispose(bool disposing)
32 {
33 if (disposing) {
34 if (components != null) {
35 components.Dispose();
36 }
37 }
38 base.Dispose(disposing);
39 }
40
41 /// <summary>
42 /// This method is required for Windows Forms designer support.
43 /// Do not change the method contents inside the source code editor. The Forms designer might
44 /// not be able to load this method if it was changed manually.
45 /// </summary>
46 private void InitializeComponent()
47 {
48 this.components = new System.ComponentModel.Container();
49 this.richTextBox1 = new System.Windows.Forms.RichTextBox();
50 this.timer1 = new System.Windows.Forms.Timer(this.components);
51 this.SuspendLayout();
52 //
53 // richTextBox1
54 //
55 this.richTextBox1.Location = new System.Drawing.Point(11, 12);
56 this.richTextBox1.Name = "richTextBox1";
57 this.richTextBox1.Size = new System.Drawing.Size(346, 402);
58 this.richTextBox1.TabIndex = 0;
59 this.richTextBox1.Text = "";
60 //
61 // timer1
62 //
63 this.timer1.Enabled = true;
64 this.timer1.Interval = 200;
65 this.timer1.Tick += new System.EventHandler(this.Timer1Tick);
66 //
67 // Main_server
68 //
69 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
70 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
71 this.ClientSize = new System.Drawing.Size(596, 426);
72 this.Controls.Add(this.richTextBox1);
73 this.Name = "Main_server";
74 this.Text = "Main_sever";
75 this.ResumeLayout(false);
76 }
77 private System.Windows.Forms.Timer timer1;
78 private System.Windows.Forms.RichTextBox richTextBox1;
79 }
80}
diff --git a/Main-sever.cs b/Main-sever.cs
new file mode 100644
index 0000000..911d9d7
--- /dev/null
+++ b/Main-sever.cs
@@ -0,0 +1,270 @@
1/*
2Copyright (c) 2007 Michael Wright
3
4* Copyright (c) <year>, <copyright holder>
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Collections.Generic;
32using System.Drawing;
33using System.Windows.Forms;
34using libsecondlife;
35using libsecondlife.Packets;
36using System.Collections;
37using System.Text;
38using System.IO;
39using Axiom.MathLib;
40
41namespace Second_server
42{
43 /// <summary>
44 /// Description of MainForm.
45 /// </summary>
46 public partial class Main_server:Server_callback
47 {
48
49 [STAThread]
50 public static void Main(string[] args)
51 {
52 Application.EnableVisualStyles();
53 Application.SetCompatibleTextRenderingDefault(false);
54 Application.Run(new Main_server());
55 }
56 public Server server;
57
58 //public bool intin=false;
59 //private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock avatar_template;
60 //private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock object_template;
61
62 private Agent_Manager agent_man;
63 private Prim_manager prim_man;
64 private Texture_manager texture_man;
65 private Asset_manager asset_man;
66 private Login_manager login_man; //built in login server
67 private ulong time; //ticks
68
69 public Main_server()
70 {
71 //
72 // The InitializeComponent() call is required for Windows Forms designer support.
73 //
74 InitializeComponent();
75
76 //
77 // TODO: Add constructor code after the InitializeComponent() call.
78 //
79
80 server=new Server(this);
81 agent_man=new Agent_Manager(this.server);
82 prim_man=new Prim_manager(this.server);
83 texture_man=new Texture_manager(this.server);
84 asset_man=new Asset_manager(this.server);
85 prim_man.agent_man=agent_man;
86 agent_man.prim_man=prim_man;
87 login_man=new Login_manager(); // startup
88 login_man.startup(); // login server
89
90 }
91 public void main_callback(Packet pack, User_Agent_info User_info)
92 {
93 if((pack.Type!= PacketType.StartPingCheck) && (pack.Type!= PacketType.AgentUpdate))
94 {
95 //System.Console.WriteLine(pack.Type);
96 //this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type;
97 }
98 if(pack.Type== PacketType.AgentSetAppearance)
99 {
100 //System.Console.WriteLine(pack);
101 //this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type;
102
103 }
104 if(pack.Type== PacketType.TransferRequest)
105 {
106 TransferRequestPacket tran=(TransferRequestPacket)pack;
107 LLUUID id=new LLUUID(tran.TransferInfo.Params,0);
108
109 if((id==new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73")) ||(id==new LLUUID("e0ee49b5a4184df8d3c9a65361fe7f49")))
110 {
111 //System.Console.WriteLine(pack);
112 //System.Console.WriteLine(tran.TransferInfo.TransferID);
113 asset_man.add_request(User_info,id,tran);
114 //this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type;
115 }
116
117 }
118 if((pack.Type== PacketType.StartPingCheck) )
119 {
120 //reply to pingcheck
121 libsecondlife.Packets.StartPingCheckPacket startp=(libsecondlife.Packets.StartPingCheckPacket)pack;
122 libsecondlife.Packets.CompletePingCheckPacket endping=new CompletePingCheckPacket();
123 endping.PingID.PingID=startp.PingID.PingID;
124 server.SendPacket(endping,true,User_info);
125 }
126 if(pack.Type==PacketType.CompleteAgentMovement)
127 {
128 // new client
129 agent_man.Agent_join(User_info);
130 }
131 if (pack.Type==PacketType.RequestImage)
132 {
133 RequestImagePacket image_req=(RequestImagePacket)pack;
134 for(int i=0; i<image_req.RequestImage.Length ;i++)
135 {
136 this.texture_man.add_request(User_info,image_req.RequestImage[i].Image);
137
138 }
139 }
140 if (pack.Type==PacketType.RegionHandshakeReply)
141 {
142 //recieved regionhandshake so can now start sending info
143 agent_man.send_intial_data(User_info);
144 //this.setuptemplates("objectupate164.dat",User_info,false);
145 }
146 if(pack.Type== PacketType.ObjectAdd)
147 {
148 ObjectAddPacket ad=(ObjectAddPacket)pack;
149 prim_man.create_prim(User_info,ad.ObjectData.RayEnd, ad);
150 //this.send_prim(User_info,ad.ObjectData.RayEnd, ad);
151 }
152 if(pack.Type== PacketType.ObjectPosition)
153 {
154 //System.Console.WriteLine(pack.ToString());
155 }
156 if(pack.Type== PacketType.MultipleObjectUpdate)
157 {
158 //System.Console.WriteLine(pack.ToString());
159 MultipleObjectUpdatePacket mupd=(MultipleObjectUpdatePacket)pack;
160
161 for(int i=0; i<mupd.ObjectData.Length; i++)
162 {
163 if(mupd.ObjectData[i].Type==9) //change position
164 {
165 libsecondlife.LLVector3 pos=new LLVector3(mupd.ObjectData[i].Data, 0);
166
167 prim_man.update_prim_position(User_info, pos.X,pos.Y,pos.Z,mupd.ObjectData[i].ObjectLocalID);
168 //should update stored position of the prim
169 }
170 }
171 }
172 if(pack.Type== PacketType.AgentWearablesRequest)
173 {
174 agent_man.send_intial_avatar_apper(User_info);
175 }
176
177 if(pack.Type==PacketType.AgentUpdate)
178 {
179 AgentUpdatePacket ag=(AgentUpdatePacket)pack;
180 uint mask=ag.AgentData.ControlFlags&(1);
181 Avatar_data m_av=agent_man.Get_Agent(User_info.AgentID);
182 if(m_av!=null)
183 {
184 if(m_av.started)
185 {
186 if(mask==(1))
187 {
188 if(!m_av.walk)
189 {
190 //start walking
191 agent_man.send_move_command(User_info,false,m_av.pos.X,m_av.pos.Y,m_av.pos.Z,0,ag.AgentData.BodyRotation);
192 Axiom.MathLib.Vector3 v3=new Axiom.MathLib.Vector3(1,0,0);
193 Axiom.MathLib.Quaternion q=new Axiom.MathLib.Quaternion(ag.AgentData.BodyRotation.W,ag.AgentData.BodyRotation.X,ag.AgentData.BodyRotation.Y,ag.AgentData.BodyRotation.Z);
194 Axiom.MathLib.Vector3 direc=q*v3;
195 direc.Normalize();
196 direc=direc*((0.03f)*128f);
197
198 m_av.vel.X=direc.x;
199 m_av.vel.Y=direc.y;
200 m_av.vel.Z=direc.z;
201 m_av.walk=true;
202 }
203 }
204 else{
205 if(m_av.walk)
206 {
207 //walking but key not pressed so need to stop
208 agent_man.send_move_command(User_info,true,m_av.pos.X,m_av.pos.Y,m_av.pos.Z,0,ag.AgentData.BodyRotation);
209 m_av.walk=false;
210 m_av.vel.X=0;
211 m_av.vel.Y=0;
212 m_av.vel.Z=0;
213 }
214 }
215 }}
216 }
217
218 if(pack.Type==PacketType.ChatFromViewer)
219 {
220 ChatFromViewerPacket chat=(ChatFromViewerPacket)pack;
221 System.Text.Encoding enc = System.Text.Encoding.ASCII;
222
223 string myString = enc.GetString(chat.ChatData.Message );
224 if(myString!="")
225 {
226 string [] comp= new string[10];
227 string delimStr = " , ";
228 char [] delimiter = delimStr.ToCharArray();
229 string line;
230
231 line=myString;
232 comp=line.Split(delimiter);
233 if(comp[0]=="pos")
234 {
235 }
236 else if(comp[0]=="veloc")
237 {
238 }
239 else
240 {
241 agent_man.send_chat_message(User_info,line);
242
243 }
244 }
245 }
246 }
247 public void new_user(User_Agent_info User_info)
248 {
249 this.richTextBox1.Text=this.richTextBox1.Text+"\n "+"new user - "+User_info.AgentID.ToString()+" - has joined";
250 this.richTextBox1.Text=this.richTextBox1.Text+"\n "+"session id := "+User_info.SessionID.ToString();
251 agent_man.New_Agent(User_info);
252
253 }
254
255 public void error(string text)
256 {
257 this.richTextBox1.Text=this.richTextBox1.Text+"\n error report: "+text;
258 }
259
260 void Timer1Tick(object sender, System.EventArgs e)
261 {
262 this.time++;
263 agent_man.tick();
264 texture_man.Do_work(time);
265 }
266
267
268 }
269
270}
diff --git a/Main-sever.resx b/Main-sever.resx
new file mode 100644
index 0000000..6999fbf
--- /dev/null
+++ b/Main-sever.resx
@@ -0,0 +1,123 @@
1<?xml version="1.0" encoding="utf-8"?>
2<root>
3 <!--
4 Microsoft ResX Schema
5
6 Version 2.0
7
8 The primary goals of this format is to allow a simple XML format
9 that is mostly human readable. The generation and parsing of the
10 various data types are done through the TypeConverter classes
11 associated with the data types.
12
13 Example:
14
15 ... ado.net/XML headers & schema ...
16 <resheader name="resmimetype">text/microsoft-resx</resheader>
17 <resheader name="version">2.0</resheader>
18 <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19 <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20 <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21 <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22 <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23 <value>[base64 mime encoded serialized .NET Framework object]</value>
24 </data>
25 <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26 <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27 <comment>This is a comment</comment>
28 </data>
29
30 There are any number of "resheader" rows that contain simple
31 name/value pairs.
32
33 Each data row contains a name, and value. The row also contains a
34 type or mimetype. Type corresponds to a .NET class that support
35 text/value conversion through the TypeConverter architecture.
36 Classes that don't support this are serialized and stored with the
37 mimetype set.
38
39 The mimetype is used for serialized objects, and tells the
40 ResXResourceReader how to depersist the object. This is currently not
41 extensible. For a given mimetype the value must be set accordingly:
42
43 Note - application/x-microsoft.net.object.binary.base64 is the format
44 that the ResXResourceWriter will generate, however the reader can
45 read any of the formats listed below.
46
47 mimetype: application/x-microsoft.net.object.binary.base64
48 value : The object must be serialized with
49 : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50 : and then encoded with base64 encoding.
51
52 mimetype: application/x-microsoft.net.object.soap.base64
53 value : The object must be serialized with
54 : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55 : and then encoded with base64 encoding.
56
57 mimetype: application/x-microsoft.net.object.bytearray.base64
58 value : The object must be serialized into a byte array
59 : using a System.ComponentModel.TypeConverter
60 : and then encoded with base64 encoding.
61 -->
62 <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63 <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64 <xsd:element name="root" msdata:IsDataSet="true">
65 <xsd:complexType>
66 <xsd:choice maxOccurs="unbounded">
67 <xsd:element name="metadata">
68 <xsd:complexType>
69 <xsd:sequence>
70 <xsd:element name="value" type="xsd:string" minOccurs="0" />
71 </xsd:sequence>
72 <xsd:attribute name="name" use="required" type="xsd:string" />
73 <xsd:attribute name="type" type="xsd:string" />
74 <xsd:attribute name="mimetype" type="xsd:string" />
75 <xsd:attribute ref="xml:space" />
76 </xsd:complexType>
77 </xsd:element>
78 <xsd:element name="assembly">
79 <xsd:complexType>
80 <xsd:attribute name="alias" type="xsd:string" />
81 <xsd:attribute name="name" type="xsd:string" />
82 </xsd:complexType>
83 </xsd:element>
84 <xsd:element name="data">
85 <xsd:complexType>
86 <xsd:sequence>
87 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88 <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89 </xsd:sequence>
90 <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91 <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92 <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93 <xsd:attribute ref="xml:space" />
94 </xsd:complexType>
95 </xsd:element>
96 <xsd:element name="resheader">
97 <xsd:complexType>
98 <xsd:sequence>
99 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100 </xsd:sequence>
101 <xsd:attribute name="name" type="xsd:string" use="required" />
102 </xsd:complexType>
103 </xsd:element>
104 </xsd:choice>
105 </xsd:complexType>
106 </xsd:element>
107 </xsd:schema>
108 <resheader name="resmimetype">
109 <value>text/microsoft-resx</value>
110 </resheader>
111 <resheader name="version">
112 <value>2.0</value>
113 </resheader>
114 <resheader name="reader">
115 <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116 </resheader>
117 <resheader name="writer">
118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119 </resheader>
120 <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121 <value>17, 17</value>
122 </metadata>
123</root> \ No newline at end of file
diff --git a/Physics_manager.cs b/Physics_manager.cs
new file mode 100644
index 0000000..22102a1
--- /dev/null
+++ b/Physics_manager.cs
@@ -0,0 +1,43 @@
1/*
2Copyright (c) 2007 Michael Wright
3
4* Copyright (c) <year>, <copyright holder>
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31
32namespace Second_server
33{
34 /// <summary>
35 /// Description of Physics_manager.
36 /// </summary>
37 public class Physics_manager
38 {
39 public Physics_manager()
40 {
41 }
42 }
43}
diff --git a/Prim_manager.cs b/Prim_manager.cs
new file mode 100644
index 0000000..dff2d24
--- /dev/null
+++ b/Prim_manager.cs
@@ -0,0 +1,310 @@
1/*
2Copyright (c) 2007 Michael Wright
3
4* Copyright (c) <year>, <copyright holder>
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Collections.Generic;
32using libsecondlife;
33using libsecondlife.Packets;
34using libsecondlife.AssetSystem;
35using System.IO;
36using Axiom.MathLib;
37
38namespace Second_server
39{
40 /// <summary>
41 /// Description of Prim_manager.
42 /// </summary>
43 public class Prim_manager
44 {
45 private Server server;
46 public Agent_Manager agent_man;
47
48 private uint prim_count;
49
50 public libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock object_template;
51 public Dictionary<libsecondlife.LLUUID,prim_info> Prim_list;
52 public Prim_manager(Server serve)
53 {
54 server=serve;
55 Prim_list=new Dictionary<libsecondlife.LLUUID,prim_info> ();
56 this.setuptemplates("objectupate164.dat");
57 }
58
59
60 //*********************************************************************
61 public void create_prim(User_Agent_info User_info, libsecondlife.LLVector3 p1, ObjectAddPacket add_pack)
62 {
63 ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
64 objupdate.RegionData.RegionHandle=1096213093147648;
65 objupdate.RegionData.TimeDilation=64096;
66 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
67
68 objupdate.ObjectData[0]=this.object_template;
69 objupdate.ObjectData[0].OwnerID=User_info.AgentID;
70 objupdate.ObjectData[0].PCode=add_pack.ObjectData.PCode;
71 objupdate.ObjectData[0].PathBegin=add_pack.ObjectData.PathBegin;
72 objupdate.ObjectData[0].PathEnd=add_pack.ObjectData.PathEnd;
73 objupdate.ObjectData[0].PathScaleX=add_pack.ObjectData.PathScaleX;
74 objupdate.ObjectData[0].PathScaleY=add_pack.ObjectData.PathScaleY;
75 objupdate.ObjectData[0].PathShearX=add_pack.ObjectData.PathShearX;
76 objupdate.ObjectData[0].PathShearY=add_pack.ObjectData.PathShearY;
77 objupdate.ObjectData[0].PathSkew=add_pack.ObjectData.PathSkew;
78 objupdate.ObjectData[0].ProfileBegin=add_pack.ObjectData.ProfileBegin;
79 objupdate.ObjectData[0].ProfileEnd=add_pack.ObjectData.ProfileEnd;
80 objupdate.ObjectData[0].Scale=add_pack.ObjectData.Scale;//new LLVector3(1,1,1);
81 objupdate.ObjectData[0].PathCurve=add_pack.ObjectData.PathCurve;
82 objupdate.ObjectData[0].ProfileCurve=add_pack.ObjectData.ProfileCurve;
83 objupdate.ObjectData[0].ParentID=0;
84 objupdate.ObjectData[0].ProfileHollow=add_pack.ObjectData.ProfileHollow;
85 //finish off copying rest of shape data
86
87 objupdate.ObjectData[0].ID=(uint)(702000+prim_count);
88 objupdate.ObjectData[0].FullID=new LLUUID("edba7151-5857-acc5-b30b-f01efefda"+prim_count.ToString("000"));
89
90 //update position
91 byte[] pb=p1.GetBytes();
92 Array.Copy(pb,0,objupdate.ObjectData[0].ObjectData,0,pb.Length);
93
94 prim_count++;
95 server.SendPacket(objupdate,true,User_info);
96
97 //should send to all users
98 foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in agent_man.Agent_list)
99 {
100 if(kp.Value.Net_info.AgentID!=User_info.AgentID)
101 {
102 server.SendPacket(objupdate,true,kp.Value.Net_info);
103 }
104 }
105 //should store this infomation
106 prim_info n_prim=new prim_info();
107 n_prim.full_ID=objupdate.ObjectData[0].FullID;
108 n_prim.local_ID=objupdate.ObjectData[0].ID;
109 n_prim.pos=p1;
110
111 this.Prim_list.Add(n_prim.full_ID,n_prim);
112
113 //store rest of data
114
115 }
116 public void update_prim_position(User_Agent_info user,float x, float y, float z,uint l_id)
117 {
118 prim_info pri=null;
119 foreach (KeyValuePair<libsecondlife.LLUUID,prim_info> kp in this.Prim_list)
120 {
121 if(kp.Value.local_ID==l_id)
122 {
123 pri=kp.Value;
124 }
125 }
126 if(pri==null)
127 {
128 return;
129 }
130 uint ID=pri.local_ID;
131 byte[] bytes=new byte[60];
132
133 ImprovedTerseObjectUpdatePacket im=new ImprovedTerseObjectUpdatePacket();
134 im.RegionData.RegionHandle=1096213093147648;
135 im.RegionData.TimeDilation=64096;
136 im.ObjectData=new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
137 int i=0;
138 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat=new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
139 im.ObjectData[0]=dat;
140 dat.TextureEntry=object_template.TextureEntry;
141 libsecondlife.LLVector3 pos2=new LLVector3(x,y,z);
142
143 bytes[i++] = (byte)(ID % 256);
144 bytes[i++] = (byte)((ID >> 8) % 256);
145 bytes[i++] = (byte)((ID >> 16) % 256);
146 bytes[i++] = (byte)((ID >> 24) % 256);
147 bytes[i++]=0;
148 bytes[i++]=0;//1;
149
150 // i+=14;
151 // bytes[i++]=128;
152 // bytes[i++]=63;
153 byte[] pb=pos2.GetBytes();
154 pri.pos=pos2;
155 Array.Copy(pb,0,bytes,i,pb.Length);
156 i+=12;
157 ushort ac=32767;
158
159 //vel
160 bytes[i++] = (byte)(ac % 256);
161 bytes[i++] = (byte)((ac >> 8) % 256);
162 bytes[i++] = (byte)(ac % 256);
163 bytes[i++] = (byte)((ac >> 8) % 256);
164 bytes[i++] = (byte)(ac % 256);
165 bytes[i++] = (byte)((ac >> 8) % 256);
166
167 //accel
168 bytes[i++] = (byte)(ac % 256);
169 bytes[i++] = (byte)((ac >> 8) % 256);
170 bytes[i++] = (byte)(ac % 256);
171 bytes[i++] = (byte)((ac >> 8) % 256);
172 bytes[i++] = (byte)(ac % 256);
173 bytes[i++] = (byte)((ac >> 8) % 256);
174
175 //rot
176 bytes[i++] = (byte)(ac % 256);
177 bytes[i++] = (byte)((ac >> 8) % 256);
178 bytes[i++] = (byte)(ac % 256);
179 bytes[i++] = (byte)((ac >> 8) % 256);
180 bytes[i++] = (byte)(ac % 256);
181 bytes[i++] = (byte)((ac >> 8) % 256);
182 bytes[i++] = (byte)(ac % 256);
183 bytes[i++] = (byte)((ac >> 8) % 256);
184
185 //rotation vel
186 bytes[i++] = (byte)(ac % 256);
187 bytes[i++] = (byte)((ac >> 8) % 256);
188 bytes[i++] = (byte)(ac % 256);
189 bytes[i++] = (byte)((ac >> 8) % 256);
190 bytes[i++] = (byte)(ac % 256);
191 bytes[i++] = (byte)((ac >> 8) % 256);
192
193 dat.Data=bytes;
194 //server.SendPacket(im,true,user);
195 //should send to all users.
196 foreach (KeyValuePair<libsecondlife.LLUUID,Avatar_data> kp in agent_man.Agent_list)
197 {
198 if(kp.Value.Net_info.AgentID!=user.AgentID)
199 {
200 server.SendPacket(im,true,kp.Value.Net_info);
201 }
202 }
203 }
204 public void send_existing_prims(User_Agent_info user)
205 {
206 //send data for already created prims to a new joining user
207 }
208 //**************************************************************
209 public void setuptemplates(string name)
210 {
211 ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
212 objupdate.RegionData.RegionHandle=1096213093147648;
213 objupdate.RegionData.TimeDilation=64096;
214 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
215
216 int i=0;
217 FileInfo fInfo = new FileInfo(name);
218 long numBytes = fInfo.Length;
219 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
220 BinaryReader br = new BinaryReader(fStream);
221 byte [] data1 = br.ReadBytes((int)numBytes);
222 br.Close();
223 fStream.Close();
224
225 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1,ref i);
226 objupdate.ObjectData[0]=objdata;
227 this.object_template=objdata;
228 objdata.UpdateFlags=objdata.UpdateFlags+12-16+32+256;
229 objdata.OwnerID=new LLUUID("00000000-0000-0000-0000-000000000000");
230 //test adding a new texture to object , to test image downloading
231 LLObject.TextureEntry te=new LLObject.TextureEntry(objdata.TextureEntry,0,objdata.TextureEntry.Length);
232 te.DefaultTexture.TextureID=new LLUUID("00000000-0000-0000-5005-000000000005");
233
234 LLObject.TextureEntry ntex=new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
235
236 objdata.TextureEntry=ntex.ToBytes();
237 }
238 //********************************************************************
239 public void Read_Prim_database(string name,User_Agent_info user)
240 {
241 StreamReader SR;
242 string line;
243 SR=File.OpenText(name);
244 string [] comp= new string[10];
245 string delimStr = " , ";
246 char [] delimiter = delimStr.ToCharArray();
247
248 line=SR.ReadLine();
249 while(line!="end")
250 {
251 comp=line.Split(delimiter);
252 if(comp[0]=="ObjPack"){
253 int num=Convert.ToInt32(comp[2]);
254 int start=Convert.ToInt32(comp[1]);
255 ObjectUpdatePacket objupdate=new ObjectUpdatePacket();
256 objupdate.RegionData.RegionHandle=1096213093147648;
257 objupdate.RegionData.TimeDilation=64096;
258 objupdate.ObjectData=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[num];
259
260 // int count=0;
261 string data_path=System.Windows.Forms.Application.StartupPath + @"\data\";
262 for(int cc=0; cc<num; cc++)
263 {
264 string filenam=data_path+@"prim_updates"+start+".dat";
265 int i=0;
266 //FileInfo fInfo = new FileInfo("objectupate"+start+".dat");
267 FileInfo fInfo = new FileInfo(filenam);
268 long numBytes = fInfo.Length;
269 //FileStream fStream = new FileStream("objectupate"+start+".dat", FileMode.Open, FileAccess.Read);
270 FileStream fStream = new FileStream(filenam, FileMode.Open, FileAccess.Read);
271 BinaryReader br = new BinaryReader(fStream);
272 byte [] data1 = br.ReadBytes((int)numBytes);
273 br.Close();
274 fStream.Close();
275
276 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata=new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1,ref i);
277 objupdate.ObjectData[cc]=objdata;
278 start++;
279 }
280 server.SendPacket(objupdate,true,user);
281 line=SR.ReadLine();
282 }
283 }
284 SR.Close();
285 }
286 }
287
288 public class prim_info
289 {
290 public LLVector3 pos;
291 public LLVector3 vel;
292 public uint local_ID;
293 public LLUUID full_ID;
294 public prim_data data;
295
296 public prim_info()
297 {
298 pos=new LLVector3(0,0,0);
299 vel=new LLVector3(0,0,0);
300 data=new prim_data();
301 }
302 }
303 public class prim_data
304 {
305 public prim_data()
306 {
307
308 }
309 }
310}
diff --git a/Script_manager.cs b/Script_manager.cs
new file mode 100644
index 0000000..87f2eca
--- /dev/null
+++ b/Script_manager.cs
@@ -0,0 +1,89 @@
1/*
2 * Copyright (c) 2007 Michael Wright
3
4* Copyright (c) <year>, <copyright holder>
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 */
30
31using System;
32using System.Collections;
33//using LuaInterface;
34using libsecondlife;
35
36namespace Second_server
37{
38 /// <summary>
39 /// Description of Script_manager.
40 /// </summary>
41 public class Script_manager
42 {
43 //public LuaInterface.Lua Lu;
44 //private ArrayList scripts;
45 //private prim_info current_prim;
46
47 public Script_manager()
48 {
49 }
50
51 /*public void start_up (Lua lua, App ap)
52 {
53 this.Lu=lua;
54 //register any lua routines , like check finish script one
55 Lu.OpenMathLib();
56 }*/
57 public void script_register( script_object_interface script)
58 {
59 //called by scripts to register themselves
60 }
61
62 public void Call_tick(prim_info prim)
63 {
64 //set current prim and then call tick function in linked script
65 }
66 public void Call_click(prim_info prim)
67 {
68 //set current prim and then call clicked function in linked script
69
70 }
71 private void Register_functions()
72 {
73 //lu.RegisterFunction( "register_script",this,this.GetType().GetMethod("script_register"));
74 //lu.RegisterFunction( "Move_object",this,this.GetType().GetMethod("Move_object"));
75
76 }
77 //Lua registered functions
78 public void Move_object(float x ,float y, float z)
79 {
80
81 }
82 }
83
84 public interface script_object_interface
85 {
86 void Frame_tick();
87 void clicked();
88 }
89}
diff --git a/Second-server.csproj b/Second-server.csproj
new file mode 100644
index 0000000..4823611
--- /dev/null
+++ b/Second-server.csproj
@@ -0,0 +1,62 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <OutputType>Exe</OutputType>
4 <RootNamespace>Second_server</RootNamespace>
5 <AssemblyName>Second-server</AssemblyName>
6 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8 <ProjectGuid>{132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}</ProjectGuid>
9 </PropertyGroup>
10 <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
11 <OutputPath>bin\Debug\</OutputPath>
12 <Optimize>False</Optimize>
13 <DefineConstants>DEBUG;TRACE</DefineConstants>
14 <DebugSymbols>True</DebugSymbols>
15 <DebugType>Full</DebugType>
16 <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
17 </PropertyGroup>
18 <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
19 <OutputPath>bin\Release\</OutputPath>
20 <Optimize>True</Optimize>
21 <DefineConstants>TRACE</DefineConstants>
22 <DebugSymbols>False</DebugSymbols>
23 <DebugType>None</DebugType>
24 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
25 </PropertyGroup>
26 <ItemGroup>
27 <Reference Include="System" />
28 <Reference Include="System.Data" />
29 <Reference Include="System.Drawing" />
30 <Reference Include="System.Windows.Forms" />
31 <Reference Include="System.Xml" />
32 <Reference Include="Axiom.MathLib">
33 <HintPath>bin\Release\Axiom.MathLib.dll</HintPath>
34 <SpecificVersion>False</SpecificVersion>
35 </Reference>
36 <Reference Include="libsecondlife">
37 <HintPath>bin\Release\libsecondlife.dll</HintPath>
38 <SpecificVersion>False</SpecificVersion>
39 </Reference>
40 </ItemGroup>
41 <ItemGroup>
42 <Compile Include="AssemblyInfo.cs" />
43 <Compile Include="Main-sever.Designer.cs">
44 <DependentUpon>Main-sever.cs</DependentUpon>
45 </Compile>
46 <Compile Include="Main-sever.cs">
47 <SubType>Form</SubType>
48 </Compile>
49 <EmbeddedResource Include="Main-sever.resx">
50 <DependentUpon>Main-sever.cs</DependentUpon>
51 </EmbeddedResource>
52 <Compile Include="Agent_Manager.cs" />
53 <Compile Include="Prim_manager.cs" />
54 <Compile Include="Texture_manager.cs" />
55 <Compile Include="Login_manager.cs" />
56 <Compile Include="Physics_manager.cs" />
57 <Compile Include="Asset_manager.cs" />
58 <Compile Include="Script_manager.cs" />
59 <Compile Include="Server.cs" />
60 </ItemGroup>
61 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
62</Project> \ No newline at end of file
diff --git a/Second-server.sln b/Second-server.sln
new file mode 100644
index 0000000..0106f61
--- /dev/null
+++ b/Second-server.sln
@@ -0,0 +1,17 @@
1
2Microsoft Visual Studio Solution File, Format Version 9.00
3# SharpDevelop 2.1.0.2017
4Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Second-server", "Second-server.csproj", "{132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}"
5EndProject
6Global
7 GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 Debug|Any CPU = Debug|Any CPU
9 Release|Any CPU = Release|Any CPU
10 EndGlobalSection
11 GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Debug|Any CPU.Build.0 = Debug|Any CPU
13 {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14 {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Release|Any CPU.Build.0 = Release|Any CPU
15 {132A6E3E-8F2D-4BF5-BDFB-8555F53F334E}.Release|Any CPU.ActiveCfg = Release|Any CPU
16 EndGlobalSection
17EndGlobal
diff --git a/Server.cs b/Server.cs
new file mode 100644
index 0000000..1917922
--- /dev/null
+++ b/Server.cs
@@ -0,0 +1,756 @@
1/*
2 * * Copyright (c) <year>, <copyright holder>
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the <organization> nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28using System;
29using System.Collections.Generic;
30using libsecondlife;
31using System.Collections;
32using libsecondlife.Packets;
33using libsecondlife.AssetSystem;
34using System.Net;
35using System.Net.Sockets;
36using System.Timers;
37
38//really hacked , messy code
39
40namespace Second_server
41{
42 /// <summary>
43 /// Description of Server.
44 /// </summary>
45 public interface Server_callback
46 {
47 void main_callback(Packet pack, User_Agent_info User_info);
48 void new_user(User_Agent_info User_info);
49 void error(string text);
50 }
51 public class Server
52 {
53 /// <summary>A public reference to the client that this Simulator object
54 /// is attached to</summary>
55 //public SecondLife Client;
56
57 /// <summary>The Region class that this Simulator wraps</summary>
58 // public Region Region;
59
60 /// <summary>
61 /// Used internally to track sim disconnections, do not modify this
62 /// variable
63 /// </summary>
64 public bool DisconnectCandidate = false;
65
66 /// <summary>
67 /// The ID number associated with this particular connection to the
68 /// simulator, used to emulate TCP connections. This is used
69 /// internally for packets that have a CircuitCode field
70 /// </summary>
71 public uint CircuitCode
72 {
73 get { return circuitCode; }
74 set { circuitCode = value; }
75 }
76
77 /// <summary>
78 /// The IP address and port of the server
79 /// </summary>
80 public IPEndPoint IPEndPoint
81 {
82 get { return ipEndPoint; }
83 }
84
85 /// <summary>
86 /// A boolean representing whether there is a working connection to the
87 /// simulator or not
88 /// </summary>
89 public bool Connected
90 {
91 get { return connected; }
92 }
93
94 private Server_callback callback_object;
95 //private NetworkManager Network;
96 // private Dictionary<PacketType, List<NetworkManager.PacketCallback>> Callbacks;
97 private uint Sequence = 0;
98 private object SequenceLock = new object();
99 private byte[] RecvBuffer = new byte[4096];
100 private byte[] ZeroBuffer = new byte[8192];
101 private byte[] ZeroOutBuffer = new byte[4096];
102 private Socket Connection = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
103 private AsyncCallback ReceivedData;
104 // Packets we sent out that need ACKs from the simulator
105 // private Dictionary<uint, Packet> NeedAck = new Dictionary<uint, Packet>();
106 // Sequence numbers of packets we've received from the simulator
107 // private Queue<uint> Inbox;
108 // ACKs that are queued up to be sent to the simulator
109 //private Dictionary<uint, uint> PendingAcks = new Dictionary<uint, uint>();
110 private bool connected = false;
111 private uint circuitCode;
112 private IPEndPoint ipEndPoint;
113 private EndPoint endPoint;
114 private IPEndPoint ipeSender;
115 private EndPoint epSender;
116 private System.Timers.Timer AckTimer;
117 private Server_Settings Settings=new Server_Settings();
118 public ArrayList User_agents=new ArrayList();
119
120 /// <summary>
121 /// Constructor for Simulator
122 /// </summary>
123 /// <param name="client"></param>
124 /// <param name="callbacks"></param>
125 /// <param name="circuit"></param>
126 /// <param name="ip"></param>
127 /// <param name="port"></param>
128 public Server(Server_callback s_callback)
129 {
130
131 this.callback_object=s_callback;
132 // Client = client;
133 // Network = client.Network;
134 // Callbacks = callbacks;
135 // Region = new Region(client);
136 // circuitCode = circuit;
137 // Inbox = new Queue<uint>(Settings.INBOX_SIZE);
138 AckTimer = new System.Timers.Timer(Settings.NETWORK_TICK_LENGTH);
139 AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
140
141 // Initialize the callback for receiving a new packet
142 ReceivedData = new AsyncCallback(this.OnReceivedData);
143
144 // Client.Log("Connecting to " + ip.ToString() + ":" + port, Helpers.LogLevel.Info);
145
146 try
147 {
148 // Create an endpoint that we will be communicating with (need it in two
149 // types due to .NET weirdness)
150 // ipEndPoint = new IPEndPoint(ip, port);
151 ipEndPoint = new IPEndPoint(IPAddress.Any, 1000);
152
153
154 endPoint = (EndPoint)ipEndPoint;
155
156 // Associate this simulator's socket with the given ip/port and start listening
157 Connection.Bind(endPoint);
158
159 ipeSender = new IPEndPoint(IPAddress.Any, 0);
160 //The epSender identifies the incoming clients
161 epSender = (EndPoint) ipeSender;
162 Connection.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
163
164
165 // Start the ACK timer
166 AckTimer.Start();
167
168
169
170 // Track the current time for timeout purposes
171 //int start = Environment.TickCount;
172
173 /* while (true)
174 {
175 if (connected || Environment.TickCount - start > Settings.SIMULATOR_TIMEOUT)
176 {
177 return;
178 }
179 System.Threading.Thread.Sleep(10);
180 }*/
181 }
182 catch (Exception e)
183 {
184 // Client.Log(e.ToString(), Helpers.LogLevel.Error);
185 System.Console.WriteLine(e.Message);
186 }
187 }
188
189 /// <summary>
190 /// Disconnect a Simulator
191 /// </summary>
192 public void Disconnect()
193 {
194 if (connected)
195 {
196 connected = false;
197 AckTimer.Stop();
198
199 // Send the CloseCircuit notice
200 CloseCircuitPacket close = new CloseCircuitPacket();
201
202 if (Connection.Connected)
203 {
204 try
205 {
206 // Connection.Send(close.ToBytes());
207 }
208 catch (SocketException)
209 {
210 // There's a high probability of this failing if the network is
211 // disconnecting, so don't even bother logging the error
212 }
213 }
214
215 try
216 {
217 // Shut the socket communication down
218 // Connection.Shutdown(SocketShutdown.Both);
219 }
220 catch (SocketException)
221 {
222 }
223 }
224 }
225
226 /// <summary>
227 /// Sends a packet
228 /// </summary>
229 /// <param name="packet">Packet to be sent</param>
230 /// <param name="incrementSequence">Increment sequence number?</param>
231 public void SendPacket(Packet packet, bool incrementSequence, User_Agent_info User_info)
232 {
233 byte[] buffer;
234 int bytes;
235
236 if (!connected && packet.Type != PacketType.UseCircuitCode)
237 {
238 // Client.Log("Trying to send a " + packet.Type.ToString() + " packet when the socket is closed",
239 // Helpers.LogLevel.Info);
240
241 return;
242 }
243
244 if (packet.Header.AckList.Length > 0)
245 {
246 // Scrub any appended ACKs since all of the ACK handling is done here
247 packet.Header.AckList = new uint[0];
248 }
249 packet.Header.AppendedAcks = false;
250
251 // Keep track of when this packet was sent out
252 packet.TickCount = Environment.TickCount;
253
254 if (incrementSequence)
255 {
256 // Set the sequence number
257 lock (SequenceLock)
258 {
259 if (Sequence > Settings.MAX_SEQUENCE)
260 Sequence = 1;
261 else
262 Sequence++;
263 packet.Header.Sequence = Sequence;
264 }
265
266 if (packet.Header.Reliable)
267 {
268 lock (User_info.NeedAck)
269 {
270 if (!User_info.NeedAck.ContainsKey(packet.Header.Sequence))
271 {
272 User_info.NeedAck.Add(packet.Header.Sequence, packet);
273 }
274 else
275 {
276 // Client.Log("Attempted to add a duplicate sequence number (" +
277 // packet.Header.Sequence + ") to the NeedAck dictionary for packet type " +
278 // packet.Type.ToString(), Helpers.LogLevel.Warning);
279 }
280 }
281
282 // Don't append ACKs to resent packets, in case that's what was causing the
283 // delivery to fail
284 if (!packet.Header.Resent)
285 {
286 // Append any ACKs that need to be sent out to this packet
287 lock (User_info.PendingAcks)
288 {
289 if (User_info.PendingAcks.Count > 0 && User_info.PendingAcks.Count < Settings.MAX_APPENDED_ACKS &&
290 packet.Type != PacketType.PacketAck &&
291 packet.Type != PacketType.LogoutRequest)
292 {
293 packet.Header.AckList = new uint[User_info.PendingAcks.Count];
294
295 int i = 0;
296
297 foreach (uint ack in User_info.PendingAcks.Values)
298 {
299 packet.Header.AckList[i] = ack;
300 i++;
301 }
302
303 User_info.PendingAcks.Clear();
304 packet.Header.AppendedAcks = true;
305 }
306 }
307 }
308 }
309 }
310
311 // Serialize the packet
312 buffer = packet.ToBytes();
313 bytes = buffer.Length;
314
315 try
316 {
317 // Zerocode if needed
318 if (packet.Header.Zerocoded)
319 {
320 lock (ZeroOutBuffer)
321 {
322 bytes = Helpers.ZeroEncode(buffer, bytes, ZeroOutBuffer);
323 Connection.SendTo(ZeroOutBuffer, bytes, SocketFlags.None,User_info.endpoint);
324 }
325 }
326 else
327 {
328
329 Connection.SendTo(buffer, bytes, SocketFlags.None,User_info.endpoint);
330 }
331 }
332 catch (SocketException)
333 {
334 //Client.Log("Tried to send a " + packet.Type.ToString() + " on a closed socket",
335 // Helpers.LogLevel.Warning);
336
337 Disconnect();
338 }
339 }
340
341 /// <summary>
342 /// Send a raw byte array payload as a packet
343 /// </summary>
344 /// <param name="payload">The packet payload</param>
345 /// <param name="setSequence">Whether the second, third, and fourth bytes
346 /// should be modified to the current stream sequence number</param>
347 /* public void SendPacket(byte[] payload, bool setSequence)
348 {
349 if (connected)
350 {
351 try
352 {
353 if (setSequence && payload.Length > 3)
354 {
355 lock (SequenceLock)
356 {
357 payload[1] = (byte)(Sequence >> 16);
358 payload[2] = (byte)(Sequence >> 8);
359 payload[3] = (byte)(Sequence % 256);
360 Sequence++;
361 }
362 }
363
364 Connection.Send(payload, payload.Length, SocketFlags.None);
365 }
366 catch (SocketException e)
367 {
368 // Client.Log(e.ToString(), Helpers.LogLevel.Error);
369 }
370 }
371 else
372 {
373 // Client.Log("Attempted to send a " + payload.Length + " byte payload when " +
374 // "we are disconnected", Helpers.LogLevel.Warning);
375 }
376 }
377 */
378 /// <summary>
379 /// Returns Simulator Name as a String
380 /// </summary>
381 /// <returns></returns>
382 public override string ToString()
383 {
384 return( " (" + ipEndPoint.ToString() + ")");
385 }
386
387 /// <summary>
388 /// Sends out pending acknowledgements
389 /// </summary>
390 private void SendAcks(User_Agent_info User_info)
391 {
392 lock (User_info.PendingAcks)
393 {
394 if (connected && User_info.PendingAcks.Count > 0)
395 {
396 if (User_info.PendingAcks.Count > 250)
397 {
398 // FIXME: Handle the odd case where we have too many pending ACKs queued up
399 //Client.Log("Too many ACKs queued up!", Helpers.LogLevel.Error);
400 return;
401 }
402
403 int i = 0;
404 PacketAckPacket acks = new PacketAckPacket();
405 acks.Packets = new PacketAckPacket.PacketsBlock[User_info.PendingAcks.Count];
406
407 foreach (uint ack in User_info.PendingAcks.Values)
408 {
409 acks.Packets[i] = new PacketAckPacket.PacketsBlock();
410 acks.Packets[i].ID = ack;
411 i++;
412 }
413
414 acks.Header.Reliable = false;
415 SendPacket(acks, true,User_info);
416
417 User_info.PendingAcks.Clear();
418 }
419 }
420 }
421 /// <summary>
422 /// Resend unacknowledged packets
423 /// </summary>
424 private void ResendUnacked(User_Agent_info User_info)
425 {
426 if (connected)
427 {
428 int now = Environment.TickCount;
429
430 lock (User_info.NeedAck)
431 {
432 foreach (Packet packet in User_info.NeedAck.Values)
433 {
434 if (now - packet.TickCount > Settings.RESEND_TIMEOUT)
435 {
436 // Client.Log("Resending " + packet.Type.ToString() + " packet, " +
437 // (now - packet.TickCount) + "ms have passed", Helpers.LogLevel.Info);
438
439 packet.Header.Resent = true;
440 SendPacket(packet, false,User_info);
441 }
442 }
443 }
444 }
445 }
446 /// <summary>
447 /// Callback handler for incomming data
448 /// </summary>
449 /// <param name="result"></param>
450 private void OnReceivedData(IAsyncResult result)
451 {
452
453 ipeSender = new IPEndPoint(IPAddress.Any, 0);
454 epSender = (EndPoint)ipeSender;
455 Packet packet = null;
456 int numBytes;
457
458 // If we're receiving data the sim connection is open
459 connected = true;
460
461 // Update the disconnect flag so this sim doesn't time out
462 DisconnectCandidate = false;
463 User_Agent_info User_info=null;
464
465 lock (RecvBuffer)
466 {
467 // Retrieve the incoming packet
468 try
469 {
470 numBytes = Connection.EndReceiveFrom(result, ref epSender);
471
472 //find user_agent_info
473
474 int packetEnd = numBytes - 1;
475 packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
476
477
478 //should check if login/useconnection packet first
479 if (packet.Type == PacketType.UseCircuitCode)
480 {
481 UseCircuitCodePacket cir_pack=(UseCircuitCodePacket)packet;
482 User_Agent_info new_user=new User_Agent_info();
483 new_user.circuitCode=cir_pack.CircuitCode.Code;
484 new_user.AgentID=cir_pack.CircuitCode.ID;
485 new_user.SessionID=cir_pack.CircuitCode.SessionID;
486 new_user.endpoint=epSender;
487 new_user.Inbox = new Queue<uint>(Settings.INBOX_SIZE);
488
489 this.callback_object.new_user(new_user);
490 this.User_agents.Add(new_user);
491
492 }
493
494
495 User_Agent_info temp_agent=null;
496 IPEndPoint send_ip=(IPEndPoint)epSender;
497 // this.callback_object.error("incoming: address is "+send_ip.Address +"port number is: "+send_ip.Port.ToString());
498
499 for(int ii=0; ii<this.User_agents.Count ; ii++)
500 {
501 temp_agent=(User_Agent_info)this.User_agents[ii];
502 IPEndPoint ag_ip=(IPEndPoint)temp_agent.endpoint;
503 //this.callback_object.error("searching: address is "+ag_ip.Address +"port number is: "+ag_ip.Port.ToString());
504
505 if((ag_ip.Address.ToString()==send_ip.Address.ToString()) && (ag_ip.Port.ToString()==send_ip.Port.ToString()))
506 {
507 //this.callback_object.error("found user");
508 User_info=temp_agent;
509 break;
510 }
511 }
512
513 Connection.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
514 }
515 catch (SocketException)
516 {
517 // Client.Log(endPoint.ToString() + " socket is closed, shutting down " + this.Region.Name,
518 // Helpers.LogLevel.Info);
519
520 connected = false;
521 //Network.DisconnectSim(this);
522 return;
523 }
524 }
525 if(User_info==null)
526 {
527
528 //error finding agent
529 this.callback_object.error("no user found");
530 return;
531 }
532
533 // Fail-safe check
534 if (packet == null)
535 {
536 this.callback_object.error("couldn't build packet");
537 // Client.Log("Couldn't build a message from the incoming data", Helpers.LogLevel.Warning);
538 return;
539 }
540 //this.callback_object.error("past tests");
541 // Track the sequence number for this packet if it's marked as reliable
542 if (packet.Header.Reliable)
543 {
544 if (User_info.PendingAcks.Count > Settings.MAX_PENDING_ACKS)
545 {
546 SendAcks(User_info);
547 }
548
549 // Check if we already received this packet
550 if (User_info.Inbox.Contains(packet.Header.Sequence))
551 {
552 //Client.Log("Received a duplicate " + packet.Type.ToString() + ", sequence=" +
553 // packet.Header.Sequence + ", resent=" + ((packet.Header.Resent) ? "Yes" : "No") +
554 // ", Inbox.Count=" + Inbox.Count + ", NeedAck.Count=" + NeedAck.Count,
555 // Helpers.LogLevel.Info);
556
557 // Send an ACK for this packet immediately
558 //SendAck(packet.Header.Sequence);
559
560 // TESTING: Try just queuing up ACKs for resent packets instead of immediately triggering an ACK
561 lock (User_info.PendingAcks)
562 {
563 uint sequence = (uint)packet.Header.Sequence;
564 if (!User_info.PendingAcks.ContainsKey(sequence)) { User_info.PendingAcks[sequence] = sequence; }
565 }
566
567 // Avoid firing a callback twice for the same packet
568 // this.callback_object.error("avoiding callback");
569 return;
570 }
571 else
572 {
573 lock (User_info.PendingAcks)
574 {
575 uint sequence = (uint)packet.Header.Sequence;
576 if (!User_info.PendingAcks.ContainsKey(sequence)) { User_info.PendingAcks[sequence] = sequence; }
577 }
578 }
579 }
580
581 // Add this packet to our inbox
582 lock (User_info.Inbox)
583 {
584 while (User_info.Inbox.Count >= Settings.INBOX_SIZE)
585 {
586 User_info.Inbox.Dequeue();
587 }
588 User_info.Inbox.Enqueue(packet.Header.Sequence);
589 }
590
591 // Handle appended ACKs
592 if (packet.Header.AppendedAcks)
593 {
594 lock (User_info.NeedAck)
595 {
596 foreach (uint ack in packet.Header.AckList)
597 {
598 User_info.NeedAck.Remove(ack);
599 }
600 }
601 }
602
603 // Handle PacketAck packets
604 if (packet.Type == PacketType.PacketAck)
605 {
606 PacketAckPacket ackPacket = (PacketAckPacket)packet;
607
608 lock (User_info.NeedAck)
609 {
610 foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
611 {
612 User_info.NeedAck.Remove(block.ID);
613 }
614 }
615 }
616
617 // this.callback_object.error("calling callback");
618 this.callback_object.main_callback(packet,User_info);
619 // this.callback_object.error("finished");
620 // Fire the registered packet events
621 #region FireCallbacks
622 /* if (Callbacks.ContainsKey(packet.Type))
623 {
624 List<NetworkManager.PacketCallback> callbackArray = Callbacks[packet.Type];
625
626 // Fire any registered callbacks
627 foreach (NetworkManager.PacketCallback callback in callbackArray)
628 {
629 if (callback != null)
630 {
631 try
632 {
633 callback(packet, this);
634 }
635 catch (Exception e)
636 {
637 Client.Log("Caught an exception in a packet callback: " + e.ToString(),
638 Helpers.LogLevel.Error);
639 }
640 }
641 }
642 }
643
644 if (Callbacks.ContainsKey(PacketType.Default))
645 {
646 List<NetworkManager.PacketCallback> callbackArray = Callbacks[PacketType.Default];
647
648 // Fire any registered callbacks
649 foreach (NetworkManager.PacketCallback callback in callbackArray)
650 {
651 if (callback != null)
652 {
653 try
654 {
655 callback(packet, this);
656 }
657 catch (Exception e)
658 {
659 Client.Log("Caught an exception in a packet callback: " + e.ToString(),
660 Helpers.LogLevel.Error);
661 }
662 }
663 }
664 }
665 */
666 #endregion FireCallbacks
667 }
668
669 private void AckTimer_Elapsed(object sender, ElapsedEventArgs ea)
670 {
671 if (connected)
672 {
673
674 //TODO for each user_agent_info
675 for(int i=0; i<this.User_agents.Count; i++)
676 {
677 User_Agent_info user=(User_Agent_info)this.User_agents[i];
678
679 SendAcks(user);
680 ResendUnacked(user);
681 }
682 }
683 }
684 }
685
686 public class Server_Settings
687 {
688 /// <summary>The version of libsecondlife (not the SL protocol itself)</summary>
689 public string VERSION = "libsecondlife 0.0.9";
690 /// <summary>XML-RPC login server to connect to</summary>
691 public string LOGIN_SERVER = "https://login.agni.lindenlab.com/cgi-bin/login.cgi";
692
693 /// <summary>Millisecond interval between ticks, where all ACKs are
694 /// sent out and the age of unACKed packets is checked</summary>
695 public readonly int NETWORK_TICK_LENGTH = 500;
696 /// <summary>The maximum value of a packet sequence number. After that
697 /// we assume the sequence number just rolls over? Or maybe the
698 /// protocol isn't able to sustain a connection past that</summary>
699 public readonly int MAX_SEQUENCE = 0xFFFFFF;
700 /// <summary>Number of milliseconds before a teleport attempt will time
701 /// out</summary>
702 public readonly int TELEPORT_TIMEOUT = 18 * 1000;
703
704 /// <summary>Number of milliseconds before NetworkManager.Logout() will time out</summary>
705 public int LOGOUT_TIMEOUT = 5 * 1000;
706 /// <summary>Number of milliseconds for xml-rpc to timeout</summary>
707 public int LOGIN_TIMEOUT = 30 * 1000;
708 /// <summary>The maximum size of the sequence number inbox, used to
709 /// check for resent and/or duplicate packets</summary>
710 public int INBOX_SIZE = 100;
711 /// <summary>Milliseconds before a packet is assumed lost and resent</summary>
712 public int RESEND_TIMEOUT = 4000;
713 /// <summary>Milliseconds before the connection to a simulator is
714 /// assumed lost</summary>
715 public int SIMULATOR_TIMEOUT = 15000;
716 /// <summary>Maximum number of queued ACKs to be sent before SendAcks()
717 /// is forced</summary>
718 public int MAX_PENDING_ACKS = 10;
719 /// <summary>Maximum number of ACKs to append to a packet</summary>
720 public int MAX_APPENDED_ACKS = 10;
721 /// <summary>Cost of uploading an asset</summary>
722 public int UPLOAD_COST { get { return priceUpload; } }
723
724
725 private int priceUpload = 0;
726
727 public Server_Settings()
728 {
729
730 }
731 }
732
733 public class User_Agent_info
734 {
735 public EndPoint endpoint;
736 public LLUUID AgentID;
737 public LLUUID SessionID;
738 public uint circuitCode;
739 public string name;
740 public uint localID;
741 public string first_name;
742 public string last_name;
743
744 public Dictionary<uint, Packet> NeedAck = new Dictionary<uint, Packet>();
745 // Sequence numbers of packets we've received from the simulator
746 public Queue<uint> Inbox;
747 // ACKs that are queued up to be sent to the simulator
748 public Dictionary<uint, uint> PendingAcks = new Dictionary<uint, uint>();
749
750 public User_Agent_info()
751 {
752
753 }
754 }
755
756}
diff --git a/Texture_manager.cs b/Texture_manager.cs
new file mode 100644
index 0000000..990557e
--- /dev/null
+++ b/Texture_manager.cs
@@ -0,0 +1,219 @@
1/*
2Copyright (c) 2007 Michael Wright
3
4* Copyright (c) <year>, <copyright holder>
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Collections.Generic;
32using libsecondlife;
33using System.Collections;
34using libsecondlife.Packets;
35using libsecondlife.AssetSystem;
36using System.IO;
37
38
39namespace Second_server
40{
41 /// <summary>
42 /// Description of Texture_manager.
43 /// </summary>
44 public class Texture_manager
45 {
46 public Dictionary<libsecondlife.LLUUID,Texture_image> textures;
47 public ArrayList requests=new ArrayList(); //should change to a generic
48 public ArrayList uploads=new ArrayList();
49 private Server server;
50
51 public Texture_manager(Server serve)
52 {
53 server=serve;
54 textures=new Dictionary<libsecondlife.LLUUID,Texture_image> ();
55 this.initialise();
56 }
57
58 public void add_request(User_Agent_info user, LLUUID image_id)
59 {
60
61 if(!this.textures.ContainsKey(image_id))
62 {
63 //not found image so send back image not in data base message
64 ImageNotInDatabasePacket im_not=new ImageNotInDatabasePacket();
65 im_not.ImageID.ID=image_id;
66 server.SendPacket(im_not,true,user);
67 return;
68 }
69 Texture_image imag=this.textures[image_id];
70 Texture_request req=new Texture_request();
71 req.req_user=user;
72 req.req_image=image_id;
73 req.image_info=imag;
74
75 if(imag.data.LongLength>1000) //should be bigger or smaller?
76 {
77 //over 1000 bytes so split up file
78 req.num_packets=(int)imag.data.LongLength/1000;
79 req.num_packets++;
80 }
81 else
82 {
83 req.num_packets=1;
84 }
85
86 this.requests.Add(req);
87
88 }
89
90 public void add_texture(LLUUID image_id, string name, byte[] data)
91 {
92
93 }
94 public void Do_work(ulong time)
95 {
96 if(this.requests.Count==0)
97 {
98 //no requests waiting
99 return;
100 }
101 int num;
102 //should be running in its own thread but for now is called by timer
103 if(this.requests.Count<5)
104 {
105 //lower than 5 so do all of them
106 num=this.requests.Count;
107 }
108 else
109 {
110 num=5;
111 }
112 Texture_request req;
113 for(int i=0; i<num; i++)
114 {
115 req=(Texture_request)this.requests[i];
116
117 if(req.packet_counter==0)
118 {
119 //first time for this request so send imagedata packet
120 if(req.num_packets==1)
121 {
122 //only one packet so send whole file
123 ImageDataPacket im=new ImageDataPacket();
124 im.ImageID.Packets=1;
125 im.ImageID.ID=req.image_info.Full_ID;
126 im.ImageID.Size=(uint)req.image_info.data.Length;
127 im.ImageData.Data=req.image_info.data;
128 im.ImageID.Codec=2;
129 server.SendPacket(im,true,req.req_user);
130 req.packet_counter++;
131 req.image_info.last_used=time;
132 }
133 else
134 {
135 //more than one packet so split file up
136 }
137 }
138 else
139 {
140 //send imagepacket
141
142 }
143 }
144
145 //remove requests that have been completed
146 for(int i=0; i<num; i++)
147 {
148 req=(Texture_request)this.requests[i];
149 if(req.packet_counter==req.num_packets)
150 {
151 this.requests.Remove(req);
152 }
153 }
154 }
155
156 public void recieve_texture(Packet pack)
157 {
158
159 }
160
161 private void initialise()
162 {
163 //for now read in our test image
164 Texture_image im=new Texture_image();
165 im.filename="testpic2.jp2";
166 im.Full_ID=new LLUUID("00000000-0000-0000-5005-000000000005");
167 this.load_image(im);
168 this.textures.Add(im.Full_ID,im);
169 }
170 private void load_image(Texture_image im)
171 {
172 string data_path=System.Windows.Forms.Application.StartupPath + @"\textures\";
173 string filename=data_path+@im.filename;
174 FileInfo fInfo = new FileInfo(filename);
175
176 long numBytes = fInfo.Length;
177
178 FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
179 byte[] idata=new byte[numBytes];
180 BinaryReader br = new BinaryReader(fStream);
181 idata= br.ReadBytes((int)numBytes);
182 br.Close();
183 fStream.Close();
184 im.data=idata;
185 im.loaded=true;
186 }
187
188 }
189
190 public class Texture_request
191 {
192 public User_Agent_info req_user;
193 public LLUUID req_image;
194 public Texture_image image_info;
195 public long data_pointer=0;
196 public int num_packets=0;
197 public int packet_counter=0;
198
199 public Texture_request()
200 {
201
202 }
203 }
204 public class Texture_image
205 {
206 public byte[] data;
207 public LLUUID Full_ID;
208 public string name;
209 public string filename;
210 public bool loaded;
211 public ulong last_used; //need to add a tick/time counter and keep record
212 // of how often images are requested to unload unused ones.
213
214 public Texture_image()
215 {
216
217 }
218 }
219}