Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ compile_commands.json

.DS_Store
Thumbs.db

.bonus
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ TEST_DIR := ./tests
INCLUDES := -I$(INC_DIR) \
-I$(INC_DIR)/core \
-I$(INC_DIR)/network \
-I$(INC_DIR)/commands
-I$(INC_DIR)/commands \
-I$(INC_DIR)/bot

BONUS_INCLUDES := -I$(INC_DIR)/bot

Expand Down Expand Up @@ -60,8 +61,11 @@ SRCS := $(SRCS_DIR)/main.cpp \
$(SRCS_DIR)/modes/UserLimitMode.cpp \
$(SRCS_DIR)/protocol/IrcUtils.cpp

BONUS_SRCS := $(SRCS_DIR)/bot/BotClient.cpp \
$(SRCS_DIR)/bot/SixSevenBot.cpp

OBJ = $(SRCS:$(SRCS_DIR)/%.cpp=$(OBJ_DIR)/%.o)

BONUS_SRCS := $(SRCS_DIR)/bot/BotMessageBuffer.cpp \
$(SRCS_DIR)/bot/BotClient.cpp

OBJS := $(SRCS:$(SRCS_DIR)/%.cpp=$(OBJ_DIR)/%.o)
OBJS_BONUS := $(SRCS:$(SRCS_DIR)/%.cpp=$(OBJ_DIR)/bonus/%.o) \
Expand Down
77 changes: 77 additions & 0 deletions ascii/xavier.txt
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evil XaViEr NiEl

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allez hop set as finished -> give up

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-----:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::----------------------------------------------------------------------------------------------------------------:::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::--------------------------------------------------------------------------------------------------------------------------------------------:::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::------------------------------------------------------------------------------------------------------=------==-===-=---=--=-----------------------------:::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::------------------------------------------------------------------------------------------=====-=+===++=+=++=++==---=---------::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--::::::::::::::::::::::::::::::::::::::::::::---==++++==+==++++++*****+**#+**++==-==----::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--::::-*=++=+**###**+*+*+**##**++*#+++++***+----::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-+===+=++=+=***##%####%%%#%%%##**+++=*+++====-::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-:---=+===+=+##%%%##%%%%%%@%%%%%%%%#%##*+==-===++=---:::::::::::::::::::::::::::::::::::.::::::::
..........::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--==++===+#%%%%%%@%@@@@@@%@@@@@%@@@%%%%%##*+-=+++==---:::::::::::::::::::::::::::::::::::::::::::
.....:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-===+*+*%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@%%%%%#*+==+**+==---::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::----++*%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@%%%%%%#*=--==------:::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--:-+*#%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@%%%%%%%##++*+==-::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--::+*%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@%%%%%%%%%##*++=--:::-::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::---=#%%##%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@%%%%%%%%%%%##+++-:-:::-:::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::----::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-----*###%#%%%%%%%%%@@@@@@@@@@@@@@@@@%%@%%%%%%%#########*=-:-----:::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::-----::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-=--=#####%%%%%%%%%%%%@%%@@@@@%@%@@@@%%%%%%%%%%%########*+--:::--:::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::----::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::---=*#######%#%%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#####******+=::-:---::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::---::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--:-=*###########%%%#%%%%%%%%%%%%%%%%%%%%%%%%%#####********=--:----::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::--::-=***#*####%%###%####%%######%%%%####%%%%#######********=-::-----:::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-::-=****########%%#%%#%%%%%%%%%%%%%%%%%%%%%%%%#*#********+=-:::-::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-:---:-=+****#####%%%%%%%%%%#######%%#%%%%%%%#####*##*******++--:::::-::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::----:-=+****###%%%%%%%%%%%%%%%##%#%%##%%%%%%%#######******++=-::::::-::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::------=+**###%%%%%#%%#%%#%%%%%%%%%%%%%%%%%%%%%%#%%###*#****+==::::::--:::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::-----::::::::::::::::::::::::::::::::::::::::::::::::::::---:--=+**#%%%%%##*#####*#%%######%#########%####%%%##%#***++=-:::----:::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::-----:::::::::::::::::::::::::::::::::::::::::::::::::::---::--=**####%####%#**+++++****#**************#####****+*****=-:::::--:::::::::::::::::::::::::::::::::::
::::::::::::::::------:::::::::::::::::::::::::-----------:::::::::::::::::::::::::::::::::::::::::::::::--:::--+*#****+==++==--==-===+++=+++=+=====-=-===========+**#*=-::---=-:::::::::::::::::::::::::::::::::::
::::::::------------------------------------------===========---:::::::::::::::::::::::::::::::::::::::::---:---*##*===------:::::::--========----------:--------=+**#*+--:--==--::::::::::::::::::::::::::::------
:::::----=======----------------===============+++++++++++++++==-------::::::::::::::::::::::::::::::::::----:-=*##*=-:-----------------==++==-----------------=-=***#*+-::=--==---:::::::::::::::::::::::::----===
::::---====++++=====-------================+++++**************++==------:::::::::::::::::::::::::::::::::-:----=*###+=--:::::::::::-::-=+**++=---::::::::-::---===**#**+--:---===--::::::::::::::::::::::::----====
:::---===+++++++======================+++++++++*****######*****+===------::::::::::::::::::::::::::::::::::==--=**#*++=-:--------::::::+###%#=::::::::---:::---=*+****+=-:-======--::::::::::::::::::::::::----====
:::---===++++++======================+++++++++*****##########**++==------::::::::::::::::::::::::::::::::::+=-==**###*++++======------=+#%%%%+------------+=+*=******++==-==+=+==--:::::::::::::::::::::::::---====
::::--===+++======-------=================+++++*****#######****+==-------:::::::::::::::::::::::::::::::::-+=-=+*###%#####+-:::--:--=+*###%%%#==:--=====+++==*##*##***+==--==++==--::::::::::::::::::::::::::----==
:::::----=====-------------------===========++++**************++==------::::::::::::::::::::::::::::::::::-**===+######%%%##*+=+++++*##%*##%%##+=--:----::-+***####***+==--=+++===---::::::::::::::::::::::::::----
::::::-------:--------------------------=====+++****++++******++==------:::::::::::::::::::::::::::::::::::+#+==+#########%%%#%#########%%%%%#*##*++++++*#%%%%%##****+=-=-=++++====--:::::::::::::::::::::::::::---
:::::::::::::::::::--------------------====++*******++++*******++==-----::::::::::::::::::::::::::::::::::::=*#+=****+++*####%#%%%%#**####%%%#####%%%%%%%%%%%#******++==***++++=====---:::::::::::::::::::::::::---
:::::::::---------------------------=====+++*******************++==----------::::::::::::::::::::::::::::::--***+++++=+##*******==-=+*#####%%####*-=++####**####****++-+***++++====----:---:::::::::::::::::::-----
::::::------------------------------=====+++*******************++==--------------------------:::::::::::-----+++=+====***++==+=----**#****####***##=--==++*++***+++++===*+++======-----------::::::::::::::::------
::::--------------------------------=====++++******++++++++++*++==-------------------------------------------=++=+=-==========---==****###*##*++****----==++++++*+=++++=+++======-----------------------------=====
:-------------==========++++++++++++======+++++++++++====++++++===-----====================+++++++++==========++++==-========---+**====##******++====----=======++==++++++=======--------------=-===============+++
-==========+++++***#####%%%%%%%%%%%%###*******+++++++++++++++++==========+++++++++++==++++++++****+++++++=++++++++=========----+***=-::-=====++=--=++=----==========+++++===-==--------======================++++++
===++++++++++***####%%%%%%@@@@@@@@@%%%%####*******++++++++++++++=======+++++++++++++++++++++*******++++++++++==--+======---::--=+**+==--:-===-::-=+*+==----=========++======================================+++++++
=+++++++++++****###%%%%%@@@@@@@@@@@@%%%%####*********+++++++++++=======+++++++++++++++++++++********+++++====----+=======------=+**++==---:::---=+++++=---:-========+----=====================================+++++
+++++++++++++***###%%%%%%@@@@@@@@@@@%%%%#####*******+++++++++++++======+++++++++++++++++++++++****++++======-----========-:----===+====--------==+=+===-------=====++:::---========================--==============
====++++++++++***####%%%%%%%@@@@@@%%%%#####*******+++++++++++++++=======++++++===========+++++++++=========-----::==+=====--------------------=======---------======-::::---------===------------------------------
==============+++*****#######%%%%#####******+++++++++++++++========---==================================------:::::=====+==-----------:::::-----:::::-------========:::::::::::------------------------------------
--------------====================================================-----===============-==------========-------:::::-=========++*****++============+**++===-========-::::-:::::::-----------------------------------
--------=============================+++++++++++++++++++++++***++++==+++******+==========------:--====-------::::::-========++***++=+++++=======+******+==========:::::::--:::::::-------------------------========
----====++=++++******************************#####################******#+==============------------------:::-:::::-*-====--=++++++=====-==========+++*++========:::::::::---::::::::::-----------------------=====
---==+++++++++****###******************################%%%%%%%%%%###*+================---:-----:::------:::::::::::=#=--==--=+**+++====----========++++++=======:::::::::::----::::::::::::::::::::---------------=
---==++++++++**************************##########################*================-------:-------------::::::::::::-%===-===-==++**++++=========++++++++=======#:::::::::::::-::::::::::::::::::::::::::-----------
---===+++++++++++******************************###############+=============---------------------------:::::::::::::%*==-=====-==*++++++++====+****+++========+%::::::::::::::::::-::::::::::::::::::::::::::::::--
::---========================================+++++++++++++=================----------------------------:::::::::::::#%====-====-==++===++++===+++++++=========+%:::::::::::::::::::::::::::::::::::::::::::::::::::
::::-----====----------------------------------------=------===-==========-----------::::::::::-------::::::::::::::#%#======================================-+@:::::::::::::::::::::::::::::::::::::::::::::::::::
::::::-----------:::::::::::::-----------------------==----==============----------::::::::::::-------::::::::::::::+%%====================================-::+%:::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::---------------==-===========-------------:::::::::::::-------::::::::::::::-%%*----================+++==+========-:::*%:::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::---------------=--=========--------------:::::::::::---------:::::::::::::::#%#=:---===========++++++++++=======-:::-%%:::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::---------:-----=-=========-------------:::::::::::----------:::::::::::::::#%%+::--=========++++++++++++=====--::::*%#:::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::----------:-------====------------------:::::::::::-:-----:::::::::::::::::*%%#-::--========++++++++++++====-:::::=%@*:::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::-----------------::------====----------------:::::::::::::::--::::::::::::::::::::=%%%+::::--=======++++++++++====-:::::-%%@+:::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::--------------------===========--------------=------------------:::::::::::::::::::::::::::::::::::::-#%%#=:::---======++++++++++==--:::::-#+*#*:::::::::::::::::::::::::::::::::::::::::::::::::::
:::::--------------------------=========+++++++=-:----::-------------------:----::::::::::::::::::::::::::::::::::::::#%%%#-::-----==+==++++++++==--:::::=#=**#::::::::::::::::::::::::::::::::::::::::::::::::::::
:::-------------------------==========+++******+-::---::-----------------------:::::::::::::::::::::::::::::::::::::::#%%%%#=:------====+++++++==---::::+*==**:::::::::::::::::::::::::::::::::::::::::::::::::::::
:::-------------------------===========+++**++++--::--:::::-------------------::::::::::::::::::::::::::::::::::::::::*%%%%*#=-------===+++++==-----:::+*+==*::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::-------------------------------------========-:::::::::::------------------::::::::::::::::::::::::::::::::::::::::=%*+*++**-------========-----:::**++=+-::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::-----------------------------------:::------::::::::::::::---------------::::::::::::::::::::::::::::::::::::::::::#*+++++***------=====------::-**++==--::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::-----------------------------------::::::----::::::::::::::--------------:::::::::::::-::::::::::::::::::::::::::::**++++***###--------------::-***+====-::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::------------------------======+++++****#*-----:::::::::::::::------------::::::::::::::::::::::::::::::::::::::::::+=+++++****##*-:---------:::*#*+=====:::::::::::::::::::::::::::::::::::::::::::::::::::::::
----===============++++++****####%%%@@@@@@@@@=----:::::::::::::::::::------::::::::::::::::::::::::::::::::::::::::::::-=++++++*****##+:::::---:::=##*+++===:::::::::::::::::::::::::::::::::::::::::::::::::::::::
==+++++++++++++******######%%%%%@@@@@@@@@@@@@@----::::::::::::::::::::::----:::::::::::::::::::::::::::::::::::::::::::===++++++******#*+-::::::::##*+++++==:::::::::::::::::::::::::::::::::::::::::::::::::::::::
****####*******#######%%%%%%%%@@@@@@@@@@@@@@@@@+--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::==++**++++**+++**###+-:::-+#***++++=-:::::::::::::::::::::::::::::::::::::::::::::::::::::::
******##********###########%%%%%%%@@@@@@@@@@@@@:::--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-=+++++++++++++++++++++=-+#****+++++-:::::::::::::::::::::::::::::::::::::::::::::::::::.:..
+++++++++++++++++++++++++***********#########%-:::::--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-===++++++===++++++++++++##********+-:::::::::::::::::::::::::::::::::::::::::::::::::::::..
--------------------------------------------------::::-::::::::::::...::::::::::::::::::::::::::::::::::::::::::::::::::+====++++++===++++++++*###*******++::::::::::::::::::::::::::::::::::::::::::::::::::......


71 changes: 71 additions & 0 deletions death.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

if [[ $# -lt 3 ]]; then
echo "Usage: $0 <hostname> <port> <password>"
echo "Example: $0 127.0.0.1 6667 lol"
exit 1
fi

HOST="$1"
PORT="$2"
PASS="$3"

CLIENTS=1000
CHANNEL="#the-void"
MAX_DEATHS=10
MESSAGE="this is a test message"
SLEEP_BETWEEN_MSGS=0.01 # set to 0 for max pain

rand_nick() {
echo "lab$(tr -dc a-z0-9 </dev/urandom | head -c6)"
}

rand_goodbye() {
shuf -n1 <<-EOF
brb dissolving
lost to entropy
lab rat escaped
signal collapsed
EOF
}

# choose victims
DEATH_COUNT=$(shuf -i0-$MAX_DEATHS -n1)
DEAD_CLIENTS=$(shuf -i1-$CLIENTS -n "$DEATH_COUNT")

should_die() {
grep -qx "$1" <<< "$DEAD_CLIENTS"
}

echo "[*] Target: $HOST:$PORT"
echo "[*] Clients: $CLIENTS"
echo "[*] Mid-stream deaths: $DEATH_COUNT"

for i in $(seq 1 "$CLIENTS"); do
(
nick=$(rand_nick)
msg_count=$(shuf -i100-200 -n1)

{
echo "PASS $PASS"
echo "NICK $nick"
echo "USER $nick 0 * : Lab rat"
echo "JOIN $CHANNEL"

for m in $(seq 1 "$msg_count"); do
echo "PRIVMSG $CHANNEL :$MESSAGE [$m/$msg_count]"
sleep "$SLEEP_BETWEEN_MSGS"

if should_die "$i" && (( m == msg_count / 2 )); then
# abrupt disconnect (no QUIT)
exit 0
fi
done

echo "QUIT :$(rand_goodbye)"
} | nc "$HOST" "$PORT" >/dev/null 2>&1
) &
done

wait
echo "[*] Tests complete, surely your server hasn't died right :)?"
2 changes: 1 addition & 1 deletion incs/bot/BotClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "IClient.hpp"
#include "IServer.hpp"
#include "IChannel.hpp"
#include "bot/BotMessageBuffer.hpp"

class IBot;
class BotMessageBuffer;
class BotClient : public IClient
{
private:
Expand Down
41 changes: 41 additions & 0 deletions incs/bot/BotMessageBuffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once
#include <iostream>
#include <cstddef>
#include <vector>

#include "core/IMessageBuffer.hpp"
#include "core/IServer.hpp"
#include "bot/IBot.hpp"


class BotMessageBuffer : public IMessageBuffer
{
private:
IServer &m_server;
IBot *m_bot;
std::string m_readBuffer;
std::string m_writeBuffer;

void processIncomingMessage(const std::string& raw);
void parseAndDispatch(const std::string& prefix,
const std::string& command,
const std::vector<std::string>& params);

void setBot(IBot* bot);
void setBotClient(IClient* client);

public:
BotMessageBuffer(IServer& server);
virtual ~BotMessageBuffer();

void appendRead(const std::string& data);
bool hasCompleteMessage() const;
std::string getNextMessage();
size_t getReadBufferSize() const;

void appendWrite(const std::string& data);
void consumeWriteBuffer(size_t bytes);
const std::string& getWriteBuffer() const;
void clearWriteBuffer();

};
22 changes: 22 additions & 0 deletions incs/bot/NielBot.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma one

#include "bot/IBot.hpp"
#include "core/IServer.hpp"

class NielBot : public IBot
{
private:
IServer* m_server;
IClient* m_client;
bool contains42(const std::string& msg)const;
void sendReply(IChannel* channel);

public:
NielBot(IServer* server, IClient* botClient);
virtual ~NielBot();

void onPrivateMessage(IClient* sender, const std::string& msg);
void onChannelMessage(IClient* sender, IChannel* channel, const std::string& msg);

IClient* getClient();
};
1 change: 0 additions & 1 deletion incs/core/IClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <string>

class IMessageBuffer;
// class MessageBuffer;

class IClient
{
Expand Down
Loading