找回密码
 立即注册
首页 业界区 安全 Uchicago的chirc项目的随笔

Uchicago的chirc项目的随笔

颛孙中 2025-7-14 15:18:34
chirc

以下RFC对IRC协议的描述


  • [RFC2810] Internet Relay Chat:Architecture。 本文档描述了 IRC 的整体架构。
  • [RFC2811] Internet Relay Chat: Channel Management。本文档描述了如何在 IRC 中管理频道(channels)。
  • [RFC2812] 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

  • [RFC2813] Internet Relay Chat: Server Protocol。本文档描述了同一网络中 IRC 服务器之间使用的“服务器 - 服务器”协议。
软件要求


项目的构建和执行


  • Once you have done this, simply run make inside the build directory to build chirc:
  1. cd build/
  2. 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:
  1. make VERBOSE=1
复制代码

  • 运行
  1. ./chirc -o foobar
复制代码
Message部分

每条 IRC 消息最多由三部分组成:前缀(可选)、命令 和 命令参数(最多 15 个)
在 IRC 协议中,一条消息的结构大致是:
  1. [:prefix](optional) command [params] [:trailing]
  2. 前缀      命令     参数      
复制代码
前缀、命令和所有参数之间都使用一个 ASCII 空格字符(0x20)进行分隔。
消息类型:

登录到IRC服务器

当 IRC 客户端连接到 IRC 服务器时,必须首先注册其连接

所有可能的回复代码都在 RFC2812 第5节中定义。
用户间的消息传递

聊天中继,以及相关的格式
加入,聊天,以及离开频道

连接到 IRC 服务器的用户可以使用 JOIN 消息加入现有频道。消息本身的格式非常简单(唯一的参数是用户想要加入的频道的名称)
中文任务书中提到的,频道"运营商"和"操作员"其实就是频道的管理者,具有特权模式
一旦用户加入了频道,向频道发送消息与向个人用户发送消息基本相同
使用项目文件的注意事项


  • 要修改代码,只需将文件添加到 src /目录。请注意,如果添加其他.c 文件,则需要修改Makefile 文件,以便把它们包含在构建中
  • chirc 服务器使用简单日志记录函数 chilog()将消息打印到标准输出,该函数在 src /
    log.h 中声明。如果需要将消息打印到标准输出,则必须使用 chilog()函数。 这是一个简单的函数,它需与 printf 相同的参数,以及指定日志记录级别的附加参数

测试和调试

1. 分别自动测试(用于评分)和手动测试(用于debug)

2.


3. pytest具有调试功能

3.1 罗列category
  1. make categories-assignment-N
复制代码

3.2运行某一类测试
  1. pytest ../tests/ --chirc-category PRIVMSG_NOTICE
复制代码
3.3 运行某一个测试
  1. pytest ../tests/ -k test_connect_both_messages_at_once
复制代码
可以找到的测试名
  1. ===================================== FAILURES =====================================
  2. ______________ TestBasicConnection.test_connect_both_messages_at_once ______________
复制代码

  • 可以通过手动连接服务器的方式进行更交互式的调试。
    只需运行服务器,比如:
  1. make && ./chirc -o foobar -p 7776
复制代码
然后使用 telnet 连接:
  1. telnet localhost 7776
复制代码
这样你就能直接和 IRC 协议交互。
例如,注册一个用户,你需要在 telnet 里输入:
  1. NICK user1
复制代码
按回车(发送 \r\n)后,接着输入:
  1. USER user1 * * :User One
复制代码
再按回车。如果你的服务器实现正确,telnet 会显示服务器对这两个命令的欢迎回复。
登录成功后,你可以手动测试其他 IRC 命令。
C语言语法知识部分





来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册