Exemple #1
0
//#SHOW02_1 Logon GUI code here. No work yet.
    void OnGUI()
    {
        if (m_state == MyState.Disconnected || m_state == MyState.Connecting)
        {
            GUI.Label(new Rect(10, 10, 300, 30), "## ProudNet Sample ##");

            GUI.Label(new Rect(10, 30, 300, 30), "Enter your ID, password here.");
            m_userID   = GUI.TextField(new Rect(10, 60, 200, 30), m_userID);
            m_password = GUI.TextField(new Rect(10, 90, 200, 30), m_password);

            if (m_state == MyState.Disconnected)
            {
                if (GUI.Button(new Rect(10, 130, 100, 20), "Login!"))
                {
                    // #SHOW09 Connection request
                    var connectParam = new NetConnectionParam();
                    connectParam.protocolVersion = new Guid();
                    connectParam.protocolVersion.Set(Version);
                    connectParam.serverIP   = "localhost";
                    connectParam.serverPort = ServerPort;

                    m_netClient.Connect(connectParam);
                    m_state = MyState.Connecting;
                }
            }
            if (m_state == MyState.Connecting)
            {
                GUI.Button(new Rect(10, 130, 100, 20), "Connecting...");
            }
        }
    }
Exemple #2
0
    public NetConnectionParam GetNetworkParam()
    {
        NetConnectionParam clientParam = new NetConnectionParam();

        // QQQ 로컬 테스트용 서버 IP 적용

/*#if UNITY_EDITOR
 *      var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
 *
 *      foreach(var ip in host.AddressList)
 *      {
 *          if(ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
 *          {
 *              _serverAddress = ip.ToString();
 *              break;
 *          }
 *      }
 #endif*/

        clientParam.serverIP        = _serverAddress;
        clientParam.serverPort      = _port;
        clientParam.protocolVersion = new Guid("{0xc88b40fb,0x9260,0x4c77,{0x89,0x63,0x79,0x3c,0x9,0xc2,0xc6,0x76}}");
        clientParam.enableAutoConnectionRecovery = true;

        return(clientParam);
    }
    // 로그인 시도
    public void GetLogin(string _id, string _password)
    {
        // 로그인 캔버스에서 로딩 캔버스로 전환
        GameObject.Find("UIManager").GetComponent <SceneChange>().I_LoginToLoading();

        // 아이디 비밀번호 업데이트
        m_userID   = _id;
        m_password = _password;

        m_proxy.RequestLogin(HostID.HostID_Server,
                             RmiContext.SecureReliableSend, m_userID, m_password);

        if (m_state == MyState.Disconnected)             // 연결되지 않은상태이면
        {
            var connectParam = new NetConnectionParam(); // 연결은 위한 config 작성
            connectParam.protocolVersion = new Guid();
            connectParam.protocolVersion.Set(Version);   // 프로토콜 버전은 서버와 동일하게
            connectParam.serverIP   = "localhost";       // 서버 IP
            connectParam.serverPort = ServerPort;        // 서버 포트 값

            m_Client.Connect(connectParam);              // 연결 시도.
            m_state = MyState.Connecting;                // 연결 중으로 변경.
        }
        else
        {
            //Debug.Log("서버 연결 오류");
        }
    }
Exemple #4
0
    public void IssueConnect()
    {
        m_eState = eState.InVille;
        NetConnectionParam cp = new NetConnectionParam();

        cp.serverIP   = m_szServerAddr;
        cp.serverPort = 12349;
        // 프로토콜 버전 : 서버랑 클라이언트랑 버전이 같은지 판별, 두 버전이 같을 때만 접속이 허가됩니다.
        cp.protocolVersion = new Guid("{0x9213733,0x4631,0x4034,{0x90,0x58,0xbf,0xe6,0x23,0x53,0x9b,0xff}}");
        // 이 함수는 비동기로 실행됩니다. 그래서 호출을 하면 바로 리턴하고 백그라운드로 서버와 연결이 진행됩니다.
        m_netClient.Connect(cp);
    }
        // returns client instance ID
        public int Create(NetConnectionParam connectionParam)
        {
            System.Uri uri = new Uri(connectionParam.serverIP);

            string protocol = uri.Scheme;

            if (!protocol.Equals("ws") && !protocol.Equals("wss"))
            {
                throw new ArgumentException("Unsupported protocol: " + protocol);
            }

            return(CreateJSClient(uri.ToString(), Misc.Base64Encode(connectionParam.protocolVersion.ToByteArray()),
                                  connectionParam.userData.data == null ? "" : Misc.Base64Encode(connectionParam.userData.data), Misc.GetInternalVersion()));
        }
Exemple #6
0
        public bool Connect(NetConnectionParam param)
        {
            // Javascript는 멀티스레드로 동작하지 않으며 Connect시 콜백으로 수행되는 것도 없기 때문에 참조복사도 괜찮다.
            m_connectionParam = param;

            m_clientInstanceID = m_jsClient.Create(m_connectionParam);

            if (!m_callbackRegistered)
            {
                RegisterCallbacks();
                m_callbackRegistered = true;
            }

            // javascript에서 생성한 instanceID가 0이상이면 성공으로 간주한다.
            return(m_clientInstanceID >= 0);
        }
Exemple #7
0
    private void IssueConnect()
    {
        // prepare network client
        m_netClient.AttachProxy(m_C2SProxy);
        m_netClient.AttachStub(m_S2CStub);

        m_netClient.AttachProxy(m_C2CProxy);
        m_netClient.AttachStub(m_C2CStub);

        m_netClient.JoinServerCompleteHandler = (ErrorInfo info, ByteArray replyFromServer) =>
        {
            if (info.errorType == ErrorType.ErrorType_Ok)
            {
                m_state           = State.LoggingOn;
                m_loginButtonText = "Logging on...";

                // try to join the specified ville by name given by the user.
                m_C2SProxy.RequestLogon(HostID.HostID_Server, RmiContext.ReliableSend, m_villeName, false);
            }
            else
            {
                m_state           = State.Failed;
                m_loginButtonText = "FAIL!";
                m_failMessage     = info.ToString();
            }
        };

        // if the server connection is down, we should prepare for exit.
        m_netClient.LeaveServerHandler = (ErrorInfo info) =>
        {
            m_state       = State.Failed;
            m_failMessage = "Disconnected from server: " + info.ToString();
        };

        //fill parameters and go
        NetConnectionParam cp = new NetConnectionParam();

        cp.serverIP           = m_serverAddr;
        cp.clientAddrAtServer = "192.168.77.138";
        cp.serverPort         = 15001;
        cp.protocolVersion    = new Nettention.Proud.Guid("{0x4ea36ea0,0x3900,0x4b1d,{0xbb,0xde,0x3f,0xbf,0x42,0xf4,0xa,0x6b}}");

        m_netClient.Connect(cp);
    }
Exemple #8
0
    private void IssueConnect()
    {
        m_netClient.AttachProxy(m_C2SProxy);
        m_netClient.AttachStub(m_S2CStub);
        m_netClient.AttachProxy(m_C2CProxy);
        m_netClient.AttachStub(m_C2CStub);

        m_netClient.JoinServerCompleteHandler = (ErrorInfo info, ByteArray replyFromServer) =>
        {
            if (info.errorType == ErrorType.ErrorType_Ok)
            {
                m_state = State.LoggingOn;
                ServerRoom.instance.ServerJoinComplete();
                m_C2SProxy.RequestLogon(HostID.HostID_Server, RmiContext.ReliableSend, m_groupName, false);
                m_C2SProxy.RequestClientCount(HostID.HostID_Server, RmiContext.ReliableSend);
            }
            else
            {
                m_state = State.Failed;
                //m_failMessage = info.ToString();
            }
        };
        m_netClient.LeaveServerHandler = (ErrorInfo info) =>
        {
            m_state = State.Failed;
            //m_failMessage = "Disconnected from server: " + info.ToString();
        };


        NetConnectionParam cp = new NetConnectionParam();

        //cp.serverIP = "127.0.0.1";
        //cp.clientAddrAtServer = "127.0.0.1";
        cp.serverIP           = "112.166.83.92";
        cp.clientAddrAtServer = "112.166.83.92";
        //cp.serverIP = m_serverAddr;
        //cp.clientAddrAtServer = m_serverAddr;
        cp.serverPort      = 15005;
        cp.protocolVersion = new Nettention.Proud.Guid("{0x342e9077,0x4619,0x466f,{0xa9,0x34,0x1a,0x12,0x9f,0xde,0xa1,0xd}}");


        m_netClient.Connect(cp);
    }
Exemple #9
0
    void Start()
    {
        startPos = this.transform.position;

        c = new NetClient();
        NetConnectionParam cp = new NetConnectionParam();

        //Guid.ConvertStringToUUID(Version, cp.protocolVersion);
        cp.protocolVersion.Set(new System.Guid(Version));
        cp.serverIP   = "localhost";
        cp.serverPort = (ushort)serverPort;

        c.JoinServerCompleteHandler = (info, replyFromServer) =>
        {
            if (info.errorType == ErrorType.ErrorType_Ok)
            {
                print("Succeed to connect server. Allocated hostID=" + c.GetLocalHostID());
                GameObject.Find("JEEP_BODY").GetComponent <MeshRenderer>().material.color = Color.magenta;
            }
            else
            {
                // connection failure.
                print("Failed to connect server.\n");
                print("errorType = " + info.errorType);
            }
        };
        c.LeaveServerHandler = (errorInfo) =>
        {
            // show why disconnected.
            print("OnLeaveServer: " + errorInfo.comment);
        };

        stub.Move = (remote, ctx, x, y, z) =>
        {
            print("x: " + x);
            return(true);
        };

        c.AttachProxy(proxy);
        c.AttachStub(stub);
        c.Connect(cp);
    }
Exemple #10
0
        // Use this for initialization
        IEnumerator Start()
        {
            m_client          = new NetClient();
            m_connectionParam = new NetConnectionParam();

            m_simpleProxy = new Simple.Proxy();
            m_simpleStub  = new Simple.Stub();

            m_eventSink = new ClientEventSink(m_client, m_simpleProxy);

            m_myClass = new SimpleUnity.MyClass();

            m_simpleStub.ShowChat   = ShowChat;
            m_simpleStub.SystemChat = SystemChat;
            m_simpleStub.P2PChat    = P2PChat;

            m_client.AttachProxy(m_simpleProxy);
            m_client.AttachStub(m_simpleStub);

            m_connectionParam.protocolVersion = new Nettention.Proud.Guid();
            m_connectionParam.protocolVersion.Set(SimpleUnity.Vars.Version);

            // 웹플레이어로 접속시에는 localhost 가 아닌 IP를 써주어야 함.
            m_connectionParam.serverIP   = "localhost";
            m_connectionParam.serverPort = (ushort)SimpleUnity.Vars.ServerPort;

            m_screenWidth  = Screen.width;           // 현재 화면의 가로 값 셋팅.
            m_screenHeight = Screen.height;          // 현재 화면의 세로 값 셋팅.
            m_screenOneW   = m_screenWidth / 5;      // 현재 화면의 가로를 5로 나눈값으로 셋팅.
            m_screenOneH   = m_screenHeight / 10;    // 현재 화면의 세로를 10으로 나눈 값으로 셋팅.

            m_height = m_screenOneH * 7;             // 채팅창 높이 초기화.

            m_scrollHeight = 0;

            LogList = new List <string>();

#if UNITY_WEBPLAYER
            Security.PrefetchSocketPolicy(m_connectionParam.serverIP, (int)m_connectionParam.serverPort);
#endif

            if (m_client.Connect(m_connectionParam) == false)
            {
                print("m_client failed to connect to server!!");
            }
            else
            {
                long time = System.DateTime.Now.Ticks;
                long currentTime;

                while (m_eventSink.IsConnectWaiting)
                {
                    // 코루틴을 이용해 m_WaitTime 동안 대기.
                    yield return(new WaitForSeconds(m_WaitTime));

                    m_client.FrameMove();

                    currentTime = System.DateTime.Now.Ticks;

                    // ticks 의 1초는 10000000
                    if (currentTime - time > 100000000)
                    {
                        break;
                    }
                }

                m_myClass.a = 1;
                m_myClass.b = 1.5f;
                m_myClass.c = 3.141592;

                // List혹은 Dictionary를 Rmi인자로 사용이 가능합니다.
                m_listData = new List <int>();
                m_listData.Add(4);
                m_listData.Add(5);

                m_dictionaryData = new Dictionary <int, float>();
                m_dictionaryData.Add(1, 1.5f);
                m_dictionaryData.Add(2, 3.1f);

                m_blockData = new ByteArray();
                for (int i = 0; i < 100; ++i)
                {
                    m_blockData.Add((byte)i);
                }

                m_simpleProxy.Chat(HostID.HostID_Server, RmiContext.ReliableSend, "우갸갸갸갸갹.", 22, 22.33f);
            }
        }
        public void Connect(byte chServerType, String m_serverIP, int m_serverPort, OnConnect dlg = null)
        {
            Guid m_Version = new Guid ("{0x5f6f921f,0x285f,0x40dc,{0x8f,0xd3,0xcf,0x5a,0xb3,0x84,0x80,0x66}}");

            NetConnectionParam cp = new NetConnectionParam ();
            cp.protocolVersion = m_Version;
            cp.serverIP = m_serverIP;
            cp.serverPort = (ushort)m_serverPort;

            #if UNITY_WEBPLAYER
            Security.PrefetchSocketPolicy(m_serverIP, m_serverPort);
            #endif
            if(dlg != null) {
                ConnectHandler = dlg;
            }
            if (m_Client.Connect (cp) == false) {
                if (dlg != null)
                {
                    dlg(false);
                }
            }
        }