public Caps(SecondLife client, Region region, string seedcaps, List<NetworkManager.EventQueueCallback> callbacks) { Client = client; Region = region; this.seedcaps = seedcaps; Callbacks = callbacks; ArrayList req = new ArrayList(); req.Add("MapLayer"); req.Add("MapLayerGod"); req.Add("NewAgentInventory"); req.Add("EventQueueGet"); Hashtable resp = (Hashtable)LLSDRequest(seedcaps,req); foreach(string cap in resp.Keys) { Console.WriteLine("Got cap "+cap+": "+(string)resp[cap]); caps[cap] = (string)resp[cap]; } if(caps.ContainsKey("EventQueueGet")) { Console.WriteLine("Running event queue"); eventThread = new Thread(new ThreadStart(EventQueue)); eventThread.Start(); } }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="callbacks"></param> /// <param name="circuit"></param> /// <param name="ip"></param> /// <param name="port"></param> public Simulator(SecondLife client, Dictionary<PacketType,List<PacketCallback>> callbacks, uint circuit, IPAddress ip, int port) { Client = client; Network = client.Network; Callbacks = callbacks; Region = new Region(client); circuitCode = circuit; Sequence = 0; RecvBuffer = new byte[2048]; Connection = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); connected = false; DisconnectCandidate = false; AckTimer = new System.Timers.Timer(500); AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); // Initialize the dictionary for reliable packets waiting on ACKs from the server NeedAck = new Dictionary<int, Packet>(); // Initialize the lists of sequence numbers we've received so far Inbox = new Queue<ushort>(INBOX_SIZE); PendingAcks = new List<uint>(); Client.Log("Connecting to " + ip.ToString() + ":" + port, Helpers.LogLevel.Info); try { // Setup the callback ReceivedData = new AsyncCallback(OnReceivedData); // Create an endpoint that we will be communicating with (need it in two // types due to .NET weirdness) ipEndPoint = new IPEndPoint(ip, port); endPoint = (EndPoint)ipEndPoint; // Associate this simulator's socket with the given ip/port and start listening Connection.Connect(endPoint); Connection.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref endPoint, ReceivedData, null); // Send the UseCircuitCode packet to initiate the connection UseCircuitCodePacket use = new UseCircuitCodePacket(); use.CircuitCode.Code = circuitCode; use.CircuitCode.ID = Network.AgentID; use.CircuitCode.SessionID = Network.SessionID; // Start the ACK timer AckTimer.Start(); // Send the initial packet out SendPacket(use, true); // Track the current time for timeout purposes int start = Environment.TickCount; while (true) { if (connected || Environment.TickCount - start > 8000) { return; } System.Threading.Thread.Sleep(10); } } catch (Exception e) { Console.WriteLine(e.ToString()); Client.Log(e.ToString(), Helpers.LogLevel.Error); } }
/// <summary> /// Constructor for Simulator /// </summary> /// <param name="client"></param> /// <param name="callbacks"></param> /// <param name="circuit"></param> /// <param name="ip"></param> /// <param name="port"></param> public Simulator(SecondLife client, Dictionary<PacketType, List<NetworkManager.PacketCallback>> callbacks, uint circuit, IPAddress ip, int port) { Client = client; Network = client.Network; Callbacks = callbacks; Region = new Region(client); circuitCode = circuit; Inbox = new Queue<uint>(Client.Settings.INBOX_SIZE); AckTimer = new System.Timers.Timer(Client.Settings.NETWORK_TICK_LENGTH); AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); // Initialize the callback for receiving a new packet ReceivedData = new AsyncCallback(OnReceivedData); Client.Log("Connecting to " + ip.ToString() + ":" + port, Helpers.LogLevel.Info); try { // Create an endpoint that we will be communicating with (need it in two // types due to .NET weirdness) ipEndPoint = new IPEndPoint(ip, port); endPoint = (EndPoint)ipEndPoint; // Associate this simulator's socket with the given ip/port and start listening Connection.Connect(endPoint); Connection.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref endPoint, ReceivedData, null); // Send the UseCircuitCode packet to initiate the connection UseCircuitCodePacket use = new UseCircuitCodePacket(); use.CircuitCode.Code = circuitCode; use.CircuitCode.ID = Network.AgentID; use.CircuitCode.SessionID = Network.SessionID; // Start the ACK timer AckTimer.Start(); // Send the initial packet out SendPacket(use, true); // Track the current time for timeout purposes int start = Environment.TickCount; while (true) { if (connected || Environment.TickCount - start > Client.Settings.SIMULATOR_TIMEOUT) { return; } System.Threading.Thread.Sleep(10); } } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } }