mirror of
https://github.com/Astatin3/meteorbot-old.git
synced 2026-06-09 00:28:06 -06:00
Initial commit
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
project(0_HelloWorld)
|
||||
|
||||
set(${PROJECT_NAME}_SOURCE_FILES
|
||||
${PROJECT_SOURCE_DIR}/src/main.cpp
|
||||
)
|
||||
set(${PROJECT_NAME}_INCLUDE_FOLDERS
|
||||
|
||||
)
|
||||
|
||||
add_example("${${PROJECT_NAME}_INCLUDE_FOLDERS}" "${${PROJECT_NAME}_SOURCE_FILES}")
|
||||
@@ -0,0 +1,126 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "botcraft/Game/ConnectionClient.hpp"
|
||||
#include "botcraft/Utilities/Logger.hpp"
|
||||
|
||||
void ShowHelp(const char* argv0)
|
||||
{
|
||||
std::cout << "Usage: " << argv0 << " <options>\n"
|
||||
<< "Options:\n"
|
||||
<< "\t-h, --help\tShow this help message\n"
|
||||
<< "\t--address\tAddress of the server you want to connect to, default: 127.0.0.1:25565\n"
|
||||
<< "\t--login\t\tPlayer name in offline mode, empty for Microsoft account, default: BCHelloWorld\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
struct Args
|
||||
{
|
||||
bool help = false;
|
||||
std::string address = "127.0.0.1:25565";
|
||||
std::string login = "BCHelloWorld";
|
||||
|
||||
int return_code = 0;
|
||||
};
|
||||
|
||||
Args ParseCommandLine(int argc, char* argv[]);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// Init logging, log everything >= Info, only to console, no file
|
||||
Botcraft::Logger::GetInstance().SetLogLevel(Botcraft::LogLevel::Info);
|
||||
Botcraft::Logger::GetInstance().SetFilename("");
|
||||
// Add a name to this thread for logging
|
||||
Botcraft::Logger::GetInstance().RegisterThread("main");
|
||||
|
||||
Args args;
|
||||
if (argc == 1)
|
||||
{
|
||||
LOG_WARNING("No command arguments. Using default options.");
|
||||
ShowHelp(argv[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
args = ParseCommandLine(argc, argv);
|
||||
if (args.help)
|
||||
{
|
||||
ShowHelp(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
if (args.return_code != 0)
|
||||
{
|
||||
return args.return_code;
|
||||
}
|
||||
}
|
||||
|
||||
Botcraft::ConnectionClient client;
|
||||
|
||||
LOG_INFO("Starting connection process");
|
||||
client.Connect(args.address, args.login);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
client.SendChatMessage(u8"Hello, World!");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
|
||||
client.Disconnect();
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG_FATAL("Exception: " << e.what());
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_FATAL("Unknown exception");
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Args ParseCommandLine(int argc, char* argv[])
|
||||
{
|
||||
Args args;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
std::string arg = argv[i];
|
||||
if (arg == "-h" || arg == "--help")
|
||||
{
|
||||
args.help = true;
|
||||
return args;
|
||||
}
|
||||
else if (arg == "--address")
|
||||
{
|
||||
if (i + 1 < argc)
|
||||
{
|
||||
args.address = argv[++i];
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_FATAL("--address requires an argument");
|
||||
args.return_code = 1;
|
||||
return args;
|
||||
}
|
||||
}
|
||||
else if (arg == "--login")
|
||||
{
|
||||
if (i + 1 < argc)
|
||||
{
|
||||
args.login = argv[++i];
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_FATAL("--login requires an argument");
|
||||
args.return_code = 1;
|
||||
return args;
|
||||
}
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
Reference in New Issue
Block a user