section.begin
   Name = DoProgressQuickPlay1x1
   Code : struct.begin
      [*] = ;// DoProgressQuickPlay1x1
      [*] = ;// _misc_QuickPlayMake
      [*] = ;//
      [*] = ;function _misc_QuickPlayMake() : Boolean;
      [*] = ;begin
      [*] = ;   const bForce2v2 = True;
      [*] = ;   var matchMaxPlayers : Integer = gc_quickplay_countofplayers2;
      [*] = ;   var matchMaxTeam : Integer = matchMaxPlayers div 2;
      [*] = ;   //gint_quickplay_countofplayers := gc_quickplay_countofplayers6;
      [*] = ;
      [*] = ;   const waittimestep = 30;
      [*] = ;
      [*] = ;   Result := False;
      [*] = ;
      [*] = ;   var p : Pointer = gQuickPlay;
      [*] = ;   if p<>nil then
      [*] = ;   FillMem(p, SizeOf(gQuickPlay), 0);
      [*] = ;
      [*] = ;   if (gInterface.gamemode=gc_gamemode_mainmenu) and IsLanPublicServerMode and (not IsLanReady) then
      [*] = ;   begin
      [*] = ;      //if realtime>gInternetShell.autosearchantispamlasttime then
      [*] = ;      begin
      [*] = ;         //gInternetShell.autosearchantispamlasttime := realtime+_misc_QuickPlayGetAntispamTime;
      [*] = ;
      [*] = ;         var bexists : Boolean;
      [*] = ;         gbool_gui_showinternetshell := True;
      [*] = ;         var i : Integer;
      [*] = ;         for i:=gInternetShell.sessions.GetCount-1 downto 0 do
      [*] = ;         begin
      [*] = ;            var psession : Pointer = gInternetShell.sessions.Get(i);
      [*] = ;            if (psession<>nil) then
      [*] = ;            begin
      [*] = ;               var visiblename, pass, roomchecksum : String;
      [*] = ;               _misc_GetGameNameAndPasswordBySession(psession, visiblename, pass, roomchecksum);
      [*] = ;               if (not TInternetShellSession(psession).blocked) then
      [*] = ;               begin
      [*] = ;                  if (pass=gc_quickplay_roompass) then
      [*] = ;                  begin
      [*] = ;                     var code : String = SubStr(visiblename, 0, 3);
      [*] = ;
      [*] = ;                     var searchcode, altsearchcode : String;
      [*] = ;                     if gInternetShell.qprankedgame then
      [*] = ;                     begin
      [*] = ;                        searchcode := 'qs=';
      [*] = ;                        altsearchcode := 'qz=';
      [*] = ;                     end
      [*] = ;                     else
      [*] = ;                     begin
      [*] = ;                        searchcode := 'qz=';
      [*] = ;                        altsearchcode := 'qs=';
      [*] = ;                     end;
      [*] = ;                     if (code=searchcode) or (code=altsearchcode) then // quick search - alone player that looking for quick play
      [*] = ;                     begin
      [*] = ;                        var str : String = SubStr(visiblename, 4, StrLength(visiblename)-3);
      [*] = ;                        if IsDelimiterCharExists(str, gc_gui_dotchar) then
      [*] = ;                        begin
      [*] = ;                           var masterid, time : Integer;
      [*] = ;                           case GetDelimiterStringCount(str, gc_gui_dotchar, gc_gui_quotechar) of
      [*] = ;                              1 : masterid := StrToInt(GetDelimiterStringByIndex(str, gc_gui_dotchar, gc_gui_quotechar, 0));
      [*] = ;                              2 : begin
      [*] = ;                                 masterid := StrToInt(GetDelimiterStringByIndex(str, gc_gui_dotchar, gc_gui_quotechar, 0));
      [*] = ;                                 time := StrToInt(GetDelimiterStringByIndex(str, gc_gui_dotchar, gc_gui_quotechar, 1));
      [*] = ;                              end;
      [*] = ;                           end;
      [*] = ;                           var checksum : String = SubStr(roomchecksum, 2, 4);
      [*] = ;                           if (checksum=gstring_checksum) then
      [*] = ;                           begin
      [*] = ;                              if code=searchcode then
      [*] = ;                              begin
      [*] = ;                                 if masterid=LanMyInfoID then
      [*] = ;                                 bexists := True;
      [*] = ;                                 gQuickPlay.AddPlayer(masterid, time, checksum);
      [*] = ;                              end
      [*] = ;                              else
      [*] = ;                              gQuickPlayHideIcon.Add(masterid);
      [*] = ;                           end;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                  end
      [*] = ;                  else
      [*] = ;                  if (SubStr(roomchecksum, 1, 1)='r') then // quick custom - custom room for quick search, contains list of ids in name
      [*] = ;                  begin
      [*] = ;                     var sclientid1, sclientid2, stime, sqpstate, checksum : String;
      [*] = ;                     var mapname : String = TInternetShellSession(psession).mapname;
      [*] = ;                     if (GetDelimiterStringCount(mapname, gc_gui_delimiterchar, gc_gui_quotechar)>8) then
      [*] = ;                     begin
      [*] = ;                        sclientid1 := GetDelimiterStringByIndex(mapname, gc_gui_delimiterchar, gc_gui_quotechar, 6);
      [*] = ;                        sclientid2 := GetDelimiterStringByIndex(mapname, gc_gui_delimiterchar, gc_gui_quotechar, 7);
      [*] = ;                        stime := GetDelimiterStringByIndex(mapname, gc_gui_delimiterchar, gc_gui_quotechar, 8);
      [*] = ;                        sqpstate := GetDelimiterStringByIndex(mapname, gc_gui_delimiterchar, gc_gui_quotechar, 9);
      [*] = ;                     end;
      [*] = ;                     checksum := SubStr(roomchecksum, 2, 4);;
      [*] = ;                     var qpstate : Integer = StrToInt(sqpstate);
      [*] = ;                     if (qpstate>0) and ((checksum='') or (checksum=gstring_checksum)) then
      [*] = ;                     begin
      [*] = ;                        var masterid : Integer = TInternetShellSession(psession).masterid;
      [*] = ;                        var clientid1 : Integer = StrToInt(sclientid1);
      [*] = ;                        var clientid2 : Integer = StrToInt(sclientid2);
      [*] = ;                        var time : Integer = StrToInt(stime);
      [*] = ;                        var count : Integer;
      [*] = ;                        if not bexists and ((masterid=LanMyInfoID) or (clientid1=LanMyInfoID) or (clientid2=LanMyInfoID)) then
      [*] = ;                        bexists := True;
      [*] = ;                        if (masterid>0) then count := count+1;
      [*] = ;                        if (clientid1>0) then count := count+1;
      [*] = ;                        if (clientid2>0) then count := count+1;
      [*] = ;                        if (masterid<>0) and (count=TInternetShellSession(psession).clientscount) and (masterid=TInternetShellSession(psession).masterid) then
      [*] = ;                        begin
      [*] = ;                           if (count>=2) then
      [*] = ;                           begin
      [*] = ;                              gQuickPlay.AddSession(masterid, clientid1, clientid2, time);
      [*] = ;                              matchMaxTeam := Max(matchMaxTeam, count);
      [*] = ;                           end
      [*] = ;                           else
      [*] = ;                           gQuickPlay.AddPlayer(masterid, time, checksum);
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;         if (matchMaxTeam=1) then // no room found
      [*] = ;         matchMaxTeam := 3;
      [*] = ;
      [*] = ;         if (not bexists) then
      [*] = ;         gQuickPlay.AddPlayer(LanMyInfoID, floor(gInternetShell.autosearchtotaltime), gstring_checksum);
      [*] = ;
      [*] = ;         var minexistrank : Float = 10000;
      [*] = ;         var maxexistrank : Float;
      [*] = ;         if (gQuickPlay.count>=matchMaxPlayers) or (gQuickPlay.sessioncount>0) then
      [*] = ;         begin
      [*] = ;            // if we have team then limit min pvp team count to max session player size;
      [*] = ;            if (gQuickPlay.sessioncount=0) then
      [*] = ;            begin
      [*] = ;               var i : Integer;
      [*] = ;               for i:=gQuickPlay.count-1 downto 0 do
      [*] = ;               begin
      [*] = ;                  if (gQuickPlay.player[i].rank<minexistrank) then
      [*] = ;                  minexistrank := gQuickPlay.player[i].rank;
      [*] = ;                  if (gQuickPlay.player[i].rank>maxexistrank) then
      [*] = ;                  maxexistrank := gQuickPlay.player[i].rank;
      [*] = ;                  if gQuickPlay.player[i].waittime>=300 then
      [*] = ;                  matchMaxTeam := 1
      [*] = ;                  else
      [*] = ;                  if (matchMaxTeam>2) and (gQuickPlay.player[i].waittime>=200) then
      [*] = ;                  matchMaxTeam := 2;
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;
      [*] = ;            if (bForce2v2) then
      [*] = ;            matchMaxTeam := 1;
      [*] = ;
      [*] = ;            matchMaxPlayers := matchMaxTeam*2;
      [*] = ;
      [*] = ;            // find good players
      [*] = ;            const cMaxRankCount = 10;
      [*] = ;            var countteam1, countteam2 : Integer;
      [*] = ;            var arrplTeam1 : array [0..gc_quickplay_countofplayers6-1] of TIntegerList;
      [*] = ;            var arrplTeam2 : array [0..gc_quickplay_countofplayers6-1] of TIntegerList;
      [*] = ;            var arrpl : array [0..cMaxRankCount-1] of TIntegerList;
      [*] = ;            var arrplMakeMatch : array [0..gc_quickplay_countofplayers6-1] of Integer;
      [*] = ;            var bplMakeMatch : Boolean;
      [*] = ;
      [*] = ;            type TSessionRect = class
      [*] = ;               count : Integer;
      [*] = ;               player : array [0..(gc_quickplay_countofplayers6 div 2)-1] of Integer;
      [*] = ;               rect : TBox;
      [*] = ;            end;
      [*] = ;            var arrSession : array [0..64-1] of TSessionRect;
      [*] = ;            var rect : TBox;
      [*] = ;            var j, k, m, n, sind1, sind2, plind1, plind2 : Integer;
      [*] = ;            // cache sessions
      [*] = ;            if (not bForce2v2) and (gQuickPlay.sessioncount>0) then
      [*] = ;            begin
      [*] = ;               for i:=0 to gQuickPlay.sessioncount-1 do
      [*] = ;               begin
      [*] = ;                  countteam1 := 0;
      [*] = ;                  for k:=0 to (gc_quickplay_countofplayers6 div 2)-1 do
      [*] = ;                  begin
      [*] = ;                     var playerid : Integer = gQuickPlay.session[i].players[k].playerid;
      [*] = ;                     if (playerid<>0) then
      [*] = ;                     begin
      [*] = ;                        arrSession[i].player[k] := playerid;
      [*] = ;                        var rank : Float = gQuickPlay.session[i].players[k].rank;
      [*] = ;                        var timefactor : Integer = floor(gQuickPlay.session[i].players[k].waittime/waittimestep);
      [*] = ;                        var ranktolerance : Float;
      [*] = ;                        case timefactor of
      [*] = ;                           0,1 : ranktolerance := 0.5;
      [*] = ;                           2 : ranktolerance := 1;
      [*] = ;                           3,4,5,6 : ranktolerance := 2;
      [*] = ;                           7,8 : ranktolerance := 3;
      [*] = ;                           9  : ranktolerance := 4;
      [*] = ;                           10 : ranktolerance := 5;
      [*] = ;                           11 : ranktolerance := 6;
      [*] = ;                           12 : ranktolerance := 7;
      [*] = ;                           13 : ranktolerance := 8;
      [*] = ;                           14 : ranktolerance := 9;
      [*] = ;                           else
      [*] = ;                           ranktolerance := 10;
      [*] = ;                        end;
      [*] = ;                        var rankmin : Float = MaxFloat(0, rank-ranktolerance);
      [*] = ;                        var rankmax : Float = MinFloat(maxexistrank, rank+ranktolerance);
      [*] = ;                        case k of
      [*] = ;                           0 : begin arrSession[i].rect.minx := rankmin; arrSession[i].rect.maxx := rankmax; end;
      [*] = ;                           1 : begin arrSession[i].rect.miny := rankmin; arrSession[i].rect.maxy := rankmax; end;
      [*] = ;                           2 : begin arrSession[i].rect.minz := rankmin; arrSession[i].rect.maxz := rankmax; end;
      [*] = ;                        end;
      [*] = ;                        countteam1 := countteam1+1;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;                  arrSession[i].count := countteam1;
      [*] = ;               end;
      [*] = ;
      [*] = ;               for [MAIN]sind1:=0 to gQuickPlay.sessioncount do
      [*] = ;               for sind2:=(sind1+1) to gQuickPlay.sessioncount do
      [*] = ;               if (sind1<>sind2) or (sind1=gQuickPlay.sessioncount) or (sind2=gQuickPlay.sessioncount) then
      [*] = ;               begin
      [*] = ;                  //if (sind1<>gQuickPlay.sessioncount) and (sind2=gQuickPlay.sessioncount)
      [*] = ;                  var volumerect1, volume : Float;
      [*] = ;                  if (matchMaxTeam=2) then
      [*] = ;                  begin
      [*] = ;                     arrSession[sind1].rect.minz := 0;
      [*] = ;                     arrSession[sind1].rect.maxz := 1;
      [*] = ;                     arrSession[sind2].rect.minz := 0;
      [*] = ;                     arrSession[sind2].rect.maxz := 1;
      [*] = ;                  end;
      [*] = ;                  if (sind1<gQuickPlay.sessioncount) and (sind2<gQuickPlay.sessioncount) and (arrSession[sind1].count=matchMaxTeam) and (arrSession[sind2].count=matchMaxTeam) then
      [*] = ;                  begin
      [*] = ;                     _misc_IntersectBox(arrSession[sind1].rect, arrSession[sind2].rect, rect);
      [*] = ;                     volumerect1 := _misc_GetBoxVolume(arrSession[sind1].rect);
      [*] = ;                     volume := _misc_GetBoxVolume(rect);
      [*] = ;
      [*] = ;                     if (gbool_lan_debug) and (volumerect1>0) then
      [*] = ;                     Log('1 : matchMaxTeam = '+IntToStr(matchMaxTeam)+' : volume/volumerect1 = '+FloatToStr(volume/volumerect1));
      [*] = ;                     if matchMaxTeam=3 then
      [*] = ;                     begin
      [*] = ;                        if (volumerect1>0) and ((volume/volumerect1)>0.3) then
      [*] = ;                        begin
      [*] = ;                           bplMakeMatch := True;
      [*] = ;                           arrplMakeMatch[0] := arrSession[sind1].player[0];
      [*] = ;                           arrplMakeMatch[1] := arrSession[sind1].player[1];
      [*] = ;                           arrplMakeMatch[2] := arrSession[sind1].player[2];
      [*] = ;                           arrplMakeMatch[3] := arrSession[sind2].player[0];
      [*] = ;                           arrplMakeMatch[4] := arrSession[sind2].player[1];
      [*] = ;                           arrplMakeMatch[5] := arrSession[sind2].player[2];
      [*] = ;                           break(MAIN);
      [*] = ;                        end
      [*] = ;                     end
      [*] = ;                     else
      [*] = ;                     if matchMaxTeam=2 then
      [*] = ;                     begin
      [*] = ;                        if (volumerect1>0) and ((volume/volumerect1)>0.3) then
      [*] = ;                        begin
      [*] = ;                           bplMakeMatch := True;
      [*] = ;                           arrplMakeMatch[0] := arrSession[sind1].player[0];
      [*] = ;                           arrplMakeMatch[1] := arrSession[sind1].player[1];
      [*] = ;                           arrplMakeMatch[2] := arrSession[sind2].player[0];
      [*] = ;                           arrplMakeMatch[3] := arrSession[sind2].player[1];
      [*] = ;                           break(MAIN);
      [*] = ;                        end
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;                  for plind1:=0 to gQuickPlay.count-1 do
      [*] = ;                  for plind2:=0 to gQuickPlay.count-1 do
      [*] = ;                  if (plind1=0) or (plind1<>plind2) then
      [*] = ;                  begin
      [*] = ;                     var bpl1used : Boolean;
      [*] = ;                     // fill not full teams but dont increase session count
      [*] = ;                     if (sind1<gQuickPlay.sessioncount) and (arrSession[sind1].count<matchMaxTeam) then
      [*] = ;                     begin
      [*] = ;                        var playerid : Integer = gQuickPlay.player[plind1].playerid;
      [*] = ;                        if (playerid<>0) then
      [*] = ;                        begin
      [*] = ;                           if (plind1=0) then
      [*] = ;                           bpl1used := True;
      [*] = ;                           arrSession[sind1].player[matchMaxTeam-1] := playerid;
      [*] = ;                           var rank : Float = gQuickPlay.player[plind1].rank;
      [*] = ;                           var timefactor : Integer = floor(gQuickPlay.player[plind1].waittime/waittimestep);
      [*] = ;                           var ranktolerance : Float;
      [*] = ;                           case timefactor of
      [*] = ;                              0,1 : ranktolerance := 0.5;
      [*] = ;                              2 : ranktolerance := 1;
      [*] = ;                              3,4,5,6 : ranktolerance := 2;
      [*] = ;                              7,8 : ranktolerance := 3;
      [*] = ;                              9  : ranktolerance := 4;
      [*] = ;                              10 : ranktolerance := 5;
      [*] = ;                              11 : ranktolerance := 6;
      [*] = ;                              12 : ranktolerance := 7;
      [*] = ;                              13 : ranktolerance := 8;
      [*] = ;                              14 : ranktolerance := 9;
      [*] = ;                              else
      [*] = ;                              ranktolerance := 10;
      [*] = ;                           end;
      [*] = ;                           var rankmin : Float = MaxFloat(0, rank-ranktolerance);
      [*] = ;                           var rankmax : Float = MinFloat(maxexistrank, rank+ranktolerance);
      [*] = ;                           if (matchMaxTeam=3) then
      [*] = ;                           begin
      [*] = ;                              arrSession[sind1].rect.minz := rankmin;
      [*] = ;                              arrSession[sind1].rect.maxz := rankmax;
      [*] = ;                           end
      [*] = ;                           else
      [*] = ;                           begin
      [*] = ;                              arrSession[sind1].rect.miny := rankmin;
      [*] = ;                              arrSession[sind1].rect.maxy := rankmax;
      [*] = ;                           end;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                     if ((plind1<>plind2) or (not bpl1used)) and (sind2<gQuickPlay.sessioncount) and (arrSession[sind2].count<matchMaxTeam) then
      [*] = ;                     begin
      [*] = ;                        var playerid : Integer = gQuickPlay.player[plind2].playerid;
      [*] = ;                        if (playerid<>0) then
      [*] = ;                        begin
      [*] = ;                           arrSession[sind2].player[matchMaxTeam-1] := playerid;
      [*] = ;                           var rank : Float = gQuickPlay.player[plind2].rank;
      [*] = ;                           var timefactor : Integer = floor(gQuickPlay.player[plind2].waittime/waittimestep);
      [*] = ;                           var ranktolerance : Float;
      [*] = ;                           case timefactor of
      [*] = ;                              0,1 : ranktolerance := 0.5;
      [*] = ;                              2 : ranktolerance := 1;
      [*] = ;                              3,4,5,6 : ranktolerance := 2;
      [*] = ;                              7,8 : ranktolerance := 3;
      [*] = ;                              9  : ranktolerance := 4;
      [*] = ;                              10 : ranktolerance := 5;
      [*] = ;                              11 : ranktolerance := 6;
      [*] = ;                              12 : ranktolerance := 7;
      [*] = ;                              13 : ranktolerance := 8;
      [*] = ;                              14 : ranktolerance := 9;
      [*] = ;                              else
      [*] = ;                              ranktolerance := 10;
      [*] = ;                           end;
      [*] = ;                           var rankmin : Float = MaxFloat(0, rank-ranktolerance);
      [*] = ;                           var rankmax : Float = MinFloat(maxexistrank, rank+ranktolerance);
      [*] = ;                           if (matchMaxTeam=3) then
      [*] = ;                           begin
      [*] = ;                              arrSession[sind2].rect.minz := rankmin;
      [*] = ;                              arrSession[sind2].rect.maxz := rankmax;
      [*] = ;                           end
      [*] = ;                           else
      [*] = ;                           begin
      [*] = ;                              arrSession[sind2].rect.miny := rankmin;
      [*] = ;                              arrSession[sind2].rect.maxy := rankmax;
      [*] = ;                           end;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                     var volumerect1, volume : Float;
      [*] = ;
      [*] = ;                     if (matchMaxTeam=2) then
      [*] = ;                     begin
      [*] = ;                        arrSession[sind1].rect.minz := 0;
      [*] = ;                        arrSession[sind1].rect.maxz := 1;
      [*] = ;                        arrSession[sind2].rect.minz := 0;
      [*] = ;                        arrSession[sind2].rect.maxz := 1;
      [*] = ;                     end;
      [*] = ;                     if (sind1<gQuickPlay.sessioncount) and (sind2<gQuickPlay.sessioncount) then
      [*] = ;                     begin
      [*] = ;                        _misc_IntersectBox(arrSession[sind1].rect, arrSession[sind2].rect, rect);
      [*] = ;                        volumerect1 := _misc_GetBoxVolume(arrSession[sind1].rect);
      [*] = ;                        volume := _misc_GetBoxVolume(rect);
      [*] = ;                     end;
      [*] = ;                     if (gbool_lan_debug) and (volumerect1>0) then
      [*] = ;                     Log('2 : matchMaxTeam = '+IntToStr(matchMaxTeam)+' : volume/volumerect1 = '+FloatToStr(volume/volumerect1));
      [*] = ;                     if matchMaxTeam=3 then
      [*] = ;                     begin
      [*] = ;                        if (volumerect1>0) and ((volume/volumerect1)>0.3) then
      [*] = ;                        begin
      [*] = ;                           bplMakeMatch := True;
      [*] = ;                           arrplMakeMatch[0] := arrSession[sind1].player[0];
      [*] = ;                           arrplMakeMatch[1] := arrSession[sind1].player[1];
      [*] = ;                           arrplMakeMatch[2] := arrSession[sind1].player[2];
      [*] = ;                           arrplMakeMatch[3] := arrSession[sind2].player[0];
      [*] = ;                           arrplMakeMatch[4] := arrSession[sind2].player[1];
      [*] = ;                           arrplMakeMatch[5] := arrSession[sind2].player[2];
      [*] = ;                           break(MAIN);
      [*] = ;                        end
      [*] = ;                     end
      [*] = ;                     else
      [*] = ;                     if matchMaxTeam=2 then
      [*] = ;                     begin
      [*] = ;                        if (volumerect1>0) and ((volume/volumerect1)>0.3) then
      [*] = ;                        begin
      [*] = ;                           bplMakeMatch := True;
      [*] = ;                           arrplMakeMatch[0] := arrSession[sind1].player[0];
      [*] = ;                           arrplMakeMatch[1] := arrSession[sind1].player[1];
      [*] = ;                           arrplMakeMatch[2] := arrSession[sind2].player[0];
      [*] = ;                           arrplMakeMatch[3] := arrSession[sind2].player[1];
      [*] = ;                           break(MAIN);
      [*] = ;                        end
      [*] = ;                     end;
      [*] = ;
      [*] = ;                     if (sind1<gQuickPlay.sessioncount) and (sind2=gQuickPlay.sessioncount) then // no proper team 2 found, try to collide with random players
      [*] = ;                     begin
      [*] = ;                        arrplMakeMatch[0] := arrSession[sind1].player[0];
      [*] = ;                        arrplMakeMatch[1] := arrSession[sind1].player[1];
      [*] = ;                        if matchMaxTeam=3 then
      [*] = ;                        arrplMakeMatch[2] := arrSession[sind1].player[2];
      [*] = ;
      [*] = ;                        arrSession[gQuickPlay.sessioncount].player[1] := gQuickPlay.player[plind2].playerid;
      [*] = ;                        var rank : Float = gQuickPlay.player[plind2].rank;
      [*] = ;                        var timefactor : Integer = floor(gQuickPlay.player[plind2].waittime/waittimestep);
      [*] = ;                        var ranktolerance : Float;
      [*] = ;                        case timefactor of
      [*] = ;                           0,1 : ranktolerance := 0.5;
      [*] = ;                           2 : ranktolerance := 1;
      [*] = ;                           3,4,5,6 : ranktolerance := 2;
      [*] = ;                           7,8 : ranktolerance := 3;
      [*] = ;                           9  : ranktolerance := 4;
      [*] = ;                           10 : ranktolerance := 5;
      [*] = ;                           11 : ranktolerance := 6;
      [*] = ;                           12 : ranktolerance := 7;
      [*] = ;                           13 : ranktolerance := 8;
      [*] = ;                           14 : ranktolerance := 9;
      [*] = ;                           else
      [*] = ;                           ranktolerance := 10;
      [*] = ;                        end;
      [*] = ;                        var rankmin : Float = MaxFloat(0, rank-ranktolerance);
      [*] = ;                        var rankmax : Float = MinFloat(maxexistrank, rank+ranktolerance);
      [*] = ;                        arrSession[gQuickPlay.sessioncount].rect.miny := rankmin;
      [*] = ;                        arrSession[gQuickPlay.sessioncount].rect.maxy := rankmax;
      [*] = ;
      [*] = ;                        if matchMaxTeam=3 then
      [*] = ;                        begin
      [*] = ;                           var plind1a, plind3 : Integer;
      [*] = ;                           for plind1a:=0 to gQuickPlay.count-1 do
      [*] = ;                           if (plind1a<>plind2) then
      [*] = ;                           begin
      [*] = ;                              var playerid : Integer = gQuickPlay.player[plind1a].playerid;
      [*] = ;                              var rank : Float = gQuickPlay.player[plind1a].rank;
      [*] = ;                              var timefactor : Integer = floor(gQuickPlay.player[plind1a].waittime/waittimestep);
      [*] = ;                              var ranktolerance : Float;
      [*] = ;                              case timefactor of
      [*] = ;                                 0,1 : ranktolerance := 0.5;
      [*] = ;                                 2 : ranktolerance := 1;
      [*] = ;                                 3,4,5,6 : ranktolerance := 2;
      [*] = ;                                 7,8 : ranktolerance := 3;
      [*] = ;                                 9  : ranktolerance := 4;
      [*] = ;                                 10 : ranktolerance := 5;
      [*] = ;                                 11 : ranktolerance := 6;
      [*] = ;                                 12 : ranktolerance := 7;
      [*] = ;                                 13 : ranktolerance := 8;
      [*] = ;                                 14 : ranktolerance := 9;
      [*] = ;                                 else
      [*] = ;                                 ranktolerance := 10;
      [*] = ;                              end;
      [*] = ;                              var rankmin : Float = MaxFloat(0, rank-ranktolerance);
      [*] = ;                              var rankmax : Float = MinFloat(maxexistrank, rank+ranktolerance);
      [*] = ;                              arrSession[gQuickPlay.sessioncount].player[0] := playerid;
      [*] = ;                              arrSession[gQuickPlay.sessioncount].rect.minx := rankmin;
      [*] = ;                              arrSession[gQuickPlay.sessioncount].rect.maxx := rankmax;
      [*] = ;
      [*] = ;                              for plind3:=0 to gQuickPlay.count-1 do
      [*] = ;                              if (plind1a<>plind2) and (plind1a<>plind3) and (plind2<>plind3) and (plind1a<>plind3) then
      [*] = ;                              begin
      [*] = ;                                 var playerid : Integer = gQuickPlay.player[plind3].playerid;
      [*] = ;                                 var rank : Float = gQuickPlay.player[plind3].rank;
      [*] = ;                                 var timefactor : Integer = floor(gQuickPlay.player[plind3].waittime/waittimestep);
      [*] = ;                                 var ranktolerance : Float;
      [*] = ;                                 case timefactor of
      [*] = ;                                    0,1 : ranktolerance := 0.5;
      [*] = ;                                    2 : ranktolerance := 1;
      [*] = ;                                    3,4,5,6 : ranktolerance := 2;
      [*] = ;                                    7,8 : ranktolerance := 3;
      [*] = ;                                    9  : ranktolerance := 4;
      [*] = ;                                    10 : ranktolerance := 5;
      [*] = ;                                    11 : ranktolerance := 6;
      [*] = ;                                    12 : ranktolerance := 7;
      [*] = ;                                    13 : ranktolerance := 8;
      [*] = ;                                    14 : ranktolerance := 9;
      [*] = ;                                    else
      [*] = ;                                    ranktolerance := 10;
      [*] = ;                                 end;
      [*] = ;                                 var rankmin : Float = MaxFloat(0, rank-ranktolerance);
      [*] = ;                                 var rankmax : Float = MinFloat(maxexistrank, rank+ranktolerance);
      [*] = ;                                 arrSession[gQuickPlay.sessioncount].player[2] := playerid;
      [*] = ;                                 arrSession[gQuickPlay.sessioncount].rect.minz := rankmin;
      [*] = ;                                 arrSession[gQuickPlay.sessioncount].rect.maxz := rankmax;
      [*] = ;
      [*] = ;                                 var volumerect1, volume : Float;
      [*] = ;                                 _misc_IntersectBox(arrSession[sind1].rect, arrSession[gQuickPlay.sessioncount].rect, rect);
      [*] = ;                                 volumerect1 := _misc_GetBoxVolume(arrSession[sind1].rect);
      [*] = ;                                 volume := _misc_GetBoxVolume(rect);
      [*] = ;                                 if (gbool_lan_debug) and (volumerect1>0) then
      [*] = ;                                 Log('3 : matchMaxTeam = '+IntToStr(matchMaxTeam)+' : volume/volumerect1 = '+FloatToStr(volume/volumerect1));
      [*] = ;                                 if (volumerect1>0) and ((volume/volumerect1)>0.3) then
      [*] = ;                                 begin
      [*] = ;                                    bplMakeMatch := True;
      [*] = ;                                    arrplMakeMatch[3] := arrSession[gQuickPlay.sessioncount].player[0];
      [*] = ;                                    arrplMakeMatch[4] := arrSession[gQuickPlay.sessioncount].player[1];
      [*] = ;                                    arrplMakeMatch[5] := arrSession[gQuickPlay.sessioncount].player[2];
      [*] = ;                                    break(MAIN);
      [*] = ;                                 end
      [*] = ;                              end;
      [*] = ;                           end;
      [*] = ;                        end
      [*] = ;                        else
      [*] = ;                        begin
      [*] = ;                           var plind1a : Integer;
      [*] = ;                           for plind1a:=0 to gQuickPlay.count-1 do
      [*] = ;                           if (plind1a<>plind2) then
      [*] = ;                           begin
      [*] = ;                              var playerid : Integer = gQuickPlay.player[plind1a].playerid;
      [*] = ;                              var rank : Float = gQuickPlay.player[plind1a].rank;
      [*] = ;                              var timefactor : Integer = floor(gQuickPlay.player[plind1a].waittime/waittimestep);
      [*] = ;                              var ranktolerance : Float;
      [*] = ;                              case timefactor of
      [*] = ;                                 0,1 : ranktolerance := 0.5;
      [*] = ;                                 2 : ranktolerance := 1;
      [*] = ;                                 3,4,5,6 : ranktolerance := 2;
      [*] = ;                                 7,8 : ranktolerance := 3;
      [*] = ;                                 9  : ranktolerance := 4;
      [*] = ;                                 10 : ranktolerance := 5;
      [*] = ;                                 11 : ranktolerance := 6;
      [*] = ;                                 12 : ranktolerance := 7;
      [*] = ;                                 13 : ranktolerance := 8;
      [*] = ;                                 14 : ranktolerance := 9;
      [*] = ;                                 else
      [*] = ;                                 ranktolerance := 10;
      [*] = ;                              end;
      [*] = ;                              var rankmin : Float = MaxFloat(0, rank-ranktolerance);
      [*] = ;                              var rankmax : Float = MinFloat(maxexistrank, rank+ranktolerance);
      [*] = ;                              arrSession[gQuickPlay.sessioncount].player[0] := playerid;
      [*] = ;                              arrSession[gQuickPlay.sessioncount].rect.minx := rankmin;
      [*] = ;                              arrSession[gQuickPlay.sessioncount].rect.maxx := rankmax;
      [*] = ;                           end;
      [*] = ;                           if (gbool_lan_debug) and (arrSession[gQuickPlay.sessioncount].rect.maxz<>1) then
      [*] = ;                           ErrorLog('arrSession[gQuickPlay.sessioncount].rect.maxz<>1');
      [*] = ;                           arrSession[gQuickPlay.sessioncount].rect.minz := 0;
      [*] = ;                           arrSession[gQuickPlay.sessioncount].rect.maxz := 1;
      [*] = ;
      [*] = ;                           var volumerect1, volume : Float;
      [*] = ;                           _misc_IntersectBox(arrSession[sind1].rect, arrSession[gQuickPlay.sessioncount].rect, rect);
      [*] = ;                           volumerect1 := _misc_GetBoxVolume(arrSession[sind1].rect);
      [*] = ;                           volume := _misc_GetBoxVolume(rect);
      [*] = ;                           if (gbool_lan_debug) and (volumerect1>0) then
      [*] = ;                           Log('4 : matchMaxTeam = '+IntToStr(matchMaxTeam)+' : volume/volumerect1 = '+FloatToStr(volume/volumerect1));
      [*] = ;                           if (volumerect1>0) and ((volume/volumerect1)>0.3) then
      [*] = ;                           begin
      [*] = ;                              bplMakeMatch := True;
      [*] = ;                              arrplMakeMatch[2] := arrSession[gQuickPlay.sessioncount].player[0];
      [*] = ;                              arrplMakeMatch[3] := arrSession[gQuickPlay.sessioncount].player[1];
      [*] = ;                              break(MAIN);
      [*] = ;                           end
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;
      [*] = ;                     if (sind1=gQuickPlay.sessioncount) and (sind2=gQuickPlay.sessioncount) then // search just for random players
      [*] = ;                     begin
      [*] = ;                        break(MAIN);
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;
      [*] = ;            var arrused : TIntegerList;
      [*] = ;            var tries : Integer;
      [*] = ;            //for tries to 3 do
      [*] = ;            begin
      [*] = ;               for j:=0 to cMaxRankCount-1 do
      [*] = ;               arrpl[j].Clear;
      [*] = ;               // random vs random
      [*] = ;               if (not bplMakeMatch) then
      [*] = ;               begin
      [*] = ;                  var plmakematchind : Integer;
      [*] = ;                  for i:=0 to gc_quickplay_countofplayers6-1 do
      [*] = ;                  arrplMakeMatch[i] := 0;
      [*] = ;                  for i:=0 to gQuickPlay.count-1 do
      [*] = ;                  begin
      [*] = ;                     var playerid : Integer = gQuickPlay.player[i].playerid;
      [*] = ;                     if (arrused.IndexOf(playerid)<0) then
      [*] = ;                     begin
      [*] = ;                        var time : Integer = Round(gQuickPlay.player[i].waittime);
      [*] = ;                        if time=0 then // skip first iteration of qs
      [*] = ;                        continue;
      [*] = ;                        var rank : Float = gQuickPlay.player[i].rank;
      [*] = ;                        var timefactor : Integer = time div waittimestep;
      [*] = ;                        var ranktolerance : Integer;
      [*] = ;                        case timefactor of
      [*] = ;                           0,1,2 : ranktolerance := 0;
      [*] = ;                           3,4,5 : ranktolerance := 1;
      [*] = ;                           6,7 : ranktolerance := 2;
      [*] = ;                           8,9 : ranktolerance := 3;
      [*] = ;                           10,11 : ranktolerance := 4;
      [*] = ;                           12  : ranktolerance := 5;
      [*] = ;                           13  : ranktolerance := 6;
      [*] = ;                           14  : ranktolerance := 7;
      [*] = ;                           15  : ranktolerance := 8;
      [*] = ;                           16  : ranktolerance := 9;
      [*] = ;                           else
      [*] = ;                           ranktolerance := 10;
      [*] = ;                        end;
      [*] = ;                        var rankmin : Integer = floor(MaxFloat(0, floor(rank-ranktolerance)));
      [*] = ;                        var rankmax : Integer = floor(MinFloat(maxexistrank, floor(rank+ranktolerance)));
      [*] = ;                        var j : Integer;
      [*] = ;                        for j:=rankmin to rankmax do
      [*] = ;                        arrpl[j].Add(i);
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;                  // sort also by wait time
      [*] = ;                  var arrmatch : TIntegerList;
      [*] = ;                  var rank : Integer;
      [*] = ;                  for [MAIN]rank:=cMaxRankCount-1 downto 0 do
      [*] = ;                  begin
      [*] = ;                     if (arrpl[rank].GetCount>=matchMaxPlayers) then
      [*] = ;                     begin
      [*] = ;                        for plmakematchind:=0 to matchMaxPlayers-1 do
      [*] = ;                        begin
      [*] = ;                           var sum : Float;
      [*] = ;                           for i:=arrpl[rank].GetCount-1 downto 0 do
      [*] = ;                           begin
      [*] = ;                              var plind : Integer = arrpl[rank].Get(i);
      [*] = ;                              var playerid : Integer = gQuickPlay.player[plind].playerid;
      [*] = ;                              if (arrused.IndexOf(playerid)<0) then
      [*] = ;                              sum := sum+gQuickPlay.player[plind].weight+(cMaxRankCount*2-Abs(gQuickPlay.player[plind].rank-rank)*2);
      [*] = ;                           end;
      [*] = ;                           var rnd : Float = random*sum;
      [*] = ;                           sum := 0;
      [*] = ;                           for i:=arrpl[rank].GetCount-1 downto 0 do
      [*] = ;                           begin
      [*] = ;                              var plind : Integer = arrpl[rank].Get(i);
      [*] = ;                              var playerid : Integer = gQuickPlay.player[plind].playerid;
      [*] = ;                              if (arrused.IndexOf(playerid)<0) then
      [*] = ;                              begin
      [*] = ;                                 sum := sum+gQuickPlay.player[plind].weight+(cMaxRankCount*2-Abs(gQuickPlay.player[plind].rank-rank)*2);
      [*] = ;                                 if sum>=rnd then
      [*] = ;                                 begin
      [*] = ;                                    arrplMakeMatch[plmakematchind] := playerid;
      [*] = ;                                    arrused.Add(playerid);
      [*] = ;                                    break;
      [*] = ;                                 end;
      [*] = ;                              end;
      [*] = ;                           end;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;
      [*] = ;                  var count : Integer = arrmatch.GetCount;
      [*] = ;                  if (count=matchMaxPlayers) then
      [*] = ;                  begin
      [*] = ;                     var rndarrmatch : TIntegerList;
      [*] = ;                     for i:=count-1 downto 0 do
      [*] = ;                     begin
      [*] = ;                        var rndind : Integer = floor(random*arrmatch.GetCount);
      [*] = ;                        var rndid : Integer = arrmatch.Get(rndind);
      [*] = ;                        rndarrmatch.Add(rndid);
      [*] = ;                        arrmatch.Delete(rndind);
      [*] = ;                        arrplMakeMatch[i] := rndid;
      [*] = ;                     end;
      [*] = ;                     bplMakeMatch := True;
      [*] = ;                  end;
      [*] = ;               end;
      [*] = ;               var count : Integer;
      [*] = ;               for i:=0 to matchMaxPlayers-1 do
      [*] = ;               begin
      [*] = ;                  if arrplMakeMatch[i]>0 then
      [*] = ;                  begin
      [*] = ;                     count := count+1;
      [*] = ;                     if count=matchMaxPlayers then
      [*] = ;                     begin
      [*] = ;                        bplMakeMatch := True;
      [*] = ;                        break;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;               end;
      [*] = ;
      [*] = ;               //var approxtime : Integer;
      [*] = ;               if (bplMakeMatch) and (count=matchMaxPlayers) then
      [*] = ;               begin
      [*] = ;                  var masterind : Integer;
      [*] = ;                  var minram : Integer = 10000;
      [*] = ;                  var maxram : Integer;
      [*] = ;                  var sumram : Integer;
      [*] = ;                  for i:=0 to count-1 do
      [*] = ;                  begin
      [*] = ;                     var pclient : Pointer = gInternetShell.clients.GetByLanID(arrplMakeMatch[i]);
      [*] = ;                     if (pclient<>nil) then
      [*] = ;                     begin
      [*] = ;                        var ram : Integer = TInternetShellClient(pclient).ram;
      [*] = ;                        if (ram>maxram) then
      [*] = ;                        maxram := ram;
      [*] = ;                        if (ram<minram) then
      [*] = ;                        minram := ram;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;                  for i:=0 to count-1 do
      [*] = ;                  begin
      [*] = ;                     var pclient : Pointer = gInternetShell.clients.GetByLanID(arrplMakeMatch[i]);
      [*] = ;                     if (pclient<>nil) then
      [*] = ;                     begin
      [*] = ;                        var ram : Integer = TInternetShellClient(pclient).ram;
      [*] = ;                        if (maxram>=12) and (ram>=12) then
      [*] = ;                        sumram := sumram+ram
      [*] = ;                        else
      [*] = ;                        if (maxram>=8) and (ram>=8) then
      [*] = ;                        sumram := sumram+ram
      [*] = ;                        else
      [*] = ;                        if (maxram>=4) and (ram>=4) then
      [*] = ;                        sumram := sumram+ram
      [*] = ;                        else
      [*] = ;                        if (maxram>=3) and (ram>=3) then
      [*] = ;                        sumram := sumram+ram
      [*] = ;                        else
      [*] = ;                        sumram := sumram+ram;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;                  var rndram : Float = random*sumram;
      [*] = ;                  sumram := 0;
      [*] = ;                  for i:=0 to count-1 do
      [*] = ;                  begin
      [*] = ;                     var pclient : Pointer = gInternetShell.clients.GetByLanID(arrplMakeMatch[i]);
      [*] = ;                     if (pclient<>nil) then
      [*] = ;                     begin
      [*] = ;                        var ram : Integer = TInternetShellClient(pclient).ram;
      [*] = ;                        if (maxram>=12) and (ram>=12) then
      [*] = ;                        sumram := sumram+ram
      [*] = ;                        else
      [*] = ;                        if (maxram>=8) and (ram>=8) then
      [*] = ;                        sumram := sumram+ram
      [*] = ;                        else
      [*] = ;                        if (maxram>=4) and (ram>=4) then
      [*] = ;                        sumram := sumram+ram
      [*] = ;                        else
      [*] = ;                        if (maxram>=3) and (ram>=3) then
      [*] = ;                        sumram := sumram+ram
      [*] = ;                        else
      [*] = ;                        sumram := sumram+ram;
      [*] = ;                        if sumram>=rndram then
      [*] = ;                        begin
      [*] = ;                           masterind := i;
      [*] = ;                           break;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;
      [*] = ;                  var masterid : Integer = arrplMakeMatch[masterind];
      [*] = ;
      [*] = ;                  var matchcode : String;
      [*] = ;                  if gInternetShell.qprankedgame then
      [*] = ;                  matchcode := 'qp='
      [*] = ;                  else
      [*] = ;                  matchcode := 'qt=';
      [*] = ;
      [*] = ;                  var matchname : String = matchcode+IntToStr(masterid);
      [*] = ;                  var bIAmMentioned : Boolean = (masterid=LanMyInfoID);
      [*] = ;                  for i:=0 to count-1 do
      [*] = ;                  begin
      [*] = ;                     if (i<>masterind) then
      [*] = ;                     begin
      [*] = ;                        matchname := matchname+gc_gui_dotcharstr;
      [*] = ;                        var playerid : Integer = arrplMakeMatch[i];
      [*] = ;                        if (playerid>0) then
      [*] = ;                        begin
      [*] = ;                           matchname := matchname+IntToStr(playerid);
      [*] = ;                           bIAmMentioned := bIAmMentioned or (playerid=LanMyInfoID);
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;                  if (gbool_lan_debug) then
      [*] = ;                  log('send from '+IntToStr(LanMyInfoID)+' to '+IntToStr(masterid)+' msg = '+matchname);
      [*] = ;                  LanPublicServerSendMessage(masterid, #9+matchname);
      [*] = ;                  Result := bIAmMentioned;
      [*] = ;               end;
      [*] = ;               bplMakeMatch := False;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;   end;
      [*] = ;end;
      [*] = ;
      [*] = ;procedure SetupTime(var time : Float);
      [*] = ;begin
      [*] = ;   if time=0 then
      [*] = ;   time := _misc_GetRealTime;
      [*] = ;end;
      [*] = ;
      [*] = ;function CheckTime(var time : Float) : Boolean;
      [*] = ;begin
      [*] = ;   Result := (time>0) and ((_misc_GetRealTime-time)>0.5);
      [*] = ;   if Result then
      [*] = ;   time := 0;
      [*] = ;end;
      [*] = ;
      [*] = ;if (IsLanPublicServerMode) and (gInternetShell.qprequeststart>0) and (gMap.gamestage<>gc_map_gamestage_none) then
      [*] = ;begin
      [*] = ;   ErrorLog('gMap.gamestage<>gc_map_gamestage_none on cTagStartAutoSearch in EventCustomGame; _net_IsOnline = '+BoolToStr(gbool_lan_isonlinecached));
      [*] = ;   if (not gbool_lan_isonlinecached) then
      [*] = ;   gMap.gamestage := gc_map_gamestage_none;
      [*] = ;end;
      [*] = ;
      [*] = ;var binqsroom, binqproom, bincustomroom : Boolean;
      [*] = ;var validroomid, validroomplcount : Integer;
      [*] = ;if ((gInternetShell.bautosearch) or (gInternetShell.bcustomautosearch)) and (gMap.gamestage=gc_map_gamestage_none) then
      [*] = ;begin
      [*] = ;   var i : Integer;
      [*] = ;   for [MAIN]i:=gInternetShell.sessions.GetCount-1 downto 0 do
      [*] = ;   begin
      [*] = ;      var psession : Pointer = gInternetShell.sessions.Get(i);
      [*] = ;      if (psession<>nil) then
      [*] = ;      begin
      [*] = ;         var visiblename, pass, roomchecksum : String;
      [*] = ;         _misc_GetGameNameAndPasswordBySession(psession, visiblename, pass, roomchecksum);
      [*] = ;         if (not TInternetShellSession(psession).blocked) then
      [*] = ;         begin
      [*] = ;            if (pass=gc_quickplay_roompass) then
      [*] = ;            begin
      [*] = ;               var code : String = SubStr(visiblename, 0, 3);
      [*] = ;               var searchcode : String;
      [*] = ;               if gInternetShell.qprankedgame then
      [*] = ;               searchcode := 'qp='
      [*] = ;               else
      [*] = ;               searchcode := 'qt=';
      [*] = ;               if (code=searchcode) then // quick play - finally found quickplay match with ids of participants
      [*] = ;               begin
      [*] = ;                  var str : String = SubStr(visiblename, 4, StrLength(visiblename)-3);
      [*] = ;                  if IsDelimiterCharExists(str, gc_gui_dotchar) then
      [*] = ;                  begin
      [*] = ;                     var masterid : Integer = StrToInt(GetDelimiterStringByIndex(str, gc_gui_dotchar, gc_gui_quotechar, 0));
      [*] = ;                     if masterid>0 then
      [*] = ;                     begin
      [*] = ;                        validroomplcount := GetDelimiterStringCount(str, gc_gui_dotchar, gc_gui_quotechar);
      [*] = ;                        var j : Integer;
      [*] = ;                        for j:=0 to validroomplcount-1 do
      [*] = ;                        begin
      [*] = ;                           var num : Integer = StrToInt(GetDelimiterStringByIndex(str, gc_gui_dotchar, gc_gui_quotechar, j));
      [*] = ;                           if (num=LanMyInfoID) then
      [*] = ;                           begin
      [*] = ;                              validroomid := masterid;
      [*] = ;                              if (j<(validroomplcount div 2)) then
      [*] = ;                              gInternetShell.autosearchteam := 1
      [*] = ;                              else
      [*] = ;                              gInternetShell.autosearchteam := 2;
      [*] = ;                              break(MAIN);
      [*] = ;                           end;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;               end
      [*] = ;               else
      [*] = ;               begin
      [*] = ;                  if gInternetShell.qprankedgame then
      [*] = ;                  searchcode := 'qs='
      [*] = ;                  else
      [*] = ;                  searchcode := 'qz=';
      [*] = ;                  if (code=searchcode) then
      [*] = ;                  begin
      [*] = ;                     var str : String = SubStr(visiblename, 4, StrLength(visiblename)-3);
      [*] = ;                     if IsDelimiterCharExists(str, gc_gui_dotchar) then
      [*] = ;                     begin
      [*] = ;                        var masterid : Integer = StrToInt(GetDelimiterStringByIndex(str, gc_gui_dotchar, gc_gui_quotechar, 0));
      [*] = ;                        if (masterid=LanMyInfoID) then
      [*] = ;                        begin
      [*] = ;                           binqsroom := True;
      [*] = ;                        end;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;   end;
      [*] = ;end;
      [*] = ;
      [*] = ;const quickplaytimestep = 25;
      [*] = ;var bLanIdle : Boolean = True;
      [*] = ;if (IsLanPublicServerMode) and (gMap.gamestage=gc_map_gamestage_none) then
      [*] = ;begin
      [*] = ;   bLanIdle := (gInternetShell.qprequestsleep=0)
      [*] = ;   and (gInternetShell.qprequeststartgame=0)
      [*] = ;   and (gInternetShell.qprequeststop=0)
      [*] = ;   and (gInternetShell.qprequestmakematch=0)
      [*] = ;   and (gInternetShell.qprequestterminate=0)
      [*] = ;   //and (gInternetShell.qprequestcloseroom=0) // do not pay attention here
      [*] = ;   and (gInternetShell.qprequeststart=0)
      [*] = ;   and (gInternetShell.qprequestsign=0);
      [*] = ;
      [*] = ;   if (gInternetShell.qprequestsleep>0) then
      [*] = ;   begin
      [*] = ;      if (Abs(_misc_GetRealTime-gInternetShell.qprequestsleep)>2) then
      [*] = ;      gInternetShell.qprequestsleep := 0;
      [*] = ;   end
      [*] = ;   else
      [*] = ;   if (CheckTime(gInternetShell.qprequeststartgame)) then
      [*] = ;   begin
      [*] = ;      if (gbool_lan_isonlinecached) and (gInternetShell.currentsessionid=validroomid) then
      [*] = ;      begin
      [*] = ;         if (gbool_lan_debug) then
      [*] = ;         TimeLog('gInternetShell.qprequeststartgame');
      [*] = ;         var qproomplcount : Integer = gInternetShell.qprequeststartgameplcount;
      [*] = ;         var visiblename : String = gInternetShell.qprequeststartgamename;
      [*] = ;         gInternetShell.qprequeststartgameplcount := 0;
      [*] = ;         gInternetShell.qprequeststartgamename := '';
      [*] = ;         if (LanGetClientsCount=qproomplcount) and (visiblename<>'') then
      [*] = ;         begin
      [*] = ;            if (gbool_lan_debug) then
      [*] = ;            TimeLog('_misc_QuickPlayProgress : IsServer, clientcount enough. Start Game');
      [*] = ;            var btop30 : Boolean = True;
      [*] = ;            if (gInternetShell.qprankedgame) then
      [*] = ;            begin
      [*] = ;               var i, j : Integer;
      [*] = ;               for i:=0 to qproomplcount-1 do
      [*] = ;               for j:=0 to gQuickPlay.count-1 do
      [*] = ;               begin
      [*] = ;                  var lanid : Integer = LanGetClientIDByIndex(i);
      [*] = ;                  if (lanid=0) then
      [*] = ;                  Log('lanid=0')
      [*] = ;                  else
      [*] = ;                  if (lanid>0) and (lanid=gQuickPlay.player[j].playerid) and (gQuickPlay.player[j].score<gInternetShell.mirrormatchscore) then
      [*] = ;                  btop30 := False;
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;            //Log('gInternetShell.qprankedgame='+BoolToStr(gInternetShell.qprankedgame)+' btop30='+BoolToStr(btop30)+' gInternetShell.mirrormatchscore='+IntToStr(gInternetShell.mirrormatchscore));
      [*] = ;            _map_ResetMapSettings(gMap, False, False, False, True, gInternetShell.qprankedgame, (gInternetShell.qprankedgame and btop30));
      [*] = ;            gMap.gamestage := gc_map_gamestage_waitingloading;
      [*] = ;            gMap.dlcs := gProfile.lastknowndlcs;
      [*] = ;            var i : Integer;
      [*] = ;            for i:=0 to qproomplcount-1 do
      [*] = ;            begin
      [*] = ;               gMap.players[i].lanid := LanGetClientIDByIndex(i);
      [*] = ;               gMap.players[i].name := LanGetClientNameByIndex(i);
      [*] = ;               gMap.players[i].bexists := True;
      [*] = ;               gMap.players[i].bhuman := True;
      [*] = ;
      [*] = ;               // setup teams
      [*] = ;               var str : String = SubStr(visiblename, 4, StrLength(visiblename)-3);
      [*] = ;               if IsDelimiterCharExists(str, gc_gui_dotchar) then
      [*] = ;               begin
      [*] = ;                  var j : Integer;
      [*] = ;                  for j:=0 to GetDelimiterStringCount(str, gc_gui_dotchar, gc_gui_quotechar)-1 do
      [*] = ;                  begin
      [*] = ;                     var num : Integer = StrToInt(GetDelimiterStringByIndex(str, gc_gui_dotchar, gc_gui_quotechar, j));
      [*] = ;                     if num=gMap.players[i].lanid then
      [*] = ;                     begin
      [*] = ;                        gMap.players[i].color := j;
      [*] = ;                        if (j<(qproomplcount div 2)) then
      [*] = ;                        gMap.players[i].team := 1
      [*] = ;                        else
      [*] = ;                        gMap.players[i].team := 2;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;            var pLan : Integer = _parser_ParserTemporary(True);
      [*] = ;            gMap.brating := gInternetShell.qprankedgame;
      [*] = ;            if (qproomplcount=2) then
      [*] = ;            gMap.settings.gen.mapsize := 3;
      [*] = ;            gbool_gui_hidenicks := True;
      [*] = ;
      [*] = ;            _misc_SetupMapPlayersInfo();
      [*] = ;            StateMachineGlobalVariablesSaveToParser(pLan, 'gMap', False, False);
      [*] = ;            LanSendParser(gc_LAN_GENERATE, pLan);
      [*] = ;            LanLockServer;
      [*] = ;            LanDoStart();
      [*] = ;         end
      [*] = ;         else
      [*] = ;         begin
      [*] = ;            LanTerminateGame;
      [*] = ;            SetupTime(gInternetShell.qprequeststart);
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;   end
      [*] = ;   else
      [*] = ;   if (validroomid=0) and (gInternetShell.qprequeststop<>0) then
      [*] = ;   begin
      [*] = ;      if (CheckTime(gInternetShell.qprequeststop)) then
      [*] = ;      begin
      [*] = ;         if (gbool_lan_debug) then
      [*] = ;         TimeLog('gInternetShell.qprequeststop');
      [*] = ;         gInternetShell.qprequeststart := 0;
      [*] = ;         gInternetShell.autosearchrealstarttime := 0;
      [*] = ;         if gInternetShell.bratingroom then
      [*] = ;         begin
      [*] = ;            gbool_gui_showcustomgame := True;
      [*] = ;            gInternetShell.autosearchhistorytotaltime := gInternetShell.autosearchhistorytotaltime+gInternetShell.autosearchtotaltime;
      [*] = ;            gInternetShell.autosearchtotaltime := 0;
      [*] = ;            gInternetShell.ClearQuickPlay;
      [*] = ;            _misc_InternetShellUpdateCurrentSessionName(gInternetShell, False);
      [*] = ;         end
      [*] = ;         else
      [*] = ;         begin
      [*] = ;            gstring_roomchecksum := '';
      [*] = ;            _misc_QuickPlayUnsign(False);
      [*] = ;         end;
      [*] = ;         gInternetShell.ClearQuickPlay;
      [*] = ;      end;
      [*] = ;   end
      [*] = ;   else
      [*] = ;   if (validroomid=0) and (CheckTime(gInternetShell.qprequestmakematch)) then
      [*] = ;   begin
      [*] = ;      if (gbool_lan_debug) then
      [*] = ;      TimeLog('gInternetShell.qprequestmakematch');
      [*] = ;      if gInternetShell.bratingroom then
      [*] = ;      begin
      [*] = ;         var bmatchmade : Boolean = _misc_QuickPlayMake;
      [*] = ;         if (not bmatchmade) then
      [*] = ;         begin
      [*] = ;            gInternetShell.autosearchtotaltime := gInternetShell.autosearchtotaltime+quickplaytimestep;
      [*] = ;            var psession : Pointer = gInternetShell.sessions.GetByMasterID(gInternetShell.currentsessionid);
      [*] = ;            if (psession<>nil) then
      [*] = ;            begin
      [*] = ;               var newroomdata, newmapname : String;
      [*] = ;               var prevmapname : String = TInternetShellSession(psession).mapname;
      [*] = ;               _misc_GenerateRoomDataAndMapName(psession, newroomdata, newmapname);
      [*] = ;               if (prevmapname<>newmapname) then
      [*] = ;               begin
      [*] = ;                  gInternetShell.currentsession.mapname := newmapname;
      [*] = ;                  TInternetShellSession(psession).mapname := newmapname;
      [*] = ;                  LanSrvSetMapFile(newmapname);
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;         end
      [*] = ;         else
      [*] = ;         gInternetShell.qprequestsleep := _misc_GetRealTime;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      begin
      [*] = ;         var bmatchmade : Boolean;
      [*] = ;         if (gInternetShell.autosearchtotaltime>49) then
      [*] = ;         bmatchmade := _misc_QuickPlayMake;
      [*] = ;         if (not bmatchmade) then
      [*] = ;         SetupTime(gInternetShell.qprequestsign)
      [*] = ;         //_misc_QuickPlaySign(gInternetShell.autosearchtotaltime)
      [*] = ;         else
      [*] = ;         gInternetShell.qprequestsleep := _misc_GetRealTime;
      [*] = ;      end;
      [*] = ;   end
      [*] = ;   else
      [*] = ;   if (CheckTime(gInternetShell.qprequestcloseroom)) then
      [*] = ;   begin
      [*] = ;      if (gbool_lan_debug) then
      [*] = ;      TimeLog('gInternetShell.qprequestcloseroom');
      [*] = ;      bLanIdle := False;
      [*] = ;      gInternetShell.qprequestterminate := 0;
      [*] = ;      gInternetShell.autosearchroomtime := 0;
      [*] = ;      LanTerminateGame;
      [*] = ;   end
      [*] = ;   else
      [*] = ;   if (CheckTime(gInternetShell.qprequestterminate)) then
      [*] = ;   begin
      [*] = ;      if (gbool_lan_debug) then
      [*] = ;      TimeLog('gInternetShell.qprequestterminate');
      [*] = ;      gInternetShell.qprequestcloseroom := 0;
      [*] = ;      gInternetShell.autosearchroomtime := 0;
      [*] = ;      LanTerminateGame;
      [*] = ;   end
      [*] = ;   else
      [*] = ;   if (validroomid=0) and (CheckTime(gInternetShell.qprequeststart)) then
      [*] = ;   begin
      [*] = ;      if (gbool_lan_debug) then
      [*] = ;      TimeLog('gInternetShell.qprequeststart');
      [*] = ;      gInternetShell.bautosearch := True;
      [*] = ;      gInternetShell.autosearchtotaltime := gInternetShell.autosearchhistorytotaltime;
      [*] = ;      gInternetShell.autosearchrealstarttime := _misc_GetRealTime;
      [*] = ;      if gInternetShell.bratingroom then
      [*] = ;      begin
      [*] = ;         gbool_gui_showcustomgame := True;
      [*] = ;         gInternetShell.bcustomautosearch := True;
      [*] = ;         _misc_InternetShellUpdateCurrentSessionName(gInternetShell, False);
      [*] = ;      end
      [*] = ;      else
      [*] = ;      begin
      [*] = ;         gstring_roomchecksum := '';
      [*] = ;         gbool_gui_showinternetshell := True;
      [*] = ;      end;
      [*] = ;   end
      [*] = ;   else
      [*] = ;   if (validroomid=0) and (CheckTime(gInternetShell.qprequestsign)) then
      [*] = ;   begin
      [*] = ;      if (gbool_lan_debug) then
      [*] = ;      TimeLog('gInternetShell.qprequestsign : _net_IsOnline = '+BoolToStr(gbool_lan_isonlinecached));
      [*] = ;      if (not gbool_lan_isonlinecached) then
      [*] = ;      _misc_QuickPlaySign(gInternetShell.autosearchtotaltime);
      [*] = ;   end;
      [*] = ;
      [*] = ;   var elmCurrent, elmList : Integer;
      [*] = ;   if gInternetShell.bshowranking then
      [*] = ;   begin
      [*] = ;      elmCurrent := GetGUIElementIndexByNameParent('internetshell.rankingsback', _gui_GetTop);
      [*] = ;      if elmCurrent<>0 then
      [*] = ;      elmList := GetGUIElementIndexByNameParent('rankings', elmCurrent);
      [*] = ;   end
      [*] = ;   else
      [*] = ;   begin
      [*] = ;      elmCurrent := GetGUIElementIndexByNameParent('internetshell.sessionsback', _gui_GetTop);
      [*] = ;      if elmCurrent<>0 then
      [*] = ;      elmList := GetGUIElementIndexByNameParent('sessions', elmCurrent);
      [*] = ;   end;
      [*] = ;   if (elmCurrent<>0) and (GetGUIElementVisible(elmCurrent)) then
      [*] = ;   begin
      [*] = ;      if (not gInternetShell.bshowranking) then
      [*] = ;      begin
      [*] = ;         var ind : Integer = GetGUIListBoxItemIndexOfTag(elmList, -1);
      [*] = ;         if ind>=0 then
      [*] = ;         begin
      [*] = ;            var pllist : String;
      [*] = ;            ArrayClear;
      [*] = ;            var i : Integer;
      [*] = ;            for i:=0 to gQuickPlay.count-1 do
      [*] = ;            ArrayPushValue(gQuickPlay.player[i].playerid);
      [*] = ;            ArraySort(True);
      [*] = ;            for i:=ArrayGetCount-1 downto 0 do
      [*] = ;            begin
      [*] = ;               var playerid : Integer = ArrayPopValue;
      [*] = ;               var pclient : Pointer = gInternetShell.clients.GetByLanID(playerid);
      [*] = ;               if (pclient<>nil) then
      [*] = ;               begin
      [*] = ;                  if pllist<>'' then
      [*] = ;                  pllist := pllist+', ';
      [*] = ;                  var nick : String = TInternetShellClient(pclient).nick;
      [*] = ;                  pllist := pllist+nick;
      [*] = ;                  if (i>5) then
      [*] = ;                  begin
      [*] = ;                     pllist := pllist+'...';
      [*] = ;                     break;
      [*] = ;                  end;
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;            SetGUIListBoxItemValue(elmList, ind, #9+'!'+#9+#9+GetLocaleTableListItemByID('new', 'internetshell.text.autosearchroom')+'...'+#9+#9+#9+#9+#9+' '+IntToStr(gQuickPlay.count));
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;
      [*] = ;      if (gInternetShell.autosearchrealstarttime>0) then
      [*] = ;      begin
      [*] = ;         var elmTimer : Integer = GetGUIElementIndexByNameParent('quickplaytimer', elmCurrent);
      [*] = ;         if (elmTimer<>0) then
      [*] = ;         begin
      [*] = ;            var text : String;
      [*] = ;            _misc_TimeToStr(_misc_GetRealTime-gInternetShell.autosearchrealstarttime, text, True);
      [*] = ;            SetGUIElementText(elmTimer, text);
      [*] = ;         end;
      [*] = ;      end;
      [*] = ;   end;
      [*] = ;end;
      [*] = ;
      [*] = ;if ((gInternetShell.bautosearch) or (gInternetShell.bcustomautosearch)) and (gMap.gamestage=gc_map_gamestage_none) and (gInternetShell.qprequestsleep=0) and (bLanIdle) then
      [*] = ;begin
      [*] = ;   if (gbool_lan_isonlinecached) then
      [*] = ;   begin
      [*] = ;      var qproomplcount : Integer;
      [*] = ;      var visiblename : String;
      [*] = ;      if (gInternetShell.currentsessionid>0) then
      [*] = ;      begin
      [*] = ;         var psession : Pointer = gInternetShell.sessions.GetByMasterID(gInternetShell.currentsessionid);
      [*] = ;         if (psession<>nil) then
      [*] = ;         begin
      [*] = ;            var pass, roomchecksum : String;
      [*] = ;            _misc_GetGameNameAndPasswordBySession(psession, visiblename, pass, roomchecksum);
      [*] = ;            if (pass=gc_quickplay_roompass) then
      [*] = ;            begin
      [*] = ;               var code : String = SubStr(visiblename, 0, 3);
      [*] = ;               var searchcode : String;
      [*] = ;               if gInternetShell.qprankedgame then
      [*] = ;               searchcode := 'qp='
      [*] = ;               else
      [*] = ;               searchcode := 'qt=';
      [*] = ;               if (code=searchcode) then
      [*] = ;               begin
      [*] = ;                  binqproom := True;
      [*] = ;                  var str : String = SubStr(visiblename, 4, StrLength(visiblename)-3);
      [*] = ;                  if IsDelimiterCharExists(str, gc_gui_dotchar) then
      [*] = ;                  begin
      [*] = ;                     var masterid : Integer = StrToInt(GetDelimiterStringByIndex(str, gc_gui_dotchar, gc_gui_quotechar, 0));
      [*] = ;                     if masterid>0 then
      [*] = ;                     begin
      [*] = ;                        var j : Integer;
      [*] = ;                        for j:=0 to GetDelimiterStringCount(str, gc_gui_dotchar, gc_gui_quotechar)-1 do
      [*] = ;                        qproomplcount := qproomplcount+1;
      [*] = ;                     end;
      [*] = ;                  end;
      [*] = ;               end
      [*] = ;               else
      [*] = ;               begin
      [*] = ;                  if gInternetShell.qprankedgame then
      [*] = ;                  searchcode := 'qs='
      [*] = ;                  else
      [*] = ;                  searchcode := 'qz=';
      [*] = ;                  if (code=searchcode) then
      [*] = ;                  binqsroom := True;
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;            if (StrLength(roomchecksum)=5) and (SubStr(roomchecksum, 1, 1)='r') then
      [*] = ;            bincustomroom := True;
      [*] = ;         end;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      if binqsroom then
      [*] = ;      begin
      [*] = ;         ErrorLog('DoProgress : binqsroom=True but gInternetShell.currentsessionid=0');
      [*] = ;         gInternetShell.currentsessionid := LanMyInfoID;
      [*] = ;      end;
      [*] = ;
      [*] = ;      if (bincustomroom) then
      [*] = ;      begin
      [*] = ;         if gInternetShell.autosearchdocreate<>'' then
      [*] = ;         begin
      [*] = ;            if (gbool_lan_debug) then
      [*] = ;            TimeLog('bincustomroom : SetupTime(gInternetShell.qprequestterminate) : autosearchdocreate<>''''');
      [*] = ;            SetupTime(gInternetShell.qprequestterminate);
      [*] = ;         end
      [*] = ;         else
      [*] = ;         if validroomid>0 then
      [*] = ;         begin
      [*] = ;            if (gbool_lan_debug) then
      [*] = ;            TimeLog('bincustomroom : SetupTime(gInternetShell.qprequestterminate) : validroomid>0');
      [*] = ;            SetupTime(gInternetShell.qprequestterminate);
      [*] = ;         end
      [*] = ;         else
      [*] = ;         if (_net_IsServer) then
      [*] = ;         begin
      [*] = ;            // increase timer in mapname
      [*] = ;            if (_misc_GetRealTime-gInternetShell.autosearchstarttime>quickplaytimestep) then
      [*] = ;            begin
      [*] = ;               gInternetShell.autosearchstarttime := _misc_GetRealTime;
      [*] = ;               SetupTime(gInternetShell.qprequestmakematch);
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      if (binqsroom) then
      [*] = ;      begin
      [*] = ;         if gInternetShell.autosearchdocreate<>'' then
      [*] = ;         begin
      [*] = ;            if (gbool_lan_debug) then
      [*] = ;            TimeLog('binqsroom : SetupTime(gInternetShell.qprequestterminate) : autosearchdocreate<>''''');
      [*] = ;            SetupTime(gInternetShell.qprequestterminate);
      [*] = ;         end
      [*] = ;         else
      [*] = ;         if validroomid>0 then
      [*] = ;         begin
      [*] = ;            if (gbool_lan_debug) then
      [*] = ;            TimeLog('binqsroom : SetupTime(gInternetShell.qprequestterminate) : validroomid>0');
      [*] = ;            SetupTime(gInternetShell.qprequestterminate);
      [*] = ;         end
      [*] = ;         else
      [*] = ;         if _misc_GetRealTime-gInternetShell.autosearchstarttime>quickplaytimestep then
      [*] = ;         begin
      [*] = ;            gInternetShell.autosearchtotaltime := gInternetShell.autosearchtotaltime+quickplaytimestep;
      [*] = ;            gInternetShell.autosearchstarttime := _misc_GetRealTime;
      [*] = ;            if (gbool_lan_debug) then
      [*] = ;            TimeLog('gInternetShell.autosearchstarttime>quickplaytimestep : SetupTime(gInternetShell.qprequestterminate)');
      [*] = ;            SetupTime(gInternetShell.qprequestterminate);
      [*] = ;         end;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      if (binqproom) then
      [*] = ;      begin
      [*] = ;         if (gMap.gamestage=gc_map_gamestage_none) then
      [*] = ;         begin
      [*] = ;            if _net_IsServer then
      [*] = ;            begin
      [*] = ;               if LanGetClientsCount>qproomplcount then
      [*] = ;               begin
      [*] = ;                  LanKillClient(LanGetClientIDByIndex(LanGetClientsCount-1));
      [*] = ;                  if (gbool_lan_debug) then
      [*] = ;                  TimeLog('LanGetClientsCount>qproomplcount : LanKillClient');
      [*] = ;               end
      [*] = ;               else
      [*] = ;               if (LanGetClientsCount=qproomplcount) then
      [*] = ;               begin
      [*] = ;                  SetupTime(gInternetShell.qprequeststartgame);
      [*] = ;                  gInternetShell.qprequeststartgameplcount := qproomplcount;
      [*] = ;                  gInternetShell.qprequeststartgamename := visiblename;
      [*] = ;               end
      [*] = ;               else
      [*] = ;               if (gInternetShell.autosearchroomtime>0) and (gInternetShell.autosearchroomtime+17<_misc_GetRealTime) then
      [*] = ;               begin
      [*] = ;                  ErrorLog('DoProgress : Shouldnt be here, but not a problem 1');
      [*] = ;                  SetupTime(gInternetShell.qprequestterminate);
      [*] = ;               end;
      [*] = ;            end
      [*] = ;            else
      [*] = ;            //if _net_IsClient then
      [*] = ;            begin
      [*] = ;               if (gInternetShell.autosearchroomtime>0) and (gInternetShell.autosearchroomtime+22<_misc_GetRealTime) then
      [*] = ;               begin
      [*] = ;                  ErrorLog('DoProgress : Shouldnt be here, but not a problem 2');
      [*] = ;                  SetupTime(gInternetShell.qprequestterminate);
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      if (gInternetShell.qprequestterminate=0) and (gInternetShell.qprequestmakematch=0) then
      [*] = ;      begin
      [*] = ;         //ErrorLog('IsOnline, autosearch, but unknown room');
      [*] = ;         //SetupTime(gInternetShell.qprequestterminate);
      [*] = ;         //SetupTime(gInternetShell.qprequestmakematch);
      [*] = ;      end;
      [*] = ;   end
      [*] = ;   else
      [*] = ;   begin
      [*] = ;      if (validroomid>0) then
      [*] = ;      begin
      [*] = ;         if (gMap.gamestage=gc_map_gamestage_none) then
      [*] = ;         begin
      [*] = ;            if (_misc_GetRealTime>gInternetShell.autosearchantispamlasttime) and (validroomid<>LanMyInfoID) then
      [*] = ;            begin
      [*] = ;               if (gbool_lan_debug) then
      [*] = ;               TimeLog('validroomid='+IntToStr(validroomid)+' LanMyInfoID='+IntToStr(LanMyInfoID)+' : LanJoinGame : gInternetShell.qprequestcloseroom := realtime+15');
      [*] = ;               gInternetShell.autosearchantispamlasttime := _misc_GetRealTime+_misc_QuickPlayGetAntispamTime*0.5;
      [*] = ;               gInternetShell.autosearchroomtime := _misc_GetRealTime;
      [*] = ;               //gInternetShell.currentsessionid := validroomid;
      [*] = ;               LanJoinGame('', IntToStr(validroomid), False);
      [*] = ;               gInternetShell.qprequeststop := 0;
      [*] = ;               gInternetShell.qprequeststart := 0;
      [*] = ;               gInternetShell.qprequestsign := 0;
      [*] = ;               gInternetShell.qprequestmakematch := 0;
      [*] = ;               gInternetShell.qprequeststartgame := 0;
      [*] = ;               gInternetShell.qprequestcloseroom := _misc_GetRealTime+15;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      if (gInternetShell.autosearchdocreate<>'') then
      [*] = ;      begin
      [*] = ;         if (gInternetShell.qprequestterminate=0) then
      [*] = ;         begin
      [*] = ;            var msg : String = gInternetShell.autosearchdocreate;
      [*] = ;            gInternetShell.autosearchdocreate := '';
      [*] = ;            if (SubStr(msg, 0, 1)=#9) then
      [*] = ;            begin
      [*] = ;               if (gbool_lan_debug) then
      [*] = ;               TimeLog('autosearchdocreate = '+msg);
      [*] = ;               if ((gInternetShell.bautosearch) or (gInternetShell.bcustomautosearch)) and (not gbool_lan_isonlinecached) then
      [*] = ;               begin
      [*] = ;                  var pass : String = gc_quickplay_roompass;
      [*] = ;                  var gamename : String = SubStr(msg, 2, StrLength(msg)-1);
      [*] = ;                  var checksum : String;
      [*] = ;                  if gbool_modsscript then
      [*] = ;                  checksum := gstring_checksum
      [*] = ;                  else
      [*] = ;                  checksum := '0'+gstring_checksum;
      [*] = ;                  gInternetShell.autosearchteam := 1; // master always in team 1
      [*] = ;                  var plcount : Integer = GetDelimiterStringCount(msg, gc_gui_dotchar, gc_gui_quotechar)+1;
      [*] = ;                  LanCreateGame('', #34+gamename+#34+#9+#34+pass+#34+#9+checksum, '0', plcount);
      [*] = ;                  //gInternetShell.currentsessionid := LanMyInfoID;
      [*] = ;                  gInternetShell.autosearchroomtime := _misc_GetRealTime;
      [*] = ;                  gInternetShell.qprequeststop := 0;
      [*] = ;                  gInternetShell.qprequeststart := 0;
      [*] = ;                  gInternetShell.qprequestsign := 0;
      [*] = ;                  gInternetShell.qprequestmakematch := 0;
      [*] = ;                  gInternetShell.qprequeststartgame := 0;
      [*] = ;                  gInternetShell.qprequestcloseroom := _misc_GetRealTime+10;
      [*] = ;               end;
      [*] = ;            end;
      [*] = ;         end;
      [*] = ;      end
      [*] = ;      else
      [*] = ;      if (gInternetShell.qprequestmakematch=0) then
      [*] = ;      begin
      [*] = ;         SetupTime(gInternetShell.qprequestmakematch);
      [*] = ;      end;
      [*] = ;      //else
      [*] = ;      //if (gInternetShell.qprequeststart=0) then
      [*] = ;      //begin
      [*] = ;         //   ErrorLog('IsOnline=False, gInternetShell.qprequeststart=0, set gInternetShell.qprequeststart to realtime');
      [*] = ;         //   SetupTime(gInternetShell.qprequeststart);
      [*] = ;      //end;
      [*] = ;   end;
      [*] = ;end;
   struct.end
section.end

