Player head as console icon

For Windows only
Idea from TNT-UP
This commit is contained in:
ORelio 2014-06-30 13:55:51 +02:00
parent 168f8c4d99
commit 42e706d1a7
5 changed files with 63 additions and 5 deletions

View file

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
using System.Net;
using System.IO;
using System.Drawing;
namespace MinecraftClient
{
/// <summary>
/// Allow to set the player skin as console icon, on Windows only.
/// See StackOverflow no. 2986853
/// </summary>
public static class ConsoleIcon
{
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleIcon(IntPtr hIcon);
/// <summary>
/// Asynchronously download the player's skin and set the head as console icon
/// </summary>
public static void setPlayerIconAsync(string playerName)
{
Thread t = new Thread(new ThreadStart(delegate
{
if (!Program.isUsingMono) //Windows Only
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://skins.minecraft.net/MinecraftSkins/" + playerName + ".png");
try
{
using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
Bitmap skin = new Bitmap(Image.FromStream(httpWebReponse.GetResponseStream())); //Read skin from network
skin = skin.Clone(new Rectangle(8, 8, 8, 8), skin.PixelFormat); //Crop skin
SetConsoleIcon(skin.GetHicon()); //Set skin as icon
}
}
catch (WebException) { } //Skin not found
}
}
));
t.Name = "Player skin icon setter";
t.Start();
}
}
}

View file

@ -62,6 +62,7 @@
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
@ -89,6 +90,7 @@
<Compile Include="Commands\Script.cs" /> <Compile Include="Commands\Script.cs" />
<Compile Include="Commands\Send.cs" /> <Compile Include="Commands\Send.cs" />
<Compile Include="Commands\Set.cs" /> <Compile Include="Commands\Set.cs" />
<Compile Include="ConsoleIcon.cs" />
<Compile Include="ConsoleIO.cs" /> <Compile Include="ConsoleIO.cs" />
<Compile Include="Crypto\Streams\MonoAesStream.cs" /> <Compile Include="Crypto\Streams\MonoAesStream.cs" />
<Compile Include="Crypto\Streams\RegularAesStream.cs" /> <Compile Include="Crypto\Streams\RegularAesStream.cs" />

View file

@ -127,11 +127,13 @@ namespace MinecraftClient
if (result == ProtocolHandler.LoginResult.Success) if (result == ProtocolHandler.LoginResult.Success)
{ {
if (Settings.ConsoleTitle != "") if (Settings.ConsoleTitle != "")
{
Console.Title = Settings.expandVars(Settings.ConsoleTitle); Console.Title = Settings.expandVars(Settings.ConsoleTitle);
}
if (Settings.playerHeadAsIcon)
ConsoleIcon.setPlayerIconAsync(Settings.Username);
Console.WriteLine("Success. (session ID: " + sessionID + ')'); Console.WriteLine("Success. (session ID: " + sessionID + ')');
if (Settings.ServerIP == "") if (Settings.ServerIP == "")
{ {
Console.Write("Server IP : "); Console.Write("Server IP : ");

View file

@ -176,11 +176,11 @@ namespace MinecraftClient.Protocol
catch (System.Security.Authentication.AuthenticationException) catch (System.Security.Authentication.AuthenticationException)
{ {
return LoginResult.SSLError; return LoginResult.SSLError;
}/* }
catch catch
{ {
return LoginResult.OtherError; return LoginResult.OtherError;
}*/ }
} }
/// <summary> /// <summary>

View file

@ -42,6 +42,7 @@ namespace MinecraftClient
public static bool chatTimeStamps = false; public static bool chatTimeStamps = false;
public static bool exitOnFailure = false; public static bool exitOnFailure = false;
public static char internalCmdChar = '/'; public static char internalCmdChar = '/';
public static bool playerHeadAsIcon = false;
//AntiAFK Settings //AntiAFK Settings
public static bool AntiAFK_Enabled = false; public static bool AntiAFK_Enabled = false;
@ -328,6 +329,7 @@ namespace MinecraftClient
+ "mcversion=auto #use 'auto' or '1.X.X' values\r\n" + "mcversion=auto #use 'auto' or '1.X.X' values\r\n"
+ "accountlist=accounts.txt\r\n" + "accountlist=accounts.txt\r\n"
+ "serverlist=servers.txt\r\n" + "serverlist=servers.txt\r\n"
+ "playerheadicon=true\r\n"
+ "exitonfailure=false\r\n" + "exitonfailure=false\r\n"
+ "timestamps=false\r\n" + "timestamps=false\r\n"
+ "\r\n" + "\r\n"