Question

This is kinda hard to explain for me but look:

I made a MMORPG server launcher wich has a start button, whe you click it a little window pops up and asks you to vote for the server and then you can click start again to launch the game(there is a 10 sec countdown before you can actually start the game)

The only thing is that the vote website only accepts a vote from an user each 12 hours(IP and cookie based) and after someone has voted once, it is kinda annoying to have that little window pop up and wait each time you want to start the game.

My idea is: When someone clicks to open the vote window, his system's date and exact hour aer written into a file.

After that, each time you click start the launchers reads that date and time and calculates if 12 hours have been elapsed since you last voted, if yes, it will ask you again to vote and IF NOT, it will just skip that part and directly start the game.

I'm not very experienced and I don't know where to start and how to make this work, your help is highly appreciated.

Thank you!

Here's my event if it can help.

    private void btnStart_Click(object sender, EventArgs e)
    {
        var voteForm = new VoteWindow();
        voteForm.Show();
        voteForm.BringToFront();
        this.Enabled = false;
    }

And here is my code for actually starting the game.

    private void btnStart2_Click(object sender, EventArgs e)
    {
        string error1 = "Deleted because it was too long...";
        string title1 = "Deleted because it was too long...";

        if (File.Exists("engine.exe"))
        {
            Process.Start("engine.exe", "/load /config debug");
            Application.Exit();
        }
        else
        {
            MessageBox.Show(error1, title1, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
Was it helpful?

Solution

Just use Properties.Settings. You can create a new setting by going to your Solution Explorer then expand Properties and open up Settings.Settings. On this page you can create a new System.DateTime object. Then you would do something like this.

private void btnStart_Click(object sender, EventArgs e)
{
    TimeSpan ts = DateTime.Now - Properties.Settings.Default.MySetting;

    if (ts.TotalHours > 12)
    {
        Properties.Settings.Default.MySetting = DateTime.Now;
        Properties.Settings.Default.Save();

        var voteForm = new VoteWindow();
        voteForm.Show();
        voteForm.BringToFront();
        this.Enabled = false;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top