Example #1
0
        public void StartConnection(Action after)
        {
            this.doAfterFetch = after;
            MasterInfo masterInfo = MasterInfo.Fetch();

            if (masterInfo == null)
            {
                if (GameTracker.mgcache0 == null)
                {
                    GameTracker.mgcache0 = new Action <string>(MsgController.ShowMsg);
                }
                SyncContext.RunOnUI <string>(GameTracker.mgcache0, SFST.T.STP_Request_Timeout);
                return;
            }
            this.client = new Client(masterInfo.REDIRECT, 100);
            this.client.rec.eventSystem.RegisterListener(new EventListener <ClientAuthedEvent>(delegate(ClientAuthedEvent e)
            {
                SyncContext.RunOnUI(after);
            }));
            this.client.rec.eventSystem.RegisterListener(new EventListener <InitialTimeoutEvent>(delegate(InitialTimeoutEvent e)
            {
                if (GameTracker.mgcache1 == null)
                {
                    GameTracker.mgcache1 = new Action <string>(MsgController.ShowMsg);
                }
                SyncContext.RunOnUI <string>(GameTracker.mgcache1, SFST.T.STP_Request_Timeout);
            }));
            this.client.rec.eventSystem.RegisterListener(new EventListener <PacketReceivedEvent>(delegate(PacketReceivedEvent e)
            {
                if (e.receivedPacket.Is <ServerErrorPacket>())
                {
                    ServerErrorPacket serverErrorPacket = e.receivedPacket.ToTargetPacket <ServerErrorPacket>();
                    if (serverErrorPacket.Error == "AUTHENTICATION")
                    {
                        SyncContext.RunOnUI(delegate
                        {
                            MsgController.ShowMsg(SFST.T.STP_Old_Credentials);
                            Sharing.sharing.downloadMenu.SetActive(false);
                            this.client.rec.Delete();
                            this.client.CleanCreds();
                        });
                        this.StartConnection(delegate
                        {
                            if (GameTracker.mgcache2 == null)
                            {
                                GameTracker.mgcache2 = new Action <string>(MsgController.ShowMsg);
                            }
                            SyncContext.RunOnUI <string>(GameTracker.mgcache2, SFST.T.STP_Reconnected);
                        });
                    }
                }
            }));
        }
Example #2
0
    public void Upload()
    {
        if (!this.CheckConnection())
        {
            return;
        }
        string text = TouchKeyboard.main.GetText(string.Empty);

        if (text == string.Empty)
        {
            return;
        }
        string buildJson = Build.main.GetBuildJson(text);
        UploadRocketRequest uploadRocketRequest = new UploadRocketRequest();

        uploadRocketRequest.toUpload = new CLRocket
        {
            Title       = text,
            Description = "Uploaded before descriptions where supported.",
            JSON        = buildJson
        };
        GameTracker.Tracker.client.AuthedRequest(uploadRocketRequest, delegate(DefaultPacket r)
        {
            SyncContext.RunOnUI(delegate
            {
                if (r.Success)
                {
                    this.onUploaded.InvokeEvenets();
                    MsgController.ShowMsg(SFST.T.Sharing_Upload_Success);
                }
                else
                {
                    ServerErrorPacket serverErrorPacket = r.ToTargetPacket <ServerErrorPacket>();
                    if (serverErrorPacket.Task == "OP_UPLOAD_LIMIT")
                    {
                        this.onUploadFailed.InvokeEvenets();
                        MsgController.ShowMsg(serverErrorPacket.Error);
                    }
                    else
                    {
                        this.onUploadFailed.InvokeEvenets();
                        MsgController.ShowMsg(SFST.T.Sharing_Upload_Failed);
                    }
                }
            });
        });
    }