<commit_before>﻿using System;
using System.Collections;
using System.Net;
using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using Domain;
using Akka.Interfaced.SlimSocket.Client;
using Akka.Interfaced.SlimSocket.Base;
using Common.Logging;
using TypeAlias;

public class LoginDialog : UiDialog
{
    public InputField ServerInput;
    public InputField IdInput;
    public InputField PasswordInput;
    public Text MessageText;

    private bool _isLoginBusy;
    private IUserEventObserver _userEventObserver;

    public override void OnShow(object param)
    {
        _userEventObserver = (IUserEventObserver)param;

        var loginServer = PlayerPrefs.GetString("LoginServer", "127.0.0.1:9001");
        var loginId = PlayerPrefs.GetString("LoginId", "test");
        var loginPassword = PlayerPrefs.GetString("LoginPassword", "<PASSWORD>");

        ServerInput.text = loginServer;
        IdInput.text = loginId;
        PasswordInput.text = loginPassword;

        SetMessage(null);
    }

    public void OnLoginButtonClick()
    {
        if (_isLoginBusy)
            return;

        _isLoginBusy = true;
        SetMessage(null);

        PlayerPrefs.SetString("LoginServer", ServerInput.text);
        PlayerPrefs.SetString("LoginId", IdInput.text);
        PlayerPrefs.SetString("LoginPassword", PasswordInput.text);

        StartCoroutine(ProcessLogin(ServerInput.text, IdInput.text, PasswordInput.text));
    }

    private IEnumerator ProcessLogin(string server, string id, string password)
    {
        try
        {
            IPEndPoint serverEndPoint;
            try
            {
                serverEndPoint = CreateIPEndPoint(server);
            }
            catch (Exception e)
            {
                SetMessage(e.ToString());
                yield break;
            }

            G.Comm = CommunicatorHelper.CreateCommunicator<DomainProtobufSerializer>(G.Logger, serverEndPoint);
            G.Comm.Start();

            // Try Login

            var userLogin = G.Comm.CreateRef<UserLoginRef>();
            var observer = G.Comm.CreateObserver<IUserEventObserver>(_userEventObserver);
            var t1 = userLogin.Login(id, password, observer);
            yield return t1.WaitHandle;
            if (t1.Exception != null)
            {
                var re = t1.Exception as ResultException;
                if (re != null)
                {
                    SetMessage(re.ResultCode.ToString());
                }
                else
                {
                    SetMessage(t1.Exception.ToString());
                }
                yield break;
            }

            G.User = (UserRef)t1.Result;
            G.UserId = id;
            Hide(id);
        }
        finally
        {
            _isLoginBusy = false;
        }<commit_msg>Add missing dispose<commit_after>﻿using System;
using System.Collections;
using System.Net;
using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using Domain;
using Akka.Interfaced.SlimSocket.Client;
using Akka.Interfaced.SlimSocket.Base;
using Common.Logging;
using TypeAlias;

public class LoginDialog : UiDialog
{
    public InputField ServerInput;
    public InputField IdInput;
    public InputField PasswordInput;
    public Text MessageText;

    private bool _isLoginBusy;
    private IUserEventObserver _userEventObserver;

    public override void OnShow(object param)
    {
        _userEventObserver = (IUserEventObserver)param;

        var loginServer = PlayerPrefs.GetString("LoginServer", "127.0.0.1:9001");
        var loginId = PlayerPrefs.GetString("LoginId", "test");
        var loginPassword = PlayerPrefs.GetString("LoginPassword", "<PASSWORD>");

        ServerInput.text = loginServer;
        IdInput.text = loginId;
        PasswordInput.text = loginPassword;

        SetMessage(null);
    }

    public void OnLoginButtonClick()
    {
        if (_isLoginBusy)
            return;

        _isLoginBusy = true;
        SetMessage(null);

        PlayerPrefs.SetString("LoginServer", ServerInput.text);
        PlayerPrefs.SetString("LoginId", IdInput.text);
        PlayerPrefs.SetString("LoginPassword", PasswordInput.text);

        StartCoroutine(ProcessLogin(ServerInput.text, IdInput.text, PasswordInput.text));
    }

    private IEnumerator ProcessLogin(string server, string id, string password)
    {
        try
        {
            IPEndPoint serverEndPoint;
            try
            {
                serverEndPoint = CreateIPEndPoint(server);
            }
            catch (Exception e)
            {
                SetMessage(e.ToString());
                yield break;
            }

            G.Comm = CommunicatorHelper.CreateCommunicator<DomainProtobufSerializer>(G.Logger, serverEndPoint);
            G.Comm.Start();

            // Try Login

            var userLogin = G.Comm.CreateRef<UserLoginRef>();
            var observer = G.Comm.CreateObserver<IUserEventObserver>(_userEventObserver);
            var t1 = userLogin.Login(id, password, observer);
            yield return t1.WaitHandle;
            if (t1.Exception != null)
            {
                observer.Dispose();
                var re = t1.Exception as ResultException;
                if (re != null)
                {
                    SetMessage(re.ResultCode.ToString());
                }
                else
                {
                    SetMessage(t1.Exception.ToString());
                }
                yield break;
            }

            G.User = (UserRef)t1.Result;
            G.UserId = id;
            Hide(id);
        }
        finally
        {
            _isLoginBusy = false;
        }
{'fraction_non_alphanumeric': 0.08922969675845242, 'fraction_numerical': 0.0055768560474032764, 'mean_word_length': 1.9385560675883255, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7149602', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1498, 'n_words': 311}