private void SendCommandBase(WaitBlock wb, Ts3Command com) { lock (CommmandQueueLock) { if (com.ExpectResponse) { var retCode = new CommandParameter("return_code", returnCode); com.AppendParameter(retCode); msgProc.EnqueueRequest(retCode.Value, wb); returnCode++; } byte[] data = Util.Encoder.GetBytes(com.ToString()); lock (StatusLock) { if (wasExit) { throw new Ts3CommandException(new CommandError { Id = Ts3ErrorCode.custom_error, Message = "Connection closed" }); } packetHandler.AddOutgoingPacket(data, PacketType.Command); } } }
// serverrequestconnectioninfo // servergetvariables // Splitted base commands public override ServerGroupAddResponse ServerGroupAdd(string name, PermissionGroupDatabaseType?type = null) { var cmd = new Ts3Command("servergroupadd", new List <ICommandPart> { new CommandParameter("name", name) }); if (type.HasValue) { cmd.AppendParameter(new CommandParameter("type", (int)type.Value)); } var answer = SendSpecialCommand(cmd, NotificationType.ServerGroupList).Notifications .Cast <ServerGroupList>() .FirstOrDefault(x => x.Name == name); if (answer == null) { throw new Ts3CommandException(new CommandError() { Id = Ts3ErrorCode.custom_error, Message = "Missing answer" }); } else { return new ServerGroupAddResponse() { ServerGroupId = answer.ServerGroupId } }; }
// serverrequestconnectioninfo // servergetvariables // Splitted base commands public override R <ServerGroupAddResponse, CommandError> ServerGroupAdd(string name, GroupType?type = null) { var cmd = new Ts3Command("servergroupadd", new List <ICommandPart> { new CommandParameter("name", name) }); if (type.HasValue) { cmd.AppendParameter(new CommandParameter("type", (int)type.Value)); } var result = SendNotifyCommand(cmd, NotificationType.ServerGroupList); if (!result.Ok) { return(result.Error); } return(result.Value.Notifications .Cast <ServerGroupList>() .Where(x => x.Name == name) .Take(1) .Select(x => new ServerGroupAddResponse() { ServerGroupId = x.ServerGroupId }) .WrapSingle()); }
public void takeAction(Client client, string section, bool alreadyBlocked = false) { if (!alreadyBlocked) { if (!String.IsNullOrWhiteSpace(cfg[section]["msg"])) { try { Message(client, parseMSG(cfg[section]["msg"], client)); } catch (Exception ex) { PluginLog(Log.Level.Warning, $"Could not message {client.NickName}:\n{ex.Message}"); } } if (!String.IsNullOrWhiteSpace(cfg[section]["poke"])) { try { Poke(client, parseMSG(cfg[section]["poke"], client)); } catch (Exception ex) { PluginLog(Log.Level.Warning, $"Could not poke {client.NickName}:\n{ex.Message}"); } } } if (cfg[section]["kickonly"] == "true") { //bot.QueryConnection.KickClientFromServer(client.Id, (parseMSG(cfg[section]["reason"]); try { // clientkick reasonid=5 reasonmsg=test clid=1 var cmd = new Ts3Command("clientkick", new List <ICommandPart>() { new CommandParameter("clid", client.Id), new CommandParameter("reasonid", 5) }); if (!alreadyBlocked && parseMSG(cfg[section]["reason"], client).Length < 100) { cmd.AppendParameter(new CommandParameter("reasonmsg", parseMSG(cfg[section]["reason"], client))); } lib.SendCommand <ResponseVoid>(cmd); } catch (Exception ex) { PluginLog(Log.Level.Warning, $"Could not kick {client.NickName}:\n{ex.Message}"); } } else { try { // banclient clid=1 time=0 banreason=text var cmd = new Ts3Command("banclient", new List <ICommandPart>() { new CommandParameter("clid", client.Id), new CommandParameter("time", parseMSG(cfg[section]["bantime"], client)) }); if (!alreadyBlocked && parseMSG(cfg[section]["reason"], client).Length < 100) { cmd.AppendParameter(new CommandParameter("banreason", parseMSG(cfg[section]["reason"], client))); } lib.SendCommand <ResponseVoid>(cmd); } catch (Exception ex) { PluginLog(Log.Level.Warning, $"Could not ban {client.NickName}:\n{ex.Message}"); } } }
private E <CommandError> SendCommandBase(WaitBlock wb, Ts3Command com) { if (context.WasExit || com.ExpectResponse) { return(Util.TimeOutCommandError); } var message = com.ToString(); byte[] data = Util.Encoder.GetBytes(message); packetHandler.AddOutgoingPacket(data, PacketType.Command); return(R.Ok); }
public override R <T[], CommandError> Send <T>(Ts3Command com) // Synchronous { using (var wb = new WaitBlock(msgProc.Deserializer, false)) { lock (sendQueueLock) { msgProc.EnqueueRequest(wb); SendRaw(com.ToString()); } return(wb.WaitForMessage <T>()); } }
public LazyNotification SendSpecialCommand(Ts3Command com, params NotificationType[] dependsOn) { if (!com.ExpectResponse) { throw new ArgumentException("A special command must take a response"); } using (var wb = new WaitBlock(dependsOn)) { SendCommandBase(wb, com); return(wb.WaitForNotification()); } }
public void ClientMove(ClientIdT clientId, ChannelIdT channelId, string channelPassword = null) { var cmd = new Ts3Command("clientmove", new List <ICommandPart> { new CommandParameter("clid", clientId), new CommandParameter("cid", channelId) }); if (channelPassword != null) { cmd.AppendParameter(new CommandParameter("cpw", channelPassword)); } SendCommand <ResponseVoid>(cmd); }
protected override IEnumerable <T> SendCommand <T>(Ts3Command com) // Synchronous { using (var wb = new WaitBlock()) { lock (SendQueueLock) { msgProc.EnqueueRequest(wb); SendRaw(com.ToString()); } return(wb.WaitForMessage <T>()); } }
public CmdR ClientMove(ClientIdT clientId, ChannelIdT channelId, string channelPassword = null) { var cmd = new Ts3Command("clientmove", new List <ICommandPart> { new CommandParameter("clid", clientId), new CommandParameter("cid", channelId) }); if (channelPassword != null) { cmd.AppendParameter(new CommandParameter("cpw", ClientType == ClientType.Full ? Full.Ts3Crypt.HashPassword(channelPassword) : channelPassword)); } return(SendCommand <ResponseVoid>(cmd)); }
/// <summary> /// Sends a command to the server. Commands look exactly like query commands and mostly also behave identically. /// <para>NOTE: Do not expect all commands to work exactly like in the query documentation.</para> /// </summary> /// <typeparam name="T">The type to deserialize the response to. Use <see cref="ResponseDictionary"/> for unknow response data.</typeparam> /// <param name="com">The raw command to send. /// <para>NOTE: By default does the command expect an answer from the server. Set <see cref="Ts3Command.ExpectResponse"/> to false /// if the client hangs after a special command (<see cref="SendCommand{T}"/> will return <code>null</code> instead).</para></param> /// <returns>Returns an enumeration of the deserialized and split up in <see cref="T"/> objects data. /// Or <code>null</code> if no reponse is expected.</returns> /// <exception cref="Ts3CommandException">When the response has an error code.</exception> public override IEnumerable <T> SendCommand <T>(Ts3Command com) { using (var wb = new WaitBlock()) { SendCommandBase(wb, com); if (com.ExpectResponse) { return(wb.WaitForMessage <T>()); } else { return(null); } } }
public R <LazyNotification, CommandError> SendNotifyCommand(Ts3Command com, params NotificationType[] dependsOn) { if (!com.ExpectResponse) { throw new ArgumentException("A special command must take a response"); } using (var wb = new WaitBlock(false, dependsOn)) { var result = SendCommandBase(wb, com); if (!result.Ok) { return(result.Error); } return(wb.WaitForNotification()); } }
public CmdR FileTransferRenameFile(ChannelIdT channelId, string oldName, string channelPassword, string newName, ChannelIdT?targetChannel = null, string targetChannelPassword = "") { var cmd = new Ts3Command("ftrenamefile", new List <ICommandPart> { new CommandParameter("cid", channelId), new CommandParameter("oldname", oldName), new CommandParameter("newname", newName), new CommandParameter("cpw", channelPassword) }); if (targetChannel.HasValue) { cmd.AppendParameter(new CommandParameter("tcid", targetChannel.Value)); cmd.AppendParameter(new CommandParameter("tcpw", targetChannelPassword)); } return(SendCommand <ResponseVoid>(cmd)); }
/// <summary> /// Sends a command to the server. Commands look exactly like query commands and mostly also behave identically. /// <para>NOTE: Do not expect all commands to work exactly like in the query documentation.</para> /// </summary> /// <typeparam name="T">The type to deserialize the response to. Use <see cref="ResponseDictionary"/> for unknow response data.</typeparam> /// <param name="com">The command to send. /// <para>NOTE: By default does the command expect an answer from the server. Set <see cref="Ts3Command.ExpectResponse"/> to false /// if the client hangs after a special command (<see cref="Send{T}(Ts3Command)"/> will return a generic error instead).</para></param> /// <returns>Returns <code>R(OK)</code> with an enumeration of the deserialized and split up in <see cref="T"/> objects data. /// Or <code>R(ERR)</code> with the returned error if no response is expected.</returns> public override R <T[], CommandError> Send <T>(Ts3Command com) { using (var wb = new WaitBlock(msgProc.Deserializer, false)) { var result = SendCommandBase(wb, com); if (!result.Ok) { return(result.Error); } if (com.ExpectResponse) { return(wb.WaitForMessage <T>()); } else { return(Array.Empty <T>()); } } }
protected override IEnumerable <T> SendCommand <T>(Ts3Command com) { var retCode = new CommandParameter("return_code", returnCode); if (com.ExpectResponse) { com.AppendParameter(retCode); } using (var wb = new WaitBlock()) { lock (CommmandQueueLock) { if (com.ExpectResponse) { msgProc.EnqueueRequest(retCode.Value, wb); returnCode++; } byte[] data = Util.Encoder.GetBytes(com.ToString()); lock (StatusLock) { if (wasExit) { throw new Ts3CommandException(new CommandError { Id = Ts3ErrorCode.custom_error, Message = "Connection closed" }); } packetHandler.AddOutgoingPacket(data, PacketType.Command); } } if (com.ExpectResponse) { return(wb.WaitForMessage <T>()); } else { return(null); } } }
public async Task <R <IEnumerable <T>, CommandError> > SendCommandAsync <T>(Ts3Command com) where T : IResponse, new() { using (var wb = new WaitBlock(true)) { var result = SendCommandBase(wb, com); if (!result.Ok) { return(result.Error); } if (com.ExpectResponse) { return(await wb.WaitForMessageAsync <T>()); } else { // This might not be the nicest way to return in this case // but we don't know what the response is, so this acceptable. return(Util.NoResultCommandError); } } }
/// <summary> /// Sends a command to the server. Commands look exactly like query commands and mostly also behave identically. /// <para>NOTE: Do not expect all commands to work exactly like in the query documentation.</para> /// </summary> /// <typeparam name="T">The type to deserialize the response to. Use <see cref="ResponseDictionary"/> for unknow response data.</typeparam> /// <param name="com">The raw command to send. /// <para>NOTE: By default does the command expect an answer from the server. Set <see cref="Ts3Command.ExpectResponse"/> to false /// if the client hangs after a special command (<see cref="SendCommand{T}"/> will return <code>null</code> instead).</para></param> /// <returns>Returns <code>R(OK)</code> with an enumeration of the deserialized and split up in <see cref="T"/> objects data. /// Or <code>R(ERR)</code> with the returned error if no response is expected.</returns> public override R <IEnumerable <T>, CommandError> SendCommand <T>(Ts3Command com) { using (var wb = new WaitBlock(false)) { var result = SendCommandBase(wb, com); if (!result.Ok) { return(result.Error); } if (com.ExpectResponse) { return(wb.WaitForMessage <T>()); } else { // This might not be the nicest way to return in this case // but we don't know what the response is, so this acceptable. return(Util.NoResultCommandError); } } }
private void SendCommandBase(WaitBlock wb, Ts3Command com) { lock (statusLock) { if (context.WasExit || (!Connected && com.ExpectResponse)) { throw new Ts3CommandException(Util.TimeOutCommandError); } if (com.ExpectResponse) { var responseNumber = ++returnCode; var retCodeParameter = new CommandParameter("return_code", responseNumber); com.AppendParameter(retCodeParameter); msgProc.EnqueueRequest(retCodeParameter.Value, wb); } byte[] data = Util.Encoder.GetBytes(com.ToString()); packetHandler.AddOutgoingPacket(data, PacketType.Command); } }
public static ChannelCreated ChannelCreate(Ts3FullClient cli, string name, string password, string neededTP, string phoname) { var cmd = new Ts3Command("channelcreate", new List <ICommandPart>() { new CommandParameter("channel_name", name), new CommandParameter("channel_password", Ts3Crypt.HashPassword(password)), new CommandParameter("channel_needed_talk_power", neededTP), new CommandParameter("channel_name_phonetic", phoname) }); var createdchan = cli.SendSpecialCommand(cmd, NotificationType.ChannelCreated).Notifications.Cast <ChannelCreated>(); foreach (var chan in createdchan) { Console.WriteLine("#{0} CID: {1} CNAME: {2}", cli.ClientId, chan.ChannelId, chan.Name); if (chan.Name == name) { return(chan); } } return(null); }
public R <T[], CommandError> SendCommand <T>(Ts3Command com) where T : IResponse, new() { using (var wb = new WaitBlock(msgProc.Deserializer, false)) { var result = SendCommandBase(wb, com); if (!result.Ok) { return(result.Error); } if (com.ExpectResponse) { return(wb.WaitForMessage <T>()); } else { // This might not be the nicest way to return in this case // but we don't know what the response is, so this acceptable. return(Util.NoResultCommandError); } } }
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); }
protected void SendNoResponsed(Ts3Command command) { command.ExpectResponse = false; SendCommand <ResponseVoid>(command); }
/// <summary> /// Sends a command and depending on the client type waits for a response or notification. /// <para>NOTE: Do not use this method unless you are sure the ts3 command fits the criteria.</para> /// </summary> /// <param name="command">The command to send.</param> /// <param name="type">The notification type to wait for and serialize to.</param> public abstract R <T[], CommandError> SendHybrid <T>(Ts3Command com, NotificationType type) where T : class, IResponse, new();
public override R <T[], CommandError> SendHybrid <T>(Ts3Command com, NotificationType type) => SendNotifyCommand(com, type).UnwrapNotification <T>();
public override R <T[], CommandError> SendHybrid <T>(Ts3Command com, NotificationType type) => Send <T>(com);
protected CmdR SendNoResponsed(Ts3Command command) => SendCommand <ResponseVoid>(command.ExpectsResponse(false));
/// <summary>Sends a command to the server. Commands look exactly like query commands and mostly also behave identically.</summary> /// <typeparam name="T">The type to deserialize the response to. Use <see cref="ResponseDictionary"/> for unknown response data.</typeparam> /// <param name="com">The raw command to send.</param> /// <returns>Returns an enumeration of the deserialized and split up in <see cref="T"/> objects data.</returns> public abstract R <IEnumerable <T>, CommandError> SendCommand <T>(Ts3Command com) where T : IResponse, new();
protected abstract IEnumerable <T> SendCommand <T>(Ts3Command com) where T : IResponse, new();
/// <summary>Sends a command to the server. Commands look exactly like query commands and mostly also behave identically.</summary> /// <typeparam name="T">The type to deserialize the response to. Use <see cref="ResponseDictionary"/> for unknown response data.</typeparam> /// <param name="com">The raw command to send.</param> /// <returns>Returns an enumeration of the deserialized and split up in <see cref="T"/> objects data.</returns> public abstract R <T[], CommandError> SendCommand <T>(Ts3Command com) where T : IResponse, new();
internal byte[] ProcessInit1(byte[] data) { const int versionLen = 4; const int initTypeLen = 1; if (data == null) { var sendData = new byte[versionLen + initTypeLen + 4 + 4 + 8]; Array.Copy(Initversion, 0, sendData, 0, versionLen); // initVersion sendData[versionLen] = 0x00; // initType NetUtil.H2N(Util.UnixNow, sendData, versionLen + initTypeLen); // 4byte timestamp for (int i = 0; i < 4; i++) { sendData[i + versionLen + initTypeLen + 4] = (byte)Util.Random.Next(0, 256); // 4byte random } return(sendData); } if (data.Length < initTypeLen) { return(null); } int type = data[0]; if (type == 1) { var sendData = new byte[versionLen + initTypeLen + 16 + 4]; Array.Copy(Initversion, 0, sendData, 0, versionLen); // initVersion sendData[versionLen] = 0x02; // initType Array.Copy(data, 1, sendData, versionLen + initTypeLen, 20); return(sendData); } else if (type == 3) { byte[] alphaBytes = new byte[10]; Util.Random.NextBytes(alphaBytes); var alpha = Convert.ToBase64String(alphaBytes); string initAdd = Ts3Command.BuildToString("clientinitiv", new ICommandPart[] { new CommandParameter("alpha", alpha), new CommandParameter("omega", Identity.PublicKeyString), new CommandParameter("ip", string.Empty) }); var textBytes = Util.Encoder.GetBytes(initAdd); // Prepare solution int level = NetUtil.N2Hint(data, initTypeLen + 128); byte[] y = SolveRsaChallange(data, initTypeLen, level); // Copy bytes for this result: [Version..., InitType..., data..., y..., text...] var sendData = new byte[versionLen + initTypeLen + 232 + 64 + textBytes.Length]; // Copy this.Version Array.Copy(Initversion, 0, sendData, 0, versionLen); // Write InitType sendData[versionLen] = 0x04; // Copy data Array.Copy(data, initTypeLen, sendData, versionLen + initTypeLen, 232); // Copy y Array.Copy(y, 0, sendData, versionLen + initTypeLen + 232 + (64 - y.Length), y.Length); // Copy text Array.Copy(textBytes, 0, sendData, versionLen + initTypeLen + 232 + 64, textBytes.Length); return(sendData); } else { return(null); } }