diff --git a/CTZLauncher/CTZAuth/CTZAuth.cs b/CTZLauncher/CTZAuth/CTZAuth.cs
new file mode 100644
index 0000000..fa316d2
--- /dev/null
+++ b/CTZLauncher/CTZAuth/CTZAuth.cs
@@ -0,0 +1,42 @@
+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;
+ string port;
+ public bool isRegister(string username)
+ {
+ return getResult(address + ":" + port + "/isregister?username=" + username);
+ }
+
+ public bool Register(string username, string password)
+ {
+ return false;
+ }
+
+ public bool isLogin(string username)
+ {
+ return getResult(address + ":" + port + "/islogin?username=" + username);
+ }
+
+ public bool Login(string username, string password)
+ {
+ return false;
+ }
+
+ public bool getResult(string url)
+ {
+ string result = http.Send(HttpMethod.GET, url);
+ if (result == "true")
+ return true;
+ return false;
+ }
+ }
+}
diff --git a/CTZLauncher/CTZAuth/ICTZAuth.cs b/CTZLauncher/CTZAuth/ICTZAuth.cs
new file mode 100644
index 0000000..a9487d8
--- /dev/null
+++ b/CTZLauncher/CTZAuth/ICTZAuth.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace CTZLauncher.CTZAuth
+{
+ interface ICTZAuth
+ {
+ public abstract bool isRegister(string username);
+
+ public abstract bool Register(string username, string password);
+
+ public abstract bool isLogin(string username);
+
+ public abstract bool Login(string username, string password);
+
+ }
+}
diff --git a/CTZLauncher/CTZLauncher.csproj b/CTZLauncher/CTZLauncher.csproj
index 5ad845e..c749904 100644
--- a/CTZLauncher/CTZLauncher.csproj
+++ b/CTZLauncher/CTZLauncher.csproj
@@ -65,6 +65,8 @@
App.xaml
Code
+
+
MainWindow.xaml
diff --git a/CTZLauncher/HttpHelper.cs b/CTZLauncher/HttpHelper.cs
index 52d0ce9..ce42cf8 100644
--- a/CTZLauncher/HttpHelper.cs
+++ b/CTZLauncher/HttpHelper.cs
@@ -12,6 +12,7 @@ using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
+using System.Windows.Threading;
namespace CityCraft
{
@@ -60,12 +61,33 @@ namespace CityCraft
/// 请求地址
/// Cookies存储器
/// 请求返回的Stream
- public void Send(HttpMethod method, string url)
+ public string Send(HttpMethod method, string url, bool Async = false)
{
readyState = HttpReadyState.载入;
ParseURL(url);
args.Method = method;
new Thread(new ThreadStart(ReciveData)).Start();
+ if (!Async)
+ {
+ while (readyState != HttpReadyState.完成) { this.DoEvent(); }
+ return responseBody;
+ }
+ return string.Empty;
+ }
+
+ ///
+ /// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
+ ///
+ 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;
}
public void ReciveData()
diff --git a/CTZLauncher/MainWindow.xaml b/CTZLauncher/MainWindow.xaml
index e499b27..ba49efb 100644
--- a/CTZLauncher/MainWindow.xaml
+++ b/CTZLauncher/MainWindow.xaml
@@ -66,7 +66,7 @@
-
+
diff --git a/CTZLauncher/MainWindow.xaml.cs b/CTZLauncher/MainWindow.xaml.cs
index 7bcc6d5..ec2bc9f 100644
--- a/CTZLauncher/MainWindow.xaml.cs
+++ b/CTZLauncher/MainWindow.xaml.cs
@@ -160,7 +160,6 @@ namespace CTZLauncher
private void maxmem_TextChanged(object sender, TextChangedEventArgs e)
{
-
//屏蔽中文输入和非法字符粘贴输入
TextBox textBox = sender as TextBox;
TextChange[] change = new TextChange[e.Changes.Count];
@@ -177,5 +176,15 @@ namespace CTZLauncher
}
}
}
+
+ private void register_Click(object sender, RoutedEventArgs e)
+ {
+ if (username.Text.Length == 0 || password.Text.Length == 0)
+ {
+ MessageBox.Show("请输入账号密码!");
+ return;
+ }
+
+ }
}
}
diff --git a/KMCCC.Shared/Authentication/AuthenticationInfo.cs b/KMCCC.Shared/Authentication/AuthenticationInfo.cs
index 698ba42..b131dda 100644
--- a/KMCCC.Shared/Authentication/AuthenticationInfo.cs
+++ b/KMCCC.Shared/Authentication/AuthenticationInfo.cs
@@ -20,12 +20,12 @@
///
/// UUID不解释
///
- public Guid UUID { get; set; }
+ public Guid? UUID { get; set; }
///
/// Session不解释
///
- public Guid AccessToken { get; set; }
+ public Guid? AccessToken { get; set; }
///
/// 各种属性(比如Twitch的Session)
diff --git a/KMCCC.Shared/Authentication/OfflineAuthenticator.cs b/KMCCC.Shared/Authentication/OfflineAuthenticator.cs
index 3d124b2..d20cc92 100644
--- a/KMCCC.Shared/Authentication/OfflineAuthenticator.cs
+++ b/KMCCC.Shared/Authentication/OfflineAuthenticator.cs
@@ -1,70 +1,70 @@
-namespace KMCCC.Authentication
-{
- #region
-
- using System;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
-
- #endregion
-
- ///
- /// 离线验证器
- ///
- public class OfflineAuthenticator : IAuthenticator
- {
- ///
- /// 玩家的名字
- ///
- public readonly string DisplayName;
-
- ///
- /// 构造离线验证器
- ///
- /// 玩家的名字
- public OfflineAuthenticator(string displayName)
- {
- DisplayName = displayName;
- }
-
- ///
- /// 标注离线验证器
- ///
- public string Type
- {
- get { return "KMCCC.Offline"; }
- }
-
- public AuthenticationInfo Do()
- {
- if (String.IsNullOrWhiteSpace(DisplayName))
- {
- return new AuthenticationInfo
- {
- Error = "DisplayName不符合规范"
- };
- }
- if (DisplayName.Count(char.IsWhiteSpace) > 0)
- {
- return new AuthenticationInfo
- {
- Error = "DisplayName不符合规范"
- };
- }
- return new AuthenticationInfo
- {
- AccessToken = Guid.NewGuid(),
- DisplayName = DisplayName,
- UUID = Guid.NewGuid(),
- Properties = "{}",
- UserType = "Mojang"
- };
- }
-
- public Task DoAsync(CancellationToken token)
- {
- return Task.Factory.StartNew((Func)Do, token);
- }
- }
+namespace KMCCC.Authentication
+{
+ #region
+
+ using System;
+ using System.Linq;
+ using System.Threading;
+ using System.Threading.Tasks;
+
+ #endregion
+
+ ///
+ /// 离线验证器
+ ///
+ public class OfflineAuthenticator : IAuthenticator
+ {
+ ///
+ /// 玩家的名字
+ ///
+ public readonly string DisplayName;
+
+ ///
+ /// 构造离线验证器
+ ///
+ /// 玩家的名字
+ public OfflineAuthenticator(string displayName)
+ {
+ DisplayName = displayName;
+ }
+
+ ///
+ /// 标注离线验证器
+ ///
+ public string Type
+ {
+ get { return "KMCCC.Offline"; }
+ }
+
+ public AuthenticationInfo Do()
+ {
+ if (String.IsNullOrWhiteSpace(DisplayName))
+ {
+ return new AuthenticationInfo
+ {
+ Error = "DisplayName不符合规范"
+ };
+ }
+ if (DisplayName.Count(char.IsWhiteSpace) > 0)
+ {
+ return new AuthenticationInfo
+ {
+ Error = "DisplayName不符合规范"
+ };
+ }
+ return new AuthenticationInfo
+ {
+ AccessToken = null,
+ DisplayName = DisplayName,
+ UUID = null,
+ Properties = "{}",
+ UserType = "Mojang"
+ };
+ }
+
+ public Task DoAsync(CancellationToken token)
+ {
+ return Task.Factory.StartNew((Func)Do, token);
+ }
+ }
}
\ No newline at end of file
diff --git a/KMCCC.Shared/Launcher/LauncherCoreInternal.cs b/KMCCC.Shared/Launcher/LauncherCoreInternal.cs
index 2dbcce1..5187fa4 100644
--- a/KMCCC.Shared/Launcher/LauncherCoreInternal.cs
+++ b/KMCCC.Shared/Launcher/LauncherCoreInternal.cs
@@ -1,217 +1,217 @@
-namespace KMCCC.Launcher
-{
- #region
-
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Tools;
-
- #endregion
-
- partial class LauncherCore
- {
- internal object Locker = new object();
-
- private LaunchResult GenerateArguments(LaunchOptions options, ref MinecraftLaunchArguments args)
- {
- try
- {
- var authentication = options.Authenticator.Do();
- if (!string.IsNullOrWhiteSpace(authentication.Error))
- return new LaunchResult
- {
- Success = false,
- ErrorType = ErrorType.AuthenticationFailed,
- ErrorMessage = "验证错误: " + authentication.Error
- };
- args.CGCEnabled = true;
- args.MainClass = options.Version.MainClass;
- args.MaxMemory = options.MaxMemory;
- args.MinMemory = options.MinMemory;
- args.NativePath = GameRootPath + options.Version.Id + @"\\" + options.Version.Id + @"-natives";
- foreach (var native in options.Version.Natives)
- {
- var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options);
- if (exp == null)
- {
- continue;
- }
- return new LaunchResult
- {
- Success = false,
- ErrorType = ErrorType.UncompressingFailed,
- ErrorMessage = string.Format("解压错误: {0}:{1}:{2}", native.NS, native.Name, native.Version),
- Exception = exp
- };
- }
- args.Server = options.Server;
- args.Size = options.Size;
- args.Libraries = options.Version.Libraries.Select(this.GetLibPath).ToList();
- args.Libraries.Add(this.GetVersionJarPath(options.Version.JarId));
- args.MinecraftArguments = options.Version.MinecraftArguments;
-
- args.Tokens.Add("auth_access_token", authentication.AccessToken.GoString());
- args.Tokens.Add("auth_session", authentication.AccessToken.GoString());
- args.Tokens.Add("auth_player_name", authentication.DisplayName);
- args.Tokens.Add("version_name", options.Version.Id);
- args.Tokens.Add("game_directory", ".");
- args.Tokens.Add("game_assets", "assets");
- args.Tokens.Add("assets_root", "assets");
- args.Tokens.Add("assets_index_name", options.Version.Assets);
- args.Tokens.Add("auth_uuid", authentication.UUID.GoString());
- args.Tokens.Add("user_properties", authentication.Properties);
- args.Tokens.Add("user_type", authentication.UserType);
-
- args.AdvencedArguments = new List { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" };
-
- args.Authentication = authentication;
- args.Version = options.Version;
- if (options.Mode != null)
- {
- options.Mode.Operate(this, args);
- }
- return null;
- }
- catch (Exception exp)
- {
- Console.WriteLine(exp.Message);
- Console.WriteLine(exp.Source);
- Console.WriteLine(exp.StackTrace);
- return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "在生成参数时发生了意外的错误", Exception = exp };
- }
- }
-
- internal LaunchResult LaunchInternal(LaunchOptions options, params Action[] argumentsOperators)
- {
- lock (Locker)
- {
- if (!File.Exists(JavaPath))
- {
- return new LaunchResult { Success = false, ErrorType = ErrorType.NoJAVA, ErrorMessage = "指定的JAVA位置不存在" };
- }
- CurrentCode = Random.Next();
- var args = new MinecraftLaunchArguments();
- var result = GenerateArguments(options, ref args);
- if (result != null)
- {
- return result;
- }
- if (argumentsOperators == null) return LaunchGame(args);
- foreach (var opt in argumentsOperators)
- {
- try
- {
- if (opt != null)
- {
- opt(args);
- }
- }
- catch (Exception exp)
- {
- return new LaunchResult { Success = false, ErrorType = ErrorType.OperatorException, ErrorMessage = "指定的操作器引发了异常", Exception = exp };
- }
- }
- return LaunchGame(args);
- }
- }
-
- private LaunchResult LaunchGame(MinecraftLaunchArguments args)
- {
- Console.WriteLine(args.ToArguments());
- try
- {
- var handle = new LaunchHandle(args.Authentication)
- {
- Code = CurrentCode,
- Core = this,
- Arguments = args,
- Process = Process.Start(new ProcessStartInfo(JavaPath)
- {
- Arguments = args.ToArguments(),
- UseShellExecute = false,
- WorkingDirectory = GameRootPath,
- RedirectStandardError = true,
- RedirectStandardOutput = true
- })
- };
- handle.Work();
- Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
- return new LaunchResult { Success = true, Handle = handle };
- }
- catch (Exception exp)
- {
- return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "启动时出现了异常", Exception = exp };
- }
- }
-
- #region 复制文件夹
-
- public void CopyVersionDirectory(string directoryName, string versionId)
- {
- CopyDirectory(string.Format(@"{0}\versions\{2}\{1}", GameRootPath, directoryName, versionId),
- string.Format(@"{0}\{1}", GameRootPath, directoryName));
- }
-
- public void CopyDirectory(string source, string target)
- {
- var code = CurrentCode;
- if (!Directory.Exists(source)) return;
- if (Directory.Exists(target))
- {
- Directory.Delete(target, true);
- }
- UsefulTools.Dircopy(source, target);
- Action handler = null;
- handler = (handle, c) =>
- {
- if (handle.Code == code)
- {
- Directory.Delete(source, true);
- UsefulTools.Dircopy(target, source);
- Directory.Delete(target, true);
- }
- GameExit -= handler;
- };
- GameExit += handler;
- }
-
- public void CopyVersionDirectories(string ver)
- {
- var root = string.Format(@"{0}\versions\{1}\moddir", GameRootPath, ver);
- if (!Directory.Exists(root))
- {
- return;
- }
- foreach (var dir in new DirectoryInfo(root).EnumerateDirectories())
- {
- CopyDirectory(dir.FullName, string.Format(@"{0}\{1}", GameRootPath, dir.Name));
- }
- }
-
- #endregion
-
- #region 事件
-
- internal void Log(LaunchHandle handle, string line)
- {
- if (GameLog != null)
- {
- GameLog(handle, line);
- }
- }
-
- internal void Exit(LaunchHandle handle, int code)
- {
- if (GameExit != null)
- {
- GameExit(handle, code);
- }
- }
-
- #endregion
- }
+namespace KMCCC.Launcher
+{
+ #region
+
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Linq;
+ using System.Threading.Tasks;
+ using Tools;
+
+ #endregion
+
+ partial class LauncherCore
+ {
+ internal object Locker = new object();
+
+ private LaunchResult GenerateArguments(LaunchOptions options, ref MinecraftLaunchArguments args)
+ {
+ try
+ {
+ var authentication = options.Authenticator.Do();
+ if (!string.IsNullOrWhiteSpace(authentication.Error))
+ return new LaunchResult
+ {
+ Success = false,
+ ErrorType = ErrorType.AuthenticationFailed,
+ ErrorMessage = "验证错误: " + authentication.Error
+ };
+ args.CGCEnabled = true;
+ args.MainClass = options.Version.MainClass;
+ args.MaxMemory = options.MaxMemory;
+ args.MinMemory = options.MinMemory;
+ args.NativePath = GameRootPath + options.Version.Id + @"\\" + options.Version.Id + @"-natives";
+ foreach (var native in options.Version.Natives)
+ {
+ var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options);
+ if (exp == null)
+ {
+ continue;
+ }
+ return new LaunchResult
+ {
+ Success = false,
+ ErrorType = ErrorType.UncompressingFailed,
+ ErrorMessage = string.Format("解压错误: {0}:{1}:{2}", native.NS, native.Name, native.Version),
+ Exception = exp
+ };
+ }
+ args.Server = options.Server;
+ args.Size = options.Size;
+ args.Libraries = options.Version.Libraries.Select(this.GetLibPath).ToList();
+ args.Libraries.Add(this.GetVersionJarPath(options.Version.JarId));
+ args.MinecraftArguments = options.Version.MinecraftArguments;
+
+ args.Tokens.Add("auth_access_token", authentication.AccessToken.GoString());
+ args.Tokens.Add("auth_session", authentication.AccessToken.GoString());
+ args.Tokens.Add("auth_player_name", authentication.DisplayName);
+ args.Tokens.Add("version_name", options.Version.Id);
+ args.Tokens.Add("game_directory", ".");
+ args.Tokens.Add("game_assets", "assets");
+ args.Tokens.Add("assets_root", "assets");
+ args.Tokens.Add("assets_index_name", options.Version.Assets);
+ args.Tokens.Add("auth_uuid", authentication.UUID.GoString());
+ args.Tokens.Add("user_properties", authentication.Properties);
+ args.Tokens.Add("user_type", authentication.UserType);
+
+ args.AdvencedArguments = new List { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" };
+
+ args.Authentication = authentication;
+ args.Version = options.Version;
+ if (options.Mode != null)
+ {
+ options.Mode.Operate(this, args);
+ }
+ return null;
+ }
+ catch (Exception exp)
+ {
+ Console.WriteLine(exp.Message);
+ Console.WriteLine(exp.Source);
+ Console.WriteLine(exp.StackTrace);
+ return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "在生成参数时发生了意外的错误", Exception = exp };
+ }
+ }
+
+ internal LaunchResult LaunchInternal(LaunchOptions options, params Action[] argumentsOperators)
+ {
+ lock (Locker)
+ {
+ if (!File.Exists(JavaPath))
+ {
+ return new LaunchResult { Success = false, ErrorType = ErrorType.NoJAVA, ErrorMessage = "指定的JAVA位置不存在" };
+ }
+ CurrentCode = Random.Next();
+ var args = new MinecraftLaunchArguments();
+ var result = GenerateArguments(options, ref args);
+ if (result != null)
+ {
+ return result;
+ }
+ if (argumentsOperators == null) return LaunchGame(args);
+ foreach (var opt in argumentsOperators)
+ {
+ try
+ {
+ if (opt != null)
+ {
+ opt(args);
+ }
+ }
+ catch (Exception exp)
+ {
+ return new LaunchResult { Success = false, ErrorType = ErrorType.OperatorException, ErrorMessage = "指定的操作器引发了异常", Exception = exp };
+ }
+ }
+ return LaunchGame(args);
+ }
+ }
+
+ private LaunchResult LaunchGame(MinecraftLaunchArguments args)
+ {
+ Console.WriteLine(args.ToArguments());
+ try
+ {
+ var handle = new LaunchHandle(args.Authentication)
+ {
+ Code = CurrentCode,
+ Core = this,
+ Arguments = args,
+ Process = Process.Start(new ProcessStartInfo(JavaPath)
+ {
+ Arguments = args.ToArguments(),
+ UseShellExecute = false,
+ WorkingDirectory = GameRootPath,
+ RedirectStandardError = true,
+ RedirectStandardOutput = true
+ })
+ };
+ handle.Work();
+ Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
+ return new LaunchResult { Success = true, Handle = handle };
+ }
+ catch (Exception exp)
+ {
+ return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "启动时出现了异常", Exception = exp };
+ }
+ }
+
+ #region 复制文件夹
+
+ public void CopyVersionDirectory(string directoryName, string versionId)
+ {
+ CopyDirectory(string.Format(@"{0}\versions\{2}\{1}", GameRootPath, directoryName, versionId),
+ string.Format(@"{0}\{1}", GameRootPath, directoryName));
+ }
+
+ public void CopyDirectory(string source, string target)
+ {
+ var code = CurrentCode;
+ if (!Directory.Exists(source)) return;
+ if (Directory.Exists(target))
+ {
+ Directory.Delete(target, true);
+ }
+ UsefulTools.Dircopy(source, target);
+ Action handler = null;
+ handler = (handle, c) =>
+ {
+ if (handle.Code == code)
+ {
+ Directory.Delete(source, true);
+ UsefulTools.Dircopy(target, source);
+ Directory.Delete(target, true);
+ }
+ GameExit -= handler;
+ };
+ GameExit += handler;
+ }
+
+ public void CopyVersionDirectories(string ver)
+ {
+ var root = string.Format(@"{0}\versions\{1}\moddir", GameRootPath, ver);
+ if (!Directory.Exists(root))
+ {
+ return;
+ }
+ foreach (var dir in new DirectoryInfo(root).EnumerateDirectories())
+ {
+ CopyDirectory(dir.FullName, string.Format(@"{0}\{1}", GameRootPath, dir.Name));
+ }
+ }
+
+ #endregion
+
+ #region 事件
+
+ internal void Log(LaunchHandle handle, string line)
+ {
+ if (GameLog != null)
+ {
+ GameLog(handle, line);
+ }
+ }
+
+ internal void Exit(LaunchHandle handle, int code)
+ {
+ if (GameExit != null)
+ {
+ GameExit(handle, code);
+ }
+ }
+
+ #endregion
+ }
}
\ No newline at end of file
diff --git a/KMCCC.Shared/Tools/UsefulTools.cs b/KMCCC.Shared/Tools/UsefulTools.cs
index ae17646..ab7b575 100644
--- a/KMCCC.Shared/Tools/UsefulTools.cs
+++ b/KMCCC.Shared/Tools/UsefulTools.cs
@@ -19,8 +19,10 @@
return dic.Aggregate(source, (current, pair) => current.Replace("${" + pair.Key + "}", pair.Value));
}
- public static string GoString(this Guid guid)
+ public static string GoString(this Guid? guid)
{
+ if (guid == null)
+ return "{}";
return guid.ToString().Replace("-", "");
}