add fake JOIN command

This commit is contained in:
tali 2024-01-08 00:31:05 -05:00
parent 4dc454e9a2
commit bd5afe7ad1
2 changed files with 20 additions and 9 deletions

View File

@ -42,10 +42,8 @@ let attempt_to_register t =
| `nick_in_use -> `nicknameinuse nick
| `nick_set ->
Logs.debug (fun m -> m "init mode: +%a" Irc.Mode.pp t.user.mode);
User.send t.user
(Irc.Msg.make "MODE" [nick; Fmt.str "+%a" Irc.Mode.pp t.user.mode]
~prefix:(User_prefix (nick, None, None)));
(* TODO: set initial mode *)
send t (Irc.Msg.make "MODE" [nick; Fmt.str "+%a" Irc.Mode.pp t.user.mode]
~prefix:(User.prefix t.user));
`welcome
end
| _, _ -> `ok
@ -78,14 +76,18 @@ let on_msg_privmsg t tgt msg _ =
| None -> `nosuchnick tgt
| Some dst -> Router.privmsg t.user (`user dst) msg; `ok
let on_msg_join t tgt _ =
send t (Irc.Msg.make "JOIN" [tgt] ~prefix:(User.prefix t.user));
`names ("@", tgt, ["@", User.nick t.user; "", "moe"; "", "barry"])
let on_msg_privmsg t tgt msg = require_registered t (on_msg_privmsg t tgt msg)
let on_msg_join t tgt = require_registered t (on_msg_join t tgt)
(* > misc *)
let on_msg_quit t why =
let why = String.concat " " why in
Logs.debug (fun m -> m "%a: quit: %S" pp_sockaddr t.addr why);
(* broadcast "quit" message *)
`quit
(* message sending *)
@ -123,6 +125,12 @@ let rpl_motd t =
rpl t "376" ["End of /MOTD command"];
end
let rpl_names t chan_prefix chan users =
begin
List.iter (fun (up, u) -> rpl t "353" [chan_prefix; chan; up ^ u]) users;
rpl t "366" [chan; "End of NAMES list"]
end
let err_alreadyregistered t = rpl t "462" ["Unauthorized command (already registered)"]
let err_needmoreparams t cmd = rpl t "461" [cmd; "Not enough parameters"]
let err_nicknameinuse t nick = rpl t "433" [nick; "Nickname is already in use"]
@ -147,13 +155,16 @@ let on_msg t (msg : Irc.Msg.t) : unit =
| "PRIVMSG", tgt :: msg :: _ ->
on_msg_privmsg t tgt msg
| "PRIVMSG", [_] -> `notexttosend | "PRIVMSG", [] -> `norecipient
| "NICK", _ | "USER", _ -> `needmoreparams
| "JOIN", tgt :: _ ->
on_msg_join t tgt
| "NICK", _ | "USER", _ | "JOIN", _ -> `needmoreparams
| _, _ -> `unknowncommand
in
match result with
| `ok -> ()
| `quit -> close t
| `welcome -> rpl_welcome t; rpl_motd t
| `names (cp, ch, us) -> rpl_names t cp ch us
| `tryagain -> rpl_tryagain t msg.command
| `alreadyregistered -> err_alreadyregistered t
| `needmoreparams -> err_needmoreparams t msg.command

View File

@ -60,7 +60,7 @@ module User = struct
if Hashtbl.mem t.router.users key then
`nick_in_use
else begin
((* TODO: notify others of nick change *));
((* TODO: relay NICK message *));
unset_nick t;
Hashtbl.add t.router.users key t;
t.key <- key;
@ -68,14 +68,14 @@ module User = struct
end
let cleanup t =
(* TODO: notify other users of quit *)
(* TODO: relay QUIT message *)
close t;
unset_nick t
end
let privmsg src dst txt =
let prefix = User.prefix src in
match dst with
| `user dst ->
let prefix = User.prefix src in
let msg = Irc.Msg.make "PRIVMSG" [User.nick dst; txt] ~prefix in
User.send dst msg