Ejemplo n.º 1
0
    /// <summary>
    /// 连接按钮
    /// </summary>
    public void ConnectSever()
    {
        //ip不符合格式
        if (!Regex.IsMatch(ip_Text.text, @"\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b"))
        {
            warringText.text = "";
            warringText.text = "ip格式不对";
            return;
        }

        string m_name = name_Text.text;

        //没有昵称
        if (m_name == "")
        {
            warringText.text = "";
            warringText.text = "输入昵称";
            return;
        }

        if (m_name.Contains("#"))
        {
            warringText.text = "";
            warringText.text = "昵称中不能有#";
            return;
        }

        //连接服务器
        try
        {
            m_client.Init(ip_Text.text, m_name, ShowMessage);
        }
        catch
        {
            warringText.text = "";
            warringText.text = "连接不到服务器";
            return;
        }
    }