TwitchLib / TwitchLib.Client

Client component of TwitchLib.
39 stars 61 forks source link

Index Out of Bounds - OnBeingHosted #39

Closed MrDKOz closed 6 years ago

MrDKOz commented 6 years ago

Hi,

Whenever another user hosts my channel, I get the following error:

  Index was outside the bounds of the array.

Here's the stack trace:

   at TwitchLib.Client.Models.BeingHostedNotification..ctor(String botUsername, IrcMessage ircMessage)
   at TwitchLib.Client.TwitchClient.HandlePrivMsg(IrcMessage ircMessage)
   at TwitchLib.Client.TwitchClient.HandleIrcMessage(IrcMessage ircMessage)
   at TwitchLib.Client.TwitchClient._client_OnMessage(Object sender, MessageReceivedEventArgs e)
   at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
   at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
swiftyspiffy commented 6 years ago

I will look into this issue tonight and get a fix out ASAP since it's kind of a big deal.

MrDKOz commented 6 years ago

@swiftyspiffy Thank you, if there's anymore data you need let me know as it's not hard to replicate.

MrDKOz commented 6 years ago

@swiftyspiffy Has a fix been found for this issue as of yet?

swiftyspiffy commented 6 years ago

Sorry about the delay, looking into this now.

swiftyspiffy commented 6 years ago

@MrDTuring If you happen to have the IRC string for your OnBeingHosted notification, that'd be useful. I know there's at least 2 different ones that need to be handled.

MrDKOz commented 6 years ago

@swiftyspiffy I don't have it to hand. I can download the source and see if I can get it though.

swiftyspiffy commented 6 years ago

@MrDTuring Subscribe to the OnLog event, and see if you can collect the IRC string when you get hosted from that event. The OnLog event fires before any twitch irc parsing is performed, so you should be able to get access to it (print it to the console?) before the app crashes.

MrDKOz commented 6 years ago

@swiftyspiffy Okay so here's what I got:

Received: :jtv!jtv@jtv.tmi.twitch.tv PRIVMSG mrdturingtest :mrdturingdebug is now hosting you for up to 3 viewers.

It looks like line 22 in BeingHostedNotifcation, splits the message on the spaces, and then tries to extract the number of users, but is using the wrong index.

I've attached a screenshot of the error, this should be enough information :)

capture

swiftyspiffy commented 6 years ago

Yup, I knew it was that line, but I wasn't sure what the message was that was being parsed. Awesome, this will help a lot.

MrDKOz commented 6 years ago

@swiftyspiffy Awesome. I assume'd you know, but I didn't want to just skip over that line just in case :)

swiftyspiffy commented 6 years ago

@MrDTuring Give it a go now :)

MrDKOz commented 6 years ago

@swiftyspiffy looks good! Any idea when the Nuget Packages will adopt this change?

swiftyspiffy commented 6 years ago

@MrDTuring Will have to talk to the other members, but hopefully soon (a few days?).

MrDKOz commented 6 years ago

@swiftyspiffy sounds good, thanks for your help 👍

MoonieGZ commented 6 years ago

Still crashes on hosts over 1 viewer, hoping this would fix it but it doesn't

swiftyspiffy commented 6 years ago

Shit. Can you paste the IRC code that is received when you get a host? You can get it by listening to the OnLog event, and printing out e.Data I think.

MoonieGZ commented 6 years ago

I've been trying to trace this for a while but my brain doesn't work enough sometimes, I don't personally use my program, and when I stream I don't get multiple viewer hosts, luckily my friend who I made it for is extremely patient.

I've tried using logging to files, which ended up getting file access issues... I'm going to just make it open a console and ask him to screenshot it when it happens.

I'll get back to you as soon as I get something.

swiftyspiffy commented 6 years ago

Excellent, and sorry about the issues! Will get right on it as soon as you respond with them!

MoonieGZ commented 6 years ago

I published the new version to my friend with logging as you asked with the OnLog + e.Data Literally 2 minutes later he got raided with 6 viewers... perfect timing. 10 seconds after I pointed out that my debugging attempts yesterday were trash...

His screenshot:

Index out of bounds

Last lines of the log file before crashing:

[2018-05-29T11:02:06] Received: @badges=moderator/1,subscriber/0,sub-gifter/1;color=#1E90FF;display-name=LeafyDev;emotes=425618:33-35;id=9ca742d3-a4b1-410e-b1ea-f1d75fcc9ec3;mod=1;room-id=124788407;subscriber=1;tmi-sent-ts=1527591723404;turbo=0;user-id=42251884;user-type=mod :leafydev!leafydev@leafydev.tmi.twitch.tv PRIVMSG #cloudy95 :time flies when your bot crashes LUL
[2018-05-29T11:02:06] Unaccounted for: @badges=moderator/1,subscriber/0,sub-gifter/1;color=#1E90FF;display-name=LeafyDev;emotes=425618:33-35;id=9ca742d3-a4b1-410e-b1ea-f1d75fcc9ec3;mod=1;room-id=124788407;subscriber=1;tmi-sent-ts=1527591723404;turbo=0;user-id=42251884;user-type=mod :leafydev!leafydev@leafydev.tmi.twitch.tv PRIVMSG #cloudy95 :time flies when your bot crashes LUL
[2018-05-29T11:02:16] Received: @badges=;color=#8A2BE2;display-name=xxkenshiraxx;emotes=;id=71e53c48-d53c-486a-a468-b5a4487db57f;login=xxkenshiraxx;mod=0;msg-id=raid;msg-param-displayName=xxkenshiraxx;msg-param-login=xxkenshiraxx;msg-param-viewerCount=8;room-id=124788407;subscriber=0;system-msg=8\sraiders\sfrom\sxxkenshiraxx\shave\sjoined\n!;tmi-sent-ts=1527591733012;turbo=0;user-id=19641086;user-type= :tmi.twitch.tv USERNOTICE #cloudy95
[2018-05-29T11:02:16] Received: :jtv!jtv@jtv.tmi.twitch.tv PRIVMSG cloudy95 :xxkenshiraxx is now hosting you for up to 6 viewers.
swiftyspiffy commented 6 years ago

Excellent, that's exactly what I needed. Working on it now.

swiftyspiffy commented 6 years ago

@LeafyDev Can I know what version/code you're using? Is it the latest Github code, or the latest nuget package?

MoonieGZ commented 6 years ago

Latest NuGet, 2.1.3

I'm just using the client, using only the message received / disconnected and channeljoined. Which is why the hosting crash was intriguing.

I can provide code if needed.

swiftyspiffy commented 6 years ago

@LeafyDev if you want to give the latest github code a try. Added some additional checks there.

MoonieGZ commented 6 years ago

Dang, wish I got the email sooner, will do for tomorrow morning (GMT+2)

On Wed, 30 May 2018, 00:01 Cole, notifications@github.com wrote:

@LeafyDev https://github.com/LeafyDev if you want to give the latest github code a try. Added some additional checks there.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TwitchLib/TwitchLib.Client/issues/39#issuecomment-392960544, or mute the thread https://github.com/notifications/unsubscribe-auth/ABnVrbew5YdPjr3dJpKZTxCfCcXEDiCcks5t3cVPgaJpZM4UDgGS .

swiftyspiffy commented 6 years ago

Sounds good, let me know :)

MoonieGZ commented 6 years ago

Just spent an hour with dependency issues, got rid of Fody/Costura and it's working.........

It's currently running live on GitHub code, now we just wait for a host I guess...

MoonieGZ commented 6 years ago

Just hosted with 4 times myself, working now, no crash.

swiftyspiffy commented 6 years ago

Excellent! That's awesome to hear! I'll go ahead and close this. Feel free to reopen.