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

Commit

Permalink
v0.3.5 - Lots more channel fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholastay committed Jun 22, 2019
1 parent f6b99b8 commit ab30051
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 33 deletions.
65 changes: 58 additions & 7 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,50 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
toggleUi(true);
}

private async void startButton_Click(object sender, RoutedEventArgs e)
private bool noAuth = false;
private void startButton_Click(object sender, RoutedEventArgs e)
{
startGame();
}

private async void startGame()
{
toggleUi(false);

try
{
await Maple.Start((bool)tespiaCheckBox.IsChecked);
}
catch (VerdantException.NoAuthException)
{
if (noAuth)
{
MessageBox.Show("We failed to auth. Login data will be deleted, and Verdant will be closed. Please try logging in completely again.");
File.Delete(PathToCookies);
Close();
return;
}

// last ditch
noAuth = true;
await mapleIdSelection(true);
startButton.IsEnabled = false;

if (Maple.MapleIds.Count == 1)
{
mapleIdBox.Text = Maple.MapleIds[0];
await switchMapleId();
Close();
}
else
{
MessageBox.Show("There was an error starting the game, but... we have one last trick. Please select the Maple ID in the dropdown box below that you would like to login to, and we can try again!", "Verdant");
mapleIdBox.Focus();
mapleIdBox.IsDropDownOpen = true;
}

return;
}
catch (Exception ex)
{
MessageBox.Show("Error starting game...\n\n" + ex.ToString());
Expand All @@ -171,28 +207,36 @@ private async void startButton_Click(object sender, RoutedEventArgs e)
Close();
}

private async void changeMapleIdButton_Click(object sender, RoutedEventArgs e)
private void changeMapleIdButton_Click(object sender, RoutedEventArgs e)
{
mapleIdSelection();
}

private async Task mapleIdSelection(bool inStart = false)
{
toggleUi(false);
await Maple.GetMapleIds();
otherIdsLoaded = true;

if (Maple.MapleIds.Count < 2)
if (!inStart && Maple.MapleIds.Count < 2)
{
MessageBox.Show("You only have 1 maple id...");
return;
}

Maple.MapleIds.ForEach(x => mapleIdBox.Items.Add(x));
mapleIdBox.Text = Maple.MainCharName;
mapleIdBox.IsEnabled = true;
toggleUi(true);
}

private async void mapleIdBox_DropDownClosed(object sender, EventArgs e)
private void mapleIdBox_DropDownClosed(object sender, EventArgs e)
{
switchMapleId();
}

private async Task switchMapleId()
{
// in case
if (mapleIdBox.Text == Maple.MainCharName)
if (String.IsNullOrEmpty(mapleIdBox.Text) || !Maple.MapleIds.Contains(mapleIdBox.Text))
return;

charImage.Source = null;
Expand All @@ -212,6 +256,13 @@ private async void mapleIdBox_DropDownClosed(object sender, EventArgs e)
if (Maple.CharacterImageUrl != null)
charImage.Source = Tools.UrlToXamlImage(Maple.CharacterImageUrl);
tespiaCheckBox.IsChecked = false;

if (noAuth)
{
startGame();
return;
}

toggleUi(true);
}

Expand Down
72 changes: 47 additions & 25 deletions MapleGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ namespace Verdant
{
public class MapleGame
{
// Note to self: We use the /CashShop URL because if there is an event page on the home page, we want a reliable page to get
// Otherwise, it may redirect to an update page

private const string MAPLE_HOME = "https://maplestory.nexon.game.naver.com/News/CashShop";
private const string MAPLE_HOME = "https://maplestory.nexon.game.naver.com/Home/Main";
private const string MAPLE_TESPIA_HOME = "https://maplestory.nexon.game.naver.com/Testworld/Main";

public NaverAccount Account;
Expand Down Expand Up @@ -71,7 +68,20 @@ public async Task Start(bool tespia = false, bool firstTry = true)
// last min update sesh
Debug.WriteLine("updating session");
var sesRes = await webClient.GetAsync("https://sso.nexon.game.naver.com/Ajax/Default.aspx?_vb=UpdateSession");
Debug.WriteLine(await sesRes.Content.ReadAsStringAsync());
string sesData = await sesRes.Content.ReadAsStringAsync();
Debug.WriteLine(sesData);
if (!sesData.Contains("name=\"ErrorCode\" value=\"0\""))
{
if (!firstTry)
throw new Exception("session error");

// session update failed, implies loginProc to refresh NPP
Debug.WriteLine("updateSess failed, should loginProc");
await loginProc();
// hard retry
await Start(tespia, false);
return;
}

Debug.WriteLine("msgenc update");
// msgenc
Expand All @@ -88,25 +98,11 @@ public async Task Start(bool tespia = false, bool firstTry = true)
var res = await webClient.SendAsync(req);
string data = await res.Content.ReadAsStringAsync();
Debug.WriteLine(data);
if (data.Contains("\"Code\":5"))
if (!data.Contains("\"Code\":" + (tespia ? "0" : "1"))) // for some reason swkt code 0 for success
{
//"session expired try logging in again"
Debug.WriteLine("relogging expired session and crossing fingers");
await Account.WebClient.GetAsync("http://nxgamechanneling.nexon.game.naver.com/login/loginproc.aspx?gamecode=589824");
}
else if (!data.Contains("\"Code\":" + (tespia ? "0" : "1"))) // for some reason swkt code 0 for success
{
if (firstTry && Account.Preloaded)
{
Debug.WriteLine("preload, so trying loginproc to update sess");
await Account.WebClient.GetAsync("http://nxgamechanneling.nexon.game.naver.com/login/logout.aspx?gamecode=589824");
await Account.WebClient.GetAsync("http://nxgamechanneling.nexon.game.naver.com/login/loginproc.aspx?gamecode=589824");
Account.SaveCookies();
// hard retry
await Start(tespia, false);
return;
}
throw new Exception("could not auth for game...");
// the hell hole
// there is one last fix - reselect maple id.
throw new VerdantException.NoAuthException();
}

string msgenc = Account.Cookies.GetCookies(new Uri("http://maplestory.nexon.game.naver.com"))[tespia ? "MSGENCT" : "MSGENC"].Value;
Expand All @@ -123,9 +119,35 @@ private async Task channeling()
await webClient.GetAsync(MAPLE_HOME); // the home page may redirect too
}

private Regex charRepRegex = new Regex("<span class=\"sub_user_name\">(.+?)</span>");
private async Task loginProc()
{
await webClient.GetAsync("http://nxgamechanneling.nexon.game.naver.com/login/loginproc.aspx?gamecode=589824");

// get the home page & update the launch WID
HttpRequestMessage req = new HttpRequestMessage() { RequestUri = new Uri(MAPLE_HOME) };
req.Headers.Add("Referer", "http://nxgamechanneling.nexon.game.naver.com/login/loginproc.aspx?gamecode=589824");

HttpResponseMessage res = await webClient.SendAsync(req);
res.EnsureSuccessStatusCode();
string data = await res.Content.ReadAsStringAsync();

Match wid = launchWIDRegex.Match(data);
if (!wid.Success)
{
Debug.WriteLine("couldnt update wid!! probably will be a web verification ingame fail!");
}
else
{
launchWID = wid.Groups[1].Value;
Debug.WriteLine("wid update: " + launchWID);
}

Account.SaveCookies();
}

private Regex charRepRegex = new Regex("<dd class=\"login_id\">.*?>(.+?).</");
private Regex launchWIDRegex = new Regex("\\.LaunchGame\\('(\\d+)'\\)");
private Regex charImgRegex = new Regex("<span class=\"sub_login_char\"><img src=\"(.+?)\" onerror=");
private Regex charImgRegex = new Regex("<img src=\"(.+?)\" alt=\"\uB300\uD45C");
private async Task<bool> getCurrentMaple()
{
HttpResponseMessage res = await webClient.GetAsync(MAPLE_HOME);
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.4.0")]
[assembly: AssemblyVersion("0.3.5.0")]
//[assembly: AssemblyFileVersion("0.3.1.0")]
1 change: 1 addition & 0 deletions VerdantException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class VerdantException
{
public class GameNotFoundException : Exception { }
public class ChannelingRequiredException : Exception { }
public class NoAuthException : Exception { }
}
}

0 comments on commit ab30051

Please sign in to comment.