public override void Incoming( Message mgs ) { if ( UserManager.HasPermission( Permissions.Operator , mgs.MUser ) ) { string line = mgs.Line; if ( line.StartsWith( mgs.MServer.MyNick + ": " , StringComparison.OrdinalIgnoreCase ) ) { line = line.Replace( mgs.MServer.MyNick + ": " , "" ); if ( line.StartsWith( "join " , StringComparison.OrdinalIgnoreCase ) ) { line = line.Replace( "join " , "" ); Reply( line , MessageType.Join ); } else if ( line.Equals( "part" , StringComparison.OrdinalIgnoreCase ) ) { Reply( MessageType.Part ); } else if ( line.StartsWith( "quit " , StringComparison.OrdinalIgnoreCase ) ) { line = line.Replace( "quit" , "" ); line = line.Trim(); Reply( line , MessageType.Quit ); } else if ( line.Equals( "quit" , StringComparison.OrdinalIgnoreCase ) ) { line = "F*CK ALL OF YOU!"; Reply( line , MessageType.Quit ); } } } }
public void MessagesIn() { string line = ""; while ( ( line = Console.ReadLine() ) != null ) { string[] lineparts = line.Split( new char[] { ':' } , 2 ); Message res = new Message(); if ( lineparts.Length > 1 ) { res.Line = lineparts[1]; if ( !lineparts[ 0 ].Contains( "#" ) ) { lineparts[ 0 ] = "#" + lineparts[ 0 ]; } res.MChannel = ( from Channel x in LastMessage.MServer.Channels where x.CFullName.Equals( lineparts[ 0 ] , StringComparison.OrdinalIgnoreCase ) select x ).FirstOrDefault(); LastMessage.MChannel = res.MChannel; } else { res.Line = line; res.MChannel = LastMessage.MChannel; } res.MServer = LastMessage.MServer; res.MUser = LastMessage.MUser; res.MType = MessageType.Message; res.Line = res.Line.Trim(); Reply( res ); } }
public override void Incoming( Message mgs ) { if ( mgs.Line.StartsWith( "!rr3 " ) && mgs.MChannel != null && mgs.MUser != null ) { string l = mgs.Line.Split( new char[] { ' ' } , 2 )[1].Trim(); User target = ( from User u in mgs.MChannel.CUsers where u.Nick.Equals( l , StringComparison.OrdinalIgnoreCase ) select u ).FirstOrDefault(); if ( target == null ) { Reply( "No such user in channel" , MessageType.Message ); } else if ( target.Nick == mgs.MServer.MyNick ) { Reply( "Sorry, I won't play." , MessageType.Message ); } else if ( target == mgs.MUser ) { Reply( "Russian roulette is a 2 person game man, piss of some more people!" , MessageType.Message ); } else { Reply( "*RR* " + mgs.MUser.Nick + " challenged " + target.Nick + " to russian roulette." , MessageType.Message ); rnd = new Random(); int i = 0; while ( i < 6 ) { Thread.Sleep( 500 ); if ( i % 2 == 0 ) { if ( UserGetsKicked( i ) ) { Reply( "*RR* " + mgs.MUser.Nick + " takes the gun : *BANG*" , MessageType.Message ); KickUser( "You're dead." , mgs.MUser , mgs.MChannel ); return; } else { Reply( "*RR* " + mgs.MUser.Nick + " takes the gun : *Click*" , MessageType.Message ); } } else { if ( UserGetsKicked( i ) ) { Reply( "*RR* " + target.Nick + " takes the gun : *BANG*" , MessageType.Message ); KickUser( "You're dead." , target , mgs.MChannel ); return; } else { Reply( "*RR* " + target.Nick + " takes the gun : *Click*" , MessageType.Message ); } } i++; } Reply( "*RR* " + mgs.MUser.Nick + " takes the gun : *BANG*" , MessageType.Message ); KickUser( "You're dead." , mgs.MUser , mgs.MChannel ); } } }
private void MessageReceived( Message mess ) { LastMessage = mess; if ( UserManager.HasPermission( Permissions.Basic , mess.MUser ) ) { Incoming( mess ); } }
public void Receive( Message msg ) { if ( MessageReceived != null) { MessageReceived.Invoke( msg ); } //Console.WriteLine( msg.MServer.Name + " - " + msg.Line ); }
public void Reply( string line , MessageType type ) { Message res = new Message(); res.Line = line; res.MChannel = LastMessage.MChannel; res.MServer = LastMessage.MServer; res.MUser = LastMessage.MUser; res.MType = type; Reply( res ); }
private void KickUser( string message , User us , Channel chan ) { Message msg = new Message(); msg.Line = message; msg.MChannel = chan; msg.MType = MessageType.Kick; msg.MUser = us; msg.MServer = LastMessage.MServer; Reply( msg ); }
public bool Send( Message msg ) { if ( msg.MServer == null || msg.MChannel == null ) { string builtMessage = msg.Line; msg.MServer = new Server(); //return ConnManager.Instance.Send( msg.MServer , builtMessage ); return false; } else if ( msg.MType == MessageType.Message ) { string builtMessage = "PRIVMSG " + msg.MChannel.CFullName + " :" + msg.Line; return ConnManager.Instance.Send( msg.MServer , builtMessage ); } else if ( msg.MType == MessageType.Action ) { string builtMessage = "PRIVMSG " + msg.MChannel.CFullName + " :" + "\u0001" + "ACTION " + msg.Line + "\u0001"; return ConnManager.Instance.Send( msg.MServer , builtMessage ); } else if ( msg.MType == MessageType.Join ) { string builtMessage = "JOIN " + msg.Line; Channel c = new Channel(); c.CFullName = msg.Line; c.CName = msg.Line.Replace( "#" , "" ); c.CServer = msg.MServer; msg.MServer.Channels.Add( c ); return ConnManager.Instance.Send( msg.MServer , builtMessage ); } else if ( msg.MType == MessageType.Part ) { string builtMessage = "PART " + msg.MChannel.CFullName; msg.MServer.Channels.Remove( msg.MChannel ); return ConnManager.Instance.Send( msg.MServer , builtMessage ); } else if ( msg.MType == MessageType.Quit ) { string builtMessage = "QUIT :" + msg.Line; //ConnManager.Instance.Sockets.Remove( msg.MServer ); return ConnManager.Instance.Send( msg.MServer , builtMessage ); } else if ( msg.MType == MessageType.Kick ) { string builtMessage = "KICK " + msg.MChannel.CFullName + " " + msg.MUser.Nick + " :" + msg.Line; return ConnManager.Instance.Send( msg.MServer , builtMessage ); } else return false; }
public override void Incoming( Message mgs ) { if ( mgs.MChannel != null && mgs.MUser != null ) { Console.WriteLine( mgs.MType + ": (" + mgs.MServer.Name + " - " + mgs.MChannel.CFullName + ") " + mgs.Time.TimeOfDay + " <" + mgs.MUser.Nick + "> " + mgs.Line ); } else if ( !String.IsNullOrEmpty( mgs.Line ) ) { Console.WriteLine( mgs.MType + ": (" + mgs.MServer.Name + ") " + mgs.Time.TimeOfDay + ":" + mgs.Line ); } else { Console.WriteLine( mgs.MType + ": (" + mgs.MServer.Name + ") " + mgs.Time.TimeOfDay + " " + mgs.RawLine ); } }
public override void Incoming( Message mgs ) { if ( mgs.Line.Equals( "!d" ) ) { Reply( "DIRECTED BY M. NIGHT SHYAMALAN" , MessageType.Message ); } if ( mgs.Line.Equals( "botsnack" , StringComparison.OrdinalIgnoreCase ) ) { Reply( ":D" ); } else if ( mgs.Line.Equals( "relixsnack" , StringComparison.OrdinalIgnoreCase ) ) { Reply( ":DG<" ); } }
public override void Incoming( Message mgs ) { if ( mgs.MUser != null ) { if ( tells.ContainsKey( mgs.MUser.Nick ) ) { foreach ( string s in tells[ mgs.MUser.Nick ] ) { Reply( mgs.MUser.Nick + ": " + s , MessageType.Message ); } tells.Remove( mgs.MUser.Nick ); WriteTells(); } if ( mgs.Line.StartsWith( "!ytell " , StringComparison.OrdinalIgnoreCase ) ) { string[] lineparts = mgs.Line.Split( new char[] { ' ' } , 3 ); if ( lineparts.Length == 3 ) { if ( tells.ContainsKey( lineparts[ 1 ] ) ) { if ( tells[ lineparts[ 1 ] ].Count < 10 ) { tells[ lineparts[ 1 ] ].Add( mgs.Time.Hour + ":" + mgs.Time.Minute + " <" + mgs.MUser.Nick + "> " + lineparts[ 2 ] ); Reply( "I'll pass that on when " + lineparts[ 1 ] + " is around." , MessageType.Message ); } else { Reply( "Sorry, there are already too much messages in the queue for " + lineparts[ 1 ] + "." , MessageType.Message ); } } else { tells[ lineparts[ 1 ] ] = new List<string>(); tells[ lineparts[ 1 ] ].Add( mgs.Time.Hour + ":" + mgs.Time.Minute + " <" + mgs.MUser.Nick + "> " + lineparts[ 2 ] ); Reply( "I'll pass that on when " + lineparts[ 1 ] + " is around." , MessageType.Message ); } WriteTells(); } } } }
private void ProcessPart( Message newMessage , string left ) { string[] leftparts = left.Split( new char[] { ' ' } ); newMessage.MChannel = ( from Channel x in newMessage.MServer.Channels where x.CFullName.Equals( leftparts[ 2 ] , StringComparison.OrdinalIgnoreCase ) select x ).FirstOrDefault(); newMessage.MUser = FindUser( newMessage , leftparts[ 0 ] , false ); if ( newMessage.MChannel.CUsers.Contains( newMessage.MUser ) ) { newMessage.MChannel.CUsers.Remove( newMessage.MUser ); } newMessage.MType = MessageType.Part; }
public bool Send( Message mgs ) { return Pre.Send( mgs ); }
public void Reply( Message message ) { Hub.Instance.Send( message ); }
public abstract void Incoming( Message mgs );
public void Receive( Server server , string msg ) { //:[email protected] PRIVMSG #zeus :3m is ideaal //:[email protected] PART #zeus //:[email protected] JOIN :#zeus //:wina.kelder.be 332 YellingBird #zeus :Zeus WPI | Please don't feed the trolls http://tinyurl.com/33ob4or | Got paint? http://bit.ly/9646nm //:wina.kelder.be 333 YellingBird #zeus Lolcat 1278758838 //:wina.kelder.be 353 YellingBird = #zeus :YellingBird reeeelix kire Rofldawg kidk nudded CIA-1 Chton Tots Frying_ookelvis jaspervdj GilJ Mathiasdm +ddfreyne +polipie @Javache lucas +dolfijn +mrosmosis +MrWhite //:wina.kelder.be 366 YellingBird #zeus :End of /NAMES list. Message newMessage = new Message(); newMessage.Time = DateTime.Now; newMessage.RawLine = msg; msg = msg.TrimStart( ':' ); newMessage.MServer = server; // :[email protected] PRIVMSG #zeus :excellent, time to reverse engineer me some IRC :p string[] messageparts = msg.Split( new char[] { ':' } , 2 ); string left = messageparts[ 0 ]; string right = ""; if ( messageparts.Length > 1 ) { right = messageparts[ 1 ]; } //:[email protected] PRIVMSG #zeus :3m is ideaal if ( left.Contains( "PRIVMSG" ) ) { ProcessPrivMsg( newMessage , left , right ); } //:[email protected] JOIN :#zeus else if ( left.Contains( "JOIN" ) ) { ProcessJoin( newMessage , left , right ); } //:[email protected] PART #zeus else if ( left.Contains( "PART" ) ) { ProcessPart( newMessage , left ); } //:[email protected] QUIT :Quit: Lost terminal else if ( left.Contains( "QUIT" ) ) { ProcessQuit( newMessage , left , right ); } //:wina.kelder.be 332 YellingBird #zeus :Zeus WPI | Please don't feed the trolls http://tinyurl.com/33ob4or | Got paint? http://bit.ly/9646nm else if ( left.Contains( "332" ) ) { ProcessTopic( newMessage , left , right ); } //:wina.kelder.be 353 YellingBird = #zeus :YellingBird reeeelix kire Rofldawg kidk nudded CIA-1 Chton Tots Frying_ookelvis jaspervdj GilJ Mathiasdm +ddfreyne +polipie @Javache lucas +dolfijn +mrosmosis +MrWhite else if ( left.Contains( "353" ) ) { ProcessNickList( newMessage , left , right ); } //:wina.kelder.be 311 YellingBird Chton ~Chton ip-213-49-92-48.dsl.scarlet.be * :bram de buyser else if ( left.Contains( "311" ) ) { ProcessWhois( newMessage , left , right ); } if ( newMessage.Line == null ) { newMessage.Line = ""; } if ( newMessage.MUser == null ) { newMessage.MUser = ( from User y in newMessage.MServer.AllUsers where y.Nick.Equals( newMessage.MServer.MyNick ) select y ).FirstOrDefault(); } CentralHub.Receive( newMessage ); }
private void ProcessWhois( Message newMessage , string left , string right ) { string[] leftparts = left.Split( new char[] { ' ' } ); User result = ( from User y in newMessage.MServer.AllUsers where y.Nick.Equals( leftparts[ 3 ] ) select y ).FirstOrDefault(); if ( result == null ) { result = new User(); result.Nick = leftparts[ 3 ]; result.UServer = newMessage.MServer; newMessage.MServer.AllUsers.Add( result ); } result.Ident = leftparts[ 4 ]; result.HostName = leftparts[ 5 ]; result.RealName = right; }
private void ProcessTopic( Message newMessage , string left , string right ) { string[] leftparts = left.Split( new char[] { ' ' } ); newMessage.MChannel = ( from Channel x in newMessage.MServer.Channels where x.CFullName.Equals( leftparts[ 3 ] , StringComparison.OrdinalIgnoreCase ) select x ).FirstOrDefault(); newMessage.Line = right; newMessage.MChannel.Topic = right; }
private void ProcessQuit( Message newMessage , string left , string right ) { //:[email protected] QUIT :Quit: Lost terminal string[] leftparts = left.Split( new char[] { ' ' } ); newMessage.MUser = FindUser( newMessage , leftparts[ 0 ] , false ); foreach ( Channel chan in newMessage.MServer.Channels ) { if ( chan.CUsers.Contains( newMessage.MUser ) ) { chan.CUsers.Remove( newMessage.MUser ); } chan.CServer.AllUsers.Remove( newMessage.MUser ); } newMessage.MType = MessageType.Quit; newMessage.Line = right; }
private void ProcessNickList( Message newMessage , string left , string right ) { string[] leftparts = left.Split( new char[] { ' ' } ); newMessage.MChannel = ( from Channel x in newMessage.MServer.Channels where x.CFullName.Equals( leftparts[ 4 ] , StringComparison.OrdinalIgnoreCase ) select x ).FirstOrDefault(); BuildUserList( right , newMessage.MServer , newMessage.MChannel ); }
private void ProcessJoin( Message newMessage , string left , string right ) { string[] leftparts = left.Split( new char[] { ' ' } ); newMessage.MChannel = newMessage.MChannel = ( from Channel x in newMessage.MServer.Channels where x.CFullName.Equals( right , StringComparison.OrdinalIgnoreCase ) select x ).FirstOrDefault(); newMessage.MUser = FindUser( newMessage , leftparts[ 0 ] , true ); newMessage.MType = MessageType.Join; }
private User FindUser( Message newMessage , string id , bool addtochannel ) { User result = ( from User y in newMessage.MServer.AllUsers where ( y.Nick + "!" + y.Ident + "@" + y.HostName ).Equals( id , StringComparison.OrdinalIgnoreCase ) select y ).FirstOrDefault(); if ( result == null ) { User newUser = new User(); newUser.Nick = id.Substring( 0 , id.IndexOf( "!" ) ); newUser.Ident = id.Substring( id.IndexOf( "!" ) + 1 , id.IndexOf( "@" ) - id.IndexOf( "!" ) - 1 ); newUser.HostName = id.Substring( id.IndexOf( "@" ) + 1 , id.Length - id.IndexOf( "@" ) - 1 ); newUser.UServer = newMessage.MServer; newMessage.MServer.AllUsers.Add( newUser ); result = newUser; } if ( addtochannel && !newMessage.MChannel.CUsers.Contains( result ) ) { newMessage.MChannel.CUsers.Add( result ); } return result; }
private void ProcessPrivMsg( Message newMessage , string left , string right ) { left = left.Trim(); string[] leftparts = left.Split( ' ' ); if ( leftparts.Length == 3 ) { newMessage.MType = MessageType.Message; newMessage.MChannel = ( from Channel x in newMessage.MServer.Channels where x.CFullName.Equals( leftparts[ 2 ] , StringComparison.OrdinalIgnoreCase ) select x ).FirstOrDefault(); newMessage.MUser = FindUser( newMessage , leftparts[ 0 ] , true ); if ( right.StartsWith( "\u0001" + "ACTION" ) ) { right = right.Replace( "\u0001" + "ACTION" , "" ); right = right.Replace( "\u0001" , "" ); right = right.Trim(); newMessage.MType = MessageType.Action; } newMessage.Line = right; if ( newMessage.MChannel != null && newMessage.Line == null ) { newMessage.Line = ""; } } }
public override void Incoming( Message mgs ) { string line = mgs.Line; if ( line.StartsWith( "!b " ) || (mgs.MType == MessageType.Action && line.StartsWith("googles ", StringComparison.OrdinalIgnoreCase))) { line = line.Replace( "!b " , "" ); if ( mgs.MType == MessageType.Action && line.StartsWith( "googles " , StringComparison.OrdinalIgnoreCase ) ) { line = line.Replace( "googles ", "" ); } SearchRequest sr = new SearchRequest(); sr.AppId = "msappidhere"; sr.Query = line; sr.Sources = new SourceType[] { SourceType.Web }; SearchResponse resp = lss.Search( sr ); if ( resp.Web.Results != null && resp.Web.Results.Length > 0 ) { WebResult result = resp.Web.Results.FirstOrDefault(); if ( result != null ) { if ( mgs.MType == MessageType.Action ) { Reply( "googled that for you: " + result.Title + " || " + result.Url ); } else { Reply( "Your result: " + result.Title + " || " + result.Url ); } } } else { if ( mgs.MType == MessageType.Action ) { Reply( "couldn't find that." ); } else { Reply( "No results found!" ); } } } if ( line.StartsWith( "!v " ) ) { line = line.Replace( "!v " , "" ); SearchRequest sr = new SearchRequest(); sr.AppId = "msappidhere"; sr.Query = line; sr.Sources = new SourceType[] { SourceType.Video }; SearchResponse resp = lss.Search( sr ); if ( resp.Video.Results != null && resp.Video.Results.Length > 0 ) { VideoResult result = resp.Video.Results.FirstOrDefault(); if ( result != null ) { Reply("Your video: " + result.Title + " || " + result.PlayUrl); } } else { Reply("No videos found!"); } } if ( line.StartsWith( "!i " ) ) { line = line.Replace( "!i " , "" ); SearchRequest sr = new SearchRequest(); sr.AppId = "msappidhere"; sr.Query = line; sr.Sources = new SourceType[] { SourceType.Image }; SearchResponse resp = lss.Search( sr ); if ( resp.Image.Results != null && resp.Image.Results.Length > 0 ) { ImageResult result = resp.Image.Results.FirstOrDefault(); if ( result != null ) { Reply("Your image: " + result.Title + " || " + result.MediaUrl); } } else { Reply("No images found!"); } } }