static Dictionary <string, ICmd> InitializeCommands()
        {
            Dictionary <string, ICmd> result =
                new Dictionary <string, ICmd>(StringComparer.InvariantCultureIgnoreCase);

            ICmd cmd = new InstallCmd();

            result.Add(cmd.CommandName, cmd);

            cmd = new UninstallCmd();
            result.Add(cmd.CommandName, cmd);

            cmd = new ServerCmd();
            result.Add(cmd.CommandName, cmd);

            cmd = new RepofilterCmd();
            result.Add(cmd.CommandName, cmd);

            cmd = new RepomapCmd();
            result.Add(cmd.CommandName, cmd);

            cmd = new TriggerCmd();
            result.Add(cmd.CommandName, cmd);

            cmd = new RunCmd();
            result.Add(cmd.CommandName, cmd);

            cmd = new WarnEmailCmd();
            result.Add(cmd.CommandName, cmd);

            cmd = new LogCmd();
            result.Add(cmd.CommandName, cmd);

            return(result);
        }
Beispiel #2
0
        public static LogCmdResult Log(ICollection <string> urls, ICollection <uint> revisions,
                                       LogRevisionMode revisionMode = LogRevisionMode.Change,
                                       Depth depth          = Depth.svn_depth_unknown,
                                       Depth setDepth       = Depth.svn_depth_unknown,
                                       int limit            = 0,
                                       bool stopOnCopy      = false,
                                       bool useMergeHistory = true)
        {
            if (urls.Count <= 0)
            {
                throw new Exception("Empty urls");
            }

            SortedSet <uint> filteredRevisions = new SortedSet <uint>(revisions, new RevisionComparer());

            switch (revisionMode)
            {
            case LogRevisionMode.RevisionRanges:
                throw new NotImplementedException();

            case LogRevisionMode.Change:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(revisionMode), revisionMode, null);
            }

            LogCmd       logCmd = new LogCmd();
            BridgeCliOpt opt    = new BridgeCliOpt
            {
                depth             = (int)depth,
                set_depth         = (int)setDepth,
                limit             = limit,
                verbose           = Convert.ToInt32(true),
                stop_on_copy      = Convert.ToInt32(stopOnCopy),
                use_merge_history = Convert.ToInt32(useMergeHistory)
            };

            List <IntPtr> nativeUtf8 = new List <IntPtr>();

            foreach (string url in urls)
            {
                if (String.IsNullOrEmpty(url))
                {
                    throw new Exception("url is empty");
                }

                nativeUtf8.Add(NativeStringHelper.StringToNativeUtf8(url));
            }

            BridgeCli.LogCmdResult cliResult = logCmd.Run(nativeUtf8, filteredRevisions, opt);

            return(ParseCliResult(cliResult));
        }
 public void AgregarLog(LogCmd log)
 {
     try
     {
         _LogAutenticacionAPI logE = new _LogAutenticacionAPI(log.Tipo, log.Usuario, log.Aplicacion, log.Metodo, log.Entidad, log.Request, log.Response, log.EsExcepcion, log.Mensaje, log.Parametros);
         _ufw.InsertarLog(logE);
     }
     catch (Exception e)
     {
         _ufw.Rollback();
         throw e;
     }
 }
Beispiel #4
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:
                    LogCmd.ConditionalDebug("[I] {0}", Util.Encoder.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(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;
                }
            }
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        private void Chat_MessageReceived(string author, string message, ChatMessage.Data original)
        {
            var commandInfo = MessageUtilities.getCommandInfo(message);

            if (commandInfo.matches && commandInfo.commandName.ToLower() == "plugin")
            {
                printClient();
            }

            if (!GeneralUtilities.isHost())
            {
                addMessageFromRemote(original);
                chatReplicationManager.AddPublic(original.message_);
                return;
            }

            Cmd cmd = commandInfo.matches ? Cmd.all.getCommand(commandInfo.commandName) : null;

            string logMessage = "";

            var client = GeneralUtilities.clientFromName(author);

            var showRegularChat = !LogCmd.localClientCommands || !commandInfo.matches || commandInfo.forceVisible || (cmd != null && client != null && cmd.showChatPublic(client)) || commandInfo.local;

            if (showRegularChat)
            {
                chatReplicationManager.AddPublic(original.message_);
                addMessageFromRemote(original);
                logMessage = message;
            }

            if (client == null)
            {
                Console.WriteLine($"Error: client can't be found for name: {author}");
                return;
            }

            if (!commandInfo.matches || commandInfo.commandName.ToLower() == "plugin" || commandInfo.local)
            {
                return;
            }

            if (!showRegularChat)
            {
                logMessage = $"[00FFFF]{message}[-]";
                MessageUtilities.sendMessage(client, logMessage);
                chatReplicationManager.MarkAllForReplication();
                if (LogCmd.showHostAllCommands)
                {
                    var hostClient = GeneralUtilities.localClient();
                    if (hostClient == null)
                    {
                        Console.WriteLine("Error: Local client can't be found !");
                        return;
                    }
                    string usedCmd;
                    if (cmd == null || cmd.perm != PermType.ALL)
                    {
                        usedCmd = MessageUtilities.closeTags(client.GetChatName()) + " tried to use " + logMessage;
                    }
                    else
                    {
                        usedCmd = MessageUtilities.closeTags(client.GetChatName()) + " used " + logMessage;
                    }
                    MessageUtilities.sendMessage(hostClient, usedCmd);
                }
            }

            MessageStateOptionLog cmdLog = new MessageStateOptionLog(new List <string>());

            MessageUtilities.pushMessageOption(cmdLog);


            if (LogCmd.showHostAllResults)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionShowToHost(true));
            }

            if (LogCmd.localClientResults)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(client));
            }
            else
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer());
            }

            if (cmd == null)
            {
                MessageUtilities.sendMessage(client, "The command '" + commandInfo.commandName + "' doesn't exist.");
                chatReplicationManager.MarkForReplication(client.NetworkPlayer_);
                chatReplicationManager.ReplicateNeeded();
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popAllMessageOptions();
                return;
            }

            if (cmd.perm != PermType.ALL)
            {
                MessageUtilities.sendMessage(client, "You don't have permission to do that!");
                chatReplicationManager.MarkForReplication(client.NetworkPlayer_);
                chatReplicationManager.ReplicateNeeded();
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popAllMessageOptions();
                return;
            }

            MessageUtilities.popMessageOptions();

            if (commandInfo.forceVisible || !LogCmd.localClientResults)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer());
            }

            exec(cmd, client, commandInfo.commandParams);

            chatReplicationManager.ReplicateNeeded();
            LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
            MessageUtilities.popAllMessageOptions();
        }
Beispiel #8
0
        private void Chat_MessageSent(ChatSubmitMessage.Data messageData)
        {
            // by doing the below instead, we preserver formatting symbols.
            string message = UIExInputGeneric <string> .current_.Value_; //messageData.message_;

            var commandInfo = MessageUtilities.getCommandInfo(message);
            Cmd cmd         = commandInfo.matches ? Cmd.all.getCommand(commandInfo.commandName) : null;

            string logMessage = "";

            var client = GeneralUtilities.localClient();

            var showRegularChat = (!commandInfo.local && !GeneralUtilities.isHost()) || !LogCmd.localHostCommands ||
                                  !commandInfo.matches || commandInfo.forceVisible || (cmd != null && client != null && cmd.showChatPublic(client));

            if (showRegularChat)
            {
                sendingLocalChat = true;
                replicateLocalChatFunc?.Invoke(messageData);
                if (!commandInfo.matches)
                {
                    return;
                }
                logMessage = message;
            }

            if (client == null)
            {
                Console.WriteLine("Error: Local client can't be found !");
                return;
            }

            if (!showRegularChat)
            {
                MessageUtilities.sendMessage(client, $"[00FFFF]{message}[-]");
                logMessage = $"[00FFFF]{message}[-]";
            }

            MessageStateOptionLog cmdLog = new MessageStateOptionLog(new List <string>());

            MessageUtilities.pushMessageOption(cmdLog);

            if (LogCmd.localHostResults)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer(client));
            }
            else
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer());
            }

            if (!commandInfo.local && commandInfo.commandName.ToLower() == "plugin")
            {
                printClient();
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popMessageOptions(2);
                return;
            }

            if (GeneralUtilities.isHost() && commandInfo.local)
            {
                MessageUtilities.sendMessage(client, "Cannot use local commands as host");
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popMessageOptions(2);
                return;
            }
            else if (!GeneralUtilities.isHost() && !commandInfo.local)
            {
                MessageUtilities.popMessageOptions(2);
                return;
            }

            if (cmd == null)
            {
                MessageUtilities.sendMessage(client, "The command '" + commandInfo.commandName + "' doesn't exist.");
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popMessageOptions(2);
                return;
            }

            if (commandInfo.local && !cmd.canUseLocal && cmd.perm != PermType.LOCAL)
            {
                MessageUtilities.sendMessage(client, "You can't use that command as client");
                LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
                MessageUtilities.popMessageOptions(2);
                return;
            }

            MessageUtilities.popMessageOptions();                                       // remove local/non-local only option

            bool renderToPublic = commandInfo.forceVisible || !LogCmd.localHostResults; // log settings may change if cmd changes them

            if (renderToPublic)
            {
                MessageUtilities.pushMessageOption(new MessageStateOptionPlayer());
            }
            exec(cmd, client, commandInfo.commandParams);
            if (renderToPublic)
            {
                MessageUtilities.popMessageOptions();
            }
            LogCmd.AddLog(client, logMessage, cmdLog.GetLogString());
            MessageUtilities.popAllMessageOptions();
        }