Esempio n. 1
0
 /// <summary>
 /// Unregister an event handler
 /// </summary>
 /// <param name="packetType">Packet type to unregister the handler for</param>
 /// <param name="eventHandler">Callback to be unregistered</param>
 public void UnregisterEvent(PacketType packetType, NetworkManager.PacketCallback eventHandler)
 {
     lock (_EventTable)
     {
         if (_EventTable.ContainsKey(packetType) && _EventTable[packetType] != null)
             _EventTable[packetType] -= eventHandler;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Register an event handler
 /// </summary>
 /// <remarks>Use PacketType.Default to fire this event on every 
 /// incoming packet</remarks>
 /// <param name="packetType">Packet type to register the handler for</param>
 /// <param name="eventHandler">Callback to be fired</param>
 public void RegisterEvent(PacketType packetType, NetworkManager.PacketCallback eventHandler)
 {
     lock (_EventTable)
     {
         if (_EventTable.ContainsKey(packetType))
             _EventTable[packetType] += eventHandler;
         else
             _EventTable[packetType] = eventHandler;
     }
 }
 public static void DisconnectHandler(NetworkManager.DisconnectType type, string message)
 {
     if (type == NetworkManager.DisconnectType.NetworkTimeout)
     {
         Console.WriteLine("Network connection timed out, disconnected");
     }
     else if (type == NetworkManager.DisconnectType.ServerInitiated)
     {
         Console.WriteLine("Server disconnected us: " + message);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public SecondLife()
 {
     // These are order-dependant
     Network = new NetworkManager(this);
     Settings = new Settings(this);
     Parcels = new ParcelManager(this);
     Self = new AgentManager(this);
     Avatars = new AvatarManager(this);
     Friends = new FriendsManager(this);
     Grid = new GridManager(this);
     Objects = new ObjectManager(this);
     Groups = new GroupManager(this);
     Assets = new AssetManager(this);
     Appearance = new AppearanceManager(this, Assets);
     Inventory = new InventoryManager(this);
     Directory = new DirectoryManager(this);
     Terrain = new TerrainManager(this);
     Sound = new SoundManager(this);
     Throttle = new AgentThrottle(this);
 }
Esempio n. 5
0
 private void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
 {
     this.Close();
 }
        /// <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);
            }
        }
Esempio n. 8
0
 private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason,
     NetworkManager.LoginResponseData reply)
 {
     id = reply.AgentID;
     sessionID = reply.SessionID;
     secureSessionID = reply.SecureSessionID;
     firstName = reply.FirstName;
     lastName = reply.LastName;
     startLocation = reply.StartLocation;
     agentAccess = reply.AgentAccess;
     lookAt = reply.LookAt;
     homePosition = reply.HomePosition;
     homeLookAt = reply.HomeLookAt;
 }
Esempio n. 9
0
        static void Network_OnLogin(NetworkManager.LoginStatus login, string message)
        {
            Console.WriteLine("Login: "******" (" + message + ")");

            switch (login)
            {
                case NetworkManager.LoginStatus.Failed:
                    LoginEvent.Set();
                    break;
                case NetworkManager.LoginStatus.Success:
                    LoginSuccess = true;
                    LoginEvent.Set();
                    break;
            }
        }
Esempio n. 10
0
 public ClientDisconnectEventArgs(NetworkManager.DisconnectType type, string message)
 {
     this.type = type;
     this.message = message;
 }
Esempio n. 11
0
        private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason, NetworkManager.LoginResponseData replyData)
        {
            if (loginSuccess)
            {
                _Client.DebugLog("Setting InventoryRoot to " + replyData.InventoryRoot.ToStringHyphenated());
                InventoryFolder rootFolder = new InventoryFolder(replyData.InventoryRoot);
                rootFolder.Name = String.Empty;
                rootFolder.ParentUUID = LLUUID.Zero;
                _Store.RootFolder = rootFolder;

                foreach (InventoryFolder folder in replyData.InventorySkeleton)
                    _Store.UpdateNodeFor(folder);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="client">Reference to the SecondLife client</param>
        /// <param name="address">IP address and port of the simulator</param>
        public Simulator(SecondLife client, IPEndPoint address)
        {
            Client = client;

            Estate = new EstateTools(Client);
            Network = client.Network;
            PacketArchive = new Queue<uint>(Settings.PACKET_ARCHIVE_SIZE);
            InBytes = new Queue<ulong>(Client.Settings.STATS_QUEUE_SIZE);
            OutBytes = new Queue<ulong>(Client.Settings.STATS_QUEUE_SIZE);

            // Create an endpoint that we will be communicating with (need it in two 
            // types due to .NET weirdness)
            ipEndPoint = address;
            endPoint = (EndPoint)ipEndPoint;

            // Initialize the callback for receiving a new packet
            ReceivedData = new AsyncCallback(OnReceivedData);

            AckTimer = new System.Timers.Timer(Settings.NETWORK_TICK_LENGTH);
            AckTimer.Elapsed += new System.Timers.ElapsedEventHandler(AckTimer_Elapsed);

            StatsTimer = new System.Timers.Timer(1000);
            StatsTimer.Elapsed += new System.Timers.ElapsedEventHandler(StatsTimer_Elapsed);

            PingTimer = new System.Timers.Timer(Settings.PING_INTERVAL);
            PingTimer.Elapsed += new System.Timers.ElapsedEventHandler(PingTimer_Elapsed);
        }
Esempio n. 13
0
        void onLogout(NetworkManager.DisconnectType type, string message)
        {
            XmlRpcAgencyConnector.MethodName = "XmlRpcAgencyConnector.onLogout";
            XmlRpcAgencyConnector.Params.Clear();
            XmlRpcAgencyConnector.Params.Add(agentName);
            try
            {
                #if DEBUG
                Console.WriteLine("Request: " + XmlRpcAgencyConnector);
                #endif
                XmlRpcResponse response = XmlRpcAgencyConnector.Send(XmlRpcAgencyConnectorUrl);
                #if DEBUG
                Console.WriteLine("Response: " + response);
                #endif

                if (response.IsFault)
                {
                #if DEBUG
                    Console.WriteLine("Fault {0}: {1}", response.FaultCode, response.FaultString);
                #endif
                }
                else
                {
                #if DEBUG
                    Console.WriteLine("Returned: " + response.Value);
                #endif
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception " + e);
            }
        }      
Esempio n. 14
0
        public void Parse(NetworkManager.LoginMethodResponse reply)
        {
            AgentID = LLUUID.Parse(reply.agent_id);
            SessionID = LLUUID.Parse(reply.session_id);
            SecureSessionID = LLUUID.Parse(reply.secure_session_id);
            FirstName = reply.first_name;
            LastName = reply.last_name;
            StartLocation = reply.start_location;
            AgentAccess = reply.agent_access;

            LLSDArray look_at = (LLSDArray)LLSDParser.DeserializeNotation(reply.look_at);
            LookAt = new LLVector3(
                (float)look_at[0].AsReal(),
                (float)look_at[1].AsReal(),
                (float)look_at[2].AsReal());

            if (reply.home != null)
            {
                LLSDMap home = (LLSDMap)LLSDParser.DeserializeNotation(reply.home);
                LLSDArray array = (LLSDArray)home["position"];
                HomePosition = new LLVector3(
                    (float)array[0].AsReal(),
                    (float)array[1].AsReal(),
                    (float)array[2].AsReal());

                array = (LLSDArray)home["look_at"];
                HomeLookAt = new LLVector3(
                    (float)array[0].AsReal(),
                    (float)array[1].AsReal(),
                    (float)array[2].AsReal());
            }

            CircuitCode = (uint)reply.circuit_code;
            RegionX = (uint)reply.region_x;
            RegionY = (uint)reply.region_y;
            SimPort = (ushort)reply.sim_port;
            SimIP = IPAddress.Parse(reply.sim_ip);
            SeedCapability = reply.seed_capability;

            if (reply.buddy_list != null)
            {
                BuddyList = new FriendInfo[reply.buddy_list.Length];
                for (int i = 0; i < BuddyList.Length; ++i)
                {
                    NetworkManager.BuddyListEntry buddy = reply.buddy_list[i];
                    BuddyList[i] = new FriendInfo(buddy.buddy_id, (FriendRights)buddy.buddy_rights_given,
                            (FriendRights)buddy.buddy_rights_has);
                }
            }
            else
            {
                BuddyList = new FriendInfo[0];
            }

            InventoryRoot = LLUUID.Parse(reply.inventory_root[0].folder_id);
            LibraryRoot = LLUUID.Parse(reply.inventory_lib_root[0].folder_id);
            LibraryOwner = LLUUID.Parse(reply.inventory_lib_owner[0].agent_id);
            InventorySkeleton = ParseSkeleton(reply.inventory_skeleton, AgentID);
            LibrarySkeleton = ParseSkeleton(reply.inventory_skel_lib, LibraryOwner);
        }
Esempio n. 15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="client">Reference to the SecondLife client</param>
        /// <param name="port"></param>
        public Simulator(SecondLife client, IPEndPoint address, ulong handle)
            : base(address)
        {
            Client = client;

            ipEndPoint = address;
            Handle = handle;
            Estate = new EstateTools(Client);
            Network = Client.Network;
            PacketArchive = new Queue<uint>(Settings.PACKET_ARCHIVE_SIZE);
            InBytes = new Queue<ulong>(Client.Settings.STATS_QUEUE_SIZE);
            OutBytes = new Queue<ulong>(Client.Settings.STATS_QUEUE_SIZE);

            // Timer for sending out queued packet acknowledgements
            AckTimer = new System.Timers.Timer(Settings.NETWORK_TICK_INTERVAL);
            AckTimer.Elapsed += new System.Timers.ElapsedEventHandler(AckTimer_Elapsed);
            // Timer for recording simulator connection statistics
            StatsTimer = new System.Timers.Timer(1000);
            StatsTimer.Elapsed += new System.Timers.ElapsedEventHandler(StatsTimer_Elapsed);
            // Timer for periodically pinging the simulator
            PingTimer = new System.Timers.Timer(Settings.PING_INTERVAL);
            PingTimer.Elapsed += new System.Timers.ElapsedEventHandler(PingTimer_Elapsed);
        }
Esempio n. 16
0
        private void Network_OnDisconnected(NetworkManager.DisconnectType type, string message)
        {
            if (!loggedIn) return;
            loggedIn = false;

            ClientDisconnectEventArgs ea = new ClientDisconnectEventArgs(type, message);

            if (netcomSync != null)
                netcomSync.BeginInvoke(new OnClientDisconnectRaise(OnClientDisconnected), new object[] { ea });
            else
                OnClientDisconnected(ea);
        }
Esempio n. 17
0
 public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
 {
     Hashtable item = new Hashtable();
     item.Add("MessageType", "Disconnected");
     item.Add("Reason", reason);
     item.Add("Message", message);
     enqueue(item);
 }
Esempio n. 18
0
 public bool Dequeue(int timeout, ref NetworkManager.IncomingPacket packet)
 {
     lock (base.SyncRoot)
     {
         while (open && (base.Count == 0))
         {
             if (!Monitor.Wait(base.SyncRoot, timeout))
                 return false;
         }
         if (open)
         {
             packet = (NetworkManager.IncomingPacket)base.Dequeue();
             return true;
         }
         else
             return false;
     }
 }
Esempio n. 19
0
 private void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
 {
     // Null out the cached fullName since it can change after logging
     // in again (with a different account name or different login
     // server but using the same SecondLife object
     fullName = null;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public SecondLife()
 {
     Network = new NetworkManager(this);
     Parcels = new ParcelManager(this);
     Self = new MainAvatar(this);
     Avatars = new AvatarManager(this);
     Grid = new GridManager(this);
     Objects = new ObjectManager(this);
     Groups = new GroupManager(this);
     Debug = true;
 }
 void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
 {
     // Clear out current state
     ClearState();
 }
Esempio n. 22
0
        public InventoryFolder[] ParseSkeleton(NetworkManager.InventorySkeletonEntry[] skeleton, LLUUID owner)
        {
            Dictionary<LLUUID, InventoryFolder> Folders = new Dictionary<LLUUID, InventoryFolder>();
            Dictionary<LLUUID, List<InventoryFolder>> FoldersChildren = new Dictionary<LLUUID, List<InventoryFolder>>(skeleton.Length);

            foreach (NetworkManager.InventorySkeletonEntry entry in skeleton)
            {
                InventoryFolder folder = new InventoryFolder(entry.folder_id);
                if (entry.type_default != -1)
                    folder.PreferredType = (AssetType)entry.type_default;
                folder.Version = entry.version;
                folder.OwnerID = owner;
                folder.ParentUUID = LLUUID.Parse(entry.parent_id);
                folder.Name = entry.name;
                Folders.Add(entry.folder_id, folder);

                if (entry.parent_id != LLUUID.Zero)
                {
                    List<InventoryFolder> parentChildren;
                    if (!FoldersChildren.TryGetValue(entry.parent_id, out parentChildren))
                    {
                        parentChildren = new List<InventoryFolder>();
                        FoldersChildren.Add(entry.parent_id, parentChildren);
                    }
                    parentChildren.Add(folder);
                }
            }

            foreach (KeyValuePair<LLUUID, List<InventoryFolder>> pair in FoldersChildren)
            {
                if (Folders.ContainsKey(pair.Key))
                {
                    InventoryFolder parentFolder = Folders[pair.Key];
                    parentFolder.DescendentCount = pair.Value.Count; // Should we set this here? it's just the folders, not the items!
                }
            }

            // Should we do this or just return an IEnumerable?
            InventoryFolder[] ret = new InventoryFolder[Folders.Count];
            int index = 0;
            foreach (InventoryFolder folder in Folders.Values)
            {
                ret[index] = folder;
                ++index;
            }
            return ret;
        }
Esempio n. 23
0
 /// <summary>
 /// Terminate any wait handles when the network layer disconnects
 /// </summary>
 private void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
 {
     WearablesRequestEvent.Set();
     WearablesDownloadedEvent.Set();
     CachedResponseEvent.Set();
     UpdateEvent.Set();
 }
 void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
 {
     ParcelsDownloaded.Set();
 }
Esempio n. 25
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="client">Reference to the SecondLife client</param>
        /// <param name="address">IPEndPoint of the simulator</param>
        /// <param name="handle">handle of the simulator</param>
        public Simulator(SecondLife client, IPEndPoint address, ulong handle)
            : base(address)
        {
            Client = client;

            ipEndPoint = address;
            Handle = handle;
            Estate = new EstateTools(Client);
            Network = Client.Network;
            PacketArchive = new Queue<uint>(Settings.PACKET_ARCHIVE_SIZE);
            InBytes = new Queue<ulong>(Client.Settings.STATS_QUEUE_SIZE);
            OutBytes = new Queue<ulong>(Client.Settings.STATS_QUEUE_SIZE);
        }
 void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
 {
     ClearState();
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 public SecondLife()
 {
     // These are order-dependant
     Network = new NetworkManager(this);
     Settings = new Settings(this);
     Parcels = new ParcelManager(this);
     Self = new MainAvatar(this);
     Avatars = new AvatarManager(this);
     Grid = new GridManager(this);
     Objects = new ObjectManager(this);
     Groups = new GroupManager(this);
     Assets = new AssetManager(this);
     Images = new ImageManager(this);
     Inventory = new InventoryManager(this);
     Throttle = new AgentThrottle(this);
 }