Skip to content

Commit

Permalink
Removed HashTable, CString
Browse files Browse the repository at this point in the history
Added JUPITER_SOCK_EWOULDBLOCK
Code now runs and compiles on linux
  • Loading branch information
JAJames committed Oct 12, 2019
1 parent 33bee43 commit b5be829
Show file tree
Hide file tree
Showing 27 changed files with 272 additions and 267 deletions.
2 changes: 1 addition & 1 deletion src/Bot/include/IRC_Command.h
Expand Up @@ -207,7 +207,7 @@ class JUPITER_BOT_API GenericCommandWrapperIRCCommand : public IRCCommand
/**
* @brief Copy constructor for the GenericCommandWrapperIRCCommand class
*/
GenericCommandWrapperIRCCommand(GenericCommandWrapperIRCCommand &in_command);
GenericCommandWrapperIRCCommand(const GenericCommandWrapperIRCCommand &in_command);

/**
* @brief Wrapper constructor for the GenericCommandWrapperIRCCommand class
Expand Down
19 changes: 8 additions & 11 deletions src/Bot/src/IRC_Bot.cpp
Expand Up @@ -116,20 +116,19 @@ void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command)
if (section == nullptr)
return;

auto read_section = [this, section, in_command](Jupiter::HashTable::Bucket::Entry &in_entry)
{
for (auto& entry : section->getTable()) {
size_t tmp_index;
Jupiter::ReferenceString tmp_key, tmp_sub_key;
IRCCommand *command;

tmp_index = in_entry.key.find('.');
tmp_index = entry.first.find('.');
if (tmp_index != Jupiter::INVALID_INDEX)
{
// non-default access assignment

tmp_key.set(in_entry.key.ptr(), tmp_index);
tmp_key.set(entry.first.ptr(), tmp_index);

tmp_sub_key = in_entry.key;
tmp_sub_key = entry.first;
tmp_sub_key.shiftRight(tmp_index + 1);

if (tmp_sub_key.findi("Type."_jrs) == 0)
Expand All @@ -138,7 +137,7 @@ void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command)

command = this->getCommand(tmp_key);
if (command != nullptr && (in_command == nullptr || in_command == command))
command->setAccessLevel(tmp_sub_key.asInt(), in_entry.value.asInt());
command->setAccessLevel(tmp_sub_key.asInt(), entry.second.asInt());
}
else if (tmp_sub_key.findi("Channel."_jrs) == 0)
{
Expand All @@ -147,19 +146,17 @@ void IRC_Bot::setCommandAccessLevels(IRCCommand *in_command)
// Assign access level to command (if command exists)
command = this->getCommand(tmp_key);
if (command != nullptr && (in_command == nullptr || in_command == command))
command->setAccessLevel(tmp_sub_key, in_entry.value.asInt());
command->setAccessLevel(tmp_sub_key, entry.second.asInt());
}
}
else
{
// Assign access level to command (if command exists)
command = this->getCommand(in_entry.key);
command = this->getCommand(entry.first);
if (command != nullptr && (in_command == nullptr || in_command == command))
command->setAccessLevel(in_entry.value.asInt());
command->setAccessLevel(entry.second.asInt());
}
};

section->getTable().callback(read_section);
};

set_command_access_levels(this->getSecondaryConfigSection());
Expand Down
2 changes: 1 addition & 1 deletion src/Bot/src/IRC_Command.cpp
Expand Up @@ -130,7 +130,7 @@ void IRCCommand::create()

/** GenericCommandWrapperIRCCommand */

GenericCommandWrapperIRCCommand::GenericCommandWrapperIRCCommand(GenericCommandWrapperIRCCommand &in_command) : IRCCommand(in_command)
GenericCommandWrapperIRCCommand::GenericCommandWrapperIRCCommand(const GenericCommandWrapperIRCCommand &in_command) : IRCCommand(in_command)
{
GenericCommandWrapperIRCCommand::m_command = in_command.m_command;

Expand Down
19 changes: 8 additions & 11 deletions src/Plugins/ChannelRelay/ChannelRelay.cpp
Expand Up @@ -53,7 +53,6 @@ void ChannelRelayPlugin::OnChat(Jupiter::IRC::Client *server, const Jupiter::Rea
int type = chan->getType();
if (ChannelRelayPlugin::types.contains(type))
{
unsigned int count = server->getChannelCount();
unsigned int serverCount = serverManager->size();
char prefix = chan->getUserPrefix(nick);
Jupiter::String str;
Expand All @@ -64,16 +63,14 @@ void ChannelRelayPlugin::OnChat(Jupiter::IRC::Client *server, const Jupiter::Rea
str = "<"_js + prefix + nick + "> "_jrs + message;
}

Jupiter::IRC::Client *irc_server;

auto relay_channels_callback = [irc_server, type, chan, &str](Jupiter::IRC::Client::ChannelTableType::Bucket::Entry &in_entry)
{
if (in_entry.value.getType() == type && &in_entry.value != chan)
irc_server->sendMessage(in_entry.value.getName(), str);
};

while (serverCount != 0)
serverManager->getServer(--serverCount)->getChannels().callback(relay_channels_callback);
while (serverCount != 0) {
auto server = serverManager->getServer(--serverCount);
for (auto& channel : server->getChannels()) {
if (channel.second.getType() == type && &channel.second != chan) {
server->sendMessage(channel.second.getName(), str);
}
}
}
}
}
}
Expand Down
18 changes: 6 additions & 12 deletions src/Plugins/ExtraCommands/ExtraCommands.cpp
Expand Up @@ -258,24 +258,18 @@ Jupiter::GenericCommand::ResponseLine *DebugInfoGenericCommand::trigger(const Ju
line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("Outputting data for %u channels...", server->getChannelCount()), GenericCommand::DisplayType::PublicSuccess);
line = line->next;

auto debug_callback = [&line](Jupiter::IRC::Client::ChannelTableType::Bucket::Entry &in_entry)
{
line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("Channel %.*s - Type: %d", in_entry.value.getName().size(), in_entry.value.getName().ptr(), in_entry.value.getType()), GenericCommand::DisplayType::PublicSuccess);
for (auto& channel_pair : server->getChannels()) {
auto& channel = channel_pair.second;
line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("Channel %.*s - Type: %d", channel.getName().size(), channel.getName().ptr(), channel.getType()), GenericCommand::DisplayType::PublicSuccess);
line = line->next;

auto debug_user_callback = [&line, &in_entry](Jupiter::IRC::Client::Channel::UserTableType::Bucket::Entry &in_user_entry)
{
Jupiter::IRC::Client::User *user = in_user_entry.value.getUser();
line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("User %.*s!%.*s@%.*s (prefix: %c) of channel %.*s (of %u shared)", user->getNickname().size(), user->getNickname().ptr(), user->getUsername().size(), user->getUsername().ptr(), user->getHostname().size(), user->getHostname().ptr(), in_entry.value.getUserPrefix(in_user_entry.value) ? in_entry.value.getUserPrefix(in_user_entry.value) : ' ', in_entry.value.getName().size(), in_entry.value.getName().ptr(), user->getChannelCount()), GenericCommand::DisplayType::PublicSuccess);
for (auto& user_pair : channel.getUsers()) {
Jupiter::IRC::Client::User *user = user_pair.second.getUser();
line->next = new Jupiter::GenericCommand::ResponseLine(Jupiter::StringS::Format("User %.*s!%.*s@%.*s (prefix: %c) of channel %.*s (of %u shared)", user->getNickname().size(), user->getNickname().ptr(), user->getUsername().size(), user->getUsername().ptr(), user->getHostname().size(), user->getHostname().ptr(), channel.getUserPrefix(user_pair.second) ? channel.getUserPrefix(user_pair.second) : ' ', channel.getName().size(), channel.getName().ptr(), user->getChannelCount()), GenericCommand::DisplayType::PublicSuccess);
line = line->next;
};

in_entry.value.getUsers().callback(debug_user_callback);
};

for (unsigned int index = 0; index < server->getChannelCount(); ++index)
server->getChannels().callback(debug_callback);

return ret;
}

Expand Down
5 changes: 2 additions & 3 deletions src/Plugins/FunCommands/FunCommands.cpp
Expand Up @@ -19,7 +19,6 @@
#include <cstring>
#include "Jupiter/Functions.h"
#include "Jupiter/Socket.h"
#include "Jupiter/CString.h"
#include "FunCommands.h"
#include "IRC_Bot.h"

Expand Down Expand Up @@ -167,14 +166,14 @@ Jupiter::GenericCommand::ResponseLine *ResolveGenericCommand::trigger(const Jupi
Jupiter::ReferenceString command = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE);
if (command.equalsi("hostname"_jrs) || command.equalsi("host"_jrs))
{
Jupiter::ReferenceString resolved = Jupiter::Socket::resolveHostname(Jupiter::CStringS::gotoWord(parameters, 1, WHITESPACE).c_str(), 0);
Jupiter::ReferenceString resolved = Jupiter::Socket::resolveHostname(static_cast<std::string>(Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)).c_str(), 0);
if (resolved.isEmpty())
return new Jupiter::GenericCommand::ResponseLine("Error: Unable to resolve."_jrs, GenericCommand::DisplayType::PublicError);
return new Jupiter::GenericCommand::ResponseLine(resolved, GenericCommand::DisplayType::PublicSuccess);
}
else if (command.equalsi("ip"_jrs))
{
Jupiter::ReferenceString resolved = Jupiter::Socket::resolveAddress(Jupiter::CStringS::gotoWord(parameters, 1, WHITESPACE).c_str(), 0);
Jupiter::ReferenceString resolved = Jupiter::Socket::resolveAddress(static_cast<std::string>(Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)).c_str(), 0);
if (resolved.isEmpty())
return new Jupiter::GenericCommand::ResponseLine("Error: Unable to resolve."_jrs, GenericCommand::DisplayType::PublicError);
return new Jupiter::GenericCommand::ResponseLine(resolved, GenericCommand::DisplayType::PublicSuccess);
Expand Down
1 change: 0 additions & 1 deletion src/Plugins/RenX/RenX.Announcements/RenX_Announcements.h
Expand Up @@ -23,7 +23,6 @@
#include "Jupiter/Timer.h"
#include "Jupiter/File.h"
#include "Jupiter/String.hpp"
#include "Jupiter/CString.h"
#include "Jupiter/Reference_String.h"
#include "RenX_Plugin.h"

Expand Down
26 changes: 13 additions & 13 deletions src/Plugins/RenX/RenX.Commands/RenX_Commands.cpp
Expand Up @@ -1267,7 +1267,7 @@ void ReconnectIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString
if (server->isLogChanType(type))
{
if (server->reconnect(RenX::DisconnectReason::Triggered)) msg.set("Connection established");
else msg.format("[RenX] ERROR: Failed to connect to %.*s on port %u." ENDL, server->getHostname().size(), server->getHostname().ptr(), server->getPort());
else msg.format("[RenX] ERROR: Failed to connect to %.*s on port %u." ENDL, server->getHostname().size(), server->getHostname().c_str(), server->getPort());
source->sendMessage(channel, msg);
}
}
Expand Down Expand Up @@ -2104,7 +2104,7 @@ void AddBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &c
{
size_t index = 0;
Jupiter::ReferenceString name;
Jupiter::CStringS ip_str;
std::string ip_str;
uint32_t ip = 0U;
uint8_t prefix_length = 32U;
uint64_t steamid = 0U;
Expand Down Expand Up @@ -2138,7 +2138,7 @@ void AddBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &c
return;
}

ip_str = Jupiter::ReferenceString::getWord(parameters, index++, ADDBAN_WHITESPACE);
ip_str = static_cast<std::string>(Jupiter::ReferenceString::getWord(parameters, index++, ADDBAN_WHITESPACE));
}
else if (word.equalsi("Steam"_jrs) || word.equalsi("SteamID"_jrs))
{
Expand Down Expand Up @@ -2217,13 +2217,13 @@ void AddBanIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &c
flags = RenX::BanDatabase::Entry::FLAG_TYPE_GAME;

index = ip_str.find('/');
if (index != JUPITER_INVALID_INDEX)
if (index != std::string::npos)
{
Jupiter::ReferenceString prefix_length_str(ip_str.c_str() + index + 1);
prefix_length = prefix_length_str.asUnsignedInt();
if (prefix_length == 0)
prefix_length = 32U;
ip_str.truncate(prefix_length_str.size() + 1);
ip_str.erase(index);
}
ip = Jupiter::Socket::pton4(ip_str.c_str());

Expand Down Expand Up @@ -2555,7 +2555,7 @@ void AddExemptionIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableStr
else
{
size_t index = 0;
Jupiter::CStringS ip_str;
std::string ip_str;
uint32_t ip = 0U;
uint8_t prefix_length = 32U;
uint64_t steamid = 0U;
Expand All @@ -2576,7 +2576,7 @@ void AddExemptionIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableStr
return;
}

ip_str = Jupiter::ReferenceString::getWord(parameters, index++, ADDEXEMPTION_WHITESPACE);
ip_str = static_cast<std::string>(Jupiter::ReferenceString::getWord(parameters, index++, ADDEXEMPTION_WHITESPACE));
}
else if (word.equalsi("Steam"_jrs) || word.equalsi("SteamID"_jrs))
{
Expand Down Expand Up @@ -2613,16 +2613,16 @@ void AddExemptionIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableStr
if (flags == 0)
flags = RenX::ExemptionDatabase::Entry::FLAG_TYPE_BAN;

if (ip_str.isNotEmpty())
if (!ip_str.empty())
{
index = ip_str.find('/');
if (index != JUPITER_INVALID_INDEX)
if (index != std::string::npos)
{
Jupiter::ReferenceString prefix_length_str(ip_str.c_str() + index + 1);
prefix_length = prefix_length_str.asUnsignedInt();
if (prefix_length == 0)
prefix_length = 32U;
ip_str.truncate(prefix_length_str.size() + 1);
ip_str.erase(index);
}
ip = Jupiter::Socket::pton4(ip_str.c_str());

Expand Down Expand Up @@ -3204,8 +3204,8 @@ void ModRequestGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *play
Jupiter::String fmtName = RenX::getFormattedPlayerName(*player);
Jupiter::StringL user_message = Jupiter::StringL::Format(IRCCOLOR "12[%.*s Request] " IRCCOLOR IRCBOLD "%.*s" IRCBOLD IRCCOLOR "07 has requested assistance in-game; please look in ", staff_word.size(), staff_word.ptr(), fmtName.size(), fmtName.ptr());
Jupiter::StringS channel_message = Jupiter::StringS::Format(IRCCOLOR "12[%.*s Request] " IRCCOLOR IRCBOLD "%.*s" IRCBOLD IRCCOLOR "07 has requested assistance in-game!" IRCCOLOR, staff_word.size(), staff_word.ptr(), fmtName.size(), fmtName.ptr());
auto alert_message_callback = [this, source, server, &user_message, &channel_message, &messageCount](Jupiter::IRC::Client::ChannelTableType::Bucket::Entry &in_entry)

/*auto alert_message_callback = [this, source, server, &user_message, &channel_message, &messageCount](Jupiter::IRC::Client::ChannelTableType::Bucket::Entry &in_entry)
{
auto alert_message_user_callback = [server, &in_entry, &user_message, &messageCount](Jupiter::IRC::Client::Channel::UserTableType::Bucket::Entry &in_user_entry)
{
Expand All @@ -3224,7 +3224,7 @@ void ModRequestGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *play
in_entry.value.getUsers().callback(alert_message_user_callback);
user_message -= in_entry.value.getName().size();
}
};
};*/

source->sendMessage(*player, Jupiter::StringS::Format("A total of %u %.*ss have been notified of your assistance request.", messageCount, staff_word.size(), staff_word.ptr()));
}
Expand Down
19 changes: 8 additions & 11 deletions src/Plugins/RenX/RenX.Core/RenX_BanDatabase.cpp
Expand Up @@ -62,7 +62,7 @@ void RenX::BanDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, fp

// Read varData from buffer to entry
for (size_t varData_entries = buffer.pop<size_t>(); varData_entries != 0; --varData_entries)
entry->varData.set(buffer.pop<Jupiter::String_Strict, char>(), buffer.pop<Jupiter::String_Strict, char>());
entry->varData[buffer.pop<Jupiter::String_Strict, char>()] = buffer.pop<Jupiter::String_Strict, char>();

RenX::BanDatabase::entries.add(entry);
}
Expand Down Expand Up @@ -153,13 +153,10 @@ void RenX::BanDatabase::write(RenX::BanDatabase::Entry *entry, FILE *file)
size_t varData_entries = entry->varData.size();
buffer.push(varData_entries);

auto write_varData_entry = [&buffer](Jupiter::HashTable::Bucket::Entry &in_entry)
{
buffer.push(in_entry.key);
buffer.push(in_entry.value);
};

entry->varData.callback(write_varData_entry);
for (auto& entry : entry->varData) {
buffer.push(entry.first);
buffer.push(entry.second);
}

// push buffer to file
buffer.push_to(file);
Expand Down Expand Up @@ -189,7 +186,7 @@ void RenX::BanDatabase::add(RenX::Server *server, const RenX::PlayerInfo &player
Jupiter::ArrayList<RenX::Plugin> &xPlugins = *RenX::getCore()->getPlugins();
for (size_t i = 0; i < xPlugins.size(); i++)
if (xPlugins.get(i)->RenX_OnBan(*server, player, pluginData))
entry->varData.set(xPlugins.get(i)->getName(), pluginData);
entry->varData[xPlugins.get(i)->getName()] = pluginData;

entries.add(entry);
RenX::BanDatabase::write(entry);
Expand Down Expand Up @@ -239,7 +236,7 @@ uint8_t RenX::BanDatabase::getVersion() const
return RenX::BanDatabase::write_version;
}

const Jupiter::ReadableString &RenX::BanDatabase::getFileName() const
const std::string &RenX::BanDatabase::getFileName() const
{
return RenX::BanDatabase::filename;
}
Expand All @@ -251,7 +248,7 @@ const Jupiter::ArrayList<RenX::BanDatabase::Entry> &RenX::BanDatabase::getEntrie

bool RenX::BanDatabase::initialize()
{
RenX::BanDatabase::filename = RenX::getCore()->getConfig().get("BanDB"_jrs, "Bans.db"_jrs);
RenX::BanDatabase::filename = static_cast<std::string>(RenX::getCore()->getConfig().get("BanDB"_jrs, "Bans.db"_jrs));
return this->process_file(filename);
}

Expand Down
10 changes: 6 additions & 4 deletions src/Plugins/RenX/RenX.Core/RenX_BanDatabase.h
Expand Up @@ -20,9 +20,9 @@
#define _RENX_BANDATABASE_H_HEADER

#include <cstdint>
#include <unordered_map>
#include "Jupiter/Database.h"
#include "Jupiter/String.hpp"
#include "Jupiter/CString.h"
#include "Jupiter/ArrayList.h"
#include "RenX.h"

Expand Down Expand Up @@ -79,6 +79,8 @@ namespace RenX
*/
struct RENX_API Entry
{
using VarDataTableType = std::unordered_map<Jupiter::StringS, Jupiter::StringS, Jupiter::default_hash_function>;

fpos_t pos; /** Position of the entry in the database */
uint16_t flags /** Flags affecting this ban entry (See below for flags) */ = 0x00;
std::chrono::system_clock::time_point timestamp /** Time the ban was created */;
Expand All @@ -91,7 +93,7 @@ namespace RenX
Jupiter::StringS name /** Name of the banned player */;
Jupiter::StringS banner /** Name of the user who initiated the ban */;
Jupiter::StringS reason /** Reason the player was banned */;
Jupiter::HashTable varData; /** Variable entry data */
VarDataTableType varData; /** Variable entry data */

static const uint16_t FLAG_ACTIVE = 0x8000U;
static const uint16_t FLAG_USE_RDNS = 0x4000U;
Expand Down Expand Up @@ -199,7 +201,7 @@ namespace RenX
*
* @return Database file name
*/
const Jupiter::ReadableString &getFileName() const;
const std::string &getFileName() const;

/**
* @brief Fetches the list of ban entries.
Expand All @@ -217,7 +219,7 @@ namespace RenX
uint8_t read_version = write_version;
fpos_t eof;

Jupiter::CStringS filename;
std::string filename;
Jupiter::ArrayList<RenX::BanDatabase::Entry> entries;
};

Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/RenX/RenX.Core/RenX_Core.cpp
Expand Up @@ -58,7 +58,7 @@ bool RenX::Core::initialize()

if (server->connect() == false)
{
fprintf(stderr, "[RenX] ERROR: Failed to connect to %.*s on port %u. Error code: %d" ENDL, server->getHostname().size(), server->getHostname().ptr(), server->getPort(), Jupiter::Socket::getLastError());
fprintf(stderr, "[RenX] ERROR: Failed to connect to %.*s on port %u. Error code: %d" ENDL, server->getHostname().size(), server->getHostname().c_str(), server->getPort(), Jupiter::Socket::getLastError());
delete server;
}
else RenX::Core::addServer(server);
Expand Down

0 comments on commit b5be829

Please sign in to comment.