Uchicago的chirc项目的随笔
chirc以下RFC对IRC协议的描述
[*] Internet Relay Chat:Architecture。 本文档描述了 IRC 的整体架构。
[*] Internet Relay Chat: Channel Management。本文档描述了如何在 IRC 中管理频道(channels)。
[*] Internet Relay Chat: Client Protocol。本文档描述了 IRC 客户端和服务器之间使用的协议(有时称为“客户端 - 服务器”协议)。
[*],每个命令对应的Command responsesRFC2812第5章 https://www.rfc-editor.org/rfc/rfc2812?utm_source=chatgpt.com#section-5.1
[*]第三章为每个命令的detail https://www.rfc-editor.org/rfc/rfc2812?utm_source=chatgpt.com#section-3
[*] Internet Relay Chat: Server Protocol。本文档描述了同一网络中 IRC 服务器之间使用的“服务器 - 服务器”协议。
软件要求
https://www.33rz.com/image-2.png
项目的构建和执行
[*]Once you have done this, simply run make inside the build directory to build chirc:
cd build/
make
[*]只允许修改src/文件夹下的内容和CMakeLists.txt
[*]If you add .c files to the src/ directory, you must also add that file to the list of files specified in the add_executable command in the CMakeLists.txt file.
[*]增加第三方库:If you want to use third-party libraries, add them inside the lib/ directory (do not add them in the src/ directory!). If the third-party library has header files you need to #include in your code, do not copy the header files into the src/ directory. Instead, add the library’s directory to the list of directories in the include_directories command in the CMakeLists.txt file. This way, you will be able to #include header files in those directories.
[*]如果你想让 make 输出更详细的信息(包括它在构建过程中实际执行的具体命令),只需要这样运行 make:
make VERBOSE=1
[*]运行
./chirc -o foobarMessage部分
每条 IRC 消息最多由三部分组成:前缀(可选)、命令 和 命令参数(最多 15 个)。
在 IRC 协议中,一条消息的结构大致是:
[:prefix](optional) command [:trailing]
前缀 命令 参数 前缀、命令和所有参数之间都使用一个 ASCII 空格字符(0x20)进行分隔。
消息类型:
登录到IRC服务器
当 IRC 客户端连接到 IRC 服务器时,必须首先注册其连接
https://www.33rz.com/image.png
所有可能的回复代码都在 RFC2812 第5节中定义。
用户间的消息传递
聊天中继,以及相关的格式
加入,聊天,以及离开频道
连接到 IRC 服务器的用户可以使用 JOIN 消息加入现有频道。消息本身的格式非常简单(唯一的参数是用户想要加入的频道的名称)
中文任务书中提到的,频道"运营商"和"操作员"其实就是频道的管理者,具有特权模式
一旦用户加入了频道,向频道发送消息与向个人用户发送消息基本相同
使用项目文件的注意事项
[*]要修改代码,只需将文件添加到 src /目录。请注意,如果添加其他.c 文件,则需要修改Makefile 文件,以便把它们包含在构建中
[*]chirc 服务器使用简单日志记录函数 chilog()将消息打印到标准输出,该函数在 src /
log.h 中声明。如果需要将消息打印到标准输出,则必须使用 chilog()函数。 这是一个简单的函数,它需与 printf 相同的参数,以及指定日志记录级别的附加参数
[*]
测试和调试
1. 分别自动测试(用于评分)和手动测试(用于debug)
2.
https://www.33rz.com/image-3.png
3. pytest具有调试功能
3.1 罗列category
make categories-assignment-Nhttps://www.33rz.com/image-5.png
3.2运行某一类测试
pytest ../tests/ --chirc-category PRIVMSG_NOTICE3.3 运行某一个测试
pytest ../tests/ -k test_connect_both_messages_at_once可以找到的测试名
===================================== FAILURES =====================================
______________ TestBasicConnection.test_connect_both_messages_at_once ______________
[*]可以通过手动连接服务器的方式进行更交互式的调试。
只需运行服务器,比如:
make && ./chirc -o foobar -p 7776然后使用 telnet 连接:
telnet localhost 7776这样你就能直接和 IRC 协议交互。
例如,注册一个用户,你需要在 telnet 里输入:
NICK user1按回车(发送 \r\n)后,接着输入:
USER user1 * * :User One再按回车。如果你的服务器实现正确,telnet 会显示服务器对这两个命令的欢迎回复。
登录成功后,你可以手动测试其他 IRC 命令。
C语言语法知识部分
[*]
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页:
[1]