im currently trying to make a simple IRC Gui Client. Im using the SmartIrc4net as a base, as it seems to be the most supportive out of all of them, found here: http://www.codeproject.com/Articles/8323/SmartIrc4net-the-C-IRC-library
Now What I am having problem with is the action commands. For example to make yourself an oper, you would type
/oper admin password or to changehost, would be /sethost mynewhost
My problem is that when I pass that value through a TextBox, instead of making me admin, or changing my host. My input just gets displayed as text in the chat.
Here is my code:
string[] serverlist;
serverlist = new string[] { "mydomain.com" };
int port = 6667;
string channel = "#MyChannel#";
try
{
irc.Connect(serverlist, port);
irc.Login("SmartIRC", "SmartIrc4net Test Bot");
irc.RfcJoin(channel);
irc.SendMessage(SendType.Message, channel, "/oper admin mypass");
irc.SendMessage(SendType.Action, channel, "/sethost mynewhost");
irc.Listen();
But when I pass those values, all it does is just display what I typed in the chat, without actually making me oper, or changing my sethost.
Is there anyway that I could actually make it pass commands through to the IRC server, instead of just displaying the raw text on the chat?
Any help would be appreciated, Thanks
This is because you are explicitly sending a message. IRC itself has no notion of /commands, this is done all in the client. What you are doing is to just send a message with a specific text that happens to start with /. I.e. what the server receives is
PRIVMSG #channel :/oper admin mypass
instead of
OPER admin mypass
You just need to figure out a way of sending raw IRC commands to the server. The page you linked to doesn't offer much documentation on that part, though. But judging from the layers this should be in either Layer 2 or Layer 1.
There is a lot of more options then SendMessages.
You have example irc.RfcOper(username, pasword) for Oper.
If you want to send raw data command for things it does not support on the fly example sethost you can just send a WriteLine directly.
irc.WriteLine("sethost mynewhost")
Open the IrcCommands.cs to see a list of commands and Rfc2812.cs to see how they are transfered.
I however recommend you to read or at least peek at Rfc2812 standard that you can find here https://www.rfc-editor.org/rfc/rfc2812
Related
I've searched without much success to the simplest (and yet working) example of an LDAP/AD Server for C#. Many libraries exist to connect to LDAP servers, but not the LDAP Server by itself (on C#).
I found however some information about it and even a post requesting a simple LDAP server that was answered "LDAP isn't simple"; and yet i read a lot of the RFC4511 and this sample code at GitHub Flexinet LDAP Server, but unfortunatly i don't have yet the knowledge to complete it's code.
My goal is not to make a fully functional LDAP server, but one that can at least do:
Serve as a login pool for softwares that allow it's users to be
registered and log on a AD/LDAP server (just check for login and
password for authentication).
Allow softwares like Outlook and Thunderbird to get a list of users (without passwords) with first and last name, e-mail address, phone number and department for contact list model.
No delete, add (or create), move, and other
functions are required since the main software that i aim to
integrate it with will do all the user and group management.
UPDATE
I'm trying to implement the Flexinet sample and adjust to that functionalities; as form of a question what should i do to change this function to prevent it from causing an exception (on the "var filter = searchRequest.ChildAttributes[6];" line it always breaks) when i call from a LDAP client software:
private void HandleSearchRequest(NetworkStream stream, LdapPacket requestPacket)
{
var searchRequest = requestPacket.ChildAttributes.SingleOrDefault(o => o.LdapOperation == LdapOperation.SearchRequest);
var filter = searchRequest.ChildAttributes[6];
if ((LdapFilterChoice)filter.ContextType == LdapFilterChoice.equalityMatch && filter.ChildAttributes[0].GetValue<String>() == "sAMAccountName" && filter.ChildAttributes[1].GetValue<String>() == "testuser") // equalityMatch
{
var responseEntryPacket = new LdapPacket(requestPacket.MessageId);
var searchResultEntry = new LdapAttribute(LdapOperation.SearchResultEntry);
searchResultEntry.ChildAttributes.Add(new LdapAttribute(UniversalDataType.OctetString, "cn=testuser,cn=Users,dc=dev,dc=company,dc=com"));
searchResultEntry.ChildAttributes.Add(new LdapAttribute(UniversalDataType.Sequence));
responseEntryPacket.ChildAttributes.Add(searchResultEntry);
var responsEntryBytes = responseEntryPacket.GetBytes();
stream.Write(responsEntryBytes, 0, responsEntryBytes.Length);
}
var responseDonePacket = new LdapPacket(requestPacket.MessageId);
responseDonePacket.ChildAttributes.Add(new LdapResultAttribute(LdapOperation.SearchResultDone, LdapResult.success));
var responseDoneBytes = responseDonePacket.GetBytes();
stream.Write(responseDoneBytes, 0, responseDoneBytes.Length);
}
The code is on the github link.
Finally i made a fork of the Flexinet LDAP Server on #Sammuel-Miranda/LdapServerLib and with the author's support and some changes and adaptations i completed this implementation. It responds to the bind and search calls and works perfectly for Outlook and Thunderbird to use as a shared address book.
I did not implemente however any ADD/MODIFY/DELETE request (but would not be hard to do) since i don't need then.
I found on the RFC4511 the explanation on how the search works ... and i'm "kind" of understanding it, not very well - and i see that the method implemented on the GitHub from Flexinet LDAP Server only answer to bind and search requests of one single user (since it's only a example implementation).
The client is requesting diferent calls to verify capabilities, structure and other info before making the search request itself. So i'll implement it all, one by one.
Still, if any other lib (in C#) exists, and anyone know about, would be better than writing a hole new server. If my implementation works, i'll fork it on github and share.
I'm trying to write something in C#, a simple console app that will connect to Discord, retrieve a list of all users in a channel (all currently online would suffice, but everyone who has channel access would be even better.) The app does not need to maintain a connection, just jump in, grab the list of user names and jump out.
I've experimented with DiscordSharp, but it doesn't seem to quite be working out. I think I am getting a client connection but I can't seem to find any channels via GetChannelByName or GetChannelByID. I am not set on using DiscordSharp as the only solution, though I do like the library so far.
A "server" in discord is called a Guild. Per the documentation a Guild can have a list of Channel objects. In the Channel object there is a property called recipients which should give you all users of that channel.
I wouldn't recommend using DiscordSharp because according to their GitHub it is a dead project. They recommend using DSharpPlus or Discord.NET.
I just checked the documentation for Discord.NET and found a few methods you could use:
GetGuildAsync(UInt64, RequestOptions): This will get you the RestGuild (server) based on the server ID.
GetChannelAsync(UInt64, RequestOptions): This will get you the RestChannel based on the channel ID.
Using either one of these will eventually get you a RestChannel object that will contain a GetUsersAsync(CacheMode, RequestOptions) method that will allow you to get the collection of IUSer
In a command module you can do this:
public class AllUsers : ModuleBase<SocketCommandContext>
{
public async Task Traitement()
{
var users = Context.Guild.Users;
//you can loop here on users and do the traitement
}
}
I Want Connect Multi Play Numbers To The Client And Send Message with Those Numbers At The Same Time . any way for this?
tlsharp library
You would most likely need to have multiple instances of the TelegramClient. When you create each instance, you can use the sessionUserId parameter so each has their own .dat file.
var client = new TelegramClient(appid, apihash, sessionUserId: "some unique name here");
Then to send a message from each at the same time, just do a foreach on your client list / array.
I have a c# console application that I want to use for a game server
the client is being written is as3.
I am going to embed the swf into a c# form later.
I have a couple questions, I'm really hoping someone can help me figure this out.
Currently I have it set up to send a request to log in to the server, at which point the server checks information you put in the username and password fields
and verifies the information.
If you are authenticated you get connected.
My issue is I can't figure out how to send specific information back to flash, such as a string or int.
I want to do this for things like displaying user stats for example.
I looked at many tutorials but most are about using a flash application that is embedded in a c# server application, and does not operate the same way I need it to.
I just want to send a string or int from my c# server to my flash application that I have retrieved from mysql.
so if anyone can just show me how to send a string or int to flash as a raw value please let me know :)
If you can please post a snippet of code... I am still very new as3 c# communication.
also if you need the source please contact me on skype
Skype = Serifaz2
I don't want to just publicly post it ... sorry :(
Nevermind I figured it out. It was actually pretty simple.
C#
Socket socket = TcpClient.Client;
string UserTest = "" + Username;
try
{ // sends the text with timeout 10s
UserInfo.Send(socket, Encoding.UTF8.GetBytes(UserTest), 0, UserTest.Length, 1000000);
}
catch (Exception ex) { /* ... */ }
AS3
while(socket.bytesAvailable)
{
var str:String = this.socket.readUTFBytes(this.socket.bytesAvailable);
trace(str);
myTrace("you have something");
}
So let's say I created a feedback form in C#.
It sens the feedback to my PHP Page and my PHP Page adds it to my MySQL Database.
Code:
private void PostFeed(string Params)
{
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.Headers["Accept"] = #"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
wc.Headers["Accept-Language"] = #"en-US,en;q=0.5";
string HtmlResult = wc.UploadString("http://website/feedtest.php", "POST", Params);
Console.WriteLine(HtmlResult);
}
}
On my PHP I have a code that looks similar to:
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$desc = $_REQUEST['description'];
connect
post result...
close connection
The question I have is: is there a way to protect against flood ? I understand anyone can just spam/flood it by sending feedback continuously or even creating a third party app that sends like 1000 post request per second. I was thinking of implementing some sort of check on the PHP side, for example: if the connection password from the c# app matches, then continue if not, exit.
Basically, I dont want people to take advantage of the feedback method and spam me.
Can anyone suggest a method ? or Should I not even worry about this ?
Any help is appreciated.
A typical technique is to have some kind of submissions per X unit of time limit where you have a last_submitted_at column in a table associated with some kind of identifier. For example, you might associate it with a user if you have a fairly robust user registration system, or you might associate it with an IP if you don't.
This is the system that Stack Overflow uses if you try and vote, post, or as questions too often. Each of these has a separate timer which probably translates to a separate last_X_at column in the database somewhere.
If the last time is less than some threshold, present an error instead of accepting the submission.