This project is an implementation of an IRC (Internet Relay Chat) server in C++98. The server handles multiple clients simultaneously, supports channel creation and management, and implements core IRC commands following the RFC 2119 protocol specification.
The server is capable of:
- Handling multiple client connections using non-blocking I/O and
poll() - Processing IRC commands including NICK, USER, JOIN, PRIVMSG, MODE, TOPIC, INVITE, KICK, PART, and PASS
- Managing channels with various modes (invite-only, topic restrictions, key-protected, user limits)
- Maintaining user authentication and registration
- Broadcasting messages to channels and users
- Client Authentication: PASS command for password verification
- User Registration: NICK and USER commands for client identification
- Channel Management:
- JOIN command with channel creation
- Channel modes:
i(invite-only),t(topic restricted),k(key protected),l(user limit),o(operator)
- Messaging:
- PRIVMSG for direct messages and channel broadcasts
- TOPIC for channel topic management
- User Management:
- INVITE to invite users to invite-only channels
- KICK to remove users from channels (operator only)
- PART to leave channels
- Non-blocking I/O using
poll() - Signal handling for graceful shutdown (SIGINT, SIGQUIT)
- Dynamic memory management for clients and channels
- Thread-safe design with no global state
The project includes a Makefile for compilation:
makeThis will generate the ircserv executable.
Run the server with:
./ircserv <port> <password>Parameters:
<port>: The port number on which the server will listen (e.g., 6667)<password>: The connection password required by clients
Example:
./ircserv 6667 secretpassYou can connect to the server using any IRC client (like irssi, HexChat, or netcat):
Using netcat for testing:
nc localhost 6667Then enter IRC commands manually:
PASS secretpass
NICK your_nickname
USER username 0 * :Real Name
Using a full IRC client:
/server localhost 6667 -pass secretpass
| Command | Description |
|---|---|
PASS <password> |
Authenticate with the server |
NICK <nickname> |
Set or change your nickname |
USER <username> 0 * :<realname> |
Register your user information |
JOIN <#channel> |
Join or create a channel |
PART <#channel> |
Leave a channel |
PRIVMSG <target> :<message> |
Send a message to a user or channel |
TOPIC <#channel> [<topic>] |
View or set a channel's topic |
MODE <#channel> [<modes> [<params>]] |
Change channel modes |
INVITE <nickname> <#channel> |
Invite a user to an invite-only channel |
KICK <#channel> <nickname> [:<reason>] |
Remove a user from a channel (operator only) |
| Mode | Description | Parameters |
|---|---|---|
i |
Invite-only | None |
t |
Topic restricted (operators only) | None |
k |
Key/password required | <key> |
l |
User limit | <limit> |
o |
Operator status | <nickname> |
Examples:
MODE #channel +i- Make channel invite-onlyMODE #channel +k secretkey- Set channel passwordMODE #channel +l 10- Limit channel to 10 usersMODE #channel +o username- Grant operator status
The IRC server includes a built-in bot that allows users to play a game called Nim.
-
The game contains 9 piles of objects, with each pile initially containing 9 objects.
-
On your turn, you must choose exactly one pile.
-
You must remove one or more objects from that chosen pile.
-
You cannot remove objects from multiple piles in a single turn.
-
The player who removes the very last object from the board wins the game.
-
All interactions with the bot are done using the
PRIVMSGcommand, using the syntax:PRIVMSG Bot : <amount>. -
Starting the game: To initiate your first game, send a message to the bot (e.g.,
PRIVMSG Bot : 1). Because it is your first interaction, the bot will reply with a welcome message, a list of the rules, and a visual display of the starting piles. -
Step 1 (Select a Pile): The bot will prompt you with, "Your turn, Choose pile index from 1 to 9". Send a
PRIVMSGto the bot with your chosen pile number. -
Step 2 (Remove Stones): After selecting a valid pile, the bot will ask you how many stones you want to remove (from 1 up to the current total in that pile). Send another
PRIVMSGwith the amount you wish to remove. -
Bot's Turn: After your turn, the bot will automatically calculate its move, remove stones, and display the updated board state.
-
Winning/Losing: You will alternate turns until all stones are gone. The bot will then announce if you beat it or if it won, and the game will reset for a new match.
- Server Basics: https://www.paessler.com/it-explained/server
- What is a Socket? (Reddit Discussion): https://www.reddit.com/r/learnprogramming/comments/12ifgcf/what_is_a_socket_what_does_it_mean_that_a/
- Socket in Computer Networks (GeeksforGeeks): https://www.geeksforgeeks.org/computer-networks/socket-in-computer-network/
- Socket Programming in C++ (GeeksforGeeks): https://www.geeksforgeeks.org/cpp/socket-programming-in-cpp/
- C++ Socket Programming (TutorialsPoint): https://www.tutorialspoint.com/cplusplus/cpp_socket_programming.htm
- Socket Programming Tutorial (YouTube): https://www.youtube.com/watch?v=XXfdzwEsxFk
- TCP/IP Model (GeeksforGeeks): https://www.geeksforgeeks.org/computer-networks/tcp-ip-model/
AI was used as a learning and documentation assistant throughout the project. It helped explain networking concepts, the IRC protocol, socket programming, and C++98 features, as well as assisted with debugging, code reviews, and improving the project's documentation. All implementation decisions, design, and final code were developed and validated by the project authors.