Example #1
0
    private void Update()
    {
        if (socketReady)
        {
            try
            {
                if (stream.DataAvailable)
                {
                    StreamReader reader = new StreamReader(stream, true);
                    string       data;
                    //              Debug.Log("Got here! - 1");

                    //     while ((data = reader.ReadLine()) != null)
                    //           {
                    data = reader.ReadLine();
                    //            Debug.Log(data);

                    /*              try
                     *            {
                     *    //            string data2;
                     * //                   bool thing = (data2 = reader.ReadLine())==null;
                     * //                    Debug.Log(thing);
                     *            }catch(Exception e)
                     *            {
                     *                Debug.Log(e);
                     *            } */

                    int selection = Int32.Parse(data.Substring(0, 3));
                    Debug.Log(selection);
                    //           Debug.Log(data.Substring(3));
                    switch (selection)
                    {
                    case 0:
                        OnIncomingData(data.Substring(3));
                        break;

                    case 10:
                        MultiLineInput(data.Substring(3));
                        break;

                    case 1:
                        ChangeCredits(data.Substring(3));
                        break;

                    case 3:
                        BeginHack();
                        break;

                    case 4:
                        EnterComputer();
                        break;

                    case 6:
                        CreateMap(data.Substring(3));
                        gotMapFromServer = true;
                        break;

                    case 16:
                        UpdateMapPiece(data.Substring(3));
                        break;

                    case 99:
                        //         Debug.Log(clientName + " was changed to " + data.Substring(3));
                        clientName = data.Substring(3);
                        loginPage.Login();
                        UpdateCurrency(0);
                        break;

                    case 199:
                        loginPage.LoginError(1);
                        CloseSocket();
                        break;

                    case 299:
                        loginPage.LoginError(2);
                        CloseSocket();
                        break;

                    case 399:
                        loginPage.LoginError(3);
                        CloseSocket();
                        break;

                    case 999:
                        CloseSocket();
                        break;
                    }
                    //       }
                }
            }
            catch (Exception e)
            {
                Debug.Log(e);
            }
        }
        if (Input.GetMouseButtonDown(1))
        {
            //   Debug.Log(mouseOptionLocation);
            CloseOptionMenus();
            if (mouseOptionLocation != null && !mouseOptionLocation.Equals("Untagged"))
            {
                OptionsManager.GetComponent <OptionsManager>().CreateOption(mouseOptionLocation);
                optionsOn = true;
            }
        }
        if (optionsOn && Input.GetMouseButtonDown(0))
        {
            Invoke("CloseOptionMenus", 0.2f);
        }
    }