1
0
mirror of https://e.coding.net/circlecloud/CTZLauncher.git synced 2024-11-22 02:08:49 +00:00

修改为双界面 优化登录流程...

This commit is contained in:
j502647092 2015-08-03 20:44:34 +08:00
parent 648a227970
commit cb5b7ffd22
8 changed files with 301 additions and 304 deletions

View File

@ -17,7 +17,7 @@
public class YggdrasilLogin : IAuthenticator public class YggdrasilLogin : IAuthenticator
{ {
/// <summary> /// <summary>
/// 新建正版验证器 /// 新建正版验证器
/// </summary> /// </summary>
/// <param name="email">电子邮件地址</param> /// <param name="email">电子邮件地址</param>
/// <param name="password">密码</param> /// <param name="password">密码</param>
@ -32,7 +32,7 @@
} }
/// <summary> /// <summary>
/// 新建正版验证器(随机的新ClientToken) /// 新建正版验证器(随机的新ClientToken)
/// </summary> /// </summary>
/// <param name="email">电子邮件地址</param> /// <param name="email">电子邮件地址</param>
/// <param name="password">密码</param> /// <param name="password">密码</param>
@ -42,32 +42,37 @@
} }
/// <summary> /// <summary>
/// 电子邮件地址 /// 电子邮件地址
/// </summary> /// </summary>
public string Email { get; private set; } public string Email { get; private set; }
/// <summary> /// <summary>
/// 密码 /// 密码
/// </summary> /// </summary>
public string Password { get; private set; } public string Password { get; private set; }
/// <summary> /// <summary>
/// 是否启用Twitch /// 是否启用Twitch
/// </summary> /// </summary>
public bool TwitchEnabled { get; private set; } public bool TwitchEnabled { get; private set; }
/// <summary> /// <summary>
/// 客户端Token
/// </summary> /// </summary>
public Guid ClientToken { get; private set; } public Guid ClientToken { get; private set; }
/// <summary> /// <summary>
/// 返回Yggdrasil验证器类型 /// 返回Yggdrasil验证器类型
/// </summary> /// </summary>
public string Type public string Type
{ {
get { return "KMCCC.Yggdrasil"; } get { return "KMCCC.Yggdrasil"; }
} }
/// <summary>
///
/// </summary>
/// <returns></returns>
public AuthenticationInfo Do() public AuthenticationInfo Do()
{ {
var client = new YggdrasilClient(ClientToken); var client = new YggdrasilClient(ClientToken);

View File

@ -1,49 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;
using CityCraft;
namespace CTZLauncher.CTZAuth
{
class CTZAuth : ICTZAuth
{
HttpHelper http = new HttpHelper();
string address;
int port;
CTZAuth(string address,int port = 25565)
{
this.address = address;
this.port = port;
}
public bool isRegister(string username)
{
return getResult(address + ":" + port + "/isregister?username=" + username);
}
public bool Register(string username, string password)
{
return getResult(address + ":" + port + "/register?username=" + username + "&password=" + password);
}
public bool isLogin(string username)
{
return getResult(address + ":" + port + "/islogin?username=" + username);
}
public bool Login(string username, string password)
{
return getResult(address + ":" + port + "/login?username=" + username + "&password=" + password);
}
public bool getResult(string url)
{
string result = http.Send(HttpMethod.GET, url);
if (result == "true")
return true;
return false;
}
}
}

View File

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CTZLauncher.CTZAuth
{
interface ICTZAuth
{
bool isRegister(string username);
bool Register(string username, string password);
bool isLogin(string username);
bool Login(string username, string password);
}
}

View File

@ -74,8 +74,7 @@
<Compile Include="Authentication\OfflineAuthenticator.cs" /> <Compile Include="Authentication\OfflineAuthenticator.cs" />
<Compile Include="Authentication\WarpedAuhenticator.cs" /> <Compile Include="Authentication\WarpedAuhenticator.cs" />
<Compile Include="Authentication\Yggdrasil.cs" /> <Compile Include="Authentication\Yggdrasil.cs" />
<Compile Include="CTZAuth\CTZAuth.cs" /> <Compile Include="Authentication\CTZAuthenticator.cs" />
<Compile Include="CTZAuth\ICTZAuth.cs" />
<Compile Include="HttpHelper.cs" /> <Compile Include="HttpHelper.cs" />
<Compile Include="Launcher\LaunchArguments.cs" /> <Compile Include="Launcher\LaunchArguments.cs" />
<Compile Include="Launcher\LauncherCore.cs" /> <Compile Include="Launcher\LauncherCore.cs" />

View File

@ -63,6 +63,10 @@ namespace CityCraft
/// <returns>请求返回的Stream</returns> /// <returns>请求返回的Stream</returns>
public string Send(HttpMethod method, string url, bool Async = false) public string Send(HttpMethod method, string url, bool Async = false)
{ {
if (string.IsNullOrEmpty(url))
{
return string.Empty;
}
readyState = HttpReadyState.; readyState = HttpReadyState.;
ParseURL(url); ParseURL(url);
args.Method = method; args.Method = method;
@ -142,6 +146,10 @@ namespace CityCraft
address = nohttpurl.Substring(0, iIndex); address = nohttpurl.Substring(0, iIndex);
args.Url = nohttpurl.Substring(iIndex); args.Url = nohttpurl.Substring(iIndex);
} }
else
{
args.Url = "/";
}
iIndex = nohttpurl.IndexOf(@":"); iIndex = nohttpurl.IndexOf(@":");
if (iIndex > 0) if (iIndex > 0)
{ {
@ -204,6 +212,7 @@ namespace CityCraft
{ {
string responseHeader = responseStr.Substring(0, splitindex); string responseHeader = responseStr.Substring(0, splitindex);
string responseBody = responseStr.Substring(splitindex + 4); string responseBody = responseStr.Substring(splitindex + 4);
//Console.WriteLine(responseHeader);
if (responseHeader.StartsWith("HTTP/1.1 400")) if (responseHeader.StartsWith("HTTP/1.1 400"))
{ {
Status = 400; Status = 400;
@ -377,6 +386,7 @@ namespace CityCraft
} }
string header = bulider.ToString(); string header = bulider.ToString();
//Console.WriteLine(header);
return Encoding.Default.GetBytes(header); return Encoding.Default.GetBytes(header);
} }
#endregion #endregion

View File

@ -32,7 +32,7 @@
args.MainClass = options.Version.MainClass; args.MainClass = options.Version.MainClass;
args.MaxMemory = options.MaxMemory; args.MaxMemory = options.MaxMemory;
args.MinMemory = options.MinMemory; args.MinMemory = options.MinMemory;
args.NativePath = GameRootPath + options.Version.Id + @"\\" + options.Version.Id + @"-natives"; args.NativePath = GameRootPath + @"\versions\" + options.Version.Id + @"\" + options.Version.Id + @"-natives";
foreach (var native in options.Version.Natives) foreach (var native in options.Version.Natives)
{ {
var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options); var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options);
@ -58,7 +58,7 @@
args.Tokens.Add("auth_session", authentication.AccessToken.GoString()); args.Tokens.Add("auth_session", authentication.AccessToken.GoString());
args.Tokens.Add("auth_player_name", authentication.DisplayName); args.Tokens.Add("auth_player_name", authentication.DisplayName);
args.Tokens.Add("version_name", options.Version.Id); args.Tokens.Add("version_name", options.Version.Id);
args.Tokens.Add("game_directory", "."); args.Tokens.Add("game_directory", GameRootPath + @"\versions\" + options.Version.Id + @"\");
args.Tokens.Add("game_assets", "assets"); args.Tokens.Add("game_assets", "assets");
args.Tokens.Add("assets_root", "assets"); args.Tokens.Add("assets_root", "assets");
args.Tokens.Add("assets_index_name", options.Version.Assets); args.Tokens.Add("assets_index_name", options.Version.Assets);

View File

@ -36,14 +36,6 @@
</ControlTemplate> </ControlTemplate>
</Window.Resources> </Window.Resources>
<Grid Name="outline" Background="#FF3299CC" Height="600" Width="800" VerticalAlignment="Top" MouseLeftButtonDown="outline_MouseLeftButtonDown"> <Grid Name="outline" Background="#FF3299CC" Height="600" Width="800" VerticalAlignment="Top" MouseLeftButtonDown="outline_MouseLeftButtonDown">
<Grid Margin="20,0" Background="#FF3299CC" Height="60" VerticalAlignment="Top" >
<Label x:Name="barl1" Content="论坛" HorizontalAlignment="Left" Margin="245,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
<Label x:Name="barl2" Content="资源下载" HorizontalAlignment="Left" Margin="350,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
<Label x:Name="barl3" Content="新手指南" HorizontalAlignment="Left" Margin="455,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
<Label x:Name="barl4" Content="赞助我们" HorizontalAlignment="Left" Margin="560,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
<Image HorizontalAlignment="Left" Height="50" Margin="15,5,0,0" VerticalAlignment="Top" Width="50" Source="ico.ico" RenderTransformOrigin="0.56,0.24"/>
<Label Content="魔方" HorizontalAlignment="Left" Height="50" Margin="90,5,0,0" VerticalAlignment="Top" Width="74" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" FontSize="35" />
</Grid>
<Grid Margin="20,60,20,20" Background="White"> <Grid Margin="20,60,20,20" Background="White">
<Grid Height="269" VerticalAlignment="Top"> <Grid Height="269" VerticalAlignment="Top">
<Grid Margin="20,20,0,0" HorizontalAlignment="Left" Width="400" > <Grid Margin="20,20,0,0" HorizontalAlignment="Left" Width="400" >
@ -53,14 +45,14 @@
<Grid> <Grid>
<Grid Margin="10,10,10,0" Height="174" VerticalAlignment="Top"> <Grid Margin="10,10,10,0" Height="174" VerticalAlignment="Top">
<Label Content="————— XX XX 帐 号 —————" VerticalAlignment="Top" Margin="10,0" HorizontalContentAlignment="Center" FontSize="15"/> <Label Content="————— XX XX 帐 号 —————" VerticalAlignment="Top" Margin="10,0" HorizontalContentAlignment="Center" FontSize="15"/>
<TextBox Name="username" Template="{StaticResource CornerTextBox}" Height="34" TextWrapping="Wrap" Text="" VerticalAlignment="Top" HorizontalContentAlignment="Center" FontFamily="微软雅黑" FontSize="20" Margin="30,30,30,0" /> <TextBox x:Name="username" Template="{StaticResource CornerTextBox}" Height="34" TextWrapping="Wrap" Text="" VerticalAlignment="Top" HorizontalContentAlignment="Center" FontFamily="微软雅黑" FontSize="20" Margin="30,30,30,0" />
<Label Content="————— XX XX 密 码 —————" VerticalAlignment="Top" Margin="10,69,10,0" HorizontalContentAlignment="Center" FontSize="15"/> <Label Content="————— XX XX 密 码 —————" VerticalAlignment="Top" Margin="10,69,10,0" HorizontalContentAlignment="Center" FontSize="15"/>
<TextBox Name="password" Template="{StaticResource CornerTextBox}" TextWrapping="Wrap" HorizontalContentAlignment="Center" FontFamily="微软雅黑" FontSize="20" Margin="30,104,30,0" Height="34" VerticalAlignment="Top" /> <TextBox x:Name="password" Template="{StaticResource CornerTextBox}" TextWrapping="Wrap" HorizontalContentAlignment="Center" FontFamily="微软雅黑" FontSize="20" Margin="30,104,30,0" Height="34" VerticalAlignment="Top" />
<Button Margin="217,106,33,0" Template="{StaticResource CornerButton}" Height="30" Content="?" VerticalAlignment="Top" /> <Button Margin="217,106,33,0" Template="{StaticResource CornerButton}" Height="30" Content="?" VerticalAlignment="Top" />
</Grid> </Grid>
<Grid Margin="10,0,10,10" Height="50" VerticalAlignment="Bottom"> <Grid Margin="10,0,10,10" Height="50" VerticalAlignment="Bottom">
<Button Name="Login" Margin="30,10,160,10" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Content="登录" Click="Login_Click"/> <Button x:Name="Login" Margin="30,10,160,10" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Content="登录" Click="Login_Click"/>
<Button Name="register" Margin="160,10,30,10" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Content="注册" Click="register_Click" /> <Button x:Name="register" Margin="160,10,30,10" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Content="注册" Click="register_Click" />
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>
@ -68,41 +60,91 @@
<Grid Height="246" VerticalAlignment="Bottom"> <Grid Height="246" VerticalAlignment="Bottom">
<Grid Margin="20,20,0,20" HorizontalAlignment="Left" Width="391" > <Grid Margin="20,20,0,20" HorizontalAlignment="Left" Width="391" >
<TabControl Background="White" BorderThickness="0"> <TabControl Background="White" BorderThickness="0">
<TabItem Header="动态" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="20" > <TabItem Header="动态" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="15" >
<ListBox BorderThickness="0" FontSize="20"> <ListBox BorderThickness="0" FontSize="15">
<ListBoxItem Content="动态" Height="30" /> <ListBoxItem Content="动态" />
<ListBoxItem Content="动态" Height="30" /> <ListBoxItem Content="动态" />
<ListBoxItem Content="动态" Height="30" /> <ListBoxItem Content="动态" />
<ListBoxItem Content="动态" Height="30" /> <ListBoxItem Content="动态" />
<ListBoxItem Content="动态" Height="30" /> <ListBoxItem Content="动态" />
<ListBoxItem Content="动态" Height="30" /> <ListBoxItem Content="动态" />
</ListBox> </ListBox>
</TabItem> </TabItem>
<TabItem Header="新闻" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="20" > <TabItem Header="新闻" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="15" >
<ListBox BorderThickness="0" FontSize="20"> <ListBox BorderThickness="0" FontSize="15">
<ListBoxItem Content="新闻" Height="30" /> <ListBoxItem Content="新闻" />
<ListBoxItem Content="新闻" Height="30" /> <ListBoxItem Content="新闻" />
<ListBoxItem Content="新闻" Height="30" /> <ListBoxItem Content="新闻" />
<ListBoxItem Content="新闻" Height="30" /> <ListBoxItem Content="新闻" />
<ListBoxItem Content="新闻" Height="30" /> <ListBoxItem Content="新闻" />
</ListBox> </ListBox>
</TabItem> </TabItem>
<TabItem Header="公告" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="20" /> <TabItem Header="公告" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="15" />
<TabItem Header="活动" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="20" /> <TabItem Header="活动" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="15" />
</TabControl> </TabControl>
</Grid> </Grid>
<Grid Margin="0,20,20,20" HorizontalAlignment="Right" Width="300" Grid.ShowGridLines="True"> <Grid Margin="0,20,20,20" HorizontalAlignment="Right" Width="300" ShowGridLines="True">
<Label Margin="10,15,0,0" Content="最大内存" VerticalAlignment="Top" Height="30" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black" HorizontalAlignment="Left" Width="100"/> <!--<Label Margin="10,15,0,0" Content="最大内存" VerticalAlignment="Top" Height="30" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black" HorizontalAlignment="Left" Width="100"/>
<TextBox Name="maxmem" Template="{StaticResource CornerTextBox}" Text="" Height="30" Width="174" TextWrapping="Wrap" Margin="0,15,10,161" FontSize="20" TextChanged="maxmem_TextChanged" HorizontalAlignment="Right" /> <TextBox x:Name="maxmem" Template="{StaticResource CornerTextBox}" Text="" Height="30" Width="174" TextWrapping="Wrap" Margin="0,15,10,161" FontSize="20" TextChanged="maxmem_TextChanged" HorizontalAlignment="Right" />
<ComboBox Name="javacombo" Height="30" Width="174" FontSize="15" Margin="0,50,10,0" VerticalAlignment="Top" HorizontalAlignment="Right"/> <ComboBox x:Name="javacombo" Height="30" Width="174" FontSize="15" Margin="0,50,10,0" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<Label Margin="10,50,0,126" Content="JAVA版本" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black" HorizontalAlignment="Left" Width="100"/> <Label Margin="10,50,0,126" Content="JAVA版本" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black" HorizontalAlignment="Left" Width="100"/>
<ComboBox Name="gamecombo" Height="30" Width="174" FontSize="15" Margin="0,85,10,0" VerticalAlignment="Top" HorizontalAlignment="Right"/> <ComboBox x:Name="gamecombo" Height="30" Width="174" FontSize="15" Margin="0,85,10,0" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<Label Margin="10,85,0,91" Content="游戏版本" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black" HorizontalAlignment="Left" Width="100"/> <Label Margin="10,85,0,91" Content="游戏版本" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black" HorizontalAlignment="Left" Width="100"/>
<Button Name="StartGame" BorderBrush="#FF3299CC" Content="启动游戏" Template="{StaticResource CornerButton}" HorizontalAlignment="Right" Margin="0,0,10,10" Width="100" Height="46" VerticalAlignment="Bottom" FontSize="16" Click="StartGame_Click"/> <Button x:Name="StartGame" BorderBrush="#FF3299CC" Content="启动游戏" Template="{StaticResource CornerButton}" HorizontalAlignment="Right" Margin="0,0,10,10" Width="100" Height="46" VerticalAlignment="Bottom" FontSize="16" Click="StartGame_Click" IsEnabled="False"/>
<Button x:Name="SelServer" BorderBrush="#FF3299CC" Content="选择服务器" Template="{StaticResource CornerButton}" Margin="34,0,0,16" Height="40" Width="100" FontSize="13" Click="StartGame_Click" VerticalAlignment="Bottom" HorizontalAlignment="Left"/> <Button x:Name="SelServer" BorderBrush="#FF3299CC" Content="选择服务器" Template="{StaticResource CornerButton}" Margin="20,0,0,10" Height="40" Width="100" FontSize="13" Click="StartGame_Click" VerticalAlignment="Bottom" HorizontalAlignment="Left" IsEnabled="False"/>-->
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>
<Grid Margin="20,0" Background="#FF3299CC" Height="60" VerticalAlignment="Top" >
<Label x:Name="barl1" Content="论坛" HorizontalAlignment="Left" Margin="245,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
<Label x:Name="barl2" Content="资源下载" HorizontalAlignment="Left" Margin="350,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
<Label x:Name="barl3" Content="新手指南" HorizontalAlignment="Left" Margin="455,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
<Label x:Name="barl4" Content="赞助我们" HorizontalAlignment="Left" Margin="560,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
<Image HorizontalAlignment="Left" Height="50" Margin="15,5,0,0" VerticalAlignment="Top" Width="50" Source="ico.ico" RenderTransformOrigin="0.56,0.24"/>
<Label Content="魔方" HorizontalAlignment="Left" Height="50" Margin="90,5,0,0" VerticalAlignment="Top" Width="74" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" FontSize="35" />
</Grid>
<Grid Margin="20,60,20,20" Background="White" Name="SelServer" Visibility="Hidden">
<!--Visibility="Hidden"-->
<Grid HorizontalAlignment="Left" Width="400" Margin="20,20,0,20">
<Grid Height="80" VerticalAlignment="Top" Margin="0,0,0,0">
<Label Content="选择大区" Margin="155,20" FontSize="20" VerticalAlignment="Center" VerticalContentAlignment="Center"/>
</Grid>
<Grid Height="100" VerticalAlignment="Top" Margin="0,85,0,0">
</Grid>
<Grid Height="285" VerticalAlignment="Top" Margin="10,185,10,0">
<Grid Height="50" VerticalAlignment="Top" Margin="10,0,10,0">
<Label Content="选择服务器" Margin="125,8" FontSize="20" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Grid Height="235" VerticalAlignment="Top" Margin="10,50,10,0">
</Grid>
</Grid>
</Grid>
<Grid HorizontalAlignment="Right" Width="300" Margin="0,20,20,20">
<Grid Height="269" VerticalAlignment="Top">
<Grid Height="40" VerticalAlignment="Top" Margin="10,10,10,0">
<Label Content="服务器介绍" Margin="85,2" FontSize="20" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Grid Height="200" VerticalAlignment="Bottom" Margin="10,0,10,10">
</Grid>
</Grid>
<Grid HorizontalAlignment="Right" Width="300" ShowGridLines="True" Height="206" VerticalAlignment="Bottom">
<Label Margin="10,15,0,0" Content="最大内存" VerticalAlignment="Top" Height="30" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black" HorizontalAlignment="Left" Width="100"/>
<TextBox x:Name="maxmem" Template="{StaticResource CornerTextBox}" Text="" Height="30" Width="174" TextWrapping="Wrap" Margin="0,15,10,161" FontSize="20" TextChanged="maxmem_TextChanged" HorizontalAlignment="Right" />
<ComboBox x:Name="javacombo" Height="30" Width="174" FontSize="15" Margin="0,50,10,0" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<Label Margin="10,50,0,126" Content="JAVA版本" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black" HorizontalAlignment="Left" Width="100"/>
<ComboBox x:Name="gamecombo" Height="30" Width="174" FontSize="15" Margin="0,85,10,0" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<Label Margin="10,85,0,91" Content="游戏版本" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black" HorizontalAlignment="Left" Width="100"/>
<Button x:Name="StartGame" BorderBrush="#FF3299CC" Content="启动游戏" Template="{StaticResource CornerButton}" Margin="10,0,10,10" Height="64" VerticalAlignment="Bottom" FontSize="16" Click="StartGame_Click" IsEnabled="False"/>
</Grid>
</Grid>
</Grid>
<Button Template="{StaticResource CornerButton}" Width="30" HorizontalAlignment="Right" Content="r" Background="#FFE05A5A" Height="30" VerticalAlignment="Top" FontFamily="Webdings" Click="close_Click" Margin="0,0,0,0" /> <Button Template="{StaticResource CornerButton}" Width="30" HorizontalAlignment="Right" Content="r" Background="#FFE05A5A" Height="30" VerticalAlignment="Top" FontFamily="Webdings" Click="close_Click" Margin="0,0,0,0" />
</Grid> </Grid>
</Window> </Window>

View File

@ -1,190 +1,199 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using KMCCC.Authentication; using KMCCC.Authentication;
using KMCCC.Launcher; using KMCCC.Launcher;
using KMCCC.Tools; using KMCCC.Tools;
using KMCCC.Modules; using KMCCC.Modules;
using KMCCC.Modules.JVersion; using KMCCC.Modules.JVersion;
using CityCraft; using CityCraft;
using System.IO; using System.IO;
using System.Windows.Threading; using System.Windows.Threading;
namespace CTZLauncher namespace CTZLauncher
{ {
/// <summary> /// <summary>
/// MainWindow.xaml 的交互逻辑 /// MainWindow.xaml 的交互逻辑
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
LauncherCore launcher = null; LauncherCore launcher = null;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
} }
private void Window_Initialized(object sender, EventArgs e) private void Window_Initialized(object sender, EventArgs e)
{ {
if (Directory.Exists(".minecraft")) if (Directory.Exists(".minecraft"))
{ {
launcher = LauncherCore.Create(".minecraft"); launcher = LauncherCore.Create(".minecraft");
launcher.GameLog += launcher_GameLog; launcher.GameLog += launcher_GameLog;
} }
else else
{ {
Directory.CreateDirectory(".minecraft"); Directory.CreateDirectory(".minecraft");
} }
} }
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
{ {
foreach (var item in SystemTools.FindJava()) foreach (var item in SystemTools.FindJava())
{ {
javacombo.Items.Add(item); javacombo.Items.Add(item);
} }
if (!javacombo.Items.IsEmpty) if (!javacombo.Items.IsEmpty)
javacombo.SelectedIndex = 0; javacombo.SelectedIndex = 0;
foreach (var item in launcher.GetVersions()) foreach (var item in launcher.GetVersions())
{ {
gamecombo.Items.Add(item.Id); gamecombo.Items.Add(item.Id);
} }
if (!gamecombo.Items.IsEmpty) if (!gamecombo.Items.IsEmpty)
gamecombo.SelectedIndex = 0; gamecombo.SelectedIndex = 0;
maxmem.Text = "2048"; maxmem.Text = "2048";
} }
private void Window_MouseMove(object sender, MouseEventArgs e) private void Window_MouseMove(object sender, MouseEventArgs e)
{ {
} }
private void barclick_MouseDown(object sender, MouseButtonEventArgs e) private void barclick_MouseDown(object sender, MouseButtonEventArgs e)
{ {
Label bar = (Label)sender; Label bar = (Label)sender;
MessageBox.Show(bar.Name); MessageBox.Show(bar.Name);
switch (bar.Name.Substring(4)) switch (bar.Name.Substring(4))
{ {
case "l1": case "l1":
break; break;
case "l2": case "l2":
break; break;
case "l3": case "l3":
break; break;
case "l4": case "l4":
break; break;
case "r1": case "r1":
break; break;
case "r2": case "r2":
break; break;
case "r3": case "r3":
break; break;
case "r4": case "r4":
break; break;
} }
} }
private void Button_Click(object sender, RoutedEventArgs e) private void Button_Click(object sender, RoutedEventArgs e)
{ {
IAuthenticator auth = new YggdrasilLogin("jtb1@163.com", "jtb325325", false); IAuthenticator auth = new YggdrasilLogin("jtb1@163.com", "jtb325325", false);
AuthenticationInfo result = auth.Do(); AuthenticationInfo result = auth.Do();
MessageBox.Show(result.UUID.ToString()); MessageBox.Show(result.UUID.ToString());
} }
private void Login_Click(object sender, RoutedEventArgs e) private void Login_Click(object sender, RoutedEventArgs e)
{ {
HttpHelper http = new HttpHelper(); Login.IsEnabled = false;
http.Send(HttpMethod.GET, "http://127.0.0.1:2000/isregistered?username=" + username.Text); CTZAuthenticator auth = new CTZAuthenticator(username.Text, password.Text, "127.0.0.1", 2000);
while (http.readyState != HttpReadyState.) if (auth.isLogin())
{ {
DoEvent(); MessageBox.Show("当前玩家已登录!");
} Login.IsEnabled = true;
String result = http.responseBody; return;
Console.WriteLine("服务器返回结果" + result); }
} if (!auth.Login())
{
MessageBox.Show("登录失败 账号不存在 或 密码错误 !");
/// <summary> Login.IsEnabled = true;
/// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块 return;
/// </summary> }
public void DoEvent() else
{ {
DispatcherFrame frame = new DispatcherFrame(); SelServer.Visibility = System.Windows.Visibility.Visible;
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame); return;
Dispatcher.PushFrame(frame); }
} }
public object ExitFrame(object f)
{ /// <summary>
((DispatcherFrame)f).Continue = false; /// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
return null; /// </summary>
} public void DoEvent()
{
private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) DispatcherFrame frame = new DispatcherFrame();
{ Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
if (e.LeftButton == MouseButtonState.Pressed) Dispatcher.PushFrame(frame);
this.DragMove(); }
} public object ExitFrame(object f)
{
private void StartGame_Click(object sender, RoutedEventArgs e) ((DispatcherFrame)f).Continue = false;
{ return null;
Console.WriteLine("StartGame"); }
LaunchOptions option = new LaunchOptions();
option.Mode = LaunchMode.MCLauncher; private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
option.MaxMemory = int.Parse(maxmem.Text); {
option.Authenticator = new OfflineAuthenticator(username.Text); // offline if (e.LeftButton == MouseButtonState.Pressed)
option.Version = launcher.GetVersion(gamecombo.Text); this.DragMove();
launcher.JavaPath = javacombo.Text; }
launcher.Launch(option);
} private void StartGame_Click(object sender, RoutedEventArgs e)
{
void launcher_GameLog(LaunchHandle arg1, string arg2) Console.WriteLine("StartGame");
{ LaunchOptions option = new LaunchOptions();
Console.WriteLine(arg2); option.Mode = LaunchMode.MCLauncher;
} option.MaxMemory = int.Parse(maxmem.Text);
option.Authenticator = new OfflineAuthenticator(username.Text); // offline
private void close_Click(object sender, RoutedEventArgs e) option.Version = launcher.GetVersion(gamecombo.Text);
{ launcher.JavaPath = javacombo.Text;
launcher.Launch(option);
this.Close(); }
}
void launcher_GameLog(LaunchHandle arg1, string log)
private void maxmem_TextChanged(object sender, TextChangedEventArgs e) {
{ Console.WriteLine(log);
//屏蔽中文输入和非法字符粘贴输入 }
TextBox textBox = sender as TextBox;
TextChange[] change = new TextChange[e.Changes.Count]; private void close_Click(object sender, RoutedEventArgs e)
e.Changes.CopyTo(change, 0); {
this.Close();
int offset = change[0].Offset; }
if (change[0].AddedLength > 0)
{ private void maxmem_TextChanged(object sender, TextChangedEventArgs e)
double num = 0; {
if (!Double.TryParse(textBox.Text, out num)) //屏蔽中文输入和非法字符粘贴输入
{ TextBox textBox = sender as TextBox;
textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength); TextChange[] change = new TextChange[e.Changes.Count];
textBox.Select(offset, 0); e.Changes.CopyTo(change, 0);
}
} int offset = change[0].Offset;
} if (change[0].AddedLength > 0)
{
private void register_Click(object sender, RoutedEventArgs e) double num = 0;
{ if (!Double.TryParse(textBox.Text, out num))
if (username.Text.Length == 0 || password.Text.Length == 0) {
{ textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength);
MessageBox.Show("请输入账号密码!"); textBox.Select(offset, 0);
return; }
} }
}
}
} private void register_Click(object sender, RoutedEventArgs e)
} {
if (username.Text.Length == 0 || password.Text.Length == 0)
{
MessageBox.Show("请输入账号密码!");
return;
}
}
}
}