Beispiel #1
0
        public NetManager()
        {
            core = new ZNet.CoreClientNet();

            proxy = new Rmi.Proxy();
            stub  = new Rmi.Stub();

            core.Attach(proxy, stub);


            // 서버로의 접속시도 결과 처리
            core.server_connect_result_handler = (bool isConnectSuccess) =>
            {
                if (isConnectSuccess)
                {
                    OutMsg("connect ok");
                }
                else
                {
                    OutMsg("connect fail");
                    if (JoinFailedHandler != null)
                    {
                        JoinFailedHandler();
                    }
                }
            };


            // 서버에 접속성공 이후 실제 입장성공 시점
            core.server_join_handler = (ZNet.ConnectionInfo info) =>
            {
                OutMsg("join server = {0}:{1}", info.addr.addr, info.addr.port);

                proxy.cs_login(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Basic, "홍길동");
                if (JoinHandler != null)
                {
                    JoinHandler();
                }
            };


            // 서버에서 퇴장됨
            core.server_leave_handler = (ZNet.ConnectionInfo info) =>
            {
                OutMsg("leave server {0}:{1}", info.addr.addr, info.addr.port);
                if (LeaveHandler != null)
                {
                    LeaveHandler();
                }
            };

            core.message_handler = (ZNet.ResultInfo result) =>
            {
                if (InternalHandler != null)
                {
                    InternalHandler(result.msg);
                }
            };


            // 로그인 성공 패킷 처리
            stub.sc_login_ok = (ZNet.RemoteID remote, ZNet.CPackOption pkOption, NetCommon.CUser user_data) =>
            {
                OutMsg("server login complete.  my username = {0}, userID = {1}", user_data.username, user_data.userID);
                return(true);
            };
        }