internal void Fail(string typeoffailure, string message, TSPlayer Player, VoteIP IP = null) { SendError(typeoffailure, message); if (Player == null || !Player.Active) { return; } Player.SendErrorMessage("[TServerWeb] Vote failed! Please contact an administrator."); if (IPs.ContainsKey(Player.IP)) { if (IP == null) { IP = IPs[Player.IP]; } IP.Fail(); } }
private void validateCAPTCHA(CommandArgs e) { if (!IPs.ContainsKey(e.Player.IP)) { IPs[e.Player.IP] = new VoteIP(DateTime.Now); } VoteIP IP = IPs[e.Player.IP]; if (IP.State != VoteState.Captcha) { e.Player.SendSuccessMessage("[TServerWeb] We're not awaiting CAPTCHA from you, do /vote first."); return; } int id; string message; if (!GetServerID(out id, out message)) { Fail("Configuration", message, e.Player, IP); return; } string answer = Uri.EscapeDataString(e.Parameters[0].ToString()); string playerName = Uri.EscapeDataString(e.Player.Name); string url = string.Format("answer={0}&user={1}&sid={2}", answer, playerName, id); try { tswQuery(url, e); } catch (Exception ex) { Fail("validateCaptcha", "Attempt to send the query threw an exception: " + ex.Message, e.Player, IP); } }
private void doVote(CommandArgs e) { if (!IPs.ContainsKey(e.Player.IP)) { IPs[e.Player.IP] = new VoteIP(DateTime.Now); } VoteIP IP = IPs[e.Player.IP]; if (!IP.CanVote()) { IP.NotifyPlayer(e.Player); return; } int id; string message; if (!GetServerID(out id, out message)) { Fail("Configuration", message, e.Player, IP); return; } IP.State = VoteState.InProgress; IP.StateTime = DateTime.Now; string url = string.Format("user={0}&sid={1}", Uri.EscapeDataString(e.Player.Name), id); try { tswQuery(url, e); } catch (Exception ex) { Fail("doVote", "Attempt to send the query threw an exception: " + ex.Message, e.Player, IP); } }
internal void Fail(string typeoffailure, string message, TSPlayer Player, VoteIP IP = null) { SendError(typeoffailure, message); if (Player == null || !Player.Active) return; Player.SendErrorMessage("[TServerWeb] Vote failed! Please contact an administrator."); if (IPs.ContainsKey(Player.IP)) { if (IP == null) IP = IPs[Player.IP]; IP.Fail(); } }
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); }