Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Removed old setup
-> Rewrite login code
-> Update logger template
-> Added ellipse to alert
-> Install tools now is using the logger
-> App will always start as UAC
-> Disable update checks till we have a setup
  • Loading branch information
NaysKutzu committed Oct 6, 2023
1 parent c017291 commit d78ba06
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 1,047 deletions.
95 changes: 52 additions & 43 deletions Forms/FrmAlert.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 27 additions & 27 deletions Forms/FrmAlert.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema

Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple

There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -120,8 +120,8 @@
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>265, 17</value>
</metadata>
<metadata name="bunifuElipse1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>352, 17</value>
<metadata name="guna2Elipse1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>353, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Expand Down
19 changes: 11 additions & 8 deletions Forms/FrmInstallTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public static void Delete()
}
catch (Exception ex)
{
Console.WriteLine("Error during deleting: " + ex.Message);

Program.logger.Log(Managers.LogType.Info, "[Forms.FrmInstallTools.cs]: \n" + ex.Message);
}
}

Expand All @@ -57,16 +56,20 @@ public static void Unzip()
if (File.Exists(zipFilePath))
{
ZipFile.ExtractToDirectory(zipFilePath, extractPath);
Console.WriteLine("Addons have been extracted successfully!");
Program.logger.Log(Managers.LogType.Info, "[Forms.FrmInstallTools.cs]: \nAddons have been extracted successfully!");
}
else
{
Console.WriteLine("Client.zip not found for extraction.");
Program.logger.Log(Managers.LogType.Error, "[Forms.FrmInstallTools.cs]: \nClient.zip not found for extraction.");
MessageBox.Show("Client.zip not found for extraction. \nTry again later","Addons",MessageBoxButtons.OK,MessageBoxIcon.Error);
Application.Exit();
}
}
catch (Exception ex)
{
Console.WriteLine("Error during unzip: " + ex.Message);
Program.logger.Log(Managers.LogType.Info, "[Forms.FrmInstallTools.cs]: \n"+ex.Message);
MessageBox.Show("Client.zip faild extract. \nTry again later", "Addons", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}

Expand All @@ -84,14 +87,14 @@ public static async Task Download()
using (FileStream fileStream = new FileStream("Client.zip", FileMode.Create))
{
await contentStream.CopyToAsync(fileStream);
Console.WriteLine("Addons have been downloaded successfully!");
Program.logger.Log(Managers.LogType.Info, "[Forms.FrmInstallTools.cs]: \nAddons have been downloaded successfully!");
}
}
}
else
{
Console.WriteLine("Failed to download Addons: {0}", response.StatusCode);
MessageBox.Show("Failed to download update \nTry again later");
Program.logger.Log(Managers.LogType.Info, "[Forms.FrmInstallTools.cs]: \nFailed to download Addons: " + response.StatusCode);
MessageBox.Show("Failed to download addons \nTry again later");
Application.Exit();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Forms/FrmLoading.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Forms/FrmLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ @echo off
}
private void FrmLoading_Load(object sender, EventArgs e)
{
CheckForUpdate();
//CheckForUpdate();
}
public static async Task Download()
{
Expand Down
87 changes: 73 additions & 14 deletions Forms/FrmLogin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Pterodactyl.Handlers;
using Newtonsoft.Json;
using Pterodactyl.Handlers;
using System.Net.Http.Headers;

namespace Pterodactyl.Forms
{
Expand All @@ -20,29 +22,86 @@ private async void btnaddsession_Click(object sender, EventArgs e)
else
{
try
{
await Pterodactyl.User.Info.Get(txtpanelurl.Text, txtpanelapikey.Text, txtpanelpwd.Text);
if (Pterodactyl.User.Info.panel_username != null &&
Pterodactyl.User.Info.panel_email != null &&
Pterodactyl.User.Info.panel_id != null)
{
using HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(txtpanelurl.Text);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {txtpanelapikey.Text}");

HttpResponseMessage response = await httpClient.GetAsync("/api/client/account");

if (response.IsSuccessStatusCode)
{
if (cbdirectlogin.Checked == false)
string responseBody = await response.Content.ReadAsStringAsync();
if (responseBody.StartsWith("{\"object\":\"user\","))
{
RegistryHandler rh = new RegistryHandler();
rh.CreateAccountData(txtpanelname.Text, txtpanelurl.Text, txtpanelpwd.Text, txtpanelapikey.Text);
try
{
dynamic userObject = JsonConvert.DeserializeObject<dynamic>(responseBody);

Pterodactyl.User.Info.panel_id = userObject.attributes.id;
Pterodactyl.User.Info.panel_admin = userObject.attributes.admin;
Pterodactyl.User.Info.panel_username = userObject.attributes.username;
Pterodactyl.User.Info.panel_email = userObject.attributes.email;
Pterodactyl.User.Info.panel_first_name = userObject.attributes.first_name;
Pterodactyl.User.Info.panel_last_name = userObject.attributes.last_name;
Pterodactyl.User.Info.panel_language = userObject.attributes.language;
Pterodactyl.User.Info.panel_url = txtpanelurl.Text;
Pterodactyl.User.Info.panel_api_key = txtpanelapikey.Text;
try
{
if (cbdirectlogin.Checked == false)
{
RegistryHandler rh = new RegistryHandler();
rh.CreateAccountData(txtpanelname.Text, txtpanelurl.Text, txtpanelpwd.Text, txtpanelapikey.Text);
}
Program.Alert("Successfully logged in!", FrmAlert.enmType.Succes);
FrmSessions x = new FrmSessions();
x.Show();
this.Hide();
} catch (Exception ex)
{
Program.Alert("Login failed", FrmAlert.enmType.Error);
Program.logger.Log(Managers.LogType.Error, "[Forms.FrmLogin.cs]: \n" + ex.Message);
}
}
catch (JsonException ex)
{
Program.logger.Log(Managers.LogType.Error, "[Forms.FrmLogin.cs]: \n" + ex.Message);
Program.Alert("Login Failed. JSON deserialization error.", FrmAlert.enmType.Error);
}
}
else
{
Program.Alert("Login Failed. Unexpected response format.", FrmAlert.enmType.Error);
}
FrmSessions x = new FrmSessions();
x.Show();
this.Hide();
}
else if ((int)response.StatusCode >= 500)
{
Program.Alert("Login Failed. Server returned an error.", FrmAlert.enmType.Error);
Program.logger.Log(Managers.LogType.Error, "[Forms.FrmLogin.cs]: \n" + $"Server returned an error ({ (int)response.StatusCode}): { response.ReasonPhrase}");
}
else if (response.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable ||
response.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
Program.Alert("Login Failed. Server is protected by a verification page.", FrmAlert.enmType.Error);
}
else
{
Program.Alert("Failed to login", FrmAlert.enmType.Error);
Program.Alert("Login Failed. Server returned an error.", FrmAlert.enmType.Error);
Program.logger.Log(Managers.LogType.Error, $"[Forms.FrmLogin.cs]: \nLogin Failed with status code: {response.StatusCode}");

}
}
catch (HttpRequestException ex)
{
Program.logger.Log(Managers.LogType.Error, "[Forms.FrmLogin.cs]: \n" + ex.Message);
Program.Alert("Login Failed. Check url format", FrmAlert.enmType.Error);
}
catch (Exception ex)
{
Program.Alert($"An error occurred: {ex.Message}", FrmAlert.enmType.Error);
Program.logger.Log(Managers.LogType.Error, "[Forms.FrmLogin.cs]: \n" + ex.Message);
Program.Alert("Login Failed", FrmAlert.enmType.Error);
}
}
}
Expand Down
Loading

0 comments on commit d78ba06

Please sign in to comment.