Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconstructed Project #57

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions src/TeamSpeak3QueryApi.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using TeamSpeak3QueryApi.Net.Specialized;
using TeamSpeak3QueryApi.Net.Specialized.Notifications;
using TeamSpeak3QueryApi.Net.Enums;
using TeamSpeak3QueryApi.Net.Notifications;

namespace TeamSpeak3QueryApi.Net.Demo
{
Expand All @@ -20,28 +20,27 @@ static async Task Main(string[] args)
var password = loginData[2].Trim();

var rc = new TeamSpeakClient(host);

await rc.Connect();

await rc.Login(user, password);
await rc.UseServer(1);

await rc.WhoAmI();
await rc.LoginAsync(user, password);
await rc.UseServerAsync(1);

await rc.RegisterServerNotification();
await rc.RegisterChannelNotification(30);
await rc.WhoAmIAsync();

var serverGroups = await rc.GetServerGroups();
var firstNormalGroup = serverGroups?.FirstOrDefault(s => s.ServerGroupType == ServerGroupType.NormalGroup);
var groupClients = await rc.GetServerGroupClientList(firstNormalGroup.Id);
await rc.RegisterServerNotificationAsync();
await rc.RegisterAllChannelNotificationAsync();

var serverGroups = await rc.GetServerGroupsAsync();
var firstNormalGroup = serverGroups?.FirstOrDefault(s => s.ServerGroupType == ServerGroupType.NormalGroup && s.Id != 46); // Id 46 is default Servergroup

var currentClients = await rc.GetClients();
var groupClients = await rc.GetServerGroupClientListAsync(firstNormalGroup.Id);
var currentClients = await rc.GetClientsAsync();

var fullClients = currentClients.Where(c => c.Type == ClientType.FullClient).ToList();
await rc.KickClient(fullClients, KickOrigin.Channel);
await rc.KickClientAsync(fullClients, KickOrigin.Channel, "You're kicked from channel");

// await rc.MoveClient(1, 1);
// await rc.KickClient(1, KickTarget.Server);
// await rc.MoveClientAsync(1, 1);
// await rc.KickClientAsync(1, KickTarget.Server);

rc.Subscribe<ClientEnterView>(data => data.ForEach(c => Debug.WriteLine($"Client {c.NickName} joined.")));
rc.Subscribe<ClientLeftView>(data => data.ForEach(c => Debug.WriteLine($"Client with id {c.Id} left (kicked/banned/left).")));
Expand Down
2 changes: 1 addition & 1 deletion src/TeamSpeak3QueryApi.Demo/TeamSpeak3QueryApi.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using TeamSpeak3QueryApi.Net.Enums;
using TeamSpeak3QueryApi.Net.Interfaces;
using TeamSpeak3QueryApi.Net.Query;

namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net
{
internal static class DataProxy
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
public enum ClientType
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
[Flags]
public enum GetChannelOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
[Flags]
public enum GetClientOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
[Flags]
public enum GetServerOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
public enum KickOrigin
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net
namespace TeamSpeak3QueryApi.Net.Enums
{
public enum HostMessageMode
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
public enum MessageTarget
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
internal enum NotificationEventTarget
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
///<remarks>http://redeemer.biz/medien/artikel/ts3-query-notify/</remarks>
public enum NotificationType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
public enum ReasonId
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Enums
{
public enum ServerGroupType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using System.Collections.Generic;

namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Extensions
{
internal static class EnumExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace TeamSpeak3QueryApi.Net
namespace TeamSpeak3QueryApi.Net.Extensions
{
internal static class ListExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net
namespace TeamSpeak3QueryApi.Net.Extensions
{
internal static class StringExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace TeamSpeak3QueryApi.Net
namespace TeamSpeak3QueryApi.Net.Extensions
{
internal static class TaskExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;
using System.Threading.Tasks;

namespace TeamSpeak3QueryApi.Net
namespace TeamSpeak3QueryApi.Net.FileTransfer
{
internal class FileTransferClient
{
Expand All @@ -20,43 +20,43 @@ public int GetFileTransferId()
return _currentFileTransferId++;
}

public async Task SendFile(byte[] data, int port, string key)
public async Task SendFileAsync(byte[] data, int port, string key)
{
using var client = new TcpClient();
await client.ConnectAsync(_host, port).ConfigureAwait(false);
using var ns = client.GetStream();

// Send key
// SendAsync key
var keyBytes = Encoding.ASCII.GetBytes(key);
await ns.WriteAsync(keyBytes, 0, keyBytes.Length).ConfigureAwait(false);
await ns.FlushAsync().ConfigureAwait(false);

// Send data
// SendAsync data
await ns.WriteAsync(data, 0, data.Length).ConfigureAwait(false);
}

public async Task SendFile(Stream dataStream, int port, string key)
public async Task SendFileAsync(Stream dataStream, int port, string key)
{
using var client = new TcpClient();
await client.ConnectAsync(_host, port).ConfigureAwait(false);
using var ns = client.GetStream();

// Send key
// SendAsync key
var keyBytes = Encoding.ASCII.GetBytes(key);
await ns.WriteAsync(keyBytes, 0, keyBytes.Length).ConfigureAwait(false);
await ns.FlushAsync().ConfigureAwait(false);

// Send data
// SendAsync data
await dataStream.CopyToAsync(ns).ConfigureAwait(false);
}

public async Task<Stream> ReceiveFile(int size, int port, string key)
public async Task<Stream> ReceiveFileAsync(int size, int port, string key)
{
using var client = new TcpClient();
await client.ConnectAsync(_host, port).ConfigureAwait(false);
using var ns = client.GetStream();

// Send key
// SendAsync key
var keyBytes = Encoding.ASCII.GetBytes(key);
await ns.WriteAsync(keyBytes, 0, keyBytes.Length).ConfigureAwait(false);
await ns.FlushAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace TeamSpeak3QueryApi.Net
namespace TeamSpeak3QueryApi.Net.FileTransfer
{
/// <summary>Represents errors that occur during file transfers.</summary>
[Serializable]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Interfaces
{
interface ITeamSpeakSerializable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using TeamSpeak3QueryApi.Net.Extensions;

namespace TeamSpeak3QueryApi.Net.Specialized
namespace TeamSpeak3QueryApi.Net.Interfaces
{
interface ITypeCaster
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using TeamSpeak3QueryApi.Net.Enums;

namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ChannelCreated : InvokerInformation
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ChannelDeleted : InvokerInformation
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ChannelDescriptionChanged : Notification
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using TeamSpeak3QueryApi.Net.Enums;

namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ChannelEdited : InvokerInformation
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ChannelMoved : InvokerInformation
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ChannelPasswordChanged : Notification
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using TeamSpeak3QueryApi.Net.Enums;

namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ClientEnterView : Notification
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using TeamSpeak3QueryApi.Net.Enums;

namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ClientLeftView : Notification
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ClientMoved : InvokerInformation
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
using TeamSpeak3QueryApi.Net.Enums;

namespace TeamSpeak3QueryApi.Net.Notifications
{
public abstract class InvokerInformation : Notification
{
Expand Down
7 changes: 7 additions & 0 deletions src/TeamSpeak3QueryApi/Notifications/Notification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using TeamSpeak3QueryApi.Net.Interfaces;

namespace TeamSpeak3QueryApi.Net.Notifications
{
public abstract class Notification : ITeamSpeakSerializable
{ }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using TeamSpeak3QueryApi.Net.Query;

namespace TeamSpeak3QueryApi.Net
namespace TeamSpeak3QueryApi.Net.Notifications
{
/// <summary>Provides data that was retrieved by a notification.</summary>
public class NotificationData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using TeamSpeak3QueryApi.Net.Enums;

namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class ServerEdited : Notification
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
using TeamSpeak3QueryApi.Net.Enums;

namespace TeamSpeak3QueryApi.Net.Notifications
{
public class TextMessage : InvokerInformation
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net.Specialized.Notifications
namespace TeamSpeak3QueryApi.Net.Notifications
{
public class TokenUsed : InvokerInformation
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamSpeak3QueryApi.Net
namespace TeamSpeak3QueryApi.Net.Parameters
{
/// <summary>Represents an abstraction of a parameter value.</summary>
public interface IParameterValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Diagnostics;

namespace TeamSpeak3QueryApi.Net
namespace TeamSpeak3QueryApi.Net.Parameters
{
/// <summary>Represents a Query API parameter.</summary>
public class Parameter
Expand Down
Loading