GS2-News

Notification delivery function

This system is used to distribute in-game announcements in HTML format. HTML content to be delivered must be generated by hugo(https://gohugo.io/).

hugo

hugo is a static web page generator.

It generates HTML files by building templates to specify page layout and design, and article data written in markdown format. For more information on how to use hugo, see the official hugo website or various tutorial websites.

GS2 provides minimal hugo templates and sample article data on GitHub.

https://github.com/gs2io/gs2-news-sample

Articles linked to events

GS2-News can manage articles that are linked to events managed by GS2-Schedule.

The linkage can be enabled by adding the following description to the front matter of the article data markdown file

x_gs2_scheduleEventId: ${GS2-Schedule's event GRN}

In addition, the following placeholders are available for the Event ID of GS2-Schedule.

PlaceholderValue to be replaced
{region}region name
{ownerId}GS2 owner ID

An example description is as follows.

x_gs2_scheduleEventId: grn:gs2:{region}:{ownerId}:schedule:schedule-0001:event:event-0001

Build article data

Article data to be distributed by GS2-News is updated by uploading zipped Hugo templates and article files. GS2-News will then build and distribute the article data.

If x_gs2_scheduleEventId is described in the article data, GS2-News builds each version of each article in public and private states in advance and places them on the web server.

Then, when a player tries to access the article data, it responds to the player with the URL of the most appropriate content based on the current event status.

Access rights for article data

We explained that all article data patterns are pre-built and distributed. Malicious players should not be able to identify URLs and access content that should not be distributed.

To avoid this problem, GS2-News implements access restrictions using cookies. It retrieves the URL of the currently active content and returns the cookie information to access that URL. By accessing the content URL after setting the cookie in your browser, you will be able to download the content.

The cookie will expire after one hour, and you will no longer be able to access the content.

Download Web content in Zip format

In addition to using WebView to access the HTML hosted by GS2-News, you can also download the entire HTML file created by GS2-News in zip format.

This method allows you to extract the zipped HTML content to local storage and view it in a browser to better view the content and avoid downloading the same content over and over again.

To determine whether the zip file should be downloaded again, GS2-News is able to retrieve the hash values of the template file and the hash values of the published content based on the GS2 schedule. These values can be used to determine if the zip file should be downloaded again.

Example implementation

Get content URL

    var result = await gs2.News.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).News(
    ).GetContentsUrlAsync(
    );

    List<EzSetCookieRequestEntry> cookies = new List<EzSetCookieRequestEntry>();
    var items = result.ToList();
    foreach (var item in items)
    {
        var entry = await item.ModelAsync();
        cookies.Add(entry);
    }
    var browserUrl = domain.BrowserUrl;
    var zipUrl = domain.ZipUrl;
    const auto Domain = Gs2->News->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->News(
    );
    const auto Future = Domain->GetContentsUrl(
    );
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;
    TArray<EzSetCookieRequestEntryPtr> Cookies;
	const auto It = Future->GetTask().Result();
	foreach (auto Item in It)
	{
        const auto Future2 = Item.Model();
        Future2->StartSynchronousTask();
        if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
        Cookies.Add(Future->GetTask().Result());
	}
    const auto BrowserUrl = Domain->BrowserUrl;
    const auto ZipUrl = Domain->ZipUrl;

Get a list of article data

We do not recommend using this API to perform balance consumption processing. It is recommended that you perform some kind of processing instead of spending your billable currency through a service such as GS2-Showcase.

    var domain = gs2.News.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    );
    var items = await domain.NewsesAsync(
    ).ToListAsync();
    var templateHash = domain.TemplateHash;
    var contentHash = domain.ContentHash;
    const auto Domain = Gs2->News->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    );
    const auto It = Domain->Newses(
    );
    for (auto Item : *It)
    {

    }

Detailed reference