Exemplo n.º 1
0
    public static void SetClient(TcpClient client, string name)
    {
        if (tcpClient == null)
        {
            tcpClient = client;
        }
        else
        {
            WriteToServer("MD CLOSE\n");
            tcpClient.Close();
            tcpClient = client;
        }
        name      = name.Trim(' ');
        Name      = name;
        netStream = client.GetStream();
        TimeOutFlag   timeOutFlag   = new TimeOutFlag();
        FlagInterface flagInterface = new FlagInterface();

        activeFlagInterface = flagInterface;


        singleton.StartCoroutine(singleton.TimeOutRoutine(timeOutFlag));
        singleton.StartCoroutine(singleton.InterfaceRoutine(flagInterface, timeOutFlag));

        clientThread = new Thread(new ParameterizedThreadStart(ClientSideThread));
        clientThread.Start(flagInterface); //WE ARE WORKING BABY!
    }
Exemplo n.º 2
0
    private IEnumerator InterfaceRoutine(FlagInterface flag, TimeOutFlag timeOutFlag)
    {
        while (tcpClient != null)
        {
            yield return(new WaitForEndOfFrame());

            while (flag.gameInterfaceFlags.Count != 0)
            {
                var processed = flag.gameInterfaceFlags.Dequeue();
                switch (processed.interfaceMessage)
                {
                case InterfaceMessage.resetTimeout:
                    timeOutFlag.resetTimer = true;
                    break;

                case InterfaceMessage.raiseError:
                    ErrorScene.LoadError(processed.msg);
                    break;

                case InterfaceMessage.gameStart:
                    SceneManager.LoadScene("Game");
                    latestOpponentName = processed.msg;
                    break;

                case InterfaceMessage.enableQueueMenu:
                    MenuUX.GetSingleton().RevealQueue();
                    break;

                case InterfaceMessage.updateEnqueuedNumber:
                    MenuUX.GetSingleton().UpdateEnqueuedNumber((int)processed.val);
                    break;

                case InterfaceMessage.updateGameServerPos:
                    GameManager.GetSingleton().UpdateServerPos(processed.val);
                    break;

                case InterfaceMessage.updateGameOpponentPos:
                    GameManager.GetSingleton().UpdateOpponentPos(processed.val);
                    break;

                case InterfaceMessage.updateLocalPlayerPos:
                    GameManager.GetSingleton().UpdateLocalPlayerPos(processed.val);
                    break;
                }
            }
        }
    }
Exemplo n.º 3
0
    private IEnumerator TimeOutRoutine(TimeOutFlag flag)
    {
        while (true)
        {
            float time = timeOutTime;
            while (time >= 0)
            {
                yield return(new WaitForEndOfFrame());

                time -= Time.deltaTime;
                if (flag.resetTimer)
                {
                    flag.resetTimer = false;
                    time            = timeOutTime;
                }
                if (flag.exit)
                {
                    yield break;
                }
            }
            EnqueueClientThreadCloseFlag(activeFlagInterface);
            EnqueueErrorFlag(activeFlagInterface, "Connection to server timed out.");
        }
    }