private void ReuseWC(VoteWC WC) { if (WC == null) { return; } webClientQueue.Enqueue(WC); }
public TSWVote(Main game) : base(game) { Order = 1000; WebRequest.DefaultWebProxy = null; TSWConfig = Config.Read(); webClientQueue = new ConcurrentQueue<VoteWC>(); for (int i = 0; i < TSWConfig.NumberOfWebClients; i++) { VoteWC webClient = new VoteWC(); webClient.DownloadStringCompleted += WebClient_DownloadStringCompleted; webClientQueue.Enqueue(webClient); } }
public TSWVote(Main game) : base(game) { Order = 1000; WebRequest.DefaultWebProxy = null; TSWConfig = Config.Read(); webClientQueue = new ConcurrentQueue <VoteWC>(); for (int i = 0; i < TSWConfig.NumberOfWebClients; i++) { VoteWC webClient = new VoteWC(); webClient.DownloadStringCompleted += WebClient_DownloadStringCompleted; webClientQueue.Enqueue(webClient); } }
private void ReuseWC(VoteWC WC) { if (WC == null) return; webClientQueue.Enqueue(WC); }
private void WebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { VoteWC webClient = sender as VoteWC; CommandArgs args = e.UserState as CommandArgs; if (args == null) { ReuseWC(webClient); return; } if (!IPs.ContainsKey(args.Player.IP)) { IPs[args.Player.IP] = new VoteIP(DateTime.Now); } VoteIP IP = IPs[args.Player.IP]; if (e.Error != null) { Fail("Exception", e.Error.Message, args.Player, IP); ReuseWC(webClient); return; } Response response = Response.Read(e.Result); if (response == null) { Fail("Response", "Invalid response received.", args.Player, IP); ReuseWC(webClient); return; } switch (response.response) { case "success": // Correct answer was provided // This means a vote is placed args.Player.SendSuccessMessage("[TServerWeb] " + response.message); if (response.message != "Please wait 24 hours before voting for this server again!") { IP.State = VoteState.Success; IP.StateTime = DateTime.Now; VoteHooks.InvokeVoteSuccess(args.Player); } else { IP.State = VoteState.Wait; IP.StateTime = DateTime.Now; } break; case "failure": Fail("Vote", response.message, args.Player, IP); break; case "captcha": args.Player.SendSuccessMessage("[TServerWeb] Please answer the question to make sure you are human."); args.Player.SendSuccessMessage("[TServerWeb] You can type /vote <answer>"); args.Player.SendSuccessMessage("[TServerWeb] (CAPTCHA) " + response.message); IP.State = VoteState.Captcha; IP.StateTime = DateTime.Now; break; case "nocaptcha": // Answer was provided, but there was no pending captcha // Let's consider it a fail, since plugin has VoteStates to prevent this from happening Fail("Vote", response.message, args.Player, IP); break; case "captchafail": args.Player.SendErrorMessage("[TServerWeb] Vote failed! Reason: " + response.message); IP.State = VoteState.None; IP.StateTime = DateTime.Now; break; case "": case null: default: Fail("Connection", "Response is blank, something is wrong with connection. Please email [email protected] about this issue.", args.Player, IP); break; } ReuseWC(webClient); }