예제 #1
0
        override public void FromBytes(BinaryReader br)
        {
            base.FromBytes(br);

            int userCount     = DecodeInteger(br);
            int emoticonCount = DecodeInteger(br);
            int presentCount  = DecodeInteger(br);

            for (int i = 0; i < userCount; i++)
            {
                UserInfo userInfo = (UserInfo)BaseInfo.CreateInstance(br);
                Users.Add(userInfo);
            }

            for (int i = 0; i < emoticonCount; i++)
            {
                IconInfo presentInfo = (IconInfo)BaseInfo.CreateInstance(br);
                Emoticons.Add(presentInfo);
            }

            for (int i = 0; i < presentCount; i++)
            {
                IconInfo presentInfo = (IconInfo)BaseInfo.CreateInstance(br);
                Presents.Add(presentInfo);
            }

            strRoomID = DecodeString(br);
        }
예제 #2
0
        void udpReceiveCallback(IAsyncResult ar)
        {
            try
            {
                UdpClient  udpServer      = ar.AsyncState as UdpClient;
                IPEndPoint remoteEndPoint = null;

                byte[] receiveBytes = udpServer.EndReceive(ar, ref remoteEndPoint);

                MemoryStream ms = new MemoryStream(receiveBytes, false);
                BinaryReader br = new BinaryReader(ms);

                NotifyType notifyType = (NotifyType)DecodeInteger(br);

                BaseInfo baseInfo = BaseInfo.CreateInstance(br);

                br.Close();
                ms.Close();

                if (_NotifyUdpHandler != null)
                {
                    _NotifyUdpHandler(notifyType, remoteEndPoint, baseInfo);
                }

                udpServer.BeginReceive(udpReceiveCallback, udpServer);
            }
            catch (Exception e)
            {
                SetError(ErrorType.Fail_WaitSocket, "소켓대기 실패: " + e.Message);
                //_notifyUdpHandler(NotifyType.Notify_Socket, soc, null);
            }
        }
예제 #3
0
        override public void FromBytes(BinaryReader br)
        {
            base.FromBytes(br);

            _TableId        = DecodeString(br);
            _RoundIndex     = DecodeInteger(br);
            _RoundDelayTime = DecodeInteger(br);

            int playerCount = DecodeInteger(br);

            for (int i = 0; i < playerCount; i++)
            {
                UserInfo userInfo = (UserInfo)BaseInfo.CreateInstance(br);
                _Players.Add(userInfo);
            }

            // added by usc at 2014/04/03
            int viewerCount = DecodeInteger(br);

            for (int i = 0; i < viewerCount; i++)
            {
                UserInfo userInfo = (UserInfo)BaseInfo.CreateInstance(br);
                _Viewers.Add(userInfo);
            }

            m_lMinScore = DecodeInteger(br);

            for (int i = 0; i < playerCount; i++)
            {
                m_lUserWinScore[i] = DecodeInteger(br);
            }

            m_nCashOrPointGame = DecodeInteger(br);
        }
예제 #4
0
        override public void FromBytes(BinaryReader br)
        {
            base.FromBytes(br);

            int count = DecodeInteger(br);

            for (int i = 0; i < count; i++)
            {
                UserInfo userInfo = (UserInfo)BaseInfo.CreateInstance(br);
                _Users.Add(userInfo);
            }
        }
예제 #5
0
        override public void FromBytes(BinaryReader br)
        {
            base.FromBytes(br);

            int pictureCount = DecodeInteger(br);

            for (int i = 0; i < pictureCount; i++)
            {
                ClassTypeInfo classTypeInfo = (ClassTypeInfo)BaseInfo.CreateInstance(br);
                ClassType.Add(classTypeInfo);
            }
        }
예제 #6
0
        override public void FromBytes(BinaryReader br)
        {
            base.FromBytes(br);

            int nDWFileCount = DecodeInteger(br);

            for (int i = 0; i < nDWFileCount; i++)
            {
                //DecodeInteger(br);

                string strFileName = DecodeString(br);
                listGameFile.Add(strFileName);
            }

            gameInfo = (GameInfo)BaseInfo.CreateInstance(br);
        }
예제 #7
0
        private void HandleEvent(BinaryReader br, Socket socket)
        {
            try
            {
                NotifyType notifyType = (NotifyType)DecodeInteger(br);

                // Temp
                //SetError(ErrorType.Fail_ReceiveSocket, notifyType.ToString());

                BaseInfo baseInfo = BaseInfo.CreateInstance(br);

                _NotifyHandler(notifyType, socket, baseInfo);

                SocketBuffer socketBuffer = FindBuffer(socket);
                socketBuffer._CompleteBuffer = null;
            }
            catch (Exception ex)
            {
                _errorLogs.Add(ex.ToString());
                //BaseInfo.SetError(ErrorType.Exception_Occur, ex.Message + "\n" + ex.StackTrace);
                //ErrorView.AddErrorString();
            }
        }
예제 #8
0
        override public void FromBytes(BinaryReader br)
        {
            base.FromBytes(br);

            Id        = DecodeString(br);
            Name      = DecodeString(br);
            Kind      = DecodeInteger(br);
            Icon      = DecodeString(br);
            Owner     = DecodeString(br);
            UserCount = DecodeInteger(br);
            Cash      = DecodeInteger(br);
            Point     = DecodeInteger(br);
            MaxUsers  = DecodeInteger(br);
            IsGame    = DecodeInteger(br);
            RoomPass  = DecodeString(br);

            if (IsGame > 0)
            {
                _GameInfo = (GameInfo)BaseInfo.CreateInstance(br);
            }

            _strUserID   = DecodeString(br);
            _strTargetID = DecodeString(br);
        }
예제 #9
0
        private void HandleEvent(BinaryReader br)
        {
            // 마지막으로 접수된 패킷의 시간.

            _dtPing = DateTime.Now;

            NotifyType notifyType = (NotifyType)DecodeInteger(br);

            // Temp
            //SetError(ErrorType.Fail_ReceiveSocket, notifyType.ToString());

            BaseInfo baseInfo = BaseInfo.CreateInstance(br);

            baseInfo._dtReceiveTime = System.DateTime.Now;

            // 2013-12-27: GreenRose
            switch (notifyType)
            {
            case NotifyType.Reply_RoomDetail:
            {
                Console.WriteLine("Reply_roomDetail");
                RoomDetailInfo roomDetailInfo = (RoomDetailInfo)baseInfo;
            }
            break;

            case NotifyType.Reply_EnterMeeting:
            {
                Console.WriteLine("Reply_EnterMeeting");
            }
            break;

            case NotifyType.Reply_ClassInfo:
            {
                Console.WriteLine("Reply_ClassInfo");
            }
            break;
            }

            ResultInfo resultInfo = new ResultInfo();

            if (notifyType == NotifyType.Notify_Ping)
            {
                _dtPing = DateTime.Now;
                if (_ClientConneted == null || !_ClientConneted.IsAlive)
                {
                    _ClientConneted = new Thread(OnClientConnected);
                    _ClientConneted.Start();
                }

                Send(NotifyType.Notify_Ping, resultInfo);
            }
            else if (notifyType == NotifyType.Reply_VoiceChat)
            {
                _NotifyHandler(notifyType, null, baseInfo);
            }
            else
            {
                _NotifyTypes.Add(notifyType);
                _ReceiveInfos.Add(baseInfo);
            }

            _CompleteBuffer = null;

            if (_InvokeMethod != null)
            {
                _InvokeMethod();
            }
        }
예제 #10
0
        //int nRecevieSum = 0;
        private void OnDataReceived(IAsyncResult asyn)
        {
            try
            {
                SocketPacket theSockId = (SocketPacket)asyn.AsyncState;
                Byte[]       buffer    = theSockId.dataBuffer;
                int          iRx       = theSockId.thisSocket.EndReceive(asyn);

                //nRecevieSum += iRx;

                //SetError(ErrorType.Fail_SendSocket, nRecevieSum.ToString());

                // Temp
                //SetError(ErrorType.Fail_ReceiveSocket, iRx.ToString());

                MemoryStream ms = new MemoryStream(buffer, false);
                BinaryReader br = new BinaryReader(ms);

                while (iRx > 0)
                {
                    if (_CompleteBuffer == null)
                    {
                        HeaderInfo headerInfo = (HeaderInfo)BaseInfo.CreateInstance(br);

                        if (headerInfo == null)
                        {
                            break;
                        }

                        if (headerInfo._Header != HeaderInfo.Marker)
                        {
                            break;
                        }

                        _CompleteCount = headerInfo._BodySize;
                        _ReceiveCount  = iRx - headerInfo.GetSize();

                        if (_CompleteCount > _ReceiveCount)
                        {
                            _CompleteBuffer = new byte[_CompleteCount + 1];

                            for (int i = 0; i < _ReceiveCount; i++)
                            {
                                _CompleteBuffer[i] = br.ReadByte();
                            }

                            break;
                        }

                        iRx -= headerInfo.GetSize();
                        iRx -= _CompleteCount;
                    }
                    else
                    {
                        int readCount = _CompleteCount - _ReceiveCount;

                        if (readCount > iRx)
                        {
                            readCount = iRx;
                        }

                        for (int i = 0; i < readCount; i++)
                        {
                            _CompleteBuffer[_ReceiveCount + i] = br.ReadByte();
                        }

                        _ReceiveCount += readCount;

                        if (_CompleteCount > _ReceiveCount)
                        {
                            break;
                        }

                        iRx -= readCount;
                    }

                    if (_CompleteBuffer != null)
                    {
                        MemoryStream memoryStream = new MemoryStream(_CompleteBuffer, false);
                        BinaryReader binaryReader = new BinaryReader(memoryStream);

                        HandleEvent(binaryReader);

                        binaryReader.Close();
                        memoryStream.Close();
                    }
                    else
                    {
                        HandleEvent(br);
                    }
                }
                br.Close();
                ms.Close();

                WaitForData();

                Thread.Sleep(0);
            }
            catch (ObjectDisposedException)
            {
                //SetError(ErrorType.Fail_ReceiveSocket, "OnDataReceived: Socket has been closed");
                //_NotifyHandler(NotifyType.Notify_Socket, null, null);

                //_ClientSocket.Shutdown(SocketShutdown.Both);
                //_ClientSocket.Disconnect(true);
                //_ClientSocket.Close();
                //_ClientSocket.Dispose();

                //_ClientReconnect = new Thread(Reconnect);
                //_ClientReconnect.Start();
            }
            catch (SocketException ex)
            {
                SetError(ErrorType.Fail_ReceiveSocket, "소켓수신 실패: 소켓을 열수 없습니다." + ex.ToString());

                //try
                //{
                //    _ClientSocket.Shutdown(SocketShutdown.Both);
                //    _ClientSocket.Disconnect(true);
                //    _ClientSocket.Close();
                //    _ClientSocket.Dispose();
                //    _ClientSocket = null;
                //}
                //catch (Exception ex1)
                //{
                //    SetError(ErrorType.Fail_CoonectSocket, ex1.ToString());
                //}

                //Thread.Sleep(1000);

                //if (_ClientReconnect != null)
                //{
                //    _ClientReconnect.Abort();
                //    _ClientReconnect = null;
                //}

                //_ClientReconnect = new Thread(Reconnect);
                //_ClientReconnect.Start();
            }
            catch { }
        }
예제 #11
0
        override public void FromBytes(BinaryReader br)
        {
            base.FromBytes(br);

            int faceCount           = DecodeInteger(br);
            int roomCount           = DecodeInteger(br);
            int partnerCount        = DecodeInteger(br);
            int evalHistoryCount    = DecodeInteger(br);
            int chatHistoryCount    = DecodeInteger(br);
            int chargeHistoryCount  = DecodeInteger(br);
            int gameHistoryCount    = DecodeInteger(br);
            int presentHistoryCount = DecodeInteger(br);



            for (int i = 0; i < faceCount; i++)
            {
                IconInfo faceInfo = (IconInfo)BaseInfo.CreateInstance(br);
                Faces.Add(faceInfo);
            }

            for (int i = 0; i < roomCount; i++)
            {
                RoomInfo roomInfo = (RoomInfo)BaseInfo.CreateInstance(br);
                Rooms.Add(roomInfo);
            }

            for (int i = 0; i < partnerCount; i++)
            {
                UserInfo partnerInfo = (UserInfo)BaseInfo.CreateInstance(br);
                Partners.Add(partnerInfo);
            }

            for (int i = 0; i < evalHistoryCount; i++)
            {
                EvalHistoryInfo evalHistoryInfo = (EvalHistoryInfo)BaseInfo.CreateInstance(br);
                EvalHistories.Add(evalHistoryInfo);
            }

            for (int i = 0; i < chatHistoryCount; i++)
            {
                ChatHistoryInfo chatHistoryInfo = (ChatHistoryInfo)BaseInfo.CreateInstance(br);
                ChatHistories.Add(chatHistoryInfo);
            }

            for (int i = 0; i < chargeHistoryCount; i++)
            {
                ChargeHistoryInfo chargeHistoryInfo = (ChargeHistoryInfo)BaseInfo.CreateInstance(br);
                ChargeHistories.Add(chargeHistoryInfo);
            }

            for (int i = 0; i < gameHistoryCount; i++)
            {
                GameHistoryInfo gameHistoryInfo = (GameHistoryInfo)BaseInfo.CreateInstance(br);
                GameHistories.Add(gameHistoryInfo);
            }

            for (int i = 0; i < presentHistoryCount; i++)
            {
                PresentHistoryInfo presentHistoryInfo = (PresentHistoryInfo)BaseInfo.CreateInstance(br);
                PresentHistories.Add(presentHistoryInfo);
            }



            _strDownUrl = DecodeString(br);
        }
예제 #12
0
        public void OnDataReceived(IAsyncResult asyn)//For Server Mode
        {
            lock (_objLockMain)
            {
                KeyValuePair aKeyValuePair = (KeyValuePair)asyn.AsyncState;

                Socket socket = aKeyValuePair._Socket;
                Byte[] buffer = aKeyValuePair._DataBuffer;


                try
                {
                    int iRx = socket.EndReceive(asyn);
                    if (iRx == 0 && socket.Available == 0)
                    {
                        socket.Shutdown(SocketShutdown.Both);
                        socket.Disconnect(true);
                        socket.Close();
                        _NotifyHandler(NotifyType.Notify_Socket, socket, null);
                    }

                    MemoryStream ms = new MemoryStream(buffer, false);
                    BinaryReader br = new BinaryReader(ms);

                    // Temp
                    //SetError(ErrorType.Fail_ReceiveSocket, iRx.ToString());

                    SocketBuffer socketBuffer = FindBuffer(socket);

                    while (iRx > 0)
                    {
                        if (socketBuffer._CompleteBuffer == null)
                        {
                            HeaderInfo headerInfo = (HeaderInfo)BaseInfo.CreateInstance(br);

                            if (headerInfo == null)
                            {
                                break;
                            }

                            if (headerInfo._Header != HeaderInfo.Marker)
                            {
                                break;
                            }

                            socketBuffer._CompleteCount = headerInfo._BodySize;
                            socketBuffer._ReceiveCount  = iRx - headerInfo.GetSize();

                            if (socketBuffer._CompleteCount > socketBuffer._ReceiveCount)
                            {
                                socketBuffer._CompleteBuffer = new byte[socketBuffer._CompleteCount + 1];

                                for (int i = 0; i < socketBuffer._ReceiveCount; i++)
                                {
                                    socketBuffer._CompleteBuffer[i] = br.ReadByte();
                                }

                                break;
                            }

                            iRx -= headerInfo.GetSize();
                            iRx -= socketBuffer._CompleteCount;
                        }
                        else
                        {
                            int readCount = socketBuffer._CompleteCount - socketBuffer._ReceiveCount;

                            if (readCount > iRx)
                            {
                                readCount = iRx;
                            }

                            for (int i = 0; i < readCount; i++)
                            {
                                socketBuffer._CompleteBuffer[socketBuffer._ReceiveCount + i] = br.ReadByte();
                            }

                            socketBuffer._ReceiveCount += readCount;

                            if (socketBuffer._CompleteCount > socketBuffer._ReceiveCount)
                            {
                                break;
                            }

                            iRx -= readCount;
                        }

                        if (socketBuffer._CompleteBuffer != null)
                        {
                            MemoryStream memoryStream = new MemoryStream(socketBuffer._CompleteBuffer, false);
                            BinaryReader binaryReader = new BinaryReader(memoryStream);

                            HandleEvent(binaryReader, socket);

                            binaryReader.Close();
                            memoryStream.Close();
                        }
                        else
                        {
                            HandleEvent(br, socket);
                        }
                    }
                    br.Close();
                    ms.Close();

                    WaitForData(socket);

                    System.Threading.Thread.Sleep(0);
                }
                catch (Exception e)
                {
                    SetError(ErrorType.Fail_ReceiveSocket, "소켓수신 실패: 소켓을 열수 없습니다." + e.ToString());
                    //socket.Shutdown(SocketShutdown.Both);
                    //socket.Disconnect(true);
                    //socket.Close();
                    //_NotifyHandler(NotifyType.Notify_Socket, socket, null);
                }
            }
        }