コード例 #1
0
 /// <summary>
 /// Creates an empty RADIUS packet.
 /// </summary>
 /// <param name="code">The packet type.</param>
 public RadiusPacket(PacketCode code)
 {
     this.buffer = new byte[4096];
     IsReadOnly  = false;
     Code        = code;
     Length      = 20;
 }
コード例 #2
0
ファイル: PacketCodes.cs プロジェクト: niklaskdk/Cakewalk
        /// <summary>
        /// Get the type for a given packet code.
        /// </summary>
        public static Type GetTypeForPacketCode(PacketCode c)
        {
            Type t = null;

            s_typeMap.TryGetValue(c, out t);

            return(t);
        }
コード例 #3
0
ファイル: PacketCodes.cs プロジェクト: Cakez0r/Cakewalk
        /// <summary>
        /// Get the type for a given packet code.
        /// </summary>
        public static Type GetTypeForPacketCode(PacketCode c)
        {
            Type t = null;

            s_typeMap.TryGetValue(c, out t);

            return t;
        }
コード例 #4
0
 /// <summary>
 /// Creates a response packet with code, authenticator, identifier and secret from the request packet.
 /// </summary>
 /// <param name="responseCode"></param>
 /// <returns></returns>
 public IRadiusPacket CreateResponsePacket(PacketCode responseCode)
 {
     return(new RadiusPacket
     {
         Code = responseCode,
         SharedSecret = SharedSecret,
         Identifier = Identifier,
         _requestAuthenticator = Authenticator
     });
 }
コード例 #5
0
ファイル: Packet.cs プロジェクト: JGDoerrer/KreativerName
        public int FromBytes(byte[] bytes, int startIndex)
        {
            int count = 0;

            Code   = (PacketCode)BitConverter.ToUInt16(bytes, startIndex + count);
            count += 2;
            Info   = (PacketInfo)bytes[startIndex + count];
            count += 1;

            int byteCount = BitConverter.ToInt32(bytes, startIndex + count);

            count += 4;
            Bytes  = bytes.Skip(startIndex + count).Take(byteCount).ToArray();
            count += byteCount;

            return(count);
        }
コード例 #6
0
        private void OnReceived(long peerId, ushort code, CodedInputStream stream)
        {
            PacketCode packetCode = (PacketCode)code;

            Log.Debug(typeof(Program), $"OnReceived PacketCode: {packetCode}, peerId: {peerId}");
            if (packetCode == PacketCode.EnterReq)
            {
                HandleEnterReq(peerId, stream);
            }
            else if (packetCode == PacketCode.MoveReq)
            {
                HandleMoveReq(peerId, stream);
            }
            else if (packetCode == PacketCode.StopReq)
            {
                HandleStopReq(peerId, stream);
            }
        }
コード例 #7
0
        /// <summary>
        /// Create a new packet with a random authenticator
        /// </summary>
        /// <param name="code"></param>
        /// <param name="identifier"></param>
        /// <param name="secret"></param>
        /// <param name="authenticator">Set authenticator for testing</param>
        public RadiusPacket(PacketCode code, Byte identifier, String secret)
        {
            Code         = code;
            Identifier   = identifier;
            SharedSecret = Encoding.UTF8.GetBytes(secret);

            // Generate random authenticator for access request packets
            if (Code == PacketCode.AccessRequest || Code == PacketCode.StatusServer)
            {
                using (var csp = RandomNumberGenerator.Create())
                {
                    csp.GetNonZeroBytes(Authenticator);
                }
            }

            // A Message authenticator is required in status server packets, calculated last
            if (Code == PacketCode.StatusServer)
            {
                AddAttribute("Message-Authenticator", new Byte[16]);
            }
        }
コード例 #8
0
ファイル: ValServer.cs プロジェクト: pb0/ID0_Test
        private ErrCode OnRecvPacket(SmartPacket packet)
        {
            ErrCode            errCode             = ErrCode.Success;
            PacketCode         packetCode          = (PacketCode)packet.Code;
            NotifyEventCode   nec                 = NotifyEventCode.None;
            bool                isNotifyPacket      = false;
            bool                isHandlerCalled     = false;
            object              param1              = null;
            object              param2              = null;

            Log(string.Format("[VAAL] OnRecvPacket : PacketCode={0}", packetCode));

            lock (m_lockVal)
            {
                m_packetCode    = packetCode;
                m_resultCode    = packet.Process(m_proxyServer);
                param1          = packet.Param1;
                param2          = packet.Param2;
                nec             = (NotifyEventCode)packet.Nec;
                isNotifyPacket  = !(packet is TwoWayPacket);

                OneWayPacket onewayPacket = packet as OneWayPacket;
                if (onewayPacket != null && onewayPacket.RecvTransNum > 0)
                {
                    if (m_recvTransNum >= onewayPacket.RecvTransNum)
                    {
                        Log(string.Format("[VAAL] OnRecvPacket : CurRecvTransNum = {0}, PacketRecvTransNum = {1}", m_recvTransNum, onewayPacket.RecvTransNum));
                        return errCode;
                    }
                    m_recvTransNum = onewayPacket.RecvTransNum;
                }

                switch (packetCode)
                {
                    case PacketCode.Hello:
                        {
                            m_eventSyncPacket.Set();

                            if (m_resultCode == (uint)ErrCode.VaalSvrClientVersion)
                            {
                                CallNotifyHandler(NotifyEventCode.LowerClientVersion, m_resultCode, null, null);
                            }

                            isNotifyPacket = true;
                            isHandlerCalled = true;
                        }
                        break;

                    case PacketCode.GetItemListReply:
                        {
                            if (m_resultCode == (uint)ErrCode.Success)
                            {
                                GetItemListReplyPacket packetReply = (GetItemListReplyPacket)packet;

                                byte[] temp = new byte[m_buffer.Length + packetReply.m_buffer.Length];
                                Array.Copy(m_buffer, temp, m_buffer.Length);
                                Array.Copy(packetReply.m_buffer, 0, temp, m_buffer.Length, packetReply.m_buffer.Length);
                                m_buffer = temp;

                                if (packetReply.m_isLastPacket == 0)
                                {
                                    // Waits for next packets.
                                    isHandlerCalled = true;
                                    isNotifyPacket = true;
                                }
                                else
                                {
                                    MemoryStream inMStream = new MemoryStream(m_buffer);
                                    MemoryStream outMStream = new MemoryStream();
                                    ZOutputStream outZStream = new ZOutputStream(outMStream);

                                    CopyStream(inMStream, outZStream);

                                    ItemDataType itemType = (ItemDataType)(byte)param1;

                                    switch (itemType)
                                    {
                                        case ItemDataType.Stage:
                                            StageManager stageManager = new StageManager();
                                            SimpleStream streamStage = new SimpleStream();

                                            streamStage.SetBuffer(outMStream.ToArray(), false);
                                            stageManager.SetHash(m_proxyServer.StageManager.Hash);
                                            stageManager.DeSerialize(streamStage);
                                            m_proxyServer.SetStageManager(stageManager);

                                            param2 = stageManager.Hash;
                                            break;

                                        case ItemDataType.Item:
                                            ItemManager itemManager = new ItemManager();
                                            SimpleStream streamItem = new SimpleStream();

                                            streamItem.SetBuffer(outMStream.ToArray(), false);
                                            itemManager.SetHash(m_proxyServer.ItemManager.Hash);
                                            itemManager.DeSerialize(streamItem);
                                            m_proxyServer.SetItemManager(itemManager);

                                            param2 = itemManager.Hash;
                                            break;
                                    }

                                    outZStream.Close();
                                    outMStream.Close();
                                    inMStream.Close();
                                }
                            }
                        }
                        break;

                    case PacketCode.Login:
                        {
                            LoginPacket packetReply = (LoginPacket)packet;

                            if (m_isLoginPacketSync)
                            {
                                m_eventSyncPacket.Set();
                                isNotifyPacket = true;
                            }

                            if (m_resultCode == (uint)ErrCode.Success)
                            {
                                m_proxyServer.SetLoginState(true);

                                if (packetReply.m_isAlreadyLogined == 0)
                                {
                                    m_sendTransNum = 0;
                                    m_recvTransNum = 0;
                                }
                            }
                        }
                        break;
                }
            }

            if (nec != NotifyEventCode.None)
            {
                if (!isNotifyPacket)
                {
                    lock (m_retryPackets)
                    {
                        List<RetryPacket> packetToBeRemoved = new List<RetryPacket>();

                        foreach (RetryPacket rp in m_retryPackets)
                        {
                            rp.m_event.Set();
                            rp.m_packet.Dispose();

                            if (rp.m_nec == nec)
                            {
                                m_retryPackets.Remove(rp);
                                break;
                            }
                            else
                            {
                                packetToBeRemoved.Add(rp);
                                Log(string.Format("[VAAL] No response. NC={0}", rp.m_nec));
                            }
                        }

                        foreach (RetryPacket rp in packetToBeRemoved)
                        {
                            m_retryPackets.Remove(rp);
                        }
                    }
                }

                if (!isHandlerCalled)
                    CallNotifyHandler(nec, m_resultCode, param1, param2);
            }

            return errCode;
        }
コード例 #9
0
ファイル: Packet.cs プロジェクト: JGDoerrer/KreativerName
 public Packet(PacketCode code, byte[] bytes)
 {
     Code  = code;
     Info  = PacketInfo.None;
     Bytes = bytes;
 }
コード例 #10
0
ファイル: Packet.cs プロジェクト: JGDoerrer/KreativerName
 public Packet(PacketCode code, PacketInfo info, byte[] bytes)
 {
     Code  = code;
     Info  = info;
     Bytes = bytes;
 }
コード例 #11
0
ファイル: Packet.cs プロジェクト: JGDoerrer/KreativerName
 public Packet(PacketCode code, PacketInfo info) : this()
 {
     Code = code;
     Info = info;
 }