提交合并...

master
j502647092 2015-09-05 13:23:49 +08:00
commit 021a55cc1b
23 changed files with 194 additions and 13 deletions

View File

@ -97,6 +97,8 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Modules\CTZServer\CTZServer.cs" /> <Compile Include="Modules\CTZServer\CTZServer.cs" />
<Compile Include="Modules\Minecraft\ServerInfo.cs" />
<Compile Include="Tools\MinecraftTools.cs" />
<Compile Include="Tools\SystemTools.cs" /> <Compile Include="Tools\SystemTools.cs" />
<Compile Include="Tools\UsefulTools.cs" /> <Compile Include="Tools\UsefulTools.cs" />
<Compile Include="Tools\ZipTools.cs" /> <Compile Include="Tools\ZipTools.cs" />
@ -197,6 +199,25 @@
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="bg\bg10.jpg" />
<Resource Include="bg\bg11.jpg" />
<Resource Include="bg\bg12.jpg" />
<Resource Include="bg\bg13.jpg" />
<Resource Include="bg\bg14.jpg" />
<Resource Include="bg\bg15.jpg" />
<Resource Include="bg\bg16.jpg" />
<Resource Include="bg\bg17.jpg" />
<Resource Include="bg\bg18.jpg" />
<Resource Include="bg\bg19.jpg" />
<Resource Include="bg\bg20.jpg" />
<Resource Include="bg\bg21.jpg" />
<Resource Include="bg\bg22.jpg" />
<Resource Include="bg\bg6.jpg" />
<Resource Include="bg\bg7.jpg" />
<Resource Include="bg\bg8.jpg" />
<Resource Include="bg\bg9.jpg" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -42,10 +42,6 @@
<Image HorizontalAlignment="Left" Height="50" Margin="15,5,0,0" VerticalAlignment="Top" Width="50" Source="ico.ico" RenderTransformOrigin="0.56,0.24"/> <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" /> <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>
<Grid Name="LoginWindow" Margin="20,60,20,20" Background="White"> <Grid Name="LoginWindow" Margin="20,60,20,20" Background="White">
<Grid Height="270" VerticalAlignment="Top"> <Grid Height="270" VerticalAlignment="Top">
<Grid Margin="20,20,0,0" HorizontalAlignment="Left" Width="400" > <Grid Margin="20,20,0,0" HorizontalAlignment="Left" Width="400" >
@ -55,9 +51,9 @@
<Grid> <Grid>
<Grid Margin="10,10,10,0" Height="174" VerticalAlignment="Top"> <Grid Margin="10,10,10,0" Height="174" VerticalAlignment="Top">
<Label Content="————— 游 戏 帐 号 —————" VerticalAlignment="Top" Margin="10,0" HorizontalContentAlignment="Center" FontSize="15"/> <Label Content="————— 游 戏 帐 号 —————" VerticalAlignment="Top" Margin="10,0" HorizontalContentAlignment="Center" FontSize="15"/>
<TextBox x: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" KeyDown="username_KeyDown" />
<Label Content="————— 游 戏 密 码 —————" VerticalAlignment="Top" Margin="10,69,10,0" HorizontalContentAlignment="Center" FontSize="15"/> <Label Content="————— 游 戏 密 码 —————" VerticalAlignment="Top" Margin="10,69,10,0" HorizontalContentAlignment="Center" FontSize="15"/>
<TextBox x:Name="password" Template="{StaticResource CornerTextBox}" TextWrapping="Wrap" HorizontalContentAlignment="Center" FontFamily="微软雅黑" FontSize="20" Margin="30,104,30,0" Height="34" VerticalAlignment="Top" Tag="{}{&quot;areas&quot;:[{&quot;name&quot;:&quot;\u7eaf\u51c0\u5927\u533a&quot;,&quot;servers&quot;:[{&quot;name&quot;:&quot;\u5149\u677f\u5c0f\u9547&quot;,&quot;address&quot;:&quot;CityCraft.cn&quot;,&quot;port&quot;:25565,&quot;info&quot;:&quot;\u7eaf\u51c0\u670d\u52a1\u5668&quot;,&quot;version&quot;:&quot;1.8-Forge&quot;,&quot;url&quot;:&quot;CityCraft.cn&quot;}]},{&quot;name&quot;:&quot;\u6a21\u7ec4\u5927\u533a&quot;,&quot;servers&quot;:[{&quot;name&quot;:&quot;\u5149\u677f\u5c0f\u9547&quot;,&quot;address&quot;:&quot;CityCraft.cn&quot;,&quot;port&quot;:25573,&quot;info&quot;:&quot;MOD\u670d\u52a1\u5668: \u8c46\u8150 \u5bb6\u5177 &quot;,&quot;version&quot;:&quot;1.7.10-Forge&quot;,&quot;url&quot;:&quot;CityCraft.cn&quot;}]}]}" /> <TextBox x:Name="password" Template="{StaticResource CornerTextBox}" TextWrapping="Wrap" HorizontalContentAlignment="Center" FontFamily="微软雅黑" FontSize="20" Margin="30,104,30,0" Height="34" VerticalAlignment="Top" Tag="{}{&quot;areas&quot;:[{&quot;name&quot;:&quot;\u7eaf\u51c0\u5927\u533a&quot;,&quot;servers&quot;:[{&quot;name&quot;:&quot;\u5149\u677f\u5c0f\u9547&quot;,&quot;address&quot;:&quot;CityCraft.cn&quot;,&quot;port&quot;:25565,&quot;info&quot;:&quot;\u7eaf\u51c0\u670d\u52a1\u5668&quot;,&quot;version&quot;:&quot;1.8-Forge&quot;,&quot;url&quot;:&quot;CityCraft.cn&quot;}]},{&quot;name&quot;:&quot;\u6a21\u7ec4\u5927\u533a&quot;,&quot;servers&quot;:[{&quot;name&quot;:&quot;\u5149\u677f\u5c0f\u9547&quot;,&quot;address&quot;:&quot;CityCraft.cn&quot;,&quot;port&quot;:25573,&quot;info&quot;:&quot;MOD\u670d\u52a1\u5668: \u8c46\u8150 \u5bb6\u5177 &quot;,&quot;version&quot;:&quot;1.7.10-Forge&quot;,&quot;url&quot;:&quot;CityCraft.cn&quot;}]}]}" KeyDown="password_KeyDown" />
<Button x:Name="forget" Margin="217,106,33,0" Template="{StaticResource CornerButton}" Height="30" Content="?" VerticalAlignment="Top" /> <Button x:Name="forget" 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">
@ -105,10 +101,6 @@
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>
<Grid Margin="20,60,20,20" Background="White" x:Name="ServerWindow" Visibility="Hidden"> <Grid Margin="20,60,20,20" Background="White" x:Name="ServerWindow" Visibility="Hidden">
<!--Visibility="Hidden"--> <!--Visibility="Hidden"-->
<Grid HorizontalAlignment="Left" Width="400" Margin="20,20,0,20"> <Grid HorizontalAlignment="Left" Width="400" Margin="20,20,0,20">

View File

@ -1,4 +1,5 @@
using CTZLauncher.Modules.CTZServer; using CTZLauncher.Modules.CTZServer;
using CTZLauncher.Tools;
using KMCCC.Authentication; using KMCCC.Authentication;
using KMCCC.Launcher; using KMCCC.Launcher;
using KMCCC.Tools; using KMCCC.Tools;
@ -8,6 +9,7 @@ using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@ -94,7 +96,7 @@ namespace CTZLauncher
} }
else else
{ {
ServerWindow.Visibility = System.Windows.Visibility.Visible; ServerWindow.Visibility = Visibility.Visible;
RotateTransform rtf = new RotateTransform(); RotateTransform rtf = new RotateTransform();
ServerWindow.RenderTransform = rtf; ServerWindow.RenderTransform = rtf;
LoginWindow.RenderTransform = rtf; LoginWindow.RenderTransform = rtf;
@ -237,6 +239,13 @@ namespace CTZLauncher
serverinfo.Content = server.Info; serverinfo.Content = server.Info;
selserver.Content = server.Name; selserver.Content = server.Name;
needclient.Content = server.Version; needclient.Content = server.Version;
online.Content = "获取中...";
MinecraftServer ms = new MinecraftServer(server.Address, server.Port);
var info = ms.DoAsync();
if (info != null)
online.Content = info.Players.Online + "/" + info.Players.Max;
else
online.Content = "获取失败!";
} }
private void StartGame_Click(object sender, RoutedEventArgs e) private void StartGame_Click(object sender, RoutedEventArgs e)
@ -262,5 +271,17 @@ namespace CTZLauncher
Console.WriteLine(log); Console.WriteLine(log);
} }
#endregion #endregion
private void username_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
password.Focus();
}
private void password_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
Login_Click(sender, e);
}
} }
} }

View File

@ -0,0 +1,49 @@
using LitJson;
using System.Collections.Generic;
namespace CTZLauncher.Modules.Minecraft
{
public class ServerInfo
{
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonPropertyName("players")]
public Players Players { get; set; }
[JsonPropertyName("version")]
public Version Version { get; set; }
[JsonPropertyName("modinfo")]
public ModInfo ModInfo { get; set; }
}
public class ModInfo
{
[JsonPropertyName("type")]
public string Type { get; set; }
[JsonPropertyName("modList")]
public List<Mod> ModList { get; set; }
}
public class Mod
{
[JsonPropertyName("modid")]
public string Modid { get; set; }
[JsonPropertyName("version")]
public string Version { get; set; }
}
public class Version
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("protocol")]
public int Protocol { get; set; }
}
public class Players
{
[JsonPropertyName("max")]
public int Max { get; set; }
[JsonPropertyName("online")]
public int Online { get; set; }
}
}

View File

@ -0,0 +1,98 @@
using CTZLauncher.Modules.Minecraft;
using LitJson;
using System;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Windows.Threading;
namespace CTZLauncher.Tools
{
public class MinecraftServer
{
string address;
int port;
bool finish;
ServerInfo serverinfo;
/// <summary>
/// 获取服务器详细信息
/// </summary>
/// <param name="address">服务器地址</param>
/// <param name="port">服务器端口</param>
public MinecraftServer(string address, int port)
{
this.address = address;
this.port = port;
}
/// <summary>
/// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
/// </summary>
public void DoEvent()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}
public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
/// <summary>
/// 异步获取服务器信息
/// </summary>
/// <returns>服务器信息</returns>
public ServerInfo DoAsync()
{
new Thread(new ThreadStart(GetInfoAsync)).Start();
while (finish == false) { DoEvent(); }
return serverinfo;
}
/// <summary>
/// 获取服务器信息
/// </summary>
/// <returns>服务器信息</returns>
public ServerInfo Do()
{
return GetInfo();
}
public void GetInfoAsync()
{
finish = false;
serverinfo = GetInfo();
finish = true;
}
public ServerInfo GetInfo()
{
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
try
{
client.Connect(address, port);
if (client.Connected)
{
client.Send(new byte[] { 0x0f, 0x00, 0x04, 0x09, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x63, 0xdd, 0x01 });
client.Send(new byte[] { 0x01, 0x00 });
byte[] header = new byte[5];
client.Receive(header, header.Length, SocketFlags.None);
byte[] buffer = new byte[1024];
int recover = client.Receive(buffer, buffer.Length, SocketFlags.None);
byte[] data = new byte[recover];
Array.Copy(buffer, data, recover);
string info = Encoding.UTF8.GetString(data);
return JsonMapper.ToObject<ServerInfo>(info);
}
Console.WriteLine("网络连接失败!");
return null;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
return null;
}
}
}
}
}

BIN
CTZLauncher/bg/bg10.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
CTZLauncher/bg/bg11.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
CTZLauncher/bg/bg12.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
CTZLauncher/bg/bg13.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

BIN
CTZLauncher/bg/bg14.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
CTZLauncher/bg/bg15.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

BIN
CTZLauncher/bg/bg16.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
CTZLauncher/bg/bg17.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
CTZLauncher/bg/bg18.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
CTZLauncher/bg/bg19.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
CTZLauncher/bg/bg20.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
CTZLauncher/bg/bg21.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
CTZLauncher/bg/bg22.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
CTZLauncher/bg/bg6.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
CTZLauncher/bg/bg7.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
CTZLauncher/bg/bg8.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
CTZLauncher/bg/bg9.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -11,7 +11,7 @@ namespace MinecraftServerInfo
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
using (Socket client = new Socket(SocketType.Stream, ProtocolType.Tcp)) using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
try try
{ {
client.Connect("four.mengcraft.com", 11133); client.Connect("four.mengcraft.com", 11133);
@ -19,7 +19,7 @@ namespace MinecraftServerInfo
if (client.Connected) if (client.Connected)
{ {
Console.WriteLine("发送数据"); Console.WriteLine("发送数据");
client.Send(new byte[] { 0x0F, 0x00, 0x2F, 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x31, 0x63, 0xDD, 0x01 }); client.Send(new byte[] { 0x0F, 0x00, 0x04, 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x31, 0x63, 0xDD, 0x01 });
client.Send(new byte[] { 0x01, 0x00 }); client.Send(new byte[] { 0x01, 0x00 });
Console.WriteLine("读取头数据"); Console.WriteLine("读取头数据");
byte[] header = new byte[5]; byte[] header = new byte[5];