[Add] Add back the SSH functionality.

This commit is contained in:
Ritchie Cunningham 2025-09-25 23:05:21 +01:00
parent 6272800a22
commit c7e8d97c63
6 changed files with 19 additions and 7 deletions

View File

@ -5,7 +5,9 @@
#include "lua_processor.h" #include "lua_processor.h"
#include "vfs_manager.h" #include "vfs_manager.h"
CommandProcessor::CommandProcessor(vfs_node* starting_dir) { CommandProcessor::CommandProcessor(vfs_node* starting_dir,
std::map<std::string, vfs_node*>& world_vfs) :
_world_vfs(world_vfs) {
_current_dir = starting_dir; _current_dir = starting_dir;
_lua = new LuaProcessor(); _lua = new LuaProcessor();
} }
@ -125,6 +127,13 @@ std::string CommandProcessor::_handle_vfs_action(sol::table action) {
return ""; /* Success. */ return ""; /* Success. */
} }
return std::string("rm: cannot remove '") + path + "': No such file or directory."; return std::string("rm: cannot remove '") + path + "': No such file or directory.";
} else if(action_name == "ssh") {
std::string target_ip = action["target"].get_or<std::string>("");
if(_world_vfs.count(target_ip)) {
_current_dir = _world_vfs[target_ip];
return "Connected to " + target_ip;
}
return "ssh: Could not resolve hostname " + target_ip + ": Name or service not known";
} }
return "Error: Unknown VFS action '" + action_name + "'"; return "Error: Unknown VFS action '" + action_name + "'";
} }

View File

@ -1,13 +1,14 @@
#pragma once #pragma once
#include <string> #include <string>
#include <map>
#include "vfs.h" #include "vfs.h"
#include <lua_processor.h> #include <lua_processor.h>
class CommandProcessor { class CommandProcessor {
public: public:
CommandProcessor(vfs_node* starting_dir); CommandProcessor(vfs_node* starting_dir, std::map<std::string, vfs_node*>& world_vfs);
~CommandProcessor(void); ~CommandProcessor(void);
std::string process_command(const std::string& command); std::string process_command(const std::string& command);
@ -16,5 +17,6 @@ public:
private: private:
std::string _handle_vfs_action(sol::table action); std::string _handle_vfs_action(sol::table action);
vfs_node* _current_dir; vfs_node* _current_dir;
std::map<std::string, vfs_node*>& _world_vfs;
LuaProcessor* _lua; LuaProcessor* _lua;
}; };

View File

@ -64,7 +64,7 @@ void TcpConnection::async_read_header(void) {
uint32_t body_size; uint32_t body_size;
std::memcpy(&body_size, header_buf->data(), sizeof(body_size)); std::memcpy(&body_size, header_buf->data(), sizeof(body_size));
body_size = ntohl(body_size); /* Convert network to host byte order. */ body_size = ntohl(body_size); /* Convert network to host byte order. */
if(body_size > 0) { if(body_size > 0) {
_read_msg.body.resize(body_size); _read_msg.body.resize(body_size);
/* Have header, now read body. */ /* Have header, now read body. */

View File

@ -59,7 +59,7 @@ void NetworkManager::start_accept(void) {
/* Create a new player for this connection. */ /* Create a new player for this connection. */
uint32_t player_id = _next_player_id++; uint32_t player_id = _next_player_id++;
auto new_player = std::make_unique<Player>(player_id, _vfs_manager); auto new_player = std::make_unique<Player>(player_id, _vfs_manager, _world_vfs);
Player* new_player_ptr = new_player.get(); Player* new_player_ptr = new_player.get();
_players[player_id] = std::move(new_player); _players[player_id] = std::move(new_player);
new_connection->set_id(player_id); new_connection->set_id(player_id);

View File

@ -1,10 +1,11 @@
#include "player.h" #include "player.h"
#include "command_processor.h" #include "command_processor.h"
Player::Player(uint32_t new_id, VFSManager& vfs_manager) : Player::Player(uint32_t new_id, VFSManager& vfs_manager,
std::map<std::string, vfs_node*>& world_vfs) :
id(new_id), id(new_id),
vfs_root(vfs_manager.create_vfs("player")), vfs_root(vfs_manager.create_vfs("player")),
cmd_processor(new CommandProcessor(vfs_root)) {} cmd_processor(new CommandProcessor(vfs_root, world_vfs)) {}
Player::~Player(void) { Player::~Player(void) {
if(cmd_processor) { if(cmd_processor) {

View File

@ -8,7 +8,7 @@
class Player { class Player {
public: public:
Player(uint32_t id, VFSManager& vfs_manager); Player(uint32_t id, VFSManager& vfs_manager, std::map<std::string, vfs_node*>& world_vfs);
~Player(void); ~Player(void);
uint32_t id; uint32_t id;