|
-
Jul 5th, 2002, 09:46 AM
#1
Thread Starter
Lively Member
View logged in via web page. [Parse Text log, Effecient Loops with waits] (Solved)
Ok let me see if i can describe this quickly.
I am working with the Never Winter Nights tool set. We wanted to make a small program to monitor who logs on and off the server so we can display it on the web page.
NeverWinter Nights (NWN) when running the server version writes a complete logg to a txt file. What i am getting at is what is the Best/most effecient/ or easiest way to get this information.
Obviously the program writes to the text file every time something happens, we can see that happening. Is there a way to listen on the program for when it writes, then analyze the string and get the information that way.
I know I can write a quick program to read through the text file and analyze the log ins and offs and determine who is logged in that way. But there has to be a more efficient and much easier way of doing it.
Anyone have any suggestions?
Thanks in advance for all the help and ideas.
http://www.nwnstories.everplay.net
Last edited by TheVoid; Jul 9th, 2002 at 03:32 PM.
-
Jul 9th, 2002, 02:57 PM
#2
Thread Starter
Lively Member
Feel like i am talking to myself here, but at least this helps.
ok Found a way to do it after reading some more threads and brain storming, well it more of just came to me. Here is the cut and copy of that thread.
http://209.120.143.185/showthread.ph...72#post1087072
Disclaimer: Always depends on your usage and accuracy.
However: OMG you want to see something insane, bring up your CPU usage and then run the above timer example, Damn if that thing pegs your CPU usage to the max, Very bad IMHO. No reason i need to check to see if the 10 seconds have passed 1000 times a second .
But on the other extreme you have the sleep API, While awesome, sleep is really harsh in that your form doesn't refresh well, it appears to be non responsive to windows. You can't use other functions very well in your program if you have it sleeping.
So why not use BOTH!!!!
Use the sleep API inside that Timer Sub so that you only check however often you wish. Combine that with the DoEvents call and you have responsiveness also, combined with functionality and you save the hell out of your CPU's usage allowing other programs to take place.
Here is a simple Play Stop program i threw together, am going to use it in an application to parse through Never Winter Night's text log to get statistics and names of ppl logged in for display on a web page. This application i want to run constantly on the server, taking up as little CPU usage as possible so not to lag the game; however i also want it to display correctly and have functionality. Here was the solution.
VB Code:
Dim blnStop As Boolean
'HOW TO: Call Sleep(2500) 'Would be 2.5 seconds
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub cmdplay_Click()
Dim nStart As Single
Dim length As Single
blnStop = False
cmdplay.Enabled = False
length = 60 'change to 10 seconds for testing
Do
lblstatus.Caption = "Still looping --> " & Now
nStart = Timer
Do While Timer < nStart + length
DoEvents 'Releases control of the cpu
'Allows other events to take place.
If blnStop = True Then
Exit Do
End If
'The sleep slows down the rate in which the program checks the time.
'This combined with the do events allows the user to basically
'Interact with the program every 2 seconds.
Sleep (2000)
Loop
If blnStop = True Then
lblstatus.Caption = "Stoped looping --> " & Now
blnStop = False
Exit Do
End If
Loop
cmdplay.Enabled = True
End Sub
Private Sub cmdStop_Click()
blnStop = True
End Sub
The form has two buttons cmdPlay and cmdStop and one label named lblstatus. As setup if i replaced the "Still Looping" with my called procedure to do whatever, that called procedure would run every minute, but the program isn't sleeping the entire minute, it allows other programs do what they need to, and allows the user to interact with this one.
Now i am still new to the doevents call and such, so some of the lingo here may be wrong, but at least that is how it appears to work.
Basically it turns the sleep API call into an accuracy identifier, depending on how accurate you want to be.
What do you think? Input greatly appreciated. Pros? Cons? Refinements?
Altered Wait call procedure
VB Code:
Public Sub Wait(Length As Single)
' Pauses for Length seconds
Dim nStart As Single
On Error Resume Next
nStart = Timer
Do While Timer < nStart + Length
DoEvents ' Releases control of the cpu
sleep(1000) 'Accuracy of 1 second (pauses for a second, then checks again)
Loop
MsgBox 1
End Sub
Last edited by TheVoid; Jul 9th, 2002 at 03:07 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|