-
Notifications
You must be signed in to change notification settings - Fork 7
Network
The game interacts with the server via the http protocol.
There are ready-made methods of popular queries for you in the library, they are implemented in the GameClient
class
The client is created through the constructor
Parameter | Type | Description | Default |
---|---|---|---|
identifierQuery | IdentifierQuery | Represents a uuid and udid parameters of the client |
null (IdentifierQuery.Default ) |
onlineQuery | OnlineQuery | Represents a gameVersion , binaryVersion , gdw and secret parameters of the client |
null (OnlineQuery.Default ) |
network | Network | The class that allows you to make http requests to the server Learn more |
null (new Network() ) |
To interact with the official game server
var client = new GameClient();
var server = new GameServer(
network: new Network(server: "http://game.gdpseditor.com/server")
);
Any method you call will return ServerResponse<T>
.
T
is response for your request;
ServerResponse
is a container for any Geometry Dash responses
The fields are contained inside
Field | Type | Description |
---|---|---|
HttpStatusCode | HttpStatusCode | HTTP response code, 200 when everything is ok, 404 when something is not found... etc |
GeometryDashStatusCode | int | GeometryDash response code, 0 when everything is ok and not 0 when there are errors. Errors can be unique to each method that mean something. The most frequent -1
|
There are also contains 2 methods
Method | Return type | Description |
---|---|---|
GetResultOrDefault |
T of ServerResponse<T>
|
Return a deserialized response or null , if there are error appears |
GetRawOrDefault | string | Return body from http response or null , if there are error appears |
Thus, your code can check the response to an error in at least two ways
var client = new GameClient();
var response = client.SearchUserAsync("user name");
// first way: check an error code
if (response.GeometryDashStatusCode != 0)
return $"There is an error. Code '{response.GeometryDashStatusCode}'");
// second way: check a response content
var content = response.GetResultOrDefault();
if (content == null)
return "There is no content in response";
If everything is fine, you can get a response using GetResultOrDefault
var response = await client.SeachUserAsync("...");
var content = response.GetResultOrDefault();
For some answers there is information about the pages
var page = content.Page;
There are fields exists
Field | Type | Description |
---|---|---|
RangeIn | int | The left border in the list (known as skip ) |
RangeOut | int | The right border in the list |
CountOnPage | int | Number of received list items (known as take ) |
TotalCount | int | Total elements in the list |
Also has method HasPage(int page)
To check if there are further pages or not
Here is an example of a console application using a GameClient
using GeometryDashAPI.Server;
using System;
using System.Threading;
using System.Threading.Tasks;
using GeometryDashAPI.Server.Responses;
namespace Examples;
internal static class Program
{
internal static async Task Main(string[] args)
{
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (_, _) => cts.Cancel(); // for "Ctrl + C" in console
try
{
var client = new GameClient();
var page = 0;
LevelPageResponse content = null;
while (content == null || content.Page.HasPage(page))
{
if (cts.Token.IsCancellationRequested)
break;
await Task.Delay(TimeSpan.FromSeconds(3), cts.Token); // to avoid DOS
var response = await client.GetFeaturedLevelsAsync(page);
if (response.GeometryDashStatusCode != 0)
{
Console.WriteLine($"error in page: {page}, status code: {response.GeometryDashStatusCode}");
break;
}
content = response.GetResultOrDefault();
Console.WriteLine($"{new string('=', 8)}page {page}{new string('=', 8)}");
foreach (var level in content.Levels)
Console.WriteLine($"{level.Name}: {level.Likes}");
page++;
}
}
catch (OperationCanceledException)
{
}
Console.WriteLine(cts.IsCancellationRequested ? "cancelled" : "done");
}
}
var user = await client.SearchUserAsync("user name");
var account = await client.GetAccountAsync(accountId: 71);
You can get the accountId
from the user search
var user = await client.SearchUserAsync("user name");
if (user.GeometryDashStatusCode != 0)
Console.WriteLine("error when searching for a user");
var account = await client.GetAccountAsync(user.GetResultOrDefault().User.AccountId);
var response = await client.GetAccountCommentsAsync(accountId: 71, page: 0);
foreach (var comment in response.GetResultOrDefault().Comments)
Console.WriteLine($"{comment.Date}: {comment.Comment}");
var response = await client.LoginAsync("user", "password");
var login = response.GetResultOrDefault();
See Login for get login
field
var levelsPage = await client.GetMyLevelsAsync(new PasswordQuery(login.AccountId, "password"), login.UserId, 0);
var levelResponse = await client.DownloadLevelAsync(id: 29441648);
So that you can edit the blocks and colors of the level, you need to create a Level
var level = new Level(levelResponse.GetResultOrDefault().Level.LevelString, compressed: true);
var senderAccountId = 71;
var receiverAccountId = 100;
var message = new Message()
{
Subject = "Hello",
Body = "How are you? ^_^"
};
var result = await client.SendMessageAsync(
new PasswordQuery(senderAccountId, "sender-password"),
receiverAccountId,
message
);
var messages = await client.GetMessagesAsync(new PasswordQuery(accountId: 71, "password"), page: 0);
var content = await client.ReadMessageAsync(new PasswordQuery(accountId: 71, "password"), messageId: 123);
You can get the messageId
from GetMessageAsync
method
The Network
class represents interaction over the http protocol
You can create Network
like this
var network = new Network(server, httpClientFactory, responseFilter);
Parameter | Type | Description | Default |
---|---|---|---|
server | string | The base url to the server to which requests will be sent | http://www.boomlings.com/database |
httpClientFactory | IFactory<HttpClient> | A factory for creating http clients, with which you can configure timeouts, headers, and so on Learn more to create your own http client factory |
null (DefaultHttpClientFactory) |
responseFilter | Func<string, bool> | Useless feature for manually filtering the response (For example, if suddenly cloudflare gives you html) | null |
using System;
using System.Net.Http;
public class YourHttpFactory : IFactory<HttpClient>
{
public HttpClient Create()
{
return new HttpClient()
{
Timeout = TimeSpan.FromSeconds(20),
};
}
}