Пример #1
0
    private IEnumerator Start()
    {
        while (!Kill2Live.Ready())
        {
            yield return(null);
        }
        if (tou != null)
        {
            Debug.Log("Loading TOU...");

            ResourceRequest txtAsync = Resources.LoadAsync("Translations/tou_" +
                                                           Language.l.ToString(), typeof(TextAsset));

            while (!txtAsync.isDone)
            {
                yield return(null);
            }

            if (txtAsync.asset != null)
            {
                TextAsset txtAsset = txtAsync.asset as TextAsset;
                tou.text = txtAsset.text;
            }
        }
    }
Пример #2
0
    private void Awake()
    {
        // quality settings
        QualitySettings.SetQualityLevel(1, true);
        Application.targetFrameRate = 60;
        Application.runInBackground = true;

        // set itself for static access
        self = this;

        // resolution
        Screen.SetResolution(resolutionX, resolutionY, false);
    }
Пример #3
0
    /// <summary>
    /// Chooses a character for the match
    /// </summary>
    /// <param name="cid"></param>
    /// <param name="r"></param>
    /// <returns></returns>
    public bool Choose(int cid, UDPPacket r = null)
    {
        if (r == null)
        {
            // if the user is not logged in or match type is none, restart
            if (!Account.IsLoggedIn() || cid == 0)
            {
                Kill2Live.Restart();
                return(false);
            }
            Debug.Log("Choosing a character: " + cid.ToString() + " ...");

            Event e = Match.self.activeEvent;
            e.User = Account.GetUser();
            e.Me   = new Player
            {
                Character = cid
            };

            // request
            string j = JsonConvert.SerializeObject(e);
            UDP.Request(new UDPPacket
            {
                Service = UDPService.Match,
                Action  = UDPAction.Choose,
                Request = j,
            });
            return(false);
        }
        else
        {
            if (r.Error != 0 || r.Response == null)
            {
                UIMessageGlobal.Open(Language.v["choosefailed"],
                                     Language.v["choosefaileddesc"]);
                Debug.LogWarning(r.ToString());
                return(false);
            }
            Debug.Log("Chosen: " + r.Response);

            Event e = JsonConvert.DeserializeObject <Event>(r.Response);
            Match.self.activeEvent.Me.Character = e.Me.Character;

            UIPlayers.Set(Account.GetUser().Nickname, e.Me.Character);

            // TODO update ui
            uiChoose.SetActive(false);

            return(true);
        }
    }
Пример #4
0
    public bool Leave(UDPPacket r = null, bool quit = false)
    {
        if (r == null)
        {
            // if the user is not logged in, restart
            if (!Account.IsLoggedIn())
            {
                if (!quit)
                {
                    Kill2Live.Restart();
                }
                return(false);
            }
            Debug.Log("Leaving the match...");

            Reset();
            uiPlay.SetActive(false);
            uiJoin.SetActive(true);

            Event e = new Event
            {
                User = Account.GetUser(),
            };

            // request
            string j = JsonConvert.SerializeObject(e);
            UDP.Request(new UDPPacket
            {
                Service = UDPService.Match,
                Action  = UDPAction.Leave,
                Request = j,
            });
            return(false);
        }
        else
        {
            if (r.Error != 0)
            {
                if (r.Error >= (int)ServiceError.MatchUnknown)
                {
                    UIMessageGlobal.Open(Language.v["leavefailed"],
                                         Language.v["leavefaileddesc"]);
                    Debug.LogWarning(r.ToString());
                }
                return(false);
            }

            return(true);
        }
    }
Пример #5
0
    /// <summary>
    /// Resolves the host name and starts the listener on a different thread
    /// </summary>
    void Start()
    {
        // load scripts
        main      = GetComponent <Kill2Live>();
        account   = GetComponent <Account>();
        match     = GetComponent <Match>();
        character = GetComponent <Character>();
        server    = GetComponent <Server>();
        cli       = FindObjectOfType <Client>();

        endPoint = new IPEndPoint(IPAddress.Any, 0);
        if (config == null)
        {
            return;
        }

        // reserve a port for client
        int port = 0;

        do
        {
            port = UnityEngine.Random.Range(10000, 60000);
            try
            {
                client = new UdpClient(port);
                client.Client.SendTimeout = config.requestTimeout;
            }
            catch (Exception exc)
            {
                port = 0;
                Debug.LogError(exc);
            }
        } while (port == 0);

        if (client != null)
        {
            Debug.Log("UDP Listening @ " + port + " ...");
            listener = new Thread(new ThreadStart(Translate));
            listener.IsBackground = true;
            listener.Start();
            ready = true;
        }
    }
Пример #6
0
    private void Start()
    {
        canvas = FindObjectOfType <Canvas>();

        // debug
        if (Account.GetUser() == null && (Match.self == null ||
                                          Match.self.activeEvent == null) &&
            debugAccountId != "" && debugMatchId != "")
        {
            Instantiate(debugLobbyPrefab, null);
            StartCoroutine(Debugger());
        }
        else
        {
            // e.User = Account.GetUser();
            e = Match.self.activeEvent;
        }

        k2l = FindObjectOfType <Kill2Live>();
        StartCoroutine(Network());
    }
Пример #7
0
    public IEnumerator Ready(int timerOverride = 0)
    {
        leaveBtn.interactable = false;
        if (timerOverride == 0)
        {
            timer = Match.self.matchReadyTimer;
        }
        else
        {
            timer = timerOverride;
        }
        while (timer > 0)
        {
            yield return(new WaitForSeconds(1));

            timer--;
            timerText.text = timer.ToString();
        }
        timer          = 0;
        timerText.text = "--";

        Kill2Live.Client();
    }
Пример #8
0
    /// <summary>
    /// Find and join into a game.
    /// </summary>
    /// <param name="type"></param>
    /// <param name="r"></param>
    public bool Join(MatchType typ = MatchType.None, UDPPacket r = null)
    {
        if (r == null)
        {
            // if the user is not logged in or match type is none, restart
            if (!Account.IsLoggedIn())
            {
                Kill2Live.Restart();
                return(false);
            }
            Debug.Log("Finding a match for " + typ.ToString() + " ...");

            Event e = new Event
            {
                User = Account.GetUser(),
                M    = new Game
                {
                    Typ = typ,
                }
            };

            // request
            string j = JsonConvert.SerializeObject(e);
            UDP.Request(new UDPPacket
            {
                Service = UDPService.Match,
                Action  = UDPAction.Join,
                Request = j,
            });
            return(false);
        }
        else
        {
            if (r.Error != 0)
            {
                if (r.Error == (int)ServiceError.AlreadyJoined)
                {
                    // continue
                    // no return here because of this situation
                }
                else if (r.Error >= (int)ServiceError.MatchUnknown)
                {
                    UIMessageGlobal.Open(Language.v["joinfailed"],
                                         Language.v["joinfaileddesc"]);
                    Debug.LogWarning(r.ToString());
                    return(false);
                }
            }
            Debug.Log("Joining: " + r.Response);

            Event e = JsonConvert.DeserializeObject <Event>(r.Response);
            if (e.M.Typ == MatchType.None)
            {
                return(false);
            }
            activeEvent = e;

            if (e.M.Status == MatchStatus.Reserved) // still creating a match
            {
                if (!refreshing)
                {
                    refreshing = true;
                    InvokeRepeating("PlayersLoop", 0f, refresh);
                }
            }
            else
            {
                if (e.M.Status == MatchStatus.Ready ||
                    e.M.Status == MatchStatus.Play)
                {
                    Players();
                }
                else if (e.M.Status == MatchStatus.End ||
                         e.M.Status == MatchStatus.Released)
                {
                    activeEvent = null;
                    UIPlayers.Clear();
                    return(false);
                }
            }
            return(true);
        }
    }