aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Server.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Server.cs188
1 files changed, 38 insertions, 150 deletions
diff --git a/Server.cs b/Server.cs
index 342592a..5c8d961 100644
--- a/Server.cs
+++ b/Server.cs
@@ -42,14 +42,14 @@ namespace OpenSim
42 /// <summary> 42 /// <summary>
43 /// Description of Server. 43 /// Description of Server.
44 /// </summary> 44 /// </summary>
45 public interface ServerCallback 45 public interface ServerCallback
46 { 46 {
47 //should replace with delegates 47 //should replace with delegates
48 void MainCallback(Packet pack, User_Agent_info User_info); 48 void MainCallback(Packet pack, User_Agent_info User_info);
49 void NewUserCallback(User_Agent_info User_info); 49 void NewUserCallback(User_Agent_info User_info);
50 void ErrorCallback(string text); 50 void ErrorCallback(string text);
51 } 51 }
52 public class Server 52 public class Server
53 { 53 {
54 /// <summary>A public reference to the client that this Simulator object 54 /// <summary>A public reference to the client that this Simulator object
55 /// is attached to</summary> 55 /// is attached to</summary>
@@ -93,8 +93,6 @@ namespace OpenSim
93 } 93 }
94 94
95 private ServerCallback CallbackObject; 95 private ServerCallback CallbackObject;
96 //private NetworkManager Network;
97 // private Dictionary<PacketType, List<NetworkManager.PacketCallback>> Callbacks;
98 private uint Sequence = 0; 96 private uint Sequence = 0;
99 private object SequenceLock = new object(); 97 private object SequenceLock = new object();
100 private byte[] RecvBuffer = new byte[4096]; 98 private byte[] RecvBuffer = new byte[4096];
@@ -102,12 +100,6 @@ namespace OpenSim
102 private byte[] ZeroOutBuffer = new byte[4096]; 100 private byte[] ZeroOutBuffer = new byte[4096];
103 private Socket Connection = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); 101 private Socket Connection = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
104 private AsyncCallback ReceivedData; 102 private AsyncCallback ReceivedData;
105 // Packets we sent out that need ACKs from the simulator
106 // private Dictionary<uint, Packet> NeedAck = new Dictionary<uint, Packet>();
107 // Sequence numbers of packets we've received from the simulator
108 // private Queue<uint> Inbox;
109 // ACKs that are queued up to be sent to the simulator
110 //private Dictionary<uint, uint> PendingAcks = new Dictionary<uint, uint>();
111 private bool connected = false; 103 private bool connected = false;
112 private uint circuitCode; 104 private uint circuitCode;
113 private IPEndPoint ipEndPoint; 105 private IPEndPoint ipEndPoint;
@@ -129,62 +121,38 @@ namespace OpenSim
129 public Server(ServerCallback s_callback) 121 public Server(ServerCallback s_callback)
130 { 122 {
131 123
132 this.CallbackObject=s_callback; 124 this.CallbackObject=s_callback; //should be using delegate
133 // Client = client; 125 AckTimer = new System.Timers.Timer(Settings.NETWORK_TICK_LENGTH);
134 // Network = client.Network; 126 AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
135 // Callbacks = callbacks; 127
136 // Region = new Region(client); 128 // Initialize the callback for receiving a new packet
137 // circuitCode = circuit; 129 ReceivedData = new AsyncCallback(this.OnReceivedData);
138 // Inbox = new Queue<uint>(Settings.INBOX_SIZE); 130
139 AckTimer = new System.Timers.Timer(Settings.NETWORK_TICK_LENGTH); 131 // Client.Log("Connecting to " + ip.ToString() + ":" + port, Helpers.LogLevel.Info);
140 AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); 132
141 133 try
142 // Initialize the callback for receiving a new packet 134 {
143 ReceivedData = new AsyncCallback(this.OnReceivedData); 135 // Create an endpoint that we will be communicating with (need it in two
144 136 // types due to .NET weirdness)
145 // Client.Log("Connecting to " + ip.ToString() + ":" + port, Helpers.LogLevel.Info); 137 // ipEndPoint = new IPEndPoint(ip, port);
146 138 ipEndPoint = new IPEndPoint(IPAddress.Any, Globals.Instance.IpPort);
147 try 139 endPoint = (EndPoint)ipEndPoint;
148 { 140
149 // Create an endpoint that we will be communicating with (need it in two 141 // Associate this simulator's socket with the given ip/port and start listening
150 // types due to .NET weirdness) 142 Connection.Bind(endPoint);
151 // ipEndPoint = new IPEndPoint(ip, port); 143 ipeSender = new IPEndPoint(IPAddress.Any, 0);
152 ipEndPoint = new IPEndPoint(IPAddress.Any, Globals.Instance.IpPort);
153
154
155 endPoint = (EndPoint)ipEndPoint;
156
157 // Associate this simulator's socket with the given ip/port and start listening
158 Connection.Bind(endPoint);
159
160 ipeSender = new IPEndPoint(IPAddress.Any, 0);
161 //The epSender identifies the incoming clients 144 //The epSender identifies the incoming clients
162 epSender = (EndPoint) ipeSender; 145 epSender = (EndPoint) ipeSender;
163 Connection.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); 146 Connection.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
164 147
165 148 // Start the ACK timer
166 // Start the ACK timer 149 AckTimer.Start();
167 AckTimer.Start(); 150 }
168 151 catch (Exception e)
169 152 {
170 153
171 // Track the current time for timeout purposes 154 System.Console.WriteLine(e.Message);
172 //int start = Environment.TickCount; 155 }
173
174 /* while (true)
175 {
176 if (connected || Environment.TickCount - start > Settings.SIMULATOR_TIMEOUT)
177 {
178 return;
179 }
180 System.Threading.Thread.Sleep(10);
181 }*/
182 }
183 catch (Exception e)
184 {
185 // Client.Log(e.ToString(), Helpers.LogLevel.Error);
186 System.Console.WriteLine(e.Message);
187 }
188 } 156 }
189 157
190 /// <summary> 158 /// <summary>
@@ -292,9 +260,8 @@ namespace OpenSim
292 packet.Type != PacketType.LogoutRequest) 260 packet.Type != PacketType.LogoutRequest)
293 { 261 {
294 packet.Header.AckList = new uint[User_info.PendingAcks.Count]; 262 packet.Header.AckList = new uint[User_info.PendingAcks.Count];
295
296 int i = 0; 263 int i = 0;
297 264
298 foreach (uint ack in User_info.PendingAcks.Values) 265 foreach (uint ack in User_info.PendingAcks.Values)
299 { 266 {
300 packet.Header.AckList[i] = ack; 267 packet.Header.AckList[i] = ack;
@@ -345,37 +312,6 @@ namespace OpenSim
345 /// <param name="payload">The packet payload</param> 312 /// <param name="payload">The packet payload</param>
346 /// <param name="setSequence">Whether the second, third, and fourth bytes 313 /// <param name="setSequence">Whether the second, third, and fourth bytes
347 /// should be modified to the current stream sequence number</param> 314 /// should be modified to the current stream sequence number</param>
348 /* public void SendPacket(byte[] payload, bool setSequence)
349 {
350 if (connected)
351 {
352 try
353 {
354 if (setSequence && payload.Length > 3)
355 {
356 lock (SequenceLock)
357 {
358 payload[1] = (byte)(Sequence >> 16);
359 payload[2] = (byte)(Sequence >> 8);
360 payload[3] = (byte)(Sequence % 256);
361 Sequence++;
362 }
363 }
364
365 Connection.Send(payload, payload.Length, SocketFlags.None);
366 }
367 catch (SocketException e)
368 {
369 // Client.Log(e.ToString(), Helpers.LogLevel.Error);
370 }
371 }
372 else
373 {
374 // Client.Log("Attempted to send a " + payload.Length + " byte payload when " +
375 // "we are disconnected", Helpers.LogLevel.Warning);
376 }
377 }
378 */
379 /// <summary> 315 /// <summary>
380 /// Returns Simulator Name as a String 316 /// Returns Simulator Name as a String
381 /// </summary> 317 /// </summary>
@@ -615,56 +551,8 @@ namespace OpenSim
615 } 551 }
616 } 552 }
617 553
618 // this.callback_object.error("calling callback");
619 this.CallbackObject.MainCallback(packet,User_info); 554 this.CallbackObject.MainCallback(packet,User_info);
620 // this.callback_object.error("finished"); 555
621 // Fire the registered packet events
622 #region FireCallbacks
623 /* if (Callbacks.ContainsKey(packet.Type))
624 {
625 List<NetworkManager.PacketCallback> callbackArray = Callbacks[packet.Type];
626
627 // Fire any registered callbacks
628 foreach (NetworkManager.PacketCallback callback in callbackArray)
629 {
630 if (callback != null)
631 {
632 try
633 {
634 callback(packet, this);
635 }
636 catch (Exception e)
637 {
638 Client.Log("Caught an exception in a packet callback: " + e.ToString(),
639 Helpers.LogLevel.Error);
640 }
641 }
642 }
643 }
644
645 if (Callbacks.ContainsKey(PacketType.Default))
646 {
647 List<NetworkManager.PacketCallback> callbackArray = Callbacks[PacketType.Default];
648
649 // Fire any registered callbacks
650 foreach (NetworkManager.PacketCallback callback in callbackArray)
651 {
652 if (callback != null)
653 {
654 try
655 {
656 callback(packet, this);
657 }
658 catch (Exception e)
659 {
660 Client.Log("Caught an exception in a packet callback: " + e.ToString(),
661 Helpers.LogLevel.Error);
662 }
663 }
664 }
665 }
666 */
667 #endregion FireCallbacks
668 } 556 }
669 557
670 private void AckTimer_Elapsed(object sender, ElapsedEventArgs ea) 558 private void AckTimer_Elapsed(object sender, ElapsedEventArgs ea)
@@ -677,8 +565,8 @@ namespace OpenSim
677 { 565 {
678 User_Agent_info user=(User_Agent_info)this.User_agents[i]; 566 User_Agent_info user=(User_Agent_info)this.User_agents[i];
679 567
680 SendAcks(user); 568 SendAcks(user);
681 ResendUnacked(user); 569 ResendUnacked(user);
682 } 570 }
683 } 571 }
684 } 572 }
@@ -731,7 +619,7 @@ namespace OpenSim
731 } 619 }
732 } 620 }
733 621
734 public class User_Agent_info 622 public class User_Agent_info
735 { 623 {
736 public EndPoint endpoint; 624 public EndPoint endpoint;
737 public LLUUID AgentID; 625 public LLUUID AgentID;