GithubHelp home page GithubHelp logo

the-marenga / sf-api Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 3.0 611 KB

Manage Shakes & Fidget characters via simple commands. Handles encryption, response parsing and everything else for you

License: MIT License

Rust 100.00%
shakes-and-fidget

sf-api's Introduction

S&F API ๐Ÿง™๐Ÿฝโ€โ™‚๏ธ

crates.io Build Status Licence

Overview

This is an unofficial work in progress API to talk to the Shakes & Fidget Servers.

The most basic example on how to use this would be:

    // First thing we have to do is login
    let mut session = sf_api::SimpleSession::login(
        "username",
        "password",
        "f1.sfgame.net"
    ).await.unwrap();

    // If everything went well, we are able to look at the current state
    let gs = session.game_state().unwrap();
    println!("Our current description is: {}", gs.character.description);

    //  Lets do something like changing the description as an example
    let new_description = "I love sushi!".to_string();
    let gs = session
        .send_command(Command::SetDescription {
            description: new_description.clone(),
        })
        .await
        .unwrap();
    // After successfully sending a command, the server will return the
    // gamestate so that we can check what changed:
    assert!(gs.character.description == new_description);
    println!("YAY, it worked! ๐ŸŽ‰๐Ÿฃ๐Ÿฃ๐Ÿฃ๐ŸŽ‰");

If you use a single sign-on S&F Account, you can use it like this:

    let sessions = SimpleSession::login_sf_account(
        "username",
        "password"
    ).await.unwrap();

    for session in sessions {
        // You can use the sessions, that the account returns like
        // a normal (logged out) session now
        let gs = session.send_command(Command::Update).await.unwrap();
        // ...
    }

The SimpleSession is not optimal for more complex usecases. For these, have a look at Session::new() & GameState::new() to handle session and gamestate seperately

Installation

You just need to run the following command in your Rust project:

cargo add sf-api

Guidelines

Here are a few things you should note before getting your account banned:

  1. Never send commands to the server in an infinite loop without a delay
  2. You should send an Update command every once in a while.
  3. Make sure you have access to the commands you are trying to send.
  4. Always check if the thing you expected happened after sending a command.
  5. You can assume, that every index in a command starts at 0

Performance

Performace should not matter to you, as you are not supposed to run this library on a scale, where you have to think about this. Disregarding this fact, this library is build with high scalabillity and low resource usage in mind. Parsing the login gamestate will take < 1ms on my machine with full updates after that taking < 100ยตs.

Everything is parsed into the exact datatype, that is expected, which also catches weird, or unexpected errors compared to just i64ing every int. A lot of these conversion errors are shown as log warnings and defaulting to some value, instead of returning an error. This way you will not get hard stuck, just because the mushroom price of an item somewhere is negative

Rust Features

This crate has support for serde to (de)serialize the character state and the S&F Account (sso) behind the respective feature flags. Note that sso depends on the serde crate internally to talk to the server via json.

Misc.

There are 500+ properties, that get parsed. This is such a huge amount of data, that I have opted to just give you raw access to these fields in the GameState instead of providing get() functions for all of these. This means you can create invalid gamestates with a mutable reference if you want, but as far as I am concerned, that would be your bug, not mine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.