Skip to content

Commit

Permalink
refactor: move rcon header includes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Dec 17, 2023
1 parent 022f8e9 commit f4ca171
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
15 changes: 1 addition & 14 deletions include/rcon.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#pragma once

#include <iostream>
#include <string>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <unistd.h>
#include <thread>
#include <functional>

#define DEFAULT_TIMEOUT 4
Expand Down Expand Up @@ -124,13 +117,7 @@ class rcon {
*/
rcon_packet read_packet();

inline const size_t read_packet_length() {
unsigned char* buffer = new unsigned char[4]{0};
::recv(sock, buffer, 4, 0);
const size_t len = byte32_to_int(buffer);
delete[] buffer;
return len;
}
const size_t read_packet_length();

inline const size_t byte32_to_int(unsigned char* buffer) {
return static_cast<size_t>(buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24);
Expand Down
15 changes: 15 additions & 0 deletions src/rcon.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include "../include/rcon.h"

#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <unistd.h>
#include <iostream>
#include <cstring>
#include <thread>

rcon::rcon(const std::string& addr, const unsigned int _port, const std::string& pass) : address(addr), port(_port), password(pass) {

Expand Down Expand Up @@ -169,3 +176,11 @@ rcon_packet rcon::read_packet() {

return {bytes, buffer};
}

const size_t rcon::read_packet_length() {
unsigned char* buffer = new unsigned char[4]{0};
::recv(sock, buffer, 4, 0);
const size_t len = byte32_to_int(buffer);
delete[] buffer;
return len;
}

0 comments on commit f4ca171

Please sign in to comment.