N
Nhoya
Ultima modifica da un moderatore:
Il ping è da sempre una delle cose da tenere sott'occhio se si vuol fare una partita decente. Un developer ha rilasciato questo utile tool che permette di avere sott'occhio il proprio ping durante le partite.
Ecco il codice OpenSource
Codice:
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.Threading;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
namespace League_of_Legends_Preping_checker
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.Text = "EUROPE WEST";
if (Properties.Settings.Default.save)
{
comboBox1.Text = Properties.Settings.Default.server;
host = Properties.Settings.Default.IP;
}
backgroundWorker1.RunWorkerAsync();
}
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,
int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
string host = "95.172.65.1";
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
BackgroundWorker backgroundWorker = (BackgroundWorker)sender;
long totalTime = 0;
int timeout = 120;
Ping pingSender = new Ping();
PingReply reply = pingSender.Send(host, timeout);
if (reply.Status == IPStatus.Success)
{
totalTime = reply.RoundtripTime;
}
backgroundWorker.ReportProgress((int)totalTime);
Thread.Sleep(1000);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (e.ProgressPercentage != 0)
{
UpdatePing(e.ProgressPercentage);
}
}
private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
Color GetColor(Int32 rangeStart /*Complete Red*/, Int32 rangeEnd /*Complete Green*/, Int32 actualValue)
{
if (actualValue >= rangeEnd) return Color.Red;
Int32 max = rangeEnd - rangeStart; // make the scale start from 0
Int32 value = actualValue - rangeStart; // adjust the value accordingly
Int32 red = (255 * value) / max; // calculate green (the closer the value is to max, the greener it gets)
Int32 green = 255 - red; // set red as inverse of green
return Color.FromArgb((Byte)red, (Byte)green, (Byte)0);
}
private void UpdatePing(int ping)
{
try
{
Font font = new Font("Helvetica", 7.0f);
Brush b = new SolidBrush(GetColor(10, 200, ping));
Point p = new Point(0, 3);
using (var image = new Bitmap(16, 16))
using (var g = Graphics.FromImage(image))
{
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
g.DrawString(ping.ToString(), font, b, p);
this.Icon = Icon.FromHandle(image.GetHicon());
notifyIcon1.Icon = Icon.FromHandle(image.GetHicon());
label1.Text = ping.ToString() + "ms";
label1.ForeColor = GetColor(10, 200, ping);
}
}
catch
{ }
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
}
private void button1_Click_1(object sender, EventArgs e)
{
this.Hide();
notifyIcon1.ShowBalloonTip(3);
}
private void button1_MouseHover(object sender, EventArgs e)
{
button1.BackgroundImage = Properties.Resources.btnH2;
}
private void button1_MouseLeave(object sender, EventArgs e)
{
button1.BackgroundImage = Properties.Resources.btn3;
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (Properties.Settings.Default.save)
{
Properties.Settings.Default.IP = host;
Properties.Settings.Default.server = comboBox1.Text;
Properties.Settings.Default.Save();
}
else
{
Properties.Settings.Default.save = false;
Properties.Settings.Default.Save();
}
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
this.Hide();
notifyIcon1.ShowBalloonTip(3);
}
private void comboBox1_Click(object sender, EventArgs e)
{
if (comboBox1.Text == "NORTH AMERICA")
{
comboBox1.Text = "EUROPE WEST";
host = "95.172.65.1";
}
else if (comboBox1.Text == "EUROPE WEST")
{
comboBox1.Text = "EUROPE NORDIC-EAST";
host = "95.172.65.1";
}
else if (comboBox1.Text == "EUROPE NORDIC-EAST")
{
comboBox1.Text = "NORTH AMERICA";
host = "64.7.194.1";
}
else if (comboBox1.Text == "OCEANIA")
{
host = "UNAVAILABLE";
}
else if (comboBox1.Text == "PBE Game Servers")
{
host = "UNAVAILABLE";
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
Form2 settingsForm = new Form2(Cursor.Position.X, Cursor.Position.Y);
settingsForm.ShowDialog(this);
}
private void label3_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void comboBox1_MouseHover(object sender, EventArgs e)
{
comboBox1.BackgroundImage = Properties.Resources.btnH2;
}
private void comboBox1_MouseLeave(object sender, EventArgs e)
{
comboBox1.BackgroundImage = Properties.Resources.btn3;
}
}
}
---------------------SETTINGS VINDU----------------------------------------------------------------
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.Runtime.InteropServices;
using System.Diagnostics;
namespace League_of_Legends_Preping_checker
{
public partial class Form2 : Form
{
private int desiredStartLocationX;
private int desiredStartLocationY;
public Form2(int x, int y)
{
InitializeComponent();
this.desiredStartLocationX = x;
this.desiredStartLocationY = y;
Load += new EventHandler(Form2_Load);
}
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,
int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void Form2_Load(object sender, EventArgs e)
{
if (Properties.Settings.Default.save)
{
checkBox1.Checked = true;
}
else
{
checkBox1.Checked = false;
}
this.SetDesktopLocation(desiredStartLocationX, desiredStartLocationY);
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.save = checkBox1.Checked;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Process.Start("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=sondre%2enjaastad%40gmail%2ecom&lc=NO&item_name=Njastad%2ecom¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted");
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
}
}
Crediti: Sondre Njåstad