コード例 #1
0
        private void PacketEvent(ConnectionContext ctx, ref Packet <C2S> packet)
        {
            if (ctx.WasExit)
            {
                return;
            }
            switch (packet.PacketType)
            {
            case PacketType.Command:
            case PacketType.CommandLow:
                var result = msgProc.PushMessage(packet.Data);
                if (result.HasValue)
                {
                    dispatcher.Invoke(result.Value);
                }
                break;

            case PacketType.Init1:
                if (packet.Data.Length >= 301 && packet.Data[4] == 4)
                {
                    initCheckDone = true;
                    var resultI = msgProc.PushMessage(packet.Data.AsMemory(301, packet.Data.Length - 301));
                    if (resultI.HasValue)
                    {
                        dispatcher.Invoke(resultI.Value);
                    }
                }
                break;
            }
        }
コード例 #2
0
        private void PacketEvent(ConnectionContext ctx, ref Packet <S2C> packet)
        {
            switch (packet.PacketType)
            {
            case PacketType.Command:
            case PacketType.CommandLow:
                var data = packet.Data;
                if (Log.IsDebugEnabled)
                {
                    Log.Debug("[I] {0}", Tools.Utf8Encoder.GetString(packet.Data));
                }
                _ = scheduler.Invoke(() =>
                {
                    if (ctx != context)
                    {
                        Log.Debug("Stray packet from old packethandler");
                    }

                    var result = msgProc.PushMessage(data);
                    if (result != null)
                    {
                        InvokeEvent(result.Value);
                    }
                });
                break;

            case PacketType.Voice:
            case PacketType.VoiceWhisper:
                OutStream?.Write(packet.Data, new Meta
                {
                    In = new MetaIn
                    {
                        Whisper = packet.PacketType == PacketType.VoiceWhisper
                    }
                });
                break;

            case PacketType.Init1:
                // Init error
                if (packet.Data.Length == 5 && packet.Data[0] == 1)
                {
                    var errorNum = BinaryPrimitives.ReadUInt32LittleEndian(packet.Data.AsSpan(1));
                    if (Enum.IsDefined(typeof(TsErrorCode), errorNum))
                    {
                        Log.Info("Got init error: {0}", (TsErrorCode)errorNum);
                    }
                    else
                    {
                        Log.Warn("Got undefined init error: {0}", errorNum);
                    }
                    _ = scheduler.Invoke(() => ChangeState(ctx, TsClientStatus.Disconnected));
                }
                break;
            }
        }
コード例 #3
0
        private void PacketEvent(ConnectionContext ctx, ref Packet <S2C> packet)
        {
            lock (statusLock)
            {
                if (ctx.WasExit)
                {
                    return;
                }

                switch (packet.PacketType)
                {
                case PacketType.Command:
                case PacketType.CommandLow:
                    Log.ConditionalDebug("[I] {0}", Tools.Utf8Encoder.GetString(packet.Data));
                    var result = msgProc.PushMessage(packet.Data);
                    if (result.HasValue)
                    {
                        dispatcher.Invoke(result.Value);
                    }
                    break;

                case PacketType.Voice:
                case PacketType.VoiceWhisper:
                    OutStream?.Write(packet.Data, new Meta
                    {
                        In = new MetaIn
                        {
                            Whisper = packet.PacketType == PacketType.VoiceWhisper
                        }
                    });
                    break;

                case PacketType.Init1:
                    // Init error
                    if (packet.Data.Length == 5 && packet.Data[0] == 1)
                    {
                        var errorNum = BinaryPrimitives.ReadUInt32LittleEndian(packet.Data.AsSpan(1));
                        if (Enum.IsDefined(typeof(TsErrorCode), errorNum))
                        {
                            Log.Info("Got init error: {0}", (TsErrorCode)errorNum);
                        }
                        else
                        {
                            Log.Warn("Got undefined init error: {0}", errorNum);
                        }
                        DisconnectInternal(ctx, setStatus: TsClientStatus.Disconnected);
                    }
                    break;
                }
            }
        }
コード例 #4
0
ファイル: Ts3FullClient.cs プロジェクト: sertsch1/TS3AudioBot
        private void NetworkLoop(object ctxObject)
        {
            var ctx = (ConnectionContext)ctxObject;

            while (true)
            {
                lock (statusLock)
                {
                    if (ctx.WasExit)
                    {
                        break;
                    }
                }

                var packet = packetHandler.FetchPacket();
                if (packet == null)
                {
                    break;
                }

                lock (statusLock)
                {
                    if (ctx.WasExit)
                    {
                        break;
                    }

                    switch (packet.PacketType)
                    {
                    case PacketType.Command:
                    case PacketType.CommandLow:
                        string message = Util.Encoder.GetString(packet.Data, 0, packet.Data.Length);
                        LogCmd.Debug("[I] {0}", message);
                        var result = msgProc.PushMessage(message);
                        if (result.HasValue)
                        {
                            dispatcher.Invoke(result.Value);
                        }
                        break;

                    case PacketType.Voice:
                    case PacketType.VoiceWhisper:
                        OutStream?.Write(packet.Data, new Meta
                        {
                            In = new MetaIn
                            {
                                Whisper = packet.PacketType == PacketType.VoiceWhisper
                            }
                        });
                        break;

                    case PacketType.Init1:
                        // Init error
                        if (packet.Data.Length == 5 && packet.Data[0] == 1)
                        {
                            var errorNum = BinaryPrimitives.ReadUInt32LittleEndian(packet.Data.AsReadOnlySpan().Slice(1));
                            if (Enum.IsDefined(typeof(Ts3ErrorCode), errorNum))
                            {
                                Log.Info("Got init error: {0}", (Ts3ErrorCode)errorNum);
                            }
                            else
                            {
                                Log.Warn("Got undefined init error: {0}", errorNum);
                            }
                            DisconnectInternal(ctx, setStatus: Ts3ClientStatus.Disconnected);
                        }
                        break;
                    }
                }
            }

            lock (statusLock)
            {
                DisconnectInternal(ctx, setStatus: Ts3ClientStatus.Disconnected);
            }
        }