예제 #1
0
        public static void Disconnect()
        {
            session?.Socket?.DisconnectAsync();

            serverUrl = null;
            userName  = null;
            password  = null;

            IsConnected = false;

            session = null;

            cachedConnectionResult = null;
        }
예제 #2
0
        public static LoginResult Connect(string server, string user, string pass = null, string connectionId = null)
        {
            if (IsConnected && session.Socket.Connected && cachedConnectionResult != null)
            {
                if (serverUrl == server && userName == user && password == pass)
                {
                    return(cachedConnectionResult);
                }

                Disconnect();
            }

            serverUrl = server;
            userName  = user;
            password  = pass;

            try
            {
                session = ArchipelagoSessionFactory.CreateSession(new Uri(serverUrl));
                session.Socket.PacketReceived += PackageReceived;

                var result = session.TryConnectAndLogin("Timespinner", userName, new Version(0, 3, 0),
                                                        ItemsHandlingFlags.IncludeStartingInventory, new [] { "DeathLink" }, password: password);

                IsConnected            = result.Successful;
                cachedConnectionResult = result;

                if (result.Successful)
                {
#if DEBUG
                    ScreenManager.Console.AddCommand(new ScoutCommand());
                    ScreenManager.Console.AddCommand(new GetKeyCommand());
#endif
                }
            }
            catch (Exception e)
            {
                IsConnected            = false;
                cachedConnectionResult = new LoginFailure(e.Message);
            }

            return(cachedConnectionResult);
        }