• Welcome to Valhalla Legends Archive.
 

Bnet connection uptime...

Started by Jaquio, January 19, 2004, 01:43 PM

Previous topic - Next topic

Jaquio

Uhh, Yea im back for more help because I know I can find it here err... atleast I hope. I was wondering how I would make it tell how long you are connected to bnet for I finally figured out System Uptime after 1 hour -_-, But Connection uptime is bothering me so I came here. I think im going to add everyone who helped me in the special thanks section of the bot. So... If anyone could please help me on how to do this that would be great.

K

Suppose you know the time that you first connected to battle.net, and you also know the current time.  You now know how long you have been connected.  This question really shouldn't be that stupifying.

Jaquio

Quote from: K on January 19, 2004, 01:49 PM
Suppose you know the time that you first connected to battle.net, and you also know the current time.  You now know how long you have been connected.  This question really shouldn't be that stupifying.

But how would I get it to say how long they are connected for really... I don't get it...

UserLoser.

#3
Assuming your using Visual Basic, here's a simple way (hopefully someone doesn't respond with the high res uptime bs) using GetTickCount:


Global WhenIConnected as Long


When you first connected to Battle.net:


WhenIConnected = GetTickCount


When you want to see your connection uptime


Dim ReturnValue as Long
   ReturnValue = GetTickCount - WhenIConnected


Then you take the ReturnValue, and process it the same way you process your function for computer's uptime

Tuberload

#4
Quote from: Jaquio on January 19, 2004, 01:57 PM
Quote from: K on January 19, 2004, 01:49 PM
Suppose you know the time that you first connected to battle.net, and you also know the current time.  You now know how long you have been connected.  This question really shouldn't be that stupifying.

But how would I get it to say how long they are connected for really... I don't get it...

Upon connecting to Battle.net, save the current time to a variable. Then whenever you want to know how long you have been connected subtract the variable from the current time producing how long the bot has been connected.

Example:

connect()
{
  ... snipped for brevity
 if (CONNECTED)
      var time_connected = TIME;
}

TIME howLongHaveIBeenOn()
{
  return getCurrentTime() - time_connected;
}


Edit: Userloser posted while I was, sorry for duplicate.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

Adron

Quote from: UserLoser. on January 19, 2004, 02:06 PM
Assuming your using Visual Basic, here's a simple way (hopefully someone doesn't respond with the high res uptime bs) using GetTickCount:


I'd say your code is bad, because you may get a run-time error running it.

Kp

Quote from: UserLoser. on January 19, 2004, 02:06 PM
Assuming your using Visual Basic, here's a simple way (hopefully someone doesn't respond with the high res uptime bs) using GetTickCount:

It's unlikely that the high resolution timers are needed here, as there will not be a problem unless your connection is stable for more than 49.7 days (might be less in VB if you don't take into account VB's inability to handle unsigned quantities).  Either way, it's pretty rare that you'll be able to hold a BNCS connection long enough for the value to overflow. :)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

R.a.B.B.i.T

#7
Quote from: Kp on January 19, 2004, 05:05 PM
Quote from: UserLoser. on January 19, 2004, 02:06 PM
Assuming your using Visual Basic, here's a simple way (hopefully someone doesn't respond with the high res uptime bs) using GetTickCount:

It's unlikely that the high resolution timers are needed here, as there will not be a problem unless your connection is stable for more than 49.7 days (might be less in VB if you don't take into account VB's inability to handle unsigned quantities).  Either way, it's pretty rare that you'll be able to hold a BNCS connection long enough for the value to overflow. :)

I doubt most users could keep a connection for 49.7 days.
VB also starts going negative after 21 days (IE: -23 days).  Simple bug that can be fixed by checking for Time < 0 Then Time * -1.  Not hard, but annoying.

Tuberload

#8
Quote from: Kp on January 19, 2004, 05:05 PM
Quote from: UserLoser. on January 19, 2004, 02:06 PM
Assuming your using Visual Basic, here's a simple way (hopefully someone doesn't respond with the high res uptime bs) using GetTickCount:

It's unlikely that the high resolution timers are needed here, as there will not be a problem unless your connection is stable for more than 49.7 days (might be less in VB if you don't take into account VB's inability to handle unsigned quantities).  Either way, it's pretty rare that you'll be able to hold a BNCS connection long enough for the value to overflow. :)

I will admit I never took that into concideration. You could convert the GetTickCount value into seperate long values (days, hours, minutes, seconds, etc...) and do a little more math to extend the overflow date, but using single variables will always overflow some day. Possibly using an array of integers to represent the time would fix that?
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

ChR0NiC

Quote from: Jaquio on January 19, 2004, 01:43 PM
Uhh, Yea im back for more help because I know I can find it here err... atleast I hope. I was wondering how I would make it tell how long you are connected to bnet for I finally figured out System Uptime after 1 hour -_-, But Connection uptime is bothering me so I came here. I think im going to add everyone who helped me in the special thanks section of the bot. So... If anyone could please help me on how to do this that would be great.

Ok Well I am gonna go straight to the point for you.



Public Declare Function GetTickCount Lib "kernel32" () As Long

Public ConnectTime As Long



These are your Declares.....and Below is when you Declare your ConnectTime



Private Sub mnuConnect_Click

ConnectTime = GetTickCount

ConnectionStuffDownHere <~ <~ <~

End Sub



Then I guess when you are using your uptime......however it is.....I'll just say, let's say you are using a command with a moderation bot



Dim Command() As String
Command = Split(strText, Chr(32))

Select Case Command(0)

Case "uptime"
Send "System Uptime : " FormatCount(GetTickCount)
Send "Battle.net Uptime : " FormatCount(GetTickCount - ConnectTime)

End Select


And the FormatCount is defined below......


Public Function FormatCount(Count As Long, Optional FormatType As TimeFormatType = 0) As String
   Dim Days As Long, Hours As Long, Minutes As Long, Seconds As Long, Miliseconds As Long
   
   Miliseconds = Count Mod 1000
   Count = Count \ 1000
   Days = Count \ (24& * 3600&)
   If Days > 0 Then Count = Count - (24& * 3600& * Days)
   Hours = Count \ 3600&
   If Hours > 0 Then Count = Count - (3600& * Hours)
   Minutes = Count \ 60
   Seconds = Count Mod 60
   Select Case FormatType
           Case 0
       FormatCount = Days & " days, " & Hours & " hours, " & _
           Minutes & " minutes, " & Seconds & " seconds, " & Miliseconds & _
           " milliseconds"
           Case 1
           FormatCount = Days & " days, " & Hours & " hours, " & _
               Minutes & " minutes, " & Seconds & " seconds"
           Case 2
               FormatCount = Days & ":" & Hours & ":" & _
                   Minutes & ":" & Seconds & ":" & Miliseconds
           Case 3
           Dim buffer As String
           buffer = Minutes & " minutes"
           If Hours >= 1 Then
           buffer = Hours & " hours, " & buffer
           End If
           If Days >= 1 Then
           buffer = Days & " days, " & buffer
           End If
           FormatCount = buffer
   End Select
End Function


And that should work out for ya........If you need anymore help I'll be glad to help out. And I'm not sure how much you know......but when I do the ConnectTime = GetTickCount that means I am getting the current time and setting it as ConnectTime. Then when I ask for the uptime.....it's Subtracting the current time.....from the time that was declared as ConnectTime....
I hope I'm making sense  :-[

UserLoser.

Quote from: Adron on January 19, 2004, 03:18 PM
Quote from: UserLoser. on January 19, 2004, 02:06 PM
Assuming your using Visual Basic, here's a simple way (hopefully someone doesn't respond with the high res uptime bs) using GetTickCount:


I'd say your code is bad, because you may get a run-time error running it.

Explain

Also note my code isn't what I posted

ChR0NiC

What is it you would like me to explain???

R.a.B.B.i.T


Jaquio

Wow, Thank you so much ChR0NiC your code worked others I couldnt get working... maybe it was due my knowledge of vb... but not sure. But thank you again. I have another problem though, In the channels list view when people join channels instead of it going stright down it adds on the the right of it and you can click and drag and rearrange people in the channel anyway I can fix that?

ChR0NiC

Well.....I am a little confused but......in case you aren't doing the "add" correctly it should look something like this


frmMain.ChanList.ListItems.Add , , Username, , GetIconCode(message, flags)


Make sure you have a List View that is setup with 1 column or 2 if you have lag bars/plugs.