Skip to content

Commit

Permalink
Fixes and improvements
Browse files Browse the repository at this point in the history
+ Updated launch parameter
+ Added SubscribeAll
+ Added IPv6 support
+ Updated proto
  • Loading branch information
Splamy committed Sep 10, 2017
1 parent 19bf324 commit 03c42f6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Download the git repository with `git clone https://github.com/Splamy/TS3AudioBo
1. See if you have NuGet by just executing `nuget`. If not, get `NuGet.exe` with `wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe`
1. Go into the directory of the repository with `cd TS3AudioBot`
1. Execute `nuget restore` or `mono ../Nuget.exe restore` to download all dependencies
1. Execute `msbuild /p:Configuration=Release /p:Platform=AnyCPU TS3AudioBot.sln` to build the C# AudioBot
1. Execute `msbuild /p:Configuration=Release TS3AudioBot.sln` to build the C# AudioBot
1. Getting the dependencies
* on **Ubuntu**:
Run `sudo apt-get install libopus-dev ffmpeg`
Expand Down Expand Up @@ -106,4 +106,4 @@ This project is licensed under OSL-3.0.
Why OSL-3.0:
- OSL allows you to link to our libraries without needing to disclose your own project, which might be useful if you want to use the TS3Client as a library.
- If you create plugins you do not have to make them public like in GPL. (Although we would be happier if you shared them :)
- With OSL we want to allow you providing the TS3AB as a service (even commercially). We do not want the software to be sold but the service. We want this software to be free for everyone.
- With OSL we want to allow you providing the TS3AB as a service (even commercially). We do not want the software to be sold but the service. We want this software to be free for everyone.
28 changes: 18 additions & 10 deletions TS3AudioBot/MainBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,31 @@ private bool ReadParameter(string[] args)
{
case "-h":
case "--help":
Console.WriteLine(" --Quiet -q Deactivates all output to stdout.");
Console.WriteLine(" --NoLog -L Deactivates writing to the logfile.");
Console.WriteLine(" --Stack -s Adds the stacktrace to all log writes.");
Console.WriteLine(" --Config -c <file> Specifies the path to the config file.");
Console.WriteLine(" --help -h Prints this help....");
Console.WriteLine(" --quiet -q Deactivates all output to stdout.");
Console.WriteLine(" --no-log -L Deactivates writing to the logfile.");
Console.WriteLine(" --stack -s Adds the stacktrace to all log writes.");
Console.WriteLine(" --config -c <file> Specifies the path to the config file.");
Console.WriteLine(" --version -V Gets the bot version.");
Console.WriteLine(" --help -h Prints this help....");
return false;

case "-q":
case "--Quiet":
case "--quiet":
consoleOutput = false;
break;

case "-L":
case "--NoLog":
case "--no-log":
writeLog = false;
break;

case "-s":
case "--Stack":
case "--stack":
writeLogStack = true;
break;

case "-c":
case "--Config":
case "--config":
if (i >= args.Length - 1)
{
Console.WriteLine("No config file specified after \"{0}\"", args[i]);
Expand All @@ -125,6 +126,11 @@ private bool ReadParameter(string[] args)
configFilePath = args[++i];
break;

case "-V":
case "--version":
Console.WriteLine(Util.GetAssemblyData().ToLongString());
return false;

default:
Console.WriteLine("Unrecognized parameter: {0}", args[i]);
return false;
Expand Down Expand Up @@ -1398,6 +1404,7 @@ public ICommandResult CommandTake(ExecutionInformation info, IEnumerable<IComman
throw new CommandException("Can't find a fitting return type for take", CommandExceptionReason.NoReturnMatch);
}

#if DEBUG
[Command("test", "Only for debugging purposes.")]
public JsonObject CommandTest(ExecutionInformation info, string privet)
{
Expand All @@ -1424,6 +1431,7 @@ public JsonTest(string msgval) : base(msgval)

}
}
#endif

[Command("unsubscribe", "Only lets you hear the music in active channels again.")]
public void CommandUnsubscribe(ExecutionInformation info)
Expand Down Expand Up @@ -1720,7 +1728,7 @@ public void Dispose()
PluginManager?.Dispose(); // before: SessionManager, logStream,
PluginManager = null;

PlayManager.Stop();
PlayManager?.Stop();

PlayerConnection?.Dispose(); // before: logStream,
PlayerConnection = null;
Expand Down
1 change: 0 additions & 1 deletion TS3AudioBot/PlayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace TS3AudioBot
using History;
using ResourceFactories;
using System;
using TS3Client.Messages;

public class PlayManager
{
Expand Down
20 changes: 14 additions & 6 deletions TS3Client/Full/PacketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void ConnectUdpClient(string host, ushort port)

remoteAddress = new IPEndPoint(ipAddr, port);

udpClient = new UdpClient();
udpClient = new UdpClient(remoteAddress.AddressFamily);
udpClient.Connect(remoteAddress);
}
catch (SocketException ex) { throw new Ts3Exception("Could not connect", ex); }
Expand All @@ -149,7 +149,7 @@ public void AddOutgoingPacket(byte[] packet, PacketType packetType, PacketFlags
{
if (Closed)
return;

if (NeedsSplitting(packet.Length))
{
if (packetType == PacketType.Voice || packetType == PacketType.VoiceWhisper)
Expand Down Expand Up @@ -191,8 +191,8 @@ private void AddOutgoingPacket(OutgoingPacket packet, PacketFlags flags = Packet
else
packet.PacketFlags |= flags | PacketFlags.Newprotocol;
var ids = GetPacketCounter(packet.PacketType);
packet.PacketId = ids.Item1;
packet.GenerationId = ids.Item2;
packet.PacketId = ids.Id;
packet.GenerationId = ids.Generation;
if (packet.PacketType == PacketType.Voice || packet.PacketType == PacketType.VoiceWhisper)
NetUtil.H2N(packet.PacketId, packet.Data, 0);
if (ts3Crypt.CryptoInitComplete)
Expand All @@ -213,8 +213,8 @@ private void AddOutgoingPacket(OutgoingPacket packet, PacketFlags flags = Packet
}
}

private Tuple<ushort, uint> GetPacketCounter(PacketType packetType)
=> new Tuple<ushort, uint>(packetCounter[(int)packetType], generationCounter[(int)packetType]);
private IdTuple GetPacketCounter(PacketType packetType)
=> new IdTuple(packetCounter[(int)packetType], generationCounter[(int)packetType]);
private void IncPacketCounter(PacketType packetType)
{
packetCounter[(int)packetType]++;
Expand Down Expand Up @@ -588,4 +588,12 @@ private void SendRaw(OutgoingPacket packet)
udpClient.Send(packet.Raw, packet.Raw.Length);
}
}

struct IdTuple
{
public ushort Id { get; set; }
public uint Generation { get; set; }

public IdTuple(ushort id, uint generation) { Id = id; Generation = generation; }
}
}
11 changes: 9 additions & 2 deletions TS3Client/Full/Ts3FullClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public sealed class Ts3FullClient : Ts3BaseFunctions
public override event NotifyEventHandler<TextMessage> OnTextMessageReceived;
public override event NotifyEventHandler<ClientEnterView> OnClientEnterView;
public override event NotifyEventHandler<ClientLeftView> OnClientLeftView;
public event NotifyEventHandler<ClientMoved> OnClientMoved;
public override event EventHandler<EventArgs> OnConnected;
public override event EventHandler<DisconnectEventArgs> OnDisconnected;
public event EventHandler<CommandError> OnErrorEvent;
Expand Down Expand Up @@ -157,15 +158,15 @@ private void InvokeEvent(LazyNotification lazyNotification)
OnClientLeftView?.Invoke(this, clientLeftArr);
break;

case NotificationType.ClientMoved: break;
case NotificationType.ClientMoved: OnClientMoved?.Invoke(this, notification.Cast<ClientMoved>()); break;
case NotificationType.ServerEdited: break;
case NotificationType.TextMessage: OnTextMessageReceived?.Invoke(this, notification.Cast<TextMessage>()); break;
case NotificationType.TokenUsed: break;
// full client events
case NotificationType.InitIvExpand: ProcessInitIvExpand((InitIvExpand)notification.FirstOrDefault()); break;
case NotificationType.InitServer: ProcessInitServer((InitServer)notification.FirstOrDefault()); break;
case NotificationType.ChannelList: break;
case NotificationType.ChannelListFinished: break;
case NotificationType.ChannelListFinished: ChannelSubscribeAll(); break;
case NotificationType.ClientNeededPermissions: break;
case NotificationType.ClientChannelGroupChanged: break;
case NotificationType.ClientServerGroupAdded: break;
Expand Down Expand Up @@ -360,6 +361,12 @@ public void ClientDisconnect(MoveReason reason, string reasonMsg)
new CommandParameter("reasonid", (int)reason),
new CommandParameter("reasonmsg", reasonMsg) }));

public void ChannelSubscribeAll()
=> Send("channelsubscribeall");

public void ChannelUnsubscribeAll()
=> Send("channelunsubscribeall");

public void SendAudio(byte[] buffer, int length, Codec codec)
{
// [X,X,Y,DATA]
Expand Down
2 changes: 1 addition & 1 deletion TS3Client/ts3protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ The packet header values are set as following for all packets here:
| nonce | N/A |
| Type | Init1 |
| Encrypted ||
| Flags | Newprotocol |
| Flags | Newprotocol, Unencrypted |
| Packet Id | u16: 101 |
| Client Id | u16: 0 |

Expand Down

0 comments on commit 03c42f6

Please sign in to comment.