mirror of
https://e.coding.net/circlecloud/CTZLauncher.git
synced 2024-11-21 01:58:48 +00:00
完成服务器列表获取模块 添加启动标题修改 修复HttpHelper获取到空数组...
This commit is contained in:
parent
282d195955
commit
f739a359bf
@ -69,12 +69,17 @@ namespace KMCCC.Authentication
|
||||
public string getServerList()
|
||||
{
|
||||
string sl = http.Send(HttpMethod.GET, Address + ":" + Port + "/serverlist");
|
||||
return sl.Replace("\0","");
|
||||
if (string.IsNullOrEmpty(sl))
|
||||
throw new ArgumentNullException("服务器返回了空的字符串或网络连接异常!");
|
||||
return sl;
|
||||
}
|
||||
|
||||
public bool getResult(string url)
|
||||
{
|
||||
return http.Send(HttpMethod.GET, url).Contains("true") ? true : false;
|
||||
string result = http.Send(HttpMethod.GET, url);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
throw new ArgumentNullException("服务器返回了空的字符串或网络连接异常!");
|
||||
return result.Contains("true") ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +187,14 @@ namespace CityCraft
|
||||
int iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);
|
||||
while (iNumber > 0)//使用了Connection: Close 所以判断长度为0 时停止接受
|
||||
{
|
||||
responseBytes.AddRange(new List<byte>(buffer));//添加数据到List
|
||||
if (iNumber < 1024)
|
||||
{
|
||||
byte[] shotbuffer = new byte[iNumber];
|
||||
Array.Copy(buffer, shotbuffer, iNumber);
|
||||
responseBytes.AddRange(new List<byte>(shotbuffer));//添加数据到List
|
||||
}
|
||||
else
|
||||
responseBytes.AddRange(new List<byte>(buffer));//添加数据到List
|
||||
iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);//继续接收数据
|
||||
}
|
||||
responseByte = responseBytes.ToArray();
|
||||
|
@ -43,7 +43,7 @@
|
||||
{
|
||||
public override bool Operate(LauncherCore core, MinecraftLaunchArguments args)
|
||||
{
|
||||
args.Tokens["game_directory"] = String.Format(@".\versions\{0}\", args.Version.Id);
|
||||
args.Tokens["game_directory"] = String.Format(@".minecraft\versions\{0}\", args.Version.Id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -109,15 +109,20 @@
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏退出事件
|
||||
/// 游戏退出事件
|
||||
/// </summary>
|
||||
public event Action<LaunchHandle, int> GameExit;
|
||||
|
||||
/// <summary>
|
||||
/// 游戏Log事件
|
||||
/// 游戏Log事件
|
||||
/// </summary>
|
||||
public event Action<LaunchHandle, string> GameLog;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 游戏启动事件
|
||||
/// </summary>
|
||||
public event Action<LaunchHandle, string> GameStart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动器核心选项
|
||||
|
@ -66,7 +66,7 @@
|
||||
args.Tokens.Add("user_properties", authentication.Properties);
|
||||
args.Tokens.Add("user_type", authentication.UserType);
|
||||
|
||||
args.AdvencedArguments = new List<string> { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" };
|
||||
args.AdvencedArguments = new List<string> { "-Dfml.ignoreInvalidMinecraftCertificates=true", "-Dfml.ignorePatchDiscrepancies=true" };
|
||||
|
||||
args.Authentication = authentication;
|
||||
args.Version = options.Version;
|
||||
@ -139,6 +139,7 @@
|
||||
})
|
||||
};
|
||||
handle.Work();
|
||||
Start(handle, handle.GetTile());
|
||||
Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
|
||||
return new LaunchResult { Success = true, Handle = handle };
|
||||
}
|
||||
@ -212,6 +213,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
internal void Start(LaunchHandle handle, string title)
|
||||
{
|
||||
if (GameStart != null)
|
||||
{
|
||||
GameStart(handle, title);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -116,36 +116,36 @@
|
||||
<Label Content="选择大区" Margin="155,20" FontSize="20" VerticalAlignment="Center" VerticalContentAlignment="Center"/>
|
||||
</Grid>
|
||||
<Grid Height="100" VerticalAlignment="Top" Margin="0,80,0,0" Name="GameArea">
|
||||
<RadioButton Name="a0" Content="X X大区" Margin="30,30,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="70" Visibility="Hidden" Checked="area_Checked"/>
|
||||
<RadioButton Name="a1" Content="X X大区" Margin="120,30,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="70" Visibility="Hidden" Checked="area_Checked"/>
|
||||
<RadioButton Name="a2" Content="X X大区" Margin="215,30,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="70" Visibility="Hidden" Checked="area_Checked"/>
|
||||
<RadioButton Name="a3" Content="X X大区" Margin="305,30,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="70" Visibility="Hidden" Checked="area_Checked"/>
|
||||
<Button Name="a0" BorderBrush="#FF3299CC" Content="X X大区" Template="{StaticResource CornerButton}" HorizontalAlignment="Left" Margin="30,30,0,0" VerticalAlignment="Top" Width="75" Visibility="Hidden" Click="area_Click"/>
|
||||
<Button Name="a1" BorderBrush="#FF3299CC" Content="X X大区" Template="{StaticResource CornerButton}" HorizontalAlignment="Left" Margin="120,30,0,0" VerticalAlignment="Top" Width="75" Visibility="Hidden" Click="area_Click"/>
|
||||
<Button Name="a2" BorderBrush="#FF3299CC" Content="X X大区" Template="{StaticResource CornerButton}" HorizontalAlignment="Left" Margin="215,30,0,0" VerticalAlignment="Top" Width="75" Visibility="Hidden" Click="area_Click"/>
|
||||
<Button Name="a3" BorderBrush="#FF3299CC" Content="X X大区" Template="{StaticResource CornerButton}" HorizontalAlignment="Left" Margin="305,30,0,0" VerticalAlignment="Top" Width="75" Visibility="Hidden" Click="area_Click"/>
|
||||
|
||||
<RadioButton Name="a4" Content="X X大区" Margin="30,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="70" Visibility="Hidden" Checked="area_Checked"/>
|
||||
<RadioButton Name="a5" Content="X X大区" Margin="120,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="70" Visibility="Hidden" Checked="area_Checked"/>
|
||||
<RadioButton Name="a6" Content="X X大区" Margin="215,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="70" Visibility="Hidden" Checked="area_Checked"/>
|
||||
<RadioButton Name="a7" Content="X X大区" Margin="305,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="70" Visibility="Hidden" Checked="area_Checked"/>
|
||||
<Button Name="a4" BorderBrush="#FF3299CC" Content="X X大区" Template="{StaticResource CornerButton}" HorizontalAlignment="Left" Margin="30,60,0,0" VerticalAlignment="Top" Width="75" Visibility="Hidden" Click="area_Click"/>
|
||||
<Button Name="a5" BorderBrush="#FF3299CC" Content="X X大区" Template="{StaticResource CornerButton}" HorizontalAlignment="Left" Margin="120,60,0,0" VerticalAlignment="Top" Width="75" Visibility="Hidden" Click="area_Click"/>
|
||||
<Button Name="a6" BorderBrush="#FF3299CC" Content="X X大区" Template="{StaticResource CornerButton}" HorizontalAlignment="Left" Margin="215,60,0,0" VerticalAlignment="Top" Width="75" Visibility="Hidden" Click="area_Click"/>
|
||||
<Button Name="a7" BorderBrush="#FF3299CC" Content="X X大区" Template="{StaticResource CornerButton}" HorizontalAlignment="Left" Margin="305,60,0,0" VerticalAlignment="Top" Width="75" Visibility="Hidden" Click="area_Click"/>
|
||||
</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 Margin="10,55,10,10" Name="GameServer">
|
||||
<RadioButton Name="s0" Content="服务器1" Margin="50,40,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<RadioButton Name="s1" Content="服务器2" Margin="150,40,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<RadioButton Name="s2" Content="服务器3" Margin="252,40,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<Button Name="s0" Content="服务器1" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="50,40,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
<Button Name="s1" Content="服务器2" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="150,40,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
<Button Name="s2" Content="服务器3" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="252,40,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
|
||||
<RadioButton Name="s3" Content="服务器4" Margin="50,80,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<RadioButton Name="s4" Content="服务器5" Margin="150,80,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked" />
|
||||
<RadioButton Name="s5" Content="服务器6" Margin="252,80,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<Button Name="s3" Content="服务器4" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="50,80,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
<Button Name="s4" Content="服务器5" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="150,80,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
<Button Name="s5" Content="服务器6" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="252,80,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
|
||||
<RadioButton Name="s6" Content="服务器7" Margin="50,120,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<RadioButton Name="s7" Content="服务器8" Margin="150,120,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<RadioButton Name="s8" Content="服务器9" Margin="252,120,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<Button Name="s6" Content="服务器7" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="50,120,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
<Button Name="s7" Content="服务器8" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="150,120,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
<Button Name="s8" Content="服务器9" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="252,120,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
|
||||
<RadioButton Name="s9" Content="服务器10" Margin="50,160,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<RadioButton Name="s10" Content="服务器11" Margin="150,160,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<RadioButton Name="s11" Content="服务器12" Margin="252,160,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Checked="server_Checked"/>
|
||||
<Button Name="s9" Content="服务器10" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="50,160,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
<Button Name="s10" Content="服务器11" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="150,160,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
<Button Name="s11" Content="服务器12" Template="{StaticResource CornerButton}" BorderBrush="#FF3299CC" Margin="252,160,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Visibility="Hidden" Click="server_Click"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
@ -155,10 +155,16 @@
|
||||
<Label Content="服务器介绍" Margin="85,2" FontSize="20" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<Grid Height="200" VerticalAlignment="Bottom" Margin="10,0,10,10">
|
||||
<Label Content="" Margin="50,35,50,35"/>
|
||||
<Label Name="serverinfo" Content="" Margin="50,35,50,35" FontSize="15"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid HorizontalAlignment="Right" Width="300" ShowGridLines="True" Height="206" VerticalAlignment="Bottom">
|
||||
<Grid ShowGridLines="True" Height="200" VerticalAlignment="Bottom">
|
||||
<Label Content="服务器名称:" Margin="40,20,160,0" FontSize="15" HorizontalContentAlignment="Center" Height="30" VerticalAlignment="Top" />
|
||||
<Label Name="selserver" Content="" Margin="145,20,40,0" FontSize="15" HorizontalContentAlignment="Center" Height="30" VerticalAlignment="Top" />
|
||||
<Label Content="客户端版本:" Margin="40,50,160,0" FontSize="15" HorizontalContentAlignment="Center" Height="30" VerticalAlignment="Top" />
|
||||
<Label Name="needclient" Content="" Margin="145,50,40,0" FontSize="15" HorizontalContentAlignment="Center" Height="30" VerticalAlignment="Top" />
|
||||
<Label Content="在线人数:" Margin="40,80,160,0" FontSize="15" HorizontalContentAlignment="Center" Height="30" VerticalAlignment="Top" />
|
||||
<Label Name="online" Content="" Margin="145,80,40,0" FontSize="15" HorizontalContentAlignment="Center" Height="30" VerticalAlignment="Top" />
|
||||
<Button x:Name="StartGame" BorderBrush="#FF3299CC" Content="启动游戏" Template="{StaticResource CornerButton}" Margin="10,0,10,10" Height="64" VerticalAlignment="Bottom" FontSize="16" Click="StartGame_Click"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
@ -32,7 +32,7 @@ namespace CTZLauncher
|
||||
{
|
||||
LauncherCore launcher = null;
|
||||
LaunchOptions option = new LaunchOptions();
|
||||
string serveraddress = "CityCraft.cn";
|
||||
string serveraddress = "127.0.0.1";
|
||||
int serverport = 25580;
|
||||
|
||||
#region 初始化部分
|
||||
@ -86,33 +86,43 @@ namespace CTZLauncher
|
||||
}
|
||||
Login.IsEnabled = false;
|
||||
CTZAuthenticator auth = new CTZAuthenticator(username.Text, password.Text, serveraddress, serverport);
|
||||
if (auth.isLogin())
|
||||
try
|
||||
{
|
||||
MessageBox.Show("当前玩家已登录服务器!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!auth.Login())
|
||||
if (auth.isLogin())
|
||||
{
|
||||
if (!auth.isRegistered())
|
||||
MessageBox.Show("该用户名未注册 请先注册!");
|
||||
else
|
||||
MessageBox.Show("登录失败 账号不存在 或 密码错误 !");
|
||||
MessageBox.Show("当前玩家已登录服务器!");
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerWindow.Visibility = System.Windows.Visibility.Visible;
|
||||
RotateTransform rtf = new RotateTransform();
|
||||
ServerWindow.RenderTransform = rtf;
|
||||
LoginWindow.RenderTransform = rtf;
|
||||
DoubleAnimation dbAscending = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromSeconds(0.75)));
|
||||
dbAscending.RepeatBehavior = new RepeatBehavior(1);
|
||||
rtf.BeginAnimation(RotateTransform.AngleProperty, dbAscending);
|
||||
CTZServer areas = JsonMapper.ToObject<CTZServer>(auth.getServerList().ToLower());
|
||||
LoadAreas(areas);
|
||||
if (!auth.Login())
|
||||
{
|
||||
if (!auth.isRegistered())
|
||||
MessageBox.Show("该用户名未注册 请先注册!");
|
||||
else
|
||||
MessageBox.Show("登录失败 账号不存在 或 密码错误 !");
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerWindow.Visibility = System.Windows.Visibility.Visible;
|
||||
RotateTransform rtf = new RotateTransform();
|
||||
ServerWindow.RenderTransform = rtf;
|
||||
LoginWindow.RenderTransform = rtf;
|
||||
DoubleAnimation dbAscending = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromSeconds(0.75)));
|
||||
dbAscending.RepeatBehavior = new RepeatBehavior(1);
|
||||
rtf.BeginAnimation(RotateTransform.AngleProperty, dbAscending);
|
||||
CTZServer areas = JsonMapper.ToObject<CTZServer>(auth.getServerList().ToLower());
|
||||
LoadAreas(areas);
|
||||
}
|
||||
}
|
||||
}
|
||||
Login.IsEnabled = true;
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Login.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
@ -147,25 +157,38 @@ namespace CTZLauncher
|
||||
|
||||
private void register_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
register.IsEnabled = false;
|
||||
if (username.Text.Length == 0 || password.Text.Length == 0)
|
||||
{
|
||||
MessageBox.Show("请输入账号密码!");
|
||||
return;
|
||||
}
|
||||
CTZAuthenticator auth = new CTZAuthenticator(username.Text, password.Text, "citycraft.cn", serverport);
|
||||
if (auth.isRegistered())
|
||||
try
|
||||
{
|
||||
MessageBox.Show("该用户名已注册 请更换用户名!");
|
||||
return;
|
||||
if (auth.isRegistered())
|
||||
{
|
||||
MessageBox.Show("该用户名已注册 请更换用户名!");
|
||||
return;
|
||||
}
|
||||
if (auth.Register())
|
||||
{
|
||||
MessageBox.Show("注册成功!");
|
||||
auth.Login();
|
||||
ServerWindow.Visibility = System.Windows.Visibility.Visible;
|
||||
}
|
||||
else
|
||||
MessageBox.Show("注册失败!");
|
||||
}
|
||||
if (auth.Register())
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
MessageBox.Show("注册成功!");
|
||||
auth.Login();
|
||||
ServerWindow.Visibility = System.Windows.Visibility.Visible;
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
else
|
||||
MessageBox.Show("注册失败!");
|
||||
finally
|
||||
{
|
||||
register.IsEnabled = true;
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -175,11 +198,16 @@ namespace CTZLauncher
|
||||
for (int i = 0; i < areas.Areas.Count; i++)
|
||||
{
|
||||
Area area = areas.Areas[i];
|
||||
RadioButton arearb = GameArea.FindName("a" + i) as RadioButton;
|
||||
Button arearb = GameArea.FindName("a" + i) as Button;
|
||||
arearb.Content = area.Name;
|
||||
arearb.Visibility = Visibility.Visible;
|
||||
arearb.Tag = area.Servers;
|
||||
}
|
||||
for (int i = areas.Areas.Count; i < 8; i++)
|
||||
{
|
||||
Button arearb = GameArea.FindName("a" + i) as Button;
|
||||
arearb.Visibility = Visibility.Hidden;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadServers(List<Server> servers)
|
||||
@ -187,43 +215,57 @@ namespace CTZLauncher
|
||||
for (int i = 0; i < servers.Count; i++)
|
||||
{
|
||||
Server server = servers[i];
|
||||
RadioButton serverrb = GameArea.FindName("s" + i) as RadioButton;
|
||||
Button serverrb = GameArea.FindName("s" + i) as Button;
|
||||
serverrb.Content = server.Name;
|
||||
serverrb.Visibility = Visibility.Visible;
|
||||
serverrb.Tag = server;
|
||||
}
|
||||
for (int i = servers.Count; i < 12; i++)
|
||||
{
|
||||
Button serverrb = GameArea.FindName("s" + i) as Button;
|
||||
serverrb.Visibility = Visibility.Hidden;
|
||||
}
|
||||
}
|
||||
|
||||
private void area_Checked(object sender, RoutedEventArgs e)
|
||||
private void area_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RadioButton rb = (RadioButton)sender;
|
||||
LoadServers((List<Server>)rb.Tag);
|
||||
Button arb = (Button)sender;
|
||||
LoadServers((List<Server>)arb.Tag);
|
||||
}
|
||||
|
||||
private void server_Checked(object sender, RoutedEventArgs e)
|
||||
private void server_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RadioButton rb = (RadioButton)sender;
|
||||
Server server = (Server)rb.Tag;
|
||||
Button srb = (Button)sender;
|
||||
Server server = (Server)srb.Tag;
|
||||
option.Server = new ServerInfo
|
||||
{
|
||||
Address = server.Address,
|
||||
Port = server.Port
|
||||
};
|
||||
option.Version = launcher.GetVersion(server.Version);
|
||||
serverinfo.Content = server.Info;
|
||||
selserver.Content = server.Name;
|
||||
needclient.Content = server.Version;
|
||||
}
|
||||
|
||||
private void StartGame_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Console.WriteLine("StartGame");
|
||||
Console.WriteLine("启动游戏");
|
||||
option.Mode = LaunchMode.MCLauncher;
|
||||
option.MaxMemory = 2048;
|
||||
option.Authenticator = new OfflineAuthenticator(username.Text); // offline
|
||||
option.Version = launcher.GetVersion("1.8");
|
||||
option.Authenticator = new OfflineAuthenticator(username.Text); // 离线模式
|
||||
launcher.JavaPath = SystemTools.FindJava().First();
|
||||
launcher.GameLog += launcher_GameLog;
|
||||
launcher.GameStart += Launcher_GameStart;
|
||||
launcher.Launch(option);
|
||||
}
|
||||
|
||||
private void Launcher_GameStart(LaunchHandle arg1, string arg2)
|
||||
{
|
||||
string title = selserver.Content.ToString() + " - " + username.Text;
|
||||
arg1.SetTitle(title);
|
||||
}
|
||||
|
||||
void launcher_GameLog(LaunchHandle arg1, string log)
|
||||
{
|
||||
Console.WriteLine(log);
|
||||
|
@ -74,6 +74,12 @@ namespace CTZLauncher.Modules.CTZServer
|
||||
[JsonPropertyName("url")]
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 客户端依赖项
|
||||
/// </summary>
|
||||
[JsonPropertyName("depend")]
|
||||
public string Depend { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得服务器链接
|
||||
/// </summary>
|
||||
|
@ -1,239 +1,240 @@
|
||||
namespace KMCCC.Modules.JVersion
|
||||
{
|
||||
#region
|
||||
#region
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Launcher;
|
||||
using LitJson;
|
||||
using Tools;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Launcher;
|
||||
using LitJson;
|
||||
using Tools;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 默认的版本定位器
|
||||
/// </summary>
|
||||
public class JVersionLocator : IVersionLocator
|
||||
{
|
||||
private readonly HashSet<string> _locatingVersion;
|
||||
/// <summary>
|
||||
/// 默认的版本定位器
|
||||
/// </summary>
|
||||
public class JVersionLocator : IVersionLocator
|
||||
{
|
||||
private readonly HashSet<string> _locatingVersion;
|
||||
|
||||
private readonly Dictionary<string, Version> _versions;
|
||||
private readonly Dictionary<string, Version> _versions;
|
||||
|
||||
public JVersionLocator()
|
||||
{
|
||||
_versions = new Dictionary<string, Version>();
|
||||
_locatingVersion = new HashSet<string>();
|
||||
}
|
||||
public JVersionLocator()
|
||||
{
|
||||
_versions = new Dictionary<string, Version>();
|
||||
_locatingVersion = new HashSet<string>();
|
||||
}
|
||||
|
||||
public string GameRootPath { get; set; }
|
||||
public string GameRootPath { get; set; }
|
||||
|
||||
private LauncherCore _core;
|
||||
private LauncherCore _core;
|
||||
|
||||
public LauncherCore Core
|
||||
{
|
||||
set
|
||||
{
|
||||
GameRootPath = value.GameRootPath;
|
||||
_core = value;
|
||||
}
|
||||
}
|
||||
public LauncherCore Core
|
||||
{
|
||||
set
|
||||
{
|
||||
GameRootPath = value.GameRootPath;
|
||||
_core = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Version Locate(string id)
|
||||
{
|
||||
lock (_locatingVersion)
|
||||
{
|
||||
return GetVersionInternal(id);
|
||||
}
|
||||
}
|
||||
public Version Locate(string id)
|
||||
{
|
||||
lock (_locatingVersion)
|
||||
{
|
||||
return GetVersionInternal(id);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Version> GetAllVersions()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (_locatingVersion)
|
||||
{
|
||||
return new DirectoryInfo(GameRootPath + @"\versions").EnumerateDirectories()
|
||||
.Select(dir => GetVersionInternal(dir.Name)).Where(item => item != null);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Version[0];
|
||||
}
|
||||
}
|
||||
public IEnumerable<Version> GetAllVersions()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (_locatingVersion)
|
||||
{
|
||||
return new DirectoryInfo(GameRootPath + @"\versions").EnumerateDirectories()
|
||||
.Select(dir => GetVersionInternal(dir.Name)).Where(item => item != null);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Version[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Version信息,当出现错误时会返回null
|
||||
/// </summary>
|
||||
/// <param name="id">版本id</param>
|
||||
/// <returns>Version的信息</returns>
|
||||
internal Version GetVersionInternal(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_locatingVersion.Contains(id))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_locatingVersion.Add(id);
|
||||
/// <summary>
|
||||
/// 获取Version信息,当出现错误时会返回null
|
||||
/// </summary>
|
||||
/// <param name="id">版本id</param>
|
||||
/// <returns>Version的信息</returns>
|
||||
internal Version GetVersionInternal(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_locatingVersion.Contains(id))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_locatingVersion.Add(id);
|
||||
|
||||
Version version;
|
||||
if (_versions.TryGetValue(id, out version))
|
||||
{
|
||||
return version;
|
||||
}
|
||||
Version version;
|
||||
if (_versions.TryGetValue(id, out version))
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
var jver = LoadVersion(_core.GetVersionJsonPath(id));
|
||||
if (jver == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var jver = LoadVersion(_core.GetVersionJsonPath(id));
|
||||
if (jver == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
version = new Version();
|
||||
if (string.IsNullOrWhiteSpace(jver.Id))
|
||||
{
|
||||
jver.Id = id;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(jver.MinecraftArguments))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(jver.MainClass))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(jver.Assets))
|
||||
{
|
||||
jver.Assets = "legacy";
|
||||
}
|
||||
if (jver.Libraries == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
version.Id = jver.Id;
|
||||
version.MinecraftArguments = jver.MinecraftArguments;
|
||||
version.Assets = jver.Assets;
|
||||
version.MainClass = jver.MainClass;
|
||||
version.JarId = jver.JarId;
|
||||
version.Libraries = new List<Library>();
|
||||
version.Natives = new List<Native>();
|
||||
foreach (var lib in jver.Libraries)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(lib.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var names = lib.Name.Split(':');
|
||||
if (names.Length != 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (lib.Natives == null)
|
||||
{
|
||||
if (!IfAllowed(lib.Rules))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
version.Libraries.Add(new Library
|
||||
{
|
||||
NS = names[0],
|
||||
Name = names[1],
|
||||
Version = names[2]
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!IfAllowed(lib.Rules))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var native = new Native
|
||||
{
|
||||
NS = names[0],
|
||||
Name = names[1],
|
||||
Version = names[2],
|
||||
NativeSuffix = lib.Natives["windows"].Replace("${arch}", SystemTools.GetArch())
|
||||
};
|
||||
version.Natives.Add(native);
|
||||
if (lib.Extract != null)
|
||||
{
|
||||
native.Options = new UnzipOptions {Exclude = lib.Extract.Exculde};
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jver.InheritsVersion != null)
|
||||
{
|
||||
var target = GetVersionInternal(jver.InheritsVersion);
|
||||
if (target == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
version.Assets = version.Assets ?? target.Assets;
|
||||
version.JarId = version.JarId ?? target.JarId;
|
||||
version.MainClass = version.MainClass ?? target.MainClass;
|
||||
version.MinecraftArguments = version.MinecraftArguments ?? target.MinecraftArguments;
|
||||
version.Natives.AddRange(target.Natives);
|
||||
version.Libraries.AddRange(target.Libraries);
|
||||
}
|
||||
}
|
||||
version.JarId = version.JarId ?? version.Id;
|
||||
_versions.Add(version.Id, version);
|
||||
return version;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_locatingVersion.Remove(id);
|
||||
}
|
||||
}
|
||||
version = new Version();
|
||||
//if (string.IsNullOrWhiteSpace(jver.Id))
|
||||
//{
|
||||
// jver.Id = id;
|
||||
//}
|
||||
jver.Id = id;
|
||||
if (string.IsNullOrWhiteSpace(jver.MinecraftArguments))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(jver.MainClass))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(jver.Assets))
|
||||
{
|
||||
jver.Assets = "legacy";
|
||||
}
|
||||
if (jver.Libraries == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
version.Id = jver.Id;
|
||||
version.MinecraftArguments = jver.MinecraftArguments;
|
||||
version.Assets = jver.Assets;
|
||||
version.MainClass = jver.MainClass;
|
||||
version.JarId = jver.JarId;
|
||||
version.Libraries = new List<Library>();
|
||||
version.Natives = new List<Native>();
|
||||
foreach (var lib in jver.Libraries)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(lib.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var names = lib.Name.Split(':');
|
||||
if (names.Length != 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (lib.Natives == null)
|
||||
{
|
||||
if (!IfAllowed(lib.Rules))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
version.Libraries.Add(new Library
|
||||
{
|
||||
NS = names[0],
|
||||
Name = names[1],
|
||||
Version = names[2]
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!IfAllowed(lib.Rules))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var native = new Native
|
||||
{
|
||||
NS = names[0],
|
||||
Name = names[1],
|
||||
Version = names[2],
|
||||
NativeSuffix = lib.Natives["windows"].Replace("${arch}", SystemTools.GetArch())
|
||||
};
|
||||
version.Natives.Add(native);
|
||||
if (lib.Extract != null)
|
||||
{
|
||||
native.Options = new UnzipOptions { Exclude = lib.Extract.Exculde };
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jver.InheritsVersion != null)
|
||||
{
|
||||
var target = GetVersionInternal(jver.InheritsVersion);
|
||||
if (target == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
version.Assets = version.Assets ?? target.Assets;
|
||||
version.JarId = version.JarId ?? target.JarId;
|
||||
version.MainClass = version.MainClass ?? target.MainClass;
|
||||
version.MinecraftArguments = version.MinecraftArguments ?? target.MinecraftArguments;
|
||||
version.Natives.AddRange(target.Natives);
|
||||
version.Libraries.AddRange(target.Libraries);
|
||||
}
|
||||
}
|
||||
version.JarId = version.JarId ?? version.Id;
|
||||
_versions.Add(version.Id, version);
|
||||
return version;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_locatingVersion.Remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
public JVersion LoadVersion(string jsonPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonMapper.ToObject<JVersion>(File.ReadAllText(jsonPath));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public JVersion LoadVersion(string jsonPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonMapper.ToObject<JVersion>(File.ReadAllText(jsonPath));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断一系列规则后是否启用
|
||||
/// </summary>
|
||||
/// <param name="rules">规则们</param>
|
||||
/// <returns>是否启用</returns>
|
||||
public bool IfAllowed(List<JRule> rules)
|
||||
{
|
||||
if (rules == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (rules.Count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var allowed = false;
|
||||
foreach (var rule in rules)
|
||||
{
|
||||
if (rule.OS == null)
|
||||
{
|
||||
allowed = rule.Action == "allow";
|
||||
continue;
|
||||
}
|
||||
if (rule.OS.Name == "windows")
|
||||
{
|
||||
allowed = rule.Action == "allow";
|
||||
}
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断一系列规则后是否启用
|
||||
/// </summary>
|
||||
/// <param name="rules">规则们</param>
|
||||
/// <returns>是否启用</returns>
|
||||
public bool IfAllowed(List<JRule> rules)
|
||||
{
|
||||
if (rules == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (rules.Count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var allowed = false;
|
||||
foreach (var rule in rules)
|
||||
{
|
||||
if (rule.OS == null)
|
||||
{
|
||||
allowed = rule.Action == "allow";
|
||||
continue;
|
||||
}
|
||||
if (rule.OS.Name == "windows")
|
||||
{
|
||||
allowed = rule.Action == "allow";
|
||||
}
|
||||
}
|
||||
return allowed;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user