Skip to content

Commit 1b83838

Browse files
committed
Initial commit
0 parents  commit 1b83838

14 files changed

+989
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.suo
2+
[Oo]bj/
3+
[Bb]in
4+
[Dd]ebug*/
5+
[Rr]elease*/

SAMP-Launcher.sln

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.30723.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SAMP-Launcher", "SAMP-Launcher\SAMP-Launcher.csproj", "{05DC2CF3-D79F-4183-B98D-2FA2A78066C9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{05DC2CF3-D79F-4183-B98D-2FA2A78066C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{05DC2CF3-D79F-4183-B98D-2FA2A78066C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{05DC2CF3-D79F-4183-B98D-2FA2A78066C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{05DC2CF3-D79F-4183-B98D-2FA2A78066C9}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

SAMP-Launcher/App.xaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="SAMP_Launcher.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
StartupUri="MainWindow.xaml">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>

SAMP-Launcher/App.xaml.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Windows;
7+
8+
namespace SAMP_Launcher
9+
{
10+
/// <summary>
11+
/// Interaction logic for App.xaml
12+
/// </summary>
13+
public partial class App : Application
14+
{
15+
}
16+
}

SAMP-Launcher/MainWindow.xaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Window x:Name="MainWindow1" x:Class="SAMP_Launcher.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Title="SAMP Launcher" Height="362" Width="516" Loaded="MainWindow1_Loaded" WindowStyle="ToolWindow" ResizeMode="NoResize">
5+
<Grid Margin="0,0,0,0">
6+
<Grid.Background>
7+
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
8+
<GradientStop Color="Black" Offset="0"/>
9+
<GradientStop Color="White" Offset="1"/>
10+
<GradientStop Color="#FFC19797"/>
11+
</LinearGradientBrush>
12+
</Grid.Background>
13+
<Button x:Name="btnConnect" Content="Connect" HorizontalAlignment="Left" Height="52" Margin="161,234,0,0" VerticalAlignment="Top" Width="183" FontSize="16" Background="#FFEAE0E0" Click="btnConnect_Click"/>
14+
<TextBox x:Name="txtbxPlayerName" HorizontalAlignment="Left" Height="24" Margin="161,187,0,0" TextWrapping="Wrap" Text="Nickname" VerticalAlignment="Top" Width="183" FontSize="14"/>
15+
<Label x:Name="lblSvrName" Content="SAMP Launcher" Margin="135,16,78,0" Height="48" FontSize="36" FontFamily="AgencyFB" VerticalAlignment="Top"/>
16+
<Label x:Name="lblServerLabel" Content="Tên server:" HorizontalAlignment="Left" Margin="161,83,0,0" VerticalAlignment="Top"/>
17+
<Label x:Name="lblServer" Content="" HorizontalAlignment="Left" Margin="259,83,0,0" VerticalAlignment="Top"/>
18+
<Label x:Name="lblPlayersCountLabel" Content="Số người chơi:" HorizontalAlignment="Left" Margin="71,114,0,0" VerticalAlignment="Top"/>
19+
<Label x:Name="lblPlayersCount" Content="0/0" HorizontalAlignment="Left" Margin="172,114,0,0" VerticalAlignment="Top"/>
20+
<Label x:Name="lblGameModeLabel" Content="Phiên bản:" HorizontalAlignment="Left" Margin="312,114,0,0" VerticalAlignment="Top"/>
21+
<Label x:Name="lblGameMode" Content="" HorizontalAlignment="Left" Margin="389,114,0,0" VerticalAlignment="Top"/>
22+
<Label x:Name="lblWebURLLabel" Content="Website:" HorizontalAlignment="Left" Margin="71,140,0,0" VerticalAlignment="Top"/>
23+
<Label x:Name="lblWebsite" Content="" HorizontalAlignment="Left" Margin="172,140,0,0" VerticalAlignment="Top"/>
24+
<Label x:Name="lblMapLabel" Content="Map:" HorizontalAlignment="Left" Margin="312,140,0,0" VerticalAlignment="Top"/>
25+
<Label x:Name="lblMap" Content="" HorizontalAlignment="Left" Margin="389,140,0,0" VerticalAlignment="Top"/>
26+
<StatusBar x:Name="stt" HorizontalAlignment="Left" Height="21" Margin="0,312,0,0" VerticalAlignment="Top" Width="255">
27+
<TextBlock x:Name="lblStatus" TextWrapping="Wrap" Text="Hold"/>
28+
</StatusBar>
29+
30+
</Grid>
31+
</Window>

SAMP-Launcher/MainWindow.xaml.cs

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Windows;
6+
using System.Windows.Controls;
7+
using System.Windows.Data;
8+
using System.Windows.Documents;
9+
using System.Windows.Input;
10+
using System.Windows.Media;
11+
using System.Windows.Media.Imaging;
12+
using System.Windows.Navigation;
13+
using System.Windows.Shapes;
14+
using Microsoft.Win32;
15+
using System.IO;
16+
using System.Net.NetworkInformation;
17+
using System.Net.Sockets;
18+
using System.Diagnostics;
19+
using System.Net;
20+
21+
namespace SAMP_Launcher
22+
{
23+
/// <summary>
24+
/// Interaction logic for MainWindow.xaml
25+
/// </summary>
26+
public partial class MainWindow : Window
27+
{
28+
private const string _launcherTitle = "SAMP Launcher";
29+
// Tên miền hoặc địa chỉ IP của server.
30+
private const string _serverName = "127.0.0.1";
31+
private const int _serverPort = 7777;
32+
// Password để vào server.
33+
private const string _serverPassword = "";
34+
35+
private string _serverIP;
36+
private string _playerName;
37+
private SAMP.Query _query;
38+
39+
public MainWindow()
40+
{
41+
InitializeComponent();
42+
43+
MainWindow1.Title = _launcherTitle;
44+
lblSvrName.Content = _launcherTitle;
45+
lblStatus.Text = "Đang chờ";
46+
}
47+
48+
private void MainWindow1_Loaded(object sender, RoutedEventArgs e)
49+
{
50+
if (checkFiles() == false)
51+
Application.Current.Shutdown();
52+
53+
// Lấy tên nhân vật từ registry và cho vào textbox.
54+
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\SAMP");
55+
if (key != null)
56+
{
57+
Object value = key.GetValue("PlayerName");
58+
if (value != null)
59+
{
60+
txtbxPlayerName.Text = value.ToString();
61+
}
62+
}
63+
_playerName = txtbxPlayerName.Text;
64+
65+
66+
IPAddress svIP;
67+
if (IPAddress.TryParse(_serverName, out svIP))
68+
{
69+
_serverIP = svIP.ToString();
70+
}
71+
else
72+
{
73+
// Phân giải tên miền.
74+
IPHostEntry hostEntry = Dns.GetHostEntry(_serverName);
75+
if (hostEntry.AddressList.Length == 0)
76+
{
77+
lblStatus.Text = "<!> Đã có lỗi xảy ra với DNS. Xin vui lòng liên hệ Admin.";
78+
return;
79+
}
80+
_serverIP = hostEntry.AddressList[0].ToString();
81+
}
82+
_query = new SAMP.Query(_serverIP, _serverPort, false);
83+
84+
updateServerInfo();
85+
}
86+
87+
private void updateServerInfo()
88+
{
89+
if (_query.Send((char)SAMP.Query.PaketOpcode.Info))
90+
{
91+
int count = _query.Receive();
92+
if (count == 0)
93+
{
94+
lblStatus.Text = "<!> Không thể kết nối đến server.";
95+
btnConnect.IsEnabled = false;
96+
return;
97+
}
98+
99+
lblServer.Content = _query.hostname;
100+
lblGameMode.Content = _query.gamemode;
101+
lblPlayersCount.Content = _query.players + '/' + _query.max_players;
102+
103+
if (_query.Send((char)SAMP.Query.PaketOpcode.Rules))
104+
{
105+
count = _query.Receive();
106+
if (count == 0)
107+
{
108+
lblStatus.Text = "<!> Không thể kết nối đến server.";
109+
btnConnect.IsEnabled = false;
110+
return;
111+
}
112+
string[] rules = _query.Store(count);
113+
114+
for (int i = 0; i < rules.Length - 2; i += 2)
115+
{
116+
if (rules[i] == "mapname")
117+
{
118+
lblMap.Content = rules[i + 1];
119+
}
120+
else if (rules[i] == "weburl")
121+
{
122+
lblWebsite.Content = rules[i + 1];
123+
}
124+
}
125+
}
126+
}
127+
else
128+
{
129+
btnConnect.IsEnabled = false;
130+
lblStatus.Text = "<!> Không thể kết nối đến server.";
131+
}
132+
}
133+
134+
private bool checkFiles()
135+
{
136+
if (File.Exists("samp.exe") == false)
137+
{
138+
MessageBox.Show("<!> Không tìm thấy samp.exe\n<!> Vui lòng bỏ Launcher vào cùng thư mục với file samp.exe (trong folder game).", "Lỗi");
139+
return false;
140+
}
141+
//if (File.Exists("d3d9.dll"))
142+
//{
143+
// MessageBox.Show("<!> Hê thống nhận thấy bạn đang sử dụng phần mềm thứ 3 không hợp lệ (s0beit).\n<!> Hãy xóa các file đó hoặc re-install game.", "Lỗi");
144+
// return false;
145+
//}
146+
//if (File.Exists("cleo.asi"))
147+
//{
148+
// MessageBox.Show("<!> Hê thống nhận thấy bạn đang sử dụng phần mềm thứ 3 không hợp lệ (CLEO).\n<!> Hãy xóa các file đó hoặc re-install game.", "Lỗi");
149+
// return false;
150+
//}
151+
return true;
152+
}
153+
154+
private void btnConnect_Click(object sender, RoutedEventArgs e)
155+
{
156+
if (checkFiles() == false)
157+
return;
158+
159+
// kiểm tra tên nhân vật có thay đổi không
160+
lblStatus.Text = "[*] Đang kiểm tra tên nhân vật.";
161+
if (txtbxPlayerName.Text != _playerName)
162+
{
163+
// nếu tên mới không thỏa điều kiện
164+
if (txtbxPlayerName.Text.Length > 20 || txtbxPlayerName.Text.Length < 4)
165+
{
166+
MessageBox.Show("<!> Tên không được ít hơn 4 hoặc nhiều hơn 20 ký tự.", "Tên không hợp lệ!");
167+
return;
168+
}
169+
170+
// chỉnh lại giá trị trong registry
171+
RegistryKey setKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\SAMP");
172+
if (setKey != null)
173+
{
174+
setKey.SetValue("PlayerName", txtbxPlayerName.Text);
175+
}
176+
}
177+
//MessageBox.Show(_serverIP + ":" + _serverPort);
178+
179+
lblStatus.Text = "[*] Đang tiến hành kết nối đến server.";
180+
ProcessStartInfo startInfo = new ProcessStartInfo();
181+
startInfo.FileName = "samp.exe";
182+
startInfo.Arguments = _serverIP + ":" + _serverPort + " " + _serverPassword;
183+
lblStatus.Text = "[*] Đang vào game.";
184+
Process.Start(startInfo);
185+
lblStatus.Text = "[*] Thành công.";
186+
}
187+
}
188+
}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyTitle("SAMP-Launcher")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("SAMP-Launcher")]
15+
[assembly: AssemblyCopyright("Copyright © 2014")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
// You can specify all the values or you can default the Build and Revision Numbers
52+
// by using the '*' as shown below:
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)