Solved Logging a message? (C#)

Discussion in 'Rust Development' started by Bourtak, Jun 3, 2015.

  1. hello,

    I'm beginner in C# and i will learnC# with try to develop my own plugins.

    i will first try to have a plugin who log all command sent by a player :

    Code:
    using System.Data;
    using Oxide.Core;namespace Oxide.Plugins
    {
    [Info("Log Console", "Bourtak", "0.1")]
    public class LogConsole : RustPlugin
    {
        // This is where your plugin will do its magic
        private void OnRunCommand(){
            LogCommand();
        }        // Sauvegarde le fichier
        private void LogCommand()
        {
            Interface.GetMod().DataFileSystem.SaveDatafile("LogConsole");
        }    }
    }
    Can you help me please ?
     
  2. You maybe could just write it into the console as that is also saved as a log.
    You are able to do that using
    Code:
    Puts(message);
    if im right
     
  3. I have try and puts work fine. Thanks.
    But i will not log just a message. I will log what is type in the console.

    If i type /airdrop.toplayer, i will the server puts"Y:m:d H:i:s playerid :xxxxxxxx => /airdrop.toplayer"

    But /airdrop.toplayer is variable. And i don't know how i can capture that.
     
  4. If i'm not totaly wrong.. you need to print the args ;)
     
  5. So that ?

    Code:
    using System.Data;
    using Oxide.Core;namespace Oxide.Plugins
    {
    [Info("Log Console", "Bourtak", "0.1")]
    public class LogConsole : RustPlugin
    {
        // This is where your plugin will do its magic
        private void OnRunCommand( String args){
            Puts(args);
            LogCommand(args);
        }        // Sauvegarde le fichier
        private void LogCommand( string args){  
            Interface.GetMod().DataFileSystem.SaveDatafile("LogConsole");
        }    }
    }
     
  6. Man i dont know C# but i gave u a hint :) I think someone who knows C# can help you 4 sure
     
  7. Do you want to log Chat command or Console commands? Or both
     
  8. Console command
     
  9. So what you need to use to detect a ran command, is using following hook:
    Code:
    void OnRunCommand(ConsoleSystem.Arg arg)
    {
    }
    Now, the actual ran command is called with
    arg.cmd.namefull
    so all you gotta do is, using the
    Code:
    Puts(message)
    and giving arg.cmd.namefull out as message
     
  10. Thanks, that work fine

    Code:
    using System.Data;
    using Oxide.Core;namespace Oxide.Plugins
    {
    [Info("Log Console", "Bourtak", "0.1")]
    public class LogConsole : RustPlugin
    {
        // This is where your plugin will do its magic
        private void OnRunCommand(ConsoleSystem.Arg arg){
            string message = arg.cmd.namefull;
            if ( message != "chat.say" &&
                    message != "global.kill" &&
                    message != "chat.say" &&
                    message != "inventory.endloot" &&
                    message != "craft.add" &&
                    message != "global.add" &&
                ){
                Puts(arg.cmd.namefull);
            }
            //LogCommand();
        }        /* Sauvegarde le fichier
        private void LogCommand(){  
            Interface.GetMod().DataFileSystem.SaveDatafile("LogConsole");
        }
        */    }
    }

    Yes i know, my condition is ridiculous :)
    I'm looking for make in c# what i make with !in_array() from PHP

    Thanks :)
     
  11. no problem
     
    Last edited by a moderator: Jun 4, 2015