示例#1
0
        /// <summary>
        /// Handle packet
        /// </summary>
        /// <param name="client">Client connection</param>
        /// <param name="packetBody">packet data</param>
        public static void Process(ClientConnection client, byte[] packetBody)
        {
            if (packetBody[0] == 1) //if crypto flag is 1, decrypt
            {
                client.Session.Transform(ref packetBody);
            }

            using (var stream = new MemoryStream(packetBody))
                using (var reader = new BinaryReader(stream))
                {
                    var isCrypt  = reader.ReadBoolean(); // need just read for move position, we decrypt before
                    var sequence = reader.ReadInt16();
                    var opCode   = reader.ReadInt16();
                    var body     = reader.ReadBytes(packetBody.Length - 5); // without crypt flag, sequence and opCode length

                    client.SequenceId = sequence;                           // install sequence id

                    lock (RLock)
                        RecvEvent?.Invoke(opCode, body, isCrypt);

                    if (ClientFrames.ContainsKey(opCode))                                                         // check, if packet exist
                    {
                        ((APacketProcessor)Activator.CreateInstance(ClientFrames[opCode])).Process(client, body); // process packet
                    }
                    else if (CfgCore.Default.LogUnkPackets)
                    {
                        Console.WriteLine($"Unknown packet\nOpCode {opCode}\nData:\n {body.FormatHex()}"); // if packet not exist, we cannot proccess hem, just write log
                    }
                }
        }
示例#2
0
 /// <summary>
 /// 音声認識をセットアップします。
 /// </summary>
 /// <param name="Keywords">音声認識で取得したい単語データ</param>
 /// <param name="r">音声認識で単語を取得した際のイベント(void型関数:引数はstring1つのみ)</param>
 public static void Set(string[] Keywords, RecvEvent r)
 {
     WordData[] d = new WordData[Keywords.Length];
     for (int x = 0; x < Keywords.Length; x++)
     {
         d[x] = new WordData(Keywords[x]);
     }
     Set(d, r);
 }
示例#3
0
        private void OnHandshaking()
        {
            RecvEvent.WaitOne(1);
            var atom = RecvAtom();

            if (atom == null)
            {
                return;
            }
            else if (atom.Name == Atom.PCP_OLEH)
            {
                OnPCPOleh(atom);
                OnConnected();
                state = State.Receiving;
            }
            else if (atom.Name == Atom.PCP_QUIT)
            {
                OnPCPQuit(atom);
            }
        }
示例#4
0
 /// <summary>
 /// 音声認識をセットアップします。
 /// </summary>
 /// <param name="d">音声認識で取得したい単語データ</param>
 /// <param name="r">音声認識で単語を取得した際のイベント(void型関数:引数はstring1つのみ)</param>
 public static void Set(WordData[] d, RecvEvent r)
 {
     if (Rec_ != null)
     {
         data = null;
         Rec_.Dispose();
     }
     data = d;
     Rec_ = new KeywordRecognizer(MkList(d));
     Rec_.OnPhraseRecognized += delegate(PhraseRecognizedEventArgs args)
     {
         foreach (WordData xd in data)
         {
             if (xd.Contains(args.text))
             {
                 r(xd.tag);
                 break;
             }
         }
     };
     Rec_.Start();
 }
示例#5
0
        private void OnWaitRequestResponse()
        {
            RecvEvent.WaitOne(1);
            var res = RecvRelayRequestResponse();

            if (res != null)
            {
                if (res.StatusCode == 200 || res.StatusCode == 503)
                {
                    SendPCPHelo();
                    state = State.Handshaking;
                }
                else if (res.StatusCode == 404)
                {
                    Stop(StopReason.OffAir);
                }
                else
                {
                    Stop(StopReason.UnavailableError);
                }
            }
        }
示例#6
0
 public void OnRecveHandler(object sender, RecvEvent e)
 {
     _dispatcher.AddData(e.Message, e.BytesTransferred);
 }
 public static void OnRecvEvent(string message)
 {
     RecvEvent?.Invoke(message);
 }
 public void DelRecvEvent(RecvEvent e)
 {
     _RecvEvent -= e;
 }
 public void RegisterRecvEvent(RecvEvent e)
 {
     _RecvEvent += e;
 }