public SimpleUser(IRCConnection uplink) { if (uplink == null) throw new ArgumentNullException(); this._upLink = uplink; }
/* * m_restart: */ private void m_restart(IRCConnection src, string[] ar) { if (!this.IsUser(src) || !((IRCUserConnection)src).UserMode.HasMode(IRCUserModes.MODE_OP)) { // :Permission Denied- You're not an IRC operator src.SendCommand(ReplyCodes.ERR_NOPRIVILEGES, ((IRCUserConnection)src).NickName, ":Permission Denied- You're not an IRC operator"); return; } // Close all links foreach (IRCConnection con in this.Clients) { if (this.IsServer(con)) { con.SendCommand(((IRCUserConnection)src).SimpleUser, "ERROR", ":Restarted by " + src); this.CloseLink(con); } else if (this.IsUser(con)) { ((IRCUserConnection)con).Notice("Server Restarting. " + src); this.CloseLink(con, "Server Restarting"); } else { this.CloseLink(con, "Server Restarting"); } } Logger.LogMsg("RESTART by " + src); MainClass.Restart(); }
/* public virtual void m_stat(IConnection connection, string[] ar) { Console.WriteLine("==============================="); Console.WriteLine("= Server State:"); Console.WriteLine("= TotalMemory: {0} bytes", GC.GetTotalMemory(true)); Console.WriteLine("= Clients: {0}", this.Clients.Count); Console.WriteLine("= Errors: {0}", stat.errors); Console.WriteLine("= Traffic: {0} bytes", stat.traffic); Console.WriteLine("= Threads: {0}",0); Console.WriteLine("==============================="); } */ public virtual void m_stat(IRCConnection connection, string[] ar) { #if false IRCConnection src = (IRCConnection)connection; if (true)//src.UserMode.get('D')) // only for testing { if (ServiceManager.Services.HasService(typeof(Statistic))) { Statistic service = ((Statistic)ServiceManager.Services[typeof(Statistic)]); src.Notice("server", this.ServerName + " stats: uptime=" + service.UpTime + "; Clients=" + this.Clients.Count + "; Traffic=" + stat.traffic +/* TODO: stat durch Statistic ersetzen */ " bytes ; Threads=" + service.Threads + "; TotalMemory in use=" + GC.GetTotalMemory(true) + " bytes ; Errors=" + stat.errors); } else src.Notice("server", "Stats not Available."); } else { src.Notice("server", "Permission denied, you have no D-umode"); } #endif }
/* pass-msg: pass-msg: pass pass-msg: password pass-msg: 0211000001 pass-msg: IRC|aEFJKMRTu pass-msg: P */ public virtual void m_pass(IRCConnection connection, string[] ar) { // TODO: pass ist auch vom clienten möglich! Console.WriteLine(this + ": pass message"); foreach (string s in ar) { Console.WriteLine("pass-msg: " +s); } if ((!(connection.GetType() == typeof(IRCConnection))) || ((IRCConnection)connection).PassSet) { connection.SendLine("ERROR: ERR_ALREADYREGISTRED");//connection.CloseLink(); // TO/DO: CloseLink soll RemoveConnetion in der Server-Klasse ersetzen/erweitern; RemoveConnation bleibt bestehen ruft aber nicht mehr connection.Dispose auf. return; } if (ar.Length < 3) { connection.SendLine("ERROR: ERR_NEEDMOREPARAMS"); return; } if (false) // wenn passwort falsch { connection.SendLine("ERROR: Wrong Password, clossing link ..."); this.CloseLink(connection); // CloseLink() kümmert sich um alles return; } ((IRCConnection)connection).PassSet = true; if (ar.Length > 3) { // TODO: TS-Server ; } }
private void m_resp(IRCConnection connection, string[] par) { #if false Console.WriteLine(this + ": resp message"); IRCConnection src = (IRCConnection)connection; if (src.IsPerson()) { if (src.IsServer()) { throw new Exception("is a hacked server"); } else { src.SendLine(":ERROR");//Command("error"); } } // if (this.HasServer(src.HostName)) // { // src.SendLine(":ERROR");//Command("error"); // } // todo: nur ein beispiel!; läuft auch nur in meinen netz!!! //send_capabilities // SERVER test.oulu.fi 1 1 src.SendLine("SERVER 192.168.2.5 1 1"); #endif }
private void m_privmsg(IRCConnection connection, string[] par) { Console.WriteLine("TODO privmsg"); IRCConnection src = (IRCConnection)connection; //#if false par[2] = par[2].ToLower(); if (par.Length == 4) { // channel prefixes if (par[2][0] == '#') { // Channel ch = ((IRCConnection)connection).GetChannel(par[2]); Channel ch = this.GetChannel(par[2]); if (ch != null) ch.SendChat(src, ((SimpleUser)src.SimpleClient), par[3]); } else { if (connection is IRCUserConnection) { IRCUserConnection irccon = connection as IRCUserConnection; if (this.HasNick(par[2])) { this.SendTo(":" + irccon.NickName + "!" + irccon.UserName + "@" + irccon.HostName + " " + "PRIVMSG " + par[2] + " " + par[3], par[2]); } } } } //#endif }
/* * m_user: * ar[0] = prefix * ar[1] = command * ar[2] = username * ar[3] = user modes * ar[4] = unused * ar[5] = real name */ public virtual void m_user(IRCConnection src, string[] ar) { if (this.IsUser(src)) { if (((IRCUserConnection)src).IsRegistered()) { src.SendCommand(ReplyCodes.ERR_ALREADYREGISTRED, ":Unauthorized command (already registered)"); return; } } if (!(src.SimpleClient is SimpleUser)) { src.SendCommand("ERROR", ":Internal error"); this.CloseLink(src); return; } if (!RFC2812.IsValidUserName(ar[2])) { return; // ignore message } if (ar.Length > 5) { src.SetUser(ar[2], ar[3], ar[4], ar[5]); Logger.LogMsg("Got valid USER command from " + src); if (((SimpleUser)src.SimpleClient).NickName != string.Empty) this.RegisterUser(src); } else { // <command> :Not enough parameters src.SendCommand(ReplyCodes.ERR_NEEDMOREPARAMS, ar[1], ":Not enough parameters"); } }
/* alte version private void m_nick(IConnection connection, string[] par) { if (connection.GetType().Equals(typeof(IRCConnection))) { if (RFC2812.IsValidNick(par[1])) { if (par.Length == 2) { ((IRCConnection)connection).SetNick(par[1]); } else { } } else { connection.Send(""); } } } */ private void m_nick(IRCConnection connection, string[] par) { if (connection is IRCServerConnection) // server teilt uns mit das ein user seinen nick geändert hat { throw new NotImplementedException("remote nick message; TODO: IMPLEMENT"); return; } else { if (connection is IRCConnection) { IRCConnection src = (IRCConnection)connection; if (src.SimpleClient == null) { src.SimpleClient = new SimpleUser(src); } else { if (!(src.SimpleClient is SimpleUser)) { src.SendLine("ERROR :Illegal nick usage"); this.CloseLink(src); return; } } } /* IRCUserConnection usr; if (connection is IRCConnection) { IRCConnection src = (IRCConnection)connection; this.RemoveConnection(src); usr = new IRCUserConnection(src); this.AddConnection(usr); } else usr = (IRCUserConnection)connection; */ IRCConnection usr = (IRCConnection)connection; if (par.Length == 3) { if (par[0] == String.Empty) { if (RFC2812.IsValidNick(par[1])) { usr.SetNick(par[2]); } else { usr.SendLine("ERROR :kein gültiger nick!"); } } else { usr.SendLine("ERROR :du bist kein server!"); } } } }
public virtual void m_error(IRCConnection connection, string[] ar) { string msg = string.Empty; if (ar.Length > 1) msg = ar[2]; Logger.LogMsg("ERROR from ", Convert.ToString(connection.ID), msg); }
private void m_id(IRCConnection connection, string[] par) { Console.WriteLine(this + ": TODO id message"); #if false IRCConnection src = (IRCConnection)connection; src.Notice(src.NickName, "your id is " + src.ID); #endif }
private void m_chall(IRCConnection connection, string[] par) { Console.WriteLine(this + ": chall message; TODO"); foreach (string s in par) { Console.WriteLine("chall: " +s); } #if DEC if (!(connection is IRCConnection)) { // TODO: CloseLink() return; } IRCConnection src = (IRCConnection)connection; if (src.IsPerson()) { if (src.IsServer()) { throw new Exception("is a hacked server"); } else { src.SendLine(":ERROR unknown command"); this.send_ops_flag(); } } if (src.IsServer() || src.IsPerson()) // wenn wir das bereits wissen sollten wir kein CHALL bekommen return; if (!this.EqualHosts(src.RealHostName, this.ServerName)) { src.SendLine("ERROR :I am " + this.ServerName + " not " + src.RealHostName); //this.SendToOps(UMODE_SERVCONNECT) this.CloseLink(src, "Sorry"); return; } if (this.HasServer(src.HostName)) { src.SendLine("ERROR :Server " + src.RealHostName + "already exists"); if (src.UserMode.get(IRCUserModes.CAP_SERVICES)) this.send_ops_flag(); this.CloseLink(src, "Server already exists"); return; } // sample: src.SendLine("CHALL 192.168.2.5 localhost. " + par[4] + " password :TS"); #endif }
/* orginal m_join public virtual void m_join(IConnection connection, string[] par) { if (par.Length == 2) { if (par[1].Length > 1) // BUFIX emule "#" -channel this.Join(connection as IRCConnection, par[1]); } } */ private void m_join(IRCConnection connection, string[] par) { Console.WriteLine("TO/DO: join command"); if (connection is IRCUserConnection) { // TODO: if (RFC2812.IsJoinCommand); if (par.Length == 3) { if (par[1].Length > 2) // TODO: regex this.Join((IRCUserConnection)connection, par[2]); } } else connection.SendLine("ERROR: type !IRCUserConnection"); }
//old private SimpleServer _info; public IRCServerConnection(IRCConnection bas, SimpleServer ser) : base(bas.Socket, bas.Server) { if (ser == null) throw new ArgumentNullException("ser"); // this._info = ser; // ser.UpLink = this; // if (!(bas.SimpleClient is SimpleServer)) // throw new ArgumentException("bas.SimpleClient musst be a SimpeServer"); // this._simpleClient = bas.SimpleClient; this._simpleClient = ser; this.SimpleServer.UpLink = this; }
/* * m_rehash: */ public virtual void m_rehash(IRCConnection src, string[] ar) { if (!this.IsUser(src) || !((IRCUserConnection)src).UserMode.HasMode(IRCUserModes.MODE_OP)) { src.SendCommand(ReplyCodes.ERR_NOPRIVILEGES, ((IRCUserConnection)src).NickName, ":Permission Denied- You're not an IRC operator"); return; } Logger.LogMsg("REHASH command from " + src); SettingsHost settingsHost = ((SettingsHost)ServiceManager.Services[typeof(SettingsHost)]); // <config file> :Rehashing src.SendCommand(ReplyCodes.ERR_NOPRIVILEGES, ((IRCUserConnection)src).NickName, settingsHost.ConfigFile, ":Rehashing"); // Rehash settingsHost.Reload(); }
private void m_ping(IRCConnection connection, string[] par) { // :amd.tux PONG amd.tux :506855393 if (par.Length < 2) { connection.SendLine(":ERROR ERR_NOORIGIN"); return; } string name = ((SettingsHost)ServiceManager.Services[typeof(SettingsHost)]).Settings.ServerName; if (par.Length == 4) connection.SendLine(":"+name+" PONG " + par[3] + " :"+par[2]); else connection.SendLine(":"+name+" PONG " + name + " :"+par[2]); ((IRCConnection)connection).LastPing = DateTime.Now; // reset timer }
private DateTime _lastping; // todo #endregion Fields #region Constructors public IRCUserConnection(IRCConnection bas) : base(bas.Socket, bas.Server) { Socket handler = bas.Socket; this._channels = new Hashtable(); if (!(bas.SimpleClient is SimpleUser)) throw new ArgumentException("bas.SimpleClient musst be a SimpleUser"); this._simpleClient = bas.SimpleClient; this.SimpleUser.UpLink = this; // Host data this._realhostName = bas.RealHostName; this._aliases = bas.Aliases; this._address = bas.Address; this.SetNick(this.SimpleUser.NickName); this.SetUser(this.SimpleUser.UserName, this.SimpleUser.HostName, "", this.SimpleUser.RealName); }
// :example.irc.org 353 blackdragon = #d :blackdragon // :example.irc.org 366 blackdragon #d :End of NAMES list. // :example.irc.org 324 blackdragon #d + private void m_mode(IRCConnection connection, string[] par) { //ar[0] = //ar[1] = mode //ar[2] = #test if (connection.GetType() != typeof(IRCUserConnection)) { // ERR return; } IRCUserConnection src = (IRCUserConnection)connection; src.SendCommand(ReplyCodes.RPL_CHANNELMODEIS, src.NickName, par[2], "+"); // TODO: ":" weglassen /* IRCConnection src = (IRCConnection)connection; foreach (string l in par) { Console.WriteLine(l); } Console.WriteLine("Umodes for "+src.ID+": "+src.UserMode); */ }
public void RegisterServer(IRCConnection con, SimpleServer ser) { if (con == null) throw new ArgumentNullException("con"); if (ser == null) throw new ArgumentNullException("ser"); // TODO: ircservice mitteilen das zu diesem server keine verbindung mehr hergestellt werden muss lock (con) { if (con is IRCConnection) { IRCServerConnection srv; this.RemoveConnection(con); srv = new IRCServerConnection(con, ser); this.AddConnection(srv); // TODO: mal sehen evtl. simpleserver erzeugen und mit AddServer hinzufügen this.AddServer(ser); IRCServerConnection.SendServer(srv); } else { con.SendLine("ERROR: you could not register!; internal error"); } } }
public virtual void m_who(IRCConnection connection, string[] ar) { // 0 == prefix // 1 == mask // 2 == z.B nur ops anzeigen if (this.IsServer(connection)) { throw new NotImplementedException("remote /who"); } else if (!this.IsUser(connection)) { // ERR connection.SendLine("ERROR :Not registered"); return; } if (ar.Length > 3) // zuviel parameter { connection.SendLine("ERROR :To much parameters"); return; } Channel chan = null; bool onlyops = false; IRCUserConnection src = (IRCUserConnection)connection; if (ar.Length == 3) { // only ops if (ar[2] == "o") onlyops = true; // else // connection.SendLine("ERR_NEEDMOREPARAMS_MSG"); } if (ar.Length >= 2) { // TO/DO: Search Channel chan = GetChannel(ar[2]); // TODO: rfc if (chan != null) { chan.SendWho(src, onlyops); //src.SendCommand(ReplyCodes.RPL_ENDOFWHO, src.NickName, chan.Name, "End of /WHO list."); // jetzt in IRCChannel return; } } foreach (IRCConnection client in this.Clients) { throw new NotImplementedException(); } if (ar.Length == 1) { //return "*" } else { //return ar[1] } }
public static string SendPass(IRCConnection cn, string /*password*/moresecretpassword) { // erros reply: ERR_NEEDMOREPARAMS ERR_ALREADYREGISTRED // cn.SendCommand(MessageType. return "PASS" + moresecretpassword + "0210010000 IRC|aBgH$ Z"; }
/// <summary> /// Check if "con" is a IRCUserConnection-object /// </smmary> public bool IsUser(IRCConnection con) { return (con.GetType() == typeof(IRCUserConnection)); }
public virtual void CloseLink(IRCConnection con, string message) { throw new NotImplementedException(); this.CloseLink(con); }
public override void AddConnection(Socket client) { Debug.WriteLine(this + ".AddConnection from socket"); Debug.WriteLine(this + ": Accept connection from: " + client.RemoteEndPoint.ToString()); // new //canconnect(client); //TODO schauen ob ein bann // lock (base.Clients) { IRCConnection connection = new IRCConnection(client, this);//neu, true); connection.LookupHostName(); Console.WriteLine("End Accept"); base.AddID(connection.ID); // wichtig! // OnConnected base.Clients.Add(connection); } }
#if false // TODO: msg senden // entfernen public virtual void RemoveConnection(IRCConnection connection, string msg) {
} protected override void AcceptCallback(IAsyncResult ar) { ///todo: base.AcceptCallback() ausführen AcceptObject obj = ((AcceptObject)ar.AsyncState); obj.allDone.Set(); Socket handler = obj.listener.EndAccept(ar); Console.WriteLine("Accept connection from: " + handler.RemoteEndPoint.ToString()); lock (base.Clients) { IRCConnection connection = new IRCConnection(handler, this);//neu, true); Console.WriteLine("End Accept"); base.AddID(connection.ID); // wichtig! // OnConnected base.Clients.Add(connection); // sample for exexute //connection.Execute("join #test"); } ///
public virtual void CloseLink(IRCConnection con) { this.RemoveConnection(con); con.Dispose(); }
// TODO: SendCommand anpassen /* ERR_NEEDMOREPARAMS ERR_NOSUCHCHANNEL ERR_NOTONCHANNEL */ private void m_part(IRCConnection src, string[] ar) { SimpleUser usr = null; // TODO if (this.IsServer(src)) { throw new NotImplementedException("remote /part"); //usr = this.Search(ar[0]); // TODO if (usr == null) { return; } } else if (!this.IsUser(src)) { // ERR src.SendLine("ERROR"); return; } else { usr = (SimpleUser)src.SimpleClient; } #if false if (ar.Length > 4) // zuviel parameter { src.SendLine("to much parameters"); return; } #endif if (ar.Length < 3) { // <command> :Not enough parameters src.SendCommand(ReplyCodes.ERR_NEEDMOREPARAMS, usr.NickName, ar[1], ":Not enough parameters"); return; } Channel chan; string msg = string.Empty; if (ar.Length > 3) msg = ar[3]; else msg = usr.NickName; string[] chans = ar[2].Split(new char[',']); foreach (string schan in chans) { chan = this.GetChannel(schan); if (chan == null) { // <channel name> :No such channel src.SendCommand(ReplyCodes.ERR_NOSUCHCHANNEL, usr.NickName, chan.Name, ":No such channel"); continue; } else if (!chan.HasUser(usr)) { // <channel> :You're not on that channel src.SendCommand(ReplyCodes.ERR_NOTONCHANNEL, usr.NickName, chan.Name, ":You're not on that channel"); continue; } this.Part(usr, chan, msg); } }
// TODO: nach IRCConnection verschieben und den RemoveConnection call entfernen. /// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="msg"></param> public void Quit(IRCConnection client, string msg) { lock (client) { client.Send(":" + client.RealHostName/*.NickName*/ + "[email protected]" + "@" + "Hostname" + "QUIT :quitter\n\n"); this.CloseLink(client); } }
private void m_notice(IRCConnection src, string[] par) { System.Console.WriteLine("NOTICE dummy"); if (par[1] == "AUTH") return; // eine AUTH Zeile; ensteht dadurch das storm-ircd einen verbingung zu einen anderen server herstellt -> ignorieren }
public void RegisterUser(IRCConnection con) { if (con == null) throw new ArgumentNullException("con"); lock (con) { if (con is IRCConnection) { IRCUserConnection usr; this.RemoveConnection(con); usr = new IRCUserConnection(con); this.AddConnection(usr); // TODO: if (this.IsFull) // TODO: this.AddUser(usr.SimpleUser); // send bounce 005 } else { con.SendLine("ERROR :You could not register! Internal error"); } } }