unit parser_css; interface uses types,classes,sysutils,windows,koala_types; const COLOUR_CT = '12'; COLOUR_T = '4'; COLOUR_RCONCHAT = '1,8'; type Tparser_css = class private owner :hwnd; procedure Debug(thestatus:integer;thetext:string); procedure splitstring(log:String;var subject,action,target,extra:array of string); public constructor Create(theowner:hwnd); destructor Destroy;override; function parse(logtext:string;formattext:boolean):string; end; implementation { Tparser_css } constructor Tparser_css.Create(theowner:hwnd); begin owner:=theowner; end; destructor Tparser_css.Destroy; begin inherited; end; function Tparser_css.parse(logtext: string;formattext:boolean):string; var subject,action,target,extra:array of string; returnstring:String; begin // returnstring:=copy(logtext,21,length(logtext)-20); setlength(subject,5); setlength(action,1); setlength(target,5); setlength(extra,5); splitstring(logtext,subject,action,target,extra); if (subject[0]='world') and (action[0]='triggered') then begin if target[0]='Round_Start' then returnstring:='New round has started ...'; if copy(target[0],1,13)='Restart_Round' then returnstring:='Game is restarting ('+target[0]+') ...'; end; if (subject[0]='team') and (action[0]='triggered') then begin returnstring:='Round over,'; if target[0]='CTs_Win' then begin if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; returnstring:=returnstring+' CounterTerrorists Win! (all Terrorists eliminated) '; end else if target[0]='Terrorists_Win' then begin if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+' Terrorists Win! (all CounterTerrorists eliminated) '; end else if target[0]='Target_Bombed' then begin if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+' Terrorists Win! (target bombed) '; end else if target[0]='Bomb_Defused' then begin if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; returnstring:=returnstring+' CounterTerrorists Win! (bomb defused) '; end; if target[0]='All_Hostages_Rescued' then begin if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; returnstring:=returnstring+' CounterTerrorists Win! (all hostages rescued) '; end; if formattext then returnstring:=returnstring+chr(15); if formattext then returnstring:=returnstring+'. Round Scores : '+chr(3)+COLOUR_CT+extra[0]+chr(15)+' | '+chr(3)+COLOUR_T+extra[1] else returnstring:=returnstring+'. Round Scores : '+extra[0]+' | '+extra[1]; end; if (subject[0]='player') and (action[0]='suicide') then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:='<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' killed himself'; end; if (subject[0]='player') and (action[0]='joined') then begin if uppercase(subject[4])='UNASSIGNED' then begin returnstring:=subject[1]+' has connected and is joining'; if target[0]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT+' CounterTerrorists' else returnstring:=returnstring+' CounterTerrorists'; if target[0]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T+' Terrorists' else returnstring:=returnstring+' Terrorists'; end else if subject[4]='CT' then begin if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT+subject[4]+' '+subject[1]+chr(15)+' changed team to '+chr(3)+COLOUR_T+' Terrorist' else returnstring:=subject[4]+' '+subject[1]+' changed team to Terrorist'; end else if subject[4]='TERRORIST' then begin if formattext then returnstring:=returnstring+chr(3)+COLOUR_T+subject[4]+' '+subject[1]+chr(15)+' changed team to '+chr(3)+COLOUR_CT+' CounterTerrorist' else returnstring:=subject[4]+' '+subject[1]+' changed team to CounterTerrorist'; end; end; if (subject[0]='player') and (action[0]='killed') then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); if formattext then returnstring:=returnstring+chr(2)+' killed '+chr(2) else returnstring:=returnstring+' killed '; if target[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if target[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+target[4]+'> '+target[1]; if formattext then returnstring:=returnstring+chr(15); if extra[0]='with' then returnstring:=returnstring+' with '; if formattext then returnstring:=returnstring+chr(2)+extra[1]+' '+extra[2] else returnstring:=returnstring+extra[1]+' '+extra[2]; end; if (subject[0]='player') and (action[0]='triggered') then begin if target[0]='Got_The_Bomb' then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' got the bomb'; end; if target[0]='Dropped_The_Bomb' then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' dropped the bomb'; end; if target[0]='Defused_The_Bomb' then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' defused the bomb'; end; if target[0]='Begin_Bomb_Defuse_Without_Kit' then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' begins defusing the bomb (no kit)...'; end; if target[0]='Begin_Bomb_Defuse_With_Kit' then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' begins defusing the bomb (using kit)...'; end; if target[0]='Planted_The_Bomb' then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' planted the bomb!'; end; if target[0]='Touched_A_Hostage' then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' is leading a hostage to safety'; end; if target[0]='Rescued_A_Hostage' then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' rescued a hostage'; end; if target[0]='Killed_A_Hostage' then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' killed a hostage!'; end; end; if (subject[0]='player') and (action[0]='say') then begin if subject[1]='Console' then begin if formattext then returnstring:=chr(3)+COLOUR_RCONCHAT+'*** '+target[0] else returnstring:=' *** '+target[0]; end; end; if (subject[0]='player') and (action[0]='disconnected') then begin if subject[4]='CT' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_CT; if subject[4]='TERRORIST' then if formattext then returnstring:=returnstring+chr(3)+COLOUR_T; returnstring:=returnstring+'<'+subject[4]+'> '+subject[1]; if formattext then returnstring:=returnstring+chr(15); returnstring:=returnstring+' disconnected - '+target[0]; end; if (subject[0]='loading') and (action[0]='map') then begin returnstring:='Loading new map : '+target[0]; end; result:=returnstring; end; procedure Tparser_css.splitstring(log:string;var subject, action, target, extra: array of string); var tempstring:string; begin delete(log,1,30); try // get first 'subject' of log if (copy(log,1,5)='World') then begin subject[0]:='world'; // position for next entry delete(log,1,6); end else if (copy(log,1,7)='Loading') then begin subject[0]:='loading'; // position for next entry delete(log,1,8); end else if (copy(log,1,1)='"') then begin subject[0]:='player'; // split string into player elements // delete first " delete(log,1,1); // get player string tempstring:=copy(log,1,pos('"',log)-1); subject[1]:=copy(tempstring,1,pos('<',tempstring)-1); delete(tempstring,1,pos('<',tempstring)); subject[2]:=copy(tempstring,1,pos('>',tempstring)-1); delete(tempstring,1,pos('>',tempstring)+1); // also deletes next < subject[3]:=copy(tempstring,1,pos('>',tempstring)-1); delete(tempstring,1,pos('>',tempstring)+1); // also deletes next < subject[4]:=copy(tempstring,1,pos('>',tempstring)-1); // position for next entry delete(log,1,pos('"',log)+1); end else if (copy(log,1,4)='Team') then begin subject[0]:='team'; // find out team subject delete(log,1,5); delete(log,1,1); // delete first " tempstring:=copy(log,1,pos('"',log)-1); subject[1]:=copy(tempstring,1,pos('"',tempstring)-1); // position for next entry delete(log,1,pos('"',log)+1); end else if (copy(log,1,12)='server_cvar:') then begin subject[0]:='cvar'; delete(log,1,13); delete(log,1,1); // delete first " tempstring:=copy(log,1,pos('"',log)-1); subject[1]:=copy(tempstring,1,pos('"',tempstring)-1); // position for next entry delete(log,1,pos('"',log)+1); end; // get 'action' of log if subject[0]='cvar' then begin action[0]:='set'; end else if (copy(log,1,13)='disconnected ') then begin action[0]:='disconnected'; end else if (copy(log,1,4)='map ') then begin action[0]:='map'; // position for next entry delete(log,1,4); end else if (copy(log,1,10)='triggered ') then begin action[0]:='triggered'; // position for next entry delete(log,1,10); end else if (copy(log,1,4)='say ') then begin action[0]:='say'; // position for next entry delete(log,1,4); end else if (copy(log,1,9)='say_team ') then begin action[0]:='say_team'; // position for next entry delete(log,1,9); end else if (copy(log,1,16)='entered the game') then begin action[0]:='entered'; // position for next entry delete(log,1,16); end else if (copy(log,1,7)='killed ') then begin action[0]:='killed'; // position for next entry delete(log,1,7); end else if (copy(log,1,7)='scored ') then begin action[0]:='scored'; // position for next entry delete(log,1,7); end else if (copy(log,1,19)='connected, address ') then begin action[0]:='connected'; // position for next entry delete(log,1,19); end else if (copy(log,1,23)='committed suicide with ') then begin action[0]:='suicide'; // position for next entry delete(log,1,23); end else if (copy(log,1,12)='joined team ') then begin action[0]:='joined'; // position for next entry delete(log,1,12);// dont delete next space end; // exit where there is no more info to get if action[0]='entered' then exit; // get 'target' of log if (action[0]='connected') or (action[0]='map') or (action[0]='set') or (action[0]='say') or (action[0]='joined') or (action[0]='say_team') or (action[0]='suicide') or (action[0]='scored') or (action[0]='triggered') then begin delete(log,1,1); // delete first " tempstring:=copy(log,1,pos('"',log)-1); target[0]:=trim(tempstring); // position for next entry delete(log,1,pos('"',log)); // may go past end of line if used +1, so use trim instead log:=trim(log); end else if action[0]='disconnected' then begin target[0]:=trim(log); end else if (copy(log,1,1)='"') then begin target[0]:='player'; // split string into player elements // delete first " delete(log,1,1); // get player string tempstring:=copy(log,1,pos('"',log)-1); target[1]:=copy(tempstring,1,pos('<',tempstring)-1); delete(tempstring,1,pos('<',tempstring)); target[2]:=copy(tempstring,1,pos('>',tempstring)-1); delete(tempstring,1,pos('>',tempstring)+1); // also deletes next < target[3]:=copy(tempstring,1,pos('>',tempstring)-1); delete(tempstring,1,pos('>',tempstring)+1); // also deletes next < target[4]:=copy(tempstring,1,pos('>',tempstring)-1); // position for next entry delete(log,1,pos('"',log)+1); end; // get 'extra' if (target[0]='player') then begin if copy(log,1,5)='with ' then begin extra[0]:='with'; delete(log,1,5); delete(log,1,1); // delete first " tempstring:=copy(log,1,pos('"',log)-1); extra[1]:=trim(tempstring); // position for next entry delete(log,1,pos('"',log)); log:=trim(log); if (length(log)>0) then begin extra[2]:=log; end; end; end else if (subject[0]='team') then begin if action[0]='triggered' then begin log:=trim(log); extra[0]:=copy(log,1,pos(') (',log)); delete(log,1,pos(') (',log)+1); extra[1]:=trim(log); end; if action[0]='scored' then begin extra[0]:=trim(log); end; end; except subject[0]:=''; action[0]:=''; target[0]:=''; extra[0]:=''; debug(2,'Error parsing log line '+log); end; end; procedure Tparser_css.Debug(thestatus:integer;thetext:string); var debug:Pdebugmessage; begin try debug:=new(Pdebugmessage); debug^.category:=thestatus; debug^.text:=thetext; SendMessage(owner, WM_UPDATEDEBUG, wparam(debug), lparam(-1)); except end; end; end.