Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Can send data in game in WEBGL itch.io

A topic by ajvendetta created Feb 22, 2022 Views: 441 Replies: 2
Viewing posts 1 to 3

Hello,

I  have a unity game that I am testing in a hospital, the game collects anonymous data and sends it to me via mail for analysis. Problem is that on itch.io i don't receive any mail.

using UnityEngine;

using UnityEngine.UI;

using System.Net;

using System.Net.Mail;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

using System.IO;

using System;

using Random = System.Random;

public class Sending : MonoBehaviour

{

    public InputField bodyMessage;

    public string RandomString(int length)

    {

        Random rnd = new Random();

        const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

        string randomis="";

        for(int i = 0; i < length; i++)

        {

            char c = chars[rnd.Next(chars.Length)];

            randomis += c;

        }

        return randomis;

    }

    public void SendEmail()

    {

        string randomised =     RandomString(20);

        System.IO.File.Move("Texting.txt", randomised+".txt");

        string recipientEmail = "****************@gmail.com";

        MailMessage mail = new MailMessage();

        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

        SmtpServer.Timeout = 10000;

        SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;

        SmtpServer.UseDefaultCredentials = false;

        SmtpServer.Port = 587;

        mail.From = new MailAddress("*************@gmail.com");

        mail.To.Add(new MailAddress(recipientEmail));

        

        mail.Subject = "Test Email through C Sharp App";

        mail.Body = bodyMessage.text;

         

System.Net.Mail.Attachment attachment;

attachment = new System.Net.Mail.Attachment(randomised + ".txt");

mail.Attachments.Add(attachment);

        SmtpServer.Credentials = new System.Net.NetworkCredential("****************", "******************") as ICredentialsByHost; SmtpServer.EnableSsl = true;

        ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

        {

            return true;

        };

        mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

        SmtpServer.Send(mail);

    }

}

I dunno what to do, and it is much more convenient to have an online version of the game . I am new to unity developpement, does anyone have an idea on what to do? or maybe another suggestion to get data from the game ? 

(2 edits)

I would have been very surprised if that works, and that has nothing to do with itch.io. For WebGL builds, Unity basically translates all scripts to web technology (javascript, WebGL, WASM). Many of the tools that are available in normal .NET such as file system, sockets, and probably mail too aren't available. And that's not even Unity's fault: some things simply don't exist in browsers, and other things are not allowed because of strict browser security rules. If you run your WebGL build locally on your own machine, you'll probably notice that it doesn't work there either.

However there are some things you can do instead:

From the Unity side, the easiest thing to do is using WebRequests:

https://docs.unity3d.com/Manual/webgl-networking.html

However this does require running a server that can process these requests, and that is configured correctly, which may be a hassle.

You could also combine your WebGL build with something like Google Analytics. This seems to be the best explanation I can find:

https://vediagames.com/blog/Simple-Google-Analytics-for-web-games?id=IkKE84awL0s...

Be careful with collecting analytics however, especially in Europe: with the recent very strict privacy laws, a lot of things may be considered illegal if you don't ask explicitly for user consent.

why do you need to collect data, you don't need it. What you need is beta testers not a program that is flaw at understanding what you want.

This topic has been auto-archived and can no longer be posted in because there haven't been any posts in a while.