1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*
Copyright (c) 2007 Michael Wright
* Copyright (c) <year>, <copyright holder>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Timers;
using System.Collections.Generic;
using libsecondlife;
using libsecondlife.Packets;
using System.Collections;
using System.Text;
using System.IO;
using Axiom.MathLib;
using log4net;
namespace Second_server {
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class Controller : Server_callback {
[STAThread]
public static void Main( string[] args ) {
Controller c = new Controller();
while( true ) // fuckin' a
System.Threading.Thread.Sleep( 1000 );
}
public Server server;
private Agent_Manager agent_man;
private Prim_manager prim_man;
private Texture_manager texture_man;
private Asset_manager asset_man;
private Login_manager login_man; //built in login server
private ulong time; //ticks
private Timer timer1 = new Timer();
public Controller() {
server = new Server( this );
agent_man = new Agent_Manager( this.server );
prim_man = new Prim_manager( this.server );
texture_man = new Texture_manager( this.server );
asset_man = new Asset_manager( this.server );
prim_man.agent_man = agent_man;
agent_man.prim_man = prim_man;
login_man = new Login_manager(); // startup
login_man.startup(); // login server
timer1.Enabled = true;
timer1.Interval = 200;
timer1.Elapsed +=new ElapsedEventHandler( this.Timer1Tick );
}
public void main_callback( Packet pack, User_Agent_info User_info ) {
if( ( pack.Type != PacketType.StartPingCheck ) && ( pack.Type != PacketType.AgentUpdate ) ) {
System.Console.WriteLine(pack.Type);
//this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type;
}
if( pack.Type == PacketType.AgentSetAppearance ) {
System.Console.WriteLine(pack);
//this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type;
}
if( pack.Type == PacketType.TransferRequest ) {
TransferRequestPacket tran = (TransferRequestPacket)pack;
LLUUID id = new LLUUID( tran.TransferInfo.Params, 0 );
if( ( id == new LLUUID( "66c41e39-38f9-f75a-024e-585989bfab73" ) ) || ( id == new LLUUID( "e0ee49b5a4184df8d3c9a65361fe7f49" ) ) ) {
//System.Console.WriteLine(pack);
//System.Console.WriteLine(tran.TransferInfo.TransferID);
asset_man.add_request( User_info, id, tran );
//this.richTextBox1.Text=this.richTextBox1.Text+"\n "+pack.Type;
}
}
if( ( pack.Type == PacketType.StartPingCheck ) ) {
//reply to pingcheck
libsecondlife.Packets.StartPingCheckPacket startp = (libsecondlife.Packets.StartPingCheckPacket)pack;
libsecondlife.Packets.CompletePingCheckPacket endping = new CompletePingCheckPacket();
endping.PingID.PingID = startp.PingID.PingID;
server.SendPacket( endping, true, User_info );
}
if( pack.Type == PacketType.CompleteAgentMovement ) {
// new client
agent_man.Agent_join( User_info );
}
if( pack.Type == PacketType.RequestImage ) {
RequestImagePacket image_req = (RequestImagePacket)pack;
for( int i = 0; i < image_req.RequestImage.Length; i++ ) {
this.texture_man.add_request( User_info, image_req.RequestImage[ i ].Image );
}
}
if( pack.Type == PacketType.RegionHandshakeReply ) {
//recieved regionhandshake so can now start sending info
agent_man.send_intial_data( User_info );
//this.setuptemplates("objectupate164.dat",User_info,false);
}
if( pack.Type == PacketType.ObjectAdd ) {
ObjectAddPacket ad = (ObjectAddPacket)pack;
prim_man.create_prim( User_info, ad.ObjectData.RayEnd, ad );
//this.send_prim(User_info,ad.ObjectData.RayEnd, ad);
}
if( pack.Type == PacketType.ObjectPosition ) {
//System.Console.WriteLine(pack.ToString());
}
if( pack.Type == PacketType.MultipleObjectUpdate ) {
//System.Console.WriteLine(pack.ToString());
MultipleObjectUpdatePacket mupd = (MultipleObjectUpdatePacket)pack;
for( int i = 0; i < mupd.ObjectData.Length; i++ ) {
if( mupd.ObjectData[ i ].Type == 9 ) //change position
{
libsecondlife.LLVector3 pos = new LLVector3( mupd.ObjectData[ i ].Data, 0 );
prim_man.update_prim_position( User_info, pos.X, pos.Y, pos.Z, mupd.ObjectData[ i ].ObjectLocalID );
//should update stored position of the prim
}
}
}
if( pack.Type == PacketType.AgentWearablesRequest ) {
agent_man.send_intial_avatar_apper( User_info );
}
if( pack.Type == PacketType.AgentUpdate ) {
AgentUpdatePacket ag = (AgentUpdatePacket)pack;
uint mask = ag.AgentData.ControlFlags & ( 1 );
Avatar_data m_av = agent_man.Get_Agent( User_info.AgentID );
if( m_av != null ) {
if( m_av.started ) {
if( mask == ( 1 ) ) {
if( !m_av.walk ) {
//start walking
agent_man.send_move_command( User_info, false, m_av.pos.X, m_av.pos.Y, m_av.pos.Z, 0, ag.AgentData.BodyRotation );
Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3( 1, 0, 0 );
Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion( ag.AgentData.BodyRotation.W, ag.AgentData.BodyRotation.X, ag.AgentData.BodyRotation.Y, ag.AgentData.BodyRotation.Z );
Axiom.MathLib.Vector3 direc = q * v3;
direc.Normalize();
direc = direc * ( ( 0.03f ) * 128f );
m_av.vel.X = direc.x;
m_av.vel.Y = direc.y;
m_av.vel.Z = direc.z;
m_av.walk = true;
}
}
else {
if( m_av.walk ) {
//walking but key not pressed so need to stop
agent_man.send_move_command( User_info, true, m_av.pos.X, m_av.pos.Y, m_av.pos.Z, 0, ag.AgentData.BodyRotation );
m_av.walk = false;
m_av.vel.X = 0;
m_av.vel.Y = 0;
m_av.vel.Z = 0;
}
}
}
}
}
if( pack.Type == PacketType.ChatFromViewer ) {
ChatFromViewerPacket chat = (ChatFromViewerPacket)pack;
System.Text.Encoding enc = System.Text.Encoding.ASCII;
string myString = enc.GetString( chat.ChatData.Message );
if( myString != "" ) {
string[] comp = new string[ 10 ];
string delimStr = " , ";
char[] delimiter = delimStr.ToCharArray();
string line;
line = myString;
comp = line.Split( delimiter );
if( comp[ 0 ] == "pos" ) {
}
else if( comp[ 0 ] == "veloc" ) {
}
else {
agent_man.send_chat_message( User_info, line );
}
}
}
}
public void new_user( User_Agent_info User_info ) {
Console.WriteLine( "new user - {0} - has joined [session {1}]", User_info.AgentID.ToString(), User_info.SessionID.ToString() );
agent_man.New_Agent( User_info );
}
public void error( string text ) {
Console.WriteLine( "error report: {0}", text );
}
void Timer1Tick( object sender, System.EventArgs e ) {
this.time++;
agent_man.tick();
texture_man.Do_work( time );
}
}
}
|