Exemplo n.º 1
0
        /// <summary>
        ///  Wraps the PCSC function
        ///  LONG SCardConnect(
        ///		IN SCARDCONTEXT hContext,
        ///		IN LPCTSTR szReader,
        ///		IN DWORD dwShareMode,
        ///		IN DWORD dwPreferredProtocols,
        ///		OUT LPSCARDHANDLE phCard,
        ///		OUT LPDWORD pdwActiveProtocol
        ///	);
        /// </summary>
        /// <param name="Reader"></param>
        /// <param name="ShareMode"></param>
        /// <param name="PreferredProtocols"></param>
        public override void Connect(string Reader, SHARE ShareMode, PROTOCOL PreferredProtocols)
        {
            EstablishContext(SCOPE.User);

            IntPtr	hCard = Marshal.AllocHGlobal(Marshal.SizeOf(cardHandle));
            IntPtr	pProtocol = Marshal.AllocHGlobal(Marshal.SizeOf(protocol));

            lastError = PCSC.SCardConnect(context,
                Reader,
                (uint) ShareMode,
                (uint) PreferredProtocols,
                hCard,
                pProtocol);

            if (lastError != 0)
            {
                Marshal.FreeHGlobal(hCard);
                Marshal.FreeHGlobal(pProtocol);
                ThrowSmartcardException("SCardConnect", lastError);
            }

            cardHandle = Marshal.ReadIntPtr(hCard);
            protocol = (uint) Marshal.ReadInt32(pProtocol);

            Marshal.FreeHGlobal(hCard);
            Marshal.FreeHGlobal(pProtocol);
        }
Exemplo n.º 2
0
        public IPHeader(String[] headers)
        {
            /*
            headers
            PROTOCOL TTL TOS ID IPLEN DGMLEN FLAG
            */

            switch (headers [0]) {
            case "TCP":
                protocol = PROTOCOL.TCP;
                break;
            case "UDP":
                protocol = PROTOCOL.UDP;
                break;
            case "ICMP":
                protocol = PROTOCOL.ICMP;
                break;
            }

            TTL = Convert.ToInt32 (getValue (headers [1]));
            TOS = getValue (headers [2]);
            ID = Convert.ToInt32 (getValue (headers [3]));
            IpLen = Convert.ToInt32 (getValue (headers [4]));
            DgmLen = Convert.ToInt32 (getValue (headers [5]));

            //			flag = NULL;
        }
        public unsafe RioConnectionOrientedSocketPool(RioFixedBufferPool sendPool, RioFixedBufferPool revicePool, uint socketCount, ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol,
            uint maxOutstandingReceive = 1024, uint maxOutstandingSend = 1024, uint maxConnections = 1024)
            : base(sendPool, revicePool, adressFam, sockType, protocol, maxOutstandingReceive, maxOutstandingSend, maxConnections)
        {
            var adrSize = (sizeof(sockaddr_in) + 16) * 2;
            var overlapped = Marshal.AllocHGlobal(new IntPtr(socketCount * Marshal.SizeOf<RioNativeOverlapped>()));
            var adressBuffer = Marshal.AllocHGlobal(new IntPtr(socketCount * adrSize));

            allSockets = new RioConnectionOrientedSocket[socketCount];

            for (int i = 0; i < socketCount; i++)
            {
                allSockets[i] = new RioConnectionOrientedSocket(overlapped + (i * Marshal.SizeOf<RioNativeOverlapped>()), adressBuffer + (i * adrSize), this, SendBufferPool, ReceiveBufferPool, maxOutstandingReceive, maxOutstandingSend, SendCompletionQueue, ReceiveCompletionQueue, adressFam, sockType, protocol);
                allSockets[i]._overlapped->SocketIndex = i;
            }

            if ((socketIocp = Kernel32.CreateIoCompletionPort((IntPtr)(-1), IntPtr.Zero, 0, 1)) == IntPtr.Zero)
                Kernel32.ThrowLastError();

            foreach (var s in allSockets)
            {
                if ((Kernel32.CreateIoCompletionPort(s.Socket, socketIocp, 0, 1)) == IntPtr.Zero)
                    Kernel32.ThrowLastError();
            }

            Thread SocketIocpThread = new Thread(SocketIocpComplete);
            SocketIocpThread.IsBackground = true;
            SocketIocpThread.Start();
        }
Exemplo n.º 4
0
 //ADDRESS_FAMILIES.AF_INET, SOCKET_TYPE.SOCK_DGRAM, PROTOCOL.IPPROTO_UDP
 internal RioConnectionlessSocket(RioSocketPool pool, RioFixedBufferPool sendBufferPool, RioFixedBufferPool receiveBufferPool, RioFixedBufferPool adressBufferPool,
     uint maxOutstandingReceive, uint maxOutstandingSend, IntPtr SendCompletionQueue, IntPtr ReceiveCompletionQueue,
     ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol)
     : base(sendBufferPool, receiveBufferPool, adressBufferPool, maxOutstandingReceive, maxOutstandingSend,
         SendCompletionQueue, ReceiveCompletionQueue,
         adressFam, sockType, protocol)
 {
 }
Exemplo n.º 5
0
    //리시브
    public void on_recv(CPacket msg)
    {
        // 제일 먼저 프로토콜 아이디를 꺼내온다.
        PROTOCOL protocol_id = (PROTOCOL)msg.pop_protocol_id();

        //switch (protocol_id)
        //{

        //     break;
        //}
    }
Exemplo n.º 6
0
    void checked_protocol(byte player_index, PROTOCOL protocol)
    {
        //UnityEngine.Debug.Log(player_index + ",  sent : " + protocol);
        if (this.received_protocol.ContainsKey(player_index))
        {
            UnityEngine.Debug.LogError(string.Format("Already contains player. Please call 'clear_received_protocol()' before send to client."));
            return;
        }

        this.received_protocol.Add(player_index, protocol);
    }
        void IUserState.on_message(FreeNet.CPacket msg)
        {
            PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

            switch (protocol)
            {
            case PROTOCOL.ENTER_GAME_ROOM_REQ:
                Program.game_main.matching_req(this.owner);
                break;

            case PROTOCOL.ENTER_GAME_ROOM_REQ2:
                Program.game_main.matching_req2(this.owner);
                break;

            case PROTOCOL.ENTER_GAME_ROOM_REQ3:
                invite_room_start(msg);
                break;

            case PROTOCOL.INVITE_ROOM_CREATE:     //친구초대방 생성
                Program.game_main.matching_req3(this.owner);
                this.owner.battle_room.board = msg.pop_int32();
                this.owner.battle_room.invite_room_check.Add(this.owner.player);
                break;

            case PROTOCOL.ENTER_GAME_ROOM_QUIT:
                this.owner.player.removed();
                break;

            case PROTOCOL.SERVER_CONNECT:
                this.owner.enter_lobby(msg.pop_string());
                break;

            case PROTOCOL.INVITE_FRIEND_REQ:
                invite_friend(msg);
                break;

            case PROTOCOL.INVITE_FRIEND_ACK:
                invite_room();
                break;

            case PROTOCOL.DENY_FRIEND:
                deny_friend(msg);
                break;

            case PROTOCOL.ROOM_REMOVED:
                this.owner.quit_room(this.owner.player.player_index);
                break;

            case PROTOCOL.INVITE_ROOM_QUIT_REQ:
                invite_room_quit();
                break;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 클라이언트가 보내온 모든 메시지들을 처리하는 매소드입니다.
        /// </summary>
        /// <param name="msg"></param>
        void IPeer.process_user_operation(CPacket msg)
        {
            PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

            Console.WriteLine("protocol id " + protocol);
            switch (protocol)
            {
            case PROTOCOL.ENTER_GAME_ROOM_REQ:
                Program.game_main.matching_req(this);
                break;
            }
        }
Exemplo n.º 9
0
    void on_receive(CPacket msg)
    {
        PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

        //UnityEngine.Debug.Log("AIPlayer received : " + protocol);

        if (!this.packet_handler.ContainsKey(protocol))
        {
            return;
        }
        this.packet_handler[protocol](msg);
    }
Exemplo n.º 10
0
        void IUserState.on_message(FreeNet.CPacket msg)
        {
            PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

            Console.WriteLine("protocol id " + protocol);
            switch (protocol)
            {
            case PROTOCOL.ENTER_GAME_ROOM_REQ:
                Program.game_main.matching_req(this.owner);
                break;
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// 플레이어가 받은 프로토콜을 삭제함. (public으로 하지 않는 방법 강구 필요)
 /// </summary>
 /// <param name="player_index"></param>
 /// <param name="protocol"></param>
 public bool removed_protocol(byte player_index, PROTOCOL protocol)
 {
     if (!this.received_protocol.ContainsKey(player_index))
     {
         return(false); //해당 유저에게 온 프로토콜이 없음
     }
     if (this.received_protocol[player_index] == protocol)
     {
         this.received_protocol.Remove(player_index);
         return(true); //삭제함
     }
     return(false);    //해당 유저에게 삭제할 프로토콜이 일치하지 않음
 }
Exemplo n.º 12
0
        internal RioSocketBase(RioFixedBufferPool sendBufferPool, RioFixedBufferPool receiveBufferPool,
            uint maxOutstandingReceive, uint maxOutstandingSend, IntPtr SendCompletionQueue, IntPtr ReceiveCompletionQueue,
            ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol)
        {
            if ((Socket = WinSock.WSASocket(adressFam, sockType, protocol, IntPtr.Zero, 0, SOCKET_FLAGS.REGISTERED_IO | SOCKET_FLAGS.WSA_FLAG_OVERLAPPED)) == IntPtr.Zero)
                WinSock.ThrowLastWSAError();

            SendBufferPool = sendBufferPool;
            ReceiveBufferPool = receiveBufferPool;

            _requestQueue = RioStatic.CreateRequestQueue(Socket, maxOutstandingReceive, 1, maxOutstandingSend, 1, ReceiveCompletionQueue, SendCompletionQueue, GetHashCode());
            WinSock.ThrowLastWSAError();
        }
Exemplo n.º 13
0
            public UniRx.IObservable <bool> Send(string command, Newtonsoft.Json.Linq.JToken payload)
            {
                var packet = new PROTOCOL();

                packet.ver     = PROTOCOL.VERSION;
                packet.serial  = last_send.serial + 1;
                packet.utc     = UnixDateTime.ToUnixTimeMilliseconds(System.DateTime.UtcNow);
                packet.command = command;
                packet.payload = payload;
                last_send      = packet;
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(packet);

                return(socket.Send(json));
            }
Exemplo n.º 14
0
        public void useskill(byte player_index, PROTOCOL skill)
        {
            CPacket msg = CPacket.create((short)skill);

            msg.push(player_index);

            players.ForEach(player =>
            {
                if (player_index != player.player_index)
                {
                    player.send(msg);
                }
            });
        }
Exemplo n.º 15
0
        void IPeer.on_message(CPacket msg)
        {
            PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

            switch (protocol)
            {
            case PROTOCOL.CHAT_MSG_REQ:
            {
                string text = msg.pop_string();
                if (text.Contains("create"))
                {
                    text = text.Remove(0, 6);
                    Program.create_room(this, text);
                }
                else if (text.Contains("join"))
                {
                    text = text.Remove(0, 4);
                    if (Program.join_room(this, text) == -1)
                    {
                        Console.Write("error");
                    }
                    room_information = Program.join_room(this, text);
                }
                else
                {
                    Program.rooms[room_information].send_all(this, text);
                }

                //Form1.drawing(c[0], c[1], c[2], c[3]);

                /*CPacket response = CPacket.create((short)PROTOCOL.CHAT_MSG_ACK);
                 * response.push(text);
                 * send(response);*/

                if (text.Equals("exit"))
                {
                    // 대량의 메시지를 한꺼번에 보낸 후 종료하는 시나리오 테스트.
                    for (int i = 0; i < 1000; ++i)
                    {
                        CPacket dummy = CPacket.create((short)PROTOCOL.CHAT_MSG_ACK);
                        dummy.push(i.ToString());
                        send(dummy);
                    }

                    this.token.ban();
                }
            }
            break;
            }
        }
Exemplo n.º 16
0
        internal RioSocket(RioFixedBufferPool sendBufferPool, RioFixedBufferPool receiveBufferPool,
                           uint maxOutstandingReceive, uint maxOutstandingSend, IntPtr SendCompletionQueue, IntPtr ReceiveCompletionQueue,
                           ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol)
        {
            if ((Socket = WinSock.WSASocket(adressFam, sockType, protocol, IntPtr.Zero, 0, SOCKET_FLAGS.REGISTERED_IO | SOCKET_FLAGS.WSA_FLAG_OVERLAPPED)) == IntPtr.Zero)
            {
                WinSock.ThrowLastWSAError();
            }

            SendBufferPool    = sendBufferPool;
            ReceiveBufferPool = receiveBufferPool;

            _requestQueue = RioStatic.CreateRequestQueue(Socket, maxOutstandingReceive, 1, maxOutstandingSend, 1, ReceiveCompletionQueue, SendCompletionQueue, GetHashCode());
            WinSock.ThrowLastWSAError();
        }
        void IPeer.on_message(Const <byte[]> buffer)
        {
            CPacket  msg         = new CPacket(buffer.Value, this);
            PROTOCOL protocol_id = (PROTOCOL)msg.pop_protocol_id();

            switch (protocol_id)
            {
            case PROTOCOL.CHAT_MSG_ACK:
            {
                string text = msg.pop_string();
                Console.WriteLine(string.Format("text {0}", text));
            }
            break;
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// 각 유저가 전달한 프로토콜 로직 처리
        /// </summary>
        /// <param name="protocol"></param>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        void IRoomState.on_receive(PROTOCOL protocol, CPlayer owner, CPacket msg)
        {
            Console.WriteLine("recieve protocol : " + protocol);
            switch (protocol)
            {
            case PROTOCOL.CARD_SET_REQ:
            {
                set_card(owner, msg);
            }
            break;

            case PROTOCOL.CARD_SETTED:
            {
                setted_card(owner, msg);
            }
            break;

            case PROTOCOL.ITEM_USE_REQ:
            {
                use_item(owner, msg);
            }
            break;

            case PROTOCOL.ITEM_USED:
            {
                used_item(owner, msg);
            }
            break;

            case PROTOCOL.UNIT_MOVED:
            {
                moved_unit(owner, msg);
            }
            break;

            case PROTOCOL.GAME_INIT:
            {
                init_game(owner, msg);
            }
            break;

            case PROTOCOL.GAME_OVER:
            {
                game_over(owner, msg);
            }
            break;
            }
        }
Exemplo n.º 19
0
        void IPeer.on_message(Const <byte[]> buffer)
        {
            CPacket  msg         = new CPacket(buffer.Value, this);
            PROTOCOL protocol_id = (PROTOCOL)msg.pop_protocol_id();

            switch (protocol_id)
            {
            case PROTOCOL.CHAT_MSG_ACK:
            {
                get.a = msg.pop_string();
                //Console.WriteLine(string.Format("{0}", text));
                //MessageBox.Show(Program.get_text);
            }
            break;
            }
        }
Exemplo n.º 20
0
        void IPeer.on_message(CPacket msg)
        {
            System.Threading.Interlocked.Increment(ref this.recv_count);

            PROTOCOL protocol_id = (PROTOCOL)msg.pop_protocol_id();

            switch (protocol_id)
            {
            case PROTOCOL.CHAT_MSG_ACK:
            {
                string text = msg.pop_string();
                Console.WriteLine(string.Format("text {0}", text));
            }
            break;
            }
        }
 internal RioConnectionOrientedSocket(IntPtr overlapped, IntPtr adressBuffer, RioConnectionOrientedSocketPool pool, RioFixedBufferPool sendBufferPool, RioFixedBufferPool receiveBufferPool,
     uint maxOutstandingReceive, uint maxOutstandingSend, IntPtr SendCompletionQueue, IntPtr ReceiveCompletionQueue,
     ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol) :
     base(sendBufferPool, receiveBufferPool, maxOutstandingReceive, maxOutstandingSend, SendCompletionQueue, ReceiveCompletionQueue,
         adressFam, sockType, protocol) //ADDRESS_FAMILIES.AF_INET, SOCKET_TYPE.SOCK_STREAM, PROTOCOL.IPPROTO_TCP
 {
     _overlapped = (RioNativeOverlapped*)overlapped.ToPointer();
     _eventHandle = Kernel32.CreateEvent(IntPtr.Zero, false, false, null);
     _adressBuffer = adressBuffer;
     _pool = pool;
     unsafe
     {
         var n = (NativeOverlapped*)overlapped.ToPointer();
         n->EventHandle = _eventHandle;
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Packet을 수신 했을 때 호출됨
        /// </summary>
        /// <param name="msg"></param>
        public void OnReceive(Packet msg)
        {
            // 제일 먼저 프로토콜 아이디를 꺼내온다.
            PROTOCOL protocolID = (PROTOCOL)msg.PopProtocolID();

            switch (protocolID)
            {
            case PROTOCOL.FailFriendList:
            {
                int result = msg.PopInt32();
                        #if DEBUG
                switch (result)
                {
                case -3:
                    Debug.Log("DB 연결 실패");
                    break;

                case -1:
                    Debug.Log("DB Data 없음");
                    break;
                }
                        #endif

                this.userState = UserStage.NotState;
                main.Enter();
                GameObject.Find("SceneManager").GetComponent <MySceneManager>().Present = SceneList.Main;
            }
            break;

            case PROTOCOL.SuccessFriendList:
            {
                int count = msg.PopInt32();
                int index = 0;
                for (int i = 0; i < count; i++)
                {
                    friends.Add(new UserInfo(msg.PopString(), msg.PopInt32(), (RANK)msg.PopInt32()));
                    friendsObj.Add(Instantiate(friendInfo, contents.transform));

                    Text[] texts = friendsObj[i].GetComponentsInChildren <Text>();
                    texts[0].text = friends[friends.Count - 1].Name;
                    texts[1].text = friends[friends.Count - 1].Rank.ToString();
                    texts[2].text = friends[friends.Count - 1].Score.ToString();
                }
            }
            break;
            }
        }
Exemplo n.º 23
0
 public void Connect(string reader, SHARE shareMode, PROTOCOL preferredProtocols)
 {
     try
     {
         card.Connect(reader, shareMode, preferredProtocols);
     }
     catch (SmartCardException scEx)
     {
         SmartcardFault scFault = new SmartcardFault(scEx);
         throw new FaultException<SmartcardFault>(scFault);
     }
     catch (Exception ex)
     {
         GeneralFault genFault = new GeneralFault(ex);
         throw new FaultException<GeneralFault>(genFault);
     }
 }
Exemplo n.º 24
0
    public void on_recv(CPacket msg)
    {
        PROTOCOL protocol_id = (PROTOCOL)msg.pop_protocol_id();

        switch (protocol_id)
        {
        case PROTOCOL.START_LOADING:
        {
            byte player_index = msg.pop_byte();

            this.battle_room.gameObject.SetActive(true);
            this.battle_room.start_loading(player_index);
            gameObject.SetActive(false);
        }
        break;
        }
    }
Exemplo n.º 25
0
        public ProtocolChecker()
        {
            //< 초기 셋팅
            foreach (PROTOCOL eEnum in PROTOCOL.GetValues(typeof(PROTOCOL)))
            {
                SendCheker.Add(eEnum, new ProtocolChecker(false));
            }

            //< 만약 중복으로 보낼값이 있다면 따로 처리
            SendCheker[PROTOCOL.P_USER_LOGIN].canDuplicate = true;
//            SendCheker[Protocol.PROTOCOL.P_USER_MISSION_UPDATE].canDuplicate = true;
//            SendCheker[Protocol.PROTOCOL.P_CHAT_GET_CHANNEL_IP].canDuplicate = true;

//#if UNITY_EDITOR
//            SendCheker[Protocol.PROTOCOL.P_ITEM_UNIT_SELL].canDuplicate = true;
//#endif
        }
Exemplo n.º 26
0
        //--------------------------------------------------------
        // Handler.
        //--------------------------------------------------------
        public void on_receive(CPlayer owner, CPacket msg)
        {
            PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

            if (is_received(owner.player_index, protocol))
            {
                // 플레이어가 이미 해당 프로토콜을 전송했다. 중복 처리 하지 않고 리턴한다.
                return;
            }

            // 프로토콜을 받았다고 기록한다.
            checked_protocol(owner.player_index, protocol);

            // 상태 매니저에 패킷을 보낸 플레이어와 패킷 내용을 전달한다.
            // 이후 게임 로직은 상태 매니저를 통해 현재 수행중인 상태 객체에서 처리된다.
            this.state_manager.send_state_message(protocol, owner, msg);
        }
Exemplo n.º 27
0
        void IRoomState.on_receive(PROTOCOL protocol, CPlayer owner, CPacket msg)
        {
            switch (protocol)
            {
            case PROTOCOL.LOADING_COMPLETED:
            {
                on_ready_req(owner, msg);
            }
            break;

            case PROTOCOL.INVITE_ROOM_UNREADY:
            {
                on_unready_req(owner, msg);
            }
            break;
            }
        }
Exemplo n.º 28
0
 public void Connect(string reader, SHARE shareMode, PROTOCOL preferredProtocols)
 {
     try
     {
         card.Connect(reader, shareMode, preferredProtocols);
     }
     catch (SmartCardException scEx)
     {
         SmartcardFault scFault = new SmartcardFault(scEx);
         throw new FaultException <SmartcardFault>(scFault);
     }
     catch (Exception ex)
     {
         GeneralFault genFault = new GeneralFault(ex);
         throw new FaultException <GeneralFault>(genFault);
     }
 }
Exemplo n.º 29
0
    /// <summary>
    /// Called when received packets.
    /// 패킷을 수신 했을 때 호출됨.
    /// </summary>
    /// <param name="protocol"></param>
    /// <param name="msg"></param>
    void IMessageReceiver.on_recv(CPacket msg)
    {
        PROTOCOL protocol_id = (PROTOCOL)msg.pop_protocol_id();

        // 동시접속자 정보가 아닌 다른 패킷일 수신했을 경우 WAIT팝업을 닫는다.
        if (protocol_id != PROTOCOL.CONCURRENT_USERS)
        {
            CUIManager.Instance.hide(UI_PAGE.POPUP_WAIT);
        }

        switch (protocol_id)
        {
        // 게임을 시작해라.
        case PROTOCOL.GAME_START:
            on_game_start(msg);
            break;

        // 플레이어가 이동 했다.
        case PROTOCOL.PLAYER_MOVED:
            on_player_moved(msg);
            break;

        // 턴을 시작해라.
        case PROTOCOL.START_PLAYER_TURN:
            on_start_player_turn(msg);
            break;

        // 방이 삭제됐다. 누가 끊겼던지 강제종료 했던지 등등.
        case PROTOCOL.ROOM_REMOVED:
            on_room_removed();
            break;

        // 게임이 종료됐다.
        case PROTOCOL.GAME_OVER:
            on_game_over(msg);
            break;

        case PROTOCOL.CONCURRENT_USERS:
        {
            int count = msg.pop_int32();
            CUIManager.Instance.get_uipage(UI_PAGE.STATUS_BAR).GetComponent <CStatusBar>().refresh(count);
        }
        break;
        }
    }
Exemplo n.º 30
0
        internal RioSocket(RioFixedBufferPool sendBufferPool, RioFixedBufferPool receiveBufferPool, RioFixedBufferPool adressBufferPool,
            uint maxOutstandingReceive, uint maxOutstandingSend, IntPtr SendCompletionQueue, IntPtr ReceiveCompletionQueue,
            ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol)
        {
            this.adressFam = adressFam;
            this.sockType = sockType;
            this.protocol = protocol;
            this.maxOutstandingReceive = maxOutstandingReceive;
            this.maxOutstandingSend = maxOutstandingSend;
            this.ReceiveCompletionQueue = ReceiveCompletionQueue;
            this.SendCompletionQueue = SendCompletionQueue;

            SendBufferPool = sendBufferPool;
            ReceiveBufferPool = receiveBufferPool;
            AdressPool = adressBufferPool;

            ResetSocket();
        }
Exemplo n.º 31
0
        internal RioSocket(RioFixedBufferPool sendBufferPool, RioFixedBufferPool receiveBufferPool, RioFixedBufferPool adressBufferPool,
                           uint maxOutstandingReceive, uint maxOutstandingSend, IntPtr SendCompletionQueue, IntPtr ReceiveCompletionQueue,
                           ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol)
        {
            this.adressFam              = adressFam;
            this.sockType               = sockType;
            this.protocol               = protocol;
            this.maxOutstandingReceive  = maxOutstandingReceive;
            this.maxOutstandingSend     = maxOutstandingSend;
            this.ReceiveCompletionQueue = ReceiveCompletionQueue;
            this.SendCompletionQueue    = SendCompletionQueue;

            SendBufferPool    = sendBufferPool;
            ReceiveBufferPool = receiveBufferPool;
            AdressPool        = adressBufferPool;

            ResetSocket();
        }
Exemplo n.º 32
0
        public void XML_FORM(string user_name, string user_session, string game_key, PROTOCOL protocol, List <string> datas)
        {
            if (datas.Count == 0)
            {
                return;
            }

            this.SetUserName(user_name);
            this.SetUserSession(user_session);
            this.SetGameKey(game_key);
            this.SetProtocol(protocol);
            this.SetDataCount(datas.Count);
            foreach (string o in datas)
            {
                this.PushData(o);
                this.pushCount++;
            }
        }
Exemplo n.º 33
0
    bool all_received(PROTOCOL protocol)
    {
        if (this.received_protocol.Count < this.players.Count)
        {
            return(false);
        }

        foreach (KeyValuePair <byte, PROTOCOL> kvp in this.received_protocol)
        {
            if (kvp.Value != protocol)
            {
                return(false);
            }
        }

        clear_received_protocol();
        return(true);
    }
Exemplo n.º 34
0
    public void OnRecv(CPacket msg)
    {
        // 제일 먼저 프로토콜 아이디를 꺼내온다.
        PROTOCOL protocol_id = (PROTOCOL)msg.pop_protocol_id();

        Debug.Log("on message " + protocol_id);
        // 프로토콜에 따른 분기 처리.
        switch (protocol_id)
        {
        case PROTOCOL.GAME_START:
            GameStart(msg);
            break;

        case PROTOCOL.ROOM_REMOVED:
            BackToMain();
            break;
        }
    }
Exemplo n.º 35
0
        public RuleHeader(String header)
        {
            this.raw = header;

            String[] headers = header.Split(new[] { " " }, StringSplitOptions.None);

            if (headers.Length != 7)
            {
                throw new Exception("not correct argument");
            }

            //action
            ACTION parseAction;

            if (!Enum.TryParse(headers[0].ToUpper(), out parseAction))
            {
                throw new Exception("no match action");
            }
            this.ruleAction = parseAction;

            //rule Protocol;
            PROTOCOL parseProtocol;

            if (!Enum.TryParse(headers[1].ToUpper(), out parseProtocol))
            {
                throw new Exception("no match protocol");
            }
            this.ruleProtocol = parseProtocol;

            //rule Senderip
            this.senderIp = headers[2];

            //rule Senderport
            this.senderPort = headers[3];

            //rule Direct
            this.ruleDirect = headers[4];

            //rule Receiveip
            this.receiveIp = headers[5];

            //rule Receiveport
            this.receivePort = headers[6];
        }
Exemplo n.º 36
0
        public RMCPacket(QPacket p)
        {
            MemoryStream m = new MemoryStream(p.payload);

            Helper.ReadU32(m);
            ushort b = Helper.ReadU8(m);

            isRequest = (b >> 7) == 1;
            try
            {
                if ((b & 0x7F) != 0x7F)
                {
                    proto = (PROTOCOL)(b & 0x7F);
                }
                else
                {
                    b     = Helper.ReadU16(m);
                    proto = (PROTOCOL)(b);
                }
            }
            catch
            {
                callID   = Helper.ReadU32(m);
                methodID = Helper.ReadU32(m);
                WriteLog("Error: Unknown RMC packet protocol 0x" + b.ToString("X2"));
                return;
            }
            callID   = Helper.ReadU32(m);
            methodID = Helper.ReadU32(m);
            switch (proto)
            {
            case PROTOCOL.Authentication:
                HandleAuthenticationMethods(m);
                break;

            case PROTOCOL.Secure:
                HandleSecureMethods(m);
                break;

            default:
                WriteLog("Error: No reader implemented for packet protocol " + proto);
                break;
            }
        }
Exemplo n.º 37
0
        public RuleHeader(String header)
        {
            this.raw = header;

            String[] headers = header.Split(new[] { " " }, StringSplitOptions.None);

            if (headers.Length != 7)
            {
                throw new Exception("not correct argument");
            }

            //action
            ACTION parseAction;
            if (!Enum.TryParse(headers[0].ToUpper(), out parseAction))
            {
                throw new Exception("no match action");
            }
            this.ruleAction = parseAction;

            //rule Protocol;
            PROTOCOL parseProtocol;
            if (!Enum.TryParse(headers[1].ToUpper(), out parseProtocol))
            {
                throw new Exception("no match protocol");
            }
            this.ruleProtocol = parseProtocol;

            //rule Senderip
            this.senderIp = headers[2];

            //rule Senderport
            this.senderPort = headers[3];

            //rule Direct
            this.ruleDirect = headers[4];

            //rule Receiveip
            this.receiveIp = headers[5];

            //rule Receiveport
            this.receivePort = headers[6];
        }
Exemplo n.º 38
0
        private bool sendPacket(SerialPort spTargetPort, byte id, PROTOCOL instruction, Byte[] parameters)
        {
            //go through and have functions check the return value
            //also either have the error output write to the output window, or
            //expand the response fields. Or maybe just put what we did get back in the response fields
            //and pop up an 'error' modal dialog alert. Maybe zero out the arrays before we
            //populate and send them
            Byte[] transmitBuffer;

            transmitBuffer = assemblePacket(id, (byte)instruction, parameters);
            try
            {
                spTargetPort.Write(transmitBuffer, 0, transmitBuffer.Length);
                return(true);
            }
            catch (TimeoutException stoe)
            {
                return(false);
            }
        }
Exemplo n.º 39
0
        public void Connect(string Reader, SHARE ShareMode, PROTOCOL PreferredProtocols)
        {
            EstablishContext(SCOPE.User);

            IntPtr hCard     = Marshal.AllocHGlobal(Marshal.SizeOf(m_hCard));
            IntPtr pProtocol = Marshal.AllocHGlobal(Marshal.SizeOf(m_nProtocol));


            m_nLastError = SCardConnect(m_hContext,
                                        Reader,
                                        (uint)ShareMode,
                                        (uint)PreferredProtocols,
                                        hCard,
                                        pProtocol);

            if (m_nLastError != 0)
            {
                Marshal.FreeHGlobal(hCard);
                Marshal.FreeHGlobal(pProtocol);
                unchecked
                {
                    switch (m_nLastError)
                    {
                    case ((int)0x80100009):
                        throw new Exception("Reader not found...");

                    case ((int)0x80100069):
                        throw new Exception("No smart card in reader");

                    default:
                        throw new Exception(String.Format("SCardConnect error: 0x{0:X}", m_nLastError));
                    }
                }
            }

            m_hCard     = (uint)Marshal.ReadInt32(hCard);
            m_nProtocol = (uint)Marshal.ReadInt32(pProtocol);

            Marshal.FreeHGlobal(hCard);
            Marshal.FreeHGlobal(pProtocol);
        }
Exemplo n.º 40
0
        internal RioSocket(RioFixedBufferPool sendBufferPool, RioFixedBufferPool receiveBufferPool,
            uint maxOutstandingReceive, uint maxOutstandingSend, IntPtr SendCompletionQueue, IntPtr ReceiveCompletionQueue,
            ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol)
        {
            if ((Socket = WinSock.WSASocket(adressFam, sockType, protocol, IntPtr.Zero, 0, SOCKET_FLAGS.REGISTERED_IO | SOCKET_FLAGS.WSA_FLAG_OVERLAPPED)) == IntPtr.Zero)
                WinSock.ThrowLastWSAError();

            SendBufferPool = sendBufferPool;
            ReceiveBufferPool = receiveBufferPool;

            _requestQueue = RioStatic.CreateRequestQueue(Socket, maxOutstandingReceive, 1, maxOutstandingSend, 1, ReceiveCompletionQueue, SendCompletionQueue, GetHashCode());
            WinSock.ThrowLastWSAError();

            onIncommingSegmentWrapper = (socket, segment) =>
            {
                onIncommingSegmentSafe(segment);
                if (segment.CurrentContentLength > 0)
                    socket.BeginReceive();
                else
                    socket.Dispose();
                segment.Dispose();
            };
        }
Exemplo n.º 41
0
 /// <summary>
 /// Connects to a card. Establishes a card session
 /// </summary>
 /// <param name="Reader">Reader string</param>
 /// <param name="ShareMode">Session share mode</param>
 /// <param name="PreferredProtocols">Session preferred protocol</param>
 void Connect(string reader, SHARE shareMode, PROTOCOL preferredProtocols)
 {
     cardClient.ConnectAsync(reader, (SCardService.SHARE)shareMode, (SCardService.PROTOCOL)preferredProtocols).Wait(TIMEOUT);
 }
Exemplo n.º 42
0
 /// <summary>
 ///  Wraps the PCSC function
 ///  LONG SCardConnect(
 ///		IN SCARDCONTEXT hContext,
 ///		IN LPCTSTR szReader,
 ///		IN DWORD dwShareMode,
 ///		IN DWORD dwPreferredProtocols,
 ///		OUT LPSCARDHANDLE phCard,
 ///		OUT LPDWORD pdwActiveProtocol
 ///	);
 /// </summary>
 /// <param name="Reader"></param>
 /// <param name="ShareMode"></param>
 /// <param name="PreferredProtocols"></param>
 public override void Connect(string Reader, SHARE ShareMode, PROTOCOL PreferredProtocols)
 {
     // Calls AttachReader to connect to the card
     m_itfCard.AttachByReader(Reader, (SCARD_SHARE_MODES) ShareMode, (SCARD_PROTOCOLS) PreferredProtocols);
 }
Exemplo n.º 43
0
        /// <summary>
        ///  Wraps the PCSC function
        ///  LONG SCardConnect(
        ///		IN SCARDCONTEXT hContext,
        ///		IN LPCTSTR szReader,
        ///		IN DWORD dwShareMode,
        ///		IN DWORD dwPreferredProtocols,
        ///		OUT LPSCARDHANDLE phCard,
        ///		OUT LPDWORD pdwActiveProtocol
        ///	);
        /// </summary>
        /// <param name="Reader"></param>
        /// <param name="ShareMode"></param>
        /// <param name="PreferredProtocols"></param>
        public override void Connect(string Reader, SHARE ShareMode, PROTOCOL PreferredProtocols)
        {
            EstablishContext(SCOPE.User);

            IntPtr	hCard = Marshal.AllocHGlobal(Marshal.SizeOf(m_hCard));
            IntPtr	pProtocol = Marshal.AllocHGlobal(Marshal.SizeOf(m_nProtocol));

            m_nLastError = SCardConnect(m_hContext,
                Reader,
                (uint) ShareMode,
                (uint) PreferredProtocols,
                hCard,
                pProtocol);

            if (m_nLastError != 0)
            {
                string msg = "SCardConnect error: " + m_nLastError;

                Marshal.FreeHGlobal(hCard);
                Marshal.FreeHGlobal(pProtocol);
                throw new Exception(msg);
            }

            m_hCard = Marshal.ReadIntPtr(hCard);
            m_nProtocol = (uint) Marshal.ReadInt32(pProtocol);

            Marshal.FreeHGlobal(hCard);
            Marshal.FreeHGlobal(pProtocol);
        }
Exemplo n.º 44
0
    bool all_received(PROTOCOL protocol)
    {
        if (this.received_protocol.Count < this.players.Count)
        {
            return false;
        }

        foreach (KeyValuePair<byte, PROTOCOL> kvp in this.received_protocol)
        {
            if (kvp.Value != protocol)
            {
                return false;
            }
        }

        clear_received_protocol();
        return true;
    }
Exemplo n.º 45
0
    void checked_protocol(byte player_index, PROTOCOL protocol)
    {
        //UnityEngine.Debug.Log(player_index + ",  sent : " + protocol);
        if (this.received_protocol.ContainsKey(player_index))
        {
            UnityEngine.Debug.LogError(string.Format("Already contains player. Please call 'clear_received_protocol()' before send to client."));
            return;
        }

        this.received_protocol.Add(player_index, protocol);
    }
Exemplo n.º 46
0
    bool is_received(byte player_index, PROTOCOL protocol)
    {
        if (!this.received_protocol.ContainsKey(player_index))
        {
            return false;
        }

        return this.received_protocol[player_index] == protocol;
    }
 /// <summary>
 /// Connects to a card. Establishes a card session
 /// </summary>
 /// <param name="Reader">Reader string</param>
 /// <param name="ShareMode">Session share mode</param>
 /// <param name="PreferredProtocols">Session preferred protocol</param>
 public void Connect(string reader, SHARE shareMode, PROTOCOL preferredProtocols)
 {
     try
     {
         cardClient.ConnectAsync(reader, (SCardService.SHARE)shareMode, (SCardService.PROTOCOL)preferredProtocols).Wait(TIMEOUT);
     }
     catch (AggregateException ax)
     {
         throw new Exception(ProcessAggregateException(ax));
     }
 }
 public RioConnectionlessSocketPool(RioFixedBufferPool sendPool, RioFixedBufferPool revicePool, ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol,
     uint maxOutstandingReceive = 1024, uint maxOutstandingSend = 1024, uint maxOutsandingCompletions = 1024)
     : base(sendPool, revicePool, adressFam, sockType, protocol, maxOutstandingReceive, maxOutstandingSend, maxOutsandingCompletions)
 {
 }
Exemplo n.º 49
0
        public unsafe RioSocketPool(RioFixedBufferPool sendPool, RioFixedBufferPool receivePool, ADDRESS_FAMILIES adressFam, SOCKET_TYPE sockType, PROTOCOL protocol,
            uint maxOutstandingReceive = 1024, uint maxOutstandingSend = 1024, uint maxOutsandingCompletions = 2048)
        {
            MaxOutstandingReceive = maxOutstandingReceive;
            MaxOutstandingSend = maxOutstandingSend;
            MaxOutsandingCompletions = maxOutsandingCompletions;
            SendBufferPool = sendPool;
            ReceiveBufferPool = receivePool;

            this.adressFam = adressFam;
            this.sockType = sockType;
            this.protocol = protocol;

            var version = new Version(2, 2);
            WSAData data;
            var result = WinSock.WSAStartup((short)version.Raw, out data);
            if (result != 0)
                WinSock.ThrowLastWSAError();

            RioStatic.Initalize();

            if ((ReceiveCompletionPort = Kernel32.CreateIoCompletionPort((IntPtr)(-1), IntPtr.Zero, 0, 1)) == IntPtr.Zero)
                Kernel32.ThrowLastError();

            if ((SendCompletionPort = Kernel32.CreateIoCompletionPort((IntPtr)(-1), IntPtr.Zero, 0, 1)) == IntPtr.Zero)
                Kernel32.ThrowLastError();


            _sendBufferId = RioStatic.RegisterBuffer(SendBufferPool.BufferPointer, (uint)SendBufferPool.TotalLength);
            WinSock.ThrowLastWSAError();
            SendBufferPool.SetBufferId(_sendBufferId);

            _reciveBufferId = RioStatic.RegisterBuffer(ReceiveBufferPool.BufferPointer, (uint)ReceiveBufferPool.TotalLength);
            WinSock.ThrowLastWSAError();
            ReceiveBufferPool.SetBufferId(_reciveBufferId);

            var sendCompletionMethod = new RIO_NOTIFICATION_COMPLETION()
            {
                Type = RIO_NOTIFICATION_COMPLETION_TYPE.IOCP_COMPLETION,
                Iocp = new RIO_NOTIFICATION_COMPLETION_IOCP()
                {
                    IocpHandle = SendCompletionPort,
                    QueueCorrelation = 0,
                    Overlapped = (NativeOverlapped*)-1
                }
            };

            if ((SendCompletionQueue = RioStatic.CreateCompletionQueue(MaxOutsandingCompletions, sendCompletionMethod)) == IntPtr.Zero)
                WinSock.ThrowLastWSAError();

            var receiveCompletionMethod = new RIO_NOTIFICATION_COMPLETION()
            {
                Type = RIO_NOTIFICATION_COMPLETION_TYPE.IOCP_COMPLETION,
                Iocp = new RIO_NOTIFICATION_COMPLETION_IOCP()
                {
                    IocpHandle = ReceiveCompletionPort,
                    QueueCorrelation = 0,
                    Overlapped = (NativeOverlapped*)-1
                }
            };

            if ((ReceiveCompletionQueue = RioStatic.CreateCompletionQueue(MaxOutsandingCompletions, receiveCompletionMethod)) == IntPtr.Zero)
                WinSock.ThrowLastWSAError();


            Thread receiveThread = new Thread(ProcessReceiveCompletes);
            receiveThread.IsBackground = true;
            receiveThread.Start();
            Thread sendThread = new Thread(ProcessSendCompletes);
            sendThread.IsBackground = true;
            sendThread.Start();

        }