Ejemplo n.º 1
0
    public void OnEventHandling(NetEventState state)
    {
        switch (state.type)
        {
        case NetEventType.Connect:
            if (transport.IsServer())
            {
                Debug.Log("서버입장");
            }
            else
            {
                Debug.Log("고객");
            }
            break;

        case NetEventType.Disconnect:
            if (transport.IsServer())
            {
                Debug.Log("서버가 나갔습니다.");
            }
            else
            {
                Debug.Log("고객이 나갔습니다.");
            }
            break;
        }
    }
Ejemplo n.º 2
0
    // 상대의 턴일 때의 처리.
    bool DoOppnentTurn()
    {
        // 상대의 정보를 수신합니다.
        byte[] buffer   = new byte[1];
        int    recvSize = m_transport.Receive(ref buffer, buffer.Length);

        if (recvSize <= 0)
        {
            // 아직 수신되지 않았습니다.
            return(false);
        }

        // 서버라면 ○ 클라이언트라면 ×를 지정합니다.
        //Mark mark = (m_network.IsServer() == true)? Mark.Cross : Mark.Circle;

        // 수신한 정보를 선택된 칸으로 변환합니다.
        int index = (int)buffer[0];

        Debug.Log("Recv:" + index + " [" + m_transport.IsServer() + "]");

        // 칸에 둡니다.
        //bool ret = SetMarkToSpace(index, mark);
        bool ret = SetMarkToSpace(index, remoteMark);

        if (ret == false)
        {
            // 둘 수 없다.
            return(false);
        }

        return(true);
    }
Ejemplo n.º 3
0
    public void OnEventHandling(NetEventState state)
    {
        switch (state.type)
        {
        case NetEventType.Connect:
            if (m_transport.IsServer())
            {
                AddMessage(ref m_messages, "[System] Client Joinned!");
            }
            else
            {
                AddMessage(ref m_messages, "[System] Start Chat!");
            }
            break;

        case NetEventType.Disconnect:
            if (m_transport.IsServer())
            {
                AddMessage(ref m_messages, "[System] Server Leaved");
            }
            else
            {
                AddMessage(ref m_messages, "[System] Client leaved");
            }
            break;
        }
    }
Ejemplo n.º 4
0
    void Start()
    {
        logic = transform.Find("Logic").GetComponent <Logic>();
        field = transform.Find("Field").GetComponent <Field>();

        /* 初期配置 */

        logic.Set(Logic.c_sizeOfField / 2 - 1, Logic.c_sizeOfField / 2 - 1, false);
        logic.Set(Logic.c_sizeOfField / 2, Logic.c_sizeOfField / 2 - 1, true);
        logic.Set(Logic.c_sizeOfField / 2 - 1, Logic.c_sizeOfField / 2, true);
        logic.Set(Logic.c_sizeOfField / 2, Logic.c_sizeOfField / 2, false);

        turnUI.transform.position = new Vector3(turnUI.transform.position.x, 365.0f, turnUI.transform.position.z);

        transport = GameObject.Find("Network").GetComponent <TransportTCP>();
        if (transport.IsServer())
        {
            isPlayerBlack = true;
            Debug.Log("あなたは先行です");
        }
        else
        {
            isPlayerBlack = false;
            Debug.Log("あなたは後攻です");
        }
    }
Ejemplo n.º 5
0
    public void OnEventHandling(NetEventState state)
    {
        switch (state.type)
        {
        case NetEventType.Connect:
            if (m_transport.IsServer())
            {
            }
            else
            {
            }
            break;

        case NetEventType.Disconnect:
            if (m_transport.IsServer())
            {
            }
            else
            {
            }
            break;
        }
    }
Ejemplo n.º 6
0
    void ChattingGUI()
    {
        Rect commentRect = new Rect(635, 1020, 520, 30);

        m_sendComment = GUI.TextField(commentRect, m_sendComment, 15);

        bool isSent = GUI.Button(new Rect(1165, 1020, 117, 30), "말하기");

        if (Event.current.isKey &&
            Event.current.keyCode == KeyCode.Return)
        {
            if (m_sendComment == m_prevComment)
            {
                isSent        = true;
                m_prevComment = "";
            }
            else
            {
                m_prevComment = m_sendComment;
            }
        }

        if (isSent == true)
        {
            string message = "[" + DateTime.Now.ToString("HH:mm") + "] " + m_sendComment;
            byte[] buffer  = System.Text.Encoding.UTF8.GetBytes(message);
            m_transport.Send(buffer, buffer.Length);
            AddMessage(ref m_message[(m_isServer == true) ? 0 : 1], message);
            m_sendComment = "";
        }

        if (GUI.Button(new Rect(1820, 1020, 80, 30), "나가기"))
        {
            menuPanel.SetActive(true);
            gamePlayer.SetActive(false);
            rivalPlayer.SetActive(false);
            coinImage.SetActive(false);
            myScore.SetActive(false);
            rivalScore.SetActive(false);
            chattingBox.SetActive(false);
            m_state = GameState.LEAVE;
        }


        if (m_transport.IsServer() || m_transport.IsServer() == false && m_transport.IsConnected())
        {
            DispBalloon(ref m_message[0], new Vector2(810.0f, 875.0f), new Vector2(340.0f, 360.0f), Color.cyan, true, 0);
        }

        if (m_transport.IsServer() == false || m_transport.IsServer() && m_transport.IsConnected())
        {
            DispBalloon(ref m_message[1], new Vector2(1120.0f, 875.0f), new Vector2(340.0f, 360.0f), Color.green, false, 1);
        }
    }
Ejemplo n.º 7
0
    void ChattingGUI()
    {
        Rect commentRect = new Rect(220, 450, 300, 30);

        m_sendComment = GUI.TextField(commentRect, m_sendComment, 15);

        bool isSent = GUI.Button(new Rect(530, 450, 100, 30), "しゃべる");

        if (Event.current.isKey &&
            Event.current.keyCode == KeyCode.Return)
        {
            if (m_sendComment == m_prevComment)
            {
                isSent        = true;
                m_prevComment = "";
            }
            else
            {
                m_prevComment = m_sendComment;
            }
        }

        if (isSent == true)
        {
            string message = "[" + DateTime.Now.ToString("HH:mm:ss") + "] " + m_sendComment;
            byte[] buffer  = System.Text.Encoding.UTF8.GetBytes(message);
            m_transport.Send(buffer, buffer.Length);
            AddMessage(ref m_message[(m_isServer == true)? 0 : 1], message);
            m_sendComment = "";
        }

        if (GUI.Button(new Rect(700, 560, 80, 30), "退出"))
        {
            m_state = ChatState.LEAVE;
        }

        // とうふやさん(サーバ側)のメッセージ表示.
        if (m_transport.IsServer() ||
            m_transport.IsServer() == false && m_transport.IsConnected())
        {
            DispBalloon(ref m_message[0], new Vector2(200.0f, 200.0f), new Vector2(340.0f, 360.0f), Color.cyan, true);
            GUI.DrawTexture(new Rect(50.0f, 370.0f, 145.0f, 200.0f), this.texture_tofu);
        }

        if (m_transport.IsServer() == false ||
            m_transport.IsServer() && m_transport.IsConnected())
        {
            // だいずやさんの(クライアント側)のメッセージ表示.
            DispBalloon(ref m_message[1], new Vector2(600.0f, 200.0f), new Vector2(340.0f, 360.0f), Color.green, false);
            GUI.DrawTexture(new Rect(600.0f, 370.0f, 145.0f, 200.0f), this.texture_daizu);
        }
    }
Ejemplo n.º 8
0
    void ChattingGUI()
    {
        Rect commentRect = new Rect(220, 450, 300, 30);

        m_sendComment = GUI.TextField(commentRect, m_sendComment, 15);

        bool isSent = GUI.Button(new Rect(530, 450, 100, 30), "말하기");

        if (Event.current.isKey &&
            Event.current.keyCode == KeyCode.Return)
        {
            if (m_sendComment == m_prevComment)
            {
                isSent        = true;
                m_prevComment = "";
            }
            else
            {
                m_prevComment = m_sendComment;
            }
        }

        if (isSent == true)
        {
            string message = "[" + DateTime.Now.ToString("HH:mm:ss") + "] " + m_sendComment;
            byte[] buffer  = System.Text.Encoding.UTF8.GetBytes(message);
            m_transport.Send(buffer, buffer.Length);
            AddMessage(ref m_message[(m_isServer == true)? 0 : 1], message);
            m_sendComment = "";
        }

        if (GUI.Button(new Rect(700, 560, 80, 30), "나가기"))
        {
            m_state = ChatState.LEAVE;
        }

        // 두부장수(서버 측)이 메시지 표시.
        if (m_transport.IsServer() ||                                     //내가 서버거나
            m_transport.IsServer() == false && m_transport.IsConnected()) //클라이언트라면 서버에 붙었거나
        {
            DispBalloon(ref m_message[0], new Vector2(200.0f, 200.0f), new Vector2(340.0f, 360.0f), Color.cyan, true);
            GUI.DrawTexture(new Rect(50.0f, 370.0f, 145.0f, 200.0f), this.texture_tofu);
        }

        if (m_transport.IsServer() == false ||                   //내가 클라이언트이거나
            m_transport.IsServer() && m_transport.IsConnected()) //서버라면 클라이언트가 붙었다면
        // 콩장수의(클라이언트 측) 메시지 표시.
        {
            DispBalloon(ref m_message[1], new Vector2(600.0f, 200.0f), new Vector2(340.0f, 360.0f), Color.green, false);
            GUI.DrawTexture(new Rect(600.0f, 370.0f, 145.0f, 200.0f), this.texture_daizu);
        }
    }
Ejemplo n.º 9
0
 void OnGUI()
 {
     if (isSelected == false)
     {
         OnGUISelectHost();
     }
     else
     {
         if (m_transport.IsServer() == true)
         {
             OnGUIServer();
         }
         else
         {
             OnGUIClient();
         }
     }
 }
Ejemplo n.º 10
0
    void ChattingGUI()
    {
        Rect commentRect = new Rect(10, 250, 100, 30);

        m_sendComment = GUI.TextField(commentRect, m_sendComment, 15);

        bool isSent = GUI.Button(new Rect(110, 250, 100, 30), "말하기");

        if (Event.current.isKey &&
            Event.current.keyCode == KeyCode.Return)
        {
            if (m_sendComment == m_prevComment)
            {
                isSent        = true;
                m_prevComment = "";
            }
            else
            {
                m_prevComment = m_sendComment;
            }
        }

        if (isSent == true)
        {
            string message = "[" + DateTime.Now.ToString("HH:mm:ss") + "] " + m_sendComment;
            byte[] buffer  = System.Text.Encoding.UTF8.GetBytes(message);
            m_transport.Send(buffer, buffer.Length);
            AddMessage(ref m_message[(m_isServer == true)? 0 : 1], message);
            m_sendComment = "";
        }
        if (serv == 1)
        {
            if (GUI.Button(new Rect(110, 280, 100, 30), " 게임시작"))
            {
                //m_state = ChatState.LEAVE;
                Network.InitializeServer(2, m_port, false);
            }
        }
        if (cli == 1)
        {
            if (GUI.Button(new Rect(110, 280, 100, 30), " 게임참가"))
            {
                Network.Connect(m_hostAddress, m_port);
            }
        }



        if (exit == 0)
        {
            if (GUI.Button(new Rect(120, 360, 80, 30), "나가기"))
            {
                m_state = ChatState.LEAVE;
            }
        }

        // 서버 메지 표시.
        if (m_transport.IsServer() ||
            m_transport.IsServer() == false && m_transport.IsConnected())
        {
            DispBalloon(ref m_message[0], new Vector2(180.0f, 200.0f), new Vector2(340.0f, 360.0f), Color.cyan, true);
        }

        if (m_transport.IsServer() == false ||
            m_transport.IsServer() && m_transport.IsConnected())
        {
            //클라이언트가 말하는 메시지 표시.
            DispBalloon(ref m_message[1], new Vector2(300.0f, 200.0f), new Vector2(340.0f, 360.0f), Color.green, false);
        }
    }
Ejemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
#if USE_TRANSPORT_TCP
        if (m_transport != null && m_transport.IsConnected() == true)
        {
#else
        if (m_transport != null)
        {
#endif
            byte[] buffer   = new byte[m_mtu];
            int    recvSize = m_transport.Receive(ref buffer, buffer.Length);
            if (recvSize > 0)
            {
                string message = System.Text.Encoding.UTF8.GetString(buffer);
                Debug.Log(message);
            }
        }
    }

    void OnGUI()
    {
        if (isSelected == false)
        {
            OnGUISelectHost();
        }
        else
        {
            if (m_transport.IsServer() == true)
            {
                OnGUIServer();
            }
            else
            {
                OnGUIClient();
            }
        }
    }

    void OnGUISelectHost()
    {
#if USE_TRANSPORT_TCP
        if (GUI.Button(new Rect(20, 40, 150, 20), "Launch server."))
        {
#else
        if (GUI.Button(new Rect(20, 40, 150, 20), "Launch Listener."))
        {
#endif
            m_transport.StartServer(m_port, 1);
            isSelected = true;
        }

        // 클라이언트를 선택했을 때 접속할 서버 주소를 입력합니다.
        m_strings = GUI.TextField(new Rect(20, 100, 200, 20), m_strings);
#if USE_TRANSPORT_TCP
        if (GUI.Button(new Rect(20, 70, 150, 20), "Connect to server"))
        {
#else
        if (GUI.Button(new Rect(20, 70, 150, 20), "Connect to terminal"))
        {
#endif
            m_transport.Connect(m_strings, m_port);
            isSelected = true;
            m_strings  = "";
        }
    }

    void OnGUIServer()
    {
#if USE_TRANSPORT_TCP
        if (GUI.Button(new Rect(20, 60, 150, 20), "Stop server"))
        {
#else
        if (GUI.Button(new Rect(20, 60, 150, 20), "Stop Listener"))
        {
#endif
            m_transport.StopServer();
            isSelected = false;
            m_strings  = "";
        }
    }

    void OnGUIClient()
    {
        // 클라이언트를 선택했을 때 접속할 서버의 주소를 입력합니다.
        if (GUI.Button(new Rect(20, 70, 150, 20), "Send message"))
        {
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes("Hellow, this is client.");
            m_transport.Send(buffer, buffer.Length);
        }

        if (GUI.Button(new Rect(20, 100, 150, 20), "Disconnect"))
        {
            m_transport.Disconnect();
            isSelected = false;
            m_strings  = "";
        }
    }
}