Coder Social home page Coder Social logo

mare-02 / rconcpp Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 19.41 MB

c++, asio, Rcon protocol for UNIX and windows

License: MIT License

C++ 99.81% C 0.17% Perl 0.01% HTML 0.01% Python 0.01% M4 0.01% Batchfile 0.01% Shell 0.01% CMake 0.01%
rcon asio cpp rcon-client rcon-protocol squad

rconcpp's Introduction

RconCpp

I coded this simple Source RCON API for c++. It uses boost asio so you can run it on UNIX and windows systems

Example

You can create a Rcon object via this example:

RCONCPP::RconCpp rcon(port, ip, timeout);

The timeout is the time in seconds the code waits on a response before exiting with a failure. (optional, default = 5) Just pass the port and ip.

To establish the Rcon connection, use the connect() function. The function throws a std::runtime_error exception if the connection failed.

try
{
  rcon.connect();
}
catch (std::runtime_error e)
{
  std::cout << e.what() << std::endl;
  return -1;
}

The same goes for the authentication procedure. The only difference is the variable that you pass to the function. This time it is the Rcon password.

try
{
  rcon.authenticate(rcon_pwd);
}
catch (std::runtime_error e)
{
  std::cout << e.what() << std::endl;
  return -1;
}

At this point, the connection is established and authenticated. You can now use the sendAndRecv() function to send commands and receive the answer. If the answer failed after 5 seconds, the function return a string containing "error".

std::string players = rcon.sendAndRecv("listplayers");
std::cout << players << std::endl;

Multiple-packet Responses

Supports multi-packet responses. This process activates automatically

Error while authentication

Some servers receive some sort of "shadow" packet before the authentication. If your authentication is blocking and not terminating, uncomment '#define AUTH_ERROR' in RconCpp.h

rconcpp's People

Contributors

mare-02 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

rconcpp's Issues

Can not work on Minecraft 1.20.1 in Windows11

it can run normally when running constructor function and connect function, but when running authenticate func it makes the program blocked, after a while sever shows "Thread RCON Client /127.0.0.1 shutting down", then the program continue running without throwing Exception, and when running sendAndRecv, the program shows several lines of "error"

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.