|
You last visited: Today at 02:51
Advertisement
C# tcp client dont work with GF login packet
Discussion on C# tcp client dont work with GF login packet within the Nostale forum part of the MMORPGs category.
03/13/2020, 15:14
|
#1
|
elite*gold: 0
Join Date: Mar 2020
Posts: 3
Received Thanks: 0
|
C# tcp client dont work with GF login packet
Hello, I want make login script with C#, but when I send login packet with tcp client i get "failc 1". probably there is something wrong with my login packet, but it is fine because I generated new login packet in C# and it works perfectly fine with QtTcpSocket. I dont know what to do, i tried few different tcp clients library and always i get failc 1. I don't know maybe it's this char between random hex number and nostale version, but i tried everything(\v; (char)0xB; tab; space) and nothing worked. Is there anyone here who wrote a working C# login to GF nostale and want to share knowledge?
|
|
|
03/13/2020, 15:47
|
#2
|
elite*gold: 0
Join Date: Jun 2019
Posts: 102
Received Thanks: 228
|
Here is the code i'm using for a personal project and it work just fine.
Ofc you will need to modify it to make it work for you
Code:
public class GameforgeAuthenticator : IGameforgeAuthenticator
{
private const string URL = "https://spark.gameforge.com/api/v1";
private const string PLATFORM_GAME_ID = "dd4e22d6-00d1-44b9-8126-d8b40e0cd7c9";
private const string USER_AGENT = "GameforgeClient/2.0.48";
private const string MEDIA_TYPE = "application/json";
private readonly HttpClient _httpClient;
private readonly ISerializer _serializer;
private readonly IDeserializer _deserializer;
public GameforgeAuthenticator(ISerializer serializer, IDeserializer deserializer)
{
_httpClient = new HttpClient();
_serializer = serializer;
_deserializer = deserializer;
}
public async Task<string> GetAuthenticationToken(string username, string password, Language language)
{
string serialized = _serializer.Serialize(new AuthForm
{
GfLang = language.GfLang,
Username = username,
Password = password,
Locale = language.Locale,
PlatformGameId = PLATFORM_GAME_ID
});
using var request = new HttpRequestMessage(HttpMethod.Post, $"{URL}/auth/thin/sessions")
{
Content = new StringContent(serialized, Encoding.UTF8, MEDIA_TYPE)
};
HttpResponseMessage response = await _httpClient.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
return string.Empty;
}
string content = await response.Content.ReadAsStringAsync();
var jsonContent = _deserializer.Deserialize<Dictionary<string, string>>(content);
return jsonContent.GetValueOrDefault("token") ?? string.Empty;
}
public async Task<IEnumerable<GameforgeAccount>> GetAccounts(string authenticationToken, Guid installationId)
{
using var request = new HttpRequestMessage(HttpMethod.Get, $"{URL}/user/accounts");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authenticationToken);
request.Headers.Add("TNT-Installation-Id", installationId.ToString());
request.Headers.Add("User-Agent", USER_AGENT);
HttpResponseMessage response = await _httpClient.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
return new List<GameforgeAccount>();
}
string content = await response.Content.ReadAsStringAsync();
var jsonContent = _deserializer.Deserialize<Dictionary<string, GameforgeAccount>>(content);
return jsonContent?.Values.ToArray() ?? Array.Empty<GameforgeAccount>();
}
public async Task<string> GetSessionToken(string authenticationToken, GameforgeAccount account, Guid installationId)
{
using var request = new HttpRequestMessage(HttpMethod.Post, $"{URL}/auth/thin/codes");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authenticationToken);
request.Headers.Add("TNT-Installation-Id", installationId.ToString());
request.Headers.Add("User-Agent", USER_AGENT);
string json = _serializer.Serialize(new SessionForm
{
PlatformGameAccountId = account.Id
});
request.Content = new StringContent(json, Encoding.UTF8, MEDIA_TYPE);
HttpResponseMessage response = await _httpClient.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
return string.Empty;
}
string content = await response.Content.ReadAsStringAsync();
var jsonContent = _deserializer.Deserialize<Dictionary<string, string>>(content);
return (jsonContent.GetValueOrDefault("code") ?? string.Empty).ToHex();
}
}
Code:
public IClient CreateLoginClient(string sessionToken, Guid gameforgeInstallationId)
{
LoginClient client = new LoginClient();
client.PacketReceived += packet =>
{
_packetManager.Handle(client, packet);
};
bool connected = client.Connect("79.110.84.75", 4002);
if (!connected)
{
_logger.Warning("Failed to connect to login server");
return default;
}
string randomValue = "00" + Random.Next(0, 126).ToString("X")
+ Random.Next(0, 126).ToString("X")
+ Random.Next(0, 126).ToString("X");
client.SendPacket(
$"NoS0577 {sessionToken} {gameforgeInstallationId} {randomValue}{(char) 0xB}{_configuration.ClientInfo.Version} 0 {(_configuration.ClientInfo.DxHash.ToUpper() + _configuration.ClientInfo.GlHash.ToUpper()).ToMd5()}");
return client;
}
_configuration.ClientInfo.DxHash = Latest NostaleClientX.exe md5 hash
_configuration.ClientInfo.GlHash= Latest NostaleClient.exe md5 hash
_configuration.ClientInfo.Version = Latest NostaleClientX or NostaleClient version
Btw you're receiving failc1 if your client is outdated so it's probably coming from your hashes
|
|
|
03/13/2020, 16:07
|
#3
|
elite*gold: 0
Join Date: Mar 2020
Posts: 3
Received Thanks: 0
|
Quote:
Originally Posted by Roxeez
Btw you're receiving failc1 if your client is outdated so it's probably coming from your hashes
|
Thanks, but my hashes are just fine. My code works, but there is something wrong with tcp client. I generated login packet in C# and then I tested it with C++ QtTcpSocket and I get list of servers. So idk. Can you share with me the LoginClient class?
|
|
|
03/13/2020, 16:50
|
#4
|
elite*gold: 0
Join Date: Jun 2019
Posts: 102
Received Thanks: 228
|
Quote:
Originally Posted by DonkeyKong69XD
Thanks, but my hashes are just fine. My code works, but there is something wrong with tcp client. I generated login packet in C# and then I tested it with C++ QtTcpSocket and I get list of servers. So idk. Can you share with me the LoginClient class?
|
It's just a wrapper around a System.Net.Sockets.Socket who encrypt/decrypt packets send/received
|
|
|
03/14/2020, 14:56
|
#5
|
elite*gold: 0
Join Date: Mar 2020
Posts: 3
Received Thanks: 0
|
Quote:
Originally Posted by Roxeez
It's just a wrapper around a System.Net.Sockets.Socket who encrypt/decrypt packets send/received
|
I don't know how, but somehow I fixed it 
Thanks for help.
Maybe you could help me with one more problem? How to detect GF staff?
|
|
|
03/14/2020, 15:44
|
#6
|
elite*gold: 0
Join Date: Oct 2018
Posts: 257
Received Thanks: 207
|
Check the in packet :
Code:
Authority PacketIn1::getAuthority()
{
return static_cast<Authority>(packet[8].toShort());
}
|
|
|
 |
Similar Threads
|
Handling TCP Packet Fragmentation.
03/14/2014 - CO2 Programming - 15 Replies
Well after long time digging Network programming, one topic remains ambiguous to me. Packet Fragmentation, as far as i know TCP may not give you the message you sent as a whole but might fragment or rebuild it. So there is no guarantee that when i receive for example the Client's Login packet that it would be Full so how in all the source around here From Albetros to Pheonix i can't see any sort of Fragmentation Handling ? does it exists some how and i don't know/understand ?. Please i need a...
|
tcp packet spam | schnellste variante?
11/21/2011 - General Coding - 13 Replies
hallo
ich möchte auf einen host in einer Sekunde soviele Packete verschicken wie es nur möglich ist von meiner Verbindung her.
Deswegen wollte ich hier nachforschen, wie man dies am besten erreichen soll.
Die programmier Sprache ist mir eigentlich egal, ich bin meist schnell im Verstand.
Hatte mal mit Autoit versuch das ganze zu schreiben.
Zuerst einen script mit einer schleife und in der schleife VERBINDUNG aufbau danach sofort packet senden.
|
[C++] TCP Packet senden
05/28/2011 - C/C++ - 1 Replies
Kann mit jemand erklären, wie ich in C++ TCP Packets senden kann?
Ich will damit einfach nur meine FritzBox zum reconnecten bringen...
|
DarkOrbit TCP Packet Firma
01/06/2011 - DarkOrbit - 3 Replies
Hallo
In welchem Packet wird den angegeben von welcher Firma(MArs, Venus,..) Schiff ist.
Danke
|
All times are GMT +1. The time now is 02:51.
|
|