X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fshared%2Fcli.cpp;fp=src%2Fshared%2Fcli.cpp;h=d4cf525b90e5e1c346bd0dbc9e65356c85a41627;hb=fa3c4a14546d73ddc2671cd5cc58208839bf7173;hp=6942f78704ec3a887dabff21fd35df37e0a6ba51;hpb=bc171dfe0897bccbbf9d9114d128be0801a1aff9;p=blank.git diff --git a/src/shared/cli.cpp b/src/shared/cli.cpp index 6942f78..d4cf525 100644 --- a/src/shared/cli.cpp +++ b/src/shared/cli.cpp @@ -1,4 +1,5 @@ #include "CLI.hpp" +#include "CLIContext.hpp" #include "commands.hpp" #include "../io/TokenStreamReader.hpp" @@ -7,6 +8,7 @@ #include #include +#include using namespace std; @@ -29,7 +31,7 @@ void CLI::AddCommand(const string &name, Command *cmd) { commands[name] = cmd; } -void CLI::Execute(Player &player, const string &line) { +void CLI::Execute(CLIContext &ctx, const string &line) { stringstream s(line); TokenStreamReader args(s); if (!args.HasMore()) { @@ -37,44 +39,39 @@ void CLI::Execute(Player &player, const string &line) { return; } if (args.Peek().type != Token::IDENTIFIER) { - Error("I don't understand"); + ctx.Error("I don't understand"); return; } string name; args.ReadIdentifier(name); auto entry = commands.find(name); if (entry == commands.end()) { - Error(name + ": command not found"); + ctx.Error(name + ": command not found"); return; } try { - entry->second->Execute(*this, player, args); + entry->second->Execute(*this, ctx, args); } catch (exception &e) { - Error(name + ": " + e.what()); + ctx.Error(name + ": " + e.what()); } catch (...) { - Error(name + ": unknown execution error"); + ctx.Error(name + ": unknown execution error"); } } -void CLI::Message(const string &msg) { - // TODO: display message to player - cout << msg << endl; -} - -void CLI::Error(const string &msg) { - Message("CLI error: " + msg); -} - CLI::Command::~Command() { } -void TeleportCommand::Execute(CLI &cli, Player &player, TokenStreamReader &args) { +void TeleportCommand::Execute(CLI &cli, CLIContext &ctx, TokenStreamReader &args) { glm::vec3 pos(args.GetFloat(), args.GetFloat(), args.GetFloat()); - EntityState state = player.GetEntity().GetState(); + EntityState state = ctx.GetPlayer().GetEntity().GetState(); state.pos = ExactLocation(pos).Sanitize(); - player.GetEntity().SetState(state); + ctx.GetPlayer().GetEntity().SetState(state); + + stringstream msg; + msg << ctx.GetPlayer().Name() << " teleported to " << pos; + ctx.Broadcast(msg.str()); } }