From 68428d834733f2c91fd2fec8e8249782b4eb4dd8 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 19 Mar 2008 16:19:24 -0600 Subject: [PATCH] Start at channels --- channel.ml | 27 +++++++++++++++++++-------- channel.mli | 8 ++++++-- client.ml | 4 ++-- irc.ml | 2 ++ irc.mli | 3 +++ tests.ml | 2 +- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/channel.ml b/channel.ml index 0caf517..3a1d0bb 100644 --- a/channel.ml +++ b/channel.ml @@ -1,14 +1,18 @@ -type t = {name: string} +module String_map = + Map.Make (struct + type t = string + let compare = compare + end) -let modes = "t" +type client = Iobuf.t * Irc.nuhost -let by_name = Hashtbl.create 25 +type t = {name: string; + modes: string ref; + clients: client String_map.t} -let lookup name = - Hashtbl.find by_name name +let modes = "aimnqpsrtklb" -let create name = - {name = name} +let channels = String_map.empty let is_channel_name name = match name.[0] with @@ -16,4 +20,11 @@ let is_channel_name name = true | _ -> false - + +let has_mode chan mode = + String.contains !(chan.modes) mode + +let handle_command iobuf (nick, username, hostname) cmd = + match (Command.as_tuple cmd) with + | _ -> + () diff --git a/channel.mli b/channel.mli index bd7a277..73a33e6 100644 --- a/channel.mli +++ b/channel.mli @@ -1,8 +1,12 @@ type t +(* Channels handle: + + MODE, JOIN, PART, TOPIC, NAMES, LIST, INVITE, KICK, PRIVMSG, NOTICE +*) + val modes : string -val lookup : string -> t -val create : string -> t +val handle_command : Iobuf.t -> Irc.nuhost -> Command.t -> unit val is_channel_name : string -> bool diff --git a/client.ml b/client.ml index 5df3883..08a9e97 100644 --- a/client.ml +++ b/client.ml @@ -26,8 +26,8 @@ let error num args text = let uhost cli = (!(cli.nick) ^ "!" ^ cli.username ^ "@" ^ (Iobuf.addr cli.iobuf)) -let close cli = - Iobuf.close cli.iobuf +let kill cli message = + Iobuf.close cli.iobuf ("Killed: " ^ message) let write_command cli cmd = Iobuf.write cli.iobuf cmd diff --git a/irc.ml b/irc.ml index b8d3ded..fe2b4dd 100644 --- a/irc.ml +++ b/irc.ml @@ -1,3 +1,5 @@ +type nuhost = (string * string * string) + let name = ref "irc.test" let version = "0.1" let start_time = Unix.gettimeofday () diff --git a/irc.mli b/irc.mli index 3def8cb..a1627ae 100644 --- a/irc.mli +++ b/irc.mli @@ -1,3 +1,6 @@ +(** (Nickname, username, hostname) tuple *) +type nuhost = (string * string * string) + val name : string ref val version : string val start_time : float diff --git a/tests.ml b/tests.ml index d1b8f6b..d2bf6b8 100644 --- a/tests.ml +++ b/tests.ml @@ -340,7 +340,7 @@ let do_login nick = Recv (":testserver.test 001 " ^ nick ^ " :Welcome to IRC.\r\n"); Recv (":testserver.test 002 " ^ nick ^ " :I am testserver.test Running version " ^ Irc.version ^ "\r\n"); Recv (":testserver.test 003 " ^ nick ^ " :This server was created " ^ (string_of_float Irc.start_time) ^ "\r\n"); - Recv (":testserver.test 004 " ^ nick ^ " :testserver.test 0.1 l t\r\n"); + Recv (":testserver.test 004 " ^ nick ^ " :testserver.test 0.1 l aimnqpsrtklb\r\n"); ] let regression_tests =