-
Notifications
You must be signed in to change notification settings - Fork 1
/
fsirc.fs
51 lines (39 loc) · 1.48 KB
/
fsirc.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
open System
open System.IO
open System.Net
open System.Net.Sockets
Console.WriteLine("server address?")
let server = Console.ReadLine()
Console.WriteLine("Portnum?")
let port = int(Console.ReadLine())
Console.WriteLine("Channel?")
let channel = Console.ReadLine()
Console.WriteLine("nickname?")
let nick = Console.ReadLine()
let cri_client = new TcpClient();
cri_client.Connect( server, port )
let cri_reader = new StreamReader( cri_client.GetStream() )
let cri_writer = new StreamWriter( cri_client.GetStream() )
cri_writer.WriteLine( sprintf "USER %s %s %s %s" nick nick nick nick )
cri_writer.AutoFlush <- true
cri_writer.WriteLine( sprintf "NICK %s" nick )
cri_writer.WriteLine( sprintf "JOIN %s\n" channel )
let cri_ping ( writer : StreamWriter ) (pingmsg : string) =
let pongmsg = pingmsg.[..0] + "O" + pingmsg.[2..] in
writer.WriteLine(pongmsg)
let cri_privmsg ( writer : StreamWriter ) ( phrase : string ) =
writer.WriteLine( sprintf "PRIVMSG %s :%s" channel phrase )
let cri_get_msg ( line : string )=
line.Substring( line.Substring(1).IndexOf(":") + 2)
let cri_work = async {
while( cri_reader.EndOfStream = false ) do
let line = cri_reader.ReadLine()
if line.StartsWith("PING") then
cri_ping cri_writer line
let (msg:string) = cri_get_msg line
Console.WriteLine( line )}
do cri_work |> Async.Start
while true do
let inpmsg = Console.ReadLine()
if inpmsg <> "" then
cri_privmsg cri_writer inpmsg