Example #1
0
        void SRLClient_ChannelJoined(object sender, string e)
        {
            if (IsDisposed)
            {
                return;
            }

            if (e == SRLClient.RaceChannelName)
            {
                RefreshRaceStateBasedOnAPI();
                if (GameCategory != null)
                {
                    var timer = new System.Timers.Timer(3000);
                    timer.Enabled  = true;
                    timer.Elapsed += timer_Elapsed;
                }
                EnableJoinButton();
            }
            if (e == "#speedrunslive" && RaceId == null)
            {
                SRLClient.SendMainChannelMessage(".startrace " + GameId);
                SRLClient.RaceBotResponseTimer          = new System.Timers.Timer(10000);
                SRLClient.RaceBotResponseTimer.Enabled  = true;
                SRLClient.RaceBotResponseTimer.Elapsed += RaceBotResponseTimer_Elapsed;
            }
            RebuildUserList();
        }
        private void RebuildUserList()
        {
            Action action = () =>
                {
                    lstUsers.Items.Clear();
                    foreach (var user in SRLClient.GetRaceChannelUsers())
                    {
                        lstUsers.Items.Add(new UserListItem(user.Name, GetColorFromRights(user.Rights)));
                    }
                };

            try
            {
                if (!this.Disposing && !this.IsDisposed)
                {
                    if (InvokeRequired)
                        Invoke(action);
                    else
                        action();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Example #3
0
        private void SpeedRunsLiveForm_Load(object sender, EventArgs e)
        {
            btnJoinQuit.Enabled = false;
            var authDialog = new AuthenticationDialog();

            ShareSettings.Default.Reload();
            authDialog.Username         = ShareSettings.Default.SRLIRCUsername;
            authDialog.Password         = ShareSettings.Default.SRLIRCPassword;
            authDialog.RememberPassword = authDialog.Password != "";
            if (authDialog.ShowDialog(this) == DialogResult.OK)
            {
                var username = authDialog.Username;
                var password = authDialog.Password;

                ShareSettings.Default.SRLIRCUsername = username;
                ShareSettings.Default.SRLIRCPassword = authDialog.RememberPassword ? password : "";
                ShareSettings.Default.Save();

                SRLClient.Connect(username, password);
            }
            else
            {
                Close();
            }
        }
Example #4
0
        private void SpeedRunsLiveForm_Load(object sender, EventArgs e)
        {
            btnJoinQuit.Enabled = false;
            var authDialog = new AuthenticationDialog();

            var credentials = WebCredentials.SpeedRunsLiveIRCCredentials;

            authDialog.Username         = credentials.Username ?? "";
            authDialog.Password         = credentials.Password ?? "";
            authDialog.RememberPassword = !string.IsNullOrEmpty(authDialog.Password);

            if (authDialog.ShowDialog(this) == DialogResult.OK)
            {
                var username = authDialog.Username;
                var password = authDialog.Password;

                WebCredentials.SpeedRunsLiveIRCCredentials = new SRLCredentials(username, authDialog.RememberPassword ? password : "");

                SRLClient.Connect(username, password);
            }
            else
            {
                Close();
            }
        }
Example #5
0
 private void SpeedRunsLiveForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     FormIsClosing = true;
     if (SRLClient.IsConnected)
     {
         SRLClient.Disconnect();
     }
     SRLClient.Dispose();
 }
Example #6
0
        private void SpeedRunsLiveForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (SRLClient.RaceState == RaceState.RaceEnded)
                {
                    SpeedRunsLiveAPI.Instance.RefreshRacesList();
                    var race = SpeedRunsLiveAPI.Instance.GetRace(RaceId);
                    if (race.statetext == "In Progress" && ((IDictionary <string, dynamic>)race.entrants.Properties).First(x => x.Key.ToLower() == SRLClient.Username.ToLower()).Value.statetext == "Finished")
                    {
                        var result = MessageBox.Show(this, "Due to SpeedRunsLive rules, you need to confirm that you have completed the race before leaving an unfinished race. Do you confirm that you legitimately finished the race?", "Confirmation Required", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                        if (result == DialogResult.Cancel)
                        {
                            e.Cancel = true;
                            return;
                        }
                        else if (result == DialogResult.No)
                        {
                            SRLClient.Undone();
                            SRLClient.MessageReceived += UndoneMessageReceived;
                            e.Cancel = true;
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            SRLClient.RemoveRaceComparisons();
            FormIsClosing = true;

            if (SRLClient.IsConnected)
            {
                if (SRLClient.RaceState == RaceState.EnteredRace ||
                    SRLClient.RaceState == RaceState.EnteredRaceAndReady ||
                    SRLClient.RaceState == RaceState.RaceStarted)
                {
                    e.Cancel = true;
                    SRLClient.MessageReceived += ExitMessageReceived;
                    SRLClient.QuitRace();
                }
                else
                {
                    SRLClient.Disconnect();
                }
            }

            if (!e.Cancel)
            {
                SRLClient.Dispose();
            }
        }
Example #7
0
 private void chkReady_Click(object sender, EventArgs e)
 {
     if (chkReady.Checked)
     {
         SRLClient.Ready();
     }
     else
     {
         SRLClient.Unready();
     }
 }
        private void txtMessage_KeyDown(object sender, KeyEventArgs e)
        {
            if (txtMessage.Text.StartsWith("\r\n"))
                txtMessage.Clear();

            if (e.KeyCode == Keys.Enter && txtMessage.Text.Length != 0)
            {
                string message = txtMessage.Text;
                SRLClient.SendRaceChannelMessage(message);
                SRLClient_MessageReceived(this, new Tuple<string, SRLIRCUser, string>(SRLClient.RaceChannelName, SRLClient.GetUser(), message));
                txtMessage.Clear();
                e.SuppressKeyPress = true;
                e.Handled = true;
            }
        }
Example #9
0
 private void btnJoinQuit_Click(object sender, EventArgs e)
 {
     if (SRLClient.RaceState == RaceState.EnteredRaceAndReady ||
         SRLClient.RaceState == RaceState.EnteredRace ||
         SRLClient.RaceState == RaceState.RaceStarted)
     {
         SRLClient.QuitRace();
     }
     else if (SRLClient.RaceState == RaceState.NotInRace)
     {
         SRLClient.JoinRace();
     }
     else if (SRLClient.RaceState == RaceState.RaceEnded)
     {
         SRLClient.Undone();
     }
 }
Example #10
0
        void UndoneMessageReceived(object sender, Tuple<string, SRLIRCUser, string> e)
        {
            if (IsDisposed)
                return;

            if (e.Item1 == SRLClient.RaceChannelName
                && e.Item2.Name == "RaceBot"
                && e.Item3 == SRLClient.GetUser().Name + " has been undone from the race.")
            {
                SRLClient.RaceState = RaceState.RaceStarted;
                SRLClient.MessageReceived -= UndoneMessageReceived;
                if (InvokeRequired)
                    Invoke(new Action(Close));
                else
                    Close();
            }
        }
Example #11
0
        void ExitMessageReceived(object sender, Tuple<string, SRLIRCUser, string> e)
        {
            if (IsDisposed)
                return;

            if (e.Item1 == SRLClient.RaceChannelName
                && e.Item2.Name == "RaceBot"
                && (e.Item3 == SRLClient.GetUser().Name + " has been removed from the race."
                || e.Item3 == SRLClient.GetUser().Name + " has forfeited from the race."))
            {
                SRLClient.RaceState = RaceState.NotInRace;
                SRLClient.MessageReceived -= ExitMessageReceived;
                if (InvokeRequired)
                    Invoke(new Action(Close));
                else
                    Close();
            }
        }
Example #12
0
        private void RebuildUserList()
        {
            Action action = () =>
            {
                lstUsers.Items.Clear();
                foreach (var user in SRLClient.GetRaceChannelUsers())
                {
                    lstUsers.Items.Add(new UserListItem(user.Name, GetColorFromRights(user.Rights)));
                }
            };

            if (InvokeRequired)
            {
                Invoke(action);
            }
            else
            {
                action();
            }
        }
Example #13
0
 /// <summary>
 /// Creates a new client to perform requests on the /players endpoint
 /// </summary>
 /// <param name="baseClient">The <see cref="SRLClient"/> used to perform requests</param>
 public PlayersClient(SRLClient baseClient) : base("/players", baseClient)
 {
 }
Example #14
0
 void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     SRLClient.SendRaceChannelMessage(".setgoal " + GameCategory);
     ((System.Timers.Timer)sender).Enabled = false;
 }
Example #15
0
 /// <summary>
 /// Creates a new client to perform requests on the /pastraces endpoint
 /// </summary>
 /// <param name="baseClient">The <see cref="SRLClient"/> used to perform requests</param>
 public PastRacesClient(SRLClient baseClient) : base("/pastraces", baseClient)
 {
 }
 /// <summary>
 /// Creates a new client to perform requests on the /leaderboard endpoint
 /// </summary>
 /// <param name="baseClient">The <see cref="SRLClient"/> used to perform requests</param>
 public LeaderboardsClient(SRLClient baseClient) : base("/leaderboard", baseClient)
 {
 }
Example #17
0
 public void SetUp()
 => _client = new SRLClient();
Example #18
0
 /// <summary>
 /// Creates a new client to perform requests on the /country endpoint
 /// </summary>
 /// <param name="baseClient">The <see cref="SRLClient"/> used to perform requests</param>
 public CountriesClient(SRLClient baseClient) : base("/country", baseClient)
 {
 }
Example #19
0
 /// <summary>
 /// Creates a new client to perform requests on the /games endpoint
 /// </summary>
 /// <param name="baseClient">The <see cref="SRLClient"/> used to perform requests</param>
 public GamesClient(SRLClient baseClient) : base("/games", baseClient)
 {
 }
Example #20
0
 public void Setup()
 {
     _client = new SRLClient();
     _client.Authenticate(_username, _password);
 }
Example #21
0
 /// <summary>
 /// Creates a new client to perform requests on the /stat endpoint
 /// </summary>
 /// <param name="baseClient">The <see cref="SRLClient"/> used to perform requests</param>
 public StatsClient(SRLClient baseClient) : base("/stat", baseClient)
 {
 }
Example #22
0
 /// <summary>
 /// Creates a new instance of <see cref="SRLUser"/>
 /// </summary>
 /// <param name="baseClient">The base client used for requests</param>
 public SRLUser(SRLClient baseClient)
 => _srlClient = baseClient;
Example #23
0
 /// <summary>
 /// Creates a new client to perform requests on the /races endpoint
 /// </summary>
 /// <param name="baseClient">The <see cref="SRLClient"/> used to perform requests</param>
 public RacesClient(SRLClient baseClient) : base("/races", baseClient)
 {
 }
Example #24
0
 /// <summary>
 /// Creates a new SRL endpoint clinet
 /// </summary>
 /// <param name="path"><see cref="BasePath"/> used for requests</param>
 /// <param name="client"><see cref="SrlClient"/> used for request</param>
 public SRLEndpoint(string path, SRLClient client)
 {
     SrlClient = client;
     BasePath  = path;
 }