Results 1 to 2 of 2

Thread: View logged in via web page. [Parse Text log, Effecient Loops with waits] (Solved)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    Florida
    Posts
    98

    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.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    Florida
    Posts
    98
    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:
    1. Dim blnStop As Boolean
    2.  
    3. 'HOW TO: Call Sleep(2500)  'Would be 2.5 seconds
    4. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    5.  
    6. Private Sub cmdplay_Click()
    7.    
    8.     Dim nStart As Single
    9.     Dim length As Single
    10.    
    11.     blnStop = False
    12.    
    13.     cmdplay.Enabled = False
    14.    
    15.     length = 60  'change to 10 seconds for testing
    16.    
    17.     Do
    18.        
    19.         lblstatus.Caption = "Still looping --> " & Now
    20.        
    21.         nStart = Timer
    22.        
    23.         Do While Timer < nStart + length
    24.             DoEvents    'Releases control of the cpu
    25.                         'Allows other events to take place.
    26.             If blnStop = True Then
    27.                 Exit Do
    28.             End If
    29.             'The sleep slows down the rate in which the program checks the time.
    30.             'This combined with the do events allows the user to basically
    31.             'Interact with the program every 2 seconds.
    32.             Sleep (2000)
    33.         Loop
    34.        
    35.         If blnStop = True Then
    36.             lblstatus.Caption = "Stoped looping --> " & Now
    37.             blnStop = False
    38.             Exit Do
    39.         End If
    40.        
    41.     Loop
    42.    
    43.     cmdplay.Enabled = True
    44.    
    45. End Sub
    46.  
    47. Private Sub cmdStop_Click()
    48.  
    49. blnStop = True
    50.  
    51. 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:
    1. Public Sub Wait(Length As Single)
    2. ' Pauses for Length seconds
    3.    Dim nStart As Single
    4. On Error Resume Next
    5.    nStart = Timer
    6.    Do While Timer < nStart + Length
    7.       DoEvents ' Releases control of the cpu
    8.       sleep(1000) 'Accuracy of 1 second (pauses for a second, then checks again)
    9.    Loop
    10.    MsgBox 1
    11. 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
  •  



Click Here to Expand Forum to Full Width