Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from southernwind/master
Browse files Browse the repository at this point in the history
ワンタイムパスワードの対応と、ログイン方法変更への対応
  • Loading branch information
kagasu committed Jan 24, 2016
2 parents 2cd841b + 118787c commit bc7c1cf
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 13 deletions.
8 changes: 8 additions & 0 deletions ARADAutoLauncher/ARADAutoLauncher.csproj
Expand Up @@ -41,6 +41,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand All @@ -61,6 +62,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="OneTimePassWindow.xaml.cs">
<DependentUpon>OneTimePassWindow.xaml</DependentUpon>
</Compile>
<Compile Include="WebClientEx.cs">
<SubType>Component</SubType>
</Compile>
Expand All @@ -84,6 +88,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="OneTimePassWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="PlaceHolder.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
54 changes: 45 additions & 9 deletions ARADAutoLauncher/LoadingWindow.xaml.cs
Expand Up @@ -9,8 +9,13 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Threading;
using ARADAutoLauncher;
using MessageBox = System.Windows.MessageBox;

namespace ARADLoginTool
{
Expand All @@ -29,9 +34,11 @@ private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
this.DragMove();
}

private void Window_Initialized(object sender, EventArgs e)
private void Window_Initialized(object sender, EventArgs e)
{
new Thread(() =>
OneTimePassWindow otpw = null;
DispatcherFrame dispacherFrame = null;
var thread = new Thread(() =>
{
try
{
Expand All @@ -43,17 +50,43 @@ private void Window_Initialized(object sender, EventArgs e)
wc.Proxy = new WebProxy(string.Format("http://{0}/", dataJson["proxy"]));
}
var str = wc.DownloadString("http://arad.nexon.co.jp/");
wc.Headers.Add("Referer","http://arad.nexon.co.jp/");
var str = wc.DownloadString("http://www.nexon.co.jp/login/");
var unique_id = new Regex("class=\"nexonid\" name=\"(.*?)\"").Matches(str)[0].Groups[1].Value;
var unique_password = new Regex("class=\"password\" name=\"(.*?)\"").Matches(str)[0].Groups[1].Value;
var login_key = new Regex("name=\"login_key\" value=\"(.*?)\"").Matches(str)[0].Groups[1].Value;
var unique_id = new Regex( "return document.getElementById\\('(.*?)'\\).value;" ).Matches(str)[0].Groups[1].Value;
var unique_password = Regex.Replace(unique_id,"^i","p");
var entm = new Regex( "name=(\"|')entm(\"|') value=(\"|')(.*?)(\"|')" ).Matches(str)[0].Groups[4].Value;
var data = new NameValueCollection();
data.Add( "entm", entm );
data.Add(unique_id, dataJson["id"]);
data.Add(unique_password, dataJson["password"]);
data.Add("login_key", login_key);
wc.UploadValues("https://arad.nexon.co.jp/login/loginprocess.aspx", data);
data.Add( "onetimepass", "" );
data.Add("HiddenUrl","http://arad.nexon.co.jp/");
data.Add( "otp", "" );
wc.Headers.Add( "Referer", "http://www.nexon.co.jp/login/" );
str = Encoding.UTF8.GetString( wc.UploadValues( "https://www.nexon.co.jp/login/login_process1.aspx?iframe=true", data));
// When onetimepass require
if( str.Contains( "location.replace(\"https://www.nexon.co.jp/login/otp/index.aspx" ) )
{
str = wc.DownloadString( new Regex( "location\\.replace\\(\"(https://www.nexon.co.jp/login/otp/index\\.aspx.*?)\"\\)" ).Matches(str)[0].Groups[1].Value );
dispacherFrame = new DispatcherFrame( true );
otpw = new OneTimePassWindow();
otpw.Closed += ( o, args ) =>
{
dispacherFrame.Continue = false;
};
otpw.ShowDialog();
Dispatcher.PushFrame( dispacherFrame );
var onetimepass = otpw.otp;
data = new NameValueCollection();
data.Add( "otp" , onetimepass);
wc.UploadValues( new Regex( "action=\"(.*?)\" id=\"otploginform\"" ).Matches( str )[0].Groups[1].Value, data );
}
str = wc.DownloadString("http://arad.nexon.co.jp/launcher/game/GameStart.aspx");
Expand Down Expand Up @@ -101,7 +134,10 @@ private void Window_Initialized(object sender, EventArgs e)
MessageBox.Show(ex.Message);
Environment.Exit(0);
}
}).Start();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

}

private void ButtonExit_Click(object sender, RoutedEventArgs e)
Expand Down
21 changes: 21 additions & 0 deletions ARADAutoLauncher/OneTimePassWindow.xaml
@@ -0,0 +1,21 @@
<Window x:Class="ARADAutoLauncher.OneTimePassWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="392"
Height="230"
AllowsTransparency="True"
WindowStyle="None"
Background="Transparent" MouseLeftButtonDown="Window_MouseLeftButtonDown" >
<Border BorderBrush="#000" Background="white" BorderThickness="1" Margin="10,10,10,10">
<Grid>
<Button Content="×" Background="Transparent" HorizontalAlignment="Right" VerticalAlignment="Top" Click="ButtonExit_Click" BorderBrush="Transparent" Grid.Row="1" FontSize="16" Height="30" Width="30" Foreground="#000" IsTabStop="False"/>
<Grid Margin="20,35,20,27">
<Label x:Name="label" Content="ワンタイムパスワードが要求されました。" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<TextBlock Margin="19,41,0,0" TextWrapping="Wrap" Text="OTP *" Foreground="#000" FontSize="20" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<TextBox x:Name="textBox_Otp" Width="162" Height="29" TextWrapping="NoWrap" FontSize="20" Margin="140,41,28,76" MaxLength="6" KeyDown="textBox_Otp_KeyDown"/>
<Button Content="OK" Margin="24,83,0,0" Width="278" Background="{x:Null}" BorderBrush="#000" Foreground="#000" Click="Button_Click" FontSize="20" HorizontalAlignment="Left" VerticalAlignment="Top" Height="53"/>
</Grid>
</Grid>
</Border>
</Window>
43 changes: 43 additions & 0 deletions ARADAutoLauncher/OneTimePassWindow.xaml.cs
@@ -0,0 +1,43 @@
using System;
using System.Windows;
using System.Windows.Input;

namespace ARADAutoLauncher {
/// <summary>
/// OneTimePassWindow.xaml の相互作用ロジック
/// </summary>
public partial class OneTimePassWindow :Window
{

public string otp;
public OneTimePassWindow()
{
InitializeComponent();
}

private void Button_Click( object sender, RoutedEventArgs e )
{
otp = textBox_Otp.Text;
Close();
}
private void ButtonExit_Click( object sender, RoutedEventArgs e )
{
Close();
}

private void Window_MouseLeftButtonDown( object sender, MouseButtonEventArgs e )
{
this.DragMove();
}

private void textBox_Otp_KeyDown( object sender, KeyEventArgs e )
{
if( e.Key == Key.Return )
{
otp = textBox_Otp.Text;
Close();
}
}

}
}
6 changes: 2 additions & 4 deletions ARADAutoLauncher/WebClientEx.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ARADLoginTool
Expand All @@ -11,10 +12,6 @@ class WebClientEx : WebClient
{
private CookieContainer cookieContainer = new CookieContainer();

public WebClientEx()
{
this.Headers.Add("User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)");
}

public CookieContainer CookieContainer
{
Expand All @@ -37,6 +34,7 @@ protected override WebRequest GetWebRequest(Uri uri)
{
var httpWebRequest = (HttpWebRequest)webRequest;
httpWebRequest.CookieContainer = this.cookieContainer;
httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)";
}

return webRequest;
Expand Down

0 comments on commit bc7c1cf

Please sign in to comment.