소스 검색

增加输入用户名密码的textbox

tanghai 14 년 전
부모
커밋
8b1ffa32d9
4개의 변경된 파일99개의 추가작업 그리고 28개의 파일을 삭제
  1. 16 15
      CSharp/Editor/Logical/LoginRealm.cs
  2. 28 1
      CSharp/Editor/Model/Main.cs
  3. 14 5
      CSharp/Editor/View/MainView.xaml
  4. 41 7
      CSharp/Editor/ViewModel/MainViewModel.cs

+ 16 - 15
CSharp/Editor/Logical/LoginRealm.cs

@@ -7,22 +7,22 @@ using System.Text;
 
 namespace Egametang
 {
-	enum RealmOpcode
+	enum RealmLoginState: byte
 	{
-		REALM_AUTH_LOGON_CHALLENGE = 0x0000,
-		REALM_AUTH_LOGON_PROOF = 0x0001,
-		AUTH_RECONNECT_CHALLENGE = 0x02,
-		AUTH_RECONNECT_PROOF = 0x03,
-		AUTH_LOGON_PERMIT = 0x04,
-		REALM_LIST = 0x10,
-		SURVEY = 48,
+		RealmAuthLoginChallenge = 0,
+		RealmAuthLonginProof = 1,
+		AuthReconnectChallenge = 2,
+		AuthReconnectProof = 3,
+		AuthLoginPermit = 4,
+		RealmList = 10,
+		Surver = 48,
 	}
 
-	class LoginRealm
+	class RealmLogin
 	{
 		private MainViewModel mainViewModel = null;
 
-		public LoginRealm(MainViewModel mainViewModel)
+		public RealmLogin(MainViewModel mainViewModel)
 		{
 			this.mainViewModel = mainViewModel;
 		}
@@ -42,29 +42,30 @@ namespace Egametang
 
 		public async Task LoginPermit(NetworkStream stream)
 		{
-			byte[] opcodeBuffer = System.BitConverter.GetBytes((Int32)RealmOpcode.AUTH_LOGON_PERMIT);
+			byte[] opcodeBuffer = new byte[1] { (byte)RealmLoginState.AuthLoginPermit };
 			await stream.WriteAsync(opcodeBuffer, 0, opcodeBuffer.Length);
 
-			string username = "egametang@163.com";
+			string username = mainViewModel.Username;
 			username += new string(' ', 128 - username.Length);
 			byte[] usernameBuffer = System.Text.Encoding.Default.GetBytes(username);
 			await stream.WriteAsync(usernameBuffer, 0, usernameBuffer.Length);
 
 			MD5 md5 = new MD5CryptoServiceProvider();
-			byte[] password = System.Text.Encoding.Default.GetBytes("163bio1");
+			byte[] password = System.Text.Encoding.Default.GetBytes(mainViewModel.Password);
 			byte[] passMD5Buffer = md5.ComputeHash(password);
 
 			string passMD5 = BitConverter.ToString(passMD5Buffer);
 			passMD5 = passMD5.Replace("-", "");
 			passMD5 = passMD5.ToLower();
-			App.Logger.Debug("passMD5: " + passMD5);
+			App.Logger.Debug(string.Format("username: {0}, passMD5: {1}", username, passMD5));
 
 			passMD5Buffer = System.Text.Encoding.Default.GetBytes(passMD5);
+			App.Logger.Debug("passMD5Buffer len: " + passMD5Buffer.Length.ToString());
 			await stream.WriteAsync(passMD5Buffer, 0, passMD5Buffer.Length);
 
 			await DispatcherHelper.UIDispatcher.InvokeAsync(new Action(() =>
 			{
-				mainViewModel.LoginResult = "Login Permit!";
+				mainViewModel.LoginInfo += "Login Permit!" + Environment.NewLine;
 			}));
 		}
 	}

+ 28 - 1
CSharp/Editor/Model/Main.cs

@@ -8,11 +8,14 @@ namespace Egametang
 	public class Main
 	{
 		private string loginResult = "";
+		private string username = "";
+		private string password = "";
 
 		public Main()
 		{
 		}
-		public string LoginResult
+
+		public string LoginInfo
 		{
 			get
 			{
@@ -23,5 +26,29 @@ namespace Egametang
 				loginResult = value;
 			}
 		}
+
+		public string Username
+		{
+			get
+			{
+				return username;
+			}
+			set
+			{
+				username = value;
+			}
+		}
+
+		public string Password
+		{
+			get
+			{
+				return password;
+			}
+			set
+			{
+				password = value;
+			}
+		}
 	}
 }

+ 14 - 5
CSharp/Editor/View/MainView.xaml

@@ -1,12 +1,21 @@
-<UserControl x:Class="Egametang.MainView"
+<UserControl
 		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+		xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4" x:Class="Egametang.MainView" 
 		mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="800"
 		DataContext="{Binding MainViewModel, Source={StaticResource Locator}}" >
-	<StackPanel>
-		<Label HorizontalAlignment="Center" VerticalAlignment="Center" Content="{Binding LoginResult}" />
-		<Button Content="登录" HorizontalAlignment="Center" VerticalAlignment="Center" Command="{Binding LoginCmd}" />
-	</StackPanel>
+	<Grid>		
+		<StackPanel Grid.Column="0">
+			<StackPanel Orientation="Horizontal">
+				<Label Content="用户名: "/>
+				<TextBox Width="150" x:Name="tBUsername" Text="{Binding Username}" />
+				<Label Content="密码: "/>
+				<TextBox Width="150" x:Name="tBPassword" Text="{Binding Password}" />
+				<Button Content="登录" HorizontalAlignment="Center" VerticalAlignment="Center" Command="{Binding LoginCmd}" />
+			</StackPanel>
+			<TextBox x:Name="tBInfo" Margin="10" Padding="1" Height="200" VerticalScrollBarVisibility="Visible" />
+		</StackPanel>
+	</Grid>
 </UserControl>

+ 41 - 7
CSharp/Editor/ViewModel/MainViewModel.cs

@@ -7,28 +7,62 @@ namespace Egametang
 	{
 		private Main main = new Main();
 		private RelayCommand loginCmd = null;
-		private LoginRealm loginRealm = null;
+		private RealmLogin loginRealm = null;
 
 		public MainViewModel()
 		{
 			loginCmd = new RelayCommand(Login);
-			loginRealm = new LoginRealm(this);
+			loginRealm = new RealmLogin(this);
 		}
 
-		public string LoginResult
+		public string LoginInfo
 		{
 			get
 			{
-				return main.LoginResult;
+				return main.LoginInfo;
 			}
 			set
 			{
-				if (main.LoginResult == value)
+				if (main.LoginInfo == value)
 				{
 					return;
 				}
-				main.LoginResult = value;
-				RaisePropertyChanged("LoginResult");
+				main.LoginInfo = value;
+				RaisePropertyChanged("LoginInfo");
+			}
+		}
+
+		public string Username
+		{
+			get
+			{
+				return main.Username;
+			}
+			set
+			{
+				if (main.Username == value)
+				{
+					return;
+				}
+				main.Username = value;
+				RaisePropertyChanged("Username");
+			}
+		}
+
+		public string Password
+		{
+			get
+			{
+				return main.Password;
+			}
+			set
+			{
+				if (main.Password == value)
+				{
+					return;
+				}
+				main.Password = value;
+				RaisePropertyChanged("Password");
 			}
 		}