mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-12 15:04:36 +01:00
Allow setting IP address
This commit is contained in:
@@ -16,7 +16,7 @@ namespace ServerSelector
|
||||
return !hostsFile.Contains("cloud.nikke-kr.com");
|
||||
}
|
||||
|
||||
public static void SaveCfg(bool useOffical, string gamePath, string launcherPath)
|
||||
public static void SaveCfg(bool useOffical, string gamePath, string launcherPath, string ip)
|
||||
{
|
||||
string sodiumLib = AppDomain.CurrentDomain.BaseDirectory + "sodium.dll";
|
||||
string gameSodium = gamePath + "/nikke_Data/Plugins/x86_64/sodium.dll";
|
||||
@@ -37,8 +37,20 @@ namespace ServerSelector
|
||||
try
|
||||
{
|
||||
|
||||
int startIdx = txt.IndexOf("127.0.0.1 cloud.nikke-kr.com");
|
||||
int endIdx = txt.IndexOf("y.io") + 3;
|
||||
int startIdx = txt.IndexOf("cloud.nikke-kr.com");
|
||||
|
||||
// find new line character before start index
|
||||
for (int i = startIdx - 1; i >= 0; i--)
|
||||
{
|
||||
var c = txt[i];
|
||||
if (c == '\n')
|
||||
{
|
||||
startIdx = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int endIdx = txt.IndexOf("y.io") + 4;
|
||||
txt = txt.Substring(0, startIdx) + txt.Substring(endIdx);
|
||||
|
||||
File.WriteAllText(hostsFilePath, txt);
|
||||
@@ -71,25 +83,26 @@ namespace ServerSelector
|
||||
else
|
||||
{
|
||||
// add to hosts file
|
||||
string hosts = @"127.0.0.1 cloud.nikke-kr.com
|
||||
127.0.0.1 global-lobby.nikke-kr.com
|
||||
127.0.0.1 jp-lobby.nikke-kr.com
|
||||
127.0.0.1 us-lobby.nikke-kr.com
|
||||
127.0.0.1 kr-lobby.nikke-kr.com
|
||||
127.0.0.1 sea-lobby.nikke-kr.com
|
||||
127.0.0.1 hmt-lobby.nikke-kr.com
|
||||
127.0.0.1 aws-na-dr.intlgame.com
|
||||
127.0.0.1 sg-vas.intlgame.com
|
||||
127.0.0.1 aws-na.intlgame.com
|
||||
127.0.0.1 na-community.playerinfinite.com
|
||||
127.0.0.1 common-web.intlgame.com
|
||||
127.0.0.1 li-sg.intlgame.com
|
||||
127.0.0.1 data-aws-na.intlgame.com
|
||||
string hosts = $@"{ip} cloud.nikke-kr.com
|
||||
{ip} global-lobby.nikke-kr.com
|
||||
{ip} jp-lobby.nikke-kr.com
|
||||
{ip} us-lobby.nikke-kr.com
|
||||
{ip} kr-lobby.nikke-kr.com
|
||||
{ip} sea-lobby.nikke-kr.com
|
||||
{ip} hmt-lobby.nikke-kr.com
|
||||
{ip} aws-na-dr.intlgame.com
|
||||
{ip} sg-vas.intlgame.com
|
||||
{ip} aws-na.intlgame.com
|
||||
{ip} na-community.playerinfinite.com
|
||||
{ip} common-web.intlgame.com
|
||||
{ip} li-sg.intlgame.com
|
||||
{ip} data-aws-na.intlgame.com
|
||||
255.255.221.21 sentry.io";
|
||||
|
||||
if (!File.ReadAllText(hostsFilePath).Contains("global-lobby.nikke-kr.com"))
|
||||
{
|
||||
using StreamWriter w = File.AppendText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts"));
|
||||
w.WriteLine();
|
||||
w.WriteLine(hosts);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,40 +3,56 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="clr-namespace:ServerSelector.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="370" d:DesignHeight="170"
|
||||
mc:Ignorable="d" d:DesignWidth="370" d:DesignHeight="200"
|
||||
x:Class="ServerSelector.Views.MainView"
|
||||
x:DataType="vm:MainViewModel"
|
||||
>
|
||||
<Design.DataContext>
|
||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||
<Design.DataContext>
|
||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||
<vm:MainViewModel />
|
||||
</Design.DataContext>
|
||||
<vm:MainViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<StackPanel>
|
||||
<WrapPanel Margin="5">
|
||||
<TextBlock VerticalAlignment="Center" Margin="5">Game path: </TextBlock>
|
||||
<TextBox x:Name="txtGamePath">C:\NIKKE\NIKKE\game</TextBox>
|
||||
</WrapPanel>
|
||||
<Grid Margin="5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"></ColumnDefinition>
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<WrapPanel Margin="5">
|
||||
<TextBlock VerticalAlignment="Center" Margin="5">Launcher path: </TextBlock>
|
||||
<TextBox x:Name="txtLauncherPath">C:\NIKKE\Launcher</TextBox>
|
||||
</WrapPanel>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
<RowDefinition Height="5"></RowDefinition>
|
||||
<RowDefinition Height="auto"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
||||
<WrapPanel Margin="5">
|
||||
<TextBlock VerticalAlignment="Center" Margin="5">Server: </TextBlock>
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="0" Grid.Column="0">Game path: </TextBlock>
|
||||
<TextBox x:Name="txtGamePath" Grid.Row="0" Grid.Column="1">C:\NIKKE\NIKKE\game</TextBox>
|
||||
|
||||
<ComboBox SelectedIndex="0" x:Name="CmbServerSelection">
|
||||
<ComboBox.Items>
|
||||
<ComboBoxItem>Official</ComboBoxItem>
|
||||
<ComboBoxItem>Local</ComboBoxItem>
|
||||
</ComboBox.Items>
|
||||
</ComboBox>
|
||||
</WrapPanel>
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="2" Grid.Column="0">Launcher path: </TextBlock>
|
||||
<TextBox x:Name="txtLauncherPath" Grid.Row="2" Grid.Column="1">C:\NIKKE\Launcher</TextBox>
|
||||
|
||||
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="4" Grid.Column="0">Server: </TextBlock>
|
||||
|
||||
<ComboBox SelectedIndex="0" x:Name="CmbServerSelection" Grid.Row="4" Grid.Column="1" SelectionChanged="CmbServerSelection_SelectionChanged">
|
||||
<ComboBox.Items>
|
||||
<ComboBoxItem>Official</ComboBoxItem>
|
||||
<ComboBoxItem>Local</ComboBoxItem>
|
||||
</ComboBox.Items>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock VerticalAlignment="Center" Margin="5" Grid.Row="6" Grid.Column="0">IP: </TextBlock>
|
||||
<TextBox x:Name="TxtIpAddress" Grid.Row="6" Grid.Column="1">127.0.0.1</TextBox>
|
||||
|
||||
<Button HorizontalAlignment="Right" Margin="5" Click="Save_Click">Save</Button>
|
||||
|
||||
</StackPanel>
|
||||
<Button HorizontalAlignment="Right" Margin="5" Click="Save_Click" Grid.Row="8" Grid.Column="1">Save</Button>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Avalonia.Controls;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
|
||||
@@ -11,6 +12,8 @@ public partial class MainView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
CmbServerSelection.SelectedIndex = ServerSwitcher.IsUsingOfficalServer() ? 0 : 1;
|
||||
|
||||
TxtIpAddress.IsEnabled = !ServerSwitcher.IsUsingOfficalServer();
|
||||
}
|
||||
|
||||
private void Save_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
@@ -21,16 +24,31 @@ public partial class MainView : UserControl
|
||||
return;
|
||||
}
|
||||
|
||||
if (CmbServerSelection.SelectedIndex == 1)
|
||||
{
|
||||
if (!IPAddress.TryParse(TxtIpAddress.Text, out _))
|
||||
{
|
||||
ShowWarningMsg("Invalid IP address. The entered IP address should be IPv4 or IPv6.", "Error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ServerSwitcher.SaveCfg(CmbServerSelection.SelectedIndex == 0, txtGamePath.Text, txtLauncherPath.Text);
|
||||
ServerSwitcher.SaveCfg(CmbServerSelection.SelectedIndex == 0, txtGamePath.Text, txtLauncherPath.Text, TxtIpAddress.Text);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowWarningMsg("Failed to save configuration: " + ex.ToString(), "Error");
|
||||
}
|
||||
}
|
||||
|
||||
private void CmbServerSelection_SelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (CmbServerSelection != null)
|
||||
TxtIpAddress.IsEnabled = CmbServerSelection.SelectedIndex == 1;
|
||||
}
|
||||
|
||||
// for some stupid reason avalonia does not support message boxes.
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:views="clr-namespace:ServerSelector.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="370" d:DesignHeight="170"
|
||||
mc:Ignorable="d" d:DesignWidth="370" d:DesignHeight="200"
|
||||
x:Class="ServerSelector.Views.MainWindow"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
Title="Server Switcher Utility" Width="370" Height="170" CanResize="False">
|
||||
Title="Server Switcher Utility" Width="370" Height="210" CanResize="False">
|
||||
<views:MainView />
|
||||
</Window>
|
||||
|
||||
Reference in New Issue
Block a user