diff options
Diffstat (limited to 'Controller.cs')
-rw-r--r-- | Controller.cs | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/Controller.cs b/Controller.cs new file mode 100644 index 0000000..351ff65 --- /dev/null +++ b/Controller.cs | |||
@@ -0,0 +1,229 @@ | |||
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 | using System; | ||
31 | using System.Timers; | ||
32 | using System.Collections.Generic; | ||
33 | using libsecondlife; | ||
34 | using libsecondlife.Packets; | ||
35 | using System.Collections; | ||
36 | using System.Text; | ||
37 | using System.IO; | ||
38 | using Axiom.MathLib; | ||
39 | using log4net; | ||
40 | |||
41 | namespace Second_server { | ||
42 | /// <summary> | ||
43 | /// Description of MainForm. | ||
44 | /// </summary> | ||
45 | public partial class Controller : Server_callback { | ||
46 | |||
47 | |||
48 | |||
49 | [STAThread] | ||
50 | public static void Main( string[] args ) { | ||
51 | Controller c = new Controller(); | ||
52 | while( true ) // fuckin' a | ||
53 | System.Threading.Thread.Sleep( 1000 ); | ||
54 | |||
55 | } | ||
56 | public Server server; | ||
57 | |||
58 | private Agent_Manager agent_man; | ||
59 | private Prim_manager prim_man; | ||
60 | private Texture_manager texture_man; | ||
61 | private Asset_manager asset_man; | ||
62 | private Login_manager login_man; //built in login server | ||
63 | private ulong time; //ticks | ||
64 | private Timer timer1 = new Timer(); | ||
65 | |||
66 | |||
67 | public Controller() { | ||
68 | server = new Server( this ); | ||
69 | agent_man = new Agent_Manager( this.server ); | ||
70 | prim_man = new Prim_manager( this.server ); | ||
71 | texture_man = new Texture_manager( this.server ); | ||
72 | asset_man = new Asset_manager( this.server ); | ||
73 | prim_man.agent_man = agent_man; | ||
74 | agent_man.prim_man = prim_man; | ||
75 | login_man = new Login_manager(); // startup | ||
76 | login_man.startup(); // login server | ||
77 | timer1.Enabled = true; | ||
78 | timer1.Interval = 200; | ||
79 | timer1.Elapsed +=new ElapsedEventHandler( this.Timer1Tick ); | ||
80 | |||
81 | |||
82 | } | ||
83 | public void main_callback( Packet pack, User_Agent_info User_info ) { | ||
84 | if( ( pack.Type != PacketType.StartPingCheck ) && ( pack.Type != PacketType.AgentUpdate ) ) { | ||
85 | System.Console.WriteLine(pack.Type); | ||
86 | //this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type; | ||
87 | } | ||
88 | if( pack.Type == PacketType.AgentSetAppearance ) { | ||
89 | System.Console.WriteLine(pack); | ||
90 | //this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type; | ||
91 | |||
92 | } | ||
93 | if( pack.Type == PacketType.TransferRequest ) { | ||
94 | TransferRequestPacket tran = (TransferRequestPacket)pack; | ||
95 | LLUUID id = new LLUUID( tran.TransferInfo.Params, 0 ); | ||
96 | |||
97 | if( ( id == new LLUUID( "66c41e39-38f9-f75a-024e-585989bfab73" ) ) || ( id == new LLUUID( "e0ee49b5a4184df8d3c9a65361fe7f49" ) ) ) { | ||
98 | //System.Console.WriteLine(pack); | ||
99 | //System.Console.WriteLine(tran.TransferInfo.TransferID); | ||
100 | asset_man.add_request( User_info, id, tran ); | ||
101 | //this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type; | ||
102 | } | ||
103 | |||
104 | } | ||
105 | if( ( pack.Type == PacketType.StartPingCheck ) ) { | ||
106 | //reply to pingcheck | ||
107 | libsecondlife.Packets.StartPingCheckPacket startp = (libsecondlife.Packets.StartPingCheckPacket)pack; | ||
108 | libsecondlife.Packets.CompletePingCheckPacket endping = new CompletePingCheckPacket(); | ||
109 | endping.PingID.PingID = startp.PingID.PingID; | ||
110 | server.SendPacket( endping, true, User_info ); | ||
111 | } | ||
112 | if( pack.Type == PacketType.CompleteAgentMovement ) { | ||
113 | // new client | ||
114 | agent_man.Agent_join( User_info ); | ||
115 | } | ||
116 | if( pack.Type == PacketType.RequestImage ) { | ||
117 | RequestImagePacket image_req = (RequestImagePacket)pack; | ||
118 | for( int i = 0; i < image_req.RequestImage.Length; i++ ) { | ||
119 | this.texture_man.add_request( User_info, image_req.RequestImage[ i ].Image ); | ||
120 | |||
121 | } | ||
122 | } | ||
123 | if( pack.Type == PacketType.RegionHandshakeReply ) { | ||
124 | //recieved regionhandshake so can now start sending info | ||
125 | agent_man.send_intial_data( User_info ); | ||
126 | //this.setuptemplates("objectupate164.dat",User_info,false); | ||
127 | } | ||
128 | if( pack.Type == PacketType.ObjectAdd ) { | ||
129 | ObjectAddPacket ad = (ObjectAddPacket)pack; | ||
130 | prim_man.create_prim( User_info, ad.ObjectData.RayEnd, ad ); | ||
131 | //this.send_prim(User_info,ad.ObjectData.RayEnd, ad); | ||
132 | } | ||
133 | if( pack.Type == PacketType.ObjectPosition ) { | ||
134 | //System.Console.WriteLine(pack.ToString()); | ||
135 | } | ||
136 | if( pack.Type == PacketType.MultipleObjectUpdate ) { | ||
137 | //System.Console.WriteLine(pack.ToString()); | ||
138 | MultipleObjectUpdatePacket mupd = (MultipleObjectUpdatePacket)pack; | ||
139 | |||
140 | for( int i = 0; i < mupd.ObjectData.Length; i++ ) { | ||
141 | if( mupd.ObjectData[ i ].Type == 9 ) //change position | ||
142 | { | ||
143 | libsecondlife.LLVector3 pos = new LLVector3( mupd.ObjectData[ i ].Data, 0 ); | ||
144 | |||
145 | prim_man.update_prim_position( User_info, pos.X, pos.Y, pos.Z, mupd.ObjectData[ i ].ObjectLocalID ); | ||
146 | //should update stored position of the prim | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | if( pack.Type == PacketType.AgentWearablesRequest ) { | ||
151 | agent_man.send_intial_avatar_apper( User_info ); | ||
152 | } | ||
153 | |||
154 | if( pack.Type == PacketType.AgentUpdate ) { | ||
155 | AgentUpdatePacket ag = (AgentUpdatePacket)pack; | ||
156 | uint mask = ag.AgentData.ControlFlags & ( 1 ); | ||
157 | Avatar_data m_av = agent_man.Get_Agent( User_info.AgentID ); | ||
158 | if( m_av != null ) { | ||
159 | if( m_av.started ) { | ||
160 | if( mask == ( 1 ) ) { | ||
161 | if( !m_av.walk ) { | ||
162 | //start walking | ||
163 | agent_man.send_move_command( User_info, false, m_av.pos.X, m_av.pos.Y, m_av.pos.Z, 0, ag.AgentData.BodyRotation ); | ||
164 | Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3( 1, 0, 0 ); | ||
165 | Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion( ag.AgentData.BodyRotation.W, ag.AgentData.BodyRotation.X, ag.AgentData.BodyRotation.Y, ag.AgentData.BodyRotation.Z ); | ||
166 | Axiom.MathLib.Vector3 direc = q * v3; | ||
167 | direc.Normalize(); | ||
168 | direc = direc * ( ( 0.03f ) * 128f ); | ||
169 | |||
170 | m_av.vel.X = direc.x; | ||
171 | m_av.vel.Y = direc.y; | ||
172 | m_av.vel.Z = direc.z; | ||
173 | m_av.walk = true; | ||
174 | } | ||
175 | } | ||
176 | else { | ||
177 | if( m_av.walk ) { | ||
178 | //walking but key not pressed so need to stop | ||
179 | agent_man.send_move_command( User_info, true, m_av.pos.X, m_av.pos.Y, m_av.pos.Z, 0, ag.AgentData.BodyRotation ); | ||
180 | m_av.walk = false; | ||
181 | m_av.vel.X = 0; | ||
182 | m_av.vel.Y = 0; | ||
183 | m_av.vel.Z = 0; | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | |||
190 | if( pack.Type == PacketType.ChatFromViewer ) { | ||
191 | ChatFromViewerPacket chat = (ChatFromViewerPacket)pack; | ||
192 | System.Text.Encoding enc = System.Text.Encoding.ASCII; | ||
193 | |||
194 | string myString = enc.GetString( chat.ChatData.Message ); | ||
195 | if( myString != "" ) { | ||
196 | string[] comp = new string[ 10 ]; | ||
197 | string delimStr = " , "; | ||
198 | char[] delimiter = delimStr.ToCharArray(); | ||
199 | string line; | ||
200 | |||
201 | line = myString; | ||
202 | comp = line.Split( delimiter ); | ||
203 | if( comp[ 0 ] == "pos" ) { | ||
204 | } | ||
205 | else if( comp[ 0 ] == "veloc" ) { | ||
206 | } | ||
207 | else { | ||
208 | agent_man.send_chat_message( User_info, line ); | ||
209 | |||
210 | } | ||
211 | } | ||
212 | } | ||
213 | } | ||
214 | public void new_user( User_Agent_info User_info ) { | ||
215 | Console.WriteLine( "new user - {0} - has joined [session {1}]", User_info.AgentID.ToString(), User_info.SessionID.ToString() ); | ||
216 | agent_man.New_Agent( User_info ); | ||
217 | } | ||
218 | |||
219 | public void error( string text ) { | ||
220 | Console.WriteLine( "error report: {0}", text ); | ||
221 | } | ||
222 | |||
223 | void Timer1Tick( object sender, System.EventArgs e ) { | ||
224 | this.time++; | ||
225 | agent_man.tick(); | ||
226 | texture_man.Do_work( time ); | ||
227 | } | ||
228 | } | ||
229 | } \ No newline at end of file | ||