private E <CommandError> SendCommandBase(WaitBlock wb, Ts3Command com) { lock (statusLock) { if (context.WasExit || (!Connected && com.ExpectResponse)) { return(Util.TimeOutCommandError); } if (com.ExpectResponse) { var responseNumber = ++returnCode; var retCodeParameter = new CommandParameter("return_code", responseNumber); com.AppendParameter(retCodeParameter); msgProc.EnqueueRequest(retCodeParameter.Value, wb); } var message = com.ToString(); LogCmd.Debug("[O] {0}", message); byte[] data = Util.Encoder.GetBytes(message); packetHandler.AddOutgoingPacket(data, PacketType.Command); } return(E <CommandError> .OkR); }
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); } }