Skip to content

Framework to externally add chat commands in Counter Strike

Notifications You must be signed in to change notification settings

Isaac-Duarte/source_cmd_parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Source Cmd Parser

This crate is a framework to externally add chat commands on the client side of Counter-Strike:Source

How it works

In many source games, there is an ability to write the console output to a log file. This crate waits for changes in the log file and parses the output to find chat messages. If a chat message is found, it will be parsed and processed.

Output is done by simulating key presses by using the enigo crate.

Note this is not tested on windows, but it should work.

How to enable logging

  • Type the following into developer's console: con_logfile <filename>; con_timestamp 1
  • Locate the log file in the game directory

Example implementation

This is a ping pong example, if somebody types .ping, it will respond with Pong.

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut parser = SourceCmdBuilder::new()
        .file_path(Box::new(PathBuf::from(
            "PATH_OF_LOG_FILE",
        )))
        .set_parser(Box::new(CSSLogParser::new()))
        .state(())
        .add_command(".ping", pong)
        .owner("USER_NAME") // This is required as it will put an input delay if you type the question.
        .build()?;

    parser.run().await?;

    Ok(())
}

async fn pong(chat_message: ChatMessage, _: ()) -> Result<Option<ChatResponse>, Box<dyn std::error::Error>> {
    Ok(Some(ChatResponse::new("Pong".to_string())))
}

There are many other examples including a math expression evaluator, and a ChatGPT bot.

Demo

DEMO

Roadmap

This is really just a fun side project, but I would like to implement the following.

  • Allow for custom error handling in commands (by expecting a error that implements a custom trait)
  • Mutable state for commands
  • Allow from custom parsing

Windows Support

Windows support is hack joby because of the following issue.

notify-rs/notify#422 (comment)

But hey it works :)

About

Framework to externally add chat commands in Counter Strike

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages