Significantly refactor launcher. Public servers list and 'minecraft.net/classicube.net server' tabs are merged into one tab. As both the minecraft.net and classicube.net tabs essentially shared the exact same functionality, this functionality is encapsulated in a new 'GameState' class.

This commit is contained in:
UnknownShadow200 2015-07-01 09:12:12 +10:00
parent 536845393c
commit f88405330c
6 changed files with 963 additions and 1184 deletions

View File

@ -36,7 +36,9 @@
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<NoWin32Manifest>False</NoWin32Manifest>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -52,6 +54,7 @@
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\output\release\</OutputPath>
@ -77,6 +80,7 @@
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="MainForm.GameState.cs" />
<Compile Include="MinecraftSession.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -30,19 +30,6 @@ namespace Launcher
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.btnMCSignIn = new System.Windows.Forms.Button();
this.txtMCPassword = new System.Windows.Forms.TextBox();
this.lblMCPassword = new System.Windows.Forms.Label();
this.txtMCUser = new System.Windows.Forms.TextBox();
this.lblMCUser = new System.Windows.Forms.Label();
this.txtMCSearch = new System.Windows.Forms.TextBox();
this.lblMCSearch = new System.Windows.Forms.Label();
this.btnMCConnect = new System.Windows.Forms.Button();
this.lblMCPublicName = new System.Windows.Forms.Label();
this.lblMCServerName = new System.Windows.Forms.Label();
this.txtMCHash = new System.Windows.Forms.TextBox();
this.lblMCPlayUrl = new System.Windows.Forms.Label();
this.lblMCServerUrl = new System.Windows.Forms.Label();
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.tabMinecraftNet = new System.Windows.Forms.TabPage();
this.tabMC = new System.Windows.Forms.TabControl();
@ -50,15 +37,24 @@ namespace Launcher
this.prgMCStatus = new System.Windows.Forms.ProgressBar();
this.lblMCStatusLabel = new System.Windows.Forms.Label();
this.lblMCStatus = new System.Windows.Forms.Label();
this.lbMCUser = new System.Windows.Forms.Label();
this.btnMCSignIn = new System.Windows.Forms.Button();
this.txtMCUser = new System.Windows.Forms.TextBox();
this.txtMCPassword = new System.Windows.Forms.TextBox();
this.lblMCPass = new System.Windows.Forms.Label();
this.tabMCServers = new System.Windows.Forms.TabPage();
this.tblMCServers = new System.Windows.Forms.ListView();
this.colMCName = new System.Windows.Forms.ColumnHeader();
this.colMCPlayers = new System.Windows.Forms.ColumnHeader();
this.colMCMaxPlayers = new System.Windows.Forms.ColumnHeader();
this.colMCUptime = new System.Windows.Forms.ColumnHeader();
this.cbMCHideInvalid = new System.Windows.Forms.CheckBox();
this.txtMCHash = new System.Windows.Forms.TextBox();
this.lblMCHash = new System.Windows.Forms.Label();
this.btnMCConnect = new System.Windows.Forms.Button();
this.tblMCServers = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.cbMCHideEmpty = new System.Windows.Forms.CheckBox();
this.tabMCServer = new System.Windows.Forms.TabPage();
this.txtMCSearch = new System.Windows.Forms.TextBox();
this.lblMCSearch = new System.Windows.Forms.Label();
this.tabLocal = new System.Windows.Forms.TabPage();
this.btnLanConnect = new System.Windows.Forms.Button();
this.cbLocalSkinServerCC = new System.Windows.Forms.CheckBox();
@ -81,6 +77,9 @@ namespace Launcher
this.txtCCPassword = new System.Windows.Forms.TextBox();
this.lblCCPassword = new System.Windows.Forms.Label();
this.tabCCServers = new System.Windows.Forms.TabPage();
this.txtCCHash = new System.Windows.Forms.TextBox();
this.lblCCPlayUrl = new System.Windows.Forms.Label();
this.btnCCConnect = new System.Windows.Forms.Button();
this.tblCCServers = new System.Windows.Forms.ListView();
this.colCCName = new System.Windows.Forms.ColumnHeader();
this.colCCPlayers = new System.Windows.Forms.ColumnHeader();
@ -89,156 +88,25 @@ namespace Launcher
this.cbCCHideEmpty = new System.Windows.Forms.CheckBox();
this.txtCCSearch = new System.Windows.Forms.TextBox();
this.lblCCSearch = new System.Windows.Forms.Label();
this.tabCCServer = new System.Windows.Forms.TabPage();
this.btnCCConnect = new System.Windows.Forms.Button();
this.lblCCServerUrl = new System.Windows.Forms.Label();
this.lblCCPublicName = new System.Windows.Forms.Label();
this.lblCCPlayUrl = new System.Windows.Forms.Label();
this.lblCCServerName = new System.Windows.Forms.Label();
this.txtCCHash = new System.Windows.Forms.TextBox();
this.tabMinecraftNet.SuspendLayout();
this.tabMC.SuspendLayout();
this.tabMCSignIn.SuspendLayout();
this.tabMCServers.SuspendLayout();
this.tabMCServer.SuspendLayout();
this.tabLocal.SuspendLayout();
this.tabs.SuspendLayout();
this.tabClassicubeNet.SuspendLayout();
this.tabCC.SuspendLayout();
this.tabCCSignIn.SuspendLayout();
this.tabCCServers.SuspendLayout();
this.tabCCServer.SuspendLayout();
this.SuspendLayout();
//
// btnMCSignIn
//
this.btnMCSignIn.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnMCSignIn.Location = new System.Drawing.Point(10, 120);
this.btnMCSignIn.Name = "btnMCSignIn";
this.btnMCSignIn.Size = new System.Drawing.Size(100, 30);
this.btnMCSignIn.TabIndex = 4;
this.btnMCSignIn.Text = "Sign in";
this.btnMCSignIn.UseVisualStyleBackColor = true;
this.btnMCSignIn.Click += new System.EventHandler(this.btnMCSignInClick);
//
// txtMCPassword
//
this.txtMCPassword.Location = new System.Drawing.Point(10, 80);
this.txtMCPassword.MaxLength = 64;
this.txtMCPassword.Name = "txtMCPassword";
this.txtMCPassword.Size = new System.Drawing.Size(100, 20);
this.txtMCPassword.TabIndex = 3;
this.txtMCPassword.PasswordChar = '*';
//
// lblMCPassword
//
this.lblMCPassword.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblMCPassword.Location = new System.Drawing.Point(10, 60);
this.lblMCPassword.Name = "lblMCPassword";
this.lblMCPassword.Size = new System.Drawing.Size(77, 20);
this.lblMCPassword.TabIndex = 2;
this.lblMCPassword.Text = "Password";
//
// txtMCUser
//
this.txtMCUser.Location = new System.Drawing.Point(10, 30);
this.txtMCUser.MaxLength = 64;
this.txtMCUser.Name = "txtMCUser";
this.txtMCUser.Size = new System.Drawing.Size(100, 20);
this.txtMCUser.TabIndex = 1;
//
// lblMCUser
//
this.lblMCUser.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblMCUser.Location = new System.Drawing.Point(10, 10);
this.lblMCUser.Name = "lblMCUser";
this.lblMCUser.Size = new System.Drawing.Size(81, 20);
this.lblMCUser.TabIndex = 0;
this.lblMCUser.Text = "Username";
//
// txtMCSearch
//
this.txtMCSearch.Location = new System.Drawing.Point(80, 10);
this.txtMCSearch.Name = "txtMCSearch";
this.txtMCSearch.Size = new System.Drawing.Size(100, 20);
this.txtMCSearch.TabIndex = 2;
this.txtMCSearch.TextChanged += new System.EventHandler(this.txtMCSearchTextChanged);
//
// lblMCSearch
//
this.lblMCSearch.AutoSize = true;
this.lblMCSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblMCSearch.Location = new System.Drawing.Point(10, 10);
this.lblMCSearch.Name = "lblMCSearch";
this.lblMCSearch.Size = new System.Drawing.Size(64, 20);
this.lblMCSearch.TabIndex = 1;
this.lblMCSearch.Text = "Search:";
//
// btnMCConnect
//
this.btnMCConnect.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnMCConnect.Location = new System.Drawing.Point(10, 120);
this.btnMCConnect.Name = "btnMCConnect";
this.btnMCConnect.Size = new System.Drawing.Size(100, 30);
this.btnMCConnect.TabIndex = 5;
this.btnMCConnect.Text = "Connect";
this.btnMCConnect.UseVisualStyleBackColor = true;
this.btnMCConnect.Click += new System.EventHandler(this.btnMCConnectClick);
//
// lblMCPublicName
//
this.lblMCPublicName.AutoSize = true;
this.lblMCPublicName.Location = new System.Drawing.Point(10, 80);
this.lblMCPublicName.Name = "lblMCPublicName";
this.lblMCPublicName.Size = new System.Drawing.Size(87, 13);
this.lblMCPublicName.TabIndex = 4;
this.lblMCPublicName.Text = "(No public name)";
//
// lblMCServerName
//
this.lblMCServerName.BackColor = System.Drawing.SystemColors.Control;
this.lblMCServerName.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblMCServerName.Location = new System.Drawing.Point(10, 60);
this.lblMCServerName.Name = "lblMCServerName";
this.lblMCServerName.Size = new System.Drawing.Size(166, 20);
this.lblMCServerName.TabIndex = 3;
this.lblMCServerName.Text = "Public name of server";
//
// txtMCHash
//
this.txtMCHash.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtMCHash.Location = new System.Drawing.Point(180, 30);
this.txtMCHash.Name = "txtMCHash";
this.txtMCHash.Size = new System.Drawing.Size(190, 13);
this.txtMCHash.TabIndex = 2;
this.txtMCHash.TextChanged += new System.EventHandler(this.txtMCHashTextChanged);
//
// lblMCPlayUrl
//
this.lblMCPlayUrl.AutoSize = true;
this.lblMCPlayUrl.Location = new System.Drawing.Point(10, 30);
this.lblMCPlayUrl.Name = "lblMCPlayUrl";
this.lblMCPlayUrl.Size = new System.Drawing.Size(170, 13);
this.lblMCPlayUrl.TabIndex = 1;
this.lblMCPlayUrl.Text = "https://minecraft.net/classic/play/";
//
// lblMCServerUrl
//
this.lblMCServerUrl.BackColor = System.Drawing.SystemColors.Control;
this.lblMCServerUrl.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblMCServerUrl.Location = new System.Drawing.Point(10, 10);
this.lblMCServerUrl.Name = "lblMCServerUrl";
this.lblMCServerUrl.Size = new System.Drawing.Size(92, 20);
this.lblMCServerUrl.TabIndex = 0;
this.lblMCServerUrl.Text = "Server URL";
//
// tabMinecraftNet
//
this.tabMinecraftNet.Controls.Add(this.tabMC);
this.tabMinecraftNet.Location = new System.Drawing.Point(4, 22);
this.tabMinecraftNet.Name = "tabMinecraftNet";
this.tabMinecraftNet.Padding = new System.Windows.Forms.Padding(3);
this.tabMinecraftNet.Size = new System.Drawing.Size(424, 367);
this.tabMinecraftNet.Size = new System.Drawing.Size(474, 440);
this.tabMinecraftNet.TabIndex = 1;
this.tabMinecraftNet.Text = "minecraft.net";
this.tabMinecraftNet.UseVisualStyleBackColor = true;
@ -247,27 +115,26 @@ namespace Launcher
//
this.tabMC.Controls.Add(this.tabMCSignIn);
this.tabMC.Controls.Add(this.tabMCServers);
this.tabMC.Controls.Add(this.tabMCServer);
this.tabMC.Location = new System.Drawing.Point(0, 0);
this.tabMC.Name = "tabMC";
this.tabMC.SelectedIndex = 0;
this.tabMC.Size = new System.Drawing.Size(432, 374);
this.tabMC.TabIndex = 0;
this.tabMC.Size = new System.Drawing.Size(482, 444);
this.tabMC.TabIndex = 2;
//
// tabMCSignIn
//
this.tabMCSignIn.Controls.Add(this.prgMCStatus);
this.tabMCSignIn.Controls.Add(this.lblMCStatusLabel);
this.tabMCSignIn.Controls.Add(this.lblMCStatus);
this.tabMCSignIn.Controls.Add(this.lblMCUser);
this.tabMCSignIn.Controls.Add(this.lbMCUser);
this.tabMCSignIn.Controls.Add(this.btnMCSignIn);
this.tabMCSignIn.Controls.Add(this.txtMCUser);
this.tabMCSignIn.Controls.Add(this.txtMCPassword);
this.tabMCSignIn.Controls.Add(this.lblMCPassword);
this.tabMCSignIn.Controls.Add(this.lblMCPass);
this.tabMCSignIn.Location = new System.Drawing.Point(4, 22);
this.tabMCSignIn.Name = "tabMCSignIn";
this.tabMCSignIn.Padding = new System.Windows.Forms.Padding(3);
this.tabMCSignIn.Size = new System.Drawing.Size(424, 348);
this.tabMCSignIn.Size = new System.Drawing.Size(474, 418);
this.tabMCSignIn.TabIndex = 0;
this.tabMCSignIn.Text = "Sign in";
this.tabMCSignIn.UseVisualStyleBackColor = true;
@ -299,71 +166,153 @@ namespace Launcher
this.lblMCStatus.Size = new System.Drawing.Size(0, 17);
this.lblMCStatus.TabIndex = 6;
//
// lbMCUser
//
this.lbMCUser.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbMCUser.Location = new System.Drawing.Point(10, 10);
this.lbMCUser.Name = "lbMCUser";
this.lbMCUser.Size = new System.Drawing.Size(81, 20);
this.lbMCUser.TabIndex = 0;
this.lbMCUser.Text = "Username";
//
// btnMCSignIn
//
this.btnMCSignIn.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnMCSignIn.Location = new System.Drawing.Point(10, 120);
this.btnMCSignIn.Name = "btnMCSignIn";
this.btnMCSignIn.Size = new System.Drawing.Size(100, 30);
this.btnMCSignIn.TabIndex = 4;
this.btnMCSignIn.Text = "Sign in";
this.btnMCSignIn.UseVisualStyleBackColor = true;
this.btnMCSignIn.Click += new System.EventHandler(this.btnMCSignInClick);
//
// txtMCUser
//
this.txtMCUser.Location = new System.Drawing.Point(10, 30);
this.txtMCUser.MaxLength = 64;
this.txtMCUser.Name = "txtMCUser";
this.txtMCUser.Size = new System.Drawing.Size(100, 20);
this.txtMCUser.TabIndex = 1;
//
// txtMCPassword
//
this.txtMCPassword.Location = new System.Drawing.Point(10, 80);
this.txtMCPassword.MaxLength = 64;
this.txtMCPassword.Name = "txtMCPassword";
this.txtMCPassword.PasswordChar = '*';
this.txtMCPassword.Size = new System.Drawing.Size(100, 20);
this.txtMCPassword.TabIndex = 3;
//
// lblMCPass
//
this.lblMCPass.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblMCPass.Location = new System.Drawing.Point(10, 60);
this.lblMCPass.Name = "lblMCPass";
this.lblMCPass.Size = new System.Drawing.Size(77, 20);
this.lblMCPass.TabIndex = 2;
this.lblMCPass.Text = "Password";
//
// tabMCServers
//
this.tabMCServers.Controls.Add(this.tblMCServers);
this.tabMCServers.Controls.Add(this.cbMCHideInvalid);
this.tabMCServers.Controls.Add(this.txtMCHash);
this.tabMCServers.Controls.Add(this.lblMCHash);
this.tabMCServers.Controls.Add(this.btnMCConnect);
this.tabMCServers.Controls.Add(this.tblMCServers);
this.tabMCServers.Controls.Add(this.cbMCHideEmpty);
this.tabMCServers.Controls.Add(this.txtMCSearch);
this.tabMCServers.Controls.Add(this.lblMCSearch);
this.tabMCServers.Location = new System.Drawing.Point(4, 22);
this.tabMCServers.Name = "tabMCServers";
this.tabMCServers.Padding = new System.Windows.Forms.Padding(3);
this.tabMCServers.Size = new System.Drawing.Size(424, 348);
this.tabMCServers.Size = new System.Drawing.Size(474, 418);
this.tabMCServers.TabIndex = 1;
this.tabMCServers.Text = "Public servers list";
this.tabMCServers.Text = "minecraft.net server";
this.tabMCServers.UseVisualStyleBackColor = true;
//
// tblMCServers
//
this.tblMCServers.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.colMCName,
this.colMCPlayers,
this.colMCMaxPlayers,
this.colMCUptime});
this.tblMCServers.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.tblMCServers.FullRowSelect = true;
this.tblMCServers.GridLines = true;
this.tblMCServers.Location = new System.Drawing.Point(0, 40);
this.tblMCServers.Name = "tblMCServers";
this.tblMCServers.Size = new System.Drawing.Size(424, 320);
this.tblMCServers.TabIndex = 5;
this.tblMCServers.UseCompatibleStateImageBehavior = false;
this.tblMCServers.View = System.Windows.Forms.View.Details;
this.tblMCServers.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.tblMCServersColumnClick);
this.tblMCServers.DoubleClick += new System.EventHandler(this.tblMCServersDoubleClick);
//
// colMCName
//
this.colMCName.Text = "Name";
this.colMCName.Width = 100;
//
// colMCPlayers
//
this.colMCPlayers.Text = "Players";
this.colMCPlayers.Width = 90;
//
// colMCMaxPlayers
//
this.colMCMaxPlayers.Text = "Max players";
this.colMCMaxPlayers.Width = 90;
//
// colMCUptime
//
this.colMCUptime.Text = "Uptime";
this.colMCUptime.Width = 100;
//
// cbMCHideInvalid
//
this.cbMCHideInvalid.AutoSize = true;
this.cbMCHideInvalid.Location = new System.Drawing.Point(230, 23);
this.cbMCHideInvalid.Location = new System.Drawing.Point(230, 21);
this.cbMCHideInvalid.Name = "cbMCHideInvalid";
this.cbMCHideInvalid.Size = new System.Drawing.Size(118, 17);
this.cbMCHideInvalid.TabIndex = 4;
this.cbMCHideInvalid.TabIndex = 10;
this.cbMCHideInvalid.Text = "Hide invalid servers";
this.cbMCHideInvalid.UseVisualStyleBackColor = true;
this.cbMCHideInvalid.CheckedChanged += new System.EventHandler(this.cbMCHideInvalidCheckedChanged);
//
// txtMCHash
//
this.txtMCHash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtMCHash.BackColor = System.Drawing.SystemColors.Window;
this.txtMCHash.Location = new System.Drawing.Point(137, 389);
this.txtMCHash.Name = "txtMCHash";
this.txtMCHash.Size = new System.Drawing.Size(190, 20);
this.txtMCHash.TabIndex = 9;
this.txtMCHash.TextChanged += new System.EventHandler(this.txtMCHashTextChanged);
//
// lblMCHash
//
this.lblMCHash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lblMCHash.AutoSize = true;
this.lblMCHash.Location = new System.Drawing.Point(3, 392);
this.lblMCHash.Name = "lblMCHash";
this.lblMCHash.Size = new System.Drawing.Size(134, 13);
this.lblMCHash.TabIndex = 8;
this.lblMCHash.Text = "minecraft.net/classic/play/";
//
// btnMCConnect
//
this.btnMCConnect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnMCConnect.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnMCConnect.Location = new System.Drawing.Point(367, 382);
this.btnMCConnect.Name = "btnMCConnect";
this.btnMCConnect.Size = new System.Drawing.Size(100, 30);
this.btnMCConnect.TabIndex = 7;
this.btnMCConnect.Text = "Connect";
this.btnMCConnect.UseVisualStyleBackColor = true;
this.btnMCConnect.Click += new System.EventHandler(this.btnMCConnectClick);
//
// tblMCServers
//
this.tblMCServers.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4});
this.tblMCServers.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.tblMCServers.FullRowSelect = true;
this.tblMCServers.GridLines = true;
this.tblMCServers.HideSelection = false;
this.tblMCServers.Location = new System.Drawing.Point(0, 40);
this.tblMCServers.Name = "tblMCServers";
this.tblMCServers.Size = new System.Drawing.Size(474, 335);
this.tblMCServers.TabIndex = 6;
this.tblMCServers.UseCompatibleStateImageBehavior = false;
this.tblMCServers.View = System.Windows.Forms.View.Details;
this.tblMCServers.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.tblMCServersColumnClick);
this.tblMCServers.Click += new System.EventHandler(this.tblMCServersClick);
//
// columnHeader1
//
this.columnHeader1.Text = "Name";
this.columnHeader1.Width = 100;
//
// columnHeader2
//
this.columnHeader2.Text = "Players";
this.columnHeader2.Width = 90;
//
// columnHeader3
//
this.columnHeader3.Text = "Max players";
this.columnHeader3.Width = 90;
//
// columnHeader4
//
this.columnHeader4.Text = "Uptime";
this.columnHeader4.Width = 100;
//
// cbMCHideEmpty
//
this.cbMCHideEmpty.AutoSize = true;
@ -375,20 +324,23 @@ namespace Launcher
this.cbMCHideEmpty.UseVisualStyleBackColor = true;
this.cbMCHideEmpty.CheckedChanged += new System.EventHandler(this.cbMCHideEmptyCheckedChanged);
//
// tabMCServer
// txtMCSearch
//
this.tabMCServer.Controls.Add(this.btnMCConnect);
this.tabMCServer.Controls.Add(this.lblMCServerUrl);
this.tabMCServer.Controls.Add(this.lblMCPublicName);
this.tabMCServer.Controls.Add(this.lblMCPlayUrl);
this.tabMCServer.Controls.Add(this.lblMCServerName);
this.tabMCServer.Controls.Add(this.txtMCHash);
this.tabMCServer.Location = new System.Drawing.Point(4, 22);
this.tabMCServer.Name = "tabMCServer";
this.tabMCServer.Size = new System.Drawing.Size(424, 348);
this.tabMCServer.TabIndex = 2;
this.tabMCServer.Text = "minecraft.net server";
this.tabMCServer.UseVisualStyleBackColor = true;
this.txtMCSearch.Location = new System.Drawing.Point(80, 10);
this.txtMCSearch.Name = "txtMCSearch";
this.txtMCSearch.Size = new System.Drawing.Size(100, 20);
this.txtMCSearch.TabIndex = 2;
this.txtMCSearch.TextChanged += new System.EventHandler(this.txtMCSearchTextChanged);
//
// lblMCSearch
//
this.lblMCSearch.AutoSize = true;
this.lblMCSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblMCSearch.Location = new System.Drawing.Point(10, 10);
this.lblMCSearch.Name = "lblMCSearch";
this.lblMCSearch.Size = new System.Drawing.Size(64, 20);
this.lblMCSearch.TabIndex = 1;
this.lblMCSearch.Text = "Search:";
//
// tabLocal
//
@ -403,7 +355,7 @@ namespace Launcher
this.tabLocal.Location = new System.Drawing.Point(4, 22);
this.tabLocal.Name = "tabLocal";
this.tabLocal.Padding = new System.Windows.Forms.Padding(3);
this.tabLocal.Size = new System.Drawing.Size(424, 367);
this.tabLocal.Size = new System.Drawing.Size(474, 440);
this.tabLocal.TabIndex = 0;
this.tabLocal.Text = "Local server";
this.tabLocal.UseVisualStyleBackColor = true;
@ -489,7 +441,7 @@ namespace Launcher
this.tabs.Location = new System.Drawing.Point(-1, 0);
this.tabs.Name = "tabs";
this.tabs.SelectedIndex = 0;
this.tabs.Size = new System.Drawing.Size(432, 393);
this.tabs.Size = new System.Drawing.Size(482, 466);
this.tabs.TabIndex = 0;
//
// tabClassicubeNet
@ -497,7 +449,7 @@ namespace Launcher
this.tabClassicubeNet.Controls.Add(this.tabCC);
this.tabClassicubeNet.Location = new System.Drawing.Point(4, 22);
this.tabClassicubeNet.Name = "tabClassicubeNet";
this.tabClassicubeNet.Size = new System.Drawing.Size(424, 367);
this.tabClassicubeNet.Size = new System.Drawing.Size(474, 440);
this.tabClassicubeNet.TabIndex = 2;
this.tabClassicubeNet.Text = "classicube.net";
this.tabClassicubeNet.UseVisualStyleBackColor = true;
@ -506,11 +458,10 @@ namespace Launcher
//
this.tabCC.Controls.Add(this.tabCCSignIn);
this.tabCC.Controls.Add(this.tabCCServers);
this.tabCC.Controls.Add(this.tabCCServer);
this.tabCC.Location = new System.Drawing.Point(0, 0);
this.tabCC.Name = "tabCC";
this.tabCC.SelectedIndex = 0;
this.tabCC.Size = new System.Drawing.Size(432, 374);
this.tabCC.Size = new System.Drawing.Size(482, 444);
this.tabCC.TabIndex = 1;
//
// tabCCSignIn
@ -526,7 +477,7 @@ namespace Launcher
this.tabCCSignIn.Location = new System.Drawing.Point(4, 22);
this.tabCCSignIn.Name = "tabCCSignIn";
this.tabCCSignIn.Padding = new System.Windows.Forms.Padding(3);
this.tabCCSignIn.Size = new System.Drawing.Size(424, 348);
this.tabCCSignIn.Size = new System.Drawing.Size(474, 418);
this.tabCCSignIn.TabIndex = 0;
this.tabCCSignIn.Text = "Sign in";
this.tabCCSignIn.UseVisualStyleBackColor = true;
@ -591,9 +542,9 @@ namespace Launcher
this.txtCCPassword.Location = new System.Drawing.Point(10, 80);
this.txtCCPassword.MaxLength = 64;
this.txtCCPassword.Name = "txtCCPassword";
this.txtCCPassword.PasswordChar = '*';
this.txtCCPassword.Size = new System.Drawing.Size(100, 20);
this.txtCCPassword.TabIndex = 3;
this.txtCCPassword.PasswordChar = '*';
//
// lblCCPassword
//
@ -606,6 +557,9 @@ namespace Launcher
//
// tabCCServers
//
this.tabCCServers.Controls.Add(this.txtCCHash);
this.tabCCServers.Controls.Add(this.lblCCPlayUrl);
this.tabCCServers.Controls.Add(this.btnCCConnect);
this.tabCCServers.Controls.Add(this.tblCCServers);
this.tabCCServers.Controls.Add(this.cbCCHideEmpty);
this.tabCCServers.Controls.Add(this.txtCCSearch);
@ -613,11 +567,43 @@ namespace Launcher
this.tabCCServers.Location = new System.Drawing.Point(4, 22);
this.tabCCServers.Name = "tabCCServers";
this.tabCCServers.Padding = new System.Windows.Forms.Padding(3);
this.tabCCServers.Size = new System.Drawing.Size(424, 348);
this.tabCCServers.Size = new System.Drawing.Size(474, 418);
this.tabCCServers.TabIndex = 1;
this.tabCCServers.Text = "Public servers list";
this.tabCCServers.Text = "classicube.net server";
this.tabCCServers.UseVisualStyleBackColor = true;
//
// txtCCHash
//
this.txtCCHash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtCCHash.BackColor = System.Drawing.SystemColors.Window;
this.txtCCHash.Location = new System.Drawing.Point(170, 389);
this.txtCCHash.Name = "txtCCHash";
this.txtCCHash.Size = new System.Drawing.Size(190, 20);
this.txtCCHash.TabIndex = 9;
this.txtCCHash.TextChanged += new System.EventHandler(this.txtCCHashTextChanged);
//
// lblCCPlayUrl
//
this.lblCCPlayUrl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lblCCPlayUrl.AutoSize = true;
this.lblCCPlayUrl.Location = new System.Drawing.Point(3, 392);
this.lblCCPlayUrl.Name = "lblCCPlayUrl";
this.lblCCPlayUrl.Size = new System.Drawing.Size(165, 13);
this.lblCCPlayUrl.TabIndex = 8;
this.lblCCPlayUrl.Text = "www.classicube.net/server/play/";
//
// btnCCConnect
//
this.btnCCConnect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCCConnect.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnCCConnect.Location = new System.Drawing.Point(367, 382);
this.btnCCConnect.Name = "btnCCConnect";
this.btnCCConnect.Size = new System.Drawing.Size(100, 30);
this.btnCCConnect.TabIndex = 7;
this.btnCCConnect.Text = "Connect";
this.btnCCConnect.UseVisualStyleBackColor = true;
this.btnCCConnect.Click += new System.EventHandler(this.btnCCConnectClick);
//
// tblCCServers
//
this.tblCCServers.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
@ -628,14 +614,15 @@ namespace Launcher
this.tblCCServers.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.tblCCServers.FullRowSelect = true;
this.tblCCServers.GridLines = true;
this.tblCCServers.HideSelection = false;
this.tblCCServers.Location = new System.Drawing.Point(0, 40);
this.tblCCServers.Name = "tblCCServers";
this.tblCCServers.Size = new System.Drawing.Size(424, 320);
this.tblCCServers.Size = new System.Drawing.Size(474, 335);
this.tblCCServers.TabIndex = 6;
this.tblCCServers.UseCompatibleStateImageBehavior = false;
this.tblCCServers.View = System.Windows.Forms.View.Details;
this.tblCCServers.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.tblCCServersColumnClick);
this.tblCCServers.DoubleClick += new System.EventHandler(this.tblCCServersDoubleClick);
this.tblCCServers.Click += new System.EventHandler(this.tblCCServersClick);
//
// colCCName
//
@ -686,87 +673,14 @@ namespace Launcher
this.lblCCSearch.TabIndex = 1;
this.lblCCSearch.Text = "Search:";
//
// tabCCServer
//
this.tabCCServer.Controls.Add(this.btnCCConnect);
this.tabCCServer.Controls.Add(this.lblCCServerUrl);
this.tabCCServer.Controls.Add(this.lblCCPublicName);
this.tabCCServer.Controls.Add(this.lblCCPlayUrl);
this.tabCCServer.Controls.Add(this.lblCCServerName);
this.tabCCServer.Controls.Add(this.txtCCHash);
this.tabCCServer.Location = new System.Drawing.Point(4, 22);
this.tabCCServer.Name = "tabCCServer";
this.tabCCServer.Size = new System.Drawing.Size(424, 348);
this.tabCCServer.TabIndex = 2;
this.tabCCServer.Text = "classicube.net server";
this.tabCCServer.UseVisualStyleBackColor = true;
//
// btnCCConnect
//
this.btnCCConnect.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnCCConnect.Location = new System.Drawing.Point(10, 120);
this.btnCCConnect.Name = "btnCCConnect";
this.btnCCConnect.Size = new System.Drawing.Size(100, 30);
this.btnCCConnect.TabIndex = 5;
this.btnCCConnect.Text = "Connect";
this.btnCCConnect.UseVisualStyleBackColor = true;
this.btnCCConnect.Click += new System.EventHandler(this.btnCCConnectClick);
//
// lblCCServerUrl
//
this.lblCCServerUrl.BackColor = System.Drawing.SystemColors.Control;
this.lblCCServerUrl.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblCCServerUrl.Location = new System.Drawing.Point(10, 10);
this.lblCCServerUrl.Name = "lblCCServerUrl";
this.lblCCServerUrl.Size = new System.Drawing.Size(92, 20);
this.lblCCServerUrl.TabIndex = 0;
this.lblCCServerUrl.Text = "Server URL";
//
// lblCCPublicName
//
this.lblCCPublicName.AutoSize = true;
this.lblCCPublicName.Location = new System.Drawing.Point(10, 80);
this.lblCCPublicName.Name = "lblCCPublicName";
this.lblCCPublicName.Size = new System.Drawing.Size(87, 13);
this.lblCCPublicName.TabIndex = 4;
this.lblCCPublicName.Text = "(No public name)";
//
// lblCCPlayUrl
//
this.lblCCPlayUrl.AutoSize = true;
this.lblCCPlayUrl.Location = new System.Drawing.Point(10, 30);
this.lblCCPlayUrl.Name = "lblCCPlayUrl";
this.lblCCPlayUrl.Size = new System.Drawing.Size(196, 13);
this.lblCCPlayUrl.TabIndex = 1;
this.lblCCPlayUrl.Text = "http://www.classicube.net/server/play/";
//
// lblCCServerName
//
this.lblCCServerName.BackColor = System.Drawing.SystemColors.Control;
this.lblCCServerName.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblCCServerName.Location = new System.Drawing.Point(10, 60);
this.lblCCServerName.Name = "lblCCServerName";
this.lblCCServerName.Size = new System.Drawing.Size(166, 20);
this.lblCCServerName.TabIndex = 3;
this.lblCCServerName.Text = "Public name of server";
//
// txtCCHash
//
this.txtCCHash.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtCCHash.Location = new System.Drawing.Point(206, 30);
this.txtCCHash.Name = "txtCCHash";
this.txtCCHash.Size = new System.Drawing.Size(190, 13);
this.txtCCHash.TabIndex = 2;
this.txtCCHash.TextChanged += new System.EventHandler(this.txtCCHashTextChanged);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(432, 393);
this.ClientSize = new System.Drawing.Size(484, 462);
this.Controls.Add(this.tabs);
this.Name = "MainForm";
this.Text = Launcher.MainForm.AppName;
this.Text = "ClassicalSharp Launcher 0.5";
this.ResizeEnd += new System.EventHandler(this.MainFormResizeEnd);
this.tabMinecraftNet.ResumeLayout(false);
this.tabMC.ResumeLayout(false);
@ -774,8 +688,6 @@ namespace Launcher
this.tabMCSignIn.PerformLayout();
this.tabMCServers.ResumeLayout(false);
this.tabMCServers.PerformLayout();
this.tabMCServer.ResumeLayout(false);
this.tabMCServer.PerformLayout();
this.tabLocal.ResumeLayout(false);
this.tabLocal.PerformLayout();
this.tabs.ResumeLayout(false);
@ -785,18 +697,34 @@ namespace Launcher
this.tabCCSignIn.PerformLayout();
this.tabCCServers.ResumeLayout(false);
this.tabCCServers.PerformLayout();
this.tabCCServer.ResumeLayout(false);
this.tabCCServer.PerformLayout();
this.ResumeLayout(false);
}
private System.Windows.Forms.CheckBox cbMCHideInvalid;
private System.Windows.Forms.Label lblMCSearch;
private System.Windows.Forms.TextBox txtMCSearch;
private System.Windows.Forms.CheckBox cbMCHideEmpty;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ListView tblMCServers;
private System.Windows.Forms.Button btnMCConnect;
private System.Windows.Forms.Label lblMCHash;
private System.Windows.Forms.TextBox txtMCHash;
private System.Windows.Forms.TabPage tabMCServers;
private System.Windows.Forms.Label lblMCPass;
private System.Windows.Forms.TextBox txtMCPassword;
private System.Windows.Forms.TextBox txtMCUser;
private System.Windows.Forms.Button btnMCSignIn;
private System.Windows.Forms.Label lbMCUser;
private System.Windows.Forms.Label lblMCStatus;
private System.Windows.Forms.Label lblMCStatusLabel;
private System.Windows.Forms.ProgressBar prgMCStatus;
private System.Windows.Forms.TabPage tabMCSignIn;
private System.Windows.Forms.TabControl tabMC;
private System.Windows.Forms.TextBox txtCCHash;
private System.Windows.Forms.Label lblCCServerName;
private System.Windows.Forms.Label lblCCPlayUrl;
private System.Windows.Forms.Label lblCCPublicName;
private System.Windows.Forms.Label lblCCServerUrl;
private System.Windows.Forms.Button btnCCConnect;
private System.Windows.Forms.TabPage tabCCServer;
private System.Windows.Forms.Label lblCCSearch;
private System.Windows.Forms.TextBox txtCCSearch;
private System.Windows.Forms.ColumnHeader colCCUptime;
@ -817,16 +745,7 @@ namespace Launcher
private System.Windows.Forms.TabPage tabCCSignIn;
private System.Windows.Forms.TabControl tabCC;
private System.Windows.Forms.CheckBox cbMCHideEmpty;
private System.Windows.Forms.CheckBox cbMCHideInvalid;
private System.Windows.Forms.ProgressBar prgMCStatus;
private System.Windows.Forms.Label lblMCStatus;
private System.Windows.Forms.Label lblMCStatusLabel;
private System.Windows.Forms.TabPage tabClassicubeNet;
private System.Windows.Forms.TabPage tabMCServer;
private System.Windows.Forms.TabPage tabMCServers;
private System.Windows.Forms.TabPage tabMCSignIn;
private System.Windows.Forms.TabControl tabMC;
private System.Windows.Forms.TextBox txtLanUser;
private System.Windows.Forms.Label lblLanUser;
private System.Windows.Forms.Label lblLanIP;
@ -838,23 +757,6 @@ namespace Launcher
private System.Windows.Forms.TabControl tabs;
private System.Windows.Forms.TabPage tabLocal;
private System.Windows.Forms.TabPage tabMinecraftNet;
private System.Windows.Forms.Label lblMCUser;
private System.Windows.Forms.TextBox txtMCUser;
private System.Windows.Forms.Label lblMCPassword;
private System.Windows.Forms.TextBox txtMCPassword;
private System.Windows.Forms.Button btnMCSignIn;
private System.Windows.Forms.Button btnMCConnect;
private System.Windows.Forms.Label lblMCServerName;
private System.Windows.Forms.Label lblMCPublicName;
private System.Windows.Forms.Label lblMCServerUrl;
private System.Windows.Forms.Label lblMCPlayUrl;
private System.Windows.Forms.TextBox txtMCHash;
private System.Windows.Forms.Label lblMCSearch;
private System.Windows.Forms.TextBox txtMCSearch;
private System.Windows.Forms.ColumnHeader colMCUptime;
private System.Windows.Forms.ColumnHeader colMCMaxPlayers;
private System.Windows.Forms.ColumnHeader colMCPlayers;
private System.Windows.Forms.ColumnHeader colMCName;
private System.Windows.Forms.ToolTip toolTip;
}
}

View File

@ -0,0 +1,184 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Net;
using System.Threading;
using System.Windows.Forms;
namespace Launcher {
public delegate void Action<T1, T2>( T1 arg1, T2 arg2 );
internal class GameState {
public ProgressBar Progress;
public Label Status;
public TextBox Username, Password;
public List<ServerListEntry> Servers;
public string HostServer;
public GameSession Session;
public Button SignInButton;
public TabControl Tab;
public TabPage ServersTab;
public ListView ServersTable;
public TextBox Hash;
public Predicate<ServerListEntry> Filter;
public MainForm form;
public void DoSignIn() {
if( String.IsNullOrEmpty( Username.Text ) ) {
MessageBox.Show( "Please enter a username." );
return;
}
if( String.IsNullOrEmpty( Password.Text ) ) {
MessageBox.Show( "Please enter a password." );
return;
}
if( Session.Username != null ) {
Session.ResetSession();
ServersTable.Items.Clear();
Servers.Clear();
}
SignInButton.Enabled = false;
Tab.TabPages.Remove( ServersTab );
Thread loginThread = new Thread( LoginAsync );
loginThread.Name = "Launcher.LoginAsync_" + HostServer;
loginThread.IsBackground = true;
loginThread.Start();
}
void LoginAsync() {
SetStatus( 0, "Signing in.." );
try {
Session.Login( Username.Text, Password.Text );
} catch( WebException ex ) {
Session.Username = null;
LoginEnd( false );
DisplayWebException( ex, "sign in", SetStatus );
return;
} catch( InvalidOperationException ex ) {
Session.Username = null;
LoginEnd( false );
string text = "Failed to sign in: " + Environment.NewLine + ex.Message;
SetStatus( 0, text );
return;
}
SetStatus( 50, "Retrieving public servers list.." );
try {
Servers = Session.GetPublicServers();
} catch( WebException ex ) {
Servers = new List<ServerListEntry>();
LoginEnd( false );
DisplayWebException( ex, "retrieve servers list", SetStatus );
return;
}
SetStatus( 100, "Done" );
LoginEnd( true );
}
public void LoginEnd( bool success ) {
if( form.InvokeRequired ) {
form.Invoke( (Action<bool>)LoginEnd, success );
} else {
GC.Collect();
if( success ) {
Tab.TabPages.Add( ServersTab );
FilterList();
}
SignInButton.Enabled = true;
}
}
void SetStatus( int percentage, string text ) {
if( form.InvokeRequired ) {
form.Invoke( (Action<int, string>)SetStatus, percentage, text );
} else {
Progress.Value = percentage;
Status.Text = text;
}
}
public void ConnectToServer() {
GameStartData data = null;
try {
data = Session.GetConnectInfo( Hash.Text );
} catch( WebException ex ) {
DisplayWebException( ex, "retrieve server info",
(p, text) => MessageBox.Show( text ) );
return;
}
MainForm.StartClient( data, true );
}
public void FilterList() {
ServersTable.Items.Clear();
if( Servers.Count == 0 ) return;
IComparer sorter = ServersTable.ListViewItemSorter;
ServersTable.ListViewItemSorter = null;
for( int i = 0; i < Servers.Count; i++ ) {
ServerListEntry entry = Servers[i];
if( Filter( entry ) ) {
string[] row = { entry.Name, entry.Players, entry.MaximumPlayers, entry.Uptime, entry.Hash };
ServersTable.Items.Add( new ListViewItem( row ) );
}
}
if( sorter != null ) {
ServersTable.ListViewItemSorter = sorter;
ServersTable.Sort();
}
ServersTable.EndUpdate();
}
public void HashChanged() {
string hash = Hash.Text;
ListView.SelectedIndexCollection selected = ServersTable.SelectedIndices;
if( selected.Count > 0 ) {
ServersTable.Items[selected[0]].Selected = false;
}
int count = ServersTable.Items.Count;
for( int i = 0; i < count; i++ ) {
ListViewItem entry = ServersTable.Items[i];
if( hash == entry.SubItems[4].Text ) {
entry.Selected = true;
ServersTable.EnsureVisible( i );
break;
}
}
}
public void ServerTableClick() {
Point mousePos = ServersTable.PointToClient( MainForm.MousePosition );
ListViewHitTestInfo hitTest = ServersTable.HitTest( mousePos );
if( hitTest != null && hitTest.Item != null ) {
Hash.Text = hitTest.Item.SubItems[4].Text;
}
}
void DisplayWebException( WebException ex, string action, Action<int, string> target ) {
string host = HostServer;
if( ex.Status == WebExceptionStatus.Timeout ) {
string text = "Failed to " + action + ":" +
Environment.NewLine + "Timed out while connecting to " + host + ", it may be down.";
target( 0, text );
} else if( ex.Status == WebExceptionStatus.ProtocolError ) {
HttpWebResponse response = (HttpWebResponse)ex.Response;
int errorCode = (int)response.StatusCode;
string description = response.StatusDescription;
string text = "Failed to " + action + ":" +
Environment.NewLine + host + " returned: (" + errorCode + ") " + description;
target( 0, text );
} else if( ex.Status == WebExceptionStatus.NameResolutionFailure ) {
string text = "Failed to " + action + ":" +
Environment.NewLine + "Unable to resolve " + host + ", you may not be connected to the internet.";
target( 0, text );
} else {
string text = "Failed to " + action + ":" + Environment.NewLine + ex.Status;
target( 0, text );
}
}
}
}

View File

@ -1,12 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespace Launcher {
@ -19,15 +16,32 @@ namespace Launcher {
InitializeComponent();
AdjustTabs();
SetTooltips();
tblMCServers.HandleCreated += tblMCServersHandleCreated;
tblCCServers.HandleCreated += tblCCServersHandleCreated;
// hide tabs at start
tabMC.TabPages.Remove( tabMCServers );
tabMC.TabPages.Remove( tabMCServer );
tabCC.TabPages.Remove( tabCCServers );
tabCC.TabPages.Remove( tabCCServer );
Shown += DisplayResourcesDialog;
mc = new GameState() { Progress = prgMCStatus, Status = lblMCStatus,
Username = txtMCUser, Password = txtMCPassword, HostServer = "minecraft.net",
Session = new MinecraftSession(), SignInButton = btnMCSignIn, Tab = tabMC,
ServersTab = tabMCServers, ServersTable = tblMCServers, Hash = txtMCHash,
form = this };
cc = new GameState() { Progress = prgCCStatus, Status = lblCCStatus,
Username = txtCCUser, Password = txtCCPassword, HostServer = "classicube.net",
Session = new ClassicubeSession(), SignInButton = btnCCSignIn, Tab = tabCC,
ServersTab = tabCCServers, ServersTable = tblCCServers, Hash = txtCCHash,
form = this };
mc.Filter = e =>
// NOTE: using ToLower().Contains() allocates too many unecessary strings.
e.Name.IndexOf( txtMCSearch.Text, StringComparison.OrdinalIgnoreCase ) >= 0
&& ( cbMCHideEmpty.Checked ? e.Players[0] != '0' : true )
&& ( cbMCHideInvalid.Checked ? Int32.Parse( e.Players ) < 600 : true );
cc.Filter = e =>
e.Name.IndexOf( txtCCSearch.Text, StringComparison.OrdinalIgnoreCase ) >= 0
&& ( cbCCHideEmpty.Checked ? e.Players[0] != '0' : true );
}
GameState mc, cc;
void DisplayResourcesDialog( object sender, EventArgs e ) {
// TODO: async fetching
@ -43,8 +57,6 @@ namespace Launcher {
}
}
delegate void Action<T1, T2>( T1 arg1, T2 arg2 );
void SetTooltips() {
toolTip.SetToolTip( lblLanUser, "The username to use when connecting to the local server. " + Environment.NewLine +
"(this doesn't have to be your minecraft.net or classicube.net username)" );
@ -64,82 +76,21 @@ namespace Launcher {
void AdjustTabs() {
tabs.Width = ClientSize.Width + 6;
tabs.Height = ClientSize.Height + 3;
tabMC.Width = tabCC.Width = tabs.SelectedTab.Size.Width + 10;
tabMC.Width = tabCC.Width = tabs.Width;
tabMC.Height = tabCC.Height = tabs.SelectedTab.Size.Height + 10;
if( tblMCServers.IsHandleCreated ) {
AdjustTablePos( tblMCServers );
AdjustTablePos( tblMCServers, btnMCConnect );
}
if( tblCCServers.IsHandleCreated ) {
AdjustTablePos( tblCCServers );
AdjustTablePos( tblCCServers, btnCCConnect );
}
}
void tblMCServersHandleCreated( object sender, EventArgs e ) {
AdjustTablePos( tblMCServers );
}
void tblCCServersHandleCreated( object sender, EventArgs e ) {
AdjustTablePos( tblCCServers );
}
void AdjustTablePos( Control control ) {
void AdjustTablePos( Control control, Control connectButton ) {
Point formLoc = PointToClient( control.Parent.PointToScreen( control.Location ) );
control.Width = ClientSize.Width - formLoc.X;
control.Height = ClientSize.Height - formLoc.Y;
}
static string missingExeMessage = "Failed to start ClassicalSharp. (classicalsharp.exe was not found)"
+ Environment.NewLine + Environment.NewLine +
"This application is only the launcher, it is not the actual client. " +
"Please place the launcher in the same directory as the client (classicalsharp.exe).";
static void StartClient( GameStartData data, bool classicubeSkins ) {
string skinServer = classicubeSkins ? "http://www.classicube.net/static/skins/" : "http://s3.amazonaws.com/MinecraftSkins/";
string args = data.Username + " " + data.Mppass + " " +
data.Ip + " " + data.Port + " " + skinServer;
Log( "starting..." + args );
Process process = null;
try {
process = Process.Start( "classicalsharp.exe", args );
} catch( Win32Exception ex ) {
if( ex.Message.Contains( "The system cannot find the file specified" ) ) {
MessageBox.Show( missingExeMessage );
} else {
throw;
}
} finally {
if( process != null ) {
process.Dispose();
}
}
}
static void Log( string text ) {
System.Diagnostics.Debug.WriteLine( text );
}
static void DisplayWebException( WebException ex, string action, string host, Action<int, string> target ) {
if( ex.Status == WebExceptionStatus.Timeout ) {
string text = "Failed to " + action + ":" +
Environment.NewLine + "Timed out while connecting to " + host + ", it may be down.";
target( 0, text );
} else if( ex.Status == WebExceptionStatus.ProtocolError ) {
HttpWebResponse response = (HttpWebResponse)ex.Response;
int errorCode = (int)response.StatusCode;
string description = response.StatusDescription;
string text = "Failed to " + action + ":" +
Environment.NewLine + host + " returned: (" + errorCode + ") " + description;
target( 0, text );
} else if( ex.Status == WebExceptionStatus.NameResolutionFailure ) {
string text = "Failed to " + action + ":" +
Environment.NewLine + "Unable to resolve " + host + ", you may not be connected to the internet.";
target( 0, text );
} else {
string text = "Failed to " + action + ":" +
Environment.NewLine + ex.Status;
target( 0, text );
}
control.Height = ClientSize.Height - formLoc.Y - connectButton.Height - 5;
}
#region Local tab
@ -186,12 +137,6 @@ namespace Launcher {
#endregion
#region minecraft.net tab
MinecraftSession mcSession = new MinecraftSession();
List<ServerListEntry> mcServers = new List<ServerListEntry>();
NameComparer mcNameComparer = new NameComparer( 0 );
NumericalComparer mcPlayersComparer = new NumericalComparer( 1 );
NumericalComparer mcMaxPlayersComparer = new NumericalComparer( 2 );
@ -213,164 +158,20 @@ namespace Launcher {
tblMCServers.Sort();
}
void McFilterList() {
tblMCServers.Items.Clear();
if( mcServers.Count == 0 ) return;
IComparer sorter = tblMCServers.ListViewItemSorter;
tblMCServers.ListViewItemSorter = null;
void txtMCSearchTextChanged( object sender, EventArgs e ) { mc.FilterList(); }
tblMCServers.BeginUpdate();
Predicate<ServerListEntry> filter = e =>
// NOTE: using ToLower().Contains() allocates too many unecessary strings.
e.Name.IndexOf( txtMCSearch.Text, StringComparison.OrdinalIgnoreCase ) >= 0
&& ( cbMCHideEmpty.Checked ? e.Players[0] != '0' : true )
&& ( cbMCHideInvalid.Checked ? Int32.Parse( e.Players ) < 600 : true );
void cbMCHideEmptyCheckedChanged( object sender, EventArgs e ) { mc.FilterList(); }
for( int i = 0; i < mcServers.Count; i++ ) {
ServerListEntry entry = mcServers[i];
if( filter( entry ) ) {
string[] row = { entry.Name, entry.Players, entry.MaximumPlayers, entry.Uptime, entry.Hash };
tblMCServers.Items.Add( new ListViewItem( row ) );
}
}
if( sorter != null ) {
tblMCServers.ListViewItemSorter = sorter;
tblMCServers.Sort();
}
tblMCServers.EndUpdate();
}
void cbMCHideInvalidCheckedChanged(object sender, EventArgs e ) { mc.FilterList(); }
void txtMCSearchTextChanged( object sender, EventArgs e ) {
McFilterList();
}
void tblMCServersClick( object sender, EventArgs e ) { mc.ServerTableClick(); }
void cbMCHideEmptyCheckedChanged( object sender, EventArgs e ) {
McFilterList();
}
void txtMCHashTextChanged( object sender, EventArgs e ) { mc.HashChanged(); }
void cbMCHideInvalidCheckedChanged(object sender, EventArgs e ) {
McFilterList();
}
void btnMCConnectClick( object sender, EventArgs e ) { mc.ConnectToServer(); }
void tblMCServersDoubleClick( object sender, EventArgs e ) {
Point mousePos = tblMCServers.PointToClient( MousePosition );
ListViewHitTestInfo hitTest = tblMCServers.HitTest( mousePos );
if( hitTest != null && hitTest.Item != null ) {
txtMCHash.Text = hitTest.Item.SubItems[4].Text;
tabMC.SelectedIndex = 2;
}
}
void btnMCSignInClick( object sender, EventArgs e ) { mc.DoSignIn(); }
void txtMCHashTextChanged( object sender, EventArgs e ) {
string hash = txtMCHash.Text;
lblMCPublicName.Text = "No public name";
for( int i = 0; i < mcServers.Count; i++ ) {
ServerListEntry entry = mcServers[i];
if( hash == entry.Hash ) {
lblMCPublicName.Text = entry.Name;
break;
}
}
}
void btnMCConnectClick( object sender, EventArgs e ) {
GameStartData data = null;
try {
data = mcSession.GetConnectInfo( txtMCHash.Text );
} catch( WebException ex ) {
DisplayWebException( ex, "retrieve server info", "minecraft.net",
(p, text) => MessageBox.Show( text ) );
return;
}
StartClient( data, false );
}
void btnMCSignInClick( object sender, EventArgs e ) {
if( String.IsNullOrEmpty( txtMCUser.Text ) ) {
MessageBox.Show( "Please enter a username." );
return;
}
if( String.IsNullOrEmpty( txtMCPassword.Text ) ) {
MessageBox.Show( "Please enter a password." );
return;
}
if( mcSession.Username != null ) {
mcSession.ResetSession();
tblMCServers.Items.Clear();
mcServers.Clear();
}
btnMCSignIn.Enabled = false;
tabMC.TabPages.Remove( tabMCServers );
tabMC.TabPages.Remove( tabMCServer );
mcLoginThread = new Thread( McLoginAsync );
mcLoginThread.Name = "Launcher.McLoginAsync";
mcLoginThread.IsBackground = true;
mcLoginThread.Start();
}
Thread mcLoginThread;
void McLoginAsync() {
SetMcStatus( 0, "Signing in.." );
try {
mcSession.Login( txtMCUser.Text, txtMCPassword.Text );
} catch( WebException ex ) {
mcSession.Username = null;
McLoginEnd( false );
DisplayWebException( ex, "sign in", "minecraft.net", SetMcStatus );
return;
} catch( InvalidOperationException ex ) {
SetMcStatus( 0, "Failed to sign in" );
mcSession.Username = null;
McLoginEnd( false );
string text = "Failed to sign in: " + Environment.NewLine + ex.Message;
SetMcStatus( 0, text );
return;
}
SetMcStatus( 50, "Retrieving public servers list.." );
try {
mcServers = mcSession.GetPublicServers();
} catch( WebException ex ) {
mcServers = new List<ServerListEntry>();
McLoginEnd( false );
DisplayWebException( ex, "retrieve servers list", "minecraft.net", SetMcStatus );
return;
}
SetMcStatus( 100, "Done" );
McLoginEnd( true );
}
void McLoginEnd( bool success ) {
if( InvokeRequired ) {
Invoke( (Action<bool>)McLoginEnd, success );
} else {
GC.Collect();
if( success ) {
tabMC.TabPages.Add( tabMCServers );
tabMC.TabPages.Add( tabMCServer );
McFilterList();
}
btnMCSignIn.Enabled = true;
}
}
void SetMcStatus( int percentage, string text ) {
if( InvokeRequired ) {
Invoke( (Action<int, string>)SetMcStatus, percentage, text );
} else {
prgMCStatus.Value = percentage;
lblMCStatus.Text = text;
}
}
#endregion
#region classicube.net tab
ClassicubeSession ccSession = new ClassicubeSession();
List<ServerListEntry> ccServers = new List<ServerListEntry>();
NameComparer ccNameComparer = new NameComparer( 0 );
NumericalComparer ccPlayersComparer = new NumericalComparer( 1 );
@ -391,151 +192,40 @@ namespace Launcher {
tblCCServers.Sort();
}
void CcFilterList() {
tblCCServers.Items.Clear();
if( ccServers.Count == 0 ) return;
IComparer sorter = tblCCServers.ListViewItemSorter;
tblCCServers.ListViewItemSorter = null;
void txtCCSearchTextChanged( object sender, EventArgs e ) { cc.FilterList(); }
tblCCServers.BeginUpdate();
Predicate<ServerListEntry> filter = e =>
e.Name.IndexOf( txtCCSearch.Text, StringComparison.OrdinalIgnoreCase ) >= 0
&& ( cbCCHideEmpty.Checked ? e.Players[0] != '0' : true );
void cbCCHideEmptyCheckedChanged( object sender, EventArgs e ) { cc.FilterList(); }
for( int i = 0; i < ccServers.Count; i++ ) {
ServerListEntry entry = ccServers[i];
if( filter( entry ) ) {
string[] row = { entry.Name, entry.Players, entry.MaximumPlayers, entry.Uptime, entry.Hash };
tblCCServers.Items.Add( new ListViewItem( row ) );
}
}
if( sorter != null ) {
tblCCServers.ListViewItemSorter = sorter;
tblCCServers.Sort();
}
tblCCServers.EndUpdate();
}
void tblCCServersClick( object sender, EventArgs e ) { cc.ServerTableClick(); }
void txtCCSearchTextChanged( object sender, EventArgs e ) {
CcFilterList();
}
void txtCCHashTextChanged( object sender, EventArgs e ) { cc.HashChanged(); }
void cbCCHideEmptyCheckedChanged( object sender, EventArgs e ) {
CcFilterList();
}
void btnCCConnectClick( object sender, EventArgs e ) { cc.ConnectToServer(); }
void tblCCServersDoubleClick( object sender, EventArgs e ) {
Point mousePos = tblCCServers.PointToClient( MousePosition );
ListViewHitTestInfo hitTest = tblCCServers.HitTest( mousePos );
if( hitTest != null && hitTest.Item != null ) {
txtCCHash.Text = hitTest.Item.SubItems[4].Text;
tabCC.SelectedIndex = 2;
}
}
void btnCCSignInClick( object sender, EventArgs e ) { cc.DoSignIn(); }
void txtCCHashTextChanged( object sender, EventArgs e ) {
string hash = txtCCHash.Text;
lblCCPublicName.Text = "No public name";
for( int i = 0; i < ccServers.Count; i++ ) {
ServerListEntry entry = ccServers[i];
if( hash == entry.Hash ) {
lblCCPublicName.Text = entry.Name;
break;
}
}
}
void btnCCConnectClick( object sender, EventArgs e ) {
GameStartData data = null;
static string missingExeMessage = "Failed to start ClassicalSharp. (classicalsharp.exe was not found)"
+ Environment.NewLine + Environment.NewLine +
"This application is only the launcher, it is not the actual client. " +
"Please place the launcher in the same directory as the client (classicalsharp.exe).";
internal static void StartClient( GameStartData data, bool classicubeSkins ) {
string skinServer = classicubeSkins ? "http://www.classicube.net/static/skins/" : "http://s3.amazonaws.com/MinecraftSkins/";
string args = data.Username + " " + data.Mppass + " " +
data.Ip + " " + data.Port + " " + skinServer;
System.Diagnostics.Debug.WriteLine( "starting..." + args );
Process process = null;
try {
data = ccSession.GetConnectInfo( txtCCHash.Text );
} catch( WebException ex ) {
DisplayWebException( ex, "retrieve server info", "classicube.net",
(p, text) => MessageBox.Show( text ) );
return;
}
StartClient( data, true );
}
void btnCCSignInClick( object sender, EventArgs e ) {
if( String.IsNullOrEmpty( txtCCUser.Text ) ) {
MessageBox.Show( "Please enter a username." );
return;
}
if( String.IsNullOrEmpty( txtCCPassword.Text ) ) {
MessageBox.Show( "Please enter a password." );
return;
}
if( ccSession.Username != null ) {
ccSession.ResetSession();
tblCCServers.Items.Clear();
ccServers.Clear();
}
btnCCSignIn.Enabled = false;
tabCC.TabPages.Remove( tabCCServers );
tabCC.TabPages.Remove( tabCCServer );
ccLoginThread = new Thread( CcLoginAsync );
ccLoginThread.Name = "Launcher.CcLoginAsync";
ccLoginThread.IsBackground = true;
ccLoginThread.Start();
}
Thread ccLoginThread;
void CcLoginAsync() {
SetCcStatus( 0, "Signing in.." );
try {
ccSession.Login( txtCCUser.Text, txtCCPassword.Text );
} catch( WebException ex ) {
ccSession.Username = null;
CcLoginEnd( false );
DisplayWebException( ex, "sign in", "classicube.net", SetCcStatus );
return;
} catch( InvalidOperationException ex ) {
SetCcStatus( 0, "Failed to sign in" );
ccSession.Username = null;
CcLoginEnd( false );
string text = "Failed to sign in: " + Environment.NewLine + ex.Message;
SetCcStatus( 0, text );
return;
}
SetCcStatus( 50, "Retrieving public servers list.." );
try {
ccServers = ccSession.GetPublicServers();
} catch( WebException ex ) {
ccServers = new List<ServerListEntry>();
CcLoginEnd( false );
DisplayWebException( ex, "retrieve servers list", "classicube.net", SetCcStatus );
return;
}
SetCcStatus( 100, "Done" );
CcLoginEnd( true );
}
void CcLoginEnd( bool success ) {
if( InvokeRequired ) {
Invoke( (Action<bool>)CcLoginEnd, success );
process = Process.Start( "classicalsharp.exe", args );
} catch( Win32Exception ex ) {
if( ex.Message.Contains( "The system cannot find the file specified" ) ) {
MessageBox.Show( missingExeMessage );
} else {
GC.Collect();
if( success ) {
tabCC.TabPages.Add( tabCCServers );
tabCC.TabPages.Add( tabCCServer );
CcFilterList();
}
btnCCSignIn.Enabled = true;
throw;
}
}
void SetCcStatus( int percentage, string text ) {
if( InvokeRequired ) {
Invoke( (Action<int, string>)SetCcStatus, percentage, text );
} else {
prgCCStatus.Value = percentage;
lblCCStatus.Text = text;
}
}
#endregion
}
}

View File

@ -117,8 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing">
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</data>
</metadata>
</root>

View File

@ -1,6 +1,6 @@
* Note that the first time you run the launcher, a dialog box will pop up with the message
"Some required resources weren't found." Just click OK. (This is because I cannot redistribute
the assets of Mine craft Classic with the application as they are the copyrighted property of Mojang)
the assets of MineCraft Classic with the application as they are the copyrighted property of Mojang)
The launcher is divided into 3 tabs. They are:
1) Local tab
@ -11,18 +11,18 @@ custom skins if you are not connected to the internet, however)
Click "connect" to start the client.
2) Mine craft.net
### Note: Mojang appears to have deleted all of the unpaid free accounts. Premium accounts should still
### work though. The public servers list on minecraft.net is also completely stuffed. There are servers
### that appear on the list that are either fake, or don't actually exist anymore.
### You are probably better off just using ClassiCube.net.
2) MineCraft.net
# Note: Mojang appears to have deleted all of the unpaid free accounts. Premium accounts should still
# work though. The public servers list on minecraft.net is also completely stuffed, as most servers
# that appear on the list that are either fake or don't actually exist anymore.
# You are probably better off just using ClassiCube.net.
You will need to provide the username and password for your minecraft.net account. Then click sign in.
If sign-in was successful, two new tabs should appear beside 'Sign in'.
You can then either:
A) Browse the public servers list and double-click on a server (Which will then take you to the 'minecraft.net server' tab with the hash filled in for you)
B) Directly enter in a hash in the 'minecraft.net server' tab.
A) Browse the public servers list and click on a cell (Which will then fill in the hash textbox)
B) Directly enter in a hash into the hash textbox.
Then click "connect". The launcher will then download the necessary information about the server from minecraft.net and start the client.