EldinZenderink / SimpleIRCLib

A lightweight, simple to use and implement, IRC library with support for DCC download (no upload)
MIT License
14 stars 14 forks source link

Exception Error #7

Closed aykuter closed 6 years ago

aykuter commented 6 years ago

Hi guys. I'm trying to make little irc program for read twitch messages. I read sample codes but i'm getting exception all the time. (My oauth token, server, port, username is correct.) I tried WinForm version too both getting this exception. Thank you for all kind of help. Sorry for my english :)

https://prnt.sc/i7bnxh

EldinZenderink commented 6 years ago

Ah sry for the inconvenience, thats an issue I shouldve fixed some time ago. You need to setup all the callbacks available (look @readme for the callbacks) should work if you do that. The examples are old and never updated to work with the newest version of the library.

aykuter commented 6 years ago

It's np thank you for this lib i hope i can make it work :) Now i add other callbacks but i'm still getting exception here it is : https://prnt.sc/i7kko2

I just want to read messages i don't need other callback methods or sendMessage. I have no idea how can i fix that exception. When i see first message in the console it's throwing exception immediately.

EldinZenderink commented 6 years ago

Were almost there, you did not assign the callbacks within the irc library, this is how you should do it:

        public SimpleIRC irc;

        public void launchIrc(string ip,  string username, string password, string channel)
        {          

            irc = new SimpleIRC();
            irc.setupIrc( ip, 6667, username, password, channel, chatOutput);
            irc.setDebugCallback(debugOutputCallback);
            irc.setRawOutput(rawOutputCallback);
            irc.setDownloadStatusChangeCallback(downloadStatusCallback);
            irc.setUserListReceivedCallback(userListReceivedCallback);
            irc.startClient();

        }

        public void chatOutput(string user, string message)
        {
            Console.WriteLine(user + " : " + message );

        public void debugOutputCallback(string debug)
        {
        }

        public void rawOutputCallback(string raw)
        {

        }

        public void downloadStatusCallback()
        {

        }

        public void userListReceivedCallback(string[] users)
        {
            Console.WriteLine("Users in channels:");
            foreach(string user in users){
                 Console.WriteLine(user);
            }
        }

Do think about static fields and what not, this is will not run directly in the main class of your program. You'd need to make every method static, in your situation, if I remember correctly.

Reason you need to at least define the callback methods is due to the fact that those methods will be called internally within the library, if they are not defined, the library will still try to call those methods, hence generating object reference not set. Because its trying to call a method that is NULL aka non existent.

aykuter commented 6 years ago

Ahhh how i missed the irc.setcallbacks part sorry if i bother you. I will test and manage static fields etc. I test it in WinForm app and it's working perfect now. When i try to declare two separate SimpleIRC as irc1 and irc2 i can read messages from different channels without any problem. But when i try to stop one of these clients two of them are stopping. I calling irc.stopClient(); but irc2 is stopped working too. I will keep trying but do you have any idea about this problem ? Thank you so much for all your help. I'm appreciated.

EldinZenderink commented 6 years ago

No problem, I am glad to help, it helps me improve as well. That said, I honestly never thought about using two separate instances of SimpleIRC to separate communication between multiple channels. That said, I am currently in the middle of my internship so I wont be of much help during the day. That both of them are stopping is definitely not your fault, it has something to do with the internal workings of my library, can't say out of my head why though.

I do have a (temporary) solution though: you can connect to multiple channels by defining the channel parameter of ircStart like so: "#channel1,#channel2,#channel3" (aka separating the channels with a ',').

Unfortunately this library doesn't support separate channels really well yet (the chatOutput callback will show messages from all the channels without differentiating between them), You could use the rawOutput callback and parse the raw messages that you get from the channels yourself, hence creating a way to separate messages per channel on your own (I might even implement your solution if you are willing to do so within the library, if it works well :D, of course with credit).

aykuter commented 6 years ago

Ah i see. Good luck with your internship. Thanks for the tip but it will cause unnecessary cpu usage and it will be unstable if it's doesn't support yet. I think i can handle it with reconnection. When i call stopclient i will call start client again for other one. A few missing messages isn't important for me.

I would love to help but i'm pretty sure it's beyond me. I don't have enough experience with separate classes and libraries i'm still trying to figure out. But i will definitely check the library classes maybe i can see the problem who knows :D Thanks again for this lib and your help! See you :)

EldinZenderink commented 6 years ago

Having two instances for separate channels instead of one is more cpu demanding than having just one instance and some string parsing methods. But that's up to you.

aykuter commented 6 years ago

It's good to know thanks. But i want to change channels too. I will close one of them for connect another channel. I don't want to listen exact channels all the time. But i will try it. If it's stable with soo many comments than i will stick to your solution. Ah i have to ask you can i add more channel when it's running ?

EldinZenderink commented 6 years ago

yes, just like with normal irc channels, if you send a /join #channel with the normal sendMessage function it should theoretically join that channel. But leaving specific channels isn't possible yet, there for you do indeed need to reconnect.

aykuter commented 6 years ago

Yep it's working i will check stability :)