-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoteIP.cs
79 lines (65 loc) · 1.59 KB
/
VoteIP.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
namespace TSWVote
{
internal class VoteIP
{
internal VoteState State = VoteState.None;
internal DateTime StateTime;
internal VoteIP(DateTime time, VoteState state = VoteState.None)
{
State = state;
StateTime = time;
}
internal bool CanVote()
{
bool Return;
switch (State)
{
case VoteState.None:
default:
return true;
case VoteState.InProgress:
case VoteState.Fail:
case VoteState.Captcha:
Return = (DateTime.Now - StateTime).TotalMinutes > 5;
break;
case VoteState.Success:
Return = (DateTime.Now - StateTime).TotalHours > 24;
break;
case VoteState.Wait:
Return = (DateTime.Now - StateTime).TotalHours > 1;
break;
}
if (Return && State != VoteState.None)
{
State = VoteState.None;
StateTime = DateTime.Now;
}
return Return;
}
internal void Fail()
{
State = VoteState.Fail;
StateTime = DateTime.Now;
}
internal void NotifyPlayer(TShockAPI.TSPlayer Player)
{
switch (State)
{
case VoteState.Captcha:
Player.SendSuccessMessage("[TServerWeb] Please enter CAPTCHA!");
break;
case VoteState.Fail:
Player.SendSuccessMessage("[TServerWeb] Your previous vote failed! Please wait 5 minutes before trying again!");
break;
case VoteState.InProgress:
Player.SendSuccessMessage("[TServerWeb] Your vote is being processed, please wait...");
break;
case VoteState.Success:
case VoteState.Wait:
Player.SendSuccessMessage("[TServerWeb] Please wait 24 hours before voting for this server again!");
break;
}
}
}
}