Results 1 to 3 of 3

Thread: Need help with log file.

  1. #1
    Join Date
    Sep 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Need help with log file.

    I banged my head several times over the wall... but still no solution.

    I want to strip the log file and store the time stamp, player name, message into arrays...

    Here is an example of the log.
    Code:
    01-10-07 13:04:13: Drace shouts: i need SLEPPP
    01-10-97 13:04:22: Quetzacotl shouts: checked there only gardner
    01-10-97 13:04:38: Lightwolf shouts: he's in the trees running around
    01-10-97 13:04:40: Crazygeneral shouts: bye bye Drace 
    01-10-97 13:04:47: Eole shouts: now, behind me is a blind broken bone on the ground ... :D
    01-10-97 13:04:57: Rosey shouts: ello drace :p
    01-10-97 13:05:03: Eole shouts: bye Drace, sweet dreams
    01-10-97 13:05:13: Crazygeneral shouts: nighty night night 
    01-10-97 13:05:24: Rosey shouts: O_O
    I havent tried
    function RegexPos(Txt, Regex: string): Integer;
    Returns the position of the first found occurence of the regex.

    function FindRegex(Txt, Regex: string): Integer;
    Returns the string found by the regex.

    First i need to know what they do and how they work.
    i have seen regex in other softwares... but not in scar...

    Update:
    Here is what i found searching for regex tutorials.
    Windows text files use \r\n to terminate lines

    How do i use it in scar?
    IF someone can put any light on my problem it would be really helpful

  2. #2
    Join Date
    Oct 2006
    Posts
    207
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    #13#10 are the equivalent of \r\n. I havent done much experimenting with the regex engine, but i dont think it returns the results like it does in other ones. For examples in other languages any thing you surround by a bracket can be returned in an array, but i dont think you can do that in SCAR.

    To get those i think you could do something like this:
    SCAR Code:
    program New;
    type
      tMessage = record
        timestamp: string;
        name: string;
        messages: string;
      end;
    var
      arr: array of tMessage;
      i: integer;

    procedure parseLogs(var arr: array of tMessage; s: string);
    var
      i, j, k: integer;
      tempS: string;
      len: integer;
    begin
      repeat
        i := pos(#13#10, s);
        if(i = 0) then
        begin
          j := 1;
          tempS := s;
        end else
          tempS := copy(s, 1, i - 1);
        delete(s, 1, i + 1);
        k := pos(': ', tempS);
        setlength(arr, len + 1);
        arr[len].timestamp := copy(tempS, 1, k - 1);
        delete(tempS, 1, k + 1);
        k := pos(' shouts', tempS);
        arr[len].Name := copy(tempS, 1, k - 1);
        delete(tempS, 1, k + 8);
        arr[len].Messages := copy(tempS, 1, length(tempS));
        len := len + 1;
        if(j = 1) then
          break;
      until(false)
    end;

    begin
      parseLogs(arr, '01-10-07 13:04:13: Drace shouts: i need SLEPPP'#13#10 +
            '01-10-97 13:04:22: Quetzacotl shouts: checked there only gardner'#13#10 +
            '01-10-97 13:04:38: Lightwolf shouts: he''s in the trees running around'#13#10 +
            '01-10-97 13:04:40: Crazygeneral shouts: bye bye Drace'#13#10 +
            '01-10-97 13:04:47: Eole shouts: now, behind me is a blind broken bone on the ground ... :D'#13#10 +
            '01-10-97 13:04:57: Rosey shouts: ello drace :p'#13#10 +
            '01-10-97 13:05:03: Eole shouts: bye Drace, sweet dreams'#13#10 +
            '01-10-97 13:05:13: Crazygeneral shouts: nighty night night'#13#10 +
            '01-10-97 13:05:24: Rosey shouts: O_O');
      for i := 0 to length(arr) - 1 do
      begin
        writeln(arr[i].name + ' says ' + arr[i].messages + ' at ' + arr[i].timestamp);
      end;
    end.

    What i know about the scar regex engine:
    Cannot surround things by brackets to return its value.
    Cannot use \w \d etc
    I dont think ??? It supports those things you add onto the end, for example in php:
    \\d{0,9}\i
    I think thats right, anyway the i at the end.
    EDIT: MODIFIERS!
    They are in string format eg
    regex := '[0-9]{0,9}';

  3. #3
    Join Date
    Sep 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh here is the script i tried to make.
    Here is how it works.
    1) Checks log file size.
    2) If higher than 0 then proceed
    3) It gets the contents of the log file
    4) Rewrites the log files (deletes every thing inside it)
    I did this because i coudnt think if anything better is less time.
    It scans only one message at a time.
    5) then it checks wheather it is a shout or a private message (tell)

    other things can be understood.
    Code:
    program New;
    
    var
       FileNum, LogSize :Integer;
       TempS, TempMsg :String;
    
    Procedure phrase_log;
    Begin
    ReadFileString(FileNum, TempS, LogSize);
    CloseFile(FileNum);
    CloseFile(RewriteFile('C:\Program Files\daimonin\daimonin_widget\Rosey.chat.log', False ));
    writeln(TempS)
    end;
    
    
    
    
    
    
    
    procedure chk_log;
    var a :integer;
        Name, TimeStamp, PlyrMsg :String;
    Begin
    FileNum:= OpenFile( 'C:\chat.log' , False );
    LogSize:= FileSize( FileNum )
      If ( LogSize > 0 ) Then
        Begin
          phrase_log;
            If (pos(' tells you:' , TempS) > 0) then
               begin
               a:= pos(' tells you:' , TempS);
               TimeStamp := copy(TempS, 1, 17);
               Name:= Copy(TempS, 20, (a-20) );
               PlyrMsg:= Between(' tells you:  ', #13#10, TempS)
               WriteINI('Player_Data', Name, TimeStamp, ScriptPath + 'PlayerData.ini');
               end else
                           If (pos(' shouts:' , TempS) > 0) then
                           begin
                           a:= pos(' shouts:' , TempS);
                           TimeStamp := copy(TempS, 1, 17);
                           Name:= Copy(TempS, 20, (a-20) );
                           PlyrMsg:= Between(' tells you:  ', #13#10, TempS)
                           WriteINI('Player_Data', Name, TimeStamp, ScriptPath + 'PlayerData.ini');
                           end;
        end;
    end;
    
    begin
    chk_log;
    end.

    Log File: Example
    Code:
    01-01-97 01:45:10: Crazygeneral shouts: wb Rosey 
    01-01-97 01:44:45: player shouts: message 2 
    01-01-97 01:40:56: testplayer tells you: private message 3 
    01-01-97 01:35:42: sheepy tells you: private message 4

    Now the problem is the game client locks the logfile
    That means i cant write to it while the game is running.
    Any code which only scans the last line of the log file or something like that.

    Anyone has better ideas?

    Sry Drunkenoldma, I forgot to tell you about the "shout" and "tell" messages.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. sig from file
    By skibby in forum Semi Stupid Pictures
    Replies: 6
    Last Post: 05-26-2007, 04:28 AM
  2. End of file
    By botmaster in forum OSR Help
    Replies: 3
    Last Post: 11-09-2006, 05:47 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
  •