public IrcChannel(IrcServer server) { Users = new List<IIrcUser>(); Mode = new IrcChannelMode(this); Created = DateTime.Now; IrcServer = server; }
public IrcChannel(IrcServer server) { Users = new List <IIrcUser>(); Mode = new IrcChannelMode(this); Created = DateTime.Now; IrcServer = server; }
static void Main(string[] args) { Console.Title = "IRC# Server"; Server = new IrcServer(); Config = new ServerConfig(); Config.Load(); Server.Hostname = Config.Host; for (int i = 0; i < Config.Ports.Length; i++) { int index = i; Thread thread = new Thread(() => Listen(index)) { IsBackground = true }; thread.Start(); } IrcServer.Logger.Log(LogLevel.Info, "Press ESC to exit."); while (Console.ReadKey().Key != ConsoleKey.Escape) { ; } }
static void Main(string[] args) { Console.Title = "IRC# Server"; Server = new IrcServer(); Config = new ServerConfig(); Config.Load(); Server.Hostname = Config.Host; for (int i = 0; i < Config.Ports.Length; i++) { int index = i; Thread thread = new Thread(() => Listen(index)) { IsBackground = true }; thread.Start(); } IrcServer.Logger.Log(LogLevel.Info, "Press ESC to exit."); while (Console.ReadKey().Key != ConsoleKey.Escape) ; }
public void Read() { while (true) { IrcMessage message; try { message = Stream.ReadMessage(); } catch (Exception) { IrcServer.UserLeft(this, "connection reset by peer"); Socket.Close(); return; } Idle = DateTime.Now; if (message.Command == null) { continue; } string line = message.ToString(); IrcCommand command = IrcCommand.Find(message.Command); if (command == null) { Console.WriteLine(line); continue; } if (command.RequireRegistered && !Mode.IsRegistered) { Write(new IrcNumericResponce { NumericId = IrcNumericResponceId.ERR_NOTREGISTERED, Message = "You're not registered.", Extra = command.Name.ToUpper() }); } command.Run(this, message); } }
static void Main(string[] args) { Console.Title = "IRC# Server"; Server = new IrcServer(); Config = new ServerConfig(); string TLS_string = "--tls"; foreach (string argument in args) { if (argument == TLS_string) { IrcServer.Logger.Log(LogLevel.Info, $"--tls detected"); Config.TLS = true; break; } else { IrcServer.Logger.Log(LogLevel.Info, $"No TLS"); Config.TLS = false; } } Config.Load(); Server.Hostname = Config.Host; for (int i = 0; i < Config.Ports.Length; i++) { int index = i; Thread thread = new Thread(() => Listen(index)) { IsBackground = true }; thread.Start(); } IrcServer.Logger.Log(LogLevel.Info, "Press ESC to exit."); while (Console.ReadKey().Key != ConsoleKey.Escape) { ; } }
public void OnConnect() { Stream = new IrcStream(Socket) { AutoFlush = true }; Channels = new List <IrcChannel>(); Mode = new IrcUserMode(); ChannelModes = new Dictionary <IrcChannel, IrcChannelUserMode>(); Idle = DateTime.Now; IrcServer.NewClient(this); Write(new IrcMessage() { Prefix = IrcServer.Hostname, Command = "NOTICE", Params = "AUTH,***Looking up your hostname.".Split(',') }); Task.Factory.StartNew(() => { System.Net.IPHostEntry ip = System.Net.Dns.GetHostEntry(((IPEndPoint)Socket.RemoteEndPoint).Address); Host = ip.HostName; Write(new IrcMessage() { Prefix = IrcServer.Hostname, Command = "NOTICE", Params = "AUTH,***Found your hostname.".Split(',') }); }); Task.Factory.StartNew(() => { Write(new IrcMessage() { Prefix = IrcServer.Hostname, Command = "NOTICE", Params = "AUTH,***CHECKING IDENT".Split(',') }); try { TcpClient tcp = new TcpClient(); tcp.Connect(new IPEndPoint(((IPEndPoint)Socket.RemoteEndPoint).Address, 113)); var writer = new StreamWriter(tcp.GetStream()); var reader = new StreamReader(tcp.GetStream()); writer.WriteLine("{0}, {1}", ((IPEndPoint)Socket.RemoteEndPoint).Port, 6667); writer.Flush(); if (reader.ReadLine().Contains("USERID")) { Write(new IrcMessage() { Prefix = IrcServer.Hostname, Command = "NOTICE", Params = "AUTH,***IDENT SUCCESSFUL".Split(',') }); } } catch { Write(new IrcMessage() { Prefix = IrcServer.Hostname, Command = "NOTICE", Params = "AUTH,***IDENT FAILED. CONTINUE.".Split(',') }); } }); _network = new Thread(Read) { IsBackground = true }; _network.Start(); }
public void Quit(string reason) { _network.Join(); Socket.Close(); IrcServer.UserLeft(this, reason); }