using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Diagnostics;
using System.Threading;
namespace CSGO_Helper
{
public partial class Form1 : Form
{
public static CookieCollection getCookies = new CookieCollection();
static string version = "1.0.0";
static string updurl = "https://yougame.biz/threads/38298/";
public Form1()
{
InitializeComponent();
LoadCFG();
ReloadReports();
CheckReports();
string HTML = SendGet("http://csgohelper.ho.ua/?ver");
LabelVer.Text = "ver. " + version;
if (HTML != null)
{
if(HTML.IndexOf(version) == -1)
{
Process.Start(updurl);
MessageBox.Show("Вышло обновление программы!");
}
}
//gLobby.Rows.Clear();
//gLobby.Rows.Add("Го фаст от лема", "Global Elite", "Нет", "steam://joinlobby/730/109775244772684397/76561198401863098", "присоеденится");
//gLobby.Rows.Add("го +3", "MG-3", "Да", "steam://joinlobby/730/109775244772684397/76561198401863098", "присоеденится");
}
void OpenUrl(string url)
{
if(OpenURLmtd.SelectedIndex == 1) Process.Start("steam://openurl/" + url);
else Process.Start(url);
}
public string SendGet(string Data)
{
if (Data.IndexOf("http") == -1) return null;
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Data);
req.CookieContainer = new CookieContainer();
if (getCookies.Count != 0) req.CookieContainer.Add(getCookies);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
if (HttpStatusCode.OK != resp.StatusCode)
{
MessageBox.Show("Нет подключения!");
return null;
}
getCookies.Add(resp.Cookies);
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string Out = "-1";
Out = sr.ReadToEnd();
sr.Close();
//wbhtml.DocumentText = Out;
return (Out.Length <= 0) ? "-1" : Out;
}
catch(WebException)
{
MessageBox.Show("Нет подключения! (2)");
return null;
}
}
string ParseStr(string str, string find, string end, int offset = 0)
{
int istart = str.IndexOf(find, offset) + find.Length;
if (istart - find.Length == -1) return null;
int iend = (end == null)? str.Length:str.IndexOf(end, istart);
if (iend == -1) return null;
return str.Substring(istart, iend - istart);
}
string ClearFromMask(string str, string mask)
{
string clear = "";
for(int i=0; i< str.Length; i++)
{
if (mask.IndexOf(str[i]) != -1) clear += str[i];
}
return clear;
}
void SaveCFG()
{
StreamWriter config = new StreamWriter("settings.cfg", false);
config.Write("profile=" + ProfileURL.Text + "\r\n");
config.Write("lobby_list_ticks=" + LobbyUpdateTick.Text + "\r\n");
config.Write("open_url_metod=" + OpenURLmtd.SelectedIndex + "\r\n");
config.Write("players_list_ticks=" + UpdateReportsListTick.Text + "\r\n\r\n");
int count = ReportList.Rows.Count;
for (int i = 0; i < count; i++)
{
string steamid = ReportList.Rows[i].Cells[0].Value.ToString();
string name = ReportList.Rows[i].Cells[1].Value.ToString();
string bantype = ReportList.Rows[i].Cells[2].Value.ToString();
config.Write("players_list_add[]=" + steamid + ":" + name + ":" + bantype + "\r\n");
}
config.Close();
}
void LoadCFG()
{
if (!File.Exists("settings.cfg"))
{
if (OpenURLmtd.SelectedIndex == -1) OpenURLmtd.SelectedIndex = 1;
SaveCFG();
return;
}
StreamReader config = new StreamReader("settings.cfg");
while (true)
{
string line = config.ReadLine();
if (line != null)
{
if (line.IndexOf("profile=") != -1) ProfileURL.Text = ParseStr(line, "profile=", null);
else if (line.IndexOf("lobby_list_ticks=") != -1) LobbyUpdateTick.Text = ParseStr(line, "lobby_list_ticks=", null);
else if (line.IndexOf("players_list_ticks=") != -1) UpdateReportsListTick.Text = ParseStr(line, "players_list_ticks=", null);
else if (line.IndexOf("open_url_metod=") != -1) OpenURLmtd.SelectedIndex = Convert.ToInt32(ParseStr(line, "open_url_metod=", null));
else if (line.IndexOf("players_list_add[]=") != -1)
{
string temp = ParseStr(line, "players_list_add[]=", null);
string[] param = temp.Split(':');
ReportList.Rows.Add(param[0], param[1], param[2], "", "Открыть");
CheckReports();
}
}
else break;
}
config.Close();
ReportList.Update();
BanedFrends.Update();
}
private void bUpdateBans_Click(object sender, EventArgs e)
{
if(ProfileURL.Text.IndexOf("http") == -1)
{
MessageBox.Show("Не коректная ссылка на Ваш профиль, укажите через http://");
return;
}
BanedFrends.Rows.Clear();
string html = SendGet(ProfileURL.Text);
if (html == null)
{
MessageBox.Show("Произошла ошибка!");
return;
}
string steamid = ParseStr(html, "\"steamid\":\"", "\"");
if (steamid == null)
{
MessageBox.Show("Steam профиль не найден!");
return;
}
string countfrends = ParseStr(html, "count_link_label\">Friends</span>", "</a>");
countfrends = ParseStr(countfrends, "profile_count_link_total", "</span>");
countfrends = ClearFromMask(countfrends, "0123456789");
CountBans.Text = "Проверено друзей: 0/"+ countfrends + " | Забаненые патрулем: 0 | Забаненые VAC: 0";
html = SendGet("http://steamcommunity.com/profiles/" + steamid + "/friends");
int pos = 0, countcheck = 0, overwath = 0, vac = 0;
while ((pos = html.IndexOf("friendBlock persona", pos) + 1) != -1)
{
countcheck++;
string urlprofile = ParseStr(html, "href=\"", "\">", pos);
if (urlprofile == null) continue;
string profiledata = SendGet(urlprofile);
if (profiledata == null) break;
int indexban = 0, bantype = 0;
string lastban = "";
string name = ParseStr(profiledata, "\"personaname\":\"", "\"");
steamid = ParseStr(profiledata, "\"steamid\":\"", "\"");
if (profiledata.IndexOf("VAC ban on record") != -1) { vac++; bantype = 1; }
else if (profiledata.IndexOf("game ban on record") != -1){ overwath++; bantype = 2; }
if((indexban = profiledata.LastIndexOf("profile_ban_info")) != -1)
{
indexban = profiledata.IndexOf("</div>", indexban);
lastban = ParseStr(profiledata, "</div>", "</div>", indexban);
lastban = ClearFromMask(lastban, "0123456789");
}
if (bantype != 0)BanedFrends.Rows.Add(steamid, name, bantype == 1 ? "VAC бан" : "Патруль", lastban, "Открыть");
CountBans.Text = "Проверено друзей: " + countcheck + "/" + countfrends + " | Забаненые патрулем: " + overwath + " | Забаненые VAC: " + vac;
CountBans.Update();
BanedFrends.Update();
}
}
private void urlbottun_Click(object sender, EventArgs e)
{
//SendGet(urlbox.Text);
//LoadCFG();
wbhtml.Navigate(@urlbox.Text);
}
private void BanedFrends_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4) OpenUrl("http://steamcommunity.com/profiles/" + BanedFrends.Rows[e.RowIndex].Cells[0].Value);
}
private void gLobby_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4)
{
Process.Start(gLobby.Rows[e.RowIndex].Cells[3].Value.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
SaveCFG();
}
private void AddReportList_Click(object sender, EventArgs e)
{
if (ReportProfile.Text.IndexOf("http") == -1)
{
MessageBox.Show("Не коректная ссылка на профиль игрока, укажите через http://");
return;
}
string html = SendGet(ReportProfile.Text);
if (html == null)
{
MessageBox.Show("Произошла ошибка!");
return;
}
string steamid = ParseStr(html, "\"steamid\":\"", "\"");
if (steamid == null)
{
MessageBox.Show("Steam профиль не найден!");
return;
}
string name = ParseStr(html, "\"personaname\":\"", "\"");
ReportList.Rows.Add(steamid, name, "проверка...", "", "Открыть");
CheckReports();
SaveCFG();
}
void CheckReports()
{
int count = ReportList.Rows.Count;
for (int i=0; i<count; i++)
{
string steamid = ReportList.Rows[i].Cells[0].Value.ToString();
string bantype = ReportList.Rows[i].Cells[2].Value.ToString();
if (bantype != "проверка...") continue;
string html = SendGet("http://steamcommunity.com/profiles/"+ ReportList.Rows[i].Cells[0].Value);
if (html == null)
{
MessageBox.Show("Произошла ошибка!");
return;
}
ReportList.Rows[i].Cells[1].Value = ParseStr(html, "\"personaname\":\"", "\"");
if (html.IndexOf("VAC ban on record") != -1) ReportList.Rows[i].Cells[2].Value = "VAC бан";
else if (html.IndexOf("game ban on record") != -1) ReportList.Rows[i].Cells[2].Value = "Патруль";
else ReportList.Rows[i].Cells[2].Value = "Нету";
int indexban = 0;
string lastban = "";
if ((indexban = html.LastIndexOf("profile_ban_info")) != -1)
{
indexban = html.IndexOf("</div>", indexban);
lastban = ParseStr(html, "</div>", "</div>", indexban);
ReportList.Rows[i].Cells[3].Value = ClearFromMask(lastban, "0123456789");
}
if(ReportList.Rows[i].Cells[2].Value.ToString() != "Нету")MessageBox.Show(ReportList.Rows[i].Cells[1].Value + " получил " + ReportList.Rows[i].Cells[2].Value + " " + ReportList.Rows[i].Cells[3].Value + " дня назад!");
ReportList.Update();
}
}
static int ReportRowID = 0;
private void ReportList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4) OpenUrl("http://steamcommunity.com/profiles/" + ReportList.Rows[e.RowIndex].Cells[0].Value);
ReportRowID = e.RowIndex;
}
void ReloadReports()
{
int count = ReportList.Rows.Count;
for (int i = 0; i < count; i++)
{
string steamid = ReportList.Rows[i].Cells[0].Value.ToString();
string bantype = ReportList.Rows[i].Cells[2].Value.ToString();
if (bantype != "Нету") continue;
ReportList.Rows[i].Cells[2].Value = "проверка...";
ReportList.Update();
}
}
private void UpdateReportList_Click(object sender, EventArgs e)
{
ReloadReports();
CheckReports();
}
private void DeleteReport_Click(object sender, EventArgs e)
{
ReportList.Rows.RemoveAt(ReportRowID);
SaveCFG();
}
private void OpenURLmtd_SelectedIndexChanged(object sender, EventArgs e)
{
//MessageBox.Show("Выбрано "+ OpenURLmtd.SelectedIndex);
}
private void LabelVer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(updurl);
}
}
}