public void AddFromQueue(Queue <PacketClass> fromClient)
        {
            if (_socketList.Count != 0)
            {
                for (int n = 0; n < _socketList.Count; n++)
                {
                    byte[] buffer;
                    int    recvLen;
                    if (_socketList[n].ReceiveBuffer(out buffer, out recvLen))
                    {
                        DefinedStructure.PacketInfo pInfo = new DefinedStructure.PacketInfo();
                        pInfo = (DefinedStructure.PacketInfo)ConvertPacket.ByteArrayToStructure(buffer, pInfo.GetType(), recvLen);

                        PacketClass packet = new PacketClass(pInfo._id, pInfo._data, pInfo._totalSize, n, _socketList[n]._UUID);
                        fromClient.Enqueue(packet);
                    }
                }
            }
        }
예제 #2
0
        void Accept()
        {
            try
            {
                while (true)
                {
                    if (_waitServer != null && _waitServer.Poll(0, SelectMode.SelectRead))
                    {
                        _socketManager.AddSocket(new SocketClass(_waitServer.Accept()));

                        Console.WriteLine("Client Accept");
                    }

                    _socketManager.AddFromQueue(_fromClientQueue);

                    if (_dbServer != null && _dbServer.Poll(0, SelectMode.SelectRead))
                    {
                        byte[] buffer  = new byte[1032];
                        int    recvLen = _dbServer.Receive(buffer);
                        if (recvLen > 0)
                        {
                            DefinedStructure.PacketInfo pToClient = new DefinedStructure.PacketInfo();
                            pToClient = (DefinedStructure.PacketInfo)ConvertPacket.ByteArrayToStructure(buffer, pToClient.GetType(), recvLen);

                            PacketClass packet = new PacketClass(pToClient._id, pToClient._data, pToClient._totalSize);
                            _toServerQueue.Enqueue(packet);
                        }
                    }

                    Thread.Sleep(10);
                }
            }
            catch (ThreadInterruptedException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
예제 #3
0
        void MakePacket(int packetID, object str)
        {
            DefinedStructure.PacketInfo packet;
            packet._id   = packetID;
            packet._data = new byte[1024];

            if (str != null)
            {
                byte[] temp = ConvertPacket.StructureToByteArray(str);
                for (int n = 0; n < temp.Length; n++)
                {
                    packet._data[n] = temp[n];
                }
                packet._totalSize = temp.Length;
            }
            else
            {
                packet._totalSize = packet._data.Length;
            }

            _data     = ConvertPacket.StructureToByteArray(packet);
            _dataSize = _data.Length;
        }
예제 #4
0
        void TurnAI(int roomNum, CardBattleAI ai, int index)
        {
            int[] select;

            if (!ai.Check(_iconIndexesDic[roomNum], out select))
            {
                Random rd = new Random();
                select = new int[2];

                do
                {
                    select[0] = rd.Next(0, _cardCount);
                }while (_isClickableDic[roomNum][select[0]]);

                do
                {
                    select[1] = rd.Next(0, _cardCount);
                }while (select[0] == select[1] || _isClickableDic[roomNum][select[1]]);
            }

            DefinedStructure.Packet_ChooseCard pChooseCard;
            pChooseCard._UUID       = 0;
            pChooseCard._roomNumber = roomNum;
            pChooseCard._cardIdx1   = select[0];
            pChooseCard._cardIdx2   = select[1];
            pChooseCard._slotIndex  = index;

            DefinedStructure.PacketInfo packetInfo;
            packetInfo._id        = (int)DefinedProtocol.eFromClient.ChooseCard;
            packetInfo._data      = ConvertPacket.StructureToByteArray(pChooseCard);
            packetInfo._totalSize = packetInfo._data.Length;

            PacketClass packet = new PacketClass(packetInfo._id, packetInfo._data, packetInfo._totalSize);

            _fromClientQueue.Enqueue(packet);
        }
예제 #5
0
 public object Convert(Type type)
 {
     return(ConvertPacket.ByteArrayToStructure(_data, type, _dataSize));
 }